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
,
523 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
, g_net
, g_netmsg
;
533 diag_precision
: Byte;
537 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
538 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
539 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
543 TIME_RESPAWN1
= 1500;
544 TIME_RESPAWN2
= 2000;
545 TIME_RESPAWN3
= 3000;
548 JET_MAX
= 540; // ~30 sec
549 PLAYER_SUIT_TIME
= 30000;
550 PLAYER_INVUL_TIME
= 30000;
551 PLAYER_INVIS_TIME
= 35000;
552 FRAG_COMBO_TIME
= 3000;
556 ANGLE_RIGHTDOWN
= -35;
558 ANGLE_LEFTDOWN
= -145;
559 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
560 WEAPONPOINT
: Array [TDirection
] of TPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
563 BOT_UNSAFEDIST
= 128;
564 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
566 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
567 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
568 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
569 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
570 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
571 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
572 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
573 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
574 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
575 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
576 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
577 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
578 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
579 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
580 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
581 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
582 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
583 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
584 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
585 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
586 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
587 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
588 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
589 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
590 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
591 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
593 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
594 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
596 BOTNAMES_FILENAME
= 'botnames.txt';
597 BOTLIST_FILENAME
= 'botlist.txt';
601 MaxCorpses
: Word = 20;
602 MaxShells
: Word = 300;
603 CurrentGib
: Integer = 0;
604 CurrentShell
: Integer = 0;
605 BotNames
: Array of String;
606 BotList
: Array of TBotProfile
;
609 procedure TGib
.positionChanged (); begin end;
610 procedure TShell
.positionChanged (); begin end;
613 function Lerp(X
, Y
, Factor
: Integer): Integer;
615 Result
:= X
+ ((Y
- X
) div Factor
);
618 function SameTeam(UID1
, UID2
: Word): Boolean;
622 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
623 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
625 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
627 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
628 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
630 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
633 procedure g_Gibs_SetMax(Count
: Word);
636 SetLength(gGibs
, Count
);
638 if CurrentGib
>= Count
then
642 function g_Gibs_GetMax(): Word;
647 procedure g_Shells_SetMax(Count
: Word);
650 SetLength(gShells
, Count
);
652 if CurrentShell
>= Count
then
656 function g_Shells_GetMax(): Word;
662 procedure g_Corpses_SetMax(Count
: Word);
665 SetLength(gCorpses
, Count
);
668 function g_Corpses_GetMax(): Word;
670 Result
:= MaxCorpses
;
673 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
683 // Åñòü ëè ìåñòî â gPlayers:
684 if gPlayers
<> nil then
685 for a
:= 0 to High(gPlayers
) do
686 if gPlayers
[a
] = nil then
692 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
695 SetLength(gPlayers
, Length(gPlayers
)+1);
699 // Ñîçäàåì îáúåêò èãðîêà:
701 gPlayers
[a
] := TBot
.Create()
703 gPlayers
[a
] := TPlayer
.Create();
706 gPlayers
[a
].FActualModelName
:= ModelName
;
707 gPlayers
[a
].SetModel(ModelName
);
709 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
710 if gPlayers
[a
].FModel
= nil then
714 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
718 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
719 if Random(2) = 0 then
723 gPlayers
[a
].FPreferredTeam
:= Team
;
725 case gGameSettings
.GameMode
of
726 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
728 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
730 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
733 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
734 gPlayers
[a
].FColor
:= Color
;
735 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
736 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
738 gPlayers
[a
].FModel
.Color
:= Color
;
740 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
741 gPlayers
[a
].FLive
:= False;
743 Result
:= gPlayers
[a
].FUID
;
746 function g_Player_CreateFromState(var Mem
: TBinMemoryReader
): Word;
759 if sig
<> PLAYER_SIGNATURE
then // 'PLYR'
761 raise EBinSizeError
.Create('g_Player_CreateFromState: Wrong Player Signature');
765 Mem
.ReadBoolean(Bot
);
770 // Åñòü ëè ìåñòî â gPlayers:
771 if gPlayers
<> nil then
772 for a
:= 0 to High(gPlayers
) do
773 if gPlayers
[a
] = nil then
779 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
782 SetLength(gPlayers
, Length(gPlayers
)+1);
786 // Ñîçäàåì îáúåêò èãðîêà:
788 gPlayers
[a
] := TBot
.Create()
790 gPlayers
[a
] := TPlayer
.Create();
791 gPlayers
[a
].FIamBot
:= Bot
;
792 gPlayers
[a
].FPhysics
:= True;
795 Mem
.ReadWord(gPlayers
[a
].FUID
);
797 Mem
.ReadString(gPlayers
[a
].FName
);
799 Mem
.ReadByte(gPlayers
[a
].FTeam
);
800 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
802 Mem
.ReadBoolean(gPlayers
[a
].FLive
);
803 // Èçðàñõîäîâàë ëè âñå æèçíè:
804 Mem
.ReadBoolean(gPlayers
[a
].FNoRespawn
);
808 gPlayers
[a
].FDirection
:= D_LEFT
810 gPlayers
[a
].FDirection
:= D_RIGHT
;
812 Mem
.ReadInt(gPlayers
[a
].FHealth
);
814 Mem
.ReadByte(gPlayers
[a
].FLives
);
816 Mem
.ReadInt(gPlayers
[a
].FArmor
);
818 Mem
.ReadInt(gPlayers
[a
].FAir
);
820 Mem
.ReadInt(gPlayers
[a
].FJetFuel
);
822 Mem
.ReadInt(gPlayers
[a
].FPain
);
824 Mem
.ReadInt(gPlayers
[a
].FKills
);
826 Mem
.ReadInt(gPlayers
[a
].FMonsterKills
);
828 Mem
.ReadInt(gPlayers
[a
].FFrags
);
830 Mem
.ReadByte(gPlayers
[a
].FFragCombo
);
831 // Âðåìÿ ïîñëåäíåãî ôðàãà:
832 Mem
.ReadDWORD(gPlayers
[a
].FLastFrag
);
834 Mem
.ReadInt(gPlayers
[a
].FDeath
);
836 Mem
.ReadByte(gPlayers
[a
].FFlag
);
838 Mem
.ReadInt(gPlayers
[a
].FSecrets
);
840 Mem
.ReadByte(gPlayers
[a
].FCurrWeap
);
841 // Ñëåäóþùåå æåëàåìîå îðóæèå:
842 Mem
.ReadWord(gPlayers
[a
].FNextWeap
);
844 Mem
.ReadByte(gPlayers
[a
].FNextWeapDelay
);
845 // Âðåìÿ çàðÿäêè BFG:
846 Mem
.ReadSmallInt(gPlayers
[a
].FBFGFireCounter
);
848 Mem
.ReadInt(gPlayers
[a
].FDamageBuffer
);
849 // Ïîñëåäíèé óäàðèâøèé:
850 Mem
.ReadWord(gPlayers
[a
].FLastSpawnerUID
);
851 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
852 Mem
.ReadByte(gPlayers
[a
].FLastHit
);
854 Obj_LoadState(@gPlayers
[a
].FObj
, Mem
);
855 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
856 for i
:= A_BULLETS
to A_HIGH
do
857 Mem
.ReadWord(gPlayers
[a
].FAmmo
[i
]);
858 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
859 for i
:= A_BULLETS
to A_HIGH
do
860 Mem
.ReadWord(gPlayers
[a
].FMaxAmmo
[i
]);
862 for i
:= WP_FIRST
to WP_LAST
do
863 Mem
.ReadBoolean(gPlayers
[a
].FWeapon
[i
]);
864 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
865 for i
:= WP_FIRST
to WP_LAST
do
866 Mem
.ReadWord(gPlayers
[a
].FReloading
[i
]);
870 Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
871 // Íàëè÷èå êðàñíîãî êëþ÷à:
874 Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
875 // Íàëè÷èå çåëåíîãî êëþ÷à:
878 Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
879 // Íàëè÷èå ñèíåãî êëþ÷à:
882 Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
886 Include(gPlayers
[a
].FRulez
, R_BERSERK
);
887 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
888 for i
:= MR_SUIT
to MR_MAX
do
889 Mem
.ReadDWORD(gPlayers
[a
].FMegaRulez
[i
]);
890 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
891 for i
:= T_RESPAWN
to T_FLAGCAP
do
892 Mem
.ReadDWORD(gPlayers
[a
].FTime
[i
]);
895 Mem
.ReadString(gPlayers
[a
].FActualModelName
);
897 Mem
.ReadByte(gPlayers
[a
].FColor
.R
);
898 Mem
.ReadByte(gPlayers
[a
].FColor
.G
);
899 Mem
.ReadByte(gPlayers
[a
].FColor
.B
);
900 // Îáíîâëÿåì ìîäåëü èãðîêà:
901 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
903 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
904 if gPlayers
[a
].FModel
= nil then
908 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
912 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
913 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
914 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
916 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
918 Result
:= gPlayers
[a
].FUID
;
921 procedure g_Player_ResetTeams();
925 if g_Game_IsClient
then
927 if gPlayers
= nil then
929 for a
:= Low(gPlayers
) to High(gPlayers
) do
930 if gPlayers
[a
] <> nil then
931 case gGameSettings
.GameMode
of
933 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
935 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
936 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
937 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
940 gPlayers
[a
].ChangeTeam(TEAM_RED
)
942 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
945 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
949 procedure g_Bot_Add(Team
, Difficult
: Byte);
952 _name
, _model
: String;
955 if not g_Game_IsServer
then Exit
;
957 // Ñïèñîê íàçâàíèé ìîäåëåé:
958 m
:= g_PlayerModel_GetNames();
963 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
964 Team
:= TEAM_COOP
// COOP
966 if gGameSettings
.GameMode
= GM_DM
then
967 Team
:= TEAM_NONE
// DM
969 if Team
= TEAM_NONE
then // CTF / TDM
971 // Àâòîáàëàíñ êîìàíä:
975 for a
:= 0 to High(gPlayers
) do
976 if gPlayers
[a
] <> nil then
978 if gPlayers
[a
].Team
= TEAM_RED
then
981 if gPlayers
[a
].Team
= TEAM_BLUE
then
991 if Random(2) = 0 then
997 // Âûáèðàåì áîòó èìÿ:
999 if BotNames
<> nil then
1000 for a
:= 0 to High(BotNames
) do
1001 if g_Player_ValidName(BotNames
[a
]) then
1003 _name
:= BotNames
[a
];
1007 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
1010 _name
:= Format('DFBOT%.2d', [Random(100)]);
1011 until g_Player_ValidName(_name
);
1013 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1014 _model
:= m
[Random(Length(m
))];
1017 with g_Player_Get(g_Player_Create(_model
,
1018 _RGB(Min(Random(9)*32, 255),
1019 Min(Random(9)*32, 255),
1020 Min(Random(9)*32, 255)),
1021 Team
, True)) as TBot
do
1026 1: FDifficult
:= DIFFICULT_EASY
;
1027 2: FDifficult
:= DIFFICULT_MEDIUM
;
1028 else FDifficult
:= DIFFICULT_HARD
;
1031 for a
:= WP_FIRST
to WP_LAST
do
1033 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1034 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1035 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1038 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1040 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1041 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1046 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1);
1049 _name
, _model
: String;
1052 if not g_Game_IsServer
then Exit
;
1054 // Ñïèñîê íàçâàíèé ìîäåëåé:
1055 m
:= g_PlayerModel_GetNames();
1060 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1061 Team
:= TEAM_COOP
// COOP
1063 if gGameSettings
.GameMode
= GM_DM
then
1064 Team
:= TEAM_NONE
// DM
1066 if Team
= TEAM_NONE
then
1067 Team
:= BotList
[num
].team
; // CTF / TDM
1069 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1070 lName
:= AnsiLowerCase(lName
);
1071 if (num
< 0) or (num
> Length(BotList
)-1) then
1073 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1074 for a
:= 0 to High(BotList
) do
1075 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1084 _name
:= BotList
[num
].name
;
1085 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1086 if not g_Player_ValidName(_name
) then
1088 _name
:= Format('DFBOT%.2d', [Random(100)]);
1089 until g_Player_ValidName(_name
);
1092 _model
:= BotList
[num
].model
;
1093 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1094 if not InSArray(_model
, m
) then
1095 _model
:= m
[Random(Length(m
))];
1098 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1102 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1103 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1104 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1105 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1106 FDifficult
.Cover
:= BotList
[num
].cover
;
1107 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1109 for a
:= WP_FIRST
to WP_LAST
do
1111 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1112 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1113 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1116 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1118 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1122 procedure g_Bot_RemoveAll();
1126 if not g_Game_IsServer
then Exit
;
1127 if gPlayers
= nil then Exit
;
1129 for a
:= 0 to High(gPlayers
) do
1130 if gPlayers
[a
] <> nil then
1131 if gPlayers
[a
] is TBot
then
1133 gPlayers
[a
].Lives
:= 0;
1134 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1135 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1136 g_Player_Remove(gPlayers
[a
].FUID
);
1142 procedure g_Bot_MixNames();
1147 if BotNames
<> nil then
1148 for a
:= 0 to High(BotNames
) do
1150 b
:= Random(Length(BotNames
));
1152 Botnames
[a
] := BotNames
[b
];
1157 procedure g_Player_Remove(UID
: Word);
1161 if gPlayers
= nil then Exit
;
1163 if g_Game_IsServer
and g_Game_IsNet
then
1164 MH_SEND_PlayerDelete(UID
);
1166 for i
:= 0 to High(gPlayers
) do
1167 if gPlayers
[i
] <> nil then
1168 if gPlayers
[i
].FUID
= UID
then
1170 if gPlayers
[i
] is TPlayer
then
1171 TPlayer(gPlayers
[i
]).Free()
1173 TBot(gPlayers
[i
]).Free();
1179 procedure g_Player_Init();
1189 if not FileExists(DataDir
+ BOTNAMES_FILENAME
) then
1192 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1193 AssignFile(F
, DataDir
+ BOTNAMES_FILENAME
);
1204 SetLength(BotNames
, Length(BotNames
)+1);
1205 BotNames
[High(BotNames
)] := s
;
1213 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1214 config
:= TConfig
.CreateFile(DataDir
+ BOTLIST_FILENAME
);
1218 while config
.SectionExists(IntToStr(a
)) do
1220 SetLength(BotList
, Length(BotList
)+1);
1222 with BotList
[High(BotList
)] do
1225 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1227 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1229 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1234 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1235 color
.R
:= StrToIntDef(sa
[0], 0);
1236 color
.G
:= StrToIntDef(sa
[1], 0);
1237 color
.B
:= StrToIntDef(sa
[2], 0);
1238 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1239 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1240 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1241 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1242 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1243 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1244 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1245 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1246 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1247 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1248 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1249 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1250 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1251 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1252 if Length(sa
) = 10 then
1254 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1255 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1256 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1257 if Length(sa
) = 10 then
1259 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1261 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1262 if Length(sa) = 10 then
1264 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1273 procedure g_Player_Free();
1277 if gPlayers
<> nil then
1279 for i
:= 0 to High(gPlayers
) do
1280 if gPlayers
[i
] <> nil then
1282 if gPlayers
[i
] is TPlayer
then
1283 TPlayer(gPlayers
[i
]).Free()
1285 TBot(gPlayers
[i
]).Free();
1296 procedure g_Player_UpdateAll();
1300 if gPlayers
= nil then Exit
;
1302 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1303 for i
:= 0 to High(gPlayers
) do
1305 if gPlayers
[i
] <> nil then
1307 if gPlayers
[i
] is TPlayer
then
1309 gPlayers
[i
].Update();
1310 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1314 // bot updates weapons in `UpdateCombat()`
1315 TBot(gPlayers
[i
]).Update();
1319 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1322 procedure g_Player_DrawAll();
1326 if gPlayers
= nil then Exit
;
1328 for i
:= 0 to High(gPlayers
) do
1329 if gPlayers
[i
] <> nil then
1330 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1331 else TBot(gPlayers
[i
]).Draw();
1334 procedure g_Player_DrawDebug(p
: TPlayer
);
1338 if p
= nil then Exit
;
1339 if (@p
.FObj
) = nil then Exit
;
1341 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1343 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1344 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1345 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1346 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1347 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1348 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1351 procedure g_Player_DrawHealth();
1356 if gPlayers
= nil then Exit
;
1357 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1359 for i
:= 0 to High(gPlayers
) do
1360 if gPlayers
[i
] <> nil then
1362 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1363 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1364 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1365 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1366 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1367 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1371 function g_Player_Get(UID
: Word): TPlayer
;
1377 if gPlayers
= nil then
1380 for a
:= 0 to High(gPlayers
) do
1381 if gPlayers
[a
] <> nil then
1382 if gPlayers
[a
].FUID
= UID
then
1384 Result
:= gPlayers
[a
];
1389 function g_Player_GetCount(): Byte;
1395 if gPlayers
= nil then
1398 for a
:= 0 to High(gPlayers
) do
1399 if gPlayers
[a
] <> nil then
1400 Result
:= Result
+ 1;
1403 function g_Player_GetStats(): TPlayerStatArray
;
1409 if gPlayers
= nil then Exit
;
1411 for a
:= 0 to High(gPlayers
) do
1412 if gPlayers
[a
] <> nil then
1414 SetLength(Result
, Length(Result
)+1);
1415 with Result
[High(Result
)] do
1417 Ping
:= gPlayers
[a
].FPing
;
1418 Loss
:= gPlayers
[a
].FLoss
;
1419 Name
:= gPlayers
[a
].FName
;
1420 Team
:= gPlayers
[a
].FTeam
;
1421 Frags
:= gPlayers
[a
].FFrags
;
1422 Deaths
:= gPlayers
[a
].FDeath
;
1423 Kills
:= gPlayers
[a
].FKills
;
1424 Color
:= gPlayers
[a
].FModel
.Color
;
1425 Lives
:= gPlayers
[a
].FLives
;
1426 Spectator
:= gPlayers
[a
].FSpectator
;
1431 procedure g_Player_RememberAll
;
1435 for i
:= Low(gPlayers
) to High(gPlayers
) do
1436 if (gPlayers
[i
] <> nil) and gPlayers
[i
].Live
then
1437 gPlayers
[i
].RememberState
;
1440 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1444 gTeamStat
[TEAM_RED
].Goals
:= 0;
1445 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1447 if gPlayers
<> nil then
1448 for i
:= 0 to High(gPlayers
) do
1449 if gPlayers
[i
] <> nil then
1451 gPlayers
[i
].Reset(Force
);
1453 if gPlayers
[i
] is TPlayer
then
1455 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1456 gPlayers
[i
].Respawn(Silent
)
1458 gPlayers
[i
].Spectate();
1461 TBot(gPlayers
[i
]).Respawn(Silent
);
1465 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1472 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1477 if (FHealth
>= -50) or (gGibsCount
= 0) then
1479 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1483 for find_id
:= 0 to High(gCorpses
) do
1484 if gCorpses
[find_id
] = nil then
1491 find_id
:= Random(Length(gCorpses
));
1493 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1494 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1495 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1496 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1499 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1500 FObj
.Y
+ PLAYER_RECT_CY
,
1501 FModel
.Name
, FModel
.Color
);
1505 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1509 if (gShells
= nil) or (Length(gShells
) = 0) then
1512 with gShells
[CurrentShell
] do
1518 if T
= SHELL_BULLET
then
1520 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1524 Obj
.Rect
.Width
:= 4;
1525 Obj
.Rect
.Height
:= 2;
1529 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1533 Obj
.Rect
.Width
:= 7;
1534 Obj
.Rect
.Height
:= 3;
1540 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1541 positionChanged(); // this updates spatial accelerators
1542 RAngle
:= Random(360);
1543 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1545 if CurrentShell
>= High(gShells
) then
1552 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1555 GibsArray
: TGibsArray
;
1557 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1559 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1562 for a
:= 0 to High(GibsArray
) do
1563 with gGibs
[CurrentGib
] do
1566 ID
:= GibsArray
[a
].ID
;
1567 MaskID
:= GibsArray
[a
].MaskID
;
1570 Obj
.Rect
:= GibsArray
[a
].Rect
;
1571 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1572 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1573 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1574 positionChanged(); // this updates spatial accelerators
1575 RAngle
:= Random(360);
1577 if gBloodCount
> 0 then
1578 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1579 Random(48), Random(48), 150, 0, 0);
1581 if CurrentGib
>= High(gGibs
) then
1588 procedure g_Player_UpdatePhysicalObjects();
1594 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1599 if T
= SHELL_BULLET
then
1600 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1602 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1607 if gGibs
<> nil then
1608 for i
:= 0 to High(gGibs
) do
1609 if gGibs
[i
].Live
then
1613 mr
:= g_Obj_Move(@Obj
, True, False, True);
1614 positionChanged(); // this updates spatial accelerators
1616 if WordBool(mr
and MOVE_FALLOUT
) then
1622 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1623 if WordBool(mr
and MOVE_HITWALL
) then
1624 Obj
.Vel
.X
:= -(vel
.X
div 2);
1625 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1626 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1628 if (Obj
.Vel
.X
>= 0) then
1630 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1631 if RAngle
>= 360 then
1632 RAngle
:= RAngle
mod 360;
1633 end else begin // Counter-clockwise
1634 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1636 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1639 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1640 if gTime
mod (GAME_TICK
*3) = 0 then
1641 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1645 if gCorpses
<> nil then
1646 for i
:= 0 to High(gCorpses
) do
1647 if gCorpses
[i
] <> nil then
1648 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1654 gCorpses
[i
].Update();
1657 if gShells
<> nil then
1658 for i
:= 0 to High(gShells
) do
1659 if gShells
[i
].Live
then
1663 mr
:= g_Obj_Move(@Obj
, True, False, True);
1664 positionChanged(); // this updates spatial accelerators
1666 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1672 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1673 if WordBool(mr
and MOVE_HITWALL
) then
1675 Obj
.Vel
.X
:= -(vel
.X
div 2);
1676 if not WordBool(mr
and MOVE_INWATER
) then
1677 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1679 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1681 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1682 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1683 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1685 if RAngle
mod 90 <> 0 then
1686 RAngle
:= (RAngle
div 90) * 90;
1688 else if not WordBool(mr
and MOVE_INWATER
) then
1689 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1692 if (Obj
.Vel
.X
>= 0) then
1694 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1695 if RAngle
>= 360 then
1696 RAngle
:= RAngle
mod 360;
1697 end else begin // Counter-clockwise
1698 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1700 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1705 procedure g_Player_DrawCorpses();
1710 if gGibs
<> nil then
1711 for i
:= 0 to High(gGibs
) do
1712 if gGibs
[i
].Live
then
1715 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1718 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1719 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1721 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1724 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1730 if gCorpses
<> nil then
1731 for i
:= 0 to High(gCorpses
) do
1732 if gCorpses
[i
] <> nil then
1736 procedure g_Player_DrawShells();
1741 if gShells
<> nil then
1742 for i
:= 0 to High(gShells
) do
1743 if gShells
[i
].Live
then
1746 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1752 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1756 procedure g_Player_RemoveAllCorpses();
1762 SetLength(gGibs
, MaxGibs
);
1763 SetLength(gShells
, MaxGibs
);
1767 if gCorpses
<> nil then
1768 for i
:= 0 to High(gCorpses
) do
1772 SetLength(gCorpses
, MaxCorpses
);
1775 procedure g_Player_Corpses_SaveState(var Mem
: TBinMemoryWriter
);
1780 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ:
1782 if gCorpses
<> nil then
1783 for i
:= 0 to High(gCorpses
) do
1784 if gCorpses
[i
] <> nil then
1787 Mem
:= TBinMemoryWriter
.Create((count
+1) * 128);
1789 // Êîëè÷åñòâî òðóïîâ:
1790 Mem
.WriteInt(count
);
1796 for i
:= 0 to High(gCorpses
) do
1797 if gCorpses
[i
] <> nil then
1800 Mem
.WriteString(gCorpses
[i
].FModelName
);
1802 b
:= gCorpses
[i
].Mess
;
1803 Mem
.WriteBoolean(b
);
1804 // Ñîõðàíÿåì äàííûå òðóïà:
1805 gCorpses
[i
].SaveState(Mem
);
1809 procedure g_Player_Corpses_LoadState(var Mem
: TBinMemoryReader
);
1818 g_Player_RemoveAllCorpses();
1820 // Êîëè÷åñòâî òðóïîâ:
1823 if count
> Length(gCorpses
) then
1825 raise EBinSizeError
.Create('g_Player_Corpses_LoadState: Too Many Corpses');
1832 for i
:= 0 to count
-1 do
1835 Mem
.ReadString(str
);
1839 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1840 // Çàãðóæàåì äàííûå òðóïà:
1841 gCorpses
[i
].LoadState(Mem
);
1847 procedure TPlayer
.BFGHit();
1849 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1850 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1851 if g_Game_IsServer
and g_Game_IsNet
then
1852 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1853 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1857 procedure TPlayer
.ChangeModel(ModelName
: string);
1859 locModel
: TPlayerModel
;
1861 locModel
:= g_PlayerModel_Get(ModelName
);
1862 if locModel
= nil then Exit
;
1868 procedure TPlayer
.SetModel(ModelName
: string);
1872 m
:= g_PlayerModel_Get(ModelName
);
1875 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1876 m
:= g_PlayerModel_Get('doomer');
1879 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1884 if FModel
<> nil then
1889 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1890 FModel
.Color
:= FColor
1892 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1893 FModel
.SetWeapon(FCurrWeap
);
1894 FModel
.SetFlag(FFlag
);
1895 SetDirection(FDirection
);
1898 procedure TPlayer
.SetColor(Color
: TRGB
);
1901 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1902 if FModel
<> nil then FModel
.Color
:= Color
;
1905 procedure TPlayer
.SwitchTeam
;
1907 if g_Game_IsClient
then
1909 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
1911 if gGameOn
and FLive
then
1912 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
1914 if FTeam
= TEAM_RED
then
1916 ChangeTeam(TEAM_BLUE
);
1917 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
1918 if g_Game_IsNet
then
1919 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
1923 ChangeTeam(TEAM_RED
);
1924 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
1925 if g_Game_IsNet
then
1926 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
1928 FPreferredTeam
:= FTeam
;
1931 procedure TPlayer
.ChangeTeam(Team
: Byte);
1938 TEAM_RED
, TEAM_BLUE
:
1939 FModel
.Color
:= TEAMCOLOR
[Team
];
1941 FModel
.Color
:= FColor
;
1943 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
1944 MH_SEND_PlayerStats(FUID
);
1948 procedure TPlayer.CollideItem();
1953 if gItems = nil then Exit;
1954 if not FLive then Exit;
1956 for i := 0 to High(gItems) do
1959 if (ItemType <> ITEM_NONE) and Live then
1960 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
1961 PLAYER_RECT.Height, @Obj) then
1963 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
1965 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
1966 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
1967 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
1968 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
1969 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
1971 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
1972 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
1973 (gGameSettings.GameType = GT_SINGLE) and
1974 (g_Player_GetCount() > 1)) then
1975 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
1981 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
1983 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
1984 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
1988 constructor TPlayer
.Create();
1994 FSawSound
:= TPlayableSound
.Create();
1995 FSawSoundIdle
:= TPlayableSound
.Create();
1996 FSawSoundHit
:= TPlayableSound
.Create();
1997 FSawSoundSelect
:= TPlayableSound
.Create();
1998 FJetSoundFly
:= TPlayableSound
.Create();
1999 FJetSoundOn
:= TPlayableSound
.Create();
2000 FJetSoundOff
:= TPlayableSound
.Create();
2002 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2003 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2004 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2005 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2006 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2007 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2008 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2010 FSpectatePlayer
:= -1;
2014 FSavedState
.WaitRecall
:= False;
2020 FActualModelName
:= 'doomer';
2023 FObj
.Rect
:= PLAYER_RECT
;
2025 FBFGFireCounter
:= -1;
2026 FJustTeleported
:= False;
2032 procedure TPlayer
.positionChanged ();
2036 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2040 if (not g_Game_IsClient
) and (not FLive
) then
2045 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2046 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2048 if not g_Game_IsClient
then
2051 if t
= HIT_TRAP
then
2053 // Ëîâóøêà óáèâàåò ñðàçó:
2055 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2057 if t
= HIT_SELF
then
2061 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2064 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2065 FMegaRulez
[MR_SUIT
] := 0;
2066 FMegaRulez
[MR_INVUL
] := 0;
2067 FMegaRulez
[MR_INVIS
] := 0;
2071 // Íî îò îñòàëüíîãî ñïàñàåò:
2072 if FMegaRulez
[MR_INVUL
] >= gTime
then
2079 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2080 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2081 (SpawnerUID
= FUID
) or
2082 (not SameTeam(FUID
, SpawnerUID
)) then
2084 FLastSpawnerUID
:= SpawnerUID
;
2086 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2087 if gBloodCount
> 0 then
2089 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2090 if value
div 4 <= c
then
2091 c
:= c
- (value
div 4)
2095 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2099 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2100 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2103 if t
= HIT_WATER
then
2104 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2105 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2110 Inc(FDamageBuffer
, value
);
2114 FPain
:= FPain
+ value
;
2117 if g_Game_IsServer
and g_Game_IsNet
then
2119 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2120 MH_SEND_PlayerStats(FUID
);
2121 MH_SEND_PlayerPos(False, FUID
);
2125 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2128 if g_Game_IsClient
then
2133 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2135 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2138 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2140 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2144 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2145 MH_SEND_PlayerStats(FUID
);
2148 destructor TPlayer
.Destroy();
2150 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2152 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2156 FSawSoundIdle
.Free();
2157 FSawSoundHit
.Free();
2158 FJetSoundFly
.Free();
2160 FJetSoundOff
.Free();
2166 procedure TPlayer
.DrawBubble();
2168 bubX
, bubY
: Integer;
2171 Rw
, Gw
, Bw
: SmallInt;
2174 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= D_LEFT
, -4, 18);
2175 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2183 1: // simple textual non-bubble
2185 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2186 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2187 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2190 2: // advanced pixel-perfect bubble
2192 if FTeam
= TEAM_RED
then
2195 if FTeam
= TEAM_BLUE
then
2198 3: // colored bubble
2200 Rb
:= FModel
.Color
.R
;
2201 Gb
:= FModel
.Color
.G
;
2202 Bb
:= FModel
.Color
.B
;
2203 Rw
:= Min(Rb
* 2 + 64, 255);
2204 Gw
:= Min(Gb
* 2 + 64, 255);
2205 Bw
:= Min(Bb
* 2 + 64, 255);
2206 if (Abs(Rw
- Rb
) < 32)
2207 or (Abs(Gw
- Gb
) < 32)
2208 or (Abs(Bw
- Bb
) < 32) then
2210 Rb
:= Max(Rw
div 2 - 16, 0);
2211 Gb
:= Max(Gw
div 2 - 16, 0);
2212 Bb
:= Max(Bw
div 2 - 16, 0);
2215 4: // custom textured bubble
2217 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2218 if FDirection
= D_RIGHT
then
2219 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2221 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, M_HORIZONTAL
);
2227 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2228 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2230 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2233 Dot
:= IfThen(FDirection
= D_LEFT
, 14, 5);
2234 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2235 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
);
2236 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
);
2237 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
);
2238 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
);
2242 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2243 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2244 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2247 procedure TPlayer
.Draw();
2255 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2256 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2258 e_GetTextureSize(ID
, @w
, @h
);
2259 if FDirection
= D_LEFT
then
2260 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2261 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7, 0, True, False)
2263 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2264 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7, 0, True, False);
2267 if FMegaRulez
[MR_INVIS
] > gTime
then
2269 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2270 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2272 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2273 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2277 FModel
.Draw(FObj
.X
, FObj
.Y
, 200)
2279 FModel
.Draw(FObj
.X
, FObj
.Y
);
2282 FModel
.Draw(FObj
.X
, FObj
.Y
, 254);
2285 FModel
.Draw(FObj
.X
, FObj
.Y
);
2288 if g_debug_Frames
then
2290 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2292 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2293 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2297 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2299 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2300 if gAimLine
and Live
and
2301 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2305 procedure TPlayer
.DrawAim();
2306 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2310 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2311 if g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
, true) then
2313 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2314 e_DrawPoint(4, ex
, ey
, 255, 127, 0);
2318 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2323 wx
, wy
, xx
, yy
: Integer;
2327 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= D_LEFT
, 7, -7);
2328 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2337 1: begin // Chainsaw
2344 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2345 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2346 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2347 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2352 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2353 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2354 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2355 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2357 4: begin // Double Shotgun
2360 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2361 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2362 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2363 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2365 5: begin // Chaingun
2368 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2369 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2370 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2371 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2373 6: begin // Rocket Launcher
2376 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2377 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2378 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2379 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2381 7: begin // Plasmagun
2384 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2385 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2386 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2387 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2392 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2393 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2394 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2395 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2397 9: begin // Super Chaingun
2400 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2401 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2402 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2403 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2406 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2407 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2409 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2411 drawCast(sz
, wx
, wy
, xx
, yy
);
2415 procedure TPlayer
.DrawGUI();
2418 X
, Y
, SY
, a
, p
, m
: Integer;
2422 stat
: TPlayerStatArray
;
2424 X
:= gPlayerScreenSize
.X
;
2425 SY
:= gPlayerScreenSize
.Y
;
2428 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2430 if gGameSettings
.GameMode
= GM_CTF
then
2434 if gGameSettings
.GameMode
= GM_CTF
then
2436 s
:= 'TEXTURE_PLAYER_REDFLAG';
2437 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2438 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2439 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2440 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2441 if g_Texture_Get(s
, ID
) then
2442 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2445 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2446 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2447 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2449 if gGameSettings
.GameMode
= GM_CTF
then
2451 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2452 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2453 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2454 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2455 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2456 if g_Texture_Get(s
, ID
) then
2457 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2460 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2461 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2462 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2465 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2466 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2469 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2470 e_Draw(ID
, X
+2, Y
, 0, True, False);
2472 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2476 s
:= IntToStr(Frags
);
2477 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2478 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2483 stat
:= g_Player_GetStats();
2488 for a
:= 0 to High(stat
) do
2489 if stat
[a
].Name
<> Name
then
2491 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2492 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2496 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2497 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2498 s
:= s
+IntToStr(Abs(Frags
-m
));
2500 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2501 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2504 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2506 s
:= IntToStr(Lives
);
2507 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2508 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2512 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2513 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2515 if R_BERSERK
in FRulez
then
2516 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2518 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2520 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2521 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2523 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2524 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2525 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2527 s
:= IntToStr(FArmor
);
2528 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2529 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2531 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2537 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2542 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2544 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2545 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2546 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2547 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2548 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2549 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2550 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2551 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2552 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2555 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2556 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2557 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2559 if R_KEY_RED
in FRulez
then
2560 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2562 if R_KEY_GREEN
in FRulez
then
2563 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2565 if R_KEY_BLUE
in FRulez
then
2566 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2568 if FJetFuel
> 0 then
2570 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2571 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2572 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2573 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2574 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2575 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2579 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2580 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2581 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2584 if gShowPing
and g_Game_IsClient
then
2586 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2587 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2593 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2594 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2595 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2598 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2599 s
:= _lc
[I_PLAYER_SPECT4
];
2600 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2601 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2602 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2608 procedure TPlayer
.DrawRulez();
2612 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2613 if FMegaRulez
[MR_INVUL
] >= gTime
then
2615 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2616 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2621 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2622 191, 191, 191, 0, B_INVERT
);
2625 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2626 if FMegaRulez
[MR_SUIT
] >= gTime
then
2628 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2629 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2634 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2635 0, 96, 0, 200, B_NONE
);
2638 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2639 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2641 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2642 255, 0, 0, 200, B_NONE
);
2646 procedure TPlayer
.DrawPain();
2650 if FPain
= 0 then Exit
;
2654 if a
< 15 then h
:= 0
2655 else if a
< 35 then h
:= 1
2656 else if a
< 55 then h
:= 2
2657 else if a
< 75 then h
:= 3
2658 else if a
< 95 then h
:= 4
2661 //if a > 255 then a := 255;
2663 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2664 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2667 procedure TPlayer
.DrawPickup();
2671 if FPickup
= 0 then Exit
;
2675 if a
< 15 then h
:= 1
2676 else if a
< 35 then h
:= 2
2677 else if a
< 55 then h
:= 3
2678 else if a
< 75 then h
:= 4
2681 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2684 procedure TPlayer
.Fire();
2686 f
, DidFire
: Boolean;
2687 wx
, wy
, xd
, yd
: Integer;
2690 if g_Game_IsClient
then Exit
;
2691 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2692 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2700 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2705 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2706 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2707 xd
:= wx
+IfThen(FDirection
= D_LEFT
, -30, 30);
2708 yd
:= wy
+firediry();
2713 if R_BERSERK
in FRulez
then
2715 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2716 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2717 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2720 locobj
.rect
.Width
:= 39;
2721 locobj
.rect
.Height
:= 52;
2722 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2723 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2724 locobj
.Accel
.X
:= xd
-wx
;
2725 locobj
.Accel
.y
:= yd
-wy
;
2727 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2728 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2730 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2734 FPain
:= min(FPain
+ 25, 50);
2735 end else g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2738 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2743 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2744 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2746 FSawSoundSelect
.Stop();
2748 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2750 else if not FSawSoundHit
.IsPlaying() then
2752 FSawSoundSelect
.Stop();
2753 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2756 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2762 if FAmmo
[A_BULLETS
] > 0 then
2764 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2765 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2766 Dec(FAmmo
[A_BULLETS
]);
2767 FFireAngle
:= FAngle
;
2770 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2771 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2775 if FAmmo
[A_SHELLS
] > 0 then
2777 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2778 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
2779 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2780 Dec(FAmmo
[A_SHELLS
]);
2781 FFireAngle
:= FAngle
;
2785 FShellType
:= SHELL_SHELL
;
2789 if FAmmo
[A_SHELLS
] >= 2 then
2791 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
2792 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2793 Dec(FAmmo
[A_SHELLS
], 2);
2794 FFireAngle
:= FAngle
;
2798 FShellType
:= SHELL_DBLSHELL
;
2802 if FAmmo
[A_BULLETS
] > 0 then
2804 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
2805 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
2806 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2807 Dec(FAmmo
[A_BULLETS
]);
2808 FFireAngle
:= FAngle
;
2811 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2812 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2815 WEAPON_ROCKETLAUNCHER
:
2816 if FAmmo
[A_ROCKETS
] > 0 then
2818 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
2819 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2820 Dec(FAmmo
[A_ROCKETS
]);
2821 FFireAngle
:= FAngle
;
2827 if FAmmo
[A_CELLS
] > 0 then
2829 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
2830 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2831 Dec(FAmmo
[A_CELLS
]);
2832 FFireAngle
:= FAngle
;
2838 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
2840 FBFGFireCounter
:= 17;
2841 if not FNoReload
then
2842 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
2843 Dec(FAmmo
[A_CELLS
], 40);
2847 WEAPON_SUPERPULEMET
:
2848 if FAmmo
[A_SHELLS
] > 0 then
2850 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2851 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
2852 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2853 Dec(FAmmo
[A_SHELLS
]);
2854 FFireAngle
:= FAngle
;
2857 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2858 GameVelX
, GameVelY
-2, SHELL_SHELL
);
2861 WEAPON_FLAMETHROWER
:
2862 if FAmmo
[A_FUEL
] > 0 then
2864 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
2865 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2867 FFireAngle
:= FAngle
;
2873 if g_Game_IsNet
then
2877 if FCurrWeap
<> WEAPON_BFG
then
2878 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
2880 if not FNoReload
then
2881 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
2884 MH_SEND_PlayerStats(FUID
);
2889 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
2890 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
2891 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
2894 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
2897 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
2898 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
2899 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
2900 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
2901 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
2906 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
2908 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
2909 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
2910 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
2913 procedure TPlayer
.JetpackOn
;
2917 FJetSoundOn
.SetPosition(0);
2918 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
2922 procedure TPlayer
.JetpackOff
;
2926 FJetSoundOff
.SetPosition(0);
2927 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
2930 procedure TPlayer
.CatchFire(Attacker
: Word);
2933 FFireAttacker
:= Attacker
;
2934 if g_Game_IsNet
and g_Game_IsServer
then
2935 MH_SEND_PlayerStats(FUID
);
2938 procedure TPlayer
.Jump();
2940 if gFly
or FJetpack
then
2942 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
2943 if FObj
.Vel
.Y
> -VEL_FLY
then
2944 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
2947 if FJetFuel
> 0 then
2949 if (FJetFuel
< 1) and g_Game_IsServer
then
2953 if g_Game_IsNet
then
2954 MH_SEND_PlayerStats(FUID
);
2960 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
2962 FCanJetpack
:= False;
2964 // Ïðûãàåì èëè âñïëûâàåì:
2965 if (CollideLevel(0, 1) or
2966 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
2967 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
2968 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
2970 FObj
.Vel
.Y
:= -VEL_JUMP
;
2971 FCanJetpack
:= False;
2975 if BodyInLiquid(0, 0) then
2976 FObj
.Vel
.Y
:= -VEL_SW
2977 else if (FJetFuel
> 0) and FCanJetpack
and
2978 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
2982 if g_Game_IsNet
then
2983 MH_SEND_PlayerStats(FUID
);
2988 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
2990 a
, i
, k
, ab
, ar
: Byte;
2994 srv
, netsrv
: Boolean;
3000 procedure PushItem(t
: Byte);
3004 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3005 it
:= g_Items_ByIdx(id
);
3006 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3008 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3009 (FObj
.Vel
.Y
div 2)-Random(9));
3010 it
.positionChanged(); // this updates spatial accelerators
3014 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3016 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3017 (FObj
.Vel
.Y
div 2)-Random(6));
3019 else // -3..+3; -3..0
3021 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3022 (FObj
.Vel
.Y
div 2)-Random(4));
3024 it
.positionChanged(); // this updates spatial accelerators
3027 if g_Game_IsNet
and g_Game_IsServer
then
3028 MH_SEND_ItemSpawn(True, id
);
3032 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3033 Srv
:= g_Game_IsServer
;
3034 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3035 if Srv
then FDeath
:= FDeath
+ 1;
3040 if not FPhysics
then
3046 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3048 if FLives
> 0 then FLives
:= FLives
- 1;
3049 if FLives
= 0 then FNoRespawn
:= True;
3052 // Íîìåð òèïà ñìåðòè:
3055 K_SIMPLEKILL
: a
:= 1;
3057 K_EXTRAHARDKILL
: a
:= 3;
3062 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3064 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3071 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3073 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3074 K_EXTRAHARDKILL
, K_FALLKILL
:
3075 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3078 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3082 K_HARDKILL
, K_EXTRAHARDKILL
:
3086 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3087 if (KillType
<> K_FALLKILL
) and (Srv
) then
3088 g_Monsters_killedp();
3090 if SpawnerUID
= FUID
then
3092 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3097 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3100 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3101 begin // Óáèò äðóãèì èãðîêîì
3102 KP
:= g_Player_Get(SpawnerUID
);
3103 if (KP
<> nil) and Srv
then
3105 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3106 if SameTeam(FUID
, SpawnerUID
) then
3116 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3117 Inc(gTeamStat
[KP
.Team
].Goals
,
3118 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3120 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3123 plr
:= g_Player_Get(SpawnerUID
);
3131 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3135 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3139 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3144 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3145 begin // Óáèò ìîíñòðîì
3146 mon
:= g_Monsters_ByUID(SpawnerUID
);
3150 s
:= g_Monsters_GetKilledBy(mon
.MonsterType
);
3154 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3158 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3162 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3167 else // Îñîáûå òèïû ñìåðòè
3170 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3171 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3172 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3173 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3174 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3175 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3181 for a
:= WP_FIRST
to WP_LAST
do
3185 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3186 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3187 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3188 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3189 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3190 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3191 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3192 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3193 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3202 if R_ITEM_BACKPACK
in FRulez
then
3203 PushItem(ITEM_AMMO_BACKPACK
);
3205 // Âûáðîñ ðàêåòíîãî ðàíöà:
3206 if FJetFuel
> 0 then
3207 PushItem(ITEM_JETPACK
);
3210 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3212 if R_KEY_RED
in FRulez
then
3213 PushItem(ITEM_KEY_RED
);
3215 if R_KEY_GREEN
in FRulez
then
3216 PushItem(ITEM_KEY_GREEN
);
3218 if R_KEY_BLUE
in FRulez
then
3219 PushItem(ITEM_KEY_BLUE
);
3226 g_Player_CreateCorpse(Self
);
3228 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3229 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3235 for i
:= Low(gPlayers
) to High(gPlayers
) do
3237 if gPlayers
[i
] = nil then continue
;
3238 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3241 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3242 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3247 OldLR
:= gLMSRespawn
;
3248 if (gGameSettings
.GameMode
= GM_COOP
) then
3252 // everyone is dead, restart the map
3253 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3255 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3256 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3257 gLMSRespawnTime
:= gTime
+ 5000;
3259 else if (a
= 1) then
3261 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3262 if (gPlayers
[k
] = gPlayer1
) or
3263 (gPlayers
[k
] = gPlayer2
) then
3264 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3265 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3266 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3269 else if (gGameSettings
.GameMode
= GM_TDM
) then
3271 if (ab
= 0) and (ar
<> 0) then
3274 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3276 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3277 Inc(gTeamStat
[TEAM_RED
].Goals
);
3278 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3279 gLMSRespawnTime
:= gTime
+ 5000;
3281 else if (ar
= 0) and (ab
<> 0) then
3284 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3286 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3287 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3288 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3289 gLMSRespawnTime
:= gTime
+ 5000;
3291 else if (ar
= 0) and (ab
= 0) then
3294 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3296 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3297 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3298 gLMSRespawnTime
:= gTime
+ 5000;
3301 else if (gGameSettings
.GameMode
= GM_DM
) then
3305 if gPlayers
[k
] <> nil then
3308 // survivor is the winner
3309 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3311 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3314 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3315 gLMSRespawnTime
:= gTime
+ 5000;
3317 else if (a
= 0) then
3319 // everyone is dead, restart the map
3320 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3322 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3323 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3324 gLMSRespawnTime
:= gTime
+ 5000;
3327 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3329 if NetMode
= NET_SERVER
then
3330 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3332 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3338 MH_SEND_PlayerStats(FUID
);
3339 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3340 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3343 if srv
and FNoRespawn
then Spectate(True);
3344 FWantsInGame
:= True;
3347 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3349 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3350 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3353 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3355 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3356 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3359 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3361 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3362 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3363 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3365 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3366 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3367 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3371 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3373 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3374 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3375 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3379 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3381 if g_Game_IsClient
then Exit
;
3382 if Weapon
> High(FWeapon
) then Exit
;
3383 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3386 procedure TPlayer
.resetWeaponQueue ();
3389 FNextWeapDelay
:= 0;
3392 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3396 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3397 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 0);
3398 WEAPON_PISTOL
, WEAPON_CHAINGUN
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_BULLETS
] > 0);
3399 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3400 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3401 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3402 else result
:= (weapon
< length(FWeapon
));
3406 // return 255 for "no switch"
3407 function TPlayer
.getNextWeaponIndex (): Byte;
3410 wantThisWeapon
: array[0..64] of Boolean;
3411 wwc
: Integer = 0; //HACK!
3414 result
:= 255; // default result: "no switch"
3415 // had weapon cycling on previous frame? remove that flag
3416 if (FNextWeap
and $2000) <> 0 then
3418 FNextWeap
:= FNextWeap
and $1FFF;
3419 FNextWeapDelay
:= 0;
3421 // cycling has priority
3422 if (FNextWeap
and $C000) <> 0 then
3424 if (FNextWeap
and $8000) <> 0 then
3428 FNextWeap
:= FNextWeap
or $2000; // we need this
3429 if FNextWeapDelay
> 0 then
3430 exit
; // cooldown time
3432 for i
:= 0 to High(FWeapon
) do
3434 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3435 if FWeapon
[cwi
] then
3437 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d', [FCurrWeap, cwi]), MSG_WARNING);
3438 result
:= Byte(cwi
);
3439 FNextWeapDelay
:= 10;
3447 for i
:= 0 to High(wantThisWeapon
) do
3448 wantThisWeapon
[i
] := false;
3449 for i
:= 0 to High(FWeapon
) do
3450 if (FNextWeap
and (1 shl i
)) <> 0 then
3452 wantThisWeapon
[i
] := true;
3455 // exclude currently selected weapon from the set
3456 wantThisWeapon
[FCurrWeap
] := false;
3457 // slow down alterations a little
3460 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3461 // more than one weapon requested, assume "alteration" and check alteration delay
3462 if FNextWeapDelay
> 0 then
3468 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3469 // but clear all counters if no weapon should be switched
3475 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3476 // try weapons in descending order
3477 for i
:= High(FWeapon
) downto 0 do
3479 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3484 FNextWeapDelay
:= 10; // anyway, 'cause why not
3488 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3492 procedure TPlayer
.RealizeCurrentWeapon();
3493 function switchAllowed (): Boolean;
3498 if FBFGFireCounter
<> -1 then
3500 if FTime
[T_SWITCH
] > gTime
then
3502 for i
:= WP_FIRST
to WP_LAST
do
3503 if FReloading
[i
] > 0 then
3511 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3512 //FNextWeap := FNextWeap and $1FFF;
3513 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3515 if not switchAllowed
then
3517 //HACK for weapon cycling
3518 if (FNextWeap
and $7000) <> 0 then FNextWeap
:= 0;
3522 nw
:= getNextWeaponIndex();
3523 if nw
= 255 then exit
; // don't reset anything here
3524 if nw
> High(FWeapon
) then
3526 // don't forget to reset queue here!
3527 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3535 FTime
[T_SWITCH
] := gTime
+156;
3536 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3537 FModel
.SetWeapon(FCurrWeap
);
3538 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3542 procedure TPlayer
.NextWeapon();
3544 if g_Game_IsClient
then Exit
;
3548 procedure TPlayer
.PrevWeapon();
3550 if g_Game_IsClient
then Exit
;
3554 procedure TPlayer
.SetWeapon(W
: Byte);
3556 if FCurrWeap
<> W
then
3557 if W
= WEAPON_SAW
then
3558 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3561 FModel
.SetWeapon(CurrWeap
);
3565 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3570 if g_Game_IsClient
then Exit
;
3572 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3573 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3578 if FHealth
< PLAYER_HP_SOFT
then
3580 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3584 if gFlash
= 2 then Inc(FPickup
, 5);
3588 if FHealth
< PLAYER_HP_SOFT
then
3590 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3594 if gFlash
= 2 then Inc(FPickup
, 5);
3598 if FArmor
< PLAYER_AP_SOFT
then
3600 FArmor
:= PLAYER_AP_SOFT
;
3603 if gFlash
= 2 then Inc(FPickup
, 5);
3607 if FArmor
< PLAYER_AP_LIMIT
then
3609 FArmor
:= PLAYER_AP_LIMIT
;
3612 if gFlash
= 2 then Inc(FPickup
, 5);
3616 if FHealth
< PLAYER_HP_LIMIT
then
3618 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3622 if gFlash
= 2 then Inc(FPickup
, 5);
3626 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3628 if FHealth
< PLAYER_HP_LIMIT
then
3629 FHealth
:= PLAYER_HP_LIMIT
;
3630 if FArmor
< PLAYER_AP_LIMIT
then
3631 FArmor
:= PLAYER_AP_LIMIT
;
3635 if gFlash
= 2 then Inc(FPickup
, 5);
3639 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3641 FWeapon
[WEAPON_SAW
] := True;
3643 if gFlash
= 2 then Inc(FPickup
, 5);
3644 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3647 ITEM_WEAPON_SHOTGUN1
:
3648 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3650 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3651 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3653 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3654 FWeapon
[WEAPON_SHOTGUN1
] := True;
3656 if gFlash
= 2 then Inc(FPickup
, 5);
3657 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3660 ITEM_WEAPON_SHOTGUN2
:
3661 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3663 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3665 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3666 FWeapon
[WEAPON_SHOTGUN2
] := True;
3668 if gFlash
= 2 then Inc(FPickup
, 5);
3669 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3672 ITEM_WEAPON_CHAINGUN
:
3673 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3675 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3677 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3678 FWeapon
[WEAPON_CHAINGUN
] := 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_ROCKETLAUNCHER
:
3685 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3687 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3689 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3690 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3692 if gFlash
= 2 then Inc(FPickup
, 5);
3693 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3697 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3699 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3701 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3702 FWeapon
[WEAPON_PLASMA
] := True;
3704 if gFlash
= 2 then Inc(FPickup
, 5);
3705 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3709 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3711 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3713 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3714 FWeapon
[WEAPON_BFG
] := True;
3716 if gFlash
= 2 then Inc(FPickup
, 5);
3717 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3720 ITEM_WEAPON_SUPERPULEMET
:
3721 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3723 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3725 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3726 FWeapon
[WEAPON_SUPERPULEMET
] := True;
3728 if gFlash
= 2 then Inc(FPickup
, 5);
3729 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3732 ITEM_WEAPON_FLAMETHROWER
:
3733 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
3735 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
3737 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3738 FWeapon
[WEAPON_FLAMETHROWER
] := True;
3740 if gFlash
= 2 then Inc(FPickup
, 5);
3741 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3745 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3747 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3750 if gFlash
= 2 then Inc(FPickup
, 5);
3753 ITEM_AMMO_BULLETS_BOX
:
3754 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3756 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3759 if gFlash
= 2 then Inc(FPickup
, 5);
3763 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3765 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3768 if gFlash
= 2 then Inc(FPickup
, 5);
3771 ITEM_AMMO_SHELLS_BOX
:
3772 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3774 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
3777 if gFlash
= 2 then Inc(FPickup
, 5);
3781 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3783 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3786 if gFlash
= 2 then Inc(FPickup
, 5);
3789 ITEM_AMMO_ROCKET_BOX
:
3790 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3792 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
3795 if gFlash
= 2 then Inc(FPickup
, 5);
3799 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3801 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3804 if gFlash
= 2 then Inc(FPickup
, 5);
3808 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3810 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
3813 if gFlash
= 2 then Inc(FPickup
, 5);
3817 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
3819 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3822 if gFlash
= 2 then Inc(FPickup
, 5);
3826 if not(R_ITEM_BACKPACK
in FRulez
) or
3827 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
3828 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
3829 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
3830 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
3831 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
3833 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
3834 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
3835 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
3836 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
3837 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
3839 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3840 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3841 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3842 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3843 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3844 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3845 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3846 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3848 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
3851 if gFlash
= 2 then Inc(FPickup
, 5);
3855 if not(R_KEY_RED
in FRulez
) then
3857 Include(FRulez
, R_KEY_RED
);
3859 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3860 if gFlash
= 2 then Inc(FPickup
, 5);
3861 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3865 if not(R_KEY_GREEN
in FRulez
) then
3867 Include(FRulez
, R_KEY_GREEN
);
3869 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3870 if gFlash
= 2 then Inc(FPickup
, 5);
3871 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3875 if not(R_KEY_BLUE
in FRulez
) then
3877 Include(FRulez
, R_KEY_BLUE
);
3879 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3880 if gFlash
= 2 then Inc(FPickup
, 5);
3881 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3885 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
3887 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
3891 if gFlash
= 2 then Inc(FPickup
, 5);
3895 if FAir
< AIR_MAX
then
3900 if gFlash
= 2 then Inc(FPickup
, 5);
3905 if not (R_BERSERK
in FRulez
) then
3907 Include(FRulez
, R_BERSERK
);
3908 if FBFGFireCounter
= -1 then
3910 FCurrWeap
:= WEAPON_KASTET
;
3912 FModel
.SetWeapon(WEAPON_KASTET
);
3916 if gFlash
= 2 then Inc(FPickup
, 5);
3917 FBerserk
:= gTime
+30000;
3922 if FHealth
< PLAYER_HP_SOFT
then
3924 FHealth
:= PLAYER_HP_SOFT
;
3925 FBerserk
:= gTime
+30000;
3933 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
3935 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
3938 if gFlash
= 2 then Inc(FPickup
, 5);
3942 if FHealth
< PLAYER_HP_LIMIT
then
3944 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
3948 if gFlash
= 2 then Inc(FPickup
, 5);
3952 if FArmor
< PLAYER_AP_LIMIT
then
3954 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
3957 if gFlash
= 2 then Inc(FPickup
, 5);
3961 if FJetFuel
< JET_MAX
then
3963 FJetFuel
:= JET_MAX
;
3966 if gFlash
= 2 then Inc(FPickup
, 5);
3970 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
3972 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
3975 if gFlash
= 2 then Inc(FPickup
, 5);
3980 procedure TPlayer
.Touch();
3984 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
3987 // Áðîñèòü ôëàã òîâàðèùó:
3988 if gGameSettings
.GameMode
= GM_CTF
then
3993 procedure TPlayer
.Push(vx
, vy
: Integer);
3995 if (not FPhysics
) and FGhost
then
3997 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
3998 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
3999 if g_Game_IsNet
and g_Game_IsServer
then
4000 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4003 procedure TPlayer
.Reset(Force
: Boolean);
4009 FTime
[T_RESPAWN
] := 0;
4010 FTime
[T_FLAGCAP
] := 0;
4023 FSpectator
:= False;
4026 FSpectatePlayer
:= -1;
4027 FNoRespawn
:= False;
4029 FLives
:= gGameSettings
.MaxLives
;
4034 procedure TPlayer
.SoftReset();
4040 FBFGFireCounter
:= -1;
4048 SetAction(A_STAND
, True);
4051 function TPlayer
.GetRespawnPoint(): Byte;
4056 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4058 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4059 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4061 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4063 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4064 if Self
= gPlayer1
then
4065 c
:= RESPAWNPOINT_PLAYER1
4067 c
:= RESPAWNPOINT_PLAYER2
;
4068 if g_Map_GetPointCount(c
) > 0 then
4074 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4075 if Self
= gPlayer1
then
4076 c
:= RESPAWNPOINT_PLAYER2
4078 c
:= RESPAWNPOINT_PLAYER1
;
4079 if g_Map_GetPointCount(c
) > 0 then
4086 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4087 if Random(2) = 0 then
4088 c
:= RESPAWNPOINT_PLAYER1
4090 c
:= RESPAWNPOINT_PLAYER2
;
4091 if g_Map_GetPointCount(c
) > 0 then
4098 // Òî÷êà ëþáîé èç êîìàíä
4099 if Random(2) = 0 then
4100 c
:= RESPAWNPOINT_RED
4102 c
:= RESPAWNPOINT_BLUE
;
4103 if g_Map_GetPointCount(c
) > 0 then
4110 c
:= RESPAWNPOINT_DM
;
4111 if g_Map_GetPointCount(c
) > 0 then
4119 if gGameSettings
.GameMode
= GM_DM
then
4122 c
:= RESPAWNPOINT_DM
;
4123 if g_Map_GetPointCount(c
) > 0 then
4129 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4130 if Random(2) = 0 then
4131 c
:= RESPAWNPOINT_PLAYER1
4133 c
:= RESPAWNPOINT_PLAYER2
;
4134 if g_Map_GetPointCount(c
) > 0 then
4140 // Òî÷êà ëþáîé èç êîìàíä
4141 if Random(2) = 0 then
4142 c
:= RESPAWNPOINT_RED
4144 c
:= RESPAWNPOINT_BLUE
;
4145 if g_Map_GetPointCount(c
) > 0 then
4153 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4155 // Òî÷êà ñâîåé êîìàíäû
4156 c
:= RESPAWNPOINT_DM
;
4157 if FTeam
= TEAM_RED
then
4158 c
:= RESPAWNPOINT_RED
;
4159 if FTeam
= TEAM_BLUE
then
4160 c
:= RESPAWNPOINT_BLUE
;
4161 if g_Map_GetPointCount(c
) > 0 then
4168 c
:= RESPAWNPOINT_DM
;
4169 if g_Map_GetPointCount(c
) > 0 then
4175 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4176 if Random(2) = 0 then
4177 c
:= RESPAWNPOINT_PLAYER1
4179 c
:= RESPAWNPOINT_PLAYER2
;
4180 if g_Map_GetPointCount(c
) > 0 then
4186 // Òî÷êà äðóãîé êîìàíäû
4187 c
:= RESPAWNPOINT_DM
;
4188 if FTeam
= TEAM_RED
then
4189 c
:= RESPAWNPOINT_BLUE
;
4190 if FTeam
= TEAM_BLUE
then
4191 c
:= RESPAWNPOINT_RED
;
4192 if g_Map_GetPointCount(c
) > 0 then
4200 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4202 RespawnPoint
: TRespawnPoint
;
4207 if not g_Game_IsServer
then
4211 FWantsInGame
:= True;
4212 FJustTeleported
:= True;
4215 FTime
[T_RESPAWN
] := 0;
4219 // if server changes MaxLives we gotta be ready
4220 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4222 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4223 if FTime
[T_RESPAWN
] > gTime
then
4226 // Ïðîñðàë âñå æèçíè:
4229 if not FSpectator
then Spectate(True);
4230 FWantsInGame
:= True;
4234 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4235 begin // "Ñâîÿ èãðà"
4236 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4237 FRulez
:= FRulez
-[R_BERSERK
];
4239 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4241 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4242 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4245 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4246 c
:= GetRespawnPoint();
4251 // Âîñêðåøåíèå áåç îðóæèÿ:
4254 FHealth
:= PLAYER_HP_SOFT
;
4260 for a
:= WP_FIRST
to WP_LAST
do
4262 FWeapon
[a
] := False;
4266 FWeapon
[WEAPON_PISTOL
] := True;
4267 FWeapon
[WEAPON_KASTET
] := True;
4268 FCurrWeap
:= WEAPON_PISTOL
;
4271 FModel
.SetWeapon(FCurrWeap
);
4273 for b
:= A_BULLETS
to A_HIGH
do
4276 FAmmo
[A_BULLETS
] := 50;
4278 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4279 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4280 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4281 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4282 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4284 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4285 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4290 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4291 if not g_Map_GetPoint(c
, RespawnPoint
) then
4293 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4297 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4298 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4299 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4305 FDirection
:= RespawnPoint
.Direction
;
4306 if FDirection
= D_LEFT
then
4312 FBFGFireCounter
:= -1;
4317 SetAction(A_STAND
, True);
4318 FModel
.Direction
:= FDirection
;
4320 for a
:= Low(FTime
) to High(FTime
) do
4323 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4328 FCanJetpack
:= False;
4333 // Àíèìàöèÿ âîçðîæäåíèÿ:
4334 if (not gLoadGameMode
) and (not Silent
) then
4335 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4337 Anim
:= TAnimation
.Create(ID
, False, 3);
4338 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4339 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4343 FSpectator
:= False;
4346 FSpectatePlayer
:= -1;
4349 if g_Game_IsNet
then
4351 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4352 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4354 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4355 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4360 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4363 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4364 else if (not NoMove
) then
4366 GameX
:= gMapInfo
.Width
div 2;
4367 GameY
:= gMapInfo
.Height
div 2;
4376 FWantsInGame
:= False;
4381 if Self
= gPlayer1
then
4386 if Self
= gPlayer2
then
4393 if g_Game_IsNet
then
4394 MH_SEND_PlayerStats(FUID
);
4397 procedure TPlayer
.SwitchNoClip
;
4401 FGhost
:= not FGhost
;
4402 FPhysics
:= not FGhost
;
4414 procedure TPlayer
.Run(Direction
: TDirection
);
4418 if MAX_RUNVEL
> 8 then
4422 if Direction
= D_LEFT
then
4424 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4425 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4428 if FObj
.Vel
.X
< MAX_RUNVEL
then
4429 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4431 // Âîçìîæíî, ïèíàåì êóñêè:
4432 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4434 b
:= Abs(FObj
.Vel
.X
);
4435 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4436 for a
:= 0 to High(gGibs
) do
4438 if gGibs
[a
].Live
and
4439 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4440 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4443 if FObj
.Vel
.X
< 0 then
4445 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4449 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4451 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4459 procedure TPlayer
.SeeDown();
4461 SetAction(A_SEEDOWN
);
4463 if FDirection
= D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4465 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4468 procedure TPlayer
.SeeUp();
4472 if FDirection
= D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4474 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4477 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4485 A_ATTACK
: Prior
:= 2;
4486 A_SEEUP
: Prior
:= 1;
4487 A_SEEDOWN
: Prior
:= 1;
4488 A_ATTACKUP
: Prior
:= 2;
4489 A_ATTACKDOWN
: Prior
:= 2;
4494 if (Prior
> FActionPrior
) or Force
then
4495 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4497 FActionPrior
:= Prior
;
4498 FActionAnim
:= Action
;
4499 FActionForce
:= Force
;
4500 FActionChanged
:= True;
4503 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4506 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4508 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4509 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4510 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4511 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4514 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4521 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4523 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4524 if g_Game_IsServer
and g_Game_IsNet
then
4525 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4529 FJustTeleported
:= True;
4534 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4536 Anim
:= TAnimation
.Create(ID
, False, 3);
4539 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4540 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4541 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4542 if g_Game_IsServer
and g_Game_IsNet
then
4543 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4544 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4548 FObj
.X
:= X
-PLAYER_RECT
.X
;
4549 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4550 if FLive
and FGhost
then
4556 if not g_Game_IsNet
then
4560 SetDirection(D_LEFT
);
4566 SetDirection(D_RIGHT
);
4572 if FDirection
= D_RIGHT
then
4574 SetDirection(D_LEFT
);
4579 SetDirection(D_RIGHT
);
4585 if not silent
and (Anim
<> nil) then
4587 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4588 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4591 if g_Game_IsServer
and g_Game_IsNet
then
4592 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4593 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4600 function nonz(a
: Single): Single;
4608 procedure TPlayer
.Update();
4611 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4612 blockmon
, headwater
, dospawn
: Boolean;
4617 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4618 AnyServer
:= g_Game_IsServer
;
4620 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4621 DoLerp(NetInterpLevel
+ 1)
4627 if FClientID
>= 0 then
4629 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4630 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4631 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4640 if FLive
and (gFly
or FJetpack
) then
4643 if FDirection
= D_LEFT
then
4648 if FLive
and (not FGhost
) then
4650 if FKeys
[KEY_UP
].Pressed
then
4652 if FKeys
[KEY_DOWN
].Pressed
then
4656 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4659 i
:= g_basic
.Sign(FIncCam
);
4660 FIncCam
:= Abs(FIncCam
);
4661 DecMin(FIncCam
, 5, 0);
4662 FIncCam
:= FIncCam
*i
;
4665 // no need to do that each second frame, weapon queue will take care of it
4666 if FLive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4667 if FLive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4669 if gTime
mod (GAME_TICK
*2) <> 0 then
4671 if (FObj
.Vel
.X
= 0) and FLive
then
4673 if FKeys
[KEY_LEFT
].Pressed
then
4675 if FKeys
[KEY_RIGHT
].Pressed
then
4681 g_Obj_Move(@FObj
, True, True, True);
4682 positionChanged(); // this updates spatial accelerators
4688 FActionChanged
:= False;
4692 // Let alive player do some actions
4693 if FKeys
[KEY_LEFT
].Pressed
then Run(D_LEFT
);
4694 if FKeys
[KEY_RIGHT
].Pressed
then Run(D_RIGHT
);
4695 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
4696 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
4697 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
4698 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
4699 if FKeys
[KEY_JUMP
].Pressed
then Jump()
4702 if AnyServer
and FJetpack
then
4706 if NetServer
then MH_SEND_PlayerStats(FUID
);
4708 FCanJetpack
:= True;
4715 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
4717 if FKeys
[k
].Pressed
then
4725 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4728 if (FTime
[T_RESPAWN
] <= gTime
) and
4729 gGameOn
and (not FLive
) then
4731 if (g_Player_GetCount() > 1) then
4735 gExit
:= EXIT_RESTART
;
4740 // Dead spectator actions
4743 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
4744 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
4748 if (FSpectatePlayer
>= High(gPlayers
)) then
4749 FSpectatePlayer
:= -1
4753 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
4754 if gPlayers
[I
] <> nil then
4755 if gPlayers
[I
].Live
then
4756 if gPlayers
[I
].UID
<> FUID
then
4758 FSpectatePlayer
:= I
;
4763 if not SetSpect
then FSpectatePlayer
:= -1;
4774 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
4776 FYTo
:= FObj
.Y
- 32;
4777 FSpectatePlayer
:= -1;
4779 if FKeys
[KEY_DOWN
].Pressed
then
4781 FYTo
:= FObj
.Y
+ 32;
4782 FSpectatePlayer
:= -1;
4784 if FKeys
[KEY_LEFT
].Pressed
then
4786 FXTo
:= FObj
.X
- 32;
4787 FSpectatePlayer
:= -1;
4789 if FKeys
[KEY_RIGHT
].Pressed
then
4791 FXTo
:= FObj
.X
+ 32;
4792 FSpectatePlayer
:= -1;
4795 if (FXTo
< -64) then
4797 else if (FXTo
> gMapInfo
.Width
+ 32) then
4798 FXTo
:= gMapInfo
.Width
+ 32;
4799 if (FYTo
< -72) then
4801 else if (FYTo
> gMapInfo
.Height
+ 32) then
4802 FYTo
:= gMapInfo
.Height
+ 32;
4807 g_Obj_Move(@FObj
, True, True, True);
4808 positionChanged(); // this updates spatial accelerators
4815 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
4816 if gPlayers
[FSpectatePlayer
] <> nil then
4817 if gPlayers
[FSpectatePlayer
].Live
then
4819 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
4820 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
4824 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
4825 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
4826 PANEL_BLOCKMON
, True);
4827 headwater
:= HeadInLiquid(0, 0);
4829 // Ñîïðîòèâëåíèå âîçäóõà:
4830 if (not FLive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
4831 if FObj
.Vel
.X
<> 0 then
4832 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
4834 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
4835 DecMin(FPain
, 5, 0);
4836 DecMin(FPickup
, 1, 0);
4838 if FLive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
4840 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
4841 FMegaRulez
[MR_SUIT
] := 0;
4842 FMegaRulez
[MR_INVUL
] := 0;
4843 FMegaRulez
[MR_INVIS
] := 0;
4844 Kill(K_FALLKILL
, 0, HIT_FALL
);
4851 if FCurrWeap
= WEAPON_SAW
then
4852 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
4853 FSawSoundSelect
.IsPlaying()) then
4854 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
4857 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
4858 (not FJetSoundOff
.IsPlaying()) then
4860 FJetSoundFly
.SetPosition(0);
4861 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
4864 for b
:= WP_FIRST
to WP_LAST
do
4865 if FReloading
[b
] > 0 then
4871 if FShellTimer
> -1 then
4872 if FShellTimer
= 0 then
4874 if FShellType
= SHELL_SHELL
then
4875 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4876 GameVelX
, GameVelY
-2, SHELL_SHELL
)
4877 else if FShellType
= SHELL_DBLSHELL
then
4879 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4880 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
4881 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4882 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
4885 end else Dec(FShellTimer
);
4887 if (FBFGFireCounter
> -1) then
4888 if FBFGFireCounter
= 0 then
4892 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
4893 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
4894 xd
:= wx
+IfThen(FDirection
= D_LEFT
, -30, 30);
4895 yd
:= wy
+firediry();
4896 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
4897 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
4898 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
4899 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
4900 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
4903 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
4904 FBFGFireCounter
:= -1;
4907 FBFGFireCounter
:= 0
4909 Dec(FBFGFireCounter
);
4911 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
4913 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
4915 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
4918 if (headwater
or blockmon
) then
4924 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
4927 else if (FAir
mod 31 = 0) and not blockmon
then
4929 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
4930 if Random(2) = 0 then
4931 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
4933 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
4935 end else if FAir
< AIR_DEF
then
4938 if FFireTime
> 0 then
4940 if BodyInLiquid(0, 0) then
4945 else if FMegaRulez
[MR_SUIT
] >= gTime
then
4947 if FMegaRulez
[MR_SUIT
] = gTime
then
4954 if FFirePainTime
<= 0 then
4956 if g_Game_IsServer
then
4957 Damage(5, FFireAttacker
, 0, 0, HIT_FLAME
);
4958 FFirePainTime
:= 18;
4960 FFirePainTime
:= FFirePainTime
- 1;
4961 FFireTime
:= FFireTime
- 1;
4962 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
4963 MH_SEND_PlayerStats(FUID
);
4967 if FDamageBuffer
> 0 then
4969 if FDamageBuffer
>= 9 then
4973 if FDamageBuffer
< 30 then i
:= 9
4974 else if FDamageBuffer
< 100 then i
:= 18
4978 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
4979 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
4980 FHealth
:= FHealth
-ii
;
4983 FHealth
:= FHealth
+FArmor
;
4988 if FHealth
<= 0 then
4989 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
4990 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
4991 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
4995 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
4996 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
4997 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
4998 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5005 end; // if FLive then ...
5007 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5009 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5010 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5011 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5012 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5014 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5015 then SetAction(A_STAND
, True);
5017 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5019 for b
:= Low(FKeys
) to High(FKeys
) do
5020 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5023 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5025 x
:= FObj
.X
+PLAYER_RECT
.X
;
5026 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5027 w
:= PLAYER_RECT
.Width
;
5028 h
:= PLAYER_RECT
.Height
;
5031 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5033 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5034 FObj
.Y
+PLAYER_RECT
.Y
,
5041 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5043 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5044 FObj
.Y
+PLAYER_RECT
.Y
,
5048 Panel
.Width
, Panel
.Height
);
5051 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5053 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5054 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5055 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5056 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5059 function g_Player_ValidName(Name
: string): Boolean;
5065 if gPlayers
= nil then Exit
;
5067 for a
:= 0 to High(gPlayers
) do
5068 if gPlayers
[a
] <> nil then
5069 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5076 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5080 d
:= FModel
.Direction
;
5082 FModel
.Direction
:= Direction
;
5083 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5085 FDirection
:= Direction
;
5088 function TPlayer
.GetKeys(): Byte;
5092 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5093 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5094 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5096 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5097 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5100 procedure TPlayer
.Use();
5104 if FTime
[T_USE
] > gTime
then Exit
;
5106 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5107 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5109 for a
:= 0 to High(gPlayers
) do
5110 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5111 gPlayers
[a
].Live
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5112 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5113 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5115 gPlayers
[a
].Touch();
5116 if g_Game_IsNet
and g_Game_IsServer
then
5117 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5120 FTime
[T_USE
] := gTime
+120;
5123 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5127 WX
, WY
, XD
, YD
: Integer;
5138 if R_BERSERK
in FRulez
then
5140 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5141 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5142 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5145 locobj
.rect
.Width
:= 39;
5146 locobj
.rect
.Height
:= 52;
5147 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5148 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5149 locobj
.Accel
.X
:= xd
-wx
;
5150 locobj
.Accel
.y
:= yd
-wy
;
5152 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5153 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5155 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5159 FPain
:= min(FPain
+ 25, 50);
5161 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5166 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5167 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5169 FSawSoundSelect
.Stop();
5171 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5173 else if not FSawSoundHit
.IsPlaying() then
5175 FSawSoundSelect
.Stop();
5176 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5183 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5184 FFireAngle
:= FAngle
;
5186 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5187 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5192 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5193 FFireAngle
:= FAngle
;
5196 FShellType
:= SHELL_SHELL
;
5201 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5202 FFireAngle
:= FAngle
;
5205 FShellType
:= SHELL_DBLSHELL
;
5210 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5211 FFireAngle
:= FAngle
;
5213 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5214 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5217 WEAPON_ROCKETLAUNCHER
:
5219 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5220 FFireAngle
:= FAngle
;
5226 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5227 FFireAngle
:= FAngle
;
5233 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5234 FFireAngle
:= FAngle
;
5238 WEAPON_SUPERPULEMET
:
5240 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5241 FFireAngle
:= FAngle
;
5243 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5244 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5247 WEAPON_FLAMETHROWER
:
5249 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5250 FFireAngle
:= FAngle
;
5257 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5258 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5259 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5262 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5264 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5265 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5268 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5272 if NetInterpLevel
< 1 then
5282 AX
:= Abs(FXTo
- FObj
.X
);
5283 AY
:= Abs(FYTo
- FObj
.Y
);
5284 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5286 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5291 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5293 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5294 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5295 PANEL_LIFTUP
, False) then Result
:= -1
5297 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5298 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5299 PANEL_LIFTDOWN
, False) then Result
:= 1
5303 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5310 if Flag
= FLAG_NONE
then
5313 if not g_Game_IsServer
then Exit
;
5315 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5316 if (Flag
= FTeam
) and
5317 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5318 (FFlag
<> FLAG_NONE
) then
5320 if FFlag
= FLAG_RED
then
5321 s
:= _lc
[I_PLAYER_FLAG_RED
]
5323 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5325 evtype
:= FLAG_STATE_SCORED
;
5327 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5328 Insert('.', ts
, Length(ts
) + 1 - 3);
5329 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5331 g_Map_ResetFlag(FFlag
);
5332 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5334 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5337 if g_Game_IsNet
then
5339 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5343 gFlags
[FFlag
].CaptureTime
:= 0;
5348 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5349 if (Flag
= FTeam
) and
5350 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5352 if Flag
= FLAG_RED
then
5353 s
:= _lc
[I_PLAYER_FLAG_RED
]
5355 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5357 evtype
:= FLAG_STATE_RETURNED
;
5358 gFlags
[Flag
].CaptureTime
:= 0;
5360 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5362 g_Map_ResetFlag(Flag
);
5363 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5366 if g_Game_IsNet
then
5368 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5374 // Ïîäîáðàë ÷óæîé ôëàã:
5375 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5379 if Flag
= FLAG_RED
then
5380 s
:= _lc
[I_PLAYER_FLAG_RED
]
5382 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5384 evtype
:= FLAG_STATE_CAPTURED
;
5386 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5388 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5390 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5393 if g_Game_IsNet
then
5395 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5401 procedure TPlayer
.SetFlag(Flag
: Byte);
5404 if FModel
<> nil then
5405 FModel
.SetFlag(FFlag
);
5408 function TPlayer
.DropFlag(): Boolean;
5413 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5415 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5416 with gFlags
[FFlag
] do
5420 Direction
:= FDirection
;
5421 State
:= FLAG_STATE_DROPPED
;
5423 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5424 (FObj
.Vel
.Y
div 2)-2+Random(5));
5425 positionChanged(); // this updates spatial accelerators
5427 if FFlag
= FLAG_RED
then
5428 s
:= _lc
[I_PLAYER_FLAG_RED
]
5430 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5432 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5433 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5435 if g_Game_IsNet
then
5436 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5442 procedure TPlayer
.GetSecret();
5447 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5449 Assert(Key
<= High(FKeys
));
5451 FKeys
[Key
].Pressed
:= True;
5452 FKeys
[Key
].Time
:= Time
;
5455 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5457 Result
:= FKeys
[K
].Pressed
;
5460 procedure TPlayer
.ReleaseKeys();
5464 for a
:= Low(FKeys
) to High(FKeys
) do
5466 FKeys
[a
].Pressed
:= False;
5471 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5475 function TPlayer
.firediry(): Integer;
5477 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5478 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5482 procedure TPlayer
.RememberState();
5486 FSavedState
.Health
:= FHealth
;
5487 FSavedState
.Armor
:= FArmor
;
5488 FSavedState
.Air
:= FAir
;
5489 FSavedState
.JetFuel
:= FJetFuel
;
5490 FSavedState
.CurrWeap
:= FCurrWeap
;
5491 FSavedState
.NextWeap
:= FNextWeap
;
5492 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5495 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5497 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5499 FSavedState
.Rulez
:= FRulez
;
5500 FSavedState
.WaitRecall
:= True;
5503 procedure TPlayer
.RecallState();
5507 if not FSavedState
.WaitRecall
then Exit
;
5509 FHealth
:= FSavedState
.Health
;
5510 FArmor
:= FSavedState
.Armor
;
5511 FAir
:= FSavedState
.Air
;
5512 FJetFuel
:= FSavedState
.JetFuel
;
5513 FCurrWeap
:= FSavedState
.CurrWeap
;
5514 FNextWeap
:= FSavedState
.NextWeap
;
5515 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5518 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5520 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5522 FRulez
:= FSavedState
.Rulez
;
5523 FSavedState
.WaitRecall
:= False;
5525 if gGameSettings
.GameType
= GT_SERVER
then
5526 MH_SEND_PlayerStats(FUID
);
5529 procedure TPlayer
.SaveState(var Mem
: TBinMemoryWriter
);
5541 Mem
:= TBinMemoryWriter
.Create(i
);
5543 // Ñèãíàòóðà èãðîêà:
5544 sig
:= PLAYER_SIGNATURE
; // 'PLYR'
5545 Mem
.WriteDWORD(sig
);
5547 Mem
.WriteBoolean(FIamBot
);
5549 Mem
.WriteWord(FUID
);
5551 Mem
.WriteString(FName
, 32);
5553 Mem
.WriteByte(FTeam
);
5555 Mem
.WriteBoolean(FLive
);
5556 // Èçðàñõîäîâàë ëè âñå æèçíè:
5557 Mem
.WriteBoolean(FNoRespawn
);
5559 if FDirection
= D_LEFT
then
5565 Mem
.WriteInt(FHealth
);
5567 Mem
.WriteByte(FLives
);
5569 Mem
.WriteInt(FArmor
);
5573 Mem
.WriteInt(FJetFuel
);
5575 Mem
.WriteInt(FPain
);
5577 Mem
.WriteInt(FKills
);
5579 Mem
.WriteInt(FMonsterKills
);
5581 Mem
.WriteInt(FFrags
);
5583 Mem
.WriteByte(FFragCombo
);
5584 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5585 Mem
.WriteDWORD(FLastFrag
);
5587 Mem
.WriteInt(FDeath
);
5588 // Êàêîé ôëàã íåñåò:
5589 Mem
.WriteByte(FFlag
);
5591 Mem
.WriteInt(FSecrets
);
5593 Mem
.WriteByte(FCurrWeap
);
5595 Mem
.WriteWord(FNextWeap
);
5597 Mem
.WriteByte(FNextWeapDelay
);
5598 // Âðåìÿ çàðÿäêè BFG:
5599 Mem
.WriteSmallInt(FBFGFireCounter
);
5601 Mem
.WriteInt(FDamageBuffer
);
5602 // Ïîñëåäíèé óäàðèâøèé:
5603 Mem
.WriteWord(FLastSpawnerUID
);
5604 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5605 Mem
.WriteByte(FLastHit
);
5607 Obj_SaveState(@FObj
, Mem
);
5608 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5609 for i
:= A_BULLETS
to A_HIGH
do
5610 Mem
.WriteWord(FAmmo
[i
]);
5611 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5612 for i
:= A_BULLETS
to A_HIGH
do
5613 Mem
.WriteWord(FMaxAmmo
[i
]);
5615 for i
:= WP_FIRST
to WP_LAST
do
5616 Mem
.WriteBoolean(FWeapon
[i
]);
5617 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5618 for i
:= WP_FIRST
to WP_LAST
do
5619 Mem
.WriteWord(FReloading
[i
]);
5621 if R_ITEM_BACKPACK
in FRulez
then
5626 // Íàëè÷èå êðàñíîãî êëþ÷à:
5627 if R_KEY_RED
in FRulez
then
5632 // Íàëè÷èå çåëåíîãî êëþ÷à:
5633 if R_KEY_GREEN
in FRulez
then
5638 // Íàëè÷èå ñèíåãî êëþ÷à:
5639 if R_KEY_BLUE
in FRulez
then
5644 // Íàëè÷èå áåðñåðêà:
5645 if R_BERSERK
in FRulez
then
5650 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5651 for i
:= MR_SUIT
to MR_MAX
do
5652 Mem
.WriteDWORD(FMegaRulez
[i
]);
5653 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5654 for i
:= T_RESPAWN
to T_FLAGCAP
do
5655 Mem
.WriteDWORD(FTime
[i
]);
5658 Mem
.WriteString(str
);
5668 procedure TPlayer
.LoadState(var Mem
: TBinMemoryReader
);
5678 // Ñèãíàòóðà èãðîêà:
5680 if sig
<> PLAYER_SIGNATURE
then // 'PLYR'
5682 raise EBinSizeError
.Create('TPlayer.LoadState: Wrong Player Signature');
5685 Mem
.ReadBoolean(FIamBot
);
5689 Mem
.ReadString(str
);
5690 if (Self
<> gPlayer1
) and (Self
<> gPlayer2
) then
5693 Mem
.ReadByte(FTeam
);
5695 Mem
.ReadBoolean(FLive
);
5696 // Èçðàñõîäîâàë ëè âñå æèçíè:
5697 Mem
.ReadBoolean(FNoRespawn
);
5701 FDirection
:= D_LEFT
5703 FDirection
:= D_RIGHT
;
5705 Mem
.ReadInt(FHealth
);
5707 Mem
.ReadByte(FLives
);
5709 Mem
.ReadInt(FArmor
);
5713 Mem
.ReadInt(FJetFuel
);
5717 Mem
.ReadInt(FKills
);
5719 Mem
.ReadInt(FMonsterKills
);
5721 Mem
.ReadInt(FFrags
);
5723 Mem
.ReadByte(FFragCombo
);
5724 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5725 Mem
.ReadDWORD(FLastFrag
);
5727 Mem
.ReadInt(FDeath
);
5728 // Êàêîé ôëàã íåñåò:
5729 Mem
.ReadByte(FFlag
);
5731 Mem
.ReadInt(FSecrets
);
5733 Mem
.ReadByte(FCurrWeap
);
5735 Mem
.ReadWord(FNextWeap
);
5737 Mem
.ReadByte(FNextWeapDelay
);
5738 // Âðåìÿ çàðÿäêè BFG:
5739 Mem
.ReadSmallInt(FBFGFireCounter
);
5741 Mem
.ReadInt(FDamageBuffer
);
5742 // Ïîñëåäíèé óäàðèâøèé:
5743 Mem
.ReadWord(FLastSpawnerUID
);
5744 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5745 Mem
.ReadByte(FLastHit
);
5747 Obj_LoadState(@FObj
, Mem
);
5748 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5749 for i
:= A_BULLETS
to A_HIGH
do
5750 Mem
.ReadWord(FAmmo
[i
]);
5751 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5752 for i
:= A_BULLETS
to A_HIGH
do
5753 Mem
.ReadWord(FMaxAmmo
[i
]);
5755 for i
:= WP_FIRST
to WP_LAST
do
5756 Mem
.ReadBoolean(FWeapon
[i
]);
5757 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5758 for i
:= WP_FIRST
to WP_LAST
do
5759 Mem
.ReadWord(FReloading
[i
]);
5763 Include(FRulez
, R_ITEM_BACKPACK
);
5764 // Íàëè÷èå êðàñíîãî êëþ÷à:
5767 Include(FRulez
, R_KEY_RED
);
5768 // Íàëè÷èå çåëåíîãî êëþ÷à:
5771 Include(FRulez
, R_KEY_GREEN
);
5772 // Íàëè÷èå ñèíåãî êëþ÷à:
5775 Include(FRulez
, R_KEY_BLUE
);
5776 // Íàëè÷èå áåðñåðêà:
5779 Include(FRulez
, R_BERSERK
);
5780 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5781 for i
:= MR_SUIT
to MR_MAX
do
5782 Mem
.ReadDWORD(FMegaRulez
[i
]);
5783 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5784 for i
:= T_RESPAWN
to T_FLAGCAP
do
5785 Mem
.ReadDWORD(FTime
[i
]);
5787 Mem
.ReadString(str
);
5789 Mem
.ReadByte(FColor
.R
);
5790 Mem
.ReadByte(FColor
.G
);
5791 Mem
.ReadByte(FColor
.B
);
5792 if Self
= gPlayer1
then
5794 str
:= gPlayer1Settings
.Model
;
5795 FColor
:= gPlayer1Settings
.Color
;
5797 if Self
= gPlayer2
then
5799 str
:= gPlayer2Settings
.Model
;
5800 FColor
:= gPlayer2Settings
.Color
;
5802 // Îáíîâëÿåì ìîäåëü èãðîêà:
5804 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
5805 FModel
.Color
:= TEAMCOLOR
[FTeam
]
5807 FModel
.Color
:= FColor
;
5810 procedure TPlayer
.AllRulez(Health
: Boolean);
5816 FHealth
:= PLAYER_HP_LIMIT
;
5817 FArmor
:= PLAYER_AP_LIMIT
;
5821 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
5822 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
5823 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5826 procedure TPlayer
.RestoreHealthArmor();
5828 FHealth
:= PLAYER_HP_LIMIT
;
5829 FArmor
:= PLAYER_AP_LIMIT
;
5832 procedure TPlayer
.FragCombo();
5836 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
5838 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
5840 if FFragCombo
< 5 then
5842 Param
:= FUID
or (FFragCombo
shl 16);
5843 if (FComboEvnt
>= Low(gDelayedEvents
)) and
5844 (FComboEvnt
<= High(gDelayedEvents
)) and
5845 gDelayedEvents
[FComboEvnt
].Pending
and
5846 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
5847 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
5849 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
5850 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
5853 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
5861 procedure TPlayer
.GiveItem(ItemType
: Byte);
5865 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
5867 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
5871 if FAir
< AIR_MAX
then
5878 if not (R_BERSERK
in FRulez
) then
5880 Include(FRulez
, R_BERSERK
);
5881 if FBFGFireCounter
< 1 then
5883 FCurrWeap
:= WEAPON_KASTET
;
5885 FModel
.SetWeapon(WEAPON_KASTET
);
5889 FBerserk
:= gTime
+30000;
5891 if FHealth
< PLAYER_HP_SOFT
then
5893 FHealth
:= PLAYER_HP_SOFT
;
5894 FBerserk
:= gTime
+30000;
5899 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
5901 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
5905 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
5907 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
5911 if FJetFuel
< JET_MAX
then
5913 FJetFuel
:= JET_MAX
;
5916 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
5917 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
5919 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
5920 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5922 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
5924 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
5926 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
5927 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5930 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
5931 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
5932 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
5933 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
5934 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
5935 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
5936 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
5937 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
5938 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
5940 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5941 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
5942 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5943 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
5944 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5945 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
5946 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5947 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
5948 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
5951 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
5952 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
5953 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
5954 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
5955 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
5957 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
5958 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
5959 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
5960 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
5961 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
5963 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5964 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5965 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5966 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5968 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
5971 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
5972 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
5973 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
5975 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
5976 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
5981 if g_Game_IsNet
and g_Game_IsServer
then
5982 MH_SEND_PlayerStats(FUID
);
5985 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
5990 if (Random(5) = 1) and (Times
= 1) then
5993 if BodyInLiquid(0, 0) then
5995 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
5996 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
5997 if Random(2) = 0 then
5998 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6000 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6004 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6006 for i
:= 1 to Times
do
6008 Anim
:= TAnimation
.Create(id
, False, 3);
6010 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6011 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6017 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6022 if (Random(10) = 1) and (Times
= 1) then
6025 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6027 for i
:= 1 to Times
do
6029 Anim
:= TAnimation
.Create(id
, False, 3);
6031 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6032 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6038 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6040 FSawSound
.Pause(Enable
);
6041 FSawSoundIdle
.Pause(Enable
);
6042 FSawSoundHit
.Pause(Enable
);
6043 FSawSoundSelect
.Pause(Enable
);
6048 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6053 FObj
.Rect
:= PLAYER_CORPSERECT
;
6054 FModelName
:= ModelName
;
6059 FState
:= CORPSE_STATE_MESS
;
6060 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6064 FState
:= CORPSE_STATE_NORMAL
;
6065 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6069 destructor TCorpse
.Destroy();
6076 procedure TCorpse
.positionChanged (); begin end;
6078 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6082 if FState
= CORPSE_STATE_REMOVEME
then
6085 FDamage
:= FDamage
+ Value
;
6087 if FDamage
> 150 then
6089 if FAnimation
<> nil then
6094 FState
:= CORPSE_STATE_REMOVEME
;
6096 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6097 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6098 FModelName
, FColor
);
6099 // Çâóê ìÿñà îò òðóïà:
6100 pm
:= g_PlayerModel_Get(FModelName
);
6101 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6107 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6108 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6109 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6110 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6111 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6116 procedure TCorpse
.Draw();
6118 if FState
= CORPSE_STATE_REMOVEME
then
6121 if FAnimation
<> nil then
6122 FAnimation
.Draw(FObj
.X
, FObj
.Y
, M_NONE
);
6124 if FAnimationMask
<> nil then
6127 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, M_NONE
);
6134 procedure TCorpse
.Update();
6138 if FState
= CORPSE_STATE_REMOVEME
then
6141 if gTime
mod (GAME_TICK
*2) <> 0 then
6143 g_Obj_Move(@FObj
, True, True, True);
6144 positionChanged(); // this updates spatial accelerators
6148 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6149 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6151 st
:= g_Obj_Move(@FObj
, True, True, True);
6152 positionChanged(); // this updates spatial accelerators
6154 if WordBool(st
and MOVE_FALLOUT
) then
6156 FState
:= CORPSE_STATE_REMOVEME
;
6160 if FAnimation
<> nil then
6161 FAnimation
.Update();
6162 if FAnimationMask
<> nil then
6163 FAnimationMask
.Update();
6166 procedure TCorpse
.SaveState(var Mem
: TBinMemoryWriter
);
6175 sig
:= CORPSE_SIGNATURE
; // 'CORP'
6176 Mem
.WriteDWORD(sig
);
6178 Mem
.WriteByte(FState
);
6179 // Íàêîïëåííûé óðîí:
6180 Mem
.WriteByte(FDamage
);
6182 Mem
.WriteByte(FColor
.R
);
6183 Mem
.WriteByte(FColor
.G
);
6184 Mem
.WriteByte(FColor
.B
);
6186 Obj_SaveState(@FObj
, Mem
);
6187 // Åñòü ëè àíèìàöèÿ:
6188 anim
:= FAnimation
<> nil;
6189 Mem
.WriteBoolean(anim
);
6190 // Åñëè åñòü - ñîõðàíÿåì:
6192 FAnimation
.SaveState(Mem
);
6193 // Åñòü ëè ìàñêà àíèìàöèè:
6194 anim
:= FAnimationMask
<> nil;
6195 Mem
.WriteBoolean(anim
);
6196 // Åñëè åñòü - ñîõðàíÿåì:
6198 FAnimationMask
.SaveState(Mem
);
6201 procedure TCorpse
.LoadState(var Mem
: TBinMemoryReader
);
6211 if sig
<> CORPSE_SIGNATURE
then // 'CORP'
6213 raise EBinSizeError
.Create('TCorpse.LoadState: Wrong Corpse Signature');
6216 Mem
.ReadByte(FState
);
6217 // Íàêîïëåííûé óðîí:
6218 Mem
.ReadByte(FDamage
);
6220 Mem
.ReadByte(FColor
.R
);
6221 Mem
.ReadByte(FColor
.G
);
6222 Mem
.ReadByte(FColor
.B
);
6224 Obj_LoadState(@FObj
, Mem
);
6225 // Åñòü ëè àíèìàöèÿ:
6226 Mem
.ReadBoolean(anim
);
6227 // Åñëè åñòü - çàãðóæàåì:
6230 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6231 FAnimation
.LoadState(Mem
);
6233 // Åñòü ëè ìàñêà àíèìàöèè:
6234 Mem
.ReadBoolean(anim
);
6235 // Åñëè åñòü - çàãðóæàåì:
6238 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6239 FAnimationMask
.LoadState(Mem
);
6245 constructor TBot
.Create();
6252 FSpectator
:= False;
6259 for a
:= WP_FIRST
to WP_LAST
do
6261 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6262 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6263 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6267 destructor TBot
.Destroy();
6270 inherited Destroy();
6273 procedure TBot
.Draw();
6277 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6278 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6281 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6283 inherited Respawn(Silent
, Force
);
6286 FSelectedWeapon
:= FCurrWeap
;
6291 procedure TBot
.UpdateCombat();
6304 TTargetRecord
= array of TTarget
;
6306 function Compare(a
, b
: TTarget
): Integer;
6308 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6311 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6313 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6314 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6316 if a
.Dist
> b
.Dist
then // B áëèæå
6318 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6321 else // Ñòðàííî -> A
6326 a
, x1
, y1
, x2
, y2
: Integer;
6327 targets
: TTargetRecord
;
6329 Target
, BestTarget
: TTarget
;
6330 firew
, fireh
: Integer;
6334 vsPlayer
, vsMonster
, ok
: Boolean;
6337 function monsUpdate (mon
: TMonster
): Boolean;
6339 result
:= false; // don't stop
6340 if mon
.Live
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6342 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6344 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6345 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6347 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6348 if g_TraceVector(x1
, y1
, x2
, y2
) then
6350 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6351 SetLength(targets
, Length(targets
)+1);
6352 with targets
[High(targets
)] do
6359 Rect
:= mon
.Obj
.Rect
;
6360 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6361 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6362 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6371 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6372 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6374 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6375 if FCurrWeap
<> FSelectedWeapon
then
6378 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6379 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6381 RemoveAIFlag('NEEDFIRE');
6384 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6385 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6386 else PressKey(KEY_FIRE
);
6390 // Êîîðäèíàòû ñòâîëà:
6391 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6392 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6394 Target
.UID
:= FTargetUID
;
6397 if Target
.UID
<> 0 then
6398 begin // Öåëü åñòü - íàñòðàèâàåì
6399 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6402 tpla
:= g_Player_Get(Target
.UID
);
6406 if (@FObj
) <> nil then
6413 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6414 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6415 Target
.Rect
:= PLAYER_RECT
;
6416 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6417 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6418 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6419 Target
.IsPlayer
:= True;
6423 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6426 mon
:= g_Monsters_ByUID(Target
.UID
);
6429 Target
.X
:= mon
.Obj
.X
;
6430 Target
.Y
:= mon
.Obj
.Y
;
6432 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6433 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6434 Target
.Rect
:= mon
.Obj
.Rect
;
6435 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6436 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6437 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6438 Target
.IsPlayer
:= False;
6445 begin // Öåëè íåò - îáíóëÿåì
6450 Target
.Visible
:= False;
6451 Target
.Line
:= False;
6452 Target
.IsPlayer
:= False;
6457 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6458 if (not Target
.Line
) or (not Target
.Visible
) then
6462 for a
:= 0 to High(gPlayers
) do
6463 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].Live
) and
6464 (gPlayers
[a
].FUID
<> FUID
) and
6465 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6466 (not gPlayers
[a
].NoTarget
) and
6467 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6469 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6470 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6473 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6474 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6476 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6477 if g_TraceVector(x1
, y1
, x2
, y2
) then
6479 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6480 SetLength(targets
, Length(targets
)+1);
6481 with targets
[High(targets
)] do
6483 UID
:= gPlayers
[a
].FUID
;
6484 X
:= gPlayers
[a
].FObj
.X
;
6485 Y
:= gPlayers
[a
].FObj
.Y
;
6488 Rect
:= PLAYER_RECT
;
6489 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6490 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6491 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6499 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6502 // Åñëè åñòü âîçìîæíûå öåëè:
6503 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6504 if targets
<> nil then
6506 // Âûáèðàåì íàèëó÷øóþ öåëü:
6507 BestTarget
:= targets
[0];
6508 if Length(targets
) > 1 then
6509 for a
:= 1 to High(targets
) do
6510 if Compare(BestTarget
, targets
[a
]) = 1 then
6511 BestTarget
:= targets
[a
];
6513 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6514 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6515 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6517 Target
:= BestTarget
;
6519 if (Healthy() = 3) or ((Healthy() = 2)) then
6520 begin // Åñëè çäîðîâû - äîãîíÿåì
6521 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6522 SetAIFlag('GORIGHT', '1');
6523 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6524 SetAIFlag('GOLEFT', '1');
6527 begin // Åñëè ïîáèòû - óáåãàåì
6528 if ((RunDirection() = D_LEFT
) and (Target
.X
< FObj
.X
)) then
6529 SetAIFlag('GORIGHT', '1');
6530 if ((RunDirection() = D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6531 SetAIFlag('GOLEFT', '1');
6534 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6535 SelectWeapon(Abs(x1
-Target
.cX
));
6540 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6541 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6542 if Target
.UID
<> 0 then
6544 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6545 Target
.Y
+ Target
.Rect
.Y
) then
6546 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6547 if (Healthy() = 3) or ((Healthy() = 2)) then
6548 begin // Åñëè çäîðîâû - äîãîíÿåì
6549 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6550 SetAIFlag('GORIGHT', '1');
6551 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6552 SetAIFlag('GOLEFT', '1');
6555 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6557 if ((RunDirection() = D_LEFT
) and (Target
.X
< FObj
.X
)) then
6558 SetAIFlag('GORIGHT', '1');
6559 if ((RunDirection() = D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6560 SetAIFlag('GOLEFT', '1');
6564 begin // Öåëü ïîêà íà "ýêðàíå"
6565 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6566 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6567 FLastVisible
:= gTime
;
6568 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6569 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6571 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6572 SetAIFlag('GORIGHT', '1');
6573 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6574 SetAIFlag('GOLEFT', '1');
6578 // Âûáèðàåì óãîë ââåðõ:
6579 if FDirection
= D_LEFT
then
6580 angle
:= ANGLE_LEFTUP
6582 angle
:= ANGLE_RIGHTUP
;
6584 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6585 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6587 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6588 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6589 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6590 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6591 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6592 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6593 begin // òî íóæíî ñòðåëÿòü ââåðõ
6594 SetAIFlag('NEEDFIRE', '1');
6595 SetAIFlag('NEEDSEEUP', '1');
6598 // Âûáèðàåì óãîë âíèç:
6599 if FDirection
= D_LEFT
then
6600 angle
:= ANGLE_LEFTDOWN
6602 angle
:= ANGLE_RIGHTDOWN
;
6604 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6605 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6607 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6608 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6609 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6610 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6611 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6612 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6613 begin // òî íóæíî ñòðåëÿòü âíèç
6614 SetAIFlag('NEEDFIRE', '1');
6615 SetAIFlag('NEEDSEEDOWN', '1');
6618 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6619 if Target
.Visible
and
6620 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6621 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6623 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6624 if ((FDirection
= D_LEFT
) and (Target
.X
< FObj
.X
)) or
6625 ((FDirection
= D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6626 begin // òî íóæíî ñòðåëÿòü âïåðåä
6627 SetAIFlag('NEEDFIRE', '1');
6628 SetAIFlag('NEEDSEEDOWN', '');
6629 SetAIFlag('NEEDSEEUP', '');
6631 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6632 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6633 if GetRnd(FDifficult
.CloseJump
) then
6634 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6635 if Abs(FObj
.X
-Target
.X
) < 128 then
6639 if Random(a
) = 0 then
6640 SetAIFlag('NEEDJUMP', '1');
6644 // Åñëè öåëü âñå åùå åñòü:
6645 if Target
.UID
<> 0 then
6646 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
6647 Target
.UID
:= 0 // òî çàáûòü öåëü
6648 else // Åñëè âèäåëè íåäàâíî
6649 begin // íî öåëü óáèëè
6650 if Target
.IsPlayer
then
6651 begin // Öåëü - èãðîê
6652 pla
:= g_Player_Get(Target
.UID
);
6653 if (pla
= nil) or (not pla
.Live
) or pla
.NoTarget
or
6654 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6655 Target
.UID
:= 0; // òî çàáûòü öåëü
6658 begin // Öåëü - ìîíñòð
6659 mon
:= g_Monsters_ByUID(Target
.UID
);
6660 if (mon
= nil) or (not mon
.Live
) then
6661 Target
.UID
:= 0; // òî çàáûòü öåëü
6664 end; // if Target.UID <> 0
6666 FTargetUID
:= Target
.UID
;
6668 // Åñëè âîçìîæíûõ öåëåé íåò:
6669 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
6670 if targets
= nil then
6671 if GetAIFlag('ATTACKLEFT') <> '' then
6672 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
6673 RemoveAIFlag('ATTACKLEFT');
6675 SetAIFlag('NEEDJUMP', '1');
6677 if RunDirection() = D_RIGHT
then
6678 begin // Èäåì íå â òó ñòîðîíó
6679 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6680 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
6681 SetAIFlag('NEEDFIRE', '1');
6682 SetAIFlag('GOLEFT', '1');
6686 begin // Èäåì â íóæíóþ ñòîðîíó
6687 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6688 SetAIFlag('NEEDFIRE', '1');
6689 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6690 SetAIFlag('GORIGHT', '1');
6694 if GetAIFlag('ATTACKRIGHT') <> '' then
6695 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
6696 RemoveAIFlag('ATTACKRIGHT');
6698 SetAIFlag('NEEDJUMP', '1');
6700 if RunDirection() = D_LEFT
then
6701 begin // Èäåì íå â òó ñòîðîíó
6702 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6703 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
6704 SetAIFlag('NEEDFIRE', '1');
6705 SetAIFlag('GORIGHT', '1');
6710 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6711 SetAIFlag('NEEDFIRE', '1');
6712 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6713 SetAIFlag('GOLEFT', '1');
6717 //HACK! (does it belongs there?)
6718 RealizeCurrentWeapon();
6720 // Åñëè åñòü âîçìîæíûå öåëè:
6721 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
6722 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6723 for a
:= 0 to High(targets
) do
6725 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
6726 if GetRnd(FDifficult
.DiagFire
) then
6728 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
6729 if FDirection
= D_LEFT
then
6730 angle
:= ANGLE_LEFTUP
6732 angle
:= ANGLE_RIGHTUP
;
6734 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6735 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6737 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6738 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6739 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6740 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6741 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6743 SetAIFlag('NEEDFIRE', '1');
6744 SetAIFlag('NEEDSEEUP', '1');
6747 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
6748 if FDirection
= D_LEFT
then
6749 angle
:= ANGLE_LEFTDOWN
6751 angle
:= ANGLE_RIGHTDOWN
;
6753 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6754 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6756 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6757 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6758 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6759 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6760 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6762 SetAIFlag('NEEDFIRE', '1');
6763 SetAIFlag('NEEDSEEDOWN', '1');
6767 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
6768 if targets
[a
].Line
and targets
[a
].Visible
and
6769 (((FDirection
= D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
6770 ((FDirection
= D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
6772 SetAIFlag('NEEDFIRE', '1');
6777 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
6778 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
6779 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
6780 40+GetInterval(FDifficult
.Cover
, 40)) then
6781 SetAIFlag('NEEDJUMP', '1');
6783 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
6784 ammo
:= GetAmmoByWeapon(FCurrWeap
);
6785 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
6786 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
6788 SetAIFlag('SELECTWEAPON', '1');
6790 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
6791 if GetAIFlag('SELECTWEAPON') = '1' then
6794 RemoveAIFlag('SELECTWEAPON');
6798 procedure TBot
.Update();
6811 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
6812 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
6814 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
6816 if g_debug_BotAIOff
= 3 then
6826 RealizeCurrentWeapon();
6833 procedure TBot
.ReleaseKey(Key
: Byte);
6842 function TBot
.KeyPressed(Key
: Word): Boolean;
6844 Result
:= FKeys
[Key
].Pressed
;
6847 function TBot
.GetAIFlag(aName
: String20
): String20
;
6853 aName
:= LowerCase(aName
);
6855 if FAIFlags
<> nil then
6856 for a
:= 0 to High(FAIFlags
) do
6857 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6859 Result
:= FAIFlags
[a
].Value
;
6864 procedure TBot
.RemoveAIFlag(aName
: String20
);
6868 if FAIFlags
= nil then Exit
;
6870 aName
:= LowerCase(aName
);
6872 for a
:= 0 to High(FAIFlags
) do
6873 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6875 if a
<> High(FAIFlags
) then
6876 for b
:= a
to High(FAIFlags
)-1 do
6877 FAIFlags
[b
] := FAIFlags
[b
+1];
6879 SetLength(FAIFlags
, Length(FAIFlags
)-1);
6884 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
6892 aName
:= LowerCase(aName
);
6894 if FAIFlags
<> nil then
6895 for a
:= 0 to High(FAIFlags
) do
6896 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6902 if ok
then FAIFlags
[a
].Value
:= fValue
6905 SetLength(FAIFlags
, Length(FAIFlags
)+1);
6906 with FAIFlags
[High(FAIFlags
)] do
6914 procedure TBot
.UpdateMove
;
6916 procedure GoLeft(Time
: Word = 1);
6918 ReleaseKey(KEY_LEFT
);
6919 ReleaseKey(KEY_RIGHT
);
6920 PressKey(KEY_LEFT
, Time
);
6921 SetDirection(D_LEFT
);
6924 procedure GoRight(Time
: Word = 1);
6926 ReleaseKey(KEY_LEFT
);
6927 ReleaseKey(KEY_RIGHT
);
6928 PressKey(KEY_RIGHT
, Time
);
6929 SetDirection(D_RIGHT
);
6932 function Rnd(a
: Word): Boolean;
6934 Result
:= Random(a
) = 0;
6937 procedure Turn(Time
: Word = 1200);
6939 if RunDirection() = D_LEFT
then GoRight(Time
) else GoLeft(Time
);
6944 ReleaseKey(KEY_LEFT
);
6945 ReleaseKey(KEY_RIGHT
);
6948 function CanRunLeft(): Boolean;
6950 Result
:= not CollideLevel(-1, 0);
6953 function CanRunRight(): Boolean;
6955 Result
:= not CollideLevel(1, 0);
6958 function CanRun(): Boolean;
6960 if RunDirection() = D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
6963 procedure Jump(Time
: Word = 30);
6965 PressKey(KEY_JUMP
, Time
);
6968 function NearHole(): Boolean;
6972 { TODO 5 : Ëåñòíèöû }
6973 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6974 for x
:= 1 to PLAYER_RECT
.Width
do
6975 if (not StayOnStep(x
*sx
, 0)) and
6976 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6977 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6986 function BorderHole(): Boolean;
6990 { TODO 5 : Ëåñòíèöû }
6991 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6992 for x
:= 1 to PLAYER_RECT
.Width
do
6993 if (not StayOnStep(x
*sx
, 0)) and
6994 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6995 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6997 for xx
:= x
to x
+32 do
6998 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7008 function NearDeepHole(): Boolean;
7014 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
7017 for x
:= 1 to PLAYER_RECT
.Width
do
7018 if (not StayOnStep(x
*sx
, 0)) and
7019 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7020 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7022 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7024 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7029 end else Result
:= False;
7032 function OverDeepHole(): Boolean;
7039 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7041 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7048 function OnGround(): Boolean;
7050 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7053 function OnLadder(): Boolean;
7055 Result
:= FullInStep(0, 0);
7058 function BelowLadder(): Boolean;
7060 Result
:= (FullInStep(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7061 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7062 (FullInStep(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7063 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7066 function BelowLiftUp(): Boolean;
7068 Result
:= ((FullInLift(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7069 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7070 ((FullInLift(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7071 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7074 function OnTopLift(): Boolean;
7076 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7079 function CanJumpOver(): Boolean;
7083 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
7087 if not CollideLevel(sx
, 0) then Exit
;
7089 for y
:= 1 to BOT_MAXJUMP
do
7090 if CollideLevel(0, -y
) then Exit
else
7091 if not CollideLevel(sx
, -y
) then
7098 function CanJumpUp(Dist
: ShortInt): Boolean;
7105 if CollideLevel(Dist
, 0) then Exit
;
7108 for y
:= 0 to BOT_MAXJUMP
do
7109 if CollideLevel(Dist
, -y
) then
7118 for yy
:= y
+1 to BOT_MAXJUMP
do
7119 if not CollideLevel(Dist
, -yy
) then
7128 for y
:= 0 to BOT_MAXJUMP
do
7129 if CollideLevel(0, -y
) then
7137 if y
< yy
then Exit
;
7142 function IsSafeTrigger(): Boolean;
7147 if gTriggers
= nil then
7149 for a
:= 0 to High(gTriggers
) do
7150 if Collide(gTriggers
[a
].X
,
7153 gTriggers
[a
].Height
) and
7154 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7155 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7156 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7157 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7158 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7163 // Âîçìîæíî, íàæèìàåì êíîïêó:
7164 if Rnd(16) and IsSafeTrigger() then
7167 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7168 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7170 ReleaseKey(KEY_LEFT
);
7171 ReleaseKey(KEY_RIGHT
);
7175 // Èäåì âëåâî, åñëè íàäî áûëî:
7176 if GetAIFlag('GOLEFT') <> '' then
7178 RemoveAIFlag('GOLEFT');
7179 if CanRunLeft() then
7183 // Èäåì âïðàâî, åñëè íàäî áûëî:
7184 if GetAIFlag('GORIGHT') <> '' then
7186 RemoveAIFlag('GORIGHT');
7187 if CanRunRight() then
7191 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7192 if FObj
.X
< -32 then
7195 if FObj
.X
+32 > gMapInfo
.Width
then
7198 // Ïðûãàåì, åñëè íàäî áûëî:
7199 if GetAIFlag('NEEDJUMP') <> '' then
7202 RemoveAIFlag('NEEDJUMP');
7205 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7206 if GetAIFlag('NEEDSEEUP') <> '' then
7209 ReleaseKey(KEY_DOWN
);
7210 PressKey(KEY_UP
, 20);
7211 RemoveAIFlag('NEEDSEEUP');
7214 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7215 if GetAIFlag('NEEDSEEDOWN') <> '' then
7218 ReleaseKey(KEY_DOWN
);
7219 PressKey(KEY_DOWN
, 20);
7220 RemoveAIFlag('NEEDSEEDOWN');
7223 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7224 if GetAIFlag('GOINHOLE') <> '' then
7225 if not OnGround() then
7227 ReleaseKey(KEY_LEFT
);
7228 ReleaseKey(KEY_RIGHT
);
7229 RemoveAIFlag('GOINHOLE');
7230 SetAIFlag('FALLINHOLE', '1');
7233 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7234 if GetAIFlag('FALLINHOLE') <> '' then
7236 RemoveAIFlag('FALLINHOLE');
7238 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7239 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7240 if GetAIFlag('FALLINHOLE') = '' then
7241 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7247 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7249 CanJumpUp(IfThen(RunDirection() = D_LEFT
, -1, 1)*32) and
7253 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7254 if OnGround() and NearHole() then
7255 if NearDeepHole() then // Åñëè ýòî áåçäíà
7257 0..3: Turn(); // Áåæèì îáðàòíî
7258 4: Jump(); // Ïðûãàåì
7259 5: begin // Ïðûãàåì îáðàòíî
7264 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7265 if GetAIFlag('GOINHOLE') = '' then
7267 0: Turn(); // Íå íóæíî òóäà
7268 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7269 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7270 if BorderHole() then
7271 SetAIFlag('GOINHOLE', '1');
7274 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7275 if (not CanRun()) and OnGround() then
7277 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7278 if CanJumpOver() or OnLadder() then
7280 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7281 if Random(2) = 0 then
7283 if IsSafeTrigger() then
7289 // Îñòàëîñü ìàëî âîçäóõà:
7290 if FAir
< 36 * 2 then
7293 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7294 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7295 if BodyInAcid(0, 0) then
7299 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7301 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7302 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7305 {function TBot.NeedItem(Item: Byte): Byte;
7310 procedure TBot
.SelectWeapon(Dist
: Integer);
7314 function HaveAmmo(weapon
: Byte): Boolean;
7317 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7318 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7319 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7320 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7321 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7322 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7323 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7324 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7325 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7326 else Result
:= True;
7331 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7333 if Dist
> BOT_LONGDIST
then
7334 begin // Äàëüíèé áîé
7336 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7338 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7342 else //if Dist > BOT_UNSAFEDIST then
7343 begin // Áëèæíèé áîé
7345 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7347 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7354 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7356 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7362 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7364 Result
:= inherited PickItem(ItemType
, force
, remove
);
7366 if Result
then SetAIFlag('SELECTWEAPON', '1');
7369 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7371 Result
:= inherited Heal(value
, Soft
);
7374 function TBot
.Healthy(): Byte;
7376 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7377 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7378 else if (FHealth
> 50) then Result
:= 2
7379 else if (FHealth
> 20) then Result
:= 1
7383 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7385 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7386 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7389 procedure TBot
.OnDamage(Angle
: SmallInt);
7397 if (Angle
= 0) or (Angle
= 180) then
7400 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7401 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7403 pla
:= g_Player_Get(FLastSpawnerUID
);
7404 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7405 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7408 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7409 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7411 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7412 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7413 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7418 SetAIFlag('ATTACKLEFT', '1')
7420 SetAIFlag('ATTACKRIGHT', '1');
7424 function TBot
.RunDirection(): TDirection
;
7426 if Abs(Vel
.X
) >= 1 then
7428 if Vel
.X
> 0 then Result
:= D_RIGHT
else Result
:= D_LEFT
;
7430 Result
:= FDirection
;
7433 function TBot
.GetRnd(a
: Byte): Boolean;
7435 if a
= 0 then Result
:= False
7436 else if a
= 255 then Result
:= True
7437 else Result
:= Random(256) > 255-a
;
7440 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7442 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7445 procedure TBot
.SaveState(var Mem
: TBinMemoryWriter
);
7451 inherited SaveState(Mem
);
7453 // Âûáðàííîå îðóæèå:
7454 Mem
.WriteByte(FSelectedWeapon
);
7456 Mem
.WriteWord(FTargetUID
);
7457 // Âðåìÿ ïîòåðè öåëè:
7458 Mem
.WriteDWORD(FLastVisible
);
7459 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7460 dw
:= Length(FAIFlags
);
7463 for i
:= 0 to Integer(dw
)-1 do
7465 Mem
.WriteString(FAIFlags
[i
].Name
, 20);
7466 Mem
.WriteString(FAIFlags
[i
].Value
, 20);
7468 // Íàñòðîéêè ñëîæíîñòè:
7470 Mem
.WriteMemory(p
, SizeOf(TDifficult
));
7473 procedure TBot
.LoadState(var Mem
: TBinMemoryReader
);
7479 inherited LoadState(Mem
);
7481 // Âûáðàííîå îðóæèå:
7482 Mem
.ReadByte(FSelectedWeapon
);
7484 Mem
.ReadWord(FTargetUID
);
7485 // Âðåìÿ ïîòåðè öåëè:
7486 Mem
.ReadDWORD(FLastVisible
);
7487 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7489 SetLength(FAIFlags
, dw
);
7491 for i
:= 0 to Integer(dw
)-1 do
7493 Mem
.ReadString(FAIFlags
[i
].Name
);
7494 Mem
.ReadString(FAIFlags
[i
].Value
);
7496 // Íàñòðîéêè ñëîæíîñòè:
7497 Mem
.ReadMemory(p
, dw
);
7498 if dw
<> SizeOf(TDifficult
) then
7500 raise EBinSizeError
.Create('TBot.LoadState: Wrong FDifficult Size');
7502 FDifficult
:= TDifficult(p
^);