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
,
74 ANGLE_NONE
= Low(SmallInt);
76 CORPSE_STATE_REMOVEME
= 0;
77 CORPSE_STATE_NORMAL
= 1;
78 CORPSE_STATE_MESS
= 2;
80 PLAYER_RECT
: TRectWH
= (X
:15; Y
:12; Width
:34; Height
:52);
81 PLAYER_RECT_CX
= 15+(34 div 2);
82 PLAYER_RECT_CY
= 12+(52 div 2);
83 PLAYER_CORPSERECT
: TRectWH
= (X
:15; Y
:48; Width
:34; Height
:16);
86 PLAYER_HP_LIMIT
= 200;
88 PLAYER_AP_LIMIT
= 200;
91 PLAYER1_DEF_COLOR
: TRGB
= (R
:64; G
:175; B
:48);
92 PLAYER2_DEF_COLOR
: TRGB
= (R
:96; G
:96; B
:96);
108 TPlayerStatArray
= Array of TPlayerStat
;
110 TPlayerSavedState
= record
118 Ammo
: Array [A_BULLETS
..A_HIGH
] of Word;
119 MaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
120 Weapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
121 Rulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
130 TPlayer
= class (TObject
)
138 FDirection
: TDirection
;
146 FMonsterKills
: Integer;
152 FCanJetpack
: Boolean;
158 FNextWeapDelay
: Byte; // frames
159 FBFGFireCounter
: SmallInt;
160 FLastSpawnerUID
: Word;
164 FSpectatePlayer
: Integer;
166 FSavedState
: TPlayerSavedState
;
168 FModel
: TPlayerModel
;
171 FActionForce
: Boolean;
172 FActionChanged
: Boolean;
174 FFireAngle
: SmallInt;
176 FShellTimer
: Integer;
178 FSawSound
: TPlayableSound
;
179 FSawSoundIdle
: TPlayableSound
;
180 FSawSoundHit
: TPlayableSound
;
181 FSawSoundSelect
: TPlayableSound
;
182 FJetSoundOn
: TPlayableSound
;
183 FJetSoundOff
: TPlayableSound
;
184 FJetSoundFly
: TPlayableSound
;
188 FJustTeleported
: Boolean;
191 function CollideLevel(XInc
, YInc
: Integer): Boolean;
192 function StayOnStep(XInc
, YInc
: Integer): Boolean;
193 function HeadInLiquid(XInc
, YInc
: Integer): Boolean;
194 function BodyInLiquid(XInc
, YInc
: Integer): Boolean;
195 function BodyInAcid(XInc
, YInc
: Integer): Boolean;
196 function FullInLift(XInc
, YInc
: Integer): Integer;
197 {procedure CollideItem();}
198 procedure FlySmoke(Times
: DWORD
= 1);
199 function GetAmmoByWeapon(Weapon
: Byte): Word;
200 procedure SetAction(Action
: Byte; Force
: Boolean = False);
201 procedure OnDamage(Angle
: SmallInt); virtual;
202 function firediry(): Integer;
204 procedure Run(Direction
: TDirection
);
205 procedure NextWeapon();
206 procedure PrevWeapon();
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_HIGH
] of Word;
221 FMaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
222 FWeapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
223 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
225 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
226 FReloading
: Array [WP_FIRST
..WP_LAST
] 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 [WP_FIRST
..WP_LAST
] of Byte;
346 CloseWeaponPrior
: Array [WP_FIRST
..WP_LAST
] of Byte;
347 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] 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 [WP_FIRST
..WP_LAST
] of Byte;
516 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
517 w_prior3
: Array [WP_FIRST
..WP_LAST
] 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 [WP_FIRST
..WP_LAST
] 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 [WP_FIRST
..WP_LAST
] 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 [WP_FIRST..WP_LAST] 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 [WP_FIRST
..WP_LAST
] 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_HIGH
do
827 Mem
.ReadWord(gPlayers
[a
].FAmmo
[i
]);
828 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
829 for i
:= A_BULLETS
to A_HIGH
do
830 Mem
.ReadWord(gPlayers
[a
].FMaxAmmo
[i
]);
832 for i
:= WP_FIRST
to WP_LAST
do
833 Mem
.ReadBoolean(gPlayers
[a
].FWeapon
[i
]);
834 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
835 for i
:= WP_FIRST
to WP_LAST
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
:= WP_FIRST
to WP_LAST
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
:= WP_FIRST
to WP_LAST
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 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1273 for i
:= 0 to High(gPlayers
) do
1275 if gPlayers
[i
] <> nil then
1277 if gPlayers
[i
] is TPlayer
then
1279 gPlayers
[i
].Update();
1280 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1284 // bot updates weapons in `UpdateCombat()`
1285 TBot(gPlayers
[i
]).Update();
1289 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1292 procedure g_Player_DrawAll();
1296 if gPlayers
= nil then Exit
;
1298 for i
:= 0 to High(gPlayers
) do
1299 if gPlayers
[i
] <> nil then
1300 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1301 else TBot(gPlayers
[i
]).Draw();
1304 procedure g_Player_DrawDebug(p
: TPlayer
);
1308 if p
= nil then Exit
;
1309 if (@p
.FObj
) = nil then Exit
;
1311 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1313 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1314 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1315 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1316 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1317 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1318 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1321 procedure g_Player_DrawHealth();
1326 if gPlayers
= nil then Exit
;
1327 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1329 for i
:= 0 to High(gPlayers
) do
1330 if gPlayers
[i
] <> nil then
1332 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1333 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1334 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1335 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1336 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1337 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1341 function g_Player_Get(UID
: Word): TPlayer
;
1347 if gPlayers
= nil then
1350 for a
:= 0 to High(gPlayers
) do
1351 if gPlayers
[a
] <> nil then
1352 if gPlayers
[a
].FUID
= UID
then
1354 Result
:= gPlayers
[a
];
1359 function g_Player_GetCount(): Byte;
1365 if gPlayers
= nil then
1368 for a
:= 0 to High(gPlayers
) do
1369 if gPlayers
[a
] <> nil then
1370 Result
:= Result
+ 1;
1373 function g_Player_GetStats(): TPlayerStatArray
;
1379 if gPlayers
= nil then Exit
;
1381 for a
:= 0 to High(gPlayers
) do
1382 if gPlayers
[a
] <> nil then
1384 SetLength(Result
, Length(Result
)+1);
1385 with Result
[High(Result
)] do
1387 Ping
:= gPlayers
[a
].FPing
;
1388 Loss
:= gPlayers
[a
].FLoss
;
1389 Name
:= gPlayers
[a
].FName
;
1390 Team
:= gPlayers
[a
].FTeam
;
1391 Frags
:= gPlayers
[a
].FFrags
;
1392 Deaths
:= gPlayers
[a
].FDeath
;
1393 Kills
:= gPlayers
[a
].FKills
;
1394 Color
:= gPlayers
[a
].FModel
.Color
;
1395 Lives
:= gPlayers
[a
].FLives
;
1396 Spectator
:= gPlayers
[a
].FSpectator
;
1401 procedure g_Player_RememberAll
;
1405 for i
:= Low(gPlayers
) to High(gPlayers
) do
1406 if (gPlayers
[i
] <> nil) and gPlayers
[i
].Live
then
1407 gPlayers
[i
].RememberState
;
1410 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1414 gTeamStat
[TEAM_RED
].Goals
:= 0;
1415 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1417 if gPlayers
<> nil then
1418 for i
:= 0 to High(gPlayers
) do
1419 if gPlayers
[i
] <> nil then
1421 gPlayers
[i
].Reset(Force
);
1423 if gPlayers
[i
] is TPlayer
then
1425 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1426 gPlayers
[i
].Respawn(Silent
)
1428 gPlayers
[i
].Spectate();
1431 TBot(gPlayers
[i
]).Respawn(Silent
);
1435 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1442 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1447 if (FHealth
>= -50) or (gGibsCount
= 0) then
1449 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1453 for find_id
:= 0 to High(gCorpses
) do
1454 if gCorpses
[find_id
] = nil then
1461 find_id
:= Random(Length(gCorpses
));
1463 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1464 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1465 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1466 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1469 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1470 FObj
.Y
+ PLAYER_RECT_CY
,
1471 FModel
.Name
, FModel
.Color
);
1475 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1479 if (gShells
= nil) or (Length(gShells
) = 0) then
1482 with gShells
[CurrentShell
] do
1488 if T
= SHELL_BULLET
then
1490 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1494 Obj
.Rect
.Width
:= 4;
1495 Obj
.Rect
.Height
:= 2;
1499 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1503 Obj
.Rect
.Width
:= 7;
1504 Obj
.Rect
.Height
:= 3;
1510 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1511 RAngle
:= Random(360);
1512 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1514 if CurrentShell
>= High(gShells
) then
1521 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1524 GibsArray
: TGibsArray
;
1526 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1528 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1531 for a
:= 0 to High(GibsArray
) do
1532 with gGibs
[CurrentGib
] do
1535 ID
:= GibsArray
[a
].ID
;
1536 MaskID
:= GibsArray
[a
].MaskID
;
1539 Obj
.Rect
:= GibsArray
[a
].Rect
;
1540 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1541 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1542 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1543 RAngle
:= Random(360);
1545 if gBloodCount
> 0 then
1546 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1547 Random(48), Random(48), 150, 0, 0);
1549 if CurrentGib
>= High(gGibs
) then
1556 procedure g_Player_UpdatePhysicalObjects();
1562 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1567 if T
= SHELL_BULLET
then
1568 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1570 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1575 if gGibs
<> nil then
1576 for i
:= 0 to High(gGibs
) do
1577 if gGibs
[i
].Live
then
1581 mr
:= g_Obj_Move(@Obj
, True, False, True);
1583 if WordBool(mr
and MOVE_FALLOUT
) then
1589 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1590 if WordBool(mr
and MOVE_HITWALL
) then
1591 Obj
.Vel
.X
:= -(vel
.X
div 2);
1592 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1593 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1595 if (Obj
.Vel
.X
>= 0) then
1597 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1598 if RAngle
>= 360 then
1599 RAngle
:= RAngle
mod 360;
1600 end else begin // Counter-clockwise
1601 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1603 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1606 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1607 if gTime
mod (GAME_TICK
*3) = 0 then
1608 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1612 if gCorpses
<> nil then
1613 for i
:= 0 to High(gCorpses
) do
1614 if gCorpses
[i
] <> nil then
1615 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1621 gCorpses
[i
].Update();
1624 if gShells
<> nil then
1625 for i
:= 0 to High(gShells
) do
1626 if gShells
[i
].Live
then
1630 mr
:= g_Obj_Move(@Obj
, True, False, True);
1632 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1638 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1639 if WordBool(mr
and MOVE_HITWALL
) then
1641 Obj
.Vel
.X
:= -(vel
.X
div 2);
1642 if not WordBool(mr
and MOVE_INWATER
) then
1643 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1645 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1647 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1648 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1649 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1651 if RAngle
mod 90 <> 0 then
1652 RAngle
:= (RAngle
div 90) * 90;
1654 else if not WordBool(mr
and MOVE_INWATER
) then
1655 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1658 if (Obj
.Vel
.X
>= 0) then
1660 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1661 if RAngle
>= 360 then
1662 RAngle
:= RAngle
mod 360;
1663 end else begin // Counter-clockwise
1664 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1666 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1671 procedure g_Player_DrawCorpses();
1676 if gGibs
<> nil then
1677 for i
:= 0 to High(gGibs
) do
1678 if gGibs
[i
].Live
then
1681 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1684 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1685 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1687 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1690 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1696 if gCorpses
<> nil then
1697 for i
:= 0 to High(gCorpses
) do
1698 if gCorpses
[i
] <> nil then
1702 procedure g_Player_DrawShells();
1707 if gShells
<> nil then
1708 for i
:= 0 to High(gShells
) do
1709 if gShells
[i
].Live
then
1712 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1718 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1722 procedure g_Player_RemoveAllCorpses();
1728 SetLength(gGibs
, MaxGibs
);
1729 SetLength(gShells
, MaxGibs
);
1733 if gCorpses
<> nil then
1734 for i
:= 0 to High(gCorpses
) do
1738 SetLength(gCorpses
, MaxCorpses
);
1741 procedure g_Player_Corpses_SaveState(var Mem
: TBinMemoryWriter
);
1746 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ:
1748 if gCorpses
<> nil then
1749 for i
:= 0 to High(gCorpses
) do
1750 if gCorpses
[i
] <> nil then
1753 Mem
:= TBinMemoryWriter
.Create((count
+1) * 128);
1755 // Êîëè÷åñòâî òðóïîâ:
1756 Mem
.WriteInt(count
);
1762 for i
:= 0 to High(gCorpses
) do
1763 if gCorpses
[i
] <> nil then
1766 Mem
.WriteString(gCorpses
[i
].FModelName
);
1768 b
:= gCorpses
[i
].Mess
;
1769 Mem
.WriteBoolean(b
);
1770 // Ñîõðàíÿåì äàííûå òðóïà:
1771 gCorpses
[i
].SaveState(Mem
);
1775 procedure g_Player_Corpses_LoadState(var Mem
: TBinMemoryReader
);
1784 g_Player_RemoveAllCorpses();
1786 // Êîëè÷åñòâî òðóïîâ:
1789 if count
> Length(gCorpses
) then
1791 raise EBinSizeError
.Create('g_Player_Corpses_LoadState: Too Many Corpses');
1798 for i
:= 0 to count
-1 do
1801 Mem
.ReadString(str
);
1805 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1806 // Çàãðóæàåì äàííûå òðóïà:
1807 gCorpses
[i
].LoadState(Mem
);
1813 procedure TPlayer
.BFGHit();
1815 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1816 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1817 if g_Game_IsServer
and g_Game_IsNet
then
1818 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1819 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1823 procedure TPlayer
.ChangeModel(ModelName
: string);
1825 Model
: TPlayerModel
;
1827 Model
:= g_PlayerModel_Get(ModelName
);
1828 if Model
= nil then Exit
;
1834 procedure TPlayer
.SetModel(ModelName
: string);
1838 m
:= g_PlayerModel_Get(ModelName
);
1841 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1842 m
:= g_PlayerModel_Get('doomer');
1845 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1850 if FModel
<> nil then
1855 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1856 FModel
.Color
:= FColor
1858 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1859 FModel
.SetWeapon(FCurrWeap
);
1860 FModel
.SetFlag(FFlag
);
1861 SetDirection(FDirection
);
1864 procedure TPlayer
.SetColor(Color
: TRGB
);
1867 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1868 if FModel
<> nil then FModel
.Color
:= Color
;
1871 procedure TPlayer
.SwitchTeam
;
1873 if g_Game_IsClient
then
1875 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
1877 if gGameOn
and FLive
then
1878 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
1880 if FTeam
= TEAM_RED
then
1882 ChangeTeam(TEAM_BLUE
);
1883 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
1884 if g_Game_IsNet
then
1885 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
1889 ChangeTeam(TEAM_RED
);
1890 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
1891 if g_Game_IsNet
then
1892 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
1894 FPreferredTeam
:= FTeam
;
1897 procedure TPlayer
.ChangeTeam(Team
: Byte);
1904 TEAM_RED
, TEAM_BLUE
:
1905 FModel
.Color
:= TEAMCOLOR
[Team
];
1907 FModel
.Color
:= FColor
;
1909 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
1910 MH_SEND_PlayerStats(FUID
);
1914 procedure TPlayer.CollideItem();
1919 if gItems = nil then Exit;
1920 if not FLive then Exit;
1922 for i := 0 to High(gItems) do
1925 if (ItemType <> ITEM_NONE) and Live then
1926 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
1927 PLAYER_RECT.Height, @Obj) then
1929 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
1931 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
1932 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
1933 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
1934 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
1935 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
1937 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
1938 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
1939 (gGameSettings.GameType = GT_SINGLE) and
1940 (g_Player_GetCount() > 1)) then
1941 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
1947 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
1949 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
1950 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
1954 constructor TPlayer
.Create();
1960 FSawSound
:= TPlayableSound
.Create();
1961 FSawSoundIdle
:= TPlayableSound
.Create();
1962 FSawSoundHit
:= TPlayableSound
.Create();
1963 FSawSoundSelect
:= TPlayableSound
.Create();
1964 FJetSoundFly
:= TPlayableSound
.Create();
1965 FJetSoundOn
:= TPlayableSound
.Create();
1966 FJetSoundOff
:= TPlayableSound
.Create();
1968 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
1969 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
1970 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
1971 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
1972 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
1973 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
1974 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
1976 FSpectatePlayer
:= -1;
1980 FSavedState
.WaitRecall
:= False;
1983 FActualModelName
:= 'doomer';
1986 FObj
.Rect
:= PLAYER_RECT
;
1988 FBFGFireCounter
:= -1;
1989 FJustTeleported
:= False;
1995 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
1999 if (not g_Game_IsClient
) and (not FLive
) then
2004 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2005 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2007 if not g_Game_IsClient
then
2010 if t
= HIT_TRAP
then
2012 // Ëîâóøêà óáèâàåò ñðàçó:
2014 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2016 if t
= HIT_SELF
then
2020 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2023 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2024 FMegaRulez
[MR_SUIT
] := 0;
2025 FMegaRulez
[MR_INVUL
] := 0;
2026 FMegaRulez
[MR_INVIS
] := 0;
2030 // Íî îò îñòàëüíîãî ñïàñàåò:
2031 if FMegaRulez
[MR_INVUL
] >= gTime
then
2038 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2039 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2040 (SpawnerUID
= FUID
) or
2041 (not SameTeam(FUID
, SpawnerUID
)) then
2043 FLastSpawnerUID
:= SpawnerUID
;
2045 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2046 if gBloodCount
> 0 then
2048 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2049 if value
div 4 <= c
then
2050 c
:= c
- (value
div 4)
2054 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2058 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2059 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2062 if t
= HIT_WATER
then
2063 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2064 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2069 Inc(FDamageBuffer
, value
);
2073 FPain
:= FPain
+ value
;
2076 if g_Game_IsServer
and g_Game_IsNet
then
2078 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2079 MH_SEND_PlayerStats(FUID
);
2080 MH_SEND_PlayerPos(False, FUID
);
2084 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2087 if g_Game_IsClient
then
2092 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2094 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2097 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2099 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2103 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2104 MH_SEND_PlayerStats(FUID
);
2107 destructor TPlayer
.Destroy();
2109 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2111 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2115 FSawSoundIdle
.Free();
2116 FSawSoundHit
.Free();
2117 FJetSoundFly
.Free();
2119 FJetSoundOff
.Free();
2125 procedure TPlayer
.DrawBubble();
2127 bubX
, bubY
: Integer;
2130 Rw
, Gw
, Bw
: SmallInt;
2133 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= D_LEFT
, -4, 18);
2134 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2142 1: // simple textual non-bubble
2144 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2145 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2146 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2149 2: // advanced pixel-perfect bubble
2151 if FTeam
= TEAM_RED
then
2154 if FTeam
= TEAM_BLUE
then
2157 3: // colored bubble
2159 Rb
:= FModel
.Color
.R
;
2160 Gb
:= FModel
.Color
.G
;
2161 Bb
:= FModel
.Color
.B
;
2162 Rw
:= Min(Rb
* 2 + 64, 255);
2163 Gw
:= Min(Gb
* 2 + 64, 255);
2164 Bw
:= Min(Bb
* 2 + 64, 255);
2165 if (Abs(Rw
- Rb
) < 32)
2166 or (Abs(Gw
- Gb
) < 32)
2167 or (Abs(Bw
- Bb
) < 32) then
2169 Rb
:= Max(Rw
div 2 - 16, 0);
2170 Gb
:= Max(Gw
div 2 - 16, 0);
2171 Bb
:= Max(Bw
div 2 - 16, 0);
2174 4: // custom textured bubble
2176 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2177 if FDirection
= D_RIGHT
then
2178 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2180 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, M_HORIZONTAL
);
2186 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2187 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2189 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2192 Dot
:= IfThen(FDirection
= D_LEFT
, 14, 5);
2193 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2194 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
);
2195 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
);
2196 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
);
2197 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
);
2201 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2202 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2203 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2206 procedure TPlayer
.Draw();
2214 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2215 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2217 e_GetTextureSize(ID
, @w
, @h
);
2218 if FDirection
= D_LEFT
then
2219 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2220 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7, 0, True, False)
2222 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2223 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7, 0, True, False);
2226 if FMegaRulez
[MR_INVIS
] > gTime
then
2228 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2229 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2231 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2232 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2236 FModel
.Draw(FObj
.X
, FObj
.Y
, 200)
2238 FModel
.Draw(FObj
.X
, FObj
.Y
);
2241 FModel
.Draw(FObj
.X
, FObj
.Y
, 254);
2244 FModel
.Draw(FObj
.X
, FObj
.Y
);
2247 if g_debug_Frames
then
2249 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2251 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2252 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2256 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2258 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2259 if gAimLine
and Live
and
2260 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2264 procedure TPlayer
.DrawAim();
2266 wx
, wy
, xx
, yy
: Integer;
2270 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= D_LEFT
, 7, -7);
2271 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2280 1: begin // Chainsaw
2287 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2288 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2289 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2290 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2295 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2296 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2297 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2298 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2300 4: begin // Double Shotgun
2303 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2304 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2305 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2306 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2308 5: begin // Chaingun
2311 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2312 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2313 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2314 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2316 6: begin // Rocket Launcher
2319 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2320 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2321 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2322 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2324 7: begin // Plasmagun
2327 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2328 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2329 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2330 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2335 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2336 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2337 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2338 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2340 9: begin // Super Chaingun
2343 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2344 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2345 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2346 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2349 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2350 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2351 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2354 procedure TPlayer
.DrawGUI();
2357 X
, Y
, SY
, a
, p
, m
: Integer;
2361 stat
: TPlayerStatArray
;
2363 X
:= gPlayerScreenSize
.X
;
2364 SY
:= gPlayerScreenSize
.Y
;
2367 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2369 if gGameSettings
.GameMode
= GM_CTF
then
2373 if gGameSettings
.GameMode
= GM_CTF
then
2375 s
:= 'TEXTURE_PLAYER_REDFLAG';
2376 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2377 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2378 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2379 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2380 if g_Texture_Get(s
, ID
) then
2381 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2384 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2385 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2386 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2388 if gGameSettings
.GameMode
= GM_CTF
then
2390 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2391 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2392 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2393 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2394 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2395 if g_Texture_Get(s
, ID
) then
2396 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2399 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2400 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2401 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2404 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2405 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2408 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2409 e_Draw(ID
, X
+2, Y
, 0, True, False);
2411 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2415 s
:= IntToStr(Frags
);
2416 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2417 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2422 stat
:= g_Player_GetStats();
2427 for a
:= 0 to High(stat
) do
2428 if stat
[a
].Name
<> Name
then
2430 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2431 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2435 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2436 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2437 s
:= s
+IntToStr(Abs(Frags
-m
));
2439 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2440 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2443 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2445 s
:= IntToStr(Lives
);
2446 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2447 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2451 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2452 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2454 if R_BERSERK
in FRulez
then
2455 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2457 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2459 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2460 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2462 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2463 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2464 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2466 s
:= IntToStr(FArmor
);
2467 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2468 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2470 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2476 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2481 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2483 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2484 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2485 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2486 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2487 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2488 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2489 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2490 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2493 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2494 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2495 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2497 if R_KEY_RED
in FRulez
then
2498 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2500 if R_KEY_GREEN
in FRulez
then
2501 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2503 if R_KEY_BLUE
in FRulez
then
2504 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2506 if FJetFuel
> 0 then
2508 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2509 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2510 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2511 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2512 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2513 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2517 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2518 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2519 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2522 if gShowPing
and g_Game_IsClient
then
2524 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2525 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2531 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2532 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2533 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2536 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2537 s
:= _lc
[I_PLAYER_SPECT4
];
2538 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2539 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2540 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2546 procedure TPlayer
.DrawRulez();
2550 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2551 if FMegaRulez
[MR_INVUL
] >= gTime
then
2553 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2554 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2559 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2560 191, 191, 191, 0, B_INVERT
);
2563 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2564 if FMegaRulez
[MR_SUIT
] >= gTime
then
2566 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2567 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2572 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2573 0, 96, 0, 200, B_NONE
);
2576 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2577 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2579 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2580 255, 0, 0, 200, B_NONE
);
2584 procedure TPlayer
.DrawPain();
2588 if FPain
= 0 then Exit
;
2592 if a
< 15 then h
:= 0
2593 else if a
< 35 then h
:= 1
2594 else if a
< 55 then h
:= 2
2595 else if a
< 75 then h
:= 3
2596 else if a
< 95 then h
:= 4
2599 //if a > 255 then a := 255;
2601 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2602 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2605 procedure TPlayer
.DrawPickup();
2609 if FPickup
= 0 then Exit
;
2613 if a
< 15 then h
:= 1
2614 else if a
< 35 then h
:= 2
2615 else if a
< 55 then h
:= 3
2616 else if a
< 75 then h
:= 4
2619 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2622 procedure TPlayer
.Fire();
2624 f
, DidFire
: Boolean;
2625 wx
, wy
, xd
, yd
: Integer;
2628 if g_Game_IsClient
then Exit
;
2629 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2630 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2638 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2643 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2644 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2645 xd
:= wx
+IfThen(FDirection
= D_LEFT
, -30, 30);
2646 yd
:= wy
+firediry();
2651 if R_BERSERK
in FRulez
then
2653 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2654 obj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2655 obj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2658 obj
.rect
.Width
:= 39;
2659 obj
.rect
.Height
:= 52;
2660 obj
.Vel
.X
:= (xd
-wx
) div 2;
2661 obj
.Vel
.Y
:= (yd
-wy
) div 2;
2662 obj
.Accel
.X
:= xd
-wx
;
2663 obj
.Accel
.y
:= yd
-wy
;
2665 if g_Weapon_Hit(@obj
, 50, FUID
, HIT_SOME
) <> 0 then
2666 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2668 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2672 FPain
:= min(FPain
+ 25, 50);
2673 end else g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2676 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2681 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2682 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2684 FSawSoundSelect
.Stop();
2686 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2688 else if not FSawSoundHit
.IsPlaying() then
2690 FSawSoundSelect
.Stop();
2691 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2694 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2700 if FAmmo
[A_BULLETS
] > 0 then
2702 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2703 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2704 Dec(FAmmo
[A_BULLETS
]);
2705 FFireAngle
:= FAngle
;
2708 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2709 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2713 if FAmmo
[A_SHELLS
] > 0 then
2715 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2716 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
2717 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2718 Dec(FAmmo
[A_SHELLS
]);
2719 FFireAngle
:= FAngle
;
2723 FShellType
:= SHELL_SHELL
;
2727 if FAmmo
[A_SHELLS
] >= 2 then
2729 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
2730 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2731 Dec(FAmmo
[A_SHELLS
], 2);
2732 FFireAngle
:= FAngle
;
2736 FShellType
:= SHELL_DBLSHELL
;
2740 if FAmmo
[A_BULLETS
] > 0 then
2742 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
2743 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
2744 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2745 Dec(FAmmo
[A_BULLETS
]);
2746 FFireAngle
:= FAngle
;
2749 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2750 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2753 WEAPON_ROCKETLAUNCHER
:
2754 if FAmmo
[A_ROCKETS
] > 0 then
2756 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
2757 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2758 Dec(FAmmo
[A_ROCKETS
]);
2759 FFireAngle
:= FAngle
;
2765 if FAmmo
[A_CELLS
] > 0 then
2767 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
2768 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2769 Dec(FAmmo
[A_CELLS
]);
2770 FFireAngle
:= FAngle
;
2776 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
2778 FBFGFireCounter
:= 17;
2779 if not FNoReload
then
2780 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
2781 Dec(FAmmo
[A_CELLS
], 40);
2785 WEAPON_SUPERPULEMET
:
2786 if FAmmo
[A_SHELLS
] > 0 then
2788 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2789 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
2790 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2791 Dec(FAmmo
[A_SHELLS
]);
2792 FFireAngle
:= FAngle
;
2795 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2796 GameVelX
, GameVelY
-2, SHELL_SHELL
);
2800 if g_Game_IsNet
then
2804 if FCurrWeap
<> WEAPON_BFG
then
2805 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
2807 if not FNoReload
then
2808 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
2811 MH_SEND_PlayerStats(FUID
);
2816 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
2817 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
2818 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
2821 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
2824 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
2825 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
2826 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
2827 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
2832 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
2834 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
2835 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
2836 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
2839 procedure TPlayer
.JetpackOn
;
2843 FJetSoundOn
.SetPosition(0);
2844 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
2848 procedure TPlayer
.JetpackOff
;
2852 FJetSoundOff
.SetPosition(0);
2853 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
2856 procedure TPlayer
.Jump();
2858 if gFly
or FJetpack
then
2860 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
2861 if FObj
.Vel
.Y
> -VEL_FLY
then
2862 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
2865 if FJetFuel
> 0 then
2867 if (FJetFuel
< 1) and g_Game_IsServer
then
2871 if g_Game_IsNet
then
2872 MH_SEND_PlayerStats(FUID
);
2878 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
2880 FCanJetpack
:= False;
2882 // Ïðûãàåì èëè âñïëûâàåì:
2883 if (CollideLevel(0, 1) or
2884 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
2885 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
2886 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
2888 FObj
.Vel
.Y
:= -VEL_JUMP
;
2889 FCanJetpack
:= False;
2893 if BodyInLiquid(0, 0) then
2894 FObj
.Vel
.Y
:= -VEL_SW
2895 else if (FJetFuel
> 0) and FCanJetpack
and
2896 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
2900 if g_Game_IsNet
then
2901 MH_SEND_PlayerStats(FUID
);
2906 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
2908 a
, i
, k
, ab
, ar
: Byte;
2912 srv
, netsrv
: Boolean;
2917 procedure PushItem(t
: Byte);
2921 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
2922 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
2923 g_Obj_Push(@gItems
[id
].Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
2924 (FObj
.Vel
.Y
div 2)-Random(9))
2926 if KillType
= K_HARDKILL
then // -5..+5; -5..0
2927 g_Obj_Push(@gItems
[id
].Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
2928 (FObj
.Vel
.Y
div 2)-Random(6))
2929 else // -3..+3; -3..0
2930 g_Obj_Push(@gItems
[id
].Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
2931 (FObj
.Vel
.Y
div 2)-Random(4));
2933 if g_Game_IsNet
and g_Game_IsServer
then
2934 MH_SEND_ItemSpawn(True, id
);
2938 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
2939 Srv
:= g_Game_IsServer
;
2940 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
2941 if Srv
then FDeath
:= FDeath
+ 1;
2946 if not FPhysics
then
2952 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2954 if FLives
> 0 then FLives
:= FLives
- 1;
2955 if FLives
= 0 then FNoRespawn
:= True;
2958 // Íîìåð òèïà ñìåðòè:
2961 K_SIMPLEKILL
: a
:= 1;
2963 K_EXTRAHARDKILL
: a
:= 3;
2968 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
2970 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
2977 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
2979 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
2980 K_EXTRAHARDKILL
, K_FALLKILL
:
2981 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
2984 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
2988 K_HARDKILL
, K_EXTRAHARDKILL
:
2992 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
2993 if (KillType
<> K_FALLKILL
) and (Srv
) then
2994 g_Monsters_killedp();
2996 if SpawnerUID
= FUID
then
2998 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3003 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3006 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3007 begin // Óáèò äðóãèì èãðîêîì
3008 KP
:= g_Player_Get(SpawnerUID
);
3009 if (KP
<> nil) and Srv
then
3011 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3012 if SameTeam(FUID
, SpawnerUID
) then
3022 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3023 Inc(gTeamStat
[KP
.Team
].Goals
,
3024 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3026 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3029 plr
:= g_Player_Get(SpawnerUID
);
3037 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3041 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3045 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3050 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3051 begin // Óáèò ìîíñòðîì
3052 mon
:= g_Monsters_Get(SpawnerUID
);
3056 s
:= g_Monsters_GetKilledBy(mon
.MonsterType
);
3060 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3064 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3068 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3073 else // Îñîáûå òèïû ñìåðòè
3076 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3077 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3078 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3079 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3080 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3081 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3087 for a
:= WP_FIRST
to WP_LAST
do
3091 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3092 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3093 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3094 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3095 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3096 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3097 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3098 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3107 if R_ITEM_BACKPACK
in FRulez
then
3108 PushItem(ITEM_AMMO_BACKPACK
);
3110 // Âûáðîñ ðàêåòíîãî ðàíöà:
3111 if FJetFuel
> 0 then
3112 PushItem(ITEM_JETPACK
);
3115 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3117 if R_KEY_RED
in FRulez
then
3118 PushItem(ITEM_KEY_RED
);
3120 if R_KEY_GREEN
in FRulez
then
3121 PushItem(ITEM_KEY_GREEN
);
3123 if R_KEY_BLUE
in FRulez
then
3124 PushItem(ITEM_KEY_BLUE
);
3131 g_Player_CreateCorpse(Self
);
3133 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3134 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3140 for i
:= Low(gPlayers
) to High(gPlayers
) do
3142 if gPlayers
[i
] = nil then continue
;
3143 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3146 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3147 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3152 OldLR
:= gLMSRespawn
;
3153 if (gGameSettings
.GameMode
= GM_COOP
) then
3157 // everyone is dead, restart the map
3158 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3160 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3161 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3162 gLMSRespawnTime
:= gTime
+ 5000;
3164 else if (a
= 1) then
3166 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3167 if (gPlayers
[k
] = gPlayer1
) or
3168 (gPlayers
[k
] = gPlayer2
) then
3169 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3170 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3171 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3174 else if (gGameSettings
.GameMode
= GM_TDM
) then
3176 if (ab
= 0) and (ar
<> 0) then
3179 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3181 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3182 Inc(gTeamStat
[TEAM_RED
].Goals
);
3183 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3184 gLMSRespawnTime
:= gTime
+ 5000;
3186 else if (ar
= 0) and (ab
<> 0) then
3189 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3191 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3192 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3193 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3194 gLMSRespawnTime
:= gTime
+ 5000;
3196 else if (ar
= 0) and (ab
= 0) then
3199 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3201 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3202 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3203 gLMSRespawnTime
:= gTime
+ 5000;
3206 else if (gGameSettings
.GameMode
= GM_DM
) then
3210 if gPlayers
[k
] <> nil then
3213 // survivor is the winner
3214 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3216 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3219 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3220 gLMSRespawnTime
:= gTime
+ 5000;
3222 else if (a
= 0) then
3224 // everyone is dead, restart the map
3225 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3227 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3228 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3229 gLMSRespawnTime
:= gTime
+ 5000;
3232 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3234 if NetMode
= NET_SERVER
then
3235 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3237 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3243 MH_SEND_PlayerStats(FUID
);
3244 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3245 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3248 if srv
and FNoRespawn
then Spectate(True);
3249 FWantsInGame
:= True;
3252 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3254 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3255 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3258 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3260 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3261 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3264 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3266 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3267 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3268 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3270 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3271 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3272 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3276 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3278 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3279 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3280 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3284 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3286 if g_Game_IsClient
then Exit
;
3287 if Weapon
> High(FWeapon
) then Exit
;
3288 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3291 procedure TPlayer
.resetWeaponQueue ();
3294 FNextWeapDelay
:= 0;
3297 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3301 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3302 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 0);
3303 WEAPON_PISTOL
, WEAPON_CHAINGUN
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_BULLETS
] > 0);
3304 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3305 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3306 else result
:= (weapon
< length(FWeapon
));
3310 // return 255 for "no switch"
3311 function TPlayer
.getNextWeaponIndex (): Byte;
3314 wantThisWeapon
: array[0..64] of Boolean;
3315 wwc
: Integer = 0; //HACK!
3318 result
:= 255; // default result: "no switch"
3319 // had weapon cycling on previous frame? remove that flag
3320 if (FNextWeap
and $2000) <> 0 then begin FNextWeap
:= FNextWeap
and $1FFF; FNextWeapDelay
:= 0; end;
3321 // cycling has priority
3322 if (FNextWeap
and $C000) <> 0 then
3324 if (FNextWeap
and $8000) <> 0 then dir
:= 1 else dir
:= -1;
3325 FNextWeap
:= FNextWeap
or $2000; // we need this
3326 if FNextWeapDelay
> 0 then exit
; // cooldown time
3328 for i
:= 0 to High(FWeapon
) do
3330 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3331 if FWeapon
[cwi
] then
3333 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d', [FCurrWeap, cwi]), MSG_WARNING);
3334 result
:= Byte(cwi
);
3335 FNextWeapDelay
:= 10;
3343 for i
:= 0 to High(wantThisWeapon
) do wantThisWeapon
[i
] := false;
3344 for i
:= 0 to High(FWeapon
) do if (FNextWeap
and (1 shl i
)) <> 0 then begin wantThisWeapon
[i
] := true; Inc(wwc
); end;
3345 // exclude currently selected weapon from the set
3346 wantThisWeapon
[FCurrWeap
] := false;
3347 // slow down alterations a little
3350 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3351 // more than one weapon requested, assume "alteration" and check alteration delay
3352 if FNextWeapDelay
> 0 then begin FNextWeap
:= 0; exit
; end; // yeah
3354 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3355 // but clear all counters if no weapon should be switched
3356 if wwc
< 1 then begin resetWeaponQueue(); exit
; end;
3357 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3358 // try weapons in descending order
3359 for i
:= High(FWeapon
) downto 0 do
3361 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3366 FNextWeapDelay
:= 10; // anyway, 'cause why not
3370 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3374 procedure TPlayer
.RealizeCurrentWeapon();
3375 function switchAllowed (): Boolean;
3380 if FBFGFireCounter
<> -1 then
3382 if FTime
[T_SWITCH
] > gTime
then
3384 for i
:= WP_FIRST
to WP_LAST
do
3385 if FReloading
[i
] > 0 then
3393 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3394 //FNextWeap := FNextWeap and $1FFF;
3395 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3397 if not switchAllowed
then
3399 //HACK for weapon cycling
3400 if (FNextWeap
and $7000) <> 0 then FNextWeap
:= 0;
3404 nw
:= getNextWeaponIndex();
3405 if nw
= 255 then exit
; // don't reset anything here
3406 if nw
> High(FWeapon
) then
3408 // don't forget to reset queue here!
3409 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3417 FTime
[T_SWITCH
] := gTime
+156;
3418 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3419 FModel
.SetWeapon(FCurrWeap
);
3420 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3424 procedure TPlayer
.NextWeapon();
3426 if g_Game_IsClient
then Exit
;
3430 procedure TPlayer
.PrevWeapon();
3432 if g_Game_IsClient
then Exit
;
3436 procedure TPlayer
.SetWeapon(W
: Byte);
3438 if FCurrWeap
<> W
then
3439 if W
= WEAPON_SAW
then
3440 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3443 FModel
.SetWeapon(CurrWeap
);
3447 function TPlayer
.PickItem(ItemType
: Byte; respawn
: Boolean; var remove
: Boolean): Boolean;
3452 if g_Game_IsClient
then Exit
;
3454 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3455 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and respawn
;
3460 if FHealth
< PLAYER_HP_SOFT
then
3462 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3465 if gFlash
= 2 then Inc(FPickup
, 5);
3469 if FHealth
< PLAYER_HP_SOFT
then
3471 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3474 if gFlash
= 2 then Inc(FPickup
, 5);
3478 if FArmor
< PLAYER_AP_SOFT
then
3480 FArmor
:= PLAYER_AP_SOFT
;
3483 if gFlash
= 2 then Inc(FPickup
, 5);
3487 if FArmor
< PLAYER_AP_LIMIT
then
3489 FArmor
:= PLAYER_AP_LIMIT
;
3492 if gFlash
= 2 then Inc(FPickup
, 5);
3496 if FHealth
< PLAYER_HP_LIMIT
then
3498 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3501 if gFlash
= 2 then Inc(FPickup
, 5);
3505 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3507 if FHealth
< PLAYER_HP_LIMIT
then
3508 FHealth
:= PLAYER_HP_LIMIT
;
3509 if FArmor
< PLAYER_AP_LIMIT
then
3510 FArmor
:= PLAYER_AP_LIMIT
;
3513 if gFlash
= 2 then Inc(FPickup
, 5);
3517 if (not FWeapon
[WEAPON_SAW
]) or ((not respawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3519 FWeapon
[WEAPON_SAW
] := True;
3521 if gFlash
= 2 then Inc(FPickup
, 5);
3522 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3525 ITEM_WEAPON_SHOTGUN1
:
3526 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3528 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3529 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3531 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3532 FWeapon
[WEAPON_SHOTGUN1
] := True;
3534 if gFlash
= 2 then Inc(FPickup
, 5);
3535 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3538 ITEM_WEAPON_SHOTGUN2
:
3539 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3541 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3543 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3544 FWeapon
[WEAPON_SHOTGUN2
] := True;
3546 if gFlash
= 2 then Inc(FPickup
, 5);
3547 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3550 ITEM_WEAPON_CHAINGUN
:
3551 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3553 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3555 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3556 FWeapon
[WEAPON_CHAINGUN
] := True;
3558 if gFlash
= 2 then Inc(FPickup
, 5);
3559 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3562 ITEM_WEAPON_ROCKETLAUNCHER
:
3563 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3565 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3567 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3568 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3570 if gFlash
= 2 then Inc(FPickup
, 5);
3571 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3575 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3577 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3579 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3580 FWeapon
[WEAPON_PLASMA
] := True;
3582 if gFlash
= 2 then Inc(FPickup
, 5);
3583 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3587 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3589 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3591 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3592 FWeapon
[WEAPON_BFG
] := True;
3594 if gFlash
= 2 then Inc(FPickup
, 5);
3595 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3598 ITEM_WEAPON_SUPERPULEMET
:
3599 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3601 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3603 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3604 FWeapon
[WEAPON_SUPERPULEMET
] := True;
3606 if gFlash
= 2 then Inc(FPickup
, 5);
3607 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3611 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3613 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3616 if gFlash
= 2 then Inc(FPickup
, 5);
3619 ITEM_AMMO_BULLETS_BOX
:
3620 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3622 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3625 if gFlash
= 2 then Inc(FPickup
, 5);
3629 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3631 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3634 if gFlash
= 2 then Inc(FPickup
, 5);
3637 ITEM_AMMO_SHELLS_BOX
:
3638 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3640 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
3643 if gFlash
= 2 then Inc(FPickup
, 5);
3647 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3649 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3652 if gFlash
= 2 then Inc(FPickup
, 5);
3655 ITEM_AMMO_ROCKET_BOX
:
3656 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3658 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
3661 if gFlash
= 2 then Inc(FPickup
, 5);
3665 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3667 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3670 if gFlash
= 2 then Inc(FPickup
, 5);
3674 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3676 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
3679 if gFlash
= 2 then Inc(FPickup
, 5);
3683 if not(R_ITEM_BACKPACK
in FRulez
) or
3684 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
3685 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
3686 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
3687 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) then
3689 FMaxAmmo
[A_BULLETS
] := 400;
3690 FMaxAmmo
[A_SHELLS
] := 100;
3691 FMaxAmmo
[A_ROCKETS
] := 100;
3692 FMaxAmmo
[A_CELLS
] := 600;
3694 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3695 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3696 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3697 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3698 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3699 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3700 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3701 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3703 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
3706 if gFlash
= 2 then Inc(FPickup
, 5);
3710 if not(R_KEY_RED
in FRulez
) then
3712 Include(FRulez
, R_KEY_RED
);
3714 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3715 if gFlash
= 2 then Inc(FPickup
, 5);
3716 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3720 if not(R_KEY_GREEN
in FRulez
) then
3722 Include(FRulez
, R_KEY_GREEN
);
3724 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3725 if gFlash
= 2 then Inc(FPickup
, 5);
3726 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3730 if not(R_KEY_BLUE
in FRulez
) then
3732 Include(FRulez
, R_KEY_BLUE
);
3734 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3735 if gFlash
= 2 then Inc(FPickup
, 5);
3736 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3740 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
3742 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
3745 if gFlash
= 2 then Inc(FPickup
, 5);
3749 if FAir
< AIR_MAX
then
3754 if gFlash
= 2 then Inc(FPickup
, 5);
3759 if not (R_BERSERK
in FRulez
) then
3761 Include(FRulez
, R_BERSERK
);
3762 if FBFGFireCounter
= -1 then
3764 FCurrWeap
:= WEAPON_KASTET
;
3766 FModel
.SetWeapon(WEAPON_KASTET
);
3770 if gFlash
= 2 then Inc(FPickup
, 5);
3771 FBerserk
:= gTime
+30000;
3775 if FHealth
< PLAYER_HP_SOFT
then
3777 FHealth
:= PLAYER_HP_SOFT
;
3778 FBerserk
:= gTime
+30000;
3785 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
3787 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
3790 if gFlash
= 2 then Inc(FPickup
, 5);
3794 if FHealth
< PLAYER_HP_LIMIT
then
3796 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
3799 if gFlash
= 2 then Inc(FPickup
, 5);
3803 if FArmor
< PLAYER_AP_LIMIT
then
3805 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
3808 if gFlash
= 2 then Inc(FPickup
, 5);
3812 if FJetFuel
< JET_MAX
then
3814 FJetFuel
:= JET_MAX
;
3817 if gFlash
= 2 then Inc(FPickup
, 5);
3821 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
3823 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
3826 if gFlash
= 2 then Inc(FPickup
, 5);
3831 procedure TPlayer
.Touch();
3835 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
3838 // Áðîñèòü ôëàã òîâàðèùó:
3839 if gGameSettings
.GameMode
= GM_CTF
then
3844 procedure TPlayer
.Push(vx
, vy
: Integer);
3846 if (not FPhysics
) and FGhost
then
3848 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
3849 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
3850 if g_Game_IsNet
and g_Game_IsServer
then
3851 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
3854 procedure TPlayer
.Reset(Force
: Boolean);
3860 FTime
[T_RESPAWN
] := 0;
3861 FTime
[T_FLAGCAP
] := 0;
3874 FSpectator
:= False;
3877 FSpectatePlayer
:= -1;
3878 FNoRespawn
:= False;
3880 FLives
:= gGameSettings
.MaxLives
;
3885 procedure TPlayer
.SoftReset();
3891 FBFGFireCounter
:= -1;
3899 SetAction(A_STAND
, True);
3902 function TPlayer
.GetRespawnPoint(): Byte;
3907 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
3909 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
3910 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
3912 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
3914 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
3915 if Self
= gPlayer1
then
3916 c
:= RESPAWNPOINT_PLAYER1
3918 c
:= RESPAWNPOINT_PLAYER2
;
3919 if g_Map_GetPointCount(c
) > 0 then
3925 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
3926 if Self
= gPlayer1
then
3927 c
:= RESPAWNPOINT_PLAYER2
3929 c
:= RESPAWNPOINT_PLAYER1
;
3930 if g_Map_GetPointCount(c
) > 0 then
3937 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
3938 if Random(2) = 0 then
3939 c
:= RESPAWNPOINT_PLAYER1
3941 c
:= RESPAWNPOINT_PLAYER2
;
3942 if g_Map_GetPointCount(c
) > 0 then
3949 // Òî÷êà ëþáîé èç êîìàíä
3950 if Random(2) = 0 then
3951 c
:= RESPAWNPOINT_RED
3953 c
:= RESPAWNPOINT_BLUE
;
3954 if g_Map_GetPointCount(c
) > 0 then
3961 c
:= RESPAWNPOINT_DM
;
3962 if g_Map_GetPointCount(c
) > 0 then
3970 if gGameSettings
.GameMode
= GM_DM
then
3973 c
:= RESPAWNPOINT_DM
;
3974 if g_Map_GetPointCount(c
) > 0 then
3980 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
3981 if Random(2) = 0 then
3982 c
:= RESPAWNPOINT_PLAYER1
3984 c
:= RESPAWNPOINT_PLAYER2
;
3985 if g_Map_GetPointCount(c
) > 0 then
3991 // Òî÷êà ëþáîé èç êîìàíä
3992 if Random(2) = 0 then
3993 c
:= RESPAWNPOINT_RED
3995 c
:= RESPAWNPOINT_BLUE
;
3996 if g_Map_GetPointCount(c
) > 0 then
4004 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4006 // Òî÷êà ñâîåé êîìàíäû
4007 c
:= RESPAWNPOINT_DM
;
4008 if FTeam
= TEAM_RED
then
4009 c
:= RESPAWNPOINT_RED
;
4010 if FTeam
= TEAM_BLUE
then
4011 c
:= RESPAWNPOINT_BLUE
;
4012 if g_Map_GetPointCount(c
) > 0 then
4019 c
:= RESPAWNPOINT_DM
;
4020 if g_Map_GetPointCount(c
) > 0 then
4026 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4027 if Random(2) = 0 then
4028 c
:= RESPAWNPOINT_PLAYER1
4030 c
:= RESPAWNPOINT_PLAYER2
;
4031 if g_Map_GetPointCount(c
) > 0 then
4037 // Òî÷êà äðóãîé êîìàíäû
4038 c
:= RESPAWNPOINT_DM
;
4039 if FTeam
= TEAM_RED
then
4040 c
:= RESPAWNPOINT_BLUE
;
4041 if FTeam
= TEAM_BLUE
then
4042 c
:= RESPAWNPOINT_RED
;
4043 if g_Map_GetPointCount(c
) > 0 then
4051 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4053 RespawnPoint
: TRespawnPoint
;
4058 if not g_Game_IsServer
then
4062 FWantsInGame
:= True;
4063 FJustTeleported
:= True;
4066 FTime
[T_RESPAWN
] := 0;
4070 // if server changes MaxLives we gotta be ready
4071 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4073 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4074 if FTime
[T_RESPAWN
] > gTime
then
4077 // Ïðîñðàë âñå æèçíè:
4080 if not FSpectator
then Spectate(True);
4081 FWantsInGame
:= True;
4085 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4086 begin // "Ñâîÿ èãðà"
4087 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4088 FRulez
:= FRulez
-[R_BERSERK
];
4090 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4092 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4093 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4096 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4097 c
:= GetRespawnPoint();
4102 // Âîñêðåøåíèå áåç îðóæèÿ:
4105 FHealth
:= PLAYER_HP_SOFT
;
4111 for a
:= WP_FIRST
to WP_LAST
do
4113 FWeapon
[a
] := False;
4117 FWeapon
[WEAPON_PISTOL
] := True;
4118 FWeapon
[WEAPON_KASTET
] := True;
4119 FCurrWeap
:= WEAPON_PISTOL
;
4122 FModel
.SetWeapon(FCurrWeap
);
4124 for b
:= A_BULLETS
to A_HIGH
do
4127 FAmmo
[A_BULLETS
] := 50;
4129 FMaxAmmo
[A_BULLETS
] := 200;
4130 FMaxAmmo
[A_SHELLS
] := 50;
4131 FMaxAmmo
[A_ROCKETS
] := 50;
4132 FMaxAmmo
[A_CELLS
] := 300;
4134 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4135 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4140 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4141 if not g_Map_GetPoint(c
, RespawnPoint
) then
4143 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4147 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4148 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4149 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4155 FDirection
:= RespawnPoint
.Direction
;
4156 if FDirection
= D_LEFT
then
4162 FBFGFireCounter
:= -1;
4167 SetAction(A_STAND
, True);
4168 FModel
.Direction
:= FDirection
;
4170 for a
:= Low(FTime
) to High(FTime
) do
4173 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4178 FCanJetpack
:= False;
4180 // Àíèìàöèÿ âîçðîæäåíèÿ:
4181 if (not gLoadGameMode
) and (not Silent
) then
4182 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4184 Anim
:= TAnimation
.Create(ID
, False, 3);
4185 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4186 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4190 FSpectator
:= False;
4193 FSpectatePlayer
:= -1;
4196 if g_Game_IsNet
then
4198 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4199 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4201 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4202 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4207 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4210 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4211 else if (not NoMove
) then
4213 GameX
:= gMapInfo
.Width
div 2;
4214 GameY
:= gMapInfo
.Height
div 2;
4223 FWantsInGame
:= False;
4228 if Self
= gPlayer1
then
4233 if Self
= gPlayer2
then
4240 if g_Game_IsNet
then
4241 MH_SEND_PlayerStats(FUID
);
4244 procedure TPlayer
.SwitchNoClip
;
4248 FGhost
:= not FGhost
;
4249 FPhysics
:= not FGhost
;
4261 procedure TPlayer
.Run(Direction
: TDirection
);
4265 if MAX_RUNVEL
> 8 then
4269 if Direction
= D_LEFT
then
4271 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4272 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4275 if FObj
.Vel
.X
< MAX_RUNVEL
then
4276 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4278 // Âîçìîæíî, ïèíàåì êóñêè:
4279 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4281 b
:= Abs(FObj
.Vel
.X
);
4282 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4283 for a
:= 0 to High(gGibs
) do
4284 if gGibs
[a
].Live
and
4285 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4286 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4288 if FObj
.Vel
.X
< 0 then
4289 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4291 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4297 procedure TPlayer
.SeeDown();
4299 SetAction(A_SEEDOWN
);
4301 if FDirection
= D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4303 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4306 procedure TPlayer
.SeeUp();
4310 if FDirection
= D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4312 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4315 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4323 A_ATTACK
: Prior
:= 2;
4324 A_SEEUP
: Prior
:= 1;
4325 A_SEEDOWN
: Prior
:= 1;
4326 A_ATTACKUP
: Prior
:= 2;
4327 A_ATTACKDOWN
: Prior
:= 2;
4332 if (Prior
> FActionPrior
) or Force
then
4333 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4335 FActionPrior
:= Prior
;
4336 FActionAnim
:= Action
;
4337 FActionForce
:= Force
;
4338 FActionChanged
:= True;
4341 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4344 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4346 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4347 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4348 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4349 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4352 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4359 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4361 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4362 if g_Game_IsServer
and g_Game_IsNet
then
4363 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4367 FJustTeleported
:= True;
4372 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4374 Anim
:= TAnimation
.Create(ID
, False, 3);
4377 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
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
);
4380 if g_Game_IsServer
and g_Game_IsNet
then
4381 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4382 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4386 FObj
.X
:= X
-PLAYER_RECT
.X
;
4387 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4388 if FLive
and FGhost
then
4394 if not g_Game_IsNet
then
4398 SetDirection(D_LEFT
);
4404 SetDirection(D_RIGHT
);
4410 if FDirection
= D_RIGHT
then
4412 SetDirection(D_LEFT
);
4417 SetDirection(D_RIGHT
);
4423 if not silent
and (Anim
<> nil) then
4425 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4426 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4429 if g_Game_IsServer
and g_Game_IsNet
then
4430 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4431 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4438 function nonz(a
: Single): Single;
4446 procedure TPlayer
.Update();
4449 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4450 blockmon
, headwater
, dospawn
: Boolean;
4455 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4456 AnyServer
:= g_Game_IsServer
;
4458 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4459 DoLerp(NetInterpLevel
+ 1)
4465 if FClientID
>= 0 then
4467 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4468 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4469 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4478 if FLive
and (gFly
or FJetpack
) then
4481 if FDirection
= D_LEFT
then
4486 if FLive
and (not FGhost
) then
4488 if FKeys
[KEY_UP
].Pressed
then
4490 if FKeys
[KEY_DOWN
].Pressed
then
4494 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4497 i
:= g_basic
.Sign(FIncCam
);
4498 FIncCam
:= Abs(FIncCam
);
4499 DecMin(FIncCam
, 5, 0);
4500 FIncCam
:= FIncCam
*i
;
4503 // no need to do that each second frame, weapon queue will take care of it
4504 if FLive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4505 if FLive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4507 if gTime
mod (GAME_TICK
*2) <> 0 then
4509 if (FObj
.Vel
.X
= 0) and FLive
then
4511 if FKeys
[KEY_LEFT
].Pressed
then
4513 if FKeys
[KEY_RIGHT
].Pressed
then
4518 g_Obj_Move(@FObj
, True, True, True);
4523 FActionChanged
:= False;
4527 // Let alive player do some actions
4528 if FKeys
[KEY_LEFT
].Pressed
then Run(D_LEFT
);
4529 if FKeys
[KEY_RIGHT
].Pressed
then Run(D_RIGHT
);
4530 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
4531 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
4532 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
4533 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
4534 if FKeys
[KEY_JUMP
].Pressed
then Jump()
4537 if AnyServer
and FJetpack
then
4541 if NetServer
then MH_SEND_PlayerStats(FUID
);
4543 FCanJetpack
:= True;
4550 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
4552 if FKeys
[k
].Pressed
then
4560 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4563 if (FTime
[T_RESPAWN
] <= gTime
) and
4564 gGameOn
and (not FLive
) then
4566 if (g_Player_GetCount() > 1) then
4570 gExit
:= EXIT_RESTART
;
4575 // Dead spectator actions
4578 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
4579 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
4583 if (FSpectatePlayer
>= High(gPlayers
)) then
4584 FSpectatePlayer
:= -1
4588 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
4589 if gPlayers
[I
] <> nil then
4590 if gPlayers
[I
].Live
then
4591 if gPlayers
[I
].UID
<> FUID
then
4593 FSpectatePlayer
:= I
;
4598 if not SetSpect
then FSpectatePlayer
:= -1;
4609 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
4611 FYTo
:= FObj
.Y
- 32;
4612 FSpectatePlayer
:= -1;
4614 if FKeys
[KEY_DOWN
].Pressed
then
4616 FYTo
:= FObj
.Y
+ 32;
4617 FSpectatePlayer
:= -1;
4619 if FKeys
[KEY_LEFT
].Pressed
then
4621 FXTo
:= FObj
.X
- 32;
4622 FSpectatePlayer
:= -1;
4624 if FKeys
[KEY_RIGHT
].Pressed
then
4626 FXTo
:= FObj
.X
+ 32;
4627 FSpectatePlayer
:= -1;
4630 if (FXTo
< -64) then
4632 else if (FXTo
> gMapInfo
.Width
+ 32) then
4633 FXTo
:= gMapInfo
.Width
+ 32;
4634 if (FYTo
< -72) then
4636 else if (FYTo
> gMapInfo
.Height
+ 32) then
4637 FYTo
:= gMapInfo
.Height
+ 32;
4641 g_Obj_Move(@FObj
, True, True, True)
4647 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
4648 if gPlayers
[FSpectatePlayer
] <> nil then
4649 if gPlayers
[FSpectatePlayer
].Live
then
4651 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
4652 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
4656 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
4657 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
4658 PANEL_BLOCKMON
, True);
4659 headwater
:= HeadInLiquid(0, 0);
4661 // Ñîïðîòèâëåíèå âîçäóõà:
4662 if (not FLive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
4663 if FObj
.Vel
.X
<> 0 then
4664 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
4666 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
4667 DecMin(FPain
, 5, 0);
4668 DecMin(FPickup
, 1, 0);
4670 if FLive
and (FObj
.Y
> gMapInfo
.Height
+128) and AnyServer
then
4672 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
4673 FMegaRulez
[MR_SUIT
] := 0;
4674 FMegaRulez
[MR_INVUL
] := 0;
4675 FMegaRulez
[MR_INVIS
] := 0;
4676 Kill(K_FALLKILL
, 0, HIT_FALL
);
4683 if FCurrWeap
= WEAPON_SAW
then
4684 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
4685 FSawSoundSelect
.IsPlaying()) then
4686 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
4689 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
4690 (not FJetSoundOff
.IsPlaying()) then
4692 FJetSoundFly
.SetPosition(0);
4693 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
4696 for b
:= WP_FIRST
to WP_LAST
do
4697 if FReloading
[b
] > 0 then
4703 if FShellTimer
> -1 then
4704 if FShellTimer
= 0 then
4706 if FShellType
= SHELL_SHELL
then
4707 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4708 GameVelX
, GameVelY
-2, SHELL_SHELL
)
4709 else if FShellType
= SHELL_DBLSHELL
then
4711 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4712 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
4713 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4714 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
4717 end else Dec(FShellTimer
);
4719 if (FBFGFireCounter
> -1) then
4720 if FBFGFireCounter
= 0 then
4724 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
4725 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
4726 xd
:= wx
+IfThen(FDirection
= D_LEFT
, -30, 30);
4727 yd
:= wy
+firediry();
4728 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
4729 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
4730 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
4731 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
4732 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
4735 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
4736 FBFGFireCounter
:= -1;
4739 FBFGFireCounter
:= 0
4741 Dec(FBFGFireCounter
);
4743 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
4745 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
4747 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
4750 if (headwater
or blockmon
) then
4756 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
4759 else if (FAir
mod 31 = 0) and not blockmon
then
4761 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
4762 if Random(2) = 0 then
4763 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
4765 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
4767 end else if FAir
< AIR_DEF
then
4770 if FDamageBuffer
> 0 then
4772 if FDamageBuffer
>= 9 then
4776 if FDamageBuffer
< 30 then i
:= 9
4777 else if FDamageBuffer
< 100 then i
:= 18
4781 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
4782 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
4783 FHealth
:= FHealth
-ii
;
4786 FHealth
:= FHealth
+FArmor
;
4791 if FHealth
<= 0 then
4792 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
4793 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
4794 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
4798 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
4799 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
4800 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
4801 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
4808 end; // if FLive then ...
4810 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
4812 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
4813 FModel
.GetCurrentAnimation
.MinLength
:= i
;
4814 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
4815 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
4817 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
4818 then SetAction(A_STAND
, True);
4820 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
4822 for b
:= Low(FKeys
) to High(FKeys
) do
4823 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
4826 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
4828 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
4829 FObj
.Y
+PLAYER_RECT
.Y
,
4836 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
4838 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
4839 FObj
.Y
+PLAYER_RECT
.Y
,
4843 Panel
.Width
, Panel
.Height
);
4846 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
4848 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
4849 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
4850 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
4851 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
4854 function g_Player_ValidName(Name
: string): Boolean;
4860 if gPlayers
= nil then Exit
;
4862 for a
:= 0 to High(gPlayers
) do
4863 if gPlayers
[a
] <> nil then
4864 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
4871 procedure TPlayer
.SetDirection(Direction
: TDirection
);
4875 d
:= FModel
.Direction
;
4877 FModel
.Direction
:= Direction
;
4878 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
4880 FDirection
:= Direction
;
4883 function TPlayer
.GetKeys(): Byte;
4887 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
4888 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
4889 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
4891 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
4892 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
4895 procedure TPlayer
.Use();
4899 if FTime
[T_USE
] > gTime
then Exit
;
4901 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
4902 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
4904 for a
:= 0 to High(gPlayers
) do
4905 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
4906 gPlayers
[a
].Live
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
4907 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
4908 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
4910 gPlayers
[a
].Touch();
4911 if g_Game_IsNet
and g_Game_IsServer
then
4912 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
4915 FTime
[T_USE
] := gTime
+120;
4918 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
4922 WX
, WY
, XD
, YD
: Integer;
4933 if R_BERSERK
in FRulez
then
4935 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
4936 obj
.X
:= FObj
.X
+FObj
.Rect
.X
;
4937 obj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
4940 obj
.rect
.Width
:= 39;
4941 obj
.rect
.Height
:= 52;
4942 obj
.Vel
.X
:= (xd
-wx
) div 2;
4943 obj
.Vel
.Y
:= (yd
-wy
) div 2;
4944 obj
.Accel
.X
:= xd
-wx
;
4945 obj
.Accel
.y
:= yd
-wy
;
4947 if g_Weapon_Hit(@obj
, 50, FUID
, HIT_SOME
) <> 0 then
4948 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
4950 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
4954 FPain
:= min(FPain
+ 25, 50);
4956 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
4961 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
4962 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
4964 FSawSoundSelect
.Stop();
4966 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
4968 else if not FSawSoundHit
.IsPlaying() then
4970 FSawSoundSelect
.Stop();
4971 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
4978 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
4979 FFireAngle
:= FAngle
;
4981 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4982 GameVelX
, GameVelY
-2, SHELL_BULLET
);
4987 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
4988 FFireAngle
:= FAngle
;
4991 FShellType
:= SHELL_SHELL
;
4996 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
4997 FFireAngle
:= FAngle
;
5000 FShellType
:= SHELL_DBLSHELL
;
5005 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5006 FFireAngle
:= FAngle
;
5008 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5009 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5012 WEAPON_ROCKETLAUNCHER
:
5014 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5015 FFireAngle
:= FAngle
;
5021 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5022 FFireAngle
:= FAngle
;
5028 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5029 FFireAngle
:= FAngle
;
5033 WEAPON_SUPERPULEMET
:
5035 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5036 FFireAngle
:= FAngle
;
5038 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5039 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5045 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5046 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5047 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5050 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5052 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5053 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5056 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5060 if NetInterpLevel
< 1 then
5070 AX
:= Abs(FXTo
- FObj
.X
);
5071 AY
:= Abs(FYTo
- FObj
.Y
);
5072 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5074 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5079 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5081 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5082 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5083 PANEL_LIFTUP
, False) then Result
:= -1
5085 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5086 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5087 PANEL_LIFTDOWN
, False) then Result
:= 1
5091 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5098 if Flag
= FLAG_NONE
then
5101 if not g_Game_IsServer
then Exit
;
5103 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5104 if (Flag
= FTeam
) and
5105 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5106 (FFlag
<> FLAG_NONE
) then
5108 if FFlag
= FLAG_RED
then
5109 s
:= _lc
[I_PLAYER_FLAG_RED
]
5111 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5113 evtype
:= FLAG_STATE_SCORED
;
5115 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5116 Insert('.', ts
, Length(ts
) + 1 - 3);
5117 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5119 g_Map_ResetFlag(FFlag
);
5120 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5122 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5125 if g_Game_IsNet
then
5127 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5131 gFlags
[FFlag
].CaptureTime
:= 0;
5136 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5137 if (Flag
= FTeam
) and
5138 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5140 if Flag
= FLAG_RED
then
5141 s
:= _lc
[I_PLAYER_FLAG_RED
]
5143 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5145 evtype
:= FLAG_STATE_RETURNED
;
5146 gFlags
[Flag
].CaptureTime
:= 0;
5148 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5150 g_Map_ResetFlag(Flag
);
5151 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5154 if g_Game_IsNet
then
5156 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5162 // Ïîäîáðàë ÷óæîé ôëàã:
5163 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5167 if Flag
= FLAG_RED
then
5168 s
:= _lc
[I_PLAYER_FLAG_RED
]
5170 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5172 evtype
:= FLAG_STATE_CAPTURED
;
5174 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5176 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5178 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5181 if g_Game_IsNet
then
5183 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5189 procedure TPlayer
.SetFlag(Flag
: Byte);
5192 if FModel
<> nil then
5193 FModel
.SetFlag(FFlag
);
5196 function TPlayer
.DropFlag(): Boolean;
5201 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5203 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5204 with gFlags
[FFlag
] do
5208 Direction
:= FDirection
;
5209 State
:= FLAG_STATE_DROPPED
;
5211 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5212 (FObj
.Vel
.Y
div 2)-2+Random(5));
5214 if FFlag
= FLAG_RED
then
5215 s
:= _lc
[I_PLAYER_FLAG_RED
]
5217 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5219 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5220 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5222 if g_Game_IsNet
then
5223 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5229 procedure TPlayer
.GetSecret();
5234 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5236 Assert(Key
<= High(FKeys
));
5238 FKeys
[Key
].Pressed
:= True;
5239 FKeys
[Key
].Time
:= Time
;
5242 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5244 Result
:= FKeys
[K
].Pressed
;
5247 procedure TPlayer
.ReleaseKeys();
5251 for a
:= Low(FKeys
) to High(FKeys
) do
5253 FKeys
[a
].Pressed
:= False;
5258 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5262 function TPlayer
.firediry(): Integer;
5264 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5265 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5269 procedure TPlayer
.RememberState();
5273 FSavedState
.Health
:= FHealth
;
5274 FSavedState
.Armor
:= FArmor
;
5275 FSavedState
.Air
:= FAir
;
5276 FSavedState
.JetFuel
:= FJetFuel
;
5277 FSavedState
.CurrWeap
:= FCurrWeap
;
5278 FSavedState
.NextWeap
:= FNextWeap
;
5279 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5282 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5284 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5286 FSavedState
.Rulez
:= FRulez
;
5287 FSavedState
.WaitRecall
:= True;
5290 procedure TPlayer
.RecallState();
5294 if not FSavedState
.WaitRecall
then Exit
;
5296 FHealth
:= FSavedState
.Health
;
5297 FArmor
:= FSavedState
.Armor
;
5298 FAir
:= FSavedState
.Air
;
5299 FJetFuel
:= FSavedState
.JetFuel
;
5300 FCurrWeap
:= FSavedState
.CurrWeap
;
5301 FNextWeap
:= FSavedState
.NextWeap
;
5302 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5305 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5307 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5309 FRulez
:= FSavedState
.Rulez
;
5310 FSavedState
.WaitRecall
:= False;
5312 if gGameSettings
.GameType
= GT_SERVER
then
5313 MH_SEND_PlayerStats(FUID
);
5316 procedure TPlayer
.SaveState(var Mem
: TBinMemoryWriter
);
5328 Mem
:= TBinMemoryWriter
.Create(i
);
5330 // Ñèãíàòóðà èãðîêà:
5331 sig
:= PLAYER_SIGNATURE
; // 'PLYR'
5332 Mem
.WriteDWORD(sig
);
5334 Mem
.WriteBoolean(FIamBot
);
5336 Mem
.WriteWord(FUID
);
5338 Mem
.WriteString(FName
, 32);
5340 Mem
.WriteByte(FTeam
);
5342 Mem
.WriteBoolean(FLive
);
5343 // Èçðàñõîäîâàë ëè âñå æèçíè:
5344 Mem
.WriteBoolean(FNoRespawn
);
5346 if FDirection
= D_LEFT
then
5352 Mem
.WriteInt(FHealth
);
5354 Mem
.WriteByte(FLives
);
5356 Mem
.WriteInt(FArmor
);
5360 Mem
.WriteInt(FJetFuel
);
5362 Mem
.WriteInt(FPain
);
5364 Mem
.WriteInt(FKills
);
5366 Mem
.WriteInt(FMonsterKills
);
5368 Mem
.WriteInt(FFrags
);
5370 Mem
.WriteByte(FFragCombo
);
5371 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5372 Mem
.WriteDWORD(FLastFrag
);
5374 Mem
.WriteInt(FDeath
);
5375 // Êàêîé ôëàã íåñåò:
5376 Mem
.WriteByte(FFlag
);
5378 Mem
.WriteInt(FSecrets
);
5380 Mem
.WriteByte(FCurrWeap
);
5382 Mem
.WriteWord(FNextWeap
);
5384 Mem
.WriteByte(FNextWeapDelay
);
5385 // Âðåìÿ çàðÿäêè BFG:
5386 Mem
.WriteSmallInt(FBFGFireCounter
);
5388 Mem
.WriteInt(FDamageBuffer
);
5389 // Ïîñëåäíèé óäàðèâøèé:
5390 Mem
.WriteWord(FLastSpawnerUID
);
5391 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5392 Mem
.WriteByte(FLastHit
);
5394 Obj_SaveState(@FObj
, Mem
);
5395 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5396 for i
:= A_BULLETS
to A_HIGH
do
5397 Mem
.WriteWord(FAmmo
[i
]);
5398 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5399 for i
:= A_BULLETS
to A_HIGH
do
5400 Mem
.WriteWord(FMaxAmmo
[i
]);
5402 for i
:= WP_FIRST
to WP_LAST
do
5403 Mem
.WriteBoolean(FWeapon
[i
]);
5404 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5405 for i
:= WP_FIRST
to WP_LAST
do
5406 Mem
.WriteWord(FReloading
[i
]);
5408 if R_ITEM_BACKPACK
in FRulez
then
5413 // Íàëè÷èå êðàñíîãî êëþ÷à:
5414 if R_KEY_RED
in FRulez
then
5419 // Íàëè÷èå çåëåíîãî êëþ÷à:
5420 if R_KEY_GREEN
in FRulez
then
5425 // Íàëè÷èå ñèíåãî êëþ÷à:
5426 if R_KEY_BLUE
in FRulez
then
5431 // Íàëè÷èå áåðñåðêà:
5432 if R_BERSERK
in FRulez
then
5437 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5438 for i
:= MR_SUIT
to MR_MAX
do
5439 Mem
.WriteDWORD(FMegaRulez
[i
]);
5440 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5441 for i
:= T_RESPAWN
to T_FLAGCAP
do
5442 Mem
.WriteDWORD(FTime
[i
]);
5445 Mem
.WriteString(str
);
5455 procedure TPlayer
.LoadState(var Mem
: TBinMemoryReader
);
5465 // Ñèãíàòóðà èãðîêà:
5467 if sig
<> PLAYER_SIGNATURE
then // 'PLYR'
5469 raise EBinSizeError
.Create('TPlayer.LoadState: Wrong Player Signature');
5472 Mem
.ReadBoolean(FIamBot
);
5476 Mem
.ReadString(str
);
5477 if (Self
<> gPlayer1
) and (Self
<> gPlayer2
) then
5480 Mem
.ReadByte(FTeam
);
5482 Mem
.ReadBoolean(FLive
);
5483 // Èçðàñõîäîâàë ëè âñå æèçíè:
5484 Mem
.ReadBoolean(FNoRespawn
);
5488 FDirection
:= D_LEFT
5490 FDirection
:= D_RIGHT
;
5492 Mem
.ReadInt(FHealth
);
5494 Mem
.ReadByte(FLives
);
5496 Mem
.ReadInt(FArmor
);
5500 Mem
.ReadInt(FJetFuel
);
5504 Mem
.ReadInt(FKills
);
5506 Mem
.ReadInt(FMonsterKills
);
5508 Mem
.ReadInt(FFrags
);
5510 Mem
.ReadByte(FFragCombo
);
5511 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5512 Mem
.ReadDWORD(FLastFrag
);
5514 Mem
.ReadInt(FDeath
);
5515 // Êàêîé ôëàã íåñåò:
5516 Mem
.ReadByte(FFlag
);
5518 Mem
.ReadInt(FSecrets
);
5520 Mem
.ReadByte(FCurrWeap
);
5522 Mem
.ReadWord(FNextWeap
);
5524 Mem
.ReadByte(FNextWeapDelay
);
5525 // Âðåìÿ çàðÿäêè BFG:
5526 Mem
.ReadSmallInt(FBFGFireCounter
);
5528 Mem
.ReadInt(FDamageBuffer
);
5529 // Ïîñëåäíèé óäàðèâøèé:
5530 Mem
.ReadWord(FLastSpawnerUID
);
5531 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5532 Mem
.ReadByte(FLastHit
);
5534 Obj_LoadState(@FObj
, Mem
);
5535 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5536 for i
:= A_BULLETS
to A_HIGH
do
5537 Mem
.ReadWord(FAmmo
[i
]);
5538 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5539 for i
:= A_BULLETS
to A_HIGH
do
5540 Mem
.ReadWord(FMaxAmmo
[i
]);
5542 for i
:= WP_FIRST
to WP_LAST
do
5543 Mem
.ReadBoolean(FWeapon
[i
]);
5544 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5545 for i
:= WP_FIRST
to WP_LAST
do
5546 Mem
.ReadWord(FReloading
[i
]);
5550 Include(FRulez
, R_ITEM_BACKPACK
);
5551 // Íàëè÷èå êðàñíîãî êëþ÷à:
5554 Include(FRulez
, R_KEY_RED
);
5555 // Íàëè÷èå çåëåíîãî êëþ÷à:
5558 Include(FRulez
, R_KEY_GREEN
);
5559 // Íàëè÷èå ñèíåãî êëþ÷à:
5562 Include(FRulez
, R_KEY_BLUE
);
5563 // Íàëè÷èå áåðñåðêà:
5566 Include(FRulez
, R_BERSERK
);
5567 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5568 for i
:= MR_SUIT
to MR_MAX
do
5569 Mem
.ReadDWORD(FMegaRulez
[i
]);
5570 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5571 for i
:= T_RESPAWN
to T_FLAGCAP
do
5572 Mem
.ReadDWORD(FTime
[i
]);
5574 Mem
.ReadString(str
);
5576 Mem
.ReadByte(FColor
.R
);
5577 Mem
.ReadByte(FColor
.G
);
5578 Mem
.ReadByte(FColor
.B
);
5579 if Self
= gPlayer1
then
5581 str
:= gPlayer1Settings
.Model
;
5582 FColor
:= gPlayer1Settings
.Color
;
5584 if Self
= gPlayer2
then
5586 str
:= gPlayer2Settings
.Model
;
5587 FColor
:= gPlayer2Settings
.Color
;
5589 // Îáíîâëÿåì ìîäåëü èãðîêà:
5591 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
5592 FModel
.Color
:= TEAMCOLOR
[FTeam
]
5594 FModel
.Color
:= FColor
;
5597 procedure TPlayer
.AllRulez(Health
: Boolean);
5603 FHealth
:= PLAYER_HP_LIMIT
;
5604 FArmor
:= PLAYER_AP_LIMIT
;
5608 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
5609 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
5610 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5613 procedure TPlayer
.RestoreHealthArmor();
5615 FHealth
:= PLAYER_HP_LIMIT
;
5616 FArmor
:= PLAYER_AP_LIMIT
;
5619 procedure TPlayer
.FragCombo();
5623 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
5625 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
5627 if FFragCombo
< 5 then
5629 Param
:= FUID
or (FFragCombo
shl 16);
5630 if (FComboEvnt
>= Low(gDelayedEvents
)) and
5631 (FComboEvnt
<= High(gDelayedEvents
)) and
5632 gDelayedEvents
[FComboEvnt
].Pending
and
5633 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
5634 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
5636 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
5637 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
5640 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
5648 procedure TPlayer
.GiveItem(ItemType
: Byte);
5652 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
5654 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
5658 if FAir
< AIR_MAX
then
5665 if not (R_BERSERK
in FRulez
) then
5667 Include(FRulez
, R_BERSERK
);
5668 if FBFGFireCounter
< 1 then
5670 FCurrWeap
:= WEAPON_KASTET
;
5672 FModel
.SetWeapon(WEAPON_KASTET
);
5676 FBerserk
:= gTime
+30000;
5678 if FHealth
< PLAYER_HP_SOFT
then
5680 FHealth
:= PLAYER_HP_SOFT
;
5681 FBerserk
:= gTime
+30000;
5686 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
5688 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
5692 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
5694 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
5698 if FJetFuel
< JET_MAX
then
5700 FJetFuel
:= JET_MAX
;
5703 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
5704 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
5706 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
5707 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5709 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
5711 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
5713 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
5714 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5717 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
5718 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
5719 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
5720 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
5721 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
5722 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
5723 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
5724 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
5726 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5727 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
5728 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5729 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
5730 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5731 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
5732 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5733 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
5736 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
5737 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
5738 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
5739 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) then
5741 FMaxAmmo
[A_BULLETS
] := 400;
5742 FMaxAmmo
[A_SHELLS
] := 100;
5743 FMaxAmmo
[A_ROCKETS
] := 100;
5744 FMaxAmmo
[A_CELLS
] := 600;
5746 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5747 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5748 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5749 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5751 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
5754 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
5755 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
5756 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
5758 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
5759 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
5764 if g_Game_IsNet
and g_Game_IsServer
then
5765 MH_SEND_PlayerStats(FUID
);
5768 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
5773 if (Random(5) = 1) and (Times
= 1) then
5776 if BodyInLiquid(0, 0) then
5778 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
5779 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
5780 if Random(2) = 0 then
5781 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5783 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5787 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
5789 for i
:= 1 to Times
do
5791 Anim
:= TAnimation
.Create(id
, False, 3);
5793 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
5794 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
5800 procedure TPlayer
.PauseSounds(Enable
: Boolean);
5802 FSawSound
.Pause(Enable
);
5803 FSawSoundIdle
.Pause(Enable
);
5804 FSawSoundHit
.Pause(Enable
);
5805 FSawSoundSelect
.Pause(Enable
);
5810 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
5815 FObj
.Rect
:= PLAYER_CORPSERECT
;
5816 FModelName
:= ModelName
;
5821 FState
:= CORPSE_STATE_MESS
;
5822 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
5826 FState
:= CORPSE_STATE_NORMAL
;
5827 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
5831 destructor TCorpse
.Destroy();
5838 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
5842 if FState
= CORPSE_STATE_REMOVEME
then
5845 FDamage
:= FDamage
+ Value
;
5847 if FDamage
> 150 then
5849 if FAnimation
<> nil then
5854 FState
:= CORPSE_STATE_REMOVEME
;
5856 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
5857 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
5858 FModelName
, FColor
);
5859 // Çâóê ìÿñà îò òðóïà:
5860 pm
:= g_PlayerModel_Get(FModelName
);
5861 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
5867 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
5868 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
5869 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
5870 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
5871 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
5876 procedure TCorpse
.Draw();
5878 if FState
= CORPSE_STATE_REMOVEME
then
5881 if FAnimation
<> nil then
5882 FAnimation
.Draw(FObj
.X
, FObj
.Y
, M_NONE
);
5884 if FAnimationMask
<> nil then
5887 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, M_NONE
);
5894 procedure TCorpse
.Update();
5898 if FState
= CORPSE_STATE_REMOVEME
then
5901 if gTime
mod (GAME_TICK
*2) <> 0 then
5903 g_Obj_Move(@FObj
, True, True, True);
5908 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
5909 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5911 st
:= g_Obj_Move(@FObj
, True, True, True);
5913 if WordBool(st
and MOVE_FALLOUT
) then
5915 FState
:= CORPSE_STATE_REMOVEME
;
5919 if FAnimation
<> nil then
5920 FAnimation
.Update();
5921 if FAnimationMask
<> nil then
5922 FAnimationMask
.Update();
5925 procedure TCorpse
.SaveState(var Mem
: TBinMemoryWriter
);
5934 sig
:= CORPSE_SIGNATURE
; // 'CORP'
5935 Mem
.WriteDWORD(sig
);
5937 Mem
.WriteByte(FState
);
5938 // Íàêîïëåííûé óðîí:
5939 Mem
.WriteByte(FDamage
);
5941 Mem
.WriteByte(FColor
.R
);
5942 Mem
.WriteByte(FColor
.G
);
5943 Mem
.WriteByte(FColor
.B
);
5945 Obj_SaveState(@FObj
, Mem
);
5946 // Åñòü ëè àíèìàöèÿ:
5947 anim
:= FAnimation
<> nil;
5948 Mem
.WriteBoolean(anim
);
5949 // Åñëè åñòü - ñîõðàíÿåì:
5951 FAnimation
.SaveState(Mem
);
5952 // Åñòü ëè ìàñêà àíèìàöèè:
5953 anim
:= FAnimationMask
<> nil;
5954 Mem
.WriteBoolean(anim
);
5955 // Åñëè åñòü - ñîõðàíÿåì:
5957 FAnimationMask
.SaveState(Mem
);
5960 procedure TCorpse
.LoadState(var Mem
: TBinMemoryReader
);
5970 if sig
<> CORPSE_SIGNATURE
then // 'CORP'
5972 raise EBinSizeError
.Create('TCorpse.LoadState: Wrong Corpse Signature');
5975 Mem
.ReadByte(FState
);
5976 // Íàêîïëåííûé óðîí:
5977 Mem
.ReadByte(FDamage
);
5979 Mem
.ReadByte(FColor
.R
);
5980 Mem
.ReadByte(FColor
.G
);
5981 Mem
.ReadByte(FColor
.B
);
5983 Obj_LoadState(@FObj
, Mem
);
5984 // Åñòü ëè àíèìàöèÿ:
5985 Mem
.ReadBoolean(anim
);
5986 // Åñëè åñòü - çàãðóæàåì:
5989 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
5990 FAnimation
.LoadState(Mem
);
5992 // Åñòü ëè ìàñêà àíèìàöèè:
5993 Mem
.ReadBoolean(anim
);
5994 // Åñëè åñòü - çàãðóæàåì:
5997 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
5998 FAnimationMask
.LoadState(Mem
);
6004 constructor TBot
.Create();
6011 FSpectator
:= False;
6018 for a
:= WP_FIRST
to WP_LAST
do
6020 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6021 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6022 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6026 destructor TBot
.Destroy();
6029 inherited Destroy();
6032 procedure TBot
.Draw();
6036 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6037 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6040 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6042 inherited Respawn(Silent
, Force
);
6045 FSelectedWeapon
:= FCurrWeap
;
6050 procedure TBot
.UpdateCombat();
6063 TTargetRecord
= array of TTarget
;
6065 function Compare(a
, b
: TTarget
): Integer;
6067 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6070 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6072 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6073 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6075 if a
.Dist
> b
.Dist
then // B áëèæå
6077 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6080 else // Ñòðàííî -> A
6085 a
, x1
, y1
, x2
, y2
: Integer;
6086 targets
: TTargetRecord
;
6088 Target
, BestTarget
: TTarget
;
6089 firew
, fireh
: Integer;
6093 vsPlayer
, vsMonster
, ok
: Boolean;
6095 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6096 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6098 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6099 if FCurrWeap
<> FSelectedWeapon
then
6102 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6103 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6105 RemoveAIFlag('NEEDFIRE');
6108 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6109 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_MEGAKASTET
: PressKey(KEY_FIRE
, 40);
6110 else PressKey(KEY_FIRE
);
6114 // Êîîðäèíàòû ñòâîëà:
6115 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6116 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6118 Target
.UID
:= FTargetUID
;
6121 if Target
.UID
<> 0 then
6122 begin // Öåëü åñòü - íàñòðàèâàåì
6123 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6126 with g_Player_Get(Target
.UID
) do
6128 if (@FObj
) <> nil then
6135 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6136 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6137 Target
.Rect
:= PLAYER_RECT
;
6138 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6139 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6140 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6141 Target
.IsPlayer
:= True;
6145 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6148 mon
:= g_Monsters_Get(Target
.UID
);
6151 Target
.X
:= mon
.Obj
.X
;
6152 Target
.Y
:= mon
.Obj
.Y
;
6154 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6155 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6156 Target
.Rect
:= mon
.Obj
.Rect
;
6157 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6158 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6159 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6160 Target
.IsPlayer
:= False;
6167 begin // Öåëè íåò - îáíóëÿåì
6172 Target
.Visible
:= False;
6173 Target
.Line
:= False;
6174 Target
.IsPlayer
:= False;
6179 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6180 if (not Target
.Line
) or (not Target
.Visible
) then
6184 for a
:= 0 to High(gPlayers
) do
6185 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].Live
) and
6186 (gPlayers
[a
].FUID
<> FUID
) and
6187 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6188 (not gPlayers
[a
].NoTarget
) and
6189 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6191 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6192 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6195 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6196 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6198 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6199 if g_TraceVector(x1
, y1
, x2
, y2
) then
6201 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6202 SetLength(targets
, Length(targets
)+1);
6203 with targets
[High(targets
)] do
6205 UID
:= gPlayers
[a
].FUID
;
6206 X
:= gPlayers
[a
].FObj
.X
;
6207 Y
:= gPlayers
[a
].FObj
.Y
;
6210 Rect
:= PLAYER_RECT
;
6211 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6212 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6213 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6221 if vsMonster
and (gMonsters
<> nil) then
6222 for a
:= 0 to High(gMonsters
) do
6223 if (gMonsters
[a
] <> nil) and (gMonsters
[a
].Live
) and
6224 (gMonsters
[a
].MonsterType
<> MONSTER_BARREL
) then
6226 mon
:= gMonsters
[a
];
6228 if not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
6229 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
) then
6232 x2
:= mon
.Obj
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6233 y2
:= mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6235 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6236 if g_TraceVector(x1
, y1
, x2
, y2
) then
6238 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6239 SetLength(targets
, Length(targets
)+1);
6240 with targets
[High(targets
)] do
6247 Rect
:= mon
.Obj
.Rect
;
6248 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6249 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6250 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6258 // Åñëè åñòü âîçìîæíûå öåëè:
6259 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6260 if targets
<> nil then
6262 // Âûáèðàåì íàèëó÷øóþ öåëü:
6263 BestTarget
:= targets
[0];
6264 if Length(targets
) > 1 then
6265 for a
:= 1 to High(targets
) do
6266 if Compare(BestTarget
, targets
[a
]) = 1 then
6267 BestTarget
:= targets
[a
];
6269 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6270 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6271 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6273 Target
:= BestTarget
;
6275 if (Healthy() = 3) or ((Healthy() = 2)) then
6276 begin // Åñëè çäîðîâû - äîãîíÿåì
6277 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6278 SetAIFlag('GORIGHT', '1');
6279 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6280 SetAIFlag('GOLEFT', '1');
6283 begin // Åñëè ïîáèòû - óáåãàåì
6284 if ((RunDirection() = D_LEFT
) and (Target
.X
< FObj
.X
)) then
6285 SetAIFlag('GORIGHT', '1');
6286 if ((RunDirection() = D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6287 SetAIFlag('GOLEFT', '1');
6290 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6291 SelectWeapon(Abs(x1
-Target
.cX
));
6296 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6297 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6298 if Target
.UID
<> 0 then
6300 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6301 Target
.Y
+ Target
.Rect
.Y
) then
6302 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6303 if (Healthy() = 3) or ((Healthy() = 2)) then
6304 begin // Åñëè çäîðîâû - äîãîíÿåì
6305 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6306 SetAIFlag('GORIGHT', '1');
6307 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6308 SetAIFlag('GOLEFT', '1');
6311 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6313 if ((RunDirection() = D_LEFT
) and (Target
.X
< FObj
.X
)) then
6314 SetAIFlag('GORIGHT', '1');
6315 if ((RunDirection() = D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6316 SetAIFlag('GOLEFT', '1');
6320 begin // Öåëü ïîêà íà "ýêðàíå"
6321 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6322 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6323 FLastVisible
:= gTime
;
6324 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6325 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6327 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6328 SetAIFlag('GORIGHT', '1');
6329 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6330 SetAIFlag('GOLEFT', '1');
6334 // Âûáèðàåì óãîë ââåðõ:
6335 if FDirection
= D_LEFT
then
6336 angle
:= ANGLE_LEFTUP
6338 angle
:= ANGLE_RIGHTUP
;
6340 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6341 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6343 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6344 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6345 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6346 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6347 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6348 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6349 begin // òî íóæíî ñòðåëÿòü ââåðõ
6350 SetAIFlag('NEEDFIRE', '1');
6351 SetAIFlag('NEEDSEEUP', '1');
6354 // Âûáèðàåì óãîë âíèç:
6355 if FDirection
= D_LEFT
then
6356 angle
:= ANGLE_LEFTDOWN
6358 angle
:= ANGLE_RIGHTDOWN
;
6360 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6361 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6363 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6364 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6365 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6366 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6367 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6368 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6369 begin // òî íóæíî ñòðåëÿòü âíèç
6370 SetAIFlag('NEEDFIRE', '1');
6371 SetAIFlag('NEEDSEEDOWN', '1');
6374 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6375 if Target
.Visible
and
6376 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6377 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6379 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6380 if ((FDirection
= D_LEFT
) and (Target
.X
< FObj
.X
)) or
6381 ((FDirection
= D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6382 begin // òî íóæíî ñòðåëÿòü âïåðåä
6383 SetAIFlag('NEEDFIRE', '1');
6384 SetAIFlag('NEEDSEEDOWN', '');
6385 SetAIFlag('NEEDSEEUP', '');
6387 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6388 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6389 if GetRnd(FDifficult
.CloseJump
) then
6390 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6391 if Abs(FObj
.X
-Target
.X
) < 128 then
6395 if Random(a
) = 0 then
6396 SetAIFlag('NEEDJUMP', '1');
6400 // Åñëè öåëü âñå åùå åñòü:
6401 if Target
.UID
<> 0 then
6402 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
6403 Target
.UID
:= 0 // òî çàáûòü öåëü
6404 else // Åñëè âèäåëè íåäàâíî
6405 begin // íî öåëü óáèëè
6406 if Target
.IsPlayer
then
6407 begin // Öåëü - èãðîê
6408 pla
:= g_Player_Get(Target
.UID
);
6409 if (pla
= nil) or (not pla
.Live
) or pla
.NoTarget
or
6410 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6411 Target
.UID
:= 0; // òî çàáûòü öåëü
6414 begin // Öåëü - ìîíñòð
6415 mon
:= g_Monsters_Get(Target
.UID
);
6416 if (mon
= nil) or (not mon
.Live
) then
6417 Target
.UID
:= 0; // òî çàáûòü öåëü
6420 end; // if Target.UID <> 0
6422 FTargetUID
:= Target
.UID
;
6424 // Åñëè âîçìîæíûõ öåëåé íåò:
6425 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
6426 if targets
= nil then
6427 if GetAIFlag('ATTACKLEFT') <> '' then
6428 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
6429 RemoveAIFlag('ATTACKLEFT');
6431 SetAIFlag('NEEDJUMP', '1');
6433 if RunDirection() = D_RIGHT
then
6434 begin // Èäåì íå â òó ñòîðîíó
6435 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6436 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
6437 SetAIFlag('NEEDFIRE', '1');
6438 SetAIFlag('GOLEFT', '1');
6442 begin // Èäåì â íóæíóþ ñòîðîíó
6443 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6444 SetAIFlag('NEEDFIRE', '1');
6445 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6446 SetAIFlag('GORIGHT', '1');
6450 if GetAIFlag('ATTACKRIGHT') <> '' then
6451 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
6452 RemoveAIFlag('ATTACKRIGHT');
6454 SetAIFlag('NEEDJUMP', '1');
6456 if RunDirection() = D_LEFT
then
6457 begin // Èäåì íå â òó ñòîðîíó
6458 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6459 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
6460 SetAIFlag('NEEDFIRE', '1');
6461 SetAIFlag('GORIGHT', '1');
6466 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6467 SetAIFlag('NEEDFIRE', '1');
6468 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6469 SetAIFlag('GOLEFT', '1');
6473 //HACK! (does it belongs there?)
6474 RealizeCurrentWeapon();
6476 // Åñëè åñòü âîçìîæíûå öåëè:
6477 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
6478 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6479 for a
:= 0 to High(targets
) do
6481 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
6482 if GetRnd(FDifficult
.DiagFire
) then
6484 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
6485 if FDirection
= D_LEFT
then
6486 angle
:= ANGLE_LEFTUP
6488 angle
:= ANGLE_RIGHTUP
;
6490 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6491 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6493 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6494 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6495 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6496 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6497 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6499 SetAIFlag('NEEDFIRE', '1');
6500 SetAIFlag('NEEDSEEUP', '1');
6503 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
6504 if FDirection
= D_LEFT
then
6505 angle
:= ANGLE_LEFTDOWN
6507 angle
:= ANGLE_RIGHTDOWN
;
6509 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6510 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6512 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6513 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6514 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6515 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6516 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6518 SetAIFlag('NEEDFIRE', '1');
6519 SetAIFlag('NEEDSEEDOWN', '1');
6523 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
6524 if targets
[a
].Line
and targets
[a
].Visible
and
6525 (((FDirection
= D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
6526 ((FDirection
= D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
6528 SetAIFlag('NEEDFIRE', '1');
6533 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
6534 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
6535 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
6536 40+GetInterval(FDifficult
.Cover
, 40)) then
6537 SetAIFlag('NEEDJUMP', '1');
6539 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
6540 ammo
:= GetAmmoByWeapon(FCurrWeap
);
6541 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
6542 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
6544 SetAIFlag('SELECTWEAPON', '1');
6546 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
6547 if GetAIFlag('SELECTWEAPON') = '1' then
6550 RemoveAIFlag('SELECTWEAPON');
6554 procedure TBot
.Update();
6567 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
6568 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
6570 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
6572 if g_debug_BotAIOff
= 3 then
6582 RealizeCurrentWeapon();
6589 procedure TBot
.ReleaseKey(Key
: Byte);
6598 function TBot
.KeyPressed(Key
: Word): Boolean;
6600 Result
:= FKeys
[Key
].Pressed
;
6603 function TBot
.GetAIFlag(fName
: String20
): String20
;
6609 fName
:= LowerCase(fName
);
6611 if FAIFlags
<> nil then
6612 for a
:= 0 to High(FAIFlags
) do
6613 if LowerCase(FAIFlags
[a
].Name
) = fName
then
6615 Result
:= FAIFlags
[a
].Value
;
6620 procedure TBot
.RemoveAIFlag(fName
: String20
);
6624 if FAIFlags
= nil then Exit
;
6626 fName
:= LowerCase(fName
);
6628 for a
:= 0 to High(FAIFlags
) do
6629 if LowerCase(FAIFlags
[a
].Name
) = fName
then
6631 if a
<> High(FAIFlags
) then
6632 for b
:= a
to High(FAIFlags
)-1 do
6633 FAIFlags
[b
] := FAIFlags
[b
+1];
6635 SetLength(FAIFlags
, Length(FAIFlags
)-1);
6640 procedure TBot
.SetAIFlag(fName
, fValue
: String20
);
6648 fName
:= LowerCase(fName
);
6650 if FAIFlags
<> nil then
6651 for a
:= 0 to High(FAIFlags
) do
6652 if LowerCase(FAIFlags
[a
].Name
) = fName
then
6658 if ok
then FAIFlags
[a
].Value
:= fValue
6661 SetLength(FAIFlags
, Length(FAIFlags
)+1);
6662 with FAIFlags
[High(FAIFlags
)] do
6670 procedure TBot
.UpdateMove
;
6672 procedure GoLeft(Time
: Word = 1);
6674 ReleaseKey(KEY_LEFT
);
6675 ReleaseKey(KEY_RIGHT
);
6676 PressKey(KEY_LEFT
, Time
);
6677 SetDirection(D_LEFT
);
6680 procedure GoRight(Time
: Word = 1);
6682 ReleaseKey(KEY_LEFT
);
6683 ReleaseKey(KEY_RIGHT
);
6684 PressKey(KEY_RIGHT
, Time
);
6685 SetDirection(D_RIGHT
);
6688 function Rnd(a
: Word): Boolean;
6690 Result
:= Random(a
) = 0;
6693 procedure Turn(Time
: Word = 1200);
6695 if RunDirection() = D_LEFT
then GoRight(Time
) else GoLeft(Time
);
6700 ReleaseKey(KEY_LEFT
);
6701 ReleaseKey(KEY_RIGHT
);
6704 function CanRunLeft(): Boolean;
6706 Result
:= not CollideLevel(-1, 0);
6709 function CanRunRight(): Boolean;
6711 Result
:= not CollideLevel(1, 0);
6714 function CanRun(): Boolean;
6716 if RunDirection() = D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
6719 procedure Jump(Time
: Word = 30);
6721 PressKey(KEY_JUMP
, Time
);
6724 function NearHole(): Boolean;
6728 { TODO 5 : Ëåñòíèöû }
6729 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6730 for x
:= 1 to PLAYER_RECT
.Width
do
6731 if (not StayOnStep(x
*sx
, 0)) and
6732 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6733 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6742 function BorderHole(): Boolean;
6746 { TODO 5 : Ëåñòíèöû }
6747 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6748 for x
:= 1 to PLAYER_RECT
.Width
do
6749 if (not StayOnStep(x
*sx
, 0)) and
6750 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6751 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6753 for xx
:= x
to x
+32 do
6754 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
6764 function NearDeepHole(): Boolean;
6770 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6773 for x
:= 1 to PLAYER_RECT
.Width
do
6774 if (not StayOnStep(x
*sx
, 0)) and
6775 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6776 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6778 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6780 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
6785 end else Result
:= False;
6788 function OverDeepHole(): Boolean;
6795 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6797 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
6804 function OnGround(): Boolean;
6806 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
6809 function OnLadder(): Boolean;
6811 Result
:= FullInStep(0, 0);
6814 function BelowLadder(): Boolean;
6816 Result
:= (FullInStep(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
6817 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
6818 (FullInStep(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
6819 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
6822 function BelowLiftUp(): Boolean;
6824 Result
:= ((FullInLift(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
6825 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
6826 ((FullInLift(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
6827 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
6830 function OnTopLift(): Boolean;
6832 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
6835 function CanJumpOver(): Boolean;
6839 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6843 if not CollideLevel(sx
, 0) then Exit
;
6845 for y
:= 1 to BOT_MAXJUMP
do
6846 if CollideLevel(0, -y
) then Exit
else
6847 if not CollideLevel(sx
, -y
) then
6854 function CanJumpUp(Dist
: ShortInt): Boolean;
6861 if CollideLevel(Dist
, 0) then Exit
;
6864 for y
:= 0 to BOT_MAXJUMP
do
6865 if CollideLevel(Dist
, -y
) then
6874 for yy
:= y
+1 to BOT_MAXJUMP
do
6875 if not CollideLevel(Dist
, -yy
) then
6884 for y
:= 0 to BOT_MAXJUMP
do
6885 if CollideLevel(0, -y
) then
6893 if y
< yy
then Exit
;
6898 function IsSafeTrigger(): Boolean;
6903 if gTriggers
= nil then
6905 for a
:= 0 to High(gTriggers
) do
6906 if Collide(gTriggers
[a
].X
,
6909 gTriggers
[a
].Height
) and
6910 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
6911 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
6912 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
6913 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
6914 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
6919 // Âîçìîæíî, íàæèìàåì êíîïêó:
6920 if Rnd(16) and IsSafeTrigger() then
6923 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
6924 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
6926 ReleaseKey(KEY_LEFT
);
6927 ReleaseKey(KEY_RIGHT
);
6931 // Èäåì âëåâî, åñëè íàäî áûëî:
6932 if GetAIFlag('GOLEFT') <> '' then
6934 RemoveAIFlag('GOLEFT');
6935 if CanRunLeft() then
6939 // Èäåì âïðàâî, åñëè íàäî áûëî:
6940 if GetAIFlag('GORIGHT') <> '' then
6942 RemoveAIFlag('GORIGHT');
6943 if CanRunRight() then
6947 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
6948 if FObj
.X
< -32 then
6951 if FObj
.X
+32 > gMapInfo
.Width
then
6954 // Ïðûãàåì, åñëè íàäî áûëî:
6955 if GetAIFlag('NEEDJUMP') <> '' then
6958 RemoveAIFlag('NEEDJUMP');
6961 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
6962 if GetAIFlag('NEEDSEEUP') <> '' then
6965 ReleaseKey(KEY_DOWN
);
6966 PressKey(KEY_UP
, 20);
6967 RemoveAIFlag('NEEDSEEUP');
6970 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
6971 if GetAIFlag('NEEDSEEDOWN') <> '' then
6974 ReleaseKey(KEY_DOWN
);
6975 PressKey(KEY_DOWN
, 20);
6976 RemoveAIFlag('NEEDSEEDOWN');
6979 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
6980 if GetAIFlag('GOINHOLE') <> '' then
6981 if not OnGround() then
6983 ReleaseKey(KEY_LEFT
);
6984 ReleaseKey(KEY_RIGHT
);
6985 RemoveAIFlag('GOINHOLE');
6986 SetAIFlag('FALLINHOLE', '1');
6989 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
6990 if GetAIFlag('FALLINHOLE') <> '' then
6992 RemoveAIFlag('FALLINHOLE');
6994 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
6995 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
6996 if GetAIFlag('FALLINHOLE') = '' then
6997 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7003 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7005 CanJumpUp(IfThen(RunDirection() = D_LEFT
, -1, 1)*32) and
7009 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7010 if OnGround() and NearHole() then
7011 if NearDeepHole() then // Åñëè ýòî áåçäíà
7013 0..3: Turn(); // Áåæèì îáðàòíî
7014 4: Jump(); // Ïðûãàåì
7015 5: begin // Ïðûãàåì îáðàòíî
7020 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7021 if GetAIFlag('GOINHOLE') = '' then
7023 0: Turn(); // Íå íóæíî òóäà
7024 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7025 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7026 if BorderHole() then
7027 SetAIFlag('GOINHOLE', '1');
7030 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7031 if (not CanRun()) and OnGround() then
7033 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7034 if CanJumpOver() or OnLadder() then
7036 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7037 if Random(2) = 0 then
7039 if IsSafeTrigger() then
7045 // Îñòàëîñü ìàëî âîçäóõà:
7046 if FAir
< 36 * 2 then
7049 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7050 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7051 if BodyInAcid(0, 0) then
7055 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7057 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7058 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7061 {function TBot.NeedItem(Item: Byte): Byte;
7066 procedure TBot
.SelectWeapon(Dist
: Integer);
7070 function HaveAmmo(weapon
: Byte): Boolean;
7073 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7074 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7075 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7076 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7077 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7078 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7079 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7080 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7081 else Result
:= True;
7086 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7088 if Dist
> BOT_LONGDIST
then
7089 begin // Äàëüíèé áîé
7091 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7093 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7097 else //if Dist > BOT_UNSAFEDIST then
7098 begin // Áëèæíèé áîé
7100 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7102 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7109 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7111 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7117 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7119 Result
:= inherited PickItem(ItemType
, force
, remove
);
7121 if Result
then SetAIFlag('SELECTWEAPON', '1');
7124 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7126 Result
:= inherited Heal(value
, Soft
);
7129 function TBot
.Healthy(): Byte;
7131 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7132 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7133 else if (FHealth
> 50) then Result
:= 2
7134 else if (FHealth
> 20) then Result
:= 1
7138 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7140 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7141 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7144 procedure TBot
.OnDamage(Angle
: SmallInt);
7152 if (Angle
= 0) or (Angle
= 180) then
7155 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7156 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7158 pla
:= g_Player_Get(FLastSpawnerUID
);
7159 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7160 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7163 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7164 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7166 mon
:= g_Monsters_Get(FLastSpawnerUID
);
7167 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7168 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7173 SetAIFlag('ATTACKLEFT', '1')
7175 SetAIFlag('ATTACKRIGHT', '1');
7179 function TBot
.RunDirection(): TDirection
;
7181 if Abs(Vel
.X
) >= 1 then
7183 if Vel
.X
> 0 then Result
:= D_RIGHT
else Result
:= D_LEFT
;
7185 Result
:= FDirection
;
7188 function TBot
.GetRnd(a
: Byte): Boolean;
7190 if a
= 0 then Result
:= False
7191 else if a
= 255 then Result
:= True
7192 else Result
:= Random(256) > 255-a
;
7195 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7197 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7200 procedure TBot
.SaveState(var Mem
: TBinMemoryWriter
);
7206 inherited SaveState(Mem
);
7208 // Âûáðàííîå îðóæèå:
7209 Mem
.WriteByte(FSelectedWeapon
);
7211 Mem
.WriteWord(FTargetUID
);
7212 // Âðåìÿ ïîòåðè öåëè:
7213 Mem
.WriteDWORD(FLastVisible
);
7214 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7215 dw
:= Length(FAIFlags
);
7218 for i
:= 0 to Integer(dw
)-1 do
7220 Mem
.WriteString(FAIFlags
[i
].Name
, 20);
7221 Mem
.WriteString(FAIFlags
[i
].Value
, 20);
7223 // Íàñòðîéêè ñëîæíîñòè:
7225 Mem
.WriteMemory(p
, SizeOf(TDifficult
));
7228 procedure TBot
.LoadState(var Mem
: TBinMemoryReader
);
7234 inherited LoadState(Mem
);
7236 // Âûáðàííîå îðóæèå:
7237 Mem
.ReadByte(FSelectedWeapon
);
7239 Mem
.ReadWord(FTargetUID
);
7240 // Âðåìÿ ïîòåðè öåëè:
7241 Mem
.ReadDWORD(FLastVisible
);
7242 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7244 SetLength(FAIFlags
, dw
);
7246 for i
:= 0 to Integer(dw
)-1 do
7248 Mem
.ReadString(FAIFlags
[i
].Name
);
7249 Mem
.ReadString(FAIFlags
[i
].Value
);
7251 // Íàñòðîéêè ñëîæíîñòè:
7252 Mem
.ReadMemory(p
, dw
);
7253 if dw
<> SizeOf(TDifficult
) then
7255 raise EBinSizeError
.Create('TBot.LoadState: Wrong FDifficult Size');
7257 FDifficult
:= TDifficult(p
^);