1 (* Copyright (C) DooM 2D:Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
22 e_graphics
, g_playermodel
, g_basic
, g_textures
,
23 g_weapons
, g_phys
, g_sound
, g_saveload
, MAPSTRUCT
,
56 AmmoLimits
: Array [0..1] of Array [A_BULLETS
..A_HIGH
] of Word =
57 ((200, 50, 50, 300, 100),
58 (400, 100, 100, 600, 200));
79 ANGLE_NONE
= Low(SmallInt);
81 CORPSE_STATE_REMOVEME
= 0;
82 CORPSE_STATE_NORMAL
= 1;
83 CORPSE_STATE_MESS
= 2;
85 PLAYER_RECT
: TRectWH
= (X
:15; Y
:12; Width
:34; Height
:52);
86 PLAYER_RECT_CX
= 15+(34 div 2);
87 PLAYER_RECT_CY
= 12+(52 div 2);
88 PLAYER_CORPSERECT
: TRectWH
= (X
:15; Y
:48; Width
:34; Height
:16);
91 PLAYER_HP_LIMIT
= 200;
93 PLAYER_AP_LIMIT
= 200;
96 PLAYER1_DEF_COLOR
: TRGB
= (R
:64; G
:175; B
:48);
97 PLAYER2_DEF_COLOR
: TRGB
= (R
:96; G
:96; B
:96);
113 TPlayerStatArray
= Array of TPlayerStat
;
115 TPlayerSavedState
= record
123 Ammo
: Array [A_BULLETS
..A_HIGH
] of Word;
124 MaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
125 Weapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
126 Rulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
135 TPlayer
= class (TObject
)
143 FDirection
: TDirection
;
151 FMonsterKills
: Integer;
157 FCanJetpack
: Boolean;
163 FNextWeapDelay
: Byte; // frames
164 FBFGFireCounter
: SmallInt;
165 FLastSpawnerUID
: Word;
169 FSpectatePlayer
: Integer;
170 FFirePainTime
: Integer;
173 FSavedState
: TPlayerSavedState
;
175 FModel
: TPlayerModel
;
178 FActionForce
: Boolean;
179 FActionChanged
: Boolean;
181 FFireAngle
: SmallInt;
183 FShellTimer
: Integer;
185 FSawSound
: TPlayableSound
;
186 FSawSoundIdle
: TPlayableSound
;
187 FSawSoundHit
: TPlayableSound
;
188 FSawSoundSelect
: TPlayableSound
;
189 FJetSoundOn
: TPlayableSound
;
190 FJetSoundOff
: TPlayableSound
;
191 FJetSoundFly
: TPlayableSound
;
195 FJustTeleported
: Boolean;
198 function CollideLevel(XInc
, YInc
: Integer): Boolean;
199 function StayOnStep(XInc
, YInc
: Integer): Boolean;
200 function HeadInLiquid(XInc
, YInc
: Integer): Boolean;
201 function BodyInLiquid(XInc
, YInc
: Integer): Boolean;
202 function BodyInAcid(XInc
, YInc
: Integer): Boolean;
203 function FullInLift(XInc
, YInc
: Integer): Integer;
204 {procedure CollideItem();}
205 procedure FlySmoke(Times
: DWORD
= 1);
206 procedure OnFireFlame(Times
: DWORD
= 1);
207 function GetAmmoByWeapon(Weapon
: Byte): Word;
208 procedure SetAction(Action
: Byte; Force
: Boolean = False);
209 procedure OnDamage(Angle
: SmallInt); virtual;
210 function firediry(): Integer;
212 procedure Run(Direction
: TDirection
);
213 procedure NextWeapon();
214 procedure PrevWeapon();
221 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
222 procedure resetWeaponQueue ();
223 function hasAmmoForWeapon (weapon
: Byte): Boolean;
226 FDamageBuffer
: Integer;
228 FAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
229 FMaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
230 FWeapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
231 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
233 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
234 FReloading
: Array [WP_FIRST
..WP_LAST
] of Word;
235 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
236 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
238 FPreferredTeam
: Byte;
241 FWantsInGame
: Boolean;
245 FActualModelName
: string;
252 constructor Create(); virtual;
253 destructor Destroy(); override;
254 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
255 function GetRespawnPoint(): Byte;
256 procedure PressKey(Key
: Byte; Time
: Word = 1);
257 procedure ReleaseKeys();
258 procedure SetModel(ModelName
: String);
259 procedure SetColor(Color
: TRGB
);
260 procedure SetWeapon(W
: Byte);
261 function IsKeyPressed(K
: Byte): Boolean;
262 function GetKeys(): Byte;
263 function PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean; virtual;
264 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
265 function Collide(Panel
: TPanel
): Boolean; overload
;
266 function Collide(X
, Y
: Integer): Boolean; overload
;
267 procedure SetDirection(Direction
: TDirection
);
268 procedure GetSecret();
269 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
271 procedure Push(vx
, vy
: Integer);
272 procedure ChangeModel(ModelName
: String);
273 procedure SwitchTeam
;
274 procedure ChangeTeam(Team
: Byte);
276 function GetFlag(Flag
: Byte): Boolean;
277 procedure SetFlag(Flag
: Byte);
278 function DropFlag(): Boolean;
279 procedure AllRulez(Health
: Boolean);
280 procedure RestoreHealthArmor();
281 procedure FragCombo();
282 procedure GiveItem(ItemType
: Byte);
283 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
284 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
285 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
286 procedure MakeBloodSimple(Count
: Word);
287 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
288 procedure Reset(Force
: Boolean);
289 procedure Spectate(NoMove
: Boolean = False);
290 procedure SwitchNoClip
;
291 procedure SoftReset();
292 procedure Draw(); virtual;
293 procedure DrawPain();
294 procedure DrawPickup();
295 procedure DrawRulez();
297 procedure DrawBubble();
299 procedure Update(); virtual;
300 procedure RememberState();
301 procedure RecallState();
302 procedure SaveState(var Mem
: TBinMemoryWriter
); virtual;
303 procedure LoadState(var Mem
: TBinMemoryReader
); virtual;
304 procedure PauseSounds(Enable
: Boolean);
305 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
306 procedure DoLerp(Level
: Integer = 2);
307 procedure SetLerp(XTo
, YTo
: Integer);
308 procedure QueueWeaponSwitch(Weapon
: Byte);
309 procedure RealizeCurrentWeapon();
311 procedure JetpackOff
;
312 procedure CatchFire(Attacker
: Word);
314 //WARNING! this does nothing for now, but still call it!
315 procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right!
317 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
319 property Name
: String read FName write FName
;
320 property Model
: TPlayerModel read FModel
;
321 property Health
: Integer read FHealth write FHealth
;
322 property Lives
: Byte read FLives write FLives
;
323 property Armor
: Integer read FArmor write FArmor
;
324 property Air
: Integer read FAir write FAir
;
325 property JetFuel
: Integer read FJetFuel write FJetFuel
;
326 property Frags
: Integer read FFrags write FFrags
;
327 property Death
: Integer read FDeath write FDeath
;
328 property Kills
: Integer read FKills write FKills
;
329 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
330 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
331 property Secrets
: Integer read FSecrets
;
332 property GodMode
: Boolean read FGodMode write FGodMode
;
333 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
334 property NoReload
: Boolean read FNoReload write FNoReload
;
335 property Live
: Boolean read FLive write FLive
;
336 property Flag
: Byte read FFlag
;
337 property Team
: Byte read FTeam write FTeam
;
338 property Direction
: TDirection read FDirection
;
339 property GameX
: Integer read FObj
.X write FObj
.X
;
340 property GameY
: Integer read FObj
.Y write FObj
.Y
;
341 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
342 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
343 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
344 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
345 property Vel
: TPoint2i read FObj
.Vel
;
346 property Obj
: TObj read FObj
;
347 property IncCam
: Integer read FIncCam write FIncCam
;
348 property UID
: Word read FUID write FUID
;
349 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
350 property NetTime
: LongWord read FNetTime write FNetTime
;
360 WeaponPrior
: Array [WP_FIRST
..WP_LAST
] of Byte;
361 CloseWeaponPrior
: Array [WP_FIRST
..WP_LAST
] of Byte;
362 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
370 TBot
= class (TPlayer
)
372 FSelectedWeapon
: Byte;
375 FAIFlags
: Array of TAIFlag
;
376 FDifficult
: TDifficult
;
378 function GetRnd(a
: Byte): Boolean;
379 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
380 function RunDirection(): TDirection
;
381 function FullInStep(XInc
, YInc
: Integer): Boolean;
382 //function NeedItem(Item: Byte): Byte;
383 procedure SelectWeapon(Dist
: Integer);
384 procedure SetAIFlag(aName
, fValue
: String20
);
385 function GetAIFlag(aName
: String20
): String20
;
386 procedure RemoveAIFlag(aName
: String20
);
387 function Healthy(): Byte;
388 procedure UpdateMove();
389 procedure UpdateCombat();
390 function KeyPressed(Key
: Word): Boolean;
391 procedure ReleaseKey(Key
: Byte);
392 function TargetOnScreen(TX
, TY
: Integer): Boolean;
393 procedure OnDamage(Angle
: SmallInt); override;
396 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
397 constructor Create(); override;
398 destructor Destroy(); override;
399 procedure Draw(); override;
400 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
401 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
402 procedure Update(); override;
403 procedure SaveState(var Mem
: TBinMemoryWriter
); override;
404 procedure LoadState(var Mem
: TBinMemoryReader
); override;
415 procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right!
428 procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right!
431 TCorpse
= class (TObject
)
439 FAnimation
: TAnimation
;
440 FAnimationMask
: TAnimation
;
443 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
444 destructor Destroy(); override;
445 procedure Damage(Value
: Word; vx
, vy
: Integer);
448 procedure SaveState(var Mem
: TBinMemoryWriter
);
449 procedure LoadState(var Mem
: TBinMemoryReader
);
451 procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right!
453 property Obj
: TObj read FObj
;
454 property State
: Byte read FState
;
455 property Mess
: Boolean read FMess
;
458 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
464 gPlayers
: Array of TPlayer
;
465 gCorpses
: Array of TCorpse
;
466 gGibs
: Array of TGib
;
467 gShells
: Array of TShell
;
468 gTeamStat
: TTeamStat
;
469 gFly
: Boolean = False;
470 gAimLine
: Boolean = False;
471 gChatBubble
: Byte = 0;
475 MAX_RUNVEL
: Integer = 8;
476 VEL_JUMP
: Integer = 10;
477 SHELL_TIMEOUT
: Cardinal = 60000;
479 function Lerp(X
, Y
, Factor
: Integer): Integer;
481 procedure g_Gibs_SetMax(Count
: Word);
482 function g_Gibs_GetMax(): Word;
483 procedure g_Corpses_SetMax(Count
: Word);
484 function g_Corpses_GetMax(): Word;
485 procedure g_Shells_SetMax(Count
: Word);
486 function g_Shells_GetMax(): Word;
488 procedure g_Player_Init();
489 procedure g_Player_Free();
490 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
491 function g_Player_CreateFromState(var Mem
: TBinMemoryReader
): Word;
492 procedure g_Player_Remove(UID
: Word);
493 procedure g_Player_ResetTeams();
494 procedure g_Player_UpdateAll();
495 procedure g_Player_DrawAll();
496 procedure g_Player_DrawDebug(p
: TPlayer
);
497 procedure g_Player_DrawHealth();
498 procedure g_Player_RememberAll();
499 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
500 function g_Player_Get(UID
: Word): TPlayer
;
501 function g_Player_GetCount(): Byte;
502 function g_Player_GetStats(): TPlayerStatArray
;
503 function g_Player_ValidName(Name
: String): Boolean;
504 procedure g_Player_CreateCorpse(Player
: TPlayer
);
505 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
506 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
507 procedure g_Player_UpdatePhysicalObjects();
508 procedure g_Player_DrawCorpses();
509 procedure g_Player_DrawShells();
510 procedure g_Player_RemoveAllCorpses();
511 procedure g_Player_Corpses_SaveState(var Mem
: TBinMemoryWriter
);
512 procedure g_Player_Corpses_LoadState(var Mem
: TBinMemoryReader
);
513 procedure g_Bot_Add(Team
, Difficult
: Byte);
514 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1);
515 procedure g_Bot_MixNames();
516 procedure g_Bot_RemoveAll();
521 e_log
, g_map
, g_items
, g_console
, SysUtils
, g_gfx
, Math
,
522 g_options
, g_triggers
, g_menu
, MAPDEF
, g_game
,
523 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
, g_net
, g_netmsg
;
533 diag_precision
: Byte;
537 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
538 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
539 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
543 TIME_RESPAWN1
= 1500;
544 TIME_RESPAWN2
= 2000;
545 TIME_RESPAWN3
= 3000;
548 JET_MAX
= 540; // ~30 sec
549 PLAYER_SUIT_TIME
= 30000;
550 PLAYER_INVUL_TIME
= 30000;
551 PLAYER_INVIS_TIME
= 35000;
552 FRAG_COMBO_TIME
= 3000;
556 ANGLE_RIGHTDOWN
= -35;
558 ANGLE_LEFTDOWN
= -145;
559 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
560 WEAPONPOINT
: Array [TDirection
] of TPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
563 BOT_UNSAFEDIST
= 128;
564 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
566 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
567 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
568 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
569 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
570 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
571 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
572 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
573 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
574 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
575 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
576 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
577 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
578 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
579 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
580 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
581 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
582 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
583 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
584 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
585 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
586 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
587 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
588 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
589 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
590 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
591 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
593 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
594 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
596 BOTNAMES_FILENAME
= 'botnames.txt';
597 BOTLIST_FILENAME
= 'botlist.txt';
601 MaxCorpses
: Word = 20;
602 MaxShells
: Word = 300;
603 CurrentGib
: Integer = 0;
604 CurrentShell
: Integer = 0;
605 BotNames
: Array of String;
606 BotList
: Array of TBotProfile
;
609 procedure TGib
.positionChanged (); begin end;
610 procedure TShell
.positionChanged (); begin end;
613 function Lerp(X
, Y
, Factor
: Integer): Integer;
615 Result
:= X
+ ((Y
- X
) div Factor
);
618 function SameTeam(UID1
, UID2
: Word): Boolean;
622 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
623 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
625 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
627 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
628 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
630 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
633 procedure g_Gibs_SetMax(Count
: Word);
636 SetLength(gGibs
, Count
);
638 if CurrentGib
>= Count
then
642 function g_Gibs_GetMax(): Word;
647 procedure g_Shells_SetMax(Count
: Word);
650 SetLength(gShells
, Count
);
652 if CurrentShell
>= Count
then
656 function g_Shells_GetMax(): Word;
662 procedure g_Corpses_SetMax(Count
: Word);
665 SetLength(gCorpses
, Count
);
668 function g_Corpses_GetMax(): Word;
670 Result
:= MaxCorpses
;
673 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
683 // Åñòü ëè ìåñòî â gPlayers:
684 if gPlayers
<> nil then
685 for a
:= 0 to High(gPlayers
) do
686 if gPlayers
[a
] = nil then
692 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
695 SetLength(gPlayers
, Length(gPlayers
)+1);
699 // Ñîçäàåì îáúåêò èãðîêà:
701 gPlayers
[a
] := TBot
.Create()
703 gPlayers
[a
] := TPlayer
.Create();
706 gPlayers
[a
].FActualModelName
:= ModelName
;
707 gPlayers
[a
].SetModel(ModelName
);
709 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
710 if gPlayers
[a
].FModel
= nil then
714 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
718 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
719 if Random(2) = 0 then
723 gPlayers
[a
].FPreferredTeam
:= Team
;
725 case gGameSettings
.GameMode
of
726 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
728 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
730 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
733 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
734 gPlayers
[a
].FColor
:= Color
;
735 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
736 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
738 gPlayers
[a
].FModel
.Color
:= Color
;
740 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
741 gPlayers
[a
].FLive
:= False;
743 Result
:= gPlayers
[a
].FUID
;
746 function g_Player_CreateFromState(var Mem
: TBinMemoryReader
): Word;
759 if sig
<> PLAYER_SIGNATURE
then // 'PLYR'
761 raise EBinSizeError
.Create('g_Player_CreateFromState: Wrong Player Signature');
765 Mem
.ReadBoolean(Bot
);
770 // Åñòü ëè ìåñòî â gPlayers:
771 if gPlayers
<> nil then
772 for a
:= 0 to High(gPlayers
) do
773 if gPlayers
[a
] = nil then
779 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
782 SetLength(gPlayers
, Length(gPlayers
)+1);
786 // Ñîçäàåì îáúåêò èãðîêà:
788 gPlayers
[a
] := TBot
.Create()
790 gPlayers
[a
] := TPlayer
.Create();
791 gPlayers
[a
].FIamBot
:= Bot
;
792 gPlayers
[a
].FPhysics
:= True;
795 Mem
.ReadWord(gPlayers
[a
].FUID
);
797 Mem
.ReadString(gPlayers
[a
].FName
);
799 Mem
.ReadByte(gPlayers
[a
].FTeam
);
800 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
802 Mem
.ReadBoolean(gPlayers
[a
].FLive
);
803 // Èçðàñõîäîâàë ëè âñå æèçíè:
804 Mem
.ReadBoolean(gPlayers
[a
].FNoRespawn
);
808 gPlayers
[a
].FDirection
:= D_LEFT
810 gPlayers
[a
].FDirection
:= D_RIGHT
;
812 Mem
.ReadInt(gPlayers
[a
].FHealth
);
814 Mem
.ReadByte(gPlayers
[a
].FLives
);
816 Mem
.ReadInt(gPlayers
[a
].FArmor
);
818 Mem
.ReadInt(gPlayers
[a
].FAir
);
820 Mem
.ReadInt(gPlayers
[a
].FJetFuel
);
822 Mem
.ReadInt(gPlayers
[a
].FPain
);
824 Mem
.ReadInt(gPlayers
[a
].FKills
);
826 Mem
.ReadInt(gPlayers
[a
].FMonsterKills
);
828 Mem
.ReadInt(gPlayers
[a
].FFrags
);
830 Mem
.ReadByte(gPlayers
[a
].FFragCombo
);
831 // Âðåìÿ ïîñëåäíåãî ôðàãà:
832 Mem
.ReadDWORD(gPlayers
[a
].FLastFrag
);
834 Mem
.ReadInt(gPlayers
[a
].FDeath
);
836 Mem
.ReadByte(gPlayers
[a
].FFlag
);
838 Mem
.ReadInt(gPlayers
[a
].FSecrets
);
840 Mem
.ReadByte(gPlayers
[a
].FCurrWeap
);
841 // Ñëåäóþùåå æåëàåìîå îðóæèå:
842 Mem
.ReadWord(gPlayers
[a
].FNextWeap
);
844 Mem
.ReadByte(gPlayers
[a
].FNextWeapDelay
);
845 // Âðåìÿ çàðÿäêè BFG:
846 Mem
.ReadSmallInt(gPlayers
[a
].FBFGFireCounter
);
848 Mem
.ReadInt(gPlayers
[a
].FDamageBuffer
);
849 // Ïîñëåäíèé óäàðèâøèé:
850 Mem
.ReadWord(gPlayers
[a
].FLastSpawnerUID
);
851 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
852 Mem
.ReadByte(gPlayers
[a
].FLastHit
);
854 Obj_LoadState(@gPlayers
[a
].FObj
, Mem
);
855 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
856 for i
:= A_BULLETS
to A_HIGH
do
857 Mem
.ReadWord(gPlayers
[a
].FAmmo
[i
]);
858 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
859 for i
:= A_BULLETS
to A_HIGH
do
860 Mem
.ReadWord(gPlayers
[a
].FMaxAmmo
[i
]);
862 for i
:= WP_FIRST
to WP_LAST
do
863 Mem
.ReadBoolean(gPlayers
[a
].FWeapon
[i
]);
864 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
865 for i
:= WP_FIRST
to WP_LAST
do
866 Mem
.ReadWord(gPlayers
[a
].FReloading
[i
]);
870 Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
871 // Íàëè÷èå êðàñíîãî êëþ÷à:
874 Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
875 // Íàëè÷èå çåëåíîãî êëþ÷à:
878 Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
879 // Íàëè÷èå ñèíåãî êëþ÷à:
882 Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
886 Include(gPlayers
[a
].FRulez
, R_BERSERK
);
887 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
888 for i
:= MR_SUIT
to MR_MAX
do
889 Mem
.ReadDWORD(gPlayers
[a
].FMegaRulez
[i
]);
890 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
891 for i
:= T_RESPAWN
to T_FLAGCAP
do
892 Mem
.ReadDWORD(gPlayers
[a
].FTime
[i
]);
895 Mem
.ReadString(gPlayers
[a
].FActualModelName
);
897 Mem
.ReadByte(gPlayers
[a
].FColor
.R
);
898 Mem
.ReadByte(gPlayers
[a
].FColor
.G
);
899 Mem
.ReadByte(gPlayers
[a
].FColor
.B
);
900 // Îáíîâëÿåì ìîäåëü èãðîêà:
901 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
903 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
904 if gPlayers
[a
].FModel
= nil then
908 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
912 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
913 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
914 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
916 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
918 Result
:= gPlayers
[a
].FUID
;
921 procedure g_Player_ResetTeams();
925 if g_Game_IsClient
then
927 if gPlayers
= nil then
929 for a
:= Low(gPlayers
) to High(gPlayers
) do
930 if gPlayers
[a
] <> nil then
931 case gGameSettings
.GameMode
of
933 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
935 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
936 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
937 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
940 gPlayers
[a
].ChangeTeam(TEAM_RED
)
942 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
945 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
949 procedure g_Bot_Add(Team
, Difficult
: Byte);
952 _name
, _model
: String;
955 if not g_Game_IsServer
then Exit
;
957 // Ñïèñîê íàçâàíèé ìîäåëåé:
958 m
:= g_PlayerModel_GetNames();
963 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
964 Team
:= TEAM_COOP
// COOP
966 if gGameSettings
.GameMode
= GM_DM
then
967 Team
:= TEAM_NONE
// DM
969 if Team
= TEAM_NONE
then // CTF / TDM
971 // Àâòîáàëàíñ êîìàíä:
975 for a
:= 0 to High(gPlayers
) do
976 if gPlayers
[a
] <> nil then
978 if gPlayers
[a
].Team
= TEAM_RED
then
981 if gPlayers
[a
].Team
= TEAM_BLUE
then
991 if Random(2) = 0 then
997 // Âûáèðàåì áîòó èìÿ:
999 if BotNames
<> nil then
1000 for a
:= 0 to High(BotNames
) do
1001 if g_Player_ValidName(BotNames
[a
]) then
1003 _name
:= BotNames
[a
];
1007 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
1010 _name
:= Format('DFBOT%.2d', [Random(100)]);
1011 until g_Player_ValidName(_name
);
1013 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1014 _model
:= m
[Random(Length(m
))];
1017 with g_Player_Get(g_Player_Create(_model
,
1018 _RGB(Min(Random(9)*32, 255),
1019 Min(Random(9)*32, 255),
1020 Min(Random(9)*32, 255)),
1021 Team
, True)) as TBot
do
1026 1: FDifficult
:= DIFFICULT_EASY
;
1027 2: FDifficult
:= DIFFICULT_MEDIUM
;
1028 else FDifficult
:= DIFFICULT_HARD
;
1031 for a
:= WP_FIRST
to WP_LAST
do
1033 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1034 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1035 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1038 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1040 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1041 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1046 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1);
1049 _name
, _model
: String;
1052 if not g_Game_IsServer
then Exit
;
1054 // Ñïèñîê íàçâàíèé ìîäåëåé:
1055 m
:= g_PlayerModel_GetNames();
1060 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1061 Team
:= TEAM_COOP
// COOP
1063 if gGameSettings
.GameMode
= GM_DM
then
1064 Team
:= TEAM_NONE
// DM
1066 if Team
= TEAM_NONE
then
1067 Team
:= BotList
[num
].team
; // CTF / TDM
1069 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1070 lName
:= AnsiLowerCase(lName
);
1071 if (num
< 0) or (num
> Length(BotList
)-1) then
1073 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1074 for a
:= 0 to High(BotList
) do
1075 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1084 _name
:= BotList
[num
].name
;
1085 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1086 if not g_Player_ValidName(_name
) then
1088 _name
:= Format('DFBOT%.2d', [Random(100)]);
1089 until g_Player_ValidName(_name
);
1092 _model
:= BotList
[num
].model
;
1093 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1094 if not InSArray(_model
, m
) then
1095 _model
:= m
[Random(Length(m
))];
1098 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1102 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1103 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1104 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1105 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1106 FDifficult
.Cover
:= BotList
[num
].cover
;
1107 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1109 for a
:= WP_FIRST
to WP_LAST
do
1111 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1112 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1113 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1116 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1118 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1122 procedure g_Bot_RemoveAll();
1126 if not g_Game_IsServer
then Exit
;
1127 if gPlayers
= nil then Exit
;
1129 for a
:= 0 to High(gPlayers
) do
1130 if gPlayers
[a
] <> nil then
1131 if gPlayers
[a
] is TBot
then
1133 gPlayers
[a
].Lives
:= 0;
1134 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1135 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1136 g_Player_Remove(gPlayers
[a
].FUID
);
1142 procedure g_Bot_MixNames();
1147 if BotNames
<> nil then
1148 for a
:= 0 to High(BotNames
) do
1150 b
:= Random(Length(BotNames
));
1152 Botnames
[a
] := BotNames
[b
];
1157 procedure g_Player_Remove(UID
: Word);
1161 if gPlayers
= nil then Exit
;
1163 if g_Game_IsServer
and g_Game_IsNet
then
1164 MH_SEND_PlayerDelete(UID
);
1166 for i
:= 0 to High(gPlayers
) do
1167 if gPlayers
[i
] <> nil then
1168 if gPlayers
[i
].FUID
= UID
then
1170 if gPlayers
[i
] is TPlayer
then
1171 TPlayer(gPlayers
[i
]).Free()
1173 TBot(gPlayers
[i
]).Free();
1179 procedure g_Player_Init();
1189 if not FileExists(DataDir
+ BOTNAMES_FILENAME
) then
1192 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1193 AssignFile(F
, DataDir
+ BOTNAMES_FILENAME
);
1204 SetLength(BotNames
, Length(BotNames
)+1);
1205 BotNames
[High(BotNames
)] := s
;
1213 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1214 config
:= TConfig
.CreateFile(DataDir
+ BOTLIST_FILENAME
);
1218 while config
.SectionExists(IntToStr(a
)) do
1220 SetLength(BotList
, Length(BotList
)+1);
1222 with BotList
[High(BotList
)] do
1225 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1227 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1229 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1234 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1235 color
.R
:= StrToIntDef(sa
[0], 0);
1236 color
.G
:= StrToIntDef(sa
[1], 0);
1237 color
.B
:= StrToIntDef(sa
[2], 0);
1238 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1239 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1240 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1241 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1242 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1243 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1244 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1245 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1246 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1247 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1248 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1249 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1250 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1251 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1252 if Length(sa
) = 10 then
1254 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1255 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1256 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1257 if Length(sa
) = 10 then
1259 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1261 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1262 if Length(sa) = 10 then
1264 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1273 procedure g_Player_Free();
1277 if gPlayers
<> nil then
1279 for i
:= 0 to High(gPlayers
) do
1280 if gPlayers
[i
] <> nil then
1282 if gPlayers
[i
] is TPlayer
then
1283 TPlayer(gPlayers
[i
]).Free()
1285 TBot(gPlayers
[i
]).Free();
1296 procedure g_Player_UpdateAll();
1300 if gPlayers
= nil then Exit
;
1302 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1303 for i
:= 0 to High(gPlayers
) do
1305 if gPlayers
[i
] <> nil then
1307 if gPlayers
[i
] is TPlayer
then
1309 gPlayers
[i
].Update();
1310 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1314 // bot updates weapons in `UpdateCombat()`
1315 TBot(gPlayers
[i
]).Update();
1319 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1322 procedure g_Player_DrawAll();
1326 if gPlayers
= nil then Exit
;
1328 for i
:= 0 to High(gPlayers
) do
1329 if gPlayers
[i
] <> nil then
1330 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1331 else TBot(gPlayers
[i
]).Draw();
1334 procedure g_Player_DrawDebug(p
: TPlayer
);
1338 if p
= nil then Exit
;
1339 if (@p
.FObj
) = nil then Exit
;
1341 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1343 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1344 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1345 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1346 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1347 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1348 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1351 procedure g_Player_DrawHealth();
1356 if gPlayers
= nil then Exit
;
1357 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1359 for i
:= 0 to High(gPlayers
) do
1360 if gPlayers
[i
] <> nil then
1362 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1363 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1364 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1365 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1366 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1367 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1371 function g_Player_Get(UID
: Word): TPlayer
;
1377 if gPlayers
= nil then
1380 for a
:= 0 to High(gPlayers
) do
1381 if gPlayers
[a
] <> nil then
1382 if gPlayers
[a
].FUID
= UID
then
1384 Result
:= gPlayers
[a
];
1389 function g_Player_GetCount(): Byte;
1395 if gPlayers
= nil then
1398 for a
:= 0 to High(gPlayers
) do
1399 if gPlayers
[a
] <> nil then
1400 Result
:= Result
+ 1;
1403 function g_Player_GetStats(): TPlayerStatArray
;
1409 if gPlayers
= nil then Exit
;
1411 for a
:= 0 to High(gPlayers
) do
1412 if gPlayers
[a
] <> nil then
1414 SetLength(Result
, Length(Result
)+1);
1415 with Result
[High(Result
)] do
1417 Ping
:= gPlayers
[a
].FPing
;
1418 Loss
:= gPlayers
[a
].FLoss
;
1419 Name
:= gPlayers
[a
].FName
;
1420 Team
:= gPlayers
[a
].FTeam
;
1421 Frags
:= gPlayers
[a
].FFrags
;
1422 Deaths
:= gPlayers
[a
].FDeath
;
1423 Kills
:= gPlayers
[a
].FKills
;
1424 Color
:= gPlayers
[a
].FModel
.Color
;
1425 Lives
:= gPlayers
[a
].FLives
;
1426 Spectator
:= gPlayers
[a
].FSpectator
;
1431 procedure g_Player_RememberAll
;
1435 for i
:= Low(gPlayers
) to High(gPlayers
) do
1436 if (gPlayers
[i
] <> nil) and gPlayers
[i
].Live
then
1437 gPlayers
[i
].RememberState
;
1440 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1444 gTeamStat
[TEAM_RED
].Goals
:= 0;
1445 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1447 if gPlayers
<> nil then
1448 for i
:= 0 to High(gPlayers
) do
1449 if gPlayers
[i
] <> nil then
1451 gPlayers
[i
].Reset(Force
);
1453 if gPlayers
[i
] is TPlayer
then
1455 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1456 gPlayers
[i
].Respawn(Silent
)
1458 gPlayers
[i
].Spectate();
1461 TBot(gPlayers
[i
]).Respawn(Silent
);
1465 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1472 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1477 if (FHealth
>= -50) or (gGibsCount
= 0) then
1479 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1483 for find_id
:= 0 to High(gCorpses
) do
1484 if gCorpses
[find_id
] = nil then
1491 find_id
:= Random(Length(gCorpses
));
1493 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1494 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1495 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1496 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1499 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1500 FObj
.Y
+ PLAYER_RECT_CY
,
1501 FModel
.Name
, FModel
.Color
);
1505 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1509 if (gShells
= nil) or (Length(gShells
) = 0) then
1512 with gShells
[CurrentShell
] do
1518 if T
= SHELL_BULLET
then
1520 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1524 Obj
.Rect
.Width
:= 4;
1525 Obj
.Rect
.Height
:= 2;
1529 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1533 Obj
.Rect
.Width
:= 7;
1534 Obj
.Rect
.Height
:= 3;
1540 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1541 positionChanged(); // this updates spatial accelerators
1542 RAngle
:= Random(360);
1543 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1545 if CurrentShell
>= High(gShells
) then
1552 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1555 GibsArray
: TGibsArray
;
1557 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1559 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1562 for a
:= 0 to High(GibsArray
) do
1563 with gGibs
[CurrentGib
] do
1566 ID
:= GibsArray
[a
].ID
;
1567 MaskID
:= GibsArray
[a
].MaskID
;
1570 Obj
.Rect
:= GibsArray
[a
].Rect
;
1571 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1572 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1573 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1574 positionChanged(); // this updates spatial accelerators
1575 RAngle
:= Random(360);
1577 if gBloodCount
> 0 then
1578 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1579 Random(48), Random(48), 150, 0, 0);
1581 if CurrentGib
>= High(gGibs
) then
1588 procedure g_Player_UpdatePhysicalObjects();
1594 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1599 if T
= SHELL_BULLET
then
1600 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1602 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1607 if gGibs
<> nil then
1608 for i
:= 0 to High(gGibs
) do
1609 if gGibs
[i
].Live
then
1613 mr
:= g_Obj_Move(@Obj
, True, False, True);
1614 positionChanged(); // this updates spatial accelerators
1616 if WordBool(mr
and MOVE_FALLOUT
) then
1622 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1623 if WordBool(mr
and MOVE_HITWALL
) then
1624 Obj
.Vel
.X
:= -(vel
.X
div 2);
1625 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1626 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1628 if (Obj
.Vel
.X
>= 0) then
1630 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1631 if RAngle
>= 360 then
1632 RAngle
:= RAngle
mod 360;
1633 end else begin // Counter-clockwise
1634 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1636 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1639 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1640 if gTime
mod (GAME_TICK
*3) = 0 then
1641 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1645 if gCorpses
<> nil then
1646 for i
:= 0 to High(gCorpses
) do
1647 if gCorpses
[i
] <> nil then
1648 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1654 gCorpses
[i
].Update();
1657 if gShells
<> nil then
1658 for i
:= 0 to High(gShells
) do
1659 if gShells
[i
].Live
then
1663 mr
:= g_Obj_Move(@Obj
, True, False, True);
1664 positionChanged(); // this updates spatial accelerators
1666 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1672 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1673 if WordBool(mr
and MOVE_HITWALL
) then
1675 Obj
.Vel
.X
:= -(vel
.X
div 2);
1676 if not WordBool(mr
and MOVE_INWATER
) then
1677 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1679 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1681 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1682 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1683 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1685 if RAngle
mod 90 <> 0 then
1686 RAngle
:= (RAngle
div 90) * 90;
1688 else if not WordBool(mr
and MOVE_INWATER
) then
1689 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1692 if (Obj
.Vel
.X
>= 0) then
1694 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1695 if RAngle
>= 360 then
1696 RAngle
:= RAngle
mod 360;
1697 end else begin // Counter-clockwise
1698 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1700 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1705 procedure g_Player_DrawCorpses();
1710 if gGibs
<> nil then
1711 for i
:= 0 to High(gGibs
) do
1712 if gGibs
[i
].Live
then
1715 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1718 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1719 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1721 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1724 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1730 if gCorpses
<> nil then
1731 for i
:= 0 to High(gCorpses
) do
1732 if gCorpses
[i
] <> nil then
1736 procedure g_Player_DrawShells();
1741 if gShells
<> nil then
1742 for i
:= 0 to High(gShells
) do
1743 if gShells
[i
].Live
then
1746 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1752 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1756 procedure g_Player_RemoveAllCorpses();
1762 SetLength(gGibs
, MaxGibs
);
1763 SetLength(gShells
, MaxGibs
);
1767 if gCorpses
<> nil then
1768 for i
:= 0 to High(gCorpses
) do
1772 SetLength(gCorpses
, MaxCorpses
);
1775 procedure g_Player_Corpses_SaveState(var Mem
: TBinMemoryWriter
);
1780 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ:
1782 if gCorpses
<> nil then
1783 for i
:= 0 to High(gCorpses
) do
1784 if gCorpses
[i
] <> nil then
1787 Mem
:= TBinMemoryWriter
.Create((count
+1) * 128);
1789 // Êîëè÷åñòâî òðóïîâ:
1790 Mem
.WriteInt(count
);
1796 for i
:= 0 to High(gCorpses
) do
1797 if gCorpses
[i
] <> nil then
1800 Mem
.WriteString(gCorpses
[i
].FModelName
);
1802 b
:= gCorpses
[i
].Mess
;
1803 Mem
.WriteBoolean(b
);
1804 // Ñîõðàíÿåì äàííûå òðóïà:
1805 gCorpses
[i
].SaveState(Mem
);
1809 procedure g_Player_Corpses_LoadState(var Mem
: TBinMemoryReader
);
1818 g_Player_RemoveAllCorpses();
1820 // Êîëè÷åñòâî òðóïîâ:
1823 if count
> Length(gCorpses
) then
1825 raise EBinSizeError
.Create('g_Player_Corpses_LoadState: Too Many Corpses');
1832 for i
:= 0 to count
-1 do
1835 Mem
.ReadString(str
);
1839 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1840 // Çàãðóæàåì äàííûå òðóïà:
1841 gCorpses
[i
].LoadState(Mem
);
1847 procedure TPlayer
.BFGHit();
1849 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1850 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1851 if g_Game_IsServer
and g_Game_IsNet
then
1852 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1853 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1857 procedure TPlayer
.ChangeModel(ModelName
: string);
1859 locModel
: TPlayerModel
;
1861 locModel
:= g_PlayerModel_Get(ModelName
);
1862 if locModel
= nil then Exit
;
1868 procedure TPlayer
.SetModel(ModelName
: string);
1872 m
:= g_PlayerModel_Get(ModelName
);
1875 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1876 m
:= g_PlayerModel_Get('doomer');
1879 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1884 if FModel
<> nil then
1889 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1890 FModel
.Color
:= FColor
1892 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1893 FModel
.SetWeapon(FCurrWeap
);
1894 FModel
.SetFlag(FFlag
);
1895 SetDirection(FDirection
);
1898 procedure TPlayer
.SetColor(Color
: TRGB
);
1901 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1902 if FModel
<> nil then FModel
.Color
:= Color
;
1905 procedure TPlayer
.SwitchTeam
;
1907 if g_Game_IsClient
then
1909 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
1911 if gGameOn
and FLive
then
1912 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
1914 if FTeam
= TEAM_RED
then
1916 ChangeTeam(TEAM_BLUE
);
1917 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
1918 if g_Game_IsNet
then
1919 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
1923 ChangeTeam(TEAM_RED
);
1924 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
1925 if g_Game_IsNet
then
1926 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
1928 FPreferredTeam
:= FTeam
;
1931 procedure TPlayer
.ChangeTeam(Team
: Byte);
1938 TEAM_RED
, TEAM_BLUE
:
1939 FModel
.Color
:= TEAMCOLOR
[Team
];
1941 FModel
.Color
:= FColor
;
1943 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
1944 MH_SEND_PlayerStats(FUID
);
1948 procedure TPlayer.CollideItem();
1953 if gItems = nil then Exit;
1954 if not FLive then Exit;
1956 for i := 0 to High(gItems) do
1959 if (ItemType <> ITEM_NONE) and Live then
1960 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
1961 PLAYER_RECT.Height, @Obj) then
1963 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
1965 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
1966 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
1967 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
1968 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
1969 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
1971 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
1972 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
1973 (gGameSettings.GameType = GT_SINGLE) and
1974 (g_Player_GetCount() > 1)) then
1975 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
1981 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
1983 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
1984 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
1988 constructor TPlayer
.Create();
1994 FSawSound
:= TPlayableSound
.Create();
1995 FSawSoundIdle
:= TPlayableSound
.Create();
1996 FSawSoundHit
:= TPlayableSound
.Create();
1997 FSawSoundSelect
:= TPlayableSound
.Create();
1998 FJetSoundFly
:= TPlayableSound
.Create();
1999 FJetSoundOn
:= TPlayableSound
.Create();
2000 FJetSoundOff
:= TPlayableSound
.Create();
2002 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2003 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2004 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2005 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2006 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2007 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2008 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2010 FSpectatePlayer
:= -1;
2014 FSavedState
.WaitRecall
:= False;
2020 FActualModelName
:= 'doomer';
2023 FObj
.Rect
:= PLAYER_RECT
;
2025 FBFGFireCounter
:= -1;
2026 FJustTeleported
:= False;
2032 procedure TPlayer
.positionChanged ();
2036 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2040 if (not g_Game_IsClient
) and (not FLive
) then
2045 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2046 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2048 if not g_Game_IsClient
then
2051 if t
= HIT_TRAP
then
2053 // Ëîâóøêà óáèâàåò ñðàçó:
2055 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2057 if t
= HIT_SELF
then
2061 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2064 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2065 FMegaRulez
[MR_SUIT
] := 0;
2066 FMegaRulez
[MR_INVUL
] := 0;
2067 FMegaRulez
[MR_INVIS
] := 0;
2071 // Íî îò îñòàëüíîãî ñïàñàåò:
2072 if FMegaRulez
[MR_INVUL
] >= gTime
then
2079 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2080 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2081 (SpawnerUID
= FUID
) or
2082 (not SameTeam(FUID
, SpawnerUID
)) then
2084 FLastSpawnerUID
:= SpawnerUID
;
2086 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2087 if gBloodCount
> 0 then
2089 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2090 if value
div 4 <= c
then
2091 c
:= c
- (value
div 4)
2095 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2099 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2100 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2103 if t
= HIT_WATER
then
2104 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2105 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2110 Inc(FDamageBuffer
, value
);
2114 FPain
:= FPain
+ value
;
2117 if g_Game_IsServer
and g_Game_IsNet
then
2119 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2120 MH_SEND_PlayerStats(FUID
);
2121 MH_SEND_PlayerPos(False, FUID
);
2125 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2128 if g_Game_IsClient
then
2133 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2135 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2138 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2140 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2144 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2145 MH_SEND_PlayerStats(FUID
);
2148 destructor TPlayer
.Destroy();
2150 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2152 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2156 FSawSoundIdle
.Free();
2157 FSawSoundHit
.Free();
2158 FJetSoundFly
.Free();
2160 FJetSoundOff
.Free();
2166 procedure TPlayer
.DrawBubble();
2168 bubX
, bubY
: Integer;
2171 Rw
, Gw
, Bw
: SmallInt;
2174 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= D_LEFT
, -4, 18);
2175 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2183 1: // simple textual non-bubble
2185 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2186 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2187 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2190 2: // advanced pixel-perfect bubble
2192 if FTeam
= TEAM_RED
then
2195 if FTeam
= TEAM_BLUE
then
2198 3: // colored bubble
2200 Rb
:= FModel
.Color
.R
;
2201 Gb
:= FModel
.Color
.G
;
2202 Bb
:= FModel
.Color
.B
;
2203 Rw
:= Min(Rb
* 2 + 64, 255);
2204 Gw
:= Min(Gb
* 2 + 64, 255);
2205 Bw
:= Min(Bb
* 2 + 64, 255);
2206 if (Abs(Rw
- Rb
) < 32)
2207 or (Abs(Gw
- Gb
) < 32)
2208 or (Abs(Bw
- Bb
) < 32) then
2210 Rb
:= Max(Rw
div 2 - 16, 0);
2211 Gb
:= Max(Gw
div 2 - 16, 0);
2212 Bb
:= Max(Bw
div 2 - 16, 0);
2215 4: // custom textured bubble
2217 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2218 if FDirection
= D_RIGHT
then
2219 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2221 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, M_HORIZONTAL
);
2227 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2228 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2230 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2233 Dot
:= IfThen(FDirection
= D_LEFT
, 14, 5);
2234 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2235 e_DrawLine(1, bubX
+ IfThen(FDirection
= D_LEFT
, Dot
- 1, Dot
+ 1), bubY
+ 13, bubX
+ IfThen(FDirection
= D_LEFT
, Dot
- 1, Dot
+ 1), bubY
+ 15, Rw
, Gw
, Bw
);
2236 e_DrawLine(1, bubX
+ IfThen(FDirection
= D_LEFT
, Dot
- 2, Dot
+ 2), bubY
+ 13, bubX
+ IfThen(FDirection
= D_LEFT
, Dot
- 2, Dot
+ 2), bubY
+ 14, Rw
, Gw
, Bw
);
2237 e_DrawLine(1, bubX
+ IfThen(FDirection
= D_LEFT
, Dot
- 3, Dot
+ 3), bubY
+ 13, bubX
+ IfThen(FDirection
= D_LEFT
, Dot
- 3, Dot
+ 3), bubY
+ 13, Rw
, Gw
, Bw
);
2238 e_DrawLine(1, bubX
+ IfThen(FDirection
= D_LEFT
, Dot
- 3, Dot
+ 3), bubY
+ 14, bubX
+ IfThen(FDirection
= D_LEFT
, Dot
- 1, Dot
+ 1), bubY
+ 16, Rb
, Gb
, Bb
);
2242 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2243 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2244 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2247 procedure TPlayer
.Draw();
2255 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2256 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2258 e_GetTextureSize(ID
, @w
, @h
);
2259 if FDirection
= D_LEFT
then
2260 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2261 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7, 0, True, False)
2263 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2264 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7, 0, True, False);
2267 if FMegaRulez
[MR_INVIS
] > gTime
then
2269 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2270 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2272 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2273 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2277 FModel
.Draw(FObj
.X
, FObj
.Y
, 200)
2279 FModel
.Draw(FObj
.X
, FObj
.Y
);
2282 FModel
.Draw(FObj
.X
, FObj
.Y
, 254);
2285 FModel
.Draw(FObj
.X
, FObj
.Y
);
2288 if g_debug_Frames
then
2290 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2292 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2293 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2297 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2299 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2300 if gAimLine
and Live
and
2301 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2305 procedure TPlayer
.DrawAim();
2307 wx
, wy
, xx
, yy
: Integer;
2311 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= D_LEFT
, 7, -7);
2312 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2321 1: begin // Chainsaw
2328 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2329 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2330 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2331 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2336 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2337 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2338 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2339 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2341 4: begin // Double Shotgun
2344 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2345 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2346 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2347 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2349 5: begin // Chaingun
2352 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2353 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2354 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2355 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2357 6: begin // Rocket Launcher
2360 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2361 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2362 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2363 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2365 7: begin // Plasmagun
2368 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2369 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2370 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2371 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2376 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2377 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2378 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2379 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2381 9: begin // Super Chaingun
2384 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2385 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2386 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2387 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2390 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2391 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2392 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2395 procedure TPlayer
.DrawGUI();
2398 X
, Y
, SY
, a
, p
, m
: Integer;
2402 stat
: TPlayerStatArray
;
2404 X
:= gPlayerScreenSize
.X
;
2405 SY
:= gPlayerScreenSize
.Y
;
2408 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2410 if gGameSettings
.GameMode
= GM_CTF
then
2414 if gGameSettings
.GameMode
= GM_CTF
then
2416 s
:= 'TEXTURE_PLAYER_REDFLAG';
2417 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2418 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2419 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2420 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2421 if g_Texture_Get(s
, ID
) then
2422 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2425 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2426 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2427 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2429 if gGameSettings
.GameMode
= GM_CTF
then
2431 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2432 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2433 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2434 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2435 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2436 if g_Texture_Get(s
, ID
) then
2437 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2440 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2441 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2442 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2445 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2446 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2449 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2450 e_Draw(ID
, X
+2, Y
, 0, True, False);
2452 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2456 s
:= IntToStr(Frags
);
2457 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2458 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2463 stat
:= g_Player_GetStats();
2468 for a
:= 0 to High(stat
) do
2469 if stat
[a
].Name
<> Name
then
2471 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2472 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2476 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2477 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2478 s
:= s
+IntToStr(Abs(Frags
-m
));
2480 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2481 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2484 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2486 s
:= IntToStr(Lives
);
2487 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2488 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2492 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2493 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2495 if R_BERSERK
in FRulez
then
2496 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2498 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2500 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2501 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2503 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2504 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2505 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2507 s
:= IntToStr(FArmor
);
2508 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2509 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2511 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2517 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2522 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2524 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2525 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2526 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2527 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2528 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2529 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2530 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2531 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2532 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2535 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2536 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2537 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2539 if R_KEY_RED
in FRulez
then
2540 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2542 if R_KEY_GREEN
in FRulez
then
2543 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2545 if R_KEY_BLUE
in FRulez
then
2546 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2548 if FJetFuel
> 0 then
2550 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2551 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2552 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2553 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2554 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2555 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2559 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2560 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2561 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2564 if gShowPing
and g_Game_IsClient
then
2566 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2567 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2573 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2574 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2575 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2578 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2579 s
:= _lc
[I_PLAYER_SPECT4
];
2580 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2581 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2582 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2588 procedure TPlayer
.DrawRulez();
2592 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2593 if FMegaRulez
[MR_INVUL
] >= gTime
then
2595 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2596 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2601 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2602 191, 191, 191, 0, B_INVERT
);
2605 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2606 if FMegaRulez
[MR_SUIT
] >= gTime
then
2608 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2609 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2614 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2615 0, 96, 0, 200, B_NONE
);
2618 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2619 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2621 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2622 255, 0, 0, 200, B_NONE
);
2626 procedure TPlayer
.DrawPain();
2630 if FPain
= 0 then Exit
;
2634 if a
< 15 then h
:= 0
2635 else if a
< 35 then h
:= 1
2636 else if a
< 55 then h
:= 2
2637 else if a
< 75 then h
:= 3
2638 else if a
< 95 then h
:= 4
2641 //if a > 255 then a := 255;
2643 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2644 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2647 procedure TPlayer
.DrawPickup();
2651 if FPickup
= 0 then Exit
;
2655 if a
< 15 then h
:= 1
2656 else if a
< 35 then h
:= 2
2657 else if a
< 55 then h
:= 3
2658 else if a
< 75 then h
:= 4
2661 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2664 procedure TPlayer
.Fire();
2666 f
, DidFire
: Boolean;
2667 wx
, wy
, xd
, yd
: Integer;
2670 if g_Game_IsClient
then Exit
;
2671 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2672 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2680 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2685 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2686 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2687 xd
:= wx
+IfThen(FDirection
= D_LEFT
, -30, 30);
2688 yd
:= wy
+firediry();
2693 if R_BERSERK
in FRulez
then
2695 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2696 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2697 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2700 locobj
.rect
.Width
:= 39;
2701 locobj
.rect
.Height
:= 52;
2702 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2703 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2704 locobj
.Accel
.X
:= xd
-wx
;
2705 locobj
.Accel
.y
:= yd
-wy
;
2707 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2708 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2710 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2714 FPain
:= min(FPain
+ 25, 50);
2715 end else g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2718 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2723 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2724 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2726 FSawSoundSelect
.Stop();
2728 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2730 else if not FSawSoundHit
.IsPlaying() then
2732 FSawSoundSelect
.Stop();
2733 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2736 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2742 if FAmmo
[A_BULLETS
] > 0 then
2744 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2745 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2746 Dec(FAmmo
[A_BULLETS
]);
2747 FFireAngle
:= FAngle
;
2750 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2751 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2755 if FAmmo
[A_SHELLS
] > 0 then
2757 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2758 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
2759 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2760 Dec(FAmmo
[A_SHELLS
]);
2761 FFireAngle
:= FAngle
;
2765 FShellType
:= SHELL_SHELL
;
2769 if FAmmo
[A_SHELLS
] >= 2 then
2771 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
2772 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2773 Dec(FAmmo
[A_SHELLS
], 2);
2774 FFireAngle
:= FAngle
;
2778 FShellType
:= SHELL_DBLSHELL
;
2782 if FAmmo
[A_BULLETS
] > 0 then
2784 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
2785 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
2786 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2787 Dec(FAmmo
[A_BULLETS
]);
2788 FFireAngle
:= FAngle
;
2791 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2792 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2795 WEAPON_ROCKETLAUNCHER
:
2796 if FAmmo
[A_ROCKETS
] > 0 then
2798 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
2799 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2800 Dec(FAmmo
[A_ROCKETS
]);
2801 FFireAngle
:= FAngle
;
2807 if FAmmo
[A_CELLS
] > 0 then
2809 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
2810 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2811 Dec(FAmmo
[A_CELLS
]);
2812 FFireAngle
:= FAngle
;
2818 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
2820 FBFGFireCounter
:= 17;
2821 if not FNoReload
then
2822 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
2823 Dec(FAmmo
[A_CELLS
], 40);
2827 WEAPON_SUPERPULEMET
:
2828 if FAmmo
[A_SHELLS
] > 0 then
2830 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2831 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
2832 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2833 Dec(FAmmo
[A_SHELLS
]);
2834 FFireAngle
:= FAngle
;
2837 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2838 GameVelX
, GameVelY
-2, SHELL_SHELL
);
2841 WEAPON_FLAMETHROWER
:
2842 if FAmmo
[A_FUEL
] > 0 then
2844 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
2845 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2847 FFireAngle
:= FAngle
;
2853 if g_Game_IsNet
then
2857 if FCurrWeap
<> WEAPON_BFG
then
2858 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
2860 if not FNoReload
then
2861 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
2864 MH_SEND_PlayerStats(FUID
);
2869 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
2870 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
2871 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
2874 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
2877 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
2878 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
2879 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
2880 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
2881 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
2886 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
2888 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
2889 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
2890 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
2893 procedure TPlayer
.JetpackOn
;
2897 FJetSoundOn
.SetPosition(0);
2898 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
2902 procedure TPlayer
.JetpackOff
;
2906 FJetSoundOff
.SetPosition(0);
2907 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
2910 procedure TPlayer
.CatchFire(Attacker
: Word);
2913 FFireAttacker
:= Attacker
;
2914 if g_Game_IsNet
and g_Game_IsServer
then
2915 MH_SEND_PlayerStats(FUID
);
2918 procedure TPlayer
.Jump();
2920 if gFly
or FJetpack
then
2922 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
2923 if FObj
.Vel
.Y
> -VEL_FLY
then
2924 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
2927 if FJetFuel
> 0 then
2929 if (FJetFuel
< 1) and g_Game_IsServer
then
2933 if g_Game_IsNet
then
2934 MH_SEND_PlayerStats(FUID
);
2940 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
2942 FCanJetpack
:= False;
2944 // Ïðûãàåì èëè âñïëûâàåì:
2945 if (CollideLevel(0, 1) or
2946 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
2947 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
2948 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
2950 FObj
.Vel
.Y
:= -VEL_JUMP
;
2951 FCanJetpack
:= False;
2955 if BodyInLiquid(0, 0) then
2956 FObj
.Vel
.Y
:= -VEL_SW
2957 else if (FJetFuel
> 0) and FCanJetpack
and
2958 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
2962 if g_Game_IsNet
then
2963 MH_SEND_PlayerStats(FUID
);
2968 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
2970 a
, i
, k
, ab
, ar
: Byte;
2974 srv
, netsrv
: Boolean;
2980 procedure PushItem(t
: Byte);
2984 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
2985 it
:= g_Items_ByIdx(id
);
2986 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
2988 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
2989 (FObj
.Vel
.Y
div 2)-Random(9));
2990 it
.positionChanged(); // this updates spatial accelerators
2994 if KillType
= K_HARDKILL
then // -5..+5; -5..0
2996 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
2997 (FObj
.Vel
.Y
div 2)-Random(6));
2999 else // -3..+3; -3..0
3001 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3002 (FObj
.Vel
.Y
div 2)-Random(4));
3004 it
.positionChanged(); // this updates spatial accelerators
3007 if g_Game_IsNet
and g_Game_IsServer
then
3008 MH_SEND_ItemSpawn(True, id
);
3012 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3013 Srv
:= g_Game_IsServer
;
3014 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3015 if Srv
then FDeath
:= FDeath
+ 1;
3020 if not FPhysics
then
3026 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3028 if FLives
> 0 then FLives
:= FLives
- 1;
3029 if FLives
= 0 then FNoRespawn
:= True;
3032 // Íîìåð òèïà ñìåðòè:
3035 K_SIMPLEKILL
: a
:= 1;
3037 K_EXTRAHARDKILL
: a
:= 3;
3042 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3044 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3051 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3053 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3054 K_EXTRAHARDKILL
, K_FALLKILL
:
3055 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3058 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3062 K_HARDKILL
, K_EXTRAHARDKILL
:
3066 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3067 if (KillType
<> K_FALLKILL
) and (Srv
) then
3068 g_Monsters_killedp();
3070 if SpawnerUID
= FUID
then
3072 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3077 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3080 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3081 begin // Óáèò äðóãèì èãðîêîì
3082 KP
:= g_Player_Get(SpawnerUID
);
3083 if (KP
<> nil) and Srv
then
3085 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3086 if SameTeam(FUID
, SpawnerUID
) then
3096 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3097 Inc(gTeamStat
[KP
.Team
].Goals
,
3098 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3100 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3103 plr
:= g_Player_Get(SpawnerUID
);
3111 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3115 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3119 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3124 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3125 begin // Óáèò ìîíñòðîì
3126 mon
:= g_Monsters_ByUID(SpawnerUID
);
3130 s
:= g_Monsters_GetKilledBy(mon
.MonsterType
);
3134 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3138 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3142 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3147 else // Îñîáûå òèïû ñìåðòè
3150 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3151 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3152 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3153 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3154 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3155 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3161 for a
:= WP_FIRST
to WP_LAST
do
3165 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3166 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3167 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3168 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3169 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3170 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3171 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3172 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3173 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3182 if R_ITEM_BACKPACK
in FRulez
then
3183 PushItem(ITEM_AMMO_BACKPACK
);
3185 // Âûáðîñ ðàêåòíîãî ðàíöà:
3186 if FJetFuel
> 0 then
3187 PushItem(ITEM_JETPACK
);
3190 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3192 if R_KEY_RED
in FRulez
then
3193 PushItem(ITEM_KEY_RED
);
3195 if R_KEY_GREEN
in FRulez
then
3196 PushItem(ITEM_KEY_GREEN
);
3198 if R_KEY_BLUE
in FRulez
then
3199 PushItem(ITEM_KEY_BLUE
);
3206 g_Player_CreateCorpse(Self
);
3208 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3209 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3215 for i
:= Low(gPlayers
) to High(gPlayers
) do
3217 if gPlayers
[i
] = nil then continue
;
3218 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3221 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3222 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3227 OldLR
:= gLMSRespawn
;
3228 if (gGameSettings
.GameMode
= GM_COOP
) then
3232 // everyone is dead, restart the map
3233 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3235 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3236 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3237 gLMSRespawnTime
:= gTime
+ 5000;
3239 else if (a
= 1) then
3241 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3242 if (gPlayers
[k
] = gPlayer1
) or
3243 (gPlayers
[k
] = gPlayer2
) then
3244 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3245 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3246 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3249 else if (gGameSettings
.GameMode
= GM_TDM
) then
3251 if (ab
= 0) and (ar
<> 0) then
3254 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3256 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3257 Inc(gTeamStat
[TEAM_RED
].Goals
);
3258 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3259 gLMSRespawnTime
:= gTime
+ 5000;
3261 else if (ar
= 0) and (ab
<> 0) then
3264 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3266 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3267 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3268 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3269 gLMSRespawnTime
:= gTime
+ 5000;
3271 else if (ar
= 0) and (ab
= 0) then
3274 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3276 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3277 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3278 gLMSRespawnTime
:= gTime
+ 5000;
3281 else if (gGameSettings
.GameMode
= GM_DM
) then
3285 if gPlayers
[k
] <> nil then
3288 // survivor is the winner
3289 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3291 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3294 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3295 gLMSRespawnTime
:= gTime
+ 5000;
3297 else if (a
= 0) then
3299 // everyone is dead, restart the map
3300 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3302 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3303 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3304 gLMSRespawnTime
:= gTime
+ 5000;
3307 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3309 if NetMode
= NET_SERVER
then
3310 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3312 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3318 MH_SEND_PlayerStats(FUID
);
3319 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3320 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3323 if srv
and FNoRespawn
then Spectate(True);
3324 FWantsInGame
:= True;
3327 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3329 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3330 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3333 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3335 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3336 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3339 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3341 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3342 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3343 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3345 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3346 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3347 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3351 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3353 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3354 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3355 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3359 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3361 if g_Game_IsClient
then Exit
;
3362 if Weapon
> High(FWeapon
) then Exit
;
3363 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3366 procedure TPlayer
.resetWeaponQueue ();
3369 FNextWeapDelay
:= 0;
3372 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3376 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3377 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 0);
3378 WEAPON_PISTOL
, WEAPON_CHAINGUN
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_BULLETS
] > 0);
3379 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3380 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3381 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3382 else result
:= (weapon
< length(FWeapon
));
3386 // return 255 for "no switch"
3387 function TPlayer
.getNextWeaponIndex (): Byte;
3390 wantThisWeapon
: array[0..64] of Boolean;
3391 wwc
: Integer = 0; //HACK!
3394 result
:= 255; // default result: "no switch"
3395 // had weapon cycling on previous frame? remove that flag
3396 if (FNextWeap
and $2000) <> 0 then
3398 FNextWeap
:= FNextWeap
and $1FFF;
3399 FNextWeapDelay
:= 0;
3401 // cycling has priority
3402 if (FNextWeap
and $C000) <> 0 then
3404 if (FNextWeap
and $8000) <> 0 then
3408 FNextWeap
:= FNextWeap
or $2000; // we need this
3409 if FNextWeapDelay
> 0 then
3410 exit
; // cooldown time
3412 for i
:= 0 to High(FWeapon
) do
3414 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3415 if FWeapon
[cwi
] then
3417 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d', [FCurrWeap, cwi]), MSG_WARNING);
3418 result
:= Byte(cwi
);
3419 FNextWeapDelay
:= 10;
3427 for i
:= 0 to High(wantThisWeapon
) do
3428 wantThisWeapon
[i
] := false;
3429 for i
:= 0 to High(FWeapon
) do
3430 if (FNextWeap
and (1 shl i
)) <> 0 then
3432 wantThisWeapon
[i
] := true;
3435 // exclude currently selected weapon from the set
3436 wantThisWeapon
[FCurrWeap
] := false;
3437 // slow down alterations a little
3440 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3441 // more than one weapon requested, assume "alteration" and check alteration delay
3442 if FNextWeapDelay
> 0 then
3448 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3449 // but clear all counters if no weapon should be switched
3455 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3456 // try weapons in descending order
3457 for i
:= High(FWeapon
) downto 0 do
3459 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3464 FNextWeapDelay
:= 10; // anyway, 'cause why not
3468 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3472 procedure TPlayer
.RealizeCurrentWeapon();
3473 function switchAllowed (): Boolean;
3478 if FBFGFireCounter
<> -1 then
3480 if FTime
[T_SWITCH
] > gTime
then
3482 for i
:= WP_FIRST
to WP_LAST
do
3483 if FReloading
[i
] > 0 then
3491 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3492 //FNextWeap := FNextWeap and $1FFF;
3493 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3495 if not switchAllowed
then
3497 //HACK for weapon cycling
3498 if (FNextWeap
and $7000) <> 0 then FNextWeap
:= 0;
3502 nw
:= getNextWeaponIndex();
3503 if nw
= 255 then exit
; // don't reset anything here
3504 if nw
> High(FWeapon
) then
3506 // don't forget to reset queue here!
3507 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3515 FTime
[T_SWITCH
] := gTime
+156;
3516 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3517 FModel
.SetWeapon(FCurrWeap
);
3518 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3522 procedure TPlayer
.NextWeapon();
3524 if g_Game_IsClient
then Exit
;
3528 procedure TPlayer
.PrevWeapon();
3530 if g_Game_IsClient
then Exit
;
3534 procedure TPlayer
.SetWeapon(W
: Byte);
3536 if FCurrWeap
<> W
then
3537 if W
= WEAPON_SAW
then
3538 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3541 FModel
.SetWeapon(CurrWeap
);
3545 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3550 if g_Game_IsClient
then Exit
;
3552 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3553 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3558 if FHealth
< PLAYER_HP_SOFT
then
3560 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3564 if gFlash
= 2 then Inc(FPickup
, 5);
3568 if FHealth
< PLAYER_HP_SOFT
then
3570 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3574 if gFlash
= 2 then Inc(FPickup
, 5);
3578 if FArmor
< PLAYER_AP_SOFT
then
3580 FArmor
:= PLAYER_AP_SOFT
;
3583 if gFlash
= 2 then Inc(FPickup
, 5);
3587 if FArmor
< PLAYER_AP_LIMIT
then
3589 FArmor
:= PLAYER_AP_LIMIT
;
3592 if gFlash
= 2 then Inc(FPickup
, 5);
3596 if FHealth
< PLAYER_HP_LIMIT
then
3598 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3602 if gFlash
= 2 then Inc(FPickup
, 5);
3606 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3608 if FHealth
< PLAYER_HP_LIMIT
then
3609 FHealth
:= PLAYER_HP_LIMIT
;
3610 if FArmor
< PLAYER_AP_LIMIT
then
3611 FArmor
:= PLAYER_AP_LIMIT
;
3615 if gFlash
= 2 then Inc(FPickup
, 5);
3619 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3621 FWeapon
[WEAPON_SAW
] := True;
3623 if gFlash
= 2 then Inc(FPickup
, 5);
3624 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3627 ITEM_WEAPON_SHOTGUN1
:
3628 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3630 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3631 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3633 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3634 FWeapon
[WEAPON_SHOTGUN1
] := True;
3636 if gFlash
= 2 then Inc(FPickup
, 5);
3637 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3640 ITEM_WEAPON_SHOTGUN2
:
3641 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3643 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3645 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3646 FWeapon
[WEAPON_SHOTGUN2
] := True;
3648 if gFlash
= 2 then Inc(FPickup
, 5);
3649 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3652 ITEM_WEAPON_CHAINGUN
:
3653 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3655 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3657 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3658 FWeapon
[WEAPON_CHAINGUN
] := True;
3660 if gFlash
= 2 then Inc(FPickup
, 5);
3661 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3664 ITEM_WEAPON_ROCKETLAUNCHER
:
3665 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3667 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3669 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3670 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3672 if gFlash
= 2 then Inc(FPickup
, 5);
3673 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3677 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3679 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3681 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3682 FWeapon
[WEAPON_PLASMA
] := True;
3684 if gFlash
= 2 then Inc(FPickup
, 5);
3685 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3689 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3691 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3693 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3694 FWeapon
[WEAPON_BFG
] := True;
3696 if gFlash
= 2 then Inc(FPickup
, 5);
3697 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3700 ITEM_WEAPON_SUPERPULEMET
:
3701 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3703 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3705 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3706 FWeapon
[WEAPON_SUPERPULEMET
] := True;
3708 if gFlash
= 2 then Inc(FPickup
, 5);
3709 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3712 ITEM_WEAPON_FLAMETHROWER
:
3713 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
3715 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
3717 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3718 FWeapon
[WEAPON_FLAMETHROWER
] := True;
3720 if gFlash
= 2 then Inc(FPickup
, 5);
3721 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3725 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3727 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3730 if gFlash
= 2 then Inc(FPickup
, 5);
3733 ITEM_AMMO_BULLETS_BOX
:
3734 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3736 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3739 if gFlash
= 2 then Inc(FPickup
, 5);
3743 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3745 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3748 if gFlash
= 2 then Inc(FPickup
, 5);
3751 ITEM_AMMO_SHELLS_BOX
:
3752 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3754 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
3757 if gFlash
= 2 then Inc(FPickup
, 5);
3761 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3763 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3766 if gFlash
= 2 then Inc(FPickup
, 5);
3769 ITEM_AMMO_ROCKET_BOX
:
3770 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3772 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
3775 if gFlash
= 2 then Inc(FPickup
, 5);
3779 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3781 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3784 if gFlash
= 2 then Inc(FPickup
, 5);
3788 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3790 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
3793 if gFlash
= 2 then Inc(FPickup
, 5);
3797 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
3799 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3802 if gFlash
= 2 then Inc(FPickup
, 5);
3806 if not(R_ITEM_BACKPACK
in FRulez
) or
3807 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
3808 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
3809 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
3810 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
3811 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
3813 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
3814 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
3815 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
3816 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
3817 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
3819 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3820 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3821 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3822 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3823 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3824 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3825 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3826 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3828 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
3831 if gFlash
= 2 then Inc(FPickup
, 5);
3835 if not(R_KEY_RED
in FRulez
) then
3837 Include(FRulez
, R_KEY_RED
);
3839 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3840 if gFlash
= 2 then Inc(FPickup
, 5);
3841 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3845 if not(R_KEY_GREEN
in FRulez
) then
3847 Include(FRulez
, R_KEY_GREEN
);
3849 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3850 if gFlash
= 2 then Inc(FPickup
, 5);
3851 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3855 if not(R_KEY_BLUE
in FRulez
) then
3857 Include(FRulez
, R_KEY_BLUE
);
3859 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3860 if gFlash
= 2 then Inc(FPickup
, 5);
3861 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3865 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
3867 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
3871 if gFlash
= 2 then Inc(FPickup
, 5);
3875 if FAir
< AIR_MAX
then
3880 if gFlash
= 2 then Inc(FPickup
, 5);
3885 if not (R_BERSERK
in FRulez
) then
3887 Include(FRulez
, R_BERSERK
);
3888 if FBFGFireCounter
= -1 then
3890 FCurrWeap
:= WEAPON_KASTET
;
3892 FModel
.SetWeapon(WEAPON_KASTET
);
3896 if gFlash
= 2 then Inc(FPickup
, 5);
3897 FBerserk
:= gTime
+30000;
3902 if FHealth
< PLAYER_HP_SOFT
then
3904 FHealth
:= PLAYER_HP_SOFT
;
3905 FBerserk
:= gTime
+30000;
3913 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
3915 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
3918 if gFlash
= 2 then Inc(FPickup
, 5);
3922 if FHealth
< PLAYER_HP_LIMIT
then
3924 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
3928 if gFlash
= 2 then Inc(FPickup
, 5);
3932 if FArmor
< PLAYER_AP_LIMIT
then
3934 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
3937 if gFlash
= 2 then Inc(FPickup
, 5);
3941 if FJetFuel
< JET_MAX
then
3943 FJetFuel
:= JET_MAX
;
3946 if gFlash
= 2 then Inc(FPickup
, 5);
3950 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
3952 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
3955 if gFlash
= 2 then Inc(FPickup
, 5);
3960 procedure TPlayer
.Touch();
3964 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
3967 // Áðîñèòü ôëàã òîâàðèùó:
3968 if gGameSettings
.GameMode
= GM_CTF
then
3973 procedure TPlayer
.Push(vx
, vy
: Integer);
3975 if (not FPhysics
) and FGhost
then
3977 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
3978 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
3979 if g_Game_IsNet
and g_Game_IsServer
then
3980 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
3983 procedure TPlayer
.Reset(Force
: Boolean);
3989 FTime
[T_RESPAWN
] := 0;
3990 FTime
[T_FLAGCAP
] := 0;
4003 FSpectator
:= False;
4006 FSpectatePlayer
:= -1;
4007 FNoRespawn
:= False;
4009 FLives
:= gGameSettings
.MaxLives
;
4014 procedure TPlayer
.SoftReset();
4020 FBFGFireCounter
:= -1;
4028 SetAction(A_STAND
, True);
4031 function TPlayer
.GetRespawnPoint(): Byte;
4036 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4038 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4039 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4041 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4043 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4044 if Self
= gPlayer1
then
4045 c
:= RESPAWNPOINT_PLAYER1
4047 c
:= RESPAWNPOINT_PLAYER2
;
4048 if g_Map_GetPointCount(c
) > 0 then
4054 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4055 if Self
= gPlayer1
then
4056 c
:= RESPAWNPOINT_PLAYER2
4058 c
:= RESPAWNPOINT_PLAYER1
;
4059 if g_Map_GetPointCount(c
) > 0 then
4066 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4067 if Random(2) = 0 then
4068 c
:= RESPAWNPOINT_PLAYER1
4070 c
:= RESPAWNPOINT_PLAYER2
;
4071 if g_Map_GetPointCount(c
) > 0 then
4078 // Òî÷êà ëþáîé èç êîìàíä
4079 if Random(2) = 0 then
4080 c
:= RESPAWNPOINT_RED
4082 c
:= RESPAWNPOINT_BLUE
;
4083 if g_Map_GetPointCount(c
) > 0 then
4090 c
:= RESPAWNPOINT_DM
;
4091 if g_Map_GetPointCount(c
) > 0 then
4099 if gGameSettings
.GameMode
= GM_DM
then
4102 c
:= RESPAWNPOINT_DM
;
4103 if g_Map_GetPointCount(c
) > 0 then
4109 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4110 if Random(2) = 0 then
4111 c
:= RESPAWNPOINT_PLAYER1
4113 c
:= RESPAWNPOINT_PLAYER2
;
4114 if g_Map_GetPointCount(c
) > 0 then
4120 // Òî÷êà ëþáîé èç êîìàíä
4121 if Random(2) = 0 then
4122 c
:= RESPAWNPOINT_RED
4124 c
:= RESPAWNPOINT_BLUE
;
4125 if g_Map_GetPointCount(c
) > 0 then
4133 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4135 // Òî÷êà ñâîåé êîìàíäû
4136 c
:= RESPAWNPOINT_DM
;
4137 if FTeam
= TEAM_RED
then
4138 c
:= RESPAWNPOINT_RED
;
4139 if FTeam
= TEAM_BLUE
then
4140 c
:= RESPAWNPOINT_BLUE
;
4141 if g_Map_GetPointCount(c
) > 0 then
4148 c
:= RESPAWNPOINT_DM
;
4149 if g_Map_GetPointCount(c
) > 0 then
4155 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4156 if Random(2) = 0 then
4157 c
:= RESPAWNPOINT_PLAYER1
4159 c
:= RESPAWNPOINT_PLAYER2
;
4160 if g_Map_GetPointCount(c
) > 0 then
4166 // Òî÷êà äðóãîé êîìàíäû
4167 c
:= RESPAWNPOINT_DM
;
4168 if FTeam
= TEAM_RED
then
4169 c
:= RESPAWNPOINT_BLUE
;
4170 if FTeam
= TEAM_BLUE
then
4171 c
:= RESPAWNPOINT_RED
;
4172 if g_Map_GetPointCount(c
) > 0 then
4180 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4182 RespawnPoint
: TRespawnPoint
;
4187 if not g_Game_IsServer
then
4191 FWantsInGame
:= True;
4192 FJustTeleported
:= True;
4195 FTime
[T_RESPAWN
] := 0;
4199 // if server changes MaxLives we gotta be ready
4200 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4202 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4203 if FTime
[T_RESPAWN
] > gTime
then
4206 // Ïðîñðàë âñå æèçíè:
4209 if not FSpectator
then Spectate(True);
4210 FWantsInGame
:= True;
4214 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4215 begin // "Ñâîÿ èãðà"
4216 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4217 FRulez
:= FRulez
-[R_BERSERK
];
4219 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4221 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4222 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4225 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4226 c
:= GetRespawnPoint();
4231 // Âîñêðåøåíèå áåç îðóæèÿ:
4234 FHealth
:= PLAYER_HP_SOFT
;
4240 for a
:= WP_FIRST
to WP_LAST
do
4242 FWeapon
[a
] := False;
4246 FWeapon
[WEAPON_PISTOL
] := True;
4247 FWeapon
[WEAPON_KASTET
] := True;
4248 FCurrWeap
:= WEAPON_PISTOL
;
4251 FModel
.SetWeapon(FCurrWeap
);
4253 for b
:= A_BULLETS
to A_HIGH
do
4256 FAmmo
[A_BULLETS
] := 50;
4258 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4259 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4260 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4261 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4262 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4264 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4265 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4270 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4271 if not g_Map_GetPoint(c
, RespawnPoint
) then
4273 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4277 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4278 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4279 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4285 FDirection
:= RespawnPoint
.Direction
;
4286 if FDirection
= D_LEFT
then
4292 FBFGFireCounter
:= -1;
4297 SetAction(A_STAND
, True);
4298 FModel
.Direction
:= FDirection
;
4300 for a
:= Low(FTime
) to High(FTime
) do
4303 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4308 FCanJetpack
:= False;
4313 // Àíèìàöèÿ âîçðîæäåíèÿ:
4314 if (not gLoadGameMode
) and (not Silent
) then
4315 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4317 Anim
:= TAnimation
.Create(ID
, False, 3);
4318 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4319 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4323 FSpectator
:= False;
4326 FSpectatePlayer
:= -1;
4329 if g_Game_IsNet
then
4331 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4332 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4334 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4335 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4340 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4343 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4344 else if (not NoMove
) then
4346 GameX
:= gMapInfo
.Width
div 2;
4347 GameY
:= gMapInfo
.Height
div 2;
4356 FWantsInGame
:= False;
4361 if Self
= gPlayer1
then
4366 if Self
= gPlayer2
then
4373 if g_Game_IsNet
then
4374 MH_SEND_PlayerStats(FUID
);
4377 procedure TPlayer
.SwitchNoClip
;
4381 FGhost
:= not FGhost
;
4382 FPhysics
:= not FGhost
;
4394 procedure TPlayer
.Run(Direction
: TDirection
);
4398 if MAX_RUNVEL
> 8 then
4402 if Direction
= D_LEFT
then
4404 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4405 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4408 if FObj
.Vel
.X
< MAX_RUNVEL
then
4409 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4411 // Âîçìîæíî, ïèíàåì êóñêè:
4412 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4414 b
:= Abs(FObj
.Vel
.X
);
4415 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4416 for a
:= 0 to High(gGibs
) do
4418 if gGibs
[a
].Live
and
4419 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4420 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4423 if FObj
.Vel
.X
< 0 then
4425 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4429 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4431 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4439 procedure TPlayer
.SeeDown();
4441 SetAction(A_SEEDOWN
);
4443 if FDirection
= D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4445 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4448 procedure TPlayer
.SeeUp();
4452 if FDirection
= D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4454 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4457 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4465 A_ATTACK
: Prior
:= 2;
4466 A_SEEUP
: Prior
:= 1;
4467 A_SEEDOWN
: Prior
:= 1;
4468 A_ATTACKUP
: Prior
:= 2;
4469 A_ATTACKDOWN
: Prior
:= 2;
4474 if (Prior
> FActionPrior
) or Force
then
4475 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4477 FActionPrior
:= Prior
;
4478 FActionAnim
:= Action
;
4479 FActionForce
:= Force
;
4480 FActionChanged
:= True;
4483 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4486 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4488 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4489 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4490 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4491 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4494 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4501 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4503 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4504 if g_Game_IsServer
and g_Game_IsNet
then
4505 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4509 FJustTeleported
:= True;
4514 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4516 Anim
:= TAnimation
.Create(ID
, False, 3);
4519 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4520 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4521 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4522 if g_Game_IsServer
and g_Game_IsNet
then
4523 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4524 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4528 FObj
.X
:= X
-PLAYER_RECT
.X
;
4529 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4530 if FLive
and FGhost
then
4536 if not g_Game_IsNet
then
4540 SetDirection(D_LEFT
);
4546 SetDirection(D_RIGHT
);
4552 if FDirection
= D_RIGHT
then
4554 SetDirection(D_LEFT
);
4559 SetDirection(D_RIGHT
);
4565 if not silent
and (Anim
<> nil) then
4567 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4568 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4571 if g_Game_IsServer
and g_Game_IsNet
then
4572 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4573 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4580 function nonz(a
: Single): Single;
4588 procedure TPlayer
.Update();
4591 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4592 blockmon
, headwater
, dospawn
: Boolean;
4597 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4598 AnyServer
:= g_Game_IsServer
;
4600 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4601 DoLerp(NetInterpLevel
+ 1)
4607 if FClientID
>= 0 then
4609 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4610 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4611 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4620 if FLive
and (gFly
or FJetpack
) then
4623 if FDirection
= D_LEFT
then
4628 if FLive
and (not FGhost
) then
4630 if FKeys
[KEY_UP
].Pressed
then
4632 if FKeys
[KEY_DOWN
].Pressed
then
4636 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4639 i
:= g_basic
.Sign(FIncCam
);
4640 FIncCam
:= Abs(FIncCam
);
4641 DecMin(FIncCam
, 5, 0);
4642 FIncCam
:= FIncCam
*i
;
4645 // no need to do that each second frame, weapon queue will take care of it
4646 if FLive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4647 if FLive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4649 if gTime
mod (GAME_TICK
*2) <> 0 then
4651 if (FObj
.Vel
.X
= 0) and FLive
then
4653 if FKeys
[KEY_LEFT
].Pressed
then
4655 if FKeys
[KEY_RIGHT
].Pressed
then
4661 g_Obj_Move(@FObj
, True, True, True);
4662 positionChanged(); // this updates spatial accelerators
4668 FActionChanged
:= False;
4672 // Let alive player do some actions
4673 if FKeys
[KEY_LEFT
].Pressed
then Run(D_LEFT
);
4674 if FKeys
[KEY_RIGHT
].Pressed
then Run(D_RIGHT
);
4675 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
4676 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
4677 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
4678 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
4679 if FKeys
[KEY_JUMP
].Pressed
then Jump()
4682 if AnyServer
and FJetpack
then
4686 if NetServer
then MH_SEND_PlayerStats(FUID
);
4688 FCanJetpack
:= True;
4695 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
4697 if FKeys
[k
].Pressed
then
4705 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4708 if (FTime
[T_RESPAWN
] <= gTime
) and
4709 gGameOn
and (not FLive
) then
4711 if (g_Player_GetCount() > 1) then
4715 gExit
:= EXIT_RESTART
;
4720 // Dead spectator actions
4723 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
4724 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
4728 if (FSpectatePlayer
>= High(gPlayers
)) then
4729 FSpectatePlayer
:= -1
4733 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
4734 if gPlayers
[I
] <> nil then
4735 if gPlayers
[I
].Live
then
4736 if gPlayers
[I
].UID
<> FUID
then
4738 FSpectatePlayer
:= I
;
4743 if not SetSpect
then FSpectatePlayer
:= -1;
4754 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
4756 FYTo
:= FObj
.Y
- 32;
4757 FSpectatePlayer
:= -1;
4759 if FKeys
[KEY_DOWN
].Pressed
then
4761 FYTo
:= FObj
.Y
+ 32;
4762 FSpectatePlayer
:= -1;
4764 if FKeys
[KEY_LEFT
].Pressed
then
4766 FXTo
:= FObj
.X
- 32;
4767 FSpectatePlayer
:= -1;
4769 if FKeys
[KEY_RIGHT
].Pressed
then
4771 FXTo
:= FObj
.X
+ 32;
4772 FSpectatePlayer
:= -1;
4775 if (FXTo
< -64) then
4777 else if (FXTo
> gMapInfo
.Width
+ 32) then
4778 FXTo
:= gMapInfo
.Width
+ 32;
4779 if (FYTo
< -72) then
4781 else if (FYTo
> gMapInfo
.Height
+ 32) then
4782 FYTo
:= gMapInfo
.Height
+ 32;
4787 g_Obj_Move(@FObj
, True, True, True);
4788 positionChanged(); // this updates spatial accelerators
4795 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
4796 if gPlayers
[FSpectatePlayer
] <> nil then
4797 if gPlayers
[FSpectatePlayer
].Live
then
4799 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
4800 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
4804 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
4805 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
4806 PANEL_BLOCKMON
, True);
4807 headwater
:= HeadInLiquid(0, 0);
4809 // Ñîïðîòèâëåíèå âîçäóõà:
4810 if (not FLive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
4811 if FObj
.Vel
.X
<> 0 then
4812 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
4814 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
4815 DecMin(FPain
, 5, 0);
4816 DecMin(FPickup
, 1, 0);
4818 if FLive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
4820 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
4821 FMegaRulez
[MR_SUIT
] := 0;
4822 FMegaRulez
[MR_INVUL
] := 0;
4823 FMegaRulez
[MR_INVIS
] := 0;
4824 Kill(K_FALLKILL
, 0, HIT_FALL
);
4831 if FCurrWeap
= WEAPON_SAW
then
4832 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
4833 FSawSoundSelect
.IsPlaying()) then
4834 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
4837 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
4838 (not FJetSoundOff
.IsPlaying()) then
4840 FJetSoundFly
.SetPosition(0);
4841 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
4844 for b
:= WP_FIRST
to WP_LAST
do
4845 if FReloading
[b
] > 0 then
4851 if FShellTimer
> -1 then
4852 if FShellTimer
= 0 then
4854 if FShellType
= SHELL_SHELL
then
4855 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4856 GameVelX
, GameVelY
-2, SHELL_SHELL
)
4857 else if FShellType
= SHELL_DBLSHELL
then
4859 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4860 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
4861 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4862 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
4865 end else Dec(FShellTimer
);
4867 if (FBFGFireCounter
> -1) then
4868 if FBFGFireCounter
= 0 then
4872 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
4873 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
4874 xd
:= wx
+IfThen(FDirection
= D_LEFT
, -30, 30);
4875 yd
:= wy
+firediry();
4876 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
4877 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
4878 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
4879 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
4880 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
4883 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
4884 FBFGFireCounter
:= -1;
4887 FBFGFireCounter
:= 0
4889 Dec(FBFGFireCounter
);
4891 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
4893 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
4895 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
4898 if (headwater
or blockmon
) then
4904 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
4907 else if (FAir
mod 31 = 0) and not blockmon
then
4909 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
4910 if Random(2) = 0 then
4911 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
4913 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
4915 end else if FAir
< AIR_DEF
then
4918 if FFireTime
> 0 then
4920 if BodyInLiquid(0, 0) then
4925 else if FMegaRulez
[MR_SUIT
] >= gTime
then
4927 if FMegaRulez
[MR_SUIT
] = gTime
then
4934 if FFirePainTime
<= 0 then
4936 if g_Game_IsServer
then
4937 Damage(5, FFireAttacker
, 0, 0, HIT_FLAME
);
4938 FFirePainTime
:= 18;
4940 FFirePainTime
:= FFirePainTime
- 1;
4941 FFireTime
:= FFireTime
- 1;
4942 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
4943 MH_SEND_PlayerStats(FUID
);
4947 if FDamageBuffer
> 0 then
4949 if FDamageBuffer
>= 9 then
4953 if FDamageBuffer
< 30 then i
:= 9
4954 else if FDamageBuffer
< 100 then i
:= 18
4958 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
4959 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
4960 FHealth
:= FHealth
-ii
;
4963 FHealth
:= FHealth
+FArmor
;
4968 if FHealth
<= 0 then
4969 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
4970 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
4971 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
4975 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
4976 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
4977 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
4978 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
4985 end; // if FLive then ...
4987 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
4989 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
4990 FModel
.GetCurrentAnimation
.MinLength
:= i
;
4991 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
4992 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
4994 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
4995 then SetAction(A_STAND
, True);
4997 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
4999 for b
:= Low(FKeys
) to High(FKeys
) do
5000 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5003 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5005 x
:= FObj
.X
+PLAYER_RECT
.X
;
5006 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5007 w
:= PLAYER_RECT
.Width
;
5008 h
:= PLAYER_RECT
.Height
;
5011 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5013 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5014 FObj
.Y
+PLAYER_RECT
.Y
,
5021 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5023 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5024 FObj
.Y
+PLAYER_RECT
.Y
,
5028 Panel
.Width
, Panel
.Height
);
5031 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5033 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5034 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5035 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5036 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5039 function g_Player_ValidName(Name
: string): Boolean;
5045 if gPlayers
= nil then Exit
;
5047 for a
:= 0 to High(gPlayers
) do
5048 if gPlayers
[a
] <> nil then
5049 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5056 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5060 d
:= FModel
.Direction
;
5062 FModel
.Direction
:= Direction
;
5063 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5065 FDirection
:= Direction
;
5068 function TPlayer
.GetKeys(): Byte;
5072 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5073 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5074 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5076 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5077 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5080 procedure TPlayer
.Use();
5084 if FTime
[T_USE
] > gTime
then Exit
;
5086 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5087 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5089 for a
:= 0 to High(gPlayers
) do
5090 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5091 gPlayers
[a
].Live
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5092 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5093 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5095 gPlayers
[a
].Touch();
5096 if g_Game_IsNet
and g_Game_IsServer
then
5097 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5100 FTime
[T_USE
] := gTime
+120;
5103 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5107 WX
, WY
, XD
, YD
: Integer;
5118 if R_BERSERK
in FRulez
then
5120 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5121 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5122 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5125 locobj
.rect
.Width
:= 39;
5126 locobj
.rect
.Height
:= 52;
5127 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5128 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5129 locobj
.Accel
.X
:= xd
-wx
;
5130 locobj
.Accel
.y
:= yd
-wy
;
5132 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5133 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5135 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5139 FPain
:= min(FPain
+ 25, 50);
5141 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5146 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5147 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5149 FSawSoundSelect
.Stop();
5151 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5153 else if not FSawSoundHit
.IsPlaying() then
5155 FSawSoundSelect
.Stop();
5156 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5163 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5164 FFireAngle
:= FAngle
;
5166 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5167 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5172 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5173 FFireAngle
:= FAngle
;
5176 FShellType
:= SHELL_SHELL
;
5181 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5182 FFireAngle
:= FAngle
;
5185 FShellType
:= SHELL_DBLSHELL
;
5190 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5191 FFireAngle
:= FAngle
;
5193 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5194 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5197 WEAPON_ROCKETLAUNCHER
:
5199 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5200 FFireAngle
:= FAngle
;
5206 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5207 FFireAngle
:= FAngle
;
5213 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5214 FFireAngle
:= FAngle
;
5218 WEAPON_SUPERPULEMET
:
5220 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5221 FFireAngle
:= FAngle
;
5223 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5224 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5227 WEAPON_FLAMETHROWER
:
5229 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5230 FFireAngle
:= FAngle
;
5237 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5238 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5239 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5242 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5244 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5245 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5248 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5252 if NetInterpLevel
< 1 then
5262 AX
:= Abs(FXTo
- FObj
.X
);
5263 AY
:= Abs(FYTo
- FObj
.Y
);
5264 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5266 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5271 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5273 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5274 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5275 PANEL_LIFTUP
, False) then Result
:= -1
5277 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5278 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5279 PANEL_LIFTDOWN
, False) then Result
:= 1
5283 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5290 if Flag
= FLAG_NONE
then
5293 if not g_Game_IsServer
then Exit
;
5295 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5296 if (Flag
= FTeam
) and
5297 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5298 (FFlag
<> FLAG_NONE
) then
5300 if FFlag
= FLAG_RED
then
5301 s
:= _lc
[I_PLAYER_FLAG_RED
]
5303 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5305 evtype
:= FLAG_STATE_SCORED
;
5307 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5308 Insert('.', ts
, Length(ts
) + 1 - 3);
5309 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5311 g_Map_ResetFlag(FFlag
);
5312 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5314 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5317 if g_Game_IsNet
then
5319 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5323 gFlags
[FFlag
].CaptureTime
:= 0;
5328 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5329 if (Flag
= FTeam
) and
5330 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5332 if Flag
= FLAG_RED
then
5333 s
:= _lc
[I_PLAYER_FLAG_RED
]
5335 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5337 evtype
:= FLAG_STATE_RETURNED
;
5338 gFlags
[Flag
].CaptureTime
:= 0;
5340 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5342 g_Map_ResetFlag(Flag
);
5343 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5346 if g_Game_IsNet
then
5348 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5354 // Ïîäîáðàë ÷óæîé ôëàã:
5355 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5359 if Flag
= FLAG_RED
then
5360 s
:= _lc
[I_PLAYER_FLAG_RED
]
5362 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5364 evtype
:= FLAG_STATE_CAPTURED
;
5366 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5368 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5370 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5373 if g_Game_IsNet
then
5375 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5381 procedure TPlayer
.SetFlag(Flag
: Byte);
5384 if FModel
<> nil then
5385 FModel
.SetFlag(FFlag
);
5388 function TPlayer
.DropFlag(): Boolean;
5393 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5395 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5396 with gFlags
[FFlag
] do
5400 Direction
:= FDirection
;
5401 State
:= FLAG_STATE_DROPPED
;
5403 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5404 (FObj
.Vel
.Y
div 2)-2+Random(5));
5405 positionChanged(); // this updates spatial accelerators
5407 if FFlag
= FLAG_RED
then
5408 s
:= _lc
[I_PLAYER_FLAG_RED
]
5410 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5412 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5413 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5415 if g_Game_IsNet
then
5416 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5422 procedure TPlayer
.GetSecret();
5427 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5429 Assert(Key
<= High(FKeys
));
5431 FKeys
[Key
].Pressed
:= True;
5432 FKeys
[Key
].Time
:= Time
;
5435 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5437 Result
:= FKeys
[K
].Pressed
;
5440 procedure TPlayer
.ReleaseKeys();
5444 for a
:= Low(FKeys
) to High(FKeys
) do
5446 FKeys
[a
].Pressed
:= False;
5451 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5455 function TPlayer
.firediry(): Integer;
5457 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5458 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5462 procedure TPlayer
.RememberState();
5466 FSavedState
.Health
:= FHealth
;
5467 FSavedState
.Armor
:= FArmor
;
5468 FSavedState
.Air
:= FAir
;
5469 FSavedState
.JetFuel
:= FJetFuel
;
5470 FSavedState
.CurrWeap
:= FCurrWeap
;
5471 FSavedState
.NextWeap
:= FNextWeap
;
5472 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5475 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5477 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5479 FSavedState
.Rulez
:= FRulez
;
5480 FSavedState
.WaitRecall
:= True;
5483 procedure TPlayer
.RecallState();
5487 if not FSavedState
.WaitRecall
then Exit
;
5489 FHealth
:= FSavedState
.Health
;
5490 FArmor
:= FSavedState
.Armor
;
5491 FAir
:= FSavedState
.Air
;
5492 FJetFuel
:= FSavedState
.JetFuel
;
5493 FCurrWeap
:= FSavedState
.CurrWeap
;
5494 FNextWeap
:= FSavedState
.NextWeap
;
5495 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5498 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5500 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5502 FRulez
:= FSavedState
.Rulez
;
5503 FSavedState
.WaitRecall
:= False;
5505 if gGameSettings
.GameType
= GT_SERVER
then
5506 MH_SEND_PlayerStats(FUID
);
5509 procedure TPlayer
.SaveState(var Mem
: TBinMemoryWriter
);
5521 Mem
:= TBinMemoryWriter
.Create(i
);
5523 // Ñèãíàòóðà èãðîêà:
5524 sig
:= PLAYER_SIGNATURE
; // 'PLYR'
5525 Mem
.WriteDWORD(sig
);
5527 Mem
.WriteBoolean(FIamBot
);
5529 Mem
.WriteWord(FUID
);
5531 Mem
.WriteString(FName
, 32);
5533 Mem
.WriteByte(FTeam
);
5535 Mem
.WriteBoolean(FLive
);
5536 // Èçðàñõîäîâàë ëè âñå æèçíè:
5537 Mem
.WriteBoolean(FNoRespawn
);
5539 if FDirection
= D_LEFT
then
5545 Mem
.WriteInt(FHealth
);
5547 Mem
.WriteByte(FLives
);
5549 Mem
.WriteInt(FArmor
);
5553 Mem
.WriteInt(FJetFuel
);
5555 Mem
.WriteInt(FPain
);
5557 Mem
.WriteInt(FKills
);
5559 Mem
.WriteInt(FMonsterKills
);
5561 Mem
.WriteInt(FFrags
);
5563 Mem
.WriteByte(FFragCombo
);
5564 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5565 Mem
.WriteDWORD(FLastFrag
);
5567 Mem
.WriteInt(FDeath
);
5568 // Êàêîé ôëàã íåñåò:
5569 Mem
.WriteByte(FFlag
);
5571 Mem
.WriteInt(FSecrets
);
5573 Mem
.WriteByte(FCurrWeap
);
5575 Mem
.WriteWord(FNextWeap
);
5577 Mem
.WriteByte(FNextWeapDelay
);
5578 // Âðåìÿ çàðÿäêè BFG:
5579 Mem
.WriteSmallInt(FBFGFireCounter
);
5581 Mem
.WriteInt(FDamageBuffer
);
5582 // Ïîñëåäíèé óäàðèâøèé:
5583 Mem
.WriteWord(FLastSpawnerUID
);
5584 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5585 Mem
.WriteByte(FLastHit
);
5587 Obj_SaveState(@FObj
, Mem
);
5588 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5589 for i
:= A_BULLETS
to A_HIGH
do
5590 Mem
.WriteWord(FAmmo
[i
]);
5591 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5592 for i
:= A_BULLETS
to A_HIGH
do
5593 Mem
.WriteWord(FMaxAmmo
[i
]);
5595 for i
:= WP_FIRST
to WP_LAST
do
5596 Mem
.WriteBoolean(FWeapon
[i
]);
5597 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5598 for i
:= WP_FIRST
to WP_LAST
do
5599 Mem
.WriteWord(FReloading
[i
]);
5601 if R_ITEM_BACKPACK
in FRulez
then
5606 // Íàëè÷èå êðàñíîãî êëþ÷à:
5607 if R_KEY_RED
in FRulez
then
5612 // Íàëè÷èå çåëåíîãî êëþ÷à:
5613 if R_KEY_GREEN
in FRulez
then
5618 // Íàëè÷èå ñèíåãî êëþ÷à:
5619 if R_KEY_BLUE
in FRulez
then
5624 // Íàëè÷èå áåðñåðêà:
5625 if R_BERSERK
in FRulez
then
5630 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5631 for i
:= MR_SUIT
to MR_MAX
do
5632 Mem
.WriteDWORD(FMegaRulez
[i
]);
5633 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5634 for i
:= T_RESPAWN
to T_FLAGCAP
do
5635 Mem
.WriteDWORD(FTime
[i
]);
5638 Mem
.WriteString(str
);
5648 procedure TPlayer
.LoadState(var Mem
: TBinMemoryReader
);
5658 // Ñèãíàòóðà èãðîêà:
5660 if sig
<> PLAYER_SIGNATURE
then // 'PLYR'
5662 raise EBinSizeError
.Create('TPlayer.LoadState: Wrong Player Signature');
5665 Mem
.ReadBoolean(FIamBot
);
5669 Mem
.ReadString(str
);
5670 if (Self
<> gPlayer1
) and (Self
<> gPlayer2
) then
5673 Mem
.ReadByte(FTeam
);
5675 Mem
.ReadBoolean(FLive
);
5676 // Èçðàñõîäîâàë ëè âñå æèçíè:
5677 Mem
.ReadBoolean(FNoRespawn
);
5681 FDirection
:= D_LEFT
5683 FDirection
:= D_RIGHT
;
5685 Mem
.ReadInt(FHealth
);
5687 Mem
.ReadByte(FLives
);
5689 Mem
.ReadInt(FArmor
);
5693 Mem
.ReadInt(FJetFuel
);
5697 Mem
.ReadInt(FKills
);
5699 Mem
.ReadInt(FMonsterKills
);
5701 Mem
.ReadInt(FFrags
);
5703 Mem
.ReadByte(FFragCombo
);
5704 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5705 Mem
.ReadDWORD(FLastFrag
);
5707 Mem
.ReadInt(FDeath
);
5708 // Êàêîé ôëàã íåñåò:
5709 Mem
.ReadByte(FFlag
);
5711 Mem
.ReadInt(FSecrets
);
5713 Mem
.ReadByte(FCurrWeap
);
5715 Mem
.ReadWord(FNextWeap
);
5717 Mem
.ReadByte(FNextWeapDelay
);
5718 // Âðåìÿ çàðÿäêè BFG:
5719 Mem
.ReadSmallInt(FBFGFireCounter
);
5721 Mem
.ReadInt(FDamageBuffer
);
5722 // Ïîñëåäíèé óäàðèâøèé:
5723 Mem
.ReadWord(FLastSpawnerUID
);
5724 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5725 Mem
.ReadByte(FLastHit
);
5727 Obj_LoadState(@FObj
, Mem
);
5728 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5729 for i
:= A_BULLETS
to A_HIGH
do
5730 Mem
.ReadWord(FAmmo
[i
]);
5731 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5732 for i
:= A_BULLETS
to A_HIGH
do
5733 Mem
.ReadWord(FMaxAmmo
[i
]);
5735 for i
:= WP_FIRST
to WP_LAST
do
5736 Mem
.ReadBoolean(FWeapon
[i
]);
5737 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5738 for i
:= WP_FIRST
to WP_LAST
do
5739 Mem
.ReadWord(FReloading
[i
]);
5743 Include(FRulez
, R_ITEM_BACKPACK
);
5744 // Íàëè÷èå êðàñíîãî êëþ÷à:
5747 Include(FRulez
, R_KEY_RED
);
5748 // Íàëè÷èå çåëåíîãî êëþ÷à:
5751 Include(FRulez
, R_KEY_GREEN
);
5752 // Íàëè÷èå ñèíåãî êëþ÷à:
5755 Include(FRulez
, R_KEY_BLUE
);
5756 // Íàëè÷èå áåðñåðêà:
5759 Include(FRulez
, R_BERSERK
);
5760 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5761 for i
:= MR_SUIT
to MR_MAX
do
5762 Mem
.ReadDWORD(FMegaRulez
[i
]);
5763 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5764 for i
:= T_RESPAWN
to T_FLAGCAP
do
5765 Mem
.ReadDWORD(FTime
[i
]);
5767 Mem
.ReadString(str
);
5769 Mem
.ReadByte(FColor
.R
);
5770 Mem
.ReadByte(FColor
.G
);
5771 Mem
.ReadByte(FColor
.B
);
5772 if Self
= gPlayer1
then
5774 str
:= gPlayer1Settings
.Model
;
5775 FColor
:= gPlayer1Settings
.Color
;
5777 if Self
= gPlayer2
then
5779 str
:= gPlayer2Settings
.Model
;
5780 FColor
:= gPlayer2Settings
.Color
;
5782 // Îáíîâëÿåì ìîäåëü èãðîêà:
5784 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
5785 FModel
.Color
:= TEAMCOLOR
[FTeam
]
5787 FModel
.Color
:= FColor
;
5790 procedure TPlayer
.AllRulez(Health
: Boolean);
5796 FHealth
:= PLAYER_HP_LIMIT
;
5797 FArmor
:= PLAYER_AP_LIMIT
;
5801 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
5802 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
5803 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5806 procedure TPlayer
.RestoreHealthArmor();
5808 FHealth
:= PLAYER_HP_LIMIT
;
5809 FArmor
:= PLAYER_AP_LIMIT
;
5812 procedure TPlayer
.FragCombo();
5816 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
5818 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
5820 if FFragCombo
< 5 then
5822 Param
:= FUID
or (FFragCombo
shl 16);
5823 if (FComboEvnt
>= Low(gDelayedEvents
)) and
5824 (FComboEvnt
<= High(gDelayedEvents
)) and
5825 gDelayedEvents
[FComboEvnt
].Pending
and
5826 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
5827 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
5829 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
5830 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
5833 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
5841 procedure TPlayer
.GiveItem(ItemType
: Byte);
5845 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
5847 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
5851 if FAir
< AIR_MAX
then
5858 if not (R_BERSERK
in FRulez
) then
5860 Include(FRulez
, R_BERSERK
);
5861 if FBFGFireCounter
< 1 then
5863 FCurrWeap
:= WEAPON_KASTET
;
5865 FModel
.SetWeapon(WEAPON_KASTET
);
5869 FBerserk
:= gTime
+30000;
5871 if FHealth
< PLAYER_HP_SOFT
then
5873 FHealth
:= PLAYER_HP_SOFT
;
5874 FBerserk
:= gTime
+30000;
5879 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
5881 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
5885 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
5887 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
5891 if FJetFuel
< JET_MAX
then
5893 FJetFuel
:= JET_MAX
;
5896 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
5897 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
5899 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
5900 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5902 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
5904 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
5906 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
5907 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5910 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
5911 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
5912 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
5913 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
5914 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
5915 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
5916 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
5917 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
5918 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
5920 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5921 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
5922 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5923 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
5924 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5925 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
5926 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5927 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
5928 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
5931 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
5932 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
5933 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
5934 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
5935 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
5937 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
5938 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
5939 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
5940 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
5941 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
5943 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5944 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5945 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5946 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5948 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
5951 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
5952 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
5953 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
5955 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
5956 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
5961 if g_Game_IsNet
and g_Game_IsServer
then
5962 MH_SEND_PlayerStats(FUID
);
5965 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
5970 if (Random(5) = 1) and (Times
= 1) then
5973 if BodyInLiquid(0, 0) then
5975 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
5976 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
5977 if Random(2) = 0 then
5978 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5980 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5984 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
5986 for i
:= 1 to Times
do
5988 Anim
:= TAnimation
.Create(id
, False, 3);
5990 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
5991 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
5997 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6002 if (Random(10) = 1) and (Times
= 1) then
6005 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6007 for i
:= 1 to Times
do
6009 Anim
:= TAnimation
.Create(id
, False, 3);
6011 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6012 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6018 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6020 FSawSound
.Pause(Enable
);
6021 FSawSoundIdle
.Pause(Enable
);
6022 FSawSoundHit
.Pause(Enable
);
6023 FSawSoundSelect
.Pause(Enable
);
6028 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6033 FObj
.Rect
:= PLAYER_CORPSERECT
;
6034 FModelName
:= ModelName
;
6039 FState
:= CORPSE_STATE_MESS
;
6040 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6044 FState
:= CORPSE_STATE_NORMAL
;
6045 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6049 destructor TCorpse
.Destroy();
6056 procedure TCorpse
.positionChanged (); begin end;
6058 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6062 if FState
= CORPSE_STATE_REMOVEME
then
6065 FDamage
:= FDamage
+ Value
;
6067 if FDamage
> 150 then
6069 if FAnimation
<> nil then
6074 FState
:= CORPSE_STATE_REMOVEME
;
6076 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6077 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6078 FModelName
, FColor
);
6079 // Çâóê ìÿñà îò òðóïà:
6080 pm
:= g_PlayerModel_Get(FModelName
);
6081 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6087 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6088 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6089 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6090 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6091 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6096 procedure TCorpse
.Draw();
6098 if FState
= CORPSE_STATE_REMOVEME
then
6101 if FAnimation
<> nil then
6102 FAnimation
.Draw(FObj
.X
, FObj
.Y
, M_NONE
);
6104 if FAnimationMask
<> nil then
6107 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, M_NONE
);
6114 procedure TCorpse
.Update();
6118 if FState
= CORPSE_STATE_REMOVEME
then
6121 if gTime
mod (GAME_TICK
*2) <> 0 then
6123 g_Obj_Move(@FObj
, True, True, True);
6124 positionChanged(); // this updates spatial accelerators
6128 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6129 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6131 st
:= g_Obj_Move(@FObj
, True, True, True);
6132 positionChanged(); // this updates spatial accelerators
6134 if WordBool(st
and MOVE_FALLOUT
) then
6136 FState
:= CORPSE_STATE_REMOVEME
;
6140 if FAnimation
<> nil then
6141 FAnimation
.Update();
6142 if FAnimationMask
<> nil then
6143 FAnimationMask
.Update();
6146 procedure TCorpse
.SaveState(var Mem
: TBinMemoryWriter
);
6155 sig
:= CORPSE_SIGNATURE
; // 'CORP'
6156 Mem
.WriteDWORD(sig
);
6158 Mem
.WriteByte(FState
);
6159 // Íàêîïëåííûé óðîí:
6160 Mem
.WriteByte(FDamage
);
6162 Mem
.WriteByte(FColor
.R
);
6163 Mem
.WriteByte(FColor
.G
);
6164 Mem
.WriteByte(FColor
.B
);
6166 Obj_SaveState(@FObj
, Mem
);
6167 // Åñòü ëè àíèìàöèÿ:
6168 anim
:= FAnimation
<> nil;
6169 Mem
.WriteBoolean(anim
);
6170 // Åñëè åñòü - ñîõðàíÿåì:
6172 FAnimation
.SaveState(Mem
);
6173 // Åñòü ëè ìàñêà àíèìàöèè:
6174 anim
:= FAnimationMask
<> nil;
6175 Mem
.WriteBoolean(anim
);
6176 // Åñëè åñòü - ñîõðàíÿåì:
6178 FAnimationMask
.SaveState(Mem
);
6181 procedure TCorpse
.LoadState(var Mem
: TBinMemoryReader
);
6191 if sig
<> CORPSE_SIGNATURE
then // 'CORP'
6193 raise EBinSizeError
.Create('TCorpse.LoadState: Wrong Corpse Signature');
6196 Mem
.ReadByte(FState
);
6197 // Íàêîïëåííûé óðîí:
6198 Mem
.ReadByte(FDamage
);
6200 Mem
.ReadByte(FColor
.R
);
6201 Mem
.ReadByte(FColor
.G
);
6202 Mem
.ReadByte(FColor
.B
);
6204 Obj_LoadState(@FObj
, Mem
);
6205 // Åñòü ëè àíèìàöèÿ:
6206 Mem
.ReadBoolean(anim
);
6207 // Åñëè åñòü - çàãðóæàåì:
6210 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6211 FAnimation
.LoadState(Mem
);
6213 // Åñòü ëè ìàñêà àíèìàöèè:
6214 Mem
.ReadBoolean(anim
);
6215 // Åñëè åñòü - çàãðóæàåì:
6218 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6219 FAnimationMask
.LoadState(Mem
);
6225 constructor TBot
.Create();
6232 FSpectator
:= False;
6239 for a
:= WP_FIRST
to WP_LAST
do
6241 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6242 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6243 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6247 destructor TBot
.Destroy();
6250 inherited Destroy();
6253 procedure TBot
.Draw();
6257 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6258 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6261 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6263 inherited Respawn(Silent
, Force
);
6266 FSelectedWeapon
:= FCurrWeap
;
6271 procedure TBot
.UpdateCombat();
6284 TTargetRecord
= array of TTarget
;
6286 function Compare(a
, b
: TTarget
): Integer;
6288 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6291 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6293 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6294 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6296 if a
.Dist
> b
.Dist
then // B áëèæå
6298 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6301 else // Ñòðàííî -> A
6306 a
, x1
, y1
, x2
, y2
: Integer;
6307 targets
: TTargetRecord
;
6309 Target
, BestTarget
: TTarget
;
6310 firew
, fireh
: Integer;
6314 vsPlayer
, vsMonster
, ok
: Boolean;
6317 function monsUpdate (mon
: TMonster
): Boolean;
6319 result
:= false; // don't stop
6320 if mon
.Live
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6322 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6324 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6325 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6327 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6328 if g_TraceVector(x1
, y1
, x2
, y2
) then
6330 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6331 SetLength(targets
, Length(targets
)+1);
6332 with targets
[High(targets
)] do
6339 Rect
:= mon
.Obj
.Rect
;
6340 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6341 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6342 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6351 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6352 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6354 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6355 if FCurrWeap
<> FSelectedWeapon
then
6358 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6359 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6361 RemoveAIFlag('NEEDFIRE');
6364 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6365 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6366 else PressKey(KEY_FIRE
);
6370 // Êîîðäèíàòû ñòâîëà:
6371 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6372 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6374 Target
.UID
:= FTargetUID
;
6377 if Target
.UID
<> 0 then
6378 begin // Öåëü åñòü - íàñòðàèâàåì
6379 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6382 tpla
:= g_Player_Get(Target
.UID
);
6386 if (@FObj
) <> nil then
6393 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6394 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6395 Target
.Rect
:= PLAYER_RECT
;
6396 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6397 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6398 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6399 Target
.IsPlayer
:= True;
6403 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6406 mon
:= g_Monsters_ByUID(Target
.UID
);
6409 Target
.X
:= mon
.Obj
.X
;
6410 Target
.Y
:= mon
.Obj
.Y
;
6412 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6413 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6414 Target
.Rect
:= mon
.Obj
.Rect
;
6415 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6416 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6417 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6418 Target
.IsPlayer
:= False;
6425 begin // Öåëè íåò - îáíóëÿåì
6430 Target
.Visible
:= False;
6431 Target
.Line
:= False;
6432 Target
.IsPlayer
:= False;
6437 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6438 if (not Target
.Line
) or (not Target
.Visible
) then
6442 for a
:= 0 to High(gPlayers
) do
6443 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].Live
) and
6444 (gPlayers
[a
].FUID
<> FUID
) and
6445 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6446 (not gPlayers
[a
].NoTarget
) and
6447 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6449 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6450 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6453 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6454 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6456 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6457 if g_TraceVector(x1
, y1
, x2
, y2
) then
6459 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6460 SetLength(targets
, Length(targets
)+1);
6461 with targets
[High(targets
)] do
6463 UID
:= gPlayers
[a
].FUID
;
6464 X
:= gPlayers
[a
].FObj
.X
;
6465 Y
:= gPlayers
[a
].FObj
.Y
;
6468 Rect
:= PLAYER_RECT
;
6469 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6470 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6471 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6479 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6482 // Åñëè åñòü âîçìîæíûå öåëè:
6483 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6484 if targets
<> nil then
6486 // Âûáèðàåì íàèëó÷øóþ öåëü:
6487 BestTarget
:= targets
[0];
6488 if Length(targets
) > 1 then
6489 for a
:= 1 to High(targets
) do
6490 if Compare(BestTarget
, targets
[a
]) = 1 then
6491 BestTarget
:= targets
[a
];
6493 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6494 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6495 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6497 Target
:= BestTarget
;
6499 if (Healthy() = 3) or ((Healthy() = 2)) then
6500 begin // Åñëè çäîðîâû - äîãîíÿåì
6501 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6502 SetAIFlag('GORIGHT', '1');
6503 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6504 SetAIFlag('GOLEFT', '1');
6507 begin // Åñëè ïîáèòû - óáåãàåì
6508 if ((RunDirection() = D_LEFT
) and (Target
.X
< FObj
.X
)) then
6509 SetAIFlag('GORIGHT', '1');
6510 if ((RunDirection() = D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6511 SetAIFlag('GOLEFT', '1');
6514 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6515 SelectWeapon(Abs(x1
-Target
.cX
));
6520 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6521 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6522 if Target
.UID
<> 0 then
6524 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6525 Target
.Y
+ Target
.Rect
.Y
) then
6526 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6527 if (Healthy() = 3) or ((Healthy() = 2)) then
6528 begin // Åñëè çäîðîâû - äîãîíÿåì
6529 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6530 SetAIFlag('GORIGHT', '1');
6531 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6532 SetAIFlag('GOLEFT', '1');
6535 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6537 if ((RunDirection() = D_LEFT
) and (Target
.X
< FObj
.X
)) then
6538 SetAIFlag('GORIGHT', '1');
6539 if ((RunDirection() = D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6540 SetAIFlag('GOLEFT', '1');
6544 begin // Öåëü ïîêà íà "ýêðàíå"
6545 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6546 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6547 FLastVisible
:= gTime
;
6548 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6549 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6551 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6552 SetAIFlag('GORIGHT', '1');
6553 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6554 SetAIFlag('GOLEFT', '1');
6558 // Âûáèðàåì óãîë ââåðõ:
6559 if FDirection
= D_LEFT
then
6560 angle
:= ANGLE_LEFTUP
6562 angle
:= ANGLE_RIGHTUP
;
6564 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6565 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6567 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6568 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6569 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6570 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6571 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6572 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6573 begin // òî íóæíî ñòðåëÿòü ââåðõ
6574 SetAIFlag('NEEDFIRE', '1');
6575 SetAIFlag('NEEDSEEUP', '1');
6578 // Âûáèðàåì óãîë âíèç:
6579 if FDirection
= D_LEFT
then
6580 angle
:= ANGLE_LEFTDOWN
6582 angle
:= ANGLE_RIGHTDOWN
;
6584 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6585 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6587 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6588 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6589 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6590 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6591 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6592 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6593 begin // òî íóæíî ñòðåëÿòü âíèç
6594 SetAIFlag('NEEDFIRE', '1');
6595 SetAIFlag('NEEDSEEDOWN', '1');
6598 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6599 if Target
.Visible
and
6600 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6601 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6603 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6604 if ((FDirection
= D_LEFT
) and (Target
.X
< FObj
.X
)) or
6605 ((FDirection
= D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6606 begin // òî íóæíî ñòðåëÿòü âïåðåä
6607 SetAIFlag('NEEDFIRE', '1');
6608 SetAIFlag('NEEDSEEDOWN', '');
6609 SetAIFlag('NEEDSEEUP', '');
6611 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6612 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6613 if GetRnd(FDifficult
.CloseJump
) then
6614 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6615 if Abs(FObj
.X
-Target
.X
) < 128 then
6619 if Random(a
) = 0 then
6620 SetAIFlag('NEEDJUMP', '1');
6624 // Åñëè öåëü âñå åùå åñòü:
6625 if Target
.UID
<> 0 then
6626 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
6627 Target
.UID
:= 0 // òî çàáûòü öåëü
6628 else // Åñëè âèäåëè íåäàâíî
6629 begin // íî öåëü óáèëè
6630 if Target
.IsPlayer
then
6631 begin // Öåëü - èãðîê
6632 pla
:= g_Player_Get(Target
.UID
);
6633 if (pla
= nil) or (not pla
.Live
) or pla
.NoTarget
or
6634 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6635 Target
.UID
:= 0; // òî çàáûòü öåëü
6638 begin // Öåëü - ìîíñòð
6639 mon
:= g_Monsters_ByUID(Target
.UID
);
6640 if (mon
= nil) or (not mon
.Live
) then
6641 Target
.UID
:= 0; // òî çàáûòü öåëü
6644 end; // if Target.UID <> 0
6646 FTargetUID
:= Target
.UID
;
6648 // Åñëè âîçìîæíûõ öåëåé íåò:
6649 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
6650 if targets
= nil then
6651 if GetAIFlag('ATTACKLEFT') <> '' then
6652 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
6653 RemoveAIFlag('ATTACKLEFT');
6655 SetAIFlag('NEEDJUMP', '1');
6657 if RunDirection() = D_RIGHT
then
6658 begin // Èäåì íå â òó ñòîðîíó
6659 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6660 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
6661 SetAIFlag('NEEDFIRE', '1');
6662 SetAIFlag('GOLEFT', '1');
6666 begin // Èäåì â íóæíóþ ñòîðîíó
6667 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6668 SetAIFlag('NEEDFIRE', '1');
6669 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6670 SetAIFlag('GORIGHT', '1');
6674 if GetAIFlag('ATTACKRIGHT') <> '' then
6675 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
6676 RemoveAIFlag('ATTACKRIGHT');
6678 SetAIFlag('NEEDJUMP', '1');
6680 if RunDirection() = D_LEFT
then
6681 begin // Èäåì íå â òó ñòîðîíó
6682 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6683 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
6684 SetAIFlag('NEEDFIRE', '1');
6685 SetAIFlag('GORIGHT', '1');
6690 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6691 SetAIFlag('NEEDFIRE', '1');
6692 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6693 SetAIFlag('GOLEFT', '1');
6697 //HACK! (does it belongs there?)
6698 RealizeCurrentWeapon();
6700 // Åñëè åñòü âîçìîæíûå öåëè:
6701 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
6702 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6703 for a
:= 0 to High(targets
) do
6705 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
6706 if GetRnd(FDifficult
.DiagFire
) then
6708 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
6709 if FDirection
= D_LEFT
then
6710 angle
:= ANGLE_LEFTUP
6712 angle
:= ANGLE_RIGHTUP
;
6714 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6715 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6717 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6718 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6719 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6720 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6721 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6723 SetAIFlag('NEEDFIRE', '1');
6724 SetAIFlag('NEEDSEEUP', '1');
6727 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
6728 if FDirection
= D_LEFT
then
6729 angle
:= ANGLE_LEFTDOWN
6731 angle
:= ANGLE_RIGHTDOWN
;
6733 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6734 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6736 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6737 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6738 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6739 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6740 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6742 SetAIFlag('NEEDFIRE', '1');
6743 SetAIFlag('NEEDSEEDOWN', '1');
6747 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
6748 if targets
[a
].Line
and targets
[a
].Visible
and
6749 (((FDirection
= D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
6750 ((FDirection
= D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
6752 SetAIFlag('NEEDFIRE', '1');
6757 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
6758 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
6759 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
6760 40+GetInterval(FDifficult
.Cover
, 40)) then
6761 SetAIFlag('NEEDJUMP', '1');
6763 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
6764 ammo
:= GetAmmoByWeapon(FCurrWeap
);
6765 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
6766 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
6768 SetAIFlag('SELECTWEAPON', '1');
6770 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
6771 if GetAIFlag('SELECTWEAPON') = '1' then
6774 RemoveAIFlag('SELECTWEAPON');
6778 procedure TBot
.Update();
6791 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
6792 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
6794 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
6796 if g_debug_BotAIOff
= 3 then
6806 RealizeCurrentWeapon();
6813 procedure TBot
.ReleaseKey(Key
: Byte);
6822 function TBot
.KeyPressed(Key
: Word): Boolean;
6824 Result
:= FKeys
[Key
].Pressed
;
6827 function TBot
.GetAIFlag(aName
: String20
): String20
;
6833 aName
:= LowerCase(aName
);
6835 if FAIFlags
<> nil then
6836 for a
:= 0 to High(FAIFlags
) do
6837 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6839 Result
:= FAIFlags
[a
].Value
;
6844 procedure TBot
.RemoveAIFlag(aName
: String20
);
6848 if FAIFlags
= nil then Exit
;
6850 aName
:= LowerCase(aName
);
6852 for a
:= 0 to High(FAIFlags
) do
6853 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6855 if a
<> High(FAIFlags
) then
6856 for b
:= a
to High(FAIFlags
)-1 do
6857 FAIFlags
[b
] := FAIFlags
[b
+1];
6859 SetLength(FAIFlags
, Length(FAIFlags
)-1);
6864 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
6872 aName
:= LowerCase(aName
);
6874 if FAIFlags
<> nil then
6875 for a
:= 0 to High(FAIFlags
) do
6876 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6882 if ok
then FAIFlags
[a
].Value
:= fValue
6885 SetLength(FAIFlags
, Length(FAIFlags
)+1);
6886 with FAIFlags
[High(FAIFlags
)] do
6894 procedure TBot
.UpdateMove
;
6896 procedure GoLeft(Time
: Word = 1);
6898 ReleaseKey(KEY_LEFT
);
6899 ReleaseKey(KEY_RIGHT
);
6900 PressKey(KEY_LEFT
, Time
);
6901 SetDirection(D_LEFT
);
6904 procedure GoRight(Time
: Word = 1);
6906 ReleaseKey(KEY_LEFT
);
6907 ReleaseKey(KEY_RIGHT
);
6908 PressKey(KEY_RIGHT
, Time
);
6909 SetDirection(D_RIGHT
);
6912 function Rnd(a
: Word): Boolean;
6914 Result
:= Random(a
) = 0;
6917 procedure Turn(Time
: Word = 1200);
6919 if RunDirection() = D_LEFT
then GoRight(Time
) else GoLeft(Time
);
6924 ReleaseKey(KEY_LEFT
);
6925 ReleaseKey(KEY_RIGHT
);
6928 function CanRunLeft(): Boolean;
6930 Result
:= not CollideLevel(-1, 0);
6933 function CanRunRight(): Boolean;
6935 Result
:= not CollideLevel(1, 0);
6938 function CanRun(): Boolean;
6940 if RunDirection() = D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
6943 procedure Jump(Time
: Word = 30);
6945 PressKey(KEY_JUMP
, Time
);
6948 function NearHole(): Boolean;
6952 { TODO 5 : Ëåñòíèöû }
6953 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6954 for x
:= 1 to PLAYER_RECT
.Width
do
6955 if (not StayOnStep(x
*sx
, 0)) and
6956 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6957 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6966 function BorderHole(): Boolean;
6970 { TODO 5 : Ëåñòíèöû }
6971 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6972 for x
:= 1 to PLAYER_RECT
.Width
do
6973 if (not StayOnStep(x
*sx
, 0)) and
6974 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6975 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6977 for xx
:= x
to x
+32 do
6978 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
6988 function NearDeepHole(): Boolean;
6994 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6997 for x
:= 1 to PLAYER_RECT
.Width
do
6998 if (not StayOnStep(x
*sx
, 0)) and
6999 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7000 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7002 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7004 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7009 end else Result
:= False;
7012 function OverDeepHole(): Boolean;
7019 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7021 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7028 function OnGround(): Boolean;
7030 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7033 function OnLadder(): Boolean;
7035 Result
:= FullInStep(0, 0);
7038 function BelowLadder(): Boolean;
7040 Result
:= (FullInStep(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7041 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7042 (FullInStep(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7043 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7046 function BelowLiftUp(): Boolean;
7048 Result
:= ((FullInLift(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7049 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7050 ((FullInLift(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7051 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7054 function OnTopLift(): Boolean;
7056 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7059 function CanJumpOver(): Boolean;
7063 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
7067 if not CollideLevel(sx
, 0) then Exit
;
7069 for y
:= 1 to BOT_MAXJUMP
do
7070 if CollideLevel(0, -y
) then Exit
else
7071 if not CollideLevel(sx
, -y
) then
7078 function CanJumpUp(Dist
: ShortInt): Boolean;
7085 if CollideLevel(Dist
, 0) then Exit
;
7088 for y
:= 0 to BOT_MAXJUMP
do
7089 if CollideLevel(Dist
, -y
) then
7098 for yy
:= y
+1 to BOT_MAXJUMP
do
7099 if not CollideLevel(Dist
, -yy
) then
7108 for y
:= 0 to BOT_MAXJUMP
do
7109 if CollideLevel(0, -y
) then
7117 if y
< yy
then Exit
;
7122 function IsSafeTrigger(): Boolean;
7127 if gTriggers
= nil then
7129 for a
:= 0 to High(gTriggers
) do
7130 if Collide(gTriggers
[a
].X
,
7133 gTriggers
[a
].Height
) and
7134 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7135 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7136 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7137 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7138 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7143 // Âîçìîæíî, íàæèìàåì êíîïêó:
7144 if Rnd(16) and IsSafeTrigger() then
7147 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7148 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7150 ReleaseKey(KEY_LEFT
);
7151 ReleaseKey(KEY_RIGHT
);
7155 // Èäåì âëåâî, åñëè íàäî áûëî:
7156 if GetAIFlag('GOLEFT') <> '' then
7158 RemoveAIFlag('GOLEFT');
7159 if CanRunLeft() then
7163 // Èäåì âïðàâî, åñëè íàäî áûëî:
7164 if GetAIFlag('GORIGHT') <> '' then
7166 RemoveAIFlag('GORIGHT');
7167 if CanRunRight() then
7171 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7172 if FObj
.X
< -32 then
7175 if FObj
.X
+32 > gMapInfo
.Width
then
7178 // Ïðûãàåì, åñëè íàäî áûëî:
7179 if GetAIFlag('NEEDJUMP') <> '' then
7182 RemoveAIFlag('NEEDJUMP');
7185 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7186 if GetAIFlag('NEEDSEEUP') <> '' then
7189 ReleaseKey(KEY_DOWN
);
7190 PressKey(KEY_UP
, 20);
7191 RemoveAIFlag('NEEDSEEUP');
7194 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7195 if GetAIFlag('NEEDSEEDOWN') <> '' then
7198 ReleaseKey(KEY_DOWN
);
7199 PressKey(KEY_DOWN
, 20);
7200 RemoveAIFlag('NEEDSEEDOWN');
7203 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7204 if GetAIFlag('GOINHOLE') <> '' then
7205 if not OnGround() then
7207 ReleaseKey(KEY_LEFT
);
7208 ReleaseKey(KEY_RIGHT
);
7209 RemoveAIFlag('GOINHOLE');
7210 SetAIFlag('FALLINHOLE', '1');
7213 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7214 if GetAIFlag('FALLINHOLE') <> '' then
7216 RemoveAIFlag('FALLINHOLE');
7218 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7219 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7220 if GetAIFlag('FALLINHOLE') = '' then
7221 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7227 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7229 CanJumpUp(IfThen(RunDirection() = D_LEFT
, -1, 1)*32) and
7233 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7234 if OnGround() and NearHole() then
7235 if NearDeepHole() then // Åñëè ýòî áåçäíà
7237 0..3: Turn(); // Áåæèì îáðàòíî
7238 4: Jump(); // Ïðûãàåì
7239 5: begin // Ïðûãàåì îáðàòíî
7244 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7245 if GetAIFlag('GOINHOLE') = '' then
7247 0: Turn(); // Íå íóæíî òóäà
7248 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7249 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7250 if BorderHole() then
7251 SetAIFlag('GOINHOLE', '1');
7254 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7255 if (not CanRun()) and OnGround() then
7257 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7258 if CanJumpOver() or OnLadder() then
7260 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7261 if Random(2) = 0 then
7263 if IsSafeTrigger() then
7269 // Îñòàëîñü ìàëî âîçäóõà:
7270 if FAir
< 36 * 2 then
7273 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7274 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7275 if BodyInAcid(0, 0) then
7279 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7281 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7282 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7285 {function TBot.NeedItem(Item: Byte): Byte;
7290 procedure TBot
.SelectWeapon(Dist
: Integer);
7294 function HaveAmmo(weapon
: Byte): Boolean;
7297 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7298 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7299 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7300 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7301 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7302 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7303 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7304 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7305 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7306 else Result
:= True;
7311 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7313 if Dist
> BOT_LONGDIST
then
7314 begin // Äàëüíèé áîé
7316 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7318 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7322 else //if Dist > BOT_UNSAFEDIST then
7323 begin // Áëèæíèé áîé
7325 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7327 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7334 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7336 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7342 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7344 Result
:= inherited PickItem(ItemType
, force
, remove
);
7346 if Result
then SetAIFlag('SELECTWEAPON', '1');
7349 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7351 Result
:= inherited Heal(value
, Soft
);
7354 function TBot
.Healthy(): Byte;
7356 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7357 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7358 else if (FHealth
> 50) then Result
:= 2
7359 else if (FHealth
> 20) then Result
:= 1
7363 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7365 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7366 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7369 procedure TBot
.OnDamage(Angle
: SmallInt);
7377 if (Angle
= 0) or (Angle
= 180) then
7380 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7381 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7383 pla
:= g_Player_Get(FLastSpawnerUID
);
7384 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7385 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7388 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7389 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7391 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7392 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7393 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7398 SetAIFlag('ATTACKLEFT', '1')
7400 SetAIFlag('ATTACKRIGHT', '1');
7404 function TBot
.RunDirection(): TDirection
;
7406 if Abs(Vel
.X
) >= 1 then
7408 if Vel
.X
> 0 then Result
:= D_RIGHT
else Result
:= D_LEFT
;
7410 Result
:= FDirection
;
7413 function TBot
.GetRnd(a
: Byte): Boolean;
7415 if a
= 0 then Result
:= False
7416 else if a
= 255 then Result
:= True
7417 else Result
:= Random(256) > 255-a
;
7420 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7422 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7425 procedure TBot
.SaveState(var Mem
: TBinMemoryWriter
);
7431 inherited SaveState(Mem
);
7433 // Âûáðàííîå îðóæèå:
7434 Mem
.WriteByte(FSelectedWeapon
);
7436 Mem
.WriteWord(FTargetUID
);
7437 // Âðåìÿ ïîòåðè öåëè:
7438 Mem
.WriteDWORD(FLastVisible
);
7439 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7440 dw
:= Length(FAIFlags
);
7443 for i
:= 0 to Integer(dw
)-1 do
7445 Mem
.WriteString(FAIFlags
[i
].Name
, 20);
7446 Mem
.WriteString(FAIFlags
[i
].Value
, 20);
7448 // Íàñòðîéêè ñëîæíîñòè:
7450 Mem
.WriteMemory(p
, SizeOf(TDifficult
));
7453 procedure TBot
.LoadState(var Mem
: TBinMemoryReader
);
7459 inherited LoadState(Mem
);
7461 // Âûáðàííîå îðóæèå:
7462 Mem
.ReadByte(FSelectedWeapon
);
7464 Mem
.ReadWord(FTargetUID
);
7465 // Âðåìÿ ïîòåðè öåëè:
7466 Mem
.ReadDWORD(FLastVisible
);
7467 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7469 SetLength(FAIFlags
, dw
);
7471 for i
:= 0 to Integer(dw
)-1 do
7473 Mem
.ReadString(FAIFlags
[i
].Name
);
7474 Mem
.ReadString(FAIFlags
[i
].Value
);
7476 // Íàñòðîéêè ñëîæíîñòè:
7477 Mem
.ReadMemory(p
, dw
);
7478 if dw
<> SizeOf(TDifficult
) then
7480 raise EBinSizeError
.Create('TBot.LoadState: Wrong FDifficult Size');
7482 FDifficult
:= TDifficult(p
^);