1 (* Copyright (C) DooM 2D:Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
22 e_graphics
, g_playermodel
, g_basic
, g_textures
,
23 g_weapons
, g_phys
, g_sound
, g_saveload
, MAPSTRUCT
,
56 AmmoLimits
: Array [0..1] of Array [A_BULLETS
..A_HIGH
] of Word =
57 ((200, 50, 50, 300, 100),
58 (400, 100, 100, 600, 200));
79 ANGLE_NONE
= Low(SmallInt);
81 CORPSE_STATE_REMOVEME
= 0;
82 CORPSE_STATE_NORMAL
= 1;
83 CORPSE_STATE_MESS
= 2;
85 PLAYER_RECT
: TRectWH
= (X
:15; Y
:12; Width
:34; Height
:52);
86 PLAYER_RECT_CX
= 15+(34 div 2);
87 PLAYER_RECT_CY
= 12+(52 div 2);
88 PLAYER_CORPSERECT
: TRectWH
= (X
:15; Y
:48; Width
:34; Height
:16);
91 PLAYER_HP_LIMIT
= 200;
93 PLAYER_AP_LIMIT
= 200;
96 PLAYER1_DEF_COLOR
: TRGB
= (R
:64; G
:175; B
:48);
97 PLAYER2_DEF_COLOR
: TRGB
= (R
:96; G
:96; B
:96);
113 TPlayerStatArray
= Array of TPlayerStat
;
115 TPlayerSavedState
= record
123 Ammo
: Array [A_BULLETS
..A_HIGH
] of Word;
124 MaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
125 Weapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
126 Rulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
135 TPlayer
= class (TObject
)
143 FDirection
: TDirection
;
151 FMonsterKills
: Integer;
157 FCanJetpack
: Boolean;
163 FNextWeapDelay
: Byte; // frames
164 FBFGFireCounter
: SmallInt;
165 FLastSpawnerUID
: Word;
169 FSpectatePlayer
: Integer;
170 FFirePainTime
: Integer;
173 FSavedState
: TPlayerSavedState
;
175 FModel
: TPlayerModel
;
178 FActionForce
: Boolean;
179 FActionChanged
: Boolean;
181 FFireAngle
: SmallInt;
183 FShellTimer
: Integer;
185 FSawSound
: TPlayableSound
;
186 FSawSoundIdle
: TPlayableSound
;
187 FSawSoundHit
: TPlayableSound
;
188 FSawSoundSelect
: TPlayableSound
;
189 FJetSoundOn
: TPlayableSound
;
190 FJetSoundOff
: TPlayableSound
;
191 FJetSoundFly
: TPlayableSound
;
195 FJustTeleported
: Boolean;
198 function CollideLevel(XInc
, YInc
: Integer): Boolean;
199 function StayOnStep(XInc
, YInc
: Integer): Boolean;
200 function HeadInLiquid(XInc
, YInc
: Integer): Boolean;
201 function BodyInLiquid(XInc
, YInc
: Integer): Boolean;
202 function BodyInAcid(XInc
, YInc
: Integer): Boolean;
203 function FullInLift(XInc
, YInc
: Integer): Integer;
204 {procedure CollideItem();}
205 procedure FlySmoke(Times
: DWORD
= 1);
206 procedure OnFireFlame(Times
: DWORD
= 1);
207 function GetAmmoByWeapon(Weapon
: Byte): Word;
208 procedure SetAction(Action
: Byte; Force
: Boolean = False);
209 procedure OnDamage(Angle
: SmallInt); virtual;
210 function firediry(): Integer;
212 procedure Run(Direction
: TDirection
);
213 procedure NextWeapon();
214 procedure PrevWeapon();
221 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
222 procedure resetWeaponQueue ();
223 function hasAmmoForWeapon (weapon
: Byte): Boolean;
226 FDamageBuffer
: Integer;
228 FAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
229 FMaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
230 FWeapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
231 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
233 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
234 FReloading
: Array [WP_FIRST
..WP_LAST
] of Word;
235 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
236 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
238 FPreferredTeam
: Byte;
241 FWantsInGame
: Boolean;
245 FActualModelName
: string;
252 // debug: viewport offset
253 viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer;
255 function isValidViewPort (): Boolean; inline;
257 constructor Create(); virtual;
258 destructor Destroy(); override;
259 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
260 function GetRespawnPoint(): Byte;
261 procedure PressKey(Key
: Byte; Time
: Word = 1);
262 procedure ReleaseKeys();
263 procedure SetModel(ModelName
: String);
264 procedure SetColor(Color
: TRGB
);
265 procedure SetWeapon(W
: Byte);
266 function IsKeyPressed(K
: Byte): Boolean;
267 function GetKeys(): Byte;
268 function PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean; virtual;
269 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
270 function Collide(Panel
: TPanel
): Boolean; overload
;
271 function Collide(X
, Y
: Integer): Boolean; overload
;
272 procedure SetDirection(Direction
: TDirection
);
273 procedure GetSecret();
274 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
276 procedure Push(vx
, vy
: Integer);
277 procedure ChangeModel(ModelName
: String);
278 procedure SwitchTeam
;
279 procedure ChangeTeam(Team
: Byte);
281 function GetFlag(Flag
: Byte): Boolean;
282 procedure SetFlag(Flag
: Byte);
283 function DropFlag(): Boolean;
284 procedure AllRulez(Health
: Boolean);
285 procedure RestoreHealthArmor();
286 procedure FragCombo();
287 procedure GiveItem(ItemType
: Byte);
288 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
289 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
290 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
291 procedure MakeBloodSimple(Count
: Word);
292 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
293 procedure Reset(Force
: Boolean);
294 procedure Spectate(NoMove
: Boolean = False);
295 procedure SwitchNoClip
;
296 procedure SoftReset();
297 procedure Draw(); virtual;
298 procedure DrawPain();
299 procedure DrawPickup();
300 procedure DrawRulez();
302 procedure DrawBubble();
304 procedure Update(); virtual;
305 procedure RememberState();
306 procedure RecallState();
307 procedure SaveState(var Mem
: TBinMemoryWriter
); virtual;
308 procedure LoadState(var Mem
: TBinMemoryReader
); virtual;
309 procedure PauseSounds(Enable
: Boolean);
310 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
311 procedure DoLerp(Level
: Integer = 2);
312 procedure SetLerp(XTo
, YTo
: Integer);
313 procedure QueueWeaponSwitch(Weapon
: Byte);
314 procedure RealizeCurrentWeapon();
316 procedure JetpackOff
;
317 procedure CatchFire(Attacker
: Word);
319 //WARNING! this does nothing for now, but still call it!
320 procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right!
322 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
324 property Name
: String read FName write FName
;
325 property Model
: TPlayerModel read FModel
;
326 property Health
: Integer read FHealth write FHealth
;
327 property Lives
: Byte read FLives write FLives
;
328 property Armor
: Integer read FArmor write FArmor
;
329 property Air
: Integer read FAir write FAir
;
330 property JetFuel
: Integer read FJetFuel write FJetFuel
;
331 property Frags
: Integer read FFrags write FFrags
;
332 property Death
: Integer read FDeath write FDeath
;
333 property Kills
: Integer read FKills write FKills
;
334 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
335 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
336 property Secrets
: Integer read FSecrets
;
337 property GodMode
: Boolean read FGodMode write FGodMode
;
338 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
339 property NoReload
: Boolean read FNoReload write FNoReload
;
340 property Live
: Boolean read FLive write FLive
;
341 property Flag
: Byte read FFlag
;
342 property Team
: Byte read FTeam write FTeam
;
343 property Direction
: TDirection read FDirection
;
344 property GameX
: Integer read FObj
.X write FObj
.X
;
345 property GameY
: Integer read FObj
.Y write FObj
.Y
;
346 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
347 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
348 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
349 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
350 property Vel
: TPoint2i read FObj
.Vel
;
351 property Obj
: TObj read FObj
;
352 property IncCam
: Integer read FIncCam write FIncCam
;
353 property UID
: Word read FUID write FUID
;
354 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
355 property NetTime
: LongWord read FNetTime write FNetTime
;
365 WeaponPrior
: Array [WP_FIRST
..WP_LAST
] of Byte;
366 CloseWeaponPrior
: Array [WP_FIRST
..WP_LAST
] of Byte;
367 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
375 TBot
= class (TPlayer
)
377 FSelectedWeapon
: Byte;
380 FAIFlags
: Array of TAIFlag
;
381 FDifficult
: TDifficult
;
383 function GetRnd(a
: Byte): Boolean;
384 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
385 function RunDirection(): TDirection
;
386 function FullInStep(XInc
, YInc
: Integer): Boolean;
387 //function NeedItem(Item: Byte): Byte;
388 procedure SelectWeapon(Dist
: Integer);
389 procedure SetAIFlag(aName
, fValue
: String20
);
390 function GetAIFlag(aName
: String20
): String20
;
391 procedure RemoveAIFlag(aName
: String20
);
392 function Healthy(): Byte;
393 procedure UpdateMove();
394 procedure UpdateCombat();
395 function KeyPressed(Key
: Word): Boolean;
396 procedure ReleaseKey(Key
: Byte);
397 function TargetOnScreen(TX
, TY
: Integer): Boolean;
398 procedure OnDamage(Angle
: SmallInt); override;
401 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
402 constructor Create(); override;
403 destructor Destroy(); override;
404 procedure Draw(); override;
405 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
406 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
407 procedure Update(); override;
408 procedure SaveState(var Mem
: TBinMemoryWriter
); override;
409 procedure LoadState(var Mem
: TBinMemoryReader
); override;
420 procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right!
433 procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right!
436 TCorpse
= class (TObject
)
444 FAnimation
: TAnimation
;
445 FAnimationMask
: TAnimation
;
448 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
449 destructor Destroy(); override;
450 procedure Damage(Value
: Word; vx
, vy
: Integer);
453 procedure SaveState(var Mem
: TBinMemoryWriter
);
454 procedure LoadState(var Mem
: TBinMemoryReader
);
456 procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right!
458 property Obj
: TObj read FObj
;
459 property State
: Byte read FState
;
460 property Mess
: Boolean read FMess
;
463 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
469 gPlayers
: Array of TPlayer
;
470 gCorpses
: Array of TCorpse
;
471 gGibs
: Array of TGib
;
472 gShells
: Array of TShell
;
473 gTeamStat
: TTeamStat
;
474 gFly
: Boolean = False;
475 gAimLine
: Boolean = False;
476 gChatBubble
: Byte = 0;
480 MAX_RUNVEL
: Integer = 8;
481 VEL_JUMP
: Integer = 10;
482 SHELL_TIMEOUT
: Cardinal = 60000;
484 function Lerp(X
, Y
, Factor
: Integer): Integer;
486 procedure g_Gibs_SetMax(Count
: Word);
487 function g_Gibs_GetMax(): Word;
488 procedure g_Corpses_SetMax(Count
: Word);
489 function g_Corpses_GetMax(): Word;
490 procedure g_Shells_SetMax(Count
: Word);
491 function g_Shells_GetMax(): Word;
493 procedure g_Player_Init();
494 procedure g_Player_Free();
495 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
496 function g_Player_CreateFromState(var Mem
: TBinMemoryReader
): Word;
497 procedure g_Player_Remove(UID
: Word);
498 procedure g_Player_ResetTeams();
499 procedure g_Player_UpdateAll();
500 procedure g_Player_DrawAll();
501 procedure g_Player_DrawDebug(p
: TPlayer
);
502 procedure g_Player_DrawHealth();
503 procedure g_Player_RememberAll();
504 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
505 function g_Player_Get(UID
: Word): TPlayer
;
506 function g_Player_GetCount(): Byte;
507 function g_Player_GetStats(): TPlayerStatArray
;
508 function g_Player_ValidName(Name
: String): Boolean;
509 procedure g_Player_CreateCorpse(Player
: TPlayer
);
510 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
511 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
512 procedure g_Player_UpdatePhysicalObjects();
513 procedure g_Player_DrawCorpses();
514 procedure g_Player_DrawShells();
515 procedure g_Player_RemoveAllCorpses();
516 procedure g_Player_Corpses_SaveState(var Mem
: TBinMemoryWriter
);
517 procedure g_Player_Corpses_LoadState(var Mem
: TBinMemoryReader
);
518 procedure g_Bot_Add(Team
, Difficult
: Byte);
519 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1);
520 procedure g_Bot_MixNames();
521 procedure g_Bot_RemoveAll();
526 e_log
, g_map
, g_items
, g_console
, SysUtils
, g_gfx
, Math
,
527 g_options
, g_triggers
, g_menu
, MAPDEF
, g_game
, g_grid
,
528 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
,
529 g_net
, g_netmsg
, g_window
, GL
, g_holmes
;
539 diag_precision
: Byte;
543 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
544 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
545 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
549 TIME_RESPAWN1
= 1500;
550 TIME_RESPAWN2
= 2000;
551 TIME_RESPAWN3
= 3000;
554 JET_MAX
= 540; // ~30 sec
555 PLAYER_SUIT_TIME
= 30000;
556 PLAYER_INVUL_TIME
= 30000;
557 PLAYER_INVIS_TIME
= 35000;
558 FRAG_COMBO_TIME
= 3000;
562 ANGLE_RIGHTDOWN
= -35;
564 ANGLE_LEFTDOWN
= -145;
565 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
566 WEAPONPOINT
: Array [TDirection
] of TPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
569 BOT_UNSAFEDIST
= 128;
570 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
572 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
573 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
574 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
575 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
576 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
577 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
578 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
579 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
580 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
581 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
582 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
583 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
584 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
585 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
586 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
587 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
588 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
589 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
590 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
591 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
592 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
593 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
594 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
595 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
596 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
597 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
599 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
600 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
602 BOTNAMES_FILENAME
= 'botnames.txt';
603 BOTLIST_FILENAME
= 'botlist.txt';
607 MaxCorpses
: Word = 20;
608 MaxShells
: Word = 300;
609 CurrentGib
: Integer = 0;
610 CurrentShell
: Integer = 0;
611 BotNames
: Array of String;
612 BotList
: Array of TBotProfile
;
615 procedure TGib
.positionChanged (); begin end;
616 procedure TShell
.positionChanged (); begin end;
619 function Lerp(X
, Y
, Factor
: Integer): Integer;
621 Result
:= X
+ ((Y
- X
) div Factor
);
624 function SameTeam(UID1
, UID2
: Word): Boolean;
628 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
629 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
631 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
633 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
634 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
636 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
639 procedure g_Gibs_SetMax(Count
: Word);
642 SetLength(gGibs
, Count
);
644 if CurrentGib
>= Count
then
648 function g_Gibs_GetMax(): Word;
653 procedure g_Shells_SetMax(Count
: Word);
656 SetLength(gShells
, Count
);
658 if CurrentShell
>= Count
then
662 function g_Shells_GetMax(): Word;
668 procedure g_Corpses_SetMax(Count
: Word);
671 SetLength(gCorpses
, Count
);
674 function g_Corpses_GetMax(): Word;
676 Result
:= MaxCorpses
;
679 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
689 // Åñòü ëè ìåñòî â gPlayers:
690 if gPlayers
<> nil then
691 for a
:= 0 to High(gPlayers
) do
692 if gPlayers
[a
] = nil then
698 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
701 SetLength(gPlayers
, Length(gPlayers
)+1);
705 // Ñîçäàåì îáúåêò èãðîêà:
707 gPlayers
[a
] := TBot
.Create()
709 gPlayers
[a
] := TPlayer
.Create();
712 gPlayers
[a
].FActualModelName
:= ModelName
;
713 gPlayers
[a
].SetModel(ModelName
);
715 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
716 if gPlayers
[a
].FModel
= nil then
720 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
724 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
725 if Random(2) = 0 then
729 gPlayers
[a
].FPreferredTeam
:= Team
;
731 case gGameSettings
.GameMode
of
732 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
734 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
736 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
739 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
740 gPlayers
[a
].FColor
:= Color
;
741 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
742 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
744 gPlayers
[a
].FModel
.Color
:= Color
;
746 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
747 gPlayers
[a
].FLive
:= False;
749 Result
:= gPlayers
[a
].FUID
;
752 function g_Player_CreateFromState(var Mem
: TBinMemoryReader
): Word;
765 if sig
<> PLAYER_SIGNATURE
then // 'PLYR'
767 raise EBinSizeError
.Create('g_Player_CreateFromState: Wrong Player Signature');
771 Mem
.ReadBoolean(Bot
);
776 // Åñòü ëè ìåñòî â gPlayers:
777 if gPlayers
<> nil then
778 for a
:= 0 to High(gPlayers
) do
779 if gPlayers
[a
] = nil then
785 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
788 SetLength(gPlayers
, Length(gPlayers
)+1);
792 // Ñîçäàåì îáúåêò èãðîêà:
794 gPlayers
[a
] := TBot
.Create()
796 gPlayers
[a
] := TPlayer
.Create();
797 gPlayers
[a
].FIamBot
:= Bot
;
798 gPlayers
[a
].FPhysics
:= True;
801 Mem
.ReadWord(gPlayers
[a
].FUID
);
803 Mem
.ReadString(gPlayers
[a
].FName
);
805 Mem
.ReadByte(gPlayers
[a
].FTeam
);
806 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
808 Mem
.ReadBoolean(gPlayers
[a
].FLive
);
809 // Èçðàñõîäîâàë ëè âñå æèçíè:
810 Mem
.ReadBoolean(gPlayers
[a
].FNoRespawn
);
814 gPlayers
[a
].FDirection
:= D_LEFT
816 gPlayers
[a
].FDirection
:= D_RIGHT
;
818 Mem
.ReadInt(gPlayers
[a
].FHealth
);
820 Mem
.ReadByte(gPlayers
[a
].FLives
);
822 Mem
.ReadInt(gPlayers
[a
].FArmor
);
824 Mem
.ReadInt(gPlayers
[a
].FAir
);
826 Mem
.ReadInt(gPlayers
[a
].FJetFuel
);
828 Mem
.ReadInt(gPlayers
[a
].FPain
);
830 Mem
.ReadInt(gPlayers
[a
].FKills
);
832 Mem
.ReadInt(gPlayers
[a
].FMonsterKills
);
834 Mem
.ReadInt(gPlayers
[a
].FFrags
);
836 Mem
.ReadByte(gPlayers
[a
].FFragCombo
);
837 // Âðåìÿ ïîñëåäíåãî ôðàãà:
838 Mem
.ReadDWORD(gPlayers
[a
].FLastFrag
);
840 Mem
.ReadInt(gPlayers
[a
].FDeath
);
842 Mem
.ReadByte(gPlayers
[a
].FFlag
);
844 Mem
.ReadInt(gPlayers
[a
].FSecrets
);
846 Mem
.ReadByte(gPlayers
[a
].FCurrWeap
);
847 // Ñëåäóþùåå æåëàåìîå îðóæèå:
848 Mem
.ReadWord(gPlayers
[a
].FNextWeap
);
850 Mem
.ReadByte(gPlayers
[a
].FNextWeapDelay
);
851 // Âðåìÿ çàðÿäêè BFG:
852 Mem
.ReadSmallInt(gPlayers
[a
].FBFGFireCounter
);
854 Mem
.ReadInt(gPlayers
[a
].FDamageBuffer
);
855 // Ïîñëåäíèé óäàðèâøèé:
856 Mem
.ReadWord(gPlayers
[a
].FLastSpawnerUID
);
857 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
858 Mem
.ReadByte(gPlayers
[a
].FLastHit
);
860 Obj_LoadState(@gPlayers
[a
].FObj
, Mem
);
861 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
862 for i
:= A_BULLETS
to A_HIGH
do
863 Mem
.ReadWord(gPlayers
[a
].FAmmo
[i
]);
864 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
865 for i
:= A_BULLETS
to A_HIGH
do
866 Mem
.ReadWord(gPlayers
[a
].FMaxAmmo
[i
]);
868 for i
:= WP_FIRST
to WP_LAST
do
869 Mem
.ReadBoolean(gPlayers
[a
].FWeapon
[i
]);
870 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
871 for i
:= WP_FIRST
to WP_LAST
do
872 Mem
.ReadWord(gPlayers
[a
].FReloading
[i
]);
876 Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
877 // Íàëè÷èå êðàñíîãî êëþ÷à:
880 Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
881 // Íàëè÷èå çåëåíîãî êëþ÷à:
884 Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
885 // Íàëè÷èå ñèíåãî êëþ÷à:
888 Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
892 Include(gPlayers
[a
].FRulez
, R_BERSERK
);
893 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
894 for i
:= MR_SUIT
to MR_MAX
do
895 Mem
.ReadDWORD(gPlayers
[a
].FMegaRulez
[i
]);
896 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
897 for i
:= T_RESPAWN
to T_FLAGCAP
do
898 Mem
.ReadDWORD(gPlayers
[a
].FTime
[i
]);
901 Mem
.ReadString(gPlayers
[a
].FActualModelName
);
903 Mem
.ReadByte(gPlayers
[a
].FColor
.R
);
904 Mem
.ReadByte(gPlayers
[a
].FColor
.G
);
905 Mem
.ReadByte(gPlayers
[a
].FColor
.B
);
906 // Îáíîâëÿåì ìîäåëü èãðîêà:
907 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
909 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
910 if gPlayers
[a
].FModel
= nil then
914 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
918 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
919 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
920 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
922 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
924 Result
:= gPlayers
[a
].FUID
;
927 procedure g_Player_ResetTeams();
931 if g_Game_IsClient
then
933 if gPlayers
= nil then
935 for a
:= Low(gPlayers
) to High(gPlayers
) do
936 if gPlayers
[a
] <> nil then
937 case gGameSettings
.GameMode
of
939 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
941 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
942 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
943 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
946 gPlayers
[a
].ChangeTeam(TEAM_RED
)
948 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
951 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
955 procedure g_Bot_Add(Team
, Difficult
: Byte);
958 _name
, _model
: String;
961 if not g_Game_IsServer
then Exit
;
963 // Ñïèñîê íàçâàíèé ìîäåëåé:
964 m
:= g_PlayerModel_GetNames();
969 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
970 Team
:= TEAM_COOP
// COOP
972 if gGameSettings
.GameMode
= GM_DM
then
973 Team
:= TEAM_NONE
// DM
975 if Team
= TEAM_NONE
then // CTF / TDM
977 // Àâòîáàëàíñ êîìàíä:
981 for a
:= 0 to High(gPlayers
) do
982 if gPlayers
[a
] <> nil then
984 if gPlayers
[a
].Team
= TEAM_RED
then
987 if gPlayers
[a
].Team
= TEAM_BLUE
then
997 if Random(2) = 0 then
1003 // Âûáèðàåì áîòó èìÿ:
1005 if BotNames
<> nil then
1006 for a
:= 0 to High(BotNames
) do
1007 if g_Player_ValidName(BotNames
[a
]) then
1009 _name
:= BotNames
[a
];
1013 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
1016 _name
:= Format('DFBOT%.2d', [Random(100)]);
1017 until g_Player_ValidName(_name
);
1019 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1020 _model
:= m
[Random(Length(m
))];
1023 with g_Player_Get(g_Player_Create(_model
,
1024 _RGB(Min(Random(9)*32, 255),
1025 Min(Random(9)*32, 255),
1026 Min(Random(9)*32, 255)),
1027 Team
, True)) as TBot
do
1032 1: FDifficult
:= DIFFICULT_EASY
;
1033 2: FDifficult
:= DIFFICULT_MEDIUM
;
1034 else FDifficult
:= DIFFICULT_HARD
;
1037 for a
:= WP_FIRST
to WP_LAST
do
1039 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1040 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1041 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1044 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1046 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1047 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1052 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1);
1055 _name
, _model
: String;
1058 if not g_Game_IsServer
then Exit
;
1060 // Ñïèñîê íàçâàíèé ìîäåëåé:
1061 m
:= g_PlayerModel_GetNames();
1066 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1067 Team
:= TEAM_COOP
// COOP
1069 if gGameSettings
.GameMode
= GM_DM
then
1070 Team
:= TEAM_NONE
// DM
1072 if Team
= TEAM_NONE
then
1073 Team
:= BotList
[num
].team
; // CTF / TDM
1075 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1076 lName
:= AnsiLowerCase(lName
);
1077 if (num
< 0) or (num
> Length(BotList
)-1) then
1079 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1080 for a
:= 0 to High(BotList
) do
1081 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1090 _name
:= BotList
[num
].name
;
1091 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1092 if not g_Player_ValidName(_name
) then
1094 _name
:= Format('DFBOT%.2d', [Random(100)]);
1095 until g_Player_ValidName(_name
);
1098 _model
:= BotList
[num
].model
;
1099 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1100 if not InSArray(_model
, m
) then
1101 _model
:= m
[Random(Length(m
))];
1104 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1108 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1109 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1110 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1111 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1112 FDifficult
.Cover
:= BotList
[num
].cover
;
1113 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1115 for a
:= WP_FIRST
to WP_LAST
do
1117 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1118 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1119 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1122 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1124 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1128 procedure g_Bot_RemoveAll();
1132 if not g_Game_IsServer
then Exit
;
1133 if gPlayers
= nil then Exit
;
1135 for a
:= 0 to High(gPlayers
) do
1136 if gPlayers
[a
] <> nil then
1137 if gPlayers
[a
] is TBot
then
1139 gPlayers
[a
].Lives
:= 0;
1140 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1141 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1142 g_Player_Remove(gPlayers
[a
].FUID
);
1148 procedure g_Bot_MixNames();
1153 if BotNames
<> nil then
1154 for a
:= 0 to High(BotNames
) do
1156 b
:= Random(Length(BotNames
));
1158 Botnames
[a
] := BotNames
[b
];
1163 procedure g_Player_Remove(UID
: Word);
1167 if gPlayers
= nil then Exit
;
1169 if g_Game_IsServer
and g_Game_IsNet
then
1170 MH_SEND_PlayerDelete(UID
);
1172 for i
:= 0 to High(gPlayers
) do
1173 if gPlayers
[i
] <> nil then
1174 if gPlayers
[i
].FUID
= UID
then
1176 if gPlayers
[i
] is TPlayer
then
1177 TPlayer(gPlayers
[i
]).Free()
1179 TBot(gPlayers
[i
]).Free();
1185 procedure g_Player_Init();
1195 if not FileExists(DataDir
+ BOTNAMES_FILENAME
) then
1198 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1199 AssignFile(F
, DataDir
+ BOTNAMES_FILENAME
);
1210 SetLength(BotNames
, Length(BotNames
)+1);
1211 BotNames
[High(BotNames
)] := s
;
1219 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1220 config
:= TConfig
.CreateFile(DataDir
+ BOTLIST_FILENAME
);
1224 while config
.SectionExists(IntToStr(a
)) do
1226 SetLength(BotList
, Length(BotList
)+1);
1228 with BotList
[High(BotList
)] do
1231 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1233 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1235 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1240 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1241 color
.R
:= StrToIntDef(sa
[0], 0);
1242 color
.G
:= StrToIntDef(sa
[1], 0);
1243 color
.B
:= StrToIntDef(sa
[2], 0);
1244 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1245 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1246 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1247 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1248 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1249 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1250 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1251 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1252 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1253 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1254 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1255 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1256 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1257 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1258 if Length(sa
) = 10 then
1260 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1261 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1262 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1263 if Length(sa
) = 10 then
1265 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1267 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1268 if Length(sa) = 10 then
1270 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1279 procedure g_Player_Free();
1283 if gPlayers
<> nil then
1285 for i
:= 0 to High(gPlayers
) do
1286 if gPlayers
[i
] <> nil then
1288 if gPlayers
[i
] is TPlayer
then
1289 TPlayer(gPlayers
[i
]).Free()
1291 TBot(gPlayers
[i
]).Free();
1302 procedure g_Player_UpdateAll();
1306 if gPlayers
= nil then Exit
;
1308 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1309 for i
:= 0 to High(gPlayers
) do
1311 if gPlayers
[i
] <> nil then
1313 if gPlayers
[i
] is TPlayer
then
1315 gPlayers
[i
].Update();
1316 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1320 // bot updates weapons in `UpdateCombat()`
1321 TBot(gPlayers
[i
]).Update();
1325 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1328 procedure g_Player_DrawAll();
1332 if gPlayers
= nil then Exit
;
1334 for i
:= 0 to High(gPlayers
) do
1335 if gPlayers
[i
] <> nil then
1336 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1337 else TBot(gPlayers
[i
]).Draw();
1340 procedure g_Player_DrawDebug(p
: TPlayer
);
1344 if p
= nil then Exit
;
1345 if (@p
.FObj
) = nil then Exit
;
1347 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1349 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1350 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1351 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1352 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1353 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1354 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1357 procedure g_Player_DrawHealth();
1362 if gPlayers
= nil then Exit
;
1363 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1365 for i
:= 0 to High(gPlayers
) do
1366 if gPlayers
[i
] <> nil then
1368 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1369 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1370 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1371 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1372 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1373 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1377 function g_Player_Get(UID
: Word): TPlayer
;
1383 if gPlayers
= nil then
1386 for a
:= 0 to High(gPlayers
) do
1387 if gPlayers
[a
] <> nil then
1388 if gPlayers
[a
].FUID
= UID
then
1390 Result
:= gPlayers
[a
];
1395 function g_Player_GetCount(): Byte;
1401 if gPlayers
= nil then
1404 for a
:= 0 to High(gPlayers
) do
1405 if gPlayers
[a
] <> nil then
1406 Result
:= Result
+ 1;
1409 function g_Player_GetStats(): TPlayerStatArray
;
1415 if gPlayers
= nil then Exit
;
1417 for a
:= 0 to High(gPlayers
) do
1418 if gPlayers
[a
] <> nil then
1420 SetLength(Result
, Length(Result
)+1);
1421 with Result
[High(Result
)] do
1423 Ping
:= gPlayers
[a
].FPing
;
1424 Loss
:= gPlayers
[a
].FLoss
;
1425 Name
:= gPlayers
[a
].FName
;
1426 Team
:= gPlayers
[a
].FTeam
;
1427 Frags
:= gPlayers
[a
].FFrags
;
1428 Deaths
:= gPlayers
[a
].FDeath
;
1429 Kills
:= gPlayers
[a
].FKills
;
1430 Color
:= gPlayers
[a
].FModel
.Color
;
1431 Lives
:= gPlayers
[a
].FLives
;
1432 Spectator
:= gPlayers
[a
].FSpectator
;
1437 procedure g_Player_RememberAll
;
1441 for i
:= Low(gPlayers
) to High(gPlayers
) do
1442 if (gPlayers
[i
] <> nil) and gPlayers
[i
].Live
then
1443 gPlayers
[i
].RememberState
;
1446 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1450 gTeamStat
[TEAM_RED
].Goals
:= 0;
1451 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1453 if gPlayers
<> nil then
1454 for i
:= 0 to High(gPlayers
) do
1455 if gPlayers
[i
] <> nil then
1457 gPlayers
[i
].Reset(Force
);
1459 if gPlayers
[i
] is TPlayer
then
1461 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1462 gPlayers
[i
].Respawn(Silent
)
1464 gPlayers
[i
].Spectate();
1467 TBot(gPlayers
[i
]).Respawn(Silent
);
1471 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1478 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1483 if (FHealth
>= -50) or (gGibsCount
= 0) then
1485 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1489 for find_id
:= 0 to High(gCorpses
) do
1490 if gCorpses
[find_id
] = nil then
1497 find_id
:= Random(Length(gCorpses
));
1499 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1500 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1501 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1502 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1505 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1506 FObj
.Y
+ PLAYER_RECT_CY
,
1507 FModel
.Name
, FModel
.Color
);
1511 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1515 if (gShells
= nil) or (Length(gShells
) = 0) then
1518 with gShells
[CurrentShell
] do
1524 if T
= SHELL_BULLET
then
1526 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1530 Obj
.Rect
.Width
:= 4;
1531 Obj
.Rect
.Height
:= 2;
1535 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1539 Obj
.Rect
.Width
:= 7;
1540 Obj
.Rect
.Height
:= 3;
1546 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1547 positionChanged(); // this updates spatial accelerators
1548 RAngle
:= Random(360);
1549 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1551 if CurrentShell
>= High(gShells
) then
1558 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1561 GibsArray
: TGibsArray
;
1563 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1565 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1568 for a
:= 0 to High(GibsArray
) do
1569 with gGibs
[CurrentGib
] do
1572 ID
:= GibsArray
[a
].ID
;
1573 MaskID
:= GibsArray
[a
].MaskID
;
1576 Obj
.Rect
:= GibsArray
[a
].Rect
;
1577 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1578 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1579 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1580 positionChanged(); // this updates spatial accelerators
1581 RAngle
:= Random(360);
1583 if gBloodCount
> 0 then
1584 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1585 Random(48), Random(48), 150, 0, 0);
1587 if CurrentGib
>= High(gGibs
) then
1594 procedure g_Player_UpdatePhysicalObjects();
1600 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1605 if T
= SHELL_BULLET
then
1606 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1608 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1613 if gGibs
<> nil then
1614 for i
:= 0 to High(gGibs
) do
1615 if gGibs
[i
].Live
then
1619 mr
:= g_Obj_Move(@Obj
, True, False, True);
1620 positionChanged(); // this updates spatial accelerators
1622 if WordBool(mr
and MOVE_FALLOUT
) then
1628 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1629 if WordBool(mr
and MOVE_HITWALL
) then
1630 Obj
.Vel
.X
:= -(vel
.X
div 2);
1631 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1632 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1634 if (Obj
.Vel
.X
>= 0) then
1636 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1637 if RAngle
>= 360 then
1638 RAngle
:= RAngle
mod 360;
1639 end else begin // Counter-clockwise
1640 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1642 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1645 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1646 if gTime
mod (GAME_TICK
*3) = 0 then
1647 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1651 if gCorpses
<> nil then
1652 for i
:= 0 to High(gCorpses
) do
1653 if gCorpses
[i
] <> nil then
1654 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1660 gCorpses
[i
].Update();
1663 if gShells
<> nil then
1664 for i
:= 0 to High(gShells
) do
1665 if gShells
[i
].Live
then
1669 mr
:= g_Obj_Move(@Obj
, True, False, True);
1670 positionChanged(); // this updates spatial accelerators
1672 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1678 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1679 if WordBool(mr
and MOVE_HITWALL
) then
1681 Obj
.Vel
.X
:= -(vel
.X
div 2);
1682 if not WordBool(mr
and MOVE_INWATER
) then
1683 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1685 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1687 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1688 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1689 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1691 if RAngle
mod 90 <> 0 then
1692 RAngle
:= (RAngle
div 90) * 90;
1694 else if not WordBool(mr
and MOVE_INWATER
) then
1695 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1698 if (Obj
.Vel
.X
>= 0) then
1700 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1701 if RAngle
>= 360 then
1702 RAngle
:= RAngle
mod 360;
1703 end else begin // Counter-clockwise
1704 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1706 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1711 procedure g_Player_DrawCorpses();
1716 if gGibs
<> nil then
1717 for i
:= 0 to High(gGibs
) do
1718 if gGibs
[i
].Live
then
1721 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1724 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1725 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1727 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1730 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1736 if gCorpses
<> nil then
1737 for i
:= 0 to High(gCorpses
) do
1738 if gCorpses
[i
] <> nil then
1742 procedure g_Player_DrawShells();
1747 if gShells
<> nil then
1748 for i
:= 0 to High(gShells
) do
1749 if gShells
[i
].Live
then
1752 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1758 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1762 procedure g_Player_RemoveAllCorpses();
1768 SetLength(gGibs
, MaxGibs
);
1769 SetLength(gShells
, MaxGibs
);
1773 if gCorpses
<> nil then
1774 for i
:= 0 to High(gCorpses
) do
1778 SetLength(gCorpses
, MaxCorpses
);
1781 procedure g_Player_Corpses_SaveState(var Mem
: TBinMemoryWriter
);
1786 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ:
1788 if gCorpses
<> nil then
1789 for i
:= 0 to High(gCorpses
) do
1790 if gCorpses
[i
] <> nil then
1793 Mem
:= TBinMemoryWriter
.Create((count
+1) * 128);
1795 // Êîëè÷åñòâî òðóïîâ:
1796 Mem
.WriteInt(count
);
1802 for i
:= 0 to High(gCorpses
) do
1803 if gCorpses
[i
] <> nil then
1806 Mem
.WriteString(gCorpses
[i
].FModelName
);
1808 b
:= gCorpses
[i
].Mess
;
1809 Mem
.WriteBoolean(b
);
1810 // Ñîõðàíÿåì äàííûå òðóïà:
1811 gCorpses
[i
].SaveState(Mem
);
1815 procedure g_Player_Corpses_LoadState(var Mem
: TBinMemoryReader
);
1824 g_Player_RemoveAllCorpses();
1826 // Êîëè÷åñòâî òðóïîâ:
1829 if count
> Length(gCorpses
) then
1831 raise EBinSizeError
.Create('g_Player_Corpses_LoadState: Too Many Corpses');
1838 for i
:= 0 to count
-1 do
1841 Mem
.ReadString(str
);
1845 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1846 // Çàãðóæàåì äàííûå òðóïà:
1847 gCorpses
[i
].LoadState(Mem
);
1853 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1855 procedure TPlayer
.BFGHit();
1857 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1858 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1859 if g_Game_IsServer
and g_Game_IsNet
then
1860 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1861 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1865 procedure TPlayer
.ChangeModel(ModelName
: string);
1867 locModel
: TPlayerModel
;
1869 locModel
:= g_PlayerModel_Get(ModelName
);
1870 if locModel
= nil then Exit
;
1876 procedure TPlayer
.SetModel(ModelName
: string);
1880 m
:= g_PlayerModel_Get(ModelName
);
1883 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1884 m
:= g_PlayerModel_Get('doomer');
1887 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1892 if FModel
<> nil then
1897 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1898 FModel
.Color
:= FColor
1900 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1901 FModel
.SetWeapon(FCurrWeap
);
1902 FModel
.SetFlag(FFlag
);
1903 SetDirection(FDirection
);
1906 procedure TPlayer
.SetColor(Color
: TRGB
);
1909 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1910 if FModel
<> nil then FModel
.Color
:= Color
;
1913 procedure TPlayer
.SwitchTeam
;
1915 if g_Game_IsClient
then
1917 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
1919 if gGameOn
and FLive
then
1920 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
1922 if FTeam
= TEAM_RED
then
1924 ChangeTeam(TEAM_BLUE
);
1925 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
1926 if g_Game_IsNet
then
1927 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
1931 ChangeTeam(TEAM_RED
);
1932 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
1933 if g_Game_IsNet
then
1934 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
1936 FPreferredTeam
:= FTeam
;
1939 procedure TPlayer
.ChangeTeam(Team
: Byte);
1946 TEAM_RED
, TEAM_BLUE
:
1947 FModel
.Color
:= TEAMCOLOR
[Team
];
1949 FModel
.Color
:= FColor
;
1951 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
1952 MH_SEND_PlayerStats(FUID
);
1956 procedure TPlayer.CollideItem();
1961 if gItems = nil then Exit;
1962 if not FLive then Exit;
1964 for i := 0 to High(gItems) do
1967 if (ItemType <> ITEM_NONE) and Live then
1968 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
1969 PLAYER_RECT.Height, @Obj) then
1971 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
1973 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
1974 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
1975 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
1976 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
1977 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
1979 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
1980 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
1981 (gGameSettings.GameType = GT_SINGLE) and
1982 (g_Player_GetCount() > 1)) then
1983 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
1989 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
1991 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
1992 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
1996 constructor TPlayer
.Create();
2007 FSawSound
:= TPlayableSound
.Create();
2008 FSawSoundIdle
:= TPlayableSound
.Create();
2009 FSawSoundHit
:= TPlayableSound
.Create();
2010 FSawSoundSelect
:= TPlayableSound
.Create();
2011 FJetSoundFly
:= TPlayableSound
.Create();
2012 FJetSoundOn
:= TPlayableSound
.Create();
2013 FJetSoundOff
:= TPlayableSound
.Create();
2015 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2016 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2017 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2018 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2019 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2020 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2021 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2023 FSpectatePlayer
:= -1;
2027 FSavedState
.WaitRecall
:= False;
2033 FActualModelName
:= 'doomer';
2036 FObj
.Rect
:= PLAYER_RECT
;
2038 FBFGFireCounter
:= -1;
2039 FJustTeleported
:= False;
2045 procedure TPlayer
.positionChanged ();
2049 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2053 if (not g_Game_IsClient
) and (not FLive
) then
2058 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2059 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2061 if not g_Game_IsClient
then
2064 if t
= HIT_TRAP
then
2066 // Ëîâóøêà óáèâàåò ñðàçó:
2068 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2070 if t
= HIT_SELF
then
2074 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2077 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2078 FMegaRulez
[MR_SUIT
] := 0;
2079 FMegaRulez
[MR_INVUL
] := 0;
2080 FMegaRulez
[MR_INVIS
] := 0;
2084 // Íî îò îñòàëüíîãî ñïàñàåò:
2085 if FMegaRulez
[MR_INVUL
] >= gTime
then
2092 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2093 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2094 (SpawnerUID
= FUID
) or
2095 (not SameTeam(FUID
, SpawnerUID
)) then
2097 FLastSpawnerUID
:= SpawnerUID
;
2099 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2100 if gBloodCount
> 0 then
2102 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2103 if value
div 4 <= c
then
2104 c
:= c
- (value
div 4)
2108 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2112 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2113 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2116 if t
= HIT_WATER
then
2117 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2118 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2123 Inc(FDamageBuffer
, value
);
2127 FPain
:= FPain
+ value
;
2130 if g_Game_IsServer
and g_Game_IsNet
then
2132 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2133 MH_SEND_PlayerStats(FUID
);
2134 MH_SEND_PlayerPos(False, FUID
);
2138 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2141 if g_Game_IsClient
then
2146 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2148 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2151 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2153 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2157 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2158 MH_SEND_PlayerStats(FUID
);
2161 destructor TPlayer
.Destroy();
2163 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2165 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2169 FSawSoundIdle
.Free();
2170 FSawSoundHit
.Free();
2171 FJetSoundFly
.Free();
2173 FJetSoundOff
.Free();
2179 procedure TPlayer
.DrawBubble();
2181 bubX
, bubY
: Integer;
2184 Rw
, Gw
, Bw
: SmallInt;
2187 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= D_LEFT
, -4, 18);
2188 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2196 1: // simple textual non-bubble
2198 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2199 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2200 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2203 2: // advanced pixel-perfect bubble
2205 if FTeam
= TEAM_RED
then
2208 if FTeam
= TEAM_BLUE
then
2211 3: // colored bubble
2213 Rb
:= FModel
.Color
.R
;
2214 Gb
:= FModel
.Color
.G
;
2215 Bb
:= FModel
.Color
.B
;
2216 Rw
:= Min(Rb
* 2 + 64, 255);
2217 Gw
:= Min(Gb
* 2 + 64, 255);
2218 Bw
:= Min(Bb
* 2 + 64, 255);
2219 if (Abs(Rw
- Rb
) < 32)
2220 or (Abs(Gw
- Gb
) < 32)
2221 or (Abs(Bw
- Bb
) < 32) then
2223 Rb
:= Max(Rw
div 2 - 16, 0);
2224 Gb
:= Max(Gw
div 2 - 16, 0);
2225 Bb
:= Max(Bw
div 2 - 16, 0);
2228 4: // custom textured bubble
2230 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2231 if FDirection
= D_RIGHT
then
2232 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2234 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, M_HORIZONTAL
);
2240 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2241 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2243 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2246 Dot
:= IfThen(FDirection
= D_LEFT
, 14, 5);
2247 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2248 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
);
2249 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
);
2250 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
);
2251 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
);
2255 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2256 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2257 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2260 procedure TPlayer
.Draw();
2268 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2269 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2271 e_GetTextureSize(ID
, @w
, @h
);
2272 if FDirection
= D_LEFT
then
2273 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2274 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7, 0, True, False)
2276 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2277 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7, 0, True, False);
2280 if FMegaRulez
[MR_INVIS
] > gTime
then
2282 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2283 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2285 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2286 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2290 FModel
.Draw(FObj
.X
, FObj
.Y
, 200)
2292 FModel
.Draw(FObj
.X
, FObj
.Y
);
2295 FModel
.Draw(FObj
.X
, FObj
.Y
, 254);
2298 FModel
.Draw(FObj
.X
, FObj
.Y
);
2301 if g_debug_Frames
then
2303 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2305 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2306 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2310 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2312 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2313 if gAimLine
and Live
and
2314 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2319 procedure TPlayer
.DrawAim();
2320 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2323 procedure drawTileGrid ();
2327 y := mapGrid.gridY0;
2328 while (y < mapGrid.gridY0+mapGrid.gridHeight) do
2330 x := mapGrid.gridX0;
2331 while (x < mapGrid.gridX0+mapGrid.gridWidth) do
2333 if (x+mapGrid.tileSize > viewPortX) and (y+mapGrid.tileSize > viewPortY) and
2334 (x < viewPortX+viewPortW) and (y < viewPortY+viewPortH) then
2336 e_DrawQuad(x, y, x+mapGrid.tileSize-1, y+mapGrid.tileSize-1, 96, 96, 96, 96);
2338 Inc(x, mapGrid.tileSize);
2340 Inc(y, mapGrid.tileSize);
2348 if isValidViewPort
and (self
= gPlayer1
) then
2350 g_Holmes_plrView(viewPortX
, viewPortY
, viewPortW
, viewPortH
);
2351 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2354 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2355 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2357 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2361 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2368 wx
, wy
, xx
, yy
: Integer;
2372 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= D_LEFT
, 7, -7);
2373 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2382 1: begin // Chainsaw
2389 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2390 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2391 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2392 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2397 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2398 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2399 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2400 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2402 4: begin // Double Shotgun
2405 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2406 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2407 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2408 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2410 5: begin // Chaingun
2413 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2414 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2415 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2416 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2418 6: begin // Rocket Launcher
2421 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2422 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2423 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2424 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2426 7: begin // Plasmagun
2429 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2430 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2431 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2432 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2437 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2438 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2439 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2440 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2442 9: begin // Super Chaingun
2445 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2446 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2447 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2448 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2451 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2452 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2453 {$IF DEFINED(D2F_DEBUG)}
2454 drawCast(sz
, wx
, wy
, xx
, yy
);
2456 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2460 procedure TPlayer
.DrawGUI();
2463 X
, Y
, SY
, a
, p
, m
: Integer;
2467 stat
: TPlayerStatArray
;
2469 X
:= gPlayerScreenSize
.X
;
2470 SY
:= gPlayerScreenSize
.Y
;
2473 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2475 if gGameSettings
.GameMode
= GM_CTF
then
2479 if gGameSettings
.GameMode
= GM_CTF
then
2481 s
:= 'TEXTURE_PLAYER_REDFLAG';
2482 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2483 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2484 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2485 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2486 if g_Texture_Get(s
, ID
) then
2487 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2490 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2491 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2492 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2494 if gGameSettings
.GameMode
= GM_CTF
then
2496 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2497 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2498 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2499 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2500 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2501 if g_Texture_Get(s
, ID
) then
2502 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2505 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2506 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2507 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2510 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2511 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2514 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2515 e_Draw(ID
, X
+2, Y
, 0, True, False);
2517 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2521 s
:= IntToStr(Frags
);
2522 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2523 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2528 stat
:= g_Player_GetStats();
2533 for a
:= 0 to High(stat
) do
2534 if stat
[a
].Name
<> Name
then
2536 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2537 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2541 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2542 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2543 s
:= s
+IntToStr(Abs(Frags
-m
));
2545 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2546 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2549 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2551 s
:= IntToStr(Lives
);
2552 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2553 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2557 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2558 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2560 if R_BERSERK
in FRulez
then
2561 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2563 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2565 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2566 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2568 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2569 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2570 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2572 s
:= IntToStr(FArmor
);
2573 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2574 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2576 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2582 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2587 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2589 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2590 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2591 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2592 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2593 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2594 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2595 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2596 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2597 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2600 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2601 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2602 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2604 if R_KEY_RED
in FRulez
then
2605 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2607 if R_KEY_GREEN
in FRulez
then
2608 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2610 if R_KEY_BLUE
in FRulez
then
2611 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2613 if FJetFuel
> 0 then
2615 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2616 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2617 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2618 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2619 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2620 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2624 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2625 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2626 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2629 if gShowPing
and g_Game_IsClient
then
2631 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2632 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2638 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2639 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2640 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2643 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2644 s
:= _lc
[I_PLAYER_SPECT4
];
2645 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2646 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2647 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2653 procedure TPlayer
.DrawRulez();
2657 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2658 if FMegaRulez
[MR_INVUL
] >= gTime
then
2660 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2661 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2666 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2667 191, 191, 191, 0, B_INVERT
);
2670 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2671 if FMegaRulez
[MR_SUIT
] >= gTime
then
2673 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2674 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2679 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2680 0, 96, 0, 200, B_NONE
);
2683 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2684 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2686 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2687 255, 0, 0, 200, B_NONE
);
2691 procedure TPlayer
.DrawPain();
2695 if FPain
= 0 then Exit
;
2699 if a
< 15 then h
:= 0
2700 else if a
< 35 then h
:= 1
2701 else if a
< 55 then h
:= 2
2702 else if a
< 75 then h
:= 3
2703 else if a
< 95 then h
:= 4
2706 //if a > 255 then a := 255;
2708 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2709 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2712 procedure TPlayer
.DrawPickup();
2716 if FPickup
= 0 then Exit
;
2720 if a
< 15 then h
:= 1
2721 else if a
< 35 then h
:= 2
2722 else if a
< 55 then h
:= 3
2723 else if a
< 75 then h
:= 4
2726 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2729 procedure TPlayer
.Fire();
2731 f
, DidFire
: Boolean;
2732 wx
, wy
, xd
, yd
: Integer;
2735 if g_Game_IsClient
then Exit
;
2736 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2737 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2745 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2750 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2751 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2752 xd
:= wx
+IfThen(FDirection
= D_LEFT
, -30, 30);
2753 yd
:= wy
+firediry();
2758 if R_BERSERK
in FRulez
then
2760 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2761 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2762 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2765 locobj
.rect
.Width
:= 39;
2766 locobj
.rect
.Height
:= 52;
2767 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2768 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2769 locobj
.Accel
.X
:= xd
-wx
;
2770 locobj
.Accel
.y
:= yd
-wy
;
2772 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2773 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2775 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2779 FPain
:= min(FPain
+ 25, 50);
2780 end else g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2783 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2788 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2789 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2791 FSawSoundSelect
.Stop();
2793 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2795 else if not FSawSoundHit
.IsPlaying() then
2797 FSawSoundSelect
.Stop();
2798 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2801 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2807 if FAmmo
[A_BULLETS
] > 0 then
2809 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2810 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2811 Dec(FAmmo
[A_BULLETS
]);
2812 FFireAngle
:= FAngle
;
2815 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2816 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2820 if FAmmo
[A_SHELLS
] > 0 then
2822 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2823 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
2824 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2825 Dec(FAmmo
[A_SHELLS
]);
2826 FFireAngle
:= FAngle
;
2830 FShellType
:= SHELL_SHELL
;
2834 if FAmmo
[A_SHELLS
] >= 2 then
2836 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
2837 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2838 Dec(FAmmo
[A_SHELLS
], 2);
2839 FFireAngle
:= FAngle
;
2843 FShellType
:= SHELL_DBLSHELL
;
2847 if FAmmo
[A_BULLETS
] > 0 then
2849 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
2850 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
2851 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2852 Dec(FAmmo
[A_BULLETS
]);
2853 FFireAngle
:= FAngle
;
2856 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2857 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2860 WEAPON_ROCKETLAUNCHER
:
2861 if FAmmo
[A_ROCKETS
] > 0 then
2863 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
2864 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2865 Dec(FAmmo
[A_ROCKETS
]);
2866 FFireAngle
:= FAngle
;
2872 if FAmmo
[A_CELLS
] > 0 then
2874 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
2875 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2876 Dec(FAmmo
[A_CELLS
]);
2877 FFireAngle
:= FAngle
;
2883 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
2885 FBFGFireCounter
:= 17;
2886 if not FNoReload
then
2887 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
2888 Dec(FAmmo
[A_CELLS
], 40);
2892 WEAPON_SUPERPULEMET
:
2893 if FAmmo
[A_SHELLS
] > 0 then
2895 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2896 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
2897 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2898 Dec(FAmmo
[A_SHELLS
]);
2899 FFireAngle
:= FAngle
;
2902 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2903 GameVelX
, GameVelY
-2, SHELL_SHELL
);
2906 WEAPON_FLAMETHROWER
:
2907 if FAmmo
[A_FUEL
] > 0 then
2909 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
2910 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2912 FFireAngle
:= FAngle
;
2918 if g_Game_IsNet
then
2922 if FCurrWeap
<> WEAPON_BFG
then
2923 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
2925 if not FNoReload
then
2926 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
2929 MH_SEND_PlayerStats(FUID
);
2934 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
2935 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
2936 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
2939 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
2942 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
2943 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
2944 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
2945 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
2946 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
2951 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
2953 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
2954 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
2955 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
2958 procedure TPlayer
.JetpackOn
;
2962 FJetSoundOn
.SetPosition(0);
2963 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
2967 procedure TPlayer
.JetpackOff
;
2971 FJetSoundOff
.SetPosition(0);
2972 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
2975 procedure TPlayer
.CatchFire(Attacker
: Word);
2978 FFireAttacker
:= Attacker
;
2979 if g_Game_IsNet
and g_Game_IsServer
then
2980 MH_SEND_PlayerStats(FUID
);
2983 procedure TPlayer
.Jump();
2985 if gFly
or FJetpack
then
2987 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
2988 if FObj
.Vel
.Y
> -VEL_FLY
then
2989 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
2992 if FJetFuel
> 0 then
2994 if (FJetFuel
< 1) and g_Game_IsServer
then
2998 if g_Game_IsNet
then
2999 MH_SEND_PlayerStats(FUID
);
3005 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3007 FCanJetpack
:= False;
3009 // Ïðûãàåì èëè âñïëûâàåì:
3010 if (CollideLevel(0, 1) or
3011 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3012 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3013 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3015 FObj
.Vel
.Y
:= -VEL_JUMP
;
3016 FCanJetpack
:= False;
3020 if BodyInLiquid(0, 0) then
3021 FObj
.Vel
.Y
:= -VEL_SW
3022 else if (FJetFuel
> 0) and FCanJetpack
and
3023 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3027 if g_Game_IsNet
then
3028 MH_SEND_PlayerStats(FUID
);
3033 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3035 a
, i
, k
, ab
, ar
: Byte;
3039 srv
, netsrv
: Boolean;
3045 procedure PushItem(t
: Byte);
3049 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3050 it
:= g_Items_ByIdx(id
);
3051 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3053 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3054 (FObj
.Vel
.Y
div 2)-Random(9));
3055 it
.positionChanged(); // this updates spatial accelerators
3059 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3061 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3062 (FObj
.Vel
.Y
div 2)-Random(6));
3064 else // -3..+3; -3..0
3066 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3067 (FObj
.Vel
.Y
div 2)-Random(4));
3069 it
.positionChanged(); // this updates spatial accelerators
3072 if g_Game_IsNet
and g_Game_IsServer
then
3073 MH_SEND_ItemSpawn(True, id
);
3077 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3078 Srv
:= g_Game_IsServer
;
3079 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3080 if Srv
then FDeath
:= FDeath
+ 1;
3085 if not FPhysics
then
3091 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3093 if FLives
> 0 then FLives
:= FLives
- 1;
3094 if FLives
= 0 then FNoRespawn
:= True;
3097 // Íîìåð òèïà ñìåðòè:
3100 K_SIMPLEKILL
: a
:= 1;
3102 K_EXTRAHARDKILL
: a
:= 3;
3107 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3109 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3116 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3118 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3119 K_EXTRAHARDKILL
, K_FALLKILL
:
3120 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3123 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3127 K_HARDKILL
, K_EXTRAHARDKILL
:
3131 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3132 if (KillType
<> K_FALLKILL
) and (Srv
) then
3133 g_Monsters_killedp();
3135 if SpawnerUID
= FUID
then
3137 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3142 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3145 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3146 begin // Óáèò äðóãèì èãðîêîì
3147 KP
:= g_Player_Get(SpawnerUID
);
3148 if (KP
<> nil) and Srv
then
3150 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3151 if SameTeam(FUID
, SpawnerUID
) then
3161 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3162 Inc(gTeamStat
[KP
.Team
].Goals
,
3163 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3165 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3168 plr
:= g_Player_Get(SpawnerUID
);
3176 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3180 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3184 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3189 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3190 begin // Óáèò ìîíñòðîì
3191 mon
:= g_Monsters_ByUID(SpawnerUID
);
3195 s
:= g_Monsters_GetKilledBy(mon
.MonsterType
);
3199 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3203 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3207 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3212 else // Îñîáûå òèïû ñìåðòè
3215 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3216 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3217 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3218 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3219 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3220 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3226 for a
:= WP_FIRST
to WP_LAST
do
3230 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3231 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3232 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3233 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3234 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3235 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3236 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3237 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3238 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3247 if R_ITEM_BACKPACK
in FRulez
then
3248 PushItem(ITEM_AMMO_BACKPACK
);
3250 // Âûáðîñ ðàêåòíîãî ðàíöà:
3251 if FJetFuel
> 0 then
3252 PushItem(ITEM_JETPACK
);
3255 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3257 if R_KEY_RED
in FRulez
then
3258 PushItem(ITEM_KEY_RED
);
3260 if R_KEY_GREEN
in FRulez
then
3261 PushItem(ITEM_KEY_GREEN
);
3263 if R_KEY_BLUE
in FRulez
then
3264 PushItem(ITEM_KEY_BLUE
);
3271 g_Player_CreateCorpse(Self
);
3273 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3274 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3280 for i
:= Low(gPlayers
) to High(gPlayers
) do
3282 if gPlayers
[i
] = nil then continue
;
3283 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3286 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3287 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3292 OldLR
:= gLMSRespawn
;
3293 if (gGameSettings
.GameMode
= GM_COOP
) then
3297 // everyone is dead, restart the map
3298 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3300 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3301 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3302 gLMSRespawnTime
:= gTime
+ 5000;
3304 else if (a
= 1) then
3306 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3307 if (gPlayers
[k
] = gPlayer1
) or
3308 (gPlayers
[k
] = gPlayer2
) then
3309 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3310 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3311 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3314 else if (gGameSettings
.GameMode
= GM_TDM
) then
3316 if (ab
= 0) and (ar
<> 0) then
3319 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3321 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3322 Inc(gTeamStat
[TEAM_RED
].Goals
);
3323 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3324 gLMSRespawnTime
:= gTime
+ 5000;
3326 else if (ar
= 0) and (ab
<> 0) then
3329 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3331 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3332 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3333 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3334 gLMSRespawnTime
:= gTime
+ 5000;
3336 else if (ar
= 0) and (ab
= 0) then
3339 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3341 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3342 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3343 gLMSRespawnTime
:= gTime
+ 5000;
3346 else if (gGameSettings
.GameMode
= GM_DM
) then
3350 if gPlayers
[k
] <> nil then
3353 // survivor is the winner
3354 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3356 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3359 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3360 gLMSRespawnTime
:= gTime
+ 5000;
3362 else if (a
= 0) then
3364 // everyone is dead, restart the map
3365 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3367 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3368 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3369 gLMSRespawnTime
:= gTime
+ 5000;
3372 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3374 if NetMode
= NET_SERVER
then
3375 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3377 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3383 MH_SEND_PlayerStats(FUID
);
3384 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3385 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3388 if srv
and FNoRespawn
then Spectate(True);
3389 FWantsInGame
:= True;
3392 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3394 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3395 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3398 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3400 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3401 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3404 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3406 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3407 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3408 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
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,
3416 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3418 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3419 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3420 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3424 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3426 if g_Game_IsClient
then Exit
;
3427 if Weapon
> High(FWeapon
) then Exit
;
3428 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3431 procedure TPlayer
.resetWeaponQueue ();
3434 FNextWeapDelay
:= 0;
3437 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3441 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3442 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 0);
3443 WEAPON_PISTOL
, WEAPON_CHAINGUN
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_BULLETS
] > 0);
3444 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3445 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3446 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3447 else result
:= (weapon
< length(FWeapon
));
3451 // return 255 for "no switch"
3452 function TPlayer
.getNextWeaponIndex (): Byte;
3455 wantThisWeapon
: array[0..64] of Boolean;
3456 wwc
: Integer = 0; //HACK!
3459 result
:= 255; // default result: "no switch"
3460 // had weapon cycling on previous frame? remove that flag
3461 if (FNextWeap
and $2000) <> 0 then
3463 FNextWeap
:= FNextWeap
and $1FFF;
3464 FNextWeapDelay
:= 0;
3466 // cycling has priority
3467 if (FNextWeap
and $C000) <> 0 then
3469 if (FNextWeap
and $8000) <> 0 then
3473 FNextWeap
:= FNextWeap
or $2000; // we need this
3474 if FNextWeapDelay
> 0 then
3475 exit
; // cooldown time
3477 for i
:= 0 to High(FWeapon
) do
3479 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3480 if FWeapon
[cwi
] then
3482 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d', [FCurrWeap, cwi]), MSG_WARNING);
3483 result
:= Byte(cwi
);
3484 FNextWeapDelay
:= 10;
3492 for i
:= 0 to High(wantThisWeapon
) do
3493 wantThisWeapon
[i
] := false;
3494 for i
:= 0 to High(FWeapon
) do
3495 if (FNextWeap
and (1 shl i
)) <> 0 then
3497 wantThisWeapon
[i
] := true;
3500 // exclude currently selected weapon from the set
3501 wantThisWeapon
[FCurrWeap
] := false;
3502 // slow down alterations a little
3505 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3506 // more than one weapon requested, assume "alteration" and check alteration delay
3507 if FNextWeapDelay
> 0 then
3513 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3514 // but clear all counters if no weapon should be switched
3520 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3521 // try weapons in descending order
3522 for i
:= High(FWeapon
) downto 0 do
3524 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3529 FNextWeapDelay
:= 10; // anyway, 'cause why not
3533 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3537 procedure TPlayer
.RealizeCurrentWeapon();
3538 function switchAllowed (): Boolean;
3543 if FBFGFireCounter
<> -1 then
3545 if FTime
[T_SWITCH
] > gTime
then
3547 for i
:= WP_FIRST
to WP_LAST
do
3548 if FReloading
[i
] > 0 then
3556 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3557 //FNextWeap := FNextWeap and $1FFF;
3558 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3560 if not switchAllowed
then
3562 //HACK for weapon cycling
3563 if (FNextWeap
and $7000) <> 0 then FNextWeap
:= 0;
3567 nw
:= getNextWeaponIndex();
3568 if nw
= 255 then exit
; // don't reset anything here
3569 if nw
> High(FWeapon
) then
3571 // don't forget to reset queue here!
3572 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3580 FTime
[T_SWITCH
] := gTime
+156;
3581 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3582 FModel
.SetWeapon(FCurrWeap
);
3583 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3587 procedure TPlayer
.NextWeapon();
3589 if g_Game_IsClient
then Exit
;
3593 procedure TPlayer
.PrevWeapon();
3595 if g_Game_IsClient
then Exit
;
3599 procedure TPlayer
.SetWeapon(W
: Byte);
3601 if FCurrWeap
<> W
then
3602 if W
= WEAPON_SAW
then
3603 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3606 FModel
.SetWeapon(CurrWeap
);
3610 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3615 if g_Game_IsClient
then Exit
;
3617 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3618 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3623 if FHealth
< PLAYER_HP_SOFT
then
3625 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3629 if gFlash
= 2 then Inc(FPickup
, 5);
3633 if FHealth
< PLAYER_HP_SOFT
then
3635 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3639 if gFlash
= 2 then Inc(FPickup
, 5);
3643 if FArmor
< PLAYER_AP_SOFT
then
3645 FArmor
:= PLAYER_AP_SOFT
;
3648 if gFlash
= 2 then Inc(FPickup
, 5);
3652 if FArmor
< PLAYER_AP_LIMIT
then
3654 FArmor
:= PLAYER_AP_LIMIT
;
3657 if gFlash
= 2 then Inc(FPickup
, 5);
3661 if FHealth
< PLAYER_HP_LIMIT
then
3663 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3667 if gFlash
= 2 then Inc(FPickup
, 5);
3671 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3673 if FHealth
< PLAYER_HP_LIMIT
then
3674 FHealth
:= PLAYER_HP_LIMIT
;
3675 if FArmor
< PLAYER_AP_LIMIT
then
3676 FArmor
:= PLAYER_AP_LIMIT
;
3680 if gFlash
= 2 then Inc(FPickup
, 5);
3684 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3686 FWeapon
[WEAPON_SAW
] := True;
3688 if gFlash
= 2 then Inc(FPickup
, 5);
3689 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3692 ITEM_WEAPON_SHOTGUN1
:
3693 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3695 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3696 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3698 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3699 FWeapon
[WEAPON_SHOTGUN1
] := True;
3701 if gFlash
= 2 then Inc(FPickup
, 5);
3702 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3705 ITEM_WEAPON_SHOTGUN2
:
3706 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3708 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3710 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3711 FWeapon
[WEAPON_SHOTGUN2
] := True;
3713 if gFlash
= 2 then Inc(FPickup
, 5);
3714 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3717 ITEM_WEAPON_CHAINGUN
:
3718 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3720 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3722 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3723 FWeapon
[WEAPON_CHAINGUN
] := True;
3725 if gFlash
= 2 then Inc(FPickup
, 5);
3726 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3729 ITEM_WEAPON_ROCKETLAUNCHER
:
3730 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3732 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3734 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3735 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3737 if gFlash
= 2 then Inc(FPickup
, 5);
3738 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3742 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3744 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3746 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3747 FWeapon
[WEAPON_PLASMA
] := True;
3749 if gFlash
= 2 then Inc(FPickup
, 5);
3750 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3754 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3756 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3758 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3759 FWeapon
[WEAPON_BFG
] := True;
3761 if gFlash
= 2 then Inc(FPickup
, 5);
3762 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3765 ITEM_WEAPON_SUPERPULEMET
:
3766 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3768 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3770 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3771 FWeapon
[WEAPON_SUPERPULEMET
] := True;
3773 if gFlash
= 2 then Inc(FPickup
, 5);
3774 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3777 ITEM_WEAPON_FLAMETHROWER
:
3778 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
3780 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
3782 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3783 FWeapon
[WEAPON_FLAMETHROWER
] := True;
3785 if gFlash
= 2 then Inc(FPickup
, 5);
3786 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3790 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3792 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3795 if gFlash
= 2 then Inc(FPickup
, 5);
3798 ITEM_AMMO_BULLETS_BOX
:
3799 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3801 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3804 if gFlash
= 2 then Inc(FPickup
, 5);
3808 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3810 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3813 if gFlash
= 2 then Inc(FPickup
, 5);
3816 ITEM_AMMO_SHELLS_BOX
:
3817 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3819 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
3822 if gFlash
= 2 then Inc(FPickup
, 5);
3826 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3828 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3831 if gFlash
= 2 then Inc(FPickup
, 5);
3834 ITEM_AMMO_ROCKET_BOX
:
3835 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3837 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
3840 if gFlash
= 2 then Inc(FPickup
, 5);
3844 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3846 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3849 if gFlash
= 2 then Inc(FPickup
, 5);
3853 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3855 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
3858 if gFlash
= 2 then Inc(FPickup
, 5);
3862 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
3864 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3867 if gFlash
= 2 then Inc(FPickup
, 5);
3871 if not(R_ITEM_BACKPACK
in FRulez
) or
3872 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
3873 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
3874 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
3875 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
3876 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
3878 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
3879 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
3880 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
3881 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
3882 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
3884 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3885 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3886 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3887 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3888 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3889 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3890 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3891 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3893 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
3896 if gFlash
= 2 then Inc(FPickup
, 5);
3900 if not(R_KEY_RED
in FRulez
) then
3902 Include(FRulez
, R_KEY_RED
);
3904 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3905 if gFlash
= 2 then Inc(FPickup
, 5);
3906 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3910 if not(R_KEY_GREEN
in FRulez
) then
3912 Include(FRulez
, R_KEY_GREEN
);
3914 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3915 if gFlash
= 2 then Inc(FPickup
, 5);
3916 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3920 if not(R_KEY_BLUE
in FRulez
) then
3922 Include(FRulez
, R_KEY_BLUE
);
3924 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3925 if gFlash
= 2 then Inc(FPickup
, 5);
3926 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3930 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
3932 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
3936 if gFlash
= 2 then Inc(FPickup
, 5);
3940 if FAir
< AIR_MAX
then
3945 if gFlash
= 2 then Inc(FPickup
, 5);
3950 if not (R_BERSERK
in FRulez
) then
3952 Include(FRulez
, R_BERSERK
);
3953 if FBFGFireCounter
= -1 then
3955 FCurrWeap
:= WEAPON_KASTET
;
3957 FModel
.SetWeapon(WEAPON_KASTET
);
3961 if gFlash
= 2 then Inc(FPickup
, 5);
3962 FBerserk
:= gTime
+30000;
3967 if FHealth
< PLAYER_HP_SOFT
then
3969 FHealth
:= PLAYER_HP_SOFT
;
3970 FBerserk
:= gTime
+30000;
3978 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
3980 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
3983 if gFlash
= 2 then Inc(FPickup
, 5);
3987 if FHealth
< PLAYER_HP_LIMIT
then
3989 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
3993 if gFlash
= 2 then Inc(FPickup
, 5);
3997 if FArmor
< PLAYER_AP_LIMIT
then
3999 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4002 if gFlash
= 2 then Inc(FPickup
, 5);
4006 if FJetFuel
< JET_MAX
then
4008 FJetFuel
:= JET_MAX
;
4011 if gFlash
= 2 then Inc(FPickup
, 5);
4015 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4017 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4020 if gFlash
= 2 then Inc(FPickup
, 5);
4025 procedure TPlayer
.Touch();
4029 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4032 // Áðîñèòü ôëàã òîâàðèùó:
4033 if gGameSettings
.GameMode
= GM_CTF
then
4038 procedure TPlayer
.Push(vx
, vy
: Integer);
4040 if (not FPhysics
) and FGhost
then
4042 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4043 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4044 if g_Game_IsNet
and g_Game_IsServer
then
4045 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4048 procedure TPlayer
.Reset(Force
: Boolean);
4054 FTime
[T_RESPAWN
] := 0;
4055 FTime
[T_FLAGCAP
] := 0;
4068 FSpectator
:= False;
4071 FSpectatePlayer
:= -1;
4072 FNoRespawn
:= False;
4074 FLives
:= gGameSettings
.MaxLives
;
4079 procedure TPlayer
.SoftReset();
4085 FBFGFireCounter
:= -1;
4093 SetAction(A_STAND
, True);
4096 function TPlayer
.GetRespawnPoint(): Byte;
4101 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4103 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4104 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4106 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4108 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4109 if Self
= gPlayer1
then
4110 c
:= RESPAWNPOINT_PLAYER1
4112 c
:= RESPAWNPOINT_PLAYER2
;
4113 if g_Map_GetPointCount(c
) > 0 then
4119 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4120 if Self
= gPlayer1
then
4121 c
:= RESPAWNPOINT_PLAYER2
4123 c
:= RESPAWNPOINT_PLAYER1
;
4124 if g_Map_GetPointCount(c
) > 0 then
4131 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4132 if Random(2) = 0 then
4133 c
:= RESPAWNPOINT_PLAYER1
4135 c
:= RESPAWNPOINT_PLAYER2
;
4136 if g_Map_GetPointCount(c
) > 0 then
4143 // Òî÷êà ëþáîé èç êîìàíä
4144 if Random(2) = 0 then
4145 c
:= RESPAWNPOINT_RED
4147 c
:= RESPAWNPOINT_BLUE
;
4148 if g_Map_GetPointCount(c
) > 0 then
4155 c
:= RESPAWNPOINT_DM
;
4156 if g_Map_GetPointCount(c
) > 0 then
4164 if gGameSettings
.GameMode
= GM_DM
then
4167 c
:= RESPAWNPOINT_DM
;
4168 if g_Map_GetPointCount(c
) > 0 then
4174 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4175 if Random(2) = 0 then
4176 c
:= RESPAWNPOINT_PLAYER1
4178 c
:= RESPAWNPOINT_PLAYER2
;
4179 if g_Map_GetPointCount(c
) > 0 then
4185 // Òî÷êà ëþáîé èç êîìàíä
4186 if Random(2) = 0 then
4187 c
:= RESPAWNPOINT_RED
4189 c
:= RESPAWNPOINT_BLUE
;
4190 if g_Map_GetPointCount(c
) > 0 then
4198 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4200 // Òî÷êà ñâîåé êîìàíäû
4201 c
:= RESPAWNPOINT_DM
;
4202 if FTeam
= TEAM_RED
then
4203 c
:= RESPAWNPOINT_RED
;
4204 if FTeam
= TEAM_BLUE
then
4205 c
:= RESPAWNPOINT_BLUE
;
4206 if g_Map_GetPointCount(c
) > 0 then
4213 c
:= RESPAWNPOINT_DM
;
4214 if g_Map_GetPointCount(c
) > 0 then
4220 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4221 if Random(2) = 0 then
4222 c
:= RESPAWNPOINT_PLAYER1
4224 c
:= RESPAWNPOINT_PLAYER2
;
4225 if g_Map_GetPointCount(c
) > 0 then
4231 // Òî÷êà äðóãîé êîìàíäû
4232 c
:= RESPAWNPOINT_DM
;
4233 if FTeam
= TEAM_RED
then
4234 c
:= RESPAWNPOINT_BLUE
;
4235 if FTeam
= TEAM_BLUE
then
4236 c
:= RESPAWNPOINT_RED
;
4237 if g_Map_GetPointCount(c
) > 0 then
4245 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4247 RespawnPoint
: TRespawnPoint
;
4252 if not g_Game_IsServer
then
4256 FWantsInGame
:= True;
4257 FJustTeleported
:= True;
4260 FTime
[T_RESPAWN
] := 0;
4264 // if server changes MaxLives we gotta be ready
4265 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4267 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4268 if FTime
[T_RESPAWN
] > gTime
then
4271 // Ïðîñðàë âñå æèçíè:
4274 if not FSpectator
then Spectate(True);
4275 FWantsInGame
:= True;
4279 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4280 begin // "Ñâîÿ èãðà"
4281 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4282 FRulez
:= FRulez
-[R_BERSERK
];
4284 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4286 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4287 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4290 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4291 c
:= GetRespawnPoint();
4296 // Âîñêðåøåíèå áåç îðóæèÿ:
4299 FHealth
:= PLAYER_HP_SOFT
;
4305 for a
:= WP_FIRST
to WP_LAST
do
4307 FWeapon
[a
] := False;
4311 FWeapon
[WEAPON_PISTOL
] := True;
4312 FWeapon
[WEAPON_KASTET
] := True;
4313 FCurrWeap
:= WEAPON_PISTOL
;
4316 FModel
.SetWeapon(FCurrWeap
);
4318 for b
:= A_BULLETS
to A_HIGH
do
4321 FAmmo
[A_BULLETS
] := 50;
4323 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4324 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4325 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4326 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4327 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4329 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4330 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4335 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4336 if not g_Map_GetPoint(c
, RespawnPoint
) then
4338 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4342 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4343 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4344 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4350 FDirection
:= RespawnPoint
.Direction
;
4351 if FDirection
= D_LEFT
then
4357 FBFGFireCounter
:= -1;
4362 SetAction(A_STAND
, True);
4363 FModel
.Direction
:= FDirection
;
4365 for a
:= Low(FTime
) to High(FTime
) do
4368 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4373 FCanJetpack
:= False;
4378 // Àíèìàöèÿ âîçðîæäåíèÿ:
4379 if (not gLoadGameMode
) and (not Silent
) then
4380 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4382 Anim
:= TAnimation
.Create(ID
, False, 3);
4383 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4384 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4388 FSpectator
:= False;
4391 FSpectatePlayer
:= -1;
4394 if g_Game_IsNet
then
4396 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4397 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4399 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4400 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4405 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4408 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4409 else if (not NoMove
) then
4411 GameX
:= gMapInfo
.Width
div 2;
4412 GameY
:= gMapInfo
.Height
div 2;
4421 FWantsInGame
:= False;
4426 if Self
= gPlayer1
then
4431 if Self
= gPlayer2
then
4438 if g_Game_IsNet
then
4439 MH_SEND_PlayerStats(FUID
);
4442 procedure TPlayer
.SwitchNoClip
;
4446 FGhost
:= not FGhost
;
4447 FPhysics
:= not FGhost
;
4459 procedure TPlayer
.Run(Direction
: TDirection
);
4463 if MAX_RUNVEL
> 8 then
4467 if Direction
= D_LEFT
then
4469 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4470 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4473 if FObj
.Vel
.X
< MAX_RUNVEL
then
4474 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4476 // Âîçìîæíî, ïèíàåì êóñêè:
4477 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4479 b
:= Abs(FObj
.Vel
.X
);
4480 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4481 for a
:= 0 to High(gGibs
) do
4483 if gGibs
[a
].Live
and
4484 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4485 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4488 if FObj
.Vel
.X
< 0 then
4490 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4494 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4496 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4504 procedure TPlayer
.SeeDown();
4506 SetAction(A_SEEDOWN
);
4508 if FDirection
= D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4510 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4513 procedure TPlayer
.SeeUp();
4517 if FDirection
= D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4519 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4522 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4530 A_ATTACK
: Prior
:= 2;
4531 A_SEEUP
: Prior
:= 1;
4532 A_SEEDOWN
: Prior
:= 1;
4533 A_ATTACKUP
: Prior
:= 2;
4534 A_ATTACKDOWN
: Prior
:= 2;
4539 if (Prior
> FActionPrior
) or Force
then
4540 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4542 FActionPrior
:= Prior
;
4543 FActionAnim
:= Action
;
4544 FActionForce
:= Force
;
4545 FActionChanged
:= True;
4548 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4551 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4553 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4554 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4555 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4556 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4559 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4566 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4568 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4569 if g_Game_IsServer
and g_Game_IsNet
then
4570 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4574 FJustTeleported
:= True;
4579 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4581 Anim
:= TAnimation
.Create(ID
, False, 3);
4584 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4585 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4586 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4587 if g_Game_IsServer
and g_Game_IsNet
then
4588 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4589 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4593 FObj
.X
:= X
-PLAYER_RECT
.X
;
4594 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4595 if FLive
and FGhost
then
4601 if not g_Game_IsNet
then
4605 SetDirection(D_LEFT
);
4611 SetDirection(D_RIGHT
);
4617 if FDirection
= D_RIGHT
then
4619 SetDirection(D_LEFT
);
4624 SetDirection(D_RIGHT
);
4630 if not silent
and (Anim
<> nil) then
4632 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4633 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4636 if g_Game_IsServer
and g_Game_IsNet
then
4637 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4638 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4645 function nonz(a
: Single): Single;
4653 procedure TPlayer
.Update();
4656 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4657 blockmon
, headwater
, dospawn
: Boolean;
4662 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4663 AnyServer
:= g_Game_IsServer
;
4665 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4666 DoLerp(NetInterpLevel
+ 1)
4672 if FClientID
>= 0 then
4674 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4675 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4676 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4685 if FLive
and (gFly
or FJetpack
) then
4688 if FDirection
= D_LEFT
then
4693 if FLive
and (not FGhost
) then
4695 if FKeys
[KEY_UP
].Pressed
then
4697 if FKeys
[KEY_DOWN
].Pressed
then
4701 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4704 i
:= g_basic
.Sign(FIncCam
);
4705 FIncCam
:= Abs(FIncCam
);
4706 DecMin(FIncCam
, 5, 0);
4707 FIncCam
:= FIncCam
*i
;
4710 // no need to do that each second frame, weapon queue will take care of it
4711 if FLive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4712 if FLive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4714 if gTime
mod (GAME_TICK
*2) <> 0 then
4716 if (FObj
.Vel
.X
= 0) and FLive
then
4718 if FKeys
[KEY_LEFT
].Pressed
then
4720 if FKeys
[KEY_RIGHT
].Pressed
then
4726 g_Obj_Move(@FObj
, True, True, True);
4727 positionChanged(); // this updates spatial accelerators
4733 FActionChanged
:= False;
4737 // Let alive player do some actions
4738 if FKeys
[KEY_LEFT
].Pressed
then Run(D_LEFT
);
4739 if FKeys
[KEY_RIGHT
].Pressed
then Run(D_RIGHT
);
4740 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
4741 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
4742 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
4743 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
4744 if FKeys
[KEY_JUMP
].Pressed
then Jump()
4747 if AnyServer
and FJetpack
then
4751 if NetServer
then MH_SEND_PlayerStats(FUID
);
4753 FCanJetpack
:= True;
4760 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
4762 if FKeys
[k
].Pressed
then
4770 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4773 if (FTime
[T_RESPAWN
] <= gTime
) and
4774 gGameOn
and (not FLive
) then
4776 if (g_Player_GetCount() > 1) then
4780 gExit
:= EXIT_RESTART
;
4785 // Dead spectator actions
4788 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
4789 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
4793 if (FSpectatePlayer
>= High(gPlayers
)) then
4794 FSpectatePlayer
:= -1
4798 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
4799 if gPlayers
[I
] <> nil then
4800 if gPlayers
[I
].Live
then
4801 if gPlayers
[I
].UID
<> FUID
then
4803 FSpectatePlayer
:= I
;
4808 if not SetSpect
then FSpectatePlayer
:= -1;
4819 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
4821 FYTo
:= FObj
.Y
- 32;
4822 FSpectatePlayer
:= -1;
4824 if FKeys
[KEY_DOWN
].Pressed
then
4826 FYTo
:= FObj
.Y
+ 32;
4827 FSpectatePlayer
:= -1;
4829 if FKeys
[KEY_LEFT
].Pressed
then
4831 FXTo
:= FObj
.X
- 32;
4832 FSpectatePlayer
:= -1;
4834 if FKeys
[KEY_RIGHT
].Pressed
then
4836 FXTo
:= FObj
.X
+ 32;
4837 FSpectatePlayer
:= -1;
4840 if (FXTo
< -64) then
4842 else if (FXTo
> gMapInfo
.Width
+ 32) then
4843 FXTo
:= gMapInfo
.Width
+ 32;
4844 if (FYTo
< -72) then
4846 else if (FYTo
> gMapInfo
.Height
+ 32) then
4847 FYTo
:= gMapInfo
.Height
+ 32;
4852 g_Obj_Move(@FObj
, True, True, True);
4853 positionChanged(); // this updates spatial accelerators
4860 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
4861 if gPlayers
[FSpectatePlayer
] <> nil then
4862 if gPlayers
[FSpectatePlayer
].Live
then
4864 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
4865 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
4869 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
4870 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
4871 PANEL_BLOCKMON
, True);
4872 headwater
:= HeadInLiquid(0, 0);
4874 // Ñîïðîòèâëåíèå âîçäóõà:
4875 if (not FLive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
4876 if FObj
.Vel
.X
<> 0 then
4877 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
4879 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
4880 DecMin(FPain
, 5, 0);
4881 DecMin(FPickup
, 1, 0);
4883 if FLive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
4885 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
4886 FMegaRulez
[MR_SUIT
] := 0;
4887 FMegaRulez
[MR_INVUL
] := 0;
4888 FMegaRulez
[MR_INVIS
] := 0;
4889 Kill(K_FALLKILL
, 0, HIT_FALL
);
4896 if FCurrWeap
= WEAPON_SAW
then
4897 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
4898 FSawSoundSelect
.IsPlaying()) then
4899 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
4902 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
4903 (not FJetSoundOff
.IsPlaying()) then
4905 FJetSoundFly
.SetPosition(0);
4906 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
4909 for b
:= WP_FIRST
to WP_LAST
do
4910 if FReloading
[b
] > 0 then
4916 if FShellTimer
> -1 then
4917 if FShellTimer
= 0 then
4919 if FShellType
= SHELL_SHELL
then
4920 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4921 GameVelX
, GameVelY
-2, SHELL_SHELL
)
4922 else if FShellType
= SHELL_DBLSHELL
then
4924 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4925 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
4926 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4927 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
4930 end else Dec(FShellTimer
);
4932 if (FBFGFireCounter
> -1) then
4933 if FBFGFireCounter
= 0 then
4937 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
4938 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
4939 xd
:= wx
+IfThen(FDirection
= D_LEFT
, -30, 30);
4940 yd
:= wy
+firediry();
4941 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
4942 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
4943 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
4944 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
4945 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
4948 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
4949 FBFGFireCounter
:= -1;
4952 FBFGFireCounter
:= 0
4954 Dec(FBFGFireCounter
);
4956 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
4958 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
4960 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
4963 if (headwater
or blockmon
) then
4969 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
4972 else if (FAir
mod 31 = 0) and not blockmon
then
4974 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
4975 if Random(2) = 0 then
4976 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
4978 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
4980 end else if FAir
< AIR_DEF
then
4983 if FFireTime
> 0 then
4985 if BodyInLiquid(0, 0) then
4990 else if FMegaRulez
[MR_SUIT
] >= gTime
then
4992 if FMegaRulez
[MR_SUIT
] = gTime
then
4999 if FFirePainTime
<= 0 then
5001 if g_Game_IsServer
then
5002 Damage(5, FFireAttacker
, 0, 0, HIT_FLAME
);
5003 FFirePainTime
:= 18;
5005 FFirePainTime
:= FFirePainTime
- 1;
5006 FFireTime
:= FFireTime
- 1;
5007 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5008 MH_SEND_PlayerStats(FUID
);
5012 if FDamageBuffer
> 0 then
5014 if FDamageBuffer
>= 9 then
5018 if FDamageBuffer
< 30 then i
:= 9
5019 else if FDamageBuffer
< 100 then i
:= 18
5023 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5024 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5025 FHealth
:= FHealth
-ii
;
5028 FHealth
:= FHealth
+FArmor
;
5033 if FHealth
<= 0 then
5034 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5035 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5036 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5040 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5041 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5042 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5043 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5050 end; // if FLive then ...
5052 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5054 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5055 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5056 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5057 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5059 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5060 then SetAction(A_STAND
, True);
5062 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5064 for b
:= Low(FKeys
) to High(FKeys
) do
5065 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5068 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5070 x
:= FObj
.X
+PLAYER_RECT
.X
;
5071 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5072 w
:= PLAYER_RECT
.Width
;
5073 h
:= PLAYER_RECT
.Height
;
5076 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5078 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5079 FObj
.Y
+PLAYER_RECT
.Y
,
5086 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5088 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5089 FObj
.Y
+PLAYER_RECT
.Y
,
5093 Panel
.Width
, Panel
.Height
);
5096 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5098 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5099 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5100 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5101 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5104 function g_Player_ValidName(Name
: string): Boolean;
5110 if gPlayers
= nil then Exit
;
5112 for a
:= 0 to High(gPlayers
) do
5113 if gPlayers
[a
] <> nil then
5114 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5121 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5125 d
:= FModel
.Direction
;
5127 FModel
.Direction
:= Direction
;
5128 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5130 FDirection
:= Direction
;
5133 function TPlayer
.GetKeys(): Byte;
5137 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5138 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5139 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5141 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5142 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5145 procedure TPlayer
.Use();
5149 if FTime
[T_USE
] > gTime
then Exit
;
5151 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5152 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5154 for a
:= 0 to High(gPlayers
) do
5155 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5156 gPlayers
[a
].Live
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5157 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5158 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5160 gPlayers
[a
].Touch();
5161 if g_Game_IsNet
and g_Game_IsServer
then
5162 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5165 FTime
[T_USE
] := gTime
+120;
5168 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5172 WX
, WY
, XD
, YD
: Integer;
5183 if R_BERSERK
in FRulez
then
5185 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5186 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5187 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5190 locobj
.rect
.Width
:= 39;
5191 locobj
.rect
.Height
:= 52;
5192 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5193 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5194 locobj
.Accel
.X
:= xd
-wx
;
5195 locobj
.Accel
.y
:= yd
-wy
;
5197 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5198 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5200 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5204 FPain
:= min(FPain
+ 25, 50);
5206 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5211 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5212 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5214 FSawSoundSelect
.Stop();
5216 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5218 else if not FSawSoundHit
.IsPlaying() then
5220 FSawSoundSelect
.Stop();
5221 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5228 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5229 FFireAngle
:= FAngle
;
5231 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5232 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5237 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5238 FFireAngle
:= FAngle
;
5241 FShellType
:= SHELL_SHELL
;
5246 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5247 FFireAngle
:= FAngle
;
5250 FShellType
:= SHELL_DBLSHELL
;
5255 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5256 FFireAngle
:= FAngle
;
5258 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5259 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5262 WEAPON_ROCKETLAUNCHER
:
5264 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5265 FFireAngle
:= FAngle
;
5271 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5272 FFireAngle
:= FAngle
;
5278 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5279 FFireAngle
:= FAngle
;
5283 WEAPON_SUPERPULEMET
:
5285 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5286 FFireAngle
:= FAngle
;
5288 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5289 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5292 WEAPON_FLAMETHROWER
:
5294 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5295 FFireAngle
:= FAngle
;
5302 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5303 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5304 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5307 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5309 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5310 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5313 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5317 if NetInterpLevel
< 1 then
5327 AX
:= Abs(FXTo
- FObj
.X
);
5328 AY
:= Abs(FYTo
- FObj
.Y
);
5329 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5331 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5336 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5338 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5339 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5340 PANEL_LIFTUP
, False) then Result
:= -1
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_LIFTDOWN
, False) then Result
:= 1
5348 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5355 if Flag
= FLAG_NONE
then
5358 if not g_Game_IsServer
then Exit
;
5360 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5361 if (Flag
= FTeam
) and
5362 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5363 (FFlag
<> FLAG_NONE
) then
5365 if FFlag
= FLAG_RED
then
5366 s
:= _lc
[I_PLAYER_FLAG_RED
]
5368 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5370 evtype
:= FLAG_STATE_SCORED
;
5372 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5373 Insert('.', ts
, Length(ts
) + 1 - 3);
5374 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5376 g_Map_ResetFlag(FFlag
);
5377 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5379 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5382 if g_Game_IsNet
then
5384 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5388 gFlags
[FFlag
].CaptureTime
:= 0;
5393 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5394 if (Flag
= FTeam
) and
5395 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5397 if Flag
= FLAG_RED
then
5398 s
:= _lc
[I_PLAYER_FLAG_RED
]
5400 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5402 evtype
:= FLAG_STATE_RETURNED
;
5403 gFlags
[Flag
].CaptureTime
:= 0;
5405 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5407 g_Map_ResetFlag(Flag
);
5408 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5411 if g_Game_IsNet
then
5413 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5419 // Ïîäîáðàë ÷óæîé ôëàã:
5420 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5424 if Flag
= FLAG_RED
then
5425 s
:= _lc
[I_PLAYER_FLAG_RED
]
5427 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5429 evtype
:= FLAG_STATE_CAPTURED
;
5431 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5433 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5435 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5438 if g_Game_IsNet
then
5440 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5446 procedure TPlayer
.SetFlag(Flag
: Byte);
5449 if FModel
<> nil then
5450 FModel
.SetFlag(FFlag
);
5453 function TPlayer
.DropFlag(): Boolean;
5458 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5460 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5461 with gFlags
[FFlag
] do
5465 Direction
:= FDirection
;
5466 State
:= FLAG_STATE_DROPPED
;
5468 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5469 (FObj
.Vel
.Y
div 2)-2+Random(5));
5470 positionChanged(); // this updates spatial accelerators
5472 if FFlag
= FLAG_RED
then
5473 s
:= _lc
[I_PLAYER_FLAG_RED
]
5475 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5477 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5478 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5480 if g_Game_IsNet
then
5481 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5487 procedure TPlayer
.GetSecret();
5492 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5494 Assert(Key
<= High(FKeys
));
5496 FKeys
[Key
].Pressed
:= True;
5497 FKeys
[Key
].Time
:= Time
;
5500 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5502 Result
:= FKeys
[K
].Pressed
;
5505 procedure TPlayer
.ReleaseKeys();
5509 for a
:= Low(FKeys
) to High(FKeys
) do
5511 FKeys
[a
].Pressed
:= False;
5516 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5520 function TPlayer
.firediry(): Integer;
5522 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5523 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5527 procedure TPlayer
.RememberState();
5531 FSavedState
.Health
:= FHealth
;
5532 FSavedState
.Armor
:= FArmor
;
5533 FSavedState
.Air
:= FAir
;
5534 FSavedState
.JetFuel
:= FJetFuel
;
5535 FSavedState
.CurrWeap
:= FCurrWeap
;
5536 FSavedState
.NextWeap
:= FNextWeap
;
5537 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5540 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5542 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5544 FSavedState
.Rulez
:= FRulez
;
5545 FSavedState
.WaitRecall
:= True;
5548 procedure TPlayer
.RecallState();
5552 if not FSavedState
.WaitRecall
then Exit
;
5554 FHealth
:= FSavedState
.Health
;
5555 FArmor
:= FSavedState
.Armor
;
5556 FAir
:= FSavedState
.Air
;
5557 FJetFuel
:= FSavedState
.JetFuel
;
5558 FCurrWeap
:= FSavedState
.CurrWeap
;
5559 FNextWeap
:= FSavedState
.NextWeap
;
5560 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5563 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5565 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5567 FRulez
:= FSavedState
.Rulez
;
5568 FSavedState
.WaitRecall
:= False;
5570 if gGameSettings
.GameType
= GT_SERVER
then
5571 MH_SEND_PlayerStats(FUID
);
5574 procedure TPlayer
.SaveState(var Mem
: TBinMemoryWriter
);
5586 Mem
:= TBinMemoryWriter
.Create(i
);
5588 // Ñèãíàòóðà èãðîêà:
5589 sig
:= PLAYER_SIGNATURE
; // 'PLYR'
5590 Mem
.WriteDWORD(sig
);
5592 Mem
.WriteBoolean(FIamBot
);
5594 Mem
.WriteWord(FUID
);
5596 Mem
.WriteString(FName
, 32);
5598 Mem
.WriteByte(FTeam
);
5600 Mem
.WriteBoolean(FLive
);
5601 // Èçðàñõîäîâàë ëè âñå æèçíè:
5602 Mem
.WriteBoolean(FNoRespawn
);
5604 if FDirection
= D_LEFT
then
5610 Mem
.WriteInt(FHealth
);
5612 Mem
.WriteByte(FLives
);
5614 Mem
.WriteInt(FArmor
);
5618 Mem
.WriteInt(FJetFuel
);
5620 Mem
.WriteInt(FPain
);
5622 Mem
.WriteInt(FKills
);
5624 Mem
.WriteInt(FMonsterKills
);
5626 Mem
.WriteInt(FFrags
);
5628 Mem
.WriteByte(FFragCombo
);
5629 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5630 Mem
.WriteDWORD(FLastFrag
);
5632 Mem
.WriteInt(FDeath
);
5633 // Êàêîé ôëàã íåñåò:
5634 Mem
.WriteByte(FFlag
);
5636 Mem
.WriteInt(FSecrets
);
5638 Mem
.WriteByte(FCurrWeap
);
5640 Mem
.WriteWord(FNextWeap
);
5642 Mem
.WriteByte(FNextWeapDelay
);
5643 // Âðåìÿ çàðÿäêè BFG:
5644 Mem
.WriteSmallInt(FBFGFireCounter
);
5646 Mem
.WriteInt(FDamageBuffer
);
5647 // Ïîñëåäíèé óäàðèâøèé:
5648 Mem
.WriteWord(FLastSpawnerUID
);
5649 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5650 Mem
.WriteByte(FLastHit
);
5652 Obj_SaveState(@FObj
, Mem
);
5653 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5654 for i
:= A_BULLETS
to A_HIGH
do
5655 Mem
.WriteWord(FAmmo
[i
]);
5656 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5657 for i
:= A_BULLETS
to A_HIGH
do
5658 Mem
.WriteWord(FMaxAmmo
[i
]);
5660 for i
:= WP_FIRST
to WP_LAST
do
5661 Mem
.WriteBoolean(FWeapon
[i
]);
5662 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5663 for i
:= WP_FIRST
to WP_LAST
do
5664 Mem
.WriteWord(FReloading
[i
]);
5666 if R_ITEM_BACKPACK
in FRulez
then
5671 // Íàëè÷èå êðàñíîãî êëþ÷à:
5672 if R_KEY_RED
in FRulez
then
5677 // Íàëè÷èå çåëåíîãî êëþ÷à:
5678 if R_KEY_GREEN
in FRulez
then
5683 // Íàëè÷èå ñèíåãî êëþ÷à:
5684 if R_KEY_BLUE
in FRulez
then
5689 // Íàëè÷èå áåðñåðêà:
5690 if R_BERSERK
in FRulez
then
5695 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5696 for i
:= MR_SUIT
to MR_MAX
do
5697 Mem
.WriteDWORD(FMegaRulez
[i
]);
5698 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5699 for i
:= T_RESPAWN
to T_FLAGCAP
do
5700 Mem
.WriteDWORD(FTime
[i
]);
5703 Mem
.WriteString(str
);
5713 procedure TPlayer
.LoadState(var Mem
: TBinMemoryReader
);
5723 // Ñèãíàòóðà èãðîêà:
5725 if sig
<> PLAYER_SIGNATURE
then // 'PLYR'
5727 raise EBinSizeError
.Create('TPlayer.LoadState: Wrong Player Signature');
5730 Mem
.ReadBoolean(FIamBot
);
5734 Mem
.ReadString(str
);
5735 if (Self
<> gPlayer1
) and (Self
<> gPlayer2
) then
5738 Mem
.ReadByte(FTeam
);
5740 Mem
.ReadBoolean(FLive
);
5741 // Èçðàñõîäîâàë ëè âñå æèçíè:
5742 Mem
.ReadBoolean(FNoRespawn
);
5746 FDirection
:= D_LEFT
5748 FDirection
:= D_RIGHT
;
5750 Mem
.ReadInt(FHealth
);
5752 Mem
.ReadByte(FLives
);
5754 Mem
.ReadInt(FArmor
);
5758 Mem
.ReadInt(FJetFuel
);
5762 Mem
.ReadInt(FKills
);
5764 Mem
.ReadInt(FMonsterKills
);
5766 Mem
.ReadInt(FFrags
);
5768 Mem
.ReadByte(FFragCombo
);
5769 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5770 Mem
.ReadDWORD(FLastFrag
);
5772 Mem
.ReadInt(FDeath
);
5773 // Êàêîé ôëàã íåñåò:
5774 Mem
.ReadByte(FFlag
);
5776 Mem
.ReadInt(FSecrets
);
5778 Mem
.ReadByte(FCurrWeap
);
5780 Mem
.ReadWord(FNextWeap
);
5782 Mem
.ReadByte(FNextWeapDelay
);
5783 // Âðåìÿ çàðÿäêè BFG:
5784 Mem
.ReadSmallInt(FBFGFireCounter
);
5786 Mem
.ReadInt(FDamageBuffer
);
5787 // Ïîñëåäíèé óäàðèâøèé:
5788 Mem
.ReadWord(FLastSpawnerUID
);
5789 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5790 Mem
.ReadByte(FLastHit
);
5792 Obj_LoadState(@FObj
, Mem
);
5793 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5794 for i
:= A_BULLETS
to A_HIGH
do
5795 Mem
.ReadWord(FAmmo
[i
]);
5796 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5797 for i
:= A_BULLETS
to A_HIGH
do
5798 Mem
.ReadWord(FMaxAmmo
[i
]);
5800 for i
:= WP_FIRST
to WP_LAST
do
5801 Mem
.ReadBoolean(FWeapon
[i
]);
5802 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5803 for i
:= WP_FIRST
to WP_LAST
do
5804 Mem
.ReadWord(FReloading
[i
]);
5808 Include(FRulez
, R_ITEM_BACKPACK
);
5809 // Íàëè÷èå êðàñíîãî êëþ÷à:
5812 Include(FRulez
, R_KEY_RED
);
5813 // Íàëè÷èå çåëåíîãî êëþ÷à:
5816 Include(FRulez
, R_KEY_GREEN
);
5817 // Íàëè÷èå ñèíåãî êëþ÷à:
5820 Include(FRulez
, R_KEY_BLUE
);
5821 // Íàëè÷èå áåðñåðêà:
5824 Include(FRulez
, R_BERSERK
);
5825 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5826 for i
:= MR_SUIT
to MR_MAX
do
5827 Mem
.ReadDWORD(FMegaRulez
[i
]);
5828 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5829 for i
:= T_RESPAWN
to T_FLAGCAP
do
5830 Mem
.ReadDWORD(FTime
[i
]);
5832 Mem
.ReadString(str
);
5834 Mem
.ReadByte(FColor
.R
);
5835 Mem
.ReadByte(FColor
.G
);
5836 Mem
.ReadByte(FColor
.B
);
5837 if Self
= gPlayer1
then
5839 str
:= gPlayer1Settings
.Model
;
5840 FColor
:= gPlayer1Settings
.Color
;
5842 if Self
= gPlayer2
then
5844 str
:= gPlayer2Settings
.Model
;
5845 FColor
:= gPlayer2Settings
.Color
;
5847 // Îáíîâëÿåì ìîäåëü èãðîêà:
5849 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
5850 FModel
.Color
:= TEAMCOLOR
[FTeam
]
5852 FModel
.Color
:= FColor
;
5855 procedure TPlayer
.AllRulez(Health
: Boolean);
5861 FHealth
:= PLAYER_HP_LIMIT
;
5862 FArmor
:= PLAYER_AP_LIMIT
;
5866 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
5867 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
5868 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5871 procedure TPlayer
.RestoreHealthArmor();
5873 FHealth
:= PLAYER_HP_LIMIT
;
5874 FArmor
:= PLAYER_AP_LIMIT
;
5877 procedure TPlayer
.FragCombo();
5881 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
5883 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
5885 if FFragCombo
< 5 then
5887 Param
:= FUID
or (FFragCombo
shl 16);
5888 if (FComboEvnt
>= Low(gDelayedEvents
)) and
5889 (FComboEvnt
<= High(gDelayedEvents
)) and
5890 gDelayedEvents
[FComboEvnt
].Pending
and
5891 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
5892 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
5894 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
5895 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
5898 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
5906 procedure TPlayer
.GiveItem(ItemType
: Byte);
5910 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
5912 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
5916 if FAir
< AIR_MAX
then
5923 if not (R_BERSERK
in FRulez
) then
5925 Include(FRulez
, R_BERSERK
);
5926 if FBFGFireCounter
< 1 then
5928 FCurrWeap
:= WEAPON_KASTET
;
5930 FModel
.SetWeapon(WEAPON_KASTET
);
5934 FBerserk
:= gTime
+30000;
5936 if FHealth
< PLAYER_HP_SOFT
then
5938 FHealth
:= PLAYER_HP_SOFT
;
5939 FBerserk
:= gTime
+30000;
5944 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
5946 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
5950 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
5952 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
5956 if FJetFuel
< JET_MAX
then
5958 FJetFuel
:= JET_MAX
;
5961 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
5962 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
5964 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
5965 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5967 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
5969 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
5971 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
5972 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5975 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
5976 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
5977 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
5978 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
5979 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
5980 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
5981 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
5982 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
5983 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
5985 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5986 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
5987 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5988 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
5989 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5990 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
5991 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5992 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
5993 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
5996 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
5997 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
5998 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
5999 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6000 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6002 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6003 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6004 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6005 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6006 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6008 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6009 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6010 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6011 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6013 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6016 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6017 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6018 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6020 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6021 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6026 if g_Game_IsNet
and g_Game_IsServer
then
6027 MH_SEND_PlayerStats(FUID
);
6030 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6035 if (Random(5) = 1) and (Times
= 1) then
6038 if BodyInLiquid(0, 0) then
6040 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6041 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6042 if Random(2) = 0 then
6043 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6045 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6049 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6051 for i
:= 1 to Times
do
6053 Anim
:= TAnimation
.Create(id
, False, 3);
6055 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6056 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6062 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6067 if (Random(10) = 1) and (Times
= 1) then
6070 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6072 for i
:= 1 to Times
do
6074 Anim
:= TAnimation
.Create(id
, False, 3);
6076 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6077 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6083 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6085 FSawSound
.Pause(Enable
);
6086 FSawSoundIdle
.Pause(Enable
);
6087 FSawSoundHit
.Pause(Enable
);
6088 FSawSoundSelect
.Pause(Enable
);
6093 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6098 FObj
.Rect
:= PLAYER_CORPSERECT
;
6099 FModelName
:= ModelName
;
6104 FState
:= CORPSE_STATE_MESS
;
6105 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6109 FState
:= CORPSE_STATE_NORMAL
;
6110 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6114 destructor TCorpse
.Destroy();
6121 procedure TCorpse
.positionChanged (); begin end;
6123 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6127 if FState
= CORPSE_STATE_REMOVEME
then
6130 FDamage
:= FDamage
+ Value
;
6132 if FDamage
> 150 then
6134 if FAnimation
<> nil then
6139 FState
:= CORPSE_STATE_REMOVEME
;
6141 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6142 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6143 FModelName
, FColor
);
6144 // Çâóê ìÿñà îò òðóïà:
6145 pm
:= g_PlayerModel_Get(FModelName
);
6146 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6152 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6153 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6154 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6155 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6156 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6161 procedure TCorpse
.Draw();
6163 if FState
= CORPSE_STATE_REMOVEME
then
6166 if FAnimation
<> nil then
6167 FAnimation
.Draw(FObj
.X
, FObj
.Y
, M_NONE
);
6169 if FAnimationMask
<> nil then
6172 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, M_NONE
);
6179 procedure TCorpse
.Update();
6183 if FState
= CORPSE_STATE_REMOVEME
then
6186 if gTime
mod (GAME_TICK
*2) <> 0 then
6188 g_Obj_Move(@FObj
, True, True, True);
6189 positionChanged(); // this updates spatial accelerators
6193 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6194 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6196 st
:= g_Obj_Move(@FObj
, True, True, True);
6197 positionChanged(); // this updates spatial accelerators
6199 if WordBool(st
and MOVE_FALLOUT
) then
6201 FState
:= CORPSE_STATE_REMOVEME
;
6205 if FAnimation
<> nil then
6206 FAnimation
.Update();
6207 if FAnimationMask
<> nil then
6208 FAnimationMask
.Update();
6211 procedure TCorpse
.SaveState(var Mem
: TBinMemoryWriter
);
6220 sig
:= CORPSE_SIGNATURE
; // 'CORP'
6221 Mem
.WriteDWORD(sig
);
6223 Mem
.WriteByte(FState
);
6224 // Íàêîïëåííûé óðîí:
6225 Mem
.WriteByte(FDamage
);
6227 Mem
.WriteByte(FColor
.R
);
6228 Mem
.WriteByte(FColor
.G
);
6229 Mem
.WriteByte(FColor
.B
);
6231 Obj_SaveState(@FObj
, Mem
);
6232 // Åñòü ëè àíèìàöèÿ:
6233 anim
:= FAnimation
<> nil;
6234 Mem
.WriteBoolean(anim
);
6235 // Åñëè åñòü - ñîõðàíÿåì:
6237 FAnimation
.SaveState(Mem
);
6238 // Åñòü ëè ìàñêà àíèìàöèè:
6239 anim
:= FAnimationMask
<> nil;
6240 Mem
.WriteBoolean(anim
);
6241 // Åñëè åñòü - ñîõðàíÿåì:
6243 FAnimationMask
.SaveState(Mem
);
6246 procedure TCorpse
.LoadState(var Mem
: TBinMemoryReader
);
6256 if sig
<> CORPSE_SIGNATURE
then // 'CORP'
6258 raise EBinSizeError
.Create('TCorpse.LoadState: Wrong Corpse Signature');
6261 Mem
.ReadByte(FState
);
6262 // Íàêîïëåííûé óðîí:
6263 Mem
.ReadByte(FDamage
);
6265 Mem
.ReadByte(FColor
.R
);
6266 Mem
.ReadByte(FColor
.G
);
6267 Mem
.ReadByte(FColor
.B
);
6269 Obj_LoadState(@FObj
, Mem
);
6270 // Åñòü ëè àíèìàöèÿ:
6271 Mem
.ReadBoolean(anim
);
6272 // Åñëè åñòü - çàãðóæàåì:
6275 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6276 FAnimation
.LoadState(Mem
);
6278 // Åñòü ëè ìàñêà àíèìàöèè:
6279 Mem
.ReadBoolean(anim
);
6280 // Åñëè åñòü - çàãðóæàåì:
6283 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6284 FAnimationMask
.LoadState(Mem
);
6290 constructor TBot
.Create();
6297 FSpectator
:= False;
6304 for a
:= WP_FIRST
to WP_LAST
do
6306 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6307 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6308 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6312 destructor TBot
.Destroy();
6315 inherited Destroy();
6318 procedure TBot
.Draw();
6322 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6323 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6326 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6328 inherited Respawn(Silent
, Force
);
6331 FSelectedWeapon
:= FCurrWeap
;
6336 procedure TBot
.UpdateCombat();
6349 TTargetRecord
= array of TTarget
;
6351 function Compare(a
, b
: TTarget
): Integer;
6353 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6356 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6358 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6359 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6361 if a
.Dist
> b
.Dist
then // B áëèæå
6363 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6366 else // Ñòðàííî -> A
6371 a
, x1
, y1
, x2
, y2
: Integer;
6372 targets
: TTargetRecord
;
6374 Target
, BestTarget
: TTarget
;
6375 firew
, fireh
: Integer;
6379 vsPlayer
, vsMonster
, ok
: Boolean;
6382 function monsUpdate (mon
: TMonster
): Boolean;
6384 result
:= false; // don't stop
6385 if mon
.Live
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6387 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6389 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6390 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6392 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6393 if g_TraceVector(x1
, y1
, x2
, y2
) then
6395 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6396 SetLength(targets
, Length(targets
)+1);
6397 with targets
[High(targets
)] do
6404 Rect
:= mon
.Obj
.Rect
;
6405 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6406 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6407 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6416 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6417 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6419 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6420 if FCurrWeap
<> FSelectedWeapon
then
6423 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6424 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6426 RemoveAIFlag('NEEDFIRE');
6429 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6430 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6431 else PressKey(KEY_FIRE
);
6435 // Êîîðäèíàòû ñòâîëà:
6436 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6437 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6439 Target
.UID
:= FTargetUID
;
6442 if Target
.UID
<> 0 then
6443 begin // Öåëü åñòü - íàñòðàèâàåì
6444 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6447 tpla
:= g_Player_Get(Target
.UID
);
6451 if (@FObj
) <> nil then
6458 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6459 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6460 Target
.Rect
:= PLAYER_RECT
;
6461 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6462 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6463 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6464 Target
.IsPlayer
:= True;
6468 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6471 mon
:= g_Monsters_ByUID(Target
.UID
);
6474 Target
.X
:= mon
.Obj
.X
;
6475 Target
.Y
:= mon
.Obj
.Y
;
6477 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6478 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6479 Target
.Rect
:= mon
.Obj
.Rect
;
6480 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6481 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6482 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6483 Target
.IsPlayer
:= False;
6490 begin // Öåëè íåò - îáíóëÿåì
6495 Target
.Visible
:= False;
6496 Target
.Line
:= False;
6497 Target
.IsPlayer
:= False;
6502 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6503 if (not Target
.Line
) or (not Target
.Visible
) then
6507 for a
:= 0 to High(gPlayers
) do
6508 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].Live
) and
6509 (gPlayers
[a
].FUID
<> FUID
) and
6510 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6511 (not gPlayers
[a
].NoTarget
) and
6512 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6514 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6515 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6518 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6519 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6521 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6522 if g_TraceVector(x1
, y1
, x2
, y2
) then
6524 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6525 SetLength(targets
, Length(targets
)+1);
6526 with targets
[High(targets
)] do
6528 UID
:= gPlayers
[a
].FUID
;
6529 X
:= gPlayers
[a
].FObj
.X
;
6530 Y
:= gPlayers
[a
].FObj
.Y
;
6533 Rect
:= PLAYER_RECT
;
6534 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6535 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6536 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6544 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6547 // Åñëè åñòü âîçìîæíûå öåëè:
6548 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6549 if targets
<> nil then
6551 // Âûáèðàåì íàèëó÷øóþ öåëü:
6552 BestTarget
:= targets
[0];
6553 if Length(targets
) > 1 then
6554 for a
:= 1 to High(targets
) do
6555 if Compare(BestTarget
, targets
[a
]) = 1 then
6556 BestTarget
:= targets
[a
];
6558 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6559 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6560 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6562 Target
:= BestTarget
;
6564 if (Healthy() = 3) or ((Healthy() = 2)) then
6565 begin // Åñëè çäîðîâû - äîãîíÿåì
6566 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6567 SetAIFlag('GORIGHT', '1');
6568 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6569 SetAIFlag('GOLEFT', '1');
6572 begin // Åñëè ïîáèòû - óáåãàåì
6573 if ((RunDirection() = D_LEFT
) and (Target
.X
< FObj
.X
)) then
6574 SetAIFlag('GORIGHT', '1');
6575 if ((RunDirection() = D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6576 SetAIFlag('GOLEFT', '1');
6579 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6580 SelectWeapon(Abs(x1
-Target
.cX
));
6585 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6586 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6587 if Target
.UID
<> 0 then
6589 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6590 Target
.Y
+ Target
.Rect
.Y
) then
6591 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6592 if (Healthy() = 3) or ((Healthy() = 2)) then
6593 begin // Åñëè çäîðîâû - äîãîíÿåì
6594 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6595 SetAIFlag('GORIGHT', '1');
6596 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6597 SetAIFlag('GOLEFT', '1');
6600 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6602 if ((RunDirection() = D_LEFT
) and (Target
.X
< FObj
.X
)) then
6603 SetAIFlag('GORIGHT', '1');
6604 if ((RunDirection() = D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6605 SetAIFlag('GOLEFT', '1');
6609 begin // Öåëü ïîêà íà "ýêðàíå"
6610 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6611 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6612 FLastVisible
:= gTime
;
6613 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6614 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6616 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6617 SetAIFlag('GORIGHT', '1');
6618 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6619 SetAIFlag('GOLEFT', '1');
6623 // Âûáèðàåì óãîë ââåðõ:
6624 if FDirection
= D_LEFT
then
6625 angle
:= ANGLE_LEFTUP
6627 angle
:= ANGLE_RIGHTUP
;
6629 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6630 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6632 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6633 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6634 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6635 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6636 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6637 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6638 begin // òî íóæíî ñòðåëÿòü ââåðõ
6639 SetAIFlag('NEEDFIRE', '1');
6640 SetAIFlag('NEEDSEEUP', '1');
6643 // Âûáèðàåì óãîë âíèç:
6644 if FDirection
= D_LEFT
then
6645 angle
:= ANGLE_LEFTDOWN
6647 angle
:= ANGLE_RIGHTDOWN
;
6649 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6650 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6652 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6653 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6654 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6655 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6656 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6657 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6658 begin // òî íóæíî ñòðåëÿòü âíèç
6659 SetAIFlag('NEEDFIRE', '1');
6660 SetAIFlag('NEEDSEEDOWN', '1');
6663 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6664 if Target
.Visible
and
6665 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6666 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6668 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6669 if ((FDirection
= D_LEFT
) and (Target
.X
< FObj
.X
)) or
6670 ((FDirection
= D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6671 begin // òî íóæíî ñòðåëÿòü âïåðåä
6672 SetAIFlag('NEEDFIRE', '1');
6673 SetAIFlag('NEEDSEEDOWN', '');
6674 SetAIFlag('NEEDSEEUP', '');
6676 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6677 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6678 if GetRnd(FDifficult
.CloseJump
) then
6679 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6680 if Abs(FObj
.X
-Target
.X
) < 128 then
6684 if Random(a
) = 0 then
6685 SetAIFlag('NEEDJUMP', '1');
6689 // Åñëè öåëü âñå åùå åñòü:
6690 if Target
.UID
<> 0 then
6691 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
6692 Target
.UID
:= 0 // òî çàáûòü öåëü
6693 else // Åñëè âèäåëè íåäàâíî
6694 begin // íî öåëü óáèëè
6695 if Target
.IsPlayer
then
6696 begin // Öåëü - èãðîê
6697 pla
:= g_Player_Get(Target
.UID
);
6698 if (pla
= nil) or (not pla
.Live
) or pla
.NoTarget
or
6699 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6700 Target
.UID
:= 0; // òî çàáûòü öåëü
6703 begin // Öåëü - ìîíñòð
6704 mon
:= g_Monsters_ByUID(Target
.UID
);
6705 if (mon
= nil) or (not mon
.Live
) then
6706 Target
.UID
:= 0; // òî çàáûòü öåëü
6709 end; // if Target.UID <> 0
6711 FTargetUID
:= Target
.UID
;
6713 // Åñëè âîçìîæíûõ öåëåé íåò:
6714 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
6715 if targets
= nil then
6716 if GetAIFlag('ATTACKLEFT') <> '' then
6717 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
6718 RemoveAIFlag('ATTACKLEFT');
6720 SetAIFlag('NEEDJUMP', '1');
6722 if RunDirection() = D_RIGHT
then
6723 begin // Èäåì íå â òó ñòîðîíó
6724 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6725 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
6726 SetAIFlag('NEEDFIRE', '1');
6727 SetAIFlag('GOLEFT', '1');
6731 begin // Èäåì â íóæíóþ ñòîðîíó
6732 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6733 SetAIFlag('NEEDFIRE', '1');
6734 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6735 SetAIFlag('GORIGHT', '1');
6739 if GetAIFlag('ATTACKRIGHT') <> '' then
6740 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
6741 RemoveAIFlag('ATTACKRIGHT');
6743 SetAIFlag('NEEDJUMP', '1');
6745 if RunDirection() = D_LEFT
then
6746 begin // Èäåì íå â òó ñòîðîíó
6747 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6748 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
6749 SetAIFlag('NEEDFIRE', '1');
6750 SetAIFlag('GORIGHT', '1');
6755 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6756 SetAIFlag('NEEDFIRE', '1');
6757 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6758 SetAIFlag('GOLEFT', '1');
6762 //HACK! (does it belongs there?)
6763 RealizeCurrentWeapon();
6765 // Åñëè åñòü âîçìîæíûå öåëè:
6766 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
6767 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6768 for a
:= 0 to High(targets
) do
6770 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
6771 if GetRnd(FDifficult
.DiagFire
) then
6773 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
6774 if FDirection
= D_LEFT
then
6775 angle
:= ANGLE_LEFTUP
6777 angle
:= ANGLE_RIGHTUP
;
6779 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6780 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6782 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6783 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6784 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6785 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6786 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6788 SetAIFlag('NEEDFIRE', '1');
6789 SetAIFlag('NEEDSEEUP', '1');
6792 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
6793 if FDirection
= D_LEFT
then
6794 angle
:= ANGLE_LEFTDOWN
6796 angle
:= ANGLE_RIGHTDOWN
;
6798 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6799 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6801 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6802 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6803 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6804 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6805 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6807 SetAIFlag('NEEDFIRE', '1');
6808 SetAIFlag('NEEDSEEDOWN', '1');
6812 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
6813 if targets
[a
].Line
and targets
[a
].Visible
and
6814 (((FDirection
= D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
6815 ((FDirection
= D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
6817 SetAIFlag('NEEDFIRE', '1');
6822 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
6823 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
6824 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
6825 40+GetInterval(FDifficult
.Cover
, 40)) then
6826 SetAIFlag('NEEDJUMP', '1');
6828 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
6829 ammo
:= GetAmmoByWeapon(FCurrWeap
);
6830 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
6831 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
6833 SetAIFlag('SELECTWEAPON', '1');
6835 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
6836 if GetAIFlag('SELECTWEAPON') = '1' then
6839 RemoveAIFlag('SELECTWEAPON');
6843 procedure TBot
.Update();
6856 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
6857 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
6859 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
6861 if g_debug_BotAIOff
= 3 then
6871 RealizeCurrentWeapon();
6878 procedure TBot
.ReleaseKey(Key
: Byte);
6887 function TBot
.KeyPressed(Key
: Word): Boolean;
6889 Result
:= FKeys
[Key
].Pressed
;
6892 function TBot
.GetAIFlag(aName
: String20
): String20
;
6898 aName
:= LowerCase(aName
);
6900 if FAIFlags
<> nil then
6901 for a
:= 0 to High(FAIFlags
) do
6902 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6904 Result
:= FAIFlags
[a
].Value
;
6909 procedure TBot
.RemoveAIFlag(aName
: String20
);
6913 if FAIFlags
= nil then Exit
;
6915 aName
:= LowerCase(aName
);
6917 for a
:= 0 to High(FAIFlags
) do
6918 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6920 if a
<> High(FAIFlags
) then
6921 for b
:= a
to High(FAIFlags
)-1 do
6922 FAIFlags
[b
] := FAIFlags
[b
+1];
6924 SetLength(FAIFlags
, Length(FAIFlags
)-1);
6929 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
6937 aName
:= LowerCase(aName
);
6939 if FAIFlags
<> nil then
6940 for a
:= 0 to High(FAIFlags
) do
6941 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6947 if ok
then FAIFlags
[a
].Value
:= fValue
6950 SetLength(FAIFlags
, Length(FAIFlags
)+1);
6951 with FAIFlags
[High(FAIFlags
)] do
6959 procedure TBot
.UpdateMove
;
6961 procedure GoLeft(Time
: Word = 1);
6963 ReleaseKey(KEY_LEFT
);
6964 ReleaseKey(KEY_RIGHT
);
6965 PressKey(KEY_LEFT
, Time
);
6966 SetDirection(D_LEFT
);
6969 procedure GoRight(Time
: Word = 1);
6971 ReleaseKey(KEY_LEFT
);
6972 ReleaseKey(KEY_RIGHT
);
6973 PressKey(KEY_RIGHT
, Time
);
6974 SetDirection(D_RIGHT
);
6977 function Rnd(a
: Word): Boolean;
6979 Result
:= Random(a
) = 0;
6982 procedure Turn(Time
: Word = 1200);
6984 if RunDirection() = D_LEFT
then GoRight(Time
) else GoLeft(Time
);
6989 ReleaseKey(KEY_LEFT
);
6990 ReleaseKey(KEY_RIGHT
);
6993 function CanRunLeft(): Boolean;
6995 Result
:= not CollideLevel(-1, 0);
6998 function CanRunRight(): Boolean;
7000 Result
:= not CollideLevel(1, 0);
7003 function CanRun(): Boolean;
7005 if RunDirection() = D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7008 procedure Jump(Time
: Word = 30);
7010 PressKey(KEY_JUMP
, Time
);
7013 function NearHole(): Boolean;
7017 { TODO 5 : Ëåñòíèöû }
7018 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
7019 for x
:= 1 to PLAYER_RECT
.Width
do
7020 if (not StayOnStep(x
*sx
, 0)) and
7021 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7022 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7031 function BorderHole(): Boolean;
7035 { TODO 5 : Ëåñòíèöû }
7036 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
7037 for x
:= 1 to PLAYER_RECT
.Width
do
7038 if (not StayOnStep(x
*sx
, 0)) and
7039 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7040 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7042 for xx
:= x
to x
+32 do
7043 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7053 function NearDeepHole(): Boolean;
7059 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
7062 for x
:= 1 to PLAYER_RECT
.Width
do
7063 if (not StayOnStep(x
*sx
, 0)) and
7064 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7065 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7067 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7069 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7074 end else Result
:= False;
7077 function OverDeepHole(): Boolean;
7084 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7086 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7093 function OnGround(): Boolean;
7095 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7098 function OnLadder(): Boolean;
7100 Result
:= FullInStep(0, 0);
7103 function BelowLadder(): Boolean;
7105 Result
:= (FullInStep(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7106 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7107 (FullInStep(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7108 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7111 function BelowLiftUp(): Boolean;
7113 Result
:= ((FullInLift(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7114 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7115 ((FullInLift(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7116 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7119 function OnTopLift(): Boolean;
7121 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7124 function CanJumpOver(): Boolean;
7128 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
7132 if not CollideLevel(sx
, 0) then Exit
;
7134 for y
:= 1 to BOT_MAXJUMP
do
7135 if CollideLevel(0, -y
) then Exit
else
7136 if not CollideLevel(sx
, -y
) then
7143 function CanJumpUp(Dist
: ShortInt): Boolean;
7150 if CollideLevel(Dist
, 0) then Exit
;
7153 for y
:= 0 to BOT_MAXJUMP
do
7154 if CollideLevel(Dist
, -y
) then
7163 for yy
:= y
+1 to BOT_MAXJUMP
do
7164 if not CollideLevel(Dist
, -yy
) then
7173 for y
:= 0 to BOT_MAXJUMP
do
7174 if CollideLevel(0, -y
) then
7182 if y
< yy
then Exit
;
7187 function IsSafeTrigger(): Boolean;
7192 if gTriggers
= nil then
7194 for a
:= 0 to High(gTriggers
) do
7195 if Collide(gTriggers
[a
].X
,
7198 gTriggers
[a
].Height
) and
7199 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7200 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7201 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7202 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7203 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7208 // Âîçìîæíî, íàæèìàåì êíîïêó:
7209 if Rnd(16) and IsSafeTrigger() then
7212 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7213 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7215 ReleaseKey(KEY_LEFT
);
7216 ReleaseKey(KEY_RIGHT
);
7220 // Èäåì âëåâî, åñëè íàäî áûëî:
7221 if GetAIFlag('GOLEFT') <> '' then
7223 RemoveAIFlag('GOLEFT');
7224 if CanRunLeft() then
7228 // Èäåì âïðàâî, åñëè íàäî áûëî:
7229 if GetAIFlag('GORIGHT') <> '' then
7231 RemoveAIFlag('GORIGHT');
7232 if CanRunRight() then
7236 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7237 if FObj
.X
< -32 then
7240 if FObj
.X
+32 > gMapInfo
.Width
then
7243 // Ïðûãàåì, åñëè íàäî áûëî:
7244 if GetAIFlag('NEEDJUMP') <> '' then
7247 RemoveAIFlag('NEEDJUMP');
7250 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7251 if GetAIFlag('NEEDSEEUP') <> '' then
7254 ReleaseKey(KEY_DOWN
);
7255 PressKey(KEY_UP
, 20);
7256 RemoveAIFlag('NEEDSEEUP');
7259 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7260 if GetAIFlag('NEEDSEEDOWN') <> '' then
7263 ReleaseKey(KEY_DOWN
);
7264 PressKey(KEY_DOWN
, 20);
7265 RemoveAIFlag('NEEDSEEDOWN');
7268 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7269 if GetAIFlag('GOINHOLE') <> '' then
7270 if not OnGround() then
7272 ReleaseKey(KEY_LEFT
);
7273 ReleaseKey(KEY_RIGHT
);
7274 RemoveAIFlag('GOINHOLE');
7275 SetAIFlag('FALLINHOLE', '1');
7278 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7279 if GetAIFlag('FALLINHOLE') <> '' then
7281 RemoveAIFlag('FALLINHOLE');
7283 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7284 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7285 if GetAIFlag('FALLINHOLE') = '' then
7286 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7292 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7294 CanJumpUp(IfThen(RunDirection() = D_LEFT
, -1, 1)*32) and
7298 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7299 if OnGround() and NearHole() then
7300 if NearDeepHole() then // Åñëè ýòî áåçäíà
7302 0..3: Turn(); // Áåæèì îáðàòíî
7303 4: Jump(); // Ïðûãàåì
7304 5: begin // Ïðûãàåì îáðàòíî
7309 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7310 if GetAIFlag('GOINHOLE') = '' then
7312 0: Turn(); // Íå íóæíî òóäà
7313 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7314 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7315 if BorderHole() then
7316 SetAIFlag('GOINHOLE', '1');
7319 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7320 if (not CanRun()) and OnGround() then
7322 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7323 if CanJumpOver() or OnLadder() then
7325 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7326 if Random(2) = 0 then
7328 if IsSafeTrigger() then
7334 // Îñòàëîñü ìàëî âîçäóõà:
7335 if FAir
< 36 * 2 then
7338 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7339 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7340 if BodyInAcid(0, 0) then
7344 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7346 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7347 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7350 {function TBot.NeedItem(Item: Byte): Byte;
7355 procedure TBot
.SelectWeapon(Dist
: Integer);
7359 function HaveAmmo(weapon
: Byte): Boolean;
7362 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7363 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7364 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7365 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7366 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7367 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7368 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7369 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7370 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7371 else Result
:= True;
7376 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7378 if Dist
> BOT_LONGDIST
then
7379 begin // Äàëüíèé áîé
7381 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7383 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7387 else //if Dist > BOT_UNSAFEDIST then
7388 begin // Áëèæíèé áîé
7390 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7392 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7399 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7401 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7407 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7409 Result
:= inherited PickItem(ItemType
, force
, remove
);
7411 if Result
then SetAIFlag('SELECTWEAPON', '1');
7414 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7416 Result
:= inherited Heal(value
, Soft
);
7419 function TBot
.Healthy(): Byte;
7421 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7422 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7423 else if (FHealth
> 50) then Result
:= 2
7424 else if (FHealth
> 20) then Result
:= 1
7428 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7430 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7431 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7434 procedure TBot
.OnDamage(Angle
: SmallInt);
7442 if (Angle
= 0) or (Angle
= 180) then
7445 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7446 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7448 pla
:= g_Player_Get(FLastSpawnerUID
);
7449 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7450 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7453 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7454 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7456 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7457 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7458 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7463 SetAIFlag('ATTACKLEFT', '1')
7465 SetAIFlag('ATTACKRIGHT', '1');
7469 function TBot
.RunDirection(): TDirection
;
7471 if Abs(Vel
.X
) >= 1 then
7473 if Vel
.X
> 0 then Result
:= D_RIGHT
else Result
:= D_LEFT
;
7475 Result
:= FDirection
;
7478 function TBot
.GetRnd(a
: Byte): Boolean;
7480 if a
= 0 then Result
:= False
7481 else if a
= 255 then Result
:= True
7482 else Result
:= Random(256) > 255-a
;
7485 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7487 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7490 procedure TBot
.SaveState(var Mem
: TBinMemoryWriter
);
7496 inherited SaveState(Mem
);
7498 // Âûáðàííîå îðóæèå:
7499 Mem
.WriteByte(FSelectedWeapon
);
7501 Mem
.WriteWord(FTargetUID
);
7502 // Âðåìÿ ïîòåðè öåëè:
7503 Mem
.WriteDWORD(FLastVisible
);
7504 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7505 dw
:= Length(FAIFlags
);
7508 for i
:= 0 to Integer(dw
)-1 do
7510 Mem
.WriteString(FAIFlags
[i
].Name
, 20);
7511 Mem
.WriteString(FAIFlags
[i
].Value
, 20);
7513 // Íàñòðîéêè ñëîæíîñòè:
7515 Mem
.WriteMemory(p
, SizeOf(TDifficult
));
7518 procedure TBot
.LoadState(var Mem
: TBinMemoryReader
);
7524 inherited LoadState(Mem
);
7526 // Âûáðàííîå îðóæèå:
7527 Mem
.ReadByte(FSelectedWeapon
);
7529 Mem
.ReadWord(FTargetUID
);
7530 // Âðåìÿ ïîòåðè öåëè:
7531 Mem
.ReadDWORD(FLastVisible
);
7532 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7534 SetLength(FAIFlags
, dw
);
7536 for i
:= 0 to Integer(dw
)-1 do
7538 Mem
.ReadString(FAIFlags
[i
].Name
);
7539 Mem
.ReadString(FAIFlags
[i
].Value
);
7541 // Íàñòðîéêè ñëîæíîñòè:
7542 Mem
.ReadMemory(p
, dw
);
7543 if dw
<> SizeOf(TDifficult
) then
7545 raise EBinSizeError
.Create('TBot.LoadState: Wrong FDifficult Size');
7547 FDifficult
:= TDifficult(p
^);