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
,
24 BinEditor
, g_panel
, z_aabbtree
;
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;
225 function getMapAABB (): AABB2D
;
228 FDamageBuffer
: Integer;
230 FAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
231 FMaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
232 FWeapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
233 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
235 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
236 FReloading
: Array [WP_FIRST
..WP_LAST
] of Word;
237 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
238 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
240 FPreferredTeam
: Byte;
243 FWantsInGame
: Boolean;
247 FActualModelName
: string;
254 constructor Create(); virtual;
255 destructor Destroy(); override;
256 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
257 function GetRespawnPoint(): Byte;
258 procedure PressKey(Key
: Byte; Time
: Word = 1);
259 procedure ReleaseKeys();
260 procedure SetModel(ModelName
: String);
261 procedure SetColor(Color
: TRGB
);
262 procedure SetWeapon(W
: Byte);
263 function IsKeyPressed(K
: Byte): Boolean;
264 function GetKeys(): Byte;
265 function PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean; virtual;
266 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
267 function Collide(Panel
: TPanel
): Boolean; overload
;
268 function Collide(X
, Y
: Integer): Boolean; overload
;
269 procedure SetDirection(Direction
: TDirection
);
270 procedure GetSecret();
271 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
273 procedure Push(vx
, vy
: Integer);
274 procedure ChangeModel(ModelName
: String);
275 procedure SwitchTeam
;
276 procedure ChangeTeam(Team
: Byte);
278 function GetFlag(Flag
: Byte): Boolean;
279 procedure SetFlag(Flag
: Byte);
280 function DropFlag(): Boolean;
281 procedure AllRulez(Health
: Boolean);
282 procedure RestoreHealthArmor();
283 procedure FragCombo();
284 procedure GiveItem(ItemType
: Byte);
285 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
286 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
287 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
288 procedure MakeBloodSimple(Count
: Word);
289 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
290 procedure Reset(Force
: Boolean);
291 procedure Spectate(NoMove
: Boolean = False);
292 procedure SwitchNoClip
;
293 procedure SoftReset();
294 procedure Draw(); virtual;
295 procedure DrawPain();
296 procedure DrawPickup();
297 procedure DrawRulez();
299 procedure DrawBubble();
301 procedure Update(); virtual;
302 procedure RememberState();
303 procedure RecallState();
304 procedure SaveState(var Mem
: TBinMemoryWriter
); virtual;
305 procedure LoadState(var Mem
: TBinMemoryReader
); virtual;
306 procedure PauseSounds(Enable
: Boolean);
307 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
308 procedure DoLerp(Level
: Integer = 2);
309 procedure SetLerp(XTo
, YTo
: Integer);
310 procedure QueueWeaponSwitch(Weapon
: Byte);
311 procedure RealizeCurrentWeapon();
313 procedure JetpackOff
;
314 procedure CatchFire(Attacker
: Word);
316 //WARNING! this does nothing for now, but still call it!
317 procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right!
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
;
352 property mapAABB
: AABB2D read getMapAABB
;
362 WeaponPrior
: Array [WP_FIRST
..WP_LAST
] of Byte;
363 CloseWeaponPrior
: Array [WP_FIRST
..WP_LAST
] of Byte;
364 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
372 TBot
= class (TPlayer
)
374 FSelectedWeapon
: Byte;
377 FAIFlags
: Array of TAIFlag
;
378 FDifficult
: TDifficult
;
380 function GetRnd(a
: Byte): Boolean;
381 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
382 function RunDirection(): TDirection
;
383 function FullInStep(XInc
, YInc
: Integer): Boolean;
384 //function NeedItem(Item: Byte): Byte;
385 procedure SelectWeapon(Dist
: Integer);
386 procedure SetAIFlag(aName
, fValue
: String20
);
387 function GetAIFlag(aName
: String20
): String20
;
388 procedure RemoveAIFlag(aName
: String20
);
389 function Healthy(): Byte;
390 procedure UpdateMove();
391 procedure UpdateCombat();
392 function KeyPressed(Key
: Word): Boolean;
393 procedure ReleaseKey(Key
: Byte);
394 function TargetOnScreen(TX
, TY
: Integer): Boolean;
395 procedure OnDamage(Angle
: SmallInt); override;
398 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
399 constructor Create(); override;
400 destructor Destroy(); override;
401 procedure Draw(); override;
402 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
403 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
404 procedure Update(); override;
405 procedure SaveState(var Mem
: TBinMemoryWriter
); override;
406 procedure LoadState(var Mem
: TBinMemoryReader
); override;
417 procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right!
430 procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right!
433 TCorpse
= class (TObject
)
441 FAnimation
: TAnimation
;
442 FAnimationMask
: TAnimation
;
445 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
446 destructor Destroy(); override;
447 procedure Damage(Value
: Word; vx
, vy
: Integer);
450 procedure SaveState(var Mem
: TBinMemoryWriter
);
451 procedure LoadState(var Mem
: TBinMemoryReader
);
453 procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right!
455 property Obj
: TObj read FObj
;
456 property State
: Byte read FState
;
457 property Mess
: Boolean read FMess
;
460 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
466 gPlayers
: Array of TPlayer
;
467 gCorpses
: Array of TCorpse
;
468 gGibs
: Array of TGib
;
469 gShells
: Array of TShell
;
470 gTeamStat
: TTeamStat
;
471 gFly
: Boolean = False;
472 gAimLine
: Boolean = False;
473 gChatBubble
: Byte = 0;
477 MAX_RUNVEL
: Integer = 8;
478 VEL_JUMP
: Integer = 10;
479 SHELL_TIMEOUT
: Cardinal = 60000;
481 function Lerp(X
, Y
, Factor
: Integer): Integer;
483 procedure g_Gibs_SetMax(Count
: Word);
484 function g_Gibs_GetMax(): Word;
485 procedure g_Corpses_SetMax(Count
: Word);
486 function g_Corpses_GetMax(): Word;
487 procedure g_Shells_SetMax(Count
: Word);
488 function g_Shells_GetMax(): Word;
490 procedure g_Player_Init();
491 procedure g_Player_Free();
492 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
493 function g_Player_CreateFromState(var Mem
: TBinMemoryReader
): Word;
494 procedure g_Player_Remove(UID
: Word);
495 procedure g_Player_ResetTeams();
496 procedure g_Player_UpdateAll();
497 procedure g_Player_DrawAll();
498 procedure g_Player_DrawDebug(p
: TPlayer
);
499 procedure g_Player_DrawHealth();
500 procedure g_Player_RememberAll();
501 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
502 function g_Player_Get(UID
: Word): TPlayer
;
503 function g_Player_GetCount(): Byte;
504 function g_Player_GetStats(): TPlayerStatArray
;
505 function g_Player_ValidName(Name
: String): Boolean;
506 procedure g_Player_CreateCorpse(Player
: TPlayer
);
507 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
508 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
509 procedure g_Player_UpdatePhysicalObjects();
510 procedure g_Player_DrawCorpses();
511 procedure g_Player_DrawShells();
512 procedure g_Player_RemoveAllCorpses();
513 procedure g_Player_Corpses_SaveState(var Mem
: TBinMemoryWriter
);
514 procedure g_Player_Corpses_LoadState(var Mem
: TBinMemoryReader
);
515 procedure g_Bot_Add(Team
, Difficult
: Byte);
516 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1);
517 procedure g_Bot_MixNames();
518 procedure g_Bot_RemoveAll();
523 e_log
, g_map
, g_items
, g_console
, SysUtils
, g_gfx
, Math
,
524 g_options
, g_triggers
, g_menu
, MAPDEF
, g_game
,
525 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
, g_net
, g_netmsg
;
535 diag_precision
: Byte;
539 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
540 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
541 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
545 TIME_RESPAWN1
= 1500;
546 TIME_RESPAWN2
= 2000;
547 TIME_RESPAWN3
= 3000;
550 JET_MAX
= 540; // ~30 sec
551 PLAYER_SUIT_TIME
= 30000;
552 PLAYER_INVUL_TIME
= 30000;
553 PLAYER_INVIS_TIME
= 35000;
554 FRAG_COMBO_TIME
= 3000;
558 ANGLE_RIGHTDOWN
= -35;
560 ANGLE_LEFTDOWN
= -145;
561 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
562 WEAPONPOINT
: Array [TDirection
] of TPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
565 BOT_UNSAFEDIST
= 128;
566 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
568 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
569 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
570 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
571 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
572 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
573 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
574 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
575 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
576 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
577 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
578 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
579 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
580 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
581 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
582 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
583 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
584 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
585 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
586 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
587 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
588 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
589 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
590 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
591 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
592 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
593 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
595 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
596 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
598 BOTNAMES_FILENAME
= 'botnames.txt';
599 BOTLIST_FILENAME
= 'botlist.txt';
603 MaxCorpses
: Word = 20;
604 MaxShells
: Word = 300;
605 CurrentGib
: Integer = 0;
606 CurrentShell
: Integer = 0;
607 BotNames
: Array of String;
608 BotList
: Array of TBotProfile
;
611 procedure TGib
.positionChanged (); begin end;
612 procedure TShell
.positionChanged (); begin end;
615 function Lerp(X
, Y
, Factor
: Integer): Integer;
617 Result
:= X
+ ((Y
- X
) div Factor
);
620 function SameTeam(UID1
, UID2
: Word): Boolean;
624 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
625 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
627 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
629 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
630 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
632 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
635 procedure g_Gibs_SetMax(Count
: Word);
638 SetLength(gGibs
, Count
);
640 if CurrentGib
>= Count
then
644 function g_Gibs_GetMax(): Word;
649 procedure g_Shells_SetMax(Count
: Word);
652 SetLength(gShells
, Count
);
654 if CurrentShell
>= Count
then
658 function g_Shells_GetMax(): Word;
664 procedure g_Corpses_SetMax(Count
: Word);
667 SetLength(gCorpses
, Count
);
670 function g_Corpses_GetMax(): Word;
672 Result
:= MaxCorpses
;
675 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
685 // Åñòü ëè ìåñòî â gPlayers:
686 if gPlayers
<> nil then
687 for a
:= 0 to High(gPlayers
) do
688 if gPlayers
[a
] = nil then
694 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
697 SetLength(gPlayers
, Length(gPlayers
)+1);
701 // Ñîçäàåì îáúåêò èãðîêà:
703 gPlayers
[a
] := TBot
.Create()
705 gPlayers
[a
] := TPlayer
.Create();
708 gPlayers
[a
].FActualModelName
:= ModelName
;
709 gPlayers
[a
].SetModel(ModelName
);
711 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
712 if gPlayers
[a
].FModel
= nil then
716 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
720 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
721 if Random(2) = 0 then
725 gPlayers
[a
].FPreferredTeam
:= Team
;
727 case gGameSettings
.GameMode
of
728 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
730 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
732 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
735 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
736 gPlayers
[a
].FColor
:= Color
;
737 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
738 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
740 gPlayers
[a
].FModel
.Color
:= Color
;
742 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
743 gPlayers
[a
].FLive
:= False;
745 Result
:= gPlayers
[a
].FUID
;
748 function g_Player_CreateFromState(var Mem
: TBinMemoryReader
): Word;
761 if sig
<> PLAYER_SIGNATURE
then // 'PLYR'
763 raise EBinSizeError
.Create('g_Player_CreateFromState: Wrong Player Signature');
767 Mem
.ReadBoolean(Bot
);
772 // Åñòü ëè ìåñòî â gPlayers:
773 if gPlayers
<> nil then
774 for a
:= 0 to High(gPlayers
) do
775 if gPlayers
[a
] = nil then
781 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
784 SetLength(gPlayers
, Length(gPlayers
)+1);
788 // Ñîçäàåì îáúåêò èãðîêà:
790 gPlayers
[a
] := TBot
.Create()
792 gPlayers
[a
] := TPlayer
.Create();
793 gPlayers
[a
].FIamBot
:= Bot
;
794 gPlayers
[a
].FPhysics
:= True;
797 Mem
.ReadWord(gPlayers
[a
].FUID
);
799 Mem
.ReadString(gPlayers
[a
].FName
);
801 Mem
.ReadByte(gPlayers
[a
].FTeam
);
802 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
804 Mem
.ReadBoolean(gPlayers
[a
].FLive
);
805 // Èçðàñõîäîâàë ëè âñå æèçíè:
806 Mem
.ReadBoolean(gPlayers
[a
].FNoRespawn
);
810 gPlayers
[a
].FDirection
:= D_LEFT
812 gPlayers
[a
].FDirection
:= D_RIGHT
;
814 Mem
.ReadInt(gPlayers
[a
].FHealth
);
816 Mem
.ReadByte(gPlayers
[a
].FLives
);
818 Mem
.ReadInt(gPlayers
[a
].FArmor
);
820 Mem
.ReadInt(gPlayers
[a
].FAir
);
822 Mem
.ReadInt(gPlayers
[a
].FJetFuel
);
824 Mem
.ReadInt(gPlayers
[a
].FPain
);
826 Mem
.ReadInt(gPlayers
[a
].FKills
);
828 Mem
.ReadInt(gPlayers
[a
].FMonsterKills
);
830 Mem
.ReadInt(gPlayers
[a
].FFrags
);
832 Mem
.ReadByte(gPlayers
[a
].FFragCombo
);
833 // Âðåìÿ ïîñëåäíåãî ôðàãà:
834 Mem
.ReadDWORD(gPlayers
[a
].FLastFrag
);
836 Mem
.ReadInt(gPlayers
[a
].FDeath
);
838 Mem
.ReadByte(gPlayers
[a
].FFlag
);
840 Mem
.ReadInt(gPlayers
[a
].FSecrets
);
842 Mem
.ReadByte(gPlayers
[a
].FCurrWeap
);
843 // Ñëåäóþùåå æåëàåìîå îðóæèå:
844 Mem
.ReadWord(gPlayers
[a
].FNextWeap
);
846 Mem
.ReadByte(gPlayers
[a
].FNextWeapDelay
);
847 // Âðåìÿ çàðÿäêè BFG:
848 Mem
.ReadSmallInt(gPlayers
[a
].FBFGFireCounter
);
850 Mem
.ReadInt(gPlayers
[a
].FDamageBuffer
);
851 // Ïîñëåäíèé óäàðèâøèé:
852 Mem
.ReadWord(gPlayers
[a
].FLastSpawnerUID
);
853 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
854 Mem
.ReadByte(gPlayers
[a
].FLastHit
);
856 Obj_LoadState(@gPlayers
[a
].FObj
, Mem
);
857 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
858 for i
:= A_BULLETS
to A_HIGH
do
859 Mem
.ReadWord(gPlayers
[a
].FAmmo
[i
]);
860 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
861 for i
:= A_BULLETS
to A_HIGH
do
862 Mem
.ReadWord(gPlayers
[a
].FMaxAmmo
[i
]);
864 for i
:= WP_FIRST
to WP_LAST
do
865 Mem
.ReadBoolean(gPlayers
[a
].FWeapon
[i
]);
866 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
867 for i
:= WP_FIRST
to WP_LAST
do
868 Mem
.ReadWord(gPlayers
[a
].FReloading
[i
]);
872 Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
873 // Íàëè÷èå êðàñíîãî êëþ÷à:
876 Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
877 // Íàëè÷èå çåëåíîãî êëþ÷à:
880 Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
881 // Íàëè÷èå ñèíåãî êëþ÷à:
884 Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
888 Include(gPlayers
[a
].FRulez
, R_BERSERK
);
889 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
890 for i
:= MR_SUIT
to MR_MAX
do
891 Mem
.ReadDWORD(gPlayers
[a
].FMegaRulez
[i
]);
892 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
893 for i
:= T_RESPAWN
to T_FLAGCAP
do
894 Mem
.ReadDWORD(gPlayers
[a
].FTime
[i
]);
897 Mem
.ReadString(gPlayers
[a
].FActualModelName
);
899 Mem
.ReadByte(gPlayers
[a
].FColor
.R
);
900 Mem
.ReadByte(gPlayers
[a
].FColor
.G
);
901 Mem
.ReadByte(gPlayers
[a
].FColor
.B
);
902 // Îáíîâëÿåì ìîäåëü èãðîêà:
903 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
905 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
906 if gPlayers
[a
].FModel
= nil then
910 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
914 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
915 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
916 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
918 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
920 Result
:= gPlayers
[a
].FUID
;
923 procedure g_Player_ResetTeams();
927 if g_Game_IsClient
then
929 if gPlayers
= nil then
931 for a
:= Low(gPlayers
) to High(gPlayers
) do
932 if gPlayers
[a
] <> nil then
933 case gGameSettings
.GameMode
of
935 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
937 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
938 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
939 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
942 gPlayers
[a
].ChangeTeam(TEAM_RED
)
944 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
947 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
951 procedure g_Bot_Add(Team
, Difficult
: Byte);
954 _name
, _model
: String;
957 if not g_Game_IsServer
then Exit
;
959 // Ñïèñîê íàçâàíèé ìîäåëåé:
960 m
:= g_PlayerModel_GetNames();
965 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
966 Team
:= TEAM_COOP
// COOP
968 if gGameSettings
.GameMode
= GM_DM
then
969 Team
:= TEAM_NONE
// DM
971 if Team
= TEAM_NONE
then // CTF / TDM
973 // Àâòîáàëàíñ êîìàíä:
977 for a
:= 0 to High(gPlayers
) do
978 if gPlayers
[a
] <> nil then
980 if gPlayers
[a
].Team
= TEAM_RED
then
983 if gPlayers
[a
].Team
= TEAM_BLUE
then
993 if Random(2) = 0 then
999 // Âûáèðàåì áîòó èìÿ:
1001 if BotNames
<> nil then
1002 for a
:= 0 to High(BotNames
) do
1003 if g_Player_ValidName(BotNames
[a
]) then
1005 _name
:= BotNames
[a
];
1009 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
1012 _name
:= Format('DFBOT%.2d', [Random(100)]);
1013 until g_Player_ValidName(_name
);
1015 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1016 _model
:= m
[Random(Length(m
))];
1019 with g_Player_Get(g_Player_Create(_model
,
1020 _RGB(Min(Random(9)*32, 255),
1021 Min(Random(9)*32, 255),
1022 Min(Random(9)*32, 255)),
1023 Team
, True)) as TBot
do
1028 1: FDifficult
:= DIFFICULT_EASY
;
1029 2: FDifficult
:= DIFFICULT_MEDIUM
;
1030 else FDifficult
:= DIFFICULT_HARD
;
1033 for a
:= WP_FIRST
to WP_LAST
do
1035 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1036 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1037 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1040 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1042 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1043 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1048 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1);
1051 _name
, _model
: String;
1054 if not g_Game_IsServer
then Exit
;
1056 // Ñïèñîê íàçâàíèé ìîäåëåé:
1057 m
:= g_PlayerModel_GetNames();
1062 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1063 Team
:= TEAM_COOP
// COOP
1065 if gGameSettings
.GameMode
= GM_DM
then
1066 Team
:= TEAM_NONE
// DM
1068 if Team
= TEAM_NONE
then
1069 Team
:= BotList
[num
].team
; // CTF / TDM
1071 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1072 lName
:= AnsiLowerCase(lName
);
1073 if (num
< 0) or (num
> Length(BotList
)-1) then
1075 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1076 for a
:= 0 to High(BotList
) do
1077 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1086 _name
:= BotList
[num
].name
;
1087 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1088 if not g_Player_ValidName(_name
) then
1090 _name
:= Format('DFBOT%.2d', [Random(100)]);
1091 until g_Player_ValidName(_name
);
1094 _model
:= BotList
[num
].model
;
1095 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1096 if not InSArray(_model
, m
) then
1097 _model
:= m
[Random(Length(m
))];
1100 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1104 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1105 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1106 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1107 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1108 FDifficult
.Cover
:= BotList
[num
].cover
;
1109 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1111 for a
:= WP_FIRST
to WP_LAST
do
1113 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1114 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1115 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1118 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1120 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1124 procedure g_Bot_RemoveAll();
1128 if not g_Game_IsServer
then Exit
;
1129 if gPlayers
= nil then Exit
;
1131 for a
:= 0 to High(gPlayers
) do
1132 if gPlayers
[a
] <> nil then
1133 if gPlayers
[a
] is TBot
then
1135 gPlayers
[a
].Lives
:= 0;
1136 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1137 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1138 g_Player_Remove(gPlayers
[a
].FUID
);
1144 procedure g_Bot_MixNames();
1149 if BotNames
<> nil then
1150 for a
:= 0 to High(BotNames
) do
1152 b
:= Random(Length(BotNames
));
1154 Botnames
[a
] := BotNames
[b
];
1159 procedure g_Player_Remove(UID
: Word);
1163 if gPlayers
= nil then Exit
;
1165 if g_Game_IsServer
and g_Game_IsNet
then
1166 MH_SEND_PlayerDelete(UID
);
1168 for i
:= 0 to High(gPlayers
) do
1169 if gPlayers
[i
] <> nil then
1170 if gPlayers
[i
].FUID
= UID
then
1172 if gPlayers
[i
] is TPlayer
then
1173 TPlayer(gPlayers
[i
]).Free()
1175 TBot(gPlayers
[i
]).Free();
1181 procedure g_Player_Init();
1191 if not FileExists(DataDir
+ BOTNAMES_FILENAME
) then
1194 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1195 AssignFile(F
, DataDir
+ BOTNAMES_FILENAME
);
1206 SetLength(BotNames
, Length(BotNames
)+1);
1207 BotNames
[High(BotNames
)] := s
;
1215 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1216 config
:= TConfig
.CreateFile(DataDir
+ BOTLIST_FILENAME
);
1220 while config
.SectionExists(IntToStr(a
)) do
1222 SetLength(BotList
, Length(BotList
)+1);
1224 with BotList
[High(BotList
)] do
1227 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1229 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1231 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1236 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1237 color
.R
:= StrToIntDef(sa
[0], 0);
1238 color
.G
:= StrToIntDef(sa
[1], 0);
1239 color
.B
:= StrToIntDef(sa
[2], 0);
1240 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1241 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1242 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1243 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1244 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1245 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1246 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1247 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1248 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1249 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1250 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1251 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1252 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1253 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1254 if Length(sa
) = 10 then
1256 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1257 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1258 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1259 if Length(sa
) = 10 then
1261 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1263 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1264 if Length(sa) = 10 then
1266 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1275 procedure g_Player_Free();
1279 if gPlayers
<> nil then
1281 for i
:= 0 to High(gPlayers
) do
1282 if gPlayers
[i
] <> nil then
1284 if gPlayers
[i
] is TPlayer
then
1285 TPlayer(gPlayers
[i
]).Free()
1287 TBot(gPlayers
[i
]).Free();
1298 procedure g_Player_UpdateAll();
1302 if gPlayers
= nil then Exit
;
1304 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1305 for i
:= 0 to High(gPlayers
) do
1307 if gPlayers
[i
] <> nil then
1309 if gPlayers
[i
] is TPlayer
then
1311 gPlayers
[i
].Update();
1312 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1316 // bot updates weapons in `UpdateCombat()`
1317 TBot(gPlayers
[i
]).Update();
1321 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1324 procedure g_Player_DrawAll();
1328 if gPlayers
= nil then Exit
;
1330 for i
:= 0 to High(gPlayers
) do
1331 if gPlayers
[i
] <> nil then
1332 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1333 else TBot(gPlayers
[i
]).Draw();
1336 procedure g_Player_DrawDebug(p
: TPlayer
);
1340 if p
= nil then Exit
;
1341 if (@p
.FObj
) = nil then Exit
;
1343 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1345 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1346 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1347 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1348 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1349 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1350 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1353 procedure g_Player_DrawHealth();
1358 if gPlayers
= nil then Exit
;
1359 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1361 for i
:= 0 to High(gPlayers
) do
1362 if gPlayers
[i
] <> nil then
1364 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1365 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1366 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1367 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1368 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1369 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1373 function g_Player_Get(UID
: Word): TPlayer
;
1379 if gPlayers
= nil then
1382 for a
:= 0 to High(gPlayers
) do
1383 if gPlayers
[a
] <> nil then
1384 if gPlayers
[a
].FUID
= UID
then
1386 Result
:= gPlayers
[a
];
1391 function g_Player_GetCount(): Byte;
1397 if gPlayers
= nil then
1400 for a
:= 0 to High(gPlayers
) do
1401 if gPlayers
[a
] <> nil then
1402 Result
:= Result
+ 1;
1405 function g_Player_GetStats(): TPlayerStatArray
;
1411 if gPlayers
= nil then Exit
;
1413 for a
:= 0 to High(gPlayers
) do
1414 if gPlayers
[a
] <> nil then
1416 SetLength(Result
, Length(Result
)+1);
1417 with Result
[High(Result
)] do
1419 Ping
:= gPlayers
[a
].FPing
;
1420 Loss
:= gPlayers
[a
].FLoss
;
1421 Name
:= gPlayers
[a
].FName
;
1422 Team
:= gPlayers
[a
].FTeam
;
1423 Frags
:= gPlayers
[a
].FFrags
;
1424 Deaths
:= gPlayers
[a
].FDeath
;
1425 Kills
:= gPlayers
[a
].FKills
;
1426 Color
:= gPlayers
[a
].FModel
.Color
;
1427 Lives
:= gPlayers
[a
].FLives
;
1428 Spectator
:= gPlayers
[a
].FSpectator
;
1433 procedure g_Player_RememberAll
;
1437 for i
:= Low(gPlayers
) to High(gPlayers
) do
1438 if (gPlayers
[i
] <> nil) and gPlayers
[i
].Live
then
1439 gPlayers
[i
].RememberState
;
1442 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1446 gTeamStat
[TEAM_RED
].Goals
:= 0;
1447 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1449 if gPlayers
<> nil then
1450 for i
:= 0 to High(gPlayers
) do
1451 if gPlayers
[i
] <> nil then
1453 gPlayers
[i
].Reset(Force
);
1455 if gPlayers
[i
] is TPlayer
then
1457 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1458 gPlayers
[i
].Respawn(Silent
)
1460 gPlayers
[i
].Spectate();
1463 TBot(gPlayers
[i
]).Respawn(Silent
);
1467 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1474 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1479 if (FHealth
>= -50) or (gGibsCount
= 0) then
1481 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1485 for find_id
:= 0 to High(gCorpses
) do
1486 if gCorpses
[find_id
] = nil then
1493 find_id
:= Random(Length(gCorpses
));
1495 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1496 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1497 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1498 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1501 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1502 FObj
.Y
+ PLAYER_RECT_CY
,
1503 FModel
.Name
, FModel
.Color
);
1507 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1511 if (gShells
= nil) or (Length(gShells
) = 0) then
1514 with gShells
[CurrentShell
] do
1520 if T
= SHELL_BULLET
then
1522 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1526 Obj
.Rect
.Width
:= 4;
1527 Obj
.Rect
.Height
:= 2;
1531 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1535 Obj
.Rect
.Width
:= 7;
1536 Obj
.Rect
.Height
:= 3;
1542 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1543 positionChanged(); // this updates spatial accelerators
1544 RAngle
:= Random(360);
1545 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1547 if CurrentShell
>= High(gShells
) then
1554 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1557 GibsArray
: TGibsArray
;
1559 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1561 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1564 for a
:= 0 to High(GibsArray
) do
1565 with gGibs
[CurrentGib
] do
1568 ID
:= GibsArray
[a
].ID
;
1569 MaskID
:= GibsArray
[a
].MaskID
;
1572 Obj
.Rect
:= GibsArray
[a
].Rect
;
1573 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1574 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1575 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1576 positionChanged(); // this updates spatial accelerators
1577 RAngle
:= Random(360);
1579 if gBloodCount
> 0 then
1580 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1581 Random(48), Random(48), 150, 0, 0);
1583 if CurrentGib
>= High(gGibs
) then
1590 procedure g_Player_UpdatePhysicalObjects();
1596 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1601 if T
= SHELL_BULLET
then
1602 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1604 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1609 if gGibs
<> nil then
1610 for i
:= 0 to High(gGibs
) do
1611 if gGibs
[i
].Live
then
1615 mr
:= g_Obj_Move(@Obj
, True, False, True);
1616 positionChanged(); // this updates spatial accelerators
1618 if WordBool(mr
and MOVE_FALLOUT
) then
1624 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1625 if WordBool(mr
and MOVE_HITWALL
) then
1626 Obj
.Vel
.X
:= -(vel
.X
div 2);
1627 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1628 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1630 if (Obj
.Vel
.X
>= 0) then
1632 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1633 if RAngle
>= 360 then
1634 RAngle
:= RAngle
mod 360;
1635 end else begin // Counter-clockwise
1636 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1638 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1641 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1642 if gTime
mod (GAME_TICK
*3) = 0 then
1643 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1647 if gCorpses
<> nil then
1648 for i
:= 0 to High(gCorpses
) do
1649 if gCorpses
[i
] <> nil then
1650 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1656 gCorpses
[i
].Update();
1659 if gShells
<> nil then
1660 for i
:= 0 to High(gShells
) do
1661 if gShells
[i
].Live
then
1665 mr
:= g_Obj_Move(@Obj
, True, False, True);
1666 positionChanged(); // this updates spatial accelerators
1668 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1674 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1675 if WordBool(mr
and MOVE_HITWALL
) then
1677 Obj
.Vel
.X
:= -(vel
.X
div 2);
1678 if not WordBool(mr
and MOVE_INWATER
) then
1679 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1681 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1683 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1684 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1685 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1687 if RAngle
mod 90 <> 0 then
1688 RAngle
:= (RAngle
div 90) * 90;
1690 else if not WordBool(mr
and MOVE_INWATER
) then
1691 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1694 if (Obj
.Vel
.X
>= 0) then
1696 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1697 if RAngle
>= 360 then
1698 RAngle
:= RAngle
mod 360;
1699 end else begin // Counter-clockwise
1700 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1702 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1707 procedure g_Player_DrawCorpses();
1712 if gGibs
<> nil then
1713 for i
:= 0 to High(gGibs
) do
1714 if gGibs
[i
].Live
then
1717 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1720 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1721 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1723 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1726 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1732 if gCorpses
<> nil then
1733 for i
:= 0 to High(gCorpses
) do
1734 if gCorpses
[i
] <> nil then
1738 procedure g_Player_DrawShells();
1743 if gShells
<> nil then
1744 for i
:= 0 to High(gShells
) do
1745 if gShells
[i
].Live
then
1748 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1754 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1758 procedure g_Player_RemoveAllCorpses();
1764 SetLength(gGibs
, MaxGibs
);
1765 SetLength(gShells
, MaxGibs
);
1769 if gCorpses
<> nil then
1770 for i
:= 0 to High(gCorpses
) do
1774 SetLength(gCorpses
, MaxCorpses
);
1777 procedure g_Player_Corpses_SaveState(var Mem
: TBinMemoryWriter
);
1782 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ:
1784 if gCorpses
<> nil then
1785 for i
:= 0 to High(gCorpses
) do
1786 if gCorpses
[i
] <> nil then
1789 Mem
:= TBinMemoryWriter
.Create((count
+1) * 128);
1791 // Êîëè÷åñòâî òðóïîâ:
1792 Mem
.WriteInt(count
);
1798 for i
:= 0 to High(gCorpses
) do
1799 if gCorpses
[i
] <> nil then
1802 Mem
.WriteString(gCorpses
[i
].FModelName
);
1804 b
:= gCorpses
[i
].Mess
;
1805 Mem
.WriteBoolean(b
);
1806 // Ñîõðàíÿåì äàííûå òðóïà:
1807 gCorpses
[i
].SaveState(Mem
);
1811 procedure g_Player_Corpses_LoadState(var Mem
: TBinMemoryReader
);
1820 g_Player_RemoveAllCorpses();
1822 // Êîëè÷åñòâî òðóïîâ:
1825 if count
> Length(gCorpses
) then
1827 raise EBinSizeError
.Create('g_Player_Corpses_LoadState: Too Many Corpses');
1834 for i
:= 0 to count
-1 do
1837 Mem
.ReadString(str
);
1841 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1842 // Çàãðóæàåì äàííûå òðóïà:
1843 gCorpses
[i
].LoadState(Mem
);
1849 procedure TPlayer
.BFGHit();
1851 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1852 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1853 if g_Game_IsServer
and g_Game_IsNet
then
1854 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1855 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1859 procedure TPlayer
.ChangeModel(ModelName
: string);
1861 locModel
: TPlayerModel
;
1863 locModel
:= g_PlayerModel_Get(ModelName
);
1864 if locModel
= nil then Exit
;
1870 procedure TPlayer
.SetModel(ModelName
: string);
1874 m
:= g_PlayerModel_Get(ModelName
);
1877 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1878 m
:= g_PlayerModel_Get('doomer');
1881 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1886 if FModel
<> nil then
1891 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1892 FModel
.Color
:= FColor
1894 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1895 FModel
.SetWeapon(FCurrWeap
);
1896 FModel
.SetFlag(FFlag
);
1897 SetDirection(FDirection
);
1900 procedure TPlayer
.SetColor(Color
: TRGB
);
1903 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1904 if FModel
<> nil then FModel
.Color
:= Color
;
1907 procedure TPlayer
.SwitchTeam
;
1909 if g_Game_IsClient
then
1911 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
1913 if gGameOn
and FLive
then
1914 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
1916 if FTeam
= TEAM_RED
then
1918 ChangeTeam(TEAM_BLUE
);
1919 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
1920 if g_Game_IsNet
then
1921 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
1925 ChangeTeam(TEAM_RED
);
1926 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
1927 if g_Game_IsNet
then
1928 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
1930 FPreferredTeam
:= FTeam
;
1933 procedure TPlayer
.ChangeTeam(Team
: Byte);
1940 TEAM_RED
, TEAM_BLUE
:
1941 FModel
.Color
:= TEAMCOLOR
[Team
];
1943 FModel
.Color
:= FColor
;
1945 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
1946 MH_SEND_PlayerStats(FUID
);
1950 procedure TPlayer.CollideItem();
1955 if gItems = nil then Exit;
1956 if not FLive then Exit;
1958 for i := 0 to High(gItems) do
1961 if (ItemType <> ITEM_NONE) and Live then
1962 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
1963 PLAYER_RECT.Height, @Obj) then
1965 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
1967 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
1968 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
1969 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
1970 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
1971 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
1973 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
1974 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
1975 (gGameSettings.GameType = GT_SINGLE) and
1976 (g_Player_GetCount() > 1)) then
1977 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
1983 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
1985 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
1986 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
1990 constructor TPlayer
.Create();
1996 FSawSound
:= TPlayableSound
.Create();
1997 FSawSoundIdle
:= TPlayableSound
.Create();
1998 FSawSoundHit
:= TPlayableSound
.Create();
1999 FSawSoundSelect
:= TPlayableSound
.Create();
2000 FJetSoundFly
:= TPlayableSound
.Create();
2001 FJetSoundOn
:= TPlayableSound
.Create();
2002 FJetSoundOff
:= TPlayableSound
.Create();
2004 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2005 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2006 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2007 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2008 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2009 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2010 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2012 FSpectatePlayer
:= -1;
2016 FSavedState
.WaitRecall
:= False;
2022 FActualModelName
:= 'doomer';
2025 FObj
.Rect
:= PLAYER_RECT
;
2027 FBFGFireCounter
:= -1;
2028 FJustTeleported
:= False;
2034 procedure TPlayer
.positionChanged ();
2038 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2042 if (not g_Game_IsClient
) and (not FLive
) then
2047 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2048 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2050 if not g_Game_IsClient
then
2053 if t
= HIT_TRAP
then
2055 // Ëîâóøêà óáèâàåò ñðàçó:
2057 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2059 if t
= HIT_SELF
then
2063 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2066 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2067 FMegaRulez
[MR_SUIT
] := 0;
2068 FMegaRulez
[MR_INVUL
] := 0;
2069 FMegaRulez
[MR_INVIS
] := 0;
2073 // Íî îò îñòàëüíîãî ñïàñàåò:
2074 if FMegaRulez
[MR_INVUL
] >= gTime
then
2081 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2082 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2083 (SpawnerUID
= FUID
) or
2084 (not SameTeam(FUID
, SpawnerUID
)) then
2086 FLastSpawnerUID
:= SpawnerUID
;
2088 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2089 if gBloodCount
> 0 then
2091 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2092 if value
div 4 <= c
then
2093 c
:= c
- (value
div 4)
2097 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2101 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2102 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2105 if t
= HIT_WATER
then
2106 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2107 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2112 Inc(FDamageBuffer
, value
);
2116 FPain
:= FPain
+ value
;
2119 if g_Game_IsServer
and g_Game_IsNet
then
2121 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2122 MH_SEND_PlayerStats(FUID
);
2123 MH_SEND_PlayerPos(False, FUID
);
2127 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2130 if g_Game_IsClient
then
2135 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2137 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2140 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2142 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2146 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2147 MH_SEND_PlayerStats(FUID
);
2150 destructor TPlayer
.Destroy();
2152 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2154 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2158 FSawSoundIdle
.Free();
2159 FSawSoundHit
.Free();
2160 FJetSoundFly
.Free();
2162 FJetSoundOff
.Free();
2168 procedure TPlayer
.DrawBubble();
2170 bubX
, bubY
: Integer;
2173 Rw
, Gw
, Bw
: SmallInt;
2176 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= D_LEFT
, -4, 18);
2177 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2185 1: // simple textual non-bubble
2187 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2188 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2189 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2192 2: // advanced pixel-perfect bubble
2194 if FTeam
= TEAM_RED
then
2197 if FTeam
= TEAM_BLUE
then
2200 3: // colored bubble
2202 Rb
:= FModel
.Color
.R
;
2203 Gb
:= FModel
.Color
.G
;
2204 Bb
:= FModel
.Color
.B
;
2205 Rw
:= Min(Rb
* 2 + 64, 255);
2206 Gw
:= Min(Gb
* 2 + 64, 255);
2207 Bw
:= Min(Bb
* 2 + 64, 255);
2208 if (Abs(Rw
- Rb
) < 32)
2209 or (Abs(Gw
- Gb
) < 32)
2210 or (Abs(Bw
- Bb
) < 32) then
2212 Rb
:= Max(Rw
div 2 - 16, 0);
2213 Gb
:= Max(Gw
div 2 - 16, 0);
2214 Bb
:= Max(Bw
div 2 - 16, 0);
2217 4: // custom textured bubble
2219 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2220 if FDirection
= D_RIGHT
then
2221 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2223 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, M_HORIZONTAL
);
2229 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2230 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2232 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2235 Dot
:= IfThen(FDirection
= D_LEFT
, 14, 5);
2236 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2237 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
);
2238 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
);
2239 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
);
2240 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
);
2244 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2245 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2246 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2249 procedure TPlayer
.Draw();
2257 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2258 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2260 e_GetTextureSize(ID
, @w
, @h
);
2261 if FDirection
= D_LEFT
then
2262 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2263 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7, 0, True, False)
2265 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2266 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7, 0, True, False);
2269 if FMegaRulez
[MR_INVIS
] > gTime
then
2271 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2272 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2274 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2275 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2279 FModel
.Draw(FObj
.X
, FObj
.Y
, 200)
2281 FModel
.Draw(FObj
.X
, FObj
.Y
);
2284 FModel
.Draw(FObj
.X
, FObj
.Y
, 254);
2287 FModel
.Draw(FObj
.X
, FObj
.Y
);
2290 if g_debug_Frames
then
2292 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2294 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2295 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2299 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2301 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2302 if gAimLine
and Live
and
2303 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2307 procedure TPlayer
.DrawAim();
2309 wx
, wy
, xx
, yy
: Integer;
2313 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= D_LEFT
, 7, -7);
2314 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2323 1: begin // Chainsaw
2330 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2331 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2332 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2333 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2338 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2339 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2340 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2341 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2343 4: begin // Double Shotgun
2346 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2347 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2348 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2349 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2351 5: begin // Chaingun
2354 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2355 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2356 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2357 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2359 6: begin // Rocket Launcher
2362 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2363 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2364 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2365 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2367 7: begin // Plasmagun
2370 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2371 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2372 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2373 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2378 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2379 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2380 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2381 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2383 9: begin // Super Chaingun
2386 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2387 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2388 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2389 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2392 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2393 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2394 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2397 procedure TPlayer
.DrawGUI();
2400 X
, Y
, SY
, a
, p
, m
: Integer;
2404 stat
: TPlayerStatArray
;
2406 X
:= gPlayerScreenSize
.X
;
2407 SY
:= gPlayerScreenSize
.Y
;
2410 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2412 if gGameSettings
.GameMode
= GM_CTF
then
2416 if gGameSettings
.GameMode
= GM_CTF
then
2418 s
:= 'TEXTURE_PLAYER_REDFLAG';
2419 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2420 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2421 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2422 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2423 if g_Texture_Get(s
, ID
) then
2424 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2427 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2428 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2429 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2431 if gGameSettings
.GameMode
= GM_CTF
then
2433 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2434 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2435 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2436 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2437 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2438 if g_Texture_Get(s
, ID
) then
2439 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2442 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2443 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2444 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2447 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2448 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2451 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2452 e_Draw(ID
, X
+2, Y
, 0, True, False);
2454 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2458 s
:= IntToStr(Frags
);
2459 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2460 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2465 stat
:= g_Player_GetStats();
2470 for a
:= 0 to High(stat
) do
2471 if stat
[a
].Name
<> Name
then
2473 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2474 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2478 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2479 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2480 s
:= s
+IntToStr(Abs(Frags
-m
));
2482 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2483 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2486 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2488 s
:= IntToStr(Lives
);
2489 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2490 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2494 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2495 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2497 if R_BERSERK
in FRulez
then
2498 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2500 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2502 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2503 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2505 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2506 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2507 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2509 s
:= IntToStr(FArmor
);
2510 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2511 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2513 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2519 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2524 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2526 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2527 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2528 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2529 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2530 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2531 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2532 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2533 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2534 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2537 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2538 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2539 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2541 if R_KEY_RED
in FRulez
then
2542 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2544 if R_KEY_GREEN
in FRulez
then
2545 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2547 if R_KEY_BLUE
in FRulez
then
2548 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2550 if FJetFuel
> 0 then
2552 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2553 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2554 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2555 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2556 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2557 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2561 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2562 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2563 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2566 if gShowPing
and g_Game_IsClient
then
2568 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2569 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2575 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2576 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2577 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2580 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2581 s
:= _lc
[I_PLAYER_SPECT4
];
2582 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2583 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2584 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2590 procedure TPlayer
.DrawRulez();
2594 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2595 if FMegaRulez
[MR_INVUL
] >= gTime
then
2597 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2598 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2603 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2604 191, 191, 191, 0, B_INVERT
);
2607 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2608 if FMegaRulez
[MR_SUIT
] >= gTime
then
2610 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2611 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2616 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2617 0, 96, 0, 200, B_NONE
);
2620 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2621 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2623 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2624 255, 0, 0, 200, B_NONE
);
2628 procedure TPlayer
.DrawPain();
2632 if FPain
= 0 then Exit
;
2636 if a
< 15 then h
:= 0
2637 else if a
< 35 then h
:= 1
2638 else if a
< 55 then h
:= 2
2639 else if a
< 75 then h
:= 3
2640 else if a
< 95 then h
:= 4
2643 //if a > 255 then a := 255;
2645 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2646 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2649 procedure TPlayer
.DrawPickup();
2653 if FPickup
= 0 then Exit
;
2657 if a
< 15 then h
:= 1
2658 else if a
< 35 then h
:= 2
2659 else if a
< 55 then h
:= 3
2660 else if a
< 75 then h
:= 4
2663 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2666 procedure TPlayer
.Fire();
2668 f
, DidFire
: Boolean;
2669 wx
, wy
, xd
, yd
: Integer;
2672 if g_Game_IsClient
then Exit
;
2673 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2674 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2682 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2687 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2688 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2689 xd
:= wx
+IfThen(FDirection
= D_LEFT
, -30, 30);
2690 yd
:= wy
+firediry();
2695 if R_BERSERK
in FRulez
then
2697 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2698 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2699 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2702 locobj
.rect
.Width
:= 39;
2703 locobj
.rect
.Height
:= 52;
2704 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2705 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2706 locobj
.Accel
.X
:= xd
-wx
;
2707 locobj
.Accel
.y
:= yd
-wy
;
2709 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2710 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2712 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2716 FPain
:= min(FPain
+ 25, 50);
2717 end else g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2720 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2725 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2726 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2728 FSawSoundSelect
.Stop();
2730 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2732 else if not FSawSoundHit
.IsPlaying() then
2734 FSawSoundSelect
.Stop();
2735 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2738 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2744 if FAmmo
[A_BULLETS
] > 0 then
2746 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2747 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2748 Dec(FAmmo
[A_BULLETS
]);
2749 FFireAngle
:= FAngle
;
2752 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2753 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2757 if FAmmo
[A_SHELLS
] > 0 then
2759 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2760 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
2761 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2762 Dec(FAmmo
[A_SHELLS
]);
2763 FFireAngle
:= FAngle
;
2767 FShellType
:= SHELL_SHELL
;
2771 if FAmmo
[A_SHELLS
] >= 2 then
2773 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
2774 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2775 Dec(FAmmo
[A_SHELLS
], 2);
2776 FFireAngle
:= FAngle
;
2780 FShellType
:= SHELL_DBLSHELL
;
2784 if FAmmo
[A_BULLETS
] > 0 then
2786 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
2787 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
2788 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2789 Dec(FAmmo
[A_BULLETS
]);
2790 FFireAngle
:= FAngle
;
2793 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2794 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2797 WEAPON_ROCKETLAUNCHER
:
2798 if FAmmo
[A_ROCKETS
] > 0 then
2800 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
2801 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2802 Dec(FAmmo
[A_ROCKETS
]);
2803 FFireAngle
:= FAngle
;
2809 if FAmmo
[A_CELLS
] > 0 then
2811 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
2812 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2813 Dec(FAmmo
[A_CELLS
]);
2814 FFireAngle
:= FAngle
;
2820 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
2822 FBFGFireCounter
:= 17;
2823 if not FNoReload
then
2824 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
2825 Dec(FAmmo
[A_CELLS
], 40);
2829 WEAPON_SUPERPULEMET
:
2830 if FAmmo
[A_SHELLS
] > 0 then
2832 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2833 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
2834 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2835 Dec(FAmmo
[A_SHELLS
]);
2836 FFireAngle
:= FAngle
;
2839 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2840 GameVelX
, GameVelY
-2, SHELL_SHELL
);
2843 WEAPON_FLAMETHROWER
:
2844 if FAmmo
[A_FUEL
] > 0 then
2846 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
2847 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2849 FFireAngle
:= FAngle
;
2855 if g_Game_IsNet
then
2859 if FCurrWeap
<> WEAPON_BFG
then
2860 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
2862 if not FNoReload
then
2863 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
2866 MH_SEND_PlayerStats(FUID
);
2871 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
2872 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
2873 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
2876 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
2879 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
2880 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
2881 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
2882 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
2883 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
2888 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
2890 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
2891 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
2892 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
2895 procedure TPlayer
.JetpackOn
;
2899 FJetSoundOn
.SetPosition(0);
2900 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
2904 procedure TPlayer
.JetpackOff
;
2908 FJetSoundOff
.SetPosition(0);
2909 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
2912 procedure TPlayer
.CatchFire(Attacker
: Word);
2915 FFireAttacker
:= Attacker
;
2916 if g_Game_IsNet
and g_Game_IsServer
then
2917 MH_SEND_PlayerStats(FUID
);
2920 procedure TPlayer
.Jump();
2922 if gFly
or FJetpack
then
2924 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
2925 if FObj
.Vel
.Y
> -VEL_FLY
then
2926 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
2929 if FJetFuel
> 0 then
2931 if (FJetFuel
< 1) and g_Game_IsServer
then
2935 if g_Game_IsNet
then
2936 MH_SEND_PlayerStats(FUID
);
2942 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
2944 FCanJetpack
:= False;
2946 // Ïðûãàåì èëè âñïëûâàåì:
2947 if (CollideLevel(0, 1) or
2948 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
2949 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
2950 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
2952 FObj
.Vel
.Y
:= -VEL_JUMP
;
2953 FCanJetpack
:= False;
2957 if BodyInLiquid(0, 0) then
2958 FObj
.Vel
.Y
:= -VEL_SW
2959 else if (FJetFuel
> 0) and FCanJetpack
and
2960 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
2964 if g_Game_IsNet
then
2965 MH_SEND_PlayerStats(FUID
);
2970 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
2972 a
, i
, k
, ab
, ar
: Byte;
2976 srv
, netsrv
: Boolean;
2982 procedure PushItem(t
: Byte);
2986 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
2987 it
:= g_Items_ByIdx(id
);
2988 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
2990 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
2991 (FObj
.Vel
.Y
div 2)-Random(9));
2992 it
.positionChanged(); // this updates spatial accelerators
2996 if KillType
= K_HARDKILL
then // -5..+5; -5..0
2998 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
2999 (FObj
.Vel
.Y
div 2)-Random(6));
3001 else // -3..+3; -3..0
3003 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3004 (FObj
.Vel
.Y
div 2)-Random(4));
3006 it
.positionChanged(); // this updates spatial accelerators
3009 if g_Game_IsNet
and g_Game_IsServer
then
3010 MH_SEND_ItemSpawn(True, id
);
3014 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3015 Srv
:= g_Game_IsServer
;
3016 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3017 if Srv
then FDeath
:= FDeath
+ 1;
3022 if not FPhysics
then
3028 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3030 if FLives
> 0 then FLives
:= FLives
- 1;
3031 if FLives
= 0 then FNoRespawn
:= True;
3034 // Íîìåð òèïà ñìåðòè:
3037 K_SIMPLEKILL
: a
:= 1;
3039 K_EXTRAHARDKILL
: a
:= 3;
3044 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3046 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3053 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3055 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3056 K_EXTRAHARDKILL
, K_FALLKILL
:
3057 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3060 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3064 K_HARDKILL
, K_EXTRAHARDKILL
:
3068 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3069 if (KillType
<> K_FALLKILL
) and (Srv
) then
3070 g_Monsters_killedp();
3072 if SpawnerUID
= FUID
then
3074 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3079 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3082 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3083 begin // Óáèò äðóãèì èãðîêîì
3084 KP
:= g_Player_Get(SpawnerUID
);
3085 if (KP
<> nil) and Srv
then
3087 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3088 if SameTeam(FUID
, SpawnerUID
) then
3098 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3099 Inc(gTeamStat
[KP
.Team
].Goals
,
3100 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3102 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3105 plr
:= g_Player_Get(SpawnerUID
);
3113 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3117 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3121 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3126 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3127 begin // Óáèò ìîíñòðîì
3128 mon
:= g_Monsters_ByUID(SpawnerUID
);
3132 s
:= g_Monsters_GetKilledBy(mon
.MonsterType
);
3136 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3140 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3144 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3149 else // Îñîáûå òèïû ñìåðòè
3152 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3153 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3154 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3155 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3156 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3157 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3163 for a
:= WP_FIRST
to WP_LAST
do
3167 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3168 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3169 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3170 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3171 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3172 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3173 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3174 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3175 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3184 if R_ITEM_BACKPACK
in FRulez
then
3185 PushItem(ITEM_AMMO_BACKPACK
);
3187 // Âûáðîñ ðàêåòíîãî ðàíöà:
3188 if FJetFuel
> 0 then
3189 PushItem(ITEM_JETPACK
);
3192 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3194 if R_KEY_RED
in FRulez
then
3195 PushItem(ITEM_KEY_RED
);
3197 if R_KEY_GREEN
in FRulez
then
3198 PushItem(ITEM_KEY_GREEN
);
3200 if R_KEY_BLUE
in FRulez
then
3201 PushItem(ITEM_KEY_BLUE
);
3208 g_Player_CreateCorpse(Self
);
3210 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3211 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3217 for i
:= Low(gPlayers
) to High(gPlayers
) do
3219 if gPlayers
[i
] = nil then continue
;
3220 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3223 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3224 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3229 OldLR
:= gLMSRespawn
;
3230 if (gGameSettings
.GameMode
= GM_COOP
) then
3234 // everyone is dead, restart the map
3235 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3237 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3238 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3239 gLMSRespawnTime
:= gTime
+ 5000;
3241 else if (a
= 1) then
3243 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3244 if (gPlayers
[k
] = gPlayer1
) or
3245 (gPlayers
[k
] = gPlayer2
) then
3246 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3247 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3248 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3251 else if (gGameSettings
.GameMode
= GM_TDM
) then
3253 if (ab
= 0) and (ar
<> 0) then
3256 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3258 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3259 Inc(gTeamStat
[TEAM_RED
].Goals
);
3260 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3261 gLMSRespawnTime
:= gTime
+ 5000;
3263 else if (ar
= 0) and (ab
<> 0) then
3266 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3268 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3269 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3270 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3271 gLMSRespawnTime
:= gTime
+ 5000;
3273 else if (ar
= 0) and (ab
= 0) then
3276 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3278 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3279 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3280 gLMSRespawnTime
:= gTime
+ 5000;
3283 else if (gGameSettings
.GameMode
= GM_DM
) then
3287 if gPlayers
[k
] <> nil then
3290 // survivor is the winner
3291 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3293 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3296 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3297 gLMSRespawnTime
:= gTime
+ 5000;
3299 else if (a
= 0) then
3301 // everyone is dead, restart the map
3302 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3304 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3305 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3306 gLMSRespawnTime
:= gTime
+ 5000;
3309 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3311 if NetMode
= NET_SERVER
then
3312 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3314 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3320 MH_SEND_PlayerStats(FUID
);
3321 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3322 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3325 if srv
and FNoRespawn
then Spectate(True);
3326 FWantsInGame
:= True;
3329 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3331 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3332 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3335 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3337 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3338 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3341 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3343 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3344 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3345 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3347 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3348 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3349 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3353 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3355 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3356 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3357 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3361 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3363 if g_Game_IsClient
then Exit
;
3364 if Weapon
> High(FWeapon
) then Exit
;
3365 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3368 procedure TPlayer
.resetWeaponQueue ();
3371 FNextWeapDelay
:= 0;
3374 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3378 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3379 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 0);
3380 WEAPON_PISTOL
, WEAPON_CHAINGUN
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_BULLETS
] > 0);
3381 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3382 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3383 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3384 else result
:= (weapon
< length(FWeapon
));
3388 // return 255 for "no switch"
3389 function TPlayer
.getNextWeaponIndex (): Byte;
3392 wantThisWeapon
: array[0..64] of Boolean;
3393 wwc
: Integer = 0; //HACK!
3396 result
:= 255; // default result: "no switch"
3397 // had weapon cycling on previous frame? remove that flag
3398 if (FNextWeap
and $2000) <> 0 then
3400 FNextWeap
:= FNextWeap
and $1FFF;
3401 FNextWeapDelay
:= 0;
3403 // cycling has priority
3404 if (FNextWeap
and $C000) <> 0 then
3406 if (FNextWeap
and $8000) <> 0 then
3410 FNextWeap
:= FNextWeap
or $2000; // we need this
3411 if FNextWeapDelay
> 0 then
3412 exit
; // cooldown time
3414 for i
:= 0 to High(FWeapon
) do
3416 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3417 if FWeapon
[cwi
] then
3419 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d', [FCurrWeap, cwi]), MSG_WARNING);
3420 result
:= Byte(cwi
);
3421 FNextWeapDelay
:= 10;
3429 for i
:= 0 to High(wantThisWeapon
) do
3430 wantThisWeapon
[i
] := false;
3431 for i
:= 0 to High(FWeapon
) do
3432 if (FNextWeap
and (1 shl i
)) <> 0 then
3434 wantThisWeapon
[i
] := true;
3437 // exclude currently selected weapon from the set
3438 wantThisWeapon
[FCurrWeap
] := false;
3439 // slow down alterations a little
3442 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3443 // more than one weapon requested, assume "alteration" and check alteration delay
3444 if FNextWeapDelay
> 0 then
3450 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3451 // but clear all counters if no weapon should be switched
3457 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3458 // try weapons in descending order
3459 for i
:= High(FWeapon
) downto 0 do
3461 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3466 FNextWeapDelay
:= 10; // anyway, 'cause why not
3470 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3474 procedure TPlayer
.RealizeCurrentWeapon();
3475 function switchAllowed (): Boolean;
3480 if FBFGFireCounter
<> -1 then
3482 if FTime
[T_SWITCH
] > gTime
then
3484 for i
:= WP_FIRST
to WP_LAST
do
3485 if FReloading
[i
] > 0 then
3493 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3494 //FNextWeap := FNextWeap and $1FFF;
3495 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3497 if not switchAllowed
then
3499 //HACK for weapon cycling
3500 if (FNextWeap
and $7000) <> 0 then FNextWeap
:= 0;
3504 nw
:= getNextWeaponIndex();
3505 if nw
= 255 then exit
; // don't reset anything here
3506 if nw
> High(FWeapon
) then
3508 // don't forget to reset queue here!
3509 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3517 FTime
[T_SWITCH
] := gTime
+156;
3518 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3519 FModel
.SetWeapon(FCurrWeap
);
3520 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3524 procedure TPlayer
.NextWeapon();
3526 if g_Game_IsClient
then Exit
;
3530 procedure TPlayer
.PrevWeapon();
3532 if g_Game_IsClient
then Exit
;
3536 procedure TPlayer
.SetWeapon(W
: Byte);
3538 if FCurrWeap
<> W
then
3539 if W
= WEAPON_SAW
then
3540 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3543 FModel
.SetWeapon(CurrWeap
);
3547 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3552 if g_Game_IsClient
then Exit
;
3554 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3555 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3560 if FHealth
< PLAYER_HP_SOFT
then
3562 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3566 if gFlash
= 2 then Inc(FPickup
, 5);
3570 if FHealth
< PLAYER_HP_SOFT
then
3572 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3576 if gFlash
= 2 then Inc(FPickup
, 5);
3580 if FArmor
< PLAYER_AP_SOFT
then
3582 FArmor
:= PLAYER_AP_SOFT
;
3585 if gFlash
= 2 then Inc(FPickup
, 5);
3589 if FArmor
< PLAYER_AP_LIMIT
then
3591 FArmor
:= PLAYER_AP_LIMIT
;
3594 if gFlash
= 2 then Inc(FPickup
, 5);
3598 if FHealth
< PLAYER_HP_LIMIT
then
3600 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3604 if gFlash
= 2 then Inc(FPickup
, 5);
3608 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3610 if FHealth
< PLAYER_HP_LIMIT
then
3611 FHealth
:= PLAYER_HP_LIMIT
;
3612 if FArmor
< PLAYER_AP_LIMIT
then
3613 FArmor
:= PLAYER_AP_LIMIT
;
3617 if gFlash
= 2 then Inc(FPickup
, 5);
3621 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3623 FWeapon
[WEAPON_SAW
] := True;
3625 if gFlash
= 2 then Inc(FPickup
, 5);
3626 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3629 ITEM_WEAPON_SHOTGUN1
:
3630 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3632 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3633 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3635 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3636 FWeapon
[WEAPON_SHOTGUN1
] := True;
3638 if gFlash
= 2 then Inc(FPickup
, 5);
3639 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3642 ITEM_WEAPON_SHOTGUN2
:
3643 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3645 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3647 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3648 FWeapon
[WEAPON_SHOTGUN2
] := True;
3650 if gFlash
= 2 then Inc(FPickup
, 5);
3651 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3654 ITEM_WEAPON_CHAINGUN
:
3655 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3657 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3659 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3660 FWeapon
[WEAPON_CHAINGUN
] := True;
3662 if gFlash
= 2 then Inc(FPickup
, 5);
3663 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3666 ITEM_WEAPON_ROCKETLAUNCHER
:
3667 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3669 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3671 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3672 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3674 if gFlash
= 2 then Inc(FPickup
, 5);
3675 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3679 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3681 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3683 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3684 FWeapon
[WEAPON_PLASMA
] := True;
3686 if gFlash
= 2 then Inc(FPickup
, 5);
3687 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3691 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3693 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3695 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3696 FWeapon
[WEAPON_BFG
] := True;
3698 if gFlash
= 2 then Inc(FPickup
, 5);
3699 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3702 ITEM_WEAPON_SUPERPULEMET
:
3703 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3705 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3707 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3708 FWeapon
[WEAPON_SUPERPULEMET
] := True;
3710 if gFlash
= 2 then Inc(FPickup
, 5);
3711 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3714 ITEM_WEAPON_FLAMETHROWER
:
3715 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
3717 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
3719 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3720 FWeapon
[WEAPON_FLAMETHROWER
] := True;
3722 if gFlash
= 2 then Inc(FPickup
, 5);
3723 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3727 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3729 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3732 if gFlash
= 2 then Inc(FPickup
, 5);
3735 ITEM_AMMO_BULLETS_BOX
:
3736 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3738 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3741 if gFlash
= 2 then Inc(FPickup
, 5);
3745 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3747 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3750 if gFlash
= 2 then Inc(FPickup
, 5);
3753 ITEM_AMMO_SHELLS_BOX
:
3754 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3756 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
3759 if gFlash
= 2 then Inc(FPickup
, 5);
3763 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3765 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3768 if gFlash
= 2 then Inc(FPickup
, 5);
3771 ITEM_AMMO_ROCKET_BOX
:
3772 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3774 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
3777 if gFlash
= 2 then Inc(FPickup
, 5);
3781 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3783 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3786 if gFlash
= 2 then Inc(FPickup
, 5);
3790 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3792 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
3795 if gFlash
= 2 then Inc(FPickup
, 5);
3799 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
3801 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3804 if gFlash
= 2 then Inc(FPickup
, 5);
3808 if not(R_ITEM_BACKPACK
in FRulez
) or
3809 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
3810 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
3811 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
3812 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
3813 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
3815 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
3816 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
3817 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
3818 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
3819 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
3821 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3822 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3823 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3824 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3825 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3826 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3827 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3828 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3830 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
3833 if gFlash
= 2 then Inc(FPickup
, 5);
3837 if not(R_KEY_RED
in FRulez
) then
3839 Include(FRulez
, R_KEY_RED
);
3841 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3842 if gFlash
= 2 then Inc(FPickup
, 5);
3843 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3847 if not(R_KEY_GREEN
in FRulez
) then
3849 Include(FRulez
, R_KEY_GREEN
);
3851 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3852 if gFlash
= 2 then Inc(FPickup
, 5);
3853 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3857 if not(R_KEY_BLUE
in FRulez
) then
3859 Include(FRulez
, R_KEY_BLUE
);
3861 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3862 if gFlash
= 2 then Inc(FPickup
, 5);
3863 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3867 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
3869 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
3873 if gFlash
= 2 then Inc(FPickup
, 5);
3877 if FAir
< AIR_MAX
then
3882 if gFlash
= 2 then Inc(FPickup
, 5);
3887 if not (R_BERSERK
in FRulez
) then
3889 Include(FRulez
, R_BERSERK
);
3890 if FBFGFireCounter
= -1 then
3892 FCurrWeap
:= WEAPON_KASTET
;
3894 FModel
.SetWeapon(WEAPON_KASTET
);
3898 if gFlash
= 2 then Inc(FPickup
, 5);
3899 FBerserk
:= gTime
+30000;
3904 if FHealth
< PLAYER_HP_SOFT
then
3906 FHealth
:= PLAYER_HP_SOFT
;
3907 FBerserk
:= gTime
+30000;
3915 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
3917 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
3920 if gFlash
= 2 then Inc(FPickup
, 5);
3924 if FHealth
< PLAYER_HP_LIMIT
then
3926 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
3930 if gFlash
= 2 then Inc(FPickup
, 5);
3934 if FArmor
< PLAYER_AP_LIMIT
then
3936 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
3939 if gFlash
= 2 then Inc(FPickup
, 5);
3943 if FJetFuel
< JET_MAX
then
3945 FJetFuel
:= JET_MAX
;
3948 if gFlash
= 2 then Inc(FPickup
, 5);
3952 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
3954 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
3957 if gFlash
= 2 then Inc(FPickup
, 5);
3962 procedure TPlayer
.Touch();
3966 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
3969 // Áðîñèòü ôëàã òîâàðèùó:
3970 if gGameSettings
.GameMode
= GM_CTF
then
3975 procedure TPlayer
.Push(vx
, vy
: Integer);
3977 if (not FPhysics
) and FGhost
then
3979 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
3980 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
3981 if g_Game_IsNet
and g_Game_IsServer
then
3982 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
3985 procedure TPlayer
.Reset(Force
: Boolean);
3991 FTime
[T_RESPAWN
] := 0;
3992 FTime
[T_FLAGCAP
] := 0;
4005 FSpectator
:= False;
4008 FSpectatePlayer
:= -1;
4009 FNoRespawn
:= False;
4011 FLives
:= gGameSettings
.MaxLives
;
4016 procedure TPlayer
.SoftReset();
4022 FBFGFireCounter
:= -1;
4030 SetAction(A_STAND
, True);
4033 function TPlayer
.GetRespawnPoint(): Byte;
4038 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4040 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4041 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4043 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4045 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4046 if Self
= gPlayer1
then
4047 c
:= RESPAWNPOINT_PLAYER1
4049 c
:= RESPAWNPOINT_PLAYER2
;
4050 if g_Map_GetPointCount(c
) > 0 then
4056 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4057 if Self
= gPlayer1
then
4058 c
:= RESPAWNPOINT_PLAYER2
4060 c
:= RESPAWNPOINT_PLAYER1
;
4061 if g_Map_GetPointCount(c
) > 0 then
4068 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4069 if Random(2) = 0 then
4070 c
:= RESPAWNPOINT_PLAYER1
4072 c
:= RESPAWNPOINT_PLAYER2
;
4073 if g_Map_GetPointCount(c
) > 0 then
4080 // Òî÷êà ëþáîé èç êîìàíä
4081 if Random(2) = 0 then
4082 c
:= RESPAWNPOINT_RED
4084 c
:= RESPAWNPOINT_BLUE
;
4085 if g_Map_GetPointCount(c
) > 0 then
4092 c
:= RESPAWNPOINT_DM
;
4093 if g_Map_GetPointCount(c
) > 0 then
4101 if gGameSettings
.GameMode
= GM_DM
then
4104 c
:= RESPAWNPOINT_DM
;
4105 if g_Map_GetPointCount(c
) > 0 then
4111 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4112 if Random(2) = 0 then
4113 c
:= RESPAWNPOINT_PLAYER1
4115 c
:= RESPAWNPOINT_PLAYER2
;
4116 if g_Map_GetPointCount(c
) > 0 then
4122 // Òî÷êà ëþáîé èç êîìàíä
4123 if Random(2) = 0 then
4124 c
:= RESPAWNPOINT_RED
4126 c
:= RESPAWNPOINT_BLUE
;
4127 if g_Map_GetPointCount(c
) > 0 then
4135 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4137 // Òî÷êà ñâîåé êîìàíäû
4138 c
:= RESPAWNPOINT_DM
;
4139 if FTeam
= TEAM_RED
then
4140 c
:= RESPAWNPOINT_RED
;
4141 if FTeam
= TEAM_BLUE
then
4142 c
:= RESPAWNPOINT_BLUE
;
4143 if g_Map_GetPointCount(c
) > 0 then
4150 c
:= RESPAWNPOINT_DM
;
4151 if g_Map_GetPointCount(c
) > 0 then
4157 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4158 if Random(2) = 0 then
4159 c
:= RESPAWNPOINT_PLAYER1
4161 c
:= RESPAWNPOINT_PLAYER2
;
4162 if g_Map_GetPointCount(c
) > 0 then
4168 // Òî÷êà äðóãîé êîìàíäû
4169 c
:= RESPAWNPOINT_DM
;
4170 if FTeam
= TEAM_RED
then
4171 c
:= RESPAWNPOINT_BLUE
;
4172 if FTeam
= TEAM_BLUE
then
4173 c
:= RESPAWNPOINT_RED
;
4174 if g_Map_GetPointCount(c
) > 0 then
4182 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4184 RespawnPoint
: TRespawnPoint
;
4189 if not g_Game_IsServer
then
4193 FWantsInGame
:= True;
4194 FJustTeleported
:= True;
4197 FTime
[T_RESPAWN
] := 0;
4201 // if server changes MaxLives we gotta be ready
4202 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4204 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4205 if FTime
[T_RESPAWN
] > gTime
then
4208 // Ïðîñðàë âñå æèçíè:
4211 if not FSpectator
then Spectate(True);
4212 FWantsInGame
:= True;
4216 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4217 begin // "Ñâîÿ èãðà"
4218 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4219 FRulez
:= FRulez
-[R_BERSERK
];
4221 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4223 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4224 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4227 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4228 c
:= GetRespawnPoint();
4233 // Âîñêðåøåíèå áåç îðóæèÿ:
4236 FHealth
:= PLAYER_HP_SOFT
;
4242 for a
:= WP_FIRST
to WP_LAST
do
4244 FWeapon
[a
] := False;
4248 FWeapon
[WEAPON_PISTOL
] := True;
4249 FWeapon
[WEAPON_KASTET
] := True;
4250 FCurrWeap
:= WEAPON_PISTOL
;
4253 FModel
.SetWeapon(FCurrWeap
);
4255 for b
:= A_BULLETS
to A_HIGH
do
4258 FAmmo
[A_BULLETS
] := 50;
4260 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4261 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4262 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4263 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4264 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4266 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4267 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4272 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4273 if not g_Map_GetPoint(c
, RespawnPoint
) then
4275 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4279 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4280 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4281 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4287 FDirection
:= RespawnPoint
.Direction
;
4288 if FDirection
= D_LEFT
then
4294 FBFGFireCounter
:= -1;
4299 SetAction(A_STAND
, True);
4300 FModel
.Direction
:= FDirection
;
4302 for a
:= Low(FTime
) to High(FTime
) do
4305 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4310 FCanJetpack
:= False;
4315 // Àíèìàöèÿ âîçðîæäåíèÿ:
4316 if (not gLoadGameMode
) and (not Silent
) then
4317 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4319 Anim
:= TAnimation
.Create(ID
, False, 3);
4320 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4321 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4325 FSpectator
:= False;
4328 FSpectatePlayer
:= -1;
4331 if g_Game_IsNet
then
4333 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4334 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4336 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4337 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4342 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4345 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4346 else if (not NoMove
) then
4348 GameX
:= gMapInfo
.Width
div 2;
4349 GameY
:= gMapInfo
.Height
div 2;
4358 FWantsInGame
:= False;
4363 if Self
= gPlayer1
then
4368 if Self
= gPlayer2
then
4375 if g_Game_IsNet
then
4376 MH_SEND_PlayerStats(FUID
);
4379 procedure TPlayer
.SwitchNoClip
;
4383 FGhost
:= not FGhost
;
4384 FPhysics
:= not FGhost
;
4396 procedure TPlayer
.Run(Direction
: TDirection
);
4400 if MAX_RUNVEL
> 8 then
4404 if Direction
= D_LEFT
then
4406 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4407 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4410 if FObj
.Vel
.X
< MAX_RUNVEL
then
4411 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4413 // Âîçìîæíî, ïèíàåì êóñêè:
4414 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4416 b
:= Abs(FObj
.Vel
.X
);
4417 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4418 for a
:= 0 to High(gGibs
) do
4420 if gGibs
[a
].Live
and
4421 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4422 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4425 if FObj
.Vel
.X
< 0 then
4427 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4431 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4433 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4441 procedure TPlayer
.SeeDown();
4443 SetAction(A_SEEDOWN
);
4445 if FDirection
= D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4447 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4450 procedure TPlayer
.SeeUp();
4454 if FDirection
= D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4456 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4459 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4467 A_ATTACK
: Prior
:= 2;
4468 A_SEEUP
: Prior
:= 1;
4469 A_SEEDOWN
: Prior
:= 1;
4470 A_ATTACKUP
: Prior
:= 2;
4471 A_ATTACKDOWN
: Prior
:= 2;
4476 if (Prior
> FActionPrior
) or Force
then
4477 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4479 FActionPrior
:= Prior
;
4480 FActionAnim
:= Action
;
4481 FActionForce
:= Force
;
4482 FActionChanged
:= True;
4485 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4488 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4490 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4491 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4492 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4493 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4496 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4503 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4505 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4506 if g_Game_IsServer
and g_Game_IsNet
then
4507 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4511 FJustTeleported
:= True;
4516 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4518 Anim
:= TAnimation
.Create(ID
, False, 3);
4521 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4522 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4523 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4524 if g_Game_IsServer
and g_Game_IsNet
then
4525 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4526 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4530 FObj
.X
:= X
-PLAYER_RECT
.X
;
4531 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4532 if FLive
and FGhost
then
4538 if not g_Game_IsNet
then
4542 SetDirection(D_LEFT
);
4548 SetDirection(D_RIGHT
);
4554 if FDirection
= D_RIGHT
then
4556 SetDirection(D_LEFT
);
4561 SetDirection(D_RIGHT
);
4567 if not silent
and (Anim
<> nil) then
4569 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4570 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4573 if g_Game_IsServer
and g_Game_IsNet
then
4574 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4575 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4582 function nonz(a
: Single): Single;
4590 procedure TPlayer
.Update();
4593 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4594 blockmon
, headwater
, dospawn
: Boolean;
4599 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4600 AnyServer
:= g_Game_IsServer
;
4602 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4603 DoLerp(NetInterpLevel
+ 1)
4609 if FClientID
>= 0 then
4611 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4612 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4613 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4622 if FLive
and (gFly
or FJetpack
) then
4625 if FDirection
= D_LEFT
then
4630 if FLive
and (not FGhost
) then
4632 if FKeys
[KEY_UP
].Pressed
then
4634 if FKeys
[KEY_DOWN
].Pressed
then
4638 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4641 i
:= g_basic
.Sign(FIncCam
);
4642 FIncCam
:= Abs(FIncCam
);
4643 DecMin(FIncCam
, 5, 0);
4644 FIncCam
:= FIncCam
*i
;
4647 // no need to do that each second frame, weapon queue will take care of it
4648 if FLive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4649 if FLive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4651 if gTime
mod (GAME_TICK
*2) <> 0 then
4653 if (FObj
.Vel
.X
= 0) and FLive
then
4655 if FKeys
[KEY_LEFT
].Pressed
then
4657 if FKeys
[KEY_RIGHT
].Pressed
then
4663 g_Obj_Move(@FObj
, True, True, True);
4664 positionChanged(); // this updates spatial accelerators
4670 FActionChanged
:= False;
4674 // Let alive player do some actions
4675 if FKeys
[KEY_LEFT
].Pressed
then Run(D_LEFT
);
4676 if FKeys
[KEY_RIGHT
].Pressed
then Run(D_RIGHT
);
4677 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
4678 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
4679 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
4680 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
4681 if FKeys
[KEY_JUMP
].Pressed
then Jump()
4684 if AnyServer
and FJetpack
then
4688 if NetServer
then MH_SEND_PlayerStats(FUID
);
4690 FCanJetpack
:= True;
4697 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
4699 if FKeys
[k
].Pressed
then
4707 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4710 if (FTime
[T_RESPAWN
] <= gTime
) and
4711 gGameOn
and (not FLive
) then
4713 if (g_Player_GetCount() > 1) then
4717 gExit
:= EXIT_RESTART
;
4722 // Dead spectator actions
4725 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
4726 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
4730 if (FSpectatePlayer
>= High(gPlayers
)) then
4731 FSpectatePlayer
:= -1
4735 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
4736 if gPlayers
[I
] <> nil then
4737 if gPlayers
[I
].Live
then
4738 if gPlayers
[I
].UID
<> FUID
then
4740 FSpectatePlayer
:= I
;
4745 if not SetSpect
then FSpectatePlayer
:= -1;
4756 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
4758 FYTo
:= FObj
.Y
- 32;
4759 FSpectatePlayer
:= -1;
4761 if FKeys
[KEY_DOWN
].Pressed
then
4763 FYTo
:= FObj
.Y
+ 32;
4764 FSpectatePlayer
:= -1;
4766 if FKeys
[KEY_LEFT
].Pressed
then
4768 FXTo
:= FObj
.X
- 32;
4769 FSpectatePlayer
:= -1;
4771 if FKeys
[KEY_RIGHT
].Pressed
then
4773 FXTo
:= FObj
.X
+ 32;
4774 FSpectatePlayer
:= -1;
4777 if (FXTo
< -64) then
4779 else if (FXTo
> gMapInfo
.Width
+ 32) then
4780 FXTo
:= gMapInfo
.Width
+ 32;
4781 if (FYTo
< -72) then
4783 else if (FYTo
> gMapInfo
.Height
+ 32) then
4784 FYTo
:= gMapInfo
.Height
+ 32;
4789 g_Obj_Move(@FObj
, True, True, True);
4790 positionChanged(); // this updates spatial accelerators
4797 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
4798 if gPlayers
[FSpectatePlayer
] <> nil then
4799 if gPlayers
[FSpectatePlayer
].Live
then
4801 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
4802 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
4806 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
4807 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
4808 PANEL_BLOCKMON
, True);
4809 headwater
:= HeadInLiquid(0, 0);
4811 // Ñîïðîòèâëåíèå âîçäóõà:
4812 if (not FLive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
4813 if FObj
.Vel
.X
<> 0 then
4814 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
4816 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
4817 DecMin(FPain
, 5, 0);
4818 DecMin(FPickup
, 1, 0);
4820 if FLive
and (FObj
.Y
> gMapInfo
.Height
+128) and AnyServer
then
4822 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
4823 FMegaRulez
[MR_SUIT
] := 0;
4824 FMegaRulez
[MR_INVUL
] := 0;
4825 FMegaRulez
[MR_INVIS
] := 0;
4826 Kill(K_FALLKILL
, 0, HIT_FALL
);
4833 if FCurrWeap
= WEAPON_SAW
then
4834 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
4835 FSawSoundSelect
.IsPlaying()) then
4836 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
4839 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
4840 (not FJetSoundOff
.IsPlaying()) then
4842 FJetSoundFly
.SetPosition(0);
4843 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
4846 for b
:= WP_FIRST
to WP_LAST
do
4847 if FReloading
[b
] > 0 then
4853 if FShellTimer
> -1 then
4854 if FShellTimer
= 0 then
4856 if FShellType
= SHELL_SHELL
then
4857 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4858 GameVelX
, GameVelY
-2, SHELL_SHELL
)
4859 else if FShellType
= SHELL_DBLSHELL
then
4861 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4862 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
4863 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4864 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
4867 end else Dec(FShellTimer
);
4869 if (FBFGFireCounter
> -1) then
4870 if FBFGFireCounter
= 0 then
4874 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
4875 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
4876 xd
:= wx
+IfThen(FDirection
= D_LEFT
, -30, 30);
4877 yd
:= wy
+firediry();
4878 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
4879 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
4880 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
4881 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
4882 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
4885 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
4886 FBFGFireCounter
:= -1;
4889 FBFGFireCounter
:= 0
4891 Dec(FBFGFireCounter
);
4893 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
4895 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
4897 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
4900 if (headwater
or blockmon
) then
4906 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
4909 else if (FAir
mod 31 = 0) and not blockmon
then
4911 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
4912 if Random(2) = 0 then
4913 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
4915 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
4917 end else if FAir
< AIR_DEF
then
4920 if FFireTime
> 0 then
4922 if BodyInLiquid(0, 0) then
4927 else if FMegaRulez
[MR_SUIT
] >= gTime
then
4929 if FMegaRulez
[MR_SUIT
] = gTime
then
4936 if FFirePainTime
<= 0 then
4938 if g_Game_IsServer
then
4939 Damage(5, FFireAttacker
, 0, 0, HIT_FLAME
);
4940 FFirePainTime
:= 18;
4942 FFirePainTime
:= FFirePainTime
- 1;
4943 FFireTime
:= FFireTime
- 1;
4944 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
4945 MH_SEND_PlayerStats(FUID
);
4949 if FDamageBuffer
> 0 then
4951 if FDamageBuffer
>= 9 then
4955 if FDamageBuffer
< 30 then i
:= 9
4956 else if FDamageBuffer
< 100 then i
:= 18
4960 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
4961 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
4962 FHealth
:= FHealth
-ii
;
4965 FHealth
:= FHealth
+FArmor
;
4970 if FHealth
<= 0 then
4971 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
4972 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
4973 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
4977 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
4978 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
4979 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
4980 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
4987 end; // if FLive then ...
4989 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
4991 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
4992 FModel
.GetCurrentAnimation
.MinLength
:= i
;
4993 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
4994 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
4996 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
4997 then SetAction(A_STAND
, True);
4999 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5001 for b
:= Low(FKeys
) to High(FKeys
) do
5002 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5005 function TPlayer
.getMapAABB (): AABB2D
; inline;
5007 result
:= AABB2D
.CreateWH(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5010 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5012 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5013 FObj
.Y
+PLAYER_RECT
.Y
,
5020 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5022 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5023 FObj
.Y
+PLAYER_RECT
.Y
,
5027 Panel
.Width
, Panel
.Height
);
5030 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5032 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5033 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5034 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5035 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5038 function g_Player_ValidName(Name
: string): Boolean;
5044 if gPlayers
= nil then Exit
;
5046 for a
:= 0 to High(gPlayers
) do
5047 if gPlayers
[a
] <> nil then
5048 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5055 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5059 d
:= FModel
.Direction
;
5061 FModel
.Direction
:= Direction
;
5062 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5064 FDirection
:= Direction
;
5067 function TPlayer
.GetKeys(): Byte;
5071 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5072 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5073 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5075 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5076 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5079 procedure TPlayer
.Use();
5083 if FTime
[T_USE
] > gTime
then Exit
;
5085 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5086 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5088 for a
:= 0 to High(gPlayers
) do
5089 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5090 gPlayers
[a
].Live
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5091 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5092 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5094 gPlayers
[a
].Touch();
5095 if g_Game_IsNet
and g_Game_IsServer
then
5096 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5099 FTime
[T_USE
] := gTime
+120;
5102 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5106 WX
, WY
, XD
, YD
: Integer;
5117 if R_BERSERK
in FRulez
then
5119 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5120 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5121 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5124 locobj
.rect
.Width
:= 39;
5125 locobj
.rect
.Height
:= 52;
5126 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5127 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5128 locobj
.Accel
.X
:= xd
-wx
;
5129 locobj
.Accel
.y
:= yd
-wy
;
5131 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5132 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5134 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5138 FPain
:= min(FPain
+ 25, 50);
5140 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5145 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5146 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5148 FSawSoundSelect
.Stop();
5150 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5152 else if not FSawSoundHit
.IsPlaying() then
5154 FSawSoundSelect
.Stop();
5155 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5162 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5163 FFireAngle
:= FAngle
;
5165 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5166 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5171 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5172 FFireAngle
:= FAngle
;
5175 FShellType
:= SHELL_SHELL
;
5180 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5181 FFireAngle
:= FAngle
;
5184 FShellType
:= SHELL_DBLSHELL
;
5189 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5190 FFireAngle
:= FAngle
;
5192 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5193 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5196 WEAPON_ROCKETLAUNCHER
:
5198 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5199 FFireAngle
:= FAngle
;
5205 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5206 FFireAngle
:= FAngle
;
5212 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5213 FFireAngle
:= FAngle
;
5217 WEAPON_SUPERPULEMET
:
5219 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5220 FFireAngle
:= FAngle
;
5222 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5223 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5226 WEAPON_FLAMETHROWER
:
5228 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5229 FFireAngle
:= FAngle
;
5236 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5237 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5238 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5241 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5243 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5244 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5247 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5251 if NetInterpLevel
< 1 then
5261 AX
:= Abs(FXTo
- FObj
.X
);
5262 AY
:= Abs(FYTo
- FObj
.Y
);
5263 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5265 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5270 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5272 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5273 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5274 PANEL_LIFTUP
, False) then Result
:= -1
5276 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5277 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5278 PANEL_LIFTDOWN
, False) then Result
:= 1
5282 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5289 if Flag
= FLAG_NONE
then
5292 if not g_Game_IsServer
then Exit
;
5294 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5295 if (Flag
= FTeam
) and
5296 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5297 (FFlag
<> FLAG_NONE
) then
5299 if FFlag
= FLAG_RED
then
5300 s
:= _lc
[I_PLAYER_FLAG_RED
]
5302 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5304 evtype
:= FLAG_STATE_SCORED
;
5306 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5307 Insert('.', ts
, Length(ts
) + 1 - 3);
5308 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5310 g_Map_ResetFlag(FFlag
);
5311 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5313 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5316 if g_Game_IsNet
then
5318 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5322 gFlags
[FFlag
].CaptureTime
:= 0;
5327 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5328 if (Flag
= FTeam
) and
5329 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5331 if Flag
= FLAG_RED
then
5332 s
:= _lc
[I_PLAYER_FLAG_RED
]
5334 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5336 evtype
:= FLAG_STATE_RETURNED
;
5337 gFlags
[Flag
].CaptureTime
:= 0;
5339 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5341 g_Map_ResetFlag(Flag
);
5342 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5345 if g_Game_IsNet
then
5347 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5353 // Ïîäîáðàë ÷óæîé ôëàã:
5354 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5358 if Flag
= FLAG_RED
then
5359 s
:= _lc
[I_PLAYER_FLAG_RED
]
5361 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5363 evtype
:= FLAG_STATE_CAPTURED
;
5365 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5367 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5369 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5372 if g_Game_IsNet
then
5374 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5380 procedure TPlayer
.SetFlag(Flag
: Byte);
5383 if FModel
<> nil then
5384 FModel
.SetFlag(FFlag
);
5387 function TPlayer
.DropFlag(): Boolean;
5392 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5394 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5395 with gFlags
[FFlag
] do
5399 Direction
:= FDirection
;
5400 State
:= FLAG_STATE_DROPPED
;
5402 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5403 (FObj
.Vel
.Y
div 2)-2+Random(5));
5404 positionChanged(); // this updates spatial accelerators
5406 if FFlag
= FLAG_RED
then
5407 s
:= _lc
[I_PLAYER_FLAG_RED
]
5409 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5411 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5412 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5414 if g_Game_IsNet
then
5415 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5421 procedure TPlayer
.GetSecret();
5426 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5428 Assert(Key
<= High(FKeys
));
5430 FKeys
[Key
].Pressed
:= True;
5431 FKeys
[Key
].Time
:= Time
;
5434 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5436 Result
:= FKeys
[K
].Pressed
;
5439 procedure TPlayer
.ReleaseKeys();
5443 for a
:= Low(FKeys
) to High(FKeys
) do
5445 FKeys
[a
].Pressed
:= False;
5450 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5454 function TPlayer
.firediry(): Integer;
5456 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5457 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5461 procedure TPlayer
.RememberState();
5465 FSavedState
.Health
:= FHealth
;
5466 FSavedState
.Armor
:= FArmor
;
5467 FSavedState
.Air
:= FAir
;
5468 FSavedState
.JetFuel
:= FJetFuel
;
5469 FSavedState
.CurrWeap
:= FCurrWeap
;
5470 FSavedState
.NextWeap
:= FNextWeap
;
5471 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5474 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5476 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5478 FSavedState
.Rulez
:= FRulez
;
5479 FSavedState
.WaitRecall
:= True;
5482 procedure TPlayer
.RecallState();
5486 if not FSavedState
.WaitRecall
then Exit
;
5488 FHealth
:= FSavedState
.Health
;
5489 FArmor
:= FSavedState
.Armor
;
5490 FAir
:= FSavedState
.Air
;
5491 FJetFuel
:= FSavedState
.JetFuel
;
5492 FCurrWeap
:= FSavedState
.CurrWeap
;
5493 FNextWeap
:= FSavedState
.NextWeap
;
5494 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5497 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5499 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5501 FRulez
:= FSavedState
.Rulez
;
5502 FSavedState
.WaitRecall
:= False;
5504 if gGameSettings
.GameType
= GT_SERVER
then
5505 MH_SEND_PlayerStats(FUID
);
5508 procedure TPlayer
.SaveState(var Mem
: TBinMemoryWriter
);
5520 Mem
:= TBinMemoryWriter
.Create(i
);
5522 // Ñèãíàòóðà èãðîêà:
5523 sig
:= PLAYER_SIGNATURE
; // 'PLYR'
5524 Mem
.WriteDWORD(sig
);
5526 Mem
.WriteBoolean(FIamBot
);
5528 Mem
.WriteWord(FUID
);
5530 Mem
.WriteString(FName
, 32);
5532 Mem
.WriteByte(FTeam
);
5534 Mem
.WriteBoolean(FLive
);
5535 // Èçðàñõîäîâàë ëè âñå æèçíè:
5536 Mem
.WriteBoolean(FNoRespawn
);
5538 if FDirection
= D_LEFT
then
5544 Mem
.WriteInt(FHealth
);
5546 Mem
.WriteByte(FLives
);
5548 Mem
.WriteInt(FArmor
);
5552 Mem
.WriteInt(FJetFuel
);
5554 Mem
.WriteInt(FPain
);
5556 Mem
.WriteInt(FKills
);
5558 Mem
.WriteInt(FMonsterKills
);
5560 Mem
.WriteInt(FFrags
);
5562 Mem
.WriteByte(FFragCombo
);
5563 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5564 Mem
.WriteDWORD(FLastFrag
);
5566 Mem
.WriteInt(FDeath
);
5567 // Êàêîé ôëàã íåñåò:
5568 Mem
.WriteByte(FFlag
);
5570 Mem
.WriteInt(FSecrets
);
5572 Mem
.WriteByte(FCurrWeap
);
5574 Mem
.WriteWord(FNextWeap
);
5576 Mem
.WriteByte(FNextWeapDelay
);
5577 // Âðåìÿ çàðÿäêè BFG:
5578 Mem
.WriteSmallInt(FBFGFireCounter
);
5580 Mem
.WriteInt(FDamageBuffer
);
5581 // Ïîñëåäíèé óäàðèâøèé:
5582 Mem
.WriteWord(FLastSpawnerUID
);
5583 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5584 Mem
.WriteByte(FLastHit
);
5586 Obj_SaveState(@FObj
, Mem
);
5587 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5588 for i
:= A_BULLETS
to A_HIGH
do
5589 Mem
.WriteWord(FAmmo
[i
]);
5590 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5591 for i
:= A_BULLETS
to A_HIGH
do
5592 Mem
.WriteWord(FMaxAmmo
[i
]);
5594 for i
:= WP_FIRST
to WP_LAST
do
5595 Mem
.WriteBoolean(FWeapon
[i
]);
5596 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5597 for i
:= WP_FIRST
to WP_LAST
do
5598 Mem
.WriteWord(FReloading
[i
]);
5600 if R_ITEM_BACKPACK
in FRulez
then
5605 // Íàëè÷èå êðàñíîãî êëþ÷à:
5606 if R_KEY_RED
in FRulez
then
5611 // Íàëè÷èå çåëåíîãî êëþ÷à:
5612 if R_KEY_GREEN
in FRulez
then
5617 // Íàëè÷èå ñèíåãî êëþ÷à:
5618 if R_KEY_BLUE
in FRulez
then
5623 // Íàëè÷èå áåðñåðêà:
5624 if R_BERSERK
in FRulez
then
5629 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5630 for i
:= MR_SUIT
to MR_MAX
do
5631 Mem
.WriteDWORD(FMegaRulez
[i
]);
5632 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5633 for i
:= T_RESPAWN
to T_FLAGCAP
do
5634 Mem
.WriteDWORD(FTime
[i
]);
5637 Mem
.WriteString(str
);
5647 procedure TPlayer
.LoadState(var Mem
: TBinMemoryReader
);
5657 // Ñèãíàòóðà èãðîêà:
5659 if sig
<> PLAYER_SIGNATURE
then // 'PLYR'
5661 raise EBinSizeError
.Create('TPlayer.LoadState: Wrong Player Signature');
5664 Mem
.ReadBoolean(FIamBot
);
5668 Mem
.ReadString(str
);
5669 if (Self
<> gPlayer1
) and (Self
<> gPlayer2
) then
5672 Mem
.ReadByte(FTeam
);
5674 Mem
.ReadBoolean(FLive
);
5675 // Èçðàñõîäîâàë ëè âñå æèçíè:
5676 Mem
.ReadBoolean(FNoRespawn
);
5680 FDirection
:= D_LEFT
5682 FDirection
:= D_RIGHT
;
5684 Mem
.ReadInt(FHealth
);
5686 Mem
.ReadByte(FLives
);
5688 Mem
.ReadInt(FArmor
);
5692 Mem
.ReadInt(FJetFuel
);
5696 Mem
.ReadInt(FKills
);
5698 Mem
.ReadInt(FMonsterKills
);
5700 Mem
.ReadInt(FFrags
);
5702 Mem
.ReadByte(FFragCombo
);
5703 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5704 Mem
.ReadDWORD(FLastFrag
);
5706 Mem
.ReadInt(FDeath
);
5707 // Êàêîé ôëàã íåñåò:
5708 Mem
.ReadByte(FFlag
);
5710 Mem
.ReadInt(FSecrets
);
5712 Mem
.ReadByte(FCurrWeap
);
5714 Mem
.ReadWord(FNextWeap
);
5716 Mem
.ReadByte(FNextWeapDelay
);
5717 // Âðåìÿ çàðÿäêè BFG:
5718 Mem
.ReadSmallInt(FBFGFireCounter
);
5720 Mem
.ReadInt(FDamageBuffer
);
5721 // Ïîñëåäíèé óäàðèâøèé:
5722 Mem
.ReadWord(FLastSpawnerUID
);
5723 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5724 Mem
.ReadByte(FLastHit
);
5726 Obj_LoadState(@FObj
, Mem
);
5727 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5728 for i
:= A_BULLETS
to A_HIGH
do
5729 Mem
.ReadWord(FAmmo
[i
]);
5730 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5731 for i
:= A_BULLETS
to A_HIGH
do
5732 Mem
.ReadWord(FMaxAmmo
[i
]);
5734 for i
:= WP_FIRST
to WP_LAST
do
5735 Mem
.ReadBoolean(FWeapon
[i
]);
5736 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5737 for i
:= WP_FIRST
to WP_LAST
do
5738 Mem
.ReadWord(FReloading
[i
]);
5742 Include(FRulez
, R_ITEM_BACKPACK
);
5743 // Íàëè÷èå êðàñíîãî êëþ÷à:
5746 Include(FRulez
, R_KEY_RED
);
5747 // Íàëè÷èå çåëåíîãî êëþ÷à:
5750 Include(FRulez
, R_KEY_GREEN
);
5751 // Íàëè÷èå ñèíåãî êëþ÷à:
5754 Include(FRulez
, R_KEY_BLUE
);
5755 // Íàëè÷èå áåðñåðêà:
5758 Include(FRulez
, R_BERSERK
);
5759 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5760 for i
:= MR_SUIT
to MR_MAX
do
5761 Mem
.ReadDWORD(FMegaRulez
[i
]);
5762 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5763 for i
:= T_RESPAWN
to T_FLAGCAP
do
5764 Mem
.ReadDWORD(FTime
[i
]);
5766 Mem
.ReadString(str
);
5768 Mem
.ReadByte(FColor
.R
);
5769 Mem
.ReadByte(FColor
.G
);
5770 Mem
.ReadByte(FColor
.B
);
5771 if Self
= gPlayer1
then
5773 str
:= gPlayer1Settings
.Model
;
5774 FColor
:= gPlayer1Settings
.Color
;
5776 if Self
= gPlayer2
then
5778 str
:= gPlayer2Settings
.Model
;
5779 FColor
:= gPlayer2Settings
.Color
;
5781 // Îáíîâëÿåì ìîäåëü èãðîêà:
5783 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
5784 FModel
.Color
:= TEAMCOLOR
[FTeam
]
5786 FModel
.Color
:= FColor
;
5789 procedure TPlayer
.AllRulez(Health
: Boolean);
5795 FHealth
:= PLAYER_HP_LIMIT
;
5796 FArmor
:= PLAYER_AP_LIMIT
;
5800 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
5801 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
5802 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5805 procedure TPlayer
.RestoreHealthArmor();
5807 FHealth
:= PLAYER_HP_LIMIT
;
5808 FArmor
:= PLAYER_AP_LIMIT
;
5811 procedure TPlayer
.FragCombo();
5815 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
5817 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
5819 if FFragCombo
< 5 then
5821 Param
:= FUID
or (FFragCombo
shl 16);
5822 if (FComboEvnt
>= Low(gDelayedEvents
)) and
5823 (FComboEvnt
<= High(gDelayedEvents
)) and
5824 gDelayedEvents
[FComboEvnt
].Pending
and
5825 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
5826 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
5828 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
5829 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
5832 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
5840 procedure TPlayer
.GiveItem(ItemType
: Byte);
5844 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
5846 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
5850 if FAir
< AIR_MAX
then
5857 if not (R_BERSERK
in FRulez
) then
5859 Include(FRulez
, R_BERSERK
);
5860 if FBFGFireCounter
< 1 then
5862 FCurrWeap
:= WEAPON_KASTET
;
5864 FModel
.SetWeapon(WEAPON_KASTET
);
5868 FBerserk
:= gTime
+30000;
5870 if FHealth
< PLAYER_HP_SOFT
then
5872 FHealth
:= PLAYER_HP_SOFT
;
5873 FBerserk
:= gTime
+30000;
5878 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
5880 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
5884 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
5886 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
5890 if FJetFuel
< JET_MAX
then
5892 FJetFuel
:= JET_MAX
;
5895 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
5896 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
5898 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
5899 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5901 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
5903 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
5905 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
5906 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5909 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
5910 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
5911 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
5912 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
5913 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
5914 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
5915 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
5916 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
5917 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
5919 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5920 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
5921 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5922 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
5923 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5924 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
5925 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5926 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
5927 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
5930 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
5931 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
5932 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
5933 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
5934 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
5936 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
5937 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
5938 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
5939 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
5940 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
5942 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5943 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5944 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5945 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5947 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
5950 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
5951 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
5952 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
5954 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
5955 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
5960 if g_Game_IsNet
and g_Game_IsServer
then
5961 MH_SEND_PlayerStats(FUID
);
5964 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
5969 if (Random(5) = 1) and (Times
= 1) then
5972 if BodyInLiquid(0, 0) then
5974 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
5975 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
5976 if Random(2) = 0 then
5977 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5979 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5983 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
5985 for i
:= 1 to Times
do
5987 Anim
:= TAnimation
.Create(id
, False, 3);
5989 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
5990 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
5996 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6001 if (Random(10) = 1) and (Times
= 1) then
6004 if g_Frames_Get(id
, 'FRAMES_FLAME') 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
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6017 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6019 FSawSound
.Pause(Enable
);
6020 FSawSoundIdle
.Pause(Enable
);
6021 FSawSoundHit
.Pause(Enable
);
6022 FSawSoundSelect
.Pause(Enable
);
6027 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6032 FObj
.Rect
:= PLAYER_CORPSERECT
;
6033 FModelName
:= ModelName
;
6038 FState
:= CORPSE_STATE_MESS
;
6039 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6043 FState
:= CORPSE_STATE_NORMAL
;
6044 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6048 destructor TCorpse
.Destroy();
6055 procedure TCorpse
.positionChanged (); begin end;
6057 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6061 if FState
= CORPSE_STATE_REMOVEME
then
6064 FDamage
:= FDamage
+ Value
;
6066 if FDamage
> 150 then
6068 if FAnimation
<> nil then
6073 FState
:= CORPSE_STATE_REMOVEME
;
6075 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6076 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6077 FModelName
, FColor
);
6078 // Çâóê ìÿñà îò òðóïà:
6079 pm
:= g_PlayerModel_Get(FModelName
);
6080 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6086 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6087 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6088 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6089 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6090 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6095 procedure TCorpse
.Draw();
6097 if FState
= CORPSE_STATE_REMOVEME
then
6100 if FAnimation
<> nil then
6101 FAnimation
.Draw(FObj
.X
, FObj
.Y
, M_NONE
);
6103 if FAnimationMask
<> nil then
6106 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, M_NONE
);
6113 procedure TCorpse
.Update();
6117 if FState
= CORPSE_STATE_REMOVEME
then
6120 if gTime
mod (GAME_TICK
*2) <> 0 then
6122 g_Obj_Move(@FObj
, True, True, True);
6123 positionChanged(); // this updates spatial accelerators
6127 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6128 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6130 st
:= g_Obj_Move(@FObj
, True, True, True);
6131 positionChanged(); // this updates spatial accelerators
6133 if WordBool(st
and MOVE_FALLOUT
) then
6135 FState
:= CORPSE_STATE_REMOVEME
;
6139 if FAnimation
<> nil then
6140 FAnimation
.Update();
6141 if FAnimationMask
<> nil then
6142 FAnimationMask
.Update();
6145 procedure TCorpse
.SaveState(var Mem
: TBinMemoryWriter
);
6154 sig
:= CORPSE_SIGNATURE
; // 'CORP'
6155 Mem
.WriteDWORD(sig
);
6157 Mem
.WriteByte(FState
);
6158 // Íàêîïëåííûé óðîí:
6159 Mem
.WriteByte(FDamage
);
6161 Mem
.WriteByte(FColor
.R
);
6162 Mem
.WriteByte(FColor
.G
);
6163 Mem
.WriteByte(FColor
.B
);
6165 Obj_SaveState(@FObj
, Mem
);
6166 // Åñòü ëè àíèìàöèÿ:
6167 anim
:= FAnimation
<> nil;
6168 Mem
.WriteBoolean(anim
);
6169 // Åñëè åñòü - ñîõðàíÿåì:
6171 FAnimation
.SaveState(Mem
);
6172 // Åñòü ëè ìàñêà àíèìàöèè:
6173 anim
:= FAnimationMask
<> nil;
6174 Mem
.WriteBoolean(anim
);
6175 // Åñëè åñòü - ñîõðàíÿåì:
6177 FAnimationMask
.SaveState(Mem
);
6180 procedure TCorpse
.LoadState(var Mem
: TBinMemoryReader
);
6190 if sig
<> CORPSE_SIGNATURE
then // 'CORP'
6192 raise EBinSizeError
.Create('TCorpse.LoadState: Wrong Corpse Signature');
6195 Mem
.ReadByte(FState
);
6196 // Íàêîïëåííûé óðîí:
6197 Mem
.ReadByte(FDamage
);
6199 Mem
.ReadByte(FColor
.R
);
6200 Mem
.ReadByte(FColor
.G
);
6201 Mem
.ReadByte(FColor
.B
);
6203 Obj_LoadState(@FObj
, Mem
);
6204 // Åñòü ëè àíèìàöèÿ:
6205 Mem
.ReadBoolean(anim
);
6206 // Åñëè åñòü - çàãðóæàåì:
6209 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6210 FAnimation
.LoadState(Mem
);
6212 // Åñòü ëè ìàñêà àíèìàöèè:
6213 Mem
.ReadBoolean(anim
);
6214 // Åñëè åñòü - çàãðóæàåì:
6217 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6218 FAnimationMask
.LoadState(Mem
);
6224 constructor TBot
.Create();
6231 FSpectator
:= False;
6238 for a
:= WP_FIRST
to WP_LAST
do
6240 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6241 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6242 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6246 destructor TBot
.Destroy();
6249 inherited Destroy();
6252 procedure TBot
.Draw();
6256 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6257 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6260 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6262 inherited Respawn(Silent
, Force
);
6265 FSelectedWeapon
:= FCurrWeap
;
6270 procedure TBot
.UpdateCombat();
6283 TTargetRecord
= array of TTarget
;
6285 function Compare(a
, b
: TTarget
): Integer;
6287 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6290 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6292 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6293 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6295 if a
.Dist
> b
.Dist
then // B áëèæå
6297 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6300 else // Ñòðàííî -> A
6305 a
, x1
, y1
, x2
, y2
: Integer;
6306 targets
: TTargetRecord
;
6308 Target
, BestTarget
: TTarget
;
6309 firew
, fireh
: Integer;
6313 vsPlayer
, vsMonster
, ok
: Boolean;
6316 function monsUpdate (mon
: TMonster
): Boolean;
6318 result
:= false; // don't stop
6319 if mon
.Live
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6321 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6323 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6324 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6326 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6327 if g_TraceVector(x1
, y1
, x2
, y2
) then
6329 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6330 SetLength(targets
, Length(targets
)+1);
6331 with targets
[High(targets
)] do
6338 Rect
:= mon
.Obj
.Rect
;
6339 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6340 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6341 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6350 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6351 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6353 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6354 if FCurrWeap
<> FSelectedWeapon
then
6357 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6358 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6360 RemoveAIFlag('NEEDFIRE');
6363 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6364 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6365 else PressKey(KEY_FIRE
);
6369 // Êîîðäèíàòû ñòâîëà:
6370 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6371 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6373 Target
.UID
:= FTargetUID
;
6376 if Target
.UID
<> 0 then
6377 begin // Öåëü åñòü - íàñòðàèâàåì
6378 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6381 tpla
:= g_Player_Get(Target
.UID
);
6385 if (@FObj
) <> nil then
6392 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6393 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6394 Target
.Rect
:= PLAYER_RECT
;
6395 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6396 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6397 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6398 Target
.IsPlayer
:= True;
6402 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6405 mon
:= g_Monsters_ByUID(Target
.UID
);
6408 Target
.X
:= mon
.Obj
.X
;
6409 Target
.Y
:= mon
.Obj
.Y
;
6411 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6412 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6413 Target
.Rect
:= mon
.Obj
.Rect
;
6414 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6415 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6416 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6417 Target
.IsPlayer
:= False;
6424 begin // Öåëè íåò - îáíóëÿåì
6429 Target
.Visible
:= False;
6430 Target
.Line
:= False;
6431 Target
.IsPlayer
:= False;
6436 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6437 if (not Target
.Line
) or (not Target
.Visible
) then
6441 for a
:= 0 to High(gPlayers
) do
6442 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].Live
) and
6443 (gPlayers
[a
].FUID
<> FUID
) and
6444 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6445 (not gPlayers
[a
].NoTarget
) and
6446 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6448 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6449 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6452 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6453 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6455 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6456 if g_TraceVector(x1
, y1
, x2
, y2
) then
6458 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6459 SetLength(targets
, Length(targets
)+1);
6460 with targets
[High(targets
)] do
6462 UID
:= gPlayers
[a
].FUID
;
6463 X
:= gPlayers
[a
].FObj
.X
;
6464 Y
:= gPlayers
[a
].FObj
.Y
;
6467 Rect
:= PLAYER_RECT
;
6468 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6469 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6470 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6478 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6481 // Åñëè åñòü âîçìîæíûå öåëè:
6482 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6483 if targets
<> nil then
6485 // Âûáèðàåì íàèëó÷øóþ öåëü:
6486 BestTarget
:= targets
[0];
6487 if Length(targets
) > 1 then
6488 for a
:= 1 to High(targets
) do
6489 if Compare(BestTarget
, targets
[a
]) = 1 then
6490 BestTarget
:= targets
[a
];
6492 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6493 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6494 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6496 Target
:= BestTarget
;
6498 if (Healthy() = 3) or ((Healthy() = 2)) then
6499 begin // Åñëè çäîðîâû - äîãîíÿåì
6500 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6501 SetAIFlag('GORIGHT', '1');
6502 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6503 SetAIFlag('GOLEFT', '1');
6506 begin // Åñëè ïîáèòû - óáåãàåì
6507 if ((RunDirection() = D_LEFT
) and (Target
.X
< FObj
.X
)) then
6508 SetAIFlag('GORIGHT', '1');
6509 if ((RunDirection() = D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6510 SetAIFlag('GOLEFT', '1');
6513 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6514 SelectWeapon(Abs(x1
-Target
.cX
));
6519 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6520 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6521 if Target
.UID
<> 0 then
6523 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6524 Target
.Y
+ Target
.Rect
.Y
) then
6525 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6526 if (Healthy() = 3) or ((Healthy() = 2)) then
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 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6536 if ((RunDirection() = D_LEFT
) and (Target
.X
< FObj
.X
)) then
6537 SetAIFlag('GORIGHT', '1');
6538 if ((RunDirection() = D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6539 SetAIFlag('GOLEFT', '1');
6543 begin // Öåëü ïîêà íà "ýêðàíå"
6544 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6545 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6546 FLastVisible
:= gTime
;
6547 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6548 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6550 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6551 SetAIFlag('GORIGHT', '1');
6552 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6553 SetAIFlag('GOLEFT', '1');
6557 // Âûáèðàåì óãîë ââåðõ:
6558 if FDirection
= D_LEFT
then
6559 angle
:= ANGLE_LEFTUP
6561 angle
:= ANGLE_RIGHTUP
;
6563 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6564 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6566 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6567 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6568 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6569 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6570 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6571 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6572 begin // òî íóæíî ñòðåëÿòü ââåðõ
6573 SetAIFlag('NEEDFIRE', '1');
6574 SetAIFlag('NEEDSEEUP', '1');
6577 // Âûáèðàåì óãîë âíèç:
6578 if FDirection
= D_LEFT
then
6579 angle
:= ANGLE_LEFTDOWN
6581 angle
:= ANGLE_RIGHTDOWN
;
6583 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6584 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6586 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6587 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6588 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6589 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6590 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6591 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6592 begin // òî íóæíî ñòðåëÿòü âíèç
6593 SetAIFlag('NEEDFIRE', '1');
6594 SetAIFlag('NEEDSEEDOWN', '1');
6597 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6598 if Target
.Visible
and
6599 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6600 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6602 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6603 if ((FDirection
= D_LEFT
) and (Target
.X
< FObj
.X
)) or
6604 ((FDirection
= D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6605 begin // òî íóæíî ñòðåëÿòü âïåðåä
6606 SetAIFlag('NEEDFIRE', '1');
6607 SetAIFlag('NEEDSEEDOWN', '');
6608 SetAIFlag('NEEDSEEUP', '');
6610 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6611 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6612 if GetRnd(FDifficult
.CloseJump
) then
6613 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6614 if Abs(FObj
.X
-Target
.X
) < 128 then
6618 if Random(a
) = 0 then
6619 SetAIFlag('NEEDJUMP', '1');
6623 // Åñëè öåëü âñå åùå åñòü:
6624 if Target
.UID
<> 0 then
6625 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
6626 Target
.UID
:= 0 // òî çàáûòü öåëü
6627 else // Åñëè âèäåëè íåäàâíî
6628 begin // íî öåëü óáèëè
6629 if Target
.IsPlayer
then
6630 begin // Öåëü - èãðîê
6631 pla
:= g_Player_Get(Target
.UID
);
6632 if (pla
= nil) or (not pla
.Live
) or pla
.NoTarget
or
6633 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6634 Target
.UID
:= 0; // òî çàáûòü öåëü
6637 begin // Öåëü - ìîíñòð
6638 mon
:= g_Monsters_ByUID(Target
.UID
);
6639 if (mon
= nil) or (not mon
.Live
) then
6640 Target
.UID
:= 0; // òî çàáûòü öåëü
6643 end; // if Target.UID <> 0
6645 FTargetUID
:= Target
.UID
;
6647 // Åñëè âîçìîæíûõ öåëåé íåò:
6648 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
6649 if targets
= nil then
6650 if GetAIFlag('ATTACKLEFT') <> '' then
6651 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
6652 RemoveAIFlag('ATTACKLEFT');
6654 SetAIFlag('NEEDJUMP', '1');
6656 if RunDirection() = D_RIGHT
then
6657 begin // Èäåì íå â òó ñòîðîíó
6658 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6659 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
6660 SetAIFlag('NEEDFIRE', '1');
6661 SetAIFlag('GOLEFT', '1');
6665 begin // Èäåì â íóæíóþ ñòîðîíó
6666 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6667 SetAIFlag('NEEDFIRE', '1');
6668 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6669 SetAIFlag('GORIGHT', '1');
6673 if GetAIFlag('ATTACKRIGHT') <> '' then
6674 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
6675 RemoveAIFlag('ATTACKRIGHT');
6677 SetAIFlag('NEEDJUMP', '1');
6679 if RunDirection() = D_LEFT
then
6680 begin // Èäåì íå â òó ñòîðîíó
6681 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6682 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
6683 SetAIFlag('NEEDFIRE', '1');
6684 SetAIFlag('GORIGHT', '1');
6689 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6690 SetAIFlag('NEEDFIRE', '1');
6691 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6692 SetAIFlag('GOLEFT', '1');
6696 //HACK! (does it belongs there?)
6697 RealizeCurrentWeapon();
6699 // Åñëè åñòü âîçìîæíûå öåëè:
6700 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
6701 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6702 for a
:= 0 to High(targets
) do
6704 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
6705 if GetRnd(FDifficult
.DiagFire
) then
6707 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
6708 if FDirection
= D_LEFT
then
6709 angle
:= ANGLE_LEFTUP
6711 angle
:= ANGLE_RIGHTUP
;
6713 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6714 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6716 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6717 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6718 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6719 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6720 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6722 SetAIFlag('NEEDFIRE', '1');
6723 SetAIFlag('NEEDSEEUP', '1');
6726 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
6727 if FDirection
= D_LEFT
then
6728 angle
:= ANGLE_LEFTDOWN
6730 angle
:= ANGLE_RIGHTDOWN
;
6732 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6733 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6735 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6736 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6737 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6738 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6739 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6741 SetAIFlag('NEEDFIRE', '1');
6742 SetAIFlag('NEEDSEEDOWN', '1');
6746 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
6747 if targets
[a
].Line
and targets
[a
].Visible
and
6748 (((FDirection
= D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
6749 ((FDirection
= D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
6751 SetAIFlag('NEEDFIRE', '1');
6756 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
6757 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
6758 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
6759 40+GetInterval(FDifficult
.Cover
, 40)) then
6760 SetAIFlag('NEEDJUMP', '1');
6762 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
6763 ammo
:= GetAmmoByWeapon(FCurrWeap
);
6764 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
6765 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
6767 SetAIFlag('SELECTWEAPON', '1');
6769 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
6770 if GetAIFlag('SELECTWEAPON') = '1' then
6773 RemoveAIFlag('SELECTWEAPON');
6777 procedure TBot
.Update();
6790 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
6791 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
6793 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
6795 if g_debug_BotAIOff
= 3 then
6805 RealizeCurrentWeapon();
6812 procedure TBot
.ReleaseKey(Key
: Byte);
6821 function TBot
.KeyPressed(Key
: Word): Boolean;
6823 Result
:= FKeys
[Key
].Pressed
;
6826 function TBot
.GetAIFlag(aName
: String20
): String20
;
6832 aName
:= LowerCase(aName
);
6834 if FAIFlags
<> nil then
6835 for a
:= 0 to High(FAIFlags
) do
6836 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6838 Result
:= FAIFlags
[a
].Value
;
6843 procedure TBot
.RemoveAIFlag(aName
: String20
);
6847 if FAIFlags
= nil then Exit
;
6849 aName
:= LowerCase(aName
);
6851 for a
:= 0 to High(FAIFlags
) do
6852 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6854 if a
<> High(FAIFlags
) then
6855 for b
:= a
to High(FAIFlags
)-1 do
6856 FAIFlags
[b
] := FAIFlags
[b
+1];
6858 SetLength(FAIFlags
, Length(FAIFlags
)-1);
6863 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
6871 aName
:= LowerCase(aName
);
6873 if FAIFlags
<> nil then
6874 for a
:= 0 to High(FAIFlags
) do
6875 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6881 if ok
then FAIFlags
[a
].Value
:= fValue
6884 SetLength(FAIFlags
, Length(FAIFlags
)+1);
6885 with FAIFlags
[High(FAIFlags
)] do
6893 procedure TBot
.UpdateMove
;
6895 procedure GoLeft(Time
: Word = 1);
6897 ReleaseKey(KEY_LEFT
);
6898 ReleaseKey(KEY_RIGHT
);
6899 PressKey(KEY_LEFT
, Time
);
6900 SetDirection(D_LEFT
);
6903 procedure GoRight(Time
: Word = 1);
6905 ReleaseKey(KEY_LEFT
);
6906 ReleaseKey(KEY_RIGHT
);
6907 PressKey(KEY_RIGHT
, Time
);
6908 SetDirection(D_RIGHT
);
6911 function Rnd(a
: Word): Boolean;
6913 Result
:= Random(a
) = 0;
6916 procedure Turn(Time
: Word = 1200);
6918 if RunDirection() = D_LEFT
then GoRight(Time
) else GoLeft(Time
);
6923 ReleaseKey(KEY_LEFT
);
6924 ReleaseKey(KEY_RIGHT
);
6927 function CanRunLeft(): Boolean;
6929 Result
:= not CollideLevel(-1, 0);
6932 function CanRunRight(): Boolean;
6934 Result
:= not CollideLevel(1, 0);
6937 function CanRun(): Boolean;
6939 if RunDirection() = D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
6942 procedure Jump(Time
: Word = 30);
6944 PressKey(KEY_JUMP
, Time
);
6947 function NearHole(): Boolean;
6951 { TODO 5 : Ëåñòíèöû }
6952 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6953 for x
:= 1 to PLAYER_RECT
.Width
do
6954 if (not StayOnStep(x
*sx
, 0)) and
6955 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6956 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6965 function BorderHole(): Boolean;
6969 { TODO 5 : Ëåñòíèöû }
6970 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6971 for x
:= 1 to PLAYER_RECT
.Width
do
6972 if (not StayOnStep(x
*sx
, 0)) and
6973 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6974 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6976 for xx
:= x
to x
+32 do
6977 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
6987 function NearDeepHole(): Boolean;
6993 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6996 for x
:= 1 to PLAYER_RECT
.Width
do
6997 if (not StayOnStep(x
*sx
, 0)) and
6998 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6999 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7001 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7003 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7008 end else Result
:= False;
7011 function OverDeepHole(): Boolean;
7018 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7020 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7027 function OnGround(): Boolean;
7029 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7032 function OnLadder(): Boolean;
7034 Result
:= FullInStep(0, 0);
7037 function BelowLadder(): Boolean;
7039 Result
:= (FullInStep(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7040 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7041 (FullInStep(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7042 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7045 function BelowLiftUp(): Boolean;
7047 Result
:= ((FullInLift(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7048 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7049 ((FullInLift(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7050 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7053 function OnTopLift(): Boolean;
7055 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7058 function CanJumpOver(): Boolean;
7062 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
7066 if not CollideLevel(sx
, 0) then Exit
;
7068 for y
:= 1 to BOT_MAXJUMP
do
7069 if CollideLevel(0, -y
) then Exit
else
7070 if not CollideLevel(sx
, -y
) then
7077 function CanJumpUp(Dist
: ShortInt): Boolean;
7084 if CollideLevel(Dist
, 0) then Exit
;
7087 for y
:= 0 to BOT_MAXJUMP
do
7088 if CollideLevel(Dist
, -y
) then
7097 for yy
:= y
+1 to BOT_MAXJUMP
do
7098 if not CollideLevel(Dist
, -yy
) then
7107 for y
:= 0 to BOT_MAXJUMP
do
7108 if CollideLevel(0, -y
) then
7116 if y
< yy
then Exit
;
7121 function IsSafeTrigger(): Boolean;
7126 if gTriggers
= nil then
7128 for a
:= 0 to High(gTriggers
) do
7129 if Collide(gTriggers
[a
].X
,
7132 gTriggers
[a
].Height
) and
7133 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7134 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7135 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7136 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7137 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7142 // Âîçìîæíî, íàæèìàåì êíîïêó:
7143 if Rnd(16) and IsSafeTrigger() then
7146 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7147 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7149 ReleaseKey(KEY_LEFT
);
7150 ReleaseKey(KEY_RIGHT
);
7154 // Èäåì âëåâî, åñëè íàäî áûëî:
7155 if GetAIFlag('GOLEFT') <> '' then
7157 RemoveAIFlag('GOLEFT');
7158 if CanRunLeft() then
7162 // Èäåì âïðàâî, åñëè íàäî áûëî:
7163 if GetAIFlag('GORIGHT') <> '' then
7165 RemoveAIFlag('GORIGHT');
7166 if CanRunRight() then
7170 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7171 if FObj
.X
< -32 then
7174 if FObj
.X
+32 > gMapInfo
.Width
then
7177 // Ïðûãàåì, åñëè íàäî áûëî:
7178 if GetAIFlag('NEEDJUMP') <> '' then
7181 RemoveAIFlag('NEEDJUMP');
7184 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7185 if GetAIFlag('NEEDSEEUP') <> '' then
7188 ReleaseKey(KEY_DOWN
);
7189 PressKey(KEY_UP
, 20);
7190 RemoveAIFlag('NEEDSEEUP');
7193 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7194 if GetAIFlag('NEEDSEEDOWN') <> '' then
7197 ReleaseKey(KEY_DOWN
);
7198 PressKey(KEY_DOWN
, 20);
7199 RemoveAIFlag('NEEDSEEDOWN');
7202 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7203 if GetAIFlag('GOINHOLE') <> '' then
7204 if not OnGround() then
7206 ReleaseKey(KEY_LEFT
);
7207 ReleaseKey(KEY_RIGHT
);
7208 RemoveAIFlag('GOINHOLE');
7209 SetAIFlag('FALLINHOLE', '1');
7212 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7213 if GetAIFlag('FALLINHOLE') <> '' then
7215 RemoveAIFlag('FALLINHOLE');
7217 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7218 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7219 if GetAIFlag('FALLINHOLE') = '' then
7220 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7226 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7228 CanJumpUp(IfThen(RunDirection() = D_LEFT
, -1, 1)*32) and
7232 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7233 if OnGround() and NearHole() then
7234 if NearDeepHole() then // Åñëè ýòî áåçäíà
7236 0..3: Turn(); // Áåæèì îáðàòíî
7237 4: Jump(); // Ïðûãàåì
7238 5: begin // Ïðûãàåì îáðàòíî
7243 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7244 if GetAIFlag('GOINHOLE') = '' then
7246 0: Turn(); // Íå íóæíî òóäà
7247 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7248 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7249 if BorderHole() then
7250 SetAIFlag('GOINHOLE', '1');
7253 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7254 if (not CanRun()) and OnGround() then
7256 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7257 if CanJumpOver() or OnLadder() then
7259 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7260 if Random(2) = 0 then
7262 if IsSafeTrigger() then
7268 // Îñòàëîñü ìàëî âîçäóõà:
7269 if FAir
< 36 * 2 then
7272 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7273 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7274 if BodyInAcid(0, 0) then
7278 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7280 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7281 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7284 {function TBot.NeedItem(Item: Byte): Byte;
7289 procedure TBot
.SelectWeapon(Dist
: Integer);
7293 function HaveAmmo(weapon
: Byte): Boolean;
7296 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7297 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7298 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7299 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7300 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7301 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7302 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7303 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7304 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7305 else Result
:= True;
7310 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7312 if Dist
> BOT_LONGDIST
then
7313 begin // Äàëüíèé áîé
7315 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7317 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7321 else //if Dist > BOT_UNSAFEDIST then
7322 begin // Áëèæíèé áîé
7324 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7326 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7333 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7335 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7341 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7343 Result
:= inherited PickItem(ItemType
, force
, remove
);
7345 if Result
then SetAIFlag('SELECTWEAPON', '1');
7348 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7350 Result
:= inherited Heal(value
, Soft
);
7353 function TBot
.Healthy(): Byte;
7355 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7356 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7357 else if (FHealth
> 50) then Result
:= 2
7358 else if (FHealth
> 20) then Result
:= 1
7362 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7364 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7365 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7368 procedure TBot
.OnDamage(Angle
: SmallInt);
7376 if (Angle
= 0) or (Angle
= 180) then
7379 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7380 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7382 pla
:= g_Player_Get(FLastSpawnerUID
);
7383 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7384 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7387 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7388 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7390 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7391 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7392 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7397 SetAIFlag('ATTACKLEFT', '1')
7399 SetAIFlag('ATTACKRIGHT', '1');
7403 function TBot
.RunDirection(): TDirection
;
7405 if Abs(Vel
.X
) >= 1 then
7407 if Vel
.X
> 0 then Result
:= D_RIGHT
else Result
:= D_LEFT
;
7409 Result
:= FDirection
;
7412 function TBot
.GetRnd(a
: Byte): Boolean;
7414 if a
= 0 then Result
:= False
7415 else if a
= 255 then Result
:= True
7416 else Result
:= Random(256) > 255-a
;
7419 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7421 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7424 procedure TBot
.SaveState(var Mem
: TBinMemoryWriter
);
7430 inherited SaveState(Mem
);
7432 // Âûáðàííîå îðóæèå:
7433 Mem
.WriteByte(FSelectedWeapon
);
7435 Mem
.WriteWord(FTargetUID
);
7436 // Âðåìÿ ïîòåðè öåëè:
7437 Mem
.WriteDWORD(FLastVisible
);
7438 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7439 dw
:= Length(FAIFlags
);
7442 for i
:= 0 to Integer(dw
)-1 do
7444 Mem
.WriteString(FAIFlags
[i
].Name
, 20);
7445 Mem
.WriteString(FAIFlags
[i
].Value
, 20);
7447 // Íàñòðîéêè ñëîæíîñòè:
7449 Mem
.WriteMemory(p
, SizeOf(TDifficult
));
7452 procedure TBot
.LoadState(var Mem
: TBinMemoryReader
);
7458 inherited LoadState(Mem
);
7460 // Âûáðàííîå îðóæèå:
7461 Mem
.ReadByte(FSelectedWeapon
);
7463 Mem
.ReadWord(FTargetUID
);
7464 // Âðåìÿ ïîòåðè öåëè:
7465 Mem
.ReadDWORD(FLastVisible
);
7466 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7468 SetLength(FAIFlags
, dw
);
7470 for i
:= 0 to Integer(dw
)-1 do
7472 Mem
.ReadString(FAIFlags
[i
].Name
);
7473 Mem
.ReadString(FAIFlags
[i
].Value
);
7475 // Íàñòðîéêè ñëîæíîñòè:
7476 Mem
.ReadMemory(p
, dw
);
7477 if dw
<> SizeOf(TDifficult
) then
7479 raise EBinSizeError
.Create('TBot.LoadState: Wrong FDifficult Size');
7481 FDifficult
:= TDifficult(p
^);