1 (* Copyright (C) DooM 2D:Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 e_graphics
, g_playermodel
, g_basic
, g_textures
,
23 g_weapons
, g_phys
, g_sound
, g_saveload
, MAPSTRUCT
,
56 AmmoLimits
: Array [0..1] of Array [A_BULLETS
..A_HIGH
] of Word =
57 ((200, 50, 50, 300, 100),
58 (400, 100, 100, 600, 200));
79 ANGLE_NONE
= Low(SmallInt);
81 CORPSE_STATE_REMOVEME
= 0;
82 CORPSE_STATE_NORMAL
= 1;
83 CORPSE_STATE_MESS
= 2;
85 PLAYER_RECT
: TRectWH
= (X
:15; Y
:12; Width
:34; Height
:52);
86 PLAYER_RECT_CX
= 15+(34 div 2);
87 PLAYER_RECT_CY
= 12+(52 div 2);
88 PLAYER_CORPSERECT
: TRectWH
= (X
:15; Y
:48; Width
:34; Height
:16);
91 PLAYER_HP_LIMIT
= 200;
93 PLAYER_AP_LIMIT
= 200;
96 PLAYER1_DEF_COLOR
: TRGB
= (R
:64; G
:175; B
:48);
97 PLAYER2_DEF_COLOR
: TRGB
= (R
:96; G
:96; B
:96);
113 TPlayerStatArray
= Array of TPlayerStat
;
115 TPlayerSavedState
= record
123 Ammo
: Array [A_BULLETS
..A_HIGH
] of Word;
124 MaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
125 Weapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
126 Rulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
135 TPlayer
= class (TObject
)
143 FDirection
: TDirection
;
151 FMonsterKills
: Integer;
157 FCanJetpack
: Boolean;
163 FNextWeapDelay
: Byte; // frames
164 FBFGFireCounter
: SmallInt;
165 FLastSpawnerUID
: Word;
169 FSpectatePlayer
: Integer;
171 FSavedState
: TPlayerSavedState
;
173 FModel
: TPlayerModel
;
176 FActionForce
: Boolean;
177 FActionChanged
: Boolean;
179 FFireAngle
: SmallInt;
181 FShellTimer
: Integer;
183 FSawSound
: TPlayableSound
;
184 FSawSoundIdle
: TPlayableSound
;
185 FSawSoundHit
: TPlayableSound
;
186 FSawSoundSelect
: TPlayableSound
;
187 FJetSoundOn
: TPlayableSound
;
188 FJetSoundOff
: TPlayableSound
;
189 FJetSoundFly
: TPlayableSound
;
193 FJustTeleported
: Boolean;
196 function CollideLevel(XInc
, YInc
: Integer): Boolean;
197 function StayOnStep(XInc
, YInc
: Integer): Boolean;
198 function HeadInLiquid(XInc
, YInc
: Integer): Boolean;
199 function BodyInLiquid(XInc
, YInc
: Integer): Boolean;
200 function BodyInAcid(XInc
, YInc
: Integer): Boolean;
201 function FullInLift(XInc
, YInc
: Integer): Integer;
202 {procedure CollideItem();}
203 procedure FlySmoke(Times
: DWORD
= 1);
204 function GetAmmoByWeapon(Weapon
: Byte): Word;
205 procedure SetAction(Action
: Byte; Force
: Boolean = False);
206 procedure OnDamage(Angle
: SmallInt); virtual;
207 function firediry(): Integer;
209 procedure Run(Direction
: TDirection
);
210 procedure NextWeapon();
211 procedure PrevWeapon();
218 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
219 procedure resetWeaponQueue ();
220 function hasAmmoForWeapon (weapon
: Byte): Boolean;
223 FDamageBuffer
: Integer;
225 FAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
226 FMaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
227 FWeapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
228 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
230 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
231 FReloading
: Array [WP_FIRST
..WP_LAST
] of Word;
232 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
233 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
235 FPreferredTeam
: Byte;
238 FWantsInGame
: Boolean;
242 FActualModelName
: string;
248 constructor Create(); virtual;
249 destructor Destroy(); override;
250 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
251 function GetRespawnPoint(): Byte;
252 procedure PressKey(Key
: Byte; Time
: Word = 1);
253 procedure ReleaseKeys();
254 procedure SetModel(ModelName
: String);
255 procedure SetColor(Color
: TRGB
);
256 procedure SetWeapon(W
: Byte);
257 function IsKeyPressed(K
: Byte): Boolean;
258 function GetKeys(): Byte;
259 function PickItem(ItemType
: Byte; respawn
: Boolean; var remove
: Boolean): Boolean; virtual;
260 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
261 function Collide(Panel
: TPanel
): Boolean; overload
;
262 function Collide(X
, Y
: Integer): Boolean; overload
;
263 procedure SetDirection(Direction
: TDirection
);
264 procedure GetSecret();
265 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
267 procedure Push(vx
, vy
: Integer);
268 procedure ChangeModel(ModelName
: String);
269 procedure SwitchTeam
;
270 procedure ChangeTeam(Team
: Byte);
272 function GetFlag(Flag
: Byte): Boolean;
273 procedure SetFlag(Flag
: Byte);
274 function DropFlag(): Boolean;
275 procedure AllRulez(Health
: Boolean);
276 procedure RestoreHealthArmor();
277 procedure FragCombo();
278 procedure GiveItem(ItemType
: Byte);
279 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
280 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
281 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
282 procedure MakeBloodSimple(Count
: Word);
283 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
284 procedure Reset(Force
: Boolean);
285 procedure Spectate(NoMove
: Boolean = False);
286 procedure SwitchNoClip
;
287 procedure SoftReset();
288 procedure Draw(); virtual;
289 procedure DrawPain();
290 procedure DrawPickup();
291 procedure DrawRulez();
293 procedure DrawBubble();
295 procedure Update(); virtual;
296 procedure RememberState();
297 procedure RecallState();
298 procedure SaveState(var Mem
: TBinMemoryWriter
); virtual;
299 procedure LoadState(var Mem
: TBinMemoryReader
); virtual;
300 procedure PauseSounds(Enable
: Boolean);
301 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
302 procedure DoLerp(Level
: Integer = 2);
303 procedure SetLerp(XTo
, YTo
: Integer);
304 procedure QueueWeaponSwitch(Weapon
: Byte);
305 procedure RealizeCurrentWeapon();
307 procedure JetpackOff
;
309 property Name
: String read FName write FName
;
310 property Model
: TPlayerModel read FModel
;
311 property Health
: Integer read FHealth write FHealth
;
312 property Lives
: Byte read FLives write FLives
;
313 property Armor
: Integer read FArmor write FArmor
;
314 property Air
: Integer read FAir write FAir
;
315 property JetFuel
: Integer read FJetFuel write FJetFuel
;
316 property Frags
: Integer read FFrags write FFrags
;
317 property Death
: Integer read FDeath write FDeath
;
318 property Kills
: Integer read FKills write FKills
;
319 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
320 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
321 property Secrets
: Integer read FSecrets
;
322 property GodMode
: Boolean read FGodMode write FGodMode
;
323 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
324 property NoReload
: Boolean read FNoReload write FNoReload
;
325 property Live
: Boolean read FLive write FLive
;
326 property Flag
: Byte read FFlag
;
327 property Team
: Byte read FTeam write FTeam
;
328 property Direction
: TDirection read FDirection
;
329 property GameX
: Integer read FObj
.X write FObj
.X
;
330 property GameY
: Integer read FObj
.Y write FObj
.Y
;
331 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
332 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
333 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
334 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
335 property Vel
: TPoint2i read FObj
.Vel
;
336 property Obj
: TObj read FObj
;
337 property IncCam
: Integer read FIncCam write FIncCam
;
338 property UID
: Word read FUID write FUID
;
339 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
340 property NetTime
: LongWord read FNetTime write FNetTime
;
350 WeaponPrior
: Array [WP_FIRST
..WP_LAST
] of Byte;
351 CloseWeaponPrior
: Array [WP_FIRST
..WP_LAST
] of Byte;
352 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
360 TBot
= class (TPlayer
)
362 FSelectedWeapon
: Byte;
365 FAIFlags
: Array of TAIFlag
;
366 FDifficult
: TDifficult
;
368 function GetRnd(a
: Byte): Boolean;
369 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
370 function RunDirection(): TDirection
;
371 function FullInStep(XInc
, YInc
: Integer): Boolean;
372 //function NeedItem(Item: Byte): Byte;
373 procedure SelectWeapon(Dist
: Integer);
374 procedure SetAIFlag(fName
, fValue
: String20
);
375 function GetAIFlag(fName
: String20
): String20
;
376 procedure RemoveAIFlag(fName
: String20
);
377 function Healthy(): Byte;
378 procedure UpdateMove();
379 procedure UpdateCombat();
380 function KeyPressed(Key
: Word): Boolean;
381 procedure ReleaseKey(Key
: Byte);
382 function TargetOnScreen(TX
, TY
: Integer): Boolean;
383 procedure OnDamage(Angle
: SmallInt); override;
386 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
387 constructor Create(); override;
388 destructor Destroy(); override;
389 procedure Draw(); override;
390 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
391 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
392 procedure Update(); override;
393 procedure SaveState(var Mem
: TBinMemoryWriter
); override;
394 procedure LoadState(var Mem
: TBinMemoryReader
); override;
416 TCorpse
= class (TObject
)
424 FAnimation
: TAnimation
;
425 FAnimationMask
: TAnimation
;
428 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
429 destructor Destroy(); override;
430 procedure Damage(Value
: Word; vx
, vy
: Integer);
433 procedure SaveState(var Mem
: TBinMemoryWriter
);
434 procedure LoadState(var Mem
: TBinMemoryReader
);
436 property Obj
: TObj read FObj
;
437 property State
: Byte read FState
;
438 property Mess
: Boolean read FMess
;
441 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
447 gPlayers
: Array of TPlayer
;
448 gCorpses
: Array of TCorpse
;
449 gGibs
: Array of TGib
;
450 gShells
: Array of TShell
;
451 gTeamStat
: TTeamStat
;
452 gFly
: Boolean = False;
453 gAimLine
: Boolean = False;
454 gChatBubble
: Byte = 0;
458 MAX_RUNVEL
: Integer = 8;
459 VEL_JUMP
: Integer = 10;
460 SHELL_TIMEOUT
: Cardinal = 60000;
462 function Lerp(X
, Y
, Factor
: Integer): Integer;
464 procedure g_Gibs_SetMax(Count
: Word);
465 function g_Gibs_GetMax(): Word;
466 procedure g_Corpses_SetMax(Count
: Word);
467 function g_Corpses_GetMax(): Word;
468 procedure g_Shells_SetMax(Count
: Word);
469 function g_Shells_GetMax(): Word;
471 procedure g_Player_Init();
472 procedure g_Player_Free();
473 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
474 function g_Player_CreateFromState(var Mem
: TBinMemoryReader
): Word;
475 procedure g_Player_Remove(UID
: Word);
476 procedure g_Player_ResetTeams();
477 procedure g_Player_UpdateAll();
478 procedure g_Player_DrawAll();
479 procedure g_Player_DrawDebug(p
: TPlayer
);
480 procedure g_Player_DrawHealth();
481 procedure g_Player_RememberAll();
482 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
483 function g_Player_Get(UID
: Word): TPlayer
;
484 function g_Player_GetCount(): Byte;
485 function g_Player_GetStats(): TPlayerStatArray
;
486 function g_Player_ValidName(Name
: String): Boolean;
487 procedure g_Player_CreateCorpse(Player
: TPlayer
);
488 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
489 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
490 procedure g_Player_UpdatePhysicalObjects();
491 procedure g_Player_DrawCorpses();
492 procedure g_Player_DrawShells();
493 procedure g_Player_RemoveAllCorpses();
494 procedure g_Player_Corpses_SaveState(var Mem
: TBinMemoryWriter
);
495 procedure g_Player_Corpses_LoadState(var Mem
: TBinMemoryReader
);
496 procedure g_Bot_Add(Team
, Difficult
: Byte);
497 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1);
498 procedure g_Bot_MixNames();
499 procedure g_Bot_RemoveAll();
504 e_log
, g_map
, g_items
, g_console
, SysUtils
, g_gfx
, Math
,
505 g_options
, g_triggers
, g_menu
, MAPDEF
, g_game
,
506 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
, g_net
, g_netmsg
;
516 diag_precision
: Byte;
520 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
521 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
522 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
526 TIME_RESPAWN1
= 1500;
527 TIME_RESPAWN2
= 2000;
528 TIME_RESPAWN3
= 3000;
531 JET_MAX
= 540; // ~30 sec
532 PLAYER_SUIT_TIME
= 30000;
533 PLAYER_INVUL_TIME
= 30000;
534 PLAYER_INVIS_TIME
= 35000;
535 FRAG_COMBO_TIME
= 3000;
539 ANGLE_RIGHTDOWN
= -35;
541 ANGLE_LEFTDOWN
= -145;
542 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
543 WEAPONPOINT
: Array [TDirection
] of TPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
546 BOT_UNSAFEDIST
= 128;
547 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
549 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
550 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
551 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
552 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
553 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
554 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
555 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
556 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
557 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
558 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
559 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
560 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
561 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
562 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
563 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
564 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
565 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
566 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
567 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
568 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
569 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
570 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
571 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
572 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
573 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
574 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 0);
576 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
577 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
579 BOTNAMES_FILENAME
= 'botnames.txt';
580 BOTLIST_FILENAME
= 'botlist.txt';
584 MaxCorpses
: Word = 20;
585 MaxShells
: Word = 300;
586 CurrentGib
: Integer = 0;
587 CurrentShell
: Integer = 0;
588 BotNames
: Array of String;
589 BotList
: Array of TBotProfile
;
591 function Lerp(X
, Y
, Factor
: Integer): Integer;
593 Result
:= X
+ ((Y
- X
) div Factor
);
596 function SameTeam(UID1
, UID2
: Word): Boolean;
600 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
601 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
603 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
605 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
606 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
608 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
611 procedure g_Gibs_SetMax(Count
: Word);
614 SetLength(gGibs
, Count
);
616 if CurrentGib
>= Count
then
620 function g_Gibs_GetMax(): Word;
625 procedure g_Shells_SetMax(Count
: Word);
628 SetLength(gShells
, Count
);
630 if CurrentShell
>= Count
then
634 function g_Shells_GetMax(): Word;
640 procedure g_Corpses_SetMax(Count
: Word);
643 SetLength(gCorpses
, Count
);
646 function g_Corpses_GetMax(): Word;
648 Result
:= MaxCorpses
;
651 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
661 // Åñòü ëè ìåñòî â gPlayers:
662 if gPlayers
<> nil then
663 for a
:= 0 to High(gPlayers
) do
664 if gPlayers
[a
] = nil then
670 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
673 SetLength(gPlayers
, Length(gPlayers
)+1);
677 // Ñîçäàåì îáúåêò èãðîêà:
679 gPlayers
[a
] := TBot
.Create()
681 gPlayers
[a
] := TPlayer
.Create();
684 gPlayers
[a
].FActualModelName
:= ModelName
;
685 gPlayers
[a
].SetModel(ModelName
);
687 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
688 if gPlayers
[a
].FModel
= nil then
692 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
696 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
697 if Random(2) = 0 then
701 gPlayers
[a
].FPreferredTeam
:= Team
;
703 case gGameSettings
.GameMode
of
704 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
706 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
708 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
711 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
712 gPlayers
[a
].FColor
:= Color
;
713 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
714 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
716 gPlayers
[a
].FModel
.Color
:= Color
;
718 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
719 gPlayers
[a
].FLive
:= False;
721 Result
:= gPlayers
[a
].FUID
;
724 function g_Player_CreateFromState(var Mem
: TBinMemoryReader
): Word;
737 if sig
<> PLAYER_SIGNATURE
then // 'PLYR'
739 raise EBinSizeError
.Create('g_Player_CreateFromState: Wrong Player Signature');
743 Mem
.ReadBoolean(Bot
);
748 // Åñòü ëè ìåñòî â gPlayers:
749 if gPlayers
<> nil then
750 for a
:= 0 to High(gPlayers
) do
751 if gPlayers
[a
] = nil then
757 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
760 SetLength(gPlayers
, Length(gPlayers
)+1);
764 // Ñîçäàåì îáúåêò èãðîêà:
766 gPlayers
[a
] := TBot
.Create()
768 gPlayers
[a
] := TPlayer
.Create();
769 gPlayers
[a
].FIamBot
:= Bot
;
770 gPlayers
[a
].FPhysics
:= True;
773 Mem
.ReadWord(gPlayers
[a
].FUID
);
775 Mem
.ReadString(gPlayers
[a
].FName
);
777 Mem
.ReadByte(gPlayers
[a
].FTeam
);
778 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
780 Mem
.ReadBoolean(gPlayers
[a
].FLive
);
781 // Èçðàñõîäîâàë ëè âñå æèçíè:
782 Mem
.ReadBoolean(gPlayers
[a
].FNoRespawn
);
786 gPlayers
[a
].FDirection
:= D_LEFT
788 gPlayers
[a
].FDirection
:= D_RIGHT
;
790 Mem
.ReadInt(gPlayers
[a
].FHealth
);
792 Mem
.ReadByte(gPlayers
[a
].FLives
);
794 Mem
.ReadInt(gPlayers
[a
].FArmor
);
796 Mem
.ReadInt(gPlayers
[a
].FAir
);
798 Mem
.ReadInt(gPlayers
[a
].FJetFuel
);
800 Mem
.ReadInt(gPlayers
[a
].FPain
);
802 Mem
.ReadInt(gPlayers
[a
].FKills
);
804 Mem
.ReadInt(gPlayers
[a
].FMonsterKills
);
806 Mem
.ReadInt(gPlayers
[a
].FFrags
);
808 Mem
.ReadByte(gPlayers
[a
].FFragCombo
);
809 // Âðåìÿ ïîñëåäíåãî ôðàãà:
810 Mem
.ReadDWORD(gPlayers
[a
].FLastFrag
);
812 Mem
.ReadInt(gPlayers
[a
].FDeath
);
814 Mem
.ReadByte(gPlayers
[a
].FFlag
);
816 Mem
.ReadInt(gPlayers
[a
].FSecrets
);
818 Mem
.ReadByte(gPlayers
[a
].FCurrWeap
);
819 // Ñëåäóþùåå æåëàåìîå îðóæèå:
820 Mem
.ReadWord(gPlayers
[a
].FNextWeap
);
822 Mem
.ReadByte(gPlayers
[a
].FNextWeapDelay
);
823 // Âðåìÿ çàðÿäêè BFG:
824 Mem
.ReadSmallInt(gPlayers
[a
].FBFGFireCounter
);
826 Mem
.ReadInt(gPlayers
[a
].FDamageBuffer
);
827 // Ïîñëåäíèé óäàðèâøèé:
828 Mem
.ReadWord(gPlayers
[a
].FLastSpawnerUID
);
829 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
830 Mem
.ReadByte(gPlayers
[a
].FLastHit
);
832 Obj_LoadState(@gPlayers
[a
].FObj
, Mem
);
833 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
834 for i
:= A_BULLETS
to A_HIGH
do
835 Mem
.ReadWord(gPlayers
[a
].FAmmo
[i
]);
836 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
837 for i
:= A_BULLETS
to A_HIGH
do
838 Mem
.ReadWord(gPlayers
[a
].FMaxAmmo
[i
]);
840 for i
:= WP_FIRST
to WP_LAST
do
841 Mem
.ReadBoolean(gPlayers
[a
].FWeapon
[i
]);
842 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
843 for i
:= WP_FIRST
to WP_LAST
do
844 Mem
.ReadWord(gPlayers
[a
].FReloading
[i
]);
848 Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
849 // Íàëè÷èå êðàñíîãî êëþ÷à:
852 Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
853 // Íàëè÷èå çåëåíîãî êëþ÷à:
856 Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
857 // Íàëè÷èå ñèíåãî êëþ÷à:
860 Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
864 Include(gPlayers
[a
].FRulez
, R_BERSERK
);
865 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
866 for i
:= MR_SUIT
to MR_MAX
do
867 Mem
.ReadDWORD(gPlayers
[a
].FMegaRulez
[i
]);
868 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
869 for i
:= T_RESPAWN
to T_FLAGCAP
do
870 Mem
.ReadDWORD(gPlayers
[a
].FTime
[i
]);
873 Mem
.ReadString(gPlayers
[a
].FActualModelName
);
875 Mem
.ReadByte(gPlayers
[a
].FColor
.R
);
876 Mem
.ReadByte(gPlayers
[a
].FColor
.G
);
877 Mem
.ReadByte(gPlayers
[a
].FColor
.B
);
878 // Îáíîâëÿåì ìîäåëü èãðîêà:
879 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
881 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
882 if gPlayers
[a
].FModel
= nil then
886 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
890 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
891 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
892 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
894 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
896 Result
:= gPlayers
[a
].FUID
;
899 procedure g_Player_ResetTeams();
903 if g_Game_IsClient
then
905 if gPlayers
= nil then
907 for a
:= Low(gPlayers
) to High(gPlayers
) do
908 if gPlayers
[a
] <> nil then
909 case gGameSettings
.GameMode
of
911 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
913 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
914 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
915 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
918 gPlayers
[a
].ChangeTeam(TEAM_RED
)
920 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
923 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
927 procedure g_Bot_Add(Team
, Difficult
: Byte);
930 _name
, _model
: String;
933 if not g_Game_IsServer
then Exit
;
935 // Ñïèñîê íàçâàíèé ìîäåëåé:
936 m
:= g_PlayerModel_GetNames();
941 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
942 Team
:= TEAM_COOP
// COOP
944 if gGameSettings
.GameMode
= GM_DM
then
945 Team
:= TEAM_NONE
// DM
947 if Team
= TEAM_NONE
then // CTF / TDM
949 // Àâòîáàëàíñ êîìàíä:
953 for a
:= 0 to High(gPlayers
) do
954 if gPlayers
[a
] <> nil then
956 if gPlayers
[a
].Team
= TEAM_RED
then
959 if gPlayers
[a
].Team
= TEAM_BLUE
then
969 if Random(2) = 0 then
975 // Âûáèðàåì áîòó èìÿ:
977 if BotNames
<> nil then
978 for a
:= 0 to High(BotNames
) do
979 if g_Player_ValidName(BotNames
[a
]) then
981 _name
:= BotNames
[a
];
985 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
988 _name
:= Format('DFBOT%.2d', [Random(100)]);
989 until g_Player_ValidName(_name
);
991 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
992 _model
:= m
[Random(Length(m
))];
995 with g_Player_Get(g_Player_Create(_model
,
996 _RGB(Min(Random(9)*32, 255),
997 Min(Random(9)*32, 255),
998 Min(Random(9)*32, 255)),
999 Team
, True)) as TBot
do
1004 1: FDifficult
:= DIFFICULT_EASY
;
1005 2: FDifficult
:= DIFFICULT_MEDIUM
;
1006 else FDifficult
:= DIFFICULT_HARD
;
1009 for a
:= WP_FIRST
to WP_LAST
do
1011 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1012 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1013 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1016 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1018 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1019 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1024 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1);
1027 _name
, _model
: String;
1030 if not g_Game_IsServer
then Exit
;
1032 // Ñïèñîê íàçâàíèé ìîäåëåé:
1033 m
:= g_PlayerModel_GetNames();
1038 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1039 Team
:= TEAM_COOP
// COOP
1041 if gGameSettings
.GameMode
= GM_DM
then
1042 Team
:= TEAM_NONE
// DM
1044 if Team
= TEAM_NONE
then
1045 Team
:= BotList
[num
].team
; // CTF / TDM
1047 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1048 lName
:= AnsiLowerCase(lName
);
1049 if (num
< 0) or (num
> Length(BotList
)-1) then
1051 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1052 for a
:= 0 to High(BotList
) do
1053 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1062 _name
:= BotList
[num
].name
;
1063 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1064 if not g_Player_ValidName(_name
) then
1066 _name
:= Format('DFBOT%.2d', [Random(100)]);
1067 until g_Player_ValidName(_name
);
1070 _model
:= BotList
[num
].model
;
1071 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1072 if not InSArray(_model
, m
) then
1073 _model
:= m
[Random(Length(m
))];
1076 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1080 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1081 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1082 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1083 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1084 FDifficult
.Cover
:= BotList
[num
].cover
;
1085 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1087 for a
:= WP_FIRST
to WP_LAST
do
1089 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1090 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1091 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1094 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1096 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1100 procedure g_Bot_RemoveAll();
1104 if not g_Game_IsServer
then Exit
;
1105 if gPlayers
= nil then Exit
;
1107 for a
:= 0 to High(gPlayers
) do
1108 if gPlayers
[a
] <> nil then
1109 if gPlayers
[a
] is TBot
then
1111 gPlayers
[a
].Lives
:= 0;
1112 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1113 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1114 g_Player_Remove(gPlayers
[a
].FUID
);
1120 procedure g_Bot_MixNames();
1125 if BotNames
<> nil then
1126 for a
:= 0 to High(BotNames
) do
1128 b
:= Random(Length(BotNames
));
1130 Botnames
[a
] := BotNames
[b
];
1135 procedure g_Player_Remove(UID
: Word);
1139 if gPlayers
= nil then Exit
;
1141 if g_Game_IsServer
and g_Game_IsNet
then
1142 MH_SEND_PlayerDelete(UID
);
1144 for i
:= 0 to High(gPlayers
) do
1145 if gPlayers
[i
] <> nil then
1146 if gPlayers
[i
].FUID
= UID
then
1148 if gPlayers
[i
] is TPlayer
then
1149 TPlayer(gPlayers
[i
]).Free()
1151 TBot(gPlayers
[i
]).Free();
1157 procedure g_Player_Init();
1167 if not FileExists(DataDir
+ BOTNAMES_FILENAME
) then
1170 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1171 AssignFile(F
, DataDir
+ BOTNAMES_FILENAME
);
1182 SetLength(BotNames
, Length(BotNames
)+1);
1183 BotNames
[High(BotNames
)] := s
;
1191 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1192 config
:= TConfig
.CreateFile(DataDir
+ BOTLIST_FILENAME
);
1196 while config
.SectionExists(IntToStr(a
)) do
1198 SetLength(BotList
, Length(BotList
)+1);
1200 with BotList
[High(BotList
)] do
1203 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1205 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1207 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1212 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1213 color
.R
:= StrToIntDef(sa
[0], 0);
1214 color
.G
:= StrToIntDef(sa
[1], 0);
1215 color
.B
:= StrToIntDef(sa
[2], 0);
1216 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1217 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1218 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1219 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1220 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1221 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1222 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1223 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1224 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1225 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1226 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1227 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1228 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1229 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1230 if Length(sa
) = 10 then
1232 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1233 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1234 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1235 if Length(sa
) = 10 then
1237 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1239 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1240 if Length(sa) = 10 then
1242 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1251 procedure g_Player_Free();
1255 if gPlayers
<> nil then
1257 for i
:= 0 to High(gPlayers
) do
1258 if gPlayers
[i
] <> nil then
1260 if gPlayers
[i
] is TPlayer
then
1261 TPlayer(gPlayers
[i
]).Free()
1263 TBot(gPlayers
[i
]).Free();
1274 procedure g_Player_UpdateAll();
1278 if gPlayers
= nil then Exit
;
1280 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1281 for i
:= 0 to High(gPlayers
) do
1283 if gPlayers
[i
] <> nil then
1285 if gPlayers
[i
] is TPlayer
then
1287 gPlayers
[i
].Update();
1288 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1292 // bot updates weapons in `UpdateCombat()`
1293 TBot(gPlayers
[i
]).Update();
1297 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1300 procedure g_Player_DrawAll();
1304 if gPlayers
= nil then Exit
;
1306 for i
:= 0 to High(gPlayers
) do
1307 if gPlayers
[i
] <> nil then
1308 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1309 else TBot(gPlayers
[i
]).Draw();
1312 procedure g_Player_DrawDebug(p
: TPlayer
);
1316 if p
= nil then Exit
;
1317 if (@p
.FObj
) = nil then Exit
;
1319 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1321 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1322 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1323 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1324 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1325 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1326 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1329 procedure g_Player_DrawHealth();
1334 if gPlayers
= nil then Exit
;
1335 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1337 for i
:= 0 to High(gPlayers
) do
1338 if gPlayers
[i
] <> nil then
1340 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1341 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1342 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1343 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1344 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1345 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1349 function g_Player_Get(UID
: Word): TPlayer
;
1355 if gPlayers
= nil then
1358 for a
:= 0 to High(gPlayers
) do
1359 if gPlayers
[a
] <> nil then
1360 if gPlayers
[a
].FUID
= UID
then
1362 Result
:= gPlayers
[a
];
1367 function g_Player_GetCount(): Byte;
1373 if gPlayers
= nil then
1376 for a
:= 0 to High(gPlayers
) do
1377 if gPlayers
[a
] <> nil then
1378 Result
:= Result
+ 1;
1381 function g_Player_GetStats(): TPlayerStatArray
;
1387 if gPlayers
= nil then Exit
;
1389 for a
:= 0 to High(gPlayers
) do
1390 if gPlayers
[a
] <> nil then
1392 SetLength(Result
, Length(Result
)+1);
1393 with Result
[High(Result
)] do
1395 Ping
:= gPlayers
[a
].FPing
;
1396 Loss
:= gPlayers
[a
].FLoss
;
1397 Name
:= gPlayers
[a
].FName
;
1398 Team
:= gPlayers
[a
].FTeam
;
1399 Frags
:= gPlayers
[a
].FFrags
;
1400 Deaths
:= gPlayers
[a
].FDeath
;
1401 Kills
:= gPlayers
[a
].FKills
;
1402 Color
:= gPlayers
[a
].FModel
.Color
;
1403 Lives
:= gPlayers
[a
].FLives
;
1404 Spectator
:= gPlayers
[a
].FSpectator
;
1409 procedure g_Player_RememberAll
;
1413 for i
:= Low(gPlayers
) to High(gPlayers
) do
1414 if (gPlayers
[i
] <> nil) and gPlayers
[i
].Live
then
1415 gPlayers
[i
].RememberState
;
1418 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1422 gTeamStat
[TEAM_RED
].Goals
:= 0;
1423 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1425 if gPlayers
<> nil then
1426 for i
:= 0 to High(gPlayers
) do
1427 if gPlayers
[i
] <> nil then
1429 gPlayers
[i
].Reset(Force
);
1431 if gPlayers
[i
] is TPlayer
then
1433 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1434 gPlayers
[i
].Respawn(Silent
)
1436 gPlayers
[i
].Spectate();
1439 TBot(gPlayers
[i
]).Respawn(Silent
);
1443 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1450 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1455 if (FHealth
>= -50) or (gGibsCount
= 0) then
1457 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1461 for find_id
:= 0 to High(gCorpses
) do
1462 if gCorpses
[find_id
] = nil then
1469 find_id
:= Random(Length(gCorpses
));
1471 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1472 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1473 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1474 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1477 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1478 FObj
.Y
+ PLAYER_RECT_CY
,
1479 FModel
.Name
, FModel
.Color
);
1483 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1487 if (gShells
= nil) or (Length(gShells
) = 0) then
1490 with gShells
[CurrentShell
] do
1496 if T
= SHELL_BULLET
then
1498 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1502 Obj
.Rect
.Width
:= 4;
1503 Obj
.Rect
.Height
:= 2;
1507 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1511 Obj
.Rect
.Width
:= 7;
1512 Obj
.Rect
.Height
:= 3;
1518 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1519 RAngle
:= Random(360);
1520 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1522 if CurrentShell
>= High(gShells
) then
1529 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1532 GibsArray
: TGibsArray
;
1534 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1536 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1539 for a
:= 0 to High(GibsArray
) do
1540 with gGibs
[CurrentGib
] do
1543 ID
:= GibsArray
[a
].ID
;
1544 MaskID
:= GibsArray
[a
].MaskID
;
1547 Obj
.Rect
:= GibsArray
[a
].Rect
;
1548 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1549 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1550 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1551 RAngle
:= Random(360);
1553 if gBloodCount
> 0 then
1554 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1555 Random(48), Random(48), 150, 0, 0);
1557 if CurrentGib
>= High(gGibs
) then
1564 procedure g_Player_UpdatePhysicalObjects();
1570 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1575 if T
= SHELL_BULLET
then
1576 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1578 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1583 if gGibs
<> nil then
1584 for i
:= 0 to High(gGibs
) do
1585 if gGibs
[i
].Live
then
1589 mr
:= g_Obj_Move(@Obj
, True, False, True);
1591 if WordBool(mr
and MOVE_FALLOUT
) then
1597 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1598 if WordBool(mr
and MOVE_HITWALL
) then
1599 Obj
.Vel
.X
:= -(vel
.X
div 2);
1600 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1601 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1603 if (Obj
.Vel
.X
>= 0) then
1605 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1606 if RAngle
>= 360 then
1607 RAngle
:= RAngle
mod 360;
1608 end else begin // Counter-clockwise
1609 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1611 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1614 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1615 if gTime
mod (GAME_TICK
*3) = 0 then
1616 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1620 if gCorpses
<> nil then
1621 for i
:= 0 to High(gCorpses
) do
1622 if gCorpses
[i
] <> nil then
1623 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1629 gCorpses
[i
].Update();
1632 if gShells
<> nil then
1633 for i
:= 0 to High(gShells
) do
1634 if gShells
[i
].Live
then
1638 mr
:= g_Obj_Move(@Obj
, True, False, True);
1640 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1646 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1647 if WordBool(mr
and MOVE_HITWALL
) then
1649 Obj
.Vel
.X
:= -(vel
.X
div 2);
1650 if not WordBool(mr
and MOVE_INWATER
) then
1651 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1653 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1655 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1656 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1657 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1659 if RAngle
mod 90 <> 0 then
1660 RAngle
:= (RAngle
div 90) * 90;
1662 else if not WordBool(mr
and MOVE_INWATER
) then
1663 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1666 if (Obj
.Vel
.X
>= 0) then
1668 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1669 if RAngle
>= 360 then
1670 RAngle
:= RAngle
mod 360;
1671 end else begin // Counter-clockwise
1672 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1674 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1679 procedure g_Player_DrawCorpses();
1684 if gGibs
<> nil then
1685 for i
:= 0 to High(gGibs
) do
1686 if gGibs
[i
].Live
then
1689 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1692 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1693 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1695 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1698 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1704 if gCorpses
<> nil then
1705 for i
:= 0 to High(gCorpses
) do
1706 if gCorpses
[i
] <> nil then
1710 procedure g_Player_DrawShells();
1715 if gShells
<> nil then
1716 for i
:= 0 to High(gShells
) do
1717 if gShells
[i
].Live
then
1720 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1726 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1730 procedure g_Player_RemoveAllCorpses();
1736 SetLength(gGibs
, MaxGibs
);
1737 SetLength(gShells
, MaxGibs
);
1741 if gCorpses
<> nil then
1742 for i
:= 0 to High(gCorpses
) do
1746 SetLength(gCorpses
, MaxCorpses
);
1749 procedure g_Player_Corpses_SaveState(var Mem
: TBinMemoryWriter
);
1754 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ:
1756 if gCorpses
<> nil then
1757 for i
:= 0 to High(gCorpses
) do
1758 if gCorpses
[i
] <> nil then
1761 Mem
:= TBinMemoryWriter
.Create((count
+1) * 128);
1763 // Êîëè÷åñòâî òðóïîâ:
1764 Mem
.WriteInt(count
);
1770 for i
:= 0 to High(gCorpses
) do
1771 if gCorpses
[i
] <> nil then
1774 Mem
.WriteString(gCorpses
[i
].FModelName
);
1776 b
:= gCorpses
[i
].Mess
;
1777 Mem
.WriteBoolean(b
);
1778 // Ñîõðàíÿåì äàííûå òðóïà:
1779 gCorpses
[i
].SaveState(Mem
);
1783 procedure g_Player_Corpses_LoadState(var Mem
: TBinMemoryReader
);
1792 g_Player_RemoveAllCorpses();
1794 // Êîëè÷åñòâî òðóïîâ:
1797 if count
> Length(gCorpses
) then
1799 raise EBinSizeError
.Create('g_Player_Corpses_LoadState: Too Many Corpses');
1806 for i
:= 0 to count
-1 do
1809 Mem
.ReadString(str
);
1813 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1814 // Çàãðóæàåì äàííûå òðóïà:
1815 gCorpses
[i
].LoadState(Mem
);
1821 procedure TPlayer
.BFGHit();
1823 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1824 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1825 if g_Game_IsServer
and g_Game_IsNet
then
1826 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1827 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1831 procedure TPlayer
.ChangeModel(ModelName
: string);
1833 Model
: TPlayerModel
;
1835 Model
:= g_PlayerModel_Get(ModelName
);
1836 if Model
= nil then Exit
;
1842 procedure TPlayer
.SetModel(ModelName
: string);
1846 m
:= g_PlayerModel_Get(ModelName
);
1849 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1850 m
:= g_PlayerModel_Get('doomer');
1853 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1858 if FModel
<> nil then
1863 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1864 FModel
.Color
:= FColor
1866 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1867 FModel
.SetWeapon(FCurrWeap
);
1868 FModel
.SetFlag(FFlag
);
1869 SetDirection(FDirection
);
1872 procedure TPlayer
.SetColor(Color
: TRGB
);
1875 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1876 if FModel
<> nil then FModel
.Color
:= Color
;
1879 procedure TPlayer
.SwitchTeam
;
1881 if g_Game_IsClient
then
1883 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
1885 if gGameOn
and FLive
then
1886 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
1888 if FTeam
= TEAM_RED
then
1890 ChangeTeam(TEAM_BLUE
);
1891 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
1892 if g_Game_IsNet
then
1893 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
1897 ChangeTeam(TEAM_RED
);
1898 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
1899 if g_Game_IsNet
then
1900 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
1902 FPreferredTeam
:= FTeam
;
1905 procedure TPlayer
.ChangeTeam(Team
: Byte);
1912 TEAM_RED
, TEAM_BLUE
:
1913 FModel
.Color
:= TEAMCOLOR
[Team
];
1915 FModel
.Color
:= FColor
;
1917 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
1918 MH_SEND_PlayerStats(FUID
);
1922 procedure TPlayer.CollideItem();
1927 if gItems = nil then Exit;
1928 if not FLive then Exit;
1930 for i := 0 to High(gItems) do
1933 if (ItemType <> ITEM_NONE) and Live then
1934 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
1935 PLAYER_RECT.Height, @Obj) then
1937 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
1939 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
1940 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
1941 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
1942 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
1943 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
1945 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
1946 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
1947 (gGameSettings.GameType = GT_SINGLE) and
1948 (g_Player_GetCount() > 1)) then
1949 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
1955 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
1957 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
1958 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
1962 constructor TPlayer
.Create();
1968 FSawSound
:= TPlayableSound
.Create();
1969 FSawSoundIdle
:= TPlayableSound
.Create();
1970 FSawSoundHit
:= TPlayableSound
.Create();
1971 FSawSoundSelect
:= TPlayableSound
.Create();
1972 FJetSoundFly
:= TPlayableSound
.Create();
1973 FJetSoundOn
:= TPlayableSound
.Create();
1974 FJetSoundOff
:= TPlayableSound
.Create();
1976 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
1977 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
1978 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
1979 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
1980 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
1981 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
1982 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
1984 FSpectatePlayer
:= -1;
1988 FSavedState
.WaitRecall
:= False;
1991 FActualModelName
:= 'doomer';
1994 FObj
.Rect
:= PLAYER_RECT
;
1996 FBFGFireCounter
:= -1;
1997 FJustTeleported
:= False;
2003 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2007 if (not g_Game_IsClient
) and (not FLive
) then
2012 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2013 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2015 if not g_Game_IsClient
then
2018 if t
= HIT_TRAP
then
2020 // Ëîâóøêà óáèâàåò ñðàçó:
2022 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2024 if t
= HIT_SELF
then
2028 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2031 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2032 FMegaRulez
[MR_SUIT
] := 0;
2033 FMegaRulez
[MR_INVUL
] := 0;
2034 FMegaRulez
[MR_INVIS
] := 0;
2038 // Íî îò îñòàëüíîãî ñïàñàåò:
2039 if FMegaRulez
[MR_INVUL
] >= gTime
then
2046 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2047 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2048 (SpawnerUID
= FUID
) or
2049 (not SameTeam(FUID
, SpawnerUID
)) then
2051 FLastSpawnerUID
:= SpawnerUID
;
2053 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2054 if gBloodCount
> 0 then
2056 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2057 if value
div 4 <= c
then
2058 c
:= c
- (value
div 4)
2062 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2066 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2067 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2070 if t
= HIT_WATER
then
2071 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2072 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2077 Inc(FDamageBuffer
, value
);
2081 FPain
:= FPain
+ value
;
2084 if g_Game_IsServer
and g_Game_IsNet
then
2086 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2087 MH_SEND_PlayerStats(FUID
);
2088 MH_SEND_PlayerPos(False, FUID
);
2092 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2095 if g_Game_IsClient
then
2100 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2102 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2105 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2107 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2111 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2112 MH_SEND_PlayerStats(FUID
);
2115 destructor TPlayer
.Destroy();
2117 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2119 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2123 FSawSoundIdle
.Free();
2124 FSawSoundHit
.Free();
2125 FJetSoundFly
.Free();
2127 FJetSoundOff
.Free();
2133 procedure TPlayer
.DrawBubble();
2135 bubX
, bubY
: Integer;
2138 Rw
, Gw
, Bw
: SmallInt;
2141 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= D_LEFT
, -4, 18);
2142 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2150 1: // simple textual non-bubble
2152 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2153 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2154 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2157 2: // advanced pixel-perfect bubble
2159 if FTeam
= TEAM_RED
then
2162 if FTeam
= TEAM_BLUE
then
2165 3: // colored bubble
2167 Rb
:= FModel
.Color
.R
;
2168 Gb
:= FModel
.Color
.G
;
2169 Bb
:= FModel
.Color
.B
;
2170 Rw
:= Min(Rb
* 2 + 64, 255);
2171 Gw
:= Min(Gb
* 2 + 64, 255);
2172 Bw
:= Min(Bb
* 2 + 64, 255);
2173 if (Abs(Rw
- Rb
) < 32)
2174 or (Abs(Gw
- Gb
) < 32)
2175 or (Abs(Bw
- Bb
) < 32) then
2177 Rb
:= Max(Rw
div 2 - 16, 0);
2178 Gb
:= Max(Gw
div 2 - 16, 0);
2179 Bb
:= Max(Bw
div 2 - 16, 0);
2182 4: // custom textured bubble
2184 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2185 if FDirection
= D_RIGHT
then
2186 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2188 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, M_HORIZONTAL
);
2194 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2195 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2197 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2200 Dot
:= IfThen(FDirection
= D_LEFT
, 14, 5);
2201 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2202 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
);
2203 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
);
2204 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
);
2205 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
);
2209 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2210 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2211 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2214 procedure TPlayer
.Draw();
2222 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2223 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2225 e_GetTextureSize(ID
, @w
, @h
);
2226 if FDirection
= D_LEFT
then
2227 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2228 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7, 0, True, False)
2230 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2231 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7, 0, True, False);
2234 if FMegaRulez
[MR_INVIS
] > gTime
then
2236 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2237 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2239 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2240 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2244 FModel
.Draw(FObj
.X
, FObj
.Y
, 200)
2246 FModel
.Draw(FObj
.X
, FObj
.Y
);
2249 FModel
.Draw(FObj
.X
, FObj
.Y
, 254);
2252 FModel
.Draw(FObj
.X
, FObj
.Y
);
2255 if g_debug_Frames
then
2257 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2259 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2260 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2264 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2266 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2267 if gAimLine
and Live
and
2268 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2272 procedure TPlayer
.DrawAim();
2274 wx
, wy
, xx
, yy
: Integer;
2278 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= D_LEFT
, 7, -7);
2279 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2288 1: begin // Chainsaw
2295 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2296 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2297 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2298 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2303 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2304 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2305 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2306 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2308 4: begin // Double Shotgun
2311 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2312 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2313 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2314 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2316 5: begin // Chaingun
2319 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2320 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2321 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2322 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2324 6: begin // Rocket Launcher
2327 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2328 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2329 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2330 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2332 7: begin // Plasmagun
2335 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2336 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2337 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2338 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2343 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2344 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2345 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2346 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2348 9: begin // Super Chaingun
2351 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2352 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2353 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2354 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2357 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2358 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2359 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2362 procedure TPlayer
.DrawGUI();
2365 X
, Y
, SY
, a
, p
, m
: Integer;
2369 stat
: TPlayerStatArray
;
2371 X
:= gPlayerScreenSize
.X
;
2372 SY
:= gPlayerScreenSize
.Y
;
2375 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2377 if gGameSettings
.GameMode
= GM_CTF
then
2381 if gGameSettings
.GameMode
= GM_CTF
then
2383 s
:= 'TEXTURE_PLAYER_REDFLAG';
2384 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2385 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2386 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2387 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2388 if g_Texture_Get(s
, ID
) then
2389 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2392 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2393 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2394 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2396 if gGameSettings
.GameMode
= GM_CTF
then
2398 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2399 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2400 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2401 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2402 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2403 if g_Texture_Get(s
, ID
) then
2404 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2407 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2408 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2409 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2412 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2413 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2416 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2417 e_Draw(ID
, X
+2, Y
, 0, True, False);
2419 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2423 s
:= IntToStr(Frags
);
2424 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2425 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2430 stat
:= g_Player_GetStats();
2435 for a
:= 0 to High(stat
) do
2436 if stat
[a
].Name
<> Name
then
2438 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2439 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2443 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2444 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2445 s
:= s
+IntToStr(Abs(Frags
-m
));
2447 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2448 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2451 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2453 s
:= IntToStr(Lives
);
2454 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2455 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2459 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2460 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2462 if R_BERSERK
in FRulez
then
2463 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2465 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2467 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2468 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2470 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2471 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2472 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2474 s
:= IntToStr(FArmor
);
2475 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2476 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2478 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2484 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2489 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2491 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2492 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2493 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2494 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2495 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2496 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2497 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2498 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2499 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2502 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2503 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2504 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2506 if R_KEY_RED
in FRulez
then
2507 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2509 if R_KEY_GREEN
in FRulez
then
2510 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2512 if R_KEY_BLUE
in FRulez
then
2513 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2515 if FJetFuel
> 0 then
2517 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2518 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2519 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2520 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2521 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2522 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2526 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2527 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2528 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2531 if gShowPing
and g_Game_IsClient
then
2533 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2534 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2540 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2541 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2542 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2545 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2546 s
:= _lc
[I_PLAYER_SPECT4
];
2547 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2548 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2549 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2555 procedure TPlayer
.DrawRulez();
2559 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2560 if FMegaRulez
[MR_INVUL
] >= gTime
then
2562 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2563 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2568 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2569 191, 191, 191, 0, B_INVERT
);
2572 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2573 if FMegaRulez
[MR_SUIT
] >= gTime
then
2575 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2576 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2581 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2582 0, 96, 0, 200, B_NONE
);
2585 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2586 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2588 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2589 255, 0, 0, 200, B_NONE
);
2593 procedure TPlayer
.DrawPain();
2597 if FPain
= 0 then Exit
;
2601 if a
< 15 then h
:= 0
2602 else if a
< 35 then h
:= 1
2603 else if a
< 55 then h
:= 2
2604 else if a
< 75 then h
:= 3
2605 else if a
< 95 then h
:= 4
2608 //if a > 255 then a := 255;
2610 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2611 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2614 procedure TPlayer
.DrawPickup();
2618 if FPickup
= 0 then Exit
;
2622 if a
< 15 then h
:= 1
2623 else if a
< 35 then h
:= 2
2624 else if a
< 55 then h
:= 3
2625 else if a
< 75 then h
:= 4
2628 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2631 procedure TPlayer
.Fire();
2633 f
, DidFire
: Boolean;
2634 wx
, wy
, xd
, yd
: Integer;
2637 if g_Game_IsClient
then Exit
;
2638 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2639 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2647 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2652 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2653 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2654 xd
:= wx
+IfThen(FDirection
= D_LEFT
, -30, 30);
2655 yd
:= wy
+firediry();
2660 if R_BERSERK
in FRulez
then
2662 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2663 obj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2664 obj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2667 obj
.rect
.Width
:= 39;
2668 obj
.rect
.Height
:= 52;
2669 obj
.Vel
.X
:= (xd
-wx
) div 2;
2670 obj
.Vel
.Y
:= (yd
-wy
) div 2;
2671 obj
.Accel
.X
:= xd
-wx
;
2672 obj
.Accel
.y
:= yd
-wy
;
2674 if g_Weapon_Hit(@obj
, 50, FUID
, HIT_SOME
) <> 0 then
2675 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2677 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2681 FPain
:= min(FPain
+ 25, 50);
2682 end else g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2685 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2690 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2691 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2693 FSawSoundSelect
.Stop();
2695 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2697 else if not FSawSoundHit
.IsPlaying() then
2699 FSawSoundSelect
.Stop();
2700 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2703 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2709 if FAmmo
[A_BULLETS
] > 0 then
2711 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2712 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2713 Dec(FAmmo
[A_BULLETS
]);
2714 FFireAngle
:= FAngle
;
2717 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2718 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2722 if FAmmo
[A_SHELLS
] > 0 then
2724 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2725 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
2726 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2727 Dec(FAmmo
[A_SHELLS
]);
2728 FFireAngle
:= FAngle
;
2732 FShellType
:= SHELL_SHELL
;
2736 if FAmmo
[A_SHELLS
] >= 2 then
2738 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
2739 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2740 Dec(FAmmo
[A_SHELLS
], 2);
2741 FFireAngle
:= FAngle
;
2745 FShellType
:= SHELL_DBLSHELL
;
2749 if FAmmo
[A_BULLETS
] > 0 then
2751 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
2752 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
2753 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2754 Dec(FAmmo
[A_BULLETS
]);
2755 FFireAngle
:= FAngle
;
2758 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2759 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2762 WEAPON_ROCKETLAUNCHER
:
2763 if FAmmo
[A_ROCKETS
] > 0 then
2765 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
2766 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2767 Dec(FAmmo
[A_ROCKETS
]);
2768 FFireAngle
:= FAngle
;
2774 if FAmmo
[A_CELLS
] > 0 then
2776 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
2777 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2778 Dec(FAmmo
[A_CELLS
]);
2779 FFireAngle
:= FAngle
;
2785 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
2787 FBFGFireCounter
:= 17;
2788 if not FNoReload
then
2789 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
2790 Dec(FAmmo
[A_CELLS
], 40);
2794 WEAPON_SUPERPULEMET
:
2795 if FAmmo
[A_SHELLS
] > 0 then
2797 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2798 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
2799 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2800 Dec(FAmmo
[A_SHELLS
]);
2801 FFireAngle
:= FAngle
;
2804 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2805 GameVelX
, GameVelY
-2, SHELL_SHELL
);
2808 WEAPON_FLAMETHROWER
:
2809 if FAmmo
[A_FUEL
] > 0 then
2811 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2813 FFireAngle
:= FAngle
;
2819 if g_Game_IsNet
then
2823 if FCurrWeap
<> WEAPON_BFG
then
2824 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
2826 if not FNoReload
then
2827 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
2830 MH_SEND_PlayerStats(FUID
);
2835 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
2836 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
2837 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
2840 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
2843 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
2844 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
2845 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
2846 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
2847 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
2852 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
2854 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
2855 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
2856 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
2859 procedure TPlayer
.JetpackOn
;
2863 FJetSoundOn
.SetPosition(0);
2864 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
2868 procedure TPlayer
.JetpackOff
;
2872 FJetSoundOff
.SetPosition(0);
2873 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
2876 procedure TPlayer
.Jump();
2878 if gFly
or FJetpack
then
2880 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
2881 if FObj
.Vel
.Y
> -VEL_FLY
then
2882 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
2885 if FJetFuel
> 0 then
2887 if (FJetFuel
< 1) and g_Game_IsServer
then
2891 if g_Game_IsNet
then
2892 MH_SEND_PlayerStats(FUID
);
2898 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
2900 FCanJetpack
:= False;
2902 // Ïðûãàåì èëè âñïëûâàåì:
2903 if (CollideLevel(0, 1) or
2904 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
2905 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
2906 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
2908 FObj
.Vel
.Y
:= -VEL_JUMP
;
2909 FCanJetpack
:= False;
2913 if BodyInLiquid(0, 0) then
2914 FObj
.Vel
.Y
:= -VEL_SW
2915 else if (FJetFuel
> 0) and FCanJetpack
and
2916 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
2920 if g_Game_IsNet
then
2921 MH_SEND_PlayerStats(FUID
);
2926 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
2928 a
, i
, k
, ab
, ar
: Byte;
2932 srv
, netsrv
: Boolean;
2937 procedure PushItem(t
: Byte);
2941 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
2942 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
2943 g_Obj_Push(@gItems
[id
].Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
2944 (FObj
.Vel
.Y
div 2)-Random(9))
2946 if KillType
= K_HARDKILL
then // -5..+5; -5..0
2947 g_Obj_Push(@gItems
[id
].Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
2948 (FObj
.Vel
.Y
div 2)-Random(6))
2949 else // -3..+3; -3..0
2950 g_Obj_Push(@gItems
[id
].Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
2951 (FObj
.Vel
.Y
div 2)-Random(4));
2953 if g_Game_IsNet
and g_Game_IsServer
then
2954 MH_SEND_ItemSpawn(True, id
);
2958 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
2959 Srv
:= g_Game_IsServer
;
2960 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
2961 if Srv
then FDeath
:= FDeath
+ 1;
2966 if not FPhysics
then
2972 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2974 if FLives
> 0 then FLives
:= FLives
- 1;
2975 if FLives
= 0 then FNoRespawn
:= True;
2978 // Íîìåð òèïà ñìåðòè:
2981 K_SIMPLEKILL
: a
:= 1;
2983 K_EXTRAHARDKILL
: a
:= 3;
2988 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
2990 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
2997 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
2999 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3000 K_EXTRAHARDKILL
, K_FALLKILL
:
3001 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3004 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3008 K_HARDKILL
, K_EXTRAHARDKILL
:
3012 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3013 if (KillType
<> K_FALLKILL
) and (Srv
) then
3014 g_Monsters_killedp();
3016 if SpawnerUID
= FUID
then
3018 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3023 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3026 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3027 begin // Óáèò äðóãèì èãðîêîì
3028 KP
:= g_Player_Get(SpawnerUID
);
3029 if (KP
<> nil) and Srv
then
3031 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3032 if SameTeam(FUID
, SpawnerUID
) then
3042 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3043 Inc(gTeamStat
[KP
.Team
].Goals
,
3044 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3046 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3049 plr
:= g_Player_Get(SpawnerUID
);
3057 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3061 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3065 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3070 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3071 begin // Óáèò ìîíñòðîì
3072 mon
:= g_Monsters_Get(SpawnerUID
);
3076 s
:= g_Monsters_GetKilledBy(mon
.MonsterType
);
3080 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3084 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3088 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3093 else // Îñîáûå òèïû ñìåðòè
3096 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3097 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3098 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3099 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3100 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3101 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3107 for a
:= WP_FIRST
to WP_LAST
do
3111 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3112 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3113 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3114 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3115 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3116 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3117 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3118 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3119 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3128 if R_ITEM_BACKPACK
in FRulez
then
3129 PushItem(ITEM_AMMO_BACKPACK
);
3131 // Âûáðîñ ðàêåòíîãî ðàíöà:
3132 if FJetFuel
> 0 then
3133 PushItem(ITEM_JETPACK
);
3136 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3138 if R_KEY_RED
in FRulez
then
3139 PushItem(ITEM_KEY_RED
);
3141 if R_KEY_GREEN
in FRulez
then
3142 PushItem(ITEM_KEY_GREEN
);
3144 if R_KEY_BLUE
in FRulez
then
3145 PushItem(ITEM_KEY_BLUE
);
3152 g_Player_CreateCorpse(Self
);
3154 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3155 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3161 for i
:= Low(gPlayers
) to High(gPlayers
) do
3163 if gPlayers
[i
] = nil then continue
;
3164 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3167 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3168 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3173 OldLR
:= gLMSRespawn
;
3174 if (gGameSettings
.GameMode
= GM_COOP
) then
3178 // everyone is dead, restart the map
3179 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3181 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3182 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3183 gLMSRespawnTime
:= gTime
+ 5000;
3185 else if (a
= 1) then
3187 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3188 if (gPlayers
[k
] = gPlayer1
) or
3189 (gPlayers
[k
] = gPlayer2
) then
3190 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3191 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3192 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3195 else if (gGameSettings
.GameMode
= GM_TDM
) then
3197 if (ab
= 0) and (ar
<> 0) then
3200 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3202 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3203 Inc(gTeamStat
[TEAM_RED
].Goals
);
3204 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3205 gLMSRespawnTime
:= gTime
+ 5000;
3207 else if (ar
= 0) and (ab
<> 0) then
3210 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3212 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3213 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3214 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3215 gLMSRespawnTime
:= gTime
+ 5000;
3217 else if (ar
= 0) and (ab
= 0) then
3220 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3222 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3223 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3224 gLMSRespawnTime
:= gTime
+ 5000;
3227 else if (gGameSettings
.GameMode
= GM_DM
) then
3231 if gPlayers
[k
] <> nil then
3234 // survivor is the winner
3235 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3237 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3240 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3241 gLMSRespawnTime
:= gTime
+ 5000;
3243 else if (a
= 0) then
3245 // everyone is dead, restart the map
3246 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3248 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3249 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3250 gLMSRespawnTime
:= gTime
+ 5000;
3253 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3255 if NetMode
= NET_SERVER
then
3256 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3258 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3264 MH_SEND_PlayerStats(FUID
);
3265 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3266 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3269 if srv
and FNoRespawn
then Spectate(True);
3270 FWantsInGame
:= True;
3273 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3275 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3276 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3279 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3281 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3282 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3285 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3287 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3288 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3289 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3291 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3292 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3293 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3297 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3299 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3300 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3301 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3305 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3307 if g_Game_IsClient
then Exit
;
3308 if Weapon
> High(FWeapon
) then Exit
;
3309 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3312 procedure TPlayer
.resetWeaponQueue ();
3315 FNextWeapDelay
:= 0;
3318 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3322 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3323 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 0);
3324 WEAPON_PISTOL
, WEAPON_CHAINGUN
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_BULLETS
] > 0);
3325 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3326 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3327 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3328 else result
:= (weapon
< length(FWeapon
));
3332 // return 255 for "no switch"
3333 function TPlayer
.getNextWeaponIndex (): Byte;
3336 wantThisWeapon
: array[0..64] of Boolean;
3337 wwc
: Integer = 0; //HACK!
3340 result
:= 255; // default result: "no switch"
3341 // had weapon cycling on previous frame? remove that flag
3342 if (FNextWeap
and $2000) <> 0 then begin FNextWeap
:= FNextWeap
and $1FFF; FNextWeapDelay
:= 0; end;
3343 // cycling has priority
3344 if (FNextWeap
and $C000) <> 0 then
3346 if (FNextWeap
and $8000) <> 0 then dir
:= 1 else dir
:= -1;
3347 FNextWeap
:= FNextWeap
or $2000; // we need this
3348 if FNextWeapDelay
> 0 then exit
; // cooldown time
3350 for i
:= 0 to High(FWeapon
) do
3352 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3353 if FWeapon
[cwi
] then
3355 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d', [FCurrWeap, cwi]), MSG_WARNING);
3356 result
:= Byte(cwi
);
3357 FNextWeapDelay
:= 10;
3365 for i
:= 0 to High(wantThisWeapon
) do wantThisWeapon
[i
] := false;
3366 for i
:= 0 to High(FWeapon
) do if (FNextWeap
and (1 shl i
)) <> 0 then begin wantThisWeapon
[i
] := true; Inc(wwc
); end;
3367 // exclude currently selected weapon from the set
3368 wantThisWeapon
[FCurrWeap
] := false;
3369 // slow down alterations a little
3372 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3373 // more than one weapon requested, assume "alteration" and check alteration delay
3374 if FNextWeapDelay
> 0 then begin FNextWeap
:= 0; exit
; end; // yeah
3376 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3377 // but clear all counters if no weapon should be switched
3378 if wwc
< 1 then begin resetWeaponQueue(); exit
; end;
3379 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3380 // try weapons in descending order
3381 for i
:= High(FWeapon
) downto 0 do
3383 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3388 FNextWeapDelay
:= 10; // anyway, 'cause why not
3392 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3396 procedure TPlayer
.RealizeCurrentWeapon();
3397 function switchAllowed (): Boolean;
3402 if FBFGFireCounter
<> -1 then
3404 if FTime
[T_SWITCH
] > gTime
then
3406 for i
:= WP_FIRST
to WP_LAST
do
3407 if FReloading
[i
] > 0 then
3415 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3416 //FNextWeap := FNextWeap and $1FFF;
3417 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3419 if not switchAllowed
then
3421 //HACK for weapon cycling
3422 if (FNextWeap
and $7000) <> 0 then FNextWeap
:= 0;
3426 nw
:= getNextWeaponIndex();
3427 if nw
= 255 then exit
; // don't reset anything here
3428 if nw
> High(FWeapon
) then
3430 // don't forget to reset queue here!
3431 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3439 FTime
[T_SWITCH
] := gTime
+156;
3440 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3441 FModel
.SetWeapon(FCurrWeap
);
3442 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3446 procedure TPlayer
.NextWeapon();
3448 if g_Game_IsClient
then Exit
;
3452 procedure TPlayer
.PrevWeapon();
3454 if g_Game_IsClient
then Exit
;
3458 procedure TPlayer
.SetWeapon(W
: Byte);
3460 if FCurrWeap
<> W
then
3461 if W
= WEAPON_SAW
then
3462 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3465 FModel
.SetWeapon(CurrWeap
);
3469 function TPlayer
.PickItem(ItemType
: Byte; respawn
: Boolean; var remove
: Boolean): Boolean;
3474 if g_Game_IsClient
then Exit
;
3476 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3477 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and respawn
;
3482 if FHealth
< PLAYER_HP_SOFT
then
3484 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3487 if gFlash
= 2 then Inc(FPickup
, 5);
3491 if FHealth
< PLAYER_HP_SOFT
then
3493 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3496 if gFlash
= 2 then Inc(FPickup
, 5);
3500 if FArmor
< PLAYER_AP_SOFT
then
3502 FArmor
:= PLAYER_AP_SOFT
;
3505 if gFlash
= 2 then Inc(FPickup
, 5);
3509 if FArmor
< PLAYER_AP_LIMIT
then
3511 FArmor
:= PLAYER_AP_LIMIT
;
3514 if gFlash
= 2 then Inc(FPickup
, 5);
3518 if FHealth
< PLAYER_HP_LIMIT
then
3520 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3523 if gFlash
= 2 then Inc(FPickup
, 5);
3527 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3529 if FHealth
< PLAYER_HP_LIMIT
then
3530 FHealth
:= PLAYER_HP_LIMIT
;
3531 if FArmor
< PLAYER_AP_LIMIT
then
3532 FArmor
:= PLAYER_AP_LIMIT
;
3535 if gFlash
= 2 then Inc(FPickup
, 5);
3539 if (not FWeapon
[WEAPON_SAW
]) or ((not respawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3541 FWeapon
[WEAPON_SAW
] := True;
3543 if gFlash
= 2 then Inc(FPickup
, 5);
3544 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3547 ITEM_WEAPON_SHOTGUN1
:
3548 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3550 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3551 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3553 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3554 FWeapon
[WEAPON_SHOTGUN1
] := True;
3556 if gFlash
= 2 then Inc(FPickup
, 5);
3557 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3560 ITEM_WEAPON_SHOTGUN2
:
3561 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3563 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3565 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3566 FWeapon
[WEAPON_SHOTGUN2
] := True;
3568 if gFlash
= 2 then Inc(FPickup
, 5);
3569 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3572 ITEM_WEAPON_CHAINGUN
:
3573 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3575 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3577 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3578 FWeapon
[WEAPON_CHAINGUN
] := True;
3580 if gFlash
= 2 then Inc(FPickup
, 5);
3581 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3584 ITEM_WEAPON_ROCKETLAUNCHER
:
3585 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3587 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3589 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3590 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3592 if gFlash
= 2 then Inc(FPickup
, 5);
3593 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3597 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3599 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3601 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3602 FWeapon
[WEAPON_PLASMA
] := True;
3604 if gFlash
= 2 then Inc(FPickup
, 5);
3605 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3609 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3611 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3613 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3614 FWeapon
[WEAPON_BFG
] := True;
3616 if gFlash
= 2 then Inc(FPickup
, 5);
3617 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3620 ITEM_WEAPON_SUPERPULEMET
:
3621 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3623 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3625 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3626 FWeapon
[WEAPON_SUPERPULEMET
] := True;
3628 if gFlash
= 2 then Inc(FPickup
, 5);
3629 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3632 ITEM_WEAPON_FLAMETHROWER
:
3633 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
3635 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
3637 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3638 FWeapon
[WEAPON_FLAMETHROWER
] := True;
3640 if gFlash
= 2 then Inc(FPickup
, 5);
3641 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3645 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3647 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3650 if gFlash
= 2 then Inc(FPickup
, 5);
3653 ITEM_AMMO_BULLETS_BOX
:
3654 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3656 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3659 if gFlash
= 2 then Inc(FPickup
, 5);
3663 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3665 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3668 if gFlash
= 2 then Inc(FPickup
, 5);
3671 ITEM_AMMO_SHELLS_BOX
:
3672 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3674 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
3677 if gFlash
= 2 then Inc(FPickup
, 5);
3681 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3683 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3686 if gFlash
= 2 then Inc(FPickup
, 5);
3689 ITEM_AMMO_ROCKET_BOX
:
3690 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3692 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
3695 if gFlash
= 2 then Inc(FPickup
, 5);
3699 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3701 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3704 if gFlash
= 2 then Inc(FPickup
, 5);
3708 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3710 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
3713 if gFlash
= 2 then Inc(FPickup
, 5);
3717 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
3719 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3722 if gFlash
= 2 then Inc(FPickup
, 5);
3726 if not(R_ITEM_BACKPACK
in FRulez
) or
3727 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
3728 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
3729 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
3730 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
3731 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
3733 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
3734 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
3735 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
3736 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
3737 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
3739 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3740 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3741 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3742 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3743 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3744 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3745 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3746 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3748 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
3751 if gFlash
= 2 then Inc(FPickup
, 5);
3755 if not(R_KEY_RED
in FRulez
) then
3757 Include(FRulez
, R_KEY_RED
);
3759 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3760 if gFlash
= 2 then Inc(FPickup
, 5);
3761 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3765 if not(R_KEY_GREEN
in FRulez
) then
3767 Include(FRulez
, R_KEY_GREEN
);
3769 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3770 if gFlash
= 2 then Inc(FPickup
, 5);
3771 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3775 if not(R_KEY_BLUE
in FRulez
) then
3777 Include(FRulez
, R_KEY_BLUE
);
3779 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3780 if gFlash
= 2 then Inc(FPickup
, 5);
3781 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3785 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
3787 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
3790 if gFlash
= 2 then Inc(FPickup
, 5);
3794 if FAir
< AIR_MAX
then
3799 if gFlash
= 2 then Inc(FPickup
, 5);
3804 if not (R_BERSERK
in FRulez
) then
3806 Include(FRulez
, R_BERSERK
);
3807 if FBFGFireCounter
= -1 then
3809 FCurrWeap
:= WEAPON_KASTET
;
3811 FModel
.SetWeapon(WEAPON_KASTET
);
3815 if gFlash
= 2 then Inc(FPickup
, 5);
3816 FBerserk
:= gTime
+30000;
3820 if FHealth
< PLAYER_HP_SOFT
then
3822 FHealth
:= PLAYER_HP_SOFT
;
3823 FBerserk
:= gTime
+30000;
3830 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
3832 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
3835 if gFlash
= 2 then Inc(FPickup
, 5);
3839 if FHealth
< PLAYER_HP_LIMIT
then
3841 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
3844 if gFlash
= 2 then Inc(FPickup
, 5);
3848 if FArmor
< PLAYER_AP_LIMIT
then
3850 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
3853 if gFlash
= 2 then Inc(FPickup
, 5);
3857 if FJetFuel
< JET_MAX
then
3859 FJetFuel
:= JET_MAX
;
3862 if gFlash
= 2 then Inc(FPickup
, 5);
3866 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
3868 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
3871 if gFlash
= 2 then Inc(FPickup
, 5);
3876 procedure TPlayer
.Touch();
3880 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
3883 // Áðîñèòü ôëàã òîâàðèùó:
3884 if gGameSettings
.GameMode
= GM_CTF
then
3889 procedure TPlayer
.Push(vx
, vy
: Integer);
3891 if (not FPhysics
) and FGhost
then
3893 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
3894 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
3895 if g_Game_IsNet
and g_Game_IsServer
then
3896 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
3899 procedure TPlayer
.Reset(Force
: Boolean);
3905 FTime
[T_RESPAWN
] := 0;
3906 FTime
[T_FLAGCAP
] := 0;
3919 FSpectator
:= False;
3922 FSpectatePlayer
:= -1;
3923 FNoRespawn
:= False;
3925 FLives
:= gGameSettings
.MaxLives
;
3930 procedure TPlayer
.SoftReset();
3936 FBFGFireCounter
:= -1;
3944 SetAction(A_STAND
, True);
3947 function TPlayer
.GetRespawnPoint(): Byte;
3952 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
3954 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
3955 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
3957 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
3959 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
3960 if Self
= gPlayer1
then
3961 c
:= RESPAWNPOINT_PLAYER1
3963 c
:= RESPAWNPOINT_PLAYER2
;
3964 if g_Map_GetPointCount(c
) > 0 then
3970 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
3971 if Self
= gPlayer1
then
3972 c
:= RESPAWNPOINT_PLAYER2
3974 c
:= RESPAWNPOINT_PLAYER1
;
3975 if g_Map_GetPointCount(c
) > 0 then
3982 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
3983 if Random(2) = 0 then
3984 c
:= RESPAWNPOINT_PLAYER1
3986 c
:= RESPAWNPOINT_PLAYER2
;
3987 if g_Map_GetPointCount(c
) > 0 then
3994 // Òî÷êà ëþáîé èç êîìàíä
3995 if Random(2) = 0 then
3996 c
:= RESPAWNPOINT_RED
3998 c
:= RESPAWNPOINT_BLUE
;
3999 if g_Map_GetPointCount(c
) > 0 then
4006 c
:= RESPAWNPOINT_DM
;
4007 if g_Map_GetPointCount(c
) > 0 then
4015 if gGameSettings
.GameMode
= GM_DM
then
4018 c
:= RESPAWNPOINT_DM
;
4019 if g_Map_GetPointCount(c
) > 0 then
4025 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4026 if Random(2) = 0 then
4027 c
:= RESPAWNPOINT_PLAYER1
4029 c
:= RESPAWNPOINT_PLAYER2
;
4030 if g_Map_GetPointCount(c
) > 0 then
4036 // Òî÷êà ëþáîé èç êîìàíä
4037 if Random(2) = 0 then
4038 c
:= RESPAWNPOINT_RED
4040 c
:= RESPAWNPOINT_BLUE
;
4041 if g_Map_GetPointCount(c
) > 0 then
4049 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4051 // Òî÷êà ñâîåé êîìàíäû
4052 c
:= RESPAWNPOINT_DM
;
4053 if FTeam
= TEAM_RED
then
4054 c
:= RESPAWNPOINT_RED
;
4055 if FTeam
= TEAM_BLUE
then
4056 c
:= RESPAWNPOINT_BLUE
;
4057 if g_Map_GetPointCount(c
) > 0 then
4064 c
:= RESPAWNPOINT_DM
;
4065 if g_Map_GetPointCount(c
) > 0 then
4071 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4072 if Random(2) = 0 then
4073 c
:= RESPAWNPOINT_PLAYER1
4075 c
:= RESPAWNPOINT_PLAYER2
;
4076 if g_Map_GetPointCount(c
) > 0 then
4082 // Òî÷êà äðóãîé êîìàíäû
4083 c
:= RESPAWNPOINT_DM
;
4084 if FTeam
= TEAM_RED
then
4085 c
:= RESPAWNPOINT_BLUE
;
4086 if FTeam
= TEAM_BLUE
then
4087 c
:= RESPAWNPOINT_RED
;
4088 if g_Map_GetPointCount(c
) > 0 then
4096 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4098 RespawnPoint
: TRespawnPoint
;
4103 if not g_Game_IsServer
then
4107 FWantsInGame
:= True;
4108 FJustTeleported
:= True;
4111 FTime
[T_RESPAWN
] := 0;
4115 // if server changes MaxLives we gotta be ready
4116 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4118 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4119 if FTime
[T_RESPAWN
] > gTime
then
4122 // Ïðîñðàë âñå æèçíè:
4125 if not FSpectator
then Spectate(True);
4126 FWantsInGame
:= True;
4130 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4131 begin // "Ñâîÿ èãðà"
4132 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4133 FRulez
:= FRulez
-[R_BERSERK
];
4135 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4137 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4138 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4141 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4142 c
:= GetRespawnPoint();
4147 // Âîñêðåøåíèå áåç îðóæèÿ:
4150 FHealth
:= PLAYER_HP_SOFT
;
4156 for a
:= WP_FIRST
to WP_LAST
do
4158 FWeapon
[a
] := False;
4162 FWeapon
[WEAPON_PISTOL
] := True;
4163 FWeapon
[WEAPON_KASTET
] := True;
4164 FCurrWeap
:= WEAPON_PISTOL
;
4167 FModel
.SetWeapon(FCurrWeap
);
4169 for b
:= A_BULLETS
to A_HIGH
do
4172 FAmmo
[A_BULLETS
] := 50;
4174 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4175 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4176 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4177 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4178 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4180 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4181 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4186 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4187 if not g_Map_GetPoint(c
, RespawnPoint
) then
4189 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4193 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4194 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4195 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4201 FDirection
:= RespawnPoint
.Direction
;
4202 if FDirection
= D_LEFT
then
4208 FBFGFireCounter
:= -1;
4213 SetAction(A_STAND
, True);
4214 FModel
.Direction
:= FDirection
;
4216 for a
:= Low(FTime
) to High(FTime
) do
4219 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4224 FCanJetpack
:= False;
4226 // Àíèìàöèÿ âîçðîæäåíèÿ:
4227 if (not gLoadGameMode
) and (not Silent
) then
4228 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4230 Anim
:= TAnimation
.Create(ID
, False, 3);
4231 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4232 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4236 FSpectator
:= False;
4239 FSpectatePlayer
:= -1;
4242 if g_Game_IsNet
then
4244 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4245 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4247 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4248 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4253 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4256 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4257 else if (not NoMove
) then
4259 GameX
:= gMapInfo
.Width
div 2;
4260 GameY
:= gMapInfo
.Height
div 2;
4269 FWantsInGame
:= False;
4274 if Self
= gPlayer1
then
4279 if Self
= gPlayer2
then
4286 if g_Game_IsNet
then
4287 MH_SEND_PlayerStats(FUID
);
4290 procedure TPlayer
.SwitchNoClip
;
4294 FGhost
:= not FGhost
;
4295 FPhysics
:= not FGhost
;
4307 procedure TPlayer
.Run(Direction
: TDirection
);
4311 if MAX_RUNVEL
> 8 then
4315 if Direction
= D_LEFT
then
4317 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4318 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4321 if FObj
.Vel
.X
< MAX_RUNVEL
then
4322 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4324 // Âîçìîæíî, ïèíàåì êóñêè:
4325 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4327 b
:= Abs(FObj
.Vel
.X
);
4328 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4329 for a
:= 0 to High(gGibs
) do
4330 if gGibs
[a
].Live
and
4331 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4332 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4334 if FObj
.Vel
.X
< 0 then
4335 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4337 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4343 procedure TPlayer
.SeeDown();
4345 SetAction(A_SEEDOWN
);
4347 if FDirection
= D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4349 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4352 procedure TPlayer
.SeeUp();
4356 if FDirection
= D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4358 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4361 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4369 A_ATTACK
: Prior
:= 2;
4370 A_SEEUP
: Prior
:= 1;
4371 A_SEEDOWN
: Prior
:= 1;
4372 A_ATTACKUP
: Prior
:= 2;
4373 A_ATTACKDOWN
: Prior
:= 2;
4378 if (Prior
> FActionPrior
) or Force
then
4379 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4381 FActionPrior
:= Prior
;
4382 FActionAnim
:= Action
;
4383 FActionForce
:= Force
;
4384 FActionChanged
:= True;
4387 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4390 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4392 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4393 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4394 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4395 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4398 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4405 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4407 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4408 if g_Game_IsServer
and g_Game_IsNet
then
4409 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4413 FJustTeleported
:= True;
4418 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4420 Anim
:= TAnimation
.Create(ID
, False, 3);
4423 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4424 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4425 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4426 if g_Game_IsServer
and g_Game_IsNet
then
4427 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4428 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4432 FObj
.X
:= X
-PLAYER_RECT
.X
;
4433 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4434 if FLive
and FGhost
then
4440 if not g_Game_IsNet
then
4444 SetDirection(D_LEFT
);
4450 SetDirection(D_RIGHT
);
4456 if FDirection
= D_RIGHT
then
4458 SetDirection(D_LEFT
);
4463 SetDirection(D_RIGHT
);
4469 if not silent
and (Anim
<> nil) then
4471 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4472 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4475 if g_Game_IsServer
and g_Game_IsNet
then
4476 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4477 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4484 function nonz(a
: Single): Single;
4492 procedure TPlayer
.Update();
4495 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4496 blockmon
, headwater
, dospawn
: Boolean;
4501 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4502 AnyServer
:= g_Game_IsServer
;
4504 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4505 DoLerp(NetInterpLevel
+ 1)
4511 if FClientID
>= 0 then
4513 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4514 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4515 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4524 if FLive
and (gFly
or FJetpack
) then
4527 if FDirection
= D_LEFT
then
4532 if FLive
and (not FGhost
) then
4534 if FKeys
[KEY_UP
].Pressed
then
4536 if FKeys
[KEY_DOWN
].Pressed
then
4540 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4543 i
:= g_basic
.Sign(FIncCam
);
4544 FIncCam
:= Abs(FIncCam
);
4545 DecMin(FIncCam
, 5, 0);
4546 FIncCam
:= FIncCam
*i
;
4549 // no need to do that each second frame, weapon queue will take care of it
4550 if FLive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4551 if FLive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4553 if gTime
mod (GAME_TICK
*2) <> 0 then
4555 if (FObj
.Vel
.X
= 0) and FLive
then
4557 if FKeys
[KEY_LEFT
].Pressed
then
4559 if FKeys
[KEY_RIGHT
].Pressed
then
4564 g_Obj_Move(@FObj
, True, True, True);
4569 FActionChanged
:= False;
4573 // Let alive player do some actions
4574 if FKeys
[KEY_LEFT
].Pressed
then Run(D_LEFT
);
4575 if FKeys
[KEY_RIGHT
].Pressed
then Run(D_RIGHT
);
4576 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
4577 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
4578 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
4579 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
4580 if FKeys
[KEY_JUMP
].Pressed
then Jump()
4583 if AnyServer
and FJetpack
then
4587 if NetServer
then MH_SEND_PlayerStats(FUID
);
4589 FCanJetpack
:= True;
4596 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
4598 if FKeys
[k
].Pressed
then
4606 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4609 if (FTime
[T_RESPAWN
] <= gTime
) and
4610 gGameOn
and (not FLive
) then
4612 if (g_Player_GetCount() > 1) then
4616 gExit
:= EXIT_RESTART
;
4621 // Dead spectator actions
4624 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
4625 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
4629 if (FSpectatePlayer
>= High(gPlayers
)) then
4630 FSpectatePlayer
:= -1
4634 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
4635 if gPlayers
[I
] <> nil then
4636 if gPlayers
[I
].Live
then
4637 if gPlayers
[I
].UID
<> FUID
then
4639 FSpectatePlayer
:= I
;
4644 if not SetSpect
then FSpectatePlayer
:= -1;
4655 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
4657 FYTo
:= FObj
.Y
- 32;
4658 FSpectatePlayer
:= -1;
4660 if FKeys
[KEY_DOWN
].Pressed
then
4662 FYTo
:= FObj
.Y
+ 32;
4663 FSpectatePlayer
:= -1;
4665 if FKeys
[KEY_LEFT
].Pressed
then
4667 FXTo
:= FObj
.X
- 32;
4668 FSpectatePlayer
:= -1;
4670 if FKeys
[KEY_RIGHT
].Pressed
then
4672 FXTo
:= FObj
.X
+ 32;
4673 FSpectatePlayer
:= -1;
4676 if (FXTo
< -64) then
4678 else if (FXTo
> gMapInfo
.Width
+ 32) then
4679 FXTo
:= gMapInfo
.Width
+ 32;
4680 if (FYTo
< -72) then
4682 else if (FYTo
> gMapInfo
.Height
+ 32) then
4683 FYTo
:= gMapInfo
.Height
+ 32;
4687 g_Obj_Move(@FObj
, True, True, True)
4693 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
4694 if gPlayers
[FSpectatePlayer
] <> nil then
4695 if gPlayers
[FSpectatePlayer
].Live
then
4697 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
4698 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
4702 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
4703 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
4704 PANEL_BLOCKMON
, True);
4705 headwater
:= HeadInLiquid(0, 0);
4707 // Ñîïðîòèâëåíèå âîçäóõà:
4708 if (not FLive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
4709 if FObj
.Vel
.X
<> 0 then
4710 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
4712 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
4713 DecMin(FPain
, 5, 0);
4714 DecMin(FPickup
, 1, 0);
4716 if FLive
and (FObj
.Y
> gMapInfo
.Height
+128) and AnyServer
then
4718 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
4719 FMegaRulez
[MR_SUIT
] := 0;
4720 FMegaRulez
[MR_INVUL
] := 0;
4721 FMegaRulez
[MR_INVIS
] := 0;
4722 Kill(K_FALLKILL
, 0, HIT_FALL
);
4729 if FCurrWeap
= WEAPON_SAW
then
4730 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
4731 FSawSoundSelect
.IsPlaying()) then
4732 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
4735 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
4736 (not FJetSoundOff
.IsPlaying()) then
4738 FJetSoundFly
.SetPosition(0);
4739 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
4742 for b
:= WP_FIRST
to WP_LAST
do
4743 if FReloading
[b
] > 0 then
4749 if FShellTimer
> -1 then
4750 if FShellTimer
= 0 then
4752 if FShellType
= SHELL_SHELL
then
4753 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4754 GameVelX
, GameVelY
-2, SHELL_SHELL
)
4755 else if FShellType
= SHELL_DBLSHELL
then
4757 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4758 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
4759 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4760 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
4763 end else Dec(FShellTimer
);
4765 if (FBFGFireCounter
> -1) then
4766 if FBFGFireCounter
= 0 then
4770 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
4771 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
4772 xd
:= wx
+IfThen(FDirection
= D_LEFT
, -30, 30);
4773 yd
:= wy
+firediry();
4774 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
4775 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
4776 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
4777 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
4778 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
4781 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
4782 FBFGFireCounter
:= -1;
4785 FBFGFireCounter
:= 0
4787 Dec(FBFGFireCounter
);
4789 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
4791 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
4793 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
4796 if (headwater
or blockmon
) then
4802 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
4805 else if (FAir
mod 31 = 0) and not blockmon
then
4807 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
4808 if Random(2) = 0 then
4809 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
4811 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
4813 end else if FAir
< AIR_DEF
then
4816 if FDamageBuffer
> 0 then
4818 if FDamageBuffer
>= 9 then
4822 if FDamageBuffer
< 30 then i
:= 9
4823 else if FDamageBuffer
< 100 then i
:= 18
4827 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
4828 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
4829 FHealth
:= FHealth
-ii
;
4832 FHealth
:= FHealth
+FArmor
;
4837 if FHealth
<= 0 then
4838 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
4839 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
4840 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
4844 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
4845 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
4846 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
4847 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
4854 end; // if FLive then ...
4856 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
4858 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
4859 FModel
.GetCurrentAnimation
.MinLength
:= i
;
4860 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
4861 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
4863 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
4864 then SetAction(A_STAND
, True);
4866 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
4868 for b
:= Low(FKeys
) to High(FKeys
) do
4869 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
4872 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
4874 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
4875 FObj
.Y
+PLAYER_RECT
.Y
,
4882 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
4884 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
4885 FObj
.Y
+PLAYER_RECT
.Y
,
4889 Panel
.Width
, Panel
.Height
);
4892 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
4894 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
4895 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
4896 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
4897 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
4900 function g_Player_ValidName(Name
: string): Boolean;
4906 if gPlayers
= nil then Exit
;
4908 for a
:= 0 to High(gPlayers
) do
4909 if gPlayers
[a
] <> nil then
4910 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
4917 procedure TPlayer
.SetDirection(Direction
: TDirection
);
4921 d
:= FModel
.Direction
;
4923 FModel
.Direction
:= Direction
;
4924 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
4926 FDirection
:= Direction
;
4929 function TPlayer
.GetKeys(): Byte;
4933 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
4934 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
4935 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
4937 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
4938 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
4941 procedure TPlayer
.Use();
4945 if FTime
[T_USE
] > gTime
then Exit
;
4947 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
4948 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
4950 for a
:= 0 to High(gPlayers
) do
4951 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
4952 gPlayers
[a
].Live
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
4953 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
4954 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
4956 gPlayers
[a
].Touch();
4957 if g_Game_IsNet
and g_Game_IsServer
then
4958 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
4961 FTime
[T_USE
] := gTime
+120;
4964 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
4968 WX
, WY
, XD
, YD
: Integer;
4979 if R_BERSERK
in FRulez
then
4981 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
4982 obj
.X
:= FObj
.X
+FObj
.Rect
.X
;
4983 obj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
4986 obj
.rect
.Width
:= 39;
4987 obj
.rect
.Height
:= 52;
4988 obj
.Vel
.X
:= (xd
-wx
) div 2;
4989 obj
.Vel
.Y
:= (yd
-wy
) div 2;
4990 obj
.Accel
.X
:= xd
-wx
;
4991 obj
.Accel
.y
:= yd
-wy
;
4993 if g_Weapon_Hit(@obj
, 50, FUID
, HIT_SOME
) <> 0 then
4994 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
4996 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5000 FPain
:= min(FPain
+ 25, 50);
5002 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5007 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5008 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5010 FSawSoundSelect
.Stop();
5012 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5014 else if not FSawSoundHit
.IsPlaying() then
5016 FSawSoundSelect
.Stop();
5017 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5024 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5025 FFireAngle
:= FAngle
;
5027 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5028 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5033 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5034 FFireAngle
:= FAngle
;
5037 FShellType
:= SHELL_SHELL
;
5042 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5043 FFireAngle
:= FAngle
;
5046 FShellType
:= SHELL_DBLSHELL
;
5051 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5052 FFireAngle
:= FAngle
;
5054 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5055 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5058 WEAPON_ROCKETLAUNCHER
:
5060 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5061 FFireAngle
:= FAngle
;
5067 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5068 FFireAngle
:= FAngle
;
5074 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5075 FFireAngle
:= FAngle
;
5079 WEAPON_SUPERPULEMET
:
5081 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5082 FFireAngle
:= FAngle
;
5084 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5085 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5088 WEAPON_FLAMETHROWER
:
5090 FFireAngle
:= FAngle
;
5097 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5098 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5099 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5102 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5104 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5105 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5108 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5112 if NetInterpLevel
< 1 then
5122 AX
:= Abs(FXTo
- FObj
.X
);
5123 AY
:= Abs(FYTo
- FObj
.Y
);
5124 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5126 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5131 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5133 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5134 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5135 PANEL_LIFTUP
, False) then Result
:= -1
5137 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5138 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5139 PANEL_LIFTDOWN
, False) then Result
:= 1
5143 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5150 if Flag
= FLAG_NONE
then
5153 if not g_Game_IsServer
then Exit
;
5155 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5156 if (Flag
= FTeam
) and
5157 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5158 (FFlag
<> FLAG_NONE
) then
5160 if FFlag
= FLAG_RED
then
5161 s
:= _lc
[I_PLAYER_FLAG_RED
]
5163 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5165 evtype
:= FLAG_STATE_SCORED
;
5167 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5168 Insert('.', ts
, Length(ts
) + 1 - 3);
5169 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5171 g_Map_ResetFlag(FFlag
);
5172 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5174 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5177 if g_Game_IsNet
then
5179 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5183 gFlags
[FFlag
].CaptureTime
:= 0;
5188 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5189 if (Flag
= FTeam
) and
5190 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5192 if Flag
= FLAG_RED
then
5193 s
:= _lc
[I_PLAYER_FLAG_RED
]
5195 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5197 evtype
:= FLAG_STATE_RETURNED
;
5198 gFlags
[Flag
].CaptureTime
:= 0;
5200 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5202 g_Map_ResetFlag(Flag
);
5203 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5206 if g_Game_IsNet
then
5208 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5214 // Ïîäîáðàë ÷óæîé ôëàã:
5215 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5219 if Flag
= FLAG_RED
then
5220 s
:= _lc
[I_PLAYER_FLAG_RED
]
5222 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5224 evtype
:= FLAG_STATE_CAPTURED
;
5226 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5228 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5230 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5233 if g_Game_IsNet
then
5235 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5241 procedure TPlayer
.SetFlag(Flag
: Byte);
5244 if FModel
<> nil then
5245 FModel
.SetFlag(FFlag
);
5248 function TPlayer
.DropFlag(): Boolean;
5253 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5255 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5256 with gFlags
[FFlag
] do
5260 Direction
:= FDirection
;
5261 State
:= FLAG_STATE_DROPPED
;
5263 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5264 (FObj
.Vel
.Y
div 2)-2+Random(5));
5266 if FFlag
= FLAG_RED
then
5267 s
:= _lc
[I_PLAYER_FLAG_RED
]
5269 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5271 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5272 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5274 if g_Game_IsNet
then
5275 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5281 procedure TPlayer
.GetSecret();
5286 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5288 Assert(Key
<= High(FKeys
));
5290 FKeys
[Key
].Pressed
:= True;
5291 FKeys
[Key
].Time
:= Time
;
5294 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5296 Result
:= FKeys
[K
].Pressed
;
5299 procedure TPlayer
.ReleaseKeys();
5303 for a
:= Low(FKeys
) to High(FKeys
) do
5305 FKeys
[a
].Pressed
:= False;
5310 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5314 function TPlayer
.firediry(): Integer;
5316 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5317 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5321 procedure TPlayer
.RememberState();
5325 FSavedState
.Health
:= FHealth
;
5326 FSavedState
.Armor
:= FArmor
;
5327 FSavedState
.Air
:= FAir
;
5328 FSavedState
.JetFuel
:= FJetFuel
;
5329 FSavedState
.CurrWeap
:= FCurrWeap
;
5330 FSavedState
.NextWeap
:= FNextWeap
;
5331 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5334 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5336 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5338 FSavedState
.Rulez
:= FRulez
;
5339 FSavedState
.WaitRecall
:= True;
5342 procedure TPlayer
.RecallState();
5346 if not FSavedState
.WaitRecall
then Exit
;
5348 FHealth
:= FSavedState
.Health
;
5349 FArmor
:= FSavedState
.Armor
;
5350 FAir
:= FSavedState
.Air
;
5351 FJetFuel
:= FSavedState
.JetFuel
;
5352 FCurrWeap
:= FSavedState
.CurrWeap
;
5353 FNextWeap
:= FSavedState
.NextWeap
;
5354 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5357 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5359 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5361 FRulez
:= FSavedState
.Rulez
;
5362 FSavedState
.WaitRecall
:= False;
5364 if gGameSettings
.GameType
= GT_SERVER
then
5365 MH_SEND_PlayerStats(FUID
);
5368 procedure TPlayer
.SaveState(var Mem
: TBinMemoryWriter
);
5380 Mem
:= TBinMemoryWriter
.Create(i
);
5382 // Ñèãíàòóðà èãðîêà:
5383 sig
:= PLAYER_SIGNATURE
; // 'PLYR'
5384 Mem
.WriteDWORD(sig
);
5386 Mem
.WriteBoolean(FIamBot
);
5388 Mem
.WriteWord(FUID
);
5390 Mem
.WriteString(FName
, 32);
5392 Mem
.WriteByte(FTeam
);
5394 Mem
.WriteBoolean(FLive
);
5395 // Èçðàñõîäîâàë ëè âñå æèçíè:
5396 Mem
.WriteBoolean(FNoRespawn
);
5398 if FDirection
= D_LEFT
then
5404 Mem
.WriteInt(FHealth
);
5406 Mem
.WriteByte(FLives
);
5408 Mem
.WriteInt(FArmor
);
5412 Mem
.WriteInt(FJetFuel
);
5414 Mem
.WriteInt(FPain
);
5416 Mem
.WriteInt(FKills
);
5418 Mem
.WriteInt(FMonsterKills
);
5420 Mem
.WriteInt(FFrags
);
5422 Mem
.WriteByte(FFragCombo
);
5423 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5424 Mem
.WriteDWORD(FLastFrag
);
5426 Mem
.WriteInt(FDeath
);
5427 // Êàêîé ôëàã íåñåò:
5428 Mem
.WriteByte(FFlag
);
5430 Mem
.WriteInt(FSecrets
);
5432 Mem
.WriteByte(FCurrWeap
);
5434 Mem
.WriteWord(FNextWeap
);
5436 Mem
.WriteByte(FNextWeapDelay
);
5437 // Âðåìÿ çàðÿäêè BFG:
5438 Mem
.WriteSmallInt(FBFGFireCounter
);
5440 Mem
.WriteInt(FDamageBuffer
);
5441 // Ïîñëåäíèé óäàðèâøèé:
5442 Mem
.WriteWord(FLastSpawnerUID
);
5443 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5444 Mem
.WriteByte(FLastHit
);
5446 Obj_SaveState(@FObj
, Mem
);
5447 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5448 for i
:= A_BULLETS
to A_HIGH
do
5449 Mem
.WriteWord(FAmmo
[i
]);
5450 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5451 for i
:= A_BULLETS
to A_HIGH
do
5452 Mem
.WriteWord(FMaxAmmo
[i
]);
5454 for i
:= WP_FIRST
to WP_LAST
do
5455 Mem
.WriteBoolean(FWeapon
[i
]);
5456 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5457 for i
:= WP_FIRST
to WP_LAST
do
5458 Mem
.WriteWord(FReloading
[i
]);
5460 if R_ITEM_BACKPACK
in FRulez
then
5465 // Íàëè÷èå êðàñíîãî êëþ÷à:
5466 if R_KEY_RED
in FRulez
then
5471 // Íàëè÷èå çåëåíîãî êëþ÷à:
5472 if R_KEY_GREEN
in FRulez
then
5477 // Íàëè÷èå ñèíåãî êëþ÷à:
5478 if R_KEY_BLUE
in FRulez
then
5483 // Íàëè÷èå áåðñåðêà:
5484 if R_BERSERK
in FRulez
then
5489 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5490 for i
:= MR_SUIT
to MR_MAX
do
5491 Mem
.WriteDWORD(FMegaRulez
[i
]);
5492 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5493 for i
:= T_RESPAWN
to T_FLAGCAP
do
5494 Mem
.WriteDWORD(FTime
[i
]);
5497 Mem
.WriteString(str
);
5507 procedure TPlayer
.LoadState(var Mem
: TBinMemoryReader
);
5517 // Ñèãíàòóðà èãðîêà:
5519 if sig
<> PLAYER_SIGNATURE
then // 'PLYR'
5521 raise EBinSizeError
.Create('TPlayer.LoadState: Wrong Player Signature');
5524 Mem
.ReadBoolean(FIamBot
);
5528 Mem
.ReadString(str
);
5529 if (Self
<> gPlayer1
) and (Self
<> gPlayer2
) then
5532 Mem
.ReadByte(FTeam
);
5534 Mem
.ReadBoolean(FLive
);
5535 // Èçðàñõîäîâàë ëè âñå æèçíè:
5536 Mem
.ReadBoolean(FNoRespawn
);
5540 FDirection
:= D_LEFT
5542 FDirection
:= D_RIGHT
;
5544 Mem
.ReadInt(FHealth
);
5546 Mem
.ReadByte(FLives
);
5548 Mem
.ReadInt(FArmor
);
5552 Mem
.ReadInt(FJetFuel
);
5556 Mem
.ReadInt(FKills
);
5558 Mem
.ReadInt(FMonsterKills
);
5560 Mem
.ReadInt(FFrags
);
5562 Mem
.ReadByte(FFragCombo
);
5563 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5564 Mem
.ReadDWORD(FLastFrag
);
5566 Mem
.ReadInt(FDeath
);
5567 // Êàêîé ôëàã íåñåò:
5568 Mem
.ReadByte(FFlag
);
5570 Mem
.ReadInt(FSecrets
);
5572 Mem
.ReadByte(FCurrWeap
);
5574 Mem
.ReadWord(FNextWeap
);
5576 Mem
.ReadByte(FNextWeapDelay
);
5577 // Âðåìÿ çàðÿäêè BFG:
5578 Mem
.ReadSmallInt(FBFGFireCounter
);
5580 Mem
.ReadInt(FDamageBuffer
);
5581 // Ïîñëåäíèé óäàðèâøèé:
5582 Mem
.ReadWord(FLastSpawnerUID
);
5583 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5584 Mem
.ReadByte(FLastHit
);
5586 Obj_LoadState(@FObj
, Mem
);
5587 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5588 for i
:= A_BULLETS
to A_HIGH
do
5589 Mem
.ReadWord(FAmmo
[i
]);
5590 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5591 for i
:= A_BULLETS
to A_HIGH
do
5592 Mem
.ReadWord(FMaxAmmo
[i
]);
5594 for i
:= WP_FIRST
to WP_LAST
do
5595 Mem
.ReadBoolean(FWeapon
[i
]);
5596 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5597 for i
:= WP_FIRST
to WP_LAST
do
5598 Mem
.ReadWord(FReloading
[i
]);
5602 Include(FRulez
, R_ITEM_BACKPACK
);
5603 // Íàëè÷èå êðàñíîãî êëþ÷à:
5606 Include(FRulez
, R_KEY_RED
);
5607 // Íàëè÷èå çåëåíîãî êëþ÷à:
5610 Include(FRulez
, R_KEY_GREEN
);
5611 // Íàëè÷èå ñèíåãî êëþ÷à:
5614 Include(FRulez
, R_KEY_BLUE
);
5615 // Íàëè÷èå áåðñåðêà:
5618 Include(FRulez
, R_BERSERK
);
5619 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5620 for i
:= MR_SUIT
to MR_MAX
do
5621 Mem
.ReadDWORD(FMegaRulez
[i
]);
5622 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5623 for i
:= T_RESPAWN
to T_FLAGCAP
do
5624 Mem
.ReadDWORD(FTime
[i
]);
5626 Mem
.ReadString(str
);
5628 Mem
.ReadByte(FColor
.R
);
5629 Mem
.ReadByte(FColor
.G
);
5630 Mem
.ReadByte(FColor
.B
);
5631 if Self
= gPlayer1
then
5633 str
:= gPlayer1Settings
.Model
;
5634 FColor
:= gPlayer1Settings
.Color
;
5636 if Self
= gPlayer2
then
5638 str
:= gPlayer2Settings
.Model
;
5639 FColor
:= gPlayer2Settings
.Color
;
5641 // Îáíîâëÿåì ìîäåëü èãðîêà:
5643 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
5644 FModel
.Color
:= TEAMCOLOR
[FTeam
]
5646 FModel
.Color
:= FColor
;
5649 procedure TPlayer
.AllRulez(Health
: Boolean);
5655 FHealth
:= PLAYER_HP_LIMIT
;
5656 FArmor
:= PLAYER_AP_LIMIT
;
5660 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
5661 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
5662 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5665 procedure TPlayer
.RestoreHealthArmor();
5667 FHealth
:= PLAYER_HP_LIMIT
;
5668 FArmor
:= PLAYER_AP_LIMIT
;
5671 procedure TPlayer
.FragCombo();
5675 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
5677 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
5679 if FFragCombo
< 5 then
5681 Param
:= FUID
or (FFragCombo
shl 16);
5682 if (FComboEvnt
>= Low(gDelayedEvents
)) and
5683 (FComboEvnt
<= High(gDelayedEvents
)) and
5684 gDelayedEvents
[FComboEvnt
].Pending
and
5685 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
5686 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
5688 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
5689 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
5692 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
5700 procedure TPlayer
.GiveItem(ItemType
: Byte);
5704 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
5706 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
5710 if FAir
< AIR_MAX
then
5717 if not (R_BERSERK
in FRulez
) then
5719 Include(FRulez
, R_BERSERK
);
5720 if FBFGFireCounter
< 1 then
5722 FCurrWeap
:= WEAPON_KASTET
;
5724 FModel
.SetWeapon(WEAPON_KASTET
);
5728 FBerserk
:= gTime
+30000;
5730 if FHealth
< PLAYER_HP_SOFT
then
5732 FHealth
:= PLAYER_HP_SOFT
;
5733 FBerserk
:= gTime
+30000;
5738 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
5740 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
5744 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
5746 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
5750 if FJetFuel
< JET_MAX
then
5752 FJetFuel
:= JET_MAX
;
5755 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
5756 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
5758 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
5759 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5761 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
5763 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
5765 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
5766 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5769 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
5770 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
5771 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
5772 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
5773 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
5774 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
5775 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
5776 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
5777 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
5779 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5780 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
5781 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5782 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
5783 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5784 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
5785 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5786 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
5787 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
5790 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
5791 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
5792 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
5793 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
5794 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
5796 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
5797 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
5798 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
5799 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
5800 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
5802 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5803 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5804 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5805 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5807 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
5810 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
5811 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
5812 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
5814 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
5815 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
5820 if g_Game_IsNet
and g_Game_IsServer
then
5821 MH_SEND_PlayerStats(FUID
);
5824 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
5829 if (Random(5) = 1) and (Times
= 1) then
5832 if BodyInLiquid(0, 0) then
5834 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
5835 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
5836 if Random(2) = 0 then
5837 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5839 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5843 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
5845 for i
:= 1 to Times
do
5847 Anim
:= TAnimation
.Create(id
, False, 3);
5849 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
5850 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
5856 procedure TPlayer
.PauseSounds(Enable
: Boolean);
5858 FSawSound
.Pause(Enable
);
5859 FSawSoundIdle
.Pause(Enable
);
5860 FSawSoundHit
.Pause(Enable
);
5861 FSawSoundSelect
.Pause(Enable
);
5866 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
5871 FObj
.Rect
:= PLAYER_CORPSERECT
;
5872 FModelName
:= ModelName
;
5877 FState
:= CORPSE_STATE_MESS
;
5878 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
5882 FState
:= CORPSE_STATE_NORMAL
;
5883 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
5887 destructor TCorpse
.Destroy();
5894 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
5898 if FState
= CORPSE_STATE_REMOVEME
then
5901 FDamage
:= FDamage
+ Value
;
5903 if FDamage
> 150 then
5905 if FAnimation
<> nil then
5910 FState
:= CORPSE_STATE_REMOVEME
;
5912 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
5913 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
5914 FModelName
, FColor
);
5915 // Çâóê ìÿñà îò òðóïà:
5916 pm
:= g_PlayerModel_Get(FModelName
);
5917 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
5923 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
5924 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
5925 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
5926 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
5927 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
5932 procedure TCorpse
.Draw();
5934 if FState
= CORPSE_STATE_REMOVEME
then
5937 if FAnimation
<> nil then
5938 FAnimation
.Draw(FObj
.X
, FObj
.Y
, M_NONE
);
5940 if FAnimationMask
<> nil then
5943 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, M_NONE
);
5950 procedure TCorpse
.Update();
5954 if FState
= CORPSE_STATE_REMOVEME
then
5957 if gTime
mod (GAME_TICK
*2) <> 0 then
5959 g_Obj_Move(@FObj
, True, True, True);
5964 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
5965 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5967 st
:= g_Obj_Move(@FObj
, True, True, True);
5969 if WordBool(st
and MOVE_FALLOUT
) then
5971 FState
:= CORPSE_STATE_REMOVEME
;
5975 if FAnimation
<> nil then
5976 FAnimation
.Update();
5977 if FAnimationMask
<> nil then
5978 FAnimationMask
.Update();
5981 procedure TCorpse
.SaveState(var Mem
: TBinMemoryWriter
);
5990 sig
:= CORPSE_SIGNATURE
; // 'CORP'
5991 Mem
.WriteDWORD(sig
);
5993 Mem
.WriteByte(FState
);
5994 // Íàêîïëåííûé óðîí:
5995 Mem
.WriteByte(FDamage
);
5997 Mem
.WriteByte(FColor
.R
);
5998 Mem
.WriteByte(FColor
.G
);
5999 Mem
.WriteByte(FColor
.B
);
6001 Obj_SaveState(@FObj
, Mem
);
6002 // Åñòü ëè àíèìàöèÿ:
6003 anim
:= FAnimation
<> nil;
6004 Mem
.WriteBoolean(anim
);
6005 // Åñëè åñòü - ñîõðàíÿåì:
6007 FAnimation
.SaveState(Mem
);
6008 // Åñòü ëè ìàñêà àíèìàöèè:
6009 anim
:= FAnimationMask
<> nil;
6010 Mem
.WriteBoolean(anim
);
6011 // Åñëè åñòü - ñîõðàíÿåì:
6013 FAnimationMask
.SaveState(Mem
);
6016 procedure TCorpse
.LoadState(var Mem
: TBinMemoryReader
);
6026 if sig
<> CORPSE_SIGNATURE
then // 'CORP'
6028 raise EBinSizeError
.Create('TCorpse.LoadState: Wrong Corpse Signature');
6031 Mem
.ReadByte(FState
);
6032 // Íàêîïëåííûé óðîí:
6033 Mem
.ReadByte(FDamage
);
6035 Mem
.ReadByte(FColor
.R
);
6036 Mem
.ReadByte(FColor
.G
);
6037 Mem
.ReadByte(FColor
.B
);
6039 Obj_LoadState(@FObj
, Mem
);
6040 // Åñòü ëè àíèìàöèÿ:
6041 Mem
.ReadBoolean(anim
);
6042 // Åñëè åñòü - çàãðóæàåì:
6045 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6046 FAnimation
.LoadState(Mem
);
6048 // Åñòü ëè ìàñêà àíèìàöèè:
6049 Mem
.ReadBoolean(anim
);
6050 // Åñëè åñòü - çàãðóæàåì:
6053 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6054 FAnimationMask
.LoadState(Mem
);
6060 constructor TBot
.Create();
6067 FSpectator
:= False;
6074 for a
:= WP_FIRST
to WP_LAST
do
6076 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6077 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6078 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6082 destructor TBot
.Destroy();
6085 inherited Destroy();
6088 procedure TBot
.Draw();
6092 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6093 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6096 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6098 inherited Respawn(Silent
, Force
);
6101 FSelectedWeapon
:= FCurrWeap
;
6106 procedure TBot
.UpdateCombat();
6119 TTargetRecord
= array of TTarget
;
6121 function Compare(a
, b
: TTarget
): Integer;
6123 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6126 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6128 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6129 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6131 if a
.Dist
> b
.Dist
then // B áëèæå
6133 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6136 else // Ñòðàííî -> A
6141 a
, x1
, y1
, x2
, y2
: Integer;
6142 targets
: TTargetRecord
;
6144 Target
, BestTarget
: TTarget
;
6145 firew
, fireh
: Integer;
6149 vsPlayer
, vsMonster
, ok
: Boolean;
6151 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6152 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6154 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6155 if FCurrWeap
<> FSelectedWeapon
then
6158 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6159 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6161 RemoveAIFlag('NEEDFIRE');
6164 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6165 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6166 else PressKey(KEY_FIRE
);
6170 // Êîîðäèíàòû ñòâîëà:
6171 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6172 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6174 Target
.UID
:= FTargetUID
;
6177 if Target
.UID
<> 0 then
6178 begin // Öåëü åñòü - íàñòðàèâàåì
6179 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6182 with g_Player_Get(Target
.UID
) do
6184 if (@FObj
) <> nil then
6191 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6192 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6193 Target
.Rect
:= PLAYER_RECT
;
6194 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6195 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6196 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6197 Target
.IsPlayer
:= True;
6201 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6204 mon
:= g_Monsters_Get(Target
.UID
);
6207 Target
.X
:= mon
.Obj
.X
;
6208 Target
.Y
:= mon
.Obj
.Y
;
6210 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6211 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6212 Target
.Rect
:= mon
.Obj
.Rect
;
6213 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6214 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6215 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6216 Target
.IsPlayer
:= False;
6223 begin // Öåëè íåò - îáíóëÿåì
6228 Target
.Visible
:= False;
6229 Target
.Line
:= False;
6230 Target
.IsPlayer
:= False;
6235 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6236 if (not Target
.Line
) or (not Target
.Visible
) then
6240 for a
:= 0 to High(gPlayers
) do
6241 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].Live
) and
6242 (gPlayers
[a
].FUID
<> FUID
) and
6243 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6244 (not gPlayers
[a
].NoTarget
) and
6245 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6247 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6248 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6251 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6252 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6254 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6255 if g_TraceVector(x1
, y1
, x2
, y2
) then
6257 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6258 SetLength(targets
, Length(targets
)+1);
6259 with targets
[High(targets
)] do
6261 UID
:= gPlayers
[a
].FUID
;
6262 X
:= gPlayers
[a
].FObj
.X
;
6263 Y
:= gPlayers
[a
].FObj
.Y
;
6266 Rect
:= PLAYER_RECT
;
6267 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6268 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6269 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6277 if vsMonster
and (gMonsters
<> nil) then
6278 for a
:= 0 to High(gMonsters
) do
6279 if (gMonsters
[a
] <> nil) and (gMonsters
[a
].Live
) and
6280 (gMonsters
[a
].MonsterType
<> MONSTER_BARREL
) then
6282 mon
:= gMonsters
[a
];
6284 if not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
6285 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
) then
6288 x2
:= mon
.Obj
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6289 y2
:= mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6291 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6292 if g_TraceVector(x1
, y1
, x2
, y2
) then
6294 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6295 SetLength(targets
, Length(targets
)+1);
6296 with targets
[High(targets
)] do
6303 Rect
:= mon
.Obj
.Rect
;
6304 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6305 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6306 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6314 // Åñëè åñòü âîçìîæíûå öåëè:
6315 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6316 if targets
<> nil then
6318 // Âûáèðàåì íàèëó÷øóþ öåëü:
6319 BestTarget
:= targets
[0];
6320 if Length(targets
) > 1 then
6321 for a
:= 1 to High(targets
) do
6322 if Compare(BestTarget
, targets
[a
]) = 1 then
6323 BestTarget
:= targets
[a
];
6325 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6326 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6327 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6329 Target
:= BestTarget
;
6331 if (Healthy() = 3) or ((Healthy() = 2)) then
6332 begin // Åñëè çäîðîâû - äîãîíÿåì
6333 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6334 SetAIFlag('GORIGHT', '1');
6335 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6336 SetAIFlag('GOLEFT', '1');
6339 begin // Åñëè ïîáèòû - óáåãàåì
6340 if ((RunDirection() = D_LEFT
) and (Target
.X
< FObj
.X
)) then
6341 SetAIFlag('GORIGHT', '1');
6342 if ((RunDirection() = D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6343 SetAIFlag('GOLEFT', '1');
6346 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6347 SelectWeapon(Abs(x1
-Target
.cX
));
6352 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6353 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6354 if Target
.UID
<> 0 then
6356 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6357 Target
.Y
+ Target
.Rect
.Y
) then
6358 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6359 if (Healthy() = 3) or ((Healthy() = 2)) then
6360 begin // Åñëè çäîðîâû - äîãîíÿåì
6361 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6362 SetAIFlag('GORIGHT', '1');
6363 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6364 SetAIFlag('GOLEFT', '1');
6367 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6369 if ((RunDirection() = D_LEFT
) and (Target
.X
< FObj
.X
)) then
6370 SetAIFlag('GORIGHT', '1');
6371 if ((RunDirection() = D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6372 SetAIFlag('GOLEFT', '1');
6376 begin // Öåëü ïîêà íà "ýêðàíå"
6377 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6378 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6379 FLastVisible
:= gTime
;
6380 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6381 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6383 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6384 SetAIFlag('GORIGHT', '1');
6385 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6386 SetAIFlag('GOLEFT', '1');
6390 // Âûáèðàåì óãîë ââåðõ:
6391 if FDirection
= D_LEFT
then
6392 angle
:= ANGLE_LEFTUP
6394 angle
:= ANGLE_RIGHTUP
;
6396 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6397 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6399 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6400 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6401 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6402 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6403 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6404 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6405 begin // òî íóæíî ñòðåëÿòü ââåðõ
6406 SetAIFlag('NEEDFIRE', '1');
6407 SetAIFlag('NEEDSEEUP', '1');
6410 // Âûáèðàåì óãîë âíèç:
6411 if FDirection
= D_LEFT
then
6412 angle
:= ANGLE_LEFTDOWN
6414 angle
:= ANGLE_RIGHTDOWN
;
6416 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6417 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6419 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6420 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6421 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6422 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6423 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6424 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6425 begin // òî íóæíî ñòðåëÿòü âíèç
6426 SetAIFlag('NEEDFIRE', '1');
6427 SetAIFlag('NEEDSEEDOWN', '1');
6430 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6431 if Target
.Visible
and
6432 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6433 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6435 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6436 if ((FDirection
= D_LEFT
) and (Target
.X
< FObj
.X
)) or
6437 ((FDirection
= D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6438 begin // òî íóæíî ñòðåëÿòü âïåðåä
6439 SetAIFlag('NEEDFIRE', '1');
6440 SetAIFlag('NEEDSEEDOWN', '');
6441 SetAIFlag('NEEDSEEUP', '');
6443 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6444 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6445 if GetRnd(FDifficult
.CloseJump
) then
6446 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6447 if Abs(FObj
.X
-Target
.X
) < 128 then
6451 if Random(a
) = 0 then
6452 SetAIFlag('NEEDJUMP', '1');
6456 // Åñëè öåëü âñå åùå åñòü:
6457 if Target
.UID
<> 0 then
6458 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
6459 Target
.UID
:= 0 // òî çàáûòü öåëü
6460 else // Åñëè âèäåëè íåäàâíî
6461 begin // íî öåëü óáèëè
6462 if Target
.IsPlayer
then
6463 begin // Öåëü - èãðîê
6464 pla
:= g_Player_Get(Target
.UID
);
6465 if (pla
= nil) or (not pla
.Live
) or pla
.NoTarget
or
6466 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6467 Target
.UID
:= 0; // òî çàáûòü öåëü
6470 begin // Öåëü - ìîíñòð
6471 mon
:= g_Monsters_Get(Target
.UID
);
6472 if (mon
= nil) or (not mon
.Live
) then
6473 Target
.UID
:= 0; // òî çàáûòü öåëü
6476 end; // if Target.UID <> 0
6478 FTargetUID
:= Target
.UID
;
6480 // Åñëè âîçìîæíûõ öåëåé íåò:
6481 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
6482 if targets
= nil then
6483 if GetAIFlag('ATTACKLEFT') <> '' then
6484 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
6485 RemoveAIFlag('ATTACKLEFT');
6487 SetAIFlag('NEEDJUMP', '1');
6489 if RunDirection() = D_RIGHT
then
6490 begin // Èäåì íå â òó ñòîðîíó
6491 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6492 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
6493 SetAIFlag('NEEDFIRE', '1');
6494 SetAIFlag('GOLEFT', '1');
6498 begin // Èäåì â íóæíóþ ñòîðîíó
6499 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6500 SetAIFlag('NEEDFIRE', '1');
6501 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6502 SetAIFlag('GORIGHT', '1');
6506 if GetAIFlag('ATTACKRIGHT') <> '' then
6507 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
6508 RemoveAIFlag('ATTACKRIGHT');
6510 SetAIFlag('NEEDJUMP', '1');
6512 if RunDirection() = D_LEFT
then
6513 begin // Èäåì íå â òó ñòîðîíó
6514 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6515 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
6516 SetAIFlag('NEEDFIRE', '1');
6517 SetAIFlag('GORIGHT', '1');
6522 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6523 SetAIFlag('NEEDFIRE', '1');
6524 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6525 SetAIFlag('GOLEFT', '1');
6529 //HACK! (does it belongs there?)
6530 RealizeCurrentWeapon();
6532 // Åñëè åñòü âîçìîæíûå öåëè:
6533 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
6534 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6535 for a
:= 0 to High(targets
) do
6537 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
6538 if GetRnd(FDifficult
.DiagFire
) then
6540 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
6541 if FDirection
= D_LEFT
then
6542 angle
:= ANGLE_LEFTUP
6544 angle
:= ANGLE_RIGHTUP
;
6546 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6547 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6549 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6550 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6551 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6552 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6553 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6555 SetAIFlag('NEEDFIRE', '1');
6556 SetAIFlag('NEEDSEEUP', '1');
6559 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
6560 if FDirection
= D_LEFT
then
6561 angle
:= ANGLE_LEFTDOWN
6563 angle
:= ANGLE_RIGHTDOWN
;
6565 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6566 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6568 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6569 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6570 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6571 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6572 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6574 SetAIFlag('NEEDFIRE', '1');
6575 SetAIFlag('NEEDSEEDOWN', '1');
6579 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
6580 if targets
[a
].Line
and targets
[a
].Visible
and
6581 (((FDirection
= D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
6582 ((FDirection
= D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
6584 SetAIFlag('NEEDFIRE', '1');
6589 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
6590 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
6591 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
6592 40+GetInterval(FDifficult
.Cover
, 40)) then
6593 SetAIFlag('NEEDJUMP', '1');
6595 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
6596 ammo
:= GetAmmoByWeapon(FCurrWeap
);
6597 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
6598 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
6600 SetAIFlag('SELECTWEAPON', '1');
6602 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
6603 if GetAIFlag('SELECTWEAPON') = '1' then
6606 RemoveAIFlag('SELECTWEAPON');
6610 procedure TBot
.Update();
6623 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
6624 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
6626 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
6628 if g_debug_BotAIOff
= 3 then
6638 RealizeCurrentWeapon();
6645 procedure TBot
.ReleaseKey(Key
: Byte);
6654 function TBot
.KeyPressed(Key
: Word): Boolean;
6656 Result
:= FKeys
[Key
].Pressed
;
6659 function TBot
.GetAIFlag(fName
: String20
): String20
;
6665 fName
:= LowerCase(fName
);
6667 if FAIFlags
<> nil then
6668 for a
:= 0 to High(FAIFlags
) do
6669 if LowerCase(FAIFlags
[a
].Name
) = fName
then
6671 Result
:= FAIFlags
[a
].Value
;
6676 procedure TBot
.RemoveAIFlag(fName
: String20
);
6680 if FAIFlags
= nil then Exit
;
6682 fName
:= LowerCase(fName
);
6684 for a
:= 0 to High(FAIFlags
) do
6685 if LowerCase(FAIFlags
[a
].Name
) = fName
then
6687 if a
<> High(FAIFlags
) then
6688 for b
:= a
to High(FAIFlags
)-1 do
6689 FAIFlags
[b
] := FAIFlags
[b
+1];
6691 SetLength(FAIFlags
, Length(FAIFlags
)-1);
6696 procedure TBot
.SetAIFlag(fName
, fValue
: String20
);
6704 fName
:= LowerCase(fName
);
6706 if FAIFlags
<> nil then
6707 for a
:= 0 to High(FAIFlags
) do
6708 if LowerCase(FAIFlags
[a
].Name
) = fName
then
6714 if ok
then FAIFlags
[a
].Value
:= fValue
6717 SetLength(FAIFlags
, Length(FAIFlags
)+1);
6718 with FAIFlags
[High(FAIFlags
)] do
6726 procedure TBot
.UpdateMove
;
6728 procedure GoLeft(Time
: Word = 1);
6730 ReleaseKey(KEY_LEFT
);
6731 ReleaseKey(KEY_RIGHT
);
6732 PressKey(KEY_LEFT
, Time
);
6733 SetDirection(D_LEFT
);
6736 procedure GoRight(Time
: Word = 1);
6738 ReleaseKey(KEY_LEFT
);
6739 ReleaseKey(KEY_RIGHT
);
6740 PressKey(KEY_RIGHT
, Time
);
6741 SetDirection(D_RIGHT
);
6744 function Rnd(a
: Word): Boolean;
6746 Result
:= Random(a
) = 0;
6749 procedure Turn(Time
: Word = 1200);
6751 if RunDirection() = D_LEFT
then GoRight(Time
) else GoLeft(Time
);
6756 ReleaseKey(KEY_LEFT
);
6757 ReleaseKey(KEY_RIGHT
);
6760 function CanRunLeft(): Boolean;
6762 Result
:= not CollideLevel(-1, 0);
6765 function CanRunRight(): Boolean;
6767 Result
:= not CollideLevel(1, 0);
6770 function CanRun(): Boolean;
6772 if RunDirection() = D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
6775 procedure Jump(Time
: Word = 30);
6777 PressKey(KEY_JUMP
, Time
);
6780 function NearHole(): Boolean;
6784 { TODO 5 : Ëåñòíèöû }
6785 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6786 for x
:= 1 to PLAYER_RECT
.Width
do
6787 if (not StayOnStep(x
*sx
, 0)) and
6788 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6789 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6798 function BorderHole(): Boolean;
6802 { TODO 5 : Ëåñòíèöû }
6803 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6804 for x
:= 1 to PLAYER_RECT
.Width
do
6805 if (not StayOnStep(x
*sx
, 0)) and
6806 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6807 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6809 for xx
:= x
to x
+32 do
6810 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
6820 function NearDeepHole(): Boolean;
6826 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6829 for x
:= 1 to PLAYER_RECT
.Width
do
6830 if (not StayOnStep(x
*sx
, 0)) and
6831 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6832 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6834 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6836 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
6841 end else Result
:= False;
6844 function OverDeepHole(): Boolean;
6851 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6853 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
6860 function OnGround(): Boolean;
6862 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
6865 function OnLadder(): Boolean;
6867 Result
:= FullInStep(0, 0);
6870 function BelowLadder(): Boolean;
6872 Result
:= (FullInStep(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
6873 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
6874 (FullInStep(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
6875 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
6878 function BelowLiftUp(): Boolean;
6880 Result
:= ((FullInLift(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
6881 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
6882 ((FullInLift(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
6883 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
6886 function OnTopLift(): Boolean;
6888 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
6891 function CanJumpOver(): Boolean;
6895 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6899 if not CollideLevel(sx
, 0) then Exit
;
6901 for y
:= 1 to BOT_MAXJUMP
do
6902 if CollideLevel(0, -y
) then Exit
else
6903 if not CollideLevel(sx
, -y
) then
6910 function CanJumpUp(Dist
: ShortInt): Boolean;
6917 if CollideLevel(Dist
, 0) then Exit
;
6920 for y
:= 0 to BOT_MAXJUMP
do
6921 if CollideLevel(Dist
, -y
) then
6930 for yy
:= y
+1 to BOT_MAXJUMP
do
6931 if not CollideLevel(Dist
, -yy
) then
6940 for y
:= 0 to BOT_MAXJUMP
do
6941 if CollideLevel(0, -y
) then
6949 if y
< yy
then Exit
;
6954 function IsSafeTrigger(): Boolean;
6959 if gTriggers
= nil then
6961 for a
:= 0 to High(gTriggers
) do
6962 if Collide(gTriggers
[a
].X
,
6965 gTriggers
[a
].Height
) and
6966 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
6967 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
6968 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
6969 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
6970 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
6975 // Âîçìîæíî, íàæèìàåì êíîïêó:
6976 if Rnd(16) and IsSafeTrigger() then
6979 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
6980 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
6982 ReleaseKey(KEY_LEFT
);
6983 ReleaseKey(KEY_RIGHT
);
6987 // Èäåì âëåâî, åñëè íàäî áûëî:
6988 if GetAIFlag('GOLEFT') <> '' then
6990 RemoveAIFlag('GOLEFT');
6991 if CanRunLeft() then
6995 // Èäåì âïðàâî, åñëè íàäî áûëî:
6996 if GetAIFlag('GORIGHT') <> '' then
6998 RemoveAIFlag('GORIGHT');
6999 if CanRunRight() then
7003 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7004 if FObj
.X
< -32 then
7007 if FObj
.X
+32 > gMapInfo
.Width
then
7010 // Ïðûãàåì, åñëè íàäî áûëî:
7011 if GetAIFlag('NEEDJUMP') <> '' then
7014 RemoveAIFlag('NEEDJUMP');
7017 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7018 if GetAIFlag('NEEDSEEUP') <> '' then
7021 ReleaseKey(KEY_DOWN
);
7022 PressKey(KEY_UP
, 20);
7023 RemoveAIFlag('NEEDSEEUP');
7026 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7027 if GetAIFlag('NEEDSEEDOWN') <> '' then
7030 ReleaseKey(KEY_DOWN
);
7031 PressKey(KEY_DOWN
, 20);
7032 RemoveAIFlag('NEEDSEEDOWN');
7035 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7036 if GetAIFlag('GOINHOLE') <> '' then
7037 if not OnGround() then
7039 ReleaseKey(KEY_LEFT
);
7040 ReleaseKey(KEY_RIGHT
);
7041 RemoveAIFlag('GOINHOLE');
7042 SetAIFlag('FALLINHOLE', '1');
7045 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7046 if GetAIFlag('FALLINHOLE') <> '' then
7048 RemoveAIFlag('FALLINHOLE');
7050 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7051 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7052 if GetAIFlag('FALLINHOLE') = '' then
7053 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7059 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7061 CanJumpUp(IfThen(RunDirection() = D_LEFT
, -1, 1)*32) and
7065 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7066 if OnGround() and NearHole() then
7067 if NearDeepHole() then // Åñëè ýòî áåçäíà
7069 0..3: Turn(); // Áåæèì îáðàòíî
7070 4: Jump(); // Ïðûãàåì
7071 5: begin // Ïðûãàåì îáðàòíî
7076 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7077 if GetAIFlag('GOINHOLE') = '' then
7079 0: Turn(); // Íå íóæíî òóäà
7080 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7081 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7082 if BorderHole() then
7083 SetAIFlag('GOINHOLE', '1');
7086 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7087 if (not CanRun()) and OnGround() then
7089 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7090 if CanJumpOver() or OnLadder() then
7092 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7093 if Random(2) = 0 then
7095 if IsSafeTrigger() then
7101 // Îñòàëîñü ìàëî âîçäóõà:
7102 if FAir
< 36 * 2 then
7105 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7106 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7107 if BodyInAcid(0, 0) then
7111 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7113 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7114 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7117 {function TBot.NeedItem(Item: Byte): Byte;
7122 procedure TBot
.SelectWeapon(Dist
: Integer);
7126 function HaveAmmo(weapon
: Byte): Boolean;
7129 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7130 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7131 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7132 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7133 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7134 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7135 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7136 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7137 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7138 else Result
:= True;
7143 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7145 if Dist
> BOT_LONGDIST
then
7146 begin // Äàëüíèé áîé
7148 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7150 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7154 else //if Dist > BOT_UNSAFEDIST then
7155 begin // Áëèæíèé áîé
7157 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7159 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7166 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7168 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7174 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7176 Result
:= inherited PickItem(ItemType
, force
, remove
);
7178 if Result
then SetAIFlag('SELECTWEAPON', '1');
7181 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7183 Result
:= inherited Heal(value
, Soft
);
7186 function TBot
.Healthy(): Byte;
7188 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7189 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7190 else if (FHealth
> 50) then Result
:= 2
7191 else if (FHealth
> 20) then Result
:= 1
7195 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7197 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7198 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7201 procedure TBot
.OnDamage(Angle
: SmallInt);
7209 if (Angle
= 0) or (Angle
= 180) then
7212 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7213 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7215 pla
:= g_Player_Get(FLastSpawnerUID
);
7216 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7217 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7220 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7221 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7223 mon
:= g_Monsters_Get(FLastSpawnerUID
);
7224 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7225 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7230 SetAIFlag('ATTACKLEFT', '1')
7232 SetAIFlag('ATTACKRIGHT', '1');
7236 function TBot
.RunDirection(): TDirection
;
7238 if Abs(Vel
.X
) >= 1 then
7240 if Vel
.X
> 0 then Result
:= D_RIGHT
else Result
:= D_LEFT
;
7242 Result
:= FDirection
;
7245 function TBot
.GetRnd(a
: Byte): Boolean;
7247 if a
= 0 then Result
:= False
7248 else if a
= 255 then Result
:= True
7249 else Result
:= Random(256) > 255-a
;
7252 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7254 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7257 procedure TBot
.SaveState(var Mem
: TBinMemoryWriter
);
7263 inherited SaveState(Mem
);
7265 // Âûáðàííîå îðóæèå:
7266 Mem
.WriteByte(FSelectedWeapon
);
7268 Mem
.WriteWord(FTargetUID
);
7269 // Âðåìÿ ïîòåðè öåëè:
7270 Mem
.WriteDWORD(FLastVisible
);
7271 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7272 dw
:= Length(FAIFlags
);
7275 for i
:= 0 to Integer(dw
)-1 do
7277 Mem
.WriteString(FAIFlags
[i
].Name
, 20);
7278 Mem
.WriteString(FAIFlags
[i
].Value
, 20);
7280 // Íàñòðîéêè ñëîæíîñòè:
7282 Mem
.WriteMemory(p
, SizeOf(TDifficult
));
7285 procedure TBot
.LoadState(var Mem
: TBinMemoryReader
);
7291 inherited LoadState(Mem
);
7293 // Âûáðàííîå îðóæèå:
7294 Mem
.ReadByte(FSelectedWeapon
);
7296 Mem
.ReadWord(FTargetUID
);
7297 // Âðåìÿ ïîòåðè öåëè:
7298 Mem
.ReadDWORD(FLastVisible
);
7299 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7301 SetLength(FAIFlags
, dw
);
7303 for i
:= 0 to Integer(dw
)-1 do
7305 Mem
.ReadString(FAIFlags
[i
].Name
);
7306 Mem
.ReadString(FAIFlags
[i
].Value
);
7308 // Íàñòðîéêè ñëîæíîñòè:
7309 Mem
.ReadMemory(p
, dw
);
7310 if dw
<> SizeOf(TDifficult
) then
7312 raise EBinSizeError
.Create('TBot.LoadState: Wrong FDifficult Size');
7314 FDifficult
:= TDifficult(p
^);