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}
23 e_graphics
, g_playermodel
, g_basic
, g_textures
,
24 g_weapons
, g_phys
, g_sound
, g_saveload
, MAPDEF
,
57 AmmoLimits
: Array [0..1] of Array [A_BULLETS
..A_HIGH
] of Word =
58 ((200, 50, 50, 300, 100),
59 (400, 100, 100, 600, 200));
80 ANGLE_NONE
= Low(SmallInt);
82 CORPSE_STATE_REMOVEME
= 0;
83 CORPSE_STATE_NORMAL
= 1;
84 CORPSE_STATE_MESS
= 2;
86 PLAYER_RECT
: TRectWH
= (X
:15; Y
:12; Width
:34; Height
:52);
87 PLAYER_RECT_CX
= 15+(34 div 2);
88 PLAYER_RECT_CY
= 12+(52 div 2);
89 PLAYER_CORPSERECT
: TRectWH
= (X
:15; Y
:48; Width
:34; Height
:16);
92 PLAYER_HP_LIMIT
= 200;
94 PLAYER_AP_LIMIT
= 200;
97 PLAYER1_DEF_COLOR
: TRGB
= (R
:64; G
:175; B
:48);
98 PLAYER2_DEF_COLOR
: TRGB
= (R
:96; G
:96; B
:96);
114 TPlayerStatArray
= Array of TPlayerStat
;
116 TPlayerSavedState
= record
124 Ammo
: Array [A_BULLETS
..A_HIGH
] of Word;
125 MaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
126 Weapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
127 Rulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
136 TPlayer
= class (TObject
)
144 FDirection
: TDirection
;
152 FMonsterKills
: Integer;
158 FCanJetpack
: Boolean;
164 FNextWeapDelay
: Byte; // frames
165 FBFGFireCounter
: SmallInt;
166 FLastSpawnerUID
: Word;
170 FSpectatePlayer
: Integer;
171 FFirePainTime
: Integer;
174 FSavedState
: TPlayerSavedState
;
176 FModel
: TPlayerModel
;
179 FActionForce
: Boolean;
180 FActionChanged
: Boolean;
182 FFireAngle
: SmallInt;
184 FShellTimer
: Integer;
186 FSawSound
: TPlayableSound
;
187 FSawSoundIdle
: TPlayableSound
;
188 FSawSoundHit
: TPlayableSound
;
189 FSawSoundSelect
: TPlayableSound
;
190 FJetSoundOn
: TPlayableSound
;
191 FJetSoundOff
: TPlayableSound
;
192 FJetSoundFly
: TPlayableSound
;
196 FJustTeleported
: Boolean;
199 function CollideLevel(XInc
, YInc
: Integer): Boolean;
200 function StayOnStep(XInc
, YInc
: Integer): Boolean;
201 function HeadInLiquid(XInc
, YInc
: Integer): Boolean;
202 function BodyInLiquid(XInc
, YInc
: Integer): Boolean;
203 function BodyInAcid(XInc
, YInc
: Integer): Boolean;
204 function FullInLift(XInc
, YInc
: Integer): Integer;
205 {procedure CollideItem();}
206 procedure FlySmoke(Times
: DWORD
= 1);
207 procedure OnFireFlame(Times
: DWORD
= 1);
208 function GetAmmoByWeapon(Weapon
: Byte): Word;
209 procedure SetAction(Action
: Byte; Force
: Boolean = False);
210 procedure OnDamage(Angle
: SmallInt); virtual;
211 function firediry(): Integer;
213 procedure Run(Direction
: TDirection
);
214 procedure NextWeapon();
215 procedure PrevWeapon();
222 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
223 procedure resetWeaponQueue ();
224 function hasAmmoForWeapon (weapon
: Byte): Boolean;
227 FDamageBuffer
: Integer;
229 FAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
230 FMaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
231 FWeapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
232 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
234 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
235 FReloading
: Array [WP_FIRST
..WP_LAST
] of Word;
236 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
237 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
239 FPreferredTeam
: Byte;
242 FWantsInGame
: Boolean;
246 FActualModelName
: string;
253 // debug: viewport offset
254 viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer;
256 function isValidViewPort (): Boolean; inline;
258 constructor Create(); virtual;
259 destructor Destroy(); override;
260 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
261 function GetRespawnPoint(): Byte;
262 procedure PressKey(Key
: Byte; Time
: Word = 1);
263 procedure ReleaseKeys();
264 procedure SetModel(ModelName
: String);
265 procedure SetColor(Color
: TRGB
);
266 procedure SetWeapon(W
: Byte);
267 function IsKeyPressed(K
: Byte): Boolean;
268 function GetKeys(): Byte;
269 function PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean; virtual;
270 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
271 function Collide(Panel
: TPanel
): Boolean; overload
;
272 function Collide(X
, Y
: Integer): Boolean; overload
;
273 procedure SetDirection(Direction
: TDirection
);
274 procedure GetSecret();
275 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
277 procedure Push(vx
, vy
: Integer);
278 procedure ChangeModel(ModelName
: String);
279 procedure SwitchTeam
;
280 procedure ChangeTeam(Team
: Byte);
282 function GetFlag(Flag
: Byte): Boolean;
283 procedure SetFlag(Flag
: Byte);
284 function DropFlag(): Boolean;
285 procedure AllRulez(Health
: Boolean);
286 procedure RestoreHealthArmor();
287 procedure FragCombo();
288 procedure GiveItem(ItemType
: Byte);
289 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
290 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
291 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
292 procedure MakeBloodSimple(Count
: Word);
293 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
294 procedure Reset(Force
: Boolean);
295 procedure Spectate(NoMove
: Boolean = False);
296 procedure SwitchNoClip
;
297 procedure SoftReset();
298 procedure Draw(); virtual;
299 procedure DrawPain();
300 procedure DrawPickup();
301 procedure DrawRulez();
303 procedure DrawBubble();
305 procedure Update(); virtual;
306 procedure RememberState();
307 procedure RecallState();
308 procedure SaveState(var Mem
: TBinMemoryWriter
); virtual;
309 procedure LoadState(var Mem
: TBinMemoryReader
); virtual;
310 procedure PauseSounds(Enable
: Boolean);
311 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
312 procedure DoLerp(Level
: Integer = 2);
313 procedure SetLerp(XTo
, YTo
: Integer);
314 procedure QueueWeaponSwitch(Weapon
: Byte);
315 procedure RealizeCurrentWeapon();
317 procedure JetpackOff
;
318 procedure CatchFire(Attacker
: Word);
320 //WARNING! this does nothing for now, but still call it!
321 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
323 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
326 property Vel
: TPoint2i read FObj
.Vel
;
327 property Obj
: TObj read FObj
;
330 property Name
: String read FName write FName
;
331 property Model
: TPlayerModel read FModel
;
332 property Health
: Integer read FHealth write FHealth
;
333 property Lives
: Byte read FLives write FLives
;
334 property Armor
: Integer read FArmor write FArmor
;
335 property Air
: Integer read FAir write FAir
;
336 property JetFuel
: Integer read FJetFuel write FJetFuel
;
337 property Frags
: Integer read FFrags write FFrags
;
338 property Death
: Integer read FDeath write FDeath
;
339 property Kills
: Integer read FKills write FKills
;
340 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
341 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
342 property Secrets
: Integer read FSecrets
;
343 property GodMode
: Boolean read FGodMode write FGodMode
;
344 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
345 property NoReload
: Boolean read FNoReload write FNoReload
;
346 property alive
: Boolean read FAlive write FAlive
;
347 property Flag
: Byte read FFlag
;
348 property Team
: Byte read FTeam write FTeam
;
349 property Direction
: TDirection read FDirection
;
350 property GameX
: Integer read FObj
.X write FObj
.X
;
351 property GameY
: Integer read FObj
.Y write FObj
.Y
;
352 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
353 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
354 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
355 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
356 property IncCam
: Integer read FIncCam write FIncCam
;
357 property UID
: Word read FUID write FUID
;
358 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
359 property NetTime
: LongWord read FNetTime write FNetTime
;
369 WeaponPrior
: Array [WP_FIRST
..WP_LAST
] of Byte;
370 CloseWeaponPrior
: Array [WP_FIRST
..WP_LAST
] of Byte;
371 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
379 TBot
= class (TPlayer
)
381 FSelectedWeapon
: Byte;
384 FAIFlags
: Array of TAIFlag
;
385 FDifficult
: TDifficult
;
387 function GetRnd(a
: Byte): Boolean;
388 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
389 function RunDirection(): TDirection
;
390 function FullInStep(XInc
, YInc
: Integer): Boolean;
391 //function NeedItem(Item: Byte): Byte;
392 procedure SelectWeapon(Dist
: Integer);
393 procedure SetAIFlag(aName
, fValue
: String20
);
394 function GetAIFlag(aName
: String20
): String20
;
395 procedure RemoveAIFlag(aName
: String20
);
396 function Healthy(): Byte;
397 procedure UpdateMove();
398 procedure UpdateCombat();
399 function KeyPressed(Key
: Word): Boolean;
400 procedure ReleaseKey(Key
: Byte);
401 function TargetOnScreen(TX
, TY
: Integer): Boolean;
402 procedure OnDamage(Angle
: SmallInt); override;
405 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
406 constructor Create(); override;
407 destructor Destroy(); override;
408 procedure Draw(); override;
409 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
410 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
411 procedure Update(); override;
412 procedure SaveState(var Mem
: TBinMemoryWriter
); override;
413 procedure LoadState(var Mem
: TBinMemoryReader
); override;
425 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
427 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
441 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
443 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
446 TCorpse
= class (TObject
)
454 FAnimation
: TAnimation
;
455 FAnimationMask
: TAnimation
;
458 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
459 destructor Destroy(); override;
460 procedure Damage(Value
: Word; vx
, vy
: Integer);
463 procedure SaveState(var Mem
: TBinMemoryWriter
);
464 procedure LoadState(var Mem
: TBinMemoryReader
);
466 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
468 procedure moveBy (dx
, dy
: Integer); inline;
470 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
472 property Obj
: TObj read FObj
;
473 property State
: Byte read FState
;
474 property Mess
: Boolean read FMess
;
477 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
483 gPlayers
: Array of TPlayer
;
484 gCorpses
: Array of TCorpse
;
485 gGibs
: Array of TGib
;
486 gShells
: Array of TShell
;
487 gTeamStat
: TTeamStat
;
488 gFly
: Boolean = False;
489 gAimLine
: Boolean = False;
490 gChatBubble
: Byte = 0;
494 MAX_RUNVEL
: Integer = 8;
495 VEL_JUMP
: Integer = 10;
496 SHELL_TIMEOUT
: Cardinal = 60000;
498 function Lerp(X
, Y
, Factor
: Integer): Integer;
500 procedure g_Gibs_SetMax(Count
: Word);
501 function g_Gibs_GetMax(): Word;
502 procedure g_Corpses_SetMax(Count
: Word);
503 function g_Corpses_GetMax(): Word;
504 procedure g_Shells_SetMax(Count
: Word);
505 function g_Shells_GetMax(): Word;
507 procedure g_Player_Init();
508 procedure g_Player_Free();
509 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
510 function g_Player_CreateFromState(var Mem
: TBinMemoryReader
): Word;
511 procedure g_Player_Remove(UID
: Word);
512 procedure g_Player_ResetTeams();
513 procedure g_Player_UpdateAll();
514 procedure g_Player_DrawAll();
515 procedure g_Player_DrawDebug(p
: TPlayer
);
516 procedure g_Player_DrawHealth();
517 procedure g_Player_RememberAll();
518 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
519 function g_Player_Get(UID
: Word): TPlayer
;
520 function g_Player_GetCount(): Byte;
521 function g_Player_GetStats(): TPlayerStatArray
;
522 function g_Player_ValidName(Name
: String): Boolean;
523 procedure g_Player_CreateCorpse(Player
: TPlayer
);
524 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
525 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
526 procedure g_Player_UpdatePhysicalObjects();
527 procedure g_Player_DrawCorpses();
528 procedure g_Player_DrawShells();
529 procedure g_Player_RemoveAllCorpses();
530 procedure g_Player_Corpses_SaveState(var Mem
: TBinMemoryWriter
);
531 procedure g_Player_Corpses_LoadState(var Mem
: TBinMemoryReader
);
532 procedure g_Bot_Add(Team
, Difficult
: Byte);
533 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1);
534 procedure g_Bot_MixNames();
535 procedure g_Bot_RemoveAll();
540 e_log
, g_map
, g_items
, g_console
, SysUtils
, g_gfx
, Math
,
541 g_options
, g_triggers
, g_menu
, g_game
, g_grid
,
542 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
,
543 g_net
, g_netmsg
, g_window
, GL
, g_holmes
;
553 diag_precision
: Byte;
557 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
558 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
559 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
563 TIME_RESPAWN1
= 1500;
564 TIME_RESPAWN2
= 2000;
565 TIME_RESPAWN3
= 3000;
568 JET_MAX
= 540; // ~30 sec
569 PLAYER_SUIT_TIME
= 30000;
570 PLAYER_INVUL_TIME
= 30000;
571 PLAYER_INVIS_TIME
= 35000;
572 FRAG_COMBO_TIME
= 3000;
576 ANGLE_RIGHTDOWN
= -35;
578 ANGLE_LEFTDOWN
= -145;
579 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
580 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
583 BOT_UNSAFEDIST
= 128;
584 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
586 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
587 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
588 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
589 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
590 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
591 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
592 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
593 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
594 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
595 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
596 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
597 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
598 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
599 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
600 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
601 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
602 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
603 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
604 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
605 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
606 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
607 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
608 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
609 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
610 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
611 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
613 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
614 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
616 BOTNAMES_FILENAME
= 'botnames.txt';
617 BOTLIST_FILENAME
= 'botlist.txt';
621 MaxCorpses
: Word = 20;
622 MaxShells
: Word = 300;
623 CurrentGib
: Integer = 0;
624 CurrentShell
: Integer = 0;
625 BotNames
: Array of String;
626 BotList
: Array of TBotProfile
;
629 function Lerp(X
, Y
, Factor
: Integer): Integer;
631 Result
:= X
+ ((Y
- X
) div Factor
);
634 function SameTeam(UID1
, UID2
: Word): Boolean;
638 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
639 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
641 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
643 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
644 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
646 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
649 procedure g_Gibs_SetMax(Count
: Word);
652 SetLength(gGibs
, Count
);
654 if CurrentGib
>= Count
then
658 function g_Gibs_GetMax(): Word;
663 procedure g_Shells_SetMax(Count
: Word);
666 SetLength(gShells
, Count
);
668 if CurrentShell
>= Count
then
672 function g_Shells_GetMax(): Word;
678 procedure g_Corpses_SetMax(Count
: Word);
681 SetLength(gCorpses
, Count
);
684 function g_Corpses_GetMax(): Word;
686 Result
:= MaxCorpses
;
689 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
699 // Åñòü ëè ìåñòî â gPlayers:
700 if gPlayers
<> nil then
701 for a
:= 0 to High(gPlayers
) do
702 if gPlayers
[a
] = nil then
708 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
711 SetLength(gPlayers
, Length(gPlayers
)+1);
715 // Ñîçäàåì îáúåêò èãðîêà:
717 gPlayers
[a
] := TBot
.Create()
719 gPlayers
[a
] := TPlayer
.Create();
722 gPlayers
[a
].FActualModelName
:= ModelName
;
723 gPlayers
[a
].SetModel(ModelName
);
725 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
726 if gPlayers
[a
].FModel
= nil then
730 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
734 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
735 if Random(2) = 0 then
739 gPlayers
[a
].FPreferredTeam
:= Team
;
741 case gGameSettings
.GameMode
of
742 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
744 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
746 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
749 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
750 gPlayers
[a
].FColor
:= Color
;
751 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
752 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
754 gPlayers
[a
].FModel
.Color
:= Color
;
756 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
757 gPlayers
[a
].FAlive
:= False;
759 Result
:= gPlayers
[a
].FUID
;
762 function g_Player_CreateFromState(var Mem
: TBinMemoryReader
): Word;
775 if sig
<> PLAYER_SIGNATURE
then // 'PLYR'
777 raise EBinSizeError
.Create('g_Player_CreateFromState: Wrong Player Signature');
781 Mem
.ReadBoolean(Bot
);
786 // Åñòü ëè ìåñòî â gPlayers:
787 if gPlayers
<> nil then
788 for a
:= 0 to High(gPlayers
) do
789 if gPlayers
[a
] = nil then
795 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
798 SetLength(gPlayers
, Length(gPlayers
)+1);
802 // Ñîçäàåì îáúåêò èãðîêà:
804 gPlayers
[a
] := TBot
.Create()
806 gPlayers
[a
] := TPlayer
.Create();
807 gPlayers
[a
].FIamBot
:= Bot
;
808 gPlayers
[a
].FPhysics
:= True;
811 Mem
.ReadWord(gPlayers
[a
].FUID
);
813 Mem
.ReadString(gPlayers
[a
].FName
);
815 Mem
.ReadByte(gPlayers
[a
].FTeam
);
816 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
818 Mem
.ReadBoolean(gPlayers
[a
].FAlive
);
819 // Èçðàñõîäîâàë ëè âñå æèçíè:
820 Mem
.ReadBoolean(gPlayers
[a
].FNoRespawn
);
824 gPlayers
[a
].FDirection
:= D_LEFT
826 gPlayers
[a
].FDirection
:= D_RIGHT
;
828 Mem
.ReadInt(gPlayers
[a
].FHealth
);
830 Mem
.ReadByte(gPlayers
[a
].FLives
);
832 Mem
.ReadInt(gPlayers
[a
].FArmor
);
834 Mem
.ReadInt(gPlayers
[a
].FAir
);
836 Mem
.ReadInt(gPlayers
[a
].FJetFuel
);
838 Mem
.ReadInt(gPlayers
[a
].FPain
);
840 Mem
.ReadInt(gPlayers
[a
].FKills
);
842 Mem
.ReadInt(gPlayers
[a
].FMonsterKills
);
844 Mem
.ReadInt(gPlayers
[a
].FFrags
);
846 Mem
.ReadByte(gPlayers
[a
].FFragCombo
);
847 // Âðåìÿ ïîñëåäíåãî ôðàãà:
848 Mem
.ReadDWORD(gPlayers
[a
].FLastFrag
);
850 Mem
.ReadInt(gPlayers
[a
].FDeath
);
852 Mem
.ReadByte(gPlayers
[a
].FFlag
);
854 Mem
.ReadInt(gPlayers
[a
].FSecrets
);
856 Mem
.ReadByte(gPlayers
[a
].FCurrWeap
);
857 // Ñëåäóþùåå æåëàåìîå îðóæèå:
858 Mem
.ReadWord(gPlayers
[a
].FNextWeap
);
860 Mem
.ReadByte(gPlayers
[a
].FNextWeapDelay
);
861 // Âðåìÿ çàðÿäêè BFG:
862 Mem
.ReadSmallInt(gPlayers
[a
].FBFGFireCounter
);
864 Mem
.ReadInt(gPlayers
[a
].FDamageBuffer
);
865 // Ïîñëåäíèé óäàðèâøèé:
866 Mem
.ReadWord(gPlayers
[a
].FLastSpawnerUID
);
867 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
868 Mem
.ReadByte(gPlayers
[a
].FLastHit
);
870 Obj_LoadState(@gPlayers
[a
].FObj
, Mem
);
871 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
872 for i
:= A_BULLETS
to A_HIGH
do
873 Mem
.ReadWord(gPlayers
[a
].FAmmo
[i
]);
874 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
875 for i
:= A_BULLETS
to A_HIGH
do
876 Mem
.ReadWord(gPlayers
[a
].FMaxAmmo
[i
]);
878 for i
:= WP_FIRST
to WP_LAST
do
879 Mem
.ReadBoolean(gPlayers
[a
].FWeapon
[i
]);
880 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
881 for i
:= WP_FIRST
to WP_LAST
do
882 Mem
.ReadWord(gPlayers
[a
].FReloading
[i
]);
886 Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
887 // Íàëè÷èå êðàñíîãî êëþ÷à:
890 Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
891 // Íàëè÷èå çåëåíîãî êëþ÷à:
894 Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
895 // Íàëè÷èå ñèíåãî êëþ÷à:
898 Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
902 Include(gPlayers
[a
].FRulez
, R_BERSERK
);
903 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
904 for i
:= MR_SUIT
to MR_MAX
do
905 Mem
.ReadDWORD(gPlayers
[a
].FMegaRulez
[i
]);
906 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
907 for i
:= T_RESPAWN
to T_FLAGCAP
do
908 Mem
.ReadDWORD(gPlayers
[a
].FTime
[i
]);
911 Mem
.ReadString(gPlayers
[a
].FActualModelName
);
913 Mem
.ReadByte(gPlayers
[a
].FColor
.R
);
914 Mem
.ReadByte(gPlayers
[a
].FColor
.G
);
915 Mem
.ReadByte(gPlayers
[a
].FColor
.B
);
916 // Îáíîâëÿåì ìîäåëü èãðîêà:
917 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
919 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
920 if gPlayers
[a
].FModel
= nil then
924 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
928 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
929 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
930 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
932 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
934 Result
:= gPlayers
[a
].FUID
;
937 procedure g_Player_ResetTeams();
941 if g_Game_IsClient
then
943 if gPlayers
= nil then
945 for a
:= Low(gPlayers
) to High(gPlayers
) do
946 if gPlayers
[a
] <> nil then
947 case gGameSettings
.GameMode
of
949 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
951 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
952 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
953 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
956 gPlayers
[a
].ChangeTeam(TEAM_RED
)
958 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
961 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
965 procedure g_Bot_Add(Team
, Difficult
: Byte);
968 _name
, _model
: String;
971 if not g_Game_IsServer
then Exit
;
973 // Ñïèñîê íàçâàíèé ìîäåëåé:
974 m
:= g_PlayerModel_GetNames();
979 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
980 Team
:= TEAM_COOP
// COOP
982 if gGameSettings
.GameMode
= GM_DM
then
983 Team
:= TEAM_NONE
// DM
985 if Team
= TEAM_NONE
then // CTF / TDM
987 // Àâòîáàëàíñ êîìàíä:
991 for a
:= 0 to High(gPlayers
) do
992 if gPlayers
[a
] <> nil then
994 if gPlayers
[a
].Team
= TEAM_RED
then
997 if gPlayers
[a
].Team
= TEAM_BLUE
then
1007 if Random(2) = 0 then
1013 // Âûáèðàåì áîòó èìÿ:
1015 if BotNames
<> nil then
1016 for a
:= 0 to High(BotNames
) do
1017 if g_Player_ValidName(BotNames
[a
]) then
1019 _name
:= BotNames
[a
];
1023 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
1026 _name
:= Format('DFBOT%.2d', [Random(100)]);
1027 until g_Player_ValidName(_name
);
1029 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1030 _model
:= m
[Random(Length(m
))];
1033 with g_Player_Get(g_Player_Create(_model
,
1034 _RGB(Min(Random(9)*32, 255),
1035 Min(Random(9)*32, 255),
1036 Min(Random(9)*32, 255)),
1037 Team
, True)) as TBot
do
1042 1: FDifficult
:= DIFFICULT_EASY
;
1043 2: FDifficult
:= DIFFICULT_MEDIUM
;
1044 else FDifficult
:= DIFFICULT_HARD
;
1047 for a
:= WP_FIRST
to WP_LAST
do
1049 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1050 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1051 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1054 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1056 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1057 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1062 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1);
1065 _name
, _model
: String;
1068 if not g_Game_IsServer
then Exit
;
1070 // Ñïèñîê íàçâàíèé ìîäåëåé:
1071 m
:= g_PlayerModel_GetNames();
1076 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1077 Team
:= TEAM_COOP
// COOP
1079 if gGameSettings
.GameMode
= GM_DM
then
1080 Team
:= TEAM_NONE
// DM
1082 if Team
= TEAM_NONE
then
1083 Team
:= BotList
[num
].team
; // CTF / TDM
1085 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1086 lName
:= AnsiLowerCase(lName
);
1087 if (num
< 0) or (num
> Length(BotList
)-1) then
1089 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1090 for a
:= 0 to High(BotList
) do
1091 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1100 _name
:= BotList
[num
].name
;
1101 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1102 if not g_Player_ValidName(_name
) then
1104 _name
:= Format('DFBOT%.2d', [Random(100)]);
1105 until g_Player_ValidName(_name
);
1108 _model
:= BotList
[num
].model
;
1109 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1110 if not InSArray(_model
, m
) then
1111 _model
:= m
[Random(Length(m
))];
1114 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1118 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1119 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1120 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1121 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1122 FDifficult
.Cover
:= BotList
[num
].cover
;
1123 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1125 for a
:= WP_FIRST
to WP_LAST
do
1127 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1128 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1129 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1132 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1134 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1138 procedure g_Bot_RemoveAll();
1142 if not g_Game_IsServer
then Exit
;
1143 if gPlayers
= nil then Exit
;
1145 for a
:= 0 to High(gPlayers
) do
1146 if gPlayers
[a
] <> nil then
1147 if gPlayers
[a
] is TBot
then
1149 gPlayers
[a
].Lives
:= 0;
1150 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1151 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1152 g_Player_Remove(gPlayers
[a
].FUID
);
1158 procedure g_Bot_MixNames();
1163 if BotNames
<> nil then
1164 for a
:= 0 to High(BotNames
) do
1166 b
:= Random(Length(BotNames
));
1168 Botnames
[a
] := BotNames
[b
];
1173 procedure g_Player_Remove(UID
: Word);
1177 if gPlayers
= nil then Exit
;
1179 if g_Game_IsServer
and g_Game_IsNet
then
1180 MH_SEND_PlayerDelete(UID
);
1182 for i
:= 0 to High(gPlayers
) do
1183 if gPlayers
[i
] <> nil then
1184 if gPlayers
[i
].FUID
= UID
then
1186 if gPlayers
[i
] is TPlayer
then
1187 TPlayer(gPlayers
[i
]).Free()
1189 TBot(gPlayers
[i
]).Free();
1195 procedure g_Player_Init();
1205 if not FileExists(DataDir
+ BOTNAMES_FILENAME
) then
1208 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1209 AssignFile(F
, DataDir
+ BOTNAMES_FILENAME
);
1220 SetLength(BotNames
, Length(BotNames
)+1);
1221 BotNames
[High(BotNames
)] := s
;
1229 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1230 config
:= TConfig
.CreateFile(DataDir
+ BOTLIST_FILENAME
);
1234 while config
.SectionExists(IntToStr(a
)) do
1236 SetLength(BotList
, Length(BotList
)+1);
1238 with BotList
[High(BotList
)] do
1241 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1243 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1245 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1250 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1251 color
.R
:= StrToIntDef(sa
[0], 0);
1252 color
.G
:= StrToIntDef(sa
[1], 0);
1253 color
.B
:= StrToIntDef(sa
[2], 0);
1254 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1255 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1256 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1257 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1258 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1259 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1260 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1261 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1262 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1263 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1264 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1265 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1266 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1267 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1268 if Length(sa
) = 10 then
1270 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1271 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1272 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1273 if Length(sa
) = 10 then
1275 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1277 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1278 if Length(sa) = 10 then
1280 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1289 procedure g_Player_Free();
1293 if gPlayers
<> nil then
1295 for i
:= 0 to High(gPlayers
) do
1296 if gPlayers
[i
] <> nil then
1298 if gPlayers
[i
] is TPlayer
then
1299 TPlayer(gPlayers
[i
]).Free()
1301 TBot(gPlayers
[i
]).Free();
1312 procedure g_Player_UpdateAll();
1316 if gPlayers
= nil then Exit
;
1318 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1319 for i
:= 0 to High(gPlayers
) do
1321 if gPlayers
[i
] <> nil then
1323 if gPlayers
[i
] is TPlayer
then
1325 gPlayers
[i
].Update();
1326 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1330 // bot updates weapons in `UpdateCombat()`
1331 TBot(gPlayers
[i
]).Update();
1335 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1338 procedure g_Player_DrawAll();
1342 if gPlayers
= nil then Exit
;
1344 for i
:= 0 to High(gPlayers
) do
1345 if gPlayers
[i
] <> nil then
1346 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1347 else TBot(gPlayers
[i
]).Draw();
1350 procedure g_Player_DrawDebug(p
: TPlayer
);
1354 if p
= nil then Exit
;
1355 if (@p
.FObj
) = nil then Exit
;
1357 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1359 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1360 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1361 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1362 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1363 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1364 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1367 procedure g_Player_DrawHealth();
1372 if gPlayers
= nil then Exit
;
1373 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1375 for i
:= 0 to High(gPlayers
) do
1376 if gPlayers
[i
] <> nil then
1378 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1379 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1380 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1381 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1382 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1383 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1387 function g_Player_Get(UID
: Word): TPlayer
;
1393 if gPlayers
= nil then
1396 for a
:= 0 to High(gPlayers
) do
1397 if gPlayers
[a
] <> nil then
1398 if gPlayers
[a
].FUID
= UID
then
1400 Result
:= gPlayers
[a
];
1405 function g_Player_GetCount(): Byte;
1411 if gPlayers
= nil then
1414 for a
:= 0 to High(gPlayers
) do
1415 if gPlayers
[a
] <> nil then
1416 Result
:= Result
+ 1;
1419 function g_Player_GetStats(): TPlayerStatArray
;
1425 if gPlayers
= nil then Exit
;
1427 for a
:= 0 to High(gPlayers
) do
1428 if gPlayers
[a
] <> nil then
1430 SetLength(Result
, Length(Result
)+1);
1431 with Result
[High(Result
)] do
1433 Ping
:= gPlayers
[a
].FPing
;
1434 Loss
:= gPlayers
[a
].FLoss
;
1435 Name
:= gPlayers
[a
].FName
;
1436 Team
:= gPlayers
[a
].FTeam
;
1437 Frags
:= gPlayers
[a
].FFrags
;
1438 Deaths
:= gPlayers
[a
].FDeath
;
1439 Kills
:= gPlayers
[a
].FKills
;
1440 Color
:= gPlayers
[a
].FModel
.Color
;
1441 Lives
:= gPlayers
[a
].FLives
;
1442 Spectator
:= gPlayers
[a
].FSpectator
;
1447 procedure g_Player_RememberAll
;
1451 for i
:= Low(gPlayers
) to High(gPlayers
) do
1452 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1453 gPlayers
[i
].RememberState
;
1456 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1460 gTeamStat
[TEAM_RED
].Goals
:= 0;
1461 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1463 if gPlayers
<> nil then
1464 for i
:= 0 to High(gPlayers
) do
1465 if gPlayers
[i
] <> nil then
1467 gPlayers
[i
].Reset(Force
);
1469 if gPlayers
[i
] is TPlayer
then
1471 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1472 gPlayers
[i
].Respawn(Silent
)
1474 gPlayers
[i
].Spectate();
1477 TBot(gPlayers
[i
]).Respawn(Silent
);
1481 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1486 if Player
.alive
then
1488 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1493 if (FHealth
>= -50) or (gGibsCount
= 0) then
1495 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1499 for find_id
:= 0 to High(gCorpses
) do
1500 if gCorpses
[find_id
] = nil then
1507 find_id
:= Random(Length(gCorpses
));
1509 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1510 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1511 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1512 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1515 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1516 FObj
.Y
+ PLAYER_RECT_CY
,
1517 FModel
.Name
, FModel
.Color
);
1521 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1525 if (gShells
= nil) or (Length(gShells
) = 0) then
1528 with gShells
[CurrentShell
] do
1534 if T
= SHELL_BULLET
then
1536 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1540 Obj
.Rect
.Width
:= 4;
1541 Obj
.Rect
.Height
:= 2;
1545 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1549 Obj
.Rect
.Width
:= 7;
1550 Obj
.Rect
.Height
:= 3;
1556 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1557 positionChanged(); // this updates spatial accelerators
1558 RAngle
:= Random(360);
1559 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1561 if CurrentShell
>= High(gShells
) then
1568 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1571 GibsArray
: TGibsArray
;
1573 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1575 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1578 for a
:= 0 to High(GibsArray
) do
1579 with gGibs
[CurrentGib
] do
1582 ID
:= GibsArray
[a
].ID
;
1583 MaskID
:= GibsArray
[a
].MaskID
;
1586 Obj
.Rect
:= GibsArray
[a
].Rect
;
1587 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1588 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1589 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1590 positionChanged(); // this updates spatial accelerators
1591 RAngle
:= Random(360);
1593 if gBloodCount
> 0 then
1594 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1595 Random(48), Random(48), 150, 0, 0);
1597 if CurrentGib
>= High(gGibs
) then
1604 procedure g_Player_UpdatePhysicalObjects();
1610 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1615 if T
= SHELL_BULLET
then
1616 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1618 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1623 if gGibs
<> nil then
1624 for i
:= 0 to High(gGibs
) do
1625 if gGibs
[i
].alive
then
1629 mr
:= g_Obj_Move(@Obj
, True, False, True);
1630 positionChanged(); // this updates spatial accelerators
1632 if WordBool(mr
and MOVE_FALLOUT
) then
1638 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1639 if WordBool(mr
and MOVE_HITWALL
) then
1640 Obj
.Vel
.X
:= -(vel
.X
div 2);
1641 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1642 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1644 if (Obj
.Vel
.X
>= 0) then
1646 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1647 if RAngle
>= 360 then
1648 RAngle
:= RAngle
mod 360;
1649 end else begin // Counter-clockwise
1650 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1652 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1655 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1656 if gTime
mod (GAME_TICK
*3) = 0 then
1657 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1661 if gCorpses
<> nil then
1662 for i
:= 0 to High(gCorpses
) do
1663 if gCorpses
[i
] <> nil then
1664 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1670 gCorpses
[i
].Update();
1673 if gShells
<> nil then
1674 for i
:= 0 to High(gShells
) do
1675 if gShells
[i
].alive
then
1679 mr
:= g_Obj_Move(@Obj
, True, False, True);
1680 positionChanged(); // this updates spatial accelerators
1682 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1688 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1689 if WordBool(mr
and MOVE_HITWALL
) then
1691 Obj
.Vel
.X
:= -(vel
.X
div 2);
1692 if not WordBool(mr
and MOVE_INWATER
) then
1693 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1695 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1697 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1698 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1699 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1701 if RAngle
mod 90 <> 0 then
1702 RAngle
:= (RAngle
div 90) * 90;
1704 else if not WordBool(mr
and MOVE_INWATER
) then
1705 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1708 if (Obj
.Vel
.X
>= 0) then
1710 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1711 if RAngle
>= 360 then
1712 RAngle
:= RAngle
mod 360;
1713 end else begin // Counter-clockwise
1714 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1716 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1722 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1724 x
:= Obj
.X
+Obj
.Rect
.X
;
1725 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1726 w
:= Obj
.Rect
.Width
;
1727 h
:= Obj
.Rect
.Height
;
1730 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1734 w
:= Obj
.Rect
.Width
;
1735 h
:= Obj
.Rect
.Height
;
1739 procedure TGib
.positionChanged (); inline; begin end;
1740 procedure TShell
.positionChanged (); inline; begin end;
1742 procedure g_Player_DrawCorpses();
1747 if gGibs
<> nil then
1748 for i
:= 0 to High(gGibs
) do
1749 if gGibs
[i
].alive
then
1752 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1755 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1756 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1758 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1761 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1767 if gCorpses
<> nil then
1768 for i
:= 0 to High(gCorpses
) do
1769 if gCorpses
[i
] <> nil then
1773 procedure g_Player_DrawShells();
1778 if gShells
<> nil then
1779 for i
:= 0 to High(gShells
) do
1780 if gShells
[i
].alive
then
1783 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1789 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1793 procedure g_Player_RemoveAllCorpses();
1799 SetLength(gGibs
, MaxGibs
);
1800 SetLength(gShells
, MaxGibs
);
1804 if gCorpses
<> nil then
1805 for i
:= 0 to High(gCorpses
) do
1809 SetLength(gCorpses
, MaxCorpses
);
1812 procedure g_Player_Corpses_SaveState(var Mem
: TBinMemoryWriter
);
1817 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ:
1819 if gCorpses
<> nil then
1820 for i
:= 0 to High(gCorpses
) do
1821 if gCorpses
[i
] <> nil then
1824 Mem
:= TBinMemoryWriter
.Create((count
+1) * 128);
1826 // Êîëè÷åñòâî òðóïîâ:
1827 Mem
.WriteInt(count
);
1833 for i
:= 0 to High(gCorpses
) do
1834 if gCorpses
[i
] <> nil then
1837 Mem
.WriteString(gCorpses
[i
].FModelName
);
1839 b
:= gCorpses
[i
].Mess
;
1840 Mem
.WriteBoolean(b
);
1841 // Ñîõðàíÿåì äàííûå òðóïà:
1842 gCorpses
[i
].SaveState(Mem
);
1846 procedure g_Player_Corpses_LoadState(var Mem
: TBinMemoryReader
);
1855 g_Player_RemoveAllCorpses();
1857 // Êîëè÷åñòâî òðóïîâ:
1860 if count
> Length(gCorpses
) then
1862 raise EBinSizeError
.Create('g_Player_Corpses_LoadState: Too Many Corpses');
1869 for i
:= 0 to count
-1 do
1872 Mem
.ReadString(str
);
1876 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1877 // Çàãðóæàåì äàííûå òðóïà:
1878 gCorpses
[i
].LoadState(Mem
);
1884 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1886 procedure TPlayer
.BFGHit();
1888 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1889 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1890 if g_Game_IsServer
and g_Game_IsNet
then
1891 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1892 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1896 procedure TPlayer
.ChangeModel(ModelName
: string);
1898 locModel
: TPlayerModel
;
1900 locModel
:= g_PlayerModel_Get(ModelName
);
1901 if locModel
= nil then Exit
;
1907 procedure TPlayer
.SetModel(ModelName
: string);
1911 m
:= g_PlayerModel_Get(ModelName
);
1914 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1915 m
:= g_PlayerModel_Get('doomer');
1918 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1923 if FModel
<> nil then
1928 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1929 FModel
.Color
:= FColor
1931 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1932 FModel
.SetWeapon(FCurrWeap
);
1933 FModel
.SetFlag(FFlag
);
1934 SetDirection(FDirection
);
1937 procedure TPlayer
.SetColor(Color
: TRGB
);
1940 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1941 if FModel
<> nil then FModel
.Color
:= Color
;
1944 procedure TPlayer
.SwitchTeam
;
1946 if g_Game_IsClient
then
1948 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
1950 if gGameOn
and FAlive
then
1951 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
1953 if FTeam
= TEAM_RED
then
1955 ChangeTeam(TEAM_BLUE
);
1956 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
1957 if g_Game_IsNet
then
1958 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
1962 ChangeTeam(TEAM_RED
);
1963 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
1964 if g_Game_IsNet
then
1965 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
1967 FPreferredTeam
:= FTeam
;
1970 procedure TPlayer
.ChangeTeam(Team
: Byte);
1977 TEAM_RED
, TEAM_BLUE
:
1978 FModel
.Color
:= TEAMCOLOR
[Team
];
1980 FModel
.Color
:= FColor
;
1982 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
1983 MH_SEND_PlayerStats(FUID
);
1987 procedure TPlayer.CollideItem();
1992 if gItems = nil then Exit;
1993 if not FAlive then Exit;
1995 for i := 0 to High(gItems) do
1998 if (ItemType <> ITEM_NONE) and alive then
1999 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2000 PLAYER_RECT.Height, @Obj) then
2002 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2004 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2005 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2006 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2007 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2008 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2010 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2011 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2012 (gGameSettings.GameType = GT_SINGLE) and
2013 (g_Player_GetCount() > 1)) then
2014 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2020 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2022 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2023 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2027 constructor TPlayer
.Create();
2038 FSawSound
:= TPlayableSound
.Create();
2039 FSawSoundIdle
:= TPlayableSound
.Create();
2040 FSawSoundHit
:= TPlayableSound
.Create();
2041 FSawSoundSelect
:= TPlayableSound
.Create();
2042 FJetSoundFly
:= TPlayableSound
.Create();
2043 FJetSoundOn
:= TPlayableSound
.Create();
2044 FJetSoundOff
:= TPlayableSound
.Create();
2046 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2047 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2048 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2049 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2050 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2051 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2052 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2054 FSpectatePlayer
:= -1;
2058 FSavedState
.WaitRecall
:= False;
2064 FActualModelName
:= 'doomer';
2067 FObj
.Rect
:= PLAYER_RECT
;
2069 FBFGFireCounter
:= -1;
2070 FJustTeleported
:= False;
2076 procedure TPlayer
.positionChanged (); inline;
2080 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2084 if (not g_Game_IsClient
) and (not FAlive
) then
2089 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2090 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2092 if not g_Game_IsClient
then
2095 if t
= HIT_TRAP
then
2097 // Ëîâóøêà óáèâàåò ñðàçó:
2099 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2101 if t
= HIT_SELF
then
2105 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2108 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2109 FMegaRulez
[MR_SUIT
] := 0;
2110 FMegaRulez
[MR_INVUL
] := 0;
2111 FMegaRulez
[MR_INVIS
] := 0;
2115 // Íî îò îñòàëüíîãî ñïàñàåò:
2116 if FMegaRulez
[MR_INVUL
] >= gTime
then
2123 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2124 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2125 (SpawnerUID
= FUID
) or
2126 (not SameTeam(FUID
, SpawnerUID
)) then
2128 FLastSpawnerUID
:= SpawnerUID
;
2130 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2131 if gBloodCount
> 0 then
2133 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2134 if value
div 4 <= c
then
2135 c
:= c
- (value
div 4)
2139 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2143 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2144 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2147 if t
= HIT_WATER
then
2148 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2149 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2154 Inc(FDamageBuffer
, value
);
2158 FPain
:= FPain
+ value
;
2161 if g_Game_IsServer
and g_Game_IsNet
then
2163 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2164 MH_SEND_PlayerStats(FUID
);
2165 MH_SEND_PlayerPos(False, FUID
);
2169 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2172 if g_Game_IsClient
then
2177 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2179 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2182 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2184 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2188 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2189 MH_SEND_PlayerStats(FUID
);
2192 destructor TPlayer
.Destroy();
2194 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2196 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2200 FSawSoundIdle
.Free();
2201 FSawSoundHit
.Free();
2202 FJetSoundFly
.Free();
2204 FJetSoundOff
.Free();
2210 procedure TPlayer
.DrawBubble();
2212 bubX
, bubY
: Integer;
2215 Rw
, Gw
, Bw
: SmallInt;
2218 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= D_LEFT
, -4, 18);
2219 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2227 1: // simple textual non-bubble
2229 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2230 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2231 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2234 2: // advanced pixel-perfect bubble
2236 if FTeam
= TEAM_RED
then
2239 if FTeam
= TEAM_BLUE
then
2242 3: // colored bubble
2244 Rb
:= FModel
.Color
.R
;
2245 Gb
:= FModel
.Color
.G
;
2246 Bb
:= FModel
.Color
.B
;
2247 Rw
:= Min(Rb
* 2 + 64, 255);
2248 Gw
:= Min(Gb
* 2 + 64, 255);
2249 Bw
:= Min(Bb
* 2 + 64, 255);
2250 if (Abs(Rw
- Rb
) < 32)
2251 or (Abs(Gw
- Gb
) < 32)
2252 or (Abs(Bw
- Bb
) < 32) then
2254 Rb
:= Max(Rw
div 2 - 16, 0);
2255 Gb
:= Max(Gw
div 2 - 16, 0);
2256 Bb
:= Max(Bw
div 2 - 16, 0);
2259 4: // custom textured bubble
2261 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2262 if FDirection
= D_RIGHT
then
2263 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2265 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, M_HORIZONTAL
);
2271 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2272 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2274 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2277 Dot
:= IfThen(FDirection
= D_LEFT
, 14, 5);
2278 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2279 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
);
2280 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
);
2281 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
);
2282 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
);
2286 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2287 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2288 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2291 procedure TPlayer
.Draw();
2299 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2300 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2302 e_GetTextureSize(ID
, @w
, @h
);
2303 if FDirection
= D_LEFT
then
2304 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2305 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False)
2307 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2308 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False);
2311 if FMegaRulez
[MR_INVIS
] > gTime
then
2313 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2314 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2316 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2317 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2321 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 200)
2323 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2326 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 254);
2329 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2332 if g_debug_Frames
then
2334 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2336 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2337 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2341 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2343 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2344 if gAimLine
and alive
and
2345 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2350 procedure TPlayer
.DrawAim();
2351 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2355 if isValidViewPort
and (self
= gPlayer1
) then
2357 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2360 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2361 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2363 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2367 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2372 wx
, wy
, xx
, yy
: Integer;
2376 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= D_LEFT
, 7, -7);
2377 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2386 1: begin // Chainsaw
2393 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2394 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2395 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2396 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2401 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2402 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2403 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2404 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2406 4: begin // Double Shotgun
2409 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2410 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2411 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2412 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2414 5: begin // Chaingun
2417 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2418 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2419 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2420 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2422 6: begin // Rocket Launcher
2425 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2426 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2427 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2428 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2430 7: begin // Plasmagun
2433 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2434 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2435 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2436 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2441 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2442 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2443 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2444 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2446 9: begin // Super Chaingun
2449 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2450 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2451 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2452 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2455 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2456 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2457 {$IF DEFINED(D2F_DEBUG)}
2458 drawCast(sz
, wx
, wy
, xx
, yy
);
2460 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2464 procedure TPlayer
.DrawGUI();
2467 X
, Y
, SY
, a
, p
, m
: Integer;
2471 stat
: TPlayerStatArray
;
2473 X
:= gPlayerScreenSize
.X
;
2474 SY
:= gPlayerScreenSize
.Y
;
2477 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2479 if gGameSettings
.GameMode
= GM_CTF
then
2483 if gGameSettings
.GameMode
= GM_CTF
then
2485 s
:= 'TEXTURE_PLAYER_REDFLAG';
2486 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2487 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2488 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2489 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2490 if g_Texture_Get(s
, ID
) then
2491 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2494 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2495 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2496 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2498 if gGameSettings
.GameMode
= GM_CTF
then
2500 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2501 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2502 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2503 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2504 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2505 if g_Texture_Get(s
, ID
) then
2506 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2509 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2510 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2511 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2514 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2515 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2518 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2519 e_Draw(ID
, X
+2, Y
, 0, True, False);
2521 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2525 s
:= IntToStr(Frags
);
2526 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2527 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2532 stat
:= g_Player_GetStats();
2537 for a
:= 0 to High(stat
) do
2538 if stat
[a
].Name
<> Name
then
2540 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2541 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2545 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2546 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2547 s
:= s
+IntToStr(Abs(Frags
-m
));
2549 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2550 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2553 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2555 s
:= IntToStr(Lives
);
2556 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2557 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2561 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2562 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2564 if R_BERSERK
in FRulez
then
2565 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2567 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2569 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2570 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2572 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2573 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2574 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2576 s
:= IntToStr(FArmor
);
2577 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2578 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2580 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2586 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2591 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2593 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2594 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2595 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2596 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2597 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2598 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2599 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2600 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2601 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2604 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2605 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2606 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2608 if R_KEY_RED
in FRulez
then
2609 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2611 if R_KEY_GREEN
in FRulez
then
2612 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2614 if R_KEY_BLUE
in FRulez
then
2615 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2617 if FJetFuel
> 0 then
2619 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2620 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2621 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2622 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2623 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2624 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2628 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2629 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2630 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2633 if gShowPing
and g_Game_IsClient
then
2635 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2636 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2642 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2643 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2644 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2647 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2648 s
:= _lc
[I_PLAYER_SPECT4
];
2649 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2650 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2651 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2657 procedure TPlayer
.DrawRulez();
2661 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2662 if FMegaRulez
[MR_INVUL
] >= gTime
then
2664 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2665 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2670 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2671 191, 191, 191, 0, B_INVERT
);
2674 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2675 if FMegaRulez
[MR_SUIT
] >= gTime
then
2677 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2678 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2683 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2684 0, 96, 0, 200, B_NONE
);
2687 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2688 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2690 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2691 255, 0, 0, 200, B_NONE
);
2695 procedure TPlayer
.DrawPain();
2699 if FPain
= 0 then Exit
;
2703 if a
< 15 then h
:= 0
2704 else if a
< 35 then h
:= 1
2705 else if a
< 55 then h
:= 2
2706 else if a
< 75 then h
:= 3
2707 else if a
< 95 then h
:= 4
2710 //if a > 255 then a := 255;
2712 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2713 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2716 procedure TPlayer
.DrawPickup();
2720 if FPickup
= 0 then Exit
;
2724 if a
< 15 then h
:= 1
2725 else if a
< 35 then h
:= 2
2726 else if a
< 55 then h
:= 3
2727 else if a
< 75 then h
:= 4
2730 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2733 procedure TPlayer
.Fire();
2735 f
, DidFire
: Boolean;
2736 wx
, wy
, xd
, yd
: Integer;
2739 if g_Game_IsClient
then Exit
;
2740 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2741 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2749 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2754 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2755 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2756 xd
:= wx
+IfThen(FDirection
= D_LEFT
, -30, 30);
2757 yd
:= wy
+firediry();
2762 if R_BERSERK
in FRulez
then
2764 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2765 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2766 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2769 locobj
.rect
.Width
:= 39;
2770 locobj
.rect
.Height
:= 52;
2771 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2772 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2773 locobj
.Accel
.X
:= xd
-wx
;
2774 locobj
.Accel
.y
:= yd
-wy
;
2776 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2777 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2779 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2783 FPain
:= min(FPain
+ 25, 50);
2784 end else g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2787 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2792 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2793 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2795 FSawSoundSelect
.Stop();
2797 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2799 else if not FSawSoundHit
.IsPlaying() then
2801 FSawSoundSelect
.Stop();
2802 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2805 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2811 if FAmmo
[A_BULLETS
] > 0 then
2813 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2814 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2815 Dec(FAmmo
[A_BULLETS
]);
2816 FFireAngle
:= FAngle
;
2819 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2820 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2824 if FAmmo
[A_SHELLS
] > 0 then
2826 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2827 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
2828 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2829 Dec(FAmmo
[A_SHELLS
]);
2830 FFireAngle
:= FAngle
;
2834 FShellType
:= SHELL_SHELL
;
2838 if FAmmo
[A_SHELLS
] >= 2 then
2840 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
2841 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2842 Dec(FAmmo
[A_SHELLS
], 2);
2843 FFireAngle
:= FAngle
;
2847 FShellType
:= SHELL_DBLSHELL
;
2851 if FAmmo
[A_BULLETS
] > 0 then
2853 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
2854 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
2855 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2856 Dec(FAmmo
[A_BULLETS
]);
2857 FFireAngle
:= FAngle
;
2860 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2861 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2864 WEAPON_ROCKETLAUNCHER
:
2865 if FAmmo
[A_ROCKETS
] > 0 then
2867 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
2868 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2869 Dec(FAmmo
[A_ROCKETS
]);
2870 FFireAngle
:= FAngle
;
2876 if FAmmo
[A_CELLS
] > 0 then
2878 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
2879 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2880 Dec(FAmmo
[A_CELLS
]);
2881 FFireAngle
:= FAngle
;
2887 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
2889 FBFGFireCounter
:= 17;
2890 if not FNoReload
then
2891 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
2892 Dec(FAmmo
[A_CELLS
], 40);
2896 WEAPON_SUPERPULEMET
:
2897 if FAmmo
[A_SHELLS
] > 0 then
2899 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2900 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
2901 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2902 Dec(FAmmo
[A_SHELLS
]);
2903 FFireAngle
:= FAngle
;
2906 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2907 GameVelX
, GameVelY
-2, SHELL_SHELL
);
2910 WEAPON_FLAMETHROWER
:
2911 if FAmmo
[A_FUEL
] > 0 then
2913 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
2914 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2916 FFireAngle
:= FAngle
;
2922 if g_Game_IsNet
then
2926 if FCurrWeap
<> WEAPON_BFG
then
2927 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
2929 if not FNoReload
then
2930 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
2933 MH_SEND_PlayerStats(FUID
);
2938 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
2939 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
2940 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
2943 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
2946 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
2947 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
2948 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
2949 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
2950 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
2955 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
2957 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
2958 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
2959 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
2962 procedure TPlayer
.JetpackOn
;
2966 FJetSoundOn
.SetPosition(0);
2967 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
2971 procedure TPlayer
.JetpackOff
;
2975 FJetSoundOff
.SetPosition(0);
2976 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
2979 procedure TPlayer
.CatchFire(Attacker
: Word);
2982 FFireAttacker
:= Attacker
;
2983 if g_Game_IsNet
and g_Game_IsServer
then
2984 MH_SEND_PlayerStats(FUID
);
2987 procedure TPlayer
.Jump();
2989 if gFly
or FJetpack
then
2991 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
2992 if FObj
.Vel
.Y
> -VEL_FLY
then
2993 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
2996 if FJetFuel
> 0 then
2998 if (FJetFuel
< 1) and g_Game_IsServer
then
3002 if g_Game_IsNet
then
3003 MH_SEND_PlayerStats(FUID
);
3009 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3011 FCanJetpack
:= False;
3013 // Ïðûãàåì èëè âñïëûâàåì:
3014 if (CollideLevel(0, 1) or
3015 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3016 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3017 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3019 FObj
.Vel
.Y
:= -VEL_JUMP
;
3020 FCanJetpack
:= False;
3024 if BodyInLiquid(0, 0) then
3025 FObj
.Vel
.Y
:= -VEL_SW
3026 else if (FJetFuel
> 0) and FCanJetpack
and
3027 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3031 if g_Game_IsNet
then
3032 MH_SEND_PlayerStats(FUID
);
3037 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3039 a
, i
, k
, ab
, ar
: Byte;
3043 srv
, netsrv
: Boolean;
3049 procedure PushItem(t
: Byte);
3053 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3054 it
:= g_Items_ByIdx(id
);
3055 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3057 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3058 (FObj
.Vel
.Y
div 2)-Random(9));
3059 it
.positionChanged(); // this updates spatial accelerators
3063 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3065 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3066 (FObj
.Vel
.Y
div 2)-Random(6));
3068 else // -3..+3; -3..0
3070 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3071 (FObj
.Vel
.Y
div 2)-Random(4));
3073 it
.positionChanged(); // this updates spatial accelerators
3076 if g_Game_IsNet
and g_Game_IsServer
then
3077 MH_SEND_ItemSpawn(True, id
);
3081 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3082 Srv
:= g_Game_IsServer
;
3083 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3084 if Srv
then FDeath
:= FDeath
+ 1;
3089 if not FPhysics
then
3095 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3097 if FLives
> 0 then FLives
:= FLives
- 1;
3098 if FLives
= 0 then FNoRespawn
:= True;
3101 // Íîìåð òèïà ñìåðòè:
3104 K_SIMPLEKILL
: a
:= 1;
3106 K_EXTRAHARDKILL
: a
:= 3;
3111 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3113 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3120 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3122 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3123 K_EXTRAHARDKILL
, K_FALLKILL
:
3124 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3127 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3131 K_HARDKILL
, K_EXTRAHARDKILL
:
3135 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3136 if (KillType
<> K_FALLKILL
) and (Srv
) then
3137 g_Monsters_killedp();
3139 if SpawnerUID
= FUID
then
3141 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3146 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3149 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3150 begin // Óáèò äðóãèì èãðîêîì
3151 KP
:= g_Player_Get(SpawnerUID
);
3152 if (KP
<> nil) and Srv
then
3154 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3155 if SameTeam(FUID
, SpawnerUID
) then
3165 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3166 Inc(gTeamStat
[KP
.Team
].Goals
,
3167 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3169 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3172 plr
:= g_Player_Get(SpawnerUID
);
3180 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3184 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3188 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3193 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3194 begin // Óáèò ìîíñòðîì
3195 mon
:= g_Monsters_ByUID(SpawnerUID
);
3199 s
:= g_Monsters_GetKilledBy(mon
.MonsterType
);
3203 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3207 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3211 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3216 else // Îñîáûå òèïû ñìåðòè
3219 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3220 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3221 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3222 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3223 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3224 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3230 for a
:= WP_FIRST
to WP_LAST
do
3234 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3235 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3236 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3237 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3238 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3239 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3240 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3241 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3242 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3251 if R_ITEM_BACKPACK
in FRulez
then
3252 PushItem(ITEM_AMMO_BACKPACK
);
3254 // Âûáðîñ ðàêåòíîãî ðàíöà:
3255 if FJetFuel
> 0 then
3256 PushItem(ITEM_JETPACK
);
3259 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3261 if R_KEY_RED
in FRulez
then
3262 PushItem(ITEM_KEY_RED
);
3264 if R_KEY_GREEN
in FRulez
then
3265 PushItem(ITEM_KEY_GREEN
);
3267 if R_KEY_BLUE
in FRulez
then
3268 PushItem(ITEM_KEY_BLUE
);
3275 g_Player_CreateCorpse(Self
);
3277 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3278 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3284 for i
:= Low(gPlayers
) to High(gPlayers
) do
3286 if gPlayers
[i
] = nil then continue
;
3287 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3290 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3291 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3296 OldLR
:= gLMSRespawn
;
3297 if (gGameSettings
.GameMode
= GM_COOP
) then
3301 // everyone is dead, restart the map
3302 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3304 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3305 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3306 gLMSRespawnTime
:= gTime
+ 5000;
3308 else if (a
= 1) then
3310 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3311 if (gPlayers
[k
] = gPlayer1
) or
3312 (gPlayers
[k
] = gPlayer2
) then
3313 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3314 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3315 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3318 else if (gGameSettings
.GameMode
= GM_TDM
) then
3320 if (ab
= 0) and (ar
<> 0) then
3323 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3325 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3326 Inc(gTeamStat
[TEAM_RED
].Goals
);
3327 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3328 gLMSRespawnTime
:= gTime
+ 5000;
3330 else if (ar
= 0) and (ab
<> 0) then
3333 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3335 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3336 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3337 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3338 gLMSRespawnTime
:= gTime
+ 5000;
3340 else if (ar
= 0) and (ab
= 0) then
3343 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3345 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3346 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3347 gLMSRespawnTime
:= gTime
+ 5000;
3350 else if (gGameSettings
.GameMode
= GM_DM
) then
3354 if gPlayers
[k
] <> nil then
3357 // survivor is the winner
3358 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3360 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3363 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3364 gLMSRespawnTime
:= gTime
+ 5000;
3366 else if (a
= 0) then
3368 // everyone is dead, restart the map
3369 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3371 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3372 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3373 gLMSRespawnTime
:= gTime
+ 5000;
3376 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3378 if NetMode
= NET_SERVER
then
3379 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3381 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3387 MH_SEND_PlayerStats(FUID
);
3388 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3389 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3392 if srv
and FNoRespawn
then Spectate(True);
3393 FWantsInGame
:= True;
3396 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3398 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3399 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3402 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3404 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3405 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3408 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3410 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3411 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3412 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3414 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3415 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3416 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3420 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3422 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3423 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3424 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3428 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3430 if g_Game_IsClient
then Exit
;
3431 if Weapon
> High(FWeapon
) then Exit
;
3432 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3435 procedure TPlayer
.resetWeaponQueue ();
3438 FNextWeapDelay
:= 0;
3441 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3445 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3446 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 0);
3447 WEAPON_PISTOL
, WEAPON_CHAINGUN
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_BULLETS
] > 0);
3448 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3449 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3450 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3451 else result
:= (weapon
< length(FWeapon
));
3455 // return 255 for "no switch"
3456 function TPlayer
.getNextWeaponIndex (): Byte;
3459 wantThisWeapon
: array[0..64] of Boolean;
3460 wwc
: Integer = 0; //HACK!
3463 result
:= 255; // default result: "no switch"
3464 // had weapon cycling on previous frame? remove that flag
3465 if (FNextWeap
and $2000) <> 0 then
3467 FNextWeap
:= FNextWeap
and $1FFF;
3468 FNextWeapDelay
:= 0;
3470 // cycling has priority
3471 if (FNextWeap
and $C000) <> 0 then
3473 if (FNextWeap
and $8000) <> 0 then
3477 FNextWeap
:= FNextWeap
or $2000; // we need this
3478 if FNextWeapDelay
> 0 then
3479 exit
; // cooldown time
3481 for i
:= 0 to High(FWeapon
) do
3483 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3484 if FWeapon
[cwi
] then
3486 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d', [FCurrWeap, cwi]), MSG_WARNING);
3487 result
:= Byte(cwi
);
3488 FNextWeapDelay
:= 10;
3496 for i
:= 0 to High(wantThisWeapon
) do
3497 wantThisWeapon
[i
] := false;
3498 for i
:= 0 to High(FWeapon
) do
3499 if (FNextWeap
and (1 shl i
)) <> 0 then
3501 wantThisWeapon
[i
] := true;
3504 // exclude currently selected weapon from the set
3505 wantThisWeapon
[FCurrWeap
] := false;
3506 // slow down alterations a little
3509 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3510 // more than one weapon requested, assume "alteration" and check alteration delay
3511 if FNextWeapDelay
> 0 then
3517 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3518 // but clear all counters if no weapon should be switched
3524 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3525 // try weapons in descending order
3526 for i
:= High(FWeapon
) downto 0 do
3528 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3533 FNextWeapDelay
:= 10; // anyway, 'cause why not
3537 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3541 procedure TPlayer
.RealizeCurrentWeapon();
3542 function switchAllowed (): Boolean;
3547 if FBFGFireCounter
<> -1 then
3549 if FTime
[T_SWITCH
] > gTime
then
3551 for i
:= WP_FIRST
to WP_LAST
do
3552 if FReloading
[i
] > 0 then
3560 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3561 //FNextWeap := FNextWeap and $1FFF;
3562 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3564 if not switchAllowed
then
3566 //HACK for weapon cycling
3567 if (FNextWeap
and $7000) <> 0 then FNextWeap
:= 0;
3571 nw
:= getNextWeaponIndex();
3572 if nw
= 255 then exit
; // don't reset anything here
3573 if nw
> High(FWeapon
) then
3575 // don't forget to reset queue here!
3576 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3584 FTime
[T_SWITCH
] := gTime
+156;
3585 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3586 FModel
.SetWeapon(FCurrWeap
);
3587 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3591 procedure TPlayer
.NextWeapon();
3593 if g_Game_IsClient
then Exit
;
3597 procedure TPlayer
.PrevWeapon();
3599 if g_Game_IsClient
then Exit
;
3603 procedure TPlayer
.SetWeapon(W
: Byte);
3605 if FCurrWeap
<> W
then
3606 if W
= WEAPON_SAW
then
3607 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3610 FModel
.SetWeapon(CurrWeap
);
3614 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3619 if g_Game_IsClient
then Exit
;
3621 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3622 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3627 if FHealth
< PLAYER_HP_SOFT
then
3629 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3633 if gFlash
= 2 then Inc(FPickup
, 5);
3637 if FHealth
< PLAYER_HP_SOFT
then
3639 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3643 if gFlash
= 2 then Inc(FPickup
, 5);
3647 if FArmor
< PLAYER_AP_SOFT
then
3649 FArmor
:= PLAYER_AP_SOFT
;
3652 if gFlash
= 2 then Inc(FPickup
, 5);
3656 if FArmor
< PLAYER_AP_LIMIT
then
3658 FArmor
:= PLAYER_AP_LIMIT
;
3661 if gFlash
= 2 then Inc(FPickup
, 5);
3665 if FHealth
< PLAYER_HP_LIMIT
then
3667 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3671 if gFlash
= 2 then Inc(FPickup
, 5);
3675 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3677 if FHealth
< PLAYER_HP_LIMIT
then
3678 FHealth
:= PLAYER_HP_LIMIT
;
3679 if FArmor
< PLAYER_AP_LIMIT
then
3680 FArmor
:= PLAYER_AP_LIMIT
;
3684 if gFlash
= 2 then Inc(FPickup
, 5);
3688 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3690 FWeapon
[WEAPON_SAW
] := True;
3692 if gFlash
= 2 then Inc(FPickup
, 5);
3693 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3696 ITEM_WEAPON_SHOTGUN1
:
3697 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3699 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3700 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3702 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3703 FWeapon
[WEAPON_SHOTGUN1
] := True;
3705 if gFlash
= 2 then Inc(FPickup
, 5);
3706 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3709 ITEM_WEAPON_SHOTGUN2
:
3710 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3712 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3714 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3715 FWeapon
[WEAPON_SHOTGUN2
] := True;
3717 if gFlash
= 2 then Inc(FPickup
, 5);
3718 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3721 ITEM_WEAPON_CHAINGUN
:
3722 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3724 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3726 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3727 FWeapon
[WEAPON_CHAINGUN
] := True;
3729 if gFlash
= 2 then Inc(FPickup
, 5);
3730 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3733 ITEM_WEAPON_ROCKETLAUNCHER
:
3734 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3736 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3738 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3739 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3741 if gFlash
= 2 then Inc(FPickup
, 5);
3742 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3746 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3748 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3750 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3751 FWeapon
[WEAPON_PLASMA
] := True;
3753 if gFlash
= 2 then Inc(FPickup
, 5);
3754 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3758 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3760 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3762 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3763 FWeapon
[WEAPON_BFG
] := True;
3765 if gFlash
= 2 then Inc(FPickup
, 5);
3766 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3769 ITEM_WEAPON_SUPERPULEMET
:
3770 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3772 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3774 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3775 FWeapon
[WEAPON_SUPERPULEMET
] := True;
3777 if gFlash
= 2 then Inc(FPickup
, 5);
3778 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3781 ITEM_WEAPON_FLAMETHROWER
:
3782 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
3784 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
3786 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3787 FWeapon
[WEAPON_FLAMETHROWER
] := True;
3789 if gFlash
= 2 then Inc(FPickup
, 5);
3790 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3794 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3796 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3799 if gFlash
= 2 then Inc(FPickup
, 5);
3802 ITEM_AMMO_BULLETS_BOX
:
3803 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3805 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3808 if gFlash
= 2 then Inc(FPickup
, 5);
3812 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3814 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3817 if gFlash
= 2 then Inc(FPickup
, 5);
3820 ITEM_AMMO_SHELLS_BOX
:
3821 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3823 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
3826 if gFlash
= 2 then Inc(FPickup
, 5);
3830 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3832 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3835 if gFlash
= 2 then Inc(FPickup
, 5);
3838 ITEM_AMMO_ROCKET_BOX
:
3839 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3841 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
3844 if gFlash
= 2 then Inc(FPickup
, 5);
3848 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3850 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3853 if gFlash
= 2 then Inc(FPickup
, 5);
3857 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3859 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
3862 if gFlash
= 2 then Inc(FPickup
, 5);
3866 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
3868 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3871 if gFlash
= 2 then Inc(FPickup
, 5);
3875 if not(R_ITEM_BACKPACK
in FRulez
) or
3876 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
3877 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
3878 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
3879 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
3880 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
3882 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
3883 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
3884 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
3885 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
3886 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
3888 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3889 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3890 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3891 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3892 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3893 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3894 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3895 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3897 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
3900 if gFlash
= 2 then Inc(FPickup
, 5);
3904 if not(R_KEY_RED
in FRulez
) then
3906 Include(FRulez
, R_KEY_RED
);
3908 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3909 if gFlash
= 2 then Inc(FPickup
, 5);
3910 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3914 if not(R_KEY_GREEN
in FRulez
) then
3916 Include(FRulez
, R_KEY_GREEN
);
3918 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3919 if gFlash
= 2 then Inc(FPickup
, 5);
3920 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3924 if not(R_KEY_BLUE
in FRulez
) then
3926 Include(FRulez
, R_KEY_BLUE
);
3928 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3929 if gFlash
= 2 then Inc(FPickup
, 5);
3930 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3934 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
3936 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
3940 if gFlash
= 2 then Inc(FPickup
, 5);
3944 if FAir
< AIR_MAX
then
3949 if gFlash
= 2 then Inc(FPickup
, 5);
3954 if not (R_BERSERK
in FRulez
) then
3956 Include(FRulez
, R_BERSERK
);
3957 if FBFGFireCounter
= -1 then
3959 FCurrWeap
:= WEAPON_KASTET
;
3961 FModel
.SetWeapon(WEAPON_KASTET
);
3965 if gFlash
= 2 then Inc(FPickup
, 5);
3966 FBerserk
:= gTime
+30000;
3971 if FHealth
< PLAYER_HP_SOFT
then
3973 FHealth
:= PLAYER_HP_SOFT
;
3974 FBerserk
:= gTime
+30000;
3982 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
3984 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
3987 if gFlash
= 2 then Inc(FPickup
, 5);
3991 if FHealth
< PLAYER_HP_LIMIT
then
3993 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
3997 if gFlash
= 2 then Inc(FPickup
, 5);
4001 if FArmor
< PLAYER_AP_LIMIT
then
4003 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4006 if gFlash
= 2 then Inc(FPickup
, 5);
4010 if FJetFuel
< JET_MAX
then
4012 FJetFuel
:= JET_MAX
;
4015 if gFlash
= 2 then Inc(FPickup
, 5);
4019 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4021 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4024 if gFlash
= 2 then Inc(FPickup
, 5);
4029 procedure TPlayer
.Touch();
4033 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4036 // Áðîñèòü ôëàã òîâàðèùó:
4037 if gGameSettings
.GameMode
= GM_CTF
then
4042 procedure TPlayer
.Push(vx
, vy
: Integer);
4044 if (not FPhysics
) and FGhost
then
4046 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4047 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4048 if g_Game_IsNet
and g_Game_IsServer
then
4049 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4052 procedure TPlayer
.Reset(Force
: Boolean);
4058 FTime
[T_RESPAWN
] := 0;
4059 FTime
[T_FLAGCAP
] := 0;
4072 FSpectator
:= False;
4075 FSpectatePlayer
:= -1;
4076 FNoRespawn
:= False;
4078 FLives
:= gGameSettings
.MaxLives
;
4083 procedure TPlayer
.SoftReset();
4089 FBFGFireCounter
:= -1;
4097 SetAction(A_STAND
, True);
4100 function TPlayer
.GetRespawnPoint(): Byte;
4105 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4107 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4108 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4110 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4112 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4113 if Self
= gPlayer1
then
4114 c
:= RESPAWNPOINT_PLAYER1
4116 c
:= RESPAWNPOINT_PLAYER2
;
4117 if g_Map_GetPointCount(c
) > 0 then
4123 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4124 if Self
= gPlayer1
then
4125 c
:= RESPAWNPOINT_PLAYER2
4127 c
:= RESPAWNPOINT_PLAYER1
;
4128 if g_Map_GetPointCount(c
) > 0 then
4135 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4136 if Random(2) = 0 then
4137 c
:= RESPAWNPOINT_PLAYER1
4139 c
:= RESPAWNPOINT_PLAYER2
;
4140 if g_Map_GetPointCount(c
) > 0 then
4147 // Òî÷êà ëþáîé èç êîìàíä
4148 if Random(2) = 0 then
4149 c
:= RESPAWNPOINT_RED
4151 c
:= RESPAWNPOINT_BLUE
;
4152 if g_Map_GetPointCount(c
) > 0 then
4159 c
:= RESPAWNPOINT_DM
;
4160 if g_Map_GetPointCount(c
) > 0 then
4168 if gGameSettings
.GameMode
= GM_DM
then
4171 c
:= RESPAWNPOINT_DM
;
4172 if g_Map_GetPointCount(c
) > 0 then
4178 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4179 if Random(2) = 0 then
4180 c
:= RESPAWNPOINT_PLAYER1
4182 c
:= RESPAWNPOINT_PLAYER2
;
4183 if g_Map_GetPointCount(c
) > 0 then
4189 // Òî÷êà ëþáîé èç êîìàíä
4190 if Random(2) = 0 then
4191 c
:= RESPAWNPOINT_RED
4193 c
:= RESPAWNPOINT_BLUE
;
4194 if g_Map_GetPointCount(c
) > 0 then
4202 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4204 // Òî÷êà ñâîåé êîìàíäû
4205 c
:= RESPAWNPOINT_DM
;
4206 if FTeam
= TEAM_RED
then
4207 c
:= RESPAWNPOINT_RED
;
4208 if FTeam
= TEAM_BLUE
then
4209 c
:= RESPAWNPOINT_BLUE
;
4210 if g_Map_GetPointCount(c
) > 0 then
4217 c
:= RESPAWNPOINT_DM
;
4218 if g_Map_GetPointCount(c
) > 0 then
4224 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4225 if Random(2) = 0 then
4226 c
:= RESPAWNPOINT_PLAYER1
4228 c
:= RESPAWNPOINT_PLAYER2
;
4229 if g_Map_GetPointCount(c
) > 0 then
4235 // Òî÷êà äðóãîé êîìàíäû
4236 c
:= RESPAWNPOINT_DM
;
4237 if FTeam
= TEAM_RED
then
4238 c
:= RESPAWNPOINT_BLUE
;
4239 if FTeam
= TEAM_BLUE
then
4240 c
:= RESPAWNPOINT_RED
;
4241 if g_Map_GetPointCount(c
) > 0 then
4249 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4251 RespawnPoint
: TRespawnPoint
;
4256 if not g_Game_IsServer
then
4260 FWantsInGame
:= True;
4261 FJustTeleported
:= True;
4264 FTime
[T_RESPAWN
] := 0;
4268 // if server changes MaxLives we gotta be ready
4269 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4271 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4272 if FTime
[T_RESPAWN
] > gTime
then
4275 // Ïðîñðàë âñå æèçíè:
4278 if not FSpectator
then Spectate(True);
4279 FWantsInGame
:= True;
4283 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4284 begin // "Ñâîÿ èãðà"
4285 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4286 FRulez
:= FRulez
-[R_BERSERK
];
4288 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4290 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4291 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4294 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4295 c
:= GetRespawnPoint();
4300 // Âîñêðåøåíèå áåç îðóæèÿ:
4303 FHealth
:= PLAYER_HP_SOFT
;
4309 for a
:= WP_FIRST
to WP_LAST
do
4311 FWeapon
[a
] := False;
4315 FWeapon
[WEAPON_PISTOL
] := True;
4316 FWeapon
[WEAPON_KASTET
] := True;
4317 FCurrWeap
:= WEAPON_PISTOL
;
4320 FModel
.SetWeapon(FCurrWeap
);
4322 for b
:= A_BULLETS
to A_HIGH
do
4325 FAmmo
[A_BULLETS
] := 50;
4327 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4328 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4329 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4330 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4331 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4333 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4334 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4339 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4340 if not g_Map_GetPoint(c
, RespawnPoint
) then
4342 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4346 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4347 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4348 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4354 FDirection
:= RespawnPoint
.Direction
;
4355 if FDirection
= D_LEFT
then
4361 FBFGFireCounter
:= -1;
4366 SetAction(A_STAND
, True);
4367 FModel
.Direction
:= FDirection
;
4369 for a
:= Low(FTime
) to High(FTime
) do
4372 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4377 FCanJetpack
:= False;
4382 // Àíèìàöèÿ âîçðîæäåíèÿ:
4383 if (not gLoadGameMode
) and (not Silent
) then
4384 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4386 Anim
:= TAnimation
.Create(ID
, False, 3);
4387 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4388 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4392 FSpectator
:= False;
4395 FSpectatePlayer
:= -1;
4398 if g_Game_IsNet
then
4400 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4401 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4403 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4404 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4409 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4412 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4413 else if (not NoMove
) then
4415 GameX
:= gMapInfo
.Width
div 2;
4416 GameY
:= gMapInfo
.Height
div 2;
4425 FWantsInGame
:= False;
4430 if Self
= gPlayer1
then
4435 if Self
= gPlayer2
then
4442 if g_Game_IsNet
then
4443 MH_SEND_PlayerStats(FUID
);
4446 procedure TPlayer
.SwitchNoClip
;
4450 FGhost
:= not FGhost
;
4451 FPhysics
:= not FGhost
;
4463 procedure TPlayer
.Run(Direction
: TDirection
);
4467 if MAX_RUNVEL
> 8 then
4471 if Direction
= D_LEFT
then
4473 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4474 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4477 if FObj
.Vel
.X
< MAX_RUNVEL
then
4478 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4480 // Âîçìîæíî, ïèíàåì êóñêè:
4481 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4483 b
:= Abs(FObj
.Vel
.X
);
4484 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4485 for a
:= 0 to High(gGibs
) do
4487 if gGibs
[a
].alive
and
4488 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4489 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4492 if FObj
.Vel
.X
< 0 then
4494 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4498 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4500 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4508 procedure TPlayer
.SeeDown();
4510 SetAction(A_SEEDOWN
);
4512 if FDirection
= D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4514 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4517 procedure TPlayer
.SeeUp();
4521 if FDirection
= D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4523 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4526 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4534 A_ATTACK
: Prior
:= 2;
4535 A_SEEUP
: Prior
:= 1;
4536 A_SEEDOWN
: Prior
:= 1;
4537 A_ATTACKUP
: Prior
:= 2;
4538 A_ATTACKDOWN
: Prior
:= 2;
4543 if (Prior
> FActionPrior
) or Force
then
4544 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4546 FActionPrior
:= Prior
;
4547 FActionAnim
:= Action
;
4548 FActionForce
:= Force
;
4549 FActionChanged
:= True;
4552 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4555 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4557 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4558 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4559 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4560 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4563 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4570 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4572 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4573 if g_Game_IsServer
and g_Game_IsNet
then
4574 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4578 FJustTeleported
:= True;
4583 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4585 Anim
:= TAnimation
.Create(ID
, False, 3);
4588 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4589 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4590 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4591 if g_Game_IsServer
and g_Game_IsNet
then
4592 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4593 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4597 FObj
.X
:= X
-PLAYER_RECT
.X
;
4598 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4599 if FAlive
and FGhost
then
4605 if not g_Game_IsNet
then
4609 SetDirection(D_LEFT
);
4615 SetDirection(D_RIGHT
);
4621 if FDirection
= D_RIGHT
then
4623 SetDirection(D_LEFT
);
4628 SetDirection(D_RIGHT
);
4634 if not silent
and (Anim
<> nil) then
4636 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4637 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4640 if g_Game_IsServer
and g_Game_IsNet
then
4641 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4642 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4649 function nonz(a
: Single): Single;
4657 procedure TPlayer
.Update();
4660 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4661 blockmon
, headwater
, dospawn
: Boolean;
4666 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4667 AnyServer
:= g_Game_IsServer
;
4669 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4670 DoLerp(NetInterpLevel
+ 1)
4676 if FClientID
>= 0 then
4678 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4679 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4680 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4689 if FAlive
and (gFly
or FJetpack
) then
4692 if FDirection
= D_LEFT
then
4697 if FAlive
and (not FGhost
) then
4699 if FKeys
[KEY_UP
].Pressed
then
4701 if FKeys
[KEY_DOWN
].Pressed
then
4705 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4708 i
:= g_basic
.Sign(FIncCam
);
4709 FIncCam
:= Abs(FIncCam
);
4710 DecMin(FIncCam
, 5, 0);
4711 FIncCam
:= FIncCam
*i
;
4714 // no need to do that each second frame, weapon queue will take care of it
4715 if FAlive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4716 if FAlive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4718 if gTime
mod (GAME_TICK
*2) <> 0 then
4720 if (FObj
.Vel
.X
= 0) and FAlive
then
4722 if FKeys
[KEY_LEFT
].Pressed
then
4724 if FKeys
[KEY_RIGHT
].Pressed
then
4730 g_Obj_Move(@FObj
, True, True, True);
4731 positionChanged(); // this updates spatial accelerators
4737 FActionChanged
:= False;
4741 // Let alive player do some actions
4742 if FKeys
[KEY_LEFT
].Pressed
then Run(D_LEFT
);
4743 if FKeys
[KEY_RIGHT
].Pressed
then Run(D_RIGHT
);
4744 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
4745 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
4746 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
4747 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
4748 if FKeys
[KEY_JUMP
].Pressed
then Jump()
4751 if AnyServer
and FJetpack
then
4755 if NetServer
then MH_SEND_PlayerStats(FUID
);
4757 FCanJetpack
:= True;
4764 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
4766 if FKeys
[k
].Pressed
then
4774 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4777 if (FTime
[T_RESPAWN
] <= gTime
) and
4778 gGameOn
and (not FAlive
) then
4780 if (g_Player_GetCount() > 1) then
4784 gExit
:= EXIT_RESTART
;
4789 // Dead spectator actions
4792 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
4793 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
4797 if (FSpectatePlayer
>= High(gPlayers
)) then
4798 FSpectatePlayer
:= -1
4802 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
4803 if gPlayers
[I
] <> nil then
4804 if gPlayers
[I
].alive
then
4805 if gPlayers
[I
].UID
<> FUID
then
4807 FSpectatePlayer
:= I
;
4812 if not SetSpect
then FSpectatePlayer
:= -1;
4823 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
4825 FYTo
:= FObj
.Y
- 32;
4826 FSpectatePlayer
:= -1;
4828 if FKeys
[KEY_DOWN
].Pressed
then
4830 FYTo
:= FObj
.Y
+ 32;
4831 FSpectatePlayer
:= -1;
4833 if FKeys
[KEY_LEFT
].Pressed
then
4835 FXTo
:= FObj
.X
- 32;
4836 FSpectatePlayer
:= -1;
4838 if FKeys
[KEY_RIGHT
].Pressed
then
4840 FXTo
:= FObj
.X
+ 32;
4841 FSpectatePlayer
:= -1;
4844 if (FXTo
< -64) then
4846 else if (FXTo
> gMapInfo
.Width
+ 32) then
4847 FXTo
:= gMapInfo
.Width
+ 32;
4848 if (FYTo
< -72) then
4850 else if (FYTo
> gMapInfo
.Height
+ 32) then
4851 FYTo
:= gMapInfo
.Height
+ 32;
4856 g_Obj_Move(@FObj
, True, True, True);
4857 positionChanged(); // this updates spatial accelerators
4864 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
4865 if gPlayers
[FSpectatePlayer
] <> nil then
4866 if gPlayers
[FSpectatePlayer
].alive
then
4868 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
4869 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
4873 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
4874 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
4875 PANEL_BLOCKMON
, True);
4876 headwater
:= HeadInLiquid(0, 0);
4878 // Ñîïðîòèâëåíèå âîçäóõà:
4879 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
4880 if FObj
.Vel
.X
<> 0 then
4881 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
4883 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
4884 DecMin(FPain
, 5, 0);
4885 DecMin(FPickup
, 1, 0);
4887 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
4889 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
4890 FMegaRulez
[MR_SUIT
] := 0;
4891 FMegaRulez
[MR_INVUL
] := 0;
4892 FMegaRulez
[MR_INVIS
] := 0;
4893 Kill(K_FALLKILL
, 0, HIT_FALL
);
4900 if FCurrWeap
= WEAPON_SAW
then
4901 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
4902 FSawSoundSelect
.IsPlaying()) then
4903 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
4906 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
4907 (not FJetSoundOff
.IsPlaying()) then
4909 FJetSoundFly
.SetPosition(0);
4910 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
4913 for b
:= WP_FIRST
to WP_LAST
do
4914 if FReloading
[b
] > 0 then
4920 if FShellTimer
> -1 then
4921 if FShellTimer
= 0 then
4923 if FShellType
= SHELL_SHELL
then
4924 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4925 GameVelX
, GameVelY
-2, SHELL_SHELL
)
4926 else if FShellType
= SHELL_DBLSHELL
then
4928 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4929 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
4930 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4931 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
4934 end else Dec(FShellTimer
);
4936 if (FBFGFireCounter
> -1) then
4937 if FBFGFireCounter
= 0 then
4941 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
4942 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
4943 xd
:= wx
+IfThen(FDirection
= D_LEFT
, -30, 30);
4944 yd
:= wy
+firediry();
4945 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
4946 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
4947 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
4948 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
4949 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
4952 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
4953 FBFGFireCounter
:= -1;
4956 FBFGFireCounter
:= 0
4958 Dec(FBFGFireCounter
);
4960 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
4962 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
4964 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
4967 if (headwater
or blockmon
) then
4973 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
4976 else if (FAir
mod 31 = 0) and not blockmon
then
4978 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
4979 if Random(2) = 0 then
4980 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
4982 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
4984 end else if FAir
< AIR_DEF
then
4987 if FFireTime
> 0 then
4989 if BodyInLiquid(0, 0) then
4994 else if FMegaRulez
[MR_SUIT
] >= gTime
then
4996 if FMegaRulez
[MR_SUIT
] = gTime
then
5003 if FFirePainTime
<= 0 then
5005 if g_Game_IsServer
then
5006 Damage(5, FFireAttacker
, 0, 0, HIT_FLAME
);
5007 FFirePainTime
:= 18;
5009 FFirePainTime
:= FFirePainTime
- 1;
5010 FFireTime
:= FFireTime
- 1;
5011 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5012 MH_SEND_PlayerStats(FUID
);
5016 if FDamageBuffer
> 0 then
5018 if FDamageBuffer
>= 9 then
5022 if FDamageBuffer
< 30 then i
:= 9
5023 else if FDamageBuffer
< 100 then i
:= 18
5027 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5028 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5029 FHealth
:= FHealth
-ii
;
5032 FHealth
:= FHealth
+FArmor
;
5037 if FHealth
<= 0 then
5038 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5039 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5040 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5044 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5045 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5046 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5047 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5054 end; // if FAlive then ...
5056 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5058 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5059 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5060 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5061 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5063 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5064 then SetAction(A_STAND
, True);
5066 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5068 for b
:= Low(FKeys
) to High(FKeys
) do
5069 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5072 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5074 x
:= FObj
.X
+PLAYER_RECT
.X
;
5075 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5076 w
:= PLAYER_RECT
.Width
;
5077 h
:= PLAYER_RECT
.Height
;
5080 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5082 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5083 FObj
.Y
+PLAYER_RECT
.Y
,
5090 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5092 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5093 FObj
.Y
+PLAYER_RECT
.Y
,
5097 Panel
.Width
, Panel
.Height
);
5100 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5102 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5103 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5104 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5105 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5108 function g_Player_ValidName(Name
: string): Boolean;
5114 if gPlayers
= nil then Exit
;
5116 for a
:= 0 to High(gPlayers
) do
5117 if gPlayers
[a
] <> nil then
5118 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5125 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5129 d
:= FModel
.Direction
;
5131 FModel
.Direction
:= Direction
;
5132 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5134 FDirection
:= Direction
;
5137 function TPlayer
.GetKeys(): Byte;
5141 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5142 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5143 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5145 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5146 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5149 procedure TPlayer
.Use();
5153 if FTime
[T_USE
] > gTime
then Exit
;
5155 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5156 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5158 for a
:= 0 to High(gPlayers
) do
5159 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5160 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5161 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5162 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5164 gPlayers
[a
].Touch();
5165 if g_Game_IsNet
and g_Game_IsServer
then
5166 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5169 FTime
[T_USE
] := gTime
+120;
5172 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5176 WX
, WY
, XD
, YD
: Integer;
5187 if R_BERSERK
in FRulez
then
5189 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5190 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5191 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5194 locobj
.rect
.Width
:= 39;
5195 locobj
.rect
.Height
:= 52;
5196 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5197 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5198 locobj
.Accel
.X
:= xd
-wx
;
5199 locobj
.Accel
.y
:= yd
-wy
;
5201 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5202 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5204 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5208 FPain
:= min(FPain
+ 25, 50);
5210 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5215 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5216 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5218 FSawSoundSelect
.Stop();
5220 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5222 else if not FSawSoundHit
.IsPlaying() then
5224 FSawSoundSelect
.Stop();
5225 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5232 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5233 FFireAngle
:= FAngle
;
5235 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5236 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5241 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5242 FFireAngle
:= FAngle
;
5245 FShellType
:= SHELL_SHELL
;
5250 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5251 FFireAngle
:= FAngle
;
5254 FShellType
:= SHELL_DBLSHELL
;
5259 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5260 FFireAngle
:= FAngle
;
5262 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5263 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5266 WEAPON_ROCKETLAUNCHER
:
5268 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5269 FFireAngle
:= FAngle
;
5275 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5276 FFireAngle
:= FAngle
;
5282 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5283 FFireAngle
:= FAngle
;
5287 WEAPON_SUPERPULEMET
:
5289 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5290 FFireAngle
:= FAngle
;
5292 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5293 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5296 WEAPON_FLAMETHROWER
:
5298 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5299 FFireAngle
:= FAngle
;
5306 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5307 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5308 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5311 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5313 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5314 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5317 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5321 if NetInterpLevel
< 1 then
5331 AX
:= Abs(FXTo
- FObj
.X
);
5332 AY
:= Abs(FYTo
- FObj
.Y
);
5333 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5335 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5340 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5342 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5343 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5344 PANEL_LIFTUP
, False) then Result
:= -1
5346 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5347 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5348 PANEL_LIFTDOWN
, False) then Result
:= 1
5352 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5359 if Flag
= FLAG_NONE
then
5362 if not g_Game_IsServer
then Exit
;
5364 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5365 if (Flag
= FTeam
) and
5366 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5367 (FFlag
<> FLAG_NONE
) then
5369 if FFlag
= FLAG_RED
then
5370 s
:= _lc
[I_PLAYER_FLAG_RED
]
5372 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5374 evtype
:= FLAG_STATE_SCORED
;
5376 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5377 Insert('.', ts
, Length(ts
) + 1 - 3);
5378 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5380 g_Map_ResetFlag(FFlag
);
5381 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5383 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5386 if g_Game_IsNet
then
5388 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5392 gFlags
[FFlag
].CaptureTime
:= 0;
5397 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5398 if (Flag
= FTeam
) and
5399 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5401 if Flag
= FLAG_RED
then
5402 s
:= _lc
[I_PLAYER_FLAG_RED
]
5404 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5406 evtype
:= FLAG_STATE_RETURNED
;
5407 gFlags
[Flag
].CaptureTime
:= 0;
5409 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5411 g_Map_ResetFlag(Flag
);
5412 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5415 if g_Game_IsNet
then
5417 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5423 // Ïîäîáðàë ÷óæîé ôëàã:
5424 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5428 if Flag
= FLAG_RED
then
5429 s
:= _lc
[I_PLAYER_FLAG_RED
]
5431 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5433 evtype
:= FLAG_STATE_CAPTURED
;
5435 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5437 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5439 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5442 if g_Game_IsNet
then
5444 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5450 procedure TPlayer
.SetFlag(Flag
: Byte);
5453 if FModel
<> nil then
5454 FModel
.SetFlag(FFlag
);
5457 function TPlayer
.DropFlag(): Boolean;
5462 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5464 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5465 with gFlags
[FFlag
] do
5469 Direction
:= FDirection
;
5470 State
:= FLAG_STATE_DROPPED
;
5472 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5473 (FObj
.Vel
.Y
div 2)-2+Random(5));
5474 positionChanged(); // this updates spatial accelerators
5476 if FFlag
= FLAG_RED
then
5477 s
:= _lc
[I_PLAYER_FLAG_RED
]
5479 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5481 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5482 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5484 if g_Game_IsNet
then
5485 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5491 procedure TPlayer
.GetSecret();
5496 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5498 Assert(Key
<= High(FKeys
));
5500 FKeys
[Key
].Pressed
:= True;
5501 FKeys
[Key
].Time
:= Time
;
5504 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5506 Result
:= FKeys
[K
].Pressed
;
5509 procedure TPlayer
.ReleaseKeys();
5513 for a
:= Low(FKeys
) to High(FKeys
) do
5515 FKeys
[a
].Pressed
:= False;
5520 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5524 function TPlayer
.firediry(): Integer;
5526 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5527 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5531 procedure TPlayer
.RememberState();
5535 FSavedState
.Health
:= FHealth
;
5536 FSavedState
.Armor
:= FArmor
;
5537 FSavedState
.Air
:= FAir
;
5538 FSavedState
.JetFuel
:= FJetFuel
;
5539 FSavedState
.CurrWeap
:= FCurrWeap
;
5540 FSavedState
.NextWeap
:= FNextWeap
;
5541 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5544 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5546 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5548 FSavedState
.Rulez
:= FRulez
;
5549 FSavedState
.WaitRecall
:= True;
5552 procedure TPlayer
.RecallState();
5556 if not FSavedState
.WaitRecall
then Exit
;
5558 FHealth
:= FSavedState
.Health
;
5559 FArmor
:= FSavedState
.Armor
;
5560 FAir
:= FSavedState
.Air
;
5561 FJetFuel
:= FSavedState
.JetFuel
;
5562 FCurrWeap
:= FSavedState
.CurrWeap
;
5563 FNextWeap
:= FSavedState
.NextWeap
;
5564 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5567 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5569 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5571 FRulez
:= FSavedState
.Rulez
;
5572 FSavedState
.WaitRecall
:= False;
5574 if gGameSettings
.GameType
= GT_SERVER
then
5575 MH_SEND_PlayerStats(FUID
);
5578 procedure TPlayer
.SaveState(var Mem
: TBinMemoryWriter
);
5590 Mem
:= TBinMemoryWriter
.Create(i
);
5592 // Ñèãíàòóðà èãðîêà:
5593 sig
:= PLAYER_SIGNATURE
; // 'PLYR'
5594 Mem
.WriteDWORD(sig
);
5596 Mem
.WriteBoolean(FIamBot
);
5598 Mem
.WriteWord(FUID
);
5600 Mem
.WriteString(FName
, 32);
5602 Mem
.WriteByte(FTeam
);
5604 Mem
.WriteBoolean(FAlive
);
5605 // Èçðàñõîäîâàë ëè âñå æèçíè:
5606 Mem
.WriteBoolean(FNoRespawn
);
5608 if FDirection
= D_LEFT
then
5614 Mem
.WriteInt(FHealth
);
5616 Mem
.WriteByte(FLives
);
5618 Mem
.WriteInt(FArmor
);
5622 Mem
.WriteInt(FJetFuel
);
5624 Mem
.WriteInt(FPain
);
5626 Mem
.WriteInt(FKills
);
5628 Mem
.WriteInt(FMonsterKills
);
5630 Mem
.WriteInt(FFrags
);
5632 Mem
.WriteByte(FFragCombo
);
5633 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5634 Mem
.WriteDWORD(FLastFrag
);
5636 Mem
.WriteInt(FDeath
);
5637 // Êàêîé ôëàã íåñåò:
5638 Mem
.WriteByte(FFlag
);
5640 Mem
.WriteInt(FSecrets
);
5642 Mem
.WriteByte(FCurrWeap
);
5644 Mem
.WriteWord(FNextWeap
);
5646 Mem
.WriteByte(FNextWeapDelay
);
5647 // Âðåìÿ çàðÿäêè BFG:
5648 Mem
.WriteSmallInt(FBFGFireCounter
);
5650 Mem
.WriteInt(FDamageBuffer
);
5651 // Ïîñëåäíèé óäàðèâøèé:
5652 Mem
.WriteWord(FLastSpawnerUID
);
5653 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5654 Mem
.WriteByte(FLastHit
);
5656 Obj_SaveState(@FObj
, Mem
);
5657 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5658 for i
:= A_BULLETS
to A_HIGH
do
5659 Mem
.WriteWord(FAmmo
[i
]);
5660 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5661 for i
:= A_BULLETS
to A_HIGH
do
5662 Mem
.WriteWord(FMaxAmmo
[i
]);
5664 for i
:= WP_FIRST
to WP_LAST
do
5665 Mem
.WriteBoolean(FWeapon
[i
]);
5666 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5667 for i
:= WP_FIRST
to WP_LAST
do
5668 Mem
.WriteWord(FReloading
[i
]);
5670 if R_ITEM_BACKPACK
in FRulez
then
5675 // Íàëè÷èå êðàñíîãî êëþ÷à:
5676 if R_KEY_RED
in FRulez
then
5681 // Íàëè÷èå çåëåíîãî êëþ÷à:
5682 if R_KEY_GREEN
in FRulez
then
5687 // Íàëè÷èå ñèíåãî êëþ÷à:
5688 if R_KEY_BLUE
in FRulez
then
5693 // Íàëè÷èå áåðñåðêà:
5694 if R_BERSERK
in FRulez
then
5699 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5700 for i
:= MR_SUIT
to MR_MAX
do
5701 Mem
.WriteDWORD(FMegaRulez
[i
]);
5702 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5703 for i
:= T_RESPAWN
to T_FLAGCAP
do
5704 Mem
.WriteDWORD(FTime
[i
]);
5707 Mem
.WriteString(str
);
5717 procedure TPlayer
.LoadState(var Mem
: TBinMemoryReader
);
5727 // Ñèãíàòóðà èãðîêà:
5729 if sig
<> PLAYER_SIGNATURE
then // 'PLYR'
5731 raise EBinSizeError
.Create('TPlayer.LoadState: Wrong Player Signature');
5734 Mem
.ReadBoolean(FIamBot
);
5738 Mem
.ReadString(str
);
5739 if (Self
<> gPlayer1
) and (Self
<> gPlayer2
) then
5742 Mem
.ReadByte(FTeam
);
5744 Mem
.ReadBoolean(FAlive
);
5745 // Èçðàñõîäîâàë ëè âñå æèçíè:
5746 Mem
.ReadBoolean(FNoRespawn
);
5750 FDirection
:= D_LEFT
5752 FDirection
:= D_RIGHT
;
5754 Mem
.ReadInt(FHealth
);
5756 Mem
.ReadByte(FLives
);
5758 Mem
.ReadInt(FArmor
);
5762 Mem
.ReadInt(FJetFuel
);
5766 Mem
.ReadInt(FKills
);
5768 Mem
.ReadInt(FMonsterKills
);
5770 Mem
.ReadInt(FFrags
);
5772 Mem
.ReadByte(FFragCombo
);
5773 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5774 Mem
.ReadDWORD(FLastFrag
);
5776 Mem
.ReadInt(FDeath
);
5777 // Êàêîé ôëàã íåñåò:
5778 Mem
.ReadByte(FFlag
);
5780 Mem
.ReadInt(FSecrets
);
5782 Mem
.ReadByte(FCurrWeap
);
5784 Mem
.ReadWord(FNextWeap
);
5786 Mem
.ReadByte(FNextWeapDelay
);
5787 // Âðåìÿ çàðÿäêè BFG:
5788 Mem
.ReadSmallInt(FBFGFireCounter
);
5790 Mem
.ReadInt(FDamageBuffer
);
5791 // Ïîñëåäíèé óäàðèâøèé:
5792 Mem
.ReadWord(FLastSpawnerUID
);
5793 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5794 Mem
.ReadByte(FLastHit
);
5796 Obj_LoadState(@FObj
, Mem
);
5797 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5798 for i
:= A_BULLETS
to A_HIGH
do
5799 Mem
.ReadWord(FAmmo
[i
]);
5800 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5801 for i
:= A_BULLETS
to A_HIGH
do
5802 Mem
.ReadWord(FMaxAmmo
[i
]);
5804 for i
:= WP_FIRST
to WP_LAST
do
5805 Mem
.ReadBoolean(FWeapon
[i
]);
5806 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5807 for i
:= WP_FIRST
to WP_LAST
do
5808 Mem
.ReadWord(FReloading
[i
]);
5812 Include(FRulez
, R_ITEM_BACKPACK
);
5813 // Íàëè÷èå êðàñíîãî êëþ÷à:
5816 Include(FRulez
, R_KEY_RED
);
5817 // Íàëè÷èå çåëåíîãî êëþ÷à:
5820 Include(FRulez
, R_KEY_GREEN
);
5821 // Íàëè÷èå ñèíåãî êëþ÷à:
5824 Include(FRulez
, R_KEY_BLUE
);
5825 // Íàëè÷èå áåðñåðêà:
5828 Include(FRulez
, R_BERSERK
);
5829 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5830 for i
:= MR_SUIT
to MR_MAX
do
5831 Mem
.ReadDWORD(FMegaRulez
[i
]);
5832 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5833 for i
:= T_RESPAWN
to T_FLAGCAP
do
5834 Mem
.ReadDWORD(FTime
[i
]);
5836 Mem
.ReadString(str
);
5838 Mem
.ReadByte(FColor
.R
);
5839 Mem
.ReadByte(FColor
.G
);
5840 Mem
.ReadByte(FColor
.B
);
5841 if Self
= gPlayer1
then
5843 str
:= gPlayer1Settings
.Model
;
5844 FColor
:= gPlayer1Settings
.Color
;
5846 if Self
= gPlayer2
then
5848 str
:= gPlayer2Settings
.Model
;
5849 FColor
:= gPlayer2Settings
.Color
;
5851 // Îáíîâëÿåì ìîäåëü èãðîêà:
5853 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
5854 FModel
.Color
:= TEAMCOLOR
[FTeam
]
5856 FModel
.Color
:= FColor
;
5859 procedure TPlayer
.AllRulez(Health
: Boolean);
5865 FHealth
:= PLAYER_HP_LIMIT
;
5866 FArmor
:= PLAYER_AP_LIMIT
;
5870 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
5871 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
5872 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5875 procedure TPlayer
.RestoreHealthArmor();
5877 FHealth
:= PLAYER_HP_LIMIT
;
5878 FArmor
:= PLAYER_AP_LIMIT
;
5881 procedure TPlayer
.FragCombo();
5885 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
5887 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
5889 if FFragCombo
< 5 then
5891 Param
:= FUID
or (FFragCombo
shl 16);
5892 if (FComboEvnt
>= Low(gDelayedEvents
)) and
5893 (FComboEvnt
<= High(gDelayedEvents
)) and
5894 gDelayedEvents
[FComboEvnt
].Pending
and
5895 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
5896 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
5898 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
5899 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
5902 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
5910 procedure TPlayer
.GiveItem(ItemType
: Byte);
5914 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
5916 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
5920 if FAir
< AIR_MAX
then
5927 if not (R_BERSERK
in FRulez
) then
5929 Include(FRulez
, R_BERSERK
);
5930 if FBFGFireCounter
< 1 then
5932 FCurrWeap
:= WEAPON_KASTET
;
5934 FModel
.SetWeapon(WEAPON_KASTET
);
5938 FBerserk
:= gTime
+30000;
5940 if FHealth
< PLAYER_HP_SOFT
then
5942 FHealth
:= PLAYER_HP_SOFT
;
5943 FBerserk
:= gTime
+30000;
5948 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
5950 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
5954 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
5956 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
5960 if FJetFuel
< JET_MAX
then
5962 FJetFuel
:= JET_MAX
;
5965 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
5966 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
5968 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
5969 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5971 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
5973 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
5975 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
5976 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5979 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
5980 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
5981 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
5982 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
5983 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
5984 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
5985 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
5986 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
5987 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
5989 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5990 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
5991 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5992 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
5993 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5994 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
5995 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5996 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
5997 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6000 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6001 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6002 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6003 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6004 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6006 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6007 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6008 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6009 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6010 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6012 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6013 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6014 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6015 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6017 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6020 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6021 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6022 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6024 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6025 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6030 if g_Game_IsNet
and g_Game_IsServer
then
6031 MH_SEND_PlayerStats(FUID
);
6034 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6039 if (Random(5) = 1) and (Times
= 1) then
6042 if BodyInLiquid(0, 0) then
6044 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6045 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6046 if Random(2) = 0 then
6047 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6049 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6053 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6055 for i
:= 1 to Times
do
6057 Anim
:= TAnimation
.Create(id
, False, 3);
6059 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6060 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6066 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6071 if (Random(10) = 1) and (Times
= 1) then
6074 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6076 for i
:= 1 to Times
do
6078 Anim
:= TAnimation
.Create(id
, False, 3);
6080 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6081 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6087 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6089 FSawSound
.Pause(Enable
);
6090 FSawSoundIdle
.Pause(Enable
);
6091 FSawSoundHit
.Pause(Enable
);
6092 FSawSoundSelect
.Pause(Enable
);
6097 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6102 FObj
.Rect
:= PLAYER_CORPSERECT
;
6103 FModelName
:= ModelName
;
6108 FState
:= CORPSE_STATE_MESS
;
6109 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6113 FState
:= CORPSE_STATE_NORMAL
;
6114 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6118 destructor TCorpse
.Destroy();
6125 procedure TCorpse
.positionChanged (); inline; begin end;
6127 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6129 if (dx
<> 0) or (dy
<> 0) then
6138 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6140 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6141 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6142 w
:= PLAYER_CORPSERECT
.Width
;
6143 h
:= PLAYER_CORPSERECT
.Height
;
6146 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6150 if FState
= CORPSE_STATE_REMOVEME
then
6153 FDamage
:= FDamage
+ Value
;
6155 if FDamage
> 150 then
6157 if FAnimation
<> nil then
6162 FState
:= CORPSE_STATE_REMOVEME
;
6164 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6165 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6166 FModelName
, FColor
);
6167 // Çâóê ìÿñà îò òðóïà:
6168 pm
:= g_PlayerModel_Get(FModelName
);
6169 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6175 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6176 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6177 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6178 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6179 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6184 procedure TCorpse
.Draw();
6186 if FState
= CORPSE_STATE_REMOVEME
then
6189 if FAnimation
<> nil then
6190 FAnimation
.Draw(FObj
.X
, FObj
.Y
, M_NONE
);
6192 if FAnimationMask
<> nil then
6195 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, M_NONE
);
6202 procedure TCorpse
.Update();
6206 if FState
= CORPSE_STATE_REMOVEME
then
6209 if gTime
mod (GAME_TICK
*2) <> 0 then
6211 g_Obj_Move(@FObj
, True, True, True);
6212 positionChanged(); // this updates spatial accelerators
6216 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6217 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6219 st
:= g_Obj_Move(@FObj
, True, True, True);
6220 positionChanged(); // this updates spatial accelerators
6222 if WordBool(st
and MOVE_FALLOUT
) then
6224 FState
:= CORPSE_STATE_REMOVEME
;
6228 if FAnimation
<> nil then
6229 FAnimation
.Update();
6230 if FAnimationMask
<> nil then
6231 FAnimationMask
.Update();
6234 procedure TCorpse
.SaveState(var Mem
: TBinMemoryWriter
);
6243 sig
:= CORPSE_SIGNATURE
; // 'CORP'
6244 Mem
.WriteDWORD(sig
);
6246 Mem
.WriteByte(FState
);
6247 // Íàêîïëåííûé óðîí:
6248 Mem
.WriteByte(FDamage
);
6250 Mem
.WriteByte(FColor
.R
);
6251 Mem
.WriteByte(FColor
.G
);
6252 Mem
.WriteByte(FColor
.B
);
6254 Obj_SaveState(@FObj
, Mem
);
6255 // Åñòü ëè àíèìàöèÿ:
6256 anim
:= FAnimation
<> nil;
6257 Mem
.WriteBoolean(anim
);
6258 // Åñëè åñòü - ñîõðàíÿåì:
6260 FAnimation
.SaveState(Mem
);
6261 // Åñòü ëè ìàñêà àíèìàöèè:
6262 anim
:= FAnimationMask
<> nil;
6263 Mem
.WriteBoolean(anim
);
6264 // Åñëè åñòü - ñîõðàíÿåì:
6266 FAnimationMask
.SaveState(Mem
);
6269 procedure TCorpse
.LoadState(var Mem
: TBinMemoryReader
);
6279 if sig
<> CORPSE_SIGNATURE
then // 'CORP'
6281 raise EBinSizeError
.Create('TCorpse.LoadState: Wrong Corpse Signature');
6284 Mem
.ReadByte(FState
);
6285 // Íàêîïëåííûé óðîí:
6286 Mem
.ReadByte(FDamage
);
6288 Mem
.ReadByte(FColor
.R
);
6289 Mem
.ReadByte(FColor
.G
);
6290 Mem
.ReadByte(FColor
.B
);
6292 Obj_LoadState(@FObj
, Mem
);
6293 // Åñòü ëè àíèìàöèÿ:
6294 Mem
.ReadBoolean(anim
);
6295 // Åñëè åñòü - çàãðóæàåì:
6298 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6299 FAnimation
.LoadState(Mem
);
6301 // Åñòü ëè ìàñêà àíèìàöèè:
6302 Mem
.ReadBoolean(anim
);
6303 // Åñëè åñòü - çàãðóæàåì:
6306 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6307 FAnimationMask
.LoadState(Mem
);
6313 constructor TBot
.Create();
6320 FSpectator
:= False;
6327 for a
:= WP_FIRST
to WP_LAST
do
6329 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6330 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6331 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6335 destructor TBot
.Destroy();
6338 inherited Destroy();
6341 procedure TBot
.Draw();
6345 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6346 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6349 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6351 inherited Respawn(Silent
, Force
);
6354 FSelectedWeapon
:= FCurrWeap
;
6359 procedure TBot
.UpdateCombat();
6372 TTargetRecord
= array of TTarget
;
6374 function Compare(a
, b
: TTarget
): Integer;
6376 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6379 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6381 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6382 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6384 if a
.Dist
> b
.Dist
then // B áëèæå
6386 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6389 else // Ñòðàííî -> A
6394 a
, x1
, y1
, x2
, y2
: Integer;
6395 targets
: TTargetRecord
;
6397 Target
, BestTarget
: TTarget
;
6398 firew
, fireh
: Integer;
6402 vsPlayer
, vsMonster
, ok
: Boolean;
6405 function monsUpdate (mon
: TMonster
): Boolean;
6407 result
:= false; // don't stop
6408 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6410 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6412 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6413 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6415 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6416 if g_TraceVector(x1
, y1
, x2
, y2
) then
6418 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6419 SetLength(targets
, Length(targets
)+1);
6420 with targets
[High(targets
)] do
6427 Rect
:= mon
.Obj
.Rect
;
6428 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6429 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6430 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6439 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6440 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6442 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6443 if FCurrWeap
<> FSelectedWeapon
then
6446 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6447 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6449 RemoveAIFlag('NEEDFIRE');
6452 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6453 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6454 else PressKey(KEY_FIRE
);
6458 // Êîîðäèíàòû ñòâîëà:
6459 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6460 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6462 Target
.UID
:= FTargetUID
;
6465 if Target
.UID
<> 0 then
6466 begin // Öåëü åñòü - íàñòðàèâàåì
6467 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6470 tpla
:= g_Player_Get(Target
.UID
);
6474 if (@FObj
) <> nil then
6481 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6482 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6483 Target
.Rect
:= PLAYER_RECT
;
6484 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6485 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6486 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6487 Target
.IsPlayer
:= True;
6491 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6494 mon
:= g_Monsters_ByUID(Target
.UID
);
6497 Target
.X
:= mon
.Obj
.X
;
6498 Target
.Y
:= mon
.Obj
.Y
;
6500 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6501 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6502 Target
.Rect
:= mon
.Obj
.Rect
;
6503 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6504 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6505 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6506 Target
.IsPlayer
:= False;
6513 begin // Öåëè íåò - îáíóëÿåì
6518 Target
.Visible
:= False;
6519 Target
.Line
:= False;
6520 Target
.IsPlayer
:= False;
6525 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6526 if (not Target
.Line
) or (not Target
.Visible
) then
6530 for a
:= 0 to High(gPlayers
) do
6531 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6532 (gPlayers
[a
].FUID
<> FUID
) and
6533 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6534 (not gPlayers
[a
].NoTarget
) and
6535 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6537 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6538 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6541 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6542 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6544 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6545 if g_TraceVector(x1
, y1
, x2
, y2
) then
6547 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6548 SetLength(targets
, Length(targets
)+1);
6549 with targets
[High(targets
)] do
6551 UID
:= gPlayers
[a
].FUID
;
6552 X
:= gPlayers
[a
].FObj
.X
;
6553 Y
:= gPlayers
[a
].FObj
.Y
;
6556 Rect
:= PLAYER_RECT
;
6557 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6558 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6559 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6567 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6570 // Åñëè åñòü âîçìîæíûå öåëè:
6571 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6572 if targets
<> nil then
6574 // Âûáèðàåì íàèëó÷øóþ öåëü:
6575 BestTarget
:= targets
[0];
6576 if Length(targets
) > 1 then
6577 for a
:= 1 to High(targets
) do
6578 if Compare(BestTarget
, targets
[a
]) = 1 then
6579 BestTarget
:= targets
[a
];
6581 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6582 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6583 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6585 Target
:= BestTarget
;
6587 if (Healthy() = 3) or ((Healthy() = 2)) then
6588 begin // Åñëè çäîðîâû - äîãîíÿåì
6589 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6590 SetAIFlag('GORIGHT', '1');
6591 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6592 SetAIFlag('GOLEFT', '1');
6595 begin // Åñëè ïîáèòû - óáåãàåì
6596 if ((RunDirection() = D_LEFT
) and (Target
.X
< FObj
.X
)) then
6597 SetAIFlag('GORIGHT', '1');
6598 if ((RunDirection() = D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6599 SetAIFlag('GOLEFT', '1');
6602 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6603 SelectWeapon(Abs(x1
-Target
.cX
));
6608 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6609 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6610 if Target
.UID
<> 0 then
6612 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6613 Target
.Y
+ Target
.Rect
.Y
) then
6614 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6615 if (Healthy() = 3) or ((Healthy() = 2)) then
6616 begin // Åñëè çäîðîâû - äîãîíÿåì
6617 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6618 SetAIFlag('GORIGHT', '1');
6619 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6620 SetAIFlag('GOLEFT', '1');
6623 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6625 if ((RunDirection() = D_LEFT
) and (Target
.X
< FObj
.X
)) then
6626 SetAIFlag('GORIGHT', '1');
6627 if ((RunDirection() = D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6628 SetAIFlag('GOLEFT', '1');
6632 begin // Öåëü ïîêà íà "ýêðàíå"
6633 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6634 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6635 FLastVisible
:= gTime
;
6636 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6637 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6639 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6640 SetAIFlag('GORIGHT', '1');
6641 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6642 SetAIFlag('GOLEFT', '1');
6646 // Âûáèðàåì óãîë ââåðõ:
6647 if FDirection
= D_LEFT
then
6648 angle
:= ANGLE_LEFTUP
6650 angle
:= ANGLE_RIGHTUP
;
6652 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6653 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6655 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6656 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6657 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6658 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6659 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6660 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6661 begin // òî íóæíî ñòðåëÿòü ââåðõ
6662 SetAIFlag('NEEDFIRE', '1');
6663 SetAIFlag('NEEDSEEUP', '1');
6666 // Âûáèðàåì óãîë âíèç:
6667 if FDirection
= D_LEFT
then
6668 angle
:= ANGLE_LEFTDOWN
6670 angle
:= ANGLE_RIGHTDOWN
;
6672 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6673 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6675 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6676 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6677 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6678 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6679 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6680 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6681 begin // òî íóæíî ñòðåëÿòü âíèç
6682 SetAIFlag('NEEDFIRE', '1');
6683 SetAIFlag('NEEDSEEDOWN', '1');
6686 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6687 if Target
.Visible
and
6688 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6689 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6691 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6692 if ((FDirection
= D_LEFT
) and (Target
.X
< FObj
.X
)) or
6693 ((FDirection
= D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6694 begin // òî íóæíî ñòðåëÿòü âïåðåä
6695 SetAIFlag('NEEDFIRE', '1');
6696 SetAIFlag('NEEDSEEDOWN', '');
6697 SetAIFlag('NEEDSEEUP', '');
6699 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6700 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6701 if GetRnd(FDifficult
.CloseJump
) then
6702 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6703 if Abs(FObj
.X
-Target
.X
) < 128 then
6707 if Random(a
) = 0 then
6708 SetAIFlag('NEEDJUMP', '1');
6712 // Åñëè öåëü âñå åùå åñòü:
6713 if Target
.UID
<> 0 then
6714 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
6715 Target
.UID
:= 0 // òî çàáûòü öåëü
6716 else // Åñëè âèäåëè íåäàâíî
6717 begin // íî öåëü óáèëè
6718 if Target
.IsPlayer
then
6719 begin // Öåëü - èãðîê
6720 pla
:= g_Player_Get(Target
.UID
);
6721 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
6722 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6723 Target
.UID
:= 0; // òî çàáûòü öåëü
6726 begin // Öåëü - ìîíñòð
6727 mon
:= g_Monsters_ByUID(Target
.UID
);
6728 if (mon
= nil) or (not mon
.alive
) then
6729 Target
.UID
:= 0; // òî çàáûòü öåëü
6732 end; // if Target.UID <> 0
6734 FTargetUID
:= Target
.UID
;
6736 // Åñëè âîçìîæíûõ öåëåé íåò:
6737 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
6738 if targets
= nil then
6739 if GetAIFlag('ATTACKLEFT') <> '' then
6740 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
6741 RemoveAIFlag('ATTACKLEFT');
6743 SetAIFlag('NEEDJUMP', '1');
6745 if RunDirection() = D_RIGHT
then
6746 begin // Èäåì íå â òó ñòîðîíó
6747 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6748 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
6749 SetAIFlag('NEEDFIRE', '1');
6750 SetAIFlag('GOLEFT', '1');
6754 begin // Èäåì â íóæíóþ ñòîðîíó
6755 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6756 SetAIFlag('NEEDFIRE', '1');
6757 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6758 SetAIFlag('GORIGHT', '1');
6762 if GetAIFlag('ATTACKRIGHT') <> '' then
6763 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
6764 RemoveAIFlag('ATTACKRIGHT');
6766 SetAIFlag('NEEDJUMP', '1');
6768 if RunDirection() = D_LEFT
then
6769 begin // Èäåì íå â òó ñòîðîíó
6770 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6771 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
6772 SetAIFlag('NEEDFIRE', '1');
6773 SetAIFlag('GORIGHT', '1');
6778 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6779 SetAIFlag('NEEDFIRE', '1');
6780 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6781 SetAIFlag('GOLEFT', '1');
6785 //HACK! (does it belongs there?)
6786 RealizeCurrentWeapon();
6788 // Åñëè åñòü âîçìîæíûå öåëè:
6789 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
6790 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6791 for a
:= 0 to High(targets
) do
6793 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
6794 if GetRnd(FDifficult
.DiagFire
) then
6796 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
6797 if FDirection
= D_LEFT
then
6798 angle
:= ANGLE_LEFTUP
6800 angle
:= ANGLE_RIGHTUP
;
6802 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6803 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6805 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6806 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6807 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6808 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6809 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6811 SetAIFlag('NEEDFIRE', '1');
6812 SetAIFlag('NEEDSEEUP', '1');
6815 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
6816 if FDirection
= D_LEFT
then
6817 angle
:= ANGLE_LEFTDOWN
6819 angle
:= ANGLE_RIGHTDOWN
;
6821 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6822 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6824 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6825 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6826 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6827 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6828 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6830 SetAIFlag('NEEDFIRE', '1');
6831 SetAIFlag('NEEDSEEDOWN', '1');
6835 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
6836 if targets
[a
].Line
and targets
[a
].Visible
and
6837 (((FDirection
= D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
6838 ((FDirection
= D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
6840 SetAIFlag('NEEDFIRE', '1');
6845 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
6846 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
6847 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
6848 40+GetInterval(FDifficult
.Cover
, 40)) then
6849 SetAIFlag('NEEDJUMP', '1');
6851 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
6852 ammo
:= GetAmmoByWeapon(FCurrWeap
);
6853 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
6854 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
6856 SetAIFlag('SELECTWEAPON', '1');
6858 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
6859 if GetAIFlag('SELECTWEAPON') = '1' then
6862 RemoveAIFlag('SELECTWEAPON');
6866 procedure TBot
.Update();
6879 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
6880 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
6882 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
6884 if g_debug_BotAIOff
= 3 then
6894 RealizeCurrentWeapon();
6901 procedure TBot
.ReleaseKey(Key
: Byte);
6910 function TBot
.KeyPressed(Key
: Word): Boolean;
6912 Result
:= FKeys
[Key
].Pressed
;
6915 function TBot
.GetAIFlag(aName
: String20
): String20
;
6921 aName
:= LowerCase(aName
);
6923 if FAIFlags
<> nil then
6924 for a
:= 0 to High(FAIFlags
) do
6925 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6927 Result
:= FAIFlags
[a
].Value
;
6932 procedure TBot
.RemoveAIFlag(aName
: String20
);
6936 if FAIFlags
= nil then Exit
;
6938 aName
:= LowerCase(aName
);
6940 for a
:= 0 to High(FAIFlags
) do
6941 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6943 if a
<> High(FAIFlags
) then
6944 for b
:= a
to High(FAIFlags
)-1 do
6945 FAIFlags
[b
] := FAIFlags
[b
+1];
6947 SetLength(FAIFlags
, Length(FAIFlags
)-1);
6952 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
6960 aName
:= LowerCase(aName
);
6962 if FAIFlags
<> nil then
6963 for a
:= 0 to High(FAIFlags
) do
6964 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6970 if ok
then FAIFlags
[a
].Value
:= fValue
6973 SetLength(FAIFlags
, Length(FAIFlags
)+1);
6974 with FAIFlags
[High(FAIFlags
)] do
6982 procedure TBot
.UpdateMove
;
6984 procedure GoLeft(Time
: Word = 1);
6986 ReleaseKey(KEY_LEFT
);
6987 ReleaseKey(KEY_RIGHT
);
6988 PressKey(KEY_LEFT
, Time
);
6989 SetDirection(D_LEFT
);
6992 procedure GoRight(Time
: Word = 1);
6994 ReleaseKey(KEY_LEFT
);
6995 ReleaseKey(KEY_RIGHT
);
6996 PressKey(KEY_RIGHT
, Time
);
6997 SetDirection(D_RIGHT
);
7000 function Rnd(a
: Word): Boolean;
7002 Result
:= Random(a
) = 0;
7005 procedure Turn(Time
: Word = 1200);
7007 if RunDirection() = D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7012 ReleaseKey(KEY_LEFT
);
7013 ReleaseKey(KEY_RIGHT
);
7016 function CanRunLeft(): Boolean;
7018 Result
:= not CollideLevel(-1, 0);
7021 function CanRunRight(): Boolean;
7023 Result
:= not CollideLevel(1, 0);
7026 function CanRun(): Boolean;
7028 if RunDirection() = D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7031 procedure Jump(Time
: Word = 30);
7033 PressKey(KEY_JUMP
, Time
);
7036 function NearHole(): Boolean;
7040 { TODO 5 : Ëåñòíèöû }
7041 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
7042 for x
:= 1 to PLAYER_RECT
.Width
do
7043 if (not StayOnStep(x
*sx
, 0)) and
7044 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7045 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7054 function BorderHole(): Boolean;
7058 { TODO 5 : Ëåñòíèöû }
7059 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
7060 for x
:= 1 to PLAYER_RECT
.Width
do
7061 if (not StayOnStep(x
*sx
, 0)) and
7062 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7063 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7065 for xx
:= x
to x
+32 do
7066 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7076 function NearDeepHole(): Boolean;
7082 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
7085 for x
:= 1 to PLAYER_RECT
.Width
do
7086 if (not StayOnStep(x
*sx
, 0)) and
7087 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7088 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7090 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7092 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7097 end else Result
:= False;
7100 function OverDeepHole(): Boolean;
7107 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7109 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7116 function OnGround(): Boolean;
7118 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7121 function OnLadder(): Boolean;
7123 Result
:= FullInStep(0, 0);
7126 function BelowLadder(): Boolean;
7128 Result
:= (FullInStep(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7129 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7130 (FullInStep(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7131 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7134 function BelowLiftUp(): Boolean;
7136 Result
:= ((FullInLift(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7137 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7138 ((FullInLift(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7139 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7142 function OnTopLift(): Boolean;
7144 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7147 function CanJumpOver(): Boolean;
7151 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
7155 if not CollideLevel(sx
, 0) then Exit
;
7157 for y
:= 1 to BOT_MAXJUMP
do
7158 if CollideLevel(0, -y
) then Exit
else
7159 if not CollideLevel(sx
, -y
) then
7166 function CanJumpUp(Dist
: ShortInt): Boolean;
7173 if CollideLevel(Dist
, 0) then Exit
;
7176 for y
:= 0 to BOT_MAXJUMP
do
7177 if CollideLevel(Dist
, -y
) then
7186 for yy
:= y
+1 to BOT_MAXJUMP
do
7187 if not CollideLevel(Dist
, -yy
) then
7196 for y
:= 0 to BOT_MAXJUMP
do
7197 if CollideLevel(0, -y
) then
7205 if y
< yy
then Exit
;
7210 function IsSafeTrigger(): Boolean;
7215 if gTriggers
= nil then
7217 for a
:= 0 to High(gTriggers
) do
7218 if Collide(gTriggers
[a
].X
,
7221 gTriggers
[a
].Height
) and
7222 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7223 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7224 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7225 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7226 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7231 // Âîçìîæíî, íàæèìàåì êíîïêó:
7232 if Rnd(16) and IsSafeTrigger() then
7235 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7236 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7238 ReleaseKey(KEY_LEFT
);
7239 ReleaseKey(KEY_RIGHT
);
7243 // Èäåì âëåâî, åñëè íàäî áûëî:
7244 if GetAIFlag('GOLEFT') <> '' then
7246 RemoveAIFlag('GOLEFT');
7247 if CanRunLeft() then
7251 // Èäåì âïðàâî, åñëè íàäî áûëî:
7252 if GetAIFlag('GORIGHT') <> '' then
7254 RemoveAIFlag('GORIGHT');
7255 if CanRunRight() then
7259 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7260 if FObj
.X
< -32 then
7263 if FObj
.X
+32 > gMapInfo
.Width
then
7266 // Ïðûãàåì, åñëè íàäî áûëî:
7267 if GetAIFlag('NEEDJUMP') <> '' then
7270 RemoveAIFlag('NEEDJUMP');
7273 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7274 if GetAIFlag('NEEDSEEUP') <> '' then
7277 ReleaseKey(KEY_DOWN
);
7278 PressKey(KEY_UP
, 20);
7279 RemoveAIFlag('NEEDSEEUP');
7282 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7283 if GetAIFlag('NEEDSEEDOWN') <> '' then
7286 ReleaseKey(KEY_DOWN
);
7287 PressKey(KEY_DOWN
, 20);
7288 RemoveAIFlag('NEEDSEEDOWN');
7291 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7292 if GetAIFlag('GOINHOLE') <> '' then
7293 if not OnGround() then
7295 ReleaseKey(KEY_LEFT
);
7296 ReleaseKey(KEY_RIGHT
);
7297 RemoveAIFlag('GOINHOLE');
7298 SetAIFlag('FALLINHOLE', '1');
7301 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7302 if GetAIFlag('FALLINHOLE') <> '' then
7304 RemoveAIFlag('FALLINHOLE');
7306 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7307 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7308 if GetAIFlag('FALLINHOLE') = '' then
7309 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7315 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7317 CanJumpUp(IfThen(RunDirection() = D_LEFT
, -1, 1)*32) and
7321 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7322 if OnGround() and NearHole() then
7323 if NearDeepHole() then // Åñëè ýòî áåçäíà
7325 0..3: Turn(); // Áåæèì îáðàòíî
7326 4: Jump(); // Ïðûãàåì
7327 5: begin // Ïðûãàåì îáðàòíî
7332 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7333 if GetAIFlag('GOINHOLE') = '' then
7335 0: Turn(); // Íå íóæíî òóäà
7336 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7337 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7338 if BorderHole() then
7339 SetAIFlag('GOINHOLE', '1');
7342 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7343 if (not CanRun()) and OnGround() then
7345 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7346 if CanJumpOver() or OnLadder() then
7348 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7349 if Random(2) = 0 then
7351 if IsSafeTrigger() then
7357 // Îñòàëîñü ìàëî âîçäóõà:
7358 if FAir
< 36 * 2 then
7361 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7362 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7363 if BodyInAcid(0, 0) then
7367 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7369 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7370 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7373 {function TBot.NeedItem(Item: Byte): Byte;
7378 procedure TBot
.SelectWeapon(Dist
: Integer);
7382 function HaveAmmo(weapon
: Byte): Boolean;
7385 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7386 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7387 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7388 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7389 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7390 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7391 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7392 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7393 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7394 else Result
:= True;
7399 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7401 if Dist
> BOT_LONGDIST
then
7402 begin // Äàëüíèé áîé
7404 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7406 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7410 else //if Dist > BOT_UNSAFEDIST then
7411 begin // Áëèæíèé áîé
7413 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7415 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7422 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7424 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7430 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7432 Result
:= inherited PickItem(ItemType
, force
, remove
);
7434 if Result
then SetAIFlag('SELECTWEAPON', '1');
7437 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7439 Result
:= inherited Heal(value
, Soft
);
7442 function TBot
.Healthy(): Byte;
7444 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7445 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7446 else if (FHealth
> 50) then Result
:= 2
7447 else if (FHealth
> 20) then Result
:= 1
7451 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7453 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7454 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7457 procedure TBot
.OnDamage(Angle
: SmallInt);
7465 if (Angle
= 0) or (Angle
= 180) then
7468 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7469 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7471 pla
:= g_Player_Get(FLastSpawnerUID
);
7472 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7473 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7476 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7477 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7479 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7480 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7481 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7486 SetAIFlag('ATTACKLEFT', '1')
7488 SetAIFlag('ATTACKRIGHT', '1');
7492 function TBot
.RunDirection(): TDirection
;
7494 if Abs(Vel
.X
) >= 1 then
7496 if Vel
.X
> 0 then Result
:= D_RIGHT
else Result
:= D_LEFT
;
7498 Result
:= FDirection
;
7501 function TBot
.GetRnd(a
: Byte): Boolean;
7503 if a
= 0 then Result
:= False
7504 else if a
= 255 then Result
:= True
7505 else Result
:= Random(256) > 255-a
;
7508 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7510 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7513 procedure TBot
.SaveState(var Mem
: TBinMemoryWriter
);
7519 inherited SaveState(Mem
);
7521 // Âûáðàííîå îðóæèå:
7522 Mem
.WriteByte(FSelectedWeapon
);
7524 Mem
.WriteWord(FTargetUID
);
7525 // Âðåìÿ ïîòåðè öåëè:
7526 Mem
.WriteDWORD(FLastVisible
);
7527 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7528 dw
:= Length(FAIFlags
);
7531 for i
:= 0 to Integer(dw
)-1 do
7533 Mem
.WriteString(FAIFlags
[i
].Name
, 20);
7534 Mem
.WriteString(FAIFlags
[i
].Value
, 20);
7536 // Íàñòðîéêè ñëîæíîñòè:
7538 Mem
.WriteMemory(p
, SizeOf(TDifficult
));
7541 procedure TBot
.LoadState(var Mem
: TBinMemoryReader
);
7547 inherited LoadState(Mem
);
7549 // Âûáðàííîå îðóæèå:
7550 Mem
.ReadByte(FSelectedWeapon
);
7552 Mem
.ReadWord(FTargetUID
);
7553 // Âðåìÿ ïîòåðè öåëè:
7554 Mem
.ReadDWORD(FLastVisible
);
7555 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7557 SetLength(FAIFlags
, dw
);
7559 for i
:= 0 to Integer(dw
)-1 do
7561 Mem
.ReadString(FAIFlags
[i
].Name
);
7562 Mem
.ReadString(FAIFlags
[i
].Value
);
7564 // Íàñòðîéêè ñëîæíîñòè:
7565 Mem
.ReadMemory(p
, dw
);
7566 if dw
<> SizeOf(TDifficult
) then
7568 raise EBinSizeError
.Create('TBot.LoadState: Wrong FDifficult Size');
7570 FDifficult
:= TDifficult(p
^);