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
,
56 AmmoLimits
: Array [0..1] of Array [A_BULLETS
..A_HIGH
] of Word =
57 ((200, 50, 50, 300, 100),
58 (400, 100, 100, 600, 200));
79 ANGLE_NONE
= Low(SmallInt
);
81 CORPSE_STATE_REMOVEME
= 0;
82 CORPSE_STATE_NORMAL
= 1;
83 CORPSE_STATE_MESS
= 2;
85 PLAYER_RECT
: TRectWH
= (X
:15; Y
:12; Width
:34; Height
:52);
86 PLAYER_RECT_CX
= 15+(34 div 2);
87 PLAYER_RECT_CY
= 12+(52 div 2);
88 PLAYER_CORPSERECT
: TRectWH
= (X
:15; Y
:48; Width
:34; Height
:16);
91 PLAYER_HP_LIMIT
= 200;
93 PLAYER_AP_LIMIT
= 200;
96 PLAYER1_DEF_COLOR
: TRGB
= (R
:64; G
:175; B
:48);
97 PLAYER2_DEF_COLOR
: TRGB
= (R
:96; G
:96; B
:96);
113 TPlayerStatArray
= Array of TPlayerStat
;
115 TPlayerSavedState
= record
123 Ammo
: Array [A_BULLETS
..A_HIGH
] of Word;
124 MaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
125 Weapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
126 Rulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
135 TPlayer
= class (TObject
)
143 FDirection
: TDirection
;
151 FMonsterKills
: Integer;
157 FCanJetpack
: Boolean;
163 FNextWeapDelay
: Byte; // frames
164 FBFGFireCounter
: SmallInt
;
165 FLastSpawnerUID
: Word;
169 FSpectatePlayer
: Integer;
170 FFirePainTime
: Integer;
172 FSavedState
: TPlayerSavedState
;
174 FModel
: TPlayerModel
;
177 FActionForce
: Boolean;
178 FActionChanged
: Boolean;
180 FFireAngle
: SmallInt
;
182 FShellTimer
: Integer;
184 FSawSound
: TPlayableSound
;
185 FSawSoundIdle
: TPlayableSound
;
186 FSawSoundHit
: TPlayableSound
;
187 FSawSoundSelect
: TPlayableSound
;
188 FJetSoundOn
: TPlayableSound
;
189 FJetSoundOff
: TPlayableSound
;
190 FJetSoundFly
: TPlayableSound
;
194 FJustTeleported
: Boolean;
197 function CollideLevel(XInc
, YInc
: Integer): Boolean;
198 function StayOnStep(XInc
, YInc
: Integer): Boolean;
199 function HeadInLiquid(XInc
, YInc
: Integer): Boolean;
200 function BodyInLiquid(XInc
, YInc
: Integer): Boolean;
201 function BodyInAcid(XInc
, YInc
: Integer): Boolean;
202 function FullInLift(XInc
, YInc
: Integer): Integer;
203 {procedure CollideItem();}
204 procedure FlySmoke(Times
: DWORD
= 1);
205 procedure OnFireFlame(Times
: DWORD
= 1);
206 function GetAmmoByWeapon(Weapon
: Byte): Word;
207 procedure SetAction(Action
: Byte; Force
: Boolean = False);
208 procedure OnDamage(Angle
: SmallInt
); virtual;
209 function firediry(): Integer;
211 procedure Run(Direction
: TDirection
);
212 procedure NextWeapon();
213 procedure PrevWeapon();
220 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
221 procedure resetWeaponQueue ();
222 function hasAmmoForWeapon (weapon
: Byte): Boolean;
225 FDamageBuffer
: Integer;
227 FAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
228 FMaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
229 FWeapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
230 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
232 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
233 FReloading
: Array [WP_FIRST
..WP_LAST
] of Word;
234 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
235 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
237 FPreferredTeam
: Byte;
240 FWantsInGame
: Boolean;
244 FActualModelName
: string;
251 constructor Create(); virtual;
252 destructor Destroy(); override;
253 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
254 function GetRespawnPoint(): Byte;
255 procedure PressKey(Key
: Byte; Time
: Word = 1);
256 procedure ReleaseKeys();
257 procedure SetModel(ModelName
: String);
258 procedure SetColor(Color
: TRGB
);
259 procedure SetWeapon(W
: Byte);
260 function IsKeyPressed(K
: Byte): Boolean;
261 function GetKeys(): Byte;
262 function PickItem(ItemType
: Byte; respawn
: Boolean; var remove
: Boolean): Boolean; virtual;
263 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
264 function Collide(Panel
: TPanel
): Boolean; overload
;
265 function Collide(X
, Y
: Integer): Boolean; overload
;
266 procedure SetDirection(Direction
: TDirection
);
267 procedure GetSecret();
268 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
270 procedure Push(vx
, vy
: Integer);
271 procedure ChangeModel(ModelName
: String);
272 procedure SwitchTeam
;
273 procedure ChangeTeam(Team
: Byte);
275 function GetFlag(Flag
: Byte): Boolean;
276 procedure SetFlag(Flag
: Byte);
277 function DropFlag(): Boolean;
278 procedure AllRulez(Health
: Boolean);
279 procedure RestoreHealthArmor();
280 procedure FragCombo();
281 procedure GiveItem(ItemType
: Byte);
282 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
283 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
284 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
285 procedure MakeBloodSimple(Count
: Word);
286 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
287 procedure Reset(Force
: Boolean);
288 procedure Spectate(NoMove
: Boolean = False);
289 procedure SwitchNoClip
;
290 procedure SoftReset();
291 procedure Draw(); virtual;
292 procedure DrawPain();
293 procedure DrawPickup();
294 procedure DrawRulez();
296 procedure DrawBubble();
298 procedure Update(); virtual;
299 procedure RememberState();
300 procedure RecallState();
301 procedure SaveState(var Mem
: TBinMemoryWriter
); virtual;
302 procedure LoadState(var Mem
: TBinMemoryReader
); virtual;
303 procedure PauseSounds(Enable
: Boolean);
304 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
305 procedure DoLerp(Level
: Integer = 2);
306 procedure SetLerp(XTo
, YTo
: Integer);
307 procedure QueueWeaponSwitch(Weapon
: Byte);
308 procedure RealizeCurrentWeapon();
310 procedure JetpackOff
;
311 procedure CatchFire();
313 property Name
: String read FName write FName
;
314 property Model
: TPlayerModel read FModel
;
315 property Health
: Integer read FHealth write FHealth
;
316 property Lives
: Byte read FLives write FLives
;
317 property Armor
: Integer read FArmor write FArmor
;
318 property Air
: Integer read FAir write FAir
;
319 property JetFuel
: Integer read FJetFuel write FJetFuel
;
320 property Frags
: Integer read FFrags write FFrags
;
321 property Death
: Integer read FDeath write FDeath
;
322 property Kills
: Integer read FKills write FKills
;
323 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
324 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
325 property Secrets
: Integer read FSecrets
;
326 property GodMode
: Boolean read FGodMode write FGodMode
;
327 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
328 property NoReload
: Boolean read FNoReload write FNoReload
;
329 property Live
: Boolean read FLive write FLive
;
330 property Flag
: Byte read FFlag
;
331 property Team
: Byte read FTeam write FTeam
;
332 property Direction
: TDirection read FDirection
;
333 property GameX
: Integer read FObj
.X write FObj
.X
;
334 property GameY
: Integer read FObj
.Y write FObj
.Y
;
335 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
336 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
337 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
338 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
339 property Vel
: TPoint2i read FObj
.Vel
;
340 property Obj
: TObj read FObj
;
341 property IncCam
: Integer read FIncCam write FIncCam
;
342 property UID
: Word read FUID write FUID
;
343 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
344 property NetTime
: LongWord read FNetTime write FNetTime
;
354 WeaponPrior
: Array [WP_FIRST
..WP_LAST
] of Byte;
355 CloseWeaponPrior
: Array [WP_FIRST
..WP_LAST
] of Byte;
356 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
364 TBot
= class (TPlayer
)
366 FSelectedWeapon
: Byte;
369 FAIFlags
: Array of TAIFlag
;
370 FDifficult
: TDifficult
;
372 function GetRnd(a
: Byte): Boolean;
373 function GetInterval(a
: Byte; radius
: SmallInt
): SmallInt
;
374 function RunDirection(): TDirection
;
375 function FullInStep(XInc
, YInc
: Integer): Boolean;
376 //function NeedItem(Item: Byte): Byte;
377 procedure SelectWeapon(Dist
: Integer);
378 procedure SetAIFlag(fName
, fValue
: String20
);
379 function GetAIFlag(fName
: String20
): String20
;
380 procedure RemoveAIFlag(fName
: String20
);
381 function Healthy(): Byte;
382 procedure UpdateMove();
383 procedure UpdateCombat();
384 function KeyPressed(Key
: Word): Boolean;
385 procedure ReleaseKey(Key
: Byte);
386 function TargetOnScreen(TX
, TY
: Integer): Boolean;
387 procedure OnDamage(Angle
: SmallInt
); override;
390 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
391 constructor Create(); override;
392 destructor Destroy(); override;
393 procedure Draw(); override;
394 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
395 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
396 procedure Update(); override;
397 procedure SaveState(var Mem
: TBinMemoryWriter
); override;
398 procedure LoadState(var Mem
: TBinMemoryReader
); override;
420 TCorpse
= class (TObject
)
428 FAnimation
: TAnimation
;
429 FAnimationMask
: TAnimation
;
432 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
433 destructor Destroy(); override;
434 procedure Damage(Value
: Word; vx
, vy
: Integer);
437 procedure SaveState(var Mem
: TBinMemoryWriter
);
438 procedure LoadState(var Mem
: TBinMemoryReader
);
440 property Obj
: TObj read FObj
;
441 property State
: Byte read FState
;
442 property Mess
: Boolean read FMess
;
445 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
451 gPlayers
: Array of TPlayer
;
452 gCorpses
: Array of TCorpse
;
453 gGibs
: Array of TGib
;
454 gShells
: Array of TShell
;
455 gTeamStat
: TTeamStat
;
456 gFly
: Boolean = False;
457 gAimLine
: Boolean = False;
458 gChatBubble
: Byte = 0;
462 MAX_RUNVEL
: Integer = 8;
463 VEL_JUMP
: Integer = 10;
464 SHELL_TIMEOUT
: Cardinal = 60000;
466 function Lerp(X
, Y
, Factor
: Integer): Integer;
468 procedure g_Gibs_SetMax(Count
: Word);
469 function g_Gibs_GetMax(): Word;
470 procedure g_Corpses_SetMax(Count
: Word);
471 function g_Corpses_GetMax(): Word;
472 procedure g_Shells_SetMax(Count
: Word);
473 function g_Shells_GetMax(): Word;
475 procedure g_Player_Init();
476 procedure g_Player_Free();
477 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
478 function g_Player_CreateFromState(var Mem
: TBinMemoryReader
): Word;
479 procedure g_Player_Remove(UID
: Word);
480 procedure g_Player_ResetTeams();
481 procedure g_Player_UpdateAll();
482 procedure g_Player_DrawAll();
483 procedure g_Player_DrawDebug(p
: TPlayer
);
484 procedure g_Player_DrawHealth();
485 procedure g_Player_RememberAll();
486 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
487 function g_Player_Get(UID
: Word): TPlayer
;
488 function g_Player_GetCount(): Byte;
489 function g_Player_GetStats(): TPlayerStatArray
;
490 function g_Player_ValidName(Name
: String): Boolean;
491 procedure g_Player_CreateCorpse(Player
: TPlayer
);
492 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
493 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
494 procedure g_Player_UpdatePhysicalObjects();
495 procedure g_Player_DrawCorpses();
496 procedure g_Player_DrawShells();
497 procedure g_Player_RemoveAllCorpses();
498 procedure g_Player_Corpses_SaveState(var Mem
: TBinMemoryWriter
);
499 procedure g_Player_Corpses_LoadState(var Mem
: TBinMemoryReader
);
500 procedure g_Bot_Add(Team
, Difficult
: Byte);
501 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString
; num
: Integer = -1);
502 procedure g_Bot_MixNames();
503 procedure g_Bot_RemoveAll();
508 e_log
, g_map
, g_items
, g_console
, SysUtils
, g_gfx
, Math
,
509 g_options
, g_triggers
, g_menu
, MAPDEF
, g_game
,
510 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
, g_net
, g_netmsg
;
520 diag_precision
: Byte;
524 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
525 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
526 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
530 TIME_RESPAWN1
= 1500;
531 TIME_RESPAWN2
= 2000;
532 TIME_RESPAWN3
= 3000;
535 JET_MAX
= 540; // ~30 sec
536 PLAYER_SUIT_TIME
= 30000;
537 PLAYER_INVUL_TIME
= 30000;
538 PLAYER_INVIS_TIME
= 35000;
539 FRAG_COMBO_TIME
= 3000;
543 ANGLE_RIGHTDOWN
= -35;
545 ANGLE_LEFTDOWN
= -145;
546 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
547 WEAPONPOINT
: Array [TDirection
] of TPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
550 BOT_UNSAFEDIST
= 128;
551 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
553 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
554 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
555 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
556 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
557 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
558 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
559 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
560 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
561 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
562 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
563 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
564 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
565 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
566 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
567 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
568 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
569 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
570 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
571 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
572 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
573 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
574 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
575 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
576 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
577 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
578 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 0);
580 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
581 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
583 BOTNAMES_FILENAME
= 'botnames.txt';
584 BOTLIST_FILENAME
= 'botlist.txt';
588 MaxCorpses
: Word = 20;
589 MaxShells
: Word = 300;
590 CurrentGib
: Integer = 0;
591 CurrentShell
: Integer = 0;
592 BotNames
: Array of String;
593 BotList
: Array of TBotProfile
;
595 function Lerp(X
, Y
, Factor
: Integer): Integer;
597 Result
:= X
+ ((Y
- X
) div Factor
);
600 function SameTeam(UID1
, UID2
: Word): Boolean;
604 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
605 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
607 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
609 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
610 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
612 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
615 procedure g_Gibs_SetMax(Count
: Word);
618 SetLength(gGibs
, Count
);
620 if CurrentGib
>= Count
then
624 function g_Gibs_GetMax(): Word;
629 procedure g_Shells_SetMax(Count
: Word);
632 SetLength(gShells
, Count
);
634 if CurrentShell
>= Count
then
638 function g_Shells_GetMax(): Word;
644 procedure g_Corpses_SetMax(Count
: Word);
647 SetLength(gCorpses
, Count
);
650 function g_Corpses_GetMax(): Word;
652 Result
:= MaxCorpses
;
655 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
665 // Åñòü ëè ìåñòî â gPlayers:
666 if gPlayers
<> nil then
667 for a
:= 0 to High(gPlayers
) do
668 if gPlayers
[a
] = nil then
674 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
677 SetLength(gPlayers
, Length(gPlayers
)+1);
681 // Ñîçäàåì îáúåêò èãðîêà:
683 gPlayers
[a
] := TBot
.Create()
685 gPlayers
[a
] := TPlayer
.Create();
688 gPlayers
[a
].FActualModelName
:= ModelName
;
689 gPlayers
[a
].SetModel(ModelName
);
691 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
692 if gPlayers
[a
].FModel
= nil then
696 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
700 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
701 if Random(2) = 0 then
705 gPlayers
[a
].FPreferredTeam
:= Team
;
707 case gGameSettings
.GameMode
of
708 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
710 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
712 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
715 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
716 gPlayers
[a
].FColor
:= Color
;
717 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
718 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
720 gPlayers
[a
].FModel
.Color
:= Color
;
722 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
723 gPlayers
[a
].FLive
:= False;
725 Result
:= gPlayers
[a
].FUID
;
728 function g_Player_CreateFromState(var Mem
: TBinMemoryReader
): Word;
741 if sig
<> PLAYER_SIGNATURE
then // 'PLYR'
743 raise EBinSizeError
.Create('g_Player_CreateFromState: Wrong Player Signature');
747 Mem
.ReadBoolean(Bot
);
752 // Åñòü ëè ìåñòî â gPlayers:
753 if gPlayers
<> nil then
754 for a
:= 0 to High(gPlayers
) do
755 if gPlayers
[a
] = nil then
761 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
764 SetLength(gPlayers
, Length(gPlayers
)+1);
768 // Ñîçäàåì îáúåêò èãðîêà:
770 gPlayers
[a
] := TBot
.Create()
772 gPlayers
[a
] := TPlayer
.Create();
773 gPlayers
[a
].FIamBot
:= Bot
;
774 gPlayers
[a
].FPhysics
:= True;
777 Mem
.ReadWord(gPlayers
[a
].FUID
);
779 Mem
.ReadString(gPlayers
[a
].FName
);
781 Mem
.ReadByte(gPlayers
[a
].FTeam
);
782 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
784 Mem
.ReadBoolean(gPlayers
[a
].FLive
);
785 // Èçðàñõîäîâàë ëè âñå æèçíè:
786 Mem
.ReadBoolean(gPlayers
[a
].FNoRespawn
);
790 gPlayers
[a
].FDirection
:= D_LEFT
792 gPlayers
[a
].FDirection
:= D_RIGHT
;
794 Mem
.ReadInt(gPlayers
[a
].FHealth
);
796 Mem
.ReadByte(gPlayers
[a
].FLives
);
798 Mem
.ReadInt(gPlayers
[a
].FArmor
);
800 Mem
.ReadInt(gPlayers
[a
].FAir
);
802 Mem
.ReadInt(gPlayers
[a
].FJetFuel
);
804 Mem
.ReadInt(gPlayers
[a
].FPain
);
806 Mem
.ReadInt(gPlayers
[a
].FKills
);
808 Mem
.ReadInt(gPlayers
[a
].FMonsterKills
);
810 Mem
.ReadInt(gPlayers
[a
].FFrags
);
812 Mem
.ReadByte(gPlayers
[a
].FFragCombo
);
813 // Âðåìÿ ïîñëåäíåãî ôðàãà:
814 Mem
.ReadDWORD(gPlayers
[a
].FLastFrag
);
816 Mem
.ReadInt(gPlayers
[a
].FDeath
);
818 Mem
.ReadByte(gPlayers
[a
].FFlag
);
820 Mem
.ReadInt(gPlayers
[a
].FSecrets
);
822 Mem
.ReadByte(gPlayers
[a
].FCurrWeap
);
823 // Ñëåäóþùåå æåëàåìîå îðóæèå:
824 Mem
.ReadWord(gPlayers
[a
].FNextWeap
);
826 Mem
.ReadByte(gPlayers
[a
].FNextWeapDelay
);
827 // Âðåìÿ çàðÿäêè BFG:
828 Mem
.ReadSmallInt(gPlayers
[a
].FBFGFireCounter
);
830 Mem
.ReadInt(gPlayers
[a
].FDamageBuffer
);
831 // Ïîñëåäíèé óäàðèâøèé:
832 Mem
.ReadWord(gPlayers
[a
].FLastSpawnerUID
);
833 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
834 Mem
.ReadByte(gPlayers
[a
].FLastHit
);
836 Obj_LoadState(@gPlayers
[a
].FObj
, Mem
);
837 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
838 for i
:= A_BULLETS
to A_HIGH
do
839 Mem
.ReadWord(gPlayers
[a
].FAmmo
[i
]);
840 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
841 for i
:= A_BULLETS
to A_HIGH
do
842 Mem
.ReadWord(gPlayers
[a
].FMaxAmmo
[i
]);
844 for i
:= WP_FIRST
to WP_LAST
do
845 Mem
.ReadBoolean(gPlayers
[a
].FWeapon
[i
]);
846 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
847 for i
:= WP_FIRST
to WP_LAST
do
848 Mem
.ReadWord(gPlayers
[a
].FReloading
[i
]);
852 Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
853 // Íàëè÷èå êðàñíîãî êëþ÷à:
856 Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
857 // Íàëè÷èå çåëåíîãî êëþ÷à:
860 Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
861 // Íàëè÷èå ñèíåãî êëþ÷à:
864 Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
868 Include(gPlayers
[a
].FRulez
, R_BERSERK
);
869 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
870 for i
:= MR_SUIT
to MR_MAX
do
871 Mem
.ReadDWORD(gPlayers
[a
].FMegaRulez
[i
]);
872 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
873 for i
:= T_RESPAWN
to T_FLAGCAP
do
874 Mem
.ReadDWORD(gPlayers
[a
].FTime
[i
]);
877 Mem
.ReadString(gPlayers
[a
].FActualModelName
);
879 Mem
.ReadByte(gPlayers
[a
].FColor
.R
);
880 Mem
.ReadByte(gPlayers
[a
].FColor
.G
);
881 Mem
.ReadByte(gPlayers
[a
].FColor
.B
);
882 // Îáíîâëÿåì ìîäåëü èãðîêà:
883 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
885 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
886 if gPlayers
[a
].FModel
= nil then
890 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
894 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
895 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
896 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
898 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
900 Result
:= gPlayers
[a
].FUID
;
903 procedure g_Player_ResetTeams();
907 if g_Game_IsClient
then
909 if gPlayers
= nil then
911 for a
:= Low(gPlayers
) to High(gPlayers
) do
912 if gPlayers
[a
] <> nil then
913 case gGameSettings
.GameMode
of
915 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
917 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
918 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
919 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
922 gPlayers
[a
].ChangeTeam(TEAM_RED
)
924 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
927 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
931 procedure g_Bot_Add(Team
, Difficult
: Byte);
934 _name
, _model
: String;
937 if not g_Game_IsServer
then Exit
;
939 // Ñïèñîê íàçâàíèé ìîäåëåé:
940 m
:= g_PlayerModel_GetNames();
945 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
946 Team
:= TEAM_COOP
// COOP
948 if gGameSettings
.GameMode
= GM_DM
then
949 Team
:= TEAM_NONE
// DM
951 if Team
= TEAM_NONE
then // CTF / TDM
953 // Àâòîáàëàíñ êîìàíä:
957 for a
:= 0 to High(gPlayers
) do
958 if gPlayers
[a
] <> nil then
960 if gPlayers
[a
].Team
= TEAM_RED
then
963 if gPlayers
[a
].Team
= TEAM_BLUE
then
973 if Random(2) = 0 then
979 // Âûáèðàåì áîòó èìÿ:
981 if BotNames
<> nil then
982 for a
:= 0 to High(BotNames
) do
983 if g_Player_ValidName(BotNames
[a
]) then
985 _name
:= BotNames
[a
];
989 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
992 _name
:= Format('DFBOT%.2d', [Random(100)]);
993 until g_Player_ValidName(_name
);
995 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
996 _model
:= m
[Random(Length(m
))];
999 with g_Player_Get(g_Player_Create(_model
,
1000 _RGB(Min(Random(9)*32, 255),
1001 Min(Random(9)*32, 255),
1002 Min(Random(9)*32, 255)),
1003 Team
, True)) as TBot
do
1008 1: FDifficult
:= DIFFICULT_EASY
;
1009 2: FDifficult
:= DIFFICULT_MEDIUM
;
1010 else FDifficult
:= DIFFICULT_HARD
;
1013 for a
:= WP_FIRST
to WP_LAST
do
1015 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1016 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1017 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1020 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1022 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1023 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1028 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString
; num
: Integer = -1);
1031 _name
, _model
: String;
1034 if not g_Game_IsServer
then Exit
;
1036 // Ñïèñîê íàçâàíèé ìîäåëåé:
1037 m
:= g_PlayerModel_GetNames();
1042 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1043 Team
:= TEAM_COOP
// COOP
1045 if gGameSettings
.GameMode
= GM_DM
then
1046 Team
:= TEAM_NONE
// DM
1048 if Team
= TEAM_NONE
then
1049 Team
:= BotList
[num
].team
; // CTF / TDM
1051 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1052 lName
:= AnsiLowerCase(lName
);
1053 if (num
< 0) or (num
> Length(BotList
)-1) then
1055 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1056 for a
:= 0 to High(BotList
) do
1057 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1066 _name
:= BotList
[num
].name
;
1067 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1068 if not g_Player_ValidName(_name
) then
1070 _name
:= Format('DFBOT%.2d', [Random(100)]);
1071 until g_Player_ValidName(_name
);
1074 _model
:= BotList
[num
].model
;
1075 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1076 if not InSArray(_model
, m
) then
1077 _model
:= m
[Random(Length(m
))];
1080 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1084 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1085 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1086 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1087 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1088 FDifficult
.Cover
:= BotList
[num
].cover
;
1089 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1091 for a
:= WP_FIRST
to WP_LAST
do
1093 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1094 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1095 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1098 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1100 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1104 procedure g_Bot_RemoveAll();
1108 if not g_Game_IsServer
then Exit
;
1109 if gPlayers
= nil then Exit
;
1111 for a
:= 0 to High(gPlayers
) do
1112 if gPlayers
[a
] <> nil then
1113 if gPlayers
[a
] is TBot
then
1115 gPlayers
[a
].Lives
:= 0;
1116 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1117 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1118 g_Player_Remove(gPlayers
[a
].FUID
);
1124 procedure g_Bot_MixNames();
1129 if BotNames
<> nil then
1130 for a
:= 0 to High(BotNames
) do
1132 b
:= Random(Length(BotNames
));
1134 Botnames
[a
] := BotNames
[b
];
1139 procedure g_Player_Remove(UID
: Word);
1143 if gPlayers
= nil then Exit
;
1145 if g_Game_IsServer
and g_Game_IsNet
then
1146 MH_SEND_PlayerDelete(UID
);
1148 for i
:= 0 to High(gPlayers
) do
1149 if gPlayers
[i
] <> nil then
1150 if gPlayers
[i
].FUID
= UID
then
1152 if gPlayers
[i
] is TPlayer
then
1153 TPlayer(gPlayers
[i
]).Free()
1155 TBot(gPlayers
[i
]).Free();
1161 procedure g_Player_Init();
1171 if not FileExists(DataDir
+ BOTNAMES_FILENAME
) then
1174 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1175 AssignFile(F
, DataDir
+ BOTNAMES_FILENAME
);
1186 SetLength(BotNames
, Length(BotNames
)+1);
1187 BotNames
[High(BotNames
)] := s
;
1195 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1196 config
:= TConfig
.CreateFile(DataDir
+ BOTLIST_FILENAME
);
1200 while config
.SectionExists(IntToStr(a
)) do
1202 SetLength(BotList
, Length(BotList
)+1);
1204 with BotList
[High(BotList
)] do
1207 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1209 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1211 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1216 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1217 color
.R
:= StrToIntDef(sa
[0], 0);
1218 color
.G
:= StrToIntDef(sa
[1], 0);
1219 color
.B
:= StrToIntDef(sa
[2], 0);
1220 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1221 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1222 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1223 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1224 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1225 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1226 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1227 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1228 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1229 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1230 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1231 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1232 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1233 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1234 if Length(sa
) = 10 then
1236 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1237 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1238 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1239 if Length(sa
) = 10 then
1241 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1243 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1244 if Length(sa) = 10 then
1246 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1255 procedure g_Player_Free();
1259 if gPlayers
<> nil then
1261 for i
:= 0 to High(gPlayers
) do
1262 if gPlayers
[i
] <> nil then
1264 if gPlayers
[i
] is TPlayer
then
1265 TPlayer(gPlayers
[i
]).Free()
1267 TBot(gPlayers
[i
]).Free();
1278 procedure g_Player_UpdateAll();
1282 if gPlayers
= nil then Exit
;
1284 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1285 for i
:= 0 to High(gPlayers
) do
1287 if gPlayers
[i
] <> nil then
1289 if gPlayers
[i
] is TPlayer
then
1291 gPlayers
[i
].Update();
1292 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1296 // bot updates weapons in `UpdateCombat()`
1297 TBot(gPlayers
[i
]).Update();
1301 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1304 procedure g_Player_DrawAll();
1308 if gPlayers
= nil then Exit
;
1310 for i
:= 0 to High(gPlayers
) do
1311 if gPlayers
[i
] <> nil then
1312 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1313 else TBot(gPlayers
[i
]).Draw();
1316 procedure g_Player_DrawDebug(p
: TPlayer
);
1320 if p
= nil then Exit
;
1321 if (@p
.FObj
) = nil then Exit
;
1323 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1325 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1326 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1327 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1328 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1329 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1330 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1333 procedure g_Player_DrawHealth();
1338 if gPlayers
= nil then Exit
;
1339 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1341 for i
:= 0 to High(gPlayers
) do
1342 if gPlayers
[i
] <> nil then
1344 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1345 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1346 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1347 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1348 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1349 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1353 function g_Player_Get(UID
: Word): TPlayer
;
1359 if gPlayers
= nil then
1362 for a
:= 0 to High(gPlayers
) do
1363 if gPlayers
[a
] <> nil then
1364 if gPlayers
[a
].FUID
= UID
then
1366 Result
:= gPlayers
[a
];
1371 function g_Player_GetCount(): Byte;
1377 if gPlayers
= nil then
1380 for a
:= 0 to High(gPlayers
) do
1381 if gPlayers
[a
] <> nil then
1382 Result
:= Result
+ 1;
1385 function g_Player_GetStats(): TPlayerStatArray
;
1391 if gPlayers
= nil then Exit
;
1393 for a
:= 0 to High(gPlayers
) do
1394 if gPlayers
[a
] <> nil then
1396 SetLength(Result
, Length(Result
)+1);
1397 with Result
[High(Result
)] do
1399 Ping
:= gPlayers
[a
].FPing
;
1400 Loss
:= gPlayers
[a
].FLoss
;
1401 Name
:= gPlayers
[a
].FName
;
1402 Team
:= gPlayers
[a
].FTeam
;
1403 Frags
:= gPlayers
[a
].FFrags
;
1404 Deaths
:= gPlayers
[a
].FDeath
;
1405 Kills
:= gPlayers
[a
].FKills
;
1406 Color
:= gPlayers
[a
].FModel
.Color
;
1407 Lives
:= gPlayers
[a
].FLives
;
1408 Spectator
:= gPlayers
[a
].FSpectator
;
1413 procedure g_Player_RememberAll
;
1417 for i
:= Low(gPlayers
) to High(gPlayers
) do
1418 if (gPlayers
[i
] <> nil) and gPlayers
[i
].Live
then
1419 gPlayers
[i
].RememberState
;
1422 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1426 gTeamStat
[TEAM_RED
].Goals
:= 0;
1427 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1429 if gPlayers
<> nil then
1430 for i
:= 0 to High(gPlayers
) do
1431 if gPlayers
[i
] <> nil then
1433 gPlayers
[i
].Reset(Force
);
1435 if gPlayers
[i
] is TPlayer
then
1437 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1438 gPlayers
[i
].Respawn(Silent
)
1440 gPlayers
[i
].Spectate();
1443 TBot(gPlayers
[i
]).Respawn(Silent
);
1447 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1454 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1459 if (FHealth
>= -50) or (gGibsCount
= 0) then
1461 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1465 for find_id
:= 0 to High(gCorpses
) do
1466 if gCorpses
[find_id
] = nil then
1473 find_id
:= Random(Length(gCorpses
));
1475 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1476 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1477 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1478 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1481 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1482 FObj
.Y
+ PLAYER_RECT_CY
,
1483 FModel
.Name
, FModel
.Color
);
1487 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1491 if (gShells
= nil) or (Length(gShells
) = 0) then
1494 with gShells
[CurrentShell
] do
1500 if T
= SHELL_BULLET
then
1502 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1506 Obj
.Rect
.Width
:= 4;
1507 Obj
.Rect
.Height
:= 2;
1511 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1515 Obj
.Rect
.Width
:= 7;
1516 Obj
.Rect
.Height
:= 3;
1522 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1523 RAngle
:= Random(360);
1524 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1526 if CurrentShell
>= High(gShells
) then
1533 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1536 GibsArray
: TGibsArray
;
1538 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1540 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1543 for a
:= 0 to High(GibsArray
) do
1544 with gGibs
[CurrentGib
] do
1547 ID
:= GibsArray
[a
].ID
;
1548 MaskID
:= GibsArray
[a
].MaskID
;
1551 Obj
.Rect
:= GibsArray
[a
].Rect
;
1552 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1553 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1554 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1555 RAngle
:= Random(360);
1557 if gBloodCount
> 0 then
1558 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1559 Random(48), Random(48), 150, 0, 0);
1561 if CurrentGib
>= High(gGibs
) then
1568 procedure g_Player_UpdatePhysicalObjects();
1574 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1579 if T
= SHELL_BULLET
then
1580 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1582 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1587 if gGibs
<> nil then
1588 for i
:= 0 to High(gGibs
) do
1589 if gGibs
[i
].Live
then
1593 mr
:= g_Obj_Move(@Obj
, True, False, True);
1595 if WordBool(mr
and MOVE_FALLOUT
) then
1601 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1602 if WordBool(mr
and MOVE_HITWALL
) then
1603 Obj
.Vel
.X
:= -(vel
.X
div 2);
1604 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1605 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1607 if (Obj
.Vel
.X
>= 0) then
1609 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1610 if RAngle
>= 360 then
1611 RAngle
:= RAngle
mod 360;
1612 end else begin // Counter-clockwise
1613 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1615 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1618 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1619 if gTime
mod (GAME_TICK
*3) = 0 then
1620 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1624 if gCorpses
<> nil then
1625 for i
:= 0 to High(gCorpses
) do
1626 if gCorpses
[i
] <> nil then
1627 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1633 gCorpses
[i
].Update();
1636 if gShells
<> nil then
1637 for i
:= 0 to High(gShells
) do
1638 if gShells
[i
].Live
then
1642 mr
:= g_Obj_Move(@Obj
, True, False, True);
1644 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1650 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1651 if WordBool(mr
and MOVE_HITWALL
) then
1653 Obj
.Vel
.X
:= -(vel
.X
div 2);
1654 if not WordBool(mr
and MOVE_INWATER
) then
1655 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1657 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1659 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1660 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1661 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1663 if RAngle
mod 90 <> 0 then
1664 RAngle
:= (RAngle
div 90) * 90;
1666 else if not WordBool(mr
and MOVE_INWATER
) then
1667 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1670 if (Obj
.Vel
.X
>= 0) then
1672 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1673 if RAngle
>= 360 then
1674 RAngle
:= RAngle
mod 360;
1675 end else begin // Counter-clockwise
1676 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1678 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1683 procedure g_Player_DrawCorpses();
1688 if gGibs
<> nil then
1689 for i
:= 0 to High(gGibs
) do
1690 if gGibs
[i
].Live
then
1693 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1696 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1697 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1699 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1702 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1708 if gCorpses
<> nil then
1709 for i
:= 0 to High(gCorpses
) do
1710 if gCorpses
[i
] <> nil then
1714 procedure g_Player_DrawShells();
1719 if gShells
<> nil then
1720 for i
:= 0 to High(gShells
) do
1721 if gShells
[i
].Live
then
1724 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1730 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1734 procedure g_Player_RemoveAllCorpses();
1740 SetLength(gGibs
, MaxGibs
);
1741 SetLength(gShells
, MaxGibs
);
1745 if gCorpses
<> nil then
1746 for i
:= 0 to High(gCorpses
) do
1750 SetLength(gCorpses
, MaxCorpses
);
1753 procedure g_Player_Corpses_SaveState(var Mem
: TBinMemoryWriter
);
1758 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ:
1760 if gCorpses
<> nil then
1761 for i
:= 0 to High(gCorpses
) do
1762 if gCorpses
[i
] <> nil then
1765 Mem
:= TBinMemoryWriter
.Create((count
+1) * 128);
1767 // Êîëè÷åñòâî òðóïîâ:
1768 Mem
.WriteInt(count
);
1774 for i
:= 0 to High(gCorpses
) do
1775 if gCorpses
[i
] <> nil then
1778 Mem
.WriteString(gCorpses
[i
].FModelName
);
1780 b
:= gCorpses
[i
].Mess
;
1781 Mem
.WriteBoolean(b
);
1782 // Ñîõðàíÿåì äàííûå òðóïà:
1783 gCorpses
[i
].SaveState(Mem
);
1787 procedure g_Player_Corpses_LoadState(var Mem
: TBinMemoryReader
);
1796 g_Player_RemoveAllCorpses();
1798 // Êîëè÷åñòâî òðóïîâ:
1801 if count
> Length(gCorpses
) then
1803 raise EBinSizeError
.Create('g_Player_Corpses_LoadState: Too Many Corpses');
1810 for i
:= 0 to count
-1 do
1813 Mem
.ReadString(str
);
1817 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1818 // Çàãðóæàåì äàííûå òðóïà:
1819 gCorpses
[i
].LoadState(Mem
);
1825 procedure TPlayer
.BFGHit();
1827 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1828 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1829 if g_Game_IsServer
and g_Game_IsNet
then
1830 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1831 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1835 procedure TPlayer
.ChangeModel(ModelName
: string);
1837 Model
: TPlayerModel
;
1839 Model
:= g_PlayerModel_Get(ModelName
);
1840 if Model
= nil then Exit
;
1846 procedure TPlayer
.SetModel(ModelName
: string);
1850 m
:= g_PlayerModel_Get(ModelName
);
1853 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1854 m
:= g_PlayerModel_Get('doomer');
1857 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1862 if FModel
<> nil then
1867 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1868 FModel
.Color
:= FColor
1870 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1871 FModel
.SetWeapon(FCurrWeap
);
1872 FModel
.SetFlag(FFlag
);
1873 SetDirection(FDirection
);
1876 procedure TPlayer
.SetColor(Color
: TRGB
);
1879 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1880 if FModel
<> nil then FModel
.Color
:= Color
;
1883 procedure TPlayer
.SwitchTeam
;
1885 if g_Game_IsClient
then
1887 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
1889 if gGameOn
and FLive
then
1890 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
1892 if FTeam
= TEAM_RED
then
1894 ChangeTeam(TEAM_BLUE
);
1895 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
1896 if g_Game_IsNet
then
1897 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
1901 ChangeTeam(TEAM_RED
);
1902 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
1903 if g_Game_IsNet
then
1904 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
1906 FPreferredTeam
:= FTeam
;
1909 procedure TPlayer
.ChangeTeam(Team
: Byte);
1916 TEAM_RED
, TEAM_BLUE
:
1917 FModel
.Color
:= TEAMCOLOR
[Team
];
1919 FModel
.Color
:= FColor
;
1921 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
1922 MH_SEND_PlayerStats(FUID
);
1926 procedure TPlayer.CollideItem();
1931 if gItems = nil then Exit;
1932 if not FLive then Exit;
1934 for i := 0 to High(gItems) do
1937 if (ItemType <> ITEM_NONE) and Live then
1938 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
1939 PLAYER_RECT.Height, @Obj) then
1941 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
1943 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
1944 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
1945 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
1946 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
1947 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
1949 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
1950 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
1951 (gGameSettings.GameType = GT_SINGLE) and
1952 (g_Player_GetCount() > 1)) then
1953 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
1959 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
1961 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
1962 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
1966 constructor TPlayer
.Create();
1972 FSawSound
:= TPlayableSound
.Create();
1973 FSawSoundIdle
:= TPlayableSound
.Create();
1974 FSawSoundHit
:= TPlayableSound
.Create();
1975 FSawSoundSelect
:= TPlayableSound
.Create();
1976 FJetSoundFly
:= TPlayableSound
.Create();
1977 FJetSoundOn
:= TPlayableSound
.Create();
1978 FJetSoundOff
:= TPlayableSound
.Create();
1980 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
1981 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
1982 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
1983 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
1984 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
1985 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
1986 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
1988 FSpectatePlayer
:= -1;
1992 FSavedState
.WaitRecall
:= False;
1997 FActualModelName
:= 'doomer';
2000 FObj
.Rect
:= PLAYER_RECT
;
2002 FBFGFireCounter
:= -1;
2003 FJustTeleported
:= False;
2009 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2013 if (not g_Game_IsClient
) and (not FLive
) then
2018 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2019 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2021 if not g_Game_IsClient
then
2024 if t
= HIT_TRAP
then
2026 // Ëîâóøêà óáèâàåò ñðàçó:
2028 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2030 if t
= HIT_SELF
then
2034 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2037 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2038 FMegaRulez
[MR_SUIT
] := 0;
2039 FMegaRulez
[MR_INVUL
] := 0;
2040 FMegaRulez
[MR_INVIS
] := 0;
2044 // Íî îò îñòàëüíîãî ñïàñàåò:
2045 if FMegaRulez
[MR_INVUL
] >= gTime
then
2052 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2053 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2054 (SpawnerUID
= FUID
) or
2055 (not SameTeam(FUID
, SpawnerUID
)) then
2057 FLastSpawnerUID
:= SpawnerUID
;
2059 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2060 if gBloodCount
> 0 then
2062 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2063 if value
div 4 <= c
then
2064 c
:= c
- (value
div 4)
2068 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2072 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2073 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2076 if t
= HIT_WATER
then
2077 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2078 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2083 Inc(FDamageBuffer
, value
);
2087 FPain
:= FPain
+ value
;
2090 if g_Game_IsServer
and g_Game_IsNet
then
2092 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2093 MH_SEND_PlayerStats(FUID
);
2094 MH_SEND_PlayerPos(False, FUID
);
2098 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2101 if g_Game_IsClient
then
2106 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2108 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2111 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2113 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2117 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2118 MH_SEND_PlayerStats(FUID
);
2121 destructor TPlayer
.Destroy();
2123 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2125 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2129 FSawSoundIdle
.Free();
2130 FSawSoundHit
.Free();
2131 FJetSoundFly
.Free();
2133 FJetSoundOff
.Free();
2139 procedure TPlayer
.DrawBubble();
2141 bubX
, bubY
: Integer;
2144 Rw
, Gw
, Bw
: SmallInt
;
2147 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= D_LEFT
, -4, 18);
2148 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2156 1: // simple textual non-bubble
2158 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2159 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2160 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2163 2: // advanced pixel-perfect bubble
2165 if FTeam
= TEAM_RED
then
2168 if FTeam
= TEAM_BLUE
then
2171 3: // colored bubble
2173 Rb
:= FModel
.Color
.R
;
2174 Gb
:= FModel
.Color
.G
;
2175 Bb
:= FModel
.Color
.B
;
2176 Rw
:= Min(Rb
* 2 + 64, 255);
2177 Gw
:= Min(Gb
* 2 + 64, 255);
2178 Bw
:= Min(Bb
* 2 + 64, 255);
2179 if (Abs(Rw
- Rb
) < 32)
2180 or (Abs(Gw
- Gb
) < 32)
2181 or (Abs(Bw
- Bb
) < 32) then
2183 Rb
:= Max(Rw
div 2 - 16, 0);
2184 Gb
:= Max(Gw
div 2 - 16, 0);
2185 Bb
:= Max(Bw
div 2 - 16, 0);
2188 4: // custom textured bubble
2190 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2191 if FDirection
= D_RIGHT
then
2192 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2194 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, M_HORIZONTAL
);
2200 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2201 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2203 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2206 Dot
:= IfThen(FDirection
= D_LEFT
, 14, 5);
2207 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2208 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
);
2209 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
);
2210 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
);
2211 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
);
2215 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2216 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2217 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2220 procedure TPlayer
.Draw();
2228 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2229 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2231 e_GetTextureSize(ID
, @w
, @h
);
2232 if FDirection
= D_LEFT
then
2233 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2234 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7, 0, True, False)
2236 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2237 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7, 0, True, False);
2240 if FMegaRulez
[MR_INVIS
] > gTime
then
2242 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2243 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2245 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2246 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2250 FModel
.Draw(FObj
.X
, FObj
.Y
, 200)
2252 FModel
.Draw(FObj
.X
, FObj
.Y
);
2255 FModel
.Draw(FObj
.X
, FObj
.Y
, 254);
2258 FModel
.Draw(FObj
.X
, FObj
.Y
);
2261 if g_debug_Frames
then
2263 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2265 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2266 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2270 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2272 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2273 if gAimLine
and Live
and
2274 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2278 procedure TPlayer
.DrawAim();
2280 wx
, wy
, xx
, yy
: Integer;
2284 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= D_LEFT
, 7, -7);
2285 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2294 1: begin // Chainsaw
2301 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2302 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2303 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2304 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2309 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2310 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2311 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2312 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2314 4: begin // Double Shotgun
2317 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2318 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2319 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2320 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2322 5: begin // Chaingun
2325 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2326 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2327 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2328 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2330 6: begin // Rocket Launcher
2333 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2334 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2335 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2336 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2338 7: begin // Plasmagun
2341 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2342 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2343 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2344 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2349 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2350 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2351 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2352 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2354 9: begin // Super Chaingun
2357 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2358 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2359 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2360 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2363 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2364 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2365 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2368 procedure TPlayer
.DrawGUI();
2371 X
, Y
, SY
, a
, p
, m
: Integer;
2375 stat
: TPlayerStatArray
;
2377 X
:= gPlayerScreenSize
.X
;
2378 SY
:= gPlayerScreenSize
.Y
;
2381 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2383 if gGameSettings
.GameMode
= GM_CTF
then
2387 if gGameSettings
.GameMode
= GM_CTF
then
2389 s
:= 'TEXTURE_PLAYER_REDFLAG';
2390 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2391 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2392 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2393 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2394 if g_Texture_Get(s
, ID
) then
2395 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2398 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2399 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2400 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2402 if gGameSettings
.GameMode
= GM_CTF
then
2404 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2405 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2406 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2407 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2408 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2409 if g_Texture_Get(s
, ID
) then
2410 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2413 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2414 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2415 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2418 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2419 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2422 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2423 e_Draw(ID
, X
+2, Y
, 0, True, False);
2425 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2429 s
:= IntToStr(Frags
);
2430 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2431 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2436 stat
:= g_Player_GetStats();
2441 for a
:= 0 to High(stat
) do
2442 if stat
[a
].Name
<> Name
then
2444 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2445 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2449 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2450 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2451 s
:= s
+IntToStr(Abs(Frags
-m
));
2453 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2454 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2457 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2459 s
:= IntToStr(Lives
);
2460 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2461 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2465 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2466 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2468 if R_BERSERK
in FRulez
then
2469 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2471 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2473 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2474 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2476 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2477 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2478 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2480 s
:= IntToStr(FArmor
);
2481 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2482 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2484 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2490 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2495 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2497 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2498 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2499 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2500 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2501 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2502 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2503 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2504 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2505 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2508 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2509 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2510 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2512 if R_KEY_RED
in FRulez
then
2513 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2515 if R_KEY_GREEN
in FRulez
then
2516 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2518 if R_KEY_BLUE
in FRulez
then
2519 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2521 if FJetFuel
> 0 then
2523 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2524 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2525 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2526 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2527 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2528 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2532 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2533 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2534 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2537 if gShowPing
and g_Game_IsClient
then
2539 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2540 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2546 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2547 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2548 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2551 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2552 s
:= _lc
[I_PLAYER_SPECT4
];
2553 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2554 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2555 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2561 procedure TPlayer
.DrawRulez();
2565 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2566 if FMegaRulez
[MR_INVUL
] >= gTime
then
2568 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2569 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2574 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2575 191, 191, 191, 0, B_INVERT
);
2578 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2579 if FMegaRulez
[MR_SUIT
] >= gTime
then
2581 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2582 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2587 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2588 0, 96, 0, 200, B_NONE
);
2591 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2592 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2594 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2595 255, 0, 0, 200, B_NONE
);
2599 procedure TPlayer
.DrawPain();
2603 if FPain
= 0 then Exit
;
2607 if a
< 15 then h
:= 0
2608 else if a
< 35 then h
:= 1
2609 else if a
< 55 then h
:= 2
2610 else if a
< 75 then h
:= 3
2611 else if a
< 95 then h
:= 4
2614 //if a > 255 then a := 255;
2616 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2617 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2620 procedure TPlayer
.DrawPickup();
2624 if FPickup
= 0 then Exit
;
2628 if a
< 15 then h
:= 1
2629 else if a
< 35 then h
:= 2
2630 else if a
< 55 then h
:= 3
2631 else if a
< 75 then h
:= 4
2634 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2637 procedure TPlayer
.Fire();
2639 f
, DidFire
: Boolean;
2640 wx
, wy
, xd
, yd
: Integer;
2643 if g_Game_IsClient
then Exit
;
2644 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2645 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2653 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2658 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2659 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2660 xd
:= wx
+IfThen(FDirection
= D_LEFT
, -30, 30);
2661 yd
:= wy
+firediry();
2666 if R_BERSERK
in FRulez
then
2668 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2669 obj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2670 obj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2673 obj
.rect
.Width
:= 39;
2674 obj
.rect
.Height
:= 52;
2675 obj
.Vel
.X
:= (xd
-wx
) div 2;
2676 obj
.Vel
.Y
:= (yd
-wy
) div 2;
2677 obj
.Accel
.X
:= xd
-wx
;
2678 obj
.Accel
.y
:= yd
-wy
;
2680 if g_Weapon_Hit(@obj
, 50, FUID
, HIT_SOME
) <> 0 then
2681 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2683 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2687 FPain
:= min(FPain
+ 25, 50);
2688 end else g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2691 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2696 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2697 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2699 FSawSoundSelect
.Stop();
2701 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2703 else if not FSawSoundHit
.IsPlaying() then
2705 FSawSoundSelect
.Stop();
2706 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2709 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2715 if FAmmo
[A_BULLETS
] > 0 then
2717 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2718 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2719 Dec(FAmmo
[A_BULLETS
]);
2720 FFireAngle
:= FAngle
;
2723 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2724 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2728 if FAmmo
[A_SHELLS
] > 0 then
2730 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2731 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
2732 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2733 Dec(FAmmo
[A_SHELLS
]);
2734 FFireAngle
:= FAngle
;
2738 FShellType
:= SHELL_SHELL
;
2742 if FAmmo
[A_SHELLS
] >= 2 then
2744 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
2745 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2746 Dec(FAmmo
[A_SHELLS
], 2);
2747 FFireAngle
:= FAngle
;
2751 FShellType
:= SHELL_DBLSHELL
;
2755 if FAmmo
[A_BULLETS
] > 0 then
2757 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
2758 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
2759 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2760 Dec(FAmmo
[A_BULLETS
]);
2761 FFireAngle
:= FAngle
;
2764 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2765 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2768 WEAPON_ROCKETLAUNCHER
:
2769 if FAmmo
[A_ROCKETS
] > 0 then
2771 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
2772 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2773 Dec(FAmmo
[A_ROCKETS
]);
2774 FFireAngle
:= FAngle
;
2780 if FAmmo
[A_CELLS
] > 0 then
2782 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
2783 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2784 Dec(FAmmo
[A_CELLS
]);
2785 FFireAngle
:= FAngle
;
2791 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
2793 FBFGFireCounter
:= 17;
2794 if not FNoReload
then
2795 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
2796 Dec(FAmmo
[A_CELLS
], 40);
2800 WEAPON_SUPERPULEMET
:
2801 if FAmmo
[A_SHELLS
] > 0 then
2803 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2804 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
2805 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2806 Dec(FAmmo
[A_SHELLS
]);
2807 FFireAngle
:= FAngle
;
2810 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2811 GameVelX
, GameVelY
-2, SHELL_SHELL
);
2814 WEAPON_FLAMETHROWER
:
2815 if FAmmo
[A_FUEL
] > 0 then
2817 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
2818 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2820 FFireAngle
:= FAngle
;
2826 if g_Game_IsNet
then
2830 if FCurrWeap
<> WEAPON_BFG
then
2831 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
2833 if not FNoReload
then
2834 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
2837 MH_SEND_PlayerStats(FUID
);
2842 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
2843 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
2844 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
2847 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
2850 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
2851 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
2852 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
2853 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
2854 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
2859 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
2861 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
2862 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
2863 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
2866 procedure TPlayer
.JetpackOn
;
2870 FJetSoundOn
.SetPosition(0);
2871 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
2875 procedure TPlayer
.JetpackOff
;
2879 FJetSoundOff
.SetPosition(0);
2880 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
2883 procedure TPlayer
.CatchFire();
2886 if g_Game_IsNet
and g_Game_IsServer
then
2887 MH_SEND_PlayerStats(FUID
);
2890 procedure TPlayer
.Jump();
2892 if gFly
or FJetpack
then
2894 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
2895 if FObj
.Vel
.Y
> -VEL_FLY
then
2896 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
2899 if FJetFuel
> 0 then
2901 if (FJetFuel
< 1) and g_Game_IsServer
then
2905 if g_Game_IsNet
then
2906 MH_SEND_PlayerStats(FUID
);
2912 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
2914 FCanJetpack
:= False;
2916 // Ïðûãàåì èëè âñïëûâàåì:
2917 if (CollideLevel(0, 1) or
2918 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
2919 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
2920 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
2922 FObj
.Vel
.Y
:= -VEL_JUMP
;
2923 FCanJetpack
:= False;
2927 if BodyInLiquid(0, 0) then
2928 FObj
.Vel
.Y
:= -VEL_SW
2929 else if (FJetFuel
> 0) and FCanJetpack
and
2930 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
2934 if g_Game_IsNet
then
2935 MH_SEND_PlayerStats(FUID
);
2940 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
2942 a
, i
, k
, ab
, ar
: Byte;
2946 srv
, netsrv
: Boolean;
2951 procedure PushItem(t
: Byte);
2955 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
2956 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
2957 g_Obj_Push(@gItems
[id
].Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
2958 (FObj
.Vel
.Y
div 2)-Random(9))
2960 if KillType
= K_HARDKILL
then // -5..+5; -5..0
2961 g_Obj_Push(@gItems
[id
].Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
2962 (FObj
.Vel
.Y
div 2)-Random(6))
2963 else // -3..+3; -3..0
2964 g_Obj_Push(@gItems
[id
].Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
2965 (FObj
.Vel
.Y
div 2)-Random(4));
2967 if g_Game_IsNet
and g_Game_IsServer
then
2968 MH_SEND_ItemSpawn(True, id
);
2972 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
2973 Srv
:= g_Game_IsServer
;
2974 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
2975 if Srv
then FDeath
:= FDeath
+ 1;
2980 if not FPhysics
then
2986 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2988 if FLives
> 0 then FLives
:= FLives
- 1;
2989 if FLives
= 0 then FNoRespawn
:= True;
2992 // Íîìåð òèïà ñìåðòè:
2995 K_SIMPLEKILL
: a
:= 1;
2997 K_EXTRAHARDKILL
: a
:= 3;
3002 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3004 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3011 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3013 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3014 K_EXTRAHARDKILL
, K_FALLKILL
:
3015 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3018 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3022 K_HARDKILL
, K_EXTRAHARDKILL
:
3026 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3027 if (KillType
<> K_FALLKILL
) and (Srv
) then
3028 g_Monsters_killedp();
3030 if SpawnerUID
= FUID
then
3032 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3037 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3040 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3041 begin // Óáèò äðóãèì èãðîêîì
3042 KP
:= g_Player_Get(SpawnerUID
);
3043 if (KP
<> nil) and Srv
then
3045 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3046 if SameTeam(FUID
, SpawnerUID
) then
3056 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3057 Inc(gTeamStat
[KP
.Team
].Goals
,
3058 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3060 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3063 plr
:= g_Player_Get(SpawnerUID
);
3071 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3075 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3079 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3084 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3085 begin // Óáèò ìîíñòðîì
3086 mon
:= g_Monsters_Get(SpawnerUID
);
3090 s
:= g_Monsters_GetKilledBy(mon
.MonsterType
);
3094 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3098 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3102 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3107 else // Îñîáûå òèïû ñìåðòè
3110 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3111 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3112 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3113 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3114 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3115 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3121 for a
:= WP_FIRST
to WP_LAST
do
3125 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3126 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3127 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3128 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3129 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3130 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3131 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3132 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3133 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3142 if R_ITEM_BACKPACK
in FRulez
then
3143 PushItem(ITEM_AMMO_BACKPACK
);
3145 // Âûáðîñ ðàêåòíîãî ðàíöà:
3146 if FJetFuel
> 0 then
3147 PushItem(ITEM_JETPACK
);
3150 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3152 if R_KEY_RED
in FRulez
then
3153 PushItem(ITEM_KEY_RED
);
3155 if R_KEY_GREEN
in FRulez
then
3156 PushItem(ITEM_KEY_GREEN
);
3158 if R_KEY_BLUE
in FRulez
then
3159 PushItem(ITEM_KEY_BLUE
);
3166 g_Player_CreateCorpse(Self
);
3168 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3169 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3175 for i
:= Low(gPlayers
) to High(gPlayers
) do
3177 if gPlayers
[i
] = nil then continue
;
3178 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3181 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3182 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3187 OldLR
:= gLMSRespawn
;
3188 if (gGameSettings
.GameMode
= GM_COOP
) then
3192 // everyone is dead, restart the map
3193 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3195 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3196 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3197 gLMSRespawnTime
:= gTime
+ 5000;
3199 else if (a
= 1) then
3201 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3202 if (gPlayers
[k
] = gPlayer1
) or
3203 (gPlayers
[k
] = gPlayer2
) then
3204 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3205 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3206 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3209 else if (gGameSettings
.GameMode
= GM_TDM
) then
3211 if (ab
= 0) and (ar
<> 0) then
3214 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3216 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3217 Inc(gTeamStat
[TEAM_RED
].Goals
);
3218 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3219 gLMSRespawnTime
:= gTime
+ 5000;
3221 else if (ar
= 0) and (ab
<> 0) then
3224 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3226 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3227 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3228 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3229 gLMSRespawnTime
:= gTime
+ 5000;
3231 else if (ar
= 0) and (ab
= 0) then
3234 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3236 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3237 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3238 gLMSRespawnTime
:= gTime
+ 5000;
3241 else if (gGameSettings
.GameMode
= GM_DM
) then
3245 if gPlayers
[k
] <> nil then
3248 // survivor is the winner
3249 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3251 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3254 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3255 gLMSRespawnTime
:= gTime
+ 5000;
3257 else if (a
= 0) then
3259 // everyone is dead, restart the map
3260 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3262 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3263 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3264 gLMSRespawnTime
:= gTime
+ 5000;
3267 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3269 if NetMode
= NET_SERVER
then
3270 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3272 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3278 MH_SEND_PlayerStats(FUID
);
3279 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3280 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3283 if srv
and FNoRespawn
then Spectate(True);
3284 FWantsInGame
:= True;
3287 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3289 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3290 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3293 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3295 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3296 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3299 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3301 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3302 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3303 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3305 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3306 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3307 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3311 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3313 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3314 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3315 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3319 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3321 if g_Game_IsClient
then Exit
;
3322 if Weapon
> High(FWeapon
) then Exit
;
3323 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3326 procedure TPlayer
.resetWeaponQueue ();
3329 FNextWeapDelay
:= 0;
3332 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3336 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3337 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 0);
3338 WEAPON_PISTOL
, WEAPON_CHAINGUN
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_BULLETS
] > 0);
3339 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3340 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3341 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3342 else result
:= (weapon
< length(FWeapon
));
3346 // return 255 for "no switch"
3347 function TPlayer
.getNextWeaponIndex (): Byte;
3350 wantThisWeapon
: array[0..64] of Boolean;
3351 wwc
: Integer = 0; //HACK!
3354 result
:= 255; // default result: "no switch"
3355 // had weapon cycling on previous frame? remove that flag
3356 if (FNextWeap
and $2000) <> 0 then begin FNextWeap
:= FNextWeap
and $1FFF; FNextWeapDelay
:= 0; end;
3357 // cycling has priority
3358 if (FNextWeap
and $C000) <> 0 then
3360 if (FNextWeap
and $8000) <> 0 then dir
:= 1 else dir
:= -1;
3361 FNextWeap
:= FNextWeap
or $2000; // we need this
3362 if FNextWeapDelay
> 0 then exit
; // cooldown time
3364 for i
:= 0 to High(FWeapon
) do
3366 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3367 if FWeapon
[cwi
] then
3369 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d', [FCurrWeap, cwi]), MSG_WARNING);
3370 result
:= Byte(cwi
);
3371 FNextWeapDelay
:= 10;
3379 for i
:= 0 to High(wantThisWeapon
) do wantThisWeapon
[i
] := false;
3380 for i
:= 0 to High(FWeapon
) do if (FNextWeap
and (1 shl i
)) <> 0 then begin wantThisWeapon
[i
] := true; Inc(wwc
); end;
3381 // exclude currently selected weapon from the set
3382 wantThisWeapon
[FCurrWeap
] := false;
3383 // slow down alterations a little
3386 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3387 // more than one weapon requested, assume "alteration" and check alteration delay
3388 if FNextWeapDelay
> 0 then begin FNextWeap
:= 0; exit
; end; // yeah
3390 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3391 // but clear all counters if no weapon should be switched
3392 if wwc
< 1 then begin resetWeaponQueue(); exit
; end;
3393 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3394 // try weapons in descending order
3395 for i
:= High(FWeapon
) downto 0 do
3397 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3402 FNextWeapDelay
:= 10; // anyway, 'cause why not
3406 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3410 procedure TPlayer
.RealizeCurrentWeapon();
3411 function switchAllowed (): Boolean;
3416 if FBFGFireCounter
<> -1 then
3418 if FTime
[T_SWITCH
] > gTime
then
3420 for i
:= WP_FIRST
to WP_LAST
do
3421 if FReloading
[i
] > 0 then
3429 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3430 //FNextWeap := FNextWeap and $1FFF;
3431 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3433 if not switchAllowed
then
3435 //HACK for weapon cycling
3436 if (FNextWeap
and $7000) <> 0 then FNextWeap
:= 0;
3440 nw
:= getNextWeaponIndex();
3441 if nw
= 255 then exit
; // don't reset anything here
3442 if nw
> High(FWeapon
) then
3444 // don't forget to reset queue here!
3445 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3453 FTime
[T_SWITCH
] := gTime
+156;
3454 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3455 FModel
.SetWeapon(FCurrWeap
);
3456 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3460 procedure TPlayer
.NextWeapon();
3462 if g_Game_IsClient
then Exit
;
3466 procedure TPlayer
.PrevWeapon();
3468 if g_Game_IsClient
then Exit
;
3472 procedure TPlayer
.SetWeapon(W
: Byte);
3474 if FCurrWeap
<> W
then
3475 if W
= WEAPON_SAW
then
3476 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3479 FModel
.SetWeapon(CurrWeap
);
3483 function TPlayer
.PickItem(ItemType
: Byte; respawn
: Boolean; var remove
: Boolean): Boolean;
3488 if g_Game_IsClient
then Exit
;
3490 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3491 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and respawn
;
3496 if FHealth
< PLAYER_HP_SOFT
then
3498 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3501 if gFlash
= 2 then Inc(FPickup
, 5);
3505 if FHealth
< PLAYER_HP_SOFT
then
3507 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3510 if gFlash
= 2 then Inc(FPickup
, 5);
3514 if FArmor
< PLAYER_AP_SOFT
then
3516 FArmor
:= PLAYER_AP_SOFT
;
3519 if gFlash
= 2 then Inc(FPickup
, 5);
3523 if FArmor
< PLAYER_AP_LIMIT
then
3525 FArmor
:= PLAYER_AP_LIMIT
;
3528 if gFlash
= 2 then Inc(FPickup
, 5);
3532 if FHealth
< PLAYER_HP_LIMIT
then
3534 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3537 if gFlash
= 2 then Inc(FPickup
, 5);
3541 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3543 if FHealth
< PLAYER_HP_LIMIT
then
3544 FHealth
:= PLAYER_HP_LIMIT
;
3545 if FArmor
< PLAYER_AP_LIMIT
then
3546 FArmor
:= PLAYER_AP_LIMIT
;
3549 if gFlash
= 2 then Inc(FPickup
, 5);
3553 if (not FWeapon
[WEAPON_SAW
]) or ((not respawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3555 FWeapon
[WEAPON_SAW
] := 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_SHOTGUN1
:
3562 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3564 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3565 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3567 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3568 FWeapon
[WEAPON_SHOTGUN1
] := True;
3570 if gFlash
= 2 then Inc(FPickup
, 5);
3571 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3574 ITEM_WEAPON_SHOTGUN2
:
3575 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3577 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3579 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3580 FWeapon
[WEAPON_SHOTGUN2
] := True;
3582 if gFlash
= 2 then Inc(FPickup
, 5);
3583 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3586 ITEM_WEAPON_CHAINGUN
:
3587 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3589 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3591 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3592 FWeapon
[WEAPON_CHAINGUN
] := True;
3594 if gFlash
= 2 then Inc(FPickup
, 5);
3595 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3598 ITEM_WEAPON_ROCKETLAUNCHER
:
3599 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3601 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3603 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3604 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3606 if gFlash
= 2 then Inc(FPickup
, 5);
3607 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3611 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3613 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3615 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3616 FWeapon
[WEAPON_PLASMA
] := True;
3618 if gFlash
= 2 then Inc(FPickup
, 5);
3619 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3623 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3625 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3627 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3628 FWeapon
[WEAPON_BFG
] := True;
3630 if gFlash
= 2 then Inc(FPickup
, 5);
3631 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3634 ITEM_WEAPON_SUPERPULEMET
:
3635 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3637 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3639 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3640 FWeapon
[WEAPON_SUPERPULEMET
] := True;
3642 if gFlash
= 2 then Inc(FPickup
, 5);
3643 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3646 ITEM_WEAPON_FLAMETHROWER
:
3647 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
3649 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
3651 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3652 FWeapon
[WEAPON_FLAMETHROWER
] := True;
3654 if gFlash
= 2 then Inc(FPickup
, 5);
3655 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3659 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3661 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3664 if gFlash
= 2 then Inc(FPickup
, 5);
3667 ITEM_AMMO_BULLETS_BOX
:
3668 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3670 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3673 if gFlash
= 2 then Inc(FPickup
, 5);
3677 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3679 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3682 if gFlash
= 2 then Inc(FPickup
, 5);
3685 ITEM_AMMO_SHELLS_BOX
:
3686 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3688 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
3691 if gFlash
= 2 then Inc(FPickup
, 5);
3695 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3697 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3700 if gFlash
= 2 then Inc(FPickup
, 5);
3703 ITEM_AMMO_ROCKET_BOX
:
3704 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3706 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
3709 if gFlash
= 2 then Inc(FPickup
, 5);
3713 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3715 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3718 if gFlash
= 2 then Inc(FPickup
, 5);
3722 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3724 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
3727 if gFlash
= 2 then Inc(FPickup
, 5);
3731 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
3733 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3736 if gFlash
= 2 then Inc(FPickup
, 5);
3740 if not(R_ITEM_BACKPACK
in FRulez
) or
3741 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
3742 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
3743 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
3744 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
3745 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
3747 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
3748 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
3749 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
3750 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
3751 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
3753 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3754 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3755 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3756 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3757 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3758 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3759 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3760 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3762 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
3765 if gFlash
= 2 then Inc(FPickup
, 5);
3769 if not(R_KEY_RED
in FRulez
) then
3771 Include(FRulez
, R_KEY_RED
);
3773 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3774 if gFlash
= 2 then Inc(FPickup
, 5);
3775 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3779 if not(R_KEY_GREEN
in FRulez
) then
3781 Include(FRulez
, R_KEY_GREEN
);
3783 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3784 if gFlash
= 2 then Inc(FPickup
, 5);
3785 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3789 if not(R_KEY_BLUE
in FRulez
) then
3791 Include(FRulez
, R_KEY_BLUE
);
3793 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3794 if gFlash
= 2 then Inc(FPickup
, 5);
3795 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3799 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
3801 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
3804 if gFlash
= 2 then Inc(FPickup
, 5);
3808 if FAir
< AIR_MAX
then
3813 if gFlash
= 2 then Inc(FPickup
, 5);
3818 if not (R_BERSERK
in FRulez
) then
3820 Include(FRulez
, R_BERSERK
);
3821 if FBFGFireCounter
= -1 then
3823 FCurrWeap
:= WEAPON_KASTET
;
3825 FModel
.SetWeapon(WEAPON_KASTET
);
3829 if gFlash
= 2 then Inc(FPickup
, 5);
3830 FBerserk
:= gTime
+30000;
3834 if FHealth
< PLAYER_HP_SOFT
then
3836 FHealth
:= PLAYER_HP_SOFT
;
3837 FBerserk
:= gTime
+30000;
3844 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
3846 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
3849 if gFlash
= 2 then Inc(FPickup
, 5);
3853 if FHealth
< PLAYER_HP_LIMIT
then
3855 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
3858 if gFlash
= 2 then Inc(FPickup
, 5);
3862 if FArmor
< PLAYER_AP_LIMIT
then
3864 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
3867 if gFlash
= 2 then Inc(FPickup
, 5);
3871 if FJetFuel
< JET_MAX
then
3873 FJetFuel
:= JET_MAX
;
3876 if gFlash
= 2 then Inc(FPickup
, 5);
3880 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
3882 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
3885 if gFlash
= 2 then Inc(FPickup
, 5);
3890 procedure TPlayer
.Touch();
3894 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
3897 // Áðîñèòü ôëàã òîâàðèùó:
3898 if gGameSettings
.GameMode
= GM_CTF
then
3903 procedure TPlayer
.Push(vx
, vy
: Integer);
3905 if (not FPhysics
) and FGhost
then
3907 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
3908 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
3909 if g_Game_IsNet
and g_Game_IsServer
then
3910 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
3913 procedure TPlayer
.Reset(Force
: Boolean);
3919 FTime
[T_RESPAWN
] := 0;
3920 FTime
[T_FLAGCAP
] := 0;
3933 FSpectator
:= False;
3936 FSpectatePlayer
:= -1;
3937 FNoRespawn
:= False;
3939 FLives
:= gGameSettings
.MaxLives
;
3944 procedure TPlayer
.SoftReset();
3950 FBFGFireCounter
:= -1;
3958 SetAction(A_STAND
, True);
3961 function TPlayer
.GetRespawnPoint(): Byte;
3966 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
3968 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
3969 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
3971 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
3973 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
3974 if Self
= gPlayer1
then
3975 c
:= RESPAWNPOINT_PLAYER1
3977 c
:= RESPAWNPOINT_PLAYER2
;
3978 if g_Map_GetPointCount(c
) > 0 then
3984 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
3985 if Self
= gPlayer1
then
3986 c
:= RESPAWNPOINT_PLAYER2
3988 c
:= RESPAWNPOINT_PLAYER1
;
3989 if g_Map_GetPointCount(c
) > 0 then
3996 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
3997 if Random(2) = 0 then
3998 c
:= RESPAWNPOINT_PLAYER1
4000 c
:= RESPAWNPOINT_PLAYER2
;
4001 if g_Map_GetPointCount(c
) > 0 then
4008 // Òî÷êà ëþáîé èç êîìàíä
4009 if Random(2) = 0 then
4010 c
:= RESPAWNPOINT_RED
4012 c
:= RESPAWNPOINT_BLUE
;
4013 if g_Map_GetPointCount(c
) > 0 then
4020 c
:= RESPAWNPOINT_DM
;
4021 if g_Map_GetPointCount(c
) > 0 then
4029 if gGameSettings
.GameMode
= GM_DM
then
4032 c
:= RESPAWNPOINT_DM
;
4033 if g_Map_GetPointCount(c
) > 0 then
4039 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4040 if Random(2) = 0 then
4041 c
:= RESPAWNPOINT_PLAYER1
4043 c
:= RESPAWNPOINT_PLAYER2
;
4044 if g_Map_GetPointCount(c
) > 0 then
4050 // Òî÷êà ëþáîé èç êîìàíä
4051 if Random(2) = 0 then
4052 c
:= RESPAWNPOINT_RED
4054 c
:= RESPAWNPOINT_BLUE
;
4055 if g_Map_GetPointCount(c
) > 0 then
4063 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4065 // Òî÷êà ñâîåé êîìàíäû
4066 c
:= RESPAWNPOINT_DM
;
4067 if FTeam
= TEAM_RED
then
4068 c
:= RESPAWNPOINT_RED
;
4069 if FTeam
= TEAM_BLUE
then
4070 c
:= RESPAWNPOINT_BLUE
;
4071 if g_Map_GetPointCount(c
) > 0 then
4078 c
:= RESPAWNPOINT_DM
;
4079 if g_Map_GetPointCount(c
) > 0 then
4085 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4086 if Random(2) = 0 then
4087 c
:= RESPAWNPOINT_PLAYER1
4089 c
:= RESPAWNPOINT_PLAYER2
;
4090 if g_Map_GetPointCount(c
) > 0 then
4096 // Òî÷êà äðóãîé êîìàíäû
4097 c
:= RESPAWNPOINT_DM
;
4098 if FTeam
= TEAM_RED
then
4099 c
:= RESPAWNPOINT_BLUE
;
4100 if FTeam
= TEAM_BLUE
then
4101 c
:= RESPAWNPOINT_RED
;
4102 if g_Map_GetPointCount(c
) > 0 then
4110 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4112 RespawnPoint
: TRespawnPoint
;
4117 if not g_Game_IsServer
then
4121 FWantsInGame
:= True;
4122 FJustTeleported
:= True;
4125 FTime
[T_RESPAWN
] := 0;
4129 // if server changes MaxLives we gotta be ready
4130 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4132 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4133 if FTime
[T_RESPAWN
] > gTime
then
4136 // Ïðîñðàë âñå æèçíè:
4139 if not FSpectator
then Spectate(True);
4140 FWantsInGame
:= True;
4144 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4145 begin // "Ñâîÿ èãðà"
4146 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4147 FRulez
:= FRulez
-[R_BERSERK
];
4149 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4151 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4152 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4155 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4156 c
:= GetRespawnPoint();
4161 // Âîñêðåøåíèå áåç îðóæèÿ:
4164 FHealth
:= PLAYER_HP_SOFT
;
4170 for a
:= WP_FIRST
to WP_LAST
do
4172 FWeapon
[a
] := False;
4176 FWeapon
[WEAPON_PISTOL
] := True;
4177 FWeapon
[WEAPON_KASTET
] := True;
4178 FCurrWeap
:= WEAPON_PISTOL
;
4181 FModel
.SetWeapon(FCurrWeap
);
4183 for b
:= A_BULLETS
to A_HIGH
do
4186 FAmmo
[A_BULLETS
] := 50;
4188 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4189 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4190 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4191 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4192 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4194 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4195 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4200 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4201 if not g_Map_GetPoint(c
, RespawnPoint
) then
4203 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4207 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4208 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4209 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4215 FDirection
:= RespawnPoint
.Direction
;
4216 if FDirection
= D_LEFT
then
4222 FBFGFireCounter
:= -1;
4227 SetAction(A_STAND
, True);
4228 FModel
.Direction
:= FDirection
;
4230 for a
:= Low(FTime
) to High(FTime
) do
4233 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4238 FCanJetpack
:= False;
4240 // Àíèìàöèÿ âîçðîæäåíèÿ:
4241 if (not gLoadGameMode
) and (not Silent
) then
4242 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4244 Anim
:= TAnimation
.Create(ID
, False, 3);
4245 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4246 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4250 FSpectator
:= False;
4253 FSpectatePlayer
:= -1;
4256 if g_Game_IsNet
then
4258 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4259 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4261 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4262 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4267 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4270 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4271 else if (not NoMove
) then
4273 GameX
:= gMapInfo
.Width
div 2;
4274 GameY
:= gMapInfo
.Height
div 2;
4283 FWantsInGame
:= False;
4288 if Self
= gPlayer1
then
4293 if Self
= gPlayer2
then
4300 if g_Game_IsNet
then
4301 MH_SEND_PlayerStats(FUID
);
4304 procedure TPlayer
.SwitchNoClip
;
4308 FGhost
:= not FGhost
;
4309 FPhysics
:= not FGhost
;
4321 procedure TPlayer
.Run(Direction
: TDirection
);
4325 if MAX_RUNVEL
> 8 then
4329 if Direction
= D_LEFT
then
4331 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4332 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4335 if FObj
.Vel
.X
< MAX_RUNVEL
then
4336 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4338 // Âîçìîæíî, ïèíàåì êóñêè:
4339 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4341 b
:= Abs(FObj
.Vel
.X
);
4342 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4343 for a
:= 0 to High(gGibs
) do
4344 if gGibs
[a
].Live
and
4345 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4346 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4348 if FObj
.Vel
.X
< 0 then
4349 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4351 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4357 procedure TPlayer
.SeeDown();
4359 SetAction(A_SEEDOWN
);
4361 if FDirection
= D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4363 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4366 procedure TPlayer
.SeeUp();
4370 if FDirection
= D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4372 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4375 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4383 A_ATTACK
: Prior
:= 2;
4384 A_SEEUP
: Prior
:= 1;
4385 A_SEEDOWN
: Prior
:= 1;
4386 A_ATTACKUP
: Prior
:= 2;
4387 A_ATTACKDOWN
: Prior
:= 2;
4392 if (Prior
> FActionPrior
) or Force
then
4393 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4395 FActionPrior
:= Prior
;
4396 FActionAnim
:= Action
;
4397 FActionForce
:= Force
;
4398 FActionChanged
:= True;
4401 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4404 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4406 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4407 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4408 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4409 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4412 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4419 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4421 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4422 if g_Game_IsServer
and g_Game_IsNet
then
4423 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4427 FJustTeleported
:= True;
4432 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4434 Anim
:= TAnimation
.Create(ID
, False, 3);
4437 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4438 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4439 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4440 if g_Game_IsServer
and g_Game_IsNet
then
4441 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4442 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4446 FObj
.X
:= X
-PLAYER_RECT
.X
;
4447 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4448 if FLive
and FGhost
then
4454 if not g_Game_IsNet
then
4458 SetDirection(D_LEFT
);
4464 SetDirection(D_RIGHT
);
4470 if FDirection
= D_RIGHT
then
4472 SetDirection(D_LEFT
);
4477 SetDirection(D_RIGHT
);
4483 if not silent
and (Anim
<> nil) then
4485 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4486 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4489 if g_Game_IsServer
and g_Game_IsNet
then
4490 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4491 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4498 function nonz(a
: Single): Single;
4506 procedure TPlayer
.Update();
4509 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4510 blockmon
, headwater
, dospawn
: Boolean;
4515 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4516 AnyServer
:= g_Game_IsServer
;
4518 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4519 DoLerp(NetInterpLevel
+ 1)
4525 if FClientID
>= 0 then
4527 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4528 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4529 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4538 if FLive
and (gFly
or FJetpack
) then
4541 if FDirection
= D_LEFT
then
4546 if FLive
and (not FGhost
) then
4548 if FKeys
[KEY_UP
].Pressed
then
4550 if FKeys
[KEY_DOWN
].Pressed
then
4554 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4557 i
:= g_basic
.Sign(FIncCam
);
4558 FIncCam
:= Abs(FIncCam
);
4559 DecMin(FIncCam
, 5, 0);
4560 FIncCam
:= FIncCam
*i
;
4563 // no need to do that each second frame, weapon queue will take care of it
4564 if FLive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4565 if FLive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4567 if gTime
mod (GAME_TICK
*2) <> 0 then
4569 if (FObj
.Vel
.X
= 0) and FLive
then
4571 if FKeys
[KEY_LEFT
].Pressed
then
4573 if FKeys
[KEY_RIGHT
].Pressed
then
4578 g_Obj_Move(@FObj
, True, True, True);
4583 FActionChanged
:= False;
4587 // Let alive player do some actions
4588 if FKeys
[KEY_LEFT
].Pressed
then Run(D_LEFT
);
4589 if FKeys
[KEY_RIGHT
].Pressed
then Run(D_RIGHT
);
4590 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
4591 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
4592 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
4593 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
4594 if FKeys
[KEY_JUMP
].Pressed
then Jump()
4597 if AnyServer
and FJetpack
then
4601 if NetServer
then MH_SEND_PlayerStats(FUID
);
4603 FCanJetpack
:= True;
4610 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
4612 if FKeys
[k
].Pressed
then
4620 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4623 if (FTime
[T_RESPAWN
] <= gTime
) and
4624 gGameOn
and (not FLive
) then
4626 if (g_Player_GetCount() > 1) then
4630 gExit
:= EXIT_RESTART
;
4635 // Dead spectator actions
4638 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
4639 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
4643 if (FSpectatePlayer
>= High(gPlayers
)) then
4644 FSpectatePlayer
:= -1
4648 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
4649 if gPlayers
[I
] <> nil then
4650 if gPlayers
[I
].Live
then
4651 if gPlayers
[I
].UID
<> FUID
then
4653 FSpectatePlayer
:= I
;
4658 if not SetSpect
then FSpectatePlayer
:= -1;
4669 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
4671 FYTo
:= FObj
.Y
- 32;
4672 FSpectatePlayer
:= -1;
4674 if FKeys
[KEY_DOWN
].Pressed
then
4676 FYTo
:= FObj
.Y
+ 32;
4677 FSpectatePlayer
:= -1;
4679 if FKeys
[KEY_LEFT
].Pressed
then
4681 FXTo
:= FObj
.X
- 32;
4682 FSpectatePlayer
:= -1;
4684 if FKeys
[KEY_RIGHT
].Pressed
then
4686 FXTo
:= FObj
.X
+ 32;
4687 FSpectatePlayer
:= -1;
4690 if (FXTo
< -64) then
4692 else if (FXTo
> gMapInfo
.Width
+ 32) then
4693 FXTo
:= gMapInfo
.Width
+ 32;
4694 if (FYTo
< -72) then
4696 else if (FYTo
> gMapInfo
.Height
+ 32) then
4697 FYTo
:= gMapInfo
.Height
+ 32;
4701 g_Obj_Move(@FObj
, True, True, True)
4707 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
4708 if gPlayers
[FSpectatePlayer
] <> nil then
4709 if gPlayers
[FSpectatePlayer
].Live
then
4711 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
4712 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
4716 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
4717 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
4718 PANEL_BLOCKMON
, True);
4719 headwater
:= HeadInLiquid(0, 0);
4721 // Ñîïðîòèâëåíèå âîçäóõà:
4722 if (not FLive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
4723 if FObj
.Vel
.X
<> 0 then
4724 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
4726 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
4727 DecMin(FPain
, 5, 0);
4728 DecMin(FPickup
, 1, 0);
4730 if FLive
and (FObj
.Y
> gMapInfo
.Height
+128) and AnyServer
then
4732 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
4733 FMegaRulez
[MR_SUIT
] := 0;
4734 FMegaRulez
[MR_INVUL
] := 0;
4735 FMegaRulez
[MR_INVIS
] := 0;
4736 Kill(K_FALLKILL
, 0, HIT_FALL
);
4743 if FCurrWeap
= WEAPON_SAW
then
4744 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
4745 FSawSoundSelect
.IsPlaying()) then
4746 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
4749 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
4750 (not FJetSoundOff
.IsPlaying()) then
4752 FJetSoundFly
.SetPosition(0);
4753 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
4756 for b
:= WP_FIRST
to WP_LAST
do
4757 if FReloading
[b
] > 0 then
4763 if FShellTimer
> -1 then
4764 if FShellTimer
= 0 then
4766 if FShellType
= SHELL_SHELL
then
4767 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4768 GameVelX
, GameVelY
-2, SHELL_SHELL
)
4769 else if FShellType
= SHELL_DBLSHELL
then
4771 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4772 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
4773 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4774 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
4777 end else Dec(FShellTimer
);
4779 if (FBFGFireCounter
> -1) then
4780 if FBFGFireCounter
= 0 then
4784 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
4785 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
4786 xd
:= wx
+IfThen(FDirection
= D_LEFT
, -30, 30);
4787 yd
:= wy
+firediry();
4788 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
4789 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
4790 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
4791 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
4792 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
4795 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
4796 FBFGFireCounter
:= -1;
4799 FBFGFireCounter
:= 0
4801 Dec(FBFGFireCounter
);
4803 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
4805 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
4807 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
4810 if (headwater
or blockmon
) then
4816 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
4819 else if (FAir
mod 31 = 0) and not blockmon
then
4821 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
4822 if Random(2) = 0 then
4823 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
4825 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
4827 end else if FAir
< AIR_DEF
then
4830 if FFireTime
> 0 then
4832 if BodyInLiquid(0, 0) then
4840 if FFirePainTime
<= 0 then
4842 if g_Game_IsServer
then
4843 Damage(5, 0, 0, 0, HIT_FLAME
);
4844 FFirePainTime
:= 18;
4846 FFirePainTime
:= FFirePainTime
- 1;
4847 FFireTime
:= FFireTime
- 1;
4848 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
4849 MH_SEND_PlayerStats(FUID
);
4853 if FDamageBuffer
> 0 then
4855 if FDamageBuffer
>= 9 then
4859 if FDamageBuffer
< 30 then i
:= 9
4860 else if FDamageBuffer
< 100 then i
:= 18
4864 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
4865 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
4866 FHealth
:= FHealth
-ii
;
4869 FHealth
:= FHealth
+FArmor
;
4874 if FHealth
<= 0 then
4875 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
4876 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
4877 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
4881 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
4882 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
4883 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
4884 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
4891 end; // if FLive then ...
4893 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
4895 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
4896 FModel
.GetCurrentAnimation
.MinLength
:= i
;
4897 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
4898 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
4900 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
4901 then SetAction(A_STAND
, True);
4903 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
4905 for b
:= Low(FKeys
) to High(FKeys
) do
4906 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
4909 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
4911 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
4912 FObj
.Y
+PLAYER_RECT
.Y
,
4919 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
4921 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
4922 FObj
.Y
+PLAYER_RECT
.Y
,
4926 Panel
.Width
, Panel
.Height
);
4929 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
4931 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
4932 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
4933 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
4934 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
4937 function g_Player_ValidName(Name
: string): Boolean;
4943 if gPlayers
= nil then Exit
;
4945 for a
:= 0 to High(gPlayers
) do
4946 if gPlayers
[a
] <> nil then
4947 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
4954 procedure TPlayer
.SetDirection(Direction
: TDirection
);
4958 d
:= FModel
.Direction
;
4960 FModel
.Direction
:= Direction
;
4961 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
4963 FDirection
:= Direction
;
4966 function TPlayer
.GetKeys(): Byte;
4970 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
4971 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
4972 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
4974 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
4975 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
4978 procedure TPlayer
.Use();
4982 if FTime
[T_USE
] > gTime
then Exit
;
4984 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
4985 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
4987 for a
:= 0 to High(gPlayers
) do
4988 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
4989 gPlayers
[a
].Live
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
4990 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
4991 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
4993 gPlayers
[a
].Touch();
4994 if g_Game_IsNet
and g_Game_IsServer
then
4995 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
4998 FTime
[T_USE
] := gTime
+120;
5001 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5005 WX
, WY
, XD
, YD
: Integer;
5016 if R_BERSERK
in FRulez
then
5018 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5019 obj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5020 obj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5023 obj
.rect
.Width
:= 39;
5024 obj
.rect
.Height
:= 52;
5025 obj
.Vel
.X
:= (xd
-wx
) div 2;
5026 obj
.Vel
.Y
:= (yd
-wy
) div 2;
5027 obj
.Accel
.X
:= xd
-wx
;
5028 obj
.Accel
.y
:= yd
-wy
;
5030 if g_Weapon_Hit(@obj
, 50, FUID
, HIT_SOME
) <> 0 then
5031 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5033 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5037 FPain
:= min(FPain
+ 25, 50);
5039 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5044 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5045 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5047 FSawSoundSelect
.Stop();
5049 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5051 else if not FSawSoundHit
.IsPlaying() then
5053 FSawSoundSelect
.Stop();
5054 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5061 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5062 FFireAngle
:= FAngle
;
5064 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5065 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5070 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5071 FFireAngle
:= FAngle
;
5074 FShellType
:= SHELL_SHELL
;
5079 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5080 FFireAngle
:= FAngle
;
5083 FShellType
:= SHELL_DBLSHELL
;
5088 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5089 FFireAngle
:= FAngle
;
5091 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5092 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5095 WEAPON_ROCKETLAUNCHER
:
5097 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5098 FFireAngle
:= FAngle
;
5104 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5105 FFireAngle
:= FAngle
;
5111 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5112 FFireAngle
:= FAngle
;
5116 WEAPON_SUPERPULEMET
:
5118 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5119 FFireAngle
:= FAngle
;
5121 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5122 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5125 WEAPON_FLAMETHROWER
:
5127 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5128 FFireAngle
:= FAngle
;
5135 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5136 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5137 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5140 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5142 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5143 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5146 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5150 if NetInterpLevel
< 1 then
5160 AX
:= Abs(FXTo
- FObj
.X
);
5161 AY
:= Abs(FYTo
- FObj
.Y
);
5162 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5164 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5169 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5171 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5172 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5173 PANEL_LIFTUP
, False) then Result
:= -1
5175 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5176 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5177 PANEL_LIFTDOWN
, False) then Result
:= 1
5181 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5188 if Flag
= FLAG_NONE
then
5191 if not g_Game_IsServer
then Exit
;
5193 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5194 if (Flag
= FTeam
) and
5195 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5196 (FFlag
<> FLAG_NONE
) then
5198 if FFlag
= FLAG_RED
then
5199 s
:= _lc
[I_PLAYER_FLAG_RED
]
5201 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5203 evtype
:= FLAG_STATE_SCORED
;
5205 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5206 Insert('.', ts
, Length(ts
) + 1 - 3);
5207 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5209 g_Map_ResetFlag(FFlag
);
5210 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5212 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5215 if g_Game_IsNet
then
5217 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5221 gFlags
[FFlag
].CaptureTime
:= 0;
5226 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5227 if (Flag
= FTeam
) and
5228 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5230 if Flag
= FLAG_RED
then
5231 s
:= _lc
[I_PLAYER_FLAG_RED
]
5233 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5235 evtype
:= FLAG_STATE_RETURNED
;
5236 gFlags
[Flag
].CaptureTime
:= 0;
5238 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5240 g_Map_ResetFlag(Flag
);
5241 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5244 if g_Game_IsNet
then
5246 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5252 // Ïîäîáðàë ÷óæîé ôëàã:
5253 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5257 if Flag
= FLAG_RED
then
5258 s
:= _lc
[I_PLAYER_FLAG_RED
]
5260 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5262 evtype
:= FLAG_STATE_CAPTURED
;
5264 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5266 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5268 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5271 if g_Game_IsNet
then
5273 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5279 procedure TPlayer
.SetFlag(Flag
: Byte);
5282 if FModel
<> nil then
5283 FModel
.SetFlag(FFlag
);
5286 function TPlayer
.DropFlag(): Boolean;
5291 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5293 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5294 with gFlags
[FFlag
] do
5298 Direction
:= FDirection
;
5299 State
:= FLAG_STATE_DROPPED
;
5301 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5302 (FObj
.Vel
.Y
div 2)-2+Random(5));
5304 if FFlag
= FLAG_RED
then
5305 s
:= _lc
[I_PLAYER_FLAG_RED
]
5307 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5309 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5310 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5312 if g_Game_IsNet
then
5313 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5319 procedure TPlayer
.GetSecret();
5324 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5326 Assert(Key
<= High(FKeys
));
5328 FKeys
[Key
].Pressed
:= True;
5329 FKeys
[Key
].Time
:= Time
;
5332 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5334 Result
:= FKeys
[K
].Pressed
;
5337 procedure TPlayer
.ReleaseKeys();
5341 for a
:= Low(FKeys
) to High(FKeys
) do
5343 FKeys
[a
].Pressed
:= False;
5348 procedure TPlayer
.OnDamage(Angle
: SmallInt
);
5352 function TPlayer
.firediry(): Integer;
5354 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5355 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5359 procedure TPlayer
.RememberState();
5363 FSavedState
.Health
:= FHealth
;
5364 FSavedState
.Armor
:= FArmor
;
5365 FSavedState
.Air
:= FAir
;
5366 FSavedState
.JetFuel
:= FJetFuel
;
5367 FSavedState
.CurrWeap
:= FCurrWeap
;
5368 FSavedState
.NextWeap
:= FNextWeap
;
5369 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5372 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5374 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5376 FSavedState
.Rulez
:= FRulez
;
5377 FSavedState
.WaitRecall
:= True;
5380 procedure TPlayer
.RecallState();
5384 if not FSavedState
.WaitRecall
then Exit
;
5386 FHealth
:= FSavedState
.Health
;
5387 FArmor
:= FSavedState
.Armor
;
5388 FAir
:= FSavedState
.Air
;
5389 FJetFuel
:= FSavedState
.JetFuel
;
5390 FCurrWeap
:= FSavedState
.CurrWeap
;
5391 FNextWeap
:= FSavedState
.NextWeap
;
5392 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5395 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5397 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5399 FRulez
:= FSavedState
.Rulez
;
5400 FSavedState
.WaitRecall
:= False;
5402 if gGameSettings
.GameType
= GT_SERVER
then
5403 MH_SEND_PlayerStats(FUID
);
5406 procedure TPlayer
.SaveState(var Mem
: TBinMemoryWriter
);
5418 Mem
:= TBinMemoryWriter
.Create(i
);
5420 // Ñèãíàòóðà èãðîêà:
5421 sig
:= PLAYER_SIGNATURE
; // 'PLYR'
5422 Mem
.WriteDWORD(sig
);
5424 Mem
.WriteBoolean(FIamBot
);
5426 Mem
.WriteWord(FUID
);
5428 Mem
.WriteString(FName
, 32);
5430 Mem
.WriteByte(FTeam
);
5432 Mem
.WriteBoolean(FLive
);
5433 // Èçðàñõîäîâàë ëè âñå æèçíè:
5434 Mem
.WriteBoolean(FNoRespawn
);
5436 if FDirection
= D_LEFT
then
5442 Mem
.WriteInt(FHealth
);
5444 Mem
.WriteByte(FLives
);
5446 Mem
.WriteInt(FArmor
);
5450 Mem
.WriteInt(FJetFuel
);
5452 Mem
.WriteInt(FPain
);
5454 Mem
.WriteInt(FKills
);
5456 Mem
.WriteInt(FMonsterKills
);
5458 Mem
.WriteInt(FFrags
);
5460 Mem
.WriteByte(FFragCombo
);
5461 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5462 Mem
.WriteDWORD(FLastFrag
);
5464 Mem
.WriteInt(FDeath
);
5465 // Êàêîé ôëàã íåñåò:
5466 Mem
.WriteByte(FFlag
);
5468 Mem
.WriteInt(FSecrets
);
5470 Mem
.WriteByte(FCurrWeap
);
5472 Mem
.WriteWord(FNextWeap
);
5474 Mem
.WriteByte(FNextWeapDelay
);
5475 // Âðåìÿ çàðÿäêè BFG:
5476 Mem
.WriteSmallInt(FBFGFireCounter
);
5478 Mem
.WriteInt(FDamageBuffer
);
5479 // Ïîñëåäíèé óäàðèâøèé:
5480 Mem
.WriteWord(FLastSpawnerUID
);
5481 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5482 Mem
.WriteByte(FLastHit
);
5484 Obj_SaveState(@FObj
, Mem
);
5485 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5486 for i
:= A_BULLETS
to A_HIGH
do
5487 Mem
.WriteWord(FAmmo
[i
]);
5488 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5489 for i
:= A_BULLETS
to A_HIGH
do
5490 Mem
.WriteWord(FMaxAmmo
[i
]);
5492 for i
:= WP_FIRST
to WP_LAST
do
5493 Mem
.WriteBoolean(FWeapon
[i
]);
5494 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5495 for i
:= WP_FIRST
to WP_LAST
do
5496 Mem
.WriteWord(FReloading
[i
]);
5498 if R_ITEM_BACKPACK
in FRulez
then
5503 // Íàëè÷èå êðàñíîãî êëþ÷à:
5504 if R_KEY_RED
in FRulez
then
5509 // Íàëè÷èå çåëåíîãî êëþ÷à:
5510 if R_KEY_GREEN
in FRulez
then
5515 // Íàëè÷èå ñèíåãî êëþ÷à:
5516 if R_KEY_BLUE
in FRulez
then
5521 // Íàëè÷èå áåðñåðêà:
5522 if R_BERSERK
in FRulez
then
5527 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5528 for i
:= MR_SUIT
to MR_MAX
do
5529 Mem
.WriteDWORD(FMegaRulez
[i
]);
5530 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5531 for i
:= T_RESPAWN
to T_FLAGCAP
do
5532 Mem
.WriteDWORD(FTime
[i
]);
5535 Mem
.WriteString(str
);
5545 procedure TPlayer
.LoadState(var Mem
: TBinMemoryReader
);
5555 // Ñèãíàòóðà èãðîêà:
5557 if sig
<> PLAYER_SIGNATURE
then // 'PLYR'
5559 raise EBinSizeError
.Create('TPlayer.LoadState: Wrong Player Signature');
5562 Mem
.ReadBoolean(FIamBot
);
5566 Mem
.ReadString(str
);
5567 if (Self
<> gPlayer1
) and (Self
<> gPlayer2
) then
5570 Mem
.ReadByte(FTeam
);
5572 Mem
.ReadBoolean(FLive
);
5573 // Èçðàñõîäîâàë ëè âñå æèçíè:
5574 Mem
.ReadBoolean(FNoRespawn
);
5578 FDirection
:= D_LEFT
5580 FDirection
:= D_RIGHT
;
5582 Mem
.ReadInt(FHealth
);
5584 Mem
.ReadByte(FLives
);
5586 Mem
.ReadInt(FArmor
);
5590 Mem
.ReadInt(FJetFuel
);
5594 Mem
.ReadInt(FKills
);
5596 Mem
.ReadInt(FMonsterKills
);
5598 Mem
.ReadInt(FFrags
);
5600 Mem
.ReadByte(FFragCombo
);
5601 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5602 Mem
.ReadDWORD(FLastFrag
);
5604 Mem
.ReadInt(FDeath
);
5605 // Êàêîé ôëàã íåñåò:
5606 Mem
.ReadByte(FFlag
);
5608 Mem
.ReadInt(FSecrets
);
5610 Mem
.ReadByte(FCurrWeap
);
5612 Mem
.ReadWord(FNextWeap
);
5614 Mem
.ReadByte(FNextWeapDelay
);
5615 // Âðåìÿ çàðÿäêè BFG:
5616 Mem
.ReadSmallInt(FBFGFireCounter
);
5618 Mem
.ReadInt(FDamageBuffer
);
5619 // Ïîñëåäíèé óäàðèâøèé:
5620 Mem
.ReadWord(FLastSpawnerUID
);
5621 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5622 Mem
.ReadByte(FLastHit
);
5624 Obj_LoadState(@FObj
, Mem
);
5625 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5626 for i
:= A_BULLETS
to A_HIGH
do
5627 Mem
.ReadWord(FAmmo
[i
]);
5628 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5629 for i
:= A_BULLETS
to A_HIGH
do
5630 Mem
.ReadWord(FMaxAmmo
[i
]);
5632 for i
:= WP_FIRST
to WP_LAST
do
5633 Mem
.ReadBoolean(FWeapon
[i
]);
5634 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5635 for i
:= WP_FIRST
to WP_LAST
do
5636 Mem
.ReadWord(FReloading
[i
]);
5640 Include(FRulez
, R_ITEM_BACKPACK
);
5641 // Íàëè÷èå êðàñíîãî êëþ÷à:
5644 Include(FRulez
, R_KEY_RED
);
5645 // Íàëè÷èå çåëåíîãî êëþ÷à:
5648 Include(FRulez
, R_KEY_GREEN
);
5649 // Íàëè÷èå ñèíåãî êëþ÷à:
5652 Include(FRulez
, R_KEY_BLUE
);
5653 // Íàëè÷èå áåðñåðêà:
5656 Include(FRulez
, R_BERSERK
);
5657 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5658 for i
:= MR_SUIT
to MR_MAX
do
5659 Mem
.ReadDWORD(FMegaRulez
[i
]);
5660 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5661 for i
:= T_RESPAWN
to T_FLAGCAP
do
5662 Mem
.ReadDWORD(FTime
[i
]);
5664 Mem
.ReadString(str
);
5666 Mem
.ReadByte(FColor
.R
);
5667 Mem
.ReadByte(FColor
.G
);
5668 Mem
.ReadByte(FColor
.B
);
5669 if Self
= gPlayer1
then
5671 str
:= gPlayer1Settings
.Model
;
5672 FColor
:= gPlayer1Settings
.Color
;
5674 if Self
= gPlayer2
then
5676 str
:= gPlayer2Settings
.Model
;
5677 FColor
:= gPlayer2Settings
.Color
;
5679 // Îáíîâëÿåì ìîäåëü èãðîêà:
5681 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
5682 FModel
.Color
:= TEAMCOLOR
[FTeam
]
5684 FModel
.Color
:= FColor
;
5687 procedure TPlayer
.AllRulez(Health
: Boolean);
5693 FHealth
:= PLAYER_HP_LIMIT
;
5694 FArmor
:= PLAYER_AP_LIMIT
;
5698 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
5699 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
5700 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5703 procedure TPlayer
.RestoreHealthArmor();
5705 FHealth
:= PLAYER_HP_LIMIT
;
5706 FArmor
:= PLAYER_AP_LIMIT
;
5709 procedure TPlayer
.FragCombo();
5713 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
5715 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
5717 if FFragCombo
< 5 then
5719 Param
:= FUID
or (FFragCombo
shl 16);
5720 if (FComboEvnt
>= Low(gDelayedEvents
)) and
5721 (FComboEvnt
<= High(gDelayedEvents
)) and
5722 gDelayedEvents
[FComboEvnt
].Pending
and
5723 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
5724 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
5726 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
5727 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
5730 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
5738 procedure TPlayer
.GiveItem(ItemType
: Byte);
5742 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
5744 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
5748 if FAir
< AIR_MAX
then
5755 if not (R_BERSERK
in FRulez
) then
5757 Include(FRulez
, R_BERSERK
);
5758 if FBFGFireCounter
< 1 then
5760 FCurrWeap
:= WEAPON_KASTET
;
5762 FModel
.SetWeapon(WEAPON_KASTET
);
5766 FBerserk
:= gTime
+30000;
5768 if FHealth
< PLAYER_HP_SOFT
then
5770 FHealth
:= PLAYER_HP_SOFT
;
5771 FBerserk
:= gTime
+30000;
5776 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
5778 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
5782 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
5784 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
5788 if FJetFuel
< JET_MAX
then
5790 FJetFuel
:= JET_MAX
;
5793 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
5794 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
5796 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
5797 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5799 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
5801 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
5803 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
5804 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5807 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
5808 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
5809 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
5810 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
5811 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
5812 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
5813 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
5814 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
5815 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
5817 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5818 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
5819 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5820 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
5821 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5822 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
5823 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5824 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
5825 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
5828 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
5829 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
5830 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
5831 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
5832 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
5834 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
5835 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
5836 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
5837 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
5838 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
5840 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5841 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5842 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5843 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5845 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
5848 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
5849 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
5850 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
5852 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
5853 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
5858 if g_Game_IsNet
and g_Game_IsServer
then
5859 MH_SEND_PlayerStats(FUID
);
5862 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
5867 if (Random(5) = 1) and (Times
= 1) then
5870 if BodyInLiquid(0, 0) then
5872 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
5873 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
5874 if Random(2) = 0 then
5875 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5877 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5881 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
5883 for i
:= 1 to Times
do
5885 Anim
:= TAnimation
.Create(id
, False, 3);
5887 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
5888 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
5894 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
5899 if (Random(10) = 1) and (Times
= 1) then
5902 if g_Frames_Get(id
, 'FRAMES_FLAME') then
5904 for i
:= 1 to Times
do
5906 Anim
:= TAnimation
.Create(id
, False, 3);
5908 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
5909 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
5915 procedure TPlayer
.PauseSounds(Enable
: Boolean);
5917 FSawSound
.Pause(Enable
);
5918 FSawSoundIdle
.Pause(Enable
);
5919 FSawSoundHit
.Pause(Enable
);
5920 FSawSoundSelect
.Pause(Enable
);
5925 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
5930 FObj
.Rect
:= PLAYER_CORPSERECT
;
5931 FModelName
:= ModelName
;
5936 FState
:= CORPSE_STATE_MESS
;
5937 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
5941 FState
:= CORPSE_STATE_NORMAL
;
5942 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
5946 destructor TCorpse
.Destroy();
5953 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
5957 if FState
= CORPSE_STATE_REMOVEME
then
5960 FDamage
:= FDamage
+ Value
;
5962 if FDamage
> 150 then
5964 if FAnimation
<> nil then
5969 FState
:= CORPSE_STATE_REMOVEME
;
5971 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
5972 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
5973 FModelName
, FColor
);
5974 // Çâóê ìÿñà îò òðóïà:
5975 pm
:= g_PlayerModel_Get(FModelName
);
5976 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
5982 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
5983 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
5984 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
5985 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
5986 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
5991 procedure TCorpse
.Draw();
5993 if FState
= CORPSE_STATE_REMOVEME
then
5996 if FAnimation
<> nil then
5997 FAnimation
.Draw(FObj
.X
, FObj
.Y
, M_NONE
);
5999 if FAnimationMask
<> nil then
6002 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, M_NONE
);
6009 procedure TCorpse
.Update();
6013 if FState
= CORPSE_STATE_REMOVEME
then
6016 if gTime
mod (GAME_TICK
*2) <> 0 then
6018 g_Obj_Move(@FObj
, True, True, True);
6023 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6024 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6026 st
:= g_Obj_Move(@FObj
, True, True, True);
6028 if WordBool(st
and MOVE_FALLOUT
) then
6030 FState
:= CORPSE_STATE_REMOVEME
;
6034 if FAnimation
<> nil then
6035 FAnimation
.Update();
6036 if FAnimationMask
<> nil then
6037 FAnimationMask
.Update();
6040 procedure TCorpse
.SaveState(var Mem
: TBinMemoryWriter
);
6049 sig
:= CORPSE_SIGNATURE
; // 'CORP'
6050 Mem
.WriteDWORD(sig
);
6052 Mem
.WriteByte(FState
);
6053 // Íàêîïëåííûé óðîí:
6054 Mem
.WriteByte(FDamage
);
6056 Mem
.WriteByte(FColor
.R
);
6057 Mem
.WriteByte(FColor
.G
);
6058 Mem
.WriteByte(FColor
.B
);
6060 Obj_SaveState(@FObj
, Mem
);
6061 // Åñòü ëè àíèìàöèÿ:
6062 anim
:= FAnimation
<> nil;
6063 Mem
.WriteBoolean(anim
);
6064 // Åñëè åñòü - ñîõðàíÿåì:
6066 FAnimation
.SaveState(Mem
);
6067 // Åñòü ëè ìàñêà àíèìàöèè:
6068 anim
:= FAnimationMask
<> nil;
6069 Mem
.WriteBoolean(anim
);
6070 // Åñëè åñòü - ñîõðàíÿåì:
6072 FAnimationMask
.SaveState(Mem
);
6075 procedure TCorpse
.LoadState(var Mem
: TBinMemoryReader
);
6085 if sig
<> CORPSE_SIGNATURE
then // 'CORP'
6087 raise EBinSizeError
.Create('TCorpse.LoadState: Wrong Corpse Signature');
6090 Mem
.ReadByte(FState
);
6091 // Íàêîïëåííûé óðîí:
6092 Mem
.ReadByte(FDamage
);
6094 Mem
.ReadByte(FColor
.R
);
6095 Mem
.ReadByte(FColor
.G
);
6096 Mem
.ReadByte(FColor
.B
);
6098 Obj_LoadState(@FObj
, Mem
);
6099 // Åñòü ëè àíèìàöèÿ:
6100 Mem
.ReadBoolean(anim
);
6101 // Åñëè åñòü - çàãðóæàåì:
6104 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6105 FAnimation
.LoadState(Mem
);
6107 // Åñòü ëè ìàñêà àíèìàöèè:
6108 Mem
.ReadBoolean(anim
);
6109 // Åñëè åñòü - çàãðóæàåì:
6112 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6113 FAnimationMask
.LoadState(Mem
);
6119 constructor TBot
.Create();
6126 FSpectator
:= False;
6133 for a
:= WP_FIRST
to WP_LAST
do
6135 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6136 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6137 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6141 destructor TBot
.Destroy();
6144 inherited Destroy();
6147 procedure TBot
.Draw();
6151 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6152 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6155 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6157 inherited Respawn(Silent
, Force
);
6160 FSelectedWeapon
:= FCurrWeap
;
6165 procedure TBot
.UpdateCombat();
6178 TTargetRecord
= array of TTarget
;
6180 function Compare(a
, b
: TTarget
): Integer;
6182 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6185 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6187 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6188 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6190 if a
.Dist
> b
.Dist
then // B áëèæå
6192 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6195 else // Ñòðàííî -> A
6200 a
, x1
, y1
, x2
, y2
: Integer;
6201 targets
: TTargetRecord
;
6203 Target
, BestTarget
: TTarget
;
6204 firew
, fireh
: Integer;
6208 vsPlayer
, vsMonster
, ok
: Boolean;
6210 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6211 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6213 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6214 if FCurrWeap
<> FSelectedWeapon
then
6217 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6218 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6220 RemoveAIFlag('NEEDFIRE');
6223 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6224 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6225 else PressKey(KEY_FIRE
);
6229 // Êîîðäèíàòû ñòâîëà:
6230 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6231 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6233 Target
.UID
:= FTargetUID
;
6236 if Target
.UID
<> 0 then
6237 begin // Öåëü åñòü - íàñòðàèâàåì
6238 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6241 with g_Player_Get(Target
.UID
) do
6243 if (@FObj
) <> nil then
6250 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6251 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6252 Target
.Rect
:= PLAYER_RECT
;
6253 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6254 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6255 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6256 Target
.IsPlayer
:= True;
6260 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6263 mon
:= g_Monsters_Get(Target
.UID
);
6266 Target
.X
:= mon
.Obj
.X
;
6267 Target
.Y
:= mon
.Obj
.Y
;
6269 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6270 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6271 Target
.Rect
:= mon
.Obj
.Rect
;
6272 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6273 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6274 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6275 Target
.IsPlayer
:= False;
6282 begin // Öåëè íåò - îáíóëÿåì
6287 Target
.Visible
:= False;
6288 Target
.Line
:= False;
6289 Target
.IsPlayer
:= False;
6294 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6295 if (not Target
.Line
) or (not Target
.Visible
) then
6299 for a
:= 0 to High(gPlayers
) do
6300 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].Live
) and
6301 (gPlayers
[a
].FUID
<> FUID
) and
6302 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6303 (not gPlayers
[a
].NoTarget
) and
6304 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6306 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6307 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6310 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6311 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6313 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6314 if g_TraceVector(x1
, y1
, x2
, y2
) then
6316 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6317 SetLength(targets
, Length(targets
)+1);
6318 with targets
[High(targets
)] do
6320 UID
:= gPlayers
[a
].FUID
;
6321 X
:= gPlayers
[a
].FObj
.X
;
6322 Y
:= gPlayers
[a
].FObj
.Y
;
6325 Rect
:= PLAYER_RECT
;
6326 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6327 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6328 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6336 if vsMonster
and (gMonsters
<> nil) then
6337 for a
:= 0 to High(gMonsters
) do
6338 if (gMonsters
[a
] <> nil) and (gMonsters
[a
].Live
) and
6339 (gMonsters
[a
].MonsterType
<> MONSTER_BARREL
) then
6341 mon
:= gMonsters
[a
];
6343 if not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
6344 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
) then
6347 x2
:= mon
.Obj
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6348 y2
:= mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6350 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6351 if g_TraceVector(x1
, y1
, x2
, y2
) then
6353 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6354 SetLength(targets
, Length(targets
)+1);
6355 with targets
[High(targets
)] do
6362 Rect
:= mon
.Obj
.Rect
;
6363 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6364 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6365 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6373 // Åñëè åñòü âîçìîæíûå öåëè:
6374 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6375 if targets
<> nil then
6377 // Âûáèðàåì íàèëó÷øóþ öåëü:
6378 BestTarget
:= targets
[0];
6379 if Length(targets
) > 1 then
6380 for a
:= 1 to High(targets
) do
6381 if Compare(BestTarget
, targets
[a
]) = 1 then
6382 BestTarget
:= targets
[a
];
6384 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6385 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6386 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6388 Target
:= BestTarget
;
6390 if (Healthy() = 3) or ((Healthy() = 2)) then
6391 begin // Åñëè çäîðîâû - äîãîíÿåì
6392 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6393 SetAIFlag('GORIGHT', '1');
6394 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6395 SetAIFlag('GOLEFT', '1');
6398 begin // Åñëè ïîáèòû - óáåãàåì
6399 if ((RunDirection() = D_LEFT
) and (Target
.X
< FObj
.X
)) then
6400 SetAIFlag('GORIGHT', '1');
6401 if ((RunDirection() = D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6402 SetAIFlag('GOLEFT', '1');
6405 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6406 SelectWeapon(Abs(x1
-Target
.cX
));
6411 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6412 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6413 if Target
.UID
<> 0 then
6415 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6416 Target
.Y
+ Target
.Rect
.Y
) then
6417 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6418 if (Healthy() = 3) or ((Healthy() = 2)) then
6419 begin // Åñëè çäîðîâû - äîãîíÿåì
6420 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6421 SetAIFlag('GORIGHT', '1');
6422 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6423 SetAIFlag('GOLEFT', '1');
6426 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6428 if ((RunDirection() = D_LEFT
) and (Target
.X
< FObj
.X
)) then
6429 SetAIFlag('GORIGHT', '1');
6430 if ((RunDirection() = D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6431 SetAIFlag('GOLEFT', '1');
6435 begin // Öåëü ïîêà íà "ýêðàíå"
6436 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6437 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6438 FLastVisible
:= gTime
;
6439 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6440 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6442 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6443 SetAIFlag('GORIGHT', '1');
6444 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6445 SetAIFlag('GOLEFT', '1');
6449 // Âûáèðàåì óãîë ââåðõ:
6450 if FDirection
= D_LEFT
then
6451 angle
:= ANGLE_LEFTUP
6453 angle
:= ANGLE_RIGHTUP
;
6455 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6456 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6458 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6459 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6460 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6461 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6462 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6463 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6464 begin // òî íóæíî ñòðåëÿòü ââåðõ
6465 SetAIFlag('NEEDFIRE', '1');
6466 SetAIFlag('NEEDSEEUP', '1');
6469 // Âûáèðàåì óãîë âíèç:
6470 if FDirection
= D_LEFT
then
6471 angle
:= ANGLE_LEFTDOWN
6473 angle
:= ANGLE_RIGHTDOWN
;
6475 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6476 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6478 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6479 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6480 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6481 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6482 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6483 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6484 begin // òî íóæíî ñòðåëÿòü âíèç
6485 SetAIFlag('NEEDFIRE', '1');
6486 SetAIFlag('NEEDSEEDOWN', '1');
6489 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6490 if Target
.Visible
and
6491 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6492 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6494 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6495 if ((FDirection
= D_LEFT
) and (Target
.X
< FObj
.X
)) or
6496 ((FDirection
= D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6497 begin // òî íóæíî ñòðåëÿòü âïåðåä
6498 SetAIFlag('NEEDFIRE', '1');
6499 SetAIFlag('NEEDSEEDOWN', '');
6500 SetAIFlag('NEEDSEEUP', '');
6502 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6503 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6504 if GetRnd(FDifficult
.CloseJump
) then
6505 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6506 if Abs(FObj
.X
-Target
.X
) < 128 then
6510 if Random(a
) = 0 then
6511 SetAIFlag('NEEDJUMP', '1');
6515 // Åñëè öåëü âñå åùå åñòü:
6516 if Target
.UID
<> 0 then
6517 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
6518 Target
.UID
:= 0 // òî çàáûòü öåëü
6519 else // Åñëè âèäåëè íåäàâíî
6520 begin // íî öåëü óáèëè
6521 if Target
.IsPlayer
then
6522 begin // Öåëü - èãðîê
6523 pla
:= g_Player_Get(Target
.UID
);
6524 if (pla
= nil) or (not pla
.Live
) or pla
.NoTarget
or
6525 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6526 Target
.UID
:= 0; // òî çàáûòü öåëü
6529 begin // Öåëü - ìîíñòð
6530 mon
:= g_Monsters_Get(Target
.UID
);
6531 if (mon
= nil) or (not mon
.Live
) then
6532 Target
.UID
:= 0; // òî çàáûòü öåëü
6535 end; // if Target.UID <> 0
6537 FTargetUID
:= Target
.UID
;
6539 // Åñëè âîçìîæíûõ öåëåé íåò:
6540 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
6541 if targets
= nil then
6542 if GetAIFlag('ATTACKLEFT') <> '' then
6543 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
6544 RemoveAIFlag('ATTACKLEFT');
6546 SetAIFlag('NEEDJUMP', '1');
6548 if RunDirection() = D_RIGHT
then
6549 begin // Èäåì íå â òó ñòîðîíó
6550 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6551 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
6552 SetAIFlag('NEEDFIRE', '1');
6553 SetAIFlag('GOLEFT', '1');
6557 begin // Èäåì â íóæíóþ ñòîðîíó
6558 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6559 SetAIFlag('NEEDFIRE', '1');
6560 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6561 SetAIFlag('GORIGHT', '1');
6565 if GetAIFlag('ATTACKRIGHT') <> '' then
6566 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
6567 RemoveAIFlag('ATTACKRIGHT');
6569 SetAIFlag('NEEDJUMP', '1');
6571 if RunDirection() = D_LEFT
then
6572 begin // Èäåì íå â òó ñòîðîíó
6573 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6574 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
6575 SetAIFlag('NEEDFIRE', '1');
6576 SetAIFlag('GORIGHT', '1');
6581 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6582 SetAIFlag('NEEDFIRE', '1');
6583 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6584 SetAIFlag('GOLEFT', '1');
6588 //HACK! (does it belongs there?)
6589 RealizeCurrentWeapon();
6591 // Åñëè åñòü âîçìîæíûå öåëè:
6592 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
6593 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6594 for a
:= 0 to High(targets
) do
6596 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
6597 if GetRnd(FDifficult
.DiagFire
) then
6599 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
6600 if FDirection
= D_LEFT
then
6601 angle
:= ANGLE_LEFTUP
6603 angle
:= ANGLE_RIGHTUP
;
6605 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6606 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6608 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6609 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6610 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6611 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6612 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6614 SetAIFlag('NEEDFIRE', '1');
6615 SetAIFlag('NEEDSEEUP', '1');
6618 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
6619 if FDirection
= D_LEFT
then
6620 angle
:= ANGLE_LEFTDOWN
6622 angle
:= ANGLE_RIGHTDOWN
;
6624 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6625 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6627 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6628 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6629 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6630 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6631 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6633 SetAIFlag('NEEDFIRE', '1');
6634 SetAIFlag('NEEDSEEDOWN', '1');
6638 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
6639 if targets
[a
].Line
and targets
[a
].Visible
and
6640 (((FDirection
= D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
6641 ((FDirection
= D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
6643 SetAIFlag('NEEDFIRE', '1');
6648 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
6649 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
6650 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
6651 40+GetInterval(FDifficult
.Cover
, 40)) then
6652 SetAIFlag('NEEDJUMP', '1');
6654 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
6655 ammo
:= GetAmmoByWeapon(FCurrWeap
);
6656 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
6657 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
6659 SetAIFlag('SELECTWEAPON', '1');
6661 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
6662 if GetAIFlag('SELECTWEAPON') = '1' then
6665 RemoveAIFlag('SELECTWEAPON');
6669 procedure TBot
.Update();
6682 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
6683 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
6685 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
6687 if g_debug_BotAIOff
= 3 then
6697 RealizeCurrentWeapon();
6704 procedure TBot
.ReleaseKey(Key
: Byte);
6713 function TBot
.KeyPressed(Key
: Word): Boolean;
6715 Result
:= FKeys
[Key
].Pressed
;
6718 function TBot
.GetAIFlag(fName
: String20
): String20
;
6724 fName
:= LowerCase(fName
);
6726 if FAIFlags
<> nil then
6727 for a
:= 0 to High(FAIFlags
) do
6728 if LowerCase(FAIFlags
[a
].Name
) = fName
then
6730 Result
:= FAIFlags
[a
].Value
;
6735 procedure TBot
.RemoveAIFlag(fName
: String20
);
6739 if FAIFlags
= nil then Exit
;
6741 fName
:= LowerCase(fName
);
6743 for a
:= 0 to High(FAIFlags
) do
6744 if LowerCase(FAIFlags
[a
].Name
) = fName
then
6746 if a
<> High(FAIFlags
) then
6747 for b
:= a
to High(FAIFlags
)-1 do
6748 FAIFlags
[b
] := FAIFlags
[b
+1];
6750 SetLength(FAIFlags
, Length(FAIFlags
)-1);
6755 procedure TBot
.SetAIFlag(fName
, fValue
: String20
);
6763 fName
:= LowerCase(fName
);
6765 if FAIFlags
<> nil then
6766 for a
:= 0 to High(FAIFlags
) do
6767 if LowerCase(FAIFlags
[a
].Name
) = fName
then
6773 if ok
then FAIFlags
[a
].Value
:= fValue
6776 SetLength(FAIFlags
, Length(FAIFlags
)+1);
6777 with FAIFlags
[High(FAIFlags
)] do
6785 procedure TBot
.UpdateMove
;
6787 procedure GoLeft(Time
: Word = 1);
6789 ReleaseKey(KEY_LEFT
);
6790 ReleaseKey(KEY_RIGHT
);
6791 PressKey(KEY_LEFT
, Time
);
6792 SetDirection(D_LEFT
);
6795 procedure GoRight(Time
: Word = 1);
6797 ReleaseKey(KEY_LEFT
);
6798 ReleaseKey(KEY_RIGHT
);
6799 PressKey(KEY_RIGHT
, Time
);
6800 SetDirection(D_RIGHT
);
6803 function Rnd(a
: Word): Boolean;
6805 Result
:= Random(a
) = 0;
6808 procedure Turn(Time
: Word = 1200);
6810 if RunDirection() = D_LEFT
then GoRight(Time
) else GoLeft(Time
);
6815 ReleaseKey(KEY_LEFT
);
6816 ReleaseKey(KEY_RIGHT
);
6819 function CanRunLeft(): Boolean;
6821 Result
:= not CollideLevel(-1, 0);
6824 function CanRunRight(): Boolean;
6826 Result
:= not CollideLevel(1, 0);
6829 function CanRun(): Boolean;
6831 if RunDirection() = D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
6834 procedure Jump(Time
: Word = 30);
6836 PressKey(KEY_JUMP
, Time
);
6839 function NearHole(): Boolean;
6843 { TODO 5 : Ëåñòíèöû }
6844 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6845 for x
:= 1 to PLAYER_RECT
.Width
do
6846 if (not StayOnStep(x
*sx
, 0)) and
6847 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6848 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6857 function BorderHole(): Boolean;
6861 { TODO 5 : Ëåñòíèöû }
6862 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6863 for x
:= 1 to PLAYER_RECT
.Width
do
6864 if (not StayOnStep(x
*sx
, 0)) and
6865 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6866 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6868 for xx
:= x
to x
+32 do
6869 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
6879 function NearDeepHole(): Boolean;
6885 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6888 for x
:= 1 to PLAYER_RECT
.Width
do
6889 if (not StayOnStep(x
*sx
, 0)) and
6890 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6891 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6893 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6895 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
6900 end else Result
:= False;
6903 function OverDeepHole(): Boolean;
6910 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6912 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
6919 function OnGround(): Boolean;
6921 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
6924 function OnLadder(): Boolean;
6926 Result
:= FullInStep(0, 0);
6929 function BelowLadder(): Boolean;
6931 Result
:= (FullInStep(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
6932 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
6933 (FullInStep(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
6934 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
6937 function BelowLiftUp(): Boolean;
6939 Result
:= ((FullInLift(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
6940 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
6941 ((FullInLift(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
6942 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
6945 function OnTopLift(): Boolean;
6947 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
6950 function CanJumpOver(): Boolean;
6954 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6958 if not CollideLevel(sx
, 0) then Exit
;
6960 for y
:= 1 to BOT_MAXJUMP
do
6961 if CollideLevel(0, -y
) then Exit
else
6962 if not CollideLevel(sx
, -y
) then
6969 function CanJumpUp(Dist
: ShortInt
): Boolean;
6976 if CollideLevel(Dist
, 0) then Exit
;
6979 for y
:= 0 to BOT_MAXJUMP
do
6980 if CollideLevel(Dist
, -y
) then
6989 for yy
:= y
+1 to BOT_MAXJUMP
do
6990 if not CollideLevel(Dist
, -yy
) then
6999 for y
:= 0 to BOT_MAXJUMP
do
7000 if CollideLevel(0, -y
) then
7008 if y
< yy
then Exit
;
7013 function IsSafeTrigger(): Boolean;
7018 if gTriggers
= nil then
7020 for a
:= 0 to High(gTriggers
) do
7021 if Collide(gTriggers
[a
].X
,
7024 gTriggers
[a
].Height
) and
7025 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7026 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7027 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7028 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7029 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7034 // Âîçìîæíî, íàæèìàåì êíîïêó:
7035 if Rnd(16) and IsSafeTrigger() then
7038 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7039 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7041 ReleaseKey(KEY_LEFT
);
7042 ReleaseKey(KEY_RIGHT
);
7046 // Èäåì âëåâî, åñëè íàäî áûëî:
7047 if GetAIFlag('GOLEFT') <> '' then
7049 RemoveAIFlag('GOLEFT');
7050 if CanRunLeft() then
7054 // Èäåì âïðàâî, åñëè íàäî áûëî:
7055 if GetAIFlag('GORIGHT') <> '' then
7057 RemoveAIFlag('GORIGHT');
7058 if CanRunRight() then
7062 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7063 if FObj
.X
< -32 then
7066 if FObj
.X
+32 > gMapInfo
.Width
then
7069 // Ïðûãàåì, åñëè íàäî áûëî:
7070 if GetAIFlag('NEEDJUMP') <> '' then
7073 RemoveAIFlag('NEEDJUMP');
7076 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7077 if GetAIFlag('NEEDSEEUP') <> '' then
7080 ReleaseKey(KEY_DOWN
);
7081 PressKey(KEY_UP
, 20);
7082 RemoveAIFlag('NEEDSEEUP');
7085 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7086 if GetAIFlag('NEEDSEEDOWN') <> '' then
7089 ReleaseKey(KEY_DOWN
);
7090 PressKey(KEY_DOWN
, 20);
7091 RemoveAIFlag('NEEDSEEDOWN');
7094 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7095 if GetAIFlag('GOINHOLE') <> '' then
7096 if not OnGround() then
7098 ReleaseKey(KEY_LEFT
);
7099 ReleaseKey(KEY_RIGHT
);
7100 RemoveAIFlag('GOINHOLE');
7101 SetAIFlag('FALLINHOLE', '1');
7104 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7105 if GetAIFlag('FALLINHOLE') <> '' then
7107 RemoveAIFlag('FALLINHOLE');
7109 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7110 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7111 if GetAIFlag('FALLINHOLE') = '' then
7112 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7118 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7120 CanJumpUp(IfThen(RunDirection() = D_LEFT
, -1, 1)*32) and
7124 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7125 if OnGround() and NearHole() then
7126 if NearDeepHole() then // Åñëè ýòî áåçäíà
7128 0..3: Turn(); // Áåæèì îáðàòíî
7129 4: Jump(); // Ïðûãàåì
7130 5: begin // Ïðûãàåì îáðàòíî
7135 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7136 if GetAIFlag('GOINHOLE') = '' then
7138 0: Turn(); // Íå íóæíî òóäà
7139 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7140 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7141 if BorderHole() then
7142 SetAIFlag('GOINHOLE', '1');
7145 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7146 if (not CanRun()) and OnGround() then
7148 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7149 if CanJumpOver() or OnLadder() then
7151 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7152 if Random(2) = 0 then
7154 if IsSafeTrigger() then
7160 // Îñòàëîñü ìàëî âîçäóõà:
7161 if FAir
< 36 * 2 then
7164 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7165 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7166 if BodyInAcid(0, 0) then
7170 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7172 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7173 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7176 {function TBot.NeedItem(Item: Byte): Byte;
7181 procedure TBot
.SelectWeapon(Dist
: Integer);
7185 function HaveAmmo(weapon
: Byte): Boolean;
7188 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7189 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7190 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7191 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7192 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7193 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7194 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7195 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7196 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7197 else Result
:= True;
7202 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7204 if Dist
> BOT_LONGDIST
then
7205 begin // Äàëüíèé áîé
7207 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7209 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7213 else //if Dist > BOT_UNSAFEDIST then
7214 begin // Áëèæíèé áîé
7216 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7218 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7225 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7227 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7233 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7235 Result
:= inherited PickItem(ItemType
, force
, remove
);
7237 if Result
then SetAIFlag('SELECTWEAPON', '1');
7240 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7242 Result
:= inherited Heal(value
, Soft
);
7245 function TBot
.Healthy(): Byte;
7247 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7248 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7249 else if (FHealth
> 50) then Result
:= 2
7250 else if (FHealth
> 20) then Result
:= 1
7254 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7256 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7257 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7260 procedure TBot
.OnDamage(Angle
: SmallInt
);
7268 if (Angle
= 0) or (Angle
= 180) then
7271 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7272 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7274 pla
:= g_Player_Get(FLastSpawnerUID
);
7275 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7276 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7279 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7280 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7282 mon
:= g_Monsters_Get(FLastSpawnerUID
);
7283 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7284 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7289 SetAIFlag('ATTACKLEFT', '1')
7291 SetAIFlag('ATTACKRIGHT', '1');
7295 function TBot
.RunDirection(): TDirection
;
7297 if Abs(Vel
.X
) >= 1 then
7299 if Vel
.X
> 0 then Result
:= D_RIGHT
else Result
:= D_LEFT
;
7301 Result
:= FDirection
;
7304 function TBot
.GetRnd(a
: Byte): Boolean;
7306 if a
= 0 then Result
:= False
7307 else if a
= 255 then Result
:= True
7308 else Result
:= Random(256) > 255-a
;
7311 function TBot
.GetInterval(a
: Byte; radius
: SmallInt
): SmallInt
;
7313 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7316 procedure TBot
.SaveState(var Mem
: TBinMemoryWriter
);
7322 inherited SaveState(Mem
);
7324 // Âûáðàííîå îðóæèå:
7325 Mem
.WriteByte(FSelectedWeapon
);
7327 Mem
.WriteWord(FTargetUID
);
7328 // Âðåìÿ ïîòåðè öåëè:
7329 Mem
.WriteDWORD(FLastVisible
);
7330 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7331 dw
:= Length(FAIFlags
);
7334 for i
:= 0 to Integer(dw
)-1 do
7336 Mem
.WriteString(FAIFlags
[i
].Name
, 20);
7337 Mem
.WriteString(FAIFlags
[i
].Value
, 20);
7339 // Íàñòðîéêè ñëîæíîñòè:
7341 Mem
.WriteMemory(p
, SizeOf(TDifficult
));
7344 procedure TBot
.LoadState(var Mem
: TBinMemoryReader
);
7350 inherited LoadState(Mem
);
7352 // Âûáðàííîå îðóæèå:
7353 Mem
.ReadByte(FSelectedWeapon
);
7355 Mem
.ReadWord(FTargetUID
);
7356 // Âðåìÿ ïîòåðè öåëè:
7357 Mem
.ReadDWORD(FLastVisible
);
7358 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7360 SetLength(FAIFlags
, dw
);
7362 for i
:= 0 to Integer(dw
)-1 do
7364 Mem
.ReadString(FAIFlags
[i
].Name
);
7365 Mem
.ReadString(FAIFlags
[i
].Value
);
7367 // Íàñòðîéêè ñëîæíîñòè:
7368 Mem
.ReadMemory(p
, dw
);
7369 if dw
<> SizeOf(TDifficult
) then
7371 raise EBinSizeError
.Create('TBot.LoadState: Wrong FDifficult Size');
7373 FDifficult
:= TDifficult(p
^);