1 (* Copyright (C) DooM 2D:Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
22 e_graphics
, g_playermodel
, g_basic
, g_textures
,
23 g_weapons
, g_phys
, g_sound
, g_saveload
, MAPSTRUCT
,
56 AmmoLimits
: Array [0..1] of Array [A_BULLETS
..A_HIGH
] of Word =
57 ((200, 50, 50, 300, 100),
58 (400, 100, 100, 600, 200));
79 ANGLE_NONE
= Low(SmallInt);
81 CORPSE_STATE_REMOVEME
= 0;
82 CORPSE_STATE_NORMAL
= 1;
83 CORPSE_STATE_MESS
= 2;
85 PLAYER_RECT
: TRectWH
= (X
:15; Y
:12; Width
:34; Height
:52);
86 PLAYER_RECT_CX
= 15+(34 div 2);
87 PLAYER_RECT_CY
= 12+(52 div 2);
88 PLAYER_CORPSERECT
: TRectWH
= (X
:15; Y
:48; Width
:34; Height
:16);
91 PLAYER_HP_LIMIT
= 200;
93 PLAYER_AP_LIMIT
= 200;
96 PLAYER1_DEF_COLOR
: TRGB
= (R
:64; G
:175; B
:48);
97 PLAYER2_DEF_COLOR
: TRGB
= (R
:96; G
:96; B
:96);
113 TPlayerStatArray
= Array of TPlayerStat
;
115 TPlayerSavedState
= record
123 Ammo
: Array [A_BULLETS
..A_HIGH
] of Word;
124 MaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
125 Weapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
126 Rulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
135 TPlayer
= class (TObject
)
143 FDirection
: TDirection
;
151 FMonsterKills
: Integer;
157 FCanJetpack
: Boolean;
163 FNextWeapDelay
: Byte; // frames
164 FBFGFireCounter
: SmallInt;
165 FLastSpawnerUID
: Word;
169 FSpectatePlayer
: Integer;
170 FFirePainTime
: Integer;
173 FSavedState
: TPlayerSavedState
;
175 FModel
: TPlayerModel
;
178 FActionForce
: Boolean;
179 FActionChanged
: Boolean;
181 FFireAngle
: SmallInt;
183 FShellTimer
: Integer;
185 FSawSound
: TPlayableSound
;
186 FSawSoundIdle
: TPlayableSound
;
187 FSawSoundHit
: TPlayableSound
;
188 FSawSoundSelect
: TPlayableSound
;
189 FJetSoundOn
: TPlayableSound
;
190 FJetSoundOff
: TPlayableSound
;
191 FJetSoundFly
: TPlayableSound
;
195 FJustTeleported
: Boolean;
198 function CollideLevel(XInc
, YInc
: Integer): Boolean;
199 function StayOnStep(XInc
, YInc
: Integer): Boolean;
200 function HeadInLiquid(XInc
, YInc
: Integer): Boolean;
201 function BodyInLiquid(XInc
, YInc
: Integer): Boolean;
202 function BodyInAcid(XInc
, YInc
: Integer): Boolean;
203 function FullInLift(XInc
, YInc
: Integer): Integer;
204 {procedure CollideItem();}
205 procedure FlySmoke(Times
: DWORD
= 1);
206 procedure OnFireFlame(Times
: DWORD
= 1);
207 function GetAmmoByWeapon(Weapon
: Byte): Word;
208 procedure SetAction(Action
: Byte; Force
: Boolean = False);
209 procedure OnDamage(Angle
: SmallInt); virtual;
210 function firediry(): Integer;
212 procedure Run(Direction
: TDirection
);
213 procedure NextWeapon();
214 procedure PrevWeapon();
221 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
222 procedure resetWeaponQueue ();
223 function hasAmmoForWeapon (weapon
: Byte): Boolean;
226 FDamageBuffer
: Integer;
228 FAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
229 FMaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
230 FWeapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
231 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
233 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
234 FReloading
: Array [WP_FIRST
..WP_LAST
] of Word;
235 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
236 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
238 FPreferredTeam
: Byte;
241 FWantsInGame
: Boolean;
245 FActualModelName
: string;
252 constructor Create(); virtual;
253 destructor Destroy(); override;
254 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
255 function GetRespawnPoint(): Byte;
256 procedure PressKey(Key
: Byte; Time
: Word = 1);
257 procedure ReleaseKeys();
258 procedure SetModel(ModelName
: String);
259 procedure SetColor(Color
: TRGB
);
260 procedure SetWeapon(W
: Byte);
261 function IsKeyPressed(K
: Byte): Boolean;
262 function GetKeys(): Byte;
263 function PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean; virtual;
264 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
265 function Collide(Panel
: TPanel
): Boolean; overload
;
266 function Collide(X
, Y
: Integer): Boolean; overload
;
267 procedure SetDirection(Direction
: TDirection
);
268 procedure GetSecret();
269 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
271 procedure Push(vx
, vy
: Integer);
272 procedure ChangeModel(ModelName
: String);
273 procedure SwitchTeam
;
274 procedure ChangeTeam(Team
: Byte);
276 function GetFlag(Flag
: Byte): Boolean;
277 procedure SetFlag(Flag
: Byte);
278 function DropFlag(): Boolean;
279 procedure AllRulez(Health
: Boolean);
280 procedure RestoreHealthArmor();
281 procedure FragCombo();
282 procedure GiveItem(ItemType
: Byte);
283 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
284 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
285 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
286 procedure MakeBloodSimple(Count
: Word);
287 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
288 procedure Reset(Force
: Boolean);
289 procedure Spectate(NoMove
: Boolean = False);
290 procedure SwitchNoClip
;
291 procedure SoftReset();
292 procedure Draw(); virtual;
293 procedure DrawPain();
294 procedure DrawPickup();
295 procedure DrawRulez();
297 procedure DrawBubble();
299 procedure Update(); virtual;
300 procedure RememberState();
301 procedure RecallState();
302 procedure SaveState(var Mem
: TBinMemoryWriter
); virtual;
303 procedure LoadState(var Mem
: TBinMemoryReader
); virtual;
304 procedure PauseSounds(Enable
: Boolean);
305 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
306 procedure DoLerp(Level
: Integer = 2);
307 procedure SetLerp(XTo
, YTo
: Integer);
308 procedure QueueWeaponSwitch(Weapon
: Byte);
309 procedure RealizeCurrentWeapon();
311 procedure JetpackOff
;
312 procedure CatchFire(Attacker
: Word);
314 //WARNING! this does nothing for now, but still call it!
315 procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right!
317 property Name
: String read FName write FName
;
318 property Model
: TPlayerModel read FModel
;
319 property Health
: Integer read FHealth write FHealth
;
320 property Lives
: Byte read FLives write FLives
;
321 property Armor
: Integer read FArmor write FArmor
;
322 property Air
: Integer read FAir write FAir
;
323 property JetFuel
: Integer read FJetFuel write FJetFuel
;
324 property Frags
: Integer read FFrags write FFrags
;
325 property Death
: Integer read FDeath write FDeath
;
326 property Kills
: Integer read FKills write FKills
;
327 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
328 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
329 property Secrets
: Integer read FSecrets
;
330 property GodMode
: Boolean read FGodMode write FGodMode
;
331 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
332 property NoReload
: Boolean read FNoReload write FNoReload
;
333 property Live
: Boolean read FLive write FLive
;
334 property Flag
: Byte read FFlag
;
335 property Team
: Byte read FTeam write FTeam
;
336 property Direction
: TDirection read FDirection
;
337 property GameX
: Integer read FObj
.X write FObj
.X
;
338 property GameY
: Integer read FObj
.Y write FObj
.Y
;
339 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
340 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
341 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
342 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
343 property Vel
: TPoint2i read FObj
.Vel
;
344 property Obj
: TObj read FObj
;
345 property IncCam
: Integer read FIncCam write FIncCam
;
346 property UID
: Word read FUID write FUID
;
347 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
348 property NetTime
: LongWord read FNetTime write FNetTime
;
358 WeaponPrior
: Array [WP_FIRST
..WP_LAST
] of Byte;
359 CloseWeaponPrior
: Array [WP_FIRST
..WP_LAST
] of Byte;
360 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
368 TBot
= class (TPlayer
)
370 FSelectedWeapon
: Byte;
373 FAIFlags
: Array of TAIFlag
;
374 FDifficult
: TDifficult
;
376 function GetRnd(a
: Byte): Boolean;
377 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
378 function RunDirection(): TDirection
;
379 function FullInStep(XInc
, YInc
: Integer): Boolean;
380 //function NeedItem(Item: Byte): Byte;
381 procedure SelectWeapon(Dist
: Integer);
382 procedure SetAIFlag(aName
, fValue
: String20
);
383 function GetAIFlag(aName
: String20
): String20
;
384 procedure RemoveAIFlag(aName
: String20
);
385 function Healthy(): Byte;
386 procedure UpdateMove();
387 procedure UpdateCombat();
388 function KeyPressed(Key
: Word): Boolean;
389 procedure ReleaseKey(Key
: Byte);
390 function TargetOnScreen(TX
, TY
: Integer): Boolean;
391 procedure OnDamage(Angle
: SmallInt); override;
394 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
395 constructor Create(); override;
396 destructor Destroy(); override;
397 procedure Draw(); override;
398 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
399 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
400 procedure Update(); override;
401 procedure SaveState(var Mem
: TBinMemoryWriter
); override;
402 procedure LoadState(var Mem
: TBinMemoryReader
); override;
413 procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right!
426 procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right!
429 TCorpse
= class (TObject
)
437 FAnimation
: TAnimation
;
438 FAnimationMask
: TAnimation
;
441 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
442 destructor Destroy(); override;
443 procedure Damage(Value
: Word; vx
, vy
: Integer);
446 procedure SaveState(var Mem
: TBinMemoryWriter
);
447 procedure LoadState(var Mem
: TBinMemoryReader
);
449 procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right!
451 property Obj
: TObj read FObj
;
452 property State
: Byte read FState
;
453 property Mess
: Boolean read FMess
;
456 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
462 gPlayers
: Array of TPlayer
;
463 gCorpses
: Array of TCorpse
;
464 gGibs
: Array of TGib
;
465 gShells
: Array of TShell
;
466 gTeamStat
: TTeamStat
;
467 gFly
: Boolean = False;
468 gAimLine
: Boolean = False;
469 gChatBubble
: Byte = 0;
473 MAX_RUNVEL
: Integer = 8;
474 VEL_JUMP
: Integer = 10;
475 SHELL_TIMEOUT
: Cardinal = 60000;
477 function Lerp(X
, Y
, Factor
: Integer): Integer;
479 procedure g_Gibs_SetMax(Count
: Word);
480 function g_Gibs_GetMax(): Word;
481 procedure g_Corpses_SetMax(Count
: Word);
482 function g_Corpses_GetMax(): Word;
483 procedure g_Shells_SetMax(Count
: Word);
484 function g_Shells_GetMax(): Word;
486 procedure g_Player_Init();
487 procedure g_Player_Free();
488 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
489 function g_Player_CreateFromState(var Mem
: TBinMemoryReader
): Word;
490 procedure g_Player_Remove(UID
: Word);
491 procedure g_Player_ResetTeams();
492 procedure g_Player_UpdateAll();
493 procedure g_Player_DrawAll();
494 procedure g_Player_DrawDebug(p
: TPlayer
);
495 procedure g_Player_DrawHealth();
496 procedure g_Player_RememberAll();
497 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
498 function g_Player_Get(UID
: Word): TPlayer
;
499 function g_Player_GetCount(): Byte;
500 function g_Player_GetStats(): TPlayerStatArray
;
501 function g_Player_ValidName(Name
: String): Boolean;
502 procedure g_Player_CreateCorpse(Player
: TPlayer
);
503 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
504 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
505 procedure g_Player_UpdatePhysicalObjects();
506 procedure g_Player_DrawCorpses();
507 procedure g_Player_DrawShells();
508 procedure g_Player_RemoveAllCorpses();
509 procedure g_Player_Corpses_SaveState(var Mem
: TBinMemoryWriter
);
510 procedure g_Player_Corpses_LoadState(var Mem
: TBinMemoryReader
);
511 procedure g_Bot_Add(Team
, Difficult
: Byte);
512 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1);
513 procedure g_Bot_MixNames();
514 procedure g_Bot_RemoveAll();
519 e_log
, g_map
, g_items
, g_console
, SysUtils
, g_gfx
, Math
,
520 g_options
, g_triggers
, g_menu
, MAPDEF
, g_game
,
521 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
, g_net
, g_netmsg
;
531 diag_precision
: Byte;
535 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
536 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
537 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
541 TIME_RESPAWN1
= 1500;
542 TIME_RESPAWN2
= 2000;
543 TIME_RESPAWN3
= 3000;
546 JET_MAX
= 540; // ~30 sec
547 PLAYER_SUIT_TIME
= 30000;
548 PLAYER_INVUL_TIME
= 30000;
549 PLAYER_INVIS_TIME
= 35000;
550 FRAG_COMBO_TIME
= 3000;
554 ANGLE_RIGHTDOWN
= -35;
556 ANGLE_LEFTDOWN
= -145;
557 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
558 WEAPONPOINT
: Array [TDirection
] of TPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
561 BOT_UNSAFEDIST
= 128;
562 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
564 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
565 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
566 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
567 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
568 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
569 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
570 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
571 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
572 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
573 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
574 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
575 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
576 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
577 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
578 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
579 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
580 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
581 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
582 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
583 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
584 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
585 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
586 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
587 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
588 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
589 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
591 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
592 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
594 BOTNAMES_FILENAME
= 'botnames.txt';
595 BOTLIST_FILENAME
= 'botlist.txt';
599 MaxCorpses
: Word = 20;
600 MaxShells
: Word = 300;
601 CurrentGib
: Integer = 0;
602 CurrentShell
: Integer = 0;
603 BotNames
: Array of String;
604 BotList
: Array of TBotProfile
;
607 procedure TGib
.positionChanged (); begin end;
608 procedure TShell
.positionChanged (); begin end;
611 function Lerp(X
, Y
, Factor
: Integer): Integer;
613 Result
:= X
+ ((Y
- X
) div Factor
);
616 function SameTeam(UID1
, UID2
: Word): Boolean;
620 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
621 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
623 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
625 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
626 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
628 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
631 procedure g_Gibs_SetMax(Count
: Word);
634 SetLength(gGibs
, Count
);
636 if CurrentGib
>= Count
then
640 function g_Gibs_GetMax(): Word;
645 procedure g_Shells_SetMax(Count
: Word);
648 SetLength(gShells
, Count
);
650 if CurrentShell
>= Count
then
654 function g_Shells_GetMax(): Word;
660 procedure g_Corpses_SetMax(Count
: Word);
663 SetLength(gCorpses
, Count
);
666 function g_Corpses_GetMax(): Word;
668 Result
:= MaxCorpses
;
671 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
681 // Åñòü ëè ìåñòî â gPlayers:
682 if gPlayers
<> nil then
683 for a
:= 0 to High(gPlayers
) do
684 if gPlayers
[a
] = nil then
690 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
693 SetLength(gPlayers
, Length(gPlayers
)+1);
697 // Ñîçäàåì îáúåêò èãðîêà:
699 gPlayers
[a
] := TBot
.Create()
701 gPlayers
[a
] := TPlayer
.Create();
704 gPlayers
[a
].FActualModelName
:= ModelName
;
705 gPlayers
[a
].SetModel(ModelName
);
707 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
708 if gPlayers
[a
].FModel
= nil then
712 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
716 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
717 if Random(2) = 0 then
721 gPlayers
[a
].FPreferredTeam
:= Team
;
723 case gGameSettings
.GameMode
of
724 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
726 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
728 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
731 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
732 gPlayers
[a
].FColor
:= Color
;
733 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
734 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
736 gPlayers
[a
].FModel
.Color
:= Color
;
738 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
739 gPlayers
[a
].FLive
:= False;
741 Result
:= gPlayers
[a
].FUID
;
744 function g_Player_CreateFromState(var Mem
: TBinMemoryReader
): Word;
757 if sig
<> PLAYER_SIGNATURE
then // 'PLYR'
759 raise EBinSizeError
.Create('g_Player_CreateFromState: Wrong Player Signature');
763 Mem
.ReadBoolean(Bot
);
768 // Åñòü ëè ìåñòî â gPlayers:
769 if gPlayers
<> nil then
770 for a
:= 0 to High(gPlayers
) do
771 if gPlayers
[a
] = nil then
777 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
780 SetLength(gPlayers
, Length(gPlayers
)+1);
784 // Ñîçäàåì îáúåêò èãðîêà:
786 gPlayers
[a
] := TBot
.Create()
788 gPlayers
[a
] := TPlayer
.Create();
789 gPlayers
[a
].FIamBot
:= Bot
;
790 gPlayers
[a
].FPhysics
:= True;
793 Mem
.ReadWord(gPlayers
[a
].FUID
);
795 Mem
.ReadString(gPlayers
[a
].FName
);
797 Mem
.ReadByte(gPlayers
[a
].FTeam
);
798 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
800 Mem
.ReadBoolean(gPlayers
[a
].FLive
);
801 // Èçðàñõîäîâàë ëè âñå æèçíè:
802 Mem
.ReadBoolean(gPlayers
[a
].FNoRespawn
);
806 gPlayers
[a
].FDirection
:= D_LEFT
808 gPlayers
[a
].FDirection
:= D_RIGHT
;
810 Mem
.ReadInt(gPlayers
[a
].FHealth
);
812 Mem
.ReadByte(gPlayers
[a
].FLives
);
814 Mem
.ReadInt(gPlayers
[a
].FArmor
);
816 Mem
.ReadInt(gPlayers
[a
].FAir
);
818 Mem
.ReadInt(gPlayers
[a
].FJetFuel
);
820 Mem
.ReadInt(gPlayers
[a
].FPain
);
822 Mem
.ReadInt(gPlayers
[a
].FKills
);
824 Mem
.ReadInt(gPlayers
[a
].FMonsterKills
);
826 Mem
.ReadInt(gPlayers
[a
].FFrags
);
828 Mem
.ReadByte(gPlayers
[a
].FFragCombo
);
829 // Âðåìÿ ïîñëåäíåãî ôðàãà:
830 Mem
.ReadDWORD(gPlayers
[a
].FLastFrag
);
832 Mem
.ReadInt(gPlayers
[a
].FDeath
);
834 Mem
.ReadByte(gPlayers
[a
].FFlag
);
836 Mem
.ReadInt(gPlayers
[a
].FSecrets
);
838 Mem
.ReadByte(gPlayers
[a
].FCurrWeap
);
839 // Ñëåäóþùåå æåëàåìîå îðóæèå:
840 Mem
.ReadWord(gPlayers
[a
].FNextWeap
);
842 Mem
.ReadByte(gPlayers
[a
].FNextWeapDelay
);
843 // Âðåìÿ çàðÿäêè BFG:
844 Mem
.ReadSmallInt(gPlayers
[a
].FBFGFireCounter
);
846 Mem
.ReadInt(gPlayers
[a
].FDamageBuffer
);
847 // Ïîñëåäíèé óäàðèâøèé:
848 Mem
.ReadWord(gPlayers
[a
].FLastSpawnerUID
);
849 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
850 Mem
.ReadByte(gPlayers
[a
].FLastHit
);
852 Obj_LoadState(@gPlayers
[a
].FObj
, Mem
);
853 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
854 for i
:= A_BULLETS
to A_HIGH
do
855 Mem
.ReadWord(gPlayers
[a
].FAmmo
[i
]);
856 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
857 for i
:= A_BULLETS
to A_HIGH
do
858 Mem
.ReadWord(gPlayers
[a
].FMaxAmmo
[i
]);
860 for i
:= WP_FIRST
to WP_LAST
do
861 Mem
.ReadBoolean(gPlayers
[a
].FWeapon
[i
]);
862 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
863 for i
:= WP_FIRST
to WP_LAST
do
864 Mem
.ReadWord(gPlayers
[a
].FReloading
[i
]);
868 Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
869 // Íàëè÷èå êðàñíîãî êëþ÷à:
872 Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
873 // Íàëè÷èå çåëåíîãî êëþ÷à:
876 Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
877 // Íàëè÷èå ñèíåãî êëþ÷à:
880 Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
884 Include(gPlayers
[a
].FRulez
, R_BERSERK
);
885 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
886 for i
:= MR_SUIT
to MR_MAX
do
887 Mem
.ReadDWORD(gPlayers
[a
].FMegaRulez
[i
]);
888 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
889 for i
:= T_RESPAWN
to T_FLAGCAP
do
890 Mem
.ReadDWORD(gPlayers
[a
].FTime
[i
]);
893 Mem
.ReadString(gPlayers
[a
].FActualModelName
);
895 Mem
.ReadByte(gPlayers
[a
].FColor
.R
);
896 Mem
.ReadByte(gPlayers
[a
].FColor
.G
);
897 Mem
.ReadByte(gPlayers
[a
].FColor
.B
);
898 // Îáíîâëÿåì ìîäåëü èãðîêà:
899 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
901 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
902 if gPlayers
[a
].FModel
= nil then
906 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
910 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
911 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
912 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
914 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
916 Result
:= gPlayers
[a
].FUID
;
919 procedure g_Player_ResetTeams();
923 if g_Game_IsClient
then
925 if gPlayers
= nil then
927 for a
:= Low(gPlayers
) to High(gPlayers
) do
928 if gPlayers
[a
] <> nil then
929 case gGameSettings
.GameMode
of
931 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
933 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
934 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
935 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
938 gPlayers
[a
].ChangeTeam(TEAM_RED
)
940 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
943 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
947 procedure g_Bot_Add(Team
, Difficult
: Byte);
950 _name
, _model
: String;
953 if not g_Game_IsServer
then Exit
;
955 // Ñïèñîê íàçâàíèé ìîäåëåé:
956 m
:= g_PlayerModel_GetNames();
961 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
962 Team
:= TEAM_COOP
// COOP
964 if gGameSettings
.GameMode
= GM_DM
then
965 Team
:= TEAM_NONE
// DM
967 if Team
= TEAM_NONE
then // CTF / TDM
969 // Àâòîáàëàíñ êîìàíä:
973 for a
:= 0 to High(gPlayers
) do
974 if gPlayers
[a
] <> nil then
976 if gPlayers
[a
].Team
= TEAM_RED
then
979 if gPlayers
[a
].Team
= TEAM_BLUE
then
989 if Random(2) = 0 then
995 // Âûáèðàåì áîòó èìÿ:
997 if BotNames
<> nil then
998 for a
:= 0 to High(BotNames
) do
999 if g_Player_ValidName(BotNames
[a
]) then
1001 _name
:= BotNames
[a
];
1005 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
1008 _name
:= Format('DFBOT%.2d', [Random(100)]);
1009 until g_Player_ValidName(_name
);
1011 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1012 _model
:= m
[Random(Length(m
))];
1015 with g_Player_Get(g_Player_Create(_model
,
1016 _RGB(Min(Random(9)*32, 255),
1017 Min(Random(9)*32, 255),
1018 Min(Random(9)*32, 255)),
1019 Team
, True)) as TBot
do
1024 1: FDifficult
:= DIFFICULT_EASY
;
1025 2: FDifficult
:= DIFFICULT_MEDIUM
;
1026 else FDifficult
:= DIFFICULT_HARD
;
1029 for a
:= WP_FIRST
to WP_LAST
do
1031 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1032 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1033 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1036 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1038 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1039 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1044 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1);
1047 _name
, _model
: String;
1050 if not g_Game_IsServer
then Exit
;
1052 // Ñïèñîê íàçâàíèé ìîäåëåé:
1053 m
:= g_PlayerModel_GetNames();
1058 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1059 Team
:= TEAM_COOP
// COOP
1061 if gGameSettings
.GameMode
= GM_DM
then
1062 Team
:= TEAM_NONE
// DM
1064 if Team
= TEAM_NONE
then
1065 Team
:= BotList
[num
].team
; // CTF / TDM
1067 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1068 lName
:= AnsiLowerCase(lName
);
1069 if (num
< 0) or (num
> Length(BotList
)-1) then
1071 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1072 for a
:= 0 to High(BotList
) do
1073 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1082 _name
:= BotList
[num
].name
;
1083 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1084 if not g_Player_ValidName(_name
) then
1086 _name
:= Format('DFBOT%.2d', [Random(100)]);
1087 until g_Player_ValidName(_name
);
1090 _model
:= BotList
[num
].model
;
1091 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1092 if not InSArray(_model
, m
) then
1093 _model
:= m
[Random(Length(m
))];
1096 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1100 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1101 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1102 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1103 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1104 FDifficult
.Cover
:= BotList
[num
].cover
;
1105 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1107 for a
:= WP_FIRST
to WP_LAST
do
1109 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1110 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1111 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1114 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1116 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1120 procedure g_Bot_RemoveAll();
1124 if not g_Game_IsServer
then Exit
;
1125 if gPlayers
= nil then Exit
;
1127 for a
:= 0 to High(gPlayers
) do
1128 if gPlayers
[a
] <> nil then
1129 if gPlayers
[a
] is TBot
then
1131 gPlayers
[a
].Lives
:= 0;
1132 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1133 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1134 g_Player_Remove(gPlayers
[a
].FUID
);
1140 procedure g_Bot_MixNames();
1145 if BotNames
<> nil then
1146 for a
:= 0 to High(BotNames
) do
1148 b
:= Random(Length(BotNames
));
1150 Botnames
[a
] := BotNames
[b
];
1155 procedure g_Player_Remove(UID
: Word);
1159 if gPlayers
= nil then Exit
;
1161 if g_Game_IsServer
and g_Game_IsNet
then
1162 MH_SEND_PlayerDelete(UID
);
1164 for i
:= 0 to High(gPlayers
) do
1165 if gPlayers
[i
] <> nil then
1166 if gPlayers
[i
].FUID
= UID
then
1168 if gPlayers
[i
] is TPlayer
then
1169 TPlayer(gPlayers
[i
]).Free()
1171 TBot(gPlayers
[i
]).Free();
1177 procedure g_Player_Init();
1187 if not FileExists(DataDir
+ BOTNAMES_FILENAME
) then
1190 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1191 AssignFile(F
, DataDir
+ BOTNAMES_FILENAME
);
1202 SetLength(BotNames
, Length(BotNames
)+1);
1203 BotNames
[High(BotNames
)] := s
;
1211 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1212 config
:= TConfig
.CreateFile(DataDir
+ BOTLIST_FILENAME
);
1216 while config
.SectionExists(IntToStr(a
)) do
1218 SetLength(BotList
, Length(BotList
)+1);
1220 with BotList
[High(BotList
)] do
1223 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1225 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1227 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1232 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1233 color
.R
:= StrToIntDef(sa
[0], 0);
1234 color
.G
:= StrToIntDef(sa
[1], 0);
1235 color
.B
:= StrToIntDef(sa
[2], 0);
1236 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1237 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1238 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1239 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1240 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1241 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1242 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1243 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1244 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1245 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1246 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1247 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1248 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1249 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1250 if Length(sa
) = 10 then
1252 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1253 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1254 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1255 if Length(sa
) = 10 then
1257 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1259 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1260 if Length(sa) = 10 then
1262 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1271 procedure g_Player_Free();
1275 if gPlayers
<> nil then
1277 for i
:= 0 to High(gPlayers
) do
1278 if gPlayers
[i
] <> nil then
1280 if gPlayers
[i
] is TPlayer
then
1281 TPlayer(gPlayers
[i
]).Free()
1283 TBot(gPlayers
[i
]).Free();
1294 procedure g_Player_UpdateAll();
1298 if gPlayers
= nil then Exit
;
1300 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1301 for i
:= 0 to High(gPlayers
) do
1303 if gPlayers
[i
] <> nil then
1305 if gPlayers
[i
] is TPlayer
then
1307 gPlayers
[i
].Update();
1308 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1312 // bot updates weapons in `UpdateCombat()`
1313 TBot(gPlayers
[i
]).Update();
1317 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1320 procedure g_Player_DrawAll();
1324 if gPlayers
= nil then Exit
;
1326 for i
:= 0 to High(gPlayers
) do
1327 if gPlayers
[i
] <> nil then
1328 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1329 else TBot(gPlayers
[i
]).Draw();
1332 procedure g_Player_DrawDebug(p
: TPlayer
);
1336 if p
= nil then Exit
;
1337 if (@p
.FObj
) = nil then Exit
;
1339 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1341 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1342 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1343 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1344 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1345 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1346 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1349 procedure g_Player_DrawHealth();
1354 if gPlayers
= nil then Exit
;
1355 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1357 for i
:= 0 to High(gPlayers
) do
1358 if gPlayers
[i
] <> nil then
1360 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1361 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1362 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1363 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1364 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1365 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1369 function g_Player_Get(UID
: Word): TPlayer
;
1375 if gPlayers
= nil then
1378 for a
:= 0 to High(gPlayers
) do
1379 if gPlayers
[a
] <> nil then
1380 if gPlayers
[a
].FUID
= UID
then
1382 Result
:= gPlayers
[a
];
1387 function g_Player_GetCount(): Byte;
1393 if gPlayers
= nil then
1396 for a
:= 0 to High(gPlayers
) do
1397 if gPlayers
[a
] <> nil then
1398 Result
:= Result
+ 1;
1401 function g_Player_GetStats(): TPlayerStatArray
;
1407 if gPlayers
= nil then Exit
;
1409 for a
:= 0 to High(gPlayers
) do
1410 if gPlayers
[a
] <> nil then
1412 SetLength(Result
, Length(Result
)+1);
1413 with Result
[High(Result
)] do
1415 Ping
:= gPlayers
[a
].FPing
;
1416 Loss
:= gPlayers
[a
].FLoss
;
1417 Name
:= gPlayers
[a
].FName
;
1418 Team
:= gPlayers
[a
].FTeam
;
1419 Frags
:= gPlayers
[a
].FFrags
;
1420 Deaths
:= gPlayers
[a
].FDeath
;
1421 Kills
:= gPlayers
[a
].FKills
;
1422 Color
:= gPlayers
[a
].FModel
.Color
;
1423 Lives
:= gPlayers
[a
].FLives
;
1424 Spectator
:= gPlayers
[a
].FSpectator
;
1429 procedure g_Player_RememberAll
;
1433 for i
:= Low(gPlayers
) to High(gPlayers
) do
1434 if (gPlayers
[i
] <> nil) and gPlayers
[i
].Live
then
1435 gPlayers
[i
].RememberState
;
1438 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1442 gTeamStat
[TEAM_RED
].Goals
:= 0;
1443 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1445 if gPlayers
<> nil then
1446 for i
:= 0 to High(gPlayers
) do
1447 if gPlayers
[i
] <> nil then
1449 gPlayers
[i
].Reset(Force
);
1451 if gPlayers
[i
] is TPlayer
then
1453 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1454 gPlayers
[i
].Respawn(Silent
)
1456 gPlayers
[i
].Spectate();
1459 TBot(gPlayers
[i
]).Respawn(Silent
);
1463 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1470 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1475 if (FHealth
>= -50) or (gGibsCount
= 0) then
1477 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1481 for find_id
:= 0 to High(gCorpses
) do
1482 if gCorpses
[find_id
] = nil then
1489 find_id
:= Random(Length(gCorpses
));
1491 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1492 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1493 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1494 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1497 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1498 FObj
.Y
+ PLAYER_RECT_CY
,
1499 FModel
.Name
, FModel
.Color
);
1503 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1507 if (gShells
= nil) or (Length(gShells
) = 0) then
1510 with gShells
[CurrentShell
] do
1516 if T
= SHELL_BULLET
then
1518 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1522 Obj
.Rect
.Width
:= 4;
1523 Obj
.Rect
.Height
:= 2;
1527 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1531 Obj
.Rect
.Width
:= 7;
1532 Obj
.Rect
.Height
:= 3;
1538 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1539 positionChanged(); // this updates spatial accelerators
1540 RAngle
:= Random(360);
1541 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1543 if CurrentShell
>= High(gShells
) then
1550 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1553 GibsArray
: TGibsArray
;
1555 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1557 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1560 for a
:= 0 to High(GibsArray
) do
1561 with gGibs
[CurrentGib
] do
1564 ID
:= GibsArray
[a
].ID
;
1565 MaskID
:= GibsArray
[a
].MaskID
;
1568 Obj
.Rect
:= GibsArray
[a
].Rect
;
1569 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1570 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1571 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1572 positionChanged(); // this updates spatial accelerators
1573 RAngle
:= Random(360);
1575 if gBloodCount
> 0 then
1576 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1577 Random(48), Random(48), 150, 0, 0);
1579 if CurrentGib
>= High(gGibs
) then
1586 procedure g_Player_UpdatePhysicalObjects();
1592 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1597 if T
= SHELL_BULLET
then
1598 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1600 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1605 if gGibs
<> nil then
1606 for i
:= 0 to High(gGibs
) do
1607 if gGibs
[i
].Live
then
1611 mr
:= g_Obj_Move(@Obj
, True, False, True);
1612 positionChanged(); // this updates spatial accelerators
1614 if WordBool(mr
and MOVE_FALLOUT
) then
1620 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1621 if WordBool(mr
and MOVE_HITWALL
) then
1622 Obj
.Vel
.X
:= -(vel
.X
div 2);
1623 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1624 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1626 if (Obj
.Vel
.X
>= 0) then
1628 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1629 if RAngle
>= 360 then
1630 RAngle
:= RAngle
mod 360;
1631 end else begin // Counter-clockwise
1632 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1634 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1637 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1638 if gTime
mod (GAME_TICK
*3) = 0 then
1639 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1643 if gCorpses
<> nil then
1644 for i
:= 0 to High(gCorpses
) do
1645 if gCorpses
[i
] <> nil then
1646 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1652 gCorpses
[i
].Update();
1655 if gShells
<> nil then
1656 for i
:= 0 to High(gShells
) do
1657 if gShells
[i
].Live
then
1661 mr
:= g_Obj_Move(@Obj
, True, False, True);
1662 positionChanged(); // this updates spatial accelerators
1664 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1670 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1671 if WordBool(mr
and MOVE_HITWALL
) then
1673 Obj
.Vel
.X
:= -(vel
.X
div 2);
1674 if not WordBool(mr
and MOVE_INWATER
) then
1675 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1677 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1679 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1680 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1681 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1683 if RAngle
mod 90 <> 0 then
1684 RAngle
:= (RAngle
div 90) * 90;
1686 else if not WordBool(mr
and MOVE_INWATER
) then
1687 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1690 if (Obj
.Vel
.X
>= 0) then
1692 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1693 if RAngle
>= 360 then
1694 RAngle
:= RAngle
mod 360;
1695 end else begin // Counter-clockwise
1696 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1698 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1703 procedure g_Player_DrawCorpses();
1708 if gGibs
<> nil then
1709 for i
:= 0 to High(gGibs
) do
1710 if gGibs
[i
].Live
then
1713 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1716 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1717 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1719 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1722 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1728 if gCorpses
<> nil then
1729 for i
:= 0 to High(gCorpses
) do
1730 if gCorpses
[i
] <> nil then
1734 procedure g_Player_DrawShells();
1739 if gShells
<> nil then
1740 for i
:= 0 to High(gShells
) do
1741 if gShells
[i
].Live
then
1744 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1750 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1754 procedure g_Player_RemoveAllCorpses();
1760 SetLength(gGibs
, MaxGibs
);
1761 SetLength(gShells
, MaxGibs
);
1765 if gCorpses
<> nil then
1766 for i
:= 0 to High(gCorpses
) do
1770 SetLength(gCorpses
, MaxCorpses
);
1773 procedure g_Player_Corpses_SaveState(var Mem
: TBinMemoryWriter
);
1778 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ:
1780 if gCorpses
<> nil then
1781 for i
:= 0 to High(gCorpses
) do
1782 if gCorpses
[i
] <> nil then
1785 Mem
:= TBinMemoryWriter
.Create((count
+1) * 128);
1787 // Êîëè÷åñòâî òðóïîâ:
1788 Mem
.WriteInt(count
);
1794 for i
:= 0 to High(gCorpses
) do
1795 if gCorpses
[i
] <> nil then
1798 Mem
.WriteString(gCorpses
[i
].FModelName
);
1800 b
:= gCorpses
[i
].Mess
;
1801 Mem
.WriteBoolean(b
);
1802 // Ñîõðàíÿåì äàííûå òðóïà:
1803 gCorpses
[i
].SaveState(Mem
);
1807 procedure g_Player_Corpses_LoadState(var Mem
: TBinMemoryReader
);
1816 g_Player_RemoveAllCorpses();
1818 // Êîëè÷åñòâî òðóïîâ:
1821 if count
> Length(gCorpses
) then
1823 raise EBinSizeError
.Create('g_Player_Corpses_LoadState: Too Many Corpses');
1830 for i
:= 0 to count
-1 do
1833 Mem
.ReadString(str
);
1837 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1838 // Çàãðóæàåì äàííûå òðóïà:
1839 gCorpses
[i
].LoadState(Mem
);
1845 procedure TPlayer
.BFGHit();
1847 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1848 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1849 if g_Game_IsServer
and g_Game_IsNet
then
1850 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1851 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1855 procedure TPlayer
.ChangeModel(ModelName
: string);
1857 locModel
: TPlayerModel
;
1859 locModel
:= g_PlayerModel_Get(ModelName
);
1860 if locModel
= nil then Exit
;
1866 procedure TPlayer
.SetModel(ModelName
: string);
1870 m
:= g_PlayerModel_Get(ModelName
);
1873 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1874 m
:= g_PlayerModel_Get('doomer');
1877 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1882 if FModel
<> nil then
1887 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1888 FModel
.Color
:= FColor
1890 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1891 FModel
.SetWeapon(FCurrWeap
);
1892 FModel
.SetFlag(FFlag
);
1893 SetDirection(FDirection
);
1896 procedure TPlayer
.SetColor(Color
: TRGB
);
1899 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1900 if FModel
<> nil then FModel
.Color
:= Color
;
1903 procedure TPlayer
.SwitchTeam
;
1905 if g_Game_IsClient
then
1907 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
1909 if gGameOn
and FLive
then
1910 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
1912 if FTeam
= TEAM_RED
then
1914 ChangeTeam(TEAM_BLUE
);
1915 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
1916 if g_Game_IsNet
then
1917 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
1921 ChangeTeam(TEAM_RED
);
1922 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
1923 if g_Game_IsNet
then
1924 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
1926 FPreferredTeam
:= FTeam
;
1929 procedure TPlayer
.ChangeTeam(Team
: Byte);
1936 TEAM_RED
, TEAM_BLUE
:
1937 FModel
.Color
:= TEAMCOLOR
[Team
];
1939 FModel
.Color
:= FColor
;
1941 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
1942 MH_SEND_PlayerStats(FUID
);
1946 procedure TPlayer.CollideItem();
1951 if gItems = nil then Exit;
1952 if not FLive then Exit;
1954 for i := 0 to High(gItems) do
1957 if (ItemType <> ITEM_NONE) and Live then
1958 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
1959 PLAYER_RECT.Height, @Obj) then
1961 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
1963 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
1964 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
1965 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
1966 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
1967 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
1969 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
1970 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
1971 (gGameSettings.GameType = GT_SINGLE) and
1972 (g_Player_GetCount() > 1)) then
1973 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
1979 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
1981 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
1982 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
1986 constructor TPlayer
.Create();
1992 FSawSound
:= TPlayableSound
.Create();
1993 FSawSoundIdle
:= TPlayableSound
.Create();
1994 FSawSoundHit
:= TPlayableSound
.Create();
1995 FSawSoundSelect
:= TPlayableSound
.Create();
1996 FJetSoundFly
:= TPlayableSound
.Create();
1997 FJetSoundOn
:= TPlayableSound
.Create();
1998 FJetSoundOff
:= TPlayableSound
.Create();
2000 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2001 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2002 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2003 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2004 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2005 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2006 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2008 FSpectatePlayer
:= -1;
2012 FSavedState
.WaitRecall
:= False;
2018 FActualModelName
:= 'doomer';
2021 FObj
.Rect
:= PLAYER_RECT
;
2023 FBFGFireCounter
:= -1;
2024 FJustTeleported
:= False;
2030 procedure TPlayer
.positionChanged ();
2034 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2038 if (not g_Game_IsClient
) and (not FLive
) then
2043 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2044 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2046 if not g_Game_IsClient
then
2049 if t
= HIT_TRAP
then
2051 // Ëîâóøêà óáèâàåò ñðàçó:
2053 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2055 if t
= HIT_SELF
then
2059 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2062 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2063 FMegaRulez
[MR_SUIT
] := 0;
2064 FMegaRulez
[MR_INVUL
] := 0;
2065 FMegaRulez
[MR_INVIS
] := 0;
2069 // Íî îò îñòàëüíîãî ñïàñàåò:
2070 if FMegaRulez
[MR_INVUL
] >= gTime
then
2077 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2078 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2079 (SpawnerUID
= FUID
) or
2080 (not SameTeam(FUID
, SpawnerUID
)) then
2082 FLastSpawnerUID
:= SpawnerUID
;
2084 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2085 if gBloodCount
> 0 then
2087 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2088 if value
div 4 <= c
then
2089 c
:= c
- (value
div 4)
2093 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2097 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2098 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2101 if t
= HIT_WATER
then
2102 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2103 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2108 Inc(FDamageBuffer
, value
);
2112 FPain
:= FPain
+ value
;
2115 if g_Game_IsServer
and g_Game_IsNet
then
2117 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2118 MH_SEND_PlayerStats(FUID
);
2119 MH_SEND_PlayerPos(False, FUID
);
2123 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2126 if g_Game_IsClient
then
2131 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2133 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2136 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2138 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2142 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2143 MH_SEND_PlayerStats(FUID
);
2146 destructor TPlayer
.Destroy();
2148 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2150 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2154 FSawSoundIdle
.Free();
2155 FSawSoundHit
.Free();
2156 FJetSoundFly
.Free();
2158 FJetSoundOff
.Free();
2164 procedure TPlayer
.DrawBubble();
2166 bubX
, bubY
: Integer;
2169 Rw
, Gw
, Bw
: SmallInt;
2172 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= D_LEFT
, -4, 18);
2173 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2181 1: // simple textual non-bubble
2183 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2184 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2185 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2188 2: // advanced pixel-perfect bubble
2190 if FTeam
= TEAM_RED
then
2193 if FTeam
= TEAM_BLUE
then
2196 3: // colored bubble
2198 Rb
:= FModel
.Color
.R
;
2199 Gb
:= FModel
.Color
.G
;
2200 Bb
:= FModel
.Color
.B
;
2201 Rw
:= Min(Rb
* 2 + 64, 255);
2202 Gw
:= Min(Gb
* 2 + 64, 255);
2203 Bw
:= Min(Bb
* 2 + 64, 255);
2204 if (Abs(Rw
- Rb
) < 32)
2205 or (Abs(Gw
- Gb
) < 32)
2206 or (Abs(Bw
- Bb
) < 32) then
2208 Rb
:= Max(Rw
div 2 - 16, 0);
2209 Gb
:= Max(Gw
div 2 - 16, 0);
2210 Bb
:= Max(Bw
div 2 - 16, 0);
2213 4: // custom textured bubble
2215 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2216 if FDirection
= D_RIGHT
then
2217 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2219 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, M_HORIZONTAL
);
2225 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2226 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2228 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2231 Dot
:= IfThen(FDirection
= D_LEFT
, 14, 5);
2232 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2233 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
);
2234 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
);
2235 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
);
2236 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
);
2240 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2241 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2242 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2245 procedure TPlayer
.Draw();
2253 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2254 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2256 e_GetTextureSize(ID
, @w
, @h
);
2257 if FDirection
= D_LEFT
then
2258 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2259 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7, 0, True, False)
2261 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2262 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7, 0, True, False);
2265 if FMegaRulez
[MR_INVIS
] > gTime
then
2267 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2268 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2270 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2271 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2275 FModel
.Draw(FObj
.X
, FObj
.Y
, 200)
2277 FModel
.Draw(FObj
.X
, FObj
.Y
);
2280 FModel
.Draw(FObj
.X
, FObj
.Y
, 254);
2283 FModel
.Draw(FObj
.X
, FObj
.Y
);
2286 if g_debug_Frames
then
2288 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2290 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2291 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2295 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2297 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2298 if gAimLine
and Live
and
2299 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2303 procedure TPlayer
.DrawAim();
2305 wx
, wy
, xx
, yy
: Integer;
2309 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= D_LEFT
, 7, -7);
2310 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2319 1: begin // Chainsaw
2326 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2327 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2328 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2329 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2334 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2335 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2336 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2337 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2339 4: begin // Double Shotgun
2342 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2343 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2344 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2345 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2347 5: begin // Chaingun
2350 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2351 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2352 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2353 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2355 6: begin // Rocket Launcher
2358 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2359 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2360 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2361 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2363 7: begin // Plasmagun
2366 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2367 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2368 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2369 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2374 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2375 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2376 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2377 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2379 9: begin // Super Chaingun
2382 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2383 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2384 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2385 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2388 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2389 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2390 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2393 procedure TPlayer
.DrawGUI();
2396 X
, Y
, SY
, a
, p
, m
: Integer;
2400 stat
: TPlayerStatArray
;
2402 X
:= gPlayerScreenSize
.X
;
2403 SY
:= gPlayerScreenSize
.Y
;
2406 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2408 if gGameSettings
.GameMode
= GM_CTF
then
2412 if gGameSettings
.GameMode
= GM_CTF
then
2414 s
:= 'TEXTURE_PLAYER_REDFLAG';
2415 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2416 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2417 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2418 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2419 if g_Texture_Get(s
, ID
) then
2420 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2423 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2424 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2425 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2427 if gGameSettings
.GameMode
= GM_CTF
then
2429 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2430 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2431 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2432 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2433 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2434 if g_Texture_Get(s
, ID
) then
2435 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2438 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2439 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2440 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2443 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2444 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2447 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2448 e_Draw(ID
, X
+2, Y
, 0, True, False);
2450 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2454 s
:= IntToStr(Frags
);
2455 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2456 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2461 stat
:= g_Player_GetStats();
2466 for a
:= 0 to High(stat
) do
2467 if stat
[a
].Name
<> Name
then
2469 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2470 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2474 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2475 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2476 s
:= s
+IntToStr(Abs(Frags
-m
));
2478 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2479 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2482 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2484 s
:= IntToStr(Lives
);
2485 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2486 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2490 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2491 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2493 if R_BERSERK
in FRulez
then
2494 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2496 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2498 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2499 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2501 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2502 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2503 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2505 s
:= IntToStr(FArmor
);
2506 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2507 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2509 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2515 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2520 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2522 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2523 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2524 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2525 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2526 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2527 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2528 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2529 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2530 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2533 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2534 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2535 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2537 if R_KEY_RED
in FRulez
then
2538 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2540 if R_KEY_GREEN
in FRulez
then
2541 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2543 if R_KEY_BLUE
in FRulez
then
2544 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2546 if FJetFuel
> 0 then
2548 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2549 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2550 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2551 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2552 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2553 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2557 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2558 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2559 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2562 if gShowPing
and g_Game_IsClient
then
2564 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2565 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2571 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2572 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2573 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2576 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2577 s
:= _lc
[I_PLAYER_SPECT4
];
2578 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2579 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2580 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2586 procedure TPlayer
.DrawRulez();
2590 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2591 if FMegaRulez
[MR_INVUL
] >= gTime
then
2593 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2594 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2599 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2600 191, 191, 191, 0, B_INVERT
);
2603 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2604 if FMegaRulez
[MR_SUIT
] >= gTime
then
2606 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2607 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2612 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2613 0, 96, 0, 200, B_NONE
);
2616 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2617 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2619 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2620 255, 0, 0, 200, B_NONE
);
2624 procedure TPlayer
.DrawPain();
2628 if FPain
= 0 then Exit
;
2632 if a
< 15 then h
:= 0
2633 else if a
< 35 then h
:= 1
2634 else if a
< 55 then h
:= 2
2635 else if a
< 75 then h
:= 3
2636 else if a
< 95 then h
:= 4
2639 //if a > 255 then a := 255;
2641 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2642 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2645 procedure TPlayer
.DrawPickup();
2649 if FPickup
= 0 then Exit
;
2653 if a
< 15 then h
:= 1
2654 else if a
< 35 then h
:= 2
2655 else if a
< 55 then h
:= 3
2656 else if a
< 75 then h
:= 4
2659 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2662 procedure TPlayer
.Fire();
2664 f
, DidFire
: Boolean;
2665 wx
, wy
, xd
, yd
: Integer;
2668 if g_Game_IsClient
then Exit
;
2669 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2670 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2678 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2683 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2684 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2685 xd
:= wx
+IfThen(FDirection
= D_LEFT
, -30, 30);
2686 yd
:= wy
+firediry();
2691 if R_BERSERK
in FRulez
then
2693 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2694 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2695 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2698 locobj
.rect
.Width
:= 39;
2699 locobj
.rect
.Height
:= 52;
2700 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2701 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2702 locobj
.Accel
.X
:= xd
-wx
;
2703 locobj
.Accel
.y
:= yd
-wy
;
2705 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2706 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2708 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2712 FPain
:= min(FPain
+ 25, 50);
2713 end else g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2716 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2721 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2722 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2724 FSawSoundSelect
.Stop();
2726 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2728 else if not FSawSoundHit
.IsPlaying() then
2730 FSawSoundSelect
.Stop();
2731 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2734 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2740 if FAmmo
[A_BULLETS
] > 0 then
2742 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2743 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2744 Dec(FAmmo
[A_BULLETS
]);
2745 FFireAngle
:= FAngle
;
2748 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2749 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2753 if FAmmo
[A_SHELLS
] > 0 then
2755 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2756 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
2757 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2758 Dec(FAmmo
[A_SHELLS
]);
2759 FFireAngle
:= FAngle
;
2763 FShellType
:= SHELL_SHELL
;
2767 if FAmmo
[A_SHELLS
] >= 2 then
2769 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
2770 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2771 Dec(FAmmo
[A_SHELLS
], 2);
2772 FFireAngle
:= FAngle
;
2776 FShellType
:= SHELL_DBLSHELL
;
2780 if FAmmo
[A_BULLETS
] > 0 then
2782 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
2783 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
2784 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2785 Dec(FAmmo
[A_BULLETS
]);
2786 FFireAngle
:= FAngle
;
2789 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2790 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2793 WEAPON_ROCKETLAUNCHER
:
2794 if FAmmo
[A_ROCKETS
] > 0 then
2796 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
2797 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2798 Dec(FAmmo
[A_ROCKETS
]);
2799 FFireAngle
:= FAngle
;
2805 if FAmmo
[A_CELLS
] > 0 then
2807 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
2808 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2809 Dec(FAmmo
[A_CELLS
]);
2810 FFireAngle
:= FAngle
;
2816 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
2818 FBFGFireCounter
:= 17;
2819 if not FNoReload
then
2820 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
2821 Dec(FAmmo
[A_CELLS
], 40);
2825 WEAPON_SUPERPULEMET
:
2826 if FAmmo
[A_SHELLS
] > 0 then
2828 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2829 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
2830 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2831 Dec(FAmmo
[A_SHELLS
]);
2832 FFireAngle
:= FAngle
;
2835 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2836 GameVelX
, GameVelY
-2, SHELL_SHELL
);
2839 WEAPON_FLAMETHROWER
:
2840 if FAmmo
[A_FUEL
] > 0 then
2842 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
2843 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2845 FFireAngle
:= FAngle
;
2851 if g_Game_IsNet
then
2855 if FCurrWeap
<> WEAPON_BFG
then
2856 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
2858 if not FNoReload
then
2859 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
2862 MH_SEND_PlayerStats(FUID
);
2867 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
2868 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
2869 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
2872 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
2875 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
2876 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
2877 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
2878 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
2879 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
2884 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
2886 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
2887 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
2888 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
2891 procedure TPlayer
.JetpackOn
;
2895 FJetSoundOn
.SetPosition(0);
2896 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
2900 procedure TPlayer
.JetpackOff
;
2904 FJetSoundOff
.SetPosition(0);
2905 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
2908 procedure TPlayer
.CatchFire(Attacker
: Word);
2911 FFireAttacker
:= Attacker
;
2912 if g_Game_IsNet
and g_Game_IsServer
then
2913 MH_SEND_PlayerStats(FUID
);
2916 procedure TPlayer
.Jump();
2918 if gFly
or FJetpack
then
2920 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
2921 if FObj
.Vel
.Y
> -VEL_FLY
then
2922 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
2925 if FJetFuel
> 0 then
2927 if (FJetFuel
< 1) and g_Game_IsServer
then
2931 if g_Game_IsNet
then
2932 MH_SEND_PlayerStats(FUID
);
2938 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
2940 FCanJetpack
:= False;
2942 // Ïðûãàåì èëè âñïëûâàåì:
2943 if (CollideLevel(0, 1) or
2944 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
2945 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
2946 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
2948 FObj
.Vel
.Y
:= -VEL_JUMP
;
2949 FCanJetpack
:= False;
2953 if BodyInLiquid(0, 0) then
2954 FObj
.Vel
.Y
:= -VEL_SW
2955 else if (FJetFuel
> 0) and FCanJetpack
and
2956 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
2960 if g_Game_IsNet
then
2961 MH_SEND_PlayerStats(FUID
);
2966 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
2968 a
, i
, k
, ab
, ar
: Byte;
2972 srv
, netsrv
: Boolean;
2977 procedure PushItem(t
: Byte);
2981 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
2982 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
2984 g_Obj_Push(@gItems
[id
].Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
2985 (FObj
.Vel
.Y
div 2)-Random(9));
2986 gItems
[id
].positionChanged(); // this updates spatial accelerators
2990 if KillType
= K_HARDKILL
then // -5..+5; -5..0
2992 g_Obj_Push(@gItems
[id
].Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
2993 (FObj
.Vel
.Y
div 2)-Random(6));
2995 else // -3..+3; -3..0
2997 g_Obj_Push(@gItems
[id
].Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
2998 (FObj
.Vel
.Y
div 2)-Random(4));
3000 gItems
[id
].positionChanged(); // this updates spatial accelerators
3003 if g_Game_IsNet
and g_Game_IsServer
then
3004 MH_SEND_ItemSpawn(True, id
);
3008 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3009 Srv
:= g_Game_IsServer
;
3010 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3011 if Srv
then FDeath
:= FDeath
+ 1;
3016 if not FPhysics
then
3022 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3024 if FLives
> 0 then FLives
:= FLives
- 1;
3025 if FLives
= 0 then FNoRespawn
:= True;
3028 // Íîìåð òèïà ñìåðòè:
3031 K_SIMPLEKILL
: a
:= 1;
3033 K_EXTRAHARDKILL
: a
:= 3;
3038 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3040 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3047 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3049 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3050 K_EXTRAHARDKILL
, K_FALLKILL
:
3051 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3054 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3058 K_HARDKILL
, K_EXTRAHARDKILL
:
3062 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3063 if (KillType
<> K_FALLKILL
) and (Srv
) then
3064 g_Monsters_killedp();
3066 if SpawnerUID
= FUID
then
3068 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3073 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3076 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3077 begin // Óáèò äðóãèì èãðîêîì
3078 KP
:= g_Player_Get(SpawnerUID
);
3079 if (KP
<> nil) and Srv
then
3081 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3082 if SameTeam(FUID
, SpawnerUID
) then
3092 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3093 Inc(gTeamStat
[KP
.Team
].Goals
,
3094 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3096 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3099 plr
:= g_Player_Get(SpawnerUID
);
3107 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3111 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3115 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3120 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3121 begin // Óáèò ìîíñòðîì
3122 mon
:= g_Monsters_Get(SpawnerUID
);
3126 s
:= g_Monsters_GetKilledBy(mon
.MonsterType
);
3130 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3134 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3138 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3143 else // Îñîáûå òèïû ñìåðòè
3146 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3147 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3148 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3149 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3150 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3151 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3157 for a
:= WP_FIRST
to WP_LAST
do
3161 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3162 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3163 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3164 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3165 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3166 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3167 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3168 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3169 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3178 if R_ITEM_BACKPACK
in FRulez
then
3179 PushItem(ITEM_AMMO_BACKPACK
);
3181 // Âûáðîñ ðàêåòíîãî ðàíöà:
3182 if FJetFuel
> 0 then
3183 PushItem(ITEM_JETPACK
);
3186 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3188 if R_KEY_RED
in FRulez
then
3189 PushItem(ITEM_KEY_RED
);
3191 if R_KEY_GREEN
in FRulez
then
3192 PushItem(ITEM_KEY_GREEN
);
3194 if R_KEY_BLUE
in FRulez
then
3195 PushItem(ITEM_KEY_BLUE
);
3202 g_Player_CreateCorpse(Self
);
3204 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3205 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3211 for i
:= Low(gPlayers
) to High(gPlayers
) do
3213 if gPlayers
[i
] = nil then continue
;
3214 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3217 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3218 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3223 OldLR
:= gLMSRespawn
;
3224 if (gGameSettings
.GameMode
= GM_COOP
) then
3228 // everyone is dead, restart the map
3229 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3231 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3232 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3233 gLMSRespawnTime
:= gTime
+ 5000;
3235 else if (a
= 1) then
3237 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3238 if (gPlayers
[k
] = gPlayer1
) or
3239 (gPlayers
[k
] = gPlayer2
) then
3240 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3241 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3242 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3245 else if (gGameSettings
.GameMode
= GM_TDM
) then
3247 if (ab
= 0) and (ar
<> 0) then
3250 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3252 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3253 Inc(gTeamStat
[TEAM_RED
].Goals
);
3254 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3255 gLMSRespawnTime
:= gTime
+ 5000;
3257 else if (ar
= 0) and (ab
<> 0) then
3260 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3262 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3263 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3264 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3265 gLMSRespawnTime
:= gTime
+ 5000;
3267 else if (ar
= 0) and (ab
= 0) then
3270 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3272 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3273 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3274 gLMSRespawnTime
:= gTime
+ 5000;
3277 else if (gGameSettings
.GameMode
= GM_DM
) then
3281 if gPlayers
[k
] <> nil then
3284 // survivor is the winner
3285 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3287 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3290 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3291 gLMSRespawnTime
:= gTime
+ 5000;
3293 else if (a
= 0) then
3295 // everyone is dead, restart the map
3296 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3298 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3299 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3300 gLMSRespawnTime
:= gTime
+ 5000;
3303 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3305 if NetMode
= NET_SERVER
then
3306 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3308 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3314 MH_SEND_PlayerStats(FUID
);
3315 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3316 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3319 if srv
and FNoRespawn
then Spectate(True);
3320 FWantsInGame
:= True;
3323 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3325 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3326 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3329 function TPlayer
.BodyInAcid(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_ACID1
or PANEL_ACID2
, False);
3335 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3337 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3338 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3339 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3341 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3342 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3343 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3347 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3349 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3350 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3351 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3355 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3357 if g_Game_IsClient
then Exit
;
3358 if Weapon
> High(FWeapon
) then Exit
;
3359 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3362 procedure TPlayer
.resetWeaponQueue ();
3365 FNextWeapDelay
:= 0;
3368 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3372 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3373 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 0);
3374 WEAPON_PISTOL
, WEAPON_CHAINGUN
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_BULLETS
] > 0);
3375 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3376 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3377 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3378 else result
:= (weapon
< length(FWeapon
));
3382 // return 255 for "no switch"
3383 function TPlayer
.getNextWeaponIndex (): Byte;
3386 wantThisWeapon
: array[0..64] of Boolean;
3387 wwc
: Integer = 0; //HACK!
3390 result
:= 255; // default result: "no switch"
3391 // had weapon cycling on previous frame? remove that flag
3392 if (FNextWeap
and $2000) <> 0 then
3394 FNextWeap
:= FNextWeap
and $1FFF;
3395 FNextWeapDelay
:= 0;
3397 // cycling has priority
3398 if (FNextWeap
and $C000) <> 0 then
3400 if (FNextWeap
and $8000) <> 0 then
3404 FNextWeap
:= FNextWeap
or $2000; // we need this
3405 if FNextWeapDelay
> 0 then
3406 exit
; // cooldown time
3408 for i
:= 0 to High(FWeapon
) do
3410 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3411 if FWeapon
[cwi
] then
3413 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d', [FCurrWeap, cwi]), MSG_WARNING);
3414 result
:= Byte(cwi
);
3415 FNextWeapDelay
:= 10;
3423 for i
:= 0 to High(wantThisWeapon
) do
3424 wantThisWeapon
[i
] := false;
3425 for i
:= 0 to High(FWeapon
) do
3426 if (FNextWeap
and (1 shl i
)) <> 0 then
3428 wantThisWeapon
[i
] := true;
3431 // exclude currently selected weapon from the set
3432 wantThisWeapon
[FCurrWeap
] := false;
3433 // slow down alterations a little
3436 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3437 // more than one weapon requested, assume "alteration" and check alteration delay
3438 if FNextWeapDelay
> 0 then
3444 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3445 // but clear all counters if no weapon should be switched
3451 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3452 // try weapons in descending order
3453 for i
:= High(FWeapon
) downto 0 do
3455 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3460 FNextWeapDelay
:= 10; // anyway, 'cause why not
3464 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3468 procedure TPlayer
.RealizeCurrentWeapon();
3469 function switchAllowed (): Boolean;
3474 if FBFGFireCounter
<> -1 then
3476 if FTime
[T_SWITCH
] > gTime
then
3478 for i
:= WP_FIRST
to WP_LAST
do
3479 if FReloading
[i
] > 0 then
3487 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3488 //FNextWeap := FNextWeap and $1FFF;
3489 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3491 if not switchAllowed
then
3493 //HACK for weapon cycling
3494 if (FNextWeap
and $7000) <> 0 then FNextWeap
:= 0;
3498 nw
:= getNextWeaponIndex();
3499 if nw
= 255 then exit
; // don't reset anything here
3500 if nw
> High(FWeapon
) then
3502 // don't forget to reset queue here!
3503 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3511 FTime
[T_SWITCH
] := gTime
+156;
3512 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3513 FModel
.SetWeapon(FCurrWeap
);
3514 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3518 procedure TPlayer
.NextWeapon();
3520 if g_Game_IsClient
then Exit
;
3524 procedure TPlayer
.PrevWeapon();
3526 if g_Game_IsClient
then Exit
;
3530 procedure TPlayer
.SetWeapon(W
: Byte);
3532 if FCurrWeap
<> W
then
3533 if W
= WEAPON_SAW
then
3534 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3537 FModel
.SetWeapon(CurrWeap
);
3541 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3546 if g_Game_IsClient
then Exit
;
3548 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3549 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3554 if FHealth
< PLAYER_HP_SOFT
then
3556 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3560 if gFlash
= 2 then Inc(FPickup
, 5);
3564 if FHealth
< PLAYER_HP_SOFT
then
3566 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3570 if gFlash
= 2 then Inc(FPickup
, 5);
3574 if FArmor
< PLAYER_AP_SOFT
then
3576 FArmor
:= PLAYER_AP_SOFT
;
3579 if gFlash
= 2 then Inc(FPickup
, 5);
3583 if FArmor
< PLAYER_AP_LIMIT
then
3585 FArmor
:= PLAYER_AP_LIMIT
;
3588 if gFlash
= 2 then Inc(FPickup
, 5);
3592 if FHealth
< PLAYER_HP_LIMIT
then
3594 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3598 if gFlash
= 2 then Inc(FPickup
, 5);
3602 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3604 if FHealth
< PLAYER_HP_LIMIT
then
3605 FHealth
:= PLAYER_HP_LIMIT
;
3606 if FArmor
< PLAYER_AP_LIMIT
then
3607 FArmor
:= PLAYER_AP_LIMIT
;
3611 if gFlash
= 2 then Inc(FPickup
, 5);
3615 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3617 FWeapon
[WEAPON_SAW
] := True;
3619 if gFlash
= 2 then Inc(FPickup
, 5);
3620 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3623 ITEM_WEAPON_SHOTGUN1
:
3624 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3626 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3627 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3629 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3630 FWeapon
[WEAPON_SHOTGUN1
] := True;
3632 if gFlash
= 2 then Inc(FPickup
, 5);
3633 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3636 ITEM_WEAPON_SHOTGUN2
:
3637 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3639 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3641 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3642 FWeapon
[WEAPON_SHOTGUN2
] := True;
3644 if gFlash
= 2 then Inc(FPickup
, 5);
3645 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3648 ITEM_WEAPON_CHAINGUN
:
3649 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3651 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3653 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3654 FWeapon
[WEAPON_CHAINGUN
] := True;
3656 if gFlash
= 2 then Inc(FPickup
, 5);
3657 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3660 ITEM_WEAPON_ROCKETLAUNCHER
:
3661 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3663 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3665 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3666 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3668 if gFlash
= 2 then Inc(FPickup
, 5);
3669 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3673 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3675 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3677 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3678 FWeapon
[WEAPON_PLASMA
] := True;
3680 if gFlash
= 2 then Inc(FPickup
, 5);
3681 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3685 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3687 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3689 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3690 FWeapon
[WEAPON_BFG
] := True;
3692 if gFlash
= 2 then Inc(FPickup
, 5);
3693 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3696 ITEM_WEAPON_SUPERPULEMET
:
3697 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3699 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3701 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3702 FWeapon
[WEAPON_SUPERPULEMET
] := True;
3704 if gFlash
= 2 then Inc(FPickup
, 5);
3705 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3708 ITEM_WEAPON_FLAMETHROWER
:
3709 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
3711 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
3713 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3714 FWeapon
[WEAPON_FLAMETHROWER
] := True;
3716 if gFlash
= 2 then Inc(FPickup
, 5);
3717 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3721 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3723 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3726 if gFlash
= 2 then Inc(FPickup
, 5);
3729 ITEM_AMMO_BULLETS_BOX
:
3730 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3732 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3735 if gFlash
= 2 then Inc(FPickup
, 5);
3739 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3741 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3744 if gFlash
= 2 then Inc(FPickup
, 5);
3747 ITEM_AMMO_SHELLS_BOX
:
3748 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3750 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
3753 if gFlash
= 2 then Inc(FPickup
, 5);
3757 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3759 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3762 if gFlash
= 2 then Inc(FPickup
, 5);
3765 ITEM_AMMO_ROCKET_BOX
:
3766 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3768 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
3771 if gFlash
= 2 then Inc(FPickup
, 5);
3775 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3777 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3780 if gFlash
= 2 then Inc(FPickup
, 5);
3784 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3786 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
3789 if gFlash
= 2 then Inc(FPickup
, 5);
3793 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
3795 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3798 if gFlash
= 2 then Inc(FPickup
, 5);
3802 if not(R_ITEM_BACKPACK
in FRulez
) or
3803 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
3804 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
3805 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
3806 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
3807 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
3809 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
3810 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
3811 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
3812 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
3813 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
3815 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3816 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3817 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3818 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3819 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3820 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3821 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3822 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3824 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
3827 if gFlash
= 2 then Inc(FPickup
, 5);
3831 if not(R_KEY_RED
in FRulez
) then
3833 Include(FRulez
, R_KEY_RED
);
3835 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3836 if gFlash
= 2 then Inc(FPickup
, 5);
3837 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3841 if not(R_KEY_GREEN
in FRulez
) then
3843 Include(FRulez
, R_KEY_GREEN
);
3845 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3846 if gFlash
= 2 then Inc(FPickup
, 5);
3847 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3851 if not(R_KEY_BLUE
in FRulez
) then
3853 Include(FRulez
, R_KEY_BLUE
);
3855 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3856 if gFlash
= 2 then Inc(FPickup
, 5);
3857 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3861 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
3863 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
3867 if gFlash
= 2 then Inc(FPickup
, 5);
3871 if FAir
< AIR_MAX
then
3876 if gFlash
= 2 then Inc(FPickup
, 5);
3881 if not (R_BERSERK
in FRulez
) then
3883 Include(FRulez
, R_BERSERK
);
3884 if FBFGFireCounter
= -1 then
3886 FCurrWeap
:= WEAPON_KASTET
;
3888 FModel
.SetWeapon(WEAPON_KASTET
);
3892 if gFlash
= 2 then Inc(FPickup
, 5);
3893 FBerserk
:= gTime
+30000;
3898 if FHealth
< PLAYER_HP_SOFT
then
3900 FHealth
:= PLAYER_HP_SOFT
;
3901 FBerserk
:= gTime
+30000;
3909 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
3911 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
3914 if gFlash
= 2 then Inc(FPickup
, 5);
3918 if FHealth
< PLAYER_HP_LIMIT
then
3920 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
3924 if gFlash
= 2 then Inc(FPickup
, 5);
3928 if FArmor
< PLAYER_AP_LIMIT
then
3930 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
3933 if gFlash
= 2 then Inc(FPickup
, 5);
3937 if FJetFuel
< JET_MAX
then
3939 FJetFuel
:= JET_MAX
;
3942 if gFlash
= 2 then Inc(FPickup
, 5);
3946 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
3948 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
3951 if gFlash
= 2 then Inc(FPickup
, 5);
3956 procedure TPlayer
.Touch();
3960 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
3963 // Áðîñèòü ôëàã òîâàðèùó:
3964 if gGameSettings
.GameMode
= GM_CTF
then
3969 procedure TPlayer
.Push(vx
, vy
: Integer);
3971 if (not FPhysics
) and FGhost
then
3973 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
3974 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
3975 if g_Game_IsNet
and g_Game_IsServer
then
3976 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
3979 procedure TPlayer
.Reset(Force
: Boolean);
3985 FTime
[T_RESPAWN
] := 0;
3986 FTime
[T_FLAGCAP
] := 0;
3999 FSpectator
:= False;
4002 FSpectatePlayer
:= -1;
4003 FNoRespawn
:= False;
4005 FLives
:= gGameSettings
.MaxLives
;
4010 procedure TPlayer
.SoftReset();
4016 FBFGFireCounter
:= -1;
4024 SetAction(A_STAND
, True);
4027 function TPlayer
.GetRespawnPoint(): Byte;
4032 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4034 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4035 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4037 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4039 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4040 if Self
= gPlayer1
then
4041 c
:= RESPAWNPOINT_PLAYER1
4043 c
:= RESPAWNPOINT_PLAYER2
;
4044 if g_Map_GetPointCount(c
) > 0 then
4050 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4051 if Self
= gPlayer1
then
4052 c
:= RESPAWNPOINT_PLAYER2
4054 c
:= RESPAWNPOINT_PLAYER1
;
4055 if g_Map_GetPointCount(c
) > 0 then
4062 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4063 if Random(2) = 0 then
4064 c
:= RESPAWNPOINT_PLAYER1
4066 c
:= RESPAWNPOINT_PLAYER2
;
4067 if g_Map_GetPointCount(c
) > 0 then
4074 // Òî÷êà ëþáîé èç êîìàíä
4075 if Random(2) = 0 then
4076 c
:= RESPAWNPOINT_RED
4078 c
:= RESPAWNPOINT_BLUE
;
4079 if g_Map_GetPointCount(c
) > 0 then
4086 c
:= RESPAWNPOINT_DM
;
4087 if g_Map_GetPointCount(c
) > 0 then
4095 if gGameSettings
.GameMode
= GM_DM
then
4098 c
:= RESPAWNPOINT_DM
;
4099 if g_Map_GetPointCount(c
) > 0 then
4105 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4106 if Random(2) = 0 then
4107 c
:= RESPAWNPOINT_PLAYER1
4109 c
:= RESPAWNPOINT_PLAYER2
;
4110 if g_Map_GetPointCount(c
) > 0 then
4116 // Òî÷êà ëþáîé èç êîìàíä
4117 if Random(2) = 0 then
4118 c
:= RESPAWNPOINT_RED
4120 c
:= RESPAWNPOINT_BLUE
;
4121 if g_Map_GetPointCount(c
) > 0 then
4129 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4131 // Òî÷êà ñâîåé êîìàíäû
4132 c
:= RESPAWNPOINT_DM
;
4133 if FTeam
= TEAM_RED
then
4134 c
:= RESPAWNPOINT_RED
;
4135 if FTeam
= TEAM_BLUE
then
4136 c
:= RESPAWNPOINT_BLUE
;
4137 if g_Map_GetPointCount(c
) > 0 then
4144 c
:= RESPAWNPOINT_DM
;
4145 if g_Map_GetPointCount(c
) > 0 then
4151 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4152 if Random(2) = 0 then
4153 c
:= RESPAWNPOINT_PLAYER1
4155 c
:= RESPAWNPOINT_PLAYER2
;
4156 if g_Map_GetPointCount(c
) > 0 then
4162 // Òî÷êà äðóãîé êîìàíäû
4163 c
:= RESPAWNPOINT_DM
;
4164 if FTeam
= TEAM_RED
then
4165 c
:= RESPAWNPOINT_BLUE
;
4166 if FTeam
= TEAM_BLUE
then
4167 c
:= RESPAWNPOINT_RED
;
4168 if g_Map_GetPointCount(c
) > 0 then
4176 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4178 RespawnPoint
: TRespawnPoint
;
4183 if not g_Game_IsServer
then
4187 FWantsInGame
:= True;
4188 FJustTeleported
:= True;
4191 FTime
[T_RESPAWN
] := 0;
4195 // if server changes MaxLives we gotta be ready
4196 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4198 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4199 if FTime
[T_RESPAWN
] > gTime
then
4202 // Ïðîñðàë âñå æèçíè:
4205 if not FSpectator
then Spectate(True);
4206 FWantsInGame
:= True;
4210 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4211 begin // "Ñâîÿ èãðà"
4212 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4213 FRulez
:= FRulez
-[R_BERSERK
];
4215 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4217 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4218 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4221 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4222 c
:= GetRespawnPoint();
4227 // Âîñêðåøåíèå áåç îðóæèÿ:
4230 FHealth
:= PLAYER_HP_SOFT
;
4236 for a
:= WP_FIRST
to WP_LAST
do
4238 FWeapon
[a
] := False;
4242 FWeapon
[WEAPON_PISTOL
] := True;
4243 FWeapon
[WEAPON_KASTET
] := True;
4244 FCurrWeap
:= WEAPON_PISTOL
;
4247 FModel
.SetWeapon(FCurrWeap
);
4249 for b
:= A_BULLETS
to A_HIGH
do
4252 FAmmo
[A_BULLETS
] := 50;
4254 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4255 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4256 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4257 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4258 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4260 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4261 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4266 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4267 if not g_Map_GetPoint(c
, RespawnPoint
) then
4269 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4273 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4274 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4275 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4281 FDirection
:= RespawnPoint
.Direction
;
4282 if FDirection
= D_LEFT
then
4288 FBFGFireCounter
:= -1;
4293 SetAction(A_STAND
, True);
4294 FModel
.Direction
:= FDirection
;
4296 for a
:= Low(FTime
) to High(FTime
) do
4299 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4304 FCanJetpack
:= False;
4309 // Àíèìàöèÿ âîçðîæäåíèÿ:
4310 if (not gLoadGameMode
) and (not Silent
) then
4311 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4313 Anim
:= TAnimation
.Create(ID
, False, 3);
4314 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4315 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4319 FSpectator
:= False;
4322 FSpectatePlayer
:= -1;
4325 if g_Game_IsNet
then
4327 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4328 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4330 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4331 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4336 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4339 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4340 else if (not NoMove
) then
4342 GameX
:= gMapInfo
.Width
div 2;
4343 GameY
:= gMapInfo
.Height
div 2;
4352 FWantsInGame
:= False;
4357 if Self
= gPlayer1
then
4362 if Self
= gPlayer2
then
4369 if g_Game_IsNet
then
4370 MH_SEND_PlayerStats(FUID
);
4373 procedure TPlayer
.SwitchNoClip
;
4377 FGhost
:= not FGhost
;
4378 FPhysics
:= not FGhost
;
4390 procedure TPlayer
.Run(Direction
: TDirection
);
4394 if MAX_RUNVEL
> 8 then
4398 if Direction
= D_LEFT
then
4400 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4401 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4404 if FObj
.Vel
.X
< MAX_RUNVEL
then
4405 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4407 // Âîçìîæíî, ïèíàåì êóñêè:
4408 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4410 b
:= Abs(FObj
.Vel
.X
);
4411 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4412 for a
:= 0 to High(gGibs
) do
4414 if gGibs
[a
].Live
and
4415 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4416 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4419 if FObj
.Vel
.X
< 0 then
4421 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4425 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4427 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4435 procedure TPlayer
.SeeDown();
4437 SetAction(A_SEEDOWN
);
4439 if FDirection
= D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4441 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4444 procedure TPlayer
.SeeUp();
4448 if FDirection
= D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4450 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4453 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4461 A_ATTACK
: Prior
:= 2;
4462 A_SEEUP
: Prior
:= 1;
4463 A_SEEDOWN
: Prior
:= 1;
4464 A_ATTACKUP
: Prior
:= 2;
4465 A_ATTACKDOWN
: Prior
:= 2;
4470 if (Prior
> FActionPrior
) or Force
then
4471 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4473 FActionPrior
:= Prior
;
4474 FActionAnim
:= Action
;
4475 FActionForce
:= Force
;
4476 FActionChanged
:= True;
4479 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4482 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4484 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4485 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4486 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4487 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4490 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4497 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4499 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4500 if g_Game_IsServer
and g_Game_IsNet
then
4501 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4505 FJustTeleported
:= True;
4510 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4512 Anim
:= TAnimation
.Create(ID
, False, 3);
4515 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4516 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4517 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4518 if g_Game_IsServer
and g_Game_IsNet
then
4519 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4520 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4524 FObj
.X
:= X
-PLAYER_RECT
.X
;
4525 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4526 if FLive
and FGhost
then
4532 if not g_Game_IsNet
then
4536 SetDirection(D_LEFT
);
4542 SetDirection(D_RIGHT
);
4548 if FDirection
= D_RIGHT
then
4550 SetDirection(D_LEFT
);
4555 SetDirection(D_RIGHT
);
4561 if not silent
and (Anim
<> nil) then
4563 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4564 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4567 if g_Game_IsServer
and g_Game_IsNet
then
4568 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4569 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4576 function nonz(a
: Single): Single;
4584 procedure TPlayer
.Update();
4587 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4588 blockmon
, headwater
, dospawn
: Boolean;
4593 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4594 AnyServer
:= g_Game_IsServer
;
4596 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4597 DoLerp(NetInterpLevel
+ 1)
4603 if FClientID
>= 0 then
4605 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4606 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4607 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4616 if FLive
and (gFly
or FJetpack
) then
4619 if FDirection
= D_LEFT
then
4624 if FLive
and (not FGhost
) then
4626 if FKeys
[KEY_UP
].Pressed
then
4628 if FKeys
[KEY_DOWN
].Pressed
then
4632 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4635 i
:= g_basic
.Sign(FIncCam
);
4636 FIncCam
:= Abs(FIncCam
);
4637 DecMin(FIncCam
, 5, 0);
4638 FIncCam
:= FIncCam
*i
;
4641 // no need to do that each second frame, weapon queue will take care of it
4642 if FLive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4643 if FLive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4645 if gTime
mod (GAME_TICK
*2) <> 0 then
4647 if (FObj
.Vel
.X
= 0) and FLive
then
4649 if FKeys
[KEY_LEFT
].Pressed
then
4651 if FKeys
[KEY_RIGHT
].Pressed
then
4657 g_Obj_Move(@FObj
, True, True, True);
4658 positionChanged(); // this updates spatial accelerators
4664 FActionChanged
:= False;
4668 // Let alive player do some actions
4669 if FKeys
[KEY_LEFT
].Pressed
then Run(D_LEFT
);
4670 if FKeys
[KEY_RIGHT
].Pressed
then Run(D_RIGHT
);
4671 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
4672 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
4673 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
4674 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
4675 if FKeys
[KEY_JUMP
].Pressed
then Jump()
4678 if AnyServer
and FJetpack
then
4682 if NetServer
then MH_SEND_PlayerStats(FUID
);
4684 FCanJetpack
:= True;
4691 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
4693 if FKeys
[k
].Pressed
then
4701 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4704 if (FTime
[T_RESPAWN
] <= gTime
) and
4705 gGameOn
and (not FLive
) then
4707 if (g_Player_GetCount() > 1) then
4711 gExit
:= EXIT_RESTART
;
4716 // Dead spectator actions
4719 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
4720 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
4724 if (FSpectatePlayer
>= High(gPlayers
)) then
4725 FSpectatePlayer
:= -1
4729 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
4730 if gPlayers
[I
] <> nil then
4731 if gPlayers
[I
].Live
then
4732 if gPlayers
[I
].UID
<> FUID
then
4734 FSpectatePlayer
:= I
;
4739 if not SetSpect
then FSpectatePlayer
:= -1;
4750 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
4752 FYTo
:= FObj
.Y
- 32;
4753 FSpectatePlayer
:= -1;
4755 if FKeys
[KEY_DOWN
].Pressed
then
4757 FYTo
:= FObj
.Y
+ 32;
4758 FSpectatePlayer
:= -1;
4760 if FKeys
[KEY_LEFT
].Pressed
then
4762 FXTo
:= FObj
.X
- 32;
4763 FSpectatePlayer
:= -1;
4765 if FKeys
[KEY_RIGHT
].Pressed
then
4767 FXTo
:= FObj
.X
+ 32;
4768 FSpectatePlayer
:= -1;
4771 if (FXTo
< -64) then
4773 else if (FXTo
> gMapInfo
.Width
+ 32) then
4774 FXTo
:= gMapInfo
.Width
+ 32;
4775 if (FYTo
< -72) then
4777 else if (FYTo
> gMapInfo
.Height
+ 32) then
4778 FYTo
:= gMapInfo
.Height
+ 32;
4783 g_Obj_Move(@FObj
, True, True, True);
4784 positionChanged(); // this updates spatial accelerators
4791 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
4792 if gPlayers
[FSpectatePlayer
] <> nil then
4793 if gPlayers
[FSpectatePlayer
].Live
then
4795 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
4796 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
4800 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
4801 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
4802 PANEL_BLOCKMON
, True);
4803 headwater
:= HeadInLiquid(0, 0);
4805 // Ñîïðîòèâëåíèå âîçäóõà:
4806 if (not FLive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
4807 if FObj
.Vel
.X
<> 0 then
4808 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
4810 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
4811 DecMin(FPain
, 5, 0);
4812 DecMin(FPickup
, 1, 0);
4814 if FLive
and (FObj
.Y
> gMapInfo
.Height
+128) and AnyServer
then
4816 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
4817 FMegaRulez
[MR_SUIT
] := 0;
4818 FMegaRulez
[MR_INVUL
] := 0;
4819 FMegaRulez
[MR_INVIS
] := 0;
4820 Kill(K_FALLKILL
, 0, HIT_FALL
);
4827 if FCurrWeap
= WEAPON_SAW
then
4828 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
4829 FSawSoundSelect
.IsPlaying()) then
4830 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
4833 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
4834 (not FJetSoundOff
.IsPlaying()) then
4836 FJetSoundFly
.SetPosition(0);
4837 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
4840 for b
:= WP_FIRST
to WP_LAST
do
4841 if FReloading
[b
] > 0 then
4847 if FShellTimer
> -1 then
4848 if FShellTimer
= 0 then
4850 if FShellType
= SHELL_SHELL
then
4851 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4852 GameVelX
, GameVelY
-2, SHELL_SHELL
)
4853 else if FShellType
= SHELL_DBLSHELL
then
4855 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4856 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
4857 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4858 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
4861 end else Dec(FShellTimer
);
4863 if (FBFGFireCounter
> -1) then
4864 if FBFGFireCounter
= 0 then
4868 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
4869 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
4870 xd
:= wx
+IfThen(FDirection
= D_LEFT
, -30, 30);
4871 yd
:= wy
+firediry();
4872 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
4873 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
4874 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
4875 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
4876 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
4879 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
4880 FBFGFireCounter
:= -1;
4883 FBFGFireCounter
:= 0
4885 Dec(FBFGFireCounter
);
4887 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
4889 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
4891 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
4894 if (headwater
or blockmon
) then
4900 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
4903 else if (FAir
mod 31 = 0) and not blockmon
then
4905 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
4906 if Random(2) = 0 then
4907 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
4909 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
4911 end else if FAir
< AIR_DEF
then
4914 if FFireTime
> 0 then
4916 if BodyInLiquid(0, 0) then
4921 else if FMegaRulez
[MR_SUIT
] >= gTime
then
4923 if FMegaRulez
[MR_SUIT
] = gTime
then
4930 if FFirePainTime
<= 0 then
4932 if g_Game_IsServer
then
4933 Damage(5, FFireAttacker
, 0, 0, HIT_FLAME
);
4934 FFirePainTime
:= 18;
4936 FFirePainTime
:= FFirePainTime
- 1;
4937 FFireTime
:= FFireTime
- 1;
4938 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
4939 MH_SEND_PlayerStats(FUID
);
4943 if FDamageBuffer
> 0 then
4945 if FDamageBuffer
>= 9 then
4949 if FDamageBuffer
< 30 then i
:= 9
4950 else if FDamageBuffer
< 100 then i
:= 18
4954 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
4955 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
4956 FHealth
:= FHealth
-ii
;
4959 FHealth
:= FHealth
+FArmor
;
4964 if FHealth
<= 0 then
4965 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
4966 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
4967 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
4971 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
4972 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
4973 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
4974 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
4981 end; // if FLive then ...
4983 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
4985 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
4986 FModel
.GetCurrentAnimation
.MinLength
:= i
;
4987 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
4988 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
4990 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
4991 then SetAction(A_STAND
, True);
4993 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
4995 for b
:= Low(FKeys
) to High(FKeys
) do
4996 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
4999 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5001 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5002 FObj
.Y
+PLAYER_RECT
.Y
,
5009 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5011 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5012 FObj
.Y
+PLAYER_RECT
.Y
,
5016 Panel
.Width
, Panel
.Height
);
5019 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5021 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5022 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5023 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5024 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5027 function g_Player_ValidName(Name
: string): Boolean;
5033 if gPlayers
= nil then Exit
;
5035 for a
:= 0 to High(gPlayers
) do
5036 if gPlayers
[a
] <> nil then
5037 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5044 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5048 d
:= FModel
.Direction
;
5050 FModel
.Direction
:= Direction
;
5051 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5053 FDirection
:= Direction
;
5056 function TPlayer
.GetKeys(): Byte;
5060 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5061 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5062 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5064 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5065 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5068 procedure TPlayer
.Use();
5072 if FTime
[T_USE
] > gTime
then Exit
;
5074 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5075 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5077 for a
:= 0 to High(gPlayers
) do
5078 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5079 gPlayers
[a
].Live
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5080 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5081 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5083 gPlayers
[a
].Touch();
5084 if g_Game_IsNet
and g_Game_IsServer
then
5085 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5088 FTime
[T_USE
] := gTime
+120;
5091 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5095 WX
, WY
, XD
, YD
: Integer;
5106 if R_BERSERK
in FRulez
then
5108 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5109 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5110 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5113 locobj
.rect
.Width
:= 39;
5114 locobj
.rect
.Height
:= 52;
5115 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5116 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5117 locobj
.Accel
.X
:= xd
-wx
;
5118 locobj
.Accel
.y
:= yd
-wy
;
5120 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5121 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5123 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5127 FPain
:= min(FPain
+ 25, 50);
5129 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5134 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5135 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5137 FSawSoundSelect
.Stop();
5139 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5141 else if not FSawSoundHit
.IsPlaying() then
5143 FSawSoundSelect
.Stop();
5144 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5151 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5152 FFireAngle
:= FAngle
;
5154 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5155 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5160 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5161 FFireAngle
:= FAngle
;
5164 FShellType
:= SHELL_SHELL
;
5169 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5170 FFireAngle
:= FAngle
;
5173 FShellType
:= SHELL_DBLSHELL
;
5178 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5179 FFireAngle
:= FAngle
;
5181 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5182 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5185 WEAPON_ROCKETLAUNCHER
:
5187 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5188 FFireAngle
:= FAngle
;
5194 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5195 FFireAngle
:= FAngle
;
5201 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5202 FFireAngle
:= FAngle
;
5206 WEAPON_SUPERPULEMET
:
5208 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5209 FFireAngle
:= FAngle
;
5211 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5212 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5215 WEAPON_FLAMETHROWER
:
5217 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5218 FFireAngle
:= FAngle
;
5225 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5226 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5227 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5230 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5232 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5233 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5236 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5240 if NetInterpLevel
< 1 then
5250 AX
:= Abs(FXTo
- FObj
.X
);
5251 AY
:= Abs(FYTo
- FObj
.Y
);
5252 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5254 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5259 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5261 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5262 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5263 PANEL_LIFTUP
, False) then Result
:= -1
5265 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5266 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5267 PANEL_LIFTDOWN
, False) then Result
:= 1
5271 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5278 if Flag
= FLAG_NONE
then
5281 if not g_Game_IsServer
then Exit
;
5283 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5284 if (Flag
= FTeam
) and
5285 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5286 (FFlag
<> FLAG_NONE
) then
5288 if FFlag
= FLAG_RED
then
5289 s
:= _lc
[I_PLAYER_FLAG_RED
]
5291 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5293 evtype
:= FLAG_STATE_SCORED
;
5295 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5296 Insert('.', ts
, Length(ts
) + 1 - 3);
5297 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5299 g_Map_ResetFlag(FFlag
);
5300 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5302 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5305 if g_Game_IsNet
then
5307 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5311 gFlags
[FFlag
].CaptureTime
:= 0;
5316 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5317 if (Flag
= FTeam
) and
5318 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5320 if Flag
= FLAG_RED
then
5321 s
:= _lc
[I_PLAYER_FLAG_RED
]
5323 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5325 evtype
:= FLAG_STATE_RETURNED
;
5326 gFlags
[Flag
].CaptureTime
:= 0;
5328 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5330 g_Map_ResetFlag(Flag
);
5331 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5334 if g_Game_IsNet
then
5336 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5342 // Ïîäîáðàë ÷óæîé ôëàã:
5343 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5347 if Flag
= FLAG_RED
then
5348 s
:= _lc
[I_PLAYER_FLAG_RED
]
5350 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5352 evtype
:= FLAG_STATE_CAPTURED
;
5354 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5356 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5358 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5361 if g_Game_IsNet
then
5363 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5369 procedure TPlayer
.SetFlag(Flag
: Byte);
5372 if FModel
<> nil then
5373 FModel
.SetFlag(FFlag
);
5376 function TPlayer
.DropFlag(): Boolean;
5381 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5383 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5384 with gFlags
[FFlag
] do
5388 Direction
:= FDirection
;
5389 State
:= FLAG_STATE_DROPPED
;
5391 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5392 (FObj
.Vel
.Y
div 2)-2+Random(5));
5393 positionChanged(); // this updates spatial accelerators
5395 if FFlag
= FLAG_RED
then
5396 s
:= _lc
[I_PLAYER_FLAG_RED
]
5398 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5400 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5401 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5403 if g_Game_IsNet
then
5404 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5410 procedure TPlayer
.GetSecret();
5415 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5417 Assert(Key
<= High(FKeys
));
5419 FKeys
[Key
].Pressed
:= True;
5420 FKeys
[Key
].Time
:= Time
;
5423 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5425 Result
:= FKeys
[K
].Pressed
;
5428 procedure TPlayer
.ReleaseKeys();
5432 for a
:= Low(FKeys
) to High(FKeys
) do
5434 FKeys
[a
].Pressed
:= False;
5439 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5443 function TPlayer
.firediry(): Integer;
5445 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5446 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5450 procedure TPlayer
.RememberState();
5454 FSavedState
.Health
:= FHealth
;
5455 FSavedState
.Armor
:= FArmor
;
5456 FSavedState
.Air
:= FAir
;
5457 FSavedState
.JetFuel
:= FJetFuel
;
5458 FSavedState
.CurrWeap
:= FCurrWeap
;
5459 FSavedState
.NextWeap
:= FNextWeap
;
5460 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5463 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5465 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5467 FSavedState
.Rulez
:= FRulez
;
5468 FSavedState
.WaitRecall
:= True;
5471 procedure TPlayer
.RecallState();
5475 if not FSavedState
.WaitRecall
then Exit
;
5477 FHealth
:= FSavedState
.Health
;
5478 FArmor
:= FSavedState
.Armor
;
5479 FAir
:= FSavedState
.Air
;
5480 FJetFuel
:= FSavedState
.JetFuel
;
5481 FCurrWeap
:= FSavedState
.CurrWeap
;
5482 FNextWeap
:= FSavedState
.NextWeap
;
5483 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5486 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5488 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5490 FRulez
:= FSavedState
.Rulez
;
5491 FSavedState
.WaitRecall
:= False;
5493 if gGameSettings
.GameType
= GT_SERVER
then
5494 MH_SEND_PlayerStats(FUID
);
5497 procedure TPlayer
.SaveState(var Mem
: TBinMemoryWriter
);
5509 Mem
:= TBinMemoryWriter
.Create(i
);
5511 // Ñèãíàòóðà èãðîêà:
5512 sig
:= PLAYER_SIGNATURE
; // 'PLYR'
5513 Mem
.WriteDWORD(sig
);
5515 Mem
.WriteBoolean(FIamBot
);
5517 Mem
.WriteWord(FUID
);
5519 Mem
.WriteString(FName
, 32);
5521 Mem
.WriteByte(FTeam
);
5523 Mem
.WriteBoolean(FLive
);
5524 // Èçðàñõîäîâàë ëè âñå æèçíè:
5525 Mem
.WriteBoolean(FNoRespawn
);
5527 if FDirection
= D_LEFT
then
5533 Mem
.WriteInt(FHealth
);
5535 Mem
.WriteByte(FLives
);
5537 Mem
.WriteInt(FArmor
);
5541 Mem
.WriteInt(FJetFuel
);
5543 Mem
.WriteInt(FPain
);
5545 Mem
.WriteInt(FKills
);
5547 Mem
.WriteInt(FMonsterKills
);
5549 Mem
.WriteInt(FFrags
);
5551 Mem
.WriteByte(FFragCombo
);
5552 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5553 Mem
.WriteDWORD(FLastFrag
);
5555 Mem
.WriteInt(FDeath
);
5556 // Êàêîé ôëàã íåñåò:
5557 Mem
.WriteByte(FFlag
);
5559 Mem
.WriteInt(FSecrets
);
5561 Mem
.WriteByte(FCurrWeap
);
5563 Mem
.WriteWord(FNextWeap
);
5565 Mem
.WriteByte(FNextWeapDelay
);
5566 // Âðåìÿ çàðÿäêè BFG:
5567 Mem
.WriteSmallInt(FBFGFireCounter
);
5569 Mem
.WriteInt(FDamageBuffer
);
5570 // Ïîñëåäíèé óäàðèâøèé:
5571 Mem
.WriteWord(FLastSpawnerUID
);
5572 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5573 Mem
.WriteByte(FLastHit
);
5575 Obj_SaveState(@FObj
, Mem
);
5576 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5577 for i
:= A_BULLETS
to A_HIGH
do
5578 Mem
.WriteWord(FAmmo
[i
]);
5579 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5580 for i
:= A_BULLETS
to A_HIGH
do
5581 Mem
.WriteWord(FMaxAmmo
[i
]);
5583 for i
:= WP_FIRST
to WP_LAST
do
5584 Mem
.WriteBoolean(FWeapon
[i
]);
5585 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5586 for i
:= WP_FIRST
to WP_LAST
do
5587 Mem
.WriteWord(FReloading
[i
]);
5589 if R_ITEM_BACKPACK
in FRulez
then
5594 // Íàëè÷èå êðàñíîãî êëþ÷à:
5595 if R_KEY_RED
in FRulez
then
5600 // Íàëè÷èå çåëåíîãî êëþ÷à:
5601 if R_KEY_GREEN
in FRulez
then
5606 // Íàëè÷èå ñèíåãî êëþ÷à:
5607 if R_KEY_BLUE
in FRulez
then
5612 // Íàëè÷èå áåðñåðêà:
5613 if R_BERSERK
in FRulez
then
5618 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5619 for i
:= MR_SUIT
to MR_MAX
do
5620 Mem
.WriteDWORD(FMegaRulez
[i
]);
5621 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5622 for i
:= T_RESPAWN
to T_FLAGCAP
do
5623 Mem
.WriteDWORD(FTime
[i
]);
5626 Mem
.WriteString(str
);
5636 procedure TPlayer
.LoadState(var Mem
: TBinMemoryReader
);
5646 // Ñèãíàòóðà èãðîêà:
5648 if sig
<> PLAYER_SIGNATURE
then // 'PLYR'
5650 raise EBinSizeError
.Create('TPlayer.LoadState: Wrong Player Signature');
5653 Mem
.ReadBoolean(FIamBot
);
5657 Mem
.ReadString(str
);
5658 if (Self
<> gPlayer1
) and (Self
<> gPlayer2
) then
5661 Mem
.ReadByte(FTeam
);
5663 Mem
.ReadBoolean(FLive
);
5664 // Èçðàñõîäîâàë ëè âñå æèçíè:
5665 Mem
.ReadBoolean(FNoRespawn
);
5669 FDirection
:= D_LEFT
5671 FDirection
:= D_RIGHT
;
5673 Mem
.ReadInt(FHealth
);
5675 Mem
.ReadByte(FLives
);
5677 Mem
.ReadInt(FArmor
);
5681 Mem
.ReadInt(FJetFuel
);
5685 Mem
.ReadInt(FKills
);
5687 Mem
.ReadInt(FMonsterKills
);
5689 Mem
.ReadInt(FFrags
);
5691 Mem
.ReadByte(FFragCombo
);
5692 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5693 Mem
.ReadDWORD(FLastFrag
);
5695 Mem
.ReadInt(FDeath
);
5696 // Êàêîé ôëàã íåñåò:
5697 Mem
.ReadByte(FFlag
);
5699 Mem
.ReadInt(FSecrets
);
5701 Mem
.ReadByte(FCurrWeap
);
5703 Mem
.ReadWord(FNextWeap
);
5705 Mem
.ReadByte(FNextWeapDelay
);
5706 // Âðåìÿ çàðÿäêè BFG:
5707 Mem
.ReadSmallInt(FBFGFireCounter
);
5709 Mem
.ReadInt(FDamageBuffer
);
5710 // Ïîñëåäíèé óäàðèâøèé:
5711 Mem
.ReadWord(FLastSpawnerUID
);
5712 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5713 Mem
.ReadByte(FLastHit
);
5715 Obj_LoadState(@FObj
, Mem
);
5716 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5717 for i
:= A_BULLETS
to A_HIGH
do
5718 Mem
.ReadWord(FAmmo
[i
]);
5719 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5720 for i
:= A_BULLETS
to A_HIGH
do
5721 Mem
.ReadWord(FMaxAmmo
[i
]);
5723 for i
:= WP_FIRST
to WP_LAST
do
5724 Mem
.ReadBoolean(FWeapon
[i
]);
5725 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5726 for i
:= WP_FIRST
to WP_LAST
do
5727 Mem
.ReadWord(FReloading
[i
]);
5731 Include(FRulez
, R_ITEM_BACKPACK
);
5732 // Íàëè÷èå êðàñíîãî êëþ÷à:
5735 Include(FRulez
, R_KEY_RED
);
5736 // Íàëè÷èå çåëåíîãî êëþ÷à:
5739 Include(FRulez
, R_KEY_GREEN
);
5740 // Íàëè÷èå ñèíåãî êëþ÷à:
5743 Include(FRulez
, R_KEY_BLUE
);
5744 // Íàëè÷èå áåðñåðêà:
5747 Include(FRulez
, R_BERSERK
);
5748 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5749 for i
:= MR_SUIT
to MR_MAX
do
5750 Mem
.ReadDWORD(FMegaRulez
[i
]);
5751 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5752 for i
:= T_RESPAWN
to T_FLAGCAP
do
5753 Mem
.ReadDWORD(FTime
[i
]);
5755 Mem
.ReadString(str
);
5757 Mem
.ReadByte(FColor
.R
);
5758 Mem
.ReadByte(FColor
.G
);
5759 Mem
.ReadByte(FColor
.B
);
5760 if Self
= gPlayer1
then
5762 str
:= gPlayer1Settings
.Model
;
5763 FColor
:= gPlayer1Settings
.Color
;
5765 if Self
= gPlayer2
then
5767 str
:= gPlayer2Settings
.Model
;
5768 FColor
:= gPlayer2Settings
.Color
;
5770 // Îáíîâëÿåì ìîäåëü èãðîêà:
5772 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
5773 FModel
.Color
:= TEAMCOLOR
[FTeam
]
5775 FModel
.Color
:= FColor
;
5778 procedure TPlayer
.AllRulez(Health
: Boolean);
5784 FHealth
:= PLAYER_HP_LIMIT
;
5785 FArmor
:= PLAYER_AP_LIMIT
;
5789 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
5790 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
5791 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5794 procedure TPlayer
.RestoreHealthArmor();
5796 FHealth
:= PLAYER_HP_LIMIT
;
5797 FArmor
:= PLAYER_AP_LIMIT
;
5800 procedure TPlayer
.FragCombo();
5804 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
5806 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
5808 if FFragCombo
< 5 then
5810 Param
:= FUID
or (FFragCombo
shl 16);
5811 if (FComboEvnt
>= Low(gDelayedEvents
)) and
5812 (FComboEvnt
<= High(gDelayedEvents
)) and
5813 gDelayedEvents
[FComboEvnt
].Pending
and
5814 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
5815 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
5817 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
5818 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
5821 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
5829 procedure TPlayer
.GiveItem(ItemType
: Byte);
5833 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
5835 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
5839 if FAir
< AIR_MAX
then
5846 if not (R_BERSERK
in FRulez
) then
5848 Include(FRulez
, R_BERSERK
);
5849 if FBFGFireCounter
< 1 then
5851 FCurrWeap
:= WEAPON_KASTET
;
5853 FModel
.SetWeapon(WEAPON_KASTET
);
5857 FBerserk
:= gTime
+30000;
5859 if FHealth
< PLAYER_HP_SOFT
then
5861 FHealth
:= PLAYER_HP_SOFT
;
5862 FBerserk
:= gTime
+30000;
5867 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
5869 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
5873 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
5875 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
5879 if FJetFuel
< JET_MAX
then
5881 FJetFuel
:= JET_MAX
;
5884 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
5885 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
5887 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
5888 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5890 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
5892 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
5894 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
5895 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5898 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
5899 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
5900 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
5901 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
5902 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
5903 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
5904 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
5905 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
5906 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
5908 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5909 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
5910 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5911 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
5912 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5913 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
5914 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5915 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
5916 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
5919 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
5920 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
5921 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
5922 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
5923 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
5925 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
5926 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
5927 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
5928 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
5929 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
5931 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5932 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5933 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5934 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5936 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
5939 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
5940 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
5941 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
5943 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
5944 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
5949 if g_Game_IsNet
and g_Game_IsServer
then
5950 MH_SEND_PlayerStats(FUID
);
5953 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
5958 if (Random(5) = 1) and (Times
= 1) then
5961 if BodyInLiquid(0, 0) then
5963 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
5964 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
5965 if Random(2) = 0 then
5966 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5968 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5972 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
5974 for i
:= 1 to Times
do
5976 Anim
:= TAnimation
.Create(id
, False, 3);
5978 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
5979 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
5985 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
5990 if (Random(10) = 1) and (Times
= 1) then
5993 if g_Frames_Get(id
, 'FRAMES_FLAME') then
5995 for i
:= 1 to Times
do
5997 Anim
:= TAnimation
.Create(id
, False, 3);
5999 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6000 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6006 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6008 FSawSound
.Pause(Enable
);
6009 FSawSoundIdle
.Pause(Enable
);
6010 FSawSoundHit
.Pause(Enable
);
6011 FSawSoundSelect
.Pause(Enable
);
6016 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6021 FObj
.Rect
:= PLAYER_CORPSERECT
;
6022 FModelName
:= ModelName
;
6027 FState
:= CORPSE_STATE_MESS
;
6028 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6032 FState
:= CORPSE_STATE_NORMAL
;
6033 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6037 destructor TCorpse
.Destroy();
6044 procedure TCorpse
.positionChanged (); begin end;
6046 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6050 if FState
= CORPSE_STATE_REMOVEME
then
6053 FDamage
:= FDamage
+ Value
;
6055 if FDamage
> 150 then
6057 if FAnimation
<> nil then
6062 FState
:= CORPSE_STATE_REMOVEME
;
6064 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6065 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6066 FModelName
, FColor
);
6067 // Çâóê ìÿñà îò òðóïà:
6068 pm
:= g_PlayerModel_Get(FModelName
);
6069 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6075 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6076 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6077 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6078 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6079 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6084 procedure TCorpse
.Draw();
6086 if FState
= CORPSE_STATE_REMOVEME
then
6089 if FAnimation
<> nil then
6090 FAnimation
.Draw(FObj
.X
, FObj
.Y
, M_NONE
);
6092 if FAnimationMask
<> nil then
6095 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, M_NONE
);
6102 procedure TCorpse
.Update();
6106 if FState
= CORPSE_STATE_REMOVEME
then
6109 if gTime
mod (GAME_TICK
*2) <> 0 then
6111 g_Obj_Move(@FObj
, True, True, True);
6112 positionChanged(); // this updates spatial accelerators
6116 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6117 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6119 st
:= g_Obj_Move(@FObj
, True, True, True);
6120 positionChanged(); // this updates spatial accelerators
6122 if WordBool(st
and MOVE_FALLOUT
) then
6124 FState
:= CORPSE_STATE_REMOVEME
;
6128 if FAnimation
<> nil then
6129 FAnimation
.Update();
6130 if FAnimationMask
<> nil then
6131 FAnimationMask
.Update();
6134 procedure TCorpse
.SaveState(var Mem
: TBinMemoryWriter
);
6143 sig
:= CORPSE_SIGNATURE
; // 'CORP'
6144 Mem
.WriteDWORD(sig
);
6146 Mem
.WriteByte(FState
);
6147 // Íàêîïëåííûé óðîí:
6148 Mem
.WriteByte(FDamage
);
6150 Mem
.WriteByte(FColor
.R
);
6151 Mem
.WriteByte(FColor
.G
);
6152 Mem
.WriteByte(FColor
.B
);
6154 Obj_SaveState(@FObj
, Mem
);
6155 // Åñòü ëè àíèìàöèÿ:
6156 anim
:= FAnimation
<> nil;
6157 Mem
.WriteBoolean(anim
);
6158 // Åñëè åñòü - ñîõðàíÿåì:
6160 FAnimation
.SaveState(Mem
);
6161 // Åñòü ëè ìàñêà àíèìàöèè:
6162 anim
:= FAnimationMask
<> nil;
6163 Mem
.WriteBoolean(anim
);
6164 // Åñëè åñòü - ñîõðàíÿåì:
6166 FAnimationMask
.SaveState(Mem
);
6169 procedure TCorpse
.LoadState(var Mem
: TBinMemoryReader
);
6179 if sig
<> CORPSE_SIGNATURE
then // 'CORP'
6181 raise EBinSizeError
.Create('TCorpse.LoadState: Wrong Corpse Signature');
6184 Mem
.ReadByte(FState
);
6185 // Íàêîïëåííûé óðîí:
6186 Mem
.ReadByte(FDamage
);
6188 Mem
.ReadByte(FColor
.R
);
6189 Mem
.ReadByte(FColor
.G
);
6190 Mem
.ReadByte(FColor
.B
);
6192 Obj_LoadState(@FObj
, Mem
);
6193 // Åñòü ëè àíèìàöèÿ:
6194 Mem
.ReadBoolean(anim
);
6195 // Åñëè åñòü - çàãðóæàåì:
6198 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6199 FAnimation
.LoadState(Mem
);
6201 // Åñòü ëè ìàñêà àíèìàöèè:
6202 Mem
.ReadBoolean(anim
);
6203 // Åñëè åñòü - çàãðóæàåì:
6206 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6207 FAnimationMask
.LoadState(Mem
);
6213 constructor TBot
.Create();
6220 FSpectator
:= False;
6227 for a
:= WP_FIRST
to WP_LAST
do
6229 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6230 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6231 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6235 destructor TBot
.Destroy();
6238 inherited Destroy();
6241 procedure TBot
.Draw();
6245 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6246 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6249 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6251 inherited Respawn(Silent
, Force
);
6254 FSelectedWeapon
:= FCurrWeap
;
6259 procedure TBot
.UpdateCombat();
6272 TTargetRecord
= array of TTarget
;
6274 function Compare(a
, b
: TTarget
): Integer;
6276 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6279 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6281 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6282 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6284 if a
.Dist
> b
.Dist
then // B áëèæå
6286 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6289 else // Ñòðàííî -> A
6294 a
, x1
, y1
, x2
, y2
: Integer;
6295 targets
: TTargetRecord
;
6297 Target
, BestTarget
: TTarget
;
6298 firew
, fireh
: Integer;
6302 vsPlayer
, vsMonster
, ok
: Boolean;
6304 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6305 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6307 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6308 if FCurrWeap
<> FSelectedWeapon
then
6311 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6312 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6314 RemoveAIFlag('NEEDFIRE');
6317 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6318 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6319 else PressKey(KEY_FIRE
);
6323 // Êîîðäèíàòû ñòâîëà:
6324 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6325 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6327 Target
.UID
:= FTargetUID
;
6330 if Target
.UID
<> 0 then
6331 begin // Öåëü åñòü - íàñòðàèâàåì
6332 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6335 tpla
:= g_Player_Get(Target
.UID
);
6339 if (@FObj
) <> nil then
6346 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6347 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6348 Target
.Rect
:= PLAYER_RECT
;
6349 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6350 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6351 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6352 Target
.IsPlayer
:= True;
6356 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6359 mon
:= g_Monsters_Get(Target
.UID
);
6362 Target
.X
:= mon
.Obj
.X
;
6363 Target
.Y
:= mon
.Obj
.Y
;
6365 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6366 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6367 Target
.Rect
:= mon
.Obj
.Rect
;
6368 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6369 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6370 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6371 Target
.IsPlayer
:= False;
6378 begin // Öåëè íåò - îáíóëÿåì
6383 Target
.Visible
:= False;
6384 Target
.Line
:= False;
6385 Target
.IsPlayer
:= False;
6390 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6391 if (not Target
.Line
) or (not Target
.Visible
) then
6395 for a
:= 0 to High(gPlayers
) do
6396 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].Live
) and
6397 (gPlayers
[a
].FUID
<> FUID
) and
6398 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6399 (not gPlayers
[a
].NoTarget
) and
6400 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6402 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6403 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6406 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6407 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6409 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6410 if g_TraceVector(x1
, y1
, x2
, y2
) then
6412 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6413 SetLength(targets
, Length(targets
)+1);
6414 with targets
[High(targets
)] do
6416 UID
:= gPlayers
[a
].FUID
;
6417 X
:= gPlayers
[a
].FObj
.X
;
6418 Y
:= gPlayers
[a
].FObj
.Y
;
6421 Rect
:= PLAYER_RECT
;
6422 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6423 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6424 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6432 if vsMonster
and (gMonsters
<> nil) then
6433 for a
:= 0 to High(gMonsters
) do
6434 if (gMonsters
[a
] <> nil) and (gMonsters
[a
].Live
) and
6435 (gMonsters
[a
].MonsterType
<> MONSTER_BARREL
) then
6437 mon
:= gMonsters
[a
];
6439 if not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
6440 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
) then
6443 x2
:= mon
.Obj
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6444 y2
:= mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6446 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6447 if g_TraceVector(x1
, y1
, x2
, y2
) then
6449 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6450 SetLength(targets
, Length(targets
)+1);
6451 with targets
[High(targets
)] do
6458 Rect
:= mon
.Obj
.Rect
;
6459 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6460 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6461 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6469 // Åñëè åñòü âîçìîæíûå öåëè:
6470 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6471 if targets
<> nil then
6473 // Âûáèðàåì íàèëó÷øóþ öåëü:
6474 BestTarget
:= targets
[0];
6475 if Length(targets
) > 1 then
6476 for a
:= 1 to High(targets
) do
6477 if Compare(BestTarget
, targets
[a
]) = 1 then
6478 BestTarget
:= targets
[a
];
6480 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6481 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6482 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6484 Target
:= BestTarget
;
6486 if (Healthy() = 3) or ((Healthy() = 2)) then
6487 begin // Åñëè çäîðîâû - äîãîíÿåì
6488 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6489 SetAIFlag('GORIGHT', '1');
6490 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6491 SetAIFlag('GOLEFT', '1');
6494 begin // Åñëè ïîáèòû - óáåãàåì
6495 if ((RunDirection() = D_LEFT
) and (Target
.X
< FObj
.X
)) then
6496 SetAIFlag('GORIGHT', '1');
6497 if ((RunDirection() = D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6498 SetAIFlag('GOLEFT', '1');
6501 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6502 SelectWeapon(Abs(x1
-Target
.cX
));
6507 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6508 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6509 if Target
.UID
<> 0 then
6511 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6512 Target
.Y
+ Target
.Rect
.Y
) then
6513 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6514 if (Healthy() = 3) or ((Healthy() = 2)) then
6515 begin // Åñëè çäîðîâû - äîãîíÿåì
6516 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6517 SetAIFlag('GORIGHT', '1');
6518 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6519 SetAIFlag('GOLEFT', '1');
6522 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6524 if ((RunDirection() = D_LEFT
) and (Target
.X
< FObj
.X
)) then
6525 SetAIFlag('GORIGHT', '1');
6526 if ((RunDirection() = D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6527 SetAIFlag('GOLEFT', '1');
6531 begin // Öåëü ïîêà íà "ýêðàíå"
6532 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6533 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6534 FLastVisible
:= gTime
;
6535 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6536 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6538 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6539 SetAIFlag('GORIGHT', '1');
6540 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6541 SetAIFlag('GOLEFT', '1');
6545 // Âûáèðàåì óãîë ââåðõ:
6546 if FDirection
= D_LEFT
then
6547 angle
:= ANGLE_LEFTUP
6549 angle
:= ANGLE_RIGHTUP
;
6551 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6552 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6554 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6555 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6556 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6557 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6558 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6559 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6560 begin // òî íóæíî ñòðåëÿòü ââåðõ
6561 SetAIFlag('NEEDFIRE', '1');
6562 SetAIFlag('NEEDSEEUP', '1');
6565 // Âûáèðàåì óãîë âíèç:
6566 if FDirection
= D_LEFT
then
6567 angle
:= ANGLE_LEFTDOWN
6569 angle
:= ANGLE_RIGHTDOWN
;
6571 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6572 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6574 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6575 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6576 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6577 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6578 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6579 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6580 begin // òî íóæíî ñòðåëÿòü âíèç
6581 SetAIFlag('NEEDFIRE', '1');
6582 SetAIFlag('NEEDSEEDOWN', '1');
6585 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6586 if Target
.Visible
and
6587 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6588 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6590 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6591 if ((FDirection
= D_LEFT
) and (Target
.X
< FObj
.X
)) or
6592 ((FDirection
= D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6593 begin // òî íóæíî ñòðåëÿòü âïåðåä
6594 SetAIFlag('NEEDFIRE', '1');
6595 SetAIFlag('NEEDSEEDOWN', '');
6596 SetAIFlag('NEEDSEEUP', '');
6598 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6599 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6600 if GetRnd(FDifficult
.CloseJump
) then
6601 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6602 if Abs(FObj
.X
-Target
.X
) < 128 then
6606 if Random(a
) = 0 then
6607 SetAIFlag('NEEDJUMP', '1');
6611 // Åñëè öåëü âñå åùå åñòü:
6612 if Target
.UID
<> 0 then
6613 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
6614 Target
.UID
:= 0 // òî çàáûòü öåëü
6615 else // Åñëè âèäåëè íåäàâíî
6616 begin // íî öåëü óáèëè
6617 if Target
.IsPlayer
then
6618 begin // Öåëü - èãðîê
6619 pla
:= g_Player_Get(Target
.UID
);
6620 if (pla
= nil) or (not pla
.Live
) or pla
.NoTarget
or
6621 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6622 Target
.UID
:= 0; // òî çàáûòü öåëü
6625 begin // Öåëü - ìîíñòð
6626 mon
:= g_Monsters_Get(Target
.UID
);
6627 if (mon
= nil) or (not mon
.Live
) then
6628 Target
.UID
:= 0; // òî çàáûòü öåëü
6631 end; // if Target.UID <> 0
6633 FTargetUID
:= Target
.UID
;
6635 // Åñëè âîçìîæíûõ öåëåé íåò:
6636 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
6637 if targets
= nil then
6638 if GetAIFlag('ATTACKLEFT') <> '' then
6639 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
6640 RemoveAIFlag('ATTACKLEFT');
6642 SetAIFlag('NEEDJUMP', '1');
6644 if RunDirection() = D_RIGHT
then
6645 begin // Èäåì íå â òó ñòîðîíó
6646 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6647 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
6648 SetAIFlag('NEEDFIRE', '1');
6649 SetAIFlag('GOLEFT', '1');
6653 begin // Èäåì â íóæíóþ ñòîðîíó
6654 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6655 SetAIFlag('NEEDFIRE', '1');
6656 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6657 SetAIFlag('GORIGHT', '1');
6661 if GetAIFlag('ATTACKRIGHT') <> '' then
6662 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
6663 RemoveAIFlag('ATTACKRIGHT');
6665 SetAIFlag('NEEDJUMP', '1');
6667 if RunDirection() = D_LEFT
then
6668 begin // Èäåì íå â òó ñòîðîíó
6669 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6670 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
6671 SetAIFlag('NEEDFIRE', '1');
6672 SetAIFlag('GORIGHT', '1');
6677 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6678 SetAIFlag('NEEDFIRE', '1');
6679 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6680 SetAIFlag('GOLEFT', '1');
6684 //HACK! (does it belongs there?)
6685 RealizeCurrentWeapon();
6687 // Åñëè åñòü âîçìîæíûå öåëè:
6688 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
6689 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6690 for a
:= 0 to High(targets
) do
6692 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
6693 if GetRnd(FDifficult
.DiagFire
) then
6695 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
6696 if FDirection
= D_LEFT
then
6697 angle
:= ANGLE_LEFTUP
6699 angle
:= ANGLE_RIGHTUP
;
6701 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6702 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6704 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6705 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6706 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6707 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6708 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6710 SetAIFlag('NEEDFIRE', '1');
6711 SetAIFlag('NEEDSEEUP', '1');
6714 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
6715 if FDirection
= D_LEFT
then
6716 angle
:= ANGLE_LEFTDOWN
6718 angle
:= ANGLE_RIGHTDOWN
;
6720 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6721 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6723 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6724 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6725 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6726 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6727 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6729 SetAIFlag('NEEDFIRE', '1');
6730 SetAIFlag('NEEDSEEDOWN', '1');
6734 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
6735 if targets
[a
].Line
and targets
[a
].Visible
and
6736 (((FDirection
= D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
6737 ((FDirection
= D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
6739 SetAIFlag('NEEDFIRE', '1');
6744 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
6745 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
6746 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
6747 40+GetInterval(FDifficult
.Cover
, 40)) then
6748 SetAIFlag('NEEDJUMP', '1');
6750 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
6751 ammo
:= GetAmmoByWeapon(FCurrWeap
);
6752 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
6753 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
6755 SetAIFlag('SELECTWEAPON', '1');
6757 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
6758 if GetAIFlag('SELECTWEAPON') = '1' then
6761 RemoveAIFlag('SELECTWEAPON');
6765 procedure TBot
.Update();
6778 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
6779 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
6781 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
6783 if g_debug_BotAIOff
= 3 then
6793 RealizeCurrentWeapon();
6800 procedure TBot
.ReleaseKey(Key
: Byte);
6809 function TBot
.KeyPressed(Key
: Word): Boolean;
6811 Result
:= FKeys
[Key
].Pressed
;
6814 function TBot
.GetAIFlag(aName
: String20
): String20
;
6820 aName
:= LowerCase(aName
);
6822 if FAIFlags
<> nil then
6823 for a
:= 0 to High(FAIFlags
) do
6824 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6826 Result
:= FAIFlags
[a
].Value
;
6831 procedure TBot
.RemoveAIFlag(aName
: String20
);
6835 if FAIFlags
= nil then Exit
;
6837 aName
:= LowerCase(aName
);
6839 for a
:= 0 to High(FAIFlags
) do
6840 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6842 if a
<> High(FAIFlags
) then
6843 for b
:= a
to High(FAIFlags
)-1 do
6844 FAIFlags
[b
] := FAIFlags
[b
+1];
6846 SetLength(FAIFlags
, Length(FAIFlags
)-1);
6851 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
6859 aName
:= LowerCase(aName
);
6861 if FAIFlags
<> nil then
6862 for a
:= 0 to High(FAIFlags
) do
6863 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6869 if ok
then FAIFlags
[a
].Value
:= fValue
6872 SetLength(FAIFlags
, Length(FAIFlags
)+1);
6873 with FAIFlags
[High(FAIFlags
)] do
6881 procedure TBot
.UpdateMove
;
6883 procedure GoLeft(Time
: Word = 1);
6885 ReleaseKey(KEY_LEFT
);
6886 ReleaseKey(KEY_RIGHT
);
6887 PressKey(KEY_LEFT
, Time
);
6888 SetDirection(D_LEFT
);
6891 procedure GoRight(Time
: Word = 1);
6893 ReleaseKey(KEY_LEFT
);
6894 ReleaseKey(KEY_RIGHT
);
6895 PressKey(KEY_RIGHT
, Time
);
6896 SetDirection(D_RIGHT
);
6899 function Rnd(a
: Word): Boolean;
6901 Result
:= Random(a
) = 0;
6904 procedure Turn(Time
: Word = 1200);
6906 if RunDirection() = D_LEFT
then GoRight(Time
) else GoLeft(Time
);
6911 ReleaseKey(KEY_LEFT
);
6912 ReleaseKey(KEY_RIGHT
);
6915 function CanRunLeft(): Boolean;
6917 Result
:= not CollideLevel(-1, 0);
6920 function CanRunRight(): Boolean;
6922 Result
:= not CollideLevel(1, 0);
6925 function CanRun(): Boolean;
6927 if RunDirection() = D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
6930 procedure Jump(Time
: Word = 30);
6932 PressKey(KEY_JUMP
, Time
);
6935 function NearHole(): Boolean;
6939 { TODO 5 : Ëåñòíèöû }
6940 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6941 for x
:= 1 to PLAYER_RECT
.Width
do
6942 if (not StayOnStep(x
*sx
, 0)) and
6943 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6944 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6953 function BorderHole(): Boolean;
6957 { TODO 5 : Ëåñòíèöû }
6958 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6959 for x
:= 1 to PLAYER_RECT
.Width
do
6960 if (not StayOnStep(x
*sx
, 0)) and
6961 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6962 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6964 for xx
:= x
to x
+32 do
6965 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
6975 function NearDeepHole(): Boolean;
6981 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6984 for x
:= 1 to PLAYER_RECT
.Width
do
6985 if (not StayOnStep(x
*sx
, 0)) and
6986 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6987 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6989 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6991 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
6996 end else Result
:= False;
6999 function OverDeepHole(): Boolean;
7006 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7008 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7015 function OnGround(): Boolean;
7017 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7020 function OnLadder(): Boolean;
7022 Result
:= FullInStep(0, 0);
7025 function BelowLadder(): Boolean;
7027 Result
:= (FullInStep(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7028 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7029 (FullInStep(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7030 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7033 function BelowLiftUp(): Boolean;
7035 Result
:= ((FullInLift(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7036 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7037 ((FullInLift(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7038 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7041 function OnTopLift(): Boolean;
7043 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7046 function CanJumpOver(): Boolean;
7050 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
7054 if not CollideLevel(sx
, 0) then Exit
;
7056 for y
:= 1 to BOT_MAXJUMP
do
7057 if CollideLevel(0, -y
) then Exit
else
7058 if not CollideLevel(sx
, -y
) then
7065 function CanJumpUp(Dist
: ShortInt): Boolean;
7072 if CollideLevel(Dist
, 0) then Exit
;
7075 for y
:= 0 to BOT_MAXJUMP
do
7076 if CollideLevel(Dist
, -y
) then
7085 for yy
:= y
+1 to BOT_MAXJUMP
do
7086 if not CollideLevel(Dist
, -yy
) then
7095 for y
:= 0 to BOT_MAXJUMP
do
7096 if CollideLevel(0, -y
) then
7104 if y
< yy
then Exit
;
7109 function IsSafeTrigger(): Boolean;
7114 if gTriggers
= nil then
7116 for a
:= 0 to High(gTriggers
) do
7117 if Collide(gTriggers
[a
].X
,
7120 gTriggers
[a
].Height
) and
7121 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7122 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7123 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7124 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7125 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7130 // Âîçìîæíî, íàæèìàåì êíîïêó:
7131 if Rnd(16) and IsSafeTrigger() then
7134 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7135 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7137 ReleaseKey(KEY_LEFT
);
7138 ReleaseKey(KEY_RIGHT
);
7142 // Èäåì âëåâî, åñëè íàäî áûëî:
7143 if GetAIFlag('GOLEFT') <> '' then
7145 RemoveAIFlag('GOLEFT');
7146 if CanRunLeft() then
7150 // Èäåì âïðàâî, åñëè íàäî áûëî:
7151 if GetAIFlag('GORIGHT') <> '' then
7153 RemoveAIFlag('GORIGHT');
7154 if CanRunRight() then
7158 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7159 if FObj
.X
< -32 then
7162 if FObj
.X
+32 > gMapInfo
.Width
then
7165 // Ïðûãàåì, åñëè íàäî áûëî:
7166 if GetAIFlag('NEEDJUMP') <> '' then
7169 RemoveAIFlag('NEEDJUMP');
7172 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7173 if GetAIFlag('NEEDSEEUP') <> '' then
7176 ReleaseKey(KEY_DOWN
);
7177 PressKey(KEY_UP
, 20);
7178 RemoveAIFlag('NEEDSEEUP');
7181 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7182 if GetAIFlag('NEEDSEEDOWN') <> '' then
7185 ReleaseKey(KEY_DOWN
);
7186 PressKey(KEY_DOWN
, 20);
7187 RemoveAIFlag('NEEDSEEDOWN');
7190 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7191 if GetAIFlag('GOINHOLE') <> '' then
7192 if not OnGround() then
7194 ReleaseKey(KEY_LEFT
);
7195 ReleaseKey(KEY_RIGHT
);
7196 RemoveAIFlag('GOINHOLE');
7197 SetAIFlag('FALLINHOLE', '1');
7200 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7201 if GetAIFlag('FALLINHOLE') <> '' then
7203 RemoveAIFlag('FALLINHOLE');
7205 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7206 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7207 if GetAIFlag('FALLINHOLE') = '' then
7208 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7214 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7216 CanJumpUp(IfThen(RunDirection() = D_LEFT
, -1, 1)*32) and
7220 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7221 if OnGround() and NearHole() then
7222 if NearDeepHole() then // Åñëè ýòî áåçäíà
7224 0..3: Turn(); // Áåæèì îáðàòíî
7225 4: Jump(); // Ïðûãàåì
7226 5: begin // Ïðûãàåì îáðàòíî
7231 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7232 if GetAIFlag('GOINHOLE') = '' then
7234 0: Turn(); // Íå íóæíî òóäà
7235 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7236 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7237 if BorderHole() then
7238 SetAIFlag('GOINHOLE', '1');
7241 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7242 if (not CanRun()) and OnGround() then
7244 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7245 if CanJumpOver() or OnLadder() then
7247 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7248 if Random(2) = 0 then
7250 if IsSafeTrigger() then
7256 // Îñòàëîñü ìàëî âîçäóõà:
7257 if FAir
< 36 * 2 then
7260 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7261 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7262 if BodyInAcid(0, 0) then
7266 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7268 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7269 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7272 {function TBot.NeedItem(Item: Byte): Byte;
7277 procedure TBot
.SelectWeapon(Dist
: Integer);
7281 function HaveAmmo(weapon
: Byte): Boolean;
7284 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7285 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7286 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7287 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7288 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7289 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7290 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7291 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7292 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7293 else Result
:= True;
7298 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7300 if Dist
> BOT_LONGDIST
then
7301 begin // Äàëüíèé áîé
7303 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7305 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7309 else //if Dist > BOT_UNSAFEDIST then
7310 begin // Áëèæíèé áîé
7312 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7314 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7321 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7323 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7329 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7331 Result
:= inherited PickItem(ItemType
, force
, remove
);
7333 if Result
then SetAIFlag('SELECTWEAPON', '1');
7336 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7338 Result
:= inherited Heal(value
, Soft
);
7341 function TBot
.Healthy(): Byte;
7343 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7344 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7345 else if (FHealth
> 50) then Result
:= 2
7346 else if (FHealth
> 20) then Result
:= 1
7350 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7352 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7353 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7356 procedure TBot
.OnDamage(Angle
: SmallInt);
7364 if (Angle
= 0) or (Angle
= 180) then
7367 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7368 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7370 pla
:= g_Player_Get(FLastSpawnerUID
);
7371 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7372 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7375 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7376 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7378 mon
:= g_Monsters_Get(FLastSpawnerUID
);
7379 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7380 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7385 SetAIFlag('ATTACKLEFT', '1')
7387 SetAIFlag('ATTACKRIGHT', '1');
7391 function TBot
.RunDirection(): TDirection
;
7393 if Abs(Vel
.X
) >= 1 then
7395 if Vel
.X
> 0 then Result
:= D_RIGHT
else Result
:= D_LEFT
;
7397 Result
:= FDirection
;
7400 function TBot
.GetRnd(a
: Byte): Boolean;
7402 if a
= 0 then Result
:= False
7403 else if a
= 255 then Result
:= True
7404 else Result
:= Random(256) > 255-a
;
7407 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7409 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7412 procedure TBot
.SaveState(var Mem
: TBinMemoryWriter
);
7418 inherited SaveState(Mem
);
7420 // Âûáðàííîå îðóæèå:
7421 Mem
.WriteByte(FSelectedWeapon
);
7423 Mem
.WriteWord(FTargetUID
);
7424 // Âðåìÿ ïîòåðè öåëè:
7425 Mem
.WriteDWORD(FLastVisible
);
7426 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7427 dw
:= Length(FAIFlags
);
7430 for i
:= 0 to Integer(dw
)-1 do
7432 Mem
.WriteString(FAIFlags
[i
].Name
, 20);
7433 Mem
.WriteString(FAIFlags
[i
].Value
, 20);
7435 // Íàñòðîéêè ñëîæíîñòè:
7437 Mem
.WriteMemory(p
, SizeOf(TDifficult
));
7440 procedure TBot
.LoadState(var Mem
: TBinMemoryReader
);
7446 inherited LoadState(Mem
);
7448 // Âûáðàííîå îðóæèå:
7449 Mem
.ReadByte(FSelectedWeapon
);
7451 Mem
.ReadWord(FTargetUID
);
7452 // Âðåìÿ ïîòåðè öåëè:
7453 Mem
.ReadDWORD(FLastVisible
);
7454 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7456 SetLength(FAIFlags
, dw
);
7458 for i
:= 0 to Integer(dw
)-1 do
7460 Mem
.ReadString(FAIFlags
[i
].Name
);
7461 Mem
.ReadString(FAIFlags
[i
].Value
);
7463 // Íàñòðîéêè ñëîæíîñòè:
7464 Mem
.ReadMemory(p
, dw
);
7465 if dw
<> SizeOf(TDifficult
) then
7467 raise EBinSizeError
.Create('TBot.LoadState: Wrong FDifficult Size');
7469 FDifficult
:= TDifficult(p
^);