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
, MAPDEF
,
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
, 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 TDFPoint
= ((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+FObj
.slopeUpLeft
, 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+FObj
.slopeUpLeft
, 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
+FObj
.slopeUpLeft
, 200)
2292 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2295 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 254);
2298 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
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);
2324 if isValidViewPort
and (self
= gPlayer1
) then
2326 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2329 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2330 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2332 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2336 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2341 wx
, wy
, xx
, yy
: Integer;
2345 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= D_LEFT
, 7, -7);
2346 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2355 1: begin // Chainsaw
2362 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2363 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2364 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2365 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2370 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2371 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2372 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2373 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2375 4: begin // Double Shotgun
2378 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2379 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2380 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2381 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2383 5: begin // Chaingun
2386 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2387 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2388 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2389 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2391 6: begin // Rocket Launcher
2394 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2395 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2396 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2397 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2399 7: begin // Plasmagun
2402 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2403 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2404 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2405 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2410 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2411 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2412 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2413 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2415 9: begin // Super Chaingun
2418 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2419 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2420 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2421 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2424 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2425 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2426 {$IF DEFINED(D2F_DEBUG)}
2427 drawCast(sz
, wx
, wy
, xx
, yy
);
2429 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2433 procedure TPlayer
.DrawGUI();
2436 X
, Y
, SY
, a
, p
, m
: Integer;
2440 stat
: TPlayerStatArray
;
2442 X
:= gPlayerScreenSize
.X
;
2443 SY
:= gPlayerScreenSize
.Y
;
2446 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2448 if gGameSettings
.GameMode
= GM_CTF
then
2452 if gGameSettings
.GameMode
= GM_CTF
then
2454 s
:= 'TEXTURE_PLAYER_REDFLAG';
2455 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2456 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2457 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2458 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2459 if g_Texture_Get(s
, ID
) then
2460 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2463 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2464 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2465 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2467 if gGameSettings
.GameMode
= GM_CTF
then
2469 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2470 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2471 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2472 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2473 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2474 if g_Texture_Get(s
, ID
) then
2475 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2478 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2479 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2480 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2483 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2484 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2487 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2488 e_Draw(ID
, X
+2, Y
, 0, True, False);
2490 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2494 s
:= IntToStr(Frags
);
2495 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2496 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2501 stat
:= g_Player_GetStats();
2506 for a
:= 0 to High(stat
) do
2507 if stat
[a
].Name
<> Name
then
2509 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2510 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2514 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2515 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2516 s
:= s
+IntToStr(Abs(Frags
-m
));
2518 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2519 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2522 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2524 s
:= IntToStr(Lives
);
2525 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2526 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2530 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2531 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2533 if R_BERSERK
in FRulez
then
2534 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2536 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2538 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2539 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2541 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2542 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2543 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2545 s
:= IntToStr(FArmor
);
2546 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2547 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2549 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2555 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2560 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2562 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2563 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2564 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2565 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2566 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2567 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2568 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2569 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2570 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2573 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2574 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2575 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2577 if R_KEY_RED
in FRulez
then
2578 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2580 if R_KEY_GREEN
in FRulez
then
2581 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2583 if R_KEY_BLUE
in FRulez
then
2584 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2586 if FJetFuel
> 0 then
2588 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2589 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2590 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2591 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2592 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2593 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2597 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2598 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2599 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2602 if gShowPing
and g_Game_IsClient
then
2604 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2605 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2611 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2612 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2613 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2616 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2617 s
:= _lc
[I_PLAYER_SPECT4
];
2618 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2619 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2620 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2626 procedure TPlayer
.DrawRulez();
2630 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2631 if FMegaRulez
[MR_INVUL
] >= gTime
then
2633 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2634 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2639 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2640 191, 191, 191, 0, B_INVERT
);
2643 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2644 if FMegaRulez
[MR_SUIT
] >= gTime
then
2646 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2647 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2652 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2653 0, 96, 0, 200, B_NONE
);
2656 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2657 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2659 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2660 255, 0, 0, 200, B_NONE
);
2664 procedure TPlayer
.DrawPain();
2668 if FPain
= 0 then Exit
;
2672 if a
< 15 then h
:= 0
2673 else if a
< 35 then h
:= 1
2674 else if a
< 55 then h
:= 2
2675 else if a
< 75 then h
:= 3
2676 else if a
< 95 then h
:= 4
2679 //if a > 255 then a := 255;
2681 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2682 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2685 procedure TPlayer
.DrawPickup();
2689 if FPickup
= 0 then Exit
;
2693 if a
< 15 then h
:= 1
2694 else if a
< 35 then h
:= 2
2695 else if a
< 55 then h
:= 3
2696 else if a
< 75 then h
:= 4
2699 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2702 procedure TPlayer
.Fire();
2704 f
, DidFire
: Boolean;
2705 wx
, wy
, xd
, yd
: Integer;
2708 if g_Game_IsClient
then Exit
;
2709 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2710 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2718 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2723 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2724 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2725 xd
:= wx
+IfThen(FDirection
= D_LEFT
, -30, 30);
2726 yd
:= wy
+firediry();
2731 if R_BERSERK
in FRulez
then
2733 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2734 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2735 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2738 locobj
.rect
.Width
:= 39;
2739 locobj
.rect
.Height
:= 52;
2740 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2741 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2742 locobj
.Accel
.X
:= xd
-wx
;
2743 locobj
.Accel
.y
:= yd
-wy
;
2745 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2746 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2748 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2752 FPain
:= min(FPain
+ 25, 50);
2753 end else g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2756 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2761 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2762 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2764 FSawSoundSelect
.Stop();
2766 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2768 else if not FSawSoundHit
.IsPlaying() then
2770 FSawSoundSelect
.Stop();
2771 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2774 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2780 if FAmmo
[A_BULLETS
] > 0 then
2782 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2783 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2784 Dec(FAmmo
[A_BULLETS
]);
2785 FFireAngle
:= FAngle
;
2788 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2789 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2793 if FAmmo
[A_SHELLS
] > 0 then
2795 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2796 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
2797 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2798 Dec(FAmmo
[A_SHELLS
]);
2799 FFireAngle
:= FAngle
;
2803 FShellType
:= SHELL_SHELL
;
2807 if FAmmo
[A_SHELLS
] >= 2 then
2809 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
2810 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2811 Dec(FAmmo
[A_SHELLS
], 2);
2812 FFireAngle
:= FAngle
;
2816 FShellType
:= SHELL_DBLSHELL
;
2820 if FAmmo
[A_BULLETS
] > 0 then
2822 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
2823 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
2824 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2825 Dec(FAmmo
[A_BULLETS
]);
2826 FFireAngle
:= FAngle
;
2829 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2830 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2833 WEAPON_ROCKETLAUNCHER
:
2834 if FAmmo
[A_ROCKETS
] > 0 then
2836 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
2837 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2838 Dec(FAmmo
[A_ROCKETS
]);
2839 FFireAngle
:= FAngle
;
2845 if FAmmo
[A_CELLS
] > 0 then
2847 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
2848 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2849 Dec(FAmmo
[A_CELLS
]);
2850 FFireAngle
:= FAngle
;
2856 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
2858 FBFGFireCounter
:= 17;
2859 if not FNoReload
then
2860 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
2861 Dec(FAmmo
[A_CELLS
], 40);
2865 WEAPON_SUPERPULEMET
:
2866 if FAmmo
[A_SHELLS
] > 0 then
2868 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2869 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
2870 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2871 Dec(FAmmo
[A_SHELLS
]);
2872 FFireAngle
:= FAngle
;
2875 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2876 GameVelX
, GameVelY
-2, SHELL_SHELL
);
2879 WEAPON_FLAMETHROWER
:
2880 if FAmmo
[A_FUEL
] > 0 then
2882 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
2883 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2885 FFireAngle
:= FAngle
;
2891 if g_Game_IsNet
then
2895 if FCurrWeap
<> WEAPON_BFG
then
2896 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
2898 if not FNoReload
then
2899 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
2902 MH_SEND_PlayerStats(FUID
);
2907 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
2908 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
2909 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
2912 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
2915 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
2916 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
2917 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
2918 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
2919 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
2924 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
2926 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
2927 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
2928 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
2931 procedure TPlayer
.JetpackOn
;
2935 FJetSoundOn
.SetPosition(0);
2936 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
2940 procedure TPlayer
.JetpackOff
;
2944 FJetSoundOff
.SetPosition(0);
2945 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
2948 procedure TPlayer
.CatchFire(Attacker
: Word);
2951 FFireAttacker
:= Attacker
;
2952 if g_Game_IsNet
and g_Game_IsServer
then
2953 MH_SEND_PlayerStats(FUID
);
2956 procedure TPlayer
.Jump();
2958 if gFly
or FJetpack
then
2960 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
2961 if FObj
.Vel
.Y
> -VEL_FLY
then
2962 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
2965 if FJetFuel
> 0 then
2967 if (FJetFuel
< 1) and g_Game_IsServer
then
2971 if g_Game_IsNet
then
2972 MH_SEND_PlayerStats(FUID
);
2978 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
2980 FCanJetpack
:= False;
2982 // Ïðûãàåì èëè âñïëûâàåì:
2983 if (CollideLevel(0, 1) or
2984 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
2985 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
2986 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
2988 FObj
.Vel
.Y
:= -VEL_JUMP
;
2989 FCanJetpack
:= False;
2993 if BodyInLiquid(0, 0) then
2994 FObj
.Vel
.Y
:= -VEL_SW
2995 else if (FJetFuel
> 0) and FCanJetpack
and
2996 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3000 if g_Game_IsNet
then
3001 MH_SEND_PlayerStats(FUID
);
3006 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3008 a
, i
, k
, ab
, ar
: Byte;
3012 srv
, netsrv
: Boolean;
3018 procedure PushItem(t
: Byte);
3022 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3023 it
:= g_Items_ByIdx(id
);
3024 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3026 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3027 (FObj
.Vel
.Y
div 2)-Random(9));
3028 it
.positionChanged(); // this updates spatial accelerators
3032 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3034 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3035 (FObj
.Vel
.Y
div 2)-Random(6));
3037 else // -3..+3; -3..0
3039 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3040 (FObj
.Vel
.Y
div 2)-Random(4));
3042 it
.positionChanged(); // this updates spatial accelerators
3045 if g_Game_IsNet
and g_Game_IsServer
then
3046 MH_SEND_ItemSpawn(True, id
);
3050 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3051 Srv
:= g_Game_IsServer
;
3052 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3053 if Srv
then FDeath
:= FDeath
+ 1;
3058 if not FPhysics
then
3064 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3066 if FLives
> 0 then FLives
:= FLives
- 1;
3067 if FLives
= 0 then FNoRespawn
:= True;
3070 // Íîìåð òèïà ñìåðòè:
3073 K_SIMPLEKILL
: a
:= 1;
3075 K_EXTRAHARDKILL
: a
:= 3;
3080 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3082 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3089 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3091 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3092 K_EXTRAHARDKILL
, K_FALLKILL
:
3093 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3096 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3100 K_HARDKILL
, K_EXTRAHARDKILL
:
3104 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3105 if (KillType
<> K_FALLKILL
) and (Srv
) then
3106 g_Monsters_killedp();
3108 if SpawnerUID
= FUID
then
3110 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3115 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3118 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3119 begin // Óáèò äðóãèì èãðîêîì
3120 KP
:= g_Player_Get(SpawnerUID
);
3121 if (KP
<> nil) and Srv
then
3123 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3124 if SameTeam(FUID
, SpawnerUID
) then
3134 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3135 Inc(gTeamStat
[KP
.Team
].Goals
,
3136 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3138 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3141 plr
:= g_Player_Get(SpawnerUID
);
3149 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3153 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3157 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3162 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3163 begin // Óáèò ìîíñòðîì
3164 mon
:= g_Monsters_ByUID(SpawnerUID
);
3168 s
:= g_Monsters_GetKilledBy(mon
.MonsterType
);
3172 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3176 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3180 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3185 else // Îñîáûå òèïû ñìåðòè
3188 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3189 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3190 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3191 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3192 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3193 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3199 for a
:= WP_FIRST
to WP_LAST
do
3203 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3204 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3205 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3206 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3207 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3208 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3209 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3210 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3211 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3220 if R_ITEM_BACKPACK
in FRulez
then
3221 PushItem(ITEM_AMMO_BACKPACK
);
3223 // Âûáðîñ ðàêåòíîãî ðàíöà:
3224 if FJetFuel
> 0 then
3225 PushItem(ITEM_JETPACK
);
3228 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3230 if R_KEY_RED
in FRulez
then
3231 PushItem(ITEM_KEY_RED
);
3233 if R_KEY_GREEN
in FRulez
then
3234 PushItem(ITEM_KEY_GREEN
);
3236 if R_KEY_BLUE
in FRulez
then
3237 PushItem(ITEM_KEY_BLUE
);
3244 g_Player_CreateCorpse(Self
);
3246 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3247 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3253 for i
:= Low(gPlayers
) to High(gPlayers
) do
3255 if gPlayers
[i
] = nil then continue
;
3256 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3259 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3260 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3265 OldLR
:= gLMSRespawn
;
3266 if (gGameSettings
.GameMode
= GM_COOP
) then
3270 // everyone is dead, restart the map
3271 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3273 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3274 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3275 gLMSRespawnTime
:= gTime
+ 5000;
3277 else if (a
= 1) then
3279 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3280 if (gPlayers
[k
] = gPlayer1
) or
3281 (gPlayers
[k
] = gPlayer2
) then
3282 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3283 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3284 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3287 else if (gGameSettings
.GameMode
= GM_TDM
) then
3289 if (ab
= 0) and (ar
<> 0) then
3292 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3294 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3295 Inc(gTeamStat
[TEAM_RED
].Goals
);
3296 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3297 gLMSRespawnTime
:= gTime
+ 5000;
3299 else if (ar
= 0) and (ab
<> 0) then
3302 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3304 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3305 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3306 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3307 gLMSRespawnTime
:= gTime
+ 5000;
3309 else if (ar
= 0) and (ab
= 0) then
3312 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3314 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3315 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3316 gLMSRespawnTime
:= gTime
+ 5000;
3319 else if (gGameSettings
.GameMode
= GM_DM
) then
3323 if gPlayers
[k
] <> nil then
3326 // survivor is the winner
3327 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3329 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3332 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3333 gLMSRespawnTime
:= gTime
+ 5000;
3335 else if (a
= 0) then
3337 // everyone is dead, restart the map
3338 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3340 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3341 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3342 gLMSRespawnTime
:= gTime
+ 5000;
3345 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3347 if NetMode
= NET_SERVER
then
3348 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3350 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3356 MH_SEND_PlayerStats(FUID
);
3357 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3358 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3361 if srv
and FNoRespawn
then Spectate(True);
3362 FWantsInGame
:= True;
3365 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3367 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3368 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3371 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3373 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3374 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3377 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3379 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3380 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3381 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3383 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3384 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3385 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3389 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3391 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3392 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3393 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3397 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3399 if g_Game_IsClient
then Exit
;
3400 if Weapon
> High(FWeapon
) then Exit
;
3401 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3404 procedure TPlayer
.resetWeaponQueue ();
3407 FNextWeapDelay
:= 0;
3410 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3414 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3415 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 0);
3416 WEAPON_PISTOL
, WEAPON_CHAINGUN
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_BULLETS
] > 0);
3417 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3418 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3419 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3420 else result
:= (weapon
< length(FWeapon
));
3424 // return 255 for "no switch"
3425 function TPlayer
.getNextWeaponIndex (): Byte;
3428 wantThisWeapon
: array[0..64] of Boolean;
3429 wwc
: Integer = 0; //HACK!
3432 result
:= 255; // default result: "no switch"
3433 // had weapon cycling on previous frame? remove that flag
3434 if (FNextWeap
and $2000) <> 0 then
3436 FNextWeap
:= FNextWeap
and $1FFF;
3437 FNextWeapDelay
:= 0;
3439 // cycling has priority
3440 if (FNextWeap
and $C000) <> 0 then
3442 if (FNextWeap
and $8000) <> 0 then
3446 FNextWeap
:= FNextWeap
or $2000; // we need this
3447 if FNextWeapDelay
> 0 then
3448 exit
; // cooldown time
3450 for i
:= 0 to High(FWeapon
) do
3452 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3453 if FWeapon
[cwi
] then
3455 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d', [FCurrWeap, cwi]), MSG_WARNING);
3456 result
:= Byte(cwi
);
3457 FNextWeapDelay
:= 10;
3465 for i
:= 0 to High(wantThisWeapon
) do
3466 wantThisWeapon
[i
] := false;
3467 for i
:= 0 to High(FWeapon
) do
3468 if (FNextWeap
and (1 shl i
)) <> 0 then
3470 wantThisWeapon
[i
] := true;
3473 // exclude currently selected weapon from the set
3474 wantThisWeapon
[FCurrWeap
] := false;
3475 // slow down alterations a little
3478 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3479 // more than one weapon requested, assume "alteration" and check alteration delay
3480 if FNextWeapDelay
> 0 then
3486 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3487 // but clear all counters if no weapon should be switched
3493 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3494 // try weapons in descending order
3495 for i
:= High(FWeapon
) downto 0 do
3497 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3502 FNextWeapDelay
:= 10; // anyway, 'cause why not
3506 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3510 procedure TPlayer
.RealizeCurrentWeapon();
3511 function switchAllowed (): Boolean;
3516 if FBFGFireCounter
<> -1 then
3518 if FTime
[T_SWITCH
] > gTime
then
3520 for i
:= WP_FIRST
to WP_LAST
do
3521 if FReloading
[i
] > 0 then
3529 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3530 //FNextWeap := FNextWeap and $1FFF;
3531 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3533 if not switchAllowed
then
3535 //HACK for weapon cycling
3536 if (FNextWeap
and $7000) <> 0 then FNextWeap
:= 0;
3540 nw
:= getNextWeaponIndex();
3541 if nw
= 255 then exit
; // don't reset anything here
3542 if nw
> High(FWeapon
) then
3544 // don't forget to reset queue here!
3545 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3553 FTime
[T_SWITCH
] := gTime
+156;
3554 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3555 FModel
.SetWeapon(FCurrWeap
);
3556 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3560 procedure TPlayer
.NextWeapon();
3562 if g_Game_IsClient
then Exit
;
3566 procedure TPlayer
.PrevWeapon();
3568 if g_Game_IsClient
then Exit
;
3572 procedure TPlayer
.SetWeapon(W
: Byte);
3574 if FCurrWeap
<> W
then
3575 if W
= WEAPON_SAW
then
3576 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3579 FModel
.SetWeapon(CurrWeap
);
3583 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3588 if g_Game_IsClient
then Exit
;
3590 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3591 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3596 if FHealth
< PLAYER_HP_SOFT
then
3598 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3602 if gFlash
= 2 then Inc(FPickup
, 5);
3606 if FHealth
< PLAYER_HP_SOFT
then
3608 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3612 if gFlash
= 2 then Inc(FPickup
, 5);
3616 if FArmor
< PLAYER_AP_SOFT
then
3618 FArmor
:= PLAYER_AP_SOFT
;
3621 if gFlash
= 2 then Inc(FPickup
, 5);
3625 if FArmor
< PLAYER_AP_LIMIT
then
3627 FArmor
:= PLAYER_AP_LIMIT
;
3630 if gFlash
= 2 then Inc(FPickup
, 5);
3634 if FHealth
< PLAYER_HP_LIMIT
then
3636 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3640 if gFlash
= 2 then Inc(FPickup
, 5);
3644 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3646 if FHealth
< PLAYER_HP_LIMIT
then
3647 FHealth
:= PLAYER_HP_LIMIT
;
3648 if FArmor
< PLAYER_AP_LIMIT
then
3649 FArmor
:= PLAYER_AP_LIMIT
;
3653 if gFlash
= 2 then Inc(FPickup
, 5);
3657 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3659 FWeapon
[WEAPON_SAW
] := True;
3661 if gFlash
= 2 then Inc(FPickup
, 5);
3662 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3665 ITEM_WEAPON_SHOTGUN1
:
3666 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3668 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3669 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3671 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3672 FWeapon
[WEAPON_SHOTGUN1
] := True;
3674 if gFlash
= 2 then Inc(FPickup
, 5);
3675 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3678 ITEM_WEAPON_SHOTGUN2
:
3679 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3681 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3683 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3684 FWeapon
[WEAPON_SHOTGUN2
] := True;
3686 if gFlash
= 2 then Inc(FPickup
, 5);
3687 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3690 ITEM_WEAPON_CHAINGUN
:
3691 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3693 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3695 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3696 FWeapon
[WEAPON_CHAINGUN
] := True;
3698 if gFlash
= 2 then Inc(FPickup
, 5);
3699 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3702 ITEM_WEAPON_ROCKETLAUNCHER
:
3703 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3705 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3707 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3708 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3710 if gFlash
= 2 then Inc(FPickup
, 5);
3711 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3715 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3717 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3719 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3720 FWeapon
[WEAPON_PLASMA
] := True;
3722 if gFlash
= 2 then Inc(FPickup
, 5);
3723 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3727 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3729 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3731 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3732 FWeapon
[WEAPON_BFG
] := True;
3734 if gFlash
= 2 then Inc(FPickup
, 5);
3735 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3738 ITEM_WEAPON_SUPERPULEMET
:
3739 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3741 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3743 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3744 FWeapon
[WEAPON_SUPERPULEMET
] := True;
3746 if gFlash
= 2 then Inc(FPickup
, 5);
3747 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3750 ITEM_WEAPON_FLAMETHROWER
:
3751 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
3753 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
3755 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3756 FWeapon
[WEAPON_FLAMETHROWER
] := True;
3758 if gFlash
= 2 then Inc(FPickup
, 5);
3759 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3763 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3765 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3768 if gFlash
= 2 then Inc(FPickup
, 5);
3771 ITEM_AMMO_BULLETS_BOX
:
3772 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3774 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3777 if gFlash
= 2 then Inc(FPickup
, 5);
3781 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3783 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3786 if gFlash
= 2 then Inc(FPickup
, 5);
3789 ITEM_AMMO_SHELLS_BOX
:
3790 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3792 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
3795 if gFlash
= 2 then Inc(FPickup
, 5);
3799 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3801 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3804 if gFlash
= 2 then Inc(FPickup
, 5);
3807 ITEM_AMMO_ROCKET_BOX
:
3808 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3810 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
3813 if gFlash
= 2 then Inc(FPickup
, 5);
3817 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3819 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3822 if gFlash
= 2 then Inc(FPickup
, 5);
3826 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3828 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
3831 if gFlash
= 2 then Inc(FPickup
, 5);
3835 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
3837 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3840 if gFlash
= 2 then Inc(FPickup
, 5);
3844 if not(R_ITEM_BACKPACK
in FRulez
) or
3845 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
3846 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
3847 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
3848 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
3849 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
3851 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
3852 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
3853 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
3854 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
3855 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
3857 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3858 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3859 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3860 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3861 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3862 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3863 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3864 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3866 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
3869 if gFlash
= 2 then Inc(FPickup
, 5);
3873 if not(R_KEY_RED
in FRulez
) then
3875 Include(FRulez
, R_KEY_RED
);
3877 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3878 if gFlash
= 2 then Inc(FPickup
, 5);
3879 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3883 if not(R_KEY_GREEN
in FRulez
) then
3885 Include(FRulez
, R_KEY_GREEN
);
3887 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3888 if gFlash
= 2 then Inc(FPickup
, 5);
3889 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3893 if not(R_KEY_BLUE
in FRulez
) then
3895 Include(FRulez
, R_KEY_BLUE
);
3897 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3898 if gFlash
= 2 then Inc(FPickup
, 5);
3899 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3903 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
3905 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
3909 if gFlash
= 2 then Inc(FPickup
, 5);
3913 if FAir
< AIR_MAX
then
3918 if gFlash
= 2 then Inc(FPickup
, 5);
3923 if not (R_BERSERK
in FRulez
) then
3925 Include(FRulez
, R_BERSERK
);
3926 if FBFGFireCounter
= -1 then
3928 FCurrWeap
:= WEAPON_KASTET
;
3930 FModel
.SetWeapon(WEAPON_KASTET
);
3934 if gFlash
= 2 then Inc(FPickup
, 5);
3935 FBerserk
:= gTime
+30000;
3940 if FHealth
< PLAYER_HP_SOFT
then
3942 FHealth
:= PLAYER_HP_SOFT
;
3943 FBerserk
:= gTime
+30000;
3951 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
3953 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
3956 if gFlash
= 2 then Inc(FPickup
, 5);
3960 if FHealth
< PLAYER_HP_LIMIT
then
3962 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
3966 if gFlash
= 2 then Inc(FPickup
, 5);
3970 if FArmor
< PLAYER_AP_LIMIT
then
3972 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
3975 if gFlash
= 2 then Inc(FPickup
, 5);
3979 if FJetFuel
< JET_MAX
then
3981 FJetFuel
:= JET_MAX
;
3984 if gFlash
= 2 then Inc(FPickup
, 5);
3988 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
3990 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
3993 if gFlash
= 2 then Inc(FPickup
, 5);
3998 procedure TPlayer
.Touch();
4002 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4005 // Áðîñèòü ôëàã òîâàðèùó:
4006 if gGameSettings
.GameMode
= GM_CTF
then
4011 procedure TPlayer
.Push(vx
, vy
: Integer);
4013 if (not FPhysics
) and FGhost
then
4015 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4016 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4017 if g_Game_IsNet
and g_Game_IsServer
then
4018 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4021 procedure TPlayer
.Reset(Force
: Boolean);
4027 FTime
[T_RESPAWN
] := 0;
4028 FTime
[T_FLAGCAP
] := 0;
4041 FSpectator
:= False;
4044 FSpectatePlayer
:= -1;
4045 FNoRespawn
:= False;
4047 FLives
:= gGameSettings
.MaxLives
;
4052 procedure TPlayer
.SoftReset();
4058 FBFGFireCounter
:= -1;
4066 SetAction(A_STAND
, True);
4069 function TPlayer
.GetRespawnPoint(): Byte;
4074 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4076 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4077 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4079 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4081 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4082 if Self
= gPlayer1
then
4083 c
:= RESPAWNPOINT_PLAYER1
4085 c
:= RESPAWNPOINT_PLAYER2
;
4086 if g_Map_GetPointCount(c
) > 0 then
4092 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4093 if Self
= gPlayer1
then
4094 c
:= RESPAWNPOINT_PLAYER2
4096 c
:= RESPAWNPOINT_PLAYER1
;
4097 if g_Map_GetPointCount(c
) > 0 then
4104 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4105 if Random(2) = 0 then
4106 c
:= RESPAWNPOINT_PLAYER1
4108 c
:= RESPAWNPOINT_PLAYER2
;
4109 if g_Map_GetPointCount(c
) > 0 then
4116 // Òî÷êà ëþáîé èç êîìàíä
4117 if Random(2) = 0 then
4118 c
:= RESPAWNPOINT_RED
4120 c
:= RESPAWNPOINT_BLUE
;
4121 if g_Map_GetPointCount(c
) > 0 then
4128 c
:= RESPAWNPOINT_DM
;
4129 if g_Map_GetPointCount(c
) > 0 then
4137 if gGameSettings
.GameMode
= GM_DM
then
4140 c
:= RESPAWNPOINT_DM
;
4141 if g_Map_GetPointCount(c
) > 0 then
4147 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4148 if Random(2) = 0 then
4149 c
:= RESPAWNPOINT_PLAYER1
4151 c
:= RESPAWNPOINT_PLAYER2
;
4152 if g_Map_GetPointCount(c
) > 0 then
4158 // Òî÷êà ëþáîé èç êîìàíä
4159 if Random(2) = 0 then
4160 c
:= RESPAWNPOINT_RED
4162 c
:= RESPAWNPOINT_BLUE
;
4163 if g_Map_GetPointCount(c
) > 0 then
4171 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4173 // Òî÷êà ñâîåé êîìàíäû
4174 c
:= RESPAWNPOINT_DM
;
4175 if FTeam
= TEAM_RED
then
4176 c
:= RESPAWNPOINT_RED
;
4177 if FTeam
= TEAM_BLUE
then
4178 c
:= RESPAWNPOINT_BLUE
;
4179 if g_Map_GetPointCount(c
) > 0 then
4186 c
:= RESPAWNPOINT_DM
;
4187 if g_Map_GetPointCount(c
) > 0 then
4193 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4194 if Random(2) = 0 then
4195 c
:= RESPAWNPOINT_PLAYER1
4197 c
:= RESPAWNPOINT_PLAYER2
;
4198 if g_Map_GetPointCount(c
) > 0 then
4204 // Òî÷êà äðóãîé êîìàíäû
4205 c
:= RESPAWNPOINT_DM
;
4206 if FTeam
= TEAM_RED
then
4207 c
:= RESPAWNPOINT_BLUE
;
4208 if FTeam
= TEAM_BLUE
then
4209 c
:= RESPAWNPOINT_RED
;
4210 if g_Map_GetPointCount(c
) > 0 then
4218 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4220 RespawnPoint
: TRespawnPoint
;
4225 if not g_Game_IsServer
then
4229 FWantsInGame
:= True;
4230 FJustTeleported
:= True;
4233 FTime
[T_RESPAWN
] := 0;
4237 // if server changes MaxLives we gotta be ready
4238 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4240 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4241 if FTime
[T_RESPAWN
] > gTime
then
4244 // Ïðîñðàë âñå æèçíè:
4247 if not FSpectator
then Spectate(True);
4248 FWantsInGame
:= True;
4252 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4253 begin // "Ñâîÿ èãðà"
4254 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4255 FRulez
:= FRulez
-[R_BERSERK
];
4257 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4259 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4260 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4263 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4264 c
:= GetRespawnPoint();
4269 // Âîñêðåøåíèå áåç îðóæèÿ:
4272 FHealth
:= PLAYER_HP_SOFT
;
4278 for a
:= WP_FIRST
to WP_LAST
do
4280 FWeapon
[a
] := False;
4284 FWeapon
[WEAPON_PISTOL
] := True;
4285 FWeapon
[WEAPON_KASTET
] := True;
4286 FCurrWeap
:= WEAPON_PISTOL
;
4289 FModel
.SetWeapon(FCurrWeap
);
4291 for b
:= A_BULLETS
to A_HIGH
do
4294 FAmmo
[A_BULLETS
] := 50;
4296 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4297 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4298 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4299 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4300 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4302 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4303 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4308 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4309 if not g_Map_GetPoint(c
, RespawnPoint
) then
4311 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4315 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4316 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4317 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4323 FDirection
:= RespawnPoint
.Direction
;
4324 if FDirection
= D_LEFT
then
4330 FBFGFireCounter
:= -1;
4335 SetAction(A_STAND
, True);
4336 FModel
.Direction
:= FDirection
;
4338 for a
:= Low(FTime
) to High(FTime
) do
4341 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4346 FCanJetpack
:= False;
4351 // Àíèìàöèÿ âîçðîæäåíèÿ:
4352 if (not gLoadGameMode
) and (not Silent
) then
4353 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4355 Anim
:= TAnimation
.Create(ID
, False, 3);
4356 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4357 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4361 FSpectator
:= False;
4364 FSpectatePlayer
:= -1;
4367 if g_Game_IsNet
then
4369 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4370 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4372 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4373 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4378 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4381 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4382 else if (not NoMove
) then
4384 GameX
:= gMapInfo
.Width
div 2;
4385 GameY
:= gMapInfo
.Height
div 2;
4394 FWantsInGame
:= False;
4399 if Self
= gPlayer1
then
4404 if Self
= gPlayer2
then
4411 if g_Game_IsNet
then
4412 MH_SEND_PlayerStats(FUID
);
4415 procedure TPlayer
.SwitchNoClip
;
4419 FGhost
:= not FGhost
;
4420 FPhysics
:= not FGhost
;
4432 procedure TPlayer
.Run(Direction
: TDirection
);
4436 if MAX_RUNVEL
> 8 then
4440 if Direction
= D_LEFT
then
4442 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4443 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4446 if FObj
.Vel
.X
< MAX_RUNVEL
then
4447 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4449 // Âîçìîæíî, ïèíàåì êóñêè:
4450 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4452 b
:= Abs(FObj
.Vel
.X
);
4453 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4454 for a
:= 0 to High(gGibs
) do
4456 if gGibs
[a
].Live
and
4457 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4458 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4461 if FObj
.Vel
.X
< 0 then
4463 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4467 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4469 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4477 procedure TPlayer
.SeeDown();
4479 SetAction(A_SEEDOWN
);
4481 if FDirection
= D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4483 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4486 procedure TPlayer
.SeeUp();
4490 if FDirection
= D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4492 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4495 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4503 A_ATTACK
: Prior
:= 2;
4504 A_SEEUP
: Prior
:= 1;
4505 A_SEEDOWN
: Prior
:= 1;
4506 A_ATTACKUP
: Prior
:= 2;
4507 A_ATTACKDOWN
: Prior
:= 2;
4512 if (Prior
> FActionPrior
) or Force
then
4513 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4515 FActionPrior
:= Prior
;
4516 FActionAnim
:= Action
;
4517 FActionForce
:= Force
;
4518 FActionChanged
:= True;
4521 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4524 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4526 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4527 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4528 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4529 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4532 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4539 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4541 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4542 if g_Game_IsServer
and g_Game_IsNet
then
4543 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4547 FJustTeleported
:= True;
4552 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4554 Anim
:= TAnimation
.Create(ID
, False, 3);
4557 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4558 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4559 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4560 if g_Game_IsServer
and g_Game_IsNet
then
4561 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4562 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4566 FObj
.X
:= X
-PLAYER_RECT
.X
;
4567 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4568 if FLive
and FGhost
then
4574 if not g_Game_IsNet
then
4578 SetDirection(D_LEFT
);
4584 SetDirection(D_RIGHT
);
4590 if FDirection
= D_RIGHT
then
4592 SetDirection(D_LEFT
);
4597 SetDirection(D_RIGHT
);
4603 if not silent
and (Anim
<> nil) then
4605 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4606 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4609 if g_Game_IsServer
and g_Game_IsNet
then
4610 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4611 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4618 function nonz(a
: Single): Single;
4626 procedure TPlayer
.Update();
4629 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4630 blockmon
, headwater
, dospawn
: Boolean;
4635 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4636 AnyServer
:= g_Game_IsServer
;
4638 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4639 DoLerp(NetInterpLevel
+ 1)
4645 if FClientID
>= 0 then
4647 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4648 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4649 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4658 if FLive
and (gFly
or FJetpack
) then
4661 if FDirection
= D_LEFT
then
4666 if FLive
and (not FGhost
) then
4668 if FKeys
[KEY_UP
].Pressed
then
4670 if FKeys
[KEY_DOWN
].Pressed
then
4674 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4677 i
:= g_basic
.Sign(FIncCam
);
4678 FIncCam
:= Abs(FIncCam
);
4679 DecMin(FIncCam
, 5, 0);
4680 FIncCam
:= FIncCam
*i
;
4683 // no need to do that each second frame, weapon queue will take care of it
4684 if FLive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4685 if FLive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4687 if gTime
mod (GAME_TICK
*2) <> 0 then
4689 if (FObj
.Vel
.X
= 0) and FLive
then
4691 if FKeys
[KEY_LEFT
].Pressed
then
4693 if FKeys
[KEY_RIGHT
].Pressed
then
4699 g_Obj_Move(@FObj
, True, True, True);
4700 positionChanged(); // this updates spatial accelerators
4706 FActionChanged
:= False;
4710 // Let alive player do some actions
4711 if FKeys
[KEY_LEFT
].Pressed
then Run(D_LEFT
);
4712 if FKeys
[KEY_RIGHT
].Pressed
then Run(D_RIGHT
);
4713 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
4714 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
4715 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
4716 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
4717 if FKeys
[KEY_JUMP
].Pressed
then Jump()
4720 if AnyServer
and FJetpack
then
4724 if NetServer
then MH_SEND_PlayerStats(FUID
);
4726 FCanJetpack
:= True;
4733 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
4735 if FKeys
[k
].Pressed
then
4743 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4746 if (FTime
[T_RESPAWN
] <= gTime
) and
4747 gGameOn
and (not FLive
) then
4749 if (g_Player_GetCount() > 1) then
4753 gExit
:= EXIT_RESTART
;
4758 // Dead spectator actions
4761 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
4762 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
4766 if (FSpectatePlayer
>= High(gPlayers
)) then
4767 FSpectatePlayer
:= -1
4771 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
4772 if gPlayers
[I
] <> nil then
4773 if gPlayers
[I
].Live
then
4774 if gPlayers
[I
].UID
<> FUID
then
4776 FSpectatePlayer
:= I
;
4781 if not SetSpect
then FSpectatePlayer
:= -1;
4792 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
4794 FYTo
:= FObj
.Y
- 32;
4795 FSpectatePlayer
:= -1;
4797 if FKeys
[KEY_DOWN
].Pressed
then
4799 FYTo
:= FObj
.Y
+ 32;
4800 FSpectatePlayer
:= -1;
4802 if FKeys
[KEY_LEFT
].Pressed
then
4804 FXTo
:= FObj
.X
- 32;
4805 FSpectatePlayer
:= -1;
4807 if FKeys
[KEY_RIGHT
].Pressed
then
4809 FXTo
:= FObj
.X
+ 32;
4810 FSpectatePlayer
:= -1;
4813 if (FXTo
< -64) then
4815 else if (FXTo
> gMapInfo
.Width
+ 32) then
4816 FXTo
:= gMapInfo
.Width
+ 32;
4817 if (FYTo
< -72) then
4819 else if (FYTo
> gMapInfo
.Height
+ 32) then
4820 FYTo
:= gMapInfo
.Height
+ 32;
4825 g_Obj_Move(@FObj
, True, True, True);
4826 positionChanged(); // this updates spatial accelerators
4833 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
4834 if gPlayers
[FSpectatePlayer
] <> nil then
4835 if gPlayers
[FSpectatePlayer
].Live
then
4837 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
4838 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
4842 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
4843 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
4844 PANEL_BLOCKMON
, True);
4845 headwater
:= HeadInLiquid(0, 0);
4847 // Ñîïðîòèâëåíèå âîçäóõà:
4848 if (not FLive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
4849 if FObj
.Vel
.X
<> 0 then
4850 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
4852 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
4853 DecMin(FPain
, 5, 0);
4854 DecMin(FPickup
, 1, 0);
4856 if FLive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
4858 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
4859 FMegaRulez
[MR_SUIT
] := 0;
4860 FMegaRulez
[MR_INVUL
] := 0;
4861 FMegaRulez
[MR_INVIS
] := 0;
4862 Kill(K_FALLKILL
, 0, HIT_FALL
);
4869 if FCurrWeap
= WEAPON_SAW
then
4870 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
4871 FSawSoundSelect
.IsPlaying()) then
4872 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
4875 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
4876 (not FJetSoundOff
.IsPlaying()) then
4878 FJetSoundFly
.SetPosition(0);
4879 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
4882 for b
:= WP_FIRST
to WP_LAST
do
4883 if FReloading
[b
] > 0 then
4889 if FShellTimer
> -1 then
4890 if FShellTimer
= 0 then
4892 if FShellType
= SHELL_SHELL
then
4893 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4894 GameVelX
, GameVelY
-2, SHELL_SHELL
)
4895 else if FShellType
= SHELL_DBLSHELL
then
4897 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4898 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
4899 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4900 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
4903 end else Dec(FShellTimer
);
4905 if (FBFGFireCounter
> -1) then
4906 if FBFGFireCounter
= 0 then
4910 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
4911 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
4912 xd
:= wx
+IfThen(FDirection
= D_LEFT
, -30, 30);
4913 yd
:= wy
+firediry();
4914 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
4915 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
4916 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
4917 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
4918 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
4921 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
4922 FBFGFireCounter
:= -1;
4925 FBFGFireCounter
:= 0
4927 Dec(FBFGFireCounter
);
4929 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
4931 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
4933 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
4936 if (headwater
or blockmon
) then
4942 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
4945 else if (FAir
mod 31 = 0) and not blockmon
then
4947 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
4948 if Random(2) = 0 then
4949 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
4951 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
4953 end else if FAir
< AIR_DEF
then
4956 if FFireTime
> 0 then
4958 if BodyInLiquid(0, 0) then
4963 else if FMegaRulez
[MR_SUIT
] >= gTime
then
4965 if FMegaRulez
[MR_SUIT
] = gTime
then
4972 if FFirePainTime
<= 0 then
4974 if g_Game_IsServer
then
4975 Damage(5, FFireAttacker
, 0, 0, HIT_FLAME
);
4976 FFirePainTime
:= 18;
4978 FFirePainTime
:= FFirePainTime
- 1;
4979 FFireTime
:= FFireTime
- 1;
4980 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
4981 MH_SEND_PlayerStats(FUID
);
4985 if FDamageBuffer
> 0 then
4987 if FDamageBuffer
>= 9 then
4991 if FDamageBuffer
< 30 then i
:= 9
4992 else if FDamageBuffer
< 100 then i
:= 18
4996 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
4997 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
4998 FHealth
:= FHealth
-ii
;
5001 FHealth
:= FHealth
+FArmor
;
5006 if FHealth
<= 0 then
5007 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5008 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5009 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5013 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5014 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5015 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5016 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5023 end; // if FLive then ...
5025 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5027 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5028 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5029 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5030 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5032 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5033 then SetAction(A_STAND
, True);
5035 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5037 for b
:= Low(FKeys
) to High(FKeys
) do
5038 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5041 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5043 x
:= FObj
.X
+PLAYER_RECT
.X
;
5044 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5045 w
:= PLAYER_RECT
.Width
;
5046 h
:= PLAYER_RECT
.Height
;
5049 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5051 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5052 FObj
.Y
+PLAYER_RECT
.Y
,
5059 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5061 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5062 FObj
.Y
+PLAYER_RECT
.Y
,
5066 Panel
.Width
, Panel
.Height
);
5069 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5071 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5072 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5073 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5074 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5077 function g_Player_ValidName(Name
: string): Boolean;
5083 if gPlayers
= nil then Exit
;
5085 for a
:= 0 to High(gPlayers
) do
5086 if gPlayers
[a
] <> nil then
5087 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5094 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5098 d
:= FModel
.Direction
;
5100 FModel
.Direction
:= Direction
;
5101 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5103 FDirection
:= Direction
;
5106 function TPlayer
.GetKeys(): Byte;
5110 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5111 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5112 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5114 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5115 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5118 procedure TPlayer
.Use();
5122 if FTime
[T_USE
] > gTime
then Exit
;
5124 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5125 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5127 for a
:= 0 to High(gPlayers
) do
5128 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5129 gPlayers
[a
].Live
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5130 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5131 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5133 gPlayers
[a
].Touch();
5134 if g_Game_IsNet
and g_Game_IsServer
then
5135 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5138 FTime
[T_USE
] := gTime
+120;
5141 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5145 WX
, WY
, XD
, YD
: Integer;
5156 if R_BERSERK
in FRulez
then
5158 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5159 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5160 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5163 locobj
.rect
.Width
:= 39;
5164 locobj
.rect
.Height
:= 52;
5165 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5166 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5167 locobj
.Accel
.X
:= xd
-wx
;
5168 locobj
.Accel
.y
:= yd
-wy
;
5170 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5171 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5173 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5177 FPain
:= min(FPain
+ 25, 50);
5179 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5184 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5185 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5187 FSawSoundSelect
.Stop();
5189 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5191 else if not FSawSoundHit
.IsPlaying() then
5193 FSawSoundSelect
.Stop();
5194 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5201 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5202 FFireAngle
:= FAngle
;
5204 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5205 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5210 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5211 FFireAngle
:= FAngle
;
5214 FShellType
:= SHELL_SHELL
;
5219 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5220 FFireAngle
:= FAngle
;
5223 FShellType
:= SHELL_DBLSHELL
;
5228 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5229 FFireAngle
:= FAngle
;
5231 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5232 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5235 WEAPON_ROCKETLAUNCHER
:
5237 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5238 FFireAngle
:= FAngle
;
5244 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5245 FFireAngle
:= FAngle
;
5251 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5252 FFireAngle
:= FAngle
;
5256 WEAPON_SUPERPULEMET
:
5258 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5259 FFireAngle
:= FAngle
;
5261 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5262 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5265 WEAPON_FLAMETHROWER
:
5267 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5268 FFireAngle
:= FAngle
;
5275 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5276 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5277 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5280 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5282 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5283 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5286 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5290 if NetInterpLevel
< 1 then
5300 AX
:= Abs(FXTo
- FObj
.X
);
5301 AY
:= Abs(FYTo
- FObj
.Y
);
5302 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5304 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5309 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5311 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5312 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5313 PANEL_LIFTUP
, False) then Result
:= -1
5315 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5316 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5317 PANEL_LIFTDOWN
, False) then Result
:= 1
5321 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5328 if Flag
= FLAG_NONE
then
5331 if not g_Game_IsServer
then Exit
;
5333 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5334 if (Flag
= FTeam
) and
5335 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5336 (FFlag
<> FLAG_NONE
) then
5338 if FFlag
= FLAG_RED
then
5339 s
:= _lc
[I_PLAYER_FLAG_RED
]
5341 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5343 evtype
:= FLAG_STATE_SCORED
;
5345 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5346 Insert('.', ts
, Length(ts
) + 1 - 3);
5347 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5349 g_Map_ResetFlag(FFlag
);
5350 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5352 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5355 if g_Game_IsNet
then
5357 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5361 gFlags
[FFlag
].CaptureTime
:= 0;
5366 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5367 if (Flag
= FTeam
) and
5368 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5370 if Flag
= FLAG_RED
then
5371 s
:= _lc
[I_PLAYER_FLAG_RED
]
5373 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5375 evtype
:= FLAG_STATE_RETURNED
;
5376 gFlags
[Flag
].CaptureTime
:= 0;
5378 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5380 g_Map_ResetFlag(Flag
);
5381 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5384 if g_Game_IsNet
then
5386 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5392 // Ïîäîáðàë ÷óæîé ôëàã:
5393 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) 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_CAPTURED
;
5404 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5406 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5408 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5411 if g_Game_IsNet
then
5413 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5419 procedure TPlayer
.SetFlag(Flag
: Byte);
5422 if FModel
<> nil then
5423 FModel
.SetFlag(FFlag
);
5426 function TPlayer
.DropFlag(): Boolean;
5431 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5433 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5434 with gFlags
[FFlag
] do
5438 Direction
:= FDirection
;
5439 State
:= FLAG_STATE_DROPPED
;
5441 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5442 (FObj
.Vel
.Y
div 2)-2+Random(5));
5443 positionChanged(); // this updates spatial accelerators
5445 if FFlag
= FLAG_RED
then
5446 s
:= _lc
[I_PLAYER_FLAG_RED
]
5448 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5450 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5451 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5453 if g_Game_IsNet
then
5454 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5460 procedure TPlayer
.GetSecret();
5465 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5467 Assert(Key
<= High(FKeys
));
5469 FKeys
[Key
].Pressed
:= True;
5470 FKeys
[Key
].Time
:= Time
;
5473 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5475 Result
:= FKeys
[K
].Pressed
;
5478 procedure TPlayer
.ReleaseKeys();
5482 for a
:= Low(FKeys
) to High(FKeys
) do
5484 FKeys
[a
].Pressed
:= False;
5489 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5493 function TPlayer
.firediry(): Integer;
5495 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5496 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5500 procedure TPlayer
.RememberState();
5504 FSavedState
.Health
:= FHealth
;
5505 FSavedState
.Armor
:= FArmor
;
5506 FSavedState
.Air
:= FAir
;
5507 FSavedState
.JetFuel
:= FJetFuel
;
5508 FSavedState
.CurrWeap
:= FCurrWeap
;
5509 FSavedState
.NextWeap
:= FNextWeap
;
5510 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5513 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5515 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5517 FSavedState
.Rulez
:= FRulez
;
5518 FSavedState
.WaitRecall
:= True;
5521 procedure TPlayer
.RecallState();
5525 if not FSavedState
.WaitRecall
then Exit
;
5527 FHealth
:= FSavedState
.Health
;
5528 FArmor
:= FSavedState
.Armor
;
5529 FAir
:= FSavedState
.Air
;
5530 FJetFuel
:= FSavedState
.JetFuel
;
5531 FCurrWeap
:= FSavedState
.CurrWeap
;
5532 FNextWeap
:= FSavedState
.NextWeap
;
5533 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5536 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5538 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5540 FRulez
:= FSavedState
.Rulez
;
5541 FSavedState
.WaitRecall
:= False;
5543 if gGameSettings
.GameType
= GT_SERVER
then
5544 MH_SEND_PlayerStats(FUID
);
5547 procedure TPlayer
.SaveState(var Mem
: TBinMemoryWriter
);
5559 Mem
:= TBinMemoryWriter
.Create(i
);
5561 // Ñèãíàòóðà èãðîêà:
5562 sig
:= PLAYER_SIGNATURE
; // 'PLYR'
5563 Mem
.WriteDWORD(sig
);
5565 Mem
.WriteBoolean(FIamBot
);
5567 Mem
.WriteWord(FUID
);
5569 Mem
.WriteString(FName
, 32);
5571 Mem
.WriteByte(FTeam
);
5573 Mem
.WriteBoolean(FLive
);
5574 // Èçðàñõîäîâàë ëè âñå æèçíè:
5575 Mem
.WriteBoolean(FNoRespawn
);
5577 if FDirection
= D_LEFT
then
5583 Mem
.WriteInt(FHealth
);
5585 Mem
.WriteByte(FLives
);
5587 Mem
.WriteInt(FArmor
);
5591 Mem
.WriteInt(FJetFuel
);
5593 Mem
.WriteInt(FPain
);
5595 Mem
.WriteInt(FKills
);
5597 Mem
.WriteInt(FMonsterKills
);
5599 Mem
.WriteInt(FFrags
);
5601 Mem
.WriteByte(FFragCombo
);
5602 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5603 Mem
.WriteDWORD(FLastFrag
);
5605 Mem
.WriteInt(FDeath
);
5606 // Êàêîé ôëàã íåñåò:
5607 Mem
.WriteByte(FFlag
);
5609 Mem
.WriteInt(FSecrets
);
5611 Mem
.WriteByte(FCurrWeap
);
5613 Mem
.WriteWord(FNextWeap
);
5615 Mem
.WriteByte(FNextWeapDelay
);
5616 // Âðåìÿ çàðÿäêè BFG:
5617 Mem
.WriteSmallInt(FBFGFireCounter
);
5619 Mem
.WriteInt(FDamageBuffer
);
5620 // Ïîñëåäíèé óäàðèâøèé:
5621 Mem
.WriteWord(FLastSpawnerUID
);
5622 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5623 Mem
.WriteByte(FLastHit
);
5625 Obj_SaveState(@FObj
, Mem
);
5626 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5627 for i
:= A_BULLETS
to A_HIGH
do
5628 Mem
.WriteWord(FAmmo
[i
]);
5629 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5630 for i
:= A_BULLETS
to A_HIGH
do
5631 Mem
.WriteWord(FMaxAmmo
[i
]);
5633 for i
:= WP_FIRST
to WP_LAST
do
5634 Mem
.WriteBoolean(FWeapon
[i
]);
5635 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5636 for i
:= WP_FIRST
to WP_LAST
do
5637 Mem
.WriteWord(FReloading
[i
]);
5639 if R_ITEM_BACKPACK
in FRulez
then
5644 // Íàëè÷èå êðàñíîãî êëþ÷à:
5645 if R_KEY_RED
in FRulez
then
5650 // Íàëè÷èå çåëåíîãî êëþ÷à:
5651 if R_KEY_GREEN
in FRulez
then
5656 // Íàëè÷èå ñèíåãî êëþ÷à:
5657 if R_KEY_BLUE
in FRulez
then
5662 // Íàëè÷èå áåðñåðêà:
5663 if R_BERSERK
in FRulez
then
5668 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5669 for i
:= MR_SUIT
to MR_MAX
do
5670 Mem
.WriteDWORD(FMegaRulez
[i
]);
5671 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5672 for i
:= T_RESPAWN
to T_FLAGCAP
do
5673 Mem
.WriteDWORD(FTime
[i
]);
5676 Mem
.WriteString(str
);
5686 procedure TPlayer
.LoadState(var Mem
: TBinMemoryReader
);
5696 // Ñèãíàòóðà èãðîêà:
5698 if sig
<> PLAYER_SIGNATURE
then // 'PLYR'
5700 raise EBinSizeError
.Create('TPlayer.LoadState: Wrong Player Signature');
5703 Mem
.ReadBoolean(FIamBot
);
5707 Mem
.ReadString(str
);
5708 if (Self
<> gPlayer1
) and (Self
<> gPlayer2
) then
5711 Mem
.ReadByte(FTeam
);
5713 Mem
.ReadBoolean(FLive
);
5714 // Èçðàñõîäîâàë ëè âñå æèçíè:
5715 Mem
.ReadBoolean(FNoRespawn
);
5719 FDirection
:= D_LEFT
5721 FDirection
:= D_RIGHT
;
5723 Mem
.ReadInt(FHealth
);
5725 Mem
.ReadByte(FLives
);
5727 Mem
.ReadInt(FArmor
);
5731 Mem
.ReadInt(FJetFuel
);
5735 Mem
.ReadInt(FKills
);
5737 Mem
.ReadInt(FMonsterKills
);
5739 Mem
.ReadInt(FFrags
);
5741 Mem
.ReadByte(FFragCombo
);
5742 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5743 Mem
.ReadDWORD(FLastFrag
);
5745 Mem
.ReadInt(FDeath
);
5746 // Êàêîé ôëàã íåñåò:
5747 Mem
.ReadByte(FFlag
);
5749 Mem
.ReadInt(FSecrets
);
5751 Mem
.ReadByte(FCurrWeap
);
5753 Mem
.ReadWord(FNextWeap
);
5755 Mem
.ReadByte(FNextWeapDelay
);
5756 // Âðåìÿ çàðÿäêè BFG:
5757 Mem
.ReadSmallInt(FBFGFireCounter
);
5759 Mem
.ReadInt(FDamageBuffer
);
5760 // Ïîñëåäíèé óäàðèâøèé:
5761 Mem
.ReadWord(FLastSpawnerUID
);
5762 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5763 Mem
.ReadByte(FLastHit
);
5765 Obj_LoadState(@FObj
, Mem
);
5766 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5767 for i
:= A_BULLETS
to A_HIGH
do
5768 Mem
.ReadWord(FAmmo
[i
]);
5769 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5770 for i
:= A_BULLETS
to A_HIGH
do
5771 Mem
.ReadWord(FMaxAmmo
[i
]);
5773 for i
:= WP_FIRST
to WP_LAST
do
5774 Mem
.ReadBoolean(FWeapon
[i
]);
5775 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5776 for i
:= WP_FIRST
to WP_LAST
do
5777 Mem
.ReadWord(FReloading
[i
]);
5781 Include(FRulez
, R_ITEM_BACKPACK
);
5782 // Íàëè÷èå êðàñíîãî êëþ÷à:
5785 Include(FRulez
, R_KEY_RED
);
5786 // Íàëè÷èå çåëåíîãî êëþ÷à:
5789 Include(FRulez
, R_KEY_GREEN
);
5790 // Íàëè÷èå ñèíåãî êëþ÷à:
5793 Include(FRulez
, R_KEY_BLUE
);
5794 // Íàëè÷èå áåðñåðêà:
5797 Include(FRulez
, R_BERSERK
);
5798 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5799 for i
:= MR_SUIT
to MR_MAX
do
5800 Mem
.ReadDWORD(FMegaRulez
[i
]);
5801 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5802 for i
:= T_RESPAWN
to T_FLAGCAP
do
5803 Mem
.ReadDWORD(FTime
[i
]);
5805 Mem
.ReadString(str
);
5807 Mem
.ReadByte(FColor
.R
);
5808 Mem
.ReadByte(FColor
.G
);
5809 Mem
.ReadByte(FColor
.B
);
5810 if Self
= gPlayer1
then
5812 str
:= gPlayer1Settings
.Model
;
5813 FColor
:= gPlayer1Settings
.Color
;
5815 if Self
= gPlayer2
then
5817 str
:= gPlayer2Settings
.Model
;
5818 FColor
:= gPlayer2Settings
.Color
;
5820 // Îáíîâëÿåì ìîäåëü èãðîêà:
5822 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
5823 FModel
.Color
:= TEAMCOLOR
[FTeam
]
5825 FModel
.Color
:= FColor
;
5828 procedure TPlayer
.AllRulez(Health
: Boolean);
5834 FHealth
:= PLAYER_HP_LIMIT
;
5835 FArmor
:= PLAYER_AP_LIMIT
;
5839 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
5840 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
5841 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5844 procedure TPlayer
.RestoreHealthArmor();
5846 FHealth
:= PLAYER_HP_LIMIT
;
5847 FArmor
:= PLAYER_AP_LIMIT
;
5850 procedure TPlayer
.FragCombo();
5854 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
5856 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
5858 if FFragCombo
< 5 then
5860 Param
:= FUID
or (FFragCombo
shl 16);
5861 if (FComboEvnt
>= Low(gDelayedEvents
)) and
5862 (FComboEvnt
<= High(gDelayedEvents
)) and
5863 gDelayedEvents
[FComboEvnt
].Pending
and
5864 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
5865 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
5867 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
5868 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
5871 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
5879 procedure TPlayer
.GiveItem(ItemType
: Byte);
5883 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
5885 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
5889 if FAir
< AIR_MAX
then
5896 if not (R_BERSERK
in FRulez
) then
5898 Include(FRulez
, R_BERSERK
);
5899 if FBFGFireCounter
< 1 then
5901 FCurrWeap
:= WEAPON_KASTET
;
5903 FModel
.SetWeapon(WEAPON_KASTET
);
5907 FBerserk
:= gTime
+30000;
5909 if FHealth
< PLAYER_HP_SOFT
then
5911 FHealth
:= PLAYER_HP_SOFT
;
5912 FBerserk
:= gTime
+30000;
5917 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
5919 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
5923 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
5925 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
5929 if FJetFuel
< JET_MAX
then
5931 FJetFuel
:= JET_MAX
;
5934 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
5935 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
5937 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
5938 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5940 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
5942 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
5944 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
5945 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5948 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
5949 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
5950 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
5951 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
5952 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
5953 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
5954 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
5955 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
5956 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
5958 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5959 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
5960 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5961 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
5962 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5963 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
5964 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5965 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
5966 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
5969 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
5970 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
5971 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
5972 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
5973 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
5975 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
5976 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
5977 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
5978 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
5979 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
5981 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5982 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5983 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5984 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5986 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
5989 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
5990 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
5991 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
5993 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
5994 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
5999 if g_Game_IsNet
and g_Game_IsServer
then
6000 MH_SEND_PlayerStats(FUID
);
6003 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6008 if (Random(5) = 1) and (Times
= 1) then
6011 if BodyInLiquid(0, 0) then
6013 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6014 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6015 if Random(2) = 0 then
6016 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6018 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6022 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6024 for i
:= 1 to Times
do
6026 Anim
:= TAnimation
.Create(id
, False, 3);
6028 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6029 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6035 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6040 if (Random(10) = 1) and (Times
= 1) then
6043 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6045 for i
:= 1 to Times
do
6047 Anim
:= TAnimation
.Create(id
, False, 3);
6049 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6050 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6056 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6058 FSawSound
.Pause(Enable
);
6059 FSawSoundIdle
.Pause(Enable
);
6060 FSawSoundHit
.Pause(Enable
);
6061 FSawSoundSelect
.Pause(Enable
);
6066 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6071 FObj
.Rect
:= PLAYER_CORPSERECT
;
6072 FModelName
:= ModelName
;
6077 FState
:= CORPSE_STATE_MESS
;
6078 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6082 FState
:= CORPSE_STATE_NORMAL
;
6083 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6087 destructor TCorpse
.Destroy();
6094 procedure TCorpse
.positionChanged (); begin end;
6096 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6100 if FState
= CORPSE_STATE_REMOVEME
then
6103 FDamage
:= FDamage
+ Value
;
6105 if FDamage
> 150 then
6107 if FAnimation
<> nil then
6112 FState
:= CORPSE_STATE_REMOVEME
;
6114 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6115 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6116 FModelName
, FColor
);
6117 // Çâóê ìÿñà îò òðóïà:
6118 pm
:= g_PlayerModel_Get(FModelName
);
6119 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6125 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6126 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6127 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6128 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6129 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6134 procedure TCorpse
.Draw();
6136 if FState
= CORPSE_STATE_REMOVEME
then
6139 if FAnimation
<> nil then
6140 FAnimation
.Draw(FObj
.X
, FObj
.Y
, M_NONE
);
6142 if FAnimationMask
<> nil then
6145 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, M_NONE
);
6152 procedure TCorpse
.Update();
6156 if FState
= CORPSE_STATE_REMOVEME
then
6159 if gTime
mod (GAME_TICK
*2) <> 0 then
6161 g_Obj_Move(@FObj
, True, True, True);
6162 positionChanged(); // this updates spatial accelerators
6166 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6167 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6169 st
:= g_Obj_Move(@FObj
, True, True, True);
6170 positionChanged(); // this updates spatial accelerators
6172 if WordBool(st
and MOVE_FALLOUT
) then
6174 FState
:= CORPSE_STATE_REMOVEME
;
6178 if FAnimation
<> nil then
6179 FAnimation
.Update();
6180 if FAnimationMask
<> nil then
6181 FAnimationMask
.Update();
6184 procedure TCorpse
.SaveState(var Mem
: TBinMemoryWriter
);
6193 sig
:= CORPSE_SIGNATURE
; // 'CORP'
6194 Mem
.WriteDWORD(sig
);
6196 Mem
.WriteByte(FState
);
6197 // Íàêîïëåííûé óðîí:
6198 Mem
.WriteByte(FDamage
);
6200 Mem
.WriteByte(FColor
.R
);
6201 Mem
.WriteByte(FColor
.G
);
6202 Mem
.WriteByte(FColor
.B
);
6204 Obj_SaveState(@FObj
, Mem
);
6205 // Åñòü ëè àíèìàöèÿ:
6206 anim
:= FAnimation
<> nil;
6207 Mem
.WriteBoolean(anim
);
6208 // Åñëè åñòü - ñîõðàíÿåì:
6210 FAnimation
.SaveState(Mem
);
6211 // Åñòü ëè ìàñêà àíèìàöèè:
6212 anim
:= FAnimationMask
<> nil;
6213 Mem
.WriteBoolean(anim
);
6214 // Åñëè åñòü - ñîõðàíÿåì:
6216 FAnimationMask
.SaveState(Mem
);
6219 procedure TCorpse
.LoadState(var Mem
: TBinMemoryReader
);
6229 if sig
<> CORPSE_SIGNATURE
then // 'CORP'
6231 raise EBinSizeError
.Create('TCorpse.LoadState: Wrong Corpse Signature');
6234 Mem
.ReadByte(FState
);
6235 // Íàêîïëåííûé óðîí:
6236 Mem
.ReadByte(FDamage
);
6238 Mem
.ReadByte(FColor
.R
);
6239 Mem
.ReadByte(FColor
.G
);
6240 Mem
.ReadByte(FColor
.B
);
6242 Obj_LoadState(@FObj
, Mem
);
6243 // Åñòü ëè àíèìàöèÿ:
6244 Mem
.ReadBoolean(anim
);
6245 // Åñëè åñòü - çàãðóæàåì:
6248 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6249 FAnimation
.LoadState(Mem
);
6251 // Åñòü ëè ìàñêà àíèìàöèè:
6252 Mem
.ReadBoolean(anim
);
6253 // Åñëè åñòü - çàãðóæàåì:
6256 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6257 FAnimationMask
.LoadState(Mem
);
6263 constructor TBot
.Create();
6270 FSpectator
:= False;
6277 for a
:= WP_FIRST
to WP_LAST
do
6279 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6280 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6281 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6285 destructor TBot
.Destroy();
6288 inherited Destroy();
6291 procedure TBot
.Draw();
6295 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6296 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6299 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6301 inherited Respawn(Silent
, Force
);
6304 FSelectedWeapon
:= FCurrWeap
;
6309 procedure TBot
.UpdateCombat();
6322 TTargetRecord
= array of TTarget
;
6324 function Compare(a
, b
: TTarget
): Integer;
6326 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6329 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6331 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6332 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6334 if a
.Dist
> b
.Dist
then // B áëèæå
6336 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6339 else // Ñòðàííî -> A
6344 a
, x1
, y1
, x2
, y2
: Integer;
6345 targets
: TTargetRecord
;
6347 Target
, BestTarget
: TTarget
;
6348 firew
, fireh
: Integer;
6352 vsPlayer
, vsMonster
, ok
: Boolean;
6355 function monsUpdate (mon
: TMonster
): Boolean;
6357 result
:= false; // don't stop
6358 if mon
.Live
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6360 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6362 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6363 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6365 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6366 if g_TraceVector(x1
, y1
, x2
, y2
) then
6368 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6369 SetLength(targets
, Length(targets
)+1);
6370 with targets
[High(targets
)] do
6377 Rect
:= mon
.Obj
.Rect
;
6378 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6379 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6380 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6389 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6390 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6392 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6393 if FCurrWeap
<> FSelectedWeapon
then
6396 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6397 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6399 RemoveAIFlag('NEEDFIRE');
6402 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6403 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6404 else PressKey(KEY_FIRE
);
6408 // Êîîðäèíàòû ñòâîëà:
6409 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6410 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6412 Target
.UID
:= FTargetUID
;
6415 if Target
.UID
<> 0 then
6416 begin // Öåëü åñòü - íàñòðàèâàåì
6417 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6420 tpla
:= g_Player_Get(Target
.UID
);
6424 if (@FObj
) <> nil then
6431 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6432 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6433 Target
.Rect
:= PLAYER_RECT
;
6434 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6435 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6436 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6437 Target
.IsPlayer
:= True;
6441 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6444 mon
:= g_Monsters_ByUID(Target
.UID
);
6447 Target
.X
:= mon
.Obj
.X
;
6448 Target
.Y
:= mon
.Obj
.Y
;
6450 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6451 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6452 Target
.Rect
:= mon
.Obj
.Rect
;
6453 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6454 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6455 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6456 Target
.IsPlayer
:= False;
6463 begin // Öåëè íåò - îáíóëÿåì
6468 Target
.Visible
:= False;
6469 Target
.Line
:= False;
6470 Target
.IsPlayer
:= False;
6475 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6476 if (not Target
.Line
) or (not Target
.Visible
) then
6480 for a
:= 0 to High(gPlayers
) do
6481 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].Live
) and
6482 (gPlayers
[a
].FUID
<> FUID
) and
6483 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6484 (not gPlayers
[a
].NoTarget
) and
6485 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6487 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6488 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6491 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6492 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6494 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6495 if g_TraceVector(x1
, y1
, x2
, y2
) then
6497 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6498 SetLength(targets
, Length(targets
)+1);
6499 with targets
[High(targets
)] do
6501 UID
:= gPlayers
[a
].FUID
;
6502 X
:= gPlayers
[a
].FObj
.X
;
6503 Y
:= gPlayers
[a
].FObj
.Y
;
6506 Rect
:= PLAYER_RECT
;
6507 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6508 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6509 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6517 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6520 // Åñëè åñòü âîçìîæíûå öåëè:
6521 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6522 if targets
<> nil then
6524 // Âûáèðàåì íàèëó÷øóþ öåëü:
6525 BestTarget
:= targets
[0];
6526 if Length(targets
) > 1 then
6527 for a
:= 1 to High(targets
) do
6528 if Compare(BestTarget
, targets
[a
]) = 1 then
6529 BestTarget
:= targets
[a
];
6531 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6532 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6533 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6535 Target
:= BestTarget
;
6537 if (Healthy() = 3) or ((Healthy() = 2)) then
6538 begin // Åñëè çäîðîâû - äîãîíÿåì
6539 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6540 SetAIFlag('GORIGHT', '1');
6541 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6542 SetAIFlag('GOLEFT', '1');
6545 begin // Åñëè ïîáèòû - óáåãàåì
6546 if ((RunDirection() = D_LEFT
) and (Target
.X
< FObj
.X
)) then
6547 SetAIFlag('GORIGHT', '1');
6548 if ((RunDirection() = D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6549 SetAIFlag('GOLEFT', '1');
6552 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6553 SelectWeapon(Abs(x1
-Target
.cX
));
6558 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6559 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6560 if Target
.UID
<> 0 then
6562 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6563 Target
.Y
+ Target
.Rect
.Y
) then
6564 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6565 if (Healthy() = 3) or ((Healthy() = 2)) then
6566 begin // Åñëè çäîðîâû - äîãîíÿåì
6567 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6568 SetAIFlag('GORIGHT', '1');
6569 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6570 SetAIFlag('GOLEFT', '1');
6573 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6575 if ((RunDirection() = D_LEFT
) and (Target
.X
< FObj
.X
)) then
6576 SetAIFlag('GORIGHT', '1');
6577 if ((RunDirection() = D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6578 SetAIFlag('GOLEFT', '1');
6582 begin // Öåëü ïîêà íà "ýêðàíå"
6583 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6584 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6585 FLastVisible
:= gTime
;
6586 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6587 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6589 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6590 SetAIFlag('GORIGHT', '1');
6591 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6592 SetAIFlag('GOLEFT', '1');
6596 // Âûáèðàåì óãîë ââåðõ:
6597 if FDirection
= D_LEFT
then
6598 angle
:= ANGLE_LEFTUP
6600 angle
:= ANGLE_RIGHTUP
;
6602 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6603 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6605 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6606 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6607 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6608 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6609 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6610 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6611 begin // òî íóæíî ñòðåëÿòü ââåðõ
6612 SetAIFlag('NEEDFIRE', '1');
6613 SetAIFlag('NEEDSEEUP', '1');
6616 // Âûáèðàåì óãîë âíèç:
6617 if FDirection
= D_LEFT
then
6618 angle
:= ANGLE_LEFTDOWN
6620 angle
:= ANGLE_RIGHTDOWN
;
6622 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6623 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6625 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6626 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6627 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6628 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6629 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6630 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6631 begin // òî íóæíî ñòðåëÿòü âíèç
6632 SetAIFlag('NEEDFIRE', '1');
6633 SetAIFlag('NEEDSEEDOWN', '1');
6636 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6637 if Target
.Visible
and
6638 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6639 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6641 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6642 if ((FDirection
= D_LEFT
) and (Target
.X
< FObj
.X
)) or
6643 ((FDirection
= D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6644 begin // òî íóæíî ñòðåëÿòü âïåðåä
6645 SetAIFlag('NEEDFIRE', '1');
6646 SetAIFlag('NEEDSEEDOWN', '');
6647 SetAIFlag('NEEDSEEUP', '');
6649 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6650 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6651 if GetRnd(FDifficult
.CloseJump
) then
6652 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6653 if Abs(FObj
.X
-Target
.X
) < 128 then
6657 if Random(a
) = 0 then
6658 SetAIFlag('NEEDJUMP', '1');
6662 // Åñëè öåëü âñå åùå åñòü:
6663 if Target
.UID
<> 0 then
6664 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
6665 Target
.UID
:= 0 // òî çàáûòü öåëü
6666 else // Åñëè âèäåëè íåäàâíî
6667 begin // íî öåëü óáèëè
6668 if Target
.IsPlayer
then
6669 begin // Öåëü - èãðîê
6670 pla
:= g_Player_Get(Target
.UID
);
6671 if (pla
= nil) or (not pla
.Live
) or pla
.NoTarget
or
6672 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6673 Target
.UID
:= 0; // òî çàáûòü öåëü
6676 begin // Öåëü - ìîíñòð
6677 mon
:= g_Monsters_ByUID(Target
.UID
);
6678 if (mon
= nil) or (not mon
.Live
) then
6679 Target
.UID
:= 0; // òî çàáûòü öåëü
6682 end; // if Target.UID <> 0
6684 FTargetUID
:= Target
.UID
;
6686 // Åñëè âîçìîæíûõ öåëåé íåò:
6687 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
6688 if targets
= nil then
6689 if GetAIFlag('ATTACKLEFT') <> '' then
6690 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
6691 RemoveAIFlag('ATTACKLEFT');
6693 SetAIFlag('NEEDJUMP', '1');
6695 if RunDirection() = D_RIGHT
then
6696 begin // Èäåì íå â òó ñòîðîíó
6697 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6698 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
6699 SetAIFlag('NEEDFIRE', '1');
6700 SetAIFlag('GOLEFT', '1');
6704 begin // Èäåì â íóæíóþ ñòîðîíó
6705 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6706 SetAIFlag('NEEDFIRE', '1');
6707 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6708 SetAIFlag('GORIGHT', '1');
6712 if GetAIFlag('ATTACKRIGHT') <> '' then
6713 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
6714 RemoveAIFlag('ATTACKRIGHT');
6716 SetAIFlag('NEEDJUMP', '1');
6718 if RunDirection() = D_LEFT
then
6719 begin // Èäåì íå â òó ñòîðîíó
6720 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6721 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
6722 SetAIFlag('NEEDFIRE', '1');
6723 SetAIFlag('GORIGHT', '1');
6728 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6729 SetAIFlag('NEEDFIRE', '1');
6730 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6731 SetAIFlag('GOLEFT', '1');
6735 //HACK! (does it belongs there?)
6736 RealizeCurrentWeapon();
6738 // Åñëè åñòü âîçìîæíûå öåëè:
6739 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
6740 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6741 for a
:= 0 to High(targets
) do
6743 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
6744 if GetRnd(FDifficult
.DiagFire
) then
6746 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
6747 if FDirection
= D_LEFT
then
6748 angle
:= ANGLE_LEFTUP
6750 angle
:= ANGLE_RIGHTUP
;
6752 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6753 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6755 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6756 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6757 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6758 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6759 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6761 SetAIFlag('NEEDFIRE', '1');
6762 SetAIFlag('NEEDSEEUP', '1');
6765 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
6766 if FDirection
= D_LEFT
then
6767 angle
:= ANGLE_LEFTDOWN
6769 angle
:= ANGLE_RIGHTDOWN
;
6771 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6772 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6774 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6775 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6776 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6777 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6778 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6780 SetAIFlag('NEEDFIRE', '1');
6781 SetAIFlag('NEEDSEEDOWN', '1');
6785 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
6786 if targets
[a
].Line
and targets
[a
].Visible
and
6787 (((FDirection
= D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
6788 ((FDirection
= D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
6790 SetAIFlag('NEEDFIRE', '1');
6795 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
6796 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
6797 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
6798 40+GetInterval(FDifficult
.Cover
, 40)) then
6799 SetAIFlag('NEEDJUMP', '1');
6801 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
6802 ammo
:= GetAmmoByWeapon(FCurrWeap
);
6803 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
6804 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
6806 SetAIFlag('SELECTWEAPON', '1');
6808 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
6809 if GetAIFlag('SELECTWEAPON') = '1' then
6812 RemoveAIFlag('SELECTWEAPON');
6816 procedure TBot
.Update();
6829 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
6830 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
6832 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
6834 if g_debug_BotAIOff
= 3 then
6844 RealizeCurrentWeapon();
6851 procedure TBot
.ReleaseKey(Key
: Byte);
6860 function TBot
.KeyPressed(Key
: Word): Boolean;
6862 Result
:= FKeys
[Key
].Pressed
;
6865 function TBot
.GetAIFlag(aName
: String20
): String20
;
6871 aName
:= LowerCase(aName
);
6873 if FAIFlags
<> nil then
6874 for a
:= 0 to High(FAIFlags
) do
6875 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6877 Result
:= FAIFlags
[a
].Value
;
6882 procedure TBot
.RemoveAIFlag(aName
: String20
);
6886 if FAIFlags
= nil then Exit
;
6888 aName
:= LowerCase(aName
);
6890 for a
:= 0 to High(FAIFlags
) do
6891 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6893 if a
<> High(FAIFlags
) then
6894 for b
:= a
to High(FAIFlags
)-1 do
6895 FAIFlags
[b
] := FAIFlags
[b
+1];
6897 SetLength(FAIFlags
, Length(FAIFlags
)-1);
6902 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
6910 aName
:= LowerCase(aName
);
6912 if FAIFlags
<> nil then
6913 for a
:= 0 to High(FAIFlags
) do
6914 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6920 if ok
then FAIFlags
[a
].Value
:= fValue
6923 SetLength(FAIFlags
, Length(FAIFlags
)+1);
6924 with FAIFlags
[High(FAIFlags
)] do
6932 procedure TBot
.UpdateMove
;
6934 procedure GoLeft(Time
: Word = 1);
6936 ReleaseKey(KEY_LEFT
);
6937 ReleaseKey(KEY_RIGHT
);
6938 PressKey(KEY_LEFT
, Time
);
6939 SetDirection(D_LEFT
);
6942 procedure GoRight(Time
: Word = 1);
6944 ReleaseKey(KEY_LEFT
);
6945 ReleaseKey(KEY_RIGHT
);
6946 PressKey(KEY_RIGHT
, Time
);
6947 SetDirection(D_RIGHT
);
6950 function Rnd(a
: Word): Boolean;
6952 Result
:= Random(a
) = 0;
6955 procedure Turn(Time
: Word = 1200);
6957 if RunDirection() = D_LEFT
then GoRight(Time
) else GoLeft(Time
);
6962 ReleaseKey(KEY_LEFT
);
6963 ReleaseKey(KEY_RIGHT
);
6966 function CanRunLeft(): Boolean;
6968 Result
:= not CollideLevel(-1, 0);
6971 function CanRunRight(): Boolean;
6973 Result
:= not CollideLevel(1, 0);
6976 function CanRun(): Boolean;
6978 if RunDirection() = D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
6981 procedure Jump(Time
: Word = 30);
6983 PressKey(KEY_JUMP
, Time
);
6986 function NearHole(): Boolean;
6990 { TODO 5 : Ëåñòíèöû }
6991 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6992 for x
:= 1 to PLAYER_RECT
.Width
do
6993 if (not StayOnStep(x
*sx
, 0)) and
6994 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6995 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7004 function BorderHole(): Boolean;
7008 { TODO 5 : Ëåñòíèöû }
7009 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
7010 for x
:= 1 to PLAYER_RECT
.Width
do
7011 if (not StayOnStep(x
*sx
, 0)) and
7012 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7013 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7015 for xx
:= x
to x
+32 do
7016 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7026 function NearDeepHole(): Boolean;
7032 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
7035 for x
:= 1 to PLAYER_RECT
.Width
do
7036 if (not StayOnStep(x
*sx
, 0)) and
7037 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7038 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7040 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7042 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7047 end else Result
:= False;
7050 function OverDeepHole(): Boolean;
7057 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7059 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7066 function OnGround(): Boolean;
7068 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7071 function OnLadder(): Boolean;
7073 Result
:= FullInStep(0, 0);
7076 function BelowLadder(): Boolean;
7078 Result
:= (FullInStep(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7079 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7080 (FullInStep(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7081 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7084 function BelowLiftUp(): Boolean;
7086 Result
:= ((FullInLift(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7087 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7088 ((FullInLift(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7089 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7092 function OnTopLift(): Boolean;
7094 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7097 function CanJumpOver(): Boolean;
7101 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
7105 if not CollideLevel(sx
, 0) then Exit
;
7107 for y
:= 1 to BOT_MAXJUMP
do
7108 if CollideLevel(0, -y
) then Exit
else
7109 if not CollideLevel(sx
, -y
) then
7116 function CanJumpUp(Dist
: ShortInt): Boolean;
7123 if CollideLevel(Dist
, 0) then Exit
;
7126 for y
:= 0 to BOT_MAXJUMP
do
7127 if CollideLevel(Dist
, -y
) then
7136 for yy
:= y
+1 to BOT_MAXJUMP
do
7137 if not CollideLevel(Dist
, -yy
) then
7146 for y
:= 0 to BOT_MAXJUMP
do
7147 if CollideLevel(0, -y
) then
7155 if y
< yy
then Exit
;
7160 function IsSafeTrigger(): Boolean;
7165 if gTriggers
= nil then
7167 for a
:= 0 to High(gTriggers
) do
7168 if Collide(gTriggers
[a
].X
,
7171 gTriggers
[a
].Height
) and
7172 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7173 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7174 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7175 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7176 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7181 // Âîçìîæíî, íàæèìàåì êíîïêó:
7182 if Rnd(16) and IsSafeTrigger() then
7185 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7186 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7188 ReleaseKey(KEY_LEFT
);
7189 ReleaseKey(KEY_RIGHT
);
7193 // Èäåì âëåâî, åñëè íàäî áûëî:
7194 if GetAIFlag('GOLEFT') <> '' then
7196 RemoveAIFlag('GOLEFT');
7197 if CanRunLeft() then
7201 // Èäåì âïðàâî, åñëè íàäî áûëî:
7202 if GetAIFlag('GORIGHT') <> '' then
7204 RemoveAIFlag('GORIGHT');
7205 if CanRunRight() then
7209 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7210 if FObj
.X
< -32 then
7213 if FObj
.X
+32 > gMapInfo
.Width
then
7216 // Ïðûãàåì, åñëè íàäî áûëî:
7217 if GetAIFlag('NEEDJUMP') <> '' then
7220 RemoveAIFlag('NEEDJUMP');
7223 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7224 if GetAIFlag('NEEDSEEUP') <> '' then
7227 ReleaseKey(KEY_DOWN
);
7228 PressKey(KEY_UP
, 20);
7229 RemoveAIFlag('NEEDSEEUP');
7232 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7233 if GetAIFlag('NEEDSEEDOWN') <> '' then
7236 ReleaseKey(KEY_DOWN
);
7237 PressKey(KEY_DOWN
, 20);
7238 RemoveAIFlag('NEEDSEEDOWN');
7241 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7242 if GetAIFlag('GOINHOLE') <> '' then
7243 if not OnGround() then
7245 ReleaseKey(KEY_LEFT
);
7246 ReleaseKey(KEY_RIGHT
);
7247 RemoveAIFlag('GOINHOLE');
7248 SetAIFlag('FALLINHOLE', '1');
7251 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7252 if GetAIFlag('FALLINHOLE') <> '' then
7254 RemoveAIFlag('FALLINHOLE');
7256 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7257 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7258 if GetAIFlag('FALLINHOLE') = '' then
7259 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7265 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7267 CanJumpUp(IfThen(RunDirection() = D_LEFT
, -1, 1)*32) and
7271 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7272 if OnGround() and NearHole() then
7273 if NearDeepHole() then // Åñëè ýòî áåçäíà
7275 0..3: Turn(); // Áåæèì îáðàòíî
7276 4: Jump(); // Ïðûãàåì
7277 5: begin // Ïðûãàåì îáðàòíî
7282 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7283 if GetAIFlag('GOINHOLE') = '' then
7285 0: Turn(); // Íå íóæíî òóäà
7286 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7287 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7288 if BorderHole() then
7289 SetAIFlag('GOINHOLE', '1');
7292 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7293 if (not CanRun()) and OnGround() then
7295 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7296 if CanJumpOver() or OnLadder() then
7298 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7299 if Random(2) = 0 then
7301 if IsSafeTrigger() then
7307 // Îñòàëîñü ìàëî âîçäóõà:
7308 if FAir
< 36 * 2 then
7311 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7312 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7313 if BodyInAcid(0, 0) then
7317 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7319 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7320 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7323 {function TBot.NeedItem(Item: Byte): Byte;
7328 procedure TBot
.SelectWeapon(Dist
: Integer);
7332 function HaveAmmo(weapon
: Byte): Boolean;
7335 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7336 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7337 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7338 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7339 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7340 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7341 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7342 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7343 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7344 else Result
:= True;
7349 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7351 if Dist
> BOT_LONGDIST
then
7352 begin // Äàëüíèé áîé
7354 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7356 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7360 else //if Dist > BOT_UNSAFEDIST then
7361 begin // Áëèæíèé áîé
7363 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7365 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7372 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7374 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7380 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7382 Result
:= inherited PickItem(ItemType
, force
, remove
);
7384 if Result
then SetAIFlag('SELECTWEAPON', '1');
7387 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7389 Result
:= inherited Heal(value
, Soft
);
7392 function TBot
.Healthy(): Byte;
7394 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7395 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7396 else if (FHealth
> 50) then Result
:= 2
7397 else if (FHealth
> 20) then Result
:= 1
7401 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7403 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7404 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7407 procedure TBot
.OnDamage(Angle
: SmallInt);
7415 if (Angle
= 0) or (Angle
= 180) then
7418 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7419 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7421 pla
:= g_Player_Get(FLastSpawnerUID
);
7422 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7423 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7426 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7427 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7429 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7430 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7431 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7436 SetAIFlag('ATTACKLEFT', '1')
7438 SetAIFlag('ATTACKRIGHT', '1');
7442 function TBot
.RunDirection(): TDirection
;
7444 if Abs(Vel
.X
) >= 1 then
7446 if Vel
.X
> 0 then Result
:= D_RIGHT
else Result
:= D_LEFT
;
7448 Result
:= FDirection
;
7451 function TBot
.GetRnd(a
: Byte): Boolean;
7453 if a
= 0 then Result
:= False
7454 else if a
= 255 then Result
:= True
7455 else Result
:= Random(256) > 255-a
;
7458 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7460 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7463 procedure TBot
.SaveState(var Mem
: TBinMemoryWriter
);
7469 inherited SaveState(Mem
);
7471 // Âûáðàííîå îðóæèå:
7472 Mem
.WriteByte(FSelectedWeapon
);
7474 Mem
.WriteWord(FTargetUID
);
7475 // Âðåìÿ ïîòåðè öåëè:
7476 Mem
.WriteDWORD(FLastVisible
);
7477 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7478 dw
:= Length(FAIFlags
);
7481 for i
:= 0 to Integer(dw
)-1 do
7483 Mem
.WriteString(FAIFlags
[i
].Name
, 20);
7484 Mem
.WriteString(FAIFlags
[i
].Value
, 20);
7486 // Íàñòðîéêè ñëîæíîñòè:
7488 Mem
.WriteMemory(p
, SizeOf(TDifficult
));
7491 procedure TBot
.LoadState(var Mem
: TBinMemoryReader
);
7497 inherited LoadState(Mem
);
7499 // Âûáðàííîå îðóæèå:
7500 Mem
.ReadByte(FSelectedWeapon
);
7502 Mem
.ReadWord(FTargetUID
);
7503 // Âðåìÿ ïîòåðè öåëè:
7504 Mem
.ReadDWORD(FLastVisible
);
7505 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7507 SetLength(FAIFlags
, dw
);
7509 for i
:= 0 to Integer(dw
)-1 do
7511 Mem
.ReadString(FAIFlags
[i
].Name
);
7512 Mem
.ReadString(FAIFlags
[i
].Value
);
7514 // Íàñòðîéêè ñëîæíîñòè:
7515 Mem
.ReadMemory(p
, dw
);
7516 if dw
<> SizeOf(TDifficult
) then
7518 raise EBinSizeError
.Create('TBot.LoadState: Wrong FDifficult Size');
7520 FDifficult
:= TDifficult(p
^);