1 (* Copyright (C) DooM 2D:Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 e_graphics
, g_playermodel
, g_basic
, g_textures
,
23 g_weapons
, g_phys
, g_sound
, g_saveload
, MAPSTRUCT
,
73 ANGLE_NONE
= Low(SmallInt);
75 CORPSE_STATE_REMOVEME
= 0;
76 CORPSE_STATE_NORMAL
= 1;
77 CORPSE_STATE_MESS
= 2;
79 PLAYER_RECT
: TRectWH
= (X
:15; Y
:12; Width
:34; Height
:52);
80 PLAYER_RECT_CX
= 15+(34 div 2);
81 PLAYER_RECT_CY
= 12+(52 div 2);
82 PLAYER_CORPSERECT
: TRectWH
= (X
:15; Y
:48; Width
:34; Height
:16);
85 PLAYER_HP_LIMIT
= 200;
87 PLAYER_AP_LIMIT
= 200;
90 PLAYER1_DEF_COLOR
: TRGB
= (R
:64; G
:175; B
:48);
91 PLAYER2_DEF_COLOR
: TRGB
= (R
:96; G
:96; B
:96);
107 TPlayerStatArray
= Array of TPlayerStat
;
109 TPlayerSavedState
= record
117 Ammo
: Array [A_BULLETS
..A_CELLS
] of Word;
118 MaxAmmo
: Array [A_BULLETS
..A_CELLS
] of Word;
119 Weapon
: Array [WEAPON_KASTET
..WEAPON_SUPERPULEMET
] of Boolean;
120 Rulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
129 TPlayer
= class (TObject
)
137 FDirection
: TDirection
;
145 FMonsterKills
: Integer;
151 FCanJetpack
: Boolean;
157 FNextWeapDelay
: Byte; // frames
158 FBFGFireCounter
: SmallInt;
159 FLastSpawnerUID
: Word;
163 FSpectatePlayer
: Integer;
165 FSavedState
: TPlayerSavedState
;
167 FModel
: TPlayerModel
;
170 FActionForce
: Boolean;
171 FActionChanged
: Boolean;
173 FFireAngle
: SmallInt;
175 FShellTimer
: Integer;
177 FSawSound
: TPlayableSound
;
178 FSawSoundIdle
: TPlayableSound
;
179 FSawSoundHit
: TPlayableSound
;
180 FSawSoundSelect
: TPlayableSound
;
181 FJetSoundOn
: TPlayableSound
;
182 FJetSoundOff
: TPlayableSound
;
183 FJetSoundFly
: TPlayableSound
;
187 FJustTeleported
: Boolean;
190 function CollideLevel(XInc
, YInc
: Integer): Boolean;
191 function StayOnStep(XInc
, YInc
: Integer): Boolean;
192 function HeadInLiquid(XInc
, YInc
: Integer): Boolean;
193 function BodyInLiquid(XInc
, YInc
: Integer): Boolean;
194 function BodyInAcid(XInc
, YInc
: Integer): Boolean;
195 function FullInLift(XInc
, YInc
: Integer): Integer;
196 {procedure CollideItem();}
197 procedure FlySmoke(Times
: DWORD
= 1);
198 function GetAmmoByWeapon(Weapon
: Byte): Word;
199 procedure SetAction(Action
: Byte; Force
: Boolean = False);
200 procedure OnDamage(Angle
: SmallInt); virtual;
201 function firediry(): Integer;
203 procedure Run(Direction
: TDirection
);
204 procedure NextWeapon();
205 procedure PrevWeapon();
212 procedure cycleWeapon (dir
: Integer);
213 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
214 procedure resetWeaponQueue ();
215 function hasAmmoForWeapon (weapon
: Byte): Boolean;
218 FDamageBuffer
: Integer;
220 FAmmo
: Array [A_BULLETS
..A_CELLS
] of Word;
221 FMaxAmmo
: Array [A_BULLETS
..A_CELLS
] of Word;
222 FWeapon
: Array [WEAPON_KASTET
..WEAPON_SUPERPULEMET
] of Boolean;
223 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
225 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
226 FReloading
: Array [WEAPON_KASTET
..WEAPON_SUPERPULEMET
] of Word;
227 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
228 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
230 FPreferredTeam
: Byte;
233 FWantsInGame
: Boolean;
237 FActualModelName
: string;
243 constructor Create(); virtual;
244 destructor Destroy(); override;
245 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
246 function GetRespawnPoint(): Byte;
247 procedure PressKey(Key
: Byte; Time
: Word = 1);
248 procedure ReleaseKeys();
249 procedure SetModel(ModelName
: String);
250 procedure SetColor(Color
: TRGB
);
251 procedure SetWeapon(W
: Byte);
252 function IsKeyPressed(K
: Byte): Boolean;
253 function GetKeys(): Byte;
254 function PickItem(ItemType
: Byte; respawn
: Boolean; var remove
: Boolean): Boolean; virtual;
255 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
256 function Collide(Panel
: TPanel
): Boolean; overload
;
257 function Collide(X
, Y
: Integer): Boolean; overload
;
258 procedure SetDirection(Direction
: TDirection
);
259 procedure GetSecret();
260 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
262 procedure Push(vx
, vy
: Integer);
263 procedure ChangeModel(ModelName
: String);
264 procedure SwitchTeam
;
265 procedure ChangeTeam(Team
: Byte);
267 function GetFlag(Flag
: Byte): Boolean;
268 procedure SetFlag(Flag
: Byte);
269 function DropFlag(): Boolean;
270 procedure AllRulez(Health
: Boolean);
271 procedure RestoreHealthArmor();
272 procedure FragCombo();
273 procedure GiveItem(ItemType
: Byte);
274 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
275 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
276 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
277 procedure MakeBloodSimple(Count
: Word);
278 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
279 procedure Reset(Force
: Boolean);
280 procedure Spectate(NoMove
: Boolean = False);
281 procedure SwitchNoClip
;
282 procedure SoftReset();
283 procedure Draw(); virtual;
284 procedure DrawPain();
285 procedure DrawPickup();
286 procedure DrawRulez();
288 procedure DrawBubble();
290 procedure Update(); virtual;
291 procedure RememberState();
292 procedure RecallState();
293 procedure SaveState(var Mem
: TBinMemoryWriter
); virtual;
294 procedure LoadState(var Mem
: TBinMemoryReader
); virtual;
295 procedure PauseSounds(Enable
: Boolean);
296 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
297 procedure DoLerp(Level
: Integer = 2);
298 procedure SetLerp(XTo
, YTo
: Integer);
299 procedure QueueWeaponSwitch(Weapon
: Byte);
300 procedure RealizeCurrentWeapon();
302 procedure JetpackOff
;
304 property Name
: String read FName write FName
;
305 property Model
: TPlayerModel read FModel
;
306 property Health
: Integer read FHealth write FHealth
;
307 property Lives
: Byte read FLives write FLives
;
308 property Armor
: Integer read FArmor write FArmor
;
309 property Air
: Integer read FAir write FAir
;
310 property JetFuel
: Integer read FJetFuel write FJetFuel
;
311 property Frags
: Integer read FFrags write FFrags
;
312 property Death
: Integer read FDeath write FDeath
;
313 property Kills
: Integer read FKills write FKills
;
314 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
315 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
316 property Secrets
: Integer read FSecrets
;
317 property GodMode
: Boolean read FGodMode write FGodMode
;
318 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
319 property NoReload
: Boolean read FNoReload write FNoReload
;
320 property Live
: Boolean read FLive write FLive
;
321 property Flag
: Byte read FFlag
;
322 property Team
: Byte read FTeam write FTeam
;
323 property Direction
: TDirection read FDirection
;
324 property GameX
: Integer read FObj
.X write FObj
.X
;
325 property GameY
: Integer read FObj
.Y write FObj
.Y
;
326 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
327 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
328 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
329 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
330 property Vel
: TPoint2i read FObj
.Vel
;
331 property Obj
: TObj read FObj
;
332 property IncCam
: Integer read FIncCam write FIncCam
;
333 property UID
: Word read FUID write FUID
;
334 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
335 property NetTime
: LongWord read FNetTime write FNetTime
;
345 WeaponPrior
: Array [WEAPON_KASTET
..WEAPON_SUPERPULEMET
] of Byte;
346 CloseWeaponPrior
: Array [WEAPON_KASTET
..WEAPON_SUPERPULEMET
] of Byte;
347 //SafeWeaponPrior: Array [WEAPON_KASTET..WEAPON_SUPERPULEMET] of Byte;
355 TBot
= class (TPlayer
)
357 FSelectedWeapon
: Byte;
360 FAIFlags
: Array of TAIFlag
;
361 FDifficult
: TDifficult
;
363 function GetRnd(a
: Byte): Boolean;
364 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
365 function RunDirection(): TDirection
;
366 function FullInStep(XInc
, YInc
: Integer): Boolean;
367 //function NeedItem(Item: Byte): Byte;
368 procedure SelectWeapon(Dist
: Integer);
369 procedure SetAIFlag(fName
, fValue
: String20
);
370 function GetAIFlag(fName
: String20
): String20
;
371 procedure RemoveAIFlag(fName
: String20
);
372 function Healthy(): Byte;
373 procedure UpdateMove();
374 procedure UpdateCombat();
375 function KeyPressed(Key
: Word): Boolean;
376 procedure ReleaseKey(Key
: Byte);
377 function TargetOnScreen(TX
, TY
: Integer): Boolean;
378 procedure OnDamage(Angle
: SmallInt); override;
381 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
382 constructor Create(); override;
383 destructor Destroy(); override;
384 procedure Draw(); override;
385 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
386 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
387 procedure Update(); override;
388 procedure SaveState(var Mem
: TBinMemoryWriter
); override;
389 procedure LoadState(var Mem
: TBinMemoryReader
); override;
411 TCorpse
= class (TObject
)
419 FAnimation
: TAnimation
;
420 FAnimationMask
: TAnimation
;
423 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
424 destructor Destroy(); override;
425 procedure Damage(Value
: Word; vx
, vy
: Integer);
428 procedure SaveState(var Mem
: TBinMemoryWriter
);
429 procedure LoadState(var Mem
: TBinMemoryReader
);
431 property Obj
: TObj read FObj
;
432 property State
: Byte read FState
;
433 property Mess
: Boolean read FMess
;
436 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
442 gPlayers
: Array of TPlayer
;
443 gCorpses
: Array of TCorpse
;
444 gGibs
: Array of TGib
;
445 gShells
: Array of TShell
;
446 gTeamStat
: TTeamStat
;
447 gFly
: Boolean = False;
448 gAimLine
: Boolean = False;
449 gChatBubble
: Byte = 0;
453 MAX_RUNVEL
: Integer = 8;
454 VEL_JUMP
: Integer = 10;
455 SHELL_TIMEOUT
: Cardinal = 60000;
457 function Lerp(X
, Y
, Factor
: Integer): Integer;
459 procedure g_Gibs_SetMax(Count
: Word);
460 function g_Gibs_GetMax(): Word;
461 procedure g_Corpses_SetMax(Count
: Word);
462 function g_Corpses_GetMax(): Word;
463 procedure g_Shells_SetMax(Count
: Word);
464 function g_Shells_GetMax(): Word;
466 procedure g_Player_Init();
467 procedure g_Player_Free();
468 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
469 function g_Player_CreateFromState(var Mem
: TBinMemoryReader
): Word;
470 procedure g_Player_Remove(UID
: Word);
471 procedure g_Player_ResetTeams();
472 procedure g_Player_UpdateAll();
473 procedure g_Player_DrawAll();
474 procedure g_Player_DrawDebug(p
: TPlayer
);
475 procedure g_Player_DrawHealth();
476 procedure g_Player_RememberAll();
477 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
478 function g_Player_Get(UID
: Word): TPlayer
;
479 function g_Player_GetCount(): Byte;
480 function g_Player_GetStats(): TPlayerStatArray
;
481 function g_Player_ValidName(Name
: String): Boolean;
482 procedure g_Player_CreateCorpse(Player
: TPlayer
);
483 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
484 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
485 procedure g_Player_UpdatePhysicalObjects();
486 procedure g_Player_DrawCorpses();
487 procedure g_Player_DrawShells();
488 procedure g_Player_RemoveAllCorpses();
489 procedure g_Player_Corpses_SaveState(var Mem
: TBinMemoryWriter
);
490 procedure g_Player_Corpses_LoadState(var Mem
: TBinMemoryReader
);
491 procedure g_Bot_Add(Team
, Difficult
: Byte);
492 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1);
493 procedure g_Bot_MixNames();
494 procedure g_Bot_RemoveAll();
499 e_log
, g_map
, g_items
, g_console
, SysUtils
, g_gfx
, Math
,
500 g_options
, g_triggers
, g_menu
, MAPDEF
, g_game
,
501 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
, g_net
, g_netmsg
;
511 diag_precision
: Byte;
515 w_prior1
: Array [WEAPON_KASTET
..WEAPON_SUPERPULEMET
] of Byte;
516 w_prior2
: Array [WEAPON_KASTET
..WEAPON_SUPERPULEMET
] of Byte;
517 w_prior3
: Array [WEAPON_KASTET
..WEAPON_SUPERPULEMET
] of Byte;
521 TIME_RESPAWN1
= 1500;
522 TIME_RESPAWN2
= 2000;
523 TIME_RESPAWN3
= 3000;
526 JET_MAX
= 540; // ~30 sec
527 PLAYER_SUIT_TIME
= 30000;
528 PLAYER_INVUL_TIME
= 30000;
529 PLAYER_INVIS_TIME
= 35000;
530 FRAG_COMBO_TIME
= 3000;
534 ANGLE_RIGHTDOWN
= -35;
536 ANGLE_LEFTDOWN
= -145;
537 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
538 WEAPONPOINT
: Array [TDirection
] of TPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
541 BOT_UNSAFEDIST
= 128;
542 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
544 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
545 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
546 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0));
547 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
548 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
549 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0));
550 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
551 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
552 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0));
553 WEAPON_PRIOR1
: Array [WEAPON_KASTET
..WEAPON_SUPERPULEMET
] of Byte =
554 (WEAPON_SUPERPULEMET
, WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
555 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
556 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
557 WEAPON_PRIOR2
: Array [WEAPON_KASTET
..WEAPON_SUPERPULEMET
] of Byte =
558 (WEAPON_SUPERPULEMET
, WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
559 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
560 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
561 //WEAPON_PRIOR3: Array [WEAPON_KASTET..WEAPON_SUPERPULEMET] of Byte =
562 // (WEAPON_SUPERPULEMET, WEAPON_BFG, WEAPON_PLASMA,
563 // WEAPON_SHOTGUN2, WEAPON_CHAINGUN, WEAPON_SHOTGUN1,
564 // WEAPON_SAW, WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
565 WEAPON_RELOAD
: Array [WEAPON_KASTET
..WEAPON_SUPERPULEMET
] of Byte =
566 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2);
568 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
569 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
571 BOTNAMES_FILENAME
= 'botnames.txt';
572 BOTLIST_FILENAME
= 'botlist.txt';
576 MaxCorpses
: Word = 20;
577 MaxShells
: Word = 300;
578 CurrentGib
: Integer = 0;
579 CurrentShell
: Integer = 0;
580 BotNames
: Array of String;
581 BotList
: Array of TBotProfile
;
583 function Lerp(X
, Y
, Factor
: Integer): Integer;
585 Result
:= X
+ ((Y
- X
) div Factor
);
588 function SameTeam(UID1
, UID2
: Word): Boolean;
592 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
593 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
595 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
597 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
598 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
600 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
603 procedure g_Gibs_SetMax(Count
: Word);
606 SetLength(gGibs
, Count
);
608 if CurrentGib
>= Count
then
612 function g_Gibs_GetMax(): Word;
617 procedure g_Shells_SetMax(Count
: Word);
620 SetLength(gShells
, Count
);
622 if CurrentShell
>= Count
then
626 function g_Shells_GetMax(): Word;
632 procedure g_Corpses_SetMax(Count
: Word);
635 SetLength(gCorpses
, Count
);
638 function g_Corpses_GetMax(): Word;
640 Result
:= MaxCorpses
;
643 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
653 // Åñòü ëè ìåñòî â gPlayers:
654 if gPlayers
<> nil then
655 for a
:= 0 to High(gPlayers
) do
656 if gPlayers
[a
] = nil then
662 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
665 SetLength(gPlayers
, Length(gPlayers
)+1);
669 // Ñîçäàåì îáúåêò èãðîêà:
671 gPlayers
[a
] := TBot
.Create()
673 gPlayers
[a
] := TPlayer
.Create();
676 gPlayers
[a
].FActualModelName
:= ModelName
;
677 gPlayers
[a
].SetModel(ModelName
);
679 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
680 if gPlayers
[a
].FModel
= nil then
684 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
688 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
689 if Random(2) = 0 then
693 gPlayers
[a
].FPreferredTeam
:= Team
;
695 case gGameSettings
.GameMode
of
696 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
698 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
700 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
703 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
704 gPlayers
[a
].FColor
:= Color
;
705 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
706 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
708 gPlayers
[a
].FModel
.Color
:= Color
;
710 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
711 gPlayers
[a
].FLive
:= False;
713 Result
:= gPlayers
[a
].FUID
;
716 function g_Player_CreateFromState(var Mem
: TBinMemoryReader
): Word;
729 if sig
<> PLAYER_SIGNATURE
then // 'PLYR'
731 raise EBinSizeError
.Create('g_Player_CreateFromState: Wrong Player Signature');
735 Mem
.ReadBoolean(Bot
);
740 // Åñòü ëè ìåñòî â gPlayers:
741 if gPlayers
<> nil then
742 for a
:= 0 to High(gPlayers
) do
743 if gPlayers
[a
] = nil then
749 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
752 SetLength(gPlayers
, Length(gPlayers
)+1);
756 // Ñîçäàåì îáúåêò èãðîêà:
758 gPlayers
[a
] := TBot
.Create()
760 gPlayers
[a
] := TPlayer
.Create();
761 gPlayers
[a
].FIamBot
:= Bot
;
762 gPlayers
[a
].FPhysics
:= True;
765 Mem
.ReadWord(gPlayers
[a
].FUID
);
767 Mem
.ReadString(gPlayers
[a
].FName
);
769 Mem
.ReadByte(gPlayers
[a
].FTeam
);
770 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
772 Mem
.ReadBoolean(gPlayers
[a
].FLive
);
773 // Èçðàñõîäîâàë ëè âñå æèçíè:
774 Mem
.ReadBoolean(gPlayers
[a
].FNoRespawn
);
778 gPlayers
[a
].FDirection
:= D_LEFT
780 gPlayers
[a
].FDirection
:= D_RIGHT
;
782 Mem
.ReadInt(gPlayers
[a
].FHealth
);
784 Mem
.ReadByte(gPlayers
[a
].FLives
);
786 Mem
.ReadInt(gPlayers
[a
].FArmor
);
788 Mem
.ReadInt(gPlayers
[a
].FAir
);
790 Mem
.ReadInt(gPlayers
[a
].FJetFuel
);
792 Mem
.ReadInt(gPlayers
[a
].FPain
);
794 Mem
.ReadInt(gPlayers
[a
].FKills
);
796 Mem
.ReadInt(gPlayers
[a
].FMonsterKills
);
798 Mem
.ReadInt(gPlayers
[a
].FFrags
);
800 Mem
.ReadByte(gPlayers
[a
].FFragCombo
);
801 // Âðåìÿ ïîñëåäíåãî ôðàãà:
802 Mem
.ReadDWORD(gPlayers
[a
].FLastFrag
);
804 Mem
.ReadInt(gPlayers
[a
].FDeath
);
806 Mem
.ReadByte(gPlayers
[a
].FFlag
);
808 Mem
.ReadInt(gPlayers
[a
].FSecrets
);
810 Mem
.ReadByte(gPlayers
[a
].FCurrWeap
);
811 // Ñëåäóþùåå æåëàåìîå îðóæèå:
812 Mem
.ReadWord(gPlayers
[a
].FNextWeap
);
814 Mem
.ReadByte(gPlayers
[a
].FNextWeapDelay
);
815 // Âðåìÿ çàðÿäêè BFG:
816 Mem
.ReadSmallInt(gPlayers
[a
].FBFGFireCounter
);
818 Mem
.ReadInt(gPlayers
[a
].FDamageBuffer
);
819 // Ïîñëåäíèé óäàðèâøèé:
820 Mem
.ReadWord(gPlayers
[a
].FLastSpawnerUID
);
821 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
822 Mem
.ReadByte(gPlayers
[a
].FLastHit
);
824 Obj_LoadState(@gPlayers
[a
].FObj
, Mem
);
825 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
826 for i
:= A_BULLETS
to A_CELLS
do
827 Mem
.ReadWord(gPlayers
[a
].FAmmo
[i
]);
828 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
829 for i
:= A_BULLETS
to A_CELLS
do
830 Mem
.ReadWord(gPlayers
[a
].FMaxAmmo
[i
]);
832 for i
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
833 Mem
.ReadBoolean(gPlayers
[a
].FWeapon
[i
]);
834 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
835 for i
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
836 Mem
.ReadWord(gPlayers
[a
].FReloading
[i
]);
840 Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
841 // Íàëè÷èå êðàñíîãî êëþ÷à:
844 Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
845 // Íàëè÷èå çåëåíîãî êëþ÷à:
848 Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
849 // Íàëè÷èå ñèíåãî êëþ÷à:
852 Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
856 Include(gPlayers
[a
].FRulez
, R_BERSERK
);
857 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
858 for i
:= MR_SUIT
to MR_MAX
do
859 Mem
.ReadDWORD(gPlayers
[a
].FMegaRulez
[i
]);
860 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
861 for i
:= T_RESPAWN
to T_FLAGCAP
do
862 Mem
.ReadDWORD(gPlayers
[a
].FTime
[i
]);
865 Mem
.ReadString(gPlayers
[a
].FActualModelName
);
867 Mem
.ReadByte(gPlayers
[a
].FColor
.R
);
868 Mem
.ReadByte(gPlayers
[a
].FColor
.G
);
869 Mem
.ReadByte(gPlayers
[a
].FColor
.B
);
870 // Îáíîâëÿåì ìîäåëü èãðîêà:
871 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
873 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
874 if gPlayers
[a
].FModel
= nil then
878 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
882 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
883 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
884 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
886 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
888 Result
:= gPlayers
[a
].FUID
;
891 procedure g_Player_ResetTeams();
895 if g_Game_IsClient
then
897 if gPlayers
= nil then
899 for a
:= Low(gPlayers
) to High(gPlayers
) do
900 if gPlayers
[a
] <> nil then
901 case gGameSettings
.GameMode
of
903 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
905 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
906 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
907 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
910 gPlayers
[a
].ChangeTeam(TEAM_RED
)
912 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
915 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
919 procedure g_Bot_Add(Team
, Difficult
: Byte);
922 _name
, _model
: String;
925 if not g_Game_IsServer
then Exit
;
927 // Ñïèñîê íàçâàíèé ìîäåëåé:
928 m
:= g_PlayerModel_GetNames();
933 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
934 Team
:= TEAM_COOP
// COOP
936 if gGameSettings
.GameMode
= GM_DM
then
937 Team
:= TEAM_NONE
// DM
939 if Team
= TEAM_NONE
then // CTF / TDM
941 // Àâòîáàëàíñ êîìàíä:
945 for a
:= 0 to High(gPlayers
) do
946 if gPlayers
[a
] <> nil then
948 if gPlayers
[a
].Team
= TEAM_RED
then
951 if gPlayers
[a
].Team
= TEAM_BLUE
then
961 if Random(2) = 0 then
967 // Âûáèðàåì áîòó èìÿ:
969 if BotNames
<> nil then
970 for a
:= 0 to High(BotNames
) do
971 if g_Player_ValidName(BotNames
[a
]) then
973 _name
:= BotNames
[a
];
977 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
980 _name
:= Format('DFBOT%.2d', [Random(100)]);
981 until g_Player_ValidName(_name
);
983 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
984 _model
:= m
[Random(Length(m
))];
987 with g_Player_Get(g_Player_Create(_model
,
988 _RGB(Min(Random(9)*32, 255),
989 Min(Random(9)*32, 255),
990 Min(Random(9)*32, 255)),
991 Team
, True)) as TBot
do
996 1: FDifficult
:= DIFFICULT_EASY
;
997 2: FDifficult
:= DIFFICULT_MEDIUM
;
998 else FDifficult
:= DIFFICULT_HARD
;
1001 for a
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
1003 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1004 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1005 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1008 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1010 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1011 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1016 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1);
1019 _name
, _model
: String;
1022 if not g_Game_IsServer
then Exit
;
1024 // Ñïèñîê íàçâàíèé ìîäåëåé:
1025 m
:= g_PlayerModel_GetNames();
1030 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1031 Team
:= TEAM_COOP
// COOP
1033 if gGameSettings
.GameMode
= GM_DM
then
1034 Team
:= TEAM_NONE
// DM
1036 if Team
= TEAM_NONE
then
1037 Team
:= BotList
[num
].team
; // CTF / TDM
1039 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1040 lName
:= AnsiLowerCase(lName
);
1041 if (num
< 0) or (num
> Length(BotList
)-1) then
1043 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1044 for a
:= 0 to High(BotList
) do
1045 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1054 _name
:= BotList
[num
].name
;
1055 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1056 if not g_Player_ValidName(_name
) then
1058 _name
:= Format('DFBOT%.2d', [Random(100)]);
1059 until g_Player_ValidName(_name
);
1062 _model
:= BotList
[num
].model
;
1063 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1064 if not InSArray(_model
, m
) then
1065 _model
:= m
[Random(Length(m
))];
1068 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1072 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1073 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1074 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1075 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1076 FDifficult
.Cover
:= BotList
[num
].cover
;
1077 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1079 for a
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
1081 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1082 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1083 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1086 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1088 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1092 procedure g_Bot_RemoveAll();
1096 if not g_Game_IsServer
then Exit
;
1097 if gPlayers
= nil then Exit
;
1099 for a
:= 0 to High(gPlayers
) do
1100 if gPlayers
[a
] <> nil then
1101 if gPlayers
[a
] is TBot
then
1103 gPlayers
[a
].Lives
:= 0;
1104 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1105 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1106 g_Player_Remove(gPlayers
[a
].FUID
);
1112 procedure g_Bot_MixNames();
1117 if BotNames
<> nil then
1118 for a
:= 0 to High(BotNames
) do
1120 b
:= Random(Length(BotNames
));
1122 Botnames
[a
] := BotNames
[b
];
1127 procedure g_Player_Remove(UID
: Word);
1131 if gPlayers
= nil then Exit
;
1133 if g_Game_IsServer
and g_Game_IsNet
then
1134 MH_SEND_PlayerDelete(UID
);
1136 for i
:= 0 to High(gPlayers
) do
1137 if gPlayers
[i
] <> nil then
1138 if gPlayers
[i
].FUID
= UID
then
1140 if gPlayers
[i
] is TPlayer
then
1141 TPlayer(gPlayers
[i
]).Free()
1143 TBot(gPlayers
[i
]).Free();
1149 procedure g_Player_Init();
1159 if not FileExists(DataDir
+ BOTNAMES_FILENAME
) then
1162 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1163 AssignFile(F
, DataDir
+ BOTNAMES_FILENAME
);
1174 SetLength(BotNames
, Length(BotNames
)+1);
1175 BotNames
[High(BotNames
)] := s
;
1183 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1184 config
:= TConfig
.CreateFile(DataDir
+ BOTLIST_FILENAME
);
1188 while config
.SectionExists(IntToStr(a
)) do
1190 SetLength(BotList
, Length(BotList
)+1);
1192 with BotList
[High(BotList
)] do
1195 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1197 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1199 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1204 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1205 color
.R
:= StrToIntDef(sa
[0], 0);
1206 color
.G
:= StrToIntDef(sa
[1], 0);
1207 color
.B
:= StrToIntDef(sa
[2], 0);
1208 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1209 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1210 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1211 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1212 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1213 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1214 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1215 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1216 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1217 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1218 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1219 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1220 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1221 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1222 if Length(sa
) = 10 then
1224 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1225 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1226 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1227 if Length(sa
) = 10 then
1229 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1231 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1232 if Length(sa) = 10 then
1234 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1243 procedure g_Player_Free();
1247 if gPlayers
<> nil then
1249 for i
:= 0 to High(gPlayers
) do
1250 if gPlayers
[i
] <> nil then
1252 if gPlayers
[i
] is TPlayer
then
1253 TPlayer(gPlayers
[i
]).Free()
1255 TBot(gPlayers
[i
]).Free();
1266 procedure g_Player_UpdateAll();
1270 if gPlayers
= nil then Exit
;
1272 for i
:= 0 to High(gPlayers
) do
1273 if gPlayers
[i
] <> nil then
1275 gPlayers
[i
].RealizeCurrentWeapon();
1276 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Update()
1277 else TBot(gPlayers
[i
]).Update();
1281 procedure g_Player_DrawAll();
1285 if gPlayers
= nil then Exit
;
1287 for i
:= 0 to High(gPlayers
) do
1288 if gPlayers
[i
] <> nil then
1289 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1290 else TBot(gPlayers
[i
]).Draw();
1293 procedure g_Player_DrawDebug(p
: TPlayer
);
1297 if p
= nil then Exit
;
1298 if (@p
.FObj
) = nil then Exit
;
1300 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1302 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1303 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1304 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1305 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1306 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1307 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1310 procedure g_Player_DrawHealth();
1315 if gPlayers
= nil then Exit
;
1316 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1318 for i
:= 0 to High(gPlayers
) do
1319 if gPlayers
[i
] <> nil then
1321 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1322 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1323 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1324 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1325 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1326 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1330 function g_Player_Get(UID
: Word): TPlayer
;
1336 if gPlayers
= nil then
1339 for a
:= 0 to High(gPlayers
) do
1340 if gPlayers
[a
] <> nil then
1341 if gPlayers
[a
].FUID
= UID
then
1343 Result
:= gPlayers
[a
];
1348 function g_Player_GetCount(): Byte;
1354 if gPlayers
= nil then
1357 for a
:= 0 to High(gPlayers
) do
1358 if gPlayers
[a
] <> nil then
1359 Result
:= Result
+ 1;
1362 function g_Player_GetStats(): TPlayerStatArray
;
1368 if gPlayers
= nil then Exit
;
1370 for a
:= 0 to High(gPlayers
) do
1371 if gPlayers
[a
] <> nil then
1373 SetLength(Result
, Length(Result
)+1);
1374 with Result
[High(Result
)] do
1376 Ping
:= gPlayers
[a
].FPing
;
1377 Loss
:= gPlayers
[a
].FLoss
;
1378 Name
:= gPlayers
[a
].FName
;
1379 Team
:= gPlayers
[a
].FTeam
;
1380 Frags
:= gPlayers
[a
].FFrags
;
1381 Deaths
:= gPlayers
[a
].FDeath
;
1382 Kills
:= gPlayers
[a
].FKills
;
1383 Color
:= gPlayers
[a
].FModel
.Color
;
1384 Lives
:= gPlayers
[a
].FLives
;
1385 Spectator
:= gPlayers
[a
].FSpectator
;
1390 procedure g_Player_RememberAll
;
1394 for i
:= Low(gPlayers
) to High(gPlayers
) do
1395 if (gPlayers
[i
] <> nil) and gPlayers
[i
].Live
then
1396 gPlayers
[i
].RememberState
;
1399 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1403 gTeamStat
[TEAM_RED
].Goals
:= 0;
1404 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1406 if gPlayers
<> nil then
1407 for i
:= 0 to High(gPlayers
) do
1408 if gPlayers
[i
] <> nil then
1410 gPlayers
[i
].Reset(Force
);
1412 if gPlayers
[i
] is TPlayer
then
1414 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1415 gPlayers
[i
].Respawn(Silent
)
1417 gPlayers
[i
].Spectate();
1420 TBot(gPlayers
[i
]).Respawn(Silent
);
1424 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1431 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1436 if (FHealth
>= -50) or (gGibsCount
= 0) then
1438 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1442 for find_id
:= 0 to High(gCorpses
) do
1443 if gCorpses
[find_id
] = nil then
1450 find_id
:= Random(Length(gCorpses
));
1452 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1453 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1454 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1455 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1458 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1459 FObj
.Y
+ PLAYER_RECT_CY
,
1460 FModel
.Name
, FModel
.Color
);
1464 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1468 if (gShells
= nil) or (Length(gShells
) = 0) then
1471 with gShells
[CurrentShell
] do
1477 if T
= SHELL_BULLET
then
1479 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1483 Obj
.Rect
.Width
:= 4;
1484 Obj
.Rect
.Height
:= 2;
1488 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1492 Obj
.Rect
.Width
:= 7;
1493 Obj
.Rect
.Height
:= 3;
1499 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1500 RAngle
:= Random(360);
1501 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1503 if CurrentShell
>= High(gShells
) then
1510 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1513 GibsArray
: TGibsArray
;
1515 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1517 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1520 for a
:= 0 to High(GibsArray
) do
1521 with gGibs
[CurrentGib
] do
1524 ID
:= GibsArray
[a
].ID
;
1525 MaskID
:= GibsArray
[a
].MaskID
;
1528 Obj
.Rect
:= GibsArray
[a
].Rect
;
1529 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1530 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1531 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1532 RAngle
:= Random(360);
1534 if gBloodCount
> 0 then
1535 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1536 Random(48), Random(48), 150, 0, 0);
1538 if CurrentGib
>= High(gGibs
) then
1545 procedure g_Player_UpdatePhysicalObjects();
1551 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1556 if T
= SHELL_BULLET
then
1557 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1559 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1564 if gGibs
<> nil then
1565 for i
:= 0 to High(gGibs
) do
1566 if gGibs
[i
].Live
then
1570 mr
:= g_Obj_Move(@Obj
, True, False, True);
1572 if WordBool(mr
and MOVE_FALLOUT
) then
1578 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1579 if WordBool(mr
and MOVE_HITWALL
) then
1580 Obj
.Vel
.X
:= -(vel
.X
div 2);
1581 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1582 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1584 if (Obj
.Vel
.X
>= 0) then
1586 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1587 if RAngle
>= 360 then
1588 RAngle
:= RAngle
mod 360;
1589 end else begin // Counter-clockwise
1590 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1592 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1595 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1596 if gTime
mod (GAME_TICK
*3) = 0 then
1597 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1601 if gCorpses
<> nil then
1602 for i
:= 0 to High(gCorpses
) do
1603 if gCorpses
[i
] <> nil then
1604 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1610 gCorpses
[i
].Update();
1613 if gShells
<> nil then
1614 for i
:= 0 to High(gShells
) do
1615 if gShells
[i
].Live
then
1619 mr
:= g_Obj_Move(@Obj
, True, False, True);
1621 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1627 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1628 if WordBool(mr
and MOVE_HITWALL
) then
1630 Obj
.Vel
.X
:= -(vel
.X
div 2);
1631 if not WordBool(mr
and MOVE_INWATER
) then
1632 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1634 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1636 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1637 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1638 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1640 if RAngle
mod 90 <> 0 then
1641 RAngle
:= (RAngle
div 90) * 90;
1643 else if not WordBool(mr
and MOVE_INWATER
) then
1644 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1647 if (Obj
.Vel
.X
>= 0) then
1649 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1650 if RAngle
>= 360 then
1651 RAngle
:= RAngle
mod 360;
1652 end else begin // Counter-clockwise
1653 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1655 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1660 procedure g_Player_DrawCorpses();
1665 if gGibs
<> nil then
1666 for i
:= 0 to High(gGibs
) do
1667 if gGibs
[i
].Live
then
1670 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1673 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1674 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1676 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1679 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1685 if gCorpses
<> nil then
1686 for i
:= 0 to High(gCorpses
) do
1687 if gCorpses
[i
] <> nil then
1691 procedure g_Player_DrawShells();
1696 if gShells
<> nil then
1697 for i
:= 0 to High(gShells
) do
1698 if gShells
[i
].Live
then
1701 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1707 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1711 procedure g_Player_RemoveAllCorpses();
1717 SetLength(gGibs
, MaxGibs
);
1718 SetLength(gShells
, MaxGibs
);
1722 if gCorpses
<> nil then
1723 for i
:= 0 to High(gCorpses
) do
1727 SetLength(gCorpses
, MaxCorpses
);
1730 procedure g_Player_Corpses_SaveState(var Mem
: TBinMemoryWriter
);
1735 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ:
1737 if gCorpses
<> nil then
1738 for i
:= 0 to High(gCorpses
) do
1739 if gCorpses
[i
] <> nil then
1742 Mem
:= TBinMemoryWriter
.Create((count
+1) * 128);
1744 // Êîëè÷åñòâî òðóïîâ:
1745 Mem
.WriteInt(count
);
1751 for i
:= 0 to High(gCorpses
) do
1752 if gCorpses
[i
] <> nil then
1755 Mem
.WriteString(gCorpses
[i
].FModelName
);
1757 b
:= gCorpses
[i
].Mess
;
1758 Mem
.WriteBoolean(b
);
1759 // Ñîõðàíÿåì äàííûå òðóïà:
1760 gCorpses
[i
].SaveState(Mem
);
1764 procedure g_Player_Corpses_LoadState(var Mem
: TBinMemoryReader
);
1773 g_Player_RemoveAllCorpses();
1775 // Êîëè÷åñòâî òðóïîâ:
1778 if count
> Length(gCorpses
) then
1780 raise EBinSizeError
.Create('g_Player_Corpses_LoadState: Too Many Corpses');
1787 for i
:= 0 to count
-1 do
1790 Mem
.ReadString(str
);
1794 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1795 // Çàãðóæàåì äàííûå òðóïà:
1796 gCorpses
[i
].LoadState(Mem
);
1802 procedure TPlayer
.BFGHit();
1804 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1805 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1806 if g_Game_IsServer
and g_Game_IsNet
then
1807 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1808 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1812 procedure TPlayer
.ChangeModel(ModelName
: string);
1814 Model
: TPlayerModel
;
1816 Model
:= g_PlayerModel_Get(ModelName
);
1817 if Model
= nil then Exit
;
1823 procedure TPlayer
.SetModel(ModelName
: string);
1827 m
:= g_PlayerModel_Get(ModelName
);
1830 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1831 m
:= g_PlayerModel_Get('doomer');
1834 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1839 if FModel
<> nil then
1844 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1845 FModel
.Color
:= FColor
1847 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1848 FModel
.SetWeapon(FCurrWeap
);
1849 FModel
.SetFlag(FFlag
);
1850 SetDirection(FDirection
);
1853 procedure TPlayer
.SetColor(Color
: TRGB
);
1856 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1857 if FModel
<> nil then FModel
.Color
:= Color
;
1860 procedure TPlayer
.SwitchTeam
;
1862 if g_Game_IsClient
then
1864 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
1866 if gGameOn
and FLive
then
1867 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
1869 if FTeam
= TEAM_RED
then
1871 ChangeTeam(TEAM_BLUE
);
1872 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
1873 if g_Game_IsNet
then
1874 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
1878 ChangeTeam(TEAM_RED
);
1879 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
1880 if g_Game_IsNet
then
1881 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
1883 FPreferredTeam
:= FTeam
;
1886 procedure TPlayer
.ChangeTeam(Team
: Byte);
1893 TEAM_RED
, TEAM_BLUE
:
1894 FModel
.Color
:= TEAMCOLOR
[Team
];
1896 FModel
.Color
:= FColor
;
1898 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
1899 MH_SEND_PlayerStats(FUID
);
1903 procedure TPlayer.CollideItem();
1908 if gItems = nil then Exit;
1909 if not FLive then Exit;
1911 for i := 0 to High(gItems) do
1914 if (ItemType <> ITEM_NONE) and Live then
1915 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
1916 PLAYER_RECT.Height, @Obj) then
1918 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
1920 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
1921 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
1922 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
1923 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
1924 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
1926 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
1927 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
1928 (gGameSettings.GameType = GT_SINGLE) and
1929 (g_Player_GetCount() > 1)) then
1930 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
1936 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
1938 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
1939 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
1943 constructor TPlayer
.Create();
1949 FSawSound
:= TPlayableSound
.Create();
1950 FSawSoundIdle
:= TPlayableSound
.Create();
1951 FSawSoundHit
:= TPlayableSound
.Create();
1952 FSawSoundSelect
:= TPlayableSound
.Create();
1953 FJetSoundFly
:= TPlayableSound
.Create();
1954 FJetSoundOn
:= TPlayableSound
.Create();
1955 FJetSoundOff
:= TPlayableSound
.Create();
1957 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
1958 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
1959 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
1960 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
1961 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
1962 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
1963 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
1965 FSpectatePlayer
:= -1;
1969 FSavedState
.WaitRecall
:= False;
1972 FActualModelName
:= 'doomer';
1975 FObj
.Rect
:= PLAYER_RECT
;
1977 FBFGFireCounter
:= -1;
1978 FJustTeleported
:= False;
1984 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
1988 if (not g_Game_IsClient
) and (not FLive
) then
1993 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
1994 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
1996 if not g_Game_IsClient
then
1999 if t
= HIT_TRAP
then
2001 // Ëîâóøêà óáèâàåò ñðàçó:
2003 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2005 if t
= HIT_SELF
then
2009 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2012 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2013 FMegaRulez
[MR_SUIT
] := 0;
2014 FMegaRulez
[MR_INVUL
] := 0;
2015 FMegaRulez
[MR_INVIS
] := 0;
2019 // Íî îò îñòàëüíîãî ñïàñàåò:
2020 if FMegaRulez
[MR_INVUL
] >= gTime
then
2027 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2028 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2029 (SpawnerUID
= FUID
) or
2030 (not SameTeam(FUID
, SpawnerUID
)) then
2032 FLastSpawnerUID
:= SpawnerUID
;
2034 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2035 if gBloodCount
> 0 then
2037 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2038 if value
div 4 <= c
then
2039 c
:= c
- (value
div 4)
2043 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2047 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2048 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2051 if t
= HIT_WATER
then
2052 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2053 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2058 Inc(FDamageBuffer
, value
);
2062 FPain
:= FPain
+ value
;
2065 if g_Game_IsServer
and g_Game_IsNet
then
2067 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2068 MH_SEND_PlayerStats(FUID
);
2069 MH_SEND_PlayerPos(False, FUID
);
2073 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2076 if g_Game_IsClient
then
2081 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2083 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2086 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2088 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2092 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2093 MH_SEND_PlayerStats(FUID
);
2096 destructor TPlayer
.Destroy();
2098 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2100 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2104 FSawSoundIdle
.Free();
2105 FSawSoundHit
.Free();
2106 FJetSoundFly
.Free();
2108 FJetSoundOff
.Free();
2114 procedure TPlayer
.DrawBubble();
2116 bubX
, bubY
: Integer;
2119 Rw
, Gw
, Bw
: SmallInt;
2122 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= D_LEFT
, -4, 18);
2123 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2131 1: // simple textual non-bubble
2133 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2134 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2135 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2138 2: // advanced pixel-perfect bubble
2140 if FTeam
= TEAM_RED
then
2143 if FTeam
= TEAM_BLUE
then
2146 3: // colored bubble
2148 Rb
:= FModel
.Color
.R
;
2149 Gb
:= FModel
.Color
.G
;
2150 Bb
:= FModel
.Color
.B
;
2151 Rw
:= Min(Rb
* 2 + 64, 255);
2152 Gw
:= Min(Gb
* 2 + 64, 255);
2153 Bw
:= Min(Bb
* 2 + 64, 255);
2154 if (Abs(Rw
- Rb
) < 32)
2155 or (Abs(Gw
- Gb
) < 32)
2156 or (Abs(Bw
- Bb
) < 32) then
2158 Rb
:= Max(Rw
div 2 - 16, 0);
2159 Gb
:= Max(Gw
div 2 - 16, 0);
2160 Bb
:= Max(Bw
div 2 - 16, 0);
2163 4: // custom textured bubble
2165 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2166 if FDirection
= D_RIGHT
then
2167 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2169 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, M_HORIZONTAL
);
2175 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2176 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2178 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2181 Dot
:= IfThen(FDirection
= D_LEFT
, 14, 5);
2182 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2183 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
);
2184 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
);
2185 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
);
2186 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
);
2190 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2191 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2192 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2195 procedure TPlayer
.Draw();
2203 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2204 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2206 e_GetTextureSize(ID
, @w
, @h
);
2207 if FDirection
= D_LEFT
then
2208 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2209 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7, 0, True, False)
2211 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2212 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7, 0, True, False);
2215 if FMegaRulez
[MR_INVIS
] > gTime
then
2217 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2218 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2220 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2221 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2225 FModel
.Draw(FObj
.X
, FObj
.Y
, 200)
2227 FModel
.Draw(FObj
.X
, FObj
.Y
);
2230 FModel
.Draw(FObj
.X
, FObj
.Y
, 254);
2233 FModel
.Draw(FObj
.X
, FObj
.Y
);
2236 if g_debug_Frames
then
2238 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2240 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2241 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2245 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2247 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2248 if gAimLine
and Live
and
2249 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2253 procedure TPlayer
.DrawAim();
2255 wx
, wy
, xx
, yy
: Integer;
2259 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= D_LEFT
, 7, -7);
2260 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2269 1: begin // Chainsaw
2276 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2277 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2278 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2279 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2284 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2285 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2286 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2287 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2289 4: begin // Double Shotgun
2292 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2293 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2294 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2295 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2297 5: begin // Chaingun
2300 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2301 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2302 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2303 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2305 6: begin // Rocket Launcher
2308 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2309 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2310 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2311 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2313 7: begin // Plasmagun
2316 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2317 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2318 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2319 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2324 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2325 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2326 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2327 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2329 9: begin // Super Chaingun
2332 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2333 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2334 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2335 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2338 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2339 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2340 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2343 procedure TPlayer
.DrawGUI();
2346 X
, Y
, SY
, a
, p
, m
: Integer;
2350 stat
: TPlayerStatArray
;
2352 X
:= gPlayerScreenSize
.X
;
2353 SY
:= gPlayerScreenSize
.Y
;
2356 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2358 if gGameSettings
.GameMode
= GM_CTF
then
2362 if gGameSettings
.GameMode
= GM_CTF
then
2364 s
:= 'TEXTURE_PLAYER_REDFLAG';
2365 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2366 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2367 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2368 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2369 if g_Texture_Get(s
, ID
) then
2370 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2373 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2374 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2375 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2377 if gGameSettings
.GameMode
= GM_CTF
then
2379 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2380 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2381 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2382 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2383 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2384 if g_Texture_Get(s
, ID
) then
2385 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2388 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2389 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2390 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2393 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2394 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2397 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2398 e_Draw(ID
, X
+2, Y
, 0, True, False);
2400 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2404 s
:= IntToStr(Frags
);
2405 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2406 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2411 stat
:= g_Player_GetStats();
2416 for a
:= 0 to High(stat
) do
2417 if stat
[a
].Name
<> Name
then
2419 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2420 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2424 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2425 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2426 s
:= s
+IntToStr(Abs(Frags
-m
));
2428 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2429 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2432 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2434 s
:= IntToStr(Lives
);
2435 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2436 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2440 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2441 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2443 if R_BERSERK
in FRulez
then
2444 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2446 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2448 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2449 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2451 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2452 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2453 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2455 s
:= IntToStr(FArmor
);
2456 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2457 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2459 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2465 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2470 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2472 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2473 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2474 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2475 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2476 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2477 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2478 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2479 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2482 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2483 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2484 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2486 if R_KEY_RED
in FRulez
then
2487 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2489 if R_KEY_GREEN
in FRulez
then
2490 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2492 if R_KEY_BLUE
in FRulez
then
2493 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2495 if FJetFuel
> 0 then
2497 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2498 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2499 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2500 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2501 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2502 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2506 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2507 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2508 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2511 if gShowPing
and g_Game_IsClient
then
2513 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2514 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2520 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2521 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2522 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2525 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2526 s
:= _lc
[I_PLAYER_SPECT4
];
2527 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2528 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2529 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2535 procedure TPlayer
.DrawRulez();
2539 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2540 if FMegaRulez
[MR_INVUL
] >= gTime
then
2542 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2543 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2548 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2549 191, 191, 191, 0, B_INVERT
);
2552 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2553 if FMegaRulez
[MR_SUIT
] >= gTime
then
2555 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2556 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2561 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2562 0, 96, 0, 200, B_NONE
);
2565 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2566 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2568 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2569 255, 0, 0, 200, B_NONE
);
2573 procedure TPlayer
.DrawPain();
2577 if FPain
= 0 then Exit
;
2581 if a
< 15 then h
:= 0
2582 else if a
< 35 then h
:= 1
2583 else if a
< 55 then h
:= 2
2584 else if a
< 75 then h
:= 3
2585 else if a
< 95 then h
:= 4
2588 //if a > 255 then a := 255;
2590 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2591 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2594 procedure TPlayer
.DrawPickup();
2598 if FPickup
= 0 then Exit
;
2602 if a
< 15 then h
:= 1
2603 else if a
< 35 then h
:= 2
2604 else if a
< 55 then h
:= 3
2605 else if a
< 75 then h
:= 4
2608 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2611 procedure TPlayer
.Fire();
2613 f
, DidFire
: Boolean;
2614 wx
, wy
, xd
, yd
: Integer;
2617 if g_Game_IsClient
then Exit
;
2618 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2619 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2627 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2632 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2633 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2634 xd
:= wx
+IfThen(FDirection
= D_LEFT
, -30, 30);
2635 yd
:= wy
+firediry();
2640 if R_BERSERK
in FRulez
then
2642 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2643 obj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2644 obj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2647 obj
.rect
.Width
:= 39;
2648 obj
.rect
.Height
:= 52;
2649 obj
.Vel
.X
:= (xd
-wx
) div 2;
2650 obj
.Vel
.Y
:= (yd
-wy
) div 2;
2651 obj
.Accel
.X
:= xd
-wx
;
2652 obj
.Accel
.y
:= yd
-wy
;
2654 if g_Weapon_Hit(@obj
, 50, FUID
, HIT_SOME
) <> 0 then
2655 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2657 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2661 FPain
:= min(FPain
+ 25, 50);
2662 end else g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2665 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2670 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2671 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2673 FSawSoundSelect
.Stop();
2675 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2677 else if not FSawSoundHit
.IsPlaying() then
2679 FSawSoundSelect
.Stop();
2680 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2683 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2689 if FAmmo
[A_BULLETS
] > 0 then
2691 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2692 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2693 Dec(FAmmo
[A_BULLETS
]);
2694 FFireAngle
:= FAngle
;
2697 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2698 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2702 if FAmmo
[A_SHELLS
] > 0 then
2704 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2705 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
2706 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2707 Dec(FAmmo
[A_SHELLS
]);
2708 FFireAngle
:= FAngle
;
2712 FShellType
:= SHELL_SHELL
;
2716 if FAmmo
[A_SHELLS
] >= 2 then
2718 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
2719 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2720 Dec(FAmmo
[A_SHELLS
], 2);
2721 FFireAngle
:= FAngle
;
2725 FShellType
:= SHELL_DBLSHELL
;
2729 if FAmmo
[A_BULLETS
] > 0 then
2731 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
2732 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
2733 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2734 Dec(FAmmo
[A_BULLETS
]);
2735 FFireAngle
:= FAngle
;
2738 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2739 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2742 WEAPON_ROCKETLAUNCHER
:
2743 if FAmmo
[A_ROCKETS
] > 0 then
2745 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
2746 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2747 Dec(FAmmo
[A_ROCKETS
]);
2748 FFireAngle
:= FAngle
;
2754 if FAmmo
[A_CELLS
] > 0 then
2756 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
2757 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2758 Dec(FAmmo
[A_CELLS
]);
2759 FFireAngle
:= FAngle
;
2765 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
2767 FBFGFireCounter
:= 17;
2768 if not FNoReload
then
2769 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
2770 Dec(FAmmo
[A_CELLS
], 40);
2774 WEAPON_SUPERPULEMET
:
2775 if FAmmo
[A_SHELLS
] > 0 then
2777 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2778 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
2779 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2780 Dec(FAmmo
[A_SHELLS
]);
2781 FFireAngle
:= FAngle
;
2784 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2785 GameVelX
, GameVelY
-2, SHELL_SHELL
);
2789 if g_Game_IsNet
then
2793 if FCurrWeap
<> WEAPON_BFG
then
2794 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
2796 if not FNoReload
then
2797 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
2800 MH_SEND_PlayerStats(FUID
);
2805 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
2806 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
2807 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
2810 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
2813 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
2814 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
2815 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
2816 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
2821 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
2823 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
2824 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
2825 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
2828 procedure TPlayer
.JetpackOn
;
2832 FJetSoundOn
.SetPosition(0);
2833 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
2837 procedure TPlayer
.JetpackOff
;
2841 FJetSoundOff
.SetPosition(0);
2842 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
2845 procedure TPlayer
.Jump();
2847 if gFly
or FJetpack
then
2849 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
2850 if FObj
.Vel
.Y
> -VEL_FLY
then
2851 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
2854 if FJetFuel
> 0 then
2856 if (FJetFuel
< 1) and g_Game_IsServer
then
2860 if g_Game_IsNet
then
2861 MH_SEND_PlayerStats(FUID
);
2867 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
2869 FCanJetpack
:= False;
2871 // Ïðûãàåì èëè âñïëûâàåì:
2872 if (CollideLevel(0, 1) or
2873 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
2874 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
2875 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
2877 FObj
.Vel
.Y
:= -VEL_JUMP
;
2878 FCanJetpack
:= False;
2882 if BodyInLiquid(0, 0) then
2883 FObj
.Vel
.Y
:= -VEL_SW
2884 else if (FJetFuel
> 0) and FCanJetpack
and
2885 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
2889 if g_Game_IsNet
then
2890 MH_SEND_PlayerStats(FUID
);
2895 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
2897 a
, i
, k
, ab
, ar
: Byte;
2901 srv
, netsrv
: Boolean;
2906 procedure PushItem(t
: Byte);
2910 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
2911 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
2912 g_Obj_Push(@gItems
[id
].Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
2913 (FObj
.Vel
.Y
div 2)-Random(9))
2915 if KillType
= K_HARDKILL
then // -5..+5; -5..0
2916 g_Obj_Push(@gItems
[id
].Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
2917 (FObj
.Vel
.Y
div 2)-Random(6))
2918 else // -3..+3; -3..0
2919 g_Obj_Push(@gItems
[id
].Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
2920 (FObj
.Vel
.Y
div 2)-Random(4));
2922 if g_Game_IsNet
and g_Game_IsServer
then
2923 MH_SEND_ItemSpawn(True, id
);
2927 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
2928 Srv
:= g_Game_IsServer
;
2929 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
2930 if Srv
then FDeath
:= FDeath
+ 1;
2935 if not FPhysics
then
2941 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2943 if FLives
> 0 then FLives
:= FLives
- 1;
2944 if FLives
= 0 then FNoRespawn
:= True;
2947 // Íîìåð òèïà ñìåðòè:
2950 K_SIMPLEKILL
: a
:= 1;
2952 K_EXTRAHARDKILL
: a
:= 3;
2957 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
2959 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
2966 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
2968 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
2969 K_EXTRAHARDKILL
, K_FALLKILL
:
2970 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
2973 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
2977 K_HARDKILL
, K_EXTRAHARDKILL
:
2981 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
2982 if (KillType
<> K_FALLKILL
) and (Srv
) then
2983 g_Monsters_killedp();
2985 if SpawnerUID
= FUID
then
2987 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
2992 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
2995 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
2996 begin // Óáèò äðóãèì èãðîêîì
2997 KP
:= g_Player_Get(SpawnerUID
);
2998 if (KP
<> nil) and Srv
then
3000 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3001 if SameTeam(FUID
, SpawnerUID
) then
3011 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3012 Inc(gTeamStat
[KP
.Team
].Goals
,
3013 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3015 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3018 plr
:= g_Player_Get(SpawnerUID
);
3026 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3030 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3034 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3039 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3040 begin // Óáèò ìîíñòðîì
3041 mon
:= g_Monsters_Get(SpawnerUID
);
3045 s
:= g_Monsters_GetKilledBy(mon
.MonsterType
);
3049 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3053 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3057 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3062 else // Îñîáûå òèïû ñìåðòè
3065 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3066 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3067 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3068 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3069 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3070 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3076 for a
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
3080 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3081 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3082 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3083 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3084 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3085 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3086 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3087 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3096 if R_ITEM_BACKPACK
in FRulez
then
3097 PushItem(ITEM_AMMO_BACKPACK
);
3099 // Âûáðîñ ðàêåòíîãî ðàíöà:
3100 if FJetFuel
> 0 then
3101 PushItem(ITEM_JETPACK
);
3104 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3106 if R_KEY_RED
in FRulez
then
3107 PushItem(ITEM_KEY_RED
);
3109 if R_KEY_GREEN
in FRulez
then
3110 PushItem(ITEM_KEY_GREEN
);
3112 if R_KEY_BLUE
in FRulez
then
3113 PushItem(ITEM_KEY_BLUE
);
3120 g_Player_CreateCorpse(Self
);
3122 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3123 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3129 for i
:= Low(gPlayers
) to High(gPlayers
) do
3131 if gPlayers
[i
] = nil then continue
;
3132 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3135 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3136 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3141 OldLR
:= gLMSRespawn
;
3142 if (gGameSettings
.GameMode
= GM_COOP
) then
3146 // everyone is dead, restart the map
3147 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3149 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3150 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3151 gLMSRespawnTime
:= gTime
+ 5000;
3153 else if (a
= 1) then
3155 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3156 if (gPlayers
[k
] = gPlayer1
) or
3157 (gPlayers
[k
] = gPlayer2
) then
3158 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3159 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3160 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3163 else if (gGameSettings
.GameMode
= GM_TDM
) then
3165 if (ab
= 0) and (ar
<> 0) then
3168 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3170 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3171 Inc(gTeamStat
[TEAM_RED
].Goals
);
3172 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3173 gLMSRespawnTime
:= gTime
+ 5000;
3175 else if (ar
= 0) and (ab
<> 0) then
3178 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3180 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3181 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3182 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3183 gLMSRespawnTime
:= gTime
+ 5000;
3185 else if (ar
= 0) and (ab
= 0) then
3188 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3190 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3191 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3192 gLMSRespawnTime
:= gTime
+ 5000;
3195 else if (gGameSettings
.GameMode
= GM_DM
) then
3199 if gPlayers
[k
] <> nil then
3202 // survivor is the winner
3203 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3205 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3208 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3209 gLMSRespawnTime
:= gTime
+ 5000;
3211 else if (a
= 0) then
3213 // everyone is dead, restart the map
3214 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3216 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3217 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3218 gLMSRespawnTime
:= gTime
+ 5000;
3221 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3223 if NetMode
= NET_SERVER
then
3224 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3226 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3232 MH_SEND_PlayerStats(FUID
);
3233 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3234 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3237 if srv
and FNoRespawn
then Spectate(True);
3238 FWantsInGame
:= True;
3241 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3243 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3244 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3247 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3249 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3250 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3253 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3255 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3256 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3257 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3259 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3260 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3261 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3265 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3267 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3268 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3269 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3273 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3275 if g_Game_IsClient
then Exit
;
3276 if Weapon
> High(FWeapon
) then Exit
;
3277 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3280 procedure TPlayer
.resetWeaponQueue ();
3283 FNextWeapDelay
:= 0;
3286 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3290 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3291 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 0);
3292 WEAPON_PISTOL
, WEAPON_CHAINGUN
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_BULLETS
] > 0);
3293 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3294 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3295 else result
:= (weapon
< length(FWeapon
));
3299 // return 255 for "no switch"
3300 function TPlayer
.getNextWeaponIndex (): Byte;
3303 wantThisWeapon
: array[0..64] of Boolean;
3304 wwc
: Integer = 0; //HACK!
3306 result
:= 255; // default result: "no switch"
3307 for i
:= 0 to High(wantThisWeapon
) do wantThisWeapon
[i
] := false;
3308 for i
:= 0 to High(FWeapon
) do if (FNextWeap
and (1 shl i
)) <> 0 then begin wantThisWeapon
[i
] := true; Inc(wwc
); end;
3309 // exclude currently selected weapon from the set
3310 wantThisWeapon
[FCurrWeap
] := false;
3311 // slow down alterations a little
3314 // more than one weapon requested, assume "alteration" and check alteration delay
3315 if FNextWeapDelay
> 0 then begin FNextWeap
:= 0; exit
; end; // yeah
3317 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3318 if wwc
< 1 then begin resetWeaponQueue(); exit
; end;
3319 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3320 // try weapons in descending order
3321 for i
:= High(FWeapon
) downto 0 do
3323 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3330 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3334 procedure TPlayer
.RealizeCurrentWeapon();
3338 nw
:= getNextWeaponIndex();
3339 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3340 if nw
= 255 then exit
; // don't reset anything here
3341 if nw
> High(FWeapon
) then begin resetWeaponQueue(); exit
; end; // don't forget to reset queue here!
3343 if FBFGFireCounter
<> -1 then exit
;
3344 if FTime
[T_SWITCH
] > gTime
then exit
;
3346 for i
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do if FReloading
[i
] > 0 then exit
;
3351 FTime
[T_SWITCH
] := gTime
+156;
3352 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3353 FModel
.SetWeapon(FCurrWeap
);
3354 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3356 // reset weapon queue; `getNextWeaponIndex()` guarantees to not select a weapon player don't have
3358 FNextWeapDelay
:= 10; // anyway, 'cause why not
3361 procedure TPlayer
.cycleWeapon (dir
: Integer);
3365 if dir
< 0 then dir
:= -1 else if dir
> 0 then dir
:= 1 else exit
;
3367 for i
:= 0 to High(FWeapon
) do
3369 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3370 if FWeapon
[cwi
] then
3372 QueueWeaponSwitch(Byte(cwi
));
3378 procedure TPlayer
.NextWeapon();
3380 if g_Game_IsClient
then Exit
;
3384 procedure TPlayer
.PrevWeapon();
3386 if g_Game_IsClient
then Exit
;
3390 procedure TPlayer
.SetWeapon(W
: Byte);
3392 if FCurrWeap
<> W
then
3393 if W
= WEAPON_SAW
then
3394 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3397 FModel
.SetWeapon(CurrWeap
);
3401 function TPlayer
.PickItem(ItemType
: Byte; respawn
: Boolean; var remove
: Boolean): Boolean;
3406 if g_Game_IsClient
then Exit
;
3408 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3409 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and respawn
;
3414 if FHealth
< PLAYER_HP_SOFT
then
3416 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3419 if gFlash
= 2 then Inc(FPickup
, 5);
3423 if FHealth
< PLAYER_HP_SOFT
then
3425 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3428 if gFlash
= 2 then Inc(FPickup
, 5);
3432 if FArmor
< PLAYER_AP_SOFT
then
3434 FArmor
:= PLAYER_AP_SOFT
;
3437 if gFlash
= 2 then Inc(FPickup
, 5);
3441 if FArmor
< PLAYER_AP_LIMIT
then
3443 FArmor
:= PLAYER_AP_LIMIT
;
3446 if gFlash
= 2 then Inc(FPickup
, 5);
3450 if FHealth
< PLAYER_HP_LIMIT
then
3452 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3455 if gFlash
= 2 then Inc(FPickup
, 5);
3459 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3461 if FHealth
< PLAYER_HP_LIMIT
then
3462 FHealth
:= PLAYER_HP_LIMIT
;
3463 if FArmor
< PLAYER_AP_LIMIT
then
3464 FArmor
:= PLAYER_AP_LIMIT
;
3467 if gFlash
= 2 then Inc(FPickup
, 5);
3471 if (not FWeapon
[WEAPON_SAW
]) or ((not respawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3473 FWeapon
[WEAPON_SAW
] := True;
3475 if gFlash
= 2 then Inc(FPickup
, 5);
3476 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3479 ITEM_WEAPON_SHOTGUN1
:
3480 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3482 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3483 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3485 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3486 FWeapon
[WEAPON_SHOTGUN1
] := True;
3488 if gFlash
= 2 then Inc(FPickup
, 5);
3489 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3492 ITEM_WEAPON_SHOTGUN2
:
3493 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3495 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3497 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3498 FWeapon
[WEAPON_SHOTGUN2
] := True;
3500 if gFlash
= 2 then Inc(FPickup
, 5);
3501 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3504 ITEM_WEAPON_CHAINGUN
:
3505 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3507 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3509 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3510 FWeapon
[WEAPON_CHAINGUN
] := True;
3512 if gFlash
= 2 then Inc(FPickup
, 5);
3513 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3516 ITEM_WEAPON_ROCKETLAUNCHER
:
3517 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3519 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3521 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3522 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3524 if gFlash
= 2 then Inc(FPickup
, 5);
3525 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3529 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3531 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3533 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3534 FWeapon
[WEAPON_PLASMA
] := True;
3536 if gFlash
= 2 then Inc(FPickup
, 5);
3537 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3541 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3543 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3545 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3546 FWeapon
[WEAPON_BFG
] := True;
3548 if gFlash
= 2 then Inc(FPickup
, 5);
3549 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3552 ITEM_WEAPON_SUPERPULEMET
:
3553 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3555 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3557 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3558 FWeapon
[WEAPON_SUPERPULEMET
] := True;
3560 if gFlash
= 2 then Inc(FPickup
, 5);
3561 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3565 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3567 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3570 if gFlash
= 2 then Inc(FPickup
, 5);
3573 ITEM_AMMO_BULLETS_BOX
:
3574 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3576 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3579 if gFlash
= 2 then Inc(FPickup
, 5);
3583 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3585 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3588 if gFlash
= 2 then Inc(FPickup
, 5);
3591 ITEM_AMMO_SHELLS_BOX
:
3592 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3594 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
3597 if gFlash
= 2 then Inc(FPickup
, 5);
3601 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3603 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3606 if gFlash
= 2 then Inc(FPickup
, 5);
3609 ITEM_AMMO_ROCKET_BOX
:
3610 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3612 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
3615 if gFlash
= 2 then Inc(FPickup
, 5);
3619 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3621 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3624 if gFlash
= 2 then Inc(FPickup
, 5);
3628 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3630 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
3633 if gFlash
= 2 then Inc(FPickup
, 5);
3637 if not(R_ITEM_BACKPACK
in FRulez
) or
3638 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
3639 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
3640 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
3641 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) then
3643 FMaxAmmo
[A_BULLETS
] := 400;
3644 FMaxAmmo
[A_SHELLS
] := 100;
3645 FMaxAmmo
[A_ROCKETS
] := 100;
3646 FMaxAmmo
[A_CELLS
] := 600;
3648 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3649 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3650 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3651 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3652 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3653 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3654 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3655 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3657 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
3660 if gFlash
= 2 then Inc(FPickup
, 5);
3664 if not(R_KEY_RED
in FRulez
) then
3666 Include(FRulez
, R_KEY_RED
);
3668 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3669 if gFlash
= 2 then Inc(FPickup
, 5);
3670 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3674 if not(R_KEY_GREEN
in FRulez
) then
3676 Include(FRulez
, R_KEY_GREEN
);
3678 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3679 if gFlash
= 2 then Inc(FPickup
, 5);
3680 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3684 if not(R_KEY_BLUE
in FRulez
) then
3686 Include(FRulez
, R_KEY_BLUE
);
3688 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3689 if gFlash
= 2 then Inc(FPickup
, 5);
3690 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3694 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
3696 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
3699 if gFlash
= 2 then Inc(FPickup
, 5);
3703 if FAir
< AIR_MAX
then
3708 if gFlash
= 2 then Inc(FPickup
, 5);
3713 if not (R_BERSERK
in FRulez
) then
3715 Include(FRulez
, R_BERSERK
);
3716 if FBFGFireCounter
= -1 then
3718 FCurrWeap
:= WEAPON_KASTET
;
3720 FModel
.SetWeapon(WEAPON_KASTET
);
3724 if gFlash
= 2 then Inc(FPickup
, 5);
3725 FBerserk
:= gTime
+30000;
3729 if FHealth
< PLAYER_HP_SOFT
then
3731 FHealth
:= PLAYER_HP_SOFT
;
3732 FBerserk
:= gTime
+30000;
3739 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
3741 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
3744 if gFlash
= 2 then Inc(FPickup
, 5);
3748 if FHealth
< PLAYER_HP_LIMIT
then
3750 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
3753 if gFlash
= 2 then Inc(FPickup
, 5);
3757 if FArmor
< PLAYER_AP_LIMIT
then
3759 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
3762 if gFlash
= 2 then Inc(FPickup
, 5);
3766 if FJetFuel
< JET_MAX
then
3768 FJetFuel
:= JET_MAX
;
3771 if gFlash
= 2 then Inc(FPickup
, 5);
3775 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
3777 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
3780 if gFlash
= 2 then Inc(FPickup
, 5);
3785 procedure TPlayer
.Touch();
3789 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
3792 // Áðîñèòü ôëàã òîâàðèùó:
3793 if gGameSettings
.GameMode
= GM_CTF
then
3798 procedure TPlayer
.Push(vx
, vy
: Integer);
3800 if (not FPhysics
) and FGhost
then
3802 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
3803 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
3804 if g_Game_IsNet
and g_Game_IsServer
then
3805 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
3808 procedure TPlayer
.Reset(Force
: Boolean);
3814 FTime
[T_RESPAWN
] := 0;
3815 FTime
[T_FLAGCAP
] := 0;
3828 FSpectator
:= False;
3831 FSpectatePlayer
:= -1;
3832 FNoRespawn
:= False;
3834 FLives
:= gGameSettings
.MaxLives
;
3839 procedure TPlayer
.SoftReset();
3845 FBFGFireCounter
:= -1;
3853 SetAction(A_STAND
, True);
3856 function TPlayer
.GetRespawnPoint(): Byte;
3861 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
3863 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
3864 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
3866 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
3868 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
3869 if Self
= gPlayer1
then
3870 c
:= RESPAWNPOINT_PLAYER1
3872 c
:= RESPAWNPOINT_PLAYER2
;
3873 if g_Map_GetPointCount(c
) > 0 then
3879 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
3880 if Self
= gPlayer1
then
3881 c
:= RESPAWNPOINT_PLAYER2
3883 c
:= RESPAWNPOINT_PLAYER1
;
3884 if g_Map_GetPointCount(c
) > 0 then
3891 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
3892 if Random(2) = 0 then
3893 c
:= RESPAWNPOINT_PLAYER1
3895 c
:= RESPAWNPOINT_PLAYER2
;
3896 if g_Map_GetPointCount(c
) > 0 then
3903 // Òî÷êà ëþáîé èç êîìàíä
3904 if Random(2) = 0 then
3905 c
:= RESPAWNPOINT_RED
3907 c
:= RESPAWNPOINT_BLUE
;
3908 if g_Map_GetPointCount(c
) > 0 then
3915 c
:= RESPAWNPOINT_DM
;
3916 if g_Map_GetPointCount(c
) > 0 then
3924 if gGameSettings
.GameMode
= GM_DM
then
3927 c
:= RESPAWNPOINT_DM
;
3928 if g_Map_GetPointCount(c
) > 0 then
3934 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
3935 if Random(2) = 0 then
3936 c
:= RESPAWNPOINT_PLAYER1
3938 c
:= RESPAWNPOINT_PLAYER2
;
3939 if g_Map_GetPointCount(c
) > 0 then
3945 // Òî÷êà ëþáîé èç êîìàíä
3946 if Random(2) = 0 then
3947 c
:= RESPAWNPOINT_RED
3949 c
:= RESPAWNPOINT_BLUE
;
3950 if g_Map_GetPointCount(c
) > 0 then
3958 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
3960 // Òî÷êà ñâîåé êîìàíäû
3961 c
:= RESPAWNPOINT_DM
;
3962 if FTeam
= TEAM_RED
then
3963 c
:= RESPAWNPOINT_RED
;
3964 if FTeam
= TEAM_BLUE
then
3965 c
:= RESPAWNPOINT_BLUE
;
3966 if g_Map_GetPointCount(c
) > 0 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 c
:= RESPAWNPOINT_DM
;
3993 if FTeam
= TEAM_RED
then
3994 c
:= RESPAWNPOINT_BLUE
;
3995 if FTeam
= TEAM_BLUE
then
3996 c
:= RESPAWNPOINT_RED
;
3997 if g_Map_GetPointCount(c
) > 0 then
4005 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4007 RespawnPoint
: TRespawnPoint
;
4012 if not g_Game_IsServer
then
4016 FWantsInGame
:= True;
4017 FJustTeleported
:= True;
4020 FTime
[T_RESPAWN
] := 0;
4024 // if server changes MaxLives we gotta be ready
4025 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4027 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4028 if FTime
[T_RESPAWN
] > gTime
then
4031 // Ïðîñðàë âñå æèçíè:
4034 if not FSpectator
then Spectate(True);
4035 FWantsInGame
:= True;
4039 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4040 begin // "Ñâîÿ èãðà"
4041 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4042 FRulez
:= FRulez
-[R_BERSERK
];
4044 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4046 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4047 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4050 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4051 c
:= GetRespawnPoint();
4056 // Âîñêðåøåíèå áåç îðóæèÿ:
4059 FHealth
:= PLAYER_HP_SOFT
;
4065 for a
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
4067 FWeapon
[a
] := False;
4071 FWeapon
[WEAPON_PISTOL
] := True;
4072 FWeapon
[WEAPON_KASTET
] := True;
4073 FCurrWeap
:= WEAPON_PISTOL
;
4076 FModel
.SetWeapon(FCurrWeap
);
4078 for b
:= A_BULLETS
to A_CELLS
do
4081 FAmmo
[A_BULLETS
] := 50;
4083 FMaxAmmo
[A_BULLETS
] := 200;
4084 FMaxAmmo
[A_SHELLS
] := 50;
4085 FMaxAmmo
[A_ROCKETS
] := 50;
4086 FMaxAmmo
[A_CELLS
] := 300;
4088 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4089 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4094 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4095 if not g_Map_GetPoint(c
, RespawnPoint
) then
4097 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4101 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4102 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4103 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4109 FDirection
:= RespawnPoint
.Direction
;
4110 if FDirection
= D_LEFT
then
4116 FBFGFireCounter
:= -1;
4121 SetAction(A_STAND
, True);
4122 FModel
.Direction
:= FDirection
;
4124 for a
:= Low(FTime
) to High(FTime
) do
4127 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4132 FCanJetpack
:= False;
4134 // Àíèìàöèÿ âîçðîæäåíèÿ:
4135 if (not gLoadGameMode
) and (not Silent
) then
4136 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4138 Anim
:= TAnimation
.Create(ID
, False, 3);
4139 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4140 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4144 FSpectator
:= False;
4147 FSpectatePlayer
:= -1;
4150 if g_Game_IsNet
then
4152 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4153 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4155 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4156 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4161 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4164 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4165 else if (not NoMove
) then
4167 GameX
:= gMapInfo
.Width
div 2;
4168 GameY
:= gMapInfo
.Height
div 2;
4177 FWantsInGame
:= False;
4182 if Self
= gPlayer1
then
4187 if Self
= gPlayer2
then
4194 if g_Game_IsNet
then
4195 MH_SEND_PlayerStats(FUID
);
4198 procedure TPlayer
.SwitchNoClip
;
4202 FGhost
:= not FGhost
;
4203 FPhysics
:= not FGhost
;
4215 procedure TPlayer
.Run(Direction
: TDirection
);
4219 if MAX_RUNVEL
> 8 then
4223 if Direction
= D_LEFT
then
4225 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4226 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4229 if FObj
.Vel
.X
< MAX_RUNVEL
then
4230 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4232 // Âîçìîæíî, ïèíàåì êóñêè:
4233 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4235 b
:= Abs(FObj
.Vel
.X
);
4236 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4237 for a
:= 0 to High(gGibs
) do
4238 if gGibs
[a
].Live
and
4239 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4240 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4242 if FObj
.Vel
.X
< 0 then
4243 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4245 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4251 procedure TPlayer
.SeeDown();
4253 SetAction(A_SEEDOWN
);
4255 if FDirection
= D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4257 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4260 procedure TPlayer
.SeeUp();
4264 if FDirection
= D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4266 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4269 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4277 A_ATTACK
: Prior
:= 2;
4278 A_SEEUP
: Prior
:= 1;
4279 A_SEEDOWN
: Prior
:= 1;
4280 A_ATTACKUP
: Prior
:= 2;
4281 A_ATTACKDOWN
: Prior
:= 2;
4286 if (Prior
> FActionPrior
) or Force
then
4287 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4289 FActionPrior
:= Prior
;
4290 FActionAnim
:= Action
;
4291 FActionForce
:= Force
;
4292 FActionChanged
:= True;
4295 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4298 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4300 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4301 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4302 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4303 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4306 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4313 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4315 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4316 if g_Game_IsServer
and g_Game_IsNet
then
4317 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4321 FJustTeleported
:= True;
4326 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4328 Anim
:= TAnimation
.Create(ID
, False, 3);
4331 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4332 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4333 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4334 if g_Game_IsServer
and g_Game_IsNet
then
4335 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4336 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4340 FObj
.X
:= X
-PLAYER_RECT
.X
;
4341 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4342 if FLive
and FGhost
then
4348 if not g_Game_IsNet
then
4352 SetDirection(D_LEFT
);
4358 SetDirection(D_RIGHT
);
4364 if FDirection
= D_RIGHT
then
4366 SetDirection(D_LEFT
);
4371 SetDirection(D_RIGHT
);
4377 if not silent
and (Anim
<> nil) then
4379 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4380 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4383 if g_Game_IsServer
and g_Game_IsNet
then
4384 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4385 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4392 function nonz(a
: Single): Single;
4400 procedure TPlayer
.Update();
4403 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4404 blockmon
, headwater
, dospawn
: Boolean;
4409 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4410 AnyServer
:= g_Game_IsServer
;
4412 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4413 DoLerp(NetInterpLevel
+ 1)
4419 if FClientID
>= 0 then
4421 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4422 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4423 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4432 if FLive
and (gFly
or FJetpack
) then
4435 if FDirection
= D_LEFT
then
4440 if FLive
and (not FGhost
) then
4442 if FKeys
[KEY_UP
].Pressed
then
4444 if FKeys
[KEY_DOWN
].Pressed
then
4448 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4451 i
:= g_basic
.Sign(FIncCam
);
4452 FIncCam
:= Abs(FIncCam
);
4453 DecMin(FIncCam
, 5, 0);
4454 FIncCam
:= FIncCam
*i
;
4457 if gTime
mod (GAME_TICK
*2) <> 0 then
4459 if (FObj
.Vel
.X
= 0) and FLive
then
4461 if FKeys
[KEY_LEFT
].Pressed
then
4463 if FKeys
[KEY_RIGHT
].Pressed
then
4468 g_Obj_Move(@FObj
, True, True, True);
4473 FActionChanged
:= False;
4477 // Let alive player do some actions
4478 if FKeys
[KEY_LEFT
].Pressed
then Run(D_LEFT
);
4479 if FKeys
[KEY_RIGHT
].Pressed
then Run(D_RIGHT
);
4480 if FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4481 if FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4482 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
4483 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
4484 if FKeys
[KEY_JUMP
].Pressed
then Jump()
4487 if AnyServer
and FJetpack
then
4491 if NetServer
then MH_SEND_PlayerStats(FUID
);
4493 FCanJetpack
:= True;
4500 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
4502 if FKeys
[k
].Pressed
then
4510 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4513 if (FTime
[T_RESPAWN
] <= gTime
) and
4514 gGameOn
and (not FLive
) then
4516 if (g_Player_GetCount() > 1) then
4520 gExit
:= EXIT_RESTART
;
4525 // Dead spectator actions
4528 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
4529 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
4533 if (FSpectatePlayer
>= High(gPlayers
)) then
4534 FSpectatePlayer
:= -1
4538 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
4539 if gPlayers
[I
] <> nil then
4540 if gPlayers
[I
].Live
then
4541 if gPlayers
[I
].UID
<> FUID
then
4543 FSpectatePlayer
:= I
;
4548 if not SetSpect
then FSpectatePlayer
:= -1;
4559 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
4561 FYTo
:= FObj
.Y
- 32;
4562 FSpectatePlayer
:= -1;
4564 if FKeys
[KEY_DOWN
].Pressed
then
4566 FYTo
:= FObj
.Y
+ 32;
4567 FSpectatePlayer
:= -1;
4569 if FKeys
[KEY_LEFT
].Pressed
then
4571 FXTo
:= FObj
.X
- 32;
4572 FSpectatePlayer
:= -1;
4574 if FKeys
[KEY_RIGHT
].Pressed
then
4576 FXTo
:= FObj
.X
+ 32;
4577 FSpectatePlayer
:= -1;
4580 if (FXTo
< -64) then
4582 else if (FXTo
> gMapInfo
.Width
+ 32) then
4583 FXTo
:= gMapInfo
.Width
+ 32;
4584 if (FYTo
< -72) then
4586 else if (FYTo
> gMapInfo
.Height
+ 32) then
4587 FYTo
:= gMapInfo
.Height
+ 32;
4591 g_Obj_Move(@FObj
, True, True, True)
4597 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
4598 if gPlayers
[FSpectatePlayer
] <> nil then
4599 if gPlayers
[FSpectatePlayer
].Live
then
4601 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
4602 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
4606 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
4607 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
4608 PANEL_BLOCKMON
, True);
4609 headwater
:= HeadInLiquid(0, 0);
4611 // Ñîïðîòèâëåíèå âîçäóõà:
4612 if (not FLive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
4613 if FObj
.Vel
.X
<> 0 then
4614 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
4616 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
4617 DecMin(FPain
, 5, 0);
4618 DecMin(FPickup
, 1, 0);
4620 if FLive
and (FObj
.Y
> gMapInfo
.Height
+128) and AnyServer
then
4622 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
4623 FMegaRulez
[MR_SUIT
] := 0;
4624 FMegaRulez
[MR_INVUL
] := 0;
4625 FMegaRulez
[MR_INVIS
] := 0;
4626 Kill(K_FALLKILL
, 0, HIT_FALL
);
4633 if FCurrWeap
= WEAPON_SAW
then
4634 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
4635 FSawSoundSelect
.IsPlaying()) then
4636 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
4639 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
4640 (not FJetSoundOff
.IsPlaying()) then
4642 FJetSoundFly
.SetPosition(0);
4643 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
4646 for b
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
4647 if FReloading
[b
] > 0 then
4653 if FShellTimer
> -1 then
4654 if FShellTimer
= 0 then
4656 if FShellType
= SHELL_SHELL
then
4657 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4658 GameVelX
, GameVelY
-2, SHELL_SHELL
)
4659 else if FShellType
= SHELL_DBLSHELL
then
4661 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4662 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
4663 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4664 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
4667 end else Dec(FShellTimer
);
4669 if (FBFGFireCounter
> -1) then
4670 if FBFGFireCounter
= 0 then
4674 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
4675 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
4676 xd
:= wx
+IfThen(FDirection
= D_LEFT
, -30, 30);
4677 yd
:= wy
+firediry();
4678 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
4679 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
4680 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
4681 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
4682 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
4685 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
4686 FBFGFireCounter
:= -1;
4689 FBFGFireCounter
:= 0
4691 Dec(FBFGFireCounter
);
4693 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
4695 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
4697 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
4700 if (headwater
or blockmon
) then
4706 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
4709 else if (FAir
mod 31 = 0) and not blockmon
then
4711 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
4712 if Random(2) = 0 then
4713 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
4715 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
4717 end else if FAir
< AIR_DEF
then
4720 if FDamageBuffer
> 0 then
4722 if FDamageBuffer
>= 9 then
4726 if FDamageBuffer
< 30 then i
:= 9
4727 else if FDamageBuffer
< 100 then i
:= 18
4731 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
4732 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
4733 FHealth
:= FHealth
-ii
;
4736 FHealth
:= FHealth
+FArmor
;
4741 if FHealth
<= 0 then
4742 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
4743 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
4744 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
4748 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
4749 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
4750 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
4751 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
4758 end; // if FLive then ...
4760 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
4762 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
4763 FModel
.GetCurrentAnimation
.MinLength
:= i
;
4764 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
4765 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
4767 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
4768 then SetAction(A_STAND
, True);
4770 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
4772 for b
:= Low(FKeys
) to High(FKeys
) do
4773 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
4776 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
4778 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
4779 FObj
.Y
+PLAYER_RECT
.Y
,
4786 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
4788 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
4789 FObj
.Y
+PLAYER_RECT
.Y
,
4793 Panel
.Width
, Panel
.Height
);
4796 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
4798 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
4799 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
4800 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
4801 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
4804 function g_Player_ValidName(Name
: string): Boolean;
4810 if gPlayers
= nil then Exit
;
4812 for a
:= 0 to High(gPlayers
) do
4813 if gPlayers
[a
] <> nil then
4814 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
4821 procedure TPlayer
.SetDirection(Direction
: TDirection
);
4825 d
:= FModel
.Direction
;
4827 FModel
.Direction
:= Direction
;
4828 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
4830 FDirection
:= Direction
;
4833 function TPlayer
.GetKeys(): Byte;
4837 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
4838 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
4839 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
4841 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
4842 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
4845 procedure TPlayer
.Use();
4849 if FTime
[T_USE
] > gTime
then Exit
;
4851 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
4852 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
4854 for a
:= 0 to High(gPlayers
) do
4855 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
4856 gPlayers
[a
].Live
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
4857 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
4858 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
4860 gPlayers
[a
].Touch();
4861 if g_Game_IsNet
and g_Game_IsServer
then
4862 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
4865 FTime
[T_USE
] := gTime
+120;
4868 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
4872 WX
, WY
, XD
, YD
: Integer;
4883 if R_BERSERK
in FRulez
then
4885 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
4886 obj
.X
:= FObj
.X
+FObj
.Rect
.X
;
4887 obj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
4890 obj
.rect
.Width
:= 39;
4891 obj
.rect
.Height
:= 52;
4892 obj
.Vel
.X
:= (xd
-wx
) div 2;
4893 obj
.Vel
.Y
:= (yd
-wy
) div 2;
4894 obj
.Accel
.X
:= xd
-wx
;
4895 obj
.Accel
.y
:= yd
-wy
;
4897 if g_Weapon_Hit(@obj
, 50, FUID
, HIT_SOME
) <> 0 then
4898 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
4900 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
4904 FPain
:= min(FPain
+ 25, 50);
4906 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
4911 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
4912 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
4914 FSawSoundSelect
.Stop();
4916 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
4918 else if not FSawSoundHit
.IsPlaying() then
4920 FSawSoundSelect
.Stop();
4921 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
4928 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
4929 FFireAngle
:= FAngle
;
4931 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4932 GameVelX
, GameVelY
-2, SHELL_BULLET
);
4937 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
4938 FFireAngle
:= FAngle
;
4941 FShellType
:= SHELL_SHELL
;
4946 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
4947 FFireAngle
:= FAngle
;
4950 FShellType
:= SHELL_DBLSHELL
;
4955 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
4956 FFireAngle
:= FAngle
;
4958 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4959 GameVelX
, GameVelY
-2, SHELL_BULLET
);
4962 WEAPON_ROCKETLAUNCHER
:
4964 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
4965 FFireAngle
:= FAngle
;
4971 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
4972 FFireAngle
:= FAngle
;
4978 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
4979 FFireAngle
:= FAngle
;
4983 WEAPON_SUPERPULEMET
:
4985 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
4986 FFireAngle
:= FAngle
;
4988 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4989 GameVelX
, GameVelY
-2, SHELL_SHELL
);
4995 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
4996 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
4997 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5000 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5002 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5003 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5006 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5010 if NetInterpLevel
< 1 then
5020 AX
:= Abs(FXTo
- FObj
.X
);
5021 AY
:= Abs(FYTo
- FObj
.Y
);
5022 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5024 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5029 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5031 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5032 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5033 PANEL_LIFTUP
, False) then Result
:= -1
5035 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5036 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5037 PANEL_LIFTDOWN
, False) then Result
:= 1
5041 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5048 if Flag
= FLAG_NONE
then
5051 if not g_Game_IsServer
then Exit
;
5053 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5054 if (Flag
= FTeam
) and
5055 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5056 (FFlag
<> FLAG_NONE
) then
5058 if FFlag
= FLAG_RED
then
5059 s
:= _lc
[I_PLAYER_FLAG_RED
]
5061 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5063 evtype
:= FLAG_STATE_SCORED
;
5065 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5066 Insert('.', ts
, Length(ts
) + 1 - 3);
5067 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5069 g_Map_ResetFlag(FFlag
);
5070 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5072 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5075 if g_Game_IsNet
then
5077 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5081 gFlags
[FFlag
].CaptureTime
:= 0;
5086 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5087 if (Flag
= FTeam
) and
5088 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5090 if Flag
= FLAG_RED
then
5091 s
:= _lc
[I_PLAYER_FLAG_RED
]
5093 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5095 evtype
:= FLAG_STATE_RETURNED
;
5096 gFlags
[Flag
].CaptureTime
:= 0;
5098 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5100 g_Map_ResetFlag(Flag
);
5101 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5104 if g_Game_IsNet
then
5106 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5112 // Ïîäîáðàë ÷óæîé ôëàã:
5113 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5117 if Flag
= FLAG_RED
then
5118 s
:= _lc
[I_PLAYER_FLAG_RED
]
5120 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5122 evtype
:= FLAG_STATE_CAPTURED
;
5124 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5126 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5128 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5131 if g_Game_IsNet
then
5133 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5139 procedure TPlayer
.SetFlag(Flag
: Byte);
5142 if FModel
<> nil then
5143 FModel
.SetFlag(FFlag
);
5146 function TPlayer
.DropFlag(): Boolean;
5151 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5153 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5154 with gFlags
[FFlag
] do
5158 Direction
:= FDirection
;
5159 State
:= FLAG_STATE_DROPPED
;
5161 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5162 (FObj
.Vel
.Y
div 2)-2+Random(5));
5164 if FFlag
= FLAG_RED
then
5165 s
:= _lc
[I_PLAYER_FLAG_RED
]
5167 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5169 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5170 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5172 if g_Game_IsNet
then
5173 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5179 procedure TPlayer
.GetSecret();
5184 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5186 Assert(Key
<= High(FKeys
));
5188 FKeys
[Key
].Pressed
:= True;
5189 FKeys
[Key
].Time
:= Time
;
5192 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5194 Result
:= FKeys
[K
].Pressed
;
5197 procedure TPlayer
.ReleaseKeys();
5201 for a
:= Low(FKeys
) to High(FKeys
) do
5203 FKeys
[a
].Pressed
:= False;
5208 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5212 function TPlayer
.firediry(): Integer;
5214 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5215 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5219 procedure TPlayer
.RememberState();
5223 FSavedState
.Health
:= FHealth
;
5224 FSavedState
.Armor
:= FArmor
;
5225 FSavedState
.Air
:= FAir
;
5226 FSavedState
.JetFuel
:= FJetFuel
;
5227 FSavedState
.CurrWeap
:= FCurrWeap
;
5228 FSavedState
.NextWeap
:= FNextWeap
;
5229 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5232 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5234 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5236 FSavedState
.Rulez
:= FRulez
;
5237 FSavedState
.WaitRecall
:= True;
5240 procedure TPlayer
.RecallState();
5244 if not FSavedState
.WaitRecall
then Exit
;
5246 FHealth
:= FSavedState
.Health
;
5247 FArmor
:= FSavedState
.Armor
;
5248 FAir
:= FSavedState
.Air
;
5249 FJetFuel
:= FSavedState
.JetFuel
;
5250 FCurrWeap
:= FSavedState
.CurrWeap
;
5251 FNextWeap
:= FSavedState
.NextWeap
;
5252 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5255 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5257 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5259 FRulez
:= FSavedState
.Rulez
;
5260 FSavedState
.WaitRecall
:= False;
5262 if gGameSettings
.GameType
= GT_SERVER
then
5263 MH_SEND_PlayerStats(FUID
);
5266 procedure TPlayer
.SaveState(var Mem
: TBinMemoryWriter
);
5278 Mem
:= TBinMemoryWriter
.Create(i
);
5280 // Ñèãíàòóðà èãðîêà:
5281 sig
:= PLAYER_SIGNATURE
; // 'PLYR'
5282 Mem
.WriteDWORD(sig
);
5284 Mem
.WriteBoolean(FIamBot
);
5286 Mem
.WriteWord(FUID
);
5288 Mem
.WriteString(FName
, 32);
5290 Mem
.WriteByte(FTeam
);
5292 Mem
.WriteBoolean(FLive
);
5293 // Èçðàñõîäîâàë ëè âñå æèçíè:
5294 Mem
.WriteBoolean(FNoRespawn
);
5296 if FDirection
= D_LEFT
then
5302 Mem
.WriteInt(FHealth
);
5304 Mem
.WriteByte(FLives
);
5306 Mem
.WriteInt(FArmor
);
5310 Mem
.WriteInt(FJetFuel
);
5312 Mem
.WriteInt(FPain
);
5314 Mem
.WriteInt(FKills
);
5316 Mem
.WriteInt(FMonsterKills
);
5318 Mem
.WriteInt(FFrags
);
5320 Mem
.WriteByte(FFragCombo
);
5321 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5322 Mem
.WriteDWORD(FLastFrag
);
5324 Mem
.WriteInt(FDeath
);
5325 // Êàêîé ôëàã íåñåò:
5326 Mem
.WriteByte(FFlag
);
5328 Mem
.WriteInt(FSecrets
);
5330 Mem
.WriteByte(FCurrWeap
);
5332 Mem
.WriteWord(FNextWeap
);
5334 Mem
.WriteByte(FNextWeapDelay
);
5335 // Âðåìÿ çàðÿäêè BFG:
5336 Mem
.WriteSmallInt(FBFGFireCounter
);
5338 Mem
.WriteInt(FDamageBuffer
);
5339 // Ïîñëåäíèé óäàðèâøèé:
5340 Mem
.WriteWord(FLastSpawnerUID
);
5341 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5342 Mem
.WriteByte(FLastHit
);
5344 Obj_SaveState(@FObj
, Mem
);
5345 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5346 for i
:= A_BULLETS
to A_CELLS
do
5347 Mem
.WriteWord(FAmmo
[i
]);
5348 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5349 for i
:= A_BULLETS
to A_CELLS
do
5350 Mem
.WriteWord(FMaxAmmo
[i
]);
5352 for i
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
5353 Mem
.WriteBoolean(FWeapon
[i
]);
5354 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5355 for i
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
5356 Mem
.WriteWord(FReloading
[i
]);
5358 if R_ITEM_BACKPACK
in FRulez
then
5363 // Íàëè÷èå êðàñíîãî êëþ÷à:
5364 if R_KEY_RED
in FRulez
then
5369 // Íàëè÷èå çåëåíîãî êëþ÷à:
5370 if R_KEY_GREEN
in FRulez
then
5375 // Íàëè÷èå ñèíåãî êëþ÷à:
5376 if R_KEY_BLUE
in FRulez
then
5381 // Íàëè÷èå áåðñåðêà:
5382 if R_BERSERK
in FRulez
then
5387 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5388 for i
:= MR_SUIT
to MR_MAX
do
5389 Mem
.WriteDWORD(FMegaRulez
[i
]);
5390 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5391 for i
:= T_RESPAWN
to T_FLAGCAP
do
5392 Mem
.WriteDWORD(FTime
[i
]);
5395 Mem
.WriteString(str
);
5405 procedure TPlayer
.LoadState(var Mem
: TBinMemoryReader
);
5415 // Ñèãíàòóðà èãðîêà:
5417 if sig
<> PLAYER_SIGNATURE
then // 'PLYR'
5419 raise EBinSizeError
.Create('TPlayer.LoadState: Wrong Player Signature');
5422 Mem
.ReadBoolean(FIamBot
);
5426 Mem
.ReadString(str
);
5427 if (Self
<> gPlayer1
) and (Self
<> gPlayer2
) then
5430 Mem
.ReadByte(FTeam
);
5432 Mem
.ReadBoolean(FLive
);
5433 // Èçðàñõîäîâàë ëè âñå æèçíè:
5434 Mem
.ReadBoolean(FNoRespawn
);
5438 FDirection
:= D_LEFT
5440 FDirection
:= D_RIGHT
;
5442 Mem
.ReadInt(FHealth
);
5444 Mem
.ReadByte(FLives
);
5446 Mem
.ReadInt(FArmor
);
5450 Mem
.ReadInt(FJetFuel
);
5454 Mem
.ReadInt(FKills
);
5456 Mem
.ReadInt(FMonsterKills
);
5458 Mem
.ReadInt(FFrags
);
5460 Mem
.ReadByte(FFragCombo
);
5461 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5462 Mem
.ReadDWORD(FLastFrag
);
5464 Mem
.ReadInt(FDeath
);
5465 // Êàêîé ôëàã íåñåò:
5466 Mem
.ReadByte(FFlag
);
5468 Mem
.ReadInt(FSecrets
);
5470 Mem
.ReadByte(FCurrWeap
);
5472 Mem
.ReadWord(FNextWeap
);
5474 Mem
.ReadByte(FNextWeapDelay
);
5475 // Âðåìÿ çàðÿäêè BFG:
5476 Mem
.ReadSmallInt(FBFGFireCounter
);
5478 Mem
.ReadInt(FDamageBuffer
);
5479 // Ïîñëåäíèé óäàðèâøèé:
5480 Mem
.ReadWord(FLastSpawnerUID
);
5481 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5482 Mem
.ReadByte(FLastHit
);
5484 Obj_LoadState(@FObj
, Mem
);
5485 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5486 for i
:= A_BULLETS
to A_CELLS
do
5487 Mem
.ReadWord(FAmmo
[i
]);
5488 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5489 for i
:= A_BULLETS
to A_CELLS
do
5490 Mem
.ReadWord(FMaxAmmo
[i
]);
5492 for i
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
5493 Mem
.ReadBoolean(FWeapon
[i
]);
5494 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5495 for i
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
5496 Mem
.ReadWord(FReloading
[i
]);
5500 Include(FRulez
, R_ITEM_BACKPACK
);
5501 // Íàëè÷èå êðàñíîãî êëþ÷à:
5504 Include(FRulez
, R_KEY_RED
);
5505 // Íàëè÷èå çåëåíîãî êëþ÷à:
5508 Include(FRulez
, R_KEY_GREEN
);
5509 // Íàëè÷èå ñèíåãî êëþ÷à:
5512 Include(FRulez
, R_KEY_BLUE
);
5513 // Íàëè÷èå áåðñåðêà:
5516 Include(FRulez
, R_BERSERK
);
5517 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5518 for i
:= MR_SUIT
to MR_MAX
do
5519 Mem
.ReadDWORD(FMegaRulez
[i
]);
5520 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5521 for i
:= T_RESPAWN
to T_FLAGCAP
do
5522 Mem
.ReadDWORD(FTime
[i
]);
5524 Mem
.ReadString(str
);
5526 Mem
.ReadByte(FColor
.R
);
5527 Mem
.ReadByte(FColor
.G
);
5528 Mem
.ReadByte(FColor
.B
);
5529 if Self
= gPlayer1
then
5531 str
:= gPlayer1Settings
.Model
;
5532 FColor
:= gPlayer1Settings
.Color
;
5534 if Self
= gPlayer2
then
5536 str
:= gPlayer2Settings
.Model
;
5537 FColor
:= gPlayer2Settings
.Color
;
5539 // Îáíîâëÿåì ìîäåëü èãðîêà:
5541 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
5542 FModel
.Color
:= TEAMCOLOR
[FTeam
]
5544 FModel
.Color
:= FColor
;
5547 procedure TPlayer
.AllRulez(Health
: Boolean);
5553 FHealth
:= PLAYER_HP_LIMIT
;
5554 FArmor
:= PLAYER_AP_LIMIT
;
5558 for a
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do FWeapon
[a
] := True;
5559 for a
:= A_BULLETS
to A_CELLS
do FAmmo
[a
] := 30000;
5560 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5563 procedure TPlayer
.RestoreHealthArmor();
5565 FHealth
:= PLAYER_HP_LIMIT
;
5566 FArmor
:= PLAYER_AP_LIMIT
;
5569 procedure TPlayer
.FragCombo();
5573 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
5575 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
5577 if FFragCombo
< 5 then
5579 Param
:= FUID
or (FFragCombo
shl 16);
5580 if (FComboEvnt
>= Low(gDelayedEvents
)) and
5581 (FComboEvnt
<= High(gDelayedEvents
)) and
5582 gDelayedEvents
[FComboEvnt
].Pending
and
5583 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
5584 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
5586 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
5587 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
5590 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
5598 procedure TPlayer
.GiveItem(ItemType
: Byte);
5602 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
5604 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
5608 if FAir
< AIR_MAX
then
5615 if not (R_BERSERK
in FRulez
) then
5617 Include(FRulez
, R_BERSERK
);
5618 if FBFGFireCounter
< 1 then
5620 FCurrWeap
:= WEAPON_KASTET
;
5622 FModel
.SetWeapon(WEAPON_KASTET
);
5626 FBerserk
:= gTime
+30000;
5628 if FHealth
< PLAYER_HP_SOFT
then
5630 FHealth
:= PLAYER_HP_SOFT
;
5631 FBerserk
:= gTime
+30000;
5636 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
5638 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
5642 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
5644 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
5648 if FJetFuel
< JET_MAX
then
5650 FJetFuel
:= JET_MAX
;
5653 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
5654 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
5656 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
5657 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5659 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
5661 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
5663 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
5664 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5667 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
5668 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
5669 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
5670 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
5671 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
5672 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
5673 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
5674 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
5676 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5677 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
5678 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5679 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
5680 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5681 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
5682 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5683 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
5686 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
5687 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
5688 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
5689 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) then
5691 FMaxAmmo
[A_BULLETS
] := 400;
5692 FMaxAmmo
[A_SHELLS
] := 100;
5693 FMaxAmmo
[A_ROCKETS
] := 100;
5694 FMaxAmmo
[A_CELLS
] := 600;
5696 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5697 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5698 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5699 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5701 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
5704 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
5705 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
5706 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
5708 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
5709 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
5714 if g_Game_IsNet
and g_Game_IsServer
then
5715 MH_SEND_PlayerStats(FUID
);
5718 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
5723 if (Random(5) = 1) and (Times
= 1) then
5726 if BodyInLiquid(0, 0) then
5728 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
5729 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
5730 if Random(2) = 0 then
5731 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5733 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5737 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
5739 for i
:= 1 to Times
do
5741 Anim
:= TAnimation
.Create(id
, False, 3);
5743 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
5744 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
5750 procedure TPlayer
.PauseSounds(Enable
: Boolean);
5752 FSawSound
.Pause(Enable
);
5753 FSawSoundIdle
.Pause(Enable
);
5754 FSawSoundHit
.Pause(Enable
);
5755 FSawSoundSelect
.Pause(Enable
);
5760 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
5765 FObj
.Rect
:= PLAYER_CORPSERECT
;
5766 FModelName
:= ModelName
;
5771 FState
:= CORPSE_STATE_MESS
;
5772 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
5776 FState
:= CORPSE_STATE_NORMAL
;
5777 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
5781 destructor TCorpse
.Destroy();
5788 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
5792 if FState
= CORPSE_STATE_REMOVEME
then
5795 FDamage
:= FDamage
+ Value
;
5797 if FDamage
> 150 then
5799 if FAnimation
<> nil then
5804 FState
:= CORPSE_STATE_REMOVEME
;
5806 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
5807 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
5808 FModelName
, FColor
);
5809 // Çâóê ìÿñà îò òðóïà:
5810 pm
:= g_PlayerModel_Get(FModelName
);
5811 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
5817 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
5818 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
5819 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
5820 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
5821 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
5826 procedure TCorpse
.Draw();
5828 if FState
= CORPSE_STATE_REMOVEME
then
5831 if FAnimation
<> nil then
5832 FAnimation
.Draw(FObj
.X
, FObj
.Y
, M_NONE
);
5834 if FAnimationMask
<> nil then
5837 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, M_NONE
);
5844 procedure TCorpse
.Update();
5848 if FState
= CORPSE_STATE_REMOVEME
then
5851 if gTime
mod (GAME_TICK
*2) <> 0 then
5853 g_Obj_Move(@FObj
, True, True, True);
5858 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
5859 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5861 st
:= g_Obj_Move(@FObj
, True, True, True);
5863 if WordBool(st
and MOVE_FALLOUT
) then
5865 FState
:= CORPSE_STATE_REMOVEME
;
5869 if FAnimation
<> nil then
5870 FAnimation
.Update();
5871 if FAnimationMask
<> nil then
5872 FAnimationMask
.Update();
5875 procedure TCorpse
.SaveState(var Mem
: TBinMemoryWriter
);
5884 sig
:= CORPSE_SIGNATURE
; // 'CORP'
5885 Mem
.WriteDWORD(sig
);
5887 Mem
.WriteByte(FState
);
5888 // Íàêîïëåííûé óðîí:
5889 Mem
.WriteByte(FDamage
);
5891 Mem
.WriteByte(FColor
.R
);
5892 Mem
.WriteByte(FColor
.G
);
5893 Mem
.WriteByte(FColor
.B
);
5895 Obj_SaveState(@FObj
, Mem
);
5896 // Åñòü ëè àíèìàöèÿ:
5897 anim
:= FAnimation
<> nil;
5898 Mem
.WriteBoolean(anim
);
5899 // Åñëè åñòü - ñîõðàíÿåì:
5901 FAnimation
.SaveState(Mem
);
5902 // Åñòü ëè ìàñêà àíèìàöèè:
5903 anim
:= FAnimationMask
<> nil;
5904 Mem
.WriteBoolean(anim
);
5905 // Åñëè åñòü - ñîõðàíÿåì:
5907 FAnimationMask
.SaveState(Mem
);
5910 procedure TCorpse
.LoadState(var Mem
: TBinMemoryReader
);
5920 if sig
<> CORPSE_SIGNATURE
then // 'CORP'
5922 raise EBinSizeError
.Create('TCorpse.LoadState: Wrong Corpse Signature');
5925 Mem
.ReadByte(FState
);
5926 // Íàêîïëåííûé óðîí:
5927 Mem
.ReadByte(FDamage
);
5929 Mem
.ReadByte(FColor
.R
);
5930 Mem
.ReadByte(FColor
.G
);
5931 Mem
.ReadByte(FColor
.B
);
5933 Obj_LoadState(@FObj
, Mem
);
5934 // Åñòü ëè àíèìàöèÿ:
5935 Mem
.ReadBoolean(anim
);
5936 // Åñëè åñòü - çàãðóæàåì:
5939 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
5940 FAnimation
.LoadState(Mem
);
5942 // Åñòü ëè ìàñêà àíèìàöèè:
5943 Mem
.ReadBoolean(anim
);
5944 // Åñëè åñòü - çàãðóæàåì:
5947 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
5948 FAnimationMask
.LoadState(Mem
);
5954 constructor TBot
.Create();
5961 FSpectator
:= False;
5968 for a
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
5970 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
5971 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
5972 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
5976 destructor TBot
.Destroy();
5979 inherited Destroy();
5982 procedure TBot
.Draw();
5986 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
5987 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
5990 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
5992 inherited Respawn(Silent
, Force
);
5995 FSelectedWeapon
:= FCurrWeap
;
6000 procedure TBot
.UpdateCombat();
6013 TTargetRecord
= array of TTarget
;
6015 function Compare(a
, b
: TTarget
): Integer;
6017 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6020 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6022 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6023 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6025 if a
.Dist
> b
.Dist
then // B áëèæå
6027 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6030 else // Ñòðàííî -> A
6035 a
, x1
, y1
, x2
, y2
: Integer;
6036 targets
: TTargetRecord
;
6038 Target
, BestTarget
: TTarget
;
6039 firew
, fireh
: Integer;
6043 vsPlayer
, vsMonster
, ok
: Boolean;
6045 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6046 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6048 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6049 if FCurrWeap
<> FSelectedWeapon
then
6052 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6053 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6055 RemoveAIFlag('NEEDFIRE');
6058 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6059 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_MEGAKASTET
: PressKey(KEY_FIRE
, 40);
6060 else PressKey(KEY_FIRE
);
6064 // Êîîðäèíàòû ñòâîëà:
6065 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6066 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6068 Target
.UID
:= FTargetUID
;
6071 if Target
.UID
<> 0 then
6072 begin // Öåëü åñòü - íàñòðàèâàåì
6073 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6076 with g_Player_Get(Target
.UID
) do
6078 if (@FObj
) <> nil then
6085 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6086 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6087 Target
.Rect
:= PLAYER_RECT
;
6088 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6089 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6090 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6091 Target
.IsPlayer
:= True;
6095 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6098 mon
:= g_Monsters_Get(Target
.UID
);
6101 Target
.X
:= mon
.Obj
.X
;
6102 Target
.Y
:= mon
.Obj
.Y
;
6104 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6105 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6106 Target
.Rect
:= mon
.Obj
.Rect
;
6107 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6108 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6109 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6110 Target
.IsPlayer
:= False;
6117 begin // Öåëè íåò - îáíóëÿåì
6122 Target
.Visible
:= False;
6123 Target
.Line
:= False;
6124 Target
.IsPlayer
:= False;
6129 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6130 if (not Target
.Line
) or (not Target
.Visible
) then
6134 for a
:= 0 to High(gPlayers
) do
6135 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].Live
) and
6136 (gPlayers
[a
].FUID
<> FUID
) and
6137 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6138 (not gPlayers
[a
].NoTarget
) and
6139 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6141 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6142 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6145 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6146 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6148 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6149 if g_TraceVector(x1
, y1
, x2
, y2
) then
6151 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6152 SetLength(targets
, Length(targets
)+1);
6153 with targets
[High(targets
)] do
6155 UID
:= gPlayers
[a
].FUID
;
6156 X
:= gPlayers
[a
].FObj
.X
;
6157 Y
:= gPlayers
[a
].FObj
.Y
;
6160 Rect
:= PLAYER_RECT
;
6161 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6162 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6163 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6171 if vsMonster
and (gMonsters
<> nil) then
6172 for a
:= 0 to High(gMonsters
) do
6173 if (gMonsters
[a
] <> nil) and (gMonsters
[a
].Live
) and
6174 (gMonsters
[a
].MonsterType
<> MONSTER_BARREL
) then
6176 mon
:= gMonsters
[a
];
6178 if not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
6179 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
) then
6182 x2
:= mon
.Obj
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6183 y2
:= mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6185 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6186 if g_TraceVector(x1
, y1
, x2
, y2
) then
6188 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6189 SetLength(targets
, Length(targets
)+1);
6190 with targets
[High(targets
)] do
6197 Rect
:= mon
.Obj
.Rect
;
6198 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6199 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6200 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6208 // Åñëè åñòü âîçìîæíûå öåëè:
6209 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6210 if targets
<> nil then
6212 // Âûáèðàåì íàèëó÷øóþ öåëü:
6213 BestTarget
:= targets
[0];
6214 if Length(targets
) > 1 then
6215 for a
:= 1 to High(targets
) do
6216 if Compare(BestTarget
, targets
[a
]) = 1 then
6217 BestTarget
:= targets
[a
];
6219 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6220 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6221 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6223 Target
:= BestTarget
;
6225 if (Healthy() = 3) or ((Healthy() = 2)) then
6226 begin // Åñëè çäîðîâû - äîãîíÿåì
6227 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6228 SetAIFlag('GORIGHT', '1');
6229 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6230 SetAIFlag('GOLEFT', '1');
6233 begin // Åñëè ïîáèòû - óáåãàåì
6234 if ((RunDirection() = D_LEFT
) and (Target
.X
< FObj
.X
)) then
6235 SetAIFlag('GORIGHT', '1');
6236 if ((RunDirection() = D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6237 SetAIFlag('GOLEFT', '1');
6240 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6241 SelectWeapon(Abs(x1
-Target
.cX
));
6246 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6247 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6248 if Target
.UID
<> 0 then
6250 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6251 Target
.Y
+ Target
.Rect
.Y
) then
6252 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6253 if (Healthy() = 3) or ((Healthy() = 2)) then
6254 begin // Åñëè çäîðîâû - äîãîíÿåì
6255 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6256 SetAIFlag('GORIGHT', '1');
6257 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6258 SetAIFlag('GOLEFT', '1');
6261 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6263 if ((RunDirection() = D_LEFT
) and (Target
.X
< FObj
.X
)) then
6264 SetAIFlag('GORIGHT', '1');
6265 if ((RunDirection() = D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6266 SetAIFlag('GOLEFT', '1');
6270 begin // Öåëü ïîêà íà "ýêðàíå"
6271 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6272 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6273 FLastVisible
:= gTime
;
6274 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6275 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
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');
6284 // Âûáèðàåì óãîë ââåðõ:
6285 if FDirection
= D_LEFT
then
6286 angle
:= ANGLE_LEFTUP
6288 angle
:= ANGLE_RIGHTUP
;
6290 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6291 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6293 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6294 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6295 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6296 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6297 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6298 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6299 begin // òî íóæíî ñòðåëÿòü ââåðõ
6300 SetAIFlag('NEEDFIRE', '1');
6301 SetAIFlag('NEEDSEEUP', '1');
6304 // Âûáèðàåì óãîë âíèç:
6305 if FDirection
= D_LEFT
then
6306 angle
:= ANGLE_LEFTDOWN
6308 angle
:= ANGLE_RIGHTDOWN
;
6310 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6311 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6313 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6314 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6315 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6316 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6317 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6318 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6319 begin // òî íóæíî ñòðåëÿòü âíèç
6320 SetAIFlag('NEEDFIRE', '1');
6321 SetAIFlag('NEEDSEEDOWN', '1');
6324 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6325 if Target
.Visible
and
6326 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6327 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6329 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6330 if ((FDirection
= D_LEFT
) and (Target
.X
< FObj
.X
)) or
6331 ((FDirection
= D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6332 begin // òî íóæíî ñòðåëÿòü âïåðåä
6333 SetAIFlag('NEEDFIRE', '1');
6334 SetAIFlag('NEEDSEEDOWN', '');
6335 SetAIFlag('NEEDSEEUP', '');
6337 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6338 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6339 if GetRnd(FDifficult
.CloseJump
) then
6340 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6341 if Abs(FObj
.X
-Target
.X
) < 128 then
6345 if Random(a
) = 0 then
6346 SetAIFlag('NEEDJUMP', '1');
6350 // Åñëè öåëü âñå åùå åñòü:
6351 if Target
.UID
<> 0 then
6352 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
6353 Target
.UID
:= 0 // òî çàáûòü öåëü
6354 else // Åñëè âèäåëè íåäàâíî
6355 begin // íî öåëü óáèëè
6356 if Target
.IsPlayer
then
6357 begin // Öåëü - èãðîê
6358 pla
:= g_Player_Get(Target
.UID
);
6359 if (pla
= nil) or (not pla
.Live
) or pla
.NoTarget
or
6360 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6361 Target
.UID
:= 0; // òî çàáûòü öåëü
6364 begin // Öåëü - ìîíñòð
6365 mon
:= g_Monsters_Get(Target
.UID
);
6366 if (mon
= nil) or (not mon
.Live
) then
6367 Target
.UID
:= 0; // òî çàáûòü öåëü
6370 end; // if Target.UID <> 0
6372 FTargetUID
:= Target
.UID
;
6374 // Åñëè âîçìîæíûõ öåëåé íåò:
6375 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
6376 if targets
= nil then
6377 if GetAIFlag('ATTACKLEFT') <> '' then
6378 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
6379 RemoveAIFlag('ATTACKLEFT');
6381 SetAIFlag('NEEDJUMP', '1');
6383 if RunDirection() = D_RIGHT
then
6384 begin // Èäåì íå â òó ñòîðîíó
6385 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6386 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
6387 SetAIFlag('NEEDFIRE', '1');
6388 SetAIFlag('GOLEFT', '1');
6392 begin // Èäåì â íóæíóþ ñòîðîíó
6393 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6394 SetAIFlag('NEEDFIRE', '1');
6395 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6396 SetAIFlag('GORIGHT', '1');
6400 if GetAIFlag('ATTACKRIGHT') <> '' then
6401 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
6402 RemoveAIFlag('ATTACKRIGHT');
6404 SetAIFlag('NEEDJUMP', '1');
6406 if RunDirection() = D_LEFT
then
6407 begin // Èäåì íå â òó ñòîðîíó
6408 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6409 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
6410 SetAIFlag('NEEDFIRE', '1');
6411 SetAIFlag('GORIGHT', '1');
6416 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6417 SetAIFlag('NEEDFIRE', '1');
6418 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6419 SetAIFlag('GOLEFT', '1');
6423 //HACK! (does it belongs there?)
6424 RealizeCurrentWeapon();
6426 // Åñëè åñòü âîçìîæíûå öåëè:
6427 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
6428 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6429 for a
:= 0 to High(targets
) do
6431 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
6432 if GetRnd(FDifficult
.DiagFire
) then
6434 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
6435 if FDirection
= D_LEFT
then
6436 angle
:= ANGLE_LEFTUP
6438 angle
:= ANGLE_RIGHTUP
;
6440 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6441 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6443 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6444 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6445 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6446 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6447 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6449 SetAIFlag('NEEDFIRE', '1');
6450 SetAIFlag('NEEDSEEUP', '1');
6453 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
6454 if FDirection
= D_LEFT
then
6455 angle
:= ANGLE_LEFTDOWN
6457 angle
:= ANGLE_RIGHTDOWN
;
6459 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6460 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6462 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6463 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6464 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6465 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6466 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6468 SetAIFlag('NEEDFIRE', '1');
6469 SetAIFlag('NEEDSEEDOWN', '1');
6473 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
6474 if targets
[a
].Line
and targets
[a
].Visible
and
6475 (((FDirection
= D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
6476 ((FDirection
= D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
6478 SetAIFlag('NEEDFIRE', '1');
6483 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
6484 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
6485 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
6486 40+GetInterval(FDifficult
.Cover
, 40)) then
6487 SetAIFlag('NEEDJUMP', '1');
6489 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
6490 ammo
:= GetAmmoByWeapon(FCurrWeap
);
6491 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
6492 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
6494 SetAIFlag('SELECTWEAPON', '1');
6496 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
6497 if GetAIFlag('SELECTWEAPON') = '1' then
6500 RemoveAIFlag('SELECTWEAPON');
6504 procedure TBot
.Update();
6517 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
6518 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
6520 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
6522 if g_debug_BotAIOff
= 3 then
6535 procedure TBot
.ReleaseKey(Key
: Byte);
6544 function TBot
.KeyPressed(Key
: Word): Boolean;
6546 Result
:= FKeys
[Key
].Pressed
;
6549 function TBot
.GetAIFlag(fName
: String20
): String20
;
6555 fName
:= LowerCase(fName
);
6557 if FAIFlags
<> nil then
6558 for a
:= 0 to High(FAIFlags
) do
6559 if LowerCase(FAIFlags
[a
].Name
) = fName
then
6561 Result
:= FAIFlags
[a
].Value
;
6566 procedure TBot
.RemoveAIFlag(fName
: String20
);
6570 if FAIFlags
= nil then Exit
;
6572 fName
:= LowerCase(fName
);
6574 for a
:= 0 to High(FAIFlags
) do
6575 if LowerCase(FAIFlags
[a
].Name
) = fName
then
6577 if a
<> High(FAIFlags
) then
6578 for b
:= a
to High(FAIFlags
)-1 do
6579 FAIFlags
[b
] := FAIFlags
[b
+1];
6581 SetLength(FAIFlags
, Length(FAIFlags
)-1);
6586 procedure TBot
.SetAIFlag(fName
, fValue
: String20
);
6594 fName
:= LowerCase(fName
);
6596 if FAIFlags
<> nil then
6597 for a
:= 0 to High(FAIFlags
) do
6598 if LowerCase(FAIFlags
[a
].Name
) = fName
then
6604 if ok
then FAIFlags
[a
].Value
:= fValue
6607 SetLength(FAIFlags
, Length(FAIFlags
)+1);
6608 with FAIFlags
[High(FAIFlags
)] do
6616 procedure TBot
.UpdateMove
;
6618 procedure GoLeft(Time
: Word = 1);
6620 ReleaseKey(KEY_LEFT
);
6621 ReleaseKey(KEY_RIGHT
);
6622 PressKey(KEY_LEFT
, Time
);
6623 SetDirection(D_LEFT
);
6626 procedure GoRight(Time
: Word = 1);
6628 ReleaseKey(KEY_LEFT
);
6629 ReleaseKey(KEY_RIGHT
);
6630 PressKey(KEY_RIGHT
, Time
);
6631 SetDirection(D_RIGHT
);
6634 function Rnd(a
: Word): Boolean;
6636 Result
:= Random(a
) = 0;
6639 procedure Turn(Time
: Word = 1200);
6641 if RunDirection() = D_LEFT
then GoRight(Time
) else GoLeft(Time
);
6646 ReleaseKey(KEY_LEFT
);
6647 ReleaseKey(KEY_RIGHT
);
6650 function CanRunLeft(): Boolean;
6652 Result
:= not CollideLevel(-1, 0);
6655 function CanRunRight(): Boolean;
6657 Result
:= not CollideLevel(1, 0);
6660 function CanRun(): Boolean;
6662 if RunDirection() = D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
6665 procedure Jump(Time
: Word = 30);
6667 PressKey(KEY_JUMP
, Time
);
6670 function NearHole(): Boolean;
6674 { TODO 5 : Ëåñòíèöû }
6675 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6676 for x
:= 1 to PLAYER_RECT
.Width
do
6677 if (not StayOnStep(x
*sx
, 0)) and
6678 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6679 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6688 function BorderHole(): Boolean;
6692 { TODO 5 : Ëåñòíèöû }
6693 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6694 for x
:= 1 to PLAYER_RECT
.Width
do
6695 if (not StayOnStep(x
*sx
, 0)) and
6696 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6697 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6699 for xx
:= x
to x
+32 do
6700 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
6710 function NearDeepHole(): Boolean;
6716 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6719 for x
:= 1 to PLAYER_RECT
.Width
do
6720 if (not StayOnStep(x
*sx
, 0)) and
6721 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6722 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6724 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6726 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
6731 end else Result
:= False;
6734 function OverDeepHole(): Boolean;
6741 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6743 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
6750 function OnGround(): Boolean;
6752 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
6755 function OnLadder(): Boolean;
6757 Result
:= FullInStep(0, 0);
6760 function BelowLadder(): Boolean;
6762 Result
:= (FullInStep(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
6763 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
6764 (FullInStep(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
6765 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
6768 function BelowLiftUp(): Boolean;
6770 Result
:= ((FullInLift(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
6771 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
6772 ((FullInLift(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
6773 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
6776 function OnTopLift(): Boolean;
6778 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
6781 function CanJumpOver(): Boolean;
6785 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6789 if not CollideLevel(sx
, 0) then Exit
;
6791 for y
:= 1 to BOT_MAXJUMP
do
6792 if CollideLevel(0, -y
) then Exit
else
6793 if not CollideLevel(sx
, -y
) then
6800 function CanJumpUp(Dist
: ShortInt): Boolean;
6807 if CollideLevel(Dist
, 0) then Exit
;
6810 for y
:= 0 to BOT_MAXJUMP
do
6811 if CollideLevel(Dist
, -y
) then
6820 for yy
:= y
+1 to BOT_MAXJUMP
do
6821 if not CollideLevel(Dist
, -yy
) then
6830 for y
:= 0 to BOT_MAXJUMP
do
6831 if CollideLevel(0, -y
) then
6839 if y
< yy
then Exit
;
6844 function IsSafeTrigger(): Boolean;
6849 if gTriggers
= nil then
6851 for a
:= 0 to High(gTriggers
) do
6852 if Collide(gTriggers
[a
].X
,
6855 gTriggers
[a
].Height
) and
6856 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
6857 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
6858 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
6859 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
6860 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
6865 // Âîçìîæíî, íàæèìàåì êíîïêó:
6866 if Rnd(16) and IsSafeTrigger() then
6869 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
6870 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
6872 ReleaseKey(KEY_LEFT
);
6873 ReleaseKey(KEY_RIGHT
);
6877 // Èäåì âëåâî, åñëè íàäî áûëî:
6878 if GetAIFlag('GOLEFT') <> '' then
6880 RemoveAIFlag('GOLEFT');
6881 if CanRunLeft() then
6885 // Èäåì âïðàâî, åñëè íàäî áûëî:
6886 if GetAIFlag('GORIGHT') <> '' then
6888 RemoveAIFlag('GORIGHT');
6889 if CanRunRight() then
6893 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
6894 if FObj
.X
< -32 then
6897 if FObj
.X
+32 > gMapInfo
.Width
then
6900 // Ïðûãàåì, åñëè íàäî áûëî:
6901 if GetAIFlag('NEEDJUMP') <> '' then
6904 RemoveAIFlag('NEEDJUMP');
6907 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
6908 if GetAIFlag('NEEDSEEUP') <> '' then
6911 ReleaseKey(KEY_DOWN
);
6912 PressKey(KEY_UP
, 20);
6913 RemoveAIFlag('NEEDSEEUP');
6916 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
6917 if GetAIFlag('NEEDSEEDOWN') <> '' then
6920 ReleaseKey(KEY_DOWN
);
6921 PressKey(KEY_DOWN
, 20);
6922 RemoveAIFlag('NEEDSEEDOWN');
6925 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
6926 if GetAIFlag('GOINHOLE') <> '' then
6927 if not OnGround() then
6929 ReleaseKey(KEY_LEFT
);
6930 ReleaseKey(KEY_RIGHT
);
6931 RemoveAIFlag('GOINHOLE');
6932 SetAIFlag('FALLINHOLE', '1');
6935 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
6936 if GetAIFlag('FALLINHOLE') <> '' then
6938 RemoveAIFlag('FALLINHOLE');
6940 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
6941 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
6942 if GetAIFlag('FALLINHOLE') = '' then
6943 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
6949 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
6951 CanJumpUp(IfThen(RunDirection() = D_LEFT
, -1, 1)*32) and
6955 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
6956 if OnGround() and NearHole() then
6957 if NearDeepHole() then // Åñëè ýòî áåçäíà
6959 0..3: Turn(); // Áåæèì îáðàòíî
6960 4: Jump(); // Ïðûãàåì
6961 5: begin // Ïðûãàåì îáðàòíî
6966 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
6967 if GetAIFlag('GOINHOLE') = '' then
6969 0: Turn(); // Íå íóæíî òóäà
6970 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
6971 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
6972 if BorderHole() then
6973 SetAIFlag('GOINHOLE', '1');
6976 // Åñëè íà çåìëå, íî íåêóäà èäòè:
6977 if (not CanRun()) and OnGround() then
6979 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
6980 if CanJumpOver() or OnLadder() then
6982 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
6983 if Random(2) = 0 then
6985 if IsSafeTrigger() then
6991 // Îñòàëîñü ìàëî âîçäóõà:
6992 if FAir
< 36 * 2 then
6995 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
6996 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
6997 if BodyInAcid(0, 0) then
7001 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7003 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7004 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7007 {function TBot.NeedItem(Item: Byte): Byte;
7012 procedure TBot
.SelectWeapon(Dist
: Integer);
7016 function HaveAmmo(weapon
: Byte): Boolean;
7019 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7020 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7021 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7022 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7023 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7024 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7025 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7026 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7027 else Result
:= True;
7032 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7034 if Dist
> BOT_LONGDIST
then
7035 begin // Äàëüíèé áîé
7037 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7039 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7043 else //if Dist > BOT_UNSAFEDIST then
7044 begin // Áëèæíèé áîé
7046 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7048 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7055 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7057 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7063 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7065 Result
:= inherited PickItem(ItemType
, force
, remove
);
7067 if Result
then SetAIFlag('SELECTWEAPON', '1');
7070 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7072 Result
:= inherited Heal(value
, Soft
);
7075 function TBot
.Healthy(): Byte;
7077 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7078 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7079 else if (FHealth
> 50) then Result
:= 2
7080 else if (FHealth
> 20) then Result
:= 1
7084 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7086 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7087 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7090 procedure TBot
.OnDamage(Angle
: SmallInt);
7098 if (Angle
= 0) or (Angle
= 180) then
7101 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7102 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7104 pla
:= g_Player_Get(FLastSpawnerUID
);
7105 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7106 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7109 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7110 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7112 mon
:= g_Monsters_Get(FLastSpawnerUID
);
7113 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7114 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7119 SetAIFlag('ATTACKLEFT', '1')
7121 SetAIFlag('ATTACKRIGHT', '1');
7125 function TBot
.RunDirection(): TDirection
;
7127 if Abs(Vel
.X
) >= 1 then
7129 if Vel
.X
> 0 then Result
:= D_RIGHT
else Result
:= D_LEFT
;
7131 Result
:= FDirection
;
7134 function TBot
.GetRnd(a
: Byte): Boolean;
7136 if a
= 0 then Result
:= False
7137 else if a
= 255 then Result
:= True
7138 else Result
:= Random(256) > 255-a
;
7141 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7143 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7146 procedure TBot
.SaveState(var Mem
: TBinMemoryWriter
);
7152 inherited SaveState(Mem
);
7154 // Âûáðàííîå îðóæèå:
7155 Mem
.WriteByte(FSelectedWeapon
);
7157 Mem
.WriteWord(FTargetUID
);
7158 // Âðåìÿ ïîòåðè öåëè:
7159 Mem
.WriteDWORD(FLastVisible
);
7160 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7161 dw
:= Length(FAIFlags
);
7164 for i
:= 0 to Integer(dw
)-1 do
7166 Mem
.WriteString(FAIFlags
[i
].Name
, 20);
7167 Mem
.WriteString(FAIFlags
[i
].Value
, 20);
7169 // Íàñòðîéêè ñëîæíîñòè:
7171 Mem
.WriteMemory(p
, SizeOf(TDifficult
));
7174 procedure TBot
.LoadState(var Mem
: TBinMemoryReader
);
7180 inherited LoadState(Mem
);
7182 // Âûáðàííîå îðóæèå:
7183 Mem
.ReadByte(FSelectedWeapon
);
7185 Mem
.ReadWord(FTargetUID
);
7186 // Âðåìÿ ïîòåðè öåëè:
7187 Mem
.ReadDWORD(FLastVisible
);
7188 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7190 SetLength(FAIFlags
, dw
);
7192 for i
:= 0 to Integer(dw
)-1 do
7194 Mem
.ReadString(FAIFlags
[i
].Name
);
7195 Mem
.ReadString(FAIFlags
[i
].Value
);
7197 // Íàñòðîéêè ñëîæíîñòè:
7198 Mem
.ReadMemory(p
, dw
);
7199 if dw
<> SizeOf(TDifficult
) then
7201 raise EBinSizeError
.Create('TBot.LoadState: Wrong FDifficult Size');
7203 FDifficult
:= TDifficult(p
^);