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 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
213 procedure resetWeaponQueue ();
214 function hasAmmoForWeapon (weapon
: Byte): Boolean;
217 FDamageBuffer
: Integer;
219 FAmmo
: Array [A_BULLETS
..A_CELLS
] of Word;
220 FMaxAmmo
: Array [A_BULLETS
..A_CELLS
] of Word;
221 FWeapon
: Array [WEAPON_KASTET
..WEAPON_SUPERPULEMET
] of Boolean;
222 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
224 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
225 FReloading
: Array [WEAPON_KASTET
..WEAPON_SUPERPULEMET
] of Word;
226 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
227 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
229 FPreferredTeam
: Byte;
232 FWantsInGame
: Boolean;
236 FActualModelName
: string;
242 constructor Create(); virtual;
243 destructor Destroy(); override;
244 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
245 function GetRespawnPoint(): Byte;
246 procedure PressKey(Key
: Byte; Time
: Word = 1);
247 procedure ReleaseKeys();
248 procedure SetModel(ModelName
: String);
249 procedure SetColor(Color
: TRGB
);
250 procedure SetWeapon(W
: Byte);
251 function IsKeyPressed(K
: Byte): Boolean;
252 function GetKeys(): Byte;
253 function PickItem(ItemType
: Byte; respawn
: Boolean; var remove
: Boolean): Boolean; virtual;
254 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
255 function Collide(Panel
: TPanel
): Boolean; overload
;
256 function Collide(X
, Y
: Integer): Boolean; overload
;
257 procedure SetDirection(Direction
: TDirection
);
258 procedure GetSecret();
259 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
261 procedure Push(vx
, vy
: Integer);
262 procedure ChangeModel(ModelName
: String);
263 procedure SwitchTeam
;
264 procedure ChangeTeam(Team
: Byte);
266 function GetFlag(Flag
: Byte): Boolean;
267 procedure SetFlag(Flag
: Byte);
268 function DropFlag(): Boolean;
269 procedure AllRulez(Health
: Boolean);
270 procedure RestoreHealthArmor();
271 procedure FragCombo();
272 procedure GiveItem(ItemType
: Byte);
273 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
274 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
275 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
276 procedure MakeBloodSimple(Count
: Word);
277 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
278 procedure Reset(Force
: Boolean);
279 procedure Spectate(NoMove
: Boolean = False);
280 procedure SwitchNoClip
;
281 procedure SoftReset();
282 procedure Draw(); virtual;
283 procedure DrawPain();
284 procedure DrawPickup();
285 procedure DrawRulez();
287 procedure DrawBubble();
289 procedure Update(); virtual;
290 procedure RememberState();
291 procedure RecallState();
292 procedure SaveState(var Mem
: TBinMemoryWriter
); virtual;
293 procedure LoadState(var Mem
: TBinMemoryReader
); virtual;
294 procedure PauseSounds(Enable
: Boolean);
295 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
296 procedure DoLerp(Level
: Integer = 2);
297 procedure SetLerp(XTo
, YTo
: Integer);
298 procedure QueueWeaponSwitch(Weapon
: Byte);
299 procedure RealizeCurrentWeapon();
301 procedure JetpackOff
;
303 property Name
: String read FName write FName
;
304 property Model
: TPlayerModel read FModel
;
305 property Health
: Integer read FHealth write FHealth
;
306 property Lives
: Byte read FLives write FLives
;
307 property Armor
: Integer read FArmor write FArmor
;
308 property Air
: Integer read FAir write FAir
;
309 property JetFuel
: Integer read FJetFuel write FJetFuel
;
310 property Frags
: Integer read FFrags write FFrags
;
311 property Death
: Integer read FDeath write FDeath
;
312 property Kills
: Integer read FKills write FKills
;
313 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
314 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
315 property Secrets
: Integer read FSecrets
;
316 property GodMode
: Boolean read FGodMode write FGodMode
;
317 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
318 property NoReload
: Boolean read FNoReload write FNoReload
;
319 property Live
: Boolean read FLive write FLive
;
320 property Flag
: Byte read FFlag
;
321 property Team
: Byte read FTeam write FTeam
;
322 property Direction
: TDirection read FDirection
;
323 property GameX
: Integer read FObj
.X write FObj
.X
;
324 property GameY
: Integer read FObj
.Y write FObj
.Y
;
325 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
326 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
327 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
328 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
329 property Vel
: TPoint2i read FObj
.Vel
;
330 property Obj
: TObj read FObj
;
331 property IncCam
: Integer read FIncCam write FIncCam
;
332 property UID
: Word read FUID write FUID
;
333 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
334 property NetTime
: LongWord read FNetTime write FNetTime
;
344 WeaponPrior
: Array [WEAPON_KASTET
..WEAPON_SUPERPULEMET
] of Byte;
345 CloseWeaponPrior
: Array [WEAPON_KASTET
..WEAPON_SUPERPULEMET
] of Byte;
346 //SafeWeaponPrior: Array [WEAPON_KASTET..WEAPON_SUPERPULEMET] of Byte;
354 TBot
= class (TPlayer
)
356 FSelectedWeapon
: Byte;
359 FAIFlags
: Array of TAIFlag
;
360 FDifficult
: TDifficult
;
362 function GetRnd(a
: Byte): Boolean;
363 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
364 function RunDirection(): TDirection
;
365 function FullInStep(XInc
, YInc
: Integer): Boolean;
366 //function NeedItem(Item: Byte): Byte;
367 procedure SelectWeapon(Dist
: Integer);
368 procedure SetAIFlag(fName
, fValue
: String20
);
369 function GetAIFlag(fName
: String20
): String20
;
370 procedure RemoveAIFlag(fName
: String20
);
371 function Healthy(): Byte;
372 procedure UpdateMove();
373 procedure UpdateCombat();
374 function KeyPressed(Key
: Word): Boolean;
375 procedure ReleaseKey(Key
: Byte);
376 function TargetOnScreen(TX
, TY
: Integer): Boolean;
377 procedure OnDamage(Angle
: SmallInt); override;
380 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
381 constructor Create(); override;
382 destructor Destroy(); override;
383 procedure Draw(); override;
384 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
385 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
386 procedure Update(); override;
387 procedure SaveState(var Mem
: TBinMemoryWriter
); override;
388 procedure LoadState(var Mem
: TBinMemoryReader
); override;
410 TCorpse
= class (TObject
)
418 FAnimation
: TAnimation
;
419 FAnimationMask
: TAnimation
;
422 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
423 destructor Destroy(); override;
424 procedure Damage(Value
: Word; vx
, vy
: Integer);
427 procedure SaveState(var Mem
: TBinMemoryWriter
);
428 procedure LoadState(var Mem
: TBinMemoryReader
);
430 property Obj
: TObj read FObj
;
431 property State
: Byte read FState
;
432 property Mess
: Boolean read FMess
;
435 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
441 gPlayers
: Array of TPlayer
;
442 gCorpses
: Array of TCorpse
;
443 gGibs
: Array of TGib
;
444 gShells
: Array of TShell
;
445 gTeamStat
: TTeamStat
;
446 gFly
: Boolean = False;
447 gAimLine
: Boolean = False;
448 gChatBubble
: Byte = 0;
452 MAX_RUNVEL
: Integer = 8;
453 VEL_JUMP
: Integer = 10;
454 SHELL_TIMEOUT
: Cardinal = 60000;
456 function Lerp(X
, Y
, Factor
: Integer): Integer;
458 procedure g_Gibs_SetMax(Count
: Word);
459 function g_Gibs_GetMax(): Word;
460 procedure g_Corpses_SetMax(Count
: Word);
461 function g_Corpses_GetMax(): Word;
462 procedure g_Shells_SetMax(Count
: Word);
463 function g_Shells_GetMax(): Word;
465 procedure g_Player_Init();
466 procedure g_Player_Free();
467 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
468 function g_Player_CreateFromState(var Mem
: TBinMemoryReader
): Word;
469 procedure g_Player_Remove(UID
: Word);
470 procedure g_Player_ResetTeams();
471 procedure g_Player_UpdateAll();
472 procedure g_Player_DrawAll();
473 procedure g_Player_DrawDebug(p
: TPlayer
);
474 procedure g_Player_DrawHealth();
475 procedure g_Player_RememberAll();
476 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
477 function g_Player_Get(UID
: Word): TPlayer
;
478 function g_Player_GetCount(): Byte;
479 function g_Player_GetStats(): TPlayerStatArray
;
480 function g_Player_ValidName(Name
: String): Boolean;
481 procedure g_Player_CreateCorpse(Player
: TPlayer
);
482 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
483 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
484 procedure g_Player_UpdatePhysicalObjects();
485 procedure g_Player_DrawCorpses();
486 procedure g_Player_DrawShells();
487 procedure g_Player_RemoveAllCorpses();
488 procedure g_Player_Corpses_SaveState(var Mem
: TBinMemoryWriter
);
489 procedure g_Player_Corpses_LoadState(var Mem
: TBinMemoryReader
);
490 procedure g_Bot_Add(Team
, Difficult
: Byte);
491 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1);
492 procedure g_Bot_MixNames();
493 procedure g_Bot_RemoveAll();
498 e_log
, g_map
, g_items
, g_console
, SysUtils
, g_gfx
, Math
,
499 g_options
, g_triggers
, g_menu
, MAPDEF
, g_game
,
500 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
, g_net
, g_netmsg
;
510 diag_precision
: Byte;
514 w_prior1
: Array [WEAPON_KASTET
..WEAPON_SUPERPULEMET
] of Byte;
515 w_prior2
: Array [WEAPON_KASTET
..WEAPON_SUPERPULEMET
] of Byte;
516 w_prior3
: Array [WEAPON_KASTET
..WEAPON_SUPERPULEMET
] of Byte;
520 TIME_RESPAWN1
= 1500;
521 TIME_RESPAWN2
= 2000;
522 TIME_RESPAWN3
= 3000;
525 JET_MAX
= 540; // ~30 sec
526 PLAYER_SUIT_TIME
= 30000;
527 PLAYER_INVUL_TIME
= 30000;
528 PLAYER_INVIS_TIME
= 35000;
529 FRAG_COMBO_TIME
= 3000;
533 ANGLE_RIGHTDOWN
= -35;
535 ANGLE_LEFTDOWN
= -145;
536 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
537 WEAPONPOINT
: Array [TDirection
] of TPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
540 BOT_UNSAFEDIST
= 128;
541 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
543 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
544 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
545 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0));
546 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
547 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
548 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0));
549 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
550 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
551 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0));
552 WEAPON_PRIOR1
: Array [WEAPON_KASTET
..WEAPON_SUPERPULEMET
] of Byte =
553 (WEAPON_SUPERPULEMET
, WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
554 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
555 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
556 WEAPON_PRIOR2
: Array [WEAPON_KASTET
..WEAPON_SUPERPULEMET
] of Byte =
557 (WEAPON_SUPERPULEMET
, WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
558 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
559 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
560 //WEAPON_PRIOR3: Array [WEAPON_KASTET..WEAPON_SUPERPULEMET] of Byte =
561 // (WEAPON_SUPERPULEMET, WEAPON_BFG, WEAPON_PLASMA,
562 // WEAPON_SHOTGUN2, WEAPON_CHAINGUN, WEAPON_SHOTGUN1,
563 // WEAPON_SAW, WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
564 WEAPON_RELOAD
: Array [WEAPON_KASTET
..WEAPON_SUPERPULEMET
] of Byte =
565 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2);
567 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
568 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
570 BOTNAMES_FILENAME
= 'botnames.txt';
571 BOTLIST_FILENAME
= 'botlist.txt';
575 MaxCorpses
: Word = 20;
576 MaxShells
: Word = 300;
577 CurrentGib
: Integer = 0;
578 CurrentShell
: Integer = 0;
579 BotNames
: Array of String;
580 BotList
: Array of TBotProfile
;
582 function Lerp(X
, Y
, Factor
: Integer): Integer;
584 Result
:= X
+ ((Y
- X
) div Factor
);
587 function SameTeam(UID1
, UID2
: Word): Boolean;
591 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
592 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
594 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
596 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
597 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
599 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
602 procedure g_Gibs_SetMax(Count
: Word);
605 SetLength(gGibs
, Count
);
607 if CurrentGib
>= Count
then
611 function g_Gibs_GetMax(): Word;
616 procedure g_Shells_SetMax(Count
: Word);
619 SetLength(gShells
, Count
);
621 if CurrentShell
>= Count
then
625 function g_Shells_GetMax(): Word;
631 procedure g_Corpses_SetMax(Count
: Word);
634 SetLength(gCorpses
, Count
);
637 function g_Corpses_GetMax(): Word;
639 Result
:= MaxCorpses
;
642 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
652 // Åñòü ëè ìåñòî â gPlayers:
653 if gPlayers
<> nil then
654 for a
:= 0 to High(gPlayers
) do
655 if gPlayers
[a
] = nil then
661 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
664 SetLength(gPlayers
, Length(gPlayers
)+1);
668 // Ñîçäàåì îáúåêò èãðîêà:
670 gPlayers
[a
] := TBot
.Create()
672 gPlayers
[a
] := TPlayer
.Create();
675 gPlayers
[a
].FActualModelName
:= ModelName
;
676 gPlayers
[a
].SetModel(ModelName
);
678 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
679 if gPlayers
[a
].FModel
= nil then
683 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
687 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
688 if Random(2) = 0 then
692 gPlayers
[a
].FPreferredTeam
:= Team
;
694 case gGameSettings
.GameMode
of
695 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
697 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
699 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
702 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
703 gPlayers
[a
].FColor
:= Color
;
704 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
705 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
707 gPlayers
[a
].FModel
.Color
:= Color
;
709 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
710 gPlayers
[a
].FLive
:= False;
712 Result
:= gPlayers
[a
].FUID
;
715 function g_Player_CreateFromState(var Mem
: TBinMemoryReader
): Word;
728 if sig
<> PLAYER_SIGNATURE
then // 'PLYR'
730 raise EBinSizeError
.Create('g_Player_CreateFromState: Wrong Player Signature');
734 Mem
.ReadBoolean(Bot
);
739 // Åñòü ëè ìåñòî â gPlayers:
740 if gPlayers
<> nil then
741 for a
:= 0 to High(gPlayers
) do
742 if gPlayers
[a
] = nil then
748 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
751 SetLength(gPlayers
, Length(gPlayers
)+1);
755 // Ñîçäàåì îáúåêò èãðîêà:
757 gPlayers
[a
] := TBot
.Create()
759 gPlayers
[a
] := TPlayer
.Create();
760 gPlayers
[a
].FIamBot
:= Bot
;
761 gPlayers
[a
].FPhysics
:= True;
764 Mem
.ReadWord(gPlayers
[a
].FUID
);
766 Mem
.ReadString(gPlayers
[a
].FName
);
768 Mem
.ReadByte(gPlayers
[a
].FTeam
);
769 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
771 Mem
.ReadBoolean(gPlayers
[a
].FLive
);
772 // Èçðàñõîäîâàë ëè âñå æèçíè:
773 Mem
.ReadBoolean(gPlayers
[a
].FNoRespawn
);
777 gPlayers
[a
].FDirection
:= D_LEFT
779 gPlayers
[a
].FDirection
:= D_RIGHT
;
781 Mem
.ReadInt(gPlayers
[a
].FHealth
);
783 Mem
.ReadByte(gPlayers
[a
].FLives
);
785 Mem
.ReadInt(gPlayers
[a
].FArmor
);
787 Mem
.ReadInt(gPlayers
[a
].FAir
);
789 Mem
.ReadInt(gPlayers
[a
].FJetFuel
);
791 Mem
.ReadInt(gPlayers
[a
].FPain
);
793 Mem
.ReadInt(gPlayers
[a
].FKills
);
795 Mem
.ReadInt(gPlayers
[a
].FMonsterKills
);
797 Mem
.ReadInt(gPlayers
[a
].FFrags
);
799 Mem
.ReadByte(gPlayers
[a
].FFragCombo
);
800 // Âðåìÿ ïîñëåäíåãî ôðàãà:
801 Mem
.ReadDWORD(gPlayers
[a
].FLastFrag
);
803 Mem
.ReadInt(gPlayers
[a
].FDeath
);
805 Mem
.ReadByte(gPlayers
[a
].FFlag
);
807 Mem
.ReadInt(gPlayers
[a
].FSecrets
);
809 Mem
.ReadByte(gPlayers
[a
].FCurrWeap
);
810 // Ñëåäóþùåå æåëàåìîå îðóæèå:
811 Mem
.ReadWord(gPlayers
[a
].FNextWeap
);
813 Mem
.ReadByte(gPlayers
[a
].FNextWeapDelay
);
814 // Âðåìÿ çàðÿäêè BFG:
815 Mem
.ReadSmallInt(gPlayers
[a
].FBFGFireCounter
);
817 Mem
.ReadInt(gPlayers
[a
].FDamageBuffer
);
818 // Ïîñëåäíèé óäàðèâøèé:
819 Mem
.ReadWord(gPlayers
[a
].FLastSpawnerUID
);
820 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
821 Mem
.ReadByte(gPlayers
[a
].FLastHit
);
823 Obj_LoadState(@gPlayers
[a
].FObj
, Mem
);
824 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
825 for i
:= A_BULLETS
to A_CELLS
do
826 Mem
.ReadWord(gPlayers
[a
].FAmmo
[i
]);
827 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
828 for i
:= A_BULLETS
to A_CELLS
do
829 Mem
.ReadWord(gPlayers
[a
].FMaxAmmo
[i
]);
831 for i
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
832 Mem
.ReadBoolean(gPlayers
[a
].FWeapon
[i
]);
833 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
834 for i
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
835 Mem
.ReadWord(gPlayers
[a
].FReloading
[i
]);
839 Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
840 // Íàëè÷èå êðàñíîãî êëþ÷à:
843 Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
844 // Íàëè÷èå çåëåíîãî êëþ÷à:
847 Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
848 // Íàëè÷èå ñèíåãî êëþ÷à:
851 Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
855 Include(gPlayers
[a
].FRulez
, R_BERSERK
);
856 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
857 for i
:= MR_SUIT
to MR_MAX
do
858 Mem
.ReadDWORD(gPlayers
[a
].FMegaRulez
[i
]);
859 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
860 for i
:= T_RESPAWN
to T_FLAGCAP
do
861 Mem
.ReadDWORD(gPlayers
[a
].FTime
[i
]);
864 Mem
.ReadString(gPlayers
[a
].FActualModelName
);
866 Mem
.ReadByte(gPlayers
[a
].FColor
.R
);
867 Mem
.ReadByte(gPlayers
[a
].FColor
.G
);
868 Mem
.ReadByte(gPlayers
[a
].FColor
.B
);
869 // Îáíîâëÿåì ìîäåëü èãðîêà:
870 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
872 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
873 if gPlayers
[a
].FModel
= nil then
877 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
881 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
882 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
883 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
885 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
887 Result
:= gPlayers
[a
].FUID
;
890 procedure g_Player_ResetTeams();
894 if g_Game_IsClient
then
896 if gPlayers
= nil then
898 for a
:= Low(gPlayers
) to High(gPlayers
) do
899 if gPlayers
[a
] <> nil then
900 case gGameSettings
.GameMode
of
902 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
904 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
905 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
906 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
909 gPlayers
[a
].ChangeTeam(TEAM_RED
)
911 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
914 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
918 procedure g_Bot_Add(Team
, Difficult
: Byte);
921 _name
, _model
: String;
924 if not g_Game_IsServer
then Exit
;
926 // Ñïèñîê íàçâàíèé ìîäåëåé:
927 m
:= g_PlayerModel_GetNames();
932 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
933 Team
:= TEAM_COOP
// COOP
935 if gGameSettings
.GameMode
= GM_DM
then
936 Team
:= TEAM_NONE
// DM
938 if Team
= TEAM_NONE
then // CTF / TDM
940 // Àâòîáàëàíñ êîìàíä:
944 for a
:= 0 to High(gPlayers
) do
945 if gPlayers
[a
] <> nil then
947 if gPlayers
[a
].Team
= TEAM_RED
then
950 if gPlayers
[a
].Team
= TEAM_BLUE
then
960 if Random(2) = 0 then
966 // Âûáèðàåì áîòó èìÿ:
968 if BotNames
<> nil then
969 for a
:= 0 to High(BotNames
) do
970 if g_Player_ValidName(BotNames
[a
]) then
972 _name
:= BotNames
[a
];
976 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
979 _name
:= Format('DFBOT%.2d', [Random(100)]);
980 until g_Player_ValidName(_name
);
982 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
983 _model
:= m
[Random(Length(m
))];
986 with g_Player_Get(g_Player_Create(_model
,
987 _RGB(Min(Random(9)*32, 255),
988 Min(Random(9)*32, 255),
989 Min(Random(9)*32, 255)),
990 Team
, True)) as TBot
do
995 1: FDifficult
:= DIFFICULT_EASY
;
996 2: FDifficult
:= DIFFICULT_MEDIUM
;
997 else FDifficult
:= DIFFICULT_HARD
;
1000 for a
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
1002 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1003 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1004 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1007 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1009 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1010 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1015 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1);
1018 _name
, _model
: String;
1021 if not g_Game_IsServer
then Exit
;
1023 // Ñïèñîê íàçâàíèé ìîäåëåé:
1024 m
:= g_PlayerModel_GetNames();
1029 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1030 Team
:= TEAM_COOP
// COOP
1032 if gGameSettings
.GameMode
= GM_DM
then
1033 Team
:= TEAM_NONE
// DM
1035 if Team
= TEAM_NONE
then
1036 Team
:= BotList
[num
].team
; // CTF / TDM
1038 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1039 lName
:= AnsiLowerCase(lName
);
1040 if (num
< 0) or (num
> Length(BotList
)-1) then
1042 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1043 for a
:= 0 to High(BotList
) do
1044 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1053 _name
:= BotList
[num
].name
;
1054 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1055 if not g_Player_ValidName(_name
) then
1057 _name
:= Format('DFBOT%.2d', [Random(100)]);
1058 until g_Player_ValidName(_name
);
1061 _model
:= BotList
[num
].model
;
1062 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1063 if not InSArray(_model
, m
) then
1064 _model
:= m
[Random(Length(m
))];
1067 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1071 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1072 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1073 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1074 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1075 FDifficult
.Cover
:= BotList
[num
].cover
;
1076 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1078 for a
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
1080 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1081 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1082 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1085 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1087 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1091 procedure g_Bot_RemoveAll();
1095 if not g_Game_IsServer
then Exit
;
1096 if gPlayers
= nil then Exit
;
1098 for a
:= 0 to High(gPlayers
) do
1099 if gPlayers
[a
] <> nil then
1100 if gPlayers
[a
] is TBot
then
1102 gPlayers
[a
].Lives
:= 0;
1103 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1104 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1105 g_Player_Remove(gPlayers
[a
].FUID
);
1111 procedure g_Bot_MixNames();
1116 if BotNames
<> nil then
1117 for a
:= 0 to High(BotNames
) do
1119 b
:= Random(Length(BotNames
));
1121 Botnames
[a
] := BotNames
[b
];
1126 procedure g_Player_Remove(UID
: Word);
1130 if gPlayers
= nil then Exit
;
1132 if g_Game_IsServer
and g_Game_IsNet
then
1133 MH_SEND_PlayerDelete(UID
);
1135 for i
:= 0 to High(gPlayers
) do
1136 if gPlayers
[i
] <> nil then
1137 if gPlayers
[i
].FUID
= UID
then
1139 if gPlayers
[i
] is TPlayer
then
1140 TPlayer(gPlayers
[i
]).Free()
1142 TBot(gPlayers
[i
]).Free();
1148 procedure g_Player_Init();
1158 if not FileExists(DataDir
+ BOTNAMES_FILENAME
) then
1161 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1162 AssignFile(F
, DataDir
+ BOTNAMES_FILENAME
);
1173 SetLength(BotNames
, Length(BotNames
)+1);
1174 BotNames
[High(BotNames
)] := s
;
1182 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1183 config
:= TConfig
.CreateFile(DataDir
+ BOTLIST_FILENAME
);
1187 while config
.SectionExists(IntToStr(a
)) do
1189 SetLength(BotList
, Length(BotList
)+1);
1191 with BotList
[High(BotList
)] do
1194 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1196 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1198 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1203 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1204 color
.R
:= StrToIntDef(sa
[0], 0);
1205 color
.G
:= StrToIntDef(sa
[1], 0);
1206 color
.B
:= StrToIntDef(sa
[2], 0);
1207 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1208 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1209 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1210 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1211 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1212 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1213 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1214 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1215 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1216 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1217 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1218 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1219 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1220 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1221 if Length(sa
) = 10 then
1223 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1224 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1225 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1226 if Length(sa
) = 10 then
1228 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1230 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1231 if Length(sa) = 10 then
1233 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1242 procedure g_Player_Free();
1246 if gPlayers
<> nil then
1248 for i
:= 0 to High(gPlayers
) do
1249 if gPlayers
[i
] <> nil then
1251 if gPlayers
[i
] is TPlayer
then
1252 TPlayer(gPlayers
[i
]).Free()
1254 TBot(gPlayers
[i
]).Free();
1265 procedure g_Player_UpdateAll();
1269 if gPlayers
= nil then Exit
;
1271 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1272 for i
:= 0 to High(gPlayers
) do
1274 if gPlayers
[i
] <> nil then
1276 if gPlayers
[i
] is TPlayer
then
1278 gPlayers
[i
].Update();
1279 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1283 // bot updates weapons in `UpdateCombat()`
1284 TBot(gPlayers
[i
]).Update();
1288 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1291 procedure g_Player_DrawAll();
1295 if gPlayers
= nil then Exit
;
1297 for i
:= 0 to High(gPlayers
) do
1298 if gPlayers
[i
] <> nil then
1299 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1300 else TBot(gPlayers
[i
]).Draw();
1303 procedure g_Player_DrawDebug(p
: TPlayer
);
1307 if p
= nil then Exit
;
1308 if (@p
.FObj
) = nil then Exit
;
1310 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1312 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1313 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1314 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1315 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1316 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1317 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1320 procedure g_Player_DrawHealth();
1325 if gPlayers
= nil then Exit
;
1326 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1328 for i
:= 0 to High(gPlayers
) do
1329 if gPlayers
[i
] <> nil then
1331 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1332 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1333 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1334 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1335 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1336 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1340 function g_Player_Get(UID
: Word): TPlayer
;
1346 if gPlayers
= nil then
1349 for a
:= 0 to High(gPlayers
) do
1350 if gPlayers
[a
] <> nil then
1351 if gPlayers
[a
].FUID
= UID
then
1353 Result
:= gPlayers
[a
];
1358 function g_Player_GetCount(): Byte;
1364 if gPlayers
= nil then
1367 for a
:= 0 to High(gPlayers
) do
1368 if gPlayers
[a
] <> nil then
1369 Result
:= Result
+ 1;
1372 function g_Player_GetStats(): TPlayerStatArray
;
1378 if gPlayers
= nil then Exit
;
1380 for a
:= 0 to High(gPlayers
) do
1381 if gPlayers
[a
] <> nil then
1383 SetLength(Result
, Length(Result
)+1);
1384 with Result
[High(Result
)] do
1386 Ping
:= gPlayers
[a
].FPing
;
1387 Loss
:= gPlayers
[a
].FLoss
;
1388 Name
:= gPlayers
[a
].FName
;
1389 Team
:= gPlayers
[a
].FTeam
;
1390 Frags
:= gPlayers
[a
].FFrags
;
1391 Deaths
:= gPlayers
[a
].FDeath
;
1392 Kills
:= gPlayers
[a
].FKills
;
1393 Color
:= gPlayers
[a
].FModel
.Color
;
1394 Lives
:= gPlayers
[a
].FLives
;
1395 Spectator
:= gPlayers
[a
].FSpectator
;
1400 procedure g_Player_RememberAll
;
1404 for i
:= Low(gPlayers
) to High(gPlayers
) do
1405 if (gPlayers
[i
] <> nil) and gPlayers
[i
].Live
then
1406 gPlayers
[i
].RememberState
;
1409 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1413 gTeamStat
[TEAM_RED
].Goals
:= 0;
1414 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1416 if gPlayers
<> nil then
1417 for i
:= 0 to High(gPlayers
) do
1418 if gPlayers
[i
] <> nil then
1420 gPlayers
[i
].Reset(Force
);
1422 if gPlayers
[i
] is TPlayer
then
1424 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1425 gPlayers
[i
].Respawn(Silent
)
1427 gPlayers
[i
].Spectate();
1430 TBot(gPlayers
[i
]).Respawn(Silent
);
1434 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1441 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1446 if (FHealth
>= -50) or (gGibsCount
= 0) then
1448 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1452 for find_id
:= 0 to High(gCorpses
) do
1453 if gCorpses
[find_id
] = nil then
1460 find_id
:= Random(Length(gCorpses
));
1462 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1463 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1464 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1465 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1468 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1469 FObj
.Y
+ PLAYER_RECT_CY
,
1470 FModel
.Name
, FModel
.Color
);
1474 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1478 if (gShells
= nil) or (Length(gShells
) = 0) then
1481 with gShells
[CurrentShell
] do
1487 if T
= SHELL_BULLET
then
1489 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1493 Obj
.Rect
.Width
:= 4;
1494 Obj
.Rect
.Height
:= 2;
1498 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1502 Obj
.Rect
.Width
:= 7;
1503 Obj
.Rect
.Height
:= 3;
1509 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1510 RAngle
:= Random(360);
1511 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1513 if CurrentShell
>= High(gShells
) then
1520 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1523 GibsArray
: TGibsArray
;
1525 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1527 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1530 for a
:= 0 to High(GibsArray
) do
1531 with gGibs
[CurrentGib
] do
1534 ID
:= GibsArray
[a
].ID
;
1535 MaskID
:= GibsArray
[a
].MaskID
;
1538 Obj
.Rect
:= GibsArray
[a
].Rect
;
1539 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1540 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1541 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1542 RAngle
:= Random(360);
1544 if gBloodCount
> 0 then
1545 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1546 Random(48), Random(48), 150, 0, 0);
1548 if CurrentGib
>= High(gGibs
) then
1555 procedure g_Player_UpdatePhysicalObjects();
1561 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1566 if T
= SHELL_BULLET
then
1567 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1569 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1574 if gGibs
<> nil then
1575 for i
:= 0 to High(gGibs
) do
1576 if gGibs
[i
].Live
then
1580 mr
:= g_Obj_Move(@Obj
, True, False, True);
1582 if WordBool(mr
and MOVE_FALLOUT
) then
1588 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1589 if WordBool(mr
and MOVE_HITWALL
) then
1590 Obj
.Vel
.X
:= -(vel
.X
div 2);
1591 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1592 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1594 if (Obj
.Vel
.X
>= 0) then
1596 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1597 if RAngle
>= 360 then
1598 RAngle
:= RAngle
mod 360;
1599 end else begin // Counter-clockwise
1600 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1602 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1605 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1606 if gTime
mod (GAME_TICK
*3) = 0 then
1607 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1611 if gCorpses
<> nil then
1612 for i
:= 0 to High(gCorpses
) do
1613 if gCorpses
[i
] <> nil then
1614 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1620 gCorpses
[i
].Update();
1623 if gShells
<> nil then
1624 for i
:= 0 to High(gShells
) do
1625 if gShells
[i
].Live
then
1629 mr
:= g_Obj_Move(@Obj
, True, False, True);
1631 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1637 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1638 if WordBool(mr
and MOVE_HITWALL
) then
1640 Obj
.Vel
.X
:= -(vel
.X
div 2);
1641 if not WordBool(mr
and MOVE_INWATER
) then
1642 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1644 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1646 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1647 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1648 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1650 if RAngle
mod 90 <> 0 then
1651 RAngle
:= (RAngle
div 90) * 90;
1653 else if not WordBool(mr
and MOVE_INWATER
) then
1654 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1657 if (Obj
.Vel
.X
>= 0) then
1659 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1660 if RAngle
>= 360 then
1661 RAngle
:= RAngle
mod 360;
1662 end else begin // Counter-clockwise
1663 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1665 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1670 procedure g_Player_DrawCorpses();
1675 if gGibs
<> nil then
1676 for i
:= 0 to High(gGibs
) do
1677 if gGibs
[i
].Live
then
1680 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1683 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1684 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1686 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1689 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1695 if gCorpses
<> nil then
1696 for i
:= 0 to High(gCorpses
) do
1697 if gCorpses
[i
] <> nil then
1701 procedure g_Player_DrawShells();
1706 if gShells
<> nil then
1707 for i
:= 0 to High(gShells
) do
1708 if gShells
[i
].Live
then
1711 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1717 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1721 procedure g_Player_RemoveAllCorpses();
1727 SetLength(gGibs
, MaxGibs
);
1728 SetLength(gShells
, MaxGibs
);
1732 if gCorpses
<> nil then
1733 for i
:= 0 to High(gCorpses
) do
1737 SetLength(gCorpses
, MaxCorpses
);
1740 procedure g_Player_Corpses_SaveState(var Mem
: TBinMemoryWriter
);
1745 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ:
1747 if gCorpses
<> nil then
1748 for i
:= 0 to High(gCorpses
) do
1749 if gCorpses
[i
] <> nil then
1752 Mem
:= TBinMemoryWriter
.Create((count
+1) * 128);
1754 // Êîëè÷åñòâî òðóïîâ:
1755 Mem
.WriteInt(count
);
1761 for i
:= 0 to High(gCorpses
) do
1762 if gCorpses
[i
] <> nil then
1765 Mem
.WriteString(gCorpses
[i
].FModelName
);
1767 b
:= gCorpses
[i
].Mess
;
1768 Mem
.WriteBoolean(b
);
1769 // Ñîõðàíÿåì äàííûå òðóïà:
1770 gCorpses
[i
].SaveState(Mem
);
1774 procedure g_Player_Corpses_LoadState(var Mem
: TBinMemoryReader
);
1783 g_Player_RemoveAllCorpses();
1785 // Êîëè÷åñòâî òðóïîâ:
1788 if count
> Length(gCorpses
) then
1790 raise EBinSizeError
.Create('g_Player_Corpses_LoadState: Too Many Corpses');
1797 for i
:= 0 to count
-1 do
1800 Mem
.ReadString(str
);
1804 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1805 // Çàãðóæàåì äàííûå òðóïà:
1806 gCorpses
[i
].LoadState(Mem
);
1812 procedure TPlayer
.BFGHit();
1814 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1815 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1816 if g_Game_IsServer
and g_Game_IsNet
then
1817 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1818 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1822 procedure TPlayer
.ChangeModel(ModelName
: string);
1824 Model
: TPlayerModel
;
1826 Model
:= g_PlayerModel_Get(ModelName
);
1827 if Model
= nil then Exit
;
1833 procedure TPlayer
.SetModel(ModelName
: string);
1837 m
:= g_PlayerModel_Get(ModelName
);
1840 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1841 m
:= g_PlayerModel_Get('doomer');
1844 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1849 if FModel
<> nil then
1854 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1855 FModel
.Color
:= FColor
1857 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1858 FModel
.SetWeapon(FCurrWeap
);
1859 FModel
.SetFlag(FFlag
);
1860 SetDirection(FDirection
);
1863 procedure TPlayer
.SetColor(Color
: TRGB
);
1866 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1867 if FModel
<> nil then FModel
.Color
:= Color
;
1870 procedure TPlayer
.SwitchTeam
;
1872 if g_Game_IsClient
then
1874 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
1876 if gGameOn
and FLive
then
1877 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
1879 if FTeam
= TEAM_RED
then
1881 ChangeTeam(TEAM_BLUE
);
1882 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
1883 if g_Game_IsNet
then
1884 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
1888 ChangeTeam(TEAM_RED
);
1889 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
1890 if g_Game_IsNet
then
1891 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
1893 FPreferredTeam
:= FTeam
;
1896 procedure TPlayer
.ChangeTeam(Team
: Byte);
1903 TEAM_RED
, TEAM_BLUE
:
1904 FModel
.Color
:= TEAMCOLOR
[Team
];
1906 FModel
.Color
:= FColor
;
1908 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
1909 MH_SEND_PlayerStats(FUID
);
1913 procedure TPlayer.CollideItem();
1918 if gItems = nil then Exit;
1919 if not FLive then Exit;
1921 for i := 0 to High(gItems) do
1924 if (ItemType <> ITEM_NONE) and Live then
1925 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
1926 PLAYER_RECT.Height, @Obj) then
1928 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
1930 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
1931 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
1932 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
1933 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
1934 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
1936 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
1937 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
1938 (gGameSettings.GameType = GT_SINGLE) and
1939 (g_Player_GetCount() > 1)) then
1940 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
1946 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
1948 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
1949 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
1953 constructor TPlayer
.Create();
1959 FSawSound
:= TPlayableSound
.Create();
1960 FSawSoundIdle
:= TPlayableSound
.Create();
1961 FSawSoundHit
:= TPlayableSound
.Create();
1962 FSawSoundSelect
:= TPlayableSound
.Create();
1963 FJetSoundFly
:= TPlayableSound
.Create();
1964 FJetSoundOn
:= TPlayableSound
.Create();
1965 FJetSoundOff
:= TPlayableSound
.Create();
1967 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
1968 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
1969 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
1970 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
1971 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
1972 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
1973 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
1975 FSpectatePlayer
:= -1;
1979 FSavedState
.WaitRecall
:= False;
1982 FActualModelName
:= 'doomer';
1985 FObj
.Rect
:= PLAYER_RECT
;
1987 FBFGFireCounter
:= -1;
1988 FJustTeleported
:= False;
1994 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
1998 if (not g_Game_IsClient
) and (not FLive
) then
2003 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2004 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2006 if not g_Game_IsClient
then
2009 if t
= HIT_TRAP
then
2011 // Ëîâóøêà óáèâàåò ñðàçó:
2013 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2015 if t
= HIT_SELF
then
2019 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2022 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2023 FMegaRulez
[MR_SUIT
] := 0;
2024 FMegaRulez
[MR_INVUL
] := 0;
2025 FMegaRulez
[MR_INVIS
] := 0;
2029 // Íî îò îñòàëüíîãî ñïàñàåò:
2030 if FMegaRulez
[MR_INVUL
] >= gTime
then
2037 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2038 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2039 (SpawnerUID
= FUID
) or
2040 (not SameTeam(FUID
, SpawnerUID
)) then
2042 FLastSpawnerUID
:= SpawnerUID
;
2044 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2045 if gBloodCount
> 0 then
2047 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2048 if value
div 4 <= c
then
2049 c
:= c
- (value
div 4)
2053 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2057 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2058 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2061 if t
= HIT_WATER
then
2062 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2063 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2068 Inc(FDamageBuffer
, value
);
2072 FPain
:= FPain
+ value
;
2075 if g_Game_IsServer
and g_Game_IsNet
then
2077 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2078 MH_SEND_PlayerStats(FUID
);
2079 MH_SEND_PlayerPos(False, FUID
);
2083 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2086 if g_Game_IsClient
then
2091 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2093 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2096 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2098 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2102 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2103 MH_SEND_PlayerStats(FUID
);
2106 destructor TPlayer
.Destroy();
2108 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2110 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2114 FSawSoundIdle
.Free();
2115 FSawSoundHit
.Free();
2116 FJetSoundFly
.Free();
2118 FJetSoundOff
.Free();
2124 procedure TPlayer
.DrawBubble();
2126 bubX
, bubY
: Integer;
2129 Rw
, Gw
, Bw
: SmallInt;
2132 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= D_LEFT
, -4, 18);
2133 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2141 1: // simple textual non-bubble
2143 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2144 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2145 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2148 2: // advanced pixel-perfect bubble
2150 if FTeam
= TEAM_RED
then
2153 if FTeam
= TEAM_BLUE
then
2156 3: // colored bubble
2158 Rb
:= FModel
.Color
.R
;
2159 Gb
:= FModel
.Color
.G
;
2160 Bb
:= FModel
.Color
.B
;
2161 Rw
:= Min(Rb
* 2 + 64, 255);
2162 Gw
:= Min(Gb
* 2 + 64, 255);
2163 Bw
:= Min(Bb
* 2 + 64, 255);
2164 if (Abs(Rw
- Rb
) < 32)
2165 or (Abs(Gw
- Gb
) < 32)
2166 or (Abs(Bw
- Bb
) < 32) then
2168 Rb
:= Max(Rw
div 2 - 16, 0);
2169 Gb
:= Max(Gw
div 2 - 16, 0);
2170 Bb
:= Max(Bw
div 2 - 16, 0);
2173 4: // custom textured bubble
2175 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2176 if FDirection
= D_RIGHT
then
2177 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2179 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, M_HORIZONTAL
);
2185 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2186 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2188 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2191 Dot
:= IfThen(FDirection
= D_LEFT
, 14, 5);
2192 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2193 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
);
2194 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
);
2195 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
);
2196 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
);
2200 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2201 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2202 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2205 procedure TPlayer
.Draw();
2213 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2214 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2216 e_GetTextureSize(ID
, @w
, @h
);
2217 if FDirection
= D_LEFT
then
2218 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2219 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7, 0, True, False)
2221 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2222 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7, 0, True, False);
2225 if FMegaRulez
[MR_INVIS
] > gTime
then
2227 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2228 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2230 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2231 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2235 FModel
.Draw(FObj
.X
, FObj
.Y
, 200)
2237 FModel
.Draw(FObj
.X
, FObj
.Y
);
2240 FModel
.Draw(FObj
.X
, FObj
.Y
, 254);
2243 FModel
.Draw(FObj
.X
, FObj
.Y
);
2246 if g_debug_Frames
then
2248 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2250 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2251 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2255 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2257 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2258 if gAimLine
and Live
and
2259 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2263 procedure TPlayer
.DrawAim();
2265 wx
, wy
, xx
, yy
: Integer;
2269 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= D_LEFT
, 7, -7);
2270 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2279 1: begin // Chainsaw
2286 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2287 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2288 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2289 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2294 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2295 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2296 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2297 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2299 4: begin // Double Shotgun
2302 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2303 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2304 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2305 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2307 5: begin // Chaingun
2310 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2311 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2312 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2313 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2315 6: begin // Rocket Launcher
2318 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2319 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2320 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2321 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2323 7: begin // Plasmagun
2326 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2327 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2328 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2329 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2334 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2335 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2336 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2337 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2339 9: begin // Super Chaingun
2342 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2343 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2344 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2345 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2348 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2349 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2350 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2353 procedure TPlayer
.DrawGUI();
2356 X
, Y
, SY
, a
, p
, m
: Integer;
2360 stat
: TPlayerStatArray
;
2362 X
:= gPlayerScreenSize
.X
;
2363 SY
:= gPlayerScreenSize
.Y
;
2366 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2368 if gGameSettings
.GameMode
= GM_CTF
then
2372 if gGameSettings
.GameMode
= GM_CTF
then
2374 s
:= 'TEXTURE_PLAYER_REDFLAG';
2375 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2376 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2377 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2378 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2379 if g_Texture_Get(s
, ID
) then
2380 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2383 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2384 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2385 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2387 if gGameSettings
.GameMode
= GM_CTF
then
2389 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2390 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2391 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2392 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2393 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2394 if g_Texture_Get(s
, ID
) then
2395 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2398 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2399 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2400 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2403 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2404 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2407 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2408 e_Draw(ID
, X
+2, Y
, 0, True, False);
2410 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2414 s
:= IntToStr(Frags
);
2415 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2416 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2421 stat
:= g_Player_GetStats();
2426 for a
:= 0 to High(stat
) do
2427 if stat
[a
].Name
<> Name
then
2429 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2430 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2434 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2435 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2436 s
:= s
+IntToStr(Abs(Frags
-m
));
2438 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2439 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2442 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2444 s
:= IntToStr(Lives
);
2445 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2446 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2450 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2451 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2453 if R_BERSERK
in FRulez
then
2454 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2456 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2458 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2459 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2461 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2462 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2463 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2465 s
:= IntToStr(FArmor
);
2466 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2467 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2469 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2475 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2480 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2482 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2483 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2484 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2485 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2486 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2487 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2488 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2489 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2492 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2493 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2494 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2496 if R_KEY_RED
in FRulez
then
2497 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2499 if R_KEY_GREEN
in FRulez
then
2500 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2502 if R_KEY_BLUE
in FRulez
then
2503 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2505 if FJetFuel
> 0 then
2507 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2508 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2509 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2510 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2511 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2512 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2516 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2517 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2518 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2521 if gShowPing
and g_Game_IsClient
then
2523 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2524 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2530 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2531 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2532 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2535 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2536 s
:= _lc
[I_PLAYER_SPECT4
];
2537 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2538 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2539 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2545 procedure TPlayer
.DrawRulez();
2549 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2550 if FMegaRulez
[MR_INVUL
] >= gTime
then
2552 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2553 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2558 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2559 191, 191, 191, 0, B_INVERT
);
2562 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2563 if FMegaRulez
[MR_SUIT
] >= gTime
then
2565 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2566 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2571 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2572 0, 96, 0, 200, B_NONE
);
2575 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2576 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2578 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2579 255, 0, 0, 200, B_NONE
);
2583 procedure TPlayer
.DrawPain();
2587 if FPain
= 0 then Exit
;
2591 if a
< 15 then h
:= 0
2592 else if a
< 35 then h
:= 1
2593 else if a
< 55 then h
:= 2
2594 else if a
< 75 then h
:= 3
2595 else if a
< 95 then h
:= 4
2598 //if a > 255 then a := 255;
2600 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2601 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2604 procedure TPlayer
.DrawPickup();
2608 if FPickup
= 0 then Exit
;
2612 if a
< 15 then h
:= 1
2613 else if a
< 35 then h
:= 2
2614 else if a
< 55 then h
:= 3
2615 else if a
< 75 then h
:= 4
2618 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2621 procedure TPlayer
.Fire();
2623 f
, DidFire
: Boolean;
2624 wx
, wy
, xd
, yd
: Integer;
2627 if g_Game_IsClient
then Exit
;
2628 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2629 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2637 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2642 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2643 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2644 xd
:= wx
+IfThen(FDirection
= D_LEFT
, -30, 30);
2645 yd
:= wy
+firediry();
2650 if R_BERSERK
in FRulez
then
2652 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2653 obj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2654 obj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2657 obj
.rect
.Width
:= 39;
2658 obj
.rect
.Height
:= 52;
2659 obj
.Vel
.X
:= (xd
-wx
) div 2;
2660 obj
.Vel
.Y
:= (yd
-wy
) div 2;
2661 obj
.Accel
.X
:= xd
-wx
;
2662 obj
.Accel
.y
:= yd
-wy
;
2664 if g_Weapon_Hit(@obj
, 50, FUID
, HIT_SOME
) <> 0 then
2665 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2667 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2671 FPain
:= min(FPain
+ 25, 50);
2672 end else g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2675 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2680 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2681 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2683 FSawSoundSelect
.Stop();
2685 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2687 else if not FSawSoundHit
.IsPlaying() then
2689 FSawSoundSelect
.Stop();
2690 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2693 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2699 if FAmmo
[A_BULLETS
] > 0 then
2701 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2702 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2703 Dec(FAmmo
[A_BULLETS
]);
2704 FFireAngle
:= FAngle
;
2707 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2708 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2712 if FAmmo
[A_SHELLS
] > 0 then
2714 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2715 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
2716 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2717 Dec(FAmmo
[A_SHELLS
]);
2718 FFireAngle
:= FAngle
;
2722 FShellType
:= SHELL_SHELL
;
2726 if FAmmo
[A_SHELLS
] >= 2 then
2728 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
2729 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2730 Dec(FAmmo
[A_SHELLS
], 2);
2731 FFireAngle
:= FAngle
;
2735 FShellType
:= SHELL_DBLSHELL
;
2739 if FAmmo
[A_BULLETS
] > 0 then
2741 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
2742 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
2743 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2744 Dec(FAmmo
[A_BULLETS
]);
2745 FFireAngle
:= FAngle
;
2748 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2749 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2752 WEAPON_ROCKETLAUNCHER
:
2753 if FAmmo
[A_ROCKETS
] > 0 then
2755 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
2756 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2757 Dec(FAmmo
[A_ROCKETS
]);
2758 FFireAngle
:= FAngle
;
2764 if FAmmo
[A_CELLS
] > 0 then
2766 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
2767 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2768 Dec(FAmmo
[A_CELLS
]);
2769 FFireAngle
:= FAngle
;
2775 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
2777 FBFGFireCounter
:= 17;
2778 if not FNoReload
then
2779 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
2780 Dec(FAmmo
[A_CELLS
], 40);
2784 WEAPON_SUPERPULEMET
:
2785 if FAmmo
[A_SHELLS
] > 0 then
2787 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2788 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
2789 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2790 Dec(FAmmo
[A_SHELLS
]);
2791 FFireAngle
:= FAngle
;
2794 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2795 GameVelX
, GameVelY
-2, SHELL_SHELL
);
2799 if g_Game_IsNet
then
2803 if FCurrWeap
<> WEAPON_BFG
then
2804 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
2806 if not FNoReload
then
2807 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
2810 MH_SEND_PlayerStats(FUID
);
2815 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
2816 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
2817 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
2820 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
2823 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
2824 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
2825 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
2826 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
2831 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
2833 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
2834 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
2835 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
2838 procedure TPlayer
.JetpackOn
;
2842 FJetSoundOn
.SetPosition(0);
2843 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
2847 procedure TPlayer
.JetpackOff
;
2851 FJetSoundOff
.SetPosition(0);
2852 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
2855 procedure TPlayer
.Jump();
2857 if gFly
or FJetpack
then
2859 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
2860 if FObj
.Vel
.Y
> -VEL_FLY
then
2861 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
2864 if FJetFuel
> 0 then
2866 if (FJetFuel
< 1) and g_Game_IsServer
then
2870 if g_Game_IsNet
then
2871 MH_SEND_PlayerStats(FUID
);
2877 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
2879 FCanJetpack
:= False;
2881 // Ïðûãàåì èëè âñïëûâàåì:
2882 if (CollideLevel(0, 1) or
2883 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
2884 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
2885 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
2887 FObj
.Vel
.Y
:= -VEL_JUMP
;
2888 FCanJetpack
:= False;
2892 if BodyInLiquid(0, 0) then
2893 FObj
.Vel
.Y
:= -VEL_SW
2894 else if (FJetFuel
> 0) and FCanJetpack
and
2895 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
2899 if g_Game_IsNet
then
2900 MH_SEND_PlayerStats(FUID
);
2905 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
2907 a
, i
, k
, ab
, ar
: Byte;
2911 srv
, netsrv
: Boolean;
2916 procedure PushItem(t
: Byte);
2920 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
2921 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
2922 g_Obj_Push(@gItems
[id
].Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
2923 (FObj
.Vel
.Y
div 2)-Random(9))
2925 if KillType
= K_HARDKILL
then // -5..+5; -5..0
2926 g_Obj_Push(@gItems
[id
].Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
2927 (FObj
.Vel
.Y
div 2)-Random(6))
2928 else // -3..+3; -3..0
2929 g_Obj_Push(@gItems
[id
].Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
2930 (FObj
.Vel
.Y
div 2)-Random(4));
2932 if g_Game_IsNet
and g_Game_IsServer
then
2933 MH_SEND_ItemSpawn(True, id
);
2937 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
2938 Srv
:= g_Game_IsServer
;
2939 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
2940 if Srv
then FDeath
:= FDeath
+ 1;
2945 if not FPhysics
then
2951 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2953 if FLives
> 0 then FLives
:= FLives
- 1;
2954 if FLives
= 0 then FNoRespawn
:= True;
2957 // Íîìåð òèïà ñìåðòè:
2960 K_SIMPLEKILL
: a
:= 1;
2962 K_EXTRAHARDKILL
: a
:= 3;
2967 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
2969 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
2976 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
2978 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
2979 K_EXTRAHARDKILL
, K_FALLKILL
:
2980 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
2983 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
2987 K_HARDKILL
, K_EXTRAHARDKILL
:
2991 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
2992 if (KillType
<> K_FALLKILL
) and (Srv
) then
2993 g_Monsters_killedp();
2995 if SpawnerUID
= FUID
then
2997 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3002 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3005 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3006 begin // Óáèò äðóãèì èãðîêîì
3007 KP
:= g_Player_Get(SpawnerUID
);
3008 if (KP
<> nil) and Srv
then
3010 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3011 if SameTeam(FUID
, SpawnerUID
) then
3021 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3022 Inc(gTeamStat
[KP
.Team
].Goals
,
3023 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3025 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3028 plr
:= g_Player_Get(SpawnerUID
);
3036 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3040 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3044 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3049 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3050 begin // Óáèò ìîíñòðîì
3051 mon
:= g_Monsters_Get(SpawnerUID
);
3055 s
:= g_Monsters_GetKilledBy(mon
.MonsterType
);
3059 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3063 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3067 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3072 else // Îñîáûå òèïû ñìåðòè
3075 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3076 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3077 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3078 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3079 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3080 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3086 for a
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
3090 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3091 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3092 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3093 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3094 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3095 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3096 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3097 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3106 if R_ITEM_BACKPACK
in FRulez
then
3107 PushItem(ITEM_AMMO_BACKPACK
);
3109 // Âûáðîñ ðàêåòíîãî ðàíöà:
3110 if FJetFuel
> 0 then
3111 PushItem(ITEM_JETPACK
);
3114 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3116 if R_KEY_RED
in FRulez
then
3117 PushItem(ITEM_KEY_RED
);
3119 if R_KEY_GREEN
in FRulez
then
3120 PushItem(ITEM_KEY_GREEN
);
3122 if R_KEY_BLUE
in FRulez
then
3123 PushItem(ITEM_KEY_BLUE
);
3130 g_Player_CreateCorpse(Self
);
3132 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3133 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3139 for i
:= Low(gPlayers
) to High(gPlayers
) do
3141 if gPlayers
[i
] = nil then continue
;
3142 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3145 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3146 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3151 OldLR
:= gLMSRespawn
;
3152 if (gGameSettings
.GameMode
= GM_COOP
) then
3156 // everyone is dead, restart the map
3157 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3159 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3160 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3161 gLMSRespawnTime
:= gTime
+ 5000;
3163 else if (a
= 1) then
3165 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3166 if (gPlayers
[k
] = gPlayer1
) or
3167 (gPlayers
[k
] = gPlayer2
) then
3168 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3169 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3170 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3173 else if (gGameSettings
.GameMode
= GM_TDM
) then
3175 if (ab
= 0) and (ar
<> 0) then
3178 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3180 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3181 Inc(gTeamStat
[TEAM_RED
].Goals
);
3182 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3183 gLMSRespawnTime
:= gTime
+ 5000;
3185 else if (ar
= 0) and (ab
<> 0) then
3188 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3190 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3191 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3192 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3193 gLMSRespawnTime
:= gTime
+ 5000;
3195 else if (ar
= 0) and (ab
= 0) then
3198 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3200 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3201 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3202 gLMSRespawnTime
:= gTime
+ 5000;
3205 else if (gGameSettings
.GameMode
= GM_DM
) then
3209 if gPlayers
[k
] <> nil then
3212 // survivor is the winner
3213 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3215 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3218 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3219 gLMSRespawnTime
:= gTime
+ 5000;
3221 else if (a
= 0) then
3223 // everyone is dead, restart the map
3224 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3226 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3227 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3228 gLMSRespawnTime
:= gTime
+ 5000;
3231 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3233 if NetMode
= NET_SERVER
then
3234 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3236 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3242 MH_SEND_PlayerStats(FUID
);
3243 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3244 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3247 if srv
and FNoRespawn
then Spectate(True);
3248 FWantsInGame
:= True;
3251 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3253 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3254 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3257 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3259 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3260 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3263 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3265 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3266 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3267 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3269 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3270 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3271 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3275 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3277 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3278 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3279 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3283 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3285 if g_Game_IsClient
then Exit
;
3286 if Weapon
> High(FWeapon
) then Exit
;
3287 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3290 procedure TPlayer
.resetWeaponQueue ();
3293 FNextWeapDelay
:= 0;
3296 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3300 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3301 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 0);
3302 WEAPON_PISTOL
, WEAPON_CHAINGUN
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_BULLETS
] > 0);
3303 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3304 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3305 else result
:= (weapon
< length(FWeapon
));
3309 // return 255 for "no switch"
3310 function TPlayer
.getNextWeaponIndex (): Byte;
3313 wantThisWeapon
: array[0..64] of Boolean;
3314 wwc
: Integer = 0; //HACK!
3317 result
:= 255; // default result: "no switch"
3318 // had weapon cycling on previous frame? remove that flag
3319 if (FNextWeap
and $2000) <> 0 then begin FNextWeap
:= FNextWeap
and $1FFF; FNextWeapDelay
:= 0; end;
3320 // cycling has priority
3321 if (FNextWeap
and $C000) <> 0 then
3323 if (FNextWeap
and $8000) <> 0 then dir
:= 1 else dir
:= -1;
3324 FNextWeap
:= FNextWeap
or $2000; // we need this
3325 if FNextWeapDelay
> 0 then exit
; // cooldown time
3327 for i
:= 0 to High(FWeapon
) do
3329 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3330 if FWeapon
[cwi
] then
3332 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d', [FCurrWeap, cwi]), MSG_WARNING);
3333 result
:= Byte(cwi
);
3334 FNextWeapDelay
:= 10;
3342 for i
:= 0 to High(wantThisWeapon
) do wantThisWeapon
[i
] := false;
3343 for i
:= 0 to High(FWeapon
) do if (FNextWeap
and (1 shl i
)) <> 0 then begin wantThisWeapon
[i
] := true; Inc(wwc
); end;
3344 // exclude currently selected weapon from the set
3345 wantThisWeapon
[FCurrWeap
] := false;
3346 // slow down alterations a little
3349 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3350 // more than one weapon requested, assume "alteration" and check alteration delay
3351 if FNextWeapDelay
> 0 then begin FNextWeap
:= 0; exit
; end; // yeah
3353 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3354 // but clear all counters if no weapon should be switched
3355 if wwc
< 1 then begin resetWeaponQueue(); exit
; end;
3356 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3357 // try weapons in descending order
3358 for i
:= High(FWeapon
) downto 0 do
3360 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3365 FNextWeapDelay
:= 10; // anyway, 'cause why not
3369 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3373 procedure TPlayer
.RealizeCurrentWeapon();
3374 function switchAllowed (): Boolean;
3379 if FBFGFireCounter
<> -1 then exit
;
3380 if FTime
[T_SWITCH
] > gTime
then exit
;
3381 for i
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do if FReloading
[i
] > 0 then exit
;
3388 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3389 //FNextWeap := FNextWeap and $1FFF;
3390 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3392 if not switchAllowed
then
3394 //HACK for weapon cycling
3395 if (FNextWeap
and $7000) <> 0 then FNextWeap
:= 0;
3399 nw
:= getNextWeaponIndex();
3400 if nw
= 255 then exit
; // don't reset anything here
3401 if nw
> High(FWeapon
) then
3403 // don't forget to reset queue here!
3404 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3412 FTime
[T_SWITCH
] := gTime
+156;
3413 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3414 FModel
.SetWeapon(FCurrWeap
);
3415 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3419 procedure TPlayer
.NextWeapon();
3421 if g_Game_IsClient
then Exit
;
3425 procedure TPlayer
.PrevWeapon();
3427 if g_Game_IsClient
then Exit
;
3431 procedure TPlayer
.SetWeapon(W
: Byte);
3433 if FCurrWeap
<> W
then
3434 if W
= WEAPON_SAW
then
3435 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3438 FModel
.SetWeapon(CurrWeap
);
3442 function TPlayer
.PickItem(ItemType
: Byte; respawn
: Boolean; var remove
: Boolean): Boolean;
3447 if g_Game_IsClient
then Exit
;
3449 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3450 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and respawn
;
3455 if FHealth
< PLAYER_HP_SOFT
then
3457 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3460 if gFlash
= 2 then Inc(FPickup
, 5);
3464 if FHealth
< PLAYER_HP_SOFT
then
3466 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3469 if gFlash
= 2 then Inc(FPickup
, 5);
3473 if FArmor
< PLAYER_AP_SOFT
then
3475 FArmor
:= PLAYER_AP_SOFT
;
3478 if gFlash
= 2 then Inc(FPickup
, 5);
3482 if FArmor
< PLAYER_AP_LIMIT
then
3484 FArmor
:= PLAYER_AP_LIMIT
;
3487 if gFlash
= 2 then Inc(FPickup
, 5);
3491 if FHealth
< PLAYER_HP_LIMIT
then
3493 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3496 if gFlash
= 2 then Inc(FPickup
, 5);
3500 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3502 if FHealth
< PLAYER_HP_LIMIT
then
3503 FHealth
:= PLAYER_HP_LIMIT
;
3504 if FArmor
< PLAYER_AP_LIMIT
then
3505 FArmor
:= PLAYER_AP_LIMIT
;
3508 if gFlash
= 2 then Inc(FPickup
, 5);
3512 if (not FWeapon
[WEAPON_SAW
]) or ((not respawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3514 FWeapon
[WEAPON_SAW
] := True;
3516 if gFlash
= 2 then Inc(FPickup
, 5);
3517 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3520 ITEM_WEAPON_SHOTGUN1
:
3521 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3523 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3524 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3526 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3527 FWeapon
[WEAPON_SHOTGUN1
] := True;
3529 if gFlash
= 2 then Inc(FPickup
, 5);
3530 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3533 ITEM_WEAPON_SHOTGUN2
:
3534 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3536 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3538 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3539 FWeapon
[WEAPON_SHOTGUN2
] := True;
3541 if gFlash
= 2 then Inc(FPickup
, 5);
3542 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3545 ITEM_WEAPON_CHAINGUN
:
3546 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3548 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3550 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3551 FWeapon
[WEAPON_CHAINGUN
] := True;
3553 if gFlash
= 2 then Inc(FPickup
, 5);
3554 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3557 ITEM_WEAPON_ROCKETLAUNCHER
:
3558 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3560 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3562 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3563 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3565 if gFlash
= 2 then Inc(FPickup
, 5);
3566 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3570 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3572 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3574 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3575 FWeapon
[WEAPON_PLASMA
] := True;
3577 if gFlash
= 2 then Inc(FPickup
, 5);
3578 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3582 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3584 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3586 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3587 FWeapon
[WEAPON_BFG
] := True;
3589 if gFlash
= 2 then Inc(FPickup
, 5);
3590 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3593 ITEM_WEAPON_SUPERPULEMET
:
3594 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3596 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3598 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3599 FWeapon
[WEAPON_SUPERPULEMET
] := True;
3601 if gFlash
= 2 then Inc(FPickup
, 5);
3602 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3606 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3608 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3611 if gFlash
= 2 then Inc(FPickup
, 5);
3614 ITEM_AMMO_BULLETS_BOX
:
3615 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3617 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3620 if gFlash
= 2 then Inc(FPickup
, 5);
3624 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3626 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3629 if gFlash
= 2 then Inc(FPickup
, 5);
3632 ITEM_AMMO_SHELLS_BOX
:
3633 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3635 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
3638 if gFlash
= 2 then Inc(FPickup
, 5);
3642 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3644 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3647 if gFlash
= 2 then Inc(FPickup
, 5);
3650 ITEM_AMMO_ROCKET_BOX
:
3651 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3653 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
3656 if gFlash
= 2 then Inc(FPickup
, 5);
3660 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3662 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3665 if gFlash
= 2 then Inc(FPickup
, 5);
3669 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3671 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
3674 if gFlash
= 2 then Inc(FPickup
, 5);
3678 if not(R_ITEM_BACKPACK
in FRulez
) or
3679 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
3680 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
3681 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
3682 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) then
3684 FMaxAmmo
[A_BULLETS
] := 400;
3685 FMaxAmmo
[A_SHELLS
] := 100;
3686 FMaxAmmo
[A_ROCKETS
] := 100;
3687 FMaxAmmo
[A_CELLS
] := 600;
3689 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3690 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3691 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3692 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3693 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3694 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3695 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3696 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3698 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
3701 if gFlash
= 2 then Inc(FPickup
, 5);
3705 if not(R_KEY_RED
in FRulez
) then
3707 Include(FRulez
, R_KEY_RED
);
3709 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3710 if gFlash
= 2 then Inc(FPickup
, 5);
3711 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3715 if not(R_KEY_GREEN
in FRulez
) then
3717 Include(FRulez
, R_KEY_GREEN
);
3719 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3720 if gFlash
= 2 then Inc(FPickup
, 5);
3721 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3725 if not(R_KEY_BLUE
in FRulez
) then
3727 Include(FRulez
, R_KEY_BLUE
);
3729 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3730 if gFlash
= 2 then Inc(FPickup
, 5);
3731 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3735 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
3737 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
3740 if gFlash
= 2 then Inc(FPickup
, 5);
3744 if FAir
< AIR_MAX
then
3749 if gFlash
= 2 then Inc(FPickup
, 5);
3754 if not (R_BERSERK
in FRulez
) then
3756 Include(FRulez
, R_BERSERK
);
3757 if FBFGFireCounter
= -1 then
3759 FCurrWeap
:= WEAPON_KASTET
;
3761 FModel
.SetWeapon(WEAPON_KASTET
);
3765 if gFlash
= 2 then Inc(FPickup
, 5);
3766 FBerserk
:= gTime
+30000;
3770 if FHealth
< PLAYER_HP_SOFT
then
3772 FHealth
:= PLAYER_HP_SOFT
;
3773 FBerserk
:= gTime
+30000;
3780 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
3782 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
3785 if gFlash
= 2 then Inc(FPickup
, 5);
3789 if FHealth
< PLAYER_HP_LIMIT
then
3791 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
3794 if gFlash
= 2 then Inc(FPickup
, 5);
3798 if FArmor
< PLAYER_AP_LIMIT
then
3800 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
3803 if gFlash
= 2 then Inc(FPickup
, 5);
3807 if FJetFuel
< JET_MAX
then
3809 FJetFuel
:= JET_MAX
;
3812 if gFlash
= 2 then Inc(FPickup
, 5);
3816 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
3818 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
3821 if gFlash
= 2 then Inc(FPickup
, 5);
3826 procedure TPlayer
.Touch();
3830 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
3833 // Áðîñèòü ôëàã òîâàðèùó:
3834 if gGameSettings
.GameMode
= GM_CTF
then
3839 procedure TPlayer
.Push(vx
, vy
: Integer);
3841 if (not FPhysics
) and FGhost
then
3843 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
3844 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
3845 if g_Game_IsNet
and g_Game_IsServer
then
3846 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
3849 procedure TPlayer
.Reset(Force
: Boolean);
3855 FTime
[T_RESPAWN
] := 0;
3856 FTime
[T_FLAGCAP
] := 0;
3869 FSpectator
:= False;
3872 FSpectatePlayer
:= -1;
3873 FNoRespawn
:= False;
3875 FLives
:= gGameSettings
.MaxLives
;
3880 procedure TPlayer
.SoftReset();
3886 FBFGFireCounter
:= -1;
3894 SetAction(A_STAND
, True);
3897 function TPlayer
.GetRespawnPoint(): Byte;
3902 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
3904 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
3905 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
3907 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
3909 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
3910 if Self
= gPlayer1
then
3911 c
:= RESPAWNPOINT_PLAYER1
3913 c
:= RESPAWNPOINT_PLAYER2
;
3914 if g_Map_GetPointCount(c
) > 0 then
3920 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
3921 if Self
= gPlayer1
then
3922 c
:= RESPAWNPOINT_PLAYER2
3924 c
:= RESPAWNPOINT_PLAYER1
;
3925 if g_Map_GetPointCount(c
) > 0 then
3932 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
3933 if Random(2) = 0 then
3934 c
:= RESPAWNPOINT_PLAYER1
3936 c
:= RESPAWNPOINT_PLAYER2
;
3937 if g_Map_GetPointCount(c
) > 0 then
3944 // Òî÷êà ëþáîé èç êîìàíä
3945 if Random(2) = 0 then
3946 c
:= RESPAWNPOINT_RED
3948 c
:= RESPAWNPOINT_BLUE
;
3949 if g_Map_GetPointCount(c
) > 0 then
3956 c
:= RESPAWNPOINT_DM
;
3957 if g_Map_GetPointCount(c
) > 0 then
3965 if gGameSettings
.GameMode
= GM_DM
then
3968 c
:= RESPAWNPOINT_DM
;
3969 if g_Map_GetPointCount(c
) > 0 then
3975 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
3976 if Random(2) = 0 then
3977 c
:= RESPAWNPOINT_PLAYER1
3979 c
:= RESPAWNPOINT_PLAYER2
;
3980 if g_Map_GetPointCount(c
) > 0 then
3986 // Òî÷êà ëþáîé èç êîìàíä
3987 if Random(2) = 0 then
3988 c
:= RESPAWNPOINT_RED
3990 c
:= RESPAWNPOINT_BLUE
;
3991 if g_Map_GetPointCount(c
) > 0 then
3999 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4001 // Òî÷êà ñâîåé êîìàíäû
4002 c
:= RESPAWNPOINT_DM
;
4003 if FTeam
= TEAM_RED
then
4004 c
:= RESPAWNPOINT_RED
;
4005 if FTeam
= TEAM_BLUE
then
4006 c
:= RESPAWNPOINT_BLUE
;
4007 if g_Map_GetPointCount(c
) > 0 then
4014 c
:= RESPAWNPOINT_DM
;
4015 if g_Map_GetPointCount(c
) > 0 then
4021 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4022 if Random(2) = 0 then
4023 c
:= RESPAWNPOINT_PLAYER1
4025 c
:= RESPAWNPOINT_PLAYER2
;
4026 if g_Map_GetPointCount(c
) > 0 then
4032 // Òî÷êà äðóãîé êîìàíäû
4033 c
:= RESPAWNPOINT_DM
;
4034 if FTeam
= TEAM_RED
then
4035 c
:= RESPAWNPOINT_BLUE
;
4036 if FTeam
= TEAM_BLUE
then
4037 c
:= RESPAWNPOINT_RED
;
4038 if g_Map_GetPointCount(c
) > 0 then
4046 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4048 RespawnPoint
: TRespawnPoint
;
4053 if not g_Game_IsServer
then
4057 FWantsInGame
:= True;
4058 FJustTeleported
:= True;
4061 FTime
[T_RESPAWN
] := 0;
4065 // if server changes MaxLives we gotta be ready
4066 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4068 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4069 if FTime
[T_RESPAWN
] > gTime
then
4072 // Ïðîñðàë âñå æèçíè:
4075 if not FSpectator
then Spectate(True);
4076 FWantsInGame
:= True;
4080 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4081 begin // "Ñâîÿ èãðà"
4082 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4083 FRulez
:= FRulez
-[R_BERSERK
];
4085 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4087 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4088 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4091 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4092 c
:= GetRespawnPoint();
4097 // Âîñêðåøåíèå áåç îðóæèÿ:
4100 FHealth
:= PLAYER_HP_SOFT
;
4106 for a
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
4108 FWeapon
[a
] := False;
4112 FWeapon
[WEAPON_PISTOL
] := True;
4113 FWeapon
[WEAPON_KASTET
] := True;
4114 FCurrWeap
:= WEAPON_PISTOL
;
4117 FModel
.SetWeapon(FCurrWeap
);
4119 for b
:= A_BULLETS
to A_CELLS
do
4122 FAmmo
[A_BULLETS
] := 50;
4124 FMaxAmmo
[A_BULLETS
] := 200;
4125 FMaxAmmo
[A_SHELLS
] := 50;
4126 FMaxAmmo
[A_ROCKETS
] := 50;
4127 FMaxAmmo
[A_CELLS
] := 300;
4129 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4130 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4135 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4136 if not g_Map_GetPoint(c
, RespawnPoint
) then
4138 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4142 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4143 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4144 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4150 FDirection
:= RespawnPoint
.Direction
;
4151 if FDirection
= D_LEFT
then
4157 FBFGFireCounter
:= -1;
4162 SetAction(A_STAND
, True);
4163 FModel
.Direction
:= FDirection
;
4165 for a
:= Low(FTime
) to High(FTime
) do
4168 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4173 FCanJetpack
:= False;
4175 // Àíèìàöèÿ âîçðîæäåíèÿ:
4176 if (not gLoadGameMode
) and (not Silent
) then
4177 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4179 Anim
:= TAnimation
.Create(ID
, False, 3);
4180 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4181 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4185 FSpectator
:= False;
4188 FSpectatePlayer
:= -1;
4191 if g_Game_IsNet
then
4193 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4194 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4196 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4197 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4202 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4205 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4206 else if (not NoMove
) then
4208 GameX
:= gMapInfo
.Width
div 2;
4209 GameY
:= gMapInfo
.Height
div 2;
4218 FWantsInGame
:= False;
4223 if Self
= gPlayer1
then
4228 if Self
= gPlayer2
then
4235 if g_Game_IsNet
then
4236 MH_SEND_PlayerStats(FUID
);
4239 procedure TPlayer
.SwitchNoClip
;
4243 FGhost
:= not FGhost
;
4244 FPhysics
:= not FGhost
;
4256 procedure TPlayer
.Run(Direction
: TDirection
);
4260 if MAX_RUNVEL
> 8 then
4264 if Direction
= D_LEFT
then
4266 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4267 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4270 if FObj
.Vel
.X
< MAX_RUNVEL
then
4271 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4273 // Âîçìîæíî, ïèíàåì êóñêè:
4274 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4276 b
:= Abs(FObj
.Vel
.X
);
4277 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4278 for a
:= 0 to High(gGibs
) do
4279 if gGibs
[a
].Live
and
4280 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4281 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4283 if FObj
.Vel
.X
< 0 then
4284 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4286 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4292 procedure TPlayer
.SeeDown();
4294 SetAction(A_SEEDOWN
);
4296 if FDirection
= D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4298 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4301 procedure TPlayer
.SeeUp();
4305 if FDirection
= D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4307 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4310 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4318 A_ATTACK
: Prior
:= 2;
4319 A_SEEUP
: Prior
:= 1;
4320 A_SEEDOWN
: Prior
:= 1;
4321 A_ATTACKUP
: Prior
:= 2;
4322 A_ATTACKDOWN
: Prior
:= 2;
4327 if (Prior
> FActionPrior
) or Force
then
4328 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4330 FActionPrior
:= Prior
;
4331 FActionAnim
:= Action
;
4332 FActionForce
:= Force
;
4333 FActionChanged
:= True;
4336 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4339 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4341 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4342 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4343 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4344 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4347 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4354 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4356 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4357 if g_Game_IsServer
and g_Game_IsNet
then
4358 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4362 FJustTeleported
:= True;
4367 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4369 Anim
:= TAnimation
.Create(ID
, False, 3);
4372 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4373 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4374 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4375 if g_Game_IsServer
and g_Game_IsNet
then
4376 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4377 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4381 FObj
.X
:= X
-PLAYER_RECT
.X
;
4382 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4383 if FLive
and FGhost
then
4389 if not g_Game_IsNet
then
4393 SetDirection(D_LEFT
);
4399 SetDirection(D_RIGHT
);
4405 if FDirection
= D_RIGHT
then
4407 SetDirection(D_LEFT
);
4412 SetDirection(D_RIGHT
);
4418 if not silent
and (Anim
<> nil) then
4420 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4421 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4424 if g_Game_IsServer
and g_Game_IsNet
then
4425 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4426 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4433 function nonz(a
: Single): Single;
4441 procedure TPlayer
.Update();
4444 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4445 blockmon
, headwater
, dospawn
: Boolean;
4450 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4451 AnyServer
:= g_Game_IsServer
;
4453 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4454 DoLerp(NetInterpLevel
+ 1)
4460 if FClientID
>= 0 then
4462 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4463 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4464 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4473 if FLive
and (gFly
or FJetpack
) then
4476 if FDirection
= D_LEFT
then
4481 if FLive
and (not FGhost
) then
4483 if FKeys
[KEY_UP
].Pressed
then
4485 if FKeys
[KEY_DOWN
].Pressed
then
4489 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4492 i
:= g_basic
.Sign(FIncCam
);
4493 FIncCam
:= Abs(FIncCam
);
4494 DecMin(FIncCam
, 5, 0);
4495 FIncCam
:= FIncCam
*i
;
4498 // no need to do that each second frame, weapon queue will take care of it
4499 if FLive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4500 if FLive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4502 if gTime
mod (GAME_TICK
*2) <> 0 then
4504 if (FObj
.Vel
.X
= 0) and FLive
then
4506 if FKeys
[KEY_LEFT
].Pressed
then
4508 if FKeys
[KEY_RIGHT
].Pressed
then
4513 g_Obj_Move(@FObj
, True, True, True);
4518 FActionChanged
:= False;
4522 // Let alive player do some actions
4523 if FKeys
[KEY_LEFT
].Pressed
then Run(D_LEFT
);
4524 if FKeys
[KEY_RIGHT
].Pressed
then Run(D_RIGHT
);
4525 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
4526 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
4527 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
4528 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
4529 if FKeys
[KEY_JUMP
].Pressed
then Jump()
4532 if AnyServer
and FJetpack
then
4536 if NetServer
then MH_SEND_PlayerStats(FUID
);
4538 FCanJetpack
:= True;
4545 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
4547 if FKeys
[k
].Pressed
then
4555 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4558 if (FTime
[T_RESPAWN
] <= gTime
) and
4559 gGameOn
and (not FLive
) then
4561 if (g_Player_GetCount() > 1) then
4565 gExit
:= EXIT_RESTART
;
4570 // Dead spectator actions
4573 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
4574 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
4578 if (FSpectatePlayer
>= High(gPlayers
)) then
4579 FSpectatePlayer
:= -1
4583 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
4584 if gPlayers
[I
] <> nil then
4585 if gPlayers
[I
].Live
then
4586 if gPlayers
[I
].UID
<> FUID
then
4588 FSpectatePlayer
:= I
;
4593 if not SetSpect
then FSpectatePlayer
:= -1;
4604 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
4606 FYTo
:= FObj
.Y
- 32;
4607 FSpectatePlayer
:= -1;
4609 if FKeys
[KEY_DOWN
].Pressed
then
4611 FYTo
:= FObj
.Y
+ 32;
4612 FSpectatePlayer
:= -1;
4614 if FKeys
[KEY_LEFT
].Pressed
then
4616 FXTo
:= FObj
.X
- 32;
4617 FSpectatePlayer
:= -1;
4619 if FKeys
[KEY_RIGHT
].Pressed
then
4621 FXTo
:= FObj
.X
+ 32;
4622 FSpectatePlayer
:= -1;
4625 if (FXTo
< -64) then
4627 else if (FXTo
> gMapInfo
.Width
+ 32) then
4628 FXTo
:= gMapInfo
.Width
+ 32;
4629 if (FYTo
< -72) then
4631 else if (FYTo
> gMapInfo
.Height
+ 32) then
4632 FYTo
:= gMapInfo
.Height
+ 32;
4636 g_Obj_Move(@FObj
, True, True, True)
4642 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
4643 if gPlayers
[FSpectatePlayer
] <> nil then
4644 if gPlayers
[FSpectatePlayer
].Live
then
4646 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
4647 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
4651 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
4652 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
4653 PANEL_BLOCKMON
, True);
4654 headwater
:= HeadInLiquid(0, 0);
4656 // Ñîïðîòèâëåíèå âîçäóõà:
4657 if (not FLive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
4658 if FObj
.Vel
.X
<> 0 then
4659 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
4661 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
4662 DecMin(FPain
, 5, 0);
4663 DecMin(FPickup
, 1, 0);
4665 if FLive
and (FObj
.Y
> gMapInfo
.Height
+128) and AnyServer
then
4667 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
4668 FMegaRulez
[MR_SUIT
] := 0;
4669 FMegaRulez
[MR_INVUL
] := 0;
4670 FMegaRulez
[MR_INVIS
] := 0;
4671 Kill(K_FALLKILL
, 0, HIT_FALL
);
4678 if FCurrWeap
= WEAPON_SAW
then
4679 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
4680 FSawSoundSelect
.IsPlaying()) then
4681 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
4684 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
4685 (not FJetSoundOff
.IsPlaying()) then
4687 FJetSoundFly
.SetPosition(0);
4688 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
4691 for b
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
4692 if FReloading
[b
] > 0 then
4698 if FShellTimer
> -1 then
4699 if FShellTimer
= 0 then
4701 if FShellType
= SHELL_SHELL
then
4702 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4703 GameVelX
, GameVelY
-2, SHELL_SHELL
)
4704 else if FShellType
= SHELL_DBLSHELL
then
4706 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4707 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
4708 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4709 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
4712 end else Dec(FShellTimer
);
4714 if (FBFGFireCounter
> -1) then
4715 if FBFGFireCounter
= 0 then
4719 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
4720 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
4721 xd
:= wx
+IfThen(FDirection
= D_LEFT
, -30, 30);
4722 yd
:= wy
+firediry();
4723 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
4724 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
4725 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
4726 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
4727 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
4730 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
4731 FBFGFireCounter
:= -1;
4734 FBFGFireCounter
:= 0
4736 Dec(FBFGFireCounter
);
4738 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
4740 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
4742 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
4745 if (headwater
or blockmon
) then
4751 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
4754 else if (FAir
mod 31 = 0) and not blockmon
then
4756 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
4757 if Random(2) = 0 then
4758 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
4760 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
4762 end else if FAir
< AIR_DEF
then
4765 if FDamageBuffer
> 0 then
4767 if FDamageBuffer
>= 9 then
4771 if FDamageBuffer
< 30 then i
:= 9
4772 else if FDamageBuffer
< 100 then i
:= 18
4776 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
4777 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
4778 FHealth
:= FHealth
-ii
;
4781 FHealth
:= FHealth
+FArmor
;
4786 if FHealth
<= 0 then
4787 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
4788 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
4789 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
4793 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
4794 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
4795 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
4796 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
4803 end; // if FLive then ...
4805 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
4807 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
4808 FModel
.GetCurrentAnimation
.MinLength
:= i
;
4809 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
4810 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
4812 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
4813 then SetAction(A_STAND
, True);
4815 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
4817 for b
:= Low(FKeys
) to High(FKeys
) do
4818 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
4821 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
4823 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
4824 FObj
.Y
+PLAYER_RECT
.Y
,
4831 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
4833 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
4834 FObj
.Y
+PLAYER_RECT
.Y
,
4838 Panel
.Width
, Panel
.Height
);
4841 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
4843 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
4844 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
4845 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
4846 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
4849 function g_Player_ValidName(Name
: string): Boolean;
4855 if gPlayers
= nil then Exit
;
4857 for a
:= 0 to High(gPlayers
) do
4858 if gPlayers
[a
] <> nil then
4859 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
4866 procedure TPlayer
.SetDirection(Direction
: TDirection
);
4870 d
:= FModel
.Direction
;
4872 FModel
.Direction
:= Direction
;
4873 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
4875 FDirection
:= Direction
;
4878 function TPlayer
.GetKeys(): Byte;
4882 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
4883 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
4884 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
4886 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
4887 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
4890 procedure TPlayer
.Use();
4894 if FTime
[T_USE
] > gTime
then Exit
;
4896 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
4897 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
4899 for a
:= 0 to High(gPlayers
) do
4900 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
4901 gPlayers
[a
].Live
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
4902 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
4903 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
4905 gPlayers
[a
].Touch();
4906 if g_Game_IsNet
and g_Game_IsServer
then
4907 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
4910 FTime
[T_USE
] := gTime
+120;
4913 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
4917 WX
, WY
, XD
, YD
: Integer;
4928 if R_BERSERK
in FRulez
then
4930 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
4931 obj
.X
:= FObj
.X
+FObj
.Rect
.X
;
4932 obj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
4935 obj
.rect
.Width
:= 39;
4936 obj
.rect
.Height
:= 52;
4937 obj
.Vel
.X
:= (xd
-wx
) div 2;
4938 obj
.Vel
.Y
:= (yd
-wy
) div 2;
4939 obj
.Accel
.X
:= xd
-wx
;
4940 obj
.Accel
.y
:= yd
-wy
;
4942 if g_Weapon_Hit(@obj
, 50, FUID
, HIT_SOME
) <> 0 then
4943 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
4945 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
4949 FPain
:= min(FPain
+ 25, 50);
4951 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
4956 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
4957 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
4959 FSawSoundSelect
.Stop();
4961 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
4963 else if not FSawSoundHit
.IsPlaying() then
4965 FSawSoundSelect
.Stop();
4966 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
4973 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
4974 FFireAngle
:= FAngle
;
4976 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4977 GameVelX
, GameVelY
-2, SHELL_BULLET
);
4982 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
4983 FFireAngle
:= FAngle
;
4986 FShellType
:= SHELL_SHELL
;
4991 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
4992 FFireAngle
:= FAngle
;
4995 FShellType
:= SHELL_DBLSHELL
;
5000 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5001 FFireAngle
:= FAngle
;
5003 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5004 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5007 WEAPON_ROCKETLAUNCHER
:
5009 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5010 FFireAngle
:= FAngle
;
5016 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5017 FFireAngle
:= FAngle
;
5023 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5024 FFireAngle
:= FAngle
;
5028 WEAPON_SUPERPULEMET
:
5030 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5031 FFireAngle
:= FAngle
;
5033 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5034 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5040 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5041 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5042 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5045 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5047 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5048 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5051 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5055 if NetInterpLevel
< 1 then
5065 AX
:= Abs(FXTo
- FObj
.X
);
5066 AY
:= Abs(FYTo
- FObj
.Y
);
5067 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5069 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5074 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5076 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5077 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5078 PANEL_LIFTUP
, False) then Result
:= -1
5080 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5081 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5082 PANEL_LIFTDOWN
, False) then Result
:= 1
5086 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5093 if Flag
= FLAG_NONE
then
5096 if not g_Game_IsServer
then Exit
;
5098 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5099 if (Flag
= FTeam
) and
5100 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5101 (FFlag
<> FLAG_NONE
) then
5103 if FFlag
= FLAG_RED
then
5104 s
:= _lc
[I_PLAYER_FLAG_RED
]
5106 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5108 evtype
:= FLAG_STATE_SCORED
;
5110 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5111 Insert('.', ts
, Length(ts
) + 1 - 3);
5112 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5114 g_Map_ResetFlag(FFlag
);
5115 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5117 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5120 if g_Game_IsNet
then
5122 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5126 gFlags
[FFlag
].CaptureTime
:= 0;
5131 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5132 if (Flag
= FTeam
) and
5133 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5135 if Flag
= FLAG_RED
then
5136 s
:= _lc
[I_PLAYER_FLAG_RED
]
5138 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5140 evtype
:= FLAG_STATE_RETURNED
;
5141 gFlags
[Flag
].CaptureTime
:= 0;
5143 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5145 g_Map_ResetFlag(Flag
);
5146 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5149 if g_Game_IsNet
then
5151 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5157 // Ïîäîáðàë ÷óæîé ôëàã:
5158 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5162 if Flag
= FLAG_RED
then
5163 s
:= _lc
[I_PLAYER_FLAG_RED
]
5165 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5167 evtype
:= FLAG_STATE_CAPTURED
;
5169 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5171 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5173 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5176 if g_Game_IsNet
then
5178 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5184 procedure TPlayer
.SetFlag(Flag
: Byte);
5187 if FModel
<> nil then
5188 FModel
.SetFlag(FFlag
);
5191 function TPlayer
.DropFlag(): Boolean;
5196 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5198 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5199 with gFlags
[FFlag
] do
5203 Direction
:= FDirection
;
5204 State
:= FLAG_STATE_DROPPED
;
5206 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5207 (FObj
.Vel
.Y
div 2)-2+Random(5));
5209 if FFlag
= FLAG_RED
then
5210 s
:= _lc
[I_PLAYER_FLAG_RED
]
5212 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5214 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5215 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5217 if g_Game_IsNet
then
5218 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5224 procedure TPlayer
.GetSecret();
5229 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5231 Assert(Key
<= High(FKeys
));
5233 FKeys
[Key
].Pressed
:= True;
5234 FKeys
[Key
].Time
:= Time
;
5237 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5239 Result
:= FKeys
[K
].Pressed
;
5242 procedure TPlayer
.ReleaseKeys();
5246 for a
:= Low(FKeys
) to High(FKeys
) do
5248 FKeys
[a
].Pressed
:= False;
5253 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5257 function TPlayer
.firediry(): Integer;
5259 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5260 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5264 procedure TPlayer
.RememberState();
5268 FSavedState
.Health
:= FHealth
;
5269 FSavedState
.Armor
:= FArmor
;
5270 FSavedState
.Air
:= FAir
;
5271 FSavedState
.JetFuel
:= FJetFuel
;
5272 FSavedState
.CurrWeap
:= FCurrWeap
;
5273 FSavedState
.NextWeap
:= FNextWeap
;
5274 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5277 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5279 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5281 FSavedState
.Rulez
:= FRulez
;
5282 FSavedState
.WaitRecall
:= True;
5285 procedure TPlayer
.RecallState();
5289 if not FSavedState
.WaitRecall
then Exit
;
5291 FHealth
:= FSavedState
.Health
;
5292 FArmor
:= FSavedState
.Armor
;
5293 FAir
:= FSavedState
.Air
;
5294 FJetFuel
:= FSavedState
.JetFuel
;
5295 FCurrWeap
:= FSavedState
.CurrWeap
;
5296 FNextWeap
:= FSavedState
.NextWeap
;
5297 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5300 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5302 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5304 FRulez
:= FSavedState
.Rulez
;
5305 FSavedState
.WaitRecall
:= False;
5307 if gGameSettings
.GameType
= GT_SERVER
then
5308 MH_SEND_PlayerStats(FUID
);
5311 procedure TPlayer
.SaveState(var Mem
: TBinMemoryWriter
);
5323 Mem
:= TBinMemoryWriter
.Create(i
);
5325 // Ñèãíàòóðà èãðîêà:
5326 sig
:= PLAYER_SIGNATURE
; // 'PLYR'
5327 Mem
.WriteDWORD(sig
);
5329 Mem
.WriteBoolean(FIamBot
);
5331 Mem
.WriteWord(FUID
);
5333 Mem
.WriteString(FName
, 32);
5335 Mem
.WriteByte(FTeam
);
5337 Mem
.WriteBoolean(FLive
);
5338 // Èçðàñõîäîâàë ëè âñå æèçíè:
5339 Mem
.WriteBoolean(FNoRespawn
);
5341 if FDirection
= D_LEFT
then
5347 Mem
.WriteInt(FHealth
);
5349 Mem
.WriteByte(FLives
);
5351 Mem
.WriteInt(FArmor
);
5355 Mem
.WriteInt(FJetFuel
);
5357 Mem
.WriteInt(FPain
);
5359 Mem
.WriteInt(FKills
);
5361 Mem
.WriteInt(FMonsterKills
);
5363 Mem
.WriteInt(FFrags
);
5365 Mem
.WriteByte(FFragCombo
);
5366 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5367 Mem
.WriteDWORD(FLastFrag
);
5369 Mem
.WriteInt(FDeath
);
5370 // Êàêîé ôëàã íåñåò:
5371 Mem
.WriteByte(FFlag
);
5373 Mem
.WriteInt(FSecrets
);
5375 Mem
.WriteByte(FCurrWeap
);
5377 Mem
.WriteWord(FNextWeap
);
5379 Mem
.WriteByte(FNextWeapDelay
);
5380 // Âðåìÿ çàðÿäêè BFG:
5381 Mem
.WriteSmallInt(FBFGFireCounter
);
5383 Mem
.WriteInt(FDamageBuffer
);
5384 // Ïîñëåäíèé óäàðèâøèé:
5385 Mem
.WriteWord(FLastSpawnerUID
);
5386 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5387 Mem
.WriteByte(FLastHit
);
5389 Obj_SaveState(@FObj
, Mem
);
5390 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5391 for i
:= A_BULLETS
to A_CELLS
do
5392 Mem
.WriteWord(FAmmo
[i
]);
5393 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5394 for i
:= A_BULLETS
to A_CELLS
do
5395 Mem
.WriteWord(FMaxAmmo
[i
]);
5397 for i
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
5398 Mem
.WriteBoolean(FWeapon
[i
]);
5399 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5400 for i
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
5401 Mem
.WriteWord(FReloading
[i
]);
5403 if R_ITEM_BACKPACK
in FRulez
then
5408 // Íàëè÷èå êðàñíîãî êëþ÷à:
5409 if R_KEY_RED
in FRulez
then
5414 // Íàëè÷èå çåëåíîãî êëþ÷à:
5415 if R_KEY_GREEN
in FRulez
then
5420 // Íàëè÷èå ñèíåãî êëþ÷à:
5421 if R_KEY_BLUE
in FRulez
then
5426 // Íàëè÷èå áåðñåðêà:
5427 if R_BERSERK
in FRulez
then
5432 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5433 for i
:= MR_SUIT
to MR_MAX
do
5434 Mem
.WriteDWORD(FMegaRulez
[i
]);
5435 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5436 for i
:= T_RESPAWN
to T_FLAGCAP
do
5437 Mem
.WriteDWORD(FTime
[i
]);
5440 Mem
.WriteString(str
);
5450 procedure TPlayer
.LoadState(var Mem
: TBinMemoryReader
);
5460 // Ñèãíàòóðà èãðîêà:
5462 if sig
<> PLAYER_SIGNATURE
then // 'PLYR'
5464 raise EBinSizeError
.Create('TPlayer.LoadState: Wrong Player Signature');
5467 Mem
.ReadBoolean(FIamBot
);
5471 Mem
.ReadString(str
);
5472 if (Self
<> gPlayer1
) and (Self
<> gPlayer2
) then
5475 Mem
.ReadByte(FTeam
);
5477 Mem
.ReadBoolean(FLive
);
5478 // Èçðàñõîäîâàë ëè âñå æèçíè:
5479 Mem
.ReadBoolean(FNoRespawn
);
5483 FDirection
:= D_LEFT
5485 FDirection
:= D_RIGHT
;
5487 Mem
.ReadInt(FHealth
);
5489 Mem
.ReadByte(FLives
);
5491 Mem
.ReadInt(FArmor
);
5495 Mem
.ReadInt(FJetFuel
);
5499 Mem
.ReadInt(FKills
);
5501 Mem
.ReadInt(FMonsterKills
);
5503 Mem
.ReadInt(FFrags
);
5505 Mem
.ReadByte(FFragCombo
);
5506 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5507 Mem
.ReadDWORD(FLastFrag
);
5509 Mem
.ReadInt(FDeath
);
5510 // Êàêîé ôëàã íåñåò:
5511 Mem
.ReadByte(FFlag
);
5513 Mem
.ReadInt(FSecrets
);
5515 Mem
.ReadByte(FCurrWeap
);
5517 Mem
.ReadWord(FNextWeap
);
5519 Mem
.ReadByte(FNextWeapDelay
);
5520 // Âðåìÿ çàðÿäêè BFG:
5521 Mem
.ReadSmallInt(FBFGFireCounter
);
5523 Mem
.ReadInt(FDamageBuffer
);
5524 // Ïîñëåäíèé óäàðèâøèé:
5525 Mem
.ReadWord(FLastSpawnerUID
);
5526 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5527 Mem
.ReadByte(FLastHit
);
5529 Obj_LoadState(@FObj
, Mem
);
5530 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5531 for i
:= A_BULLETS
to A_CELLS
do
5532 Mem
.ReadWord(FAmmo
[i
]);
5533 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5534 for i
:= A_BULLETS
to A_CELLS
do
5535 Mem
.ReadWord(FMaxAmmo
[i
]);
5537 for i
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
5538 Mem
.ReadBoolean(FWeapon
[i
]);
5539 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5540 for i
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
5541 Mem
.ReadWord(FReloading
[i
]);
5545 Include(FRulez
, R_ITEM_BACKPACK
);
5546 // Íàëè÷èå êðàñíîãî êëþ÷à:
5549 Include(FRulez
, R_KEY_RED
);
5550 // Íàëè÷èå çåëåíîãî êëþ÷à:
5553 Include(FRulez
, R_KEY_GREEN
);
5554 // Íàëè÷èå ñèíåãî êëþ÷à:
5557 Include(FRulez
, R_KEY_BLUE
);
5558 // Íàëè÷èå áåðñåðêà:
5561 Include(FRulez
, R_BERSERK
);
5562 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5563 for i
:= MR_SUIT
to MR_MAX
do
5564 Mem
.ReadDWORD(FMegaRulez
[i
]);
5565 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5566 for i
:= T_RESPAWN
to T_FLAGCAP
do
5567 Mem
.ReadDWORD(FTime
[i
]);
5569 Mem
.ReadString(str
);
5571 Mem
.ReadByte(FColor
.R
);
5572 Mem
.ReadByte(FColor
.G
);
5573 Mem
.ReadByte(FColor
.B
);
5574 if Self
= gPlayer1
then
5576 str
:= gPlayer1Settings
.Model
;
5577 FColor
:= gPlayer1Settings
.Color
;
5579 if Self
= gPlayer2
then
5581 str
:= gPlayer2Settings
.Model
;
5582 FColor
:= gPlayer2Settings
.Color
;
5584 // Îáíîâëÿåì ìîäåëü èãðîêà:
5586 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
5587 FModel
.Color
:= TEAMCOLOR
[FTeam
]
5589 FModel
.Color
:= FColor
;
5592 procedure TPlayer
.AllRulez(Health
: Boolean);
5598 FHealth
:= PLAYER_HP_LIMIT
;
5599 FArmor
:= PLAYER_AP_LIMIT
;
5603 for a
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do FWeapon
[a
] := True;
5604 for a
:= A_BULLETS
to A_CELLS
do FAmmo
[a
] := 30000;
5605 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5608 procedure TPlayer
.RestoreHealthArmor();
5610 FHealth
:= PLAYER_HP_LIMIT
;
5611 FArmor
:= PLAYER_AP_LIMIT
;
5614 procedure TPlayer
.FragCombo();
5618 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
5620 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
5622 if FFragCombo
< 5 then
5624 Param
:= FUID
or (FFragCombo
shl 16);
5625 if (FComboEvnt
>= Low(gDelayedEvents
)) and
5626 (FComboEvnt
<= High(gDelayedEvents
)) and
5627 gDelayedEvents
[FComboEvnt
].Pending
and
5628 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
5629 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
5631 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
5632 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
5635 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
5643 procedure TPlayer
.GiveItem(ItemType
: Byte);
5647 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
5649 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
5653 if FAir
< AIR_MAX
then
5660 if not (R_BERSERK
in FRulez
) then
5662 Include(FRulez
, R_BERSERK
);
5663 if FBFGFireCounter
< 1 then
5665 FCurrWeap
:= WEAPON_KASTET
;
5667 FModel
.SetWeapon(WEAPON_KASTET
);
5671 FBerserk
:= gTime
+30000;
5673 if FHealth
< PLAYER_HP_SOFT
then
5675 FHealth
:= PLAYER_HP_SOFT
;
5676 FBerserk
:= gTime
+30000;
5681 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
5683 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
5687 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
5689 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
5693 if FJetFuel
< JET_MAX
then
5695 FJetFuel
:= JET_MAX
;
5698 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
5699 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
5701 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
5702 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5704 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
5706 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
5708 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
5709 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5712 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
5713 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
5714 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
5715 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
5716 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
5717 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
5718 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
5719 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
5721 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5722 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
5723 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5724 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
5725 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5726 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
5727 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5728 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
5731 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
5732 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
5733 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
5734 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) then
5736 FMaxAmmo
[A_BULLETS
] := 400;
5737 FMaxAmmo
[A_SHELLS
] := 100;
5738 FMaxAmmo
[A_ROCKETS
] := 100;
5739 FMaxAmmo
[A_CELLS
] := 600;
5741 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5742 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5743 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5744 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5746 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
5749 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
5750 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
5751 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
5753 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
5754 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
5759 if g_Game_IsNet
and g_Game_IsServer
then
5760 MH_SEND_PlayerStats(FUID
);
5763 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
5768 if (Random(5) = 1) and (Times
= 1) then
5771 if BodyInLiquid(0, 0) then
5773 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
5774 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
5775 if Random(2) = 0 then
5776 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5778 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5782 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
5784 for i
:= 1 to Times
do
5786 Anim
:= TAnimation
.Create(id
, False, 3);
5788 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
5789 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
5795 procedure TPlayer
.PauseSounds(Enable
: Boolean);
5797 FSawSound
.Pause(Enable
);
5798 FSawSoundIdle
.Pause(Enable
);
5799 FSawSoundHit
.Pause(Enable
);
5800 FSawSoundSelect
.Pause(Enable
);
5805 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
5810 FObj
.Rect
:= PLAYER_CORPSERECT
;
5811 FModelName
:= ModelName
;
5816 FState
:= CORPSE_STATE_MESS
;
5817 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
5821 FState
:= CORPSE_STATE_NORMAL
;
5822 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
5826 destructor TCorpse
.Destroy();
5833 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
5837 if FState
= CORPSE_STATE_REMOVEME
then
5840 FDamage
:= FDamage
+ Value
;
5842 if FDamage
> 150 then
5844 if FAnimation
<> nil then
5849 FState
:= CORPSE_STATE_REMOVEME
;
5851 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
5852 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
5853 FModelName
, FColor
);
5854 // Çâóê ìÿñà îò òðóïà:
5855 pm
:= g_PlayerModel_Get(FModelName
);
5856 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
5862 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
5863 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
5864 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
5865 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
5866 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
5871 procedure TCorpse
.Draw();
5873 if FState
= CORPSE_STATE_REMOVEME
then
5876 if FAnimation
<> nil then
5877 FAnimation
.Draw(FObj
.X
, FObj
.Y
, M_NONE
);
5879 if FAnimationMask
<> nil then
5882 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, M_NONE
);
5889 procedure TCorpse
.Update();
5893 if FState
= CORPSE_STATE_REMOVEME
then
5896 if gTime
mod (GAME_TICK
*2) <> 0 then
5898 g_Obj_Move(@FObj
, True, True, True);
5903 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
5904 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5906 st
:= g_Obj_Move(@FObj
, True, True, True);
5908 if WordBool(st
and MOVE_FALLOUT
) then
5910 FState
:= CORPSE_STATE_REMOVEME
;
5914 if FAnimation
<> nil then
5915 FAnimation
.Update();
5916 if FAnimationMask
<> nil then
5917 FAnimationMask
.Update();
5920 procedure TCorpse
.SaveState(var Mem
: TBinMemoryWriter
);
5929 sig
:= CORPSE_SIGNATURE
; // 'CORP'
5930 Mem
.WriteDWORD(sig
);
5932 Mem
.WriteByte(FState
);
5933 // Íàêîïëåííûé óðîí:
5934 Mem
.WriteByte(FDamage
);
5936 Mem
.WriteByte(FColor
.R
);
5937 Mem
.WriteByte(FColor
.G
);
5938 Mem
.WriteByte(FColor
.B
);
5940 Obj_SaveState(@FObj
, Mem
);
5941 // Åñòü ëè àíèìàöèÿ:
5942 anim
:= FAnimation
<> nil;
5943 Mem
.WriteBoolean(anim
);
5944 // Åñëè åñòü - ñîõðàíÿåì:
5946 FAnimation
.SaveState(Mem
);
5947 // Åñòü ëè ìàñêà àíèìàöèè:
5948 anim
:= FAnimationMask
<> nil;
5949 Mem
.WriteBoolean(anim
);
5950 // Åñëè åñòü - ñîõðàíÿåì:
5952 FAnimationMask
.SaveState(Mem
);
5955 procedure TCorpse
.LoadState(var Mem
: TBinMemoryReader
);
5965 if sig
<> CORPSE_SIGNATURE
then // 'CORP'
5967 raise EBinSizeError
.Create('TCorpse.LoadState: Wrong Corpse Signature');
5970 Mem
.ReadByte(FState
);
5971 // Íàêîïëåííûé óðîí:
5972 Mem
.ReadByte(FDamage
);
5974 Mem
.ReadByte(FColor
.R
);
5975 Mem
.ReadByte(FColor
.G
);
5976 Mem
.ReadByte(FColor
.B
);
5978 Obj_LoadState(@FObj
, Mem
);
5979 // Åñòü ëè àíèìàöèÿ:
5980 Mem
.ReadBoolean(anim
);
5981 // Åñëè åñòü - çàãðóæàåì:
5984 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
5985 FAnimation
.LoadState(Mem
);
5987 // Åñòü ëè ìàñêà àíèìàöèè:
5988 Mem
.ReadBoolean(anim
);
5989 // Åñëè åñòü - çàãðóæàåì:
5992 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
5993 FAnimationMask
.LoadState(Mem
);
5999 constructor TBot
.Create();
6006 FSpectator
:= False;
6013 for a
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
6015 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6016 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6017 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6021 destructor TBot
.Destroy();
6024 inherited Destroy();
6027 procedure TBot
.Draw();
6031 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6032 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6035 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6037 inherited Respawn(Silent
, Force
);
6040 FSelectedWeapon
:= FCurrWeap
;
6045 procedure TBot
.UpdateCombat();
6058 TTargetRecord
= array of TTarget
;
6060 function Compare(a
, b
: TTarget
): Integer;
6062 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6065 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6067 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6068 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6070 if a
.Dist
> b
.Dist
then // B áëèæå
6072 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6075 else // Ñòðàííî -> A
6080 a
, x1
, y1
, x2
, y2
: Integer;
6081 targets
: TTargetRecord
;
6083 Target
, BestTarget
: TTarget
;
6084 firew
, fireh
: Integer;
6088 vsPlayer
, vsMonster
, ok
: Boolean;
6090 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6091 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6093 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6094 if FCurrWeap
<> FSelectedWeapon
then
6097 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6098 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6100 RemoveAIFlag('NEEDFIRE');
6103 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6104 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_MEGAKASTET
: PressKey(KEY_FIRE
, 40);
6105 else PressKey(KEY_FIRE
);
6109 // Êîîðäèíàòû ñòâîëà:
6110 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6111 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6113 Target
.UID
:= FTargetUID
;
6116 if Target
.UID
<> 0 then
6117 begin // Öåëü åñòü - íàñòðàèâàåì
6118 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6121 with g_Player_Get(Target
.UID
) do
6123 if (@FObj
) <> nil then
6130 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6131 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6132 Target
.Rect
:= PLAYER_RECT
;
6133 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6134 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6135 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6136 Target
.IsPlayer
:= True;
6140 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6143 mon
:= g_Monsters_Get(Target
.UID
);
6146 Target
.X
:= mon
.Obj
.X
;
6147 Target
.Y
:= mon
.Obj
.Y
;
6149 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6150 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6151 Target
.Rect
:= mon
.Obj
.Rect
;
6152 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6153 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6154 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6155 Target
.IsPlayer
:= False;
6162 begin // Öåëè íåò - îáíóëÿåì
6167 Target
.Visible
:= False;
6168 Target
.Line
:= False;
6169 Target
.IsPlayer
:= False;
6174 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6175 if (not Target
.Line
) or (not Target
.Visible
) then
6179 for a
:= 0 to High(gPlayers
) do
6180 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].Live
) and
6181 (gPlayers
[a
].FUID
<> FUID
) and
6182 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6183 (not gPlayers
[a
].NoTarget
) and
6184 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6186 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6187 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6190 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6191 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6193 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6194 if g_TraceVector(x1
, y1
, x2
, y2
) then
6196 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6197 SetLength(targets
, Length(targets
)+1);
6198 with targets
[High(targets
)] do
6200 UID
:= gPlayers
[a
].FUID
;
6201 X
:= gPlayers
[a
].FObj
.X
;
6202 Y
:= gPlayers
[a
].FObj
.Y
;
6205 Rect
:= PLAYER_RECT
;
6206 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6207 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6208 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6216 if vsMonster
and (gMonsters
<> nil) then
6217 for a
:= 0 to High(gMonsters
) do
6218 if (gMonsters
[a
] <> nil) and (gMonsters
[a
].Live
) and
6219 (gMonsters
[a
].MonsterType
<> MONSTER_BARREL
) then
6221 mon
:= gMonsters
[a
];
6223 if not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
6224 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
) then
6227 x2
:= mon
.Obj
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6228 y2
:= mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6230 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6231 if g_TraceVector(x1
, y1
, x2
, y2
) then
6233 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6234 SetLength(targets
, Length(targets
)+1);
6235 with targets
[High(targets
)] do
6242 Rect
:= mon
.Obj
.Rect
;
6243 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6244 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6245 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6253 // Åñëè åñòü âîçìîæíûå öåëè:
6254 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6255 if targets
<> nil then
6257 // Âûáèðàåì íàèëó÷øóþ öåëü:
6258 BestTarget
:= targets
[0];
6259 if Length(targets
) > 1 then
6260 for a
:= 1 to High(targets
) do
6261 if Compare(BestTarget
, targets
[a
]) = 1 then
6262 BestTarget
:= targets
[a
];
6264 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6265 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6266 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6268 Target
:= BestTarget
;
6270 if (Healthy() = 3) or ((Healthy() = 2)) then
6271 begin // Åñëè çäîðîâû - äîãîíÿåì
6272 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6273 SetAIFlag('GORIGHT', '1');
6274 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6275 SetAIFlag('GOLEFT', '1');
6278 begin // Åñëè ïîáèòû - óáåãàåì
6279 if ((RunDirection() = D_LEFT
) and (Target
.X
< FObj
.X
)) then
6280 SetAIFlag('GORIGHT', '1');
6281 if ((RunDirection() = D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6282 SetAIFlag('GOLEFT', '1');
6285 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6286 SelectWeapon(Abs(x1
-Target
.cX
));
6291 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6292 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6293 if Target
.UID
<> 0 then
6295 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6296 Target
.Y
+ Target
.Rect
.Y
) then
6297 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6298 if (Healthy() = 3) or ((Healthy() = 2)) then
6299 begin // Åñëè çäîðîâû - äîãîíÿåì
6300 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6301 SetAIFlag('GORIGHT', '1');
6302 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6303 SetAIFlag('GOLEFT', '1');
6306 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6308 if ((RunDirection() = D_LEFT
) and (Target
.X
< FObj
.X
)) then
6309 SetAIFlag('GORIGHT', '1');
6310 if ((RunDirection() = D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6311 SetAIFlag('GOLEFT', '1');
6315 begin // Öåëü ïîêà íà "ýêðàíå"
6316 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6317 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6318 FLastVisible
:= gTime
;
6319 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6320 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6322 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6323 SetAIFlag('GORIGHT', '1');
6324 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6325 SetAIFlag('GOLEFT', '1');
6329 // Âûáèðàåì óãîë ââåðõ:
6330 if FDirection
= D_LEFT
then
6331 angle
:= ANGLE_LEFTUP
6333 angle
:= ANGLE_RIGHTUP
;
6335 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6336 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6338 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6339 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6340 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6341 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6342 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6343 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6344 begin // òî íóæíî ñòðåëÿòü ââåðõ
6345 SetAIFlag('NEEDFIRE', '1');
6346 SetAIFlag('NEEDSEEUP', '1');
6349 // Âûáèðàåì óãîë âíèç:
6350 if FDirection
= D_LEFT
then
6351 angle
:= ANGLE_LEFTDOWN
6353 angle
:= ANGLE_RIGHTDOWN
;
6355 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6356 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6358 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6359 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6360 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6361 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6362 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6363 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6364 begin // òî íóæíî ñòðåëÿòü âíèç
6365 SetAIFlag('NEEDFIRE', '1');
6366 SetAIFlag('NEEDSEEDOWN', '1');
6369 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6370 if Target
.Visible
and
6371 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6372 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6374 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6375 if ((FDirection
= D_LEFT
) and (Target
.X
< FObj
.X
)) or
6376 ((FDirection
= D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6377 begin // òî íóæíî ñòðåëÿòü âïåðåä
6378 SetAIFlag('NEEDFIRE', '1');
6379 SetAIFlag('NEEDSEEDOWN', '');
6380 SetAIFlag('NEEDSEEUP', '');
6382 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6383 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6384 if GetRnd(FDifficult
.CloseJump
) then
6385 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6386 if Abs(FObj
.X
-Target
.X
) < 128 then
6390 if Random(a
) = 0 then
6391 SetAIFlag('NEEDJUMP', '1');
6395 // Åñëè öåëü âñå åùå åñòü:
6396 if Target
.UID
<> 0 then
6397 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
6398 Target
.UID
:= 0 // òî çàáûòü öåëü
6399 else // Åñëè âèäåëè íåäàâíî
6400 begin // íî öåëü óáèëè
6401 if Target
.IsPlayer
then
6402 begin // Öåëü - èãðîê
6403 pla
:= g_Player_Get(Target
.UID
);
6404 if (pla
= nil) or (not pla
.Live
) or pla
.NoTarget
or
6405 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6406 Target
.UID
:= 0; // òî çàáûòü öåëü
6409 begin // Öåëü - ìîíñòð
6410 mon
:= g_Monsters_Get(Target
.UID
);
6411 if (mon
= nil) or (not mon
.Live
) then
6412 Target
.UID
:= 0; // òî çàáûòü öåëü
6415 end; // if Target.UID <> 0
6417 FTargetUID
:= Target
.UID
;
6419 // Åñëè âîçìîæíûõ öåëåé íåò:
6420 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
6421 if targets
= nil then
6422 if GetAIFlag('ATTACKLEFT') <> '' then
6423 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
6424 RemoveAIFlag('ATTACKLEFT');
6426 SetAIFlag('NEEDJUMP', '1');
6428 if RunDirection() = D_RIGHT
then
6429 begin // Èäåì íå â òó ñòîðîíó
6430 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6431 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
6432 SetAIFlag('NEEDFIRE', '1');
6433 SetAIFlag('GOLEFT', '1');
6437 begin // Èäåì â íóæíóþ ñòîðîíó
6438 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6439 SetAIFlag('NEEDFIRE', '1');
6440 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6441 SetAIFlag('GORIGHT', '1');
6445 if GetAIFlag('ATTACKRIGHT') <> '' then
6446 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
6447 RemoveAIFlag('ATTACKRIGHT');
6449 SetAIFlag('NEEDJUMP', '1');
6451 if RunDirection() = D_LEFT
then
6452 begin // Èäåì íå â òó ñòîðîíó
6453 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6454 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
6455 SetAIFlag('NEEDFIRE', '1');
6456 SetAIFlag('GORIGHT', '1');
6461 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6462 SetAIFlag('NEEDFIRE', '1');
6463 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6464 SetAIFlag('GOLEFT', '1');
6468 //HACK! (does it belongs there?)
6469 RealizeCurrentWeapon();
6471 // Åñëè åñòü âîçìîæíûå öåëè:
6472 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
6473 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6474 for a
:= 0 to High(targets
) do
6476 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
6477 if GetRnd(FDifficult
.DiagFire
) then
6479 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
6480 if FDirection
= D_LEFT
then
6481 angle
:= ANGLE_LEFTUP
6483 angle
:= ANGLE_RIGHTUP
;
6485 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6486 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6488 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6489 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6490 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6491 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6492 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6494 SetAIFlag('NEEDFIRE', '1');
6495 SetAIFlag('NEEDSEEUP', '1');
6498 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
6499 if FDirection
= D_LEFT
then
6500 angle
:= ANGLE_LEFTDOWN
6502 angle
:= ANGLE_RIGHTDOWN
;
6504 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6505 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6507 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6508 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6509 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6510 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6511 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6513 SetAIFlag('NEEDFIRE', '1');
6514 SetAIFlag('NEEDSEEDOWN', '1');
6518 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
6519 if targets
[a
].Line
and targets
[a
].Visible
and
6520 (((FDirection
= D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
6521 ((FDirection
= D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
6523 SetAIFlag('NEEDFIRE', '1');
6528 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
6529 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
6530 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
6531 40+GetInterval(FDifficult
.Cover
, 40)) then
6532 SetAIFlag('NEEDJUMP', '1');
6534 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
6535 ammo
:= GetAmmoByWeapon(FCurrWeap
);
6536 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
6537 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
6539 SetAIFlag('SELECTWEAPON', '1');
6541 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
6542 if GetAIFlag('SELECTWEAPON') = '1' then
6545 RemoveAIFlag('SELECTWEAPON');
6549 procedure TBot
.Update();
6562 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
6563 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
6565 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
6567 if g_debug_BotAIOff
= 3 then
6577 RealizeCurrentWeapon();
6584 procedure TBot
.ReleaseKey(Key
: Byte);
6593 function TBot
.KeyPressed(Key
: Word): Boolean;
6595 Result
:= FKeys
[Key
].Pressed
;
6598 function TBot
.GetAIFlag(fName
: String20
): String20
;
6604 fName
:= LowerCase(fName
);
6606 if FAIFlags
<> nil then
6607 for a
:= 0 to High(FAIFlags
) do
6608 if LowerCase(FAIFlags
[a
].Name
) = fName
then
6610 Result
:= FAIFlags
[a
].Value
;
6615 procedure TBot
.RemoveAIFlag(fName
: String20
);
6619 if FAIFlags
= nil then Exit
;
6621 fName
:= LowerCase(fName
);
6623 for a
:= 0 to High(FAIFlags
) do
6624 if LowerCase(FAIFlags
[a
].Name
) = fName
then
6626 if a
<> High(FAIFlags
) then
6627 for b
:= a
to High(FAIFlags
)-1 do
6628 FAIFlags
[b
] := FAIFlags
[b
+1];
6630 SetLength(FAIFlags
, Length(FAIFlags
)-1);
6635 procedure TBot
.SetAIFlag(fName
, fValue
: String20
);
6643 fName
:= LowerCase(fName
);
6645 if FAIFlags
<> nil then
6646 for a
:= 0 to High(FAIFlags
) do
6647 if LowerCase(FAIFlags
[a
].Name
) = fName
then
6653 if ok
then FAIFlags
[a
].Value
:= fValue
6656 SetLength(FAIFlags
, Length(FAIFlags
)+1);
6657 with FAIFlags
[High(FAIFlags
)] do
6665 procedure TBot
.UpdateMove
;
6667 procedure GoLeft(Time
: Word = 1);
6669 ReleaseKey(KEY_LEFT
);
6670 ReleaseKey(KEY_RIGHT
);
6671 PressKey(KEY_LEFT
, Time
);
6672 SetDirection(D_LEFT
);
6675 procedure GoRight(Time
: Word = 1);
6677 ReleaseKey(KEY_LEFT
);
6678 ReleaseKey(KEY_RIGHT
);
6679 PressKey(KEY_RIGHT
, Time
);
6680 SetDirection(D_RIGHT
);
6683 function Rnd(a
: Word): Boolean;
6685 Result
:= Random(a
) = 0;
6688 procedure Turn(Time
: Word = 1200);
6690 if RunDirection() = D_LEFT
then GoRight(Time
) else GoLeft(Time
);
6695 ReleaseKey(KEY_LEFT
);
6696 ReleaseKey(KEY_RIGHT
);
6699 function CanRunLeft(): Boolean;
6701 Result
:= not CollideLevel(-1, 0);
6704 function CanRunRight(): Boolean;
6706 Result
:= not CollideLevel(1, 0);
6709 function CanRun(): Boolean;
6711 if RunDirection() = D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
6714 procedure Jump(Time
: Word = 30);
6716 PressKey(KEY_JUMP
, Time
);
6719 function NearHole(): Boolean;
6723 { TODO 5 : Ëåñòíèöû }
6724 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6725 for x
:= 1 to PLAYER_RECT
.Width
do
6726 if (not StayOnStep(x
*sx
, 0)) and
6727 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6728 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6737 function BorderHole(): Boolean;
6741 { TODO 5 : Ëåñòíèöû }
6742 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6743 for x
:= 1 to PLAYER_RECT
.Width
do
6744 if (not StayOnStep(x
*sx
, 0)) and
6745 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6746 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6748 for xx
:= x
to x
+32 do
6749 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
6759 function NearDeepHole(): Boolean;
6765 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6768 for x
:= 1 to PLAYER_RECT
.Width
do
6769 if (not StayOnStep(x
*sx
, 0)) and
6770 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6771 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6773 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6775 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
6780 end else Result
:= False;
6783 function OverDeepHole(): Boolean;
6790 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6792 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
6799 function OnGround(): Boolean;
6801 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
6804 function OnLadder(): Boolean;
6806 Result
:= FullInStep(0, 0);
6809 function BelowLadder(): Boolean;
6811 Result
:= (FullInStep(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
6812 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
6813 (FullInStep(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
6814 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
6817 function BelowLiftUp(): Boolean;
6819 Result
:= ((FullInLift(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
6820 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
6821 ((FullInLift(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
6822 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
6825 function OnTopLift(): Boolean;
6827 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
6830 function CanJumpOver(): Boolean;
6834 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6838 if not CollideLevel(sx
, 0) then Exit
;
6840 for y
:= 1 to BOT_MAXJUMP
do
6841 if CollideLevel(0, -y
) then Exit
else
6842 if not CollideLevel(sx
, -y
) then
6849 function CanJumpUp(Dist
: ShortInt): Boolean;
6856 if CollideLevel(Dist
, 0) then Exit
;
6859 for y
:= 0 to BOT_MAXJUMP
do
6860 if CollideLevel(Dist
, -y
) then
6869 for yy
:= y
+1 to BOT_MAXJUMP
do
6870 if not CollideLevel(Dist
, -yy
) then
6879 for y
:= 0 to BOT_MAXJUMP
do
6880 if CollideLevel(0, -y
) then
6888 if y
< yy
then Exit
;
6893 function IsSafeTrigger(): Boolean;
6898 if gTriggers
= nil then
6900 for a
:= 0 to High(gTriggers
) do
6901 if Collide(gTriggers
[a
].X
,
6904 gTriggers
[a
].Height
) and
6905 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
6906 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
6907 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
6908 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
6909 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
6914 // Âîçìîæíî, íàæèìàåì êíîïêó:
6915 if Rnd(16) and IsSafeTrigger() then
6918 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
6919 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
6921 ReleaseKey(KEY_LEFT
);
6922 ReleaseKey(KEY_RIGHT
);
6926 // Èäåì âëåâî, åñëè íàäî áûëî:
6927 if GetAIFlag('GOLEFT') <> '' then
6929 RemoveAIFlag('GOLEFT');
6930 if CanRunLeft() then
6934 // Èäåì âïðàâî, åñëè íàäî áûëî:
6935 if GetAIFlag('GORIGHT') <> '' then
6937 RemoveAIFlag('GORIGHT');
6938 if CanRunRight() then
6942 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
6943 if FObj
.X
< -32 then
6946 if FObj
.X
+32 > gMapInfo
.Width
then
6949 // Ïðûãàåì, åñëè íàäî áûëî:
6950 if GetAIFlag('NEEDJUMP') <> '' then
6953 RemoveAIFlag('NEEDJUMP');
6956 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
6957 if GetAIFlag('NEEDSEEUP') <> '' then
6960 ReleaseKey(KEY_DOWN
);
6961 PressKey(KEY_UP
, 20);
6962 RemoveAIFlag('NEEDSEEUP');
6965 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
6966 if GetAIFlag('NEEDSEEDOWN') <> '' then
6969 ReleaseKey(KEY_DOWN
);
6970 PressKey(KEY_DOWN
, 20);
6971 RemoveAIFlag('NEEDSEEDOWN');
6974 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
6975 if GetAIFlag('GOINHOLE') <> '' then
6976 if not OnGround() then
6978 ReleaseKey(KEY_LEFT
);
6979 ReleaseKey(KEY_RIGHT
);
6980 RemoveAIFlag('GOINHOLE');
6981 SetAIFlag('FALLINHOLE', '1');
6984 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
6985 if GetAIFlag('FALLINHOLE') <> '' then
6987 RemoveAIFlag('FALLINHOLE');
6989 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
6990 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
6991 if GetAIFlag('FALLINHOLE') = '' then
6992 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
6998 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7000 CanJumpUp(IfThen(RunDirection() = D_LEFT
, -1, 1)*32) and
7004 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7005 if OnGround() and NearHole() then
7006 if NearDeepHole() then // Åñëè ýòî áåçäíà
7008 0..3: Turn(); // Áåæèì îáðàòíî
7009 4: Jump(); // Ïðûãàåì
7010 5: begin // Ïðûãàåì îáðàòíî
7015 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7016 if GetAIFlag('GOINHOLE') = '' then
7018 0: Turn(); // Íå íóæíî òóäà
7019 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7020 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7021 if BorderHole() then
7022 SetAIFlag('GOINHOLE', '1');
7025 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7026 if (not CanRun()) and OnGround() then
7028 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7029 if CanJumpOver() or OnLadder() then
7031 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7032 if Random(2) = 0 then
7034 if IsSafeTrigger() then
7040 // Îñòàëîñü ìàëî âîçäóõà:
7041 if FAir
< 36 * 2 then
7044 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7045 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7046 if BodyInAcid(0, 0) then
7050 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7052 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7053 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7056 {function TBot.NeedItem(Item: Byte): Byte;
7061 procedure TBot
.SelectWeapon(Dist
: Integer);
7065 function HaveAmmo(weapon
: Byte): Boolean;
7068 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7069 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7070 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7071 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7072 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7073 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7074 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7075 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7076 else Result
:= True;
7081 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7083 if Dist
> BOT_LONGDIST
then
7084 begin // Äàëüíèé áîé
7086 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7088 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7092 else //if Dist > BOT_UNSAFEDIST then
7093 begin // Áëèæíèé áîé
7095 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7097 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7104 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7106 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7112 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7114 Result
:= inherited PickItem(ItemType
, force
, remove
);
7116 if Result
then SetAIFlag('SELECTWEAPON', '1');
7119 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7121 Result
:= inherited Heal(value
, Soft
);
7124 function TBot
.Healthy(): Byte;
7126 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7127 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7128 else if (FHealth
> 50) then Result
:= 2
7129 else if (FHealth
> 20) then Result
:= 1
7133 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7135 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7136 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7139 procedure TBot
.OnDamage(Angle
: SmallInt);
7147 if (Angle
= 0) or (Angle
= 180) then
7150 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7151 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7153 pla
:= g_Player_Get(FLastSpawnerUID
);
7154 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7155 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7158 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7159 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7161 mon
:= g_Monsters_Get(FLastSpawnerUID
);
7162 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7163 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7168 SetAIFlag('ATTACKLEFT', '1')
7170 SetAIFlag('ATTACKRIGHT', '1');
7174 function TBot
.RunDirection(): TDirection
;
7176 if Abs(Vel
.X
) >= 1 then
7178 if Vel
.X
> 0 then Result
:= D_RIGHT
else Result
:= D_LEFT
;
7180 Result
:= FDirection
;
7183 function TBot
.GetRnd(a
: Byte): Boolean;
7185 if a
= 0 then Result
:= False
7186 else if a
= 255 then Result
:= True
7187 else Result
:= Random(256) > 255-a
;
7190 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7192 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7195 procedure TBot
.SaveState(var Mem
: TBinMemoryWriter
);
7201 inherited SaveState(Mem
);
7203 // Âûáðàííîå îðóæèå:
7204 Mem
.WriteByte(FSelectedWeapon
);
7206 Mem
.WriteWord(FTargetUID
);
7207 // Âðåìÿ ïîòåðè öåëè:
7208 Mem
.WriteDWORD(FLastVisible
);
7209 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7210 dw
:= Length(FAIFlags
);
7213 for i
:= 0 to Integer(dw
)-1 do
7215 Mem
.WriteString(FAIFlags
[i
].Name
, 20);
7216 Mem
.WriteString(FAIFlags
[i
].Value
, 20);
7218 // Íàñòðîéêè ñëîæíîñòè:
7220 Mem
.WriteMemory(p
, SizeOf(TDifficult
));
7223 procedure TBot
.LoadState(var Mem
: TBinMemoryReader
);
7229 inherited LoadState(Mem
);
7231 // Âûáðàííîå îðóæèå:
7232 Mem
.ReadByte(FSelectedWeapon
);
7234 Mem
.ReadWord(FTargetUID
);
7235 // Âðåìÿ ïîòåðè öåëè:
7236 Mem
.ReadDWORD(FLastVisible
);
7237 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7239 SetLength(FAIFlags
, dw
);
7241 for i
:= 0 to Integer(dw
)-1 do
7243 Mem
.ReadString(FAIFlags
[i
].Name
);
7244 Mem
.ReadString(FAIFlags
[i
].Value
);
7246 // Íàñòðîéêè ñëîæíîñòè:
7247 Mem
.ReadMemory(p
, dw
);
7248 if dw
<> SizeOf(TDifficult
) then
7250 raise EBinSizeError
.Create('TBot.LoadState: Wrong FDifficult Size');
7252 FDifficult
:= TDifficult(p
^);