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/>.
16 {$INCLUDE ../shared/a_modes.inc}
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;
173 FSavedState
: TPlayerSavedState
;
175 FModel
: TPlayerModel
;
178 FActionForce
: Boolean;
179 FActionChanged
: Boolean;
181 FFireAngle
: SmallInt;
183 FShellTimer
: Integer;
185 FSawSound
: TPlayableSound
;
186 FSawSoundIdle
: TPlayableSound
;
187 FSawSoundHit
: TPlayableSound
;
188 FSawSoundSelect
: TPlayableSound
;
189 FJetSoundOn
: TPlayableSound
;
190 FJetSoundOff
: TPlayableSound
;
191 FJetSoundFly
: TPlayableSound
;
195 FJustTeleported
: Boolean;
198 function CollideLevel(XInc
, YInc
: Integer): Boolean;
199 function StayOnStep(XInc
, YInc
: Integer): Boolean;
200 function HeadInLiquid(XInc
, YInc
: Integer): Boolean;
201 function BodyInLiquid(XInc
, YInc
: Integer): Boolean;
202 function BodyInAcid(XInc
, YInc
: Integer): Boolean;
203 function FullInLift(XInc
, YInc
: Integer): Integer;
204 {procedure CollideItem();}
205 procedure FlySmoke(Times
: DWORD
= 1);
206 procedure OnFireFlame(Times
: DWORD
= 1);
207 function GetAmmoByWeapon(Weapon
: Byte): Word;
208 procedure SetAction(Action
: Byte; Force
: Boolean = False);
209 procedure OnDamage(Angle
: SmallInt); virtual;
210 function firediry(): Integer;
212 procedure Run(Direction
: TDirection
);
213 procedure NextWeapon();
214 procedure PrevWeapon();
221 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
222 procedure resetWeaponQueue ();
223 function hasAmmoForWeapon (weapon
: Byte): Boolean;
226 FDamageBuffer
: Integer;
228 FAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
229 FMaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
230 FWeapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
231 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
233 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
234 FReloading
: Array [WP_FIRST
..WP_LAST
] of Word;
235 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
236 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
238 FPreferredTeam
: Byte;
241 FWantsInGame
: Boolean;
245 FActualModelName
: string;
252 constructor Create(); virtual;
253 destructor Destroy(); override;
254 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
255 function GetRespawnPoint(): Byte;
256 procedure PressKey(Key
: Byte; Time
: Word = 1);
257 procedure ReleaseKeys();
258 procedure SetModel(ModelName
: String);
259 procedure SetColor(Color
: TRGB
);
260 procedure SetWeapon(W
: Byte);
261 function IsKeyPressed(K
: Byte): Boolean;
262 function GetKeys(): Byte;
263 function PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean; virtual;
264 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
265 function Collide(Panel
: TPanel
): Boolean; overload
;
266 function Collide(X
, Y
: Integer): Boolean; overload
;
267 procedure SetDirection(Direction
: TDirection
);
268 procedure GetSecret();
269 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
271 procedure Push(vx
, vy
: Integer);
272 procedure ChangeModel(ModelName
: String);
273 procedure SwitchTeam
;
274 procedure ChangeTeam(Team
: Byte);
276 function GetFlag(Flag
: Byte): Boolean;
277 procedure SetFlag(Flag
: Byte);
278 function DropFlag(): Boolean;
279 procedure AllRulez(Health
: Boolean);
280 procedure RestoreHealthArmor();
281 procedure FragCombo();
282 procedure GiveItem(ItemType
: Byte);
283 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
284 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
285 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
286 procedure MakeBloodSimple(Count
: Word);
287 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
288 procedure Reset(Force
: Boolean);
289 procedure Spectate(NoMove
: Boolean = False);
290 procedure SwitchNoClip
;
291 procedure SoftReset();
292 procedure Draw(); virtual;
293 procedure DrawPain();
294 procedure DrawPickup();
295 procedure DrawRulez();
297 procedure DrawBubble();
299 procedure Update(); virtual;
300 procedure RememberState();
301 procedure RecallState();
302 procedure SaveState(var Mem
: TBinMemoryWriter
); virtual;
303 procedure LoadState(var Mem
: TBinMemoryReader
); virtual;
304 procedure PauseSounds(Enable
: Boolean);
305 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
306 procedure DoLerp(Level
: Integer = 2);
307 procedure SetLerp(XTo
, YTo
: Integer);
308 procedure QueueWeaponSwitch(Weapon
: Byte);
309 procedure RealizeCurrentWeapon();
311 procedure JetpackOff
;
312 procedure CatchFire(Attacker
: Word);
314 //WARNING! this does nothing for now, but still call it!
315 procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right!
317 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
319 property Name
: String read FName write FName
;
320 property Model
: TPlayerModel read FModel
;
321 property Health
: Integer read FHealth write FHealth
;
322 property Lives
: Byte read FLives write FLives
;
323 property Armor
: Integer read FArmor write FArmor
;
324 property Air
: Integer read FAir write FAir
;
325 property JetFuel
: Integer read FJetFuel write FJetFuel
;
326 property Frags
: Integer read FFrags write FFrags
;
327 property Death
: Integer read FDeath write FDeath
;
328 property Kills
: Integer read FKills write FKills
;
329 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
330 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
331 property Secrets
: Integer read FSecrets
;
332 property GodMode
: Boolean read FGodMode write FGodMode
;
333 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
334 property NoReload
: Boolean read FNoReload write FNoReload
;
335 property Live
: Boolean read FLive write FLive
;
336 property Flag
: Byte read FFlag
;
337 property Team
: Byte read FTeam write FTeam
;
338 property Direction
: TDirection read FDirection
;
339 property GameX
: Integer read FObj
.X write FObj
.X
;
340 property GameY
: Integer read FObj
.Y write FObj
.Y
;
341 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
342 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
343 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
344 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
345 property Vel
: TPoint2i read FObj
.Vel
;
346 property Obj
: TObj read FObj
;
347 property IncCam
: Integer read FIncCam write FIncCam
;
348 property UID
: Word read FUID write FUID
;
349 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
350 property NetTime
: LongWord read FNetTime write FNetTime
;
360 WeaponPrior
: Array [WP_FIRST
..WP_LAST
] of Byte;
361 CloseWeaponPrior
: Array [WP_FIRST
..WP_LAST
] of Byte;
362 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
370 TBot
= class (TPlayer
)
372 FSelectedWeapon
: Byte;
375 FAIFlags
: Array of TAIFlag
;
376 FDifficult
: TDifficult
;
378 function GetRnd(a
: Byte): Boolean;
379 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
380 function RunDirection(): TDirection
;
381 function FullInStep(XInc
, YInc
: Integer): Boolean;
382 //function NeedItem(Item: Byte): Byte;
383 procedure SelectWeapon(Dist
: Integer);
384 procedure SetAIFlag(aName
, fValue
: String20
);
385 function GetAIFlag(aName
: String20
): String20
;
386 procedure RemoveAIFlag(aName
: String20
);
387 function Healthy(): Byte;
388 procedure UpdateMove();
389 procedure UpdateCombat();
390 function KeyPressed(Key
: Word): Boolean;
391 procedure ReleaseKey(Key
: Byte);
392 function TargetOnScreen(TX
, TY
: Integer): Boolean;
393 procedure OnDamage(Angle
: SmallInt); override;
396 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
397 constructor Create(); override;
398 destructor Destroy(); override;
399 procedure Draw(); override;
400 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
401 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
402 procedure Update(); override;
403 procedure SaveState(var Mem
: TBinMemoryWriter
); override;
404 procedure LoadState(var Mem
: TBinMemoryReader
); override;
415 procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right!
428 procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right!
431 TCorpse
= class (TObject
)
439 FAnimation
: TAnimation
;
440 FAnimationMask
: TAnimation
;
443 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
444 destructor Destroy(); override;
445 procedure Damage(Value
: Word; vx
, vy
: Integer);
448 procedure SaveState(var Mem
: TBinMemoryWriter
);
449 procedure LoadState(var Mem
: TBinMemoryReader
);
451 procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right!
453 property Obj
: TObj read FObj
;
454 property State
: Byte read FState
;
455 property Mess
: Boolean read FMess
;
458 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
464 gPlayers
: Array of TPlayer
;
465 gCorpses
: Array of TCorpse
;
466 gGibs
: Array of TGib
;
467 gShells
: Array of TShell
;
468 gTeamStat
: TTeamStat
;
469 gFly
: Boolean = False;
470 gAimLine
: Boolean = False;
471 gChatBubble
: Byte = 0;
475 MAX_RUNVEL
: Integer = 8;
476 VEL_JUMP
: Integer = 10;
477 SHELL_TIMEOUT
: Cardinal = 60000;
479 function Lerp(X
, Y
, Factor
: Integer): Integer;
481 procedure g_Gibs_SetMax(Count
: Word);
482 function g_Gibs_GetMax(): Word;
483 procedure g_Corpses_SetMax(Count
: Word);
484 function g_Corpses_GetMax(): Word;
485 procedure g_Shells_SetMax(Count
: Word);
486 function g_Shells_GetMax(): Word;
488 procedure g_Player_Init();
489 procedure g_Player_Free();
490 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
491 function g_Player_CreateFromState(var Mem
: TBinMemoryReader
): Word;
492 procedure g_Player_Remove(UID
: Word);
493 procedure g_Player_ResetTeams();
494 procedure g_Player_UpdateAll();
495 procedure g_Player_DrawAll();
496 procedure g_Player_DrawDebug(p
: TPlayer
);
497 procedure g_Player_DrawHealth();
498 procedure g_Player_RememberAll();
499 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
500 function g_Player_Get(UID
: Word): TPlayer
;
501 function g_Player_GetCount(): Byte;
502 function g_Player_GetStats(): TPlayerStatArray
;
503 function g_Player_ValidName(Name
: String): Boolean;
504 procedure g_Player_CreateCorpse(Player
: TPlayer
);
505 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
506 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
507 procedure g_Player_UpdatePhysicalObjects();
508 procedure g_Player_DrawCorpses();
509 procedure g_Player_DrawShells();
510 procedure g_Player_RemoveAllCorpses();
511 procedure g_Player_Corpses_SaveState(var Mem
: TBinMemoryWriter
);
512 procedure g_Player_Corpses_LoadState(var Mem
: TBinMemoryReader
);
513 procedure g_Bot_Add(Team
, Difficult
: Byte);
514 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1);
515 procedure g_Bot_MixNames();
516 procedure g_Bot_RemoveAll();
521 e_log
, g_map
, g_items
, g_console
, SysUtils
, g_gfx
, Math
,
522 g_options
, g_triggers
, g_menu
, MAPDEF
, g_game
, g_grid
,
523 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
,
534 diag_precision
: Byte;
538 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
539 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
540 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
544 TIME_RESPAWN1
= 1500;
545 TIME_RESPAWN2
= 2000;
546 TIME_RESPAWN3
= 3000;
549 JET_MAX
= 540; // ~30 sec
550 PLAYER_SUIT_TIME
= 30000;
551 PLAYER_INVUL_TIME
= 30000;
552 PLAYER_INVIS_TIME
= 35000;
553 FRAG_COMBO_TIME
= 3000;
557 ANGLE_RIGHTDOWN
= -35;
559 ANGLE_LEFTDOWN
= -145;
560 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
561 WEAPONPOINT
: Array [TDirection
] of TPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
564 BOT_UNSAFEDIST
= 128;
565 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
567 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
568 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
569 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
570 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
571 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
572 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
573 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
574 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
575 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
576 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
577 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
578 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
579 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
580 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
581 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
582 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
583 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
584 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
585 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
586 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
587 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
588 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
589 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
590 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
591 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
592 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
594 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
595 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
597 BOTNAMES_FILENAME
= 'botnames.txt';
598 BOTLIST_FILENAME
= 'botlist.txt';
602 MaxCorpses
: Word = 20;
603 MaxShells
: Word = 300;
604 CurrentGib
: Integer = 0;
605 CurrentShell
: Integer = 0;
606 BotNames
: Array of String;
607 BotList
: Array of TBotProfile
;
610 procedure TGib
.positionChanged (); begin end;
611 procedure TShell
.positionChanged (); begin end;
614 function Lerp(X
, Y
, Factor
: Integer): Integer;
616 Result
:= X
+ ((Y
- X
) div Factor
);
619 function SameTeam(UID1
, UID2
: Word): Boolean;
623 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
624 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
626 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
628 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
629 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
631 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
634 procedure g_Gibs_SetMax(Count
: Word);
637 SetLength(gGibs
, Count
);
639 if CurrentGib
>= Count
then
643 function g_Gibs_GetMax(): Word;
648 procedure g_Shells_SetMax(Count
: Word);
651 SetLength(gShells
, Count
);
653 if CurrentShell
>= Count
then
657 function g_Shells_GetMax(): Word;
663 procedure g_Corpses_SetMax(Count
: Word);
666 SetLength(gCorpses
, Count
);
669 function g_Corpses_GetMax(): Word;
671 Result
:= MaxCorpses
;
674 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
684 // Åñòü ëè ìåñòî â gPlayers:
685 if gPlayers
<> nil then
686 for a
:= 0 to High(gPlayers
) do
687 if gPlayers
[a
] = nil then
693 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
696 SetLength(gPlayers
, Length(gPlayers
)+1);
700 // Ñîçäàåì îáúåêò èãðîêà:
702 gPlayers
[a
] := TBot
.Create()
704 gPlayers
[a
] := TPlayer
.Create();
707 gPlayers
[a
].FActualModelName
:= ModelName
;
708 gPlayers
[a
].SetModel(ModelName
);
710 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
711 if gPlayers
[a
].FModel
= nil then
715 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
719 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
720 if Random(2) = 0 then
724 gPlayers
[a
].FPreferredTeam
:= Team
;
726 case gGameSettings
.GameMode
of
727 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
729 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
731 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
734 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
735 gPlayers
[a
].FColor
:= Color
;
736 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
737 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
739 gPlayers
[a
].FModel
.Color
:= Color
;
741 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
742 gPlayers
[a
].FLive
:= False;
744 Result
:= gPlayers
[a
].FUID
;
747 function g_Player_CreateFromState(var Mem
: TBinMemoryReader
): Word;
760 if sig
<> PLAYER_SIGNATURE
then // 'PLYR'
762 raise EBinSizeError
.Create('g_Player_CreateFromState: Wrong Player Signature');
766 Mem
.ReadBoolean(Bot
);
771 // Åñòü ëè ìåñòî â gPlayers:
772 if gPlayers
<> nil then
773 for a
:= 0 to High(gPlayers
) do
774 if gPlayers
[a
] = nil then
780 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
783 SetLength(gPlayers
, Length(gPlayers
)+1);
787 // Ñîçäàåì îáúåêò èãðîêà:
789 gPlayers
[a
] := TBot
.Create()
791 gPlayers
[a
] := TPlayer
.Create();
792 gPlayers
[a
].FIamBot
:= Bot
;
793 gPlayers
[a
].FPhysics
:= True;
796 Mem
.ReadWord(gPlayers
[a
].FUID
);
798 Mem
.ReadString(gPlayers
[a
].FName
);
800 Mem
.ReadByte(gPlayers
[a
].FTeam
);
801 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
803 Mem
.ReadBoolean(gPlayers
[a
].FLive
);
804 // Èçðàñõîäîâàë ëè âñå æèçíè:
805 Mem
.ReadBoolean(gPlayers
[a
].FNoRespawn
);
809 gPlayers
[a
].FDirection
:= D_LEFT
811 gPlayers
[a
].FDirection
:= D_RIGHT
;
813 Mem
.ReadInt(gPlayers
[a
].FHealth
);
815 Mem
.ReadByte(gPlayers
[a
].FLives
);
817 Mem
.ReadInt(gPlayers
[a
].FArmor
);
819 Mem
.ReadInt(gPlayers
[a
].FAir
);
821 Mem
.ReadInt(gPlayers
[a
].FJetFuel
);
823 Mem
.ReadInt(gPlayers
[a
].FPain
);
825 Mem
.ReadInt(gPlayers
[a
].FKills
);
827 Mem
.ReadInt(gPlayers
[a
].FMonsterKills
);
829 Mem
.ReadInt(gPlayers
[a
].FFrags
);
831 Mem
.ReadByte(gPlayers
[a
].FFragCombo
);
832 // Âðåìÿ ïîñëåäíåãî ôðàãà:
833 Mem
.ReadDWORD(gPlayers
[a
].FLastFrag
);
835 Mem
.ReadInt(gPlayers
[a
].FDeath
);
837 Mem
.ReadByte(gPlayers
[a
].FFlag
);
839 Mem
.ReadInt(gPlayers
[a
].FSecrets
);
841 Mem
.ReadByte(gPlayers
[a
].FCurrWeap
);
842 // Ñëåäóþùåå æåëàåìîå îðóæèå:
843 Mem
.ReadWord(gPlayers
[a
].FNextWeap
);
845 Mem
.ReadByte(gPlayers
[a
].FNextWeapDelay
);
846 // Âðåìÿ çàðÿäêè BFG:
847 Mem
.ReadSmallInt(gPlayers
[a
].FBFGFireCounter
);
849 Mem
.ReadInt(gPlayers
[a
].FDamageBuffer
);
850 // Ïîñëåäíèé óäàðèâøèé:
851 Mem
.ReadWord(gPlayers
[a
].FLastSpawnerUID
);
852 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
853 Mem
.ReadByte(gPlayers
[a
].FLastHit
);
855 Obj_LoadState(@gPlayers
[a
].FObj
, Mem
);
856 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
857 for i
:= A_BULLETS
to A_HIGH
do
858 Mem
.ReadWord(gPlayers
[a
].FAmmo
[i
]);
859 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
860 for i
:= A_BULLETS
to A_HIGH
do
861 Mem
.ReadWord(gPlayers
[a
].FMaxAmmo
[i
]);
863 for i
:= WP_FIRST
to WP_LAST
do
864 Mem
.ReadBoolean(gPlayers
[a
].FWeapon
[i
]);
865 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
866 for i
:= WP_FIRST
to WP_LAST
do
867 Mem
.ReadWord(gPlayers
[a
].FReloading
[i
]);
871 Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
872 // Íàëè÷èå êðàñíîãî êëþ÷à:
875 Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
876 // Íàëè÷èå çåëåíîãî êëþ÷à:
879 Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
880 // Íàëè÷èå ñèíåãî êëþ÷à:
883 Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
887 Include(gPlayers
[a
].FRulez
, R_BERSERK
);
888 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
889 for i
:= MR_SUIT
to MR_MAX
do
890 Mem
.ReadDWORD(gPlayers
[a
].FMegaRulez
[i
]);
891 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
892 for i
:= T_RESPAWN
to T_FLAGCAP
do
893 Mem
.ReadDWORD(gPlayers
[a
].FTime
[i
]);
896 Mem
.ReadString(gPlayers
[a
].FActualModelName
);
898 Mem
.ReadByte(gPlayers
[a
].FColor
.R
);
899 Mem
.ReadByte(gPlayers
[a
].FColor
.G
);
900 Mem
.ReadByte(gPlayers
[a
].FColor
.B
);
901 // Îáíîâëÿåì ìîäåëü èãðîêà:
902 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
904 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
905 if gPlayers
[a
].FModel
= nil then
909 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
913 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
914 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
915 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
917 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
919 Result
:= gPlayers
[a
].FUID
;
922 procedure g_Player_ResetTeams();
926 if g_Game_IsClient
then
928 if gPlayers
= nil then
930 for a
:= Low(gPlayers
) to High(gPlayers
) do
931 if gPlayers
[a
] <> nil then
932 case gGameSettings
.GameMode
of
934 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
936 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
937 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
938 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
941 gPlayers
[a
].ChangeTeam(TEAM_RED
)
943 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
946 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
950 procedure g_Bot_Add(Team
, Difficult
: Byte);
953 _name
, _model
: String;
956 if not g_Game_IsServer
then Exit
;
958 // Ñïèñîê íàçâàíèé ìîäåëåé:
959 m
:= g_PlayerModel_GetNames();
964 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
965 Team
:= TEAM_COOP
// COOP
967 if gGameSettings
.GameMode
= GM_DM
then
968 Team
:= TEAM_NONE
// DM
970 if Team
= TEAM_NONE
then // CTF / TDM
972 // Àâòîáàëàíñ êîìàíä:
976 for a
:= 0 to High(gPlayers
) do
977 if gPlayers
[a
] <> nil then
979 if gPlayers
[a
].Team
= TEAM_RED
then
982 if gPlayers
[a
].Team
= TEAM_BLUE
then
992 if Random(2) = 0 then
998 // Âûáèðàåì áîòó èìÿ:
1000 if BotNames
<> nil then
1001 for a
:= 0 to High(BotNames
) do
1002 if g_Player_ValidName(BotNames
[a
]) then
1004 _name
:= BotNames
[a
];
1008 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
1011 _name
:= Format('DFBOT%.2d', [Random(100)]);
1012 until g_Player_ValidName(_name
);
1014 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1015 _model
:= m
[Random(Length(m
))];
1018 with g_Player_Get(g_Player_Create(_model
,
1019 _RGB(Min(Random(9)*32, 255),
1020 Min(Random(9)*32, 255),
1021 Min(Random(9)*32, 255)),
1022 Team
, True)) as TBot
do
1027 1: FDifficult
:= DIFFICULT_EASY
;
1028 2: FDifficult
:= DIFFICULT_MEDIUM
;
1029 else FDifficult
:= DIFFICULT_HARD
;
1032 for a
:= WP_FIRST
to WP_LAST
do
1034 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1035 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1036 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1039 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1041 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1042 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1047 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1);
1050 _name
, _model
: String;
1053 if not g_Game_IsServer
then Exit
;
1055 // Ñïèñîê íàçâàíèé ìîäåëåé:
1056 m
:= g_PlayerModel_GetNames();
1061 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1062 Team
:= TEAM_COOP
// COOP
1064 if gGameSettings
.GameMode
= GM_DM
then
1065 Team
:= TEAM_NONE
// DM
1067 if Team
= TEAM_NONE
then
1068 Team
:= BotList
[num
].team
; // CTF / TDM
1070 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1071 lName
:= AnsiLowerCase(lName
);
1072 if (num
< 0) or (num
> Length(BotList
)-1) then
1074 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1075 for a
:= 0 to High(BotList
) do
1076 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1085 _name
:= BotList
[num
].name
;
1086 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1087 if not g_Player_ValidName(_name
) then
1089 _name
:= Format('DFBOT%.2d', [Random(100)]);
1090 until g_Player_ValidName(_name
);
1093 _model
:= BotList
[num
].model
;
1094 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1095 if not InSArray(_model
, m
) then
1096 _model
:= m
[Random(Length(m
))];
1099 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1103 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1104 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1105 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1106 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1107 FDifficult
.Cover
:= BotList
[num
].cover
;
1108 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1110 for a
:= WP_FIRST
to WP_LAST
do
1112 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1113 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1114 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1117 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1119 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1123 procedure g_Bot_RemoveAll();
1127 if not g_Game_IsServer
then Exit
;
1128 if gPlayers
= nil then Exit
;
1130 for a
:= 0 to High(gPlayers
) do
1131 if gPlayers
[a
] <> nil then
1132 if gPlayers
[a
] is TBot
then
1134 gPlayers
[a
].Lives
:= 0;
1135 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1136 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1137 g_Player_Remove(gPlayers
[a
].FUID
);
1143 procedure g_Bot_MixNames();
1148 if BotNames
<> nil then
1149 for a
:= 0 to High(BotNames
) do
1151 b
:= Random(Length(BotNames
));
1153 Botnames
[a
] := BotNames
[b
];
1158 procedure g_Player_Remove(UID
: Word);
1162 if gPlayers
= nil then Exit
;
1164 if g_Game_IsServer
and g_Game_IsNet
then
1165 MH_SEND_PlayerDelete(UID
);
1167 for i
:= 0 to High(gPlayers
) do
1168 if gPlayers
[i
] <> nil then
1169 if gPlayers
[i
].FUID
= UID
then
1171 if gPlayers
[i
] is TPlayer
then
1172 TPlayer(gPlayers
[i
]).Free()
1174 TBot(gPlayers
[i
]).Free();
1180 procedure g_Player_Init();
1190 if not FileExists(DataDir
+ BOTNAMES_FILENAME
) then
1193 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1194 AssignFile(F
, DataDir
+ BOTNAMES_FILENAME
);
1205 SetLength(BotNames
, Length(BotNames
)+1);
1206 BotNames
[High(BotNames
)] := s
;
1214 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1215 config
:= TConfig
.CreateFile(DataDir
+ BOTLIST_FILENAME
);
1219 while config
.SectionExists(IntToStr(a
)) do
1221 SetLength(BotList
, Length(BotList
)+1);
1223 with BotList
[High(BotList
)] do
1226 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1228 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1230 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1235 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1236 color
.R
:= StrToIntDef(sa
[0], 0);
1237 color
.G
:= StrToIntDef(sa
[1], 0);
1238 color
.B
:= StrToIntDef(sa
[2], 0);
1239 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1240 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1241 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1242 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1243 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1244 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1245 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1246 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1247 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1248 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1249 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1250 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1251 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1252 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1253 if Length(sa
) = 10 then
1255 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1256 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1257 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1258 if Length(sa
) = 10 then
1260 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1262 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1263 if Length(sa) = 10 then
1265 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1274 procedure g_Player_Free();
1278 if gPlayers
<> nil then
1280 for i
:= 0 to High(gPlayers
) do
1281 if gPlayers
[i
] <> nil then
1283 if gPlayers
[i
] is TPlayer
then
1284 TPlayer(gPlayers
[i
]).Free()
1286 TBot(gPlayers
[i
]).Free();
1297 procedure g_Player_UpdateAll();
1301 if gPlayers
= nil then Exit
;
1303 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1304 for i
:= 0 to High(gPlayers
) do
1306 if gPlayers
[i
] <> nil then
1308 if gPlayers
[i
] is TPlayer
then
1310 gPlayers
[i
].Update();
1311 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1315 // bot updates weapons in `UpdateCombat()`
1316 TBot(gPlayers
[i
]).Update();
1320 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1323 procedure g_Player_DrawAll();
1327 if gPlayers
= nil then Exit
;
1329 for i
:= 0 to High(gPlayers
) do
1330 if gPlayers
[i
] <> nil then
1331 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1332 else TBot(gPlayers
[i
]).Draw();
1335 procedure g_Player_DrawDebug(p
: TPlayer
);
1339 if p
= nil then Exit
;
1340 if (@p
.FObj
) = nil then Exit
;
1342 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1344 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1345 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1346 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1347 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1348 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1349 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1352 procedure g_Player_DrawHealth();
1357 if gPlayers
= nil then Exit
;
1358 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1360 for i
:= 0 to High(gPlayers
) do
1361 if gPlayers
[i
] <> nil then
1363 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1364 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1365 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1366 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1367 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1368 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1372 function g_Player_Get(UID
: Word): TPlayer
;
1378 if gPlayers
= nil then
1381 for a
:= 0 to High(gPlayers
) do
1382 if gPlayers
[a
] <> nil then
1383 if gPlayers
[a
].FUID
= UID
then
1385 Result
:= gPlayers
[a
];
1390 function g_Player_GetCount(): Byte;
1396 if gPlayers
= nil then
1399 for a
:= 0 to High(gPlayers
) do
1400 if gPlayers
[a
] <> nil then
1401 Result
:= Result
+ 1;
1404 function g_Player_GetStats(): TPlayerStatArray
;
1410 if gPlayers
= nil then Exit
;
1412 for a
:= 0 to High(gPlayers
) do
1413 if gPlayers
[a
] <> nil then
1415 SetLength(Result
, Length(Result
)+1);
1416 with Result
[High(Result
)] do
1418 Ping
:= gPlayers
[a
].FPing
;
1419 Loss
:= gPlayers
[a
].FLoss
;
1420 Name
:= gPlayers
[a
].FName
;
1421 Team
:= gPlayers
[a
].FTeam
;
1422 Frags
:= gPlayers
[a
].FFrags
;
1423 Deaths
:= gPlayers
[a
].FDeath
;
1424 Kills
:= gPlayers
[a
].FKills
;
1425 Color
:= gPlayers
[a
].FModel
.Color
;
1426 Lives
:= gPlayers
[a
].FLives
;
1427 Spectator
:= gPlayers
[a
].FSpectator
;
1432 procedure g_Player_RememberAll
;
1436 for i
:= Low(gPlayers
) to High(gPlayers
) do
1437 if (gPlayers
[i
] <> nil) and gPlayers
[i
].Live
then
1438 gPlayers
[i
].RememberState
;
1441 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1445 gTeamStat
[TEAM_RED
].Goals
:= 0;
1446 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1448 if gPlayers
<> nil then
1449 for i
:= 0 to High(gPlayers
) do
1450 if gPlayers
[i
] <> nil then
1452 gPlayers
[i
].Reset(Force
);
1454 if gPlayers
[i
] is TPlayer
then
1456 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1457 gPlayers
[i
].Respawn(Silent
)
1459 gPlayers
[i
].Spectate();
1462 TBot(gPlayers
[i
]).Respawn(Silent
);
1466 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1473 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1478 if (FHealth
>= -50) or (gGibsCount
= 0) then
1480 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1484 for find_id
:= 0 to High(gCorpses
) do
1485 if gCorpses
[find_id
] = nil then
1492 find_id
:= Random(Length(gCorpses
));
1494 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1495 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1496 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1497 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1500 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1501 FObj
.Y
+ PLAYER_RECT_CY
,
1502 FModel
.Name
, FModel
.Color
);
1506 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1510 if (gShells
= nil) or (Length(gShells
) = 0) then
1513 with gShells
[CurrentShell
] do
1519 if T
= SHELL_BULLET
then
1521 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1525 Obj
.Rect
.Width
:= 4;
1526 Obj
.Rect
.Height
:= 2;
1530 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1534 Obj
.Rect
.Width
:= 7;
1535 Obj
.Rect
.Height
:= 3;
1541 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1542 positionChanged(); // this updates spatial accelerators
1543 RAngle
:= Random(360);
1544 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1546 if CurrentShell
>= High(gShells
) then
1553 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1556 GibsArray
: TGibsArray
;
1558 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1560 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1563 for a
:= 0 to High(GibsArray
) do
1564 with gGibs
[CurrentGib
] do
1567 ID
:= GibsArray
[a
].ID
;
1568 MaskID
:= GibsArray
[a
].MaskID
;
1571 Obj
.Rect
:= GibsArray
[a
].Rect
;
1572 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1573 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1574 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1575 positionChanged(); // this updates spatial accelerators
1576 RAngle
:= Random(360);
1578 if gBloodCount
> 0 then
1579 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1580 Random(48), Random(48), 150, 0, 0);
1582 if CurrentGib
>= High(gGibs
) then
1589 procedure g_Player_UpdatePhysicalObjects();
1595 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1600 if T
= SHELL_BULLET
then
1601 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1603 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1608 if gGibs
<> nil then
1609 for i
:= 0 to High(gGibs
) do
1610 if gGibs
[i
].Live
then
1614 mr
:= g_Obj_Move(@Obj
, True, False, True);
1615 positionChanged(); // this updates spatial accelerators
1617 if WordBool(mr
and MOVE_FALLOUT
) then
1623 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1624 if WordBool(mr
and MOVE_HITWALL
) then
1625 Obj
.Vel
.X
:= -(vel
.X
div 2);
1626 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1627 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1629 if (Obj
.Vel
.X
>= 0) then
1631 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1632 if RAngle
>= 360 then
1633 RAngle
:= RAngle
mod 360;
1634 end else begin // Counter-clockwise
1635 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1637 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1640 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1641 if gTime
mod (GAME_TICK
*3) = 0 then
1642 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1646 if gCorpses
<> nil then
1647 for i
:= 0 to High(gCorpses
) do
1648 if gCorpses
[i
] <> nil then
1649 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1655 gCorpses
[i
].Update();
1658 if gShells
<> nil then
1659 for i
:= 0 to High(gShells
) do
1660 if gShells
[i
].Live
then
1664 mr
:= g_Obj_Move(@Obj
, True, False, True);
1665 positionChanged(); // this updates spatial accelerators
1667 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1673 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1674 if WordBool(mr
and MOVE_HITWALL
) then
1676 Obj
.Vel
.X
:= -(vel
.X
div 2);
1677 if not WordBool(mr
and MOVE_INWATER
) then
1678 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1680 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1682 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1683 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1684 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1686 if RAngle
mod 90 <> 0 then
1687 RAngle
:= (RAngle
div 90) * 90;
1689 else if not WordBool(mr
and MOVE_INWATER
) then
1690 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1693 if (Obj
.Vel
.X
>= 0) then
1695 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1696 if RAngle
>= 360 then
1697 RAngle
:= RAngle
mod 360;
1698 end else begin // Counter-clockwise
1699 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1701 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1706 procedure g_Player_DrawCorpses();
1711 if gGibs
<> nil then
1712 for i
:= 0 to High(gGibs
) do
1713 if gGibs
[i
].Live
then
1716 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1719 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1720 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1722 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1725 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1731 if gCorpses
<> nil then
1732 for i
:= 0 to High(gCorpses
) do
1733 if gCorpses
[i
] <> nil then
1737 procedure g_Player_DrawShells();
1742 if gShells
<> nil then
1743 for i
:= 0 to High(gShells
) do
1744 if gShells
[i
].Live
then
1747 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1753 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1757 procedure g_Player_RemoveAllCorpses();
1763 SetLength(gGibs
, MaxGibs
);
1764 SetLength(gShells
, MaxGibs
);
1768 if gCorpses
<> nil then
1769 for i
:= 0 to High(gCorpses
) do
1773 SetLength(gCorpses
, MaxCorpses
);
1776 procedure g_Player_Corpses_SaveState(var Mem
: TBinMemoryWriter
);
1781 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ:
1783 if gCorpses
<> nil then
1784 for i
:= 0 to High(gCorpses
) do
1785 if gCorpses
[i
] <> nil then
1788 Mem
:= TBinMemoryWriter
.Create((count
+1) * 128);
1790 // Êîëè÷åñòâî òðóïîâ:
1791 Mem
.WriteInt(count
);
1797 for i
:= 0 to High(gCorpses
) do
1798 if gCorpses
[i
] <> nil then
1801 Mem
.WriteString(gCorpses
[i
].FModelName
);
1803 b
:= gCorpses
[i
].Mess
;
1804 Mem
.WriteBoolean(b
);
1805 // Ñîõðàíÿåì äàííûå òðóïà:
1806 gCorpses
[i
].SaveState(Mem
);
1810 procedure g_Player_Corpses_LoadState(var Mem
: TBinMemoryReader
);
1819 g_Player_RemoveAllCorpses();
1821 // Êîëè÷åñòâî òðóïîâ:
1824 if count
> Length(gCorpses
) then
1826 raise EBinSizeError
.Create('g_Player_Corpses_LoadState: Too Many Corpses');
1833 for i
:= 0 to count
-1 do
1836 Mem
.ReadString(str
);
1840 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1841 // Çàãðóæàåì äàííûå òðóïà:
1842 gCorpses
[i
].LoadState(Mem
);
1848 procedure TPlayer
.BFGHit();
1850 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1851 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1852 if g_Game_IsServer
and g_Game_IsNet
then
1853 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1854 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1858 procedure TPlayer
.ChangeModel(ModelName
: string);
1860 locModel
: TPlayerModel
;
1862 locModel
:= g_PlayerModel_Get(ModelName
);
1863 if locModel
= nil then Exit
;
1869 procedure TPlayer
.SetModel(ModelName
: string);
1873 m
:= g_PlayerModel_Get(ModelName
);
1876 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1877 m
:= g_PlayerModel_Get('doomer');
1880 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1885 if FModel
<> nil then
1890 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1891 FModel
.Color
:= FColor
1893 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1894 FModel
.SetWeapon(FCurrWeap
);
1895 FModel
.SetFlag(FFlag
);
1896 SetDirection(FDirection
);
1899 procedure TPlayer
.SetColor(Color
: TRGB
);
1902 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1903 if FModel
<> nil then FModel
.Color
:= Color
;
1906 procedure TPlayer
.SwitchTeam
;
1908 if g_Game_IsClient
then
1910 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
1912 if gGameOn
and FLive
then
1913 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
1915 if FTeam
= TEAM_RED
then
1917 ChangeTeam(TEAM_BLUE
);
1918 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
1919 if g_Game_IsNet
then
1920 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
1924 ChangeTeam(TEAM_RED
);
1925 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
1926 if g_Game_IsNet
then
1927 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
1929 FPreferredTeam
:= FTeam
;
1932 procedure TPlayer
.ChangeTeam(Team
: Byte);
1939 TEAM_RED
, TEAM_BLUE
:
1940 FModel
.Color
:= TEAMCOLOR
[Team
];
1942 FModel
.Color
:= FColor
;
1944 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
1945 MH_SEND_PlayerStats(FUID
);
1949 procedure TPlayer.CollideItem();
1954 if gItems = nil then Exit;
1955 if not FLive then Exit;
1957 for i := 0 to High(gItems) do
1960 if (ItemType <> ITEM_NONE) and Live then
1961 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
1962 PLAYER_RECT.Height, @Obj) then
1964 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
1966 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
1967 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
1968 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
1969 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
1970 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
1972 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
1973 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
1974 (gGameSettings.GameType = GT_SINGLE) and
1975 (g_Player_GetCount() > 1)) then
1976 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
1982 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
1984 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
1985 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
1989 constructor TPlayer
.Create();
1995 FSawSound
:= TPlayableSound
.Create();
1996 FSawSoundIdle
:= TPlayableSound
.Create();
1997 FSawSoundHit
:= TPlayableSound
.Create();
1998 FSawSoundSelect
:= TPlayableSound
.Create();
1999 FJetSoundFly
:= TPlayableSound
.Create();
2000 FJetSoundOn
:= TPlayableSound
.Create();
2001 FJetSoundOff
:= TPlayableSound
.Create();
2003 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2004 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2005 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2006 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2007 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2008 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2009 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2011 FSpectatePlayer
:= -1;
2015 FSavedState
.WaitRecall
:= False;
2021 FActualModelName
:= 'doomer';
2024 FObj
.Rect
:= PLAYER_RECT
;
2026 FBFGFireCounter
:= -1;
2027 FJustTeleported
:= False;
2033 procedure TPlayer
.positionChanged ();
2037 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2041 if (not g_Game_IsClient
) and (not FLive
) then
2046 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2047 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2049 if not g_Game_IsClient
then
2052 if t
= HIT_TRAP
then
2054 // Ëîâóøêà óáèâàåò ñðàçó:
2056 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2058 if t
= HIT_SELF
then
2062 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2065 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2066 FMegaRulez
[MR_SUIT
] := 0;
2067 FMegaRulez
[MR_INVUL
] := 0;
2068 FMegaRulez
[MR_INVIS
] := 0;
2072 // Íî îò îñòàëüíîãî ñïàñàåò:
2073 if FMegaRulez
[MR_INVUL
] >= gTime
then
2080 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2081 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2082 (SpawnerUID
= FUID
) or
2083 (not SameTeam(FUID
, SpawnerUID
)) then
2085 FLastSpawnerUID
:= SpawnerUID
;
2087 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2088 if gBloodCount
> 0 then
2090 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2091 if value
div 4 <= c
then
2092 c
:= c
- (value
div 4)
2096 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2100 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2101 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2104 if t
= HIT_WATER
then
2105 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2106 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2111 Inc(FDamageBuffer
, value
);
2115 FPain
:= FPain
+ value
;
2118 if g_Game_IsServer
and g_Game_IsNet
then
2120 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2121 MH_SEND_PlayerStats(FUID
);
2122 MH_SEND_PlayerPos(False, FUID
);
2126 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2129 if g_Game_IsClient
then
2134 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2136 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2139 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2141 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2145 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2146 MH_SEND_PlayerStats(FUID
);
2149 destructor TPlayer
.Destroy();
2151 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2153 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2157 FSawSoundIdle
.Free();
2158 FSawSoundHit
.Free();
2159 FJetSoundFly
.Free();
2161 FJetSoundOff
.Free();
2167 procedure TPlayer
.DrawBubble();
2169 bubX
, bubY
: Integer;
2172 Rw
, Gw
, Bw
: SmallInt;
2175 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= D_LEFT
, -4, 18);
2176 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2184 1: // simple textual non-bubble
2186 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2187 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2188 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2191 2: // advanced pixel-perfect bubble
2193 if FTeam
= TEAM_RED
then
2196 if FTeam
= TEAM_BLUE
then
2199 3: // colored bubble
2201 Rb
:= FModel
.Color
.R
;
2202 Gb
:= FModel
.Color
.G
;
2203 Bb
:= FModel
.Color
.B
;
2204 Rw
:= Min(Rb
* 2 + 64, 255);
2205 Gw
:= Min(Gb
* 2 + 64, 255);
2206 Bw
:= Min(Bb
* 2 + 64, 255);
2207 if (Abs(Rw
- Rb
) < 32)
2208 or (Abs(Gw
- Gb
) < 32)
2209 or (Abs(Bw
- Bb
) < 32) then
2211 Rb
:= Max(Rw
div 2 - 16, 0);
2212 Gb
:= Max(Gw
div 2 - 16, 0);
2213 Bb
:= Max(Bw
div 2 - 16, 0);
2216 4: // custom textured bubble
2218 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2219 if FDirection
= D_RIGHT
then
2220 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2222 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, M_HORIZONTAL
);
2228 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2229 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2231 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2234 Dot
:= IfThen(FDirection
= D_LEFT
, 14, 5);
2235 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2236 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
);
2237 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
);
2238 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
);
2239 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
);
2243 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2244 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2245 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2248 procedure TPlayer
.Draw();
2256 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2257 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2259 e_GetTextureSize(ID
, @w
, @h
);
2260 if FDirection
= D_LEFT
then
2261 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2262 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7, 0, True, False)
2264 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2265 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7, 0, True, False);
2268 if FMegaRulez
[MR_INVIS
] > gTime
then
2270 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2271 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2273 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2274 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2278 FModel
.Draw(FObj
.X
, FObj
.Y
, 200)
2280 FModel
.Draw(FObj
.X
, FObj
.Y
);
2283 FModel
.Draw(FObj
.X
, FObj
.Y
, 254);
2286 FModel
.Draw(FObj
.X
, FObj
.Y
);
2289 if g_debug_Frames
then
2291 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2293 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2294 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2298 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2300 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2301 if gAimLine
and Live
and
2302 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2306 procedure TPlayer
.DrawAim();
2307 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2309 function monsCollector (mon
: TMonster
; tag
: Integer): Boolean;
2312 mx
, my
, mw
, mh
: Integer;
2315 mon
.getMapBox(mx
, my
, mw
, mh
);
2316 e_DrawQuad(mx
, my
, mx
+mw
-1, my
+mh
-1, 255, 255, 0, 96);
2317 if lineAABBIntersects(ax0
, ay0
, ax1
, ay1
, mx
, my
, mw
, mh
, ex
, ey
) then
2319 e_DrawPoint(8, ex
, ey
, 0, 255, 0);
2326 //mx, my, mw, mh: Integer;
2328 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2329 if g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) then
2331 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2332 e_DrawPoint(4, ex
, ey
, 255, 127, 0);
2336 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2340 mon := g_Mons_ByIdx(0);
2341 mon.getMapBox(mx, my, mw, mh);
2344 e_DrawLine(2, ax0, ay0, ax1, ay1, 0, 96, 96, 96);
2346 if lineAABBIntersects(ax0, ay0, ax1, ay1, mx, my, mw, mh, ex, ey) then
2348 e_DrawLine(2, ax0, ay0, ex, ey, 255, 255, 0, 96);
2352 e_DrawLine(2, ax0, ay0, ex, ey, 255, 127, 0, 96);
2356 g_Mons_alongLine(ax0
, ay0
, ax1
, ay1
, monsCollector
);
2360 wx
, wy
, xx
, yy
: Integer;
2364 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= D_LEFT
, 7, -7);
2365 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2374 1: begin // Chainsaw
2381 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2382 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2383 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2384 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2389 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2390 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2391 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2392 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2394 4: begin // Double Shotgun
2397 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2398 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2399 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2400 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2402 5: begin // Chaingun
2405 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2406 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2407 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2408 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2410 6: begin // Rocket Launcher
2413 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2414 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2415 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2416 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2418 7: begin // Plasmagun
2421 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2422 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2423 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2424 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2429 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2430 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2431 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2432 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2434 9: begin // Super Chaingun
2437 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2438 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2439 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2440 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2443 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2444 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2446 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2448 drawCast(sz
, wx
, wy
, xx
, yy
);
2452 procedure TPlayer
.DrawGUI();
2455 X
, Y
, SY
, a
, p
, m
: Integer;
2459 stat
: TPlayerStatArray
;
2461 X
:= gPlayerScreenSize
.X
;
2462 SY
:= gPlayerScreenSize
.Y
;
2465 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2467 if gGameSettings
.GameMode
= GM_CTF
then
2471 if gGameSettings
.GameMode
= GM_CTF
then
2473 s
:= 'TEXTURE_PLAYER_REDFLAG';
2474 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2475 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2476 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2477 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2478 if g_Texture_Get(s
, ID
) then
2479 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2482 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2483 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2484 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2486 if gGameSettings
.GameMode
= GM_CTF
then
2488 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2489 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2490 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2491 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2492 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2493 if g_Texture_Get(s
, ID
) then
2494 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2497 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2498 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2499 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2502 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2503 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2506 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2507 e_Draw(ID
, X
+2, Y
, 0, True, False);
2509 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2513 s
:= IntToStr(Frags
);
2514 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2515 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2520 stat
:= g_Player_GetStats();
2525 for a
:= 0 to High(stat
) do
2526 if stat
[a
].Name
<> Name
then
2528 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2529 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2533 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2534 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2535 s
:= s
+IntToStr(Abs(Frags
-m
));
2537 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2538 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2541 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2543 s
:= IntToStr(Lives
);
2544 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2545 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2549 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2550 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2552 if R_BERSERK
in FRulez
then
2553 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2555 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2557 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2558 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2560 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2561 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2562 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2564 s
:= IntToStr(FArmor
);
2565 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2566 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2568 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2574 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2579 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2581 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2582 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2583 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2584 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2585 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2586 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2587 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2588 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2589 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2592 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2593 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2594 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2596 if R_KEY_RED
in FRulez
then
2597 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2599 if R_KEY_GREEN
in FRulez
then
2600 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2602 if R_KEY_BLUE
in FRulez
then
2603 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2605 if FJetFuel
> 0 then
2607 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2608 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2609 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2610 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2611 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2612 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2616 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2617 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2618 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2621 if gShowPing
and g_Game_IsClient
then
2623 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2624 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2630 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2631 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2632 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2635 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2636 s
:= _lc
[I_PLAYER_SPECT4
];
2637 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2638 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2639 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2645 procedure TPlayer
.DrawRulez();
2649 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2650 if FMegaRulez
[MR_INVUL
] >= gTime
then
2652 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2653 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2658 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2659 191, 191, 191, 0, B_INVERT
);
2662 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2663 if FMegaRulez
[MR_SUIT
] >= gTime
then
2665 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2666 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2671 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2672 0, 96, 0, 200, B_NONE
);
2675 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2676 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2678 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2679 255, 0, 0, 200, B_NONE
);
2683 procedure TPlayer
.DrawPain();
2687 if FPain
= 0 then Exit
;
2691 if a
< 15 then h
:= 0
2692 else if a
< 35 then h
:= 1
2693 else if a
< 55 then h
:= 2
2694 else if a
< 75 then h
:= 3
2695 else if a
< 95 then h
:= 4
2698 //if a > 255 then a := 255;
2700 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2701 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2704 procedure TPlayer
.DrawPickup();
2708 if FPickup
= 0 then Exit
;
2712 if a
< 15 then h
:= 1
2713 else if a
< 35 then h
:= 2
2714 else if a
< 55 then h
:= 3
2715 else if a
< 75 then h
:= 4
2718 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2721 procedure TPlayer
.Fire();
2723 f
, DidFire
: Boolean;
2724 wx
, wy
, xd
, yd
: Integer;
2727 if g_Game_IsClient
then Exit
;
2728 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2729 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2737 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2742 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2743 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2744 xd
:= wx
+IfThen(FDirection
= D_LEFT
, -30, 30);
2745 yd
:= wy
+firediry();
2750 if R_BERSERK
in FRulez
then
2752 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2753 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2754 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2757 locobj
.rect
.Width
:= 39;
2758 locobj
.rect
.Height
:= 52;
2759 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2760 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2761 locobj
.Accel
.X
:= xd
-wx
;
2762 locobj
.Accel
.y
:= yd
-wy
;
2764 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2765 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2767 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2771 FPain
:= min(FPain
+ 25, 50);
2772 end else g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2775 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2780 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2781 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2783 FSawSoundSelect
.Stop();
2785 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2787 else if not FSawSoundHit
.IsPlaying() then
2789 FSawSoundSelect
.Stop();
2790 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2793 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2799 if FAmmo
[A_BULLETS
] > 0 then
2801 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2802 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2803 Dec(FAmmo
[A_BULLETS
]);
2804 FFireAngle
:= FAngle
;
2807 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2808 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2812 if FAmmo
[A_SHELLS
] > 0 then
2814 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2815 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
2816 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2817 Dec(FAmmo
[A_SHELLS
]);
2818 FFireAngle
:= FAngle
;
2822 FShellType
:= SHELL_SHELL
;
2826 if FAmmo
[A_SHELLS
] >= 2 then
2828 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
2829 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2830 Dec(FAmmo
[A_SHELLS
], 2);
2831 FFireAngle
:= FAngle
;
2835 FShellType
:= SHELL_DBLSHELL
;
2839 if FAmmo
[A_BULLETS
] > 0 then
2841 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
2842 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
2843 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2844 Dec(FAmmo
[A_BULLETS
]);
2845 FFireAngle
:= FAngle
;
2848 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2849 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2852 WEAPON_ROCKETLAUNCHER
:
2853 if FAmmo
[A_ROCKETS
] > 0 then
2855 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
2856 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2857 Dec(FAmmo
[A_ROCKETS
]);
2858 FFireAngle
:= FAngle
;
2864 if FAmmo
[A_CELLS
] > 0 then
2866 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
2867 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2868 Dec(FAmmo
[A_CELLS
]);
2869 FFireAngle
:= FAngle
;
2875 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
2877 FBFGFireCounter
:= 17;
2878 if not FNoReload
then
2879 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
2880 Dec(FAmmo
[A_CELLS
], 40);
2884 WEAPON_SUPERPULEMET
:
2885 if FAmmo
[A_SHELLS
] > 0 then
2887 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2888 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
2889 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2890 Dec(FAmmo
[A_SHELLS
]);
2891 FFireAngle
:= FAngle
;
2894 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2895 GameVelX
, GameVelY
-2, SHELL_SHELL
);
2898 WEAPON_FLAMETHROWER
:
2899 if FAmmo
[A_FUEL
] > 0 then
2901 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
2902 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2904 FFireAngle
:= FAngle
;
2910 if g_Game_IsNet
then
2914 if FCurrWeap
<> WEAPON_BFG
then
2915 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
2917 if not FNoReload
then
2918 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
2921 MH_SEND_PlayerStats(FUID
);
2926 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
2927 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
2928 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
2931 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
2934 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
2935 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
2936 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
2937 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
2938 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
2943 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
2945 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
2946 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
2947 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
2950 procedure TPlayer
.JetpackOn
;
2954 FJetSoundOn
.SetPosition(0);
2955 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
2959 procedure TPlayer
.JetpackOff
;
2963 FJetSoundOff
.SetPosition(0);
2964 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
2967 procedure TPlayer
.CatchFire(Attacker
: Word);
2970 FFireAttacker
:= Attacker
;
2971 if g_Game_IsNet
and g_Game_IsServer
then
2972 MH_SEND_PlayerStats(FUID
);
2975 procedure TPlayer
.Jump();
2977 if gFly
or FJetpack
then
2979 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
2980 if FObj
.Vel
.Y
> -VEL_FLY
then
2981 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
2984 if FJetFuel
> 0 then
2986 if (FJetFuel
< 1) and g_Game_IsServer
then
2990 if g_Game_IsNet
then
2991 MH_SEND_PlayerStats(FUID
);
2997 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
2999 FCanJetpack
:= False;
3001 // Ïðûãàåì èëè âñïëûâàåì:
3002 if (CollideLevel(0, 1) or
3003 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3004 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3005 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3007 FObj
.Vel
.Y
:= -VEL_JUMP
;
3008 FCanJetpack
:= False;
3012 if BodyInLiquid(0, 0) then
3013 FObj
.Vel
.Y
:= -VEL_SW
3014 else if (FJetFuel
> 0) and FCanJetpack
and
3015 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3019 if g_Game_IsNet
then
3020 MH_SEND_PlayerStats(FUID
);
3025 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3027 a
, i
, k
, ab
, ar
: Byte;
3031 srv
, netsrv
: Boolean;
3037 procedure PushItem(t
: Byte);
3041 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3042 it
:= g_Items_ByIdx(id
);
3043 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3045 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3046 (FObj
.Vel
.Y
div 2)-Random(9));
3047 it
.positionChanged(); // this updates spatial accelerators
3051 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3053 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3054 (FObj
.Vel
.Y
div 2)-Random(6));
3056 else // -3..+3; -3..0
3058 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3059 (FObj
.Vel
.Y
div 2)-Random(4));
3061 it
.positionChanged(); // this updates spatial accelerators
3064 if g_Game_IsNet
and g_Game_IsServer
then
3065 MH_SEND_ItemSpawn(True, id
);
3069 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3070 Srv
:= g_Game_IsServer
;
3071 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3072 if Srv
then FDeath
:= FDeath
+ 1;
3077 if not FPhysics
then
3083 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3085 if FLives
> 0 then FLives
:= FLives
- 1;
3086 if FLives
= 0 then FNoRespawn
:= True;
3089 // Íîìåð òèïà ñìåðòè:
3092 K_SIMPLEKILL
: a
:= 1;
3094 K_EXTRAHARDKILL
: a
:= 3;
3099 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3101 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3108 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3110 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3111 K_EXTRAHARDKILL
, K_FALLKILL
:
3112 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3115 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3119 K_HARDKILL
, K_EXTRAHARDKILL
:
3123 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3124 if (KillType
<> K_FALLKILL
) and (Srv
) then
3125 g_Monsters_killedp();
3127 if SpawnerUID
= FUID
then
3129 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3134 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3137 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3138 begin // Óáèò äðóãèì èãðîêîì
3139 KP
:= g_Player_Get(SpawnerUID
);
3140 if (KP
<> nil) and Srv
then
3142 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3143 if SameTeam(FUID
, SpawnerUID
) then
3153 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3154 Inc(gTeamStat
[KP
.Team
].Goals
,
3155 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3157 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3160 plr
:= g_Player_Get(SpawnerUID
);
3168 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3172 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3176 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3181 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3182 begin // Óáèò ìîíñòðîì
3183 mon
:= g_Monsters_ByUID(SpawnerUID
);
3187 s
:= g_Monsters_GetKilledBy(mon
.MonsterType
);
3191 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3195 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3199 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3204 else // Îñîáûå òèïû ñìåðòè
3207 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3208 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3209 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3210 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3211 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3212 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3218 for a
:= WP_FIRST
to WP_LAST
do
3222 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3223 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3224 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3225 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3226 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3227 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3228 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3229 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3230 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3239 if R_ITEM_BACKPACK
in FRulez
then
3240 PushItem(ITEM_AMMO_BACKPACK
);
3242 // Âûáðîñ ðàêåòíîãî ðàíöà:
3243 if FJetFuel
> 0 then
3244 PushItem(ITEM_JETPACK
);
3247 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3249 if R_KEY_RED
in FRulez
then
3250 PushItem(ITEM_KEY_RED
);
3252 if R_KEY_GREEN
in FRulez
then
3253 PushItem(ITEM_KEY_GREEN
);
3255 if R_KEY_BLUE
in FRulez
then
3256 PushItem(ITEM_KEY_BLUE
);
3263 g_Player_CreateCorpse(Self
);
3265 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3266 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3272 for i
:= Low(gPlayers
) to High(gPlayers
) do
3274 if gPlayers
[i
] = nil then continue
;
3275 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3278 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3279 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3284 OldLR
:= gLMSRespawn
;
3285 if (gGameSettings
.GameMode
= GM_COOP
) then
3289 // everyone is dead, restart the map
3290 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3292 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3293 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3294 gLMSRespawnTime
:= gTime
+ 5000;
3296 else if (a
= 1) then
3298 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3299 if (gPlayers
[k
] = gPlayer1
) or
3300 (gPlayers
[k
] = gPlayer2
) then
3301 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3302 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3303 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3306 else if (gGameSettings
.GameMode
= GM_TDM
) then
3308 if (ab
= 0) and (ar
<> 0) then
3311 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3313 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3314 Inc(gTeamStat
[TEAM_RED
].Goals
);
3315 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3316 gLMSRespawnTime
:= gTime
+ 5000;
3318 else if (ar
= 0) and (ab
<> 0) then
3321 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3323 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3324 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3325 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3326 gLMSRespawnTime
:= gTime
+ 5000;
3328 else if (ar
= 0) and (ab
= 0) then
3331 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3333 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3334 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3335 gLMSRespawnTime
:= gTime
+ 5000;
3338 else if (gGameSettings
.GameMode
= GM_DM
) then
3342 if gPlayers
[k
] <> nil then
3345 // survivor is the winner
3346 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3348 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3351 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3352 gLMSRespawnTime
:= gTime
+ 5000;
3354 else if (a
= 0) then
3356 // everyone is dead, restart the map
3357 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3359 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3360 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3361 gLMSRespawnTime
:= gTime
+ 5000;
3364 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3366 if NetMode
= NET_SERVER
then
3367 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3369 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3375 MH_SEND_PlayerStats(FUID
);
3376 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3377 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3380 if srv
and FNoRespawn
then Spectate(True);
3381 FWantsInGame
:= True;
3384 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3386 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3387 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3390 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3392 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3393 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3396 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3398 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3399 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3400 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3402 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3403 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3404 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3408 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3410 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3411 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3412 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3416 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3418 if g_Game_IsClient
then Exit
;
3419 if Weapon
> High(FWeapon
) then Exit
;
3420 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3423 procedure TPlayer
.resetWeaponQueue ();
3426 FNextWeapDelay
:= 0;
3429 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3433 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3434 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 0);
3435 WEAPON_PISTOL
, WEAPON_CHAINGUN
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_BULLETS
] > 0);
3436 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3437 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3438 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3439 else result
:= (weapon
< length(FWeapon
));
3443 // return 255 for "no switch"
3444 function TPlayer
.getNextWeaponIndex (): Byte;
3447 wantThisWeapon
: array[0..64] of Boolean;
3448 wwc
: Integer = 0; //HACK!
3451 result
:= 255; // default result: "no switch"
3452 // had weapon cycling on previous frame? remove that flag
3453 if (FNextWeap
and $2000) <> 0 then
3455 FNextWeap
:= FNextWeap
and $1FFF;
3456 FNextWeapDelay
:= 0;
3458 // cycling has priority
3459 if (FNextWeap
and $C000) <> 0 then
3461 if (FNextWeap
and $8000) <> 0 then
3465 FNextWeap
:= FNextWeap
or $2000; // we need this
3466 if FNextWeapDelay
> 0 then
3467 exit
; // cooldown time
3469 for i
:= 0 to High(FWeapon
) do
3471 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3472 if FWeapon
[cwi
] then
3474 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d', [FCurrWeap, cwi]), MSG_WARNING);
3475 result
:= Byte(cwi
);
3476 FNextWeapDelay
:= 10;
3484 for i
:= 0 to High(wantThisWeapon
) do
3485 wantThisWeapon
[i
] := false;
3486 for i
:= 0 to High(FWeapon
) do
3487 if (FNextWeap
and (1 shl i
)) <> 0 then
3489 wantThisWeapon
[i
] := true;
3492 // exclude currently selected weapon from the set
3493 wantThisWeapon
[FCurrWeap
] := false;
3494 // slow down alterations a little
3497 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3498 // more than one weapon requested, assume "alteration" and check alteration delay
3499 if FNextWeapDelay
> 0 then
3505 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3506 // but clear all counters if no weapon should be switched
3512 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3513 // try weapons in descending order
3514 for i
:= High(FWeapon
) downto 0 do
3516 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3521 FNextWeapDelay
:= 10; // anyway, 'cause why not
3525 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3529 procedure TPlayer
.RealizeCurrentWeapon();
3530 function switchAllowed (): Boolean;
3535 if FBFGFireCounter
<> -1 then
3537 if FTime
[T_SWITCH
] > gTime
then
3539 for i
:= WP_FIRST
to WP_LAST
do
3540 if FReloading
[i
] > 0 then
3548 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3549 //FNextWeap := FNextWeap and $1FFF;
3550 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3552 if not switchAllowed
then
3554 //HACK for weapon cycling
3555 if (FNextWeap
and $7000) <> 0 then FNextWeap
:= 0;
3559 nw
:= getNextWeaponIndex();
3560 if nw
= 255 then exit
; // don't reset anything here
3561 if nw
> High(FWeapon
) then
3563 // don't forget to reset queue here!
3564 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3572 FTime
[T_SWITCH
] := gTime
+156;
3573 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3574 FModel
.SetWeapon(FCurrWeap
);
3575 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3579 procedure TPlayer
.NextWeapon();
3581 if g_Game_IsClient
then Exit
;
3585 procedure TPlayer
.PrevWeapon();
3587 if g_Game_IsClient
then Exit
;
3591 procedure TPlayer
.SetWeapon(W
: Byte);
3593 if FCurrWeap
<> W
then
3594 if W
= WEAPON_SAW
then
3595 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3598 FModel
.SetWeapon(CurrWeap
);
3602 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3607 if g_Game_IsClient
then Exit
;
3609 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3610 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3615 if FHealth
< PLAYER_HP_SOFT
then
3617 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3621 if gFlash
= 2 then Inc(FPickup
, 5);
3625 if FHealth
< PLAYER_HP_SOFT
then
3627 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3631 if gFlash
= 2 then Inc(FPickup
, 5);
3635 if FArmor
< PLAYER_AP_SOFT
then
3637 FArmor
:= PLAYER_AP_SOFT
;
3640 if gFlash
= 2 then Inc(FPickup
, 5);
3644 if FArmor
< PLAYER_AP_LIMIT
then
3646 FArmor
:= PLAYER_AP_LIMIT
;
3649 if gFlash
= 2 then Inc(FPickup
, 5);
3653 if FHealth
< PLAYER_HP_LIMIT
then
3655 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3659 if gFlash
= 2 then Inc(FPickup
, 5);
3663 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3665 if FHealth
< PLAYER_HP_LIMIT
then
3666 FHealth
:= PLAYER_HP_LIMIT
;
3667 if FArmor
< PLAYER_AP_LIMIT
then
3668 FArmor
:= PLAYER_AP_LIMIT
;
3672 if gFlash
= 2 then Inc(FPickup
, 5);
3676 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3678 FWeapon
[WEAPON_SAW
] := True;
3680 if gFlash
= 2 then Inc(FPickup
, 5);
3681 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3684 ITEM_WEAPON_SHOTGUN1
:
3685 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3687 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3688 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3690 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3691 FWeapon
[WEAPON_SHOTGUN1
] := True;
3693 if gFlash
= 2 then Inc(FPickup
, 5);
3694 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3697 ITEM_WEAPON_SHOTGUN2
:
3698 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3700 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3702 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3703 FWeapon
[WEAPON_SHOTGUN2
] := True;
3705 if gFlash
= 2 then Inc(FPickup
, 5);
3706 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3709 ITEM_WEAPON_CHAINGUN
:
3710 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3712 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3714 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3715 FWeapon
[WEAPON_CHAINGUN
] := True;
3717 if gFlash
= 2 then Inc(FPickup
, 5);
3718 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3721 ITEM_WEAPON_ROCKETLAUNCHER
:
3722 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3724 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3726 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3727 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3729 if gFlash
= 2 then Inc(FPickup
, 5);
3730 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3734 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3736 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3738 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3739 FWeapon
[WEAPON_PLASMA
] := True;
3741 if gFlash
= 2 then Inc(FPickup
, 5);
3742 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3746 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3748 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3750 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3751 FWeapon
[WEAPON_BFG
] := True;
3753 if gFlash
= 2 then Inc(FPickup
, 5);
3754 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3757 ITEM_WEAPON_SUPERPULEMET
:
3758 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3760 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3762 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3763 FWeapon
[WEAPON_SUPERPULEMET
] := True;
3765 if gFlash
= 2 then Inc(FPickup
, 5);
3766 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3769 ITEM_WEAPON_FLAMETHROWER
:
3770 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
3772 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
3774 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3775 FWeapon
[WEAPON_FLAMETHROWER
] := True;
3777 if gFlash
= 2 then Inc(FPickup
, 5);
3778 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3782 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3784 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3787 if gFlash
= 2 then Inc(FPickup
, 5);
3790 ITEM_AMMO_BULLETS_BOX
:
3791 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3793 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3796 if gFlash
= 2 then Inc(FPickup
, 5);
3800 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3802 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3805 if gFlash
= 2 then Inc(FPickup
, 5);
3808 ITEM_AMMO_SHELLS_BOX
:
3809 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3811 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
3814 if gFlash
= 2 then Inc(FPickup
, 5);
3818 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3820 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3823 if gFlash
= 2 then Inc(FPickup
, 5);
3826 ITEM_AMMO_ROCKET_BOX
:
3827 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3829 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
3832 if gFlash
= 2 then Inc(FPickup
, 5);
3836 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3838 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3841 if gFlash
= 2 then Inc(FPickup
, 5);
3845 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3847 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
3850 if gFlash
= 2 then Inc(FPickup
, 5);
3854 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
3856 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3859 if gFlash
= 2 then Inc(FPickup
, 5);
3863 if not(R_ITEM_BACKPACK
in FRulez
) or
3864 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
3865 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
3866 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
3867 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
3868 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
3870 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
3871 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
3872 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
3873 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
3874 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
3876 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3877 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3878 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3879 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3880 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3881 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3882 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3883 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3885 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
3888 if gFlash
= 2 then Inc(FPickup
, 5);
3892 if not(R_KEY_RED
in FRulez
) then
3894 Include(FRulez
, R_KEY_RED
);
3896 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3897 if gFlash
= 2 then Inc(FPickup
, 5);
3898 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3902 if not(R_KEY_GREEN
in FRulez
) then
3904 Include(FRulez
, R_KEY_GREEN
);
3906 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3907 if gFlash
= 2 then Inc(FPickup
, 5);
3908 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3912 if not(R_KEY_BLUE
in FRulez
) then
3914 Include(FRulez
, R_KEY_BLUE
);
3916 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3917 if gFlash
= 2 then Inc(FPickup
, 5);
3918 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3922 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
3924 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
3928 if gFlash
= 2 then Inc(FPickup
, 5);
3932 if FAir
< AIR_MAX
then
3937 if gFlash
= 2 then Inc(FPickup
, 5);
3942 if not (R_BERSERK
in FRulez
) then
3944 Include(FRulez
, R_BERSERK
);
3945 if FBFGFireCounter
= -1 then
3947 FCurrWeap
:= WEAPON_KASTET
;
3949 FModel
.SetWeapon(WEAPON_KASTET
);
3953 if gFlash
= 2 then Inc(FPickup
, 5);
3954 FBerserk
:= gTime
+30000;
3959 if FHealth
< PLAYER_HP_SOFT
then
3961 FHealth
:= PLAYER_HP_SOFT
;
3962 FBerserk
:= gTime
+30000;
3970 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
3972 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
3975 if gFlash
= 2 then Inc(FPickup
, 5);
3979 if FHealth
< PLAYER_HP_LIMIT
then
3981 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
3985 if gFlash
= 2 then Inc(FPickup
, 5);
3989 if FArmor
< PLAYER_AP_LIMIT
then
3991 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
3994 if gFlash
= 2 then Inc(FPickup
, 5);
3998 if FJetFuel
< JET_MAX
then
4000 FJetFuel
:= JET_MAX
;
4003 if gFlash
= 2 then Inc(FPickup
, 5);
4007 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4009 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4012 if gFlash
= 2 then Inc(FPickup
, 5);
4017 procedure TPlayer
.Touch();
4021 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4024 // Áðîñèòü ôëàã òîâàðèùó:
4025 if gGameSettings
.GameMode
= GM_CTF
then
4030 procedure TPlayer
.Push(vx
, vy
: Integer);
4032 if (not FPhysics
) and FGhost
then
4034 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4035 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4036 if g_Game_IsNet
and g_Game_IsServer
then
4037 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4040 procedure TPlayer
.Reset(Force
: Boolean);
4046 FTime
[T_RESPAWN
] := 0;
4047 FTime
[T_FLAGCAP
] := 0;
4060 FSpectator
:= False;
4063 FSpectatePlayer
:= -1;
4064 FNoRespawn
:= False;
4066 FLives
:= gGameSettings
.MaxLives
;
4071 procedure TPlayer
.SoftReset();
4077 FBFGFireCounter
:= -1;
4085 SetAction(A_STAND
, True);
4088 function TPlayer
.GetRespawnPoint(): Byte;
4093 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4095 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4096 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4098 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4100 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4101 if Self
= gPlayer1
then
4102 c
:= RESPAWNPOINT_PLAYER1
4104 c
:= RESPAWNPOINT_PLAYER2
;
4105 if g_Map_GetPointCount(c
) > 0 then
4111 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4112 if Self
= gPlayer1
then
4113 c
:= RESPAWNPOINT_PLAYER2
4115 c
:= RESPAWNPOINT_PLAYER1
;
4116 if g_Map_GetPointCount(c
) > 0 then
4123 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4124 if Random(2) = 0 then
4125 c
:= RESPAWNPOINT_PLAYER1
4127 c
:= RESPAWNPOINT_PLAYER2
;
4128 if g_Map_GetPointCount(c
) > 0 then
4135 // Òî÷êà ëþáîé èç êîìàíä
4136 if Random(2) = 0 then
4137 c
:= RESPAWNPOINT_RED
4139 c
:= RESPAWNPOINT_BLUE
;
4140 if g_Map_GetPointCount(c
) > 0 then
4147 c
:= RESPAWNPOINT_DM
;
4148 if g_Map_GetPointCount(c
) > 0 then
4156 if gGameSettings
.GameMode
= GM_DM
then
4159 c
:= RESPAWNPOINT_DM
;
4160 if g_Map_GetPointCount(c
) > 0 then
4166 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4167 if Random(2) = 0 then
4168 c
:= RESPAWNPOINT_PLAYER1
4170 c
:= RESPAWNPOINT_PLAYER2
;
4171 if g_Map_GetPointCount(c
) > 0 then
4177 // Òî÷êà ëþáîé èç êîìàíä
4178 if Random(2) = 0 then
4179 c
:= RESPAWNPOINT_RED
4181 c
:= RESPAWNPOINT_BLUE
;
4182 if g_Map_GetPointCount(c
) > 0 then
4190 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4192 // Òî÷êà ñâîåé êîìàíäû
4193 c
:= RESPAWNPOINT_DM
;
4194 if FTeam
= TEAM_RED
then
4195 c
:= RESPAWNPOINT_RED
;
4196 if FTeam
= TEAM_BLUE
then
4197 c
:= RESPAWNPOINT_BLUE
;
4198 if g_Map_GetPointCount(c
) > 0 then
4205 c
:= RESPAWNPOINT_DM
;
4206 if g_Map_GetPointCount(c
) > 0 then
4212 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4213 if Random(2) = 0 then
4214 c
:= RESPAWNPOINT_PLAYER1
4216 c
:= RESPAWNPOINT_PLAYER2
;
4217 if g_Map_GetPointCount(c
) > 0 then
4223 // Òî÷êà äðóãîé êîìàíäû
4224 c
:= RESPAWNPOINT_DM
;
4225 if FTeam
= TEAM_RED
then
4226 c
:= RESPAWNPOINT_BLUE
;
4227 if FTeam
= TEAM_BLUE
then
4228 c
:= RESPAWNPOINT_RED
;
4229 if g_Map_GetPointCount(c
) > 0 then
4237 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4239 RespawnPoint
: TRespawnPoint
;
4244 if not g_Game_IsServer
then
4248 FWantsInGame
:= True;
4249 FJustTeleported
:= True;
4252 FTime
[T_RESPAWN
] := 0;
4256 // if server changes MaxLives we gotta be ready
4257 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4259 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4260 if FTime
[T_RESPAWN
] > gTime
then
4263 // Ïðîñðàë âñå æèçíè:
4266 if not FSpectator
then Spectate(True);
4267 FWantsInGame
:= True;
4271 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4272 begin // "Ñâîÿ èãðà"
4273 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4274 FRulez
:= FRulez
-[R_BERSERK
];
4276 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4278 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4279 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4282 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4283 c
:= GetRespawnPoint();
4288 // Âîñêðåøåíèå áåç îðóæèÿ:
4291 FHealth
:= PLAYER_HP_SOFT
;
4297 for a
:= WP_FIRST
to WP_LAST
do
4299 FWeapon
[a
] := False;
4303 FWeapon
[WEAPON_PISTOL
] := True;
4304 FWeapon
[WEAPON_KASTET
] := True;
4305 FCurrWeap
:= WEAPON_PISTOL
;
4308 FModel
.SetWeapon(FCurrWeap
);
4310 for b
:= A_BULLETS
to A_HIGH
do
4313 FAmmo
[A_BULLETS
] := 50;
4315 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4316 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4317 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4318 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4319 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4321 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4322 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4327 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4328 if not g_Map_GetPoint(c
, RespawnPoint
) then
4330 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4334 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4335 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4336 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4342 FDirection
:= RespawnPoint
.Direction
;
4343 if FDirection
= D_LEFT
then
4349 FBFGFireCounter
:= -1;
4354 SetAction(A_STAND
, True);
4355 FModel
.Direction
:= FDirection
;
4357 for a
:= Low(FTime
) to High(FTime
) do
4360 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4365 FCanJetpack
:= False;
4370 // Àíèìàöèÿ âîçðîæäåíèÿ:
4371 if (not gLoadGameMode
) and (not Silent
) then
4372 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4374 Anim
:= TAnimation
.Create(ID
, False, 3);
4375 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4376 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4380 FSpectator
:= False;
4383 FSpectatePlayer
:= -1;
4386 if g_Game_IsNet
then
4388 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4389 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4391 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4392 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4397 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4400 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4401 else if (not NoMove
) then
4403 GameX
:= gMapInfo
.Width
div 2;
4404 GameY
:= gMapInfo
.Height
div 2;
4413 FWantsInGame
:= False;
4418 if Self
= gPlayer1
then
4423 if Self
= gPlayer2
then
4430 if g_Game_IsNet
then
4431 MH_SEND_PlayerStats(FUID
);
4434 procedure TPlayer
.SwitchNoClip
;
4438 FGhost
:= not FGhost
;
4439 FPhysics
:= not FGhost
;
4451 procedure TPlayer
.Run(Direction
: TDirection
);
4455 if MAX_RUNVEL
> 8 then
4459 if Direction
= D_LEFT
then
4461 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4462 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4465 if FObj
.Vel
.X
< MAX_RUNVEL
then
4466 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4468 // Âîçìîæíî, ïèíàåì êóñêè:
4469 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4471 b
:= Abs(FObj
.Vel
.X
);
4472 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4473 for a
:= 0 to High(gGibs
) do
4475 if gGibs
[a
].Live
and
4476 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4477 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4480 if FObj
.Vel
.X
< 0 then
4482 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4486 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4488 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4496 procedure TPlayer
.SeeDown();
4498 SetAction(A_SEEDOWN
);
4500 if FDirection
= D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4502 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4505 procedure TPlayer
.SeeUp();
4509 if FDirection
= D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4511 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4514 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4522 A_ATTACK
: Prior
:= 2;
4523 A_SEEUP
: Prior
:= 1;
4524 A_SEEDOWN
: Prior
:= 1;
4525 A_ATTACKUP
: Prior
:= 2;
4526 A_ATTACKDOWN
: Prior
:= 2;
4531 if (Prior
> FActionPrior
) or Force
then
4532 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4534 FActionPrior
:= Prior
;
4535 FActionAnim
:= Action
;
4536 FActionForce
:= Force
;
4537 FActionChanged
:= True;
4540 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4543 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4545 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4546 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4547 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4548 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4551 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4558 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4560 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4561 if g_Game_IsServer
and g_Game_IsNet
then
4562 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4566 FJustTeleported
:= True;
4571 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4573 Anim
:= TAnimation
.Create(ID
, False, 3);
4576 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4577 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4578 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4579 if g_Game_IsServer
and g_Game_IsNet
then
4580 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4581 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4585 FObj
.X
:= X
-PLAYER_RECT
.X
;
4586 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4587 if FLive
and FGhost
then
4593 if not g_Game_IsNet
then
4597 SetDirection(D_LEFT
);
4603 SetDirection(D_RIGHT
);
4609 if FDirection
= D_RIGHT
then
4611 SetDirection(D_LEFT
);
4616 SetDirection(D_RIGHT
);
4622 if not silent
and (Anim
<> nil) then
4624 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4625 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4628 if g_Game_IsServer
and g_Game_IsNet
then
4629 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4630 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4637 function nonz(a
: Single): Single;
4645 procedure TPlayer
.Update();
4648 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4649 blockmon
, headwater
, dospawn
: Boolean;
4654 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4655 AnyServer
:= g_Game_IsServer
;
4657 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4658 DoLerp(NetInterpLevel
+ 1)
4664 if FClientID
>= 0 then
4666 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4667 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4668 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4677 if FLive
and (gFly
or FJetpack
) then
4680 if FDirection
= D_LEFT
then
4685 if FLive
and (not FGhost
) then
4687 if FKeys
[KEY_UP
].Pressed
then
4689 if FKeys
[KEY_DOWN
].Pressed
then
4693 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4696 i
:= g_basic
.Sign(FIncCam
);
4697 FIncCam
:= Abs(FIncCam
);
4698 DecMin(FIncCam
, 5, 0);
4699 FIncCam
:= FIncCam
*i
;
4702 // no need to do that each second frame, weapon queue will take care of it
4703 if FLive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4704 if FLive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4706 if gTime
mod (GAME_TICK
*2) <> 0 then
4708 if (FObj
.Vel
.X
= 0) and FLive
then
4710 if FKeys
[KEY_LEFT
].Pressed
then
4712 if FKeys
[KEY_RIGHT
].Pressed
then
4718 g_Obj_Move(@FObj
, True, True, True);
4719 positionChanged(); // this updates spatial accelerators
4725 FActionChanged
:= False;
4729 // Let alive player do some actions
4730 if FKeys
[KEY_LEFT
].Pressed
then Run(D_LEFT
);
4731 if FKeys
[KEY_RIGHT
].Pressed
then Run(D_RIGHT
);
4732 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
4733 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
4734 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
4735 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
4736 if FKeys
[KEY_JUMP
].Pressed
then Jump()
4739 if AnyServer
and FJetpack
then
4743 if NetServer
then MH_SEND_PlayerStats(FUID
);
4745 FCanJetpack
:= True;
4752 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
4754 if FKeys
[k
].Pressed
then
4762 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4765 if (FTime
[T_RESPAWN
] <= gTime
) and
4766 gGameOn
and (not FLive
) then
4768 if (g_Player_GetCount() > 1) then
4772 gExit
:= EXIT_RESTART
;
4777 // Dead spectator actions
4780 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
4781 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
4785 if (FSpectatePlayer
>= High(gPlayers
)) then
4786 FSpectatePlayer
:= -1
4790 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
4791 if gPlayers
[I
] <> nil then
4792 if gPlayers
[I
].Live
then
4793 if gPlayers
[I
].UID
<> FUID
then
4795 FSpectatePlayer
:= I
;
4800 if not SetSpect
then FSpectatePlayer
:= -1;
4811 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
4813 FYTo
:= FObj
.Y
- 32;
4814 FSpectatePlayer
:= -1;
4816 if FKeys
[KEY_DOWN
].Pressed
then
4818 FYTo
:= FObj
.Y
+ 32;
4819 FSpectatePlayer
:= -1;
4821 if FKeys
[KEY_LEFT
].Pressed
then
4823 FXTo
:= FObj
.X
- 32;
4824 FSpectatePlayer
:= -1;
4826 if FKeys
[KEY_RIGHT
].Pressed
then
4828 FXTo
:= FObj
.X
+ 32;
4829 FSpectatePlayer
:= -1;
4832 if (FXTo
< -64) then
4834 else if (FXTo
> gMapInfo
.Width
+ 32) then
4835 FXTo
:= gMapInfo
.Width
+ 32;
4836 if (FYTo
< -72) then
4838 else if (FYTo
> gMapInfo
.Height
+ 32) then
4839 FYTo
:= gMapInfo
.Height
+ 32;
4844 g_Obj_Move(@FObj
, True, True, True);
4845 positionChanged(); // this updates spatial accelerators
4852 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
4853 if gPlayers
[FSpectatePlayer
] <> nil then
4854 if gPlayers
[FSpectatePlayer
].Live
then
4856 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
4857 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
4861 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
4862 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
4863 PANEL_BLOCKMON
, True);
4864 headwater
:= HeadInLiquid(0, 0);
4866 // Ñîïðîòèâëåíèå âîçäóõà:
4867 if (not FLive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
4868 if FObj
.Vel
.X
<> 0 then
4869 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
4871 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
4872 DecMin(FPain
, 5, 0);
4873 DecMin(FPickup
, 1, 0);
4875 if FLive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
4877 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
4878 FMegaRulez
[MR_SUIT
] := 0;
4879 FMegaRulez
[MR_INVUL
] := 0;
4880 FMegaRulez
[MR_INVIS
] := 0;
4881 Kill(K_FALLKILL
, 0, HIT_FALL
);
4888 if FCurrWeap
= WEAPON_SAW
then
4889 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
4890 FSawSoundSelect
.IsPlaying()) then
4891 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
4894 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
4895 (not FJetSoundOff
.IsPlaying()) then
4897 FJetSoundFly
.SetPosition(0);
4898 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
4901 for b
:= WP_FIRST
to WP_LAST
do
4902 if FReloading
[b
] > 0 then
4908 if FShellTimer
> -1 then
4909 if FShellTimer
= 0 then
4911 if FShellType
= SHELL_SHELL
then
4912 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4913 GameVelX
, GameVelY
-2, SHELL_SHELL
)
4914 else if FShellType
= SHELL_DBLSHELL
then
4916 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4917 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
4918 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4919 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
4922 end else Dec(FShellTimer
);
4924 if (FBFGFireCounter
> -1) then
4925 if FBFGFireCounter
= 0 then
4929 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
4930 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
4931 xd
:= wx
+IfThen(FDirection
= D_LEFT
, -30, 30);
4932 yd
:= wy
+firediry();
4933 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
4934 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
4935 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
4936 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
4937 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
4940 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
4941 FBFGFireCounter
:= -1;
4944 FBFGFireCounter
:= 0
4946 Dec(FBFGFireCounter
);
4948 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
4950 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
4952 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
4955 if (headwater
or blockmon
) then
4961 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
4964 else if (FAir
mod 31 = 0) and not blockmon
then
4966 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
4967 if Random(2) = 0 then
4968 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
4970 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
4972 end else if FAir
< AIR_DEF
then
4975 if FFireTime
> 0 then
4977 if BodyInLiquid(0, 0) then
4982 else if FMegaRulez
[MR_SUIT
] >= gTime
then
4984 if FMegaRulez
[MR_SUIT
] = gTime
then
4991 if FFirePainTime
<= 0 then
4993 if g_Game_IsServer
then
4994 Damage(5, FFireAttacker
, 0, 0, HIT_FLAME
);
4995 FFirePainTime
:= 18;
4997 FFirePainTime
:= FFirePainTime
- 1;
4998 FFireTime
:= FFireTime
- 1;
4999 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5000 MH_SEND_PlayerStats(FUID
);
5004 if FDamageBuffer
> 0 then
5006 if FDamageBuffer
>= 9 then
5010 if FDamageBuffer
< 30 then i
:= 9
5011 else if FDamageBuffer
< 100 then i
:= 18
5015 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5016 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5017 FHealth
:= FHealth
-ii
;
5020 FHealth
:= FHealth
+FArmor
;
5025 if FHealth
<= 0 then
5026 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5027 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5028 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5032 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5033 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5034 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5035 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5042 end; // if FLive then ...
5044 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5046 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5047 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5048 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5049 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5051 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5052 then SetAction(A_STAND
, True);
5054 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5056 for b
:= Low(FKeys
) to High(FKeys
) do
5057 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5060 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5062 x
:= FObj
.X
+PLAYER_RECT
.X
;
5063 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5064 w
:= PLAYER_RECT
.Width
;
5065 h
:= PLAYER_RECT
.Height
;
5068 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5070 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5071 FObj
.Y
+PLAYER_RECT
.Y
,
5078 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5080 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5081 FObj
.Y
+PLAYER_RECT
.Y
,
5085 Panel
.Width
, Panel
.Height
);
5088 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5090 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5091 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5092 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5093 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5096 function g_Player_ValidName(Name
: string): Boolean;
5102 if gPlayers
= nil then Exit
;
5104 for a
:= 0 to High(gPlayers
) do
5105 if gPlayers
[a
] <> nil then
5106 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5113 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5117 d
:= FModel
.Direction
;
5119 FModel
.Direction
:= Direction
;
5120 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5122 FDirection
:= Direction
;
5125 function TPlayer
.GetKeys(): Byte;
5129 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5130 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5131 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5133 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5134 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5137 procedure TPlayer
.Use();
5141 if FTime
[T_USE
] > gTime
then Exit
;
5143 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5144 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5146 for a
:= 0 to High(gPlayers
) do
5147 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5148 gPlayers
[a
].Live
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5149 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5150 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5152 gPlayers
[a
].Touch();
5153 if g_Game_IsNet
and g_Game_IsServer
then
5154 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5157 FTime
[T_USE
] := gTime
+120;
5160 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5164 WX
, WY
, XD
, YD
: Integer;
5175 if R_BERSERK
in FRulez
then
5177 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5178 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5179 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5182 locobj
.rect
.Width
:= 39;
5183 locobj
.rect
.Height
:= 52;
5184 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5185 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5186 locobj
.Accel
.X
:= xd
-wx
;
5187 locobj
.Accel
.y
:= yd
-wy
;
5189 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5190 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5192 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5196 FPain
:= min(FPain
+ 25, 50);
5198 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5203 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5204 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5206 FSawSoundSelect
.Stop();
5208 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5210 else if not FSawSoundHit
.IsPlaying() then
5212 FSawSoundSelect
.Stop();
5213 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5220 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5221 FFireAngle
:= FAngle
;
5223 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5224 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5229 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5230 FFireAngle
:= FAngle
;
5233 FShellType
:= SHELL_SHELL
;
5238 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5239 FFireAngle
:= FAngle
;
5242 FShellType
:= SHELL_DBLSHELL
;
5247 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5248 FFireAngle
:= FAngle
;
5250 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5251 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5254 WEAPON_ROCKETLAUNCHER
:
5256 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5257 FFireAngle
:= FAngle
;
5263 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5264 FFireAngle
:= FAngle
;
5270 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5271 FFireAngle
:= FAngle
;
5275 WEAPON_SUPERPULEMET
:
5277 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5278 FFireAngle
:= FAngle
;
5280 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5281 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5284 WEAPON_FLAMETHROWER
:
5286 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5287 FFireAngle
:= FAngle
;
5294 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5295 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5296 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5299 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5301 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5302 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5305 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5309 if NetInterpLevel
< 1 then
5319 AX
:= Abs(FXTo
- FObj
.X
);
5320 AY
:= Abs(FYTo
- FObj
.Y
);
5321 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5323 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5328 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5330 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5331 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5332 PANEL_LIFTUP
, False) then Result
:= -1
5334 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5335 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5336 PANEL_LIFTDOWN
, False) then Result
:= 1
5340 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5347 if Flag
= FLAG_NONE
then
5350 if not g_Game_IsServer
then Exit
;
5352 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5353 if (Flag
= FTeam
) and
5354 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5355 (FFlag
<> FLAG_NONE
) then
5357 if FFlag
= FLAG_RED
then
5358 s
:= _lc
[I_PLAYER_FLAG_RED
]
5360 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5362 evtype
:= FLAG_STATE_SCORED
;
5364 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5365 Insert('.', ts
, Length(ts
) + 1 - 3);
5366 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5368 g_Map_ResetFlag(FFlag
);
5369 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5371 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5374 if g_Game_IsNet
then
5376 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5380 gFlags
[FFlag
].CaptureTime
:= 0;
5385 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5386 if (Flag
= FTeam
) and
5387 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5389 if Flag
= FLAG_RED
then
5390 s
:= _lc
[I_PLAYER_FLAG_RED
]
5392 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5394 evtype
:= FLAG_STATE_RETURNED
;
5395 gFlags
[Flag
].CaptureTime
:= 0;
5397 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5399 g_Map_ResetFlag(Flag
);
5400 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5403 if g_Game_IsNet
then
5405 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5411 // Ïîäîáðàë ÷óæîé ôëàã:
5412 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5416 if Flag
= FLAG_RED
then
5417 s
:= _lc
[I_PLAYER_FLAG_RED
]
5419 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5421 evtype
:= FLAG_STATE_CAPTURED
;
5423 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5425 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5427 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5430 if g_Game_IsNet
then
5432 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5438 procedure TPlayer
.SetFlag(Flag
: Byte);
5441 if FModel
<> nil then
5442 FModel
.SetFlag(FFlag
);
5445 function TPlayer
.DropFlag(): Boolean;
5450 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5452 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5453 with gFlags
[FFlag
] do
5457 Direction
:= FDirection
;
5458 State
:= FLAG_STATE_DROPPED
;
5460 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5461 (FObj
.Vel
.Y
div 2)-2+Random(5));
5462 positionChanged(); // this updates spatial accelerators
5464 if FFlag
= FLAG_RED
then
5465 s
:= _lc
[I_PLAYER_FLAG_RED
]
5467 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5469 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5470 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5472 if g_Game_IsNet
then
5473 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5479 procedure TPlayer
.GetSecret();
5484 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5486 Assert(Key
<= High(FKeys
));
5488 FKeys
[Key
].Pressed
:= True;
5489 FKeys
[Key
].Time
:= Time
;
5492 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5494 Result
:= FKeys
[K
].Pressed
;
5497 procedure TPlayer
.ReleaseKeys();
5501 for a
:= Low(FKeys
) to High(FKeys
) do
5503 FKeys
[a
].Pressed
:= False;
5508 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5512 function TPlayer
.firediry(): Integer;
5514 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5515 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5519 procedure TPlayer
.RememberState();
5523 FSavedState
.Health
:= FHealth
;
5524 FSavedState
.Armor
:= FArmor
;
5525 FSavedState
.Air
:= FAir
;
5526 FSavedState
.JetFuel
:= FJetFuel
;
5527 FSavedState
.CurrWeap
:= FCurrWeap
;
5528 FSavedState
.NextWeap
:= FNextWeap
;
5529 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5532 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5534 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5536 FSavedState
.Rulez
:= FRulez
;
5537 FSavedState
.WaitRecall
:= True;
5540 procedure TPlayer
.RecallState();
5544 if not FSavedState
.WaitRecall
then Exit
;
5546 FHealth
:= FSavedState
.Health
;
5547 FArmor
:= FSavedState
.Armor
;
5548 FAir
:= FSavedState
.Air
;
5549 FJetFuel
:= FSavedState
.JetFuel
;
5550 FCurrWeap
:= FSavedState
.CurrWeap
;
5551 FNextWeap
:= FSavedState
.NextWeap
;
5552 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5555 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5557 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5559 FRulez
:= FSavedState
.Rulez
;
5560 FSavedState
.WaitRecall
:= False;
5562 if gGameSettings
.GameType
= GT_SERVER
then
5563 MH_SEND_PlayerStats(FUID
);
5566 procedure TPlayer
.SaveState(var Mem
: TBinMemoryWriter
);
5578 Mem
:= TBinMemoryWriter
.Create(i
);
5580 // Ñèãíàòóðà èãðîêà:
5581 sig
:= PLAYER_SIGNATURE
; // 'PLYR'
5582 Mem
.WriteDWORD(sig
);
5584 Mem
.WriteBoolean(FIamBot
);
5586 Mem
.WriteWord(FUID
);
5588 Mem
.WriteString(FName
, 32);
5590 Mem
.WriteByte(FTeam
);
5592 Mem
.WriteBoolean(FLive
);
5593 // Èçðàñõîäîâàë ëè âñå æèçíè:
5594 Mem
.WriteBoolean(FNoRespawn
);
5596 if FDirection
= D_LEFT
then
5602 Mem
.WriteInt(FHealth
);
5604 Mem
.WriteByte(FLives
);
5606 Mem
.WriteInt(FArmor
);
5610 Mem
.WriteInt(FJetFuel
);
5612 Mem
.WriteInt(FPain
);
5614 Mem
.WriteInt(FKills
);
5616 Mem
.WriteInt(FMonsterKills
);
5618 Mem
.WriteInt(FFrags
);
5620 Mem
.WriteByte(FFragCombo
);
5621 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5622 Mem
.WriteDWORD(FLastFrag
);
5624 Mem
.WriteInt(FDeath
);
5625 // Êàêîé ôëàã íåñåò:
5626 Mem
.WriteByte(FFlag
);
5628 Mem
.WriteInt(FSecrets
);
5630 Mem
.WriteByte(FCurrWeap
);
5632 Mem
.WriteWord(FNextWeap
);
5634 Mem
.WriteByte(FNextWeapDelay
);
5635 // Âðåìÿ çàðÿäêè BFG:
5636 Mem
.WriteSmallInt(FBFGFireCounter
);
5638 Mem
.WriteInt(FDamageBuffer
);
5639 // Ïîñëåäíèé óäàðèâøèé:
5640 Mem
.WriteWord(FLastSpawnerUID
);
5641 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5642 Mem
.WriteByte(FLastHit
);
5644 Obj_SaveState(@FObj
, Mem
);
5645 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5646 for i
:= A_BULLETS
to A_HIGH
do
5647 Mem
.WriteWord(FAmmo
[i
]);
5648 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5649 for i
:= A_BULLETS
to A_HIGH
do
5650 Mem
.WriteWord(FMaxAmmo
[i
]);
5652 for i
:= WP_FIRST
to WP_LAST
do
5653 Mem
.WriteBoolean(FWeapon
[i
]);
5654 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5655 for i
:= WP_FIRST
to WP_LAST
do
5656 Mem
.WriteWord(FReloading
[i
]);
5658 if R_ITEM_BACKPACK
in FRulez
then
5663 // Íàëè÷èå êðàñíîãî êëþ÷à:
5664 if R_KEY_RED
in FRulez
then
5669 // Íàëè÷èå çåëåíîãî êëþ÷à:
5670 if R_KEY_GREEN
in FRulez
then
5675 // Íàëè÷èå ñèíåãî êëþ÷à:
5676 if R_KEY_BLUE
in FRulez
then
5681 // Íàëè÷èå áåðñåðêà:
5682 if R_BERSERK
in FRulez
then
5687 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5688 for i
:= MR_SUIT
to MR_MAX
do
5689 Mem
.WriteDWORD(FMegaRulez
[i
]);
5690 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5691 for i
:= T_RESPAWN
to T_FLAGCAP
do
5692 Mem
.WriteDWORD(FTime
[i
]);
5695 Mem
.WriteString(str
);
5705 procedure TPlayer
.LoadState(var Mem
: TBinMemoryReader
);
5715 // Ñèãíàòóðà èãðîêà:
5717 if sig
<> PLAYER_SIGNATURE
then // 'PLYR'
5719 raise EBinSizeError
.Create('TPlayer.LoadState: Wrong Player Signature');
5722 Mem
.ReadBoolean(FIamBot
);
5726 Mem
.ReadString(str
);
5727 if (Self
<> gPlayer1
) and (Self
<> gPlayer2
) then
5730 Mem
.ReadByte(FTeam
);
5732 Mem
.ReadBoolean(FLive
);
5733 // Èçðàñõîäîâàë ëè âñå æèçíè:
5734 Mem
.ReadBoolean(FNoRespawn
);
5738 FDirection
:= D_LEFT
5740 FDirection
:= D_RIGHT
;
5742 Mem
.ReadInt(FHealth
);
5744 Mem
.ReadByte(FLives
);
5746 Mem
.ReadInt(FArmor
);
5750 Mem
.ReadInt(FJetFuel
);
5754 Mem
.ReadInt(FKills
);
5756 Mem
.ReadInt(FMonsterKills
);
5758 Mem
.ReadInt(FFrags
);
5760 Mem
.ReadByte(FFragCombo
);
5761 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5762 Mem
.ReadDWORD(FLastFrag
);
5764 Mem
.ReadInt(FDeath
);
5765 // Êàêîé ôëàã íåñåò:
5766 Mem
.ReadByte(FFlag
);
5768 Mem
.ReadInt(FSecrets
);
5770 Mem
.ReadByte(FCurrWeap
);
5772 Mem
.ReadWord(FNextWeap
);
5774 Mem
.ReadByte(FNextWeapDelay
);
5775 // Âðåìÿ çàðÿäêè BFG:
5776 Mem
.ReadSmallInt(FBFGFireCounter
);
5778 Mem
.ReadInt(FDamageBuffer
);
5779 // Ïîñëåäíèé óäàðèâøèé:
5780 Mem
.ReadWord(FLastSpawnerUID
);
5781 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5782 Mem
.ReadByte(FLastHit
);
5784 Obj_LoadState(@FObj
, Mem
);
5785 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5786 for i
:= A_BULLETS
to A_HIGH
do
5787 Mem
.ReadWord(FAmmo
[i
]);
5788 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5789 for i
:= A_BULLETS
to A_HIGH
do
5790 Mem
.ReadWord(FMaxAmmo
[i
]);
5792 for i
:= WP_FIRST
to WP_LAST
do
5793 Mem
.ReadBoolean(FWeapon
[i
]);
5794 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5795 for i
:= WP_FIRST
to WP_LAST
do
5796 Mem
.ReadWord(FReloading
[i
]);
5800 Include(FRulez
, R_ITEM_BACKPACK
);
5801 // Íàëè÷èå êðàñíîãî êëþ÷à:
5804 Include(FRulez
, R_KEY_RED
);
5805 // Íàëè÷èå çåëåíîãî êëþ÷à:
5808 Include(FRulez
, R_KEY_GREEN
);
5809 // Íàëè÷èå ñèíåãî êëþ÷à:
5812 Include(FRulez
, R_KEY_BLUE
);
5813 // Íàëè÷èå áåðñåðêà:
5816 Include(FRulez
, R_BERSERK
);
5817 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5818 for i
:= MR_SUIT
to MR_MAX
do
5819 Mem
.ReadDWORD(FMegaRulez
[i
]);
5820 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5821 for i
:= T_RESPAWN
to T_FLAGCAP
do
5822 Mem
.ReadDWORD(FTime
[i
]);
5824 Mem
.ReadString(str
);
5826 Mem
.ReadByte(FColor
.R
);
5827 Mem
.ReadByte(FColor
.G
);
5828 Mem
.ReadByte(FColor
.B
);
5829 if Self
= gPlayer1
then
5831 str
:= gPlayer1Settings
.Model
;
5832 FColor
:= gPlayer1Settings
.Color
;
5834 if Self
= gPlayer2
then
5836 str
:= gPlayer2Settings
.Model
;
5837 FColor
:= gPlayer2Settings
.Color
;
5839 // Îáíîâëÿåì ìîäåëü èãðîêà:
5841 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
5842 FModel
.Color
:= TEAMCOLOR
[FTeam
]
5844 FModel
.Color
:= FColor
;
5847 procedure TPlayer
.AllRulez(Health
: Boolean);
5853 FHealth
:= PLAYER_HP_LIMIT
;
5854 FArmor
:= PLAYER_AP_LIMIT
;
5858 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
5859 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
5860 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5863 procedure TPlayer
.RestoreHealthArmor();
5865 FHealth
:= PLAYER_HP_LIMIT
;
5866 FArmor
:= PLAYER_AP_LIMIT
;
5869 procedure TPlayer
.FragCombo();
5873 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
5875 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
5877 if FFragCombo
< 5 then
5879 Param
:= FUID
or (FFragCombo
shl 16);
5880 if (FComboEvnt
>= Low(gDelayedEvents
)) and
5881 (FComboEvnt
<= High(gDelayedEvents
)) and
5882 gDelayedEvents
[FComboEvnt
].Pending
and
5883 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
5884 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
5886 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
5887 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
5890 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
5898 procedure TPlayer
.GiveItem(ItemType
: Byte);
5902 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
5904 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
5908 if FAir
< AIR_MAX
then
5915 if not (R_BERSERK
in FRulez
) then
5917 Include(FRulez
, R_BERSERK
);
5918 if FBFGFireCounter
< 1 then
5920 FCurrWeap
:= WEAPON_KASTET
;
5922 FModel
.SetWeapon(WEAPON_KASTET
);
5926 FBerserk
:= gTime
+30000;
5928 if FHealth
< PLAYER_HP_SOFT
then
5930 FHealth
:= PLAYER_HP_SOFT
;
5931 FBerserk
:= gTime
+30000;
5936 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
5938 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
5942 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
5944 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
5948 if FJetFuel
< JET_MAX
then
5950 FJetFuel
:= JET_MAX
;
5953 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
5954 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
5956 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
5957 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5959 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
5961 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
5963 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
5964 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5967 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
5968 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
5969 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
5970 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
5971 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
5972 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
5973 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
5974 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
5975 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
5977 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5978 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
5979 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5980 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
5981 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5982 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
5983 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5984 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
5985 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
5988 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
5989 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
5990 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
5991 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
5992 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
5994 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
5995 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
5996 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
5997 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
5998 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6000 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6001 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6002 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6003 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6005 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6008 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6009 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6010 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6012 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6013 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6018 if g_Game_IsNet
and g_Game_IsServer
then
6019 MH_SEND_PlayerStats(FUID
);
6022 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6027 if (Random(5) = 1) and (Times
= 1) then
6030 if BodyInLiquid(0, 0) then
6032 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6033 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6034 if Random(2) = 0 then
6035 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6037 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6041 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6043 for i
:= 1 to Times
do
6045 Anim
:= TAnimation
.Create(id
, False, 3);
6047 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6048 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6054 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6059 if (Random(10) = 1) and (Times
= 1) then
6062 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6064 for i
:= 1 to Times
do
6066 Anim
:= TAnimation
.Create(id
, False, 3);
6068 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6069 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6075 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6077 FSawSound
.Pause(Enable
);
6078 FSawSoundIdle
.Pause(Enable
);
6079 FSawSoundHit
.Pause(Enable
);
6080 FSawSoundSelect
.Pause(Enable
);
6085 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6090 FObj
.Rect
:= PLAYER_CORPSERECT
;
6091 FModelName
:= ModelName
;
6096 FState
:= CORPSE_STATE_MESS
;
6097 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6101 FState
:= CORPSE_STATE_NORMAL
;
6102 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6106 destructor TCorpse
.Destroy();
6113 procedure TCorpse
.positionChanged (); begin end;
6115 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6119 if FState
= CORPSE_STATE_REMOVEME
then
6122 FDamage
:= FDamage
+ Value
;
6124 if FDamage
> 150 then
6126 if FAnimation
<> nil then
6131 FState
:= CORPSE_STATE_REMOVEME
;
6133 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6134 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6135 FModelName
, FColor
);
6136 // Çâóê ìÿñà îò òðóïà:
6137 pm
:= g_PlayerModel_Get(FModelName
);
6138 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6144 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6145 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6146 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6147 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6148 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6153 procedure TCorpse
.Draw();
6155 if FState
= CORPSE_STATE_REMOVEME
then
6158 if FAnimation
<> nil then
6159 FAnimation
.Draw(FObj
.X
, FObj
.Y
, M_NONE
);
6161 if FAnimationMask
<> nil then
6164 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, M_NONE
);
6171 procedure TCorpse
.Update();
6175 if FState
= CORPSE_STATE_REMOVEME
then
6178 if gTime
mod (GAME_TICK
*2) <> 0 then
6180 g_Obj_Move(@FObj
, True, True, True);
6181 positionChanged(); // this updates spatial accelerators
6185 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6186 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6188 st
:= g_Obj_Move(@FObj
, True, True, True);
6189 positionChanged(); // this updates spatial accelerators
6191 if WordBool(st
and MOVE_FALLOUT
) then
6193 FState
:= CORPSE_STATE_REMOVEME
;
6197 if FAnimation
<> nil then
6198 FAnimation
.Update();
6199 if FAnimationMask
<> nil then
6200 FAnimationMask
.Update();
6203 procedure TCorpse
.SaveState(var Mem
: TBinMemoryWriter
);
6212 sig
:= CORPSE_SIGNATURE
; // 'CORP'
6213 Mem
.WriteDWORD(sig
);
6215 Mem
.WriteByte(FState
);
6216 // Íàêîïëåííûé óðîí:
6217 Mem
.WriteByte(FDamage
);
6219 Mem
.WriteByte(FColor
.R
);
6220 Mem
.WriteByte(FColor
.G
);
6221 Mem
.WriteByte(FColor
.B
);
6223 Obj_SaveState(@FObj
, Mem
);
6224 // Åñòü ëè àíèìàöèÿ:
6225 anim
:= FAnimation
<> nil;
6226 Mem
.WriteBoolean(anim
);
6227 // Åñëè åñòü - ñîõðàíÿåì:
6229 FAnimation
.SaveState(Mem
);
6230 // Åñòü ëè ìàñêà àíèìàöèè:
6231 anim
:= FAnimationMask
<> nil;
6232 Mem
.WriteBoolean(anim
);
6233 // Åñëè åñòü - ñîõðàíÿåì:
6235 FAnimationMask
.SaveState(Mem
);
6238 procedure TCorpse
.LoadState(var Mem
: TBinMemoryReader
);
6248 if sig
<> CORPSE_SIGNATURE
then // 'CORP'
6250 raise EBinSizeError
.Create('TCorpse.LoadState: Wrong Corpse Signature');
6253 Mem
.ReadByte(FState
);
6254 // Íàêîïëåííûé óðîí:
6255 Mem
.ReadByte(FDamage
);
6257 Mem
.ReadByte(FColor
.R
);
6258 Mem
.ReadByte(FColor
.G
);
6259 Mem
.ReadByte(FColor
.B
);
6261 Obj_LoadState(@FObj
, Mem
);
6262 // Åñòü ëè àíèìàöèÿ:
6263 Mem
.ReadBoolean(anim
);
6264 // Åñëè åñòü - çàãðóæàåì:
6267 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6268 FAnimation
.LoadState(Mem
);
6270 // Åñòü ëè ìàñêà àíèìàöèè:
6271 Mem
.ReadBoolean(anim
);
6272 // Åñëè åñòü - çàãðóæàåì:
6275 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6276 FAnimationMask
.LoadState(Mem
);
6282 constructor TBot
.Create();
6289 FSpectator
:= False;
6296 for a
:= WP_FIRST
to WP_LAST
do
6298 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6299 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6300 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6304 destructor TBot
.Destroy();
6307 inherited Destroy();
6310 procedure TBot
.Draw();
6314 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6315 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6318 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6320 inherited Respawn(Silent
, Force
);
6323 FSelectedWeapon
:= FCurrWeap
;
6328 procedure TBot
.UpdateCombat();
6341 TTargetRecord
= array of TTarget
;
6343 function Compare(a
, b
: TTarget
): Integer;
6345 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6348 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6350 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6351 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6353 if a
.Dist
> b
.Dist
then // B áëèæå
6355 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6358 else // Ñòðàííî -> A
6363 a
, x1
, y1
, x2
, y2
: Integer;
6364 targets
: TTargetRecord
;
6366 Target
, BestTarget
: TTarget
;
6367 firew
, fireh
: Integer;
6371 vsPlayer
, vsMonster
, ok
: Boolean;
6374 function monsUpdate (mon
: TMonster
): Boolean;
6376 result
:= false; // don't stop
6377 if mon
.Live
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6379 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6381 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6382 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6384 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6385 if g_TraceVector(x1
, y1
, x2
, y2
) then
6387 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6388 SetLength(targets
, Length(targets
)+1);
6389 with targets
[High(targets
)] do
6396 Rect
:= mon
.Obj
.Rect
;
6397 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6398 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6399 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6408 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6409 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6411 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6412 if FCurrWeap
<> FSelectedWeapon
then
6415 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6416 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6418 RemoveAIFlag('NEEDFIRE');
6421 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6422 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6423 else PressKey(KEY_FIRE
);
6427 // Êîîðäèíàòû ñòâîëà:
6428 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6429 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6431 Target
.UID
:= FTargetUID
;
6434 if Target
.UID
<> 0 then
6435 begin // Öåëü åñòü - íàñòðàèâàåì
6436 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6439 tpla
:= g_Player_Get(Target
.UID
);
6443 if (@FObj
) <> nil then
6450 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6451 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6452 Target
.Rect
:= PLAYER_RECT
;
6453 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6454 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6455 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6456 Target
.IsPlayer
:= True;
6460 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6463 mon
:= g_Monsters_ByUID(Target
.UID
);
6466 Target
.X
:= mon
.Obj
.X
;
6467 Target
.Y
:= mon
.Obj
.Y
;
6469 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6470 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6471 Target
.Rect
:= mon
.Obj
.Rect
;
6472 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6473 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6474 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6475 Target
.IsPlayer
:= False;
6482 begin // Öåëè íåò - îáíóëÿåì
6487 Target
.Visible
:= False;
6488 Target
.Line
:= False;
6489 Target
.IsPlayer
:= False;
6494 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6495 if (not Target
.Line
) or (not Target
.Visible
) then
6499 for a
:= 0 to High(gPlayers
) do
6500 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].Live
) and
6501 (gPlayers
[a
].FUID
<> FUID
) and
6502 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6503 (not gPlayers
[a
].NoTarget
) and
6504 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6506 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6507 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6510 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6511 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6513 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6514 if g_TraceVector(x1
, y1
, x2
, y2
) then
6516 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6517 SetLength(targets
, Length(targets
)+1);
6518 with targets
[High(targets
)] do
6520 UID
:= gPlayers
[a
].FUID
;
6521 X
:= gPlayers
[a
].FObj
.X
;
6522 Y
:= gPlayers
[a
].FObj
.Y
;
6525 Rect
:= PLAYER_RECT
;
6526 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6527 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6528 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6536 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6539 // Åñëè åñòü âîçìîæíûå öåëè:
6540 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6541 if targets
<> nil then
6543 // Âûáèðàåì íàèëó÷øóþ öåëü:
6544 BestTarget
:= targets
[0];
6545 if Length(targets
) > 1 then
6546 for a
:= 1 to High(targets
) do
6547 if Compare(BestTarget
, targets
[a
]) = 1 then
6548 BestTarget
:= targets
[a
];
6550 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6551 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6552 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6554 Target
:= BestTarget
;
6556 if (Healthy() = 3) or ((Healthy() = 2)) then
6557 begin // Åñëè çäîðîâû - äîãîíÿåì
6558 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6559 SetAIFlag('GORIGHT', '1');
6560 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6561 SetAIFlag('GOLEFT', '1');
6564 begin // Åñëè ïîáèòû - óáåãàåì
6565 if ((RunDirection() = D_LEFT
) and (Target
.X
< FObj
.X
)) then
6566 SetAIFlag('GORIGHT', '1');
6567 if ((RunDirection() = D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6568 SetAIFlag('GOLEFT', '1');
6571 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6572 SelectWeapon(Abs(x1
-Target
.cX
));
6577 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6578 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6579 if Target
.UID
<> 0 then
6581 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6582 Target
.Y
+ Target
.Rect
.Y
) then
6583 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6584 if (Healthy() = 3) or ((Healthy() = 2)) then
6585 begin // Åñëè çäîðîâû - äîãîíÿåì
6586 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6587 SetAIFlag('GORIGHT', '1');
6588 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6589 SetAIFlag('GOLEFT', '1');
6592 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6594 if ((RunDirection() = D_LEFT
) and (Target
.X
< FObj
.X
)) then
6595 SetAIFlag('GORIGHT', '1');
6596 if ((RunDirection() = D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6597 SetAIFlag('GOLEFT', '1');
6601 begin // Öåëü ïîêà íà "ýêðàíå"
6602 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6603 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6604 FLastVisible
:= gTime
;
6605 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6606 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6608 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6609 SetAIFlag('GORIGHT', '1');
6610 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6611 SetAIFlag('GOLEFT', '1');
6615 // Âûáèðàåì óãîë ââåðõ:
6616 if FDirection
= D_LEFT
then
6617 angle
:= ANGLE_LEFTUP
6619 angle
:= ANGLE_RIGHTUP
;
6621 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6622 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6624 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6625 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6626 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6627 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6628 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6629 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6630 begin // òî íóæíî ñòðåëÿòü ââåðõ
6631 SetAIFlag('NEEDFIRE', '1');
6632 SetAIFlag('NEEDSEEUP', '1');
6635 // Âûáèðàåì óãîë âíèç:
6636 if FDirection
= D_LEFT
then
6637 angle
:= ANGLE_LEFTDOWN
6639 angle
:= ANGLE_RIGHTDOWN
;
6641 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6642 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6644 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6645 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6646 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6647 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6648 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6649 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6650 begin // òî íóæíî ñòðåëÿòü âíèç
6651 SetAIFlag('NEEDFIRE', '1');
6652 SetAIFlag('NEEDSEEDOWN', '1');
6655 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6656 if Target
.Visible
and
6657 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6658 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6660 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6661 if ((FDirection
= D_LEFT
) and (Target
.X
< FObj
.X
)) or
6662 ((FDirection
= D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6663 begin // òî íóæíî ñòðåëÿòü âïåðåä
6664 SetAIFlag('NEEDFIRE', '1');
6665 SetAIFlag('NEEDSEEDOWN', '');
6666 SetAIFlag('NEEDSEEUP', '');
6668 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6669 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6670 if GetRnd(FDifficult
.CloseJump
) then
6671 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6672 if Abs(FObj
.X
-Target
.X
) < 128 then
6676 if Random(a
) = 0 then
6677 SetAIFlag('NEEDJUMP', '1');
6681 // Åñëè öåëü âñå åùå åñòü:
6682 if Target
.UID
<> 0 then
6683 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
6684 Target
.UID
:= 0 // òî çàáûòü öåëü
6685 else // Åñëè âèäåëè íåäàâíî
6686 begin // íî öåëü óáèëè
6687 if Target
.IsPlayer
then
6688 begin // Öåëü - èãðîê
6689 pla
:= g_Player_Get(Target
.UID
);
6690 if (pla
= nil) or (not pla
.Live
) or pla
.NoTarget
or
6691 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6692 Target
.UID
:= 0; // òî çàáûòü öåëü
6695 begin // Öåëü - ìîíñòð
6696 mon
:= g_Monsters_ByUID(Target
.UID
);
6697 if (mon
= nil) or (not mon
.Live
) then
6698 Target
.UID
:= 0; // òî çàáûòü öåëü
6701 end; // if Target.UID <> 0
6703 FTargetUID
:= Target
.UID
;
6705 // Åñëè âîçìîæíûõ öåëåé íåò:
6706 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
6707 if targets
= nil then
6708 if GetAIFlag('ATTACKLEFT') <> '' then
6709 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
6710 RemoveAIFlag('ATTACKLEFT');
6712 SetAIFlag('NEEDJUMP', '1');
6714 if RunDirection() = D_RIGHT
then
6715 begin // Èäåì íå â òó ñòîðîíó
6716 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6717 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
6718 SetAIFlag('NEEDFIRE', '1');
6719 SetAIFlag('GOLEFT', '1');
6723 begin // Èäåì â íóæíóþ ñòîðîíó
6724 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6725 SetAIFlag('NEEDFIRE', '1');
6726 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6727 SetAIFlag('GORIGHT', '1');
6731 if GetAIFlag('ATTACKRIGHT') <> '' then
6732 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
6733 RemoveAIFlag('ATTACKRIGHT');
6735 SetAIFlag('NEEDJUMP', '1');
6737 if RunDirection() = D_LEFT
then
6738 begin // Èäåì íå â òó ñòîðîíó
6739 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6740 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
6741 SetAIFlag('NEEDFIRE', '1');
6742 SetAIFlag('GORIGHT', '1');
6747 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6748 SetAIFlag('NEEDFIRE', '1');
6749 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6750 SetAIFlag('GOLEFT', '1');
6754 //HACK! (does it belongs there?)
6755 RealizeCurrentWeapon();
6757 // Åñëè åñòü âîçìîæíûå öåëè:
6758 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
6759 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6760 for a
:= 0 to High(targets
) do
6762 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
6763 if GetRnd(FDifficult
.DiagFire
) then
6765 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
6766 if FDirection
= D_LEFT
then
6767 angle
:= ANGLE_LEFTUP
6769 angle
:= ANGLE_RIGHTUP
;
6771 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6772 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6774 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6775 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6776 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6777 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6778 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6780 SetAIFlag('NEEDFIRE', '1');
6781 SetAIFlag('NEEDSEEUP', '1');
6784 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
6785 if FDirection
= D_LEFT
then
6786 angle
:= ANGLE_LEFTDOWN
6788 angle
:= ANGLE_RIGHTDOWN
;
6790 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6791 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6793 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6794 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6795 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6796 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6797 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6799 SetAIFlag('NEEDFIRE', '1');
6800 SetAIFlag('NEEDSEEDOWN', '1');
6804 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
6805 if targets
[a
].Line
and targets
[a
].Visible
and
6806 (((FDirection
= D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
6807 ((FDirection
= D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
6809 SetAIFlag('NEEDFIRE', '1');
6814 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
6815 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
6816 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
6817 40+GetInterval(FDifficult
.Cover
, 40)) then
6818 SetAIFlag('NEEDJUMP', '1');
6820 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
6821 ammo
:= GetAmmoByWeapon(FCurrWeap
);
6822 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
6823 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
6825 SetAIFlag('SELECTWEAPON', '1');
6827 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
6828 if GetAIFlag('SELECTWEAPON') = '1' then
6831 RemoveAIFlag('SELECTWEAPON');
6835 procedure TBot
.Update();
6848 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
6849 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
6851 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
6853 if g_debug_BotAIOff
= 3 then
6863 RealizeCurrentWeapon();
6870 procedure TBot
.ReleaseKey(Key
: Byte);
6879 function TBot
.KeyPressed(Key
: Word): Boolean;
6881 Result
:= FKeys
[Key
].Pressed
;
6884 function TBot
.GetAIFlag(aName
: String20
): String20
;
6890 aName
:= LowerCase(aName
);
6892 if FAIFlags
<> nil then
6893 for a
:= 0 to High(FAIFlags
) do
6894 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6896 Result
:= FAIFlags
[a
].Value
;
6901 procedure TBot
.RemoveAIFlag(aName
: String20
);
6905 if FAIFlags
= nil then Exit
;
6907 aName
:= LowerCase(aName
);
6909 for a
:= 0 to High(FAIFlags
) do
6910 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6912 if a
<> High(FAIFlags
) then
6913 for b
:= a
to High(FAIFlags
)-1 do
6914 FAIFlags
[b
] := FAIFlags
[b
+1];
6916 SetLength(FAIFlags
, Length(FAIFlags
)-1);
6921 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
6929 aName
:= LowerCase(aName
);
6931 if FAIFlags
<> nil then
6932 for a
:= 0 to High(FAIFlags
) do
6933 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6939 if ok
then FAIFlags
[a
].Value
:= fValue
6942 SetLength(FAIFlags
, Length(FAIFlags
)+1);
6943 with FAIFlags
[High(FAIFlags
)] do
6951 procedure TBot
.UpdateMove
;
6953 procedure GoLeft(Time
: Word = 1);
6955 ReleaseKey(KEY_LEFT
);
6956 ReleaseKey(KEY_RIGHT
);
6957 PressKey(KEY_LEFT
, Time
);
6958 SetDirection(D_LEFT
);
6961 procedure GoRight(Time
: Word = 1);
6963 ReleaseKey(KEY_LEFT
);
6964 ReleaseKey(KEY_RIGHT
);
6965 PressKey(KEY_RIGHT
, Time
);
6966 SetDirection(D_RIGHT
);
6969 function Rnd(a
: Word): Boolean;
6971 Result
:= Random(a
) = 0;
6974 procedure Turn(Time
: Word = 1200);
6976 if RunDirection() = D_LEFT
then GoRight(Time
) else GoLeft(Time
);
6981 ReleaseKey(KEY_LEFT
);
6982 ReleaseKey(KEY_RIGHT
);
6985 function CanRunLeft(): Boolean;
6987 Result
:= not CollideLevel(-1, 0);
6990 function CanRunRight(): Boolean;
6992 Result
:= not CollideLevel(1, 0);
6995 function CanRun(): Boolean;
6997 if RunDirection() = D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7000 procedure Jump(Time
: Word = 30);
7002 PressKey(KEY_JUMP
, Time
);
7005 function NearHole(): Boolean;
7009 { TODO 5 : Ëåñòíèöû }
7010 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
7011 for x
:= 1 to PLAYER_RECT
.Width
do
7012 if (not StayOnStep(x
*sx
, 0)) and
7013 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7014 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7023 function BorderHole(): Boolean;
7027 { TODO 5 : Ëåñòíèöû }
7028 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
7029 for x
:= 1 to PLAYER_RECT
.Width
do
7030 if (not StayOnStep(x
*sx
, 0)) and
7031 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7032 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7034 for xx
:= x
to x
+32 do
7035 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7045 function NearDeepHole(): Boolean;
7051 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
7054 for x
:= 1 to PLAYER_RECT
.Width
do
7055 if (not StayOnStep(x
*sx
, 0)) and
7056 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7057 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7059 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7061 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7066 end else Result
:= False;
7069 function OverDeepHole(): Boolean;
7076 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7078 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7085 function OnGround(): Boolean;
7087 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7090 function OnLadder(): Boolean;
7092 Result
:= FullInStep(0, 0);
7095 function BelowLadder(): Boolean;
7097 Result
:= (FullInStep(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7098 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7099 (FullInStep(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7100 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7103 function BelowLiftUp(): Boolean;
7105 Result
:= ((FullInLift(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7106 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7107 ((FullInLift(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7108 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7111 function OnTopLift(): Boolean;
7113 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7116 function CanJumpOver(): Boolean;
7120 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
7124 if not CollideLevel(sx
, 0) then Exit
;
7126 for y
:= 1 to BOT_MAXJUMP
do
7127 if CollideLevel(0, -y
) then Exit
else
7128 if not CollideLevel(sx
, -y
) then
7135 function CanJumpUp(Dist
: ShortInt): Boolean;
7142 if CollideLevel(Dist
, 0) then Exit
;
7145 for y
:= 0 to BOT_MAXJUMP
do
7146 if CollideLevel(Dist
, -y
) then
7155 for yy
:= y
+1 to BOT_MAXJUMP
do
7156 if not CollideLevel(Dist
, -yy
) then
7165 for y
:= 0 to BOT_MAXJUMP
do
7166 if CollideLevel(0, -y
) then
7174 if y
< yy
then Exit
;
7179 function IsSafeTrigger(): Boolean;
7184 if gTriggers
= nil then
7186 for a
:= 0 to High(gTriggers
) do
7187 if Collide(gTriggers
[a
].X
,
7190 gTriggers
[a
].Height
) and
7191 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7192 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7193 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7194 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7195 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7200 // Âîçìîæíî, íàæèìàåì êíîïêó:
7201 if Rnd(16) and IsSafeTrigger() then
7204 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7205 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7207 ReleaseKey(KEY_LEFT
);
7208 ReleaseKey(KEY_RIGHT
);
7212 // Èäåì âëåâî, åñëè íàäî áûëî:
7213 if GetAIFlag('GOLEFT') <> '' then
7215 RemoveAIFlag('GOLEFT');
7216 if CanRunLeft() then
7220 // Èäåì âïðàâî, åñëè íàäî áûëî:
7221 if GetAIFlag('GORIGHT') <> '' then
7223 RemoveAIFlag('GORIGHT');
7224 if CanRunRight() then
7228 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7229 if FObj
.X
< -32 then
7232 if FObj
.X
+32 > gMapInfo
.Width
then
7235 // Ïðûãàåì, åñëè íàäî áûëî:
7236 if GetAIFlag('NEEDJUMP') <> '' then
7239 RemoveAIFlag('NEEDJUMP');
7242 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7243 if GetAIFlag('NEEDSEEUP') <> '' then
7246 ReleaseKey(KEY_DOWN
);
7247 PressKey(KEY_UP
, 20);
7248 RemoveAIFlag('NEEDSEEUP');
7251 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7252 if GetAIFlag('NEEDSEEDOWN') <> '' then
7255 ReleaseKey(KEY_DOWN
);
7256 PressKey(KEY_DOWN
, 20);
7257 RemoveAIFlag('NEEDSEEDOWN');
7260 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7261 if GetAIFlag('GOINHOLE') <> '' then
7262 if not OnGround() then
7264 ReleaseKey(KEY_LEFT
);
7265 ReleaseKey(KEY_RIGHT
);
7266 RemoveAIFlag('GOINHOLE');
7267 SetAIFlag('FALLINHOLE', '1');
7270 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7271 if GetAIFlag('FALLINHOLE') <> '' then
7273 RemoveAIFlag('FALLINHOLE');
7275 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7276 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7277 if GetAIFlag('FALLINHOLE') = '' then
7278 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7284 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7286 CanJumpUp(IfThen(RunDirection() = D_LEFT
, -1, 1)*32) and
7290 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7291 if OnGround() and NearHole() then
7292 if NearDeepHole() then // Åñëè ýòî áåçäíà
7294 0..3: Turn(); // Áåæèì îáðàòíî
7295 4: Jump(); // Ïðûãàåì
7296 5: begin // Ïðûãàåì îáðàòíî
7301 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7302 if GetAIFlag('GOINHOLE') = '' then
7304 0: Turn(); // Íå íóæíî òóäà
7305 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7306 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7307 if BorderHole() then
7308 SetAIFlag('GOINHOLE', '1');
7311 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7312 if (not CanRun()) and OnGround() then
7314 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7315 if CanJumpOver() or OnLadder() then
7317 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7318 if Random(2) = 0 then
7320 if IsSafeTrigger() then
7326 // Îñòàëîñü ìàëî âîçäóõà:
7327 if FAir
< 36 * 2 then
7330 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7331 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7332 if BodyInAcid(0, 0) then
7336 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7338 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7339 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7342 {function TBot.NeedItem(Item: Byte): Byte;
7347 procedure TBot
.SelectWeapon(Dist
: Integer);
7351 function HaveAmmo(weapon
: Byte): Boolean;
7354 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7355 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7356 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7357 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7358 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7359 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7360 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7361 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7362 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7363 else Result
:= True;
7368 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7370 if Dist
> BOT_LONGDIST
then
7371 begin // Äàëüíèé áîé
7373 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7375 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7379 else //if Dist > BOT_UNSAFEDIST then
7380 begin // Áëèæíèé áîé
7382 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7384 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7391 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7393 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7399 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7401 Result
:= inherited PickItem(ItemType
, force
, remove
);
7403 if Result
then SetAIFlag('SELECTWEAPON', '1');
7406 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7408 Result
:= inherited Heal(value
, Soft
);
7411 function TBot
.Healthy(): Byte;
7413 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7414 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7415 else if (FHealth
> 50) then Result
:= 2
7416 else if (FHealth
> 20) then Result
:= 1
7420 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7422 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7423 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7426 procedure TBot
.OnDamage(Angle
: SmallInt);
7434 if (Angle
= 0) or (Angle
= 180) then
7437 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7438 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7440 pla
:= g_Player_Get(FLastSpawnerUID
);
7441 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7442 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7445 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7446 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7448 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7449 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7450 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7455 SetAIFlag('ATTACKLEFT', '1')
7457 SetAIFlag('ATTACKRIGHT', '1');
7461 function TBot
.RunDirection(): TDirection
;
7463 if Abs(Vel
.X
) >= 1 then
7465 if Vel
.X
> 0 then Result
:= D_RIGHT
else Result
:= D_LEFT
;
7467 Result
:= FDirection
;
7470 function TBot
.GetRnd(a
: Byte): Boolean;
7472 if a
= 0 then Result
:= False
7473 else if a
= 255 then Result
:= True
7474 else Result
:= Random(256) > 255-a
;
7477 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7479 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7482 procedure TBot
.SaveState(var Mem
: TBinMemoryWriter
);
7488 inherited SaveState(Mem
);
7490 // Âûáðàííîå îðóæèå:
7491 Mem
.WriteByte(FSelectedWeapon
);
7493 Mem
.WriteWord(FTargetUID
);
7494 // Âðåìÿ ïîòåðè öåëè:
7495 Mem
.WriteDWORD(FLastVisible
);
7496 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7497 dw
:= Length(FAIFlags
);
7500 for i
:= 0 to Integer(dw
)-1 do
7502 Mem
.WriteString(FAIFlags
[i
].Name
, 20);
7503 Mem
.WriteString(FAIFlags
[i
].Value
, 20);
7505 // Íàñòðîéêè ñëîæíîñòè:
7507 Mem
.WriteMemory(p
, SizeOf(TDifficult
));
7510 procedure TBot
.LoadState(var Mem
: TBinMemoryReader
);
7516 inherited LoadState(Mem
);
7518 // Âûáðàííîå îðóæèå:
7519 Mem
.ReadByte(FSelectedWeapon
);
7521 Mem
.ReadWord(FTargetUID
);
7522 // Âðåìÿ ïîòåðè öåëè:
7523 Mem
.ReadDWORD(FLastVisible
);
7524 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7526 SetLength(FAIFlags
, dw
);
7528 for i
:= 0 to Integer(dw
)-1 do
7530 Mem
.ReadString(FAIFlags
[i
].Name
);
7531 Mem
.ReadString(FAIFlags
[i
].Value
);
7533 // Íàñòðîéêè ñëîæíîñòè:
7534 Mem
.ReadMemory(p
, dw
);
7535 if dw
<> SizeOf(TDifficult
) then
7537 raise EBinSizeError
.Create('TBot.LoadState: Wrong FDifficult Size');
7539 FDifficult
:= TDifficult(p
^);