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 [WP_FIRST
..WP_LAST
] 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 [WP_FIRST
..WP_LAST
] of Boolean;
222 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
224 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
225 FReloading
: Array [WP_FIRST
..WP_LAST
] 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 [WP_FIRST
..WP_LAST
] of Byte;
345 CloseWeaponPrior
: Array [WP_FIRST
..WP_LAST
] of Byte;
346 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] 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 [WP_FIRST
..WP_LAST
] of Byte;
515 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
516 w_prior3
: Array [WP_FIRST
..WP_LAST
] 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 [WP_FIRST
..WP_LAST
] 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 [WP_FIRST
..WP_LAST
] 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 [WP_FIRST..WP_LAST] 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 [WP_FIRST
..WP_LAST
] 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
:= WP_FIRST
to WP_LAST
do
832 Mem
.ReadBoolean(gPlayers
[a
].FWeapon
[i
]);
833 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
834 for i
:= WP_FIRST
to WP_LAST
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
:= WP_FIRST
to WP_LAST
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
:= WP_FIRST
to WP_LAST
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
:= WP_FIRST
to WP_LAST
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
3381 if FTime
[T_SWITCH
] > gTime
then
3383 for i
:= WP_FIRST
to WP_LAST
do
3384 if FReloading
[i
] > 0 then
3392 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3393 //FNextWeap := FNextWeap and $1FFF;
3394 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3396 if not switchAllowed
then
3398 //HACK for weapon cycling
3399 if (FNextWeap
and $7000) <> 0 then FNextWeap
:= 0;
3403 nw
:= getNextWeaponIndex();
3404 if nw
= 255 then exit
; // don't reset anything here
3405 if nw
> High(FWeapon
) then
3407 // don't forget to reset queue here!
3408 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3416 FTime
[T_SWITCH
] := gTime
+156;
3417 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3418 FModel
.SetWeapon(FCurrWeap
);
3419 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3423 procedure TPlayer
.NextWeapon();
3425 if g_Game_IsClient
then Exit
;
3429 procedure TPlayer
.PrevWeapon();
3431 if g_Game_IsClient
then Exit
;
3435 procedure TPlayer
.SetWeapon(W
: Byte);
3437 if FCurrWeap
<> W
then
3438 if W
= WEAPON_SAW
then
3439 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3442 FModel
.SetWeapon(CurrWeap
);
3446 function TPlayer
.PickItem(ItemType
: Byte; respawn
: Boolean; var remove
: Boolean): Boolean;
3451 if g_Game_IsClient
then Exit
;
3453 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3454 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and respawn
;
3459 if FHealth
< PLAYER_HP_SOFT
then
3461 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3464 if gFlash
= 2 then Inc(FPickup
, 5);
3468 if FHealth
< PLAYER_HP_SOFT
then
3470 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3473 if gFlash
= 2 then Inc(FPickup
, 5);
3477 if FArmor
< PLAYER_AP_SOFT
then
3479 FArmor
:= PLAYER_AP_SOFT
;
3482 if gFlash
= 2 then Inc(FPickup
, 5);
3486 if FArmor
< PLAYER_AP_LIMIT
then
3488 FArmor
:= PLAYER_AP_LIMIT
;
3491 if gFlash
= 2 then Inc(FPickup
, 5);
3495 if FHealth
< PLAYER_HP_LIMIT
then
3497 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3500 if gFlash
= 2 then Inc(FPickup
, 5);
3504 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3506 if FHealth
< PLAYER_HP_LIMIT
then
3507 FHealth
:= PLAYER_HP_LIMIT
;
3508 if FArmor
< PLAYER_AP_LIMIT
then
3509 FArmor
:= PLAYER_AP_LIMIT
;
3512 if gFlash
= 2 then Inc(FPickup
, 5);
3516 if (not FWeapon
[WEAPON_SAW
]) or ((not respawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3518 FWeapon
[WEAPON_SAW
] := True;
3520 if gFlash
= 2 then Inc(FPickup
, 5);
3521 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3524 ITEM_WEAPON_SHOTGUN1
:
3525 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3527 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3528 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3530 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3531 FWeapon
[WEAPON_SHOTGUN1
] := True;
3533 if gFlash
= 2 then Inc(FPickup
, 5);
3534 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3537 ITEM_WEAPON_SHOTGUN2
:
3538 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3540 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3542 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3543 FWeapon
[WEAPON_SHOTGUN2
] := True;
3545 if gFlash
= 2 then Inc(FPickup
, 5);
3546 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3549 ITEM_WEAPON_CHAINGUN
:
3550 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3552 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3554 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3555 FWeapon
[WEAPON_CHAINGUN
] := True;
3557 if gFlash
= 2 then Inc(FPickup
, 5);
3558 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3561 ITEM_WEAPON_ROCKETLAUNCHER
:
3562 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3564 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3566 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3567 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3569 if gFlash
= 2 then Inc(FPickup
, 5);
3570 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3574 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3576 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3578 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3579 FWeapon
[WEAPON_PLASMA
] := True;
3581 if gFlash
= 2 then Inc(FPickup
, 5);
3582 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3586 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3588 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3590 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3591 FWeapon
[WEAPON_BFG
] := True;
3593 if gFlash
= 2 then Inc(FPickup
, 5);
3594 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3597 ITEM_WEAPON_SUPERPULEMET
:
3598 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3600 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3602 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3603 FWeapon
[WEAPON_SUPERPULEMET
] := True;
3605 if gFlash
= 2 then Inc(FPickup
, 5);
3606 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3610 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3612 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3615 if gFlash
= 2 then Inc(FPickup
, 5);
3618 ITEM_AMMO_BULLETS_BOX
:
3619 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3621 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3624 if gFlash
= 2 then Inc(FPickup
, 5);
3628 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3630 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3633 if gFlash
= 2 then Inc(FPickup
, 5);
3636 ITEM_AMMO_SHELLS_BOX
:
3637 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3639 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
3642 if gFlash
= 2 then Inc(FPickup
, 5);
3646 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3648 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3651 if gFlash
= 2 then Inc(FPickup
, 5);
3654 ITEM_AMMO_ROCKET_BOX
:
3655 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3657 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
3660 if gFlash
= 2 then Inc(FPickup
, 5);
3664 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3666 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3669 if gFlash
= 2 then Inc(FPickup
, 5);
3673 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3675 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
3678 if gFlash
= 2 then Inc(FPickup
, 5);
3682 if not(R_ITEM_BACKPACK
in FRulez
) or
3683 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
3684 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
3685 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
3686 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) then
3688 FMaxAmmo
[A_BULLETS
] := 400;
3689 FMaxAmmo
[A_SHELLS
] := 100;
3690 FMaxAmmo
[A_ROCKETS
] := 100;
3691 FMaxAmmo
[A_CELLS
] := 600;
3693 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3694 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3695 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3696 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3697 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3698 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3699 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3700 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3702 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
3705 if gFlash
= 2 then Inc(FPickup
, 5);
3709 if not(R_KEY_RED
in FRulez
) then
3711 Include(FRulez
, R_KEY_RED
);
3713 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3714 if gFlash
= 2 then Inc(FPickup
, 5);
3715 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3719 if not(R_KEY_GREEN
in FRulez
) then
3721 Include(FRulez
, R_KEY_GREEN
);
3723 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3724 if gFlash
= 2 then Inc(FPickup
, 5);
3725 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3729 if not(R_KEY_BLUE
in FRulez
) then
3731 Include(FRulez
, R_KEY_BLUE
);
3733 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3734 if gFlash
= 2 then Inc(FPickup
, 5);
3735 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3739 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
3741 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
3744 if gFlash
= 2 then Inc(FPickup
, 5);
3748 if FAir
< AIR_MAX
then
3753 if gFlash
= 2 then Inc(FPickup
, 5);
3758 if not (R_BERSERK
in FRulez
) then
3760 Include(FRulez
, R_BERSERK
);
3761 if FBFGFireCounter
= -1 then
3763 FCurrWeap
:= WEAPON_KASTET
;
3765 FModel
.SetWeapon(WEAPON_KASTET
);
3769 if gFlash
= 2 then Inc(FPickup
, 5);
3770 FBerserk
:= gTime
+30000;
3774 if FHealth
< PLAYER_HP_SOFT
then
3776 FHealth
:= PLAYER_HP_SOFT
;
3777 FBerserk
:= gTime
+30000;
3784 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
3786 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
3789 if gFlash
= 2 then Inc(FPickup
, 5);
3793 if FHealth
< PLAYER_HP_LIMIT
then
3795 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
3798 if gFlash
= 2 then Inc(FPickup
, 5);
3802 if FArmor
< PLAYER_AP_LIMIT
then
3804 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
3807 if gFlash
= 2 then Inc(FPickup
, 5);
3811 if FJetFuel
< JET_MAX
then
3813 FJetFuel
:= JET_MAX
;
3816 if gFlash
= 2 then Inc(FPickup
, 5);
3820 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
3822 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
3825 if gFlash
= 2 then Inc(FPickup
, 5);
3830 procedure TPlayer
.Touch();
3834 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
3837 // Áðîñèòü ôëàã òîâàðèùó:
3838 if gGameSettings
.GameMode
= GM_CTF
then
3843 procedure TPlayer
.Push(vx
, vy
: Integer);
3845 if (not FPhysics
) and FGhost
then
3847 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
3848 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
3849 if g_Game_IsNet
and g_Game_IsServer
then
3850 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
3853 procedure TPlayer
.Reset(Force
: Boolean);
3859 FTime
[T_RESPAWN
] := 0;
3860 FTime
[T_FLAGCAP
] := 0;
3873 FSpectator
:= False;
3876 FSpectatePlayer
:= -1;
3877 FNoRespawn
:= False;
3879 FLives
:= gGameSettings
.MaxLives
;
3884 procedure TPlayer
.SoftReset();
3890 FBFGFireCounter
:= -1;
3898 SetAction(A_STAND
, True);
3901 function TPlayer
.GetRespawnPoint(): Byte;
3906 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
3908 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
3909 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
3911 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
3913 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
3914 if Self
= gPlayer1
then
3915 c
:= RESPAWNPOINT_PLAYER1
3917 c
:= RESPAWNPOINT_PLAYER2
;
3918 if g_Map_GetPointCount(c
) > 0 then
3924 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
3925 if Self
= gPlayer1
then
3926 c
:= RESPAWNPOINT_PLAYER2
3928 c
:= RESPAWNPOINT_PLAYER1
;
3929 if g_Map_GetPointCount(c
) > 0 then
3936 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
3937 if Random(2) = 0 then
3938 c
:= RESPAWNPOINT_PLAYER1
3940 c
:= RESPAWNPOINT_PLAYER2
;
3941 if g_Map_GetPointCount(c
) > 0 then
3948 // Òî÷êà ëþáîé èç êîìàíä
3949 if Random(2) = 0 then
3950 c
:= RESPAWNPOINT_RED
3952 c
:= RESPAWNPOINT_BLUE
;
3953 if g_Map_GetPointCount(c
) > 0 then
3960 c
:= RESPAWNPOINT_DM
;
3961 if g_Map_GetPointCount(c
) > 0 then
3969 if gGameSettings
.GameMode
= GM_DM
then
3972 c
:= RESPAWNPOINT_DM
;
3973 if g_Map_GetPointCount(c
) > 0 then
3979 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
3980 if Random(2) = 0 then
3981 c
:= RESPAWNPOINT_PLAYER1
3983 c
:= RESPAWNPOINT_PLAYER2
;
3984 if g_Map_GetPointCount(c
) > 0 then
3990 // Òî÷êà ëþáîé èç êîìàíä
3991 if Random(2) = 0 then
3992 c
:= RESPAWNPOINT_RED
3994 c
:= RESPAWNPOINT_BLUE
;
3995 if g_Map_GetPointCount(c
) > 0 then
4003 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4005 // Òî÷êà ñâîåé êîìàíäû
4006 c
:= RESPAWNPOINT_DM
;
4007 if FTeam
= TEAM_RED
then
4008 c
:= RESPAWNPOINT_RED
;
4009 if FTeam
= TEAM_BLUE
then
4010 c
:= RESPAWNPOINT_BLUE
;
4011 if g_Map_GetPointCount(c
) > 0 then
4018 c
:= RESPAWNPOINT_DM
;
4019 if g_Map_GetPointCount(c
) > 0 then
4025 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4026 if Random(2) = 0 then
4027 c
:= RESPAWNPOINT_PLAYER1
4029 c
:= RESPAWNPOINT_PLAYER2
;
4030 if g_Map_GetPointCount(c
) > 0 then
4036 // Òî÷êà äðóãîé êîìàíäû
4037 c
:= RESPAWNPOINT_DM
;
4038 if FTeam
= TEAM_RED
then
4039 c
:= RESPAWNPOINT_BLUE
;
4040 if FTeam
= TEAM_BLUE
then
4041 c
:= RESPAWNPOINT_RED
;
4042 if g_Map_GetPointCount(c
) > 0 then
4050 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4052 RespawnPoint
: TRespawnPoint
;
4057 if not g_Game_IsServer
then
4061 FWantsInGame
:= True;
4062 FJustTeleported
:= True;
4065 FTime
[T_RESPAWN
] := 0;
4069 // if server changes MaxLives we gotta be ready
4070 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4072 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4073 if FTime
[T_RESPAWN
] > gTime
then
4076 // Ïðîñðàë âñå æèçíè:
4079 if not FSpectator
then Spectate(True);
4080 FWantsInGame
:= True;
4084 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4085 begin // "Ñâîÿ èãðà"
4086 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4087 FRulez
:= FRulez
-[R_BERSERK
];
4089 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4091 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4092 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4095 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4096 c
:= GetRespawnPoint();
4101 // Âîñêðåøåíèå áåç îðóæèÿ:
4104 FHealth
:= PLAYER_HP_SOFT
;
4110 for a
:= WP_FIRST
to WP_LAST
do
4112 FWeapon
[a
] := False;
4116 FWeapon
[WEAPON_PISTOL
] := True;
4117 FWeapon
[WEAPON_KASTET
] := True;
4118 FCurrWeap
:= WEAPON_PISTOL
;
4121 FModel
.SetWeapon(FCurrWeap
);
4123 for b
:= A_BULLETS
to A_CELLS
do
4126 FAmmo
[A_BULLETS
] := 50;
4128 FMaxAmmo
[A_BULLETS
] := 200;
4129 FMaxAmmo
[A_SHELLS
] := 50;
4130 FMaxAmmo
[A_ROCKETS
] := 50;
4131 FMaxAmmo
[A_CELLS
] := 300;
4133 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4134 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4139 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4140 if not g_Map_GetPoint(c
, RespawnPoint
) then
4142 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4146 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4147 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4148 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4154 FDirection
:= RespawnPoint
.Direction
;
4155 if FDirection
= D_LEFT
then
4161 FBFGFireCounter
:= -1;
4166 SetAction(A_STAND
, True);
4167 FModel
.Direction
:= FDirection
;
4169 for a
:= Low(FTime
) to High(FTime
) do
4172 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4177 FCanJetpack
:= False;
4179 // Àíèìàöèÿ âîçðîæäåíèÿ:
4180 if (not gLoadGameMode
) and (not Silent
) then
4181 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4183 Anim
:= TAnimation
.Create(ID
, False, 3);
4184 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4185 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4189 FSpectator
:= False;
4192 FSpectatePlayer
:= -1;
4195 if g_Game_IsNet
then
4197 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4198 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4200 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4201 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4206 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4209 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4210 else if (not NoMove
) then
4212 GameX
:= gMapInfo
.Width
div 2;
4213 GameY
:= gMapInfo
.Height
div 2;
4222 FWantsInGame
:= False;
4227 if Self
= gPlayer1
then
4232 if Self
= gPlayer2
then
4239 if g_Game_IsNet
then
4240 MH_SEND_PlayerStats(FUID
);
4243 procedure TPlayer
.SwitchNoClip
;
4247 FGhost
:= not FGhost
;
4248 FPhysics
:= not FGhost
;
4260 procedure TPlayer
.Run(Direction
: TDirection
);
4264 if MAX_RUNVEL
> 8 then
4268 if Direction
= D_LEFT
then
4270 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4271 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4274 if FObj
.Vel
.X
< MAX_RUNVEL
then
4275 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4277 // Âîçìîæíî, ïèíàåì êóñêè:
4278 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4280 b
:= Abs(FObj
.Vel
.X
);
4281 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4282 for a
:= 0 to High(gGibs
) do
4283 if gGibs
[a
].Live
and
4284 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4285 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4287 if FObj
.Vel
.X
< 0 then
4288 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4290 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4296 procedure TPlayer
.SeeDown();
4298 SetAction(A_SEEDOWN
);
4300 if FDirection
= D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4302 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4305 procedure TPlayer
.SeeUp();
4309 if FDirection
= D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4311 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4314 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4322 A_ATTACK
: Prior
:= 2;
4323 A_SEEUP
: Prior
:= 1;
4324 A_SEEDOWN
: Prior
:= 1;
4325 A_ATTACKUP
: Prior
:= 2;
4326 A_ATTACKDOWN
: Prior
:= 2;
4331 if (Prior
> FActionPrior
) or Force
then
4332 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4334 FActionPrior
:= Prior
;
4335 FActionAnim
:= Action
;
4336 FActionForce
:= Force
;
4337 FActionChanged
:= True;
4340 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4343 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4345 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4346 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4347 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4348 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4351 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4358 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4360 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4361 if g_Game_IsServer
and g_Game_IsNet
then
4362 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4366 FJustTeleported
:= True;
4371 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4373 Anim
:= TAnimation
.Create(ID
, False, 3);
4376 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4377 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4378 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4379 if g_Game_IsServer
and g_Game_IsNet
then
4380 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4381 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4385 FObj
.X
:= X
-PLAYER_RECT
.X
;
4386 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4387 if FLive
and FGhost
then
4393 if not g_Game_IsNet
then
4397 SetDirection(D_LEFT
);
4403 SetDirection(D_RIGHT
);
4409 if FDirection
= D_RIGHT
then
4411 SetDirection(D_LEFT
);
4416 SetDirection(D_RIGHT
);
4422 if not silent
and (Anim
<> nil) then
4424 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4425 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4428 if g_Game_IsServer
and g_Game_IsNet
then
4429 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4430 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4437 function nonz(a
: Single): Single;
4445 procedure TPlayer
.Update();
4448 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4449 blockmon
, headwater
, dospawn
: Boolean;
4454 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4455 AnyServer
:= g_Game_IsServer
;
4457 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4458 DoLerp(NetInterpLevel
+ 1)
4464 if FClientID
>= 0 then
4466 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4467 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4468 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4477 if FLive
and (gFly
or FJetpack
) then
4480 if FDirection
= D_LEFT
then
4485 if FLive
and (not FGhost
) then
4487 if FKeys
[KEY_UP
].Pressed
then
4489 if FKeys
[KEY_DOWN
].Pressed
then
4493 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4496 i
:= g_basic
.Sign(FIncCam
);
4497 FIncCam
:= Abs(FIncCam
);
4498 DecMin(FIncCam
, 5, 0);
4499 FIncCam
:= FIncCam
*i
;
4502 // no need to do that each second frame, weapon queue will take care of it
4503 if FLive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4504 if FLive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4506 if gTime
mod (GAME_TICK
*2) <> 0 then
4508 if (FObj
.Vel
.X
= 0) and FLive
then
4510 if FKeys
[KEY_LEFT
].Pressed
then
4512 if FKeys
[KEY_RIGHT
].Pressed
then
4517 g_Obj_Move(@FObj
, True, True, True);
4522 FActionChanged
:= False;
4526 // Let alive player do some actions
4527 if FKeys
[KEY_LEFT
].Pressed
then Run(D_LEFT
);
4528 if FKeys
[KEY_RIGHT
].Pressed
then Run(D_RIGHT
);
4529 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
4530 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
4531 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
4532 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
4533 if FKeys
[KEY_JUMP
].Pressed
then Jump()
4536 if AnyServer
and FJetpack
then
4540 if NetServer
then MH_SEND_PlayerStats(FUID
);
4542 FCanJetpack
:= True;
4549 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
4551 if FKeys
[k
].Pressed
then
4559 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4562 if (FTime
[T_RESPAWN
] <= gTime
) and
4563 gGameOn
and (not FLive
) then
4565 if (g_Player_GetCount() > 1) then
4569 gExit
:= EXIT_RESTART
;
4574 // Dead spectator actions
4577 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
4578 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
4582 if (FSpectatePlayer
>= High(gPlayers
)) then
4583 FSpectatePlayer
:= -1
4587 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
4588 if gPlayers
[I
] <> nil then
4589 if gPlayers
[I
].Live
then
4590 if gPlayers
[I
].UID
<> FUID
then
4592 FSpectatePlayer
:= I
;
4597 if not SetSpect
then FSpectatePlayer
:= -1;
4608 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
4610 FYTo
:= FObj
.Y
- 32;
4611 FSpectatePlayer
:= -1;
4613 if FKeys
[KEY_DOWN
].Pressed
then
4615 FYTo
:= FObj
.Y
+ 32;
4616 FSpectatePlayer
:= -1;
4618 if FKeys
[KEY_LEFT
].Pressed
then
4620 FXTo
:= FObj
.X
- 32;
4621 FSpectatePlayer
:= -1;
4623 if FKeys
[KEY_RIGHT
].Pressed
then
4625 FXTo
:= FObj
.X
+ 32;
4626 FSpectatePlayer
:= -1;
4629 if (FXTo
< -64) then
4631 else if (FXTo
> gMapInfo
.Width
+ 32) then
4632 FXTo
:= gMapInfo
.Width
+ 32;
4633 if (FYTo
< -72) then
4635 else if (FYTo
> gMapInfo
.Height
+ 32) then
4636 FYTo
:= gMapInfo
.Height
+ 32;
4640 g_Obj_Move(@FObj
, True, True, True)
4646 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
4647 if gPlayers
[FSpectatePlayer
] <> nil then
4648 if gPlayers
[FSpectatePlayer
].Live
then
4650 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
4651 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
4655 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
4656 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
4657 PANEL_BLOCKMON
, True);
4658 headwater
:= HeadInLiquid(0, 0);
4660 // Ñîïðîòèâëåíèå âîçäóõà:
4661 if (not FLive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
4662 if FObj
.Vel
.X
<> 0 then
4663 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
4665 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
4666 DecMin(FPain
, 5, 0);
4667 DecMin(FPickup
, 1, 0);
4669 if FLive
and (FObj
.Y
> gMapInfo
.Height
+128) and AnyServer
then
4671 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
4672 FMegaRulez
[MR_SUIT
] := 0;
4673 FMegaRulez
[MR_INVUL
] := 0;
4674 FMegaRulez
[MR_INVIS
] := 0;
4675 Kill(K_FALLKILL
, 0, HIT_FALL
);
4682 if FCurrWeap
= WEAPON_SAW
then
4683 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
4684 FSawSoundSelect
.IsPlaying()) then
4685 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
4688 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
4689 (not FJetSoundOff
.IsPlaying()) then
4691 FJetSoundFly
.SetPosition(0);
4692 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
4695 for b
:= WP_FIRST
to WP_LAST
do
4696 if FReloading
[b
] > 0 then
4702 if FShellTimer
> -1 then
4703 if FShellTimer
= 0 then
4705 if FShellType
= SHELL_SHELL
then
4706 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4707 GameVelX
, GameVelY
-2, SHELL_SHELL
)
4708 else if FShellType
= SHELL_DBLSHELL
then
4710 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4711 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
4712 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4713 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
4716 end else Dec(FShellTimer
);
4718 if (FBFGFireCounter
> -1) then
4719 if FBFGFireCounter
= 0 then
4723 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
4724 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
4725 xd
:= wx
+IfThen(FDirection
= D_LEFT
, -30, 30);
4726 yd
:= wy
+firediry();
4727 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
4728 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
4729 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
4730 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
4731 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
4734 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
4735 FBFGFireCounter
:= -1;
4738 FBFGFireCounter
:= 0
4740 Dec(FBFGFireCounter
);
4742 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
4744 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
4746 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
4749 if (headwater
or blockmon
) then
4755 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
4758 else if (FAir
mod 31 = 0) and not blockmon
then
4760 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
4761 if Random(2) = 0 then
4762 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
4764 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
4766 end else if FAir
< AIR_DEF
then
4769 if FDamageBuffer
> 0 then
4771 if FDamageBuffer
>= 9 then
4775 if FDamageBuffer
< 30 then i
:= 9
4776 else if FDamageBuffer
< 100 then i
:= 18
4780 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
4781 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
4782 FHealth
:= FHealth
-ii
;
4785 FHealth
:= FHealth
+FArmor
;
4790 if FHealth
<= 0 then
4791 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
4792 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
4793 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
4797 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
4798 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
4799 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
4800 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
4807 end; // if FLive then ...
4809 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
4811 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
4812 FModel
.GetCurrentAnimation
.MinLength
:= i
;
4813 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
4814 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
4816 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
4817 then SetAction(A_STAND
, True);
4819 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
4821 for b
:= Low(FKeys
) to High(FKeys
) do
4822 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
4825 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
4827 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
4828 FObj
.Y
+PLAYER_RECT
.Y
,
4835 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
4837 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
4838 FObj
.Y
+PLAYER_RECT
.Y
,
4842 Panel
.Width
, Panel
.Height
);
4845 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
4847 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
4848 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
4849 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
4850 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
4853 function g_Player_ValidName(Name
: string): Boolean;
4859 if gPlayers
= nil then Exit
;
4861 for a
:= 0 to High(gPlayers
) do
4862 if gPlayers
[a
] <> nil then
4863 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
4870 procedure TPlayer
.SetDirection(Direction
: TDirection
);
4874 d
:= FModel
.Direction
;
4876 FModel
.Direction
:= Direction
;
4877 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
4879 FDirection
:= Direction
;
4882 function TPlayer
.GetKeys(): Byte;
4886 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
4887 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
4888 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
4890 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
4891 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
4894 procedure TPlayer
.Use();
4898 if FTime
[T_USE
] > gTime
then Exit
;
4900 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
4901 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
4903 for a
:= 0 to High(gPlayers
) do
4904 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
4905 gPlayers
[a
].Live
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
4906 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
4907 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
4909 gPlayers
[a
].Touch();
4910 if g_Game_IsNet
and g_Game_IsServer
then
4911 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
4914 FTime
[T_USE
] := gTime
+120;
4917 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
4921 WX
, WY
, XD
, YD
: Integer;
4932 if R_BERSERK
in FRulez
then
4934 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
4935 obj
.X
:= FObj
.X
+FObj
.Rect
.X
;
4936 obj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
4939 obj
.rect
.Width
:= 39;
4940 obj
.rect
.Height
:= 52;
4941 obj
.Vel
.X
:= (xd
-wx
) div 2;
4942 obj
.Vel
.Y
:= (yd
-wy
) div 2;
4943 obj
.Accel
.X
:= xd
-wx
;
4944 obj
.Accel
.y
:= yd
-wy
;
4946 if g_Weapon_Hit(@obj
, 50, FUID
, HIT_SOME
) <> 0 then
4947 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
4949 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
4953 FPain
:= min(FPain
+ 25, 50);
4955 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
4960 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
4961 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
4963 FSawSoundSelect
.Stop();
4965 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
4967 else if not FSawSoundHit
.IsPlaying() then
4969 FSawSoundSelect
.Stop();
4970 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
4977 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
4978 FFireAngle
:= FAngle
;
4980 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4981 GameVelX
, GameVelY
-2, SHELL_BULLET
);
4986 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
4987 FFireAngle
:= FAngle
;
4990 FShellType
:= SHELL_SHELL
;
4995 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
4996 FFireAngle
:= FAngle
;
4999 FShellType
:= SHELL_DBLSHELL
;
5004 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5005 FFireAngle
:= FAngle
;
5007 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5008 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5011 WEAPON_ROCKETLAUNCHER
:
5013 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5014 FFireAngle
:= FAngle
;
5020 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5021 FFireAngle
:= FAngle
;
5027 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5028 FFireAngle
:= FAngle
;
5032 WEAPON_SUPERPULEMET
:
5034 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5035 FFireAngle
:= FAngle
;
5037 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5038 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5044 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5045 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5046 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5049 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5051 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5052 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5055 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5059 if NetInterpLevel
< 1 then
5069 AX
:= Abs(FXTo
- FObj
.X
);
5070 AY
:= Abs(FYTo
- FObj
.Y
);
5071 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5073 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5078 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
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_LIFTUP
, False) then Result
:= -1
5084 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5085 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5086 PANEL_LIFTDOWN
, False) then Result
:= 1
5090 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5097 if Flag
= FLAG_NONE
then
5100 if not g_Game_IsServer
then Exit
;
5102 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5103 if (Flag
= FTeam
) and
5104 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5105 (FFlag
<> FLAG_NONE
) then
5107 if FFlag
= FLAG_RED
then
5108 s
:= _lc
[I_PLAYER_FLAG_RED
]
5110 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5112 evtype
:= FLAG_STATE_SCORED
;
5114 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5115 Insert('.', ts
, Length(ts
) + 1 - 3);
5116 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5118 g_Map_ResetFlag(FFlag
);
5119 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5121 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5124 if g_Game_IsNet
then
5126 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5130 gFlags
[FFlag
].CaptureTime
:= 0;
5135 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5136 if (Flag
= FTeam
) and
5137 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5139 if Flag
= FLAG_RED
then
5140 s
:= _lc
[I_PLAYER_FLAG_RED
]
5142 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5144 evtype
:= FLAG_STATE_RETURNED
;
5145 gFlags
[Flag
].CaptureTime
:= 0;
5147 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5149 g_Map_ResetFlag(Flag
);
5150 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5153 if g_Game_IsNet
then
5155 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5161 // Ïîäîáðàë ÷óæîé ôëàã:
5162 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5166 if Flag
= FLAG_RED
then
5167 s
:= _lc
[I_PLAYER_FLAG_RED
]
5169 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5171 evtype
:= FLAG_STATE_CAPTURED
;
5173 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5175 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5177 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5180 if g_Game_IsNet
then
5182 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5188 procedure TPlayer
.SetFlag(Flag
: Byte);
5191 if FModel
<> nil then
5192 FModel
.SetFlag(FFlag
);
5195 function TPlayer
.DropFlag(): Boolean;
5200 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5202 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5203 with gFlags
[FFlag
] do
5207 Direction
:= FDirection
;
5208 State
:= FLAG_STATE_DROPPED
;
5210 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5211 (FObj
.Vel
.Y
div 2)-2+Random(5));
5213 if FFlag
= FLAG_RED
then
5214 s
:= _lc
[I_PLAYER_FLAG_RED
]
5216 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5218 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5219 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5221 if g_Game_IsNet
then
5222 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5228 procedure TPlayer
.GetSecret();
5233 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5235 Assert(Key
<= High(FKeys
));
5237 FKeys
[Key
].Pressed
:= True;
5238 FKeys
[Key
].Time
:= Time
;
5241 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5243 Result
:= FKeys
[K
].Pressed
;
5246 procedure TPlayer
.ReleaseKeys();
5250 for a
:= Low(FKeys
) to High(FKeys
) do
5252 FKeys
[a
].Pressed
:= False;
5257 procedure TPlayer
.OnDamage(Angle
: SmallInt
);
5261 function TPlayer
.firediry(): Integer;
5263 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5264 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5268 procedure TPlayer
.RememberState();
5272 FSavedState
.Health
:= FHealth
;
5273 FSavedState
.Armor
:= FArmor
;
5274 FSavedState
.Air
:= FAir
;
5275 FSavedState
.JetFuel
:= FJetFuel
;
5276 FSavedState
.CurrWeap
:= FCurrWeap
;
5277 FSavedState
.NextWeap
:= FNextWeap
;
5278 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5281 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5283 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5285 FSavedState
.Rulez
:= FRulez
;
5286 FSavedState
.WaitRecall
:= True;
5289 procedure TPlayer
.RecallState();
5293 if not FSavedState
.WaitRecall
then Exit
;
5295 FHealth
:= FSavedState
.Health
;
5296 FArmor
:= FSavedState
.Armor
;
5297 FAir
:= FSavedState
.Air
;
5298 FJetFuel
:= FSavedState
.JetFuel
;
5299 FCurrWeap
:= FSavedState
.CurrWeap
;
5300 FNextWeap
:= FSavedState
.NextWeap
;
5301 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5304 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5306 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5308 FRulez
:= FSavedState
.Rulez
;
5309 FSavedState
.WaitRecall
:= False;
5311 if gGameSettings
.GameType
= GT_SERVER
then
5312 MH_SEND_PlayerStats(FUID
);
5315 procedure TPlayer
.SaveState(var Mem
: TBinMemoryWriter
);
5327 Mem
:= TBinMemoryWriter
.Create(i
);
5329 // Ñèãíàòóðà èãðîêà:
5330 sig
:= PLAYER_SIGNATURE
; // 'PLYR'
5331 Mem
.WriteDWORD(sig
);
5333 Mem
.WriteBoolean(FIamBot
);
5335 Mem
.WriteWord(FUID
);
5337 Mem
.WriteString(FName
, 32);
5339 Mem
.WriteByte(FTeam
);
5341 Mem
.WriteBoolean(FLive
);
5342 // Èçðàñõîäîâàë ëè âñå æèçíè:
5343 Mem
.WriteBoolean(FNoRespawn
);
5345 if FDirection
= D_LEFT
then
5351 Mem
.WriteInt(FHealth
);
5353 Mem
.WriteByte(FLives
);
5355 Mem
.WriteInt(FArmor
);
5359 Mem
.WriteInt(FJetFuel
);
5361 Mem
.WriteInt(FPain
);
5363 Mem
.WriteInt(FKills
);
5365 Mem
.WriteInt(FMonsterKills
);
5367 Mem
.WriteInt(FFrags
);
5369 Mem
.WriteByte(FFragCombo
);
5370 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5371 Mem
.WriteDWORD(FLastFrag
);
5373 Mem
.WriteInt(FDeath
);
5374 // Êàêîé ôëàã íåñåò:
5375 Mem
.WriteByte(FFlag
);
5377 Mem
.WriteInt(FSecrets
);
5379 Mem
.WriteByte(FCurrWeap
);
5381 Mem
.WriteWord(FNextWeap
);
5383 Mem
.WriteByte(FNextWeapDelay
);
5384 // Âðåìÿ çàðÿäêè BFG:
5385 Mem
.WriteSmallInt(FBFGFireCounter
);
5387 Mem
.WriteInt(FDamageBuffer
);
5388 // Ïîñëåäíèé óäàðèâøèé:
5389 Mem
.WriteWord(FLastSpawnerUID
);
5390 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5391 Mem
.WriteByte(FLastHit
);
5393 Obj_SaveState(@FObj
, Mem
);
5394 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5395 for i
:= A_BULLETS
to A_CELLS
do
5396 Mem
.WriteWord(FAmmo
[i
]);
5397 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5398 for i
:= A_BULLETS
to A_CELLS
do
5399 Mem
.WriteWord(FMaxAmmo
[i
]);
5401 for i
:= WP_FIRST
to WP_LAST
do
5402 Mem
.WriteBoolean(FWeapon
[i
]);
5403 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5404 for i
:= WP_FIRST
to WP_LAST
do
5405 Mem
.WriteWord(FReloading
[i
]);
5407 if R_ITEM_BACKPACK
in FRulez
then
5412 // Íàëè÷èå êðàñíîãî êëþ÷à:
5413 if R_KEY_RED
in FRulez
then
5418 // Íàëè÷èå çåëåíîãî êëþ÷à:
5419 if R_KEY_GREEN
in FRulez
then
5424 // Íàëè÷èå ñèíåãî êëþ÷à:
5425 if R_KEY_BLUE
in FRulez
then
5430 // Íàëè÷èå áåðñåðêà:
5431 if R_BERSERK
in FRulez
then
5436 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5437 for i
:= MR_SUIT
to MR_MAX
do
5438 Mem
.WriteDWORD(FMegaRulez
[i
]);
5439 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5440 for i
:= T_RESPAWN
to T_FLAGCAP
do
5441 Mem
.WriteDWORD(FTime
[i
]);
5444 Mem
.WriteString(str
);
5454 procedure TPlayer
.LoadState(var Mem
: TBinMemoryReader
);
5464 // Ñèãíàòóðà èãðîêà:
5466 if sig
<> PLAYER_SIGNATURE
then // 'PLYR'
5468 raise EBinSizeError
.Create('TPlayer.LoadState: Wrong Player Signature');
5471 Mem
.ReadBoolean(FIamBot
);
5475 Mem
.ReadString(str
);
5476 if (Self
<> gPlayer1
) and (Self
<> gPlayer2
) then
5479 Mem
.ReadByte(FTeam
);
5481 Mem
.ReadBoolean(FLive
);
5482 // Èçðàñõîäîâàë ëè âñå æèçíè:
5483 Mem
.ReadBoolean(FNoRespawn
);
5487 FDirection
:= D_LEFT
5489 FDirection
:= D_RIGHT
;
5491 Mem
.ReadInt(FHealth
);
5493 Mem
.ReadByte(FLives
);
5495 Mem
.ReadInt(FArmor
);
5499 Mem
.ReadInt(FJetFuel
);
5503 Mem
.ReadInt(FKills
);
5505 Mem
.ReadInt(FMonsterKills
);
5507 Mem
.ReadInt(FFrags
);
5509 Mem
.ReadByte(FFragCombo
);
5510 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5511 Mem
.ReadDWORD(FLastFrag
);
5513 Mem
.ReadInt(FDeath
);
5514 // Êàêîé ôëàã íåñåò:
5515 Mem
.ReadByte(FFlag
);
5517 Mem
.ReadInt(FSecrets
);
5519 Mem
.ReadByte(FCurrWeap
);
5521 Mem
.ReadWord(FNextWeap
);
5523 Mem
.ReadByte(FNextWeapDelay
);
5524 // Âðåìÿ çàðÿäêè BFG:
5525 Mem
.ReadSmallInt(FBFGFireCounter
);
5527 Mem
.ReadInt(FDamageBuffer
);
5528 // Ïîñëåäíèé óäàðèâøèé:
5529 Mem
.ReadWord(FLastSpawnerUID
);
5530 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5531 Mem
.ReadByte(FLastHit
);
5533 Obj_LoadState(@FObj
, Mem
);
5534 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5535 for i
:= A_BULLETS
to A_CELLS
do
5536 Mem
.ReadWord(FAmmo
[i
]);
5537 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5538 for i
:= A_BULLETS
to A_CELLS
do
5539 Mem
.ReadWord(FMaxAmmo
[i
]);
5541 for i
:= WP_FIRST
to WP_LAST
do
5542 Mem
.ReadBoolean(FWeapon
[i
]);
5543 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5544 for i
:= WP_FIRST
to WP_LAST
do
5545 Mem
.ReadWord(FReloading
[i
]);
5549 Include(FRulez
, R_ITEM_BACKPACK
);
5550 // Íàëè÷èå êðàñíîãî êëþ÷à:
5553 Include(FRulez
, R_KEY_RED
);
5554 // Íàëè÷èå çåëåíîãî êëþ÷à:
5557 Include(FRulez
, R_KEY_GREEN
);
5558 // Íàëè÷èå ñèíåãî êëþ÷à:
5561 Include(FRulez
, R_KEY_BLUE
);
5562 // Íàëè÷èå áåðñåðêà:
5565 Include(FRulez
, R_BERSERK
);
5566 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5567 for i
:= MR_SUIT
to MR_MAX
do
5568 Mem
.ReadDWORD(FMegaRulez
[i
]);
5569 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5570 for i
:= T_RESPAWN
to T_FLAGCAP
do
5571 Mem
.ReadDWORD(FTime
[i
]);
5573 Mem
.ReadString(str
);
5575 Mem
.ReadByte(FColor
.R
);
5576 Mem
.ReadByte(FColor
.G
);
5577 Mem
.ReadByte(FColor
.B
);
5578 if Self
= gPlayer1
then
5580 str
:= gPlayer1Settings
.Model
;
5581 FColor
:= gPlayer1Settings
.Color
;
5583 if Self
= gPlayer2
then
5585 str
:= gPlayer2Settings
.Model
;
5586 FColor
:= gPlayer2Settings
.Color
;
5588 // Îáíîâëÿåì ìîäåëü èãðîêà:
5590 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
5591 FModel
.Color
:= TEAMCOLOR
[FTeam
]
5593 FModel
.Color
:= FColor
;
5596 procedure TPlayer
.AllRulez(Health
: Boolean);
5602 FHealth
:= PLAYER_HP_LIMIT
;
5603 FArmor
:= PLAYER_AP_LIMIT
;
5607 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
5608 for a
:= A_BULLETS
to A_CELLS
do FAmmo
[a
] := 30000;
5609 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5612 procedure TPlayer
.RestoreHealthArmor();
5614 FHealth
:= PLAYER_HP_LIMIT
;
5615 FArmor
:= PLAYER_AP_LIMIT
;
5618 procedure TPlayer
.FragCombo();
5622 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
5624 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
5626 if FFragCombo
< 5 then
5628 Param
:= FUID
or (FFragCombo
shl 16);
5629 if (FComboEvnt
>= Low(gDelayedEvents
)) and
5630 (FComboEvnt
<= High(gDelayedEvents
)) and
5631 gDelayedEvents
[FComboEvnt
].Pending
and
5632 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
5633 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
5635 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
5636 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
5639 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
5647 procedure TPlayer
.GiveItem(ItemType
: Byte);
5651 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
5653 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
5657 if FAir
< AIR_MAX
then
5664 if not (R_BERSERK
in FRulez
) then
5666 Include(FRulez
, R_BERSERK
);
5667 if FBFGFireCounter
< 1 then
5669 FCurrWeap
:= WEAPON_KASTET
;
5671 FModel
.SetWeapon(WEAPON_KASTET
);
5675 FBerserk
:= gTime
+30000;
5677 if FHealth
< PLAYER_HP_SOFT
then
5679 FHealth
:= PLAYER_HP_SOFT
;
5680 FBerserk
:= gTime
+30000;
5685 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
5687 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
5691 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
5693 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
5697 if FJetFuel
< JET_MAX
then
5699 FJetFuel
:= JET_MAX
;
5702 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
5703 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
5705 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
5706 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5708 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
5710 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
5712 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
5713 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5716 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
5717 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
5718 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
5719 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
5720 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
5721 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
5722 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
5723 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
5725 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5726 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
5727 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5728 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
5729 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5730 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
5731 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5732 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
5735 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
5736 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
5737 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
5738 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) then
5740 FMaxAmmo
[A_BULLETS
] := 400;
5741 FMaxAmmo
[A_SHELLS
] := 100;
5742 FMaxAmmo
[A_ROCKETS
] := 100;
5743 FMaxAmmo
[A_CELLS
] := 600;
5745 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5746 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5747 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5748 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5750 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
5753 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
5754 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
5755 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
5757 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
5758 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
5763 if g_Game_IsNet
and g_Game_IsServer
then
5764 MH_SEND_PlayerStats(FUID
);
5767 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
5772 if (Random(5) = 1) and (Times
= 1) then
5775 if BodyInLiquid(0, 0) then
5777 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
5778 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
5779 if Random(2) = 0 then
5780 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5782 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5786 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
5788 for i
:= 1 to Times
do
5790 Anim
:= TAnimation
.Create(id
, False, 3);
5792 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
5793 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
5799 procedure TPlayer
.PauseSounds(Enable
: Boolean);
5801 FSawSound
.Pause(Enable
);
5802 FSawSoundIdle
.Pause(Enable
);
5803 FSawSoundHit
.Pause(Enable
);
5804 FSawSoundSelect
.Pause(Enable
);
5809 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
5814 FObj
.Rect
:= PLAYER_CORPSERECT
;
5815 FModelName
:= ModelName
;
5820 FState
:= CORPSE_STATE_MESS
;
5821 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
5825 FState
:= CORPSE_STATE_NORMAL
;
5826 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
5830 destructor TCorpse
.Destroy();
5837 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
5841 if FState
= CORPSE_STATE_REMOVEME
then
5844 FDamage
:= FDamage
+ Value
;
5846 if FDamage
> 150 then
5848 if FAnimation
<> nil then
5853 FState
:= CORPSE_STATE_REMOVEME
;
5855 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
5856 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
5857 FModelName
, FColor
);
5858 // Çâóê ìÿñà îò òðóïà:
5859 pm
:= g_PlayerModel_Get(FModelName
);
5860 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
5866 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
5867 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
5868 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
5869 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
5870 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
5875 procedure TCorpse
.Draw();
5877 if FState
= CORPSE_STATE_REMOVEME
then
5880 if FAnimation
<> nil then
5881 FAnimation
.Draw(FObj
.X
, FObj
.Y
, M_NONE
);
5883 if FAnimationMask
<> nil then
5886 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, M_NONE
);
5893 procedure TCorpse
.Update();
5897 if FState
= CORPSE_STATE_REMOVEME
then
5900 if gTime
mod (GAME_TICK
*2) <> 0 then
5902 g_Obj_Move(@FObj
, True, True, True);
5907 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
5908 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5910 st
:= g_Obj_Move(@FObj
, True, True, True);
5912 if WordBool(st
and MOVE_FALLOUT
) then
5914 FState
:= CORPSE_STATE_REMOVEME
;
5918 if FAnimation
<> nil then
5919 FAnimation
.Update();
5920 if FAnimationMask
<> nil then
5921 FAnimationMask
.Update();
5924 procedure TCorpse
.SaveState(var Mem
: TBinMemoryWriter
);
5933 sig
:= CORPSE_SIGNATURE
; // 'CORP'
5934 Mem
.WriteDWORD(sig
);
5936 Mem
.WriteByte(FState
);
5937 // Íàêîïëåííûé óðîí:
5938 Mem
.WriteByte(FDamage
);
5940 Mem
.WriteByte(FColor
.R
);
5941 Mem
.WriteByte(FColor
.G
);
5942 Mem
.WriteByte(FColor
.B
);
5944 Obj_SaveState(@FObj
, Mem
);
5945 // Åñòü ëè àíèìàöèÿ:
5946 anim
:= FAnimation
<> nil;
5947 Mem
.WriteBoolean(anim
);
5948 // Åñëè åñòü - ñîõðàíÿåì:
5950 FAnimation
.SaveState(Mem
);
5951 // Åñòü ëè ìàñêà àíèìàöèè:
5952 anim
:= FAnimationMask
<> nil;
5953 Mem
.WriteBoolean(anim
);
5954 // Åñëè åñòü - ñîõðàíÿåì:
5956 FAnimationMask
.SaveState(Mem
);
5959 procedure TCorpse
.LoadState(var Mem
: TBinMemoryReader
);
5969 if sig
<> CORPSE_SIGNATURE
then // 'CORP'
5971 raise EBinSizeError
.Create('TCorpse.LoadState: Wrong Corpse Signature');
5974 Mem
.ReadByte(FState
);
5975 // Íàêîïëåííûé óðîí:
5976 Mem
.ReadByte(FDamage
);
5978 Mem
.ReadByte(FColor
.R
);
5979 Mem
.ReadByte(FColor
.G
);
5980 Mem
.ReadByte(FColor
.B
);
5982 Obj_LoadState(@FObj
, Mem
);
5983 // Åñòü ëè àíèìàöèÿ:
5984 Mem
.ReadBoolean(anim
);
5985 // Åñëè åñòü - çàãðóæàåì:
5988 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
5989 FAnimation
.LoadState(Mem
);
5991 // Åñòü ëè ìàñêà àíèìàöèè:
5992 Mem
.ReadBoolean(anim
);
5993 // Åñëè åñòü - çàãðóæàåì:
5996 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
5997 FAnimationMask
.LoadState(Mem
);
6003 constructor TBot
.Create();
6010 FSpectator
:= False;
6017 for a
:= WP_FIRST
to WP_LAST
do
6019 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6020 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6021 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6025 destructor TBot
.Destroy();
6028 inherited Destroy();
6031 procedure TBot
.Draw();
6035 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6036 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6039 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6041 inherited Respawn(Silent
, Force
);
6044 FSelectedWeapon
:= FCurrWeap
;
6049 procedure TBot
.UpdateCombat();
6062 TTargetRecord
= array of TTarget
;
6064 function Compare(a
, b
: TTarget
): Integer;
6066 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6069 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6071 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6072 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6074 if a
.Dist
> b
.Dist
then // B áëèæå
6076 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6079 else // Ñòðàííî -> A
6084 a
, x1
, y1
, x2
, y2
: Integer;
6085 targets
: TTargetRecord
;
6087 Target
, BestTarget
: TTarget
;
6088 firew
, fireh
: Integer;
6092 vsPlayer
, vsMonster
, ok
: Boolean;
6094 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6095 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6097 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6098 if FCurrWeap
<> FSelectedWeapon
then
6101 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6102 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6104 RemoveAIFlag('NEEDFIRE');
6107 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6108 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_MEGAKASTET
: PressKey(KEY_FIRE
, 40);
6109 else PressKey(KEY_FIRE
);
6113 // Êîîðäèíàòû ñòâîëà:
6114 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6115 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6117 Target
.UID
:= FTargetUID
;
6120 if Target
.UID
<> 0 then
6121 begin // Öåëü åñòü - íàñòðàèâàåì
6122 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6125 with g_Player_Get(Target
.UID
) do
6127 if (@FObj
) <> nil then
6134 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6135 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6136 Target
.Rect
:= PLAYER_RECT
;
6137 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6138 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6139 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6140 Target
.IsPlayer
:= True;
6144 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6147 mon
:= g_Monsters_Get(Target
.UID
);
6150 Target
.X
:= mon
.Obj
.X
;
6151 Target
.Y
:= mon
.Obj
.Y
;
6153 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6154 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6155 Target
.Rect
:= mon
.Obj
.Rect
;
6156 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6157 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6158 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6159 Target
.IsPlayer
:= False;
6166 begin // Öåëè íåò - îáíóëÿåì
6171 Target
.Visible
:= False;
6172 Target
.Line
:= False;
6173 Target
.IsPlayer
:= False;
6178 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6179 if (not Target
.Line
) or (not Target
.Visible
) then
6183 for a
:= 0 to High(gPlayers
) do
6184 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].Live
) and
6185 (gPlayers
[a
].FUID
<> FUID
) and
6186 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6187 (not gPlayers
[a
].NoTarget
) and
6188 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6190 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6191 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6194 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6195 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6197 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6198 if g_TraceVector(x1
, y1
, x2
, y2
) then
6200 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6201 SetLength(targets
, Length(targets
)+1);
6202 with targets
[High(targets
)] do
6204 UID
:= gPlayers
[a
].FUID
;
6205 X
:= gPlayers
[a
].FObj
.X
;
6206 Y
:= gPlayers
[a
].FObj
.Y
;
6209 Rect
:= PLAYER_RECT
;
6210 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6211 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6212 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6220 if vsMonster
and (gMonsters
<> nil) then
6221 for a
:= 0 to High(gMonsters
) do
6222 if (gMonsters
[a
] <> nil) and (gMonsters
[a
].Live
) and
6223 (gMonsters
[a
].MonsterType
<> MONSTER_BARREL
) then
6225 mon
:= gMonsters
[a
];
6227 if not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
6228 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
) then
6231 x2
:= mon
.Obj
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6232 y2
:= mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6234 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6235 if g_TraceVector(x1
, y1
, x2
, y2
) then
6237 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6238 SetLength(targets
, Length(targets
)+1);
6239 with targets
[High(targets
)] do
6246 Rect
:= mon
.Obj
.Rect
;
6247 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6248 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6249 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6257 // Åñëè åñòü âîçìîæíûå öåëè:
6258 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6259 if targets
<> nil then
6261 // Âûáèðàåì íàèëó÷øóþ öåëü:
6262 BestTarget
:= targets
[0];
6263 if Length(targets
) > 1 then
6264 for a
:= 1 to High(targets
) do
6265 if Compare(BestTarget
, targets
[a
]) = 1 then
6266 BestTarget
:= targets
[a
];
6268 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6269 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6270 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6272 Target
:= BestTarget
;
6274 if (Healthy() = 3) or ((Healthy() = 2)) then
6275 begin // Åñëè çäîðîâû - äîãîíÿåì
6276 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6277 SetAIFlag('GORIGHT', '1');
6278 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6279 SetAIFlag('GOLEFT', '1');
6282 begin // Åñëè ïîáèòû - óáåãàåì
6283 if ((RunDirection() = D_LEFT
) and (Target
.X
< FObj
.X
)) then
6284 SetAIFlag('GORIGHT', '1');
6285 if ((RunDirection() = D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6286 SetAIFlag('GOLEFT', '1');
6289 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6290 SelectWeapon(Abs(x1
-Target
.cX
));
6295 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6296 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6297 if Target
.UID
<> 0 then
6299 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6300 Target
.Y
+ Target
.Rect
.Y
) then
6301 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6302 if (Healthy() = 3) or ((Healthy() = 2)) then
6303 begin // Åñëè çäîðîâû - äîãîíÿåì
6304 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6305 SetAIFlag('GORIGHT', '1');
6306 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6307 SetAIFlag('GOLEFT', '1');
6310 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6312 if ((RunDirection() = D_LEFT
) and (Target
.X
< FObj
.X
)) then
6313 SetAIFlag('GORIGHT', '1');
6314 if ((RunDirection() = D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6315 SetAIFlag('GOLEFT', '1');
6319 begin // Öåëü ïîêà íà "ýêðàíå"
6320 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6321 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6322 FLastVisible
:= gTime
;
6323 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6324 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6326 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6327 SetAIFlag('GORIGHT', '1');
6328 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6329 SetAIFlag('GOLEFT', '1');
6333 // Âûáèðàåì óãîë ââåðõ:
6334 if FDirection
= D_LEFT
then
6335 angle
:= ANGLE_LEFTUP
6337 angle
:= ANGLE_RIGHTUP
;
6339 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6340 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6342 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6343 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6344 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6345 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6346 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6347 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6348 begin // òî íóæíî ñòðåëÿòü ââåðõ
6349 SetAIFlag('NEEDFIRE', '1');
6350 SetAIFlag('NEEDSEEUP', '1');
6353 // Âûáèðàåì óãîë âíèç:
6354 if FDirection
= D_LEFT
then
6355 angle
:= ANGLE_LEFTDOWN
6357 angle
:= ANGLE_RIGHTDOWN
;
6359 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6360 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6362 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6363 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6364 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6365 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6366 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6367 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6368 begin // òî íóæíî ñòðåëÿòü âíèç
6369 SetAIFlag('NEEDFIRE', '1');
6370 SetAIFlag('NEEDSEEDOWN', '1');
6373 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6374 if Target
.Visible
and
6375 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6376 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6378 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6379 if ((FDirection
= D_LEFT
) and (Target
.X
< FObj
.X
)) or
6380 ((FDirection
= D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6381 begin // òî íóæíî ñòðåëÿòü âïåðåä
6382 SetAIFlag('NEEDFIRE', '1');
6383 SetAIFlag('NEEDSEEDOWN', '');
6384 SetAIFlag('NEEDSEEUP', '');
6386 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6387 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6388 if GetRnd(FDifficult
.CloseJump
) then
6389 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6390 if Abs(FObj
.X
-Target
.X
) < 128 then
6394 if Random(a
) = 0 then
6395 SetAIFlag('NEEDJUMP', '1');
6399 // Åñëè öåëü âñå åùå åñòü:
6400 if Target
.UID
<> 0 then
6401 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
6402 Target
.UID
:= 0 // òî çàáûòü öåëü
6403 else // Åñëè âèäåëè íåäàâíî
6404 begin // íî öåëü óáèëè
6405 if Target
.IsPlayer
then
6406 begin // Öåëü - èãðîê
6407 pla
:= g_Player_Get(Target
.UID
);
6408 if (pla
= nil) or (not pla
.Live
) or pla
.NoTarget
or
6409 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6410 Target
.UID
:= 0; // òî çàáûòü öåëü
6413 begin // Öåëü - ìîíñòð
6414 mon
:= g_Monsters_Get(Target
.UID
);
6415 if (mon
= nil) or (not mon
.Live
) then
6416 Target
.UID
:= 0; // òî çàáûòü öåëü
6419 end; // if Target.UID <> 0
6421 FTargetUID
:= Target
.UID
;
6423 // Åñëè âîçìîæíûõ öåëåé íåò:
6424 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
6425 if targets
= nil then
6426 if GetAIFlag('ATTACKLEFT') <> '' then
6427 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
6428 RemoveAIFlag('ATTACKLEFT');
6430 SetAIFlag('NEEDJUMP', '1');
6432 if RunDirection() = D_RIGHT
then
6433 begin // Èäåì íå â òó ñòîðîíó
6434 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6435 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
6436 SetAIFlag('NEEDFIRE', '1');
6437 SetAIFlag('GOLEFT', '1');
6441 begin // Èäåì â íóæíóþ ñòîðîíó
6442 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6443 SetAIFlag('NEEDFIRE', '1');
6444 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6445 SetAIFlag('GORIGHT', '1');
6449 if GetAIFlag('ATTACKRIGHT') <> '' then
6450 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
6451 RemoveAIFlag('ATTACKRIGHT');
6453 SetAIFlag('NEEDJUMP', '1');
6455 if RunDirection() = D_LEFT
then
6456 begin // Èäåì íå â òó ñòîðîíó
6457 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6458 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
6459 SetAIFlag('NEEDFIRE', '1');
6460 SetAIFlag('GORIGHT', '1');
6465 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6466 SetAIFlag('NEEDFIRE', '1');
6467 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6468 SetAIFlag('GOLEFT', '1');
6472 //HACK! (does it belongs there?)
6473 RealizeCurrentWeapon();
6475 // Åñëè åñòü âîçìîæíûå öåëè:
6476 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
6477 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6478 for a
:= 0 to High(targets
) do
6480 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
6481 if GetRnd(FDifficult
.DiagFire
) then
6483 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
6484 if FDirection
= D_LEFT
then
6485 angle
:= ANGLE_LEFTUP
6487 angle
:= ANGLE_RIGHTUP
;
6489 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6490 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6492 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6493 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6494 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6495 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6496 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6498 SetAIFlag('NEEDFIRE', '1');
6499 SetAIFlag('NEEDSEEUP', '1');
6502 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
6503 if FDirection
= D_LEFT
then
6504 angle
:= ANGLE_LEFTDOWN
6506 angle
:= ANGLE_RIGHTDOWN
;
6508 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6509 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6511 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6512 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6513 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6514 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6515 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6517 SetAIFlag('NEEDFIRE', '1');
6518 SetAIFlag('NEEDSEEDOWN', '1');
6522 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
6523 if targets
[a
].Line
and targets
[a
].Visible
and
6524 (((FDirection
= D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
6525 ((FDirection
= D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
6527 SetAIFlag('NEEDFIRE', '1');
6532 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
6533 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
6534 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
6535 40+GetInterval(FDifficult
.Cover
, 40)) then
6536 SetAIFlag('NEEDJUMP', '1');
6538 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
6539 ammo
:= GetAmmoByWeapon(FCurrWeap
);
6540 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
6541 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
6543 SetAIFlag('SELECTWEAPON', '1');
6545 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
6546 if GetAIFlag('SELECTWEAPON') = '1' then
6549 RemoveAIFlag('SELECTWEAPON');
6553 procedure TBot
.Update();
6566 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
6567 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
6569 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
6571 if g_debug_BotAIOff
= 3 then
6581 RealizeCurrentWeapon();
6588 procedure TBot
.ReleaseKey(Key
: Byte);
6597 function TBot
.KeyPressed(Key
: Word): Boolean;
6599 Result
:= FKeys
[Key
].Pressed
;
6602 function TBot
.GetAIFlag(fName
: String20
): String20
;
6608 fName
:= LowerCase(fName
);
6610 if FAIFlags
<> nil then
6611 for a
:= 0 to High(FAIFlags
) do
6612 if LowerCase(FAIFlags
[a
].Name
) = fName
then
6614 Result
:= FAIFlags
[a
].Value
;
6619 procedure TBot
.RemoveAIFlag(fName
: String20
);
6623 if FAIFlags
= nil then Exit
;
6625 fName
:= LowerCase(fName
);
6627 for a
:= 0 to High(FAIFlags
) do
6628 if LowerCase(FAIFlags
[a
].Name
) = fName
then
6630 if a
<> High(FAIFlags
) then
6631 for b
:= a
to High(FAIFlags
)-1 do
6632 FAIFlags
[b
] := FAIFlags
[b
+1];
6634 SetLength(FAIFlags
, Length(FAIFlags
)-1);
6639 procedure TBot
.SetAIFlag(fName
, fValue
: String20
);
6647 fName
:= LowerCase(fName
);
6649 if FAIFlags
<> nil then
6650 for a
:= 0 to High(FAIFlags
) do
6651 if LowerCase(FAIFlags
[a
].Name
) = fName
then
6657 if ok
then FAIFlags
[a
].Value
:= fValue
6660 SetLength(FAIFlags
, Length(FAIFlags
)+1);
6661 with FAIFlags
[High(FAIFlags
)] do
6669 procedure TBot
.UpdateMove
;
6671 procedure GoLeft(Time
: Word = 1);
6673 ReleaseKey(KEY_LEFT
);
6674 ReleaseKey(KEY_RIGHT
);
6675 PressKey(KEY_LEFT
, Time
);
6676 SetDirection(D_LEFT
);
6679 procedure GoRight(Time
: Word = 1);
6681 ReleaseKey(KEY_LEFT
);
6682 ReleaseKey(KEY_RIGHT
);
6683 PressKey(KEY_RIGHT
, Time
);
6684 SetDirection(D_RIGHT
);
6687 function Rnd(a
: Word): Boolean;
6689 Result
:= Random(a
) = 0;
6692 procedure Turn(Time
: Word = 1200);
6694 if RunDirection() = D_LEFT
then GoRight(Time
) else GoLeft(Time
);
6699 ReleaseKey(KEY_LEFT
);
6700 ReleaseKey(KEY_RIGHT
);
6703 function CanRunLeft(): Boolean;
6705 Result
:= not CollideLevel(-1, 0);
6708 function CanRunRight(): Boolean;
6710 Result
:= not CollideLevel(1, 0);
6713 function CanRun(): Boolean;
6715 if RunDirection() = D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
6718 procedure Jump(Time
: Word = 30);
6720 PressKey(KEY_JUMP
, Time
);
6723 function NearHole(): Boolean;
6727 { TODO 5 : Ëåñòíèöû }
6728 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6729 for x
:= 1 to PLAYER_RECT
.Width
do
6730 if (not StayOnStep(x
*sx
, 0)) and
6731 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6732 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6741 function BorderHole(): Boolean;
6745 { TODO 5 : Ëåñòíèöû }
6746 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6747 for x
:= 1 to PLAYER_RECT
.Width
do
6748 if (not StayOnStep(x
*sx
, 0)) and
6749 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6750 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6752 for xx
:= x
to x
+32 do
6753 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
6763 function NearDeepHole(): Boolean;
6769 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6772 for x
:= 1 to PLAYER_RECT
.Width
do
6773 if (not StayOnStep(x
*sx
, 0)) and
6774 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6775 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6777 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6779 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
6784 end else Result
:= False;
6787 function OverDeepHole(): Boolean;
6794 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6796 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
6803 function OnGround(): Boolean;
6805 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
6808 function OnLadder(): Boolean;
6810 Result
:= FullInStep(0, 0);
6813 function BelowLadder(): Boolean;
6815 Result
:= (FullInStep(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
6816 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
6817 (FullInStep(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
6818 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
6821 function BelowLiftUp(): Boolean;
6823 Result
:= ((FullInLift(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
6824 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
6825 ((FullInLift(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
6826 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
6829 function OnTopLift(): Boolean;
6831 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
6834 function CanJumpOver(): Boolean;
6838 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6842 if not CollideLevel(sx
, 0) then Exit
;
6844 for y
:= 1 to BOT_MAXJUMP
do
6845 if CollideLevel(0, -y
) then Exit
else
6846 if not CollideLevel(sx
, -y
) then
6853 function CanJumpUp(Dist
: ShortInt
): Boolean;
6860 if CollideLevel(Dist
, 0) then Exit
;
6863 for y
:= 0 to BOT_MAXJUMP
do
6864 if CollideLevel(Dist
, -y
) then
6873 for yy
:= y
+1 to BOT_MAXJUMP
do
6874 if not CollideLevel(Dist
, -yy
) then
6883 for y
:= 0 to BOT_MAXJUMP
do
6884 if CollideLevel(0, -y
) then
6892 if y
< yy
then Exit
;
6897 function IsSafeTrigger(): Boolean;
6902 if gTriggers
= nil then
6904 for a
:= 0 to High(gTriggers
) do
6905 if Collide(gTriggers
[a
].X
,
6908 gTriggers
[a
].Height
) and
6909 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
6910 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
6911 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
6912 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
6913 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
6918 // Âîçìîæíî, íàæèìàåì êíîïêó:
6919 if Rnd(16) and IsSafeTrigger() then
6922 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
6923 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
6925 ReleaseKey(KEY_LEFT
);
6926 ReleaseKey(KEY_RIGHT
);
6930 // Èäåì âëåâî, åñëè íàäî áûëî:
6931 if GetAIFlag('GOLEFT') <> '' then
6933 RemoveAIFlag('GOLEFT');
6934 if CanRunLeft() then
6938 // Èäåì âïðàâî, åñëè íàäî áûëî:
6939 if GetAIFlag('GORIGHT') <> '' then
6941 RemoveAIFlag('GORIGHT');
6942 if CanRunRight() then
6946 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
6947 if FObj
.X
< -32 then
6950 if FObj
.X
+32 > gMapInfo
.Width
then
6953 // Ïðûãàåì, åñëè íàäî áûëî:
6954 if GetAIFlag('NEEDJUMP') <> '' then
6957 RemoveAIFlag('NEEDJUMP');
6960 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
6961 if GetAIFlag('NEEDSEEUP') <> '' then
6964 ReleaseKey(KEY_DOWN
);
6965 PressKey(KEY_UP
, 20);
6966 RemoveAIFlag('NEEDSEEUP');
6969 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
6970 if GetAIFlag('NEEDSEEDOWN') <> '' then
6973 ReleaseKey(KEY_DOWN
);
6974 PressKey(KEY_DOWN
, 20);
6975 RemoveAIFlag('NEEDSEEDOWN');
6978 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
6979 if GetAIFlag('GOINHOLE') <> '' then
6980 if not OnGround() then
6982 ReleaseKey(KEY_LEFT
);
6983 ReleaseKey(KEY_RIGHT
);
6984 RemoveAIFlag('GOINHOLE');
6985 SetAIFlag('FALLINHOLE', '1');
6988 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
6989 if GetAIFlag('FALLINHOLE') <> '' then
6991 RemoveAIFlag('FALLINHOLE');
6993 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
6994 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
6995 if GetAIFlag('FALLINHOLE') = '' then
6996 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7002 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7004 CanJumpUp(IfThen(RunDirection() = D_LEFT
, -1, 1)*32) and
7008 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7009 if OnGround() and NearHole() then
7010 if NearDeepHole() then // Åñëè ýòî áåçäíà
7012 0..3: Turn(); // Áåæèì îáðàòíî
7013 4: Jump(); // Ïðûãàåì
7014 5: begin // Ïðûãàåì îáðàòíî
7019 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7020 if GetAIFlag('GOINHOLE') = '' then
7022 0: Turn(); // Íå íóæíî òóäà
7023 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7024 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7025 if BorderHole() then
7026 SetAIFlag('GOINHOLE', '1');
7029 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7030 if (not CanRun()) and OnGround() then
7032 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7033 if CanJumpOver() or OnLadder() then
7035 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7036 if Random(2) = 0 then
7038 if IsSafeTrigger() then
7044 // Îñòàëîñü ìàëî âîçäóõà:
7045 if FAir
< 36 * 2 then
7048 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7049 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7050 if BodyInAcid(0, 0) then
7054 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7056 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7057 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7060 {function TBot.NeedItem(Item: Byte): Byte;
7065 procedure TBot
.SelectWeapon(Dist
: Integer);
7069 function HaveAmmo(weapon
: Byte): Boolean;
7072 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7073 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7074 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7075 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7076 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7077 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7078 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7079 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7080 else Result
:= True;
7085 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7087 if Dist
> BOT_LONGDIST
then
7088 begin // Äàëüíèé áîé
7090 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7092 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7096 else //if Dist > BOT_UNSAFEDIST then
7097 begin // Áëèæíèé áîé
7099 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7101 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7108 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7110 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7116 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7118 Result
:= inherited PickItem(ItemType
, force
, remove
);
7120 if Result
then SetAIFlag('SELECTWEAPON', '1');
7123 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7125 Result
:= inherited Heal(value
, Soft
);
7128 function TBot
.Healthy(): Byte;
7130 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7131 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7132 else if (FHealth
> 50) then Result
:= 2
7133 else if (FHealth
> 20) then Result
:= 1
7137 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7139 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7140 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7143 procedure TBot
.OnDamage(Angle
: SmallInt
);
7151 if (Angle
= 0) or (Angle
= 180) then
7154 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7155 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7157 pla
:= g_Player_Get(FLastSpawnerUID
);
7158 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7159 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7162 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7163 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7165 mon
:= g_Monsters_Get(FLastSpawnerUID
);
7166 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7167 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7172 SetAIFlag('ATTACKLEFT', '1')
7174 SetAIFlag('ATTACKRIGHT', '1');
7178 function TBot
.RunDirection(): TDirection
;
7180 if Abs(Vel
.X
) >= 1 then
7182 if Vel
.X
> 0 then Result
:= D_RIGHT
else Result
:= D_LEFT
;
7184 Result
:= FDirection
;
7187 function TBot
.GetRnd(a
: Byte): Boolean;
7189 if a
= 0 then Result
:= False
7190 else if a
= 255 then Result
:= True
7191 else Result
:= Random(256) > 255-a
;
7194 function TBot
.GetInterval(a
: Byte; radius
: SmallInt
): SmallInt
;
7196 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7199 procedure TBot
.SaveState(var Mem
: TBinMemoryWriter
);
7205 inherited SaveState(Mem
);
7207 // Âûáðàííîå îðóæèå:
7208 Mem
.WriteByte(FSelectedWeapon
);
7210 Mem
.WriteWord(FTargetUID
);
7211 // Âðåìÿ ïîòåðè öåëè:
7212 Mem
.WriteDWORD(FLastVisible
);
7213 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7214 dw
:= Length(FAIFlags
);
7217 for i
:= 0 to Integer(dw
)-1 do
7219 Mem
.WriteString(FAIFlags
[i
].Name
, 20);
7220 Mem
.WriteString(FAIFlags
[i
].Value
, 20);
7222 // Íàñòðîéêè ñëîæíîñòè:
7224 Mem
.WriteMemory(p
, SizeOf(TDifficult
));
7227 procedure TBot
.LoadState(var Mem
: TBinMemoryReader
);
7233 inherited LoadState(Mem
);
7235 // Âûáðàííîå îðóæèå:
7236 Mem
.ReadByte(FSelectedWeapon
);
7238 Mem
.ReadWord(FTargetUID
);
7239 // Âðåìÿ ïîòåðè öåëè:
7240 Mem
.ReadDWORD(FLastVisible
);
7241 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7243 SetLength(FAIFlags
, dw
);
7245 for i
:= 0 to Integer(dw
)-1 do
7247 Mem
.ReadString(FAIFlags
[i
].Name
);
7248 Mem
.ReadString(FAIFlags
[i
].Value
);
7250 // Íàñòðîéêè ñëîæíîñòè:
7251 Mem
.ReadMemory(p
, dw
);
7252 if dw
<> SizeOf(TDifficult
) then
7254 raise EBinSizeError
.Create('TBot.LoadState: Wrong FDifficult Size');
7256 FDifficult
:= TDifficult(p
^);