1 (* Copyright (C) DooM 2D:Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
23 e_graphics
, g_playermodel
, g_basic
, g_textures
,
24 g_weapons
, g_phys
, g_sound
, g_saveload
, MAPDEF
,
57 AmmoLimits
: Array [0..1] of Array [A_BULLETS
..A_HIGH
] of Word =
58 ((200, 50, 50, 300, 100),
59 (400, 100, 100, 600, 200));
80 ANGLE_NONE
= Low(SmallInt);
82 CORPSE_STATE_REMOVEME
= 0;
83 CORPSE_STATE_NORMAL
= 1;
84 CORPSE_STATE_MESS
= 2;
86 PLAYER_RECT
: TRectWH
= (X
:15; Y
:12; Width
:34; Height
:52);
87 PLAYER_RECT_CX
= 15+(34 div 2);
88 PLAYER_RECT_CY
= 12+(52 div 2);
89 PLAYER_CORPSERECT
: TRectWH
= (X
:15; Y
:48; Width
:34; Height
:16);
92 PLAYER_HP_LIMIT
= 200;
94 PLAYER_AP_LIMIT
= 200;
97 PLAYER1_DEF_COLOR
: TRGB
= (R
:64; G
:175; B
:48);
98 PLAYER2_DEF_COLOR
: TRGB
= (R
:96; G
:96; B
:96);
114 TPlayerStatArray
= Array of TPlayerStat
;
116 TPlayerSavedState
= record
124 Ammo
: Array [A_BULLETS
..A_HIGH
] of Word;
125 MaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
126 Weapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
127 Rulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
136 TPlayer
= class (TObject
)
144 FDirection
: TDirection
;
152 FMonsterKills
: Integer;
158 FCanJetpack
: Boolean;
164 FNextWeapDelay
: Byte; // frames
165 FBFGFireCounter
: SmallInt;
166 FLastSpawnerUID
: Word;
170 FSpectatePlayer
: Integer;
171 FFirePainTime
: Integer;
174 FSavedState
: TPlayerSavedState
;
176 FModel
: TPlayerModel
;
179 FActionForce
: Boolean;
180 FActionChanged
: Boolean;
182 FFireAngle
: SmallInt;
184 FShellTimer
: Integer;
186 FSawSound
: TPlayableSound
;
187 FSawSoundIdle
: TPlayableSound
;
188 FSawSoundHit
: TPlayableSound
;
189 FSawSoundSelect
: TPlayableSound
;
190 FJetSoundOn
: TPlayableSound
;
191 FJetSoundOff
: TPlayableSound
;
192 FJetSoundFly
: TPlayableSound
;
196 FJustTeleported
: Boolean;
199 function CollideLevel(XInc
, YInc
: Integer): Boolean;
200 function StayOnStep(XInc
, YInc
: Integer): Boolean;
201 function HeadInLiquid(XInc
, YInc
: Integer): Boolean;
202 function BodyInLiquid(XInc
, YInc
: Integer): Boolean;
203 function BodyInAcid(XInc
, YInc
: Integer): Boolean;
204 function FullInLift(XInc
, YInc
: Integer): Integer;
205 {procedure CollideItem();}
206 procedure FlySmoke(Times
: DWORD
= 1);
207 procedure OnFireFlame(Times
: DWORD
= 1);
208 function GetAmmoByWeapon(Weapon
: Byte): Word;
209 procedure SetAction(Action
: Byte; Force
: Boolean = False);
210 procedure OnDamage(Angle
: SmallInt); virtual;
211 function firediry(): Integer;
213 procedure Run(Direction
: TDirection
);
214 procedure NextWeapon();
215 procedure PrevWeapon();
222 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
223 procedure resetWeaponQueue ();
224 function hasAmmoForWeapon (weapon
: Byte): Boolean;
227 FDamageBuffer
: Integer;
229 FAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
230 FMaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
231 FWeapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
232 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
234 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
235 FReloading
: Array [WP_FIRST
..WP_LAST
] of Word;
236 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
237 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
239 FPreferredTeam
: Byte;
242 FWantsInGame
: Boolean;
246 FActualModelName
: string;
253 // debug: viewport offset
254 viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer;
256 function isValidViewPort (): Boolean; inline;
258 constructor Create(); virtual;
259 destructor Destroy(); override;
260 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
261 function GetRespawnPoint(): Byte;
262 procedure PressKey(Key
: Byte; Time
: Word = 1);
263 procedure ReleaseKeys();
264 procedure SetModel(ModelName
: String);
265 procedure SetColor(Color
: TRGB
);
266 procedure SetWeapon(W
: Byte);
267 function IsKeyPressed(K
: Byte): Boolean;
268 function GetKeys(): Byte;
269 function PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean; virtual;
270 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
271 function Collide(Panel
: TPanel
): Boolean; overload
;
272 function Collide(X
, Y
: Integer): Boolean; overload
;
273 procedure SetDirection(Direction
: TDirection
);
274 procedure GetSecret();
275 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
277 procedure Push(vx
, vy
: Integer);
278 procedure ChangeModel(ModelName
: String);
279 procedure SwitchTeam
;
280 procedure ChangeTeam(Team
: Byte);
282 function GetFlag(Flag
: Byte): Boolean;
283 procedure SetFlag(Flag
: Byte);
284 function DropFlag(): Boolean;
285 procedure AllRulez(Health
: Boolean);
286 procedure RestoreHealthArmor();
287 procedure FragCombo();
288 procedure GiveItem(ItemType
: Byte);
289 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
290 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
291 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
292 procedure MakeBloodSimple(Count
: Word);
293 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
294 procedure Reset(Force
: Boolean);
295 procedure Spectate(NoMove
: Boolean = False);
296 procedure SwitchNoClip
;
297 procedure SoftReset();
298 procedure Draw(); virtual;
299 procedure DrawPain();
300 procedure DrawPickup();
301 procedure DrawRulez();
303 procedure DrawBubble();
305 procedure Update(); virtual;
306 procedure RememberState();
307 procedure RecallState();
308 procedure SaveState(var Mem
: TBinMemoryWriter
); virtual;
309 procedure LoadState(var Mem
: TBinMemoryReader
); virtual;
310 procedure PauseSounds(Enable
: Boolean);
311 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
312 procedure DoLerp(Level
: Integer = 2);
313 procedure SetLerp(XTo
, YTo
: Integer);
314 procedure QueueWeaponSwitch(Weapon
: Byte);
315 procedure RealizeCurrentWeapon();
317 procedure JetpackOff
;
318 procedure CatchFire(Attacker
: Word);
320 //WARNING! this does nothing for now, but still call it!
321 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
323 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
324 procedure moveBy (dx
, dy
: Integer); inline;
327 property Vel
: TPoint2i read FObj
.Vel
;
328 property Obj
: TObj read FObj
;
331 property Name
: String read FName write FName
;
332 property Model
: TPlayerModel read FModel
;
333 property Health
: Integer read FHealth write FHealth
;
334 property Lives
: Byte read FLives write FLives
;
335 property Armor
: Integer read FArmor write FArmor
;
336 property Air
: Integer read FAir write FAir
;
337 property JetFuel
: Integer read FJetFuel write FJetFuel
;
338 property Frags
: Integer read FFrags write FFrags
;
339 property Death
: Integer read FDeath write FDeath
;
340 property Kills
: Integer read FKills write FKills
;
341 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
342 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
343 property Secrets
: Integer read FSecrets
;
344 property GodMode
: Boolean read FGodMode write FGodMode
;
345 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
346 property NoReload
: Boolean read FNoReload write FNoReload
;
347 property alive
: Boolean read FAlive write FAlive
;
348 property Flag
: Byte read FFlag
;
349 property Team
: Byte read FTeam write FTeam
;
350 property Direction
: TDirection read FDirection
;
351 property GameX
: Integer read FObj
.X write FObj
.X
;
352 property GameY
: Integer read FObj
.Y write FObj
.Y
;
353 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
354 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
355 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
356 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
357 property IncCam
: Integer read FIncCam write FIncCam
;
358 property UID
: Word read FUID write FUID
;
359 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
360 property NetTime
: LongWord read FNetTime write FNetTime
;
370 WeaponPrior
: Array [WP_FIRST
..WP_LAST
] of Byte;
371 CloseWeaponPrior
: Array [WP_FIRST
..WP_LAST
] of Byte;
372 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
380 TBot
= class (TPlayer
)
382 FSelectedWeapon
: Byte;
385 FAIFlags
: Array of TAIFlag
;
386 FDifficult
: TDifficult
;
388 function GetRnd(a
: Byte): Boolean;
389 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
390 function RunDirection(): TDirection
;
391 function FullInStep(XInc
, YInc
: Integer): Boolean;
392 //function NeedItem(Item: Byte): Byte;
393 procedure SelectWeapon(Dist
: Integer);
394 procedure SetAIFlag(aName
, fValue
: String20
);
395 function GetAIFlag(aName
: String20
): String20
;
396 procedure RemoveAIFlag(aName
: String20
);
397 function Healthy(): Byte;
398 procedure UpdateMove();
399 procedure UpdateCombat();
400 function KeyPressed(Key
: Word): Boolean;
401 procedure ReleaseKey(Key
: Byte);
402 function TargetOnScreen(TX
, TY
: Integer): Boolean;
403 procedure OnDamage(Angle
: SmallInt); override;
406 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
407 constructor Create(); override;
408 destructor Destroy(); override;
409 procedure Draw(); override;
410 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
411 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
412 procedure Update(); override;
413 procedure SaveState(var Mem
: TBinMemoryWriter
); override;
414 procedure LoadState(var Mem
: TBinMemoryReader
); override;
426 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
427 procedure moveBy (dx
, dy
: Integer); inline;
429 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
443 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
444 procedure moveBy (dx
, dy
: Integer); inline;
446 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
449 TCorpse
= class (TObject
)
457 FAnimation
: TAnimation
;
458 FAnimationMask
: TAnimation
;
461 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
462 destructor Destroy(); override;
463 procedure Damage(Value
: Word; vx
, vy
: Integer);
466 procedure SaveState(var Mem
: TBinMemoryWriter
);
467 procedure LoadState(var Mem
: TBinMemoryReader
);
469 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
470 procedure moveBy (dx
, dy
: Integer); inline;
472 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
474 function ObjPtr (): PObj
; inline;
476 property Obj
: TObj read FObj
; // copies object
477 property State
: Byte read FState
;
478 property Mess
: Boolean read FMess
;
481 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
487 gPlayers
: Array of TPlayer
;
488 gCorpses
: Array of TCorpse
;
489 gGibs
: Array of TGib
;
490 gShells
: Array of TShell
;
491 gTeamStat
: TTeamStat
;
492 gFly
: Boolean = False;
493 gAimLine
: Boolean = False;
494 gChatBubble
: Byte = 0;
498 MAX_RUNVEL
: Integer = 8;
499 VEL_JUMP
: Integer = 10;
500 SHELL_TIMEOUT
: Cardinal = 60000;
502 function Lerp(X
, Y
, Factor
: Integer): Integer;
504 procedure g_Gibs_SetMax(Count
: Word);
505 function g_Gibs_GetMax(): Word;
506 procedure g_Corpses_SetMax(Count
: Word);
507 function g_Corpses_GetMax(): Word;
508 procedure g_Shells_SetMax(Count
: Word);
509 function g_Shells_GetMax(): Word;
511 procedure g_Player_Init();
512 procedure g_Player_Free();
513 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
514 function g_Player_CreateFromState(var Mem
: TBinMemoryReader
): Word;
515 procedure g_Player_Remove(UID
: Word);
516 procedure g_Player_ResetTeams();
517 procedure g_Player_UpdateAll();
518 procedure g_Player_DrawAll();
519 procedure g_Player_DrawDebug(p
: TPlayer
);
520 procedure g_Player_DrawHealth();
521 procedure g_Player_RememberAll();
522 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
523 function g_Player_Get(UID
: Word): TPlayer
;
524 function g_Player_GetCount(): Byte;
525 function g_Player_GetStats(): TPlayerStatArray
;
526 function g_Player_ValidName(Name
: String): Boolean;
527 procedure g_Player_CreateCorpse(Player
: TPlayer
);
528 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
529 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
530 procedure g_Player_UpdatePhysicalObjects();
531 procedure g_Player_DrawCorpses();
532 procedure g_Player_DrawShells();
533 procedure g_Player_RemoveAllCorpses();
534 procedure g_Player_Corpses_SaveState(var Mem
: TBinMemoryWriter
);
535 procedure g_Player_Corpses_LoadState(var Mem
: TBinMemoryReader
);
536 procedure g_Bot_Add(Team
, Difficult
: Byte);
537 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1);
538 procedure g_Bot_MixNames();
539 procedure g_Bot_RemoveAll();
544 e_log
, g_map
, g_items
, g_console
, SysUtils
, g_gfx
, Math
,
545 g_options
, g_triggers
, g_menu
, g_game
, g_grid
,
546 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
,
547 g_net
, g_netmsg
, g_window
, GL
, g_holmes
;
557 diag_precision
: Byte;
561 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
562 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
563 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
567 TIME_RESPAWN1
= 1500;
568 TIME_RESPAWN2
= 2000;
569 TIME_RESPAWN3
= 3000;
572 JET_MAX
= 540; // ~30 sec
573 PLAYER_SUIT_TIME
= 30000;
574 PLAYER_INVUL_TIME
= 30000;
575 PLAYER_INVIS_TIME
= 35000;
576 FRAG_COMBO_TIME
= 3000;
580 ANGLE_RIGHTDOWN
= -35;
582 ANGLE_LEFTDOWN
= -145;
583 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
584 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
587 BOT_UNSAFEDIST
= 128;
588 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
590 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
591 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
592 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
593 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
594 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
595 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
596 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
597 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
598 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
599 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
600 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
601 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
602 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
603 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
604 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
605 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
606 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
607 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
608 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
609 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
610 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
611 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
612 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
613 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
614 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
615 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
617 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
618 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
620 BOTNAMES_FILENAME
= 'botnames.txt';
621 BOTLIST_FILENAME
= 'botlist.txt';
625 MaxCorpses
: Word = 20;
626 MaxShells
: Word = 300;
627 CurrentGib
: Integer = 0;
628 CurrentShell
: Integer = 0;
629 BotNames
: Array of String;
630 BotList
: Array of TBotProfile
;
633 function Lerp(X
, Y
, Factor
: Integer): Integer;
635 Result
:= X
+ ((Y
- X
) div Factor
);
638 function SameTeam(UID1
, UID2
: Word): Boolean;
642 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
643 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
645 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
647 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
648 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
650 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
653 procedure g_Gibs_SetMax(Count
: Word);
656 SetLength(gGibs
, Count
);
658 if CurrentGib
>= Count
then
662 function g_Gibs_GetMax(): Word;
667 procedure g_Shells_SetMax(Count
: Word);
670 SetLength(gShells
, Count
);
672 if CurrentShell
>= Count
then
676 function g_Shells_GetMax(): Word;
682 procedure g_Corpses_SetMax(Count
: Word);
685 SetLength(gCorpses
, Count
);
688 function g_Corpses_GetMax(): Word;
690 Result
:= MaxCorpses
;
693 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
703 // Åñòü ëè ìåñòî â gPlayers:
704 if gPlayers
<> nil then
705 for a
:= 0 to High(gPlayers
) do
706 if gPlayers
[a
] = nil then
712 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
715 SetLength(gPlayers
, Length(gPlayers
)+1);
719 // Ñîçäàåì îáúåêò èãðîêà:
721 gPlayers
[a
] := TBot
.Create()
723 gPlayers
[a
] := TPlayer
.Create();
726 gPlayers
[a
].FActualModelName
:= ModelName
;
727 gPlayers
[a
].SetModel(ModelName
);
729 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
730 if gPlayers
[a
].FModel
= nil then
734 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
738 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
739 if Random(2) = 0 then
743 gPlayers
[a
].FPreferredTeam
:= Team
;
745 case gGameSettings
.GameMode
of
746 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
748 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
750 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
753 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
754 gPlayers
[a
].FColor
:= Color
;
755 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
756 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
758 gPlayers
[a
].FModel
.Color
:= Color
;
760 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
761 gPlayers
[a
].FAlive
:= False;
763 Result
:= gPlayers
[a
].FUID
;
766 function g_Player_CreateFromState(var Mem
: TBinMemoryReader
): Word;
779 if sig
<> PLAYER_SIGNATURE
then // 'PLYR'
781 raise EBinSizeError
.Create('g_Player_CreateFromState: Wrong Player Signature');
785 Mem
.ReadBoolean(Bot
);
790 // Åñòü ëè ìåñòî â gPlayers:
791 if gPlayers
<> nil then
792 for a
:= 0 to High(gPlayers
) do
793 if gPlayers
[a
] = nil then
799 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
802 SetLength(gPlayers
, Length(gPlayers
)+1);
806 // Ñîçäàåì îáúåêò èãðîêà:
808 gPlayers
[a
] := TBot
.Create()
810 gPlayers
[a
] := TPlayer
.Create();
811 gPlayers
[a
].FIamBot
:= Bot
;
812 gPlayers
[a
].FPhysics
:= True;
815 Mem
.ReadWord(gPlayers
[a
].FUID
);
817 Mem
.ReadString(gPlayers
[a
].FName
);
819 Mem
.ReadByte(gPlayers
[a
].FTeam
);
820 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
822 Mem
.ReadBoolean(gPlayers
[a
].FAlive
);
823 // Èçðàñõîäîâàë ëè âñå æèçíè:
824 Mem
.ReadBoolean(gPlayers
[a
].FNoRespawn
);
828 gPlayers
[a
].FDirection
:= D_LEFT
830 gPlayers
[a
].FDirection
:= D_RIGHT
;
832 Mem
.ReadInt(gPlayers
[a
].FHealth
);
834 Mem
.ReadByte(gPlayers
[a
].FLives
);
836 Mem
.ReadInt(gPlayers
[a
].FArmor
);
838 Mem
.ReadInt(gPlayers
[a
].FAir
);
840 Mem
.ReadInt(gPlayers
[a
].FJetFuel
);
842 Mem
.ReadInt(gPlayers
[a
].FPain
);
844 Mem
.ReadInt(gPlayers
[a
].FKills
);
846 Mem
.ReadInt(gPlayers
[a
].FMonsterKills
);
848 Mem
.ReadInt(gPlayers
[a
].FFrags
);
850 Mem
.ReadByte(gPlayers
[a
].FFragCombo
);
851 // Âðåìÿ ïîñëåäíåãî ôðàãà:
852 Mem
.ReadDWORD(gPlayers
[a
].FLastFrag
);
854 Mem
.ReadInt(gPlayers
[a
].FDeath
);
856 Mem
.ReadByte(gPlayers
[a
].FFlag
);
858 Mem
.ReadInt(gPlayers
[a
].FSecrets
);
860 Mem
.ReadByte(gPlayers
[a
].FCurrWeap
);
861 // Ñëåäóþùåå æåëàåìîå îðóæèå:
862 Mem
.ReadWord(gPlayers
[a
].FNextWeap
);
864 Mem
.ReadByte(gPlayers
[a
].FNextWeapDelay
);
865 // Âðåìÿ çàðÿäêè BFG:
866 Mem
.ReadSmallInt(gPlayers
[a
].FBFGFireCounter
);
868 Mem
.ReadInt(gPlayers
[a
].FDamageBuffer
);
869 // Ïîñëåäíèé óäàðèâøèé:
870 Mem
.ReadWord(gPlayers
[a
].FLastSpawnerUID
);
871 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
872 Mem
.ReadByte(gPlayers
[a
].FLastHit
);
874 Obj_LoadState(@gPlayers
[a
].FObj
, Mem
);
875 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
876 for i
:= A_BULLETS
to A_HIGH
do
877 Mem
.ReadWord(gPlayers
[a
].FAmmo
[i
]);
878 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
879 for i
:= A_BULLETS
to A_HIGH
do
880 Mem
.ReadWord(gPlayers
[a
].FMaxAmmo
[i
]);
882 for i
:= WP_FIRST
to WP_LAST
do
883 Mem
.ReadBoolean(gPlayers
[a
].FWeapon
[i
]);
884 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
885 for i
:= WP_FIRST
to WP_LAST
do
886 Mem
.ReadWord(gPlayers
[a
].FReloading
[i
]);
890 Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
891 // Íàëè÷èå êðàñíîãî êëþ÷à:
894 Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
895 // Íàëè÷èå çåëåíîãî êëþ÷à:
898 Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
899 // Íàëè÷èå ñèíåãî êëþ÷à:
902 Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
906 Include(gPlayers
[a
].FRulez
, R_BERSERK
);
907 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
908 for i
:= MR_SUIT
to MR_MAX
do
909 Mem
.ReadDWORD(gPlayers
[a
].FMegaRulez
[i
]);
910 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
911 for i
:= T_RESPAWN
to T_FLAGCAP
do
912 Mem
.ReadDWORD(gPlayers
[a
].FTime
[i
]);
915 Mem
.ReadString(gPlayers
[a
].FActualModelName
);
917 Mem
.ReadByte(gPlayers
[a
].FColor
.R
);
918 Mem
.ReadByte(gPlayers
[a
].FColor
.G
);
919 Mem
.ReadByte(gPlayers
[a
].FColor
.B
);
920 // Îáíîâëÿåì ìîäåëü èãðîêà:
921 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
923 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
924 if gPlayers
[a
].FModel
= nil then
928 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
932 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
933 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
934 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
936 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
938 Result
:= gPlayers
[a
].FUID
;
941 procedure g_Player_ResetTeams();
945 if g_Game_IsClient
then
947 if gPlayers
= nil then
949 for a
:= Low(gPlayers
) to High(gPlayers
) do
950 if gPlayers
[a
] <> nil then
951 case gGameSettings
.GameMode
of
953 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
955 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
956 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
957 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
960 gPlayers
[a
].ChangeTeam(TEAM_RED
)
962 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
965 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
969 procedure g_Bot_Add(Team
, Difficult
: Byte);
972 _name
, _model
: String;
975 if not g_Game_IsServer
then Exit
;
977 // Ñïèñîê íàçâàíèé ìîäåëåé:
978 m
:= g_PlayerModel_GetNames();
983 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
984 Team
:= TEAM_COOP
// COOP
986 if gGameSettings
.GameMode
= GM_DM
then
987 Team
:= TEAM_NONE
// DM
989 if Team
= TEAM_NONE
then // CTF / TDM
991 // Àâòîáàëàíñ êîìàíä:
995 for a
:= 0 to High(gPlayers
) do
996 if gPlayers
[a
] <> nil then
998 if gPlayers
[a
].Team
= TEAM_RED
then
1001 if gPlayers
[a
].Team
= TEAM_BLUE
then
1011 if Random(2) = 0 then
1017 // Âûáèðàåì áîòó èìÿ:
1019 if BotNames
<> nil then
1020 for a
:= 0 to High(BotNames
) do
1021 if g_Player_ValidName(BotNames
[a
]) then
1023 _name
:= BotNames
[a
];
1027 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
1030 _name
:= Format('DFBOT%.2d', [Random(100)]);
1031 until g_Player_ValidName(_name
);
1033 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1034 _model
:= m
[Random(Length(m
))];
1037 with g_Player_Get(g_Player_Create(_model
,
1038 _RGB(Min(Random(9)*32, 255),
1039 Min(Random(9)*32, 255),
1040 Min(Random(9)*32, 255)),
1041 Team
, True)) as TBot
do
1046 1: FDifficult
:= DIFFICULT_EASY
;
1047 2: FDifficult
:= DIFFICULT_MEDIUM
;
1048 else FDifficult
:= DIFFICULT_HARD
;
1051 for a
:= WP_FIRST
to WP_LAST
do
1053 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1054 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1055 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1058 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1060 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1061 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1066 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1);
1069 _name
, _model
: String;
1072 if not g_Game_IsServer
then Exit
;
1074 // Ñïèñîê íàçâàíèé ìîäåëåé:
1075 m
:= g_PlayerModel_GetNames();
1080 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1081 Team
:= TEAM_COOP
// COOP
1083 if gGameSettings
.GameMode
= GM_DM
then
1084 Team
:= TEAM_NONE
// DM
1086 if Team
= TEAM_NONE
then
1087 Team
:= BotList
[num
].team
; // CTF / TDM
1089 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1090 lName
:= AnsiLowerCase(lName
);
1091 if (num
< 0) or (num
> Length(BotList
)-1) then
1093 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1094 for a
:= 0 to High(BotList
) do
1095 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1104 _name
:= BotList
[num
].name
;
1105 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1106 if not g_Player_ValidName(_name
) then
1108 _name
:= Format('DFBOT%.2d', [Random(100)]);
1109 until g_Player_ValidName(_name
);
1112 _model
:= BotList
[num
].model
;
1113 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1114 if not InSArray(_model
, m
) then
1115 _model
:= m
[Random(Length(m
))];
1118 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1122 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1123 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1124 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1125 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1126 FDifficult
.Cover
:= BotList
[num
].cover
;
1127 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1129 for a
:= WP_FIRST
to WP_LAST
do
1131 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1132 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1133 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1136 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1138 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1142 procedure g_Bot_RemoveAll();
1146 if not g_Game_IsServer
then Exit
;
1147 if gPlayers
= nil then Exit
;
1149 for a
:= 0 to High(gPlayers
) do
1150 if gPlayers
[a
] <> nil then
1151 if gPlayers
[a
] is TBot
then
1153 gPlayers
[a
].Lives
:= 0;
1154 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1155 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1156 g_Player_Remove(gPlayers
[a
].FUID
);
1162 procedure g_Bot_MixNames();
1167 if BotNames
<> nil then
1168 for a
:= 0 to High(BotNames
) do
1170 b
:= Random(Length(BotNames
));
1172 Botnames
[a
] := BotNames
[b
];
1177 procedure g_Player_Remove(UID
: Word);
1181 if gPlayers
= nil then Exit
;
1183 if g_Game_IsServer
and g_Game_IsNet
then
1184 MH_SEND_PlayerDelete(UID
);
1186 for i
:= 0 to High(gPlayers
) do
1187 if gPlayers
[i
] <> nil then
1188 if gPlayers
[i
].FUID
= UID
then
1190 if gPlayers
[i
] is TPlayer
then
1191 TPlayer(gPlayers
[i
]).Free()
1193 TBot(gPlayers
[i
]).Free();
1199 procedure g_Player_Init();
1209 if not FileExists(DataDir
+ BOTNAMES_FILENAME
) then
1212 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1213 AssignFile(F
, DataDir
+ BOTNAMES_FILENAME
);
1224 SetLength(BotNames
, Length(BotNames
)+1);
1225 BotNames
[High(BotNames
)] := s
;
1233 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1234 config
:= TConfig
.CreateFile(DataDir
+ BOTLIST_FILENAME
);
1238 while config
.SectionExists(IntToStr(a
)) do
1240 SetLength(BotList
, Length(BotList
)+1);
1242 with BotList
[High(BotList
)] do
1245 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1247 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1249 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1254 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1255 color
.R
:= StrToIntDef(sa
[0], 0);
1256 color
.G
:= StrToIntDef(sa
[1], 0);
1257 color
.B
:= StrToIntDef(sa
[2], 0);
1258 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1259 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1260 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1261 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1262 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1263 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1264 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1265 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1266 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1267 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1268 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1269 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1270 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1271 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1272 if Length(sa
) = 10 then
1274 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1275 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1276 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1277 if Length(sa
) = 10 then
1279 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1281 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1282 if Length(sa) = 10 then
1284 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1293 procedure g_Player_Free();
1297 if gPlayers
<> nil then
1299 for i
:= 0 to High(gPlayers
) do
1300 if gPlayers
[i
] <> nil then
1302 if gPlayers
[i
] is TPlayer
then
1303 TPlayer(gPlayers
[i
]).Free()
1305 TBot(gPlayers
[i
]).Free();
1316 procedure g_Player_UpdateAll();
1320 if gPlayers
= nil then Exit
;
1322 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1323 for i
:= 0 to High(gPlayers
) do
1325 if gPlayers
[i
] <> nil then
1327 if gPlayers
[i
] is TPlayer
then
1329 gPlayers
[i
].Update();
1330 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1334 // bot updates weapons in `UpdateCombat()`
1335 TBot(gPlayers
[i
]).Update();
1339 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1342 procedure g_Player_DrawAll();
1346 if gPlayers
= nil then Exit
;
1348 for i
:= 0 to High(gPlayers
) do
1349 if gPlayers
[i
] <> nil then
1350 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1351 else TBot(gPlayers
[i
]).Draw();
1354 procedure g_Player_DrawDebug(p
: TPlayer
);
1358 if p
= nil then Exit
;
1359 if (@p
.FObj
) = nil then Exit
;
1361 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1363 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1364 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1365 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1366 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1367 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1368 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1371 procedure g_Player_DrawHealth();
1376 if gPlayers
= nil then Exit
;
1377 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1379 for i
:= 0 to High(gPlayers
) do
1380 if gPlayers
[i
] <> nil then
1382 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1383 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1384 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1385 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1386 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1387 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1391 function g_Player_Get(UID
: Word): TPlayer
;
1397 if gPlayers
= nil then
1400 for a
:= 0 to High(gPlayers
) do
1401 if gPlayers
[a
] <> nil then
1402 if gPlayers
[a
].FUID
= UID
then
1404 Result
:= gPlayers
[a
];
1409 function g_Player_GetCount(): Byte;
1415 if gPlayers
= nil then
1418 for a
:= 0 to High(gPlayers
) do
1419 if gPlayers
[a
] <> nil then
1420 Result
:= Result
+ 1;
1423 function g_Player_GetStats(): TPlayerStatArray
;
1429 if gPlayers
= nil then Exit
;
1431 for a
:= 0 to High(gPlayers
) do
1432 if gPlayers
[a
] <> nil then
1434 SetLength(Result
, Length(Result
)+1);
1435 with Result
[High(Result
)] do
1437 Ping
:= gPlayers
[a
].FPing
;
1438 Loss
:= gPlayers
[a
].FLoss
;
1439 Name
:= gPlayers
[a
].FName
;
1440 Team
:= gPlayers
[a
].FTeam
;
1441 Frags
:= gPlayers
[a
].FFrags
;
1442 Deaths
:= gPlayers
[a
].FDeath
;
1443 Kills
:= gPlayers
[a
].FKills
;
1444 Color
:= gPlayers
[a
].FModel
.Color
;
1445 Lives
:= gPlayers
[a
].FLives
;
1446 Spectator
:= gPlayers
[a
].FSpectator
;
1451 procedure g_Player_RememberAll
;
1455 for i
:= Low(gPlayers
) to High(gPlayers
) do
1456 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1457 gPlayers
[i
].RememberState
;
1460 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1464 gTeamStat
[TEAM_RED
].Goals
:= 0;
1465 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1467 if gPlayers
<> nil then
1468 for i
:= 0 to High(gPlayers
) do
1469 if gPlayers
[i
] <> nil then
1471 gPlayers
[i
].Reset(Force
);
1473 if gPlayers
[i
] is TPlayer
then
1475 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1476 gPlayers
[i
].Respawn(Silent
)
1478 gPlayers
[i
].Spectate();
1481 TBot(gPlayers
[i
]).Respawn(Silent
);
1485 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1490 if Player
.alive
then
1492 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1497 if (FHealth
>= -50) or (gGibsCount
= 0) then
1499 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1503 for find_id
:= 0 to High(gCorpses
) do
1504 if gCorpses
[find_id
] = nil then
1511 find_id
:= Random(Length(gCorpses
));
1513 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1514 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1515 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1516 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1519 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1520 FObj
.Y
+ PLAYER_RECT_CY
,
1521 FModel
.Name
, FModel
.Color
);
1525 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1529 if (gShells
= nil) or (Length(gShells
) = 0) then
1532 with gShells
[CurrentShell
] do
1538 if T
= SHELL_BULLET
then
1540 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1544 Obj
.Rect
.Width
:= 4;
1545 Obj
.Rect
.Height
:= 2;
1549 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1553 Obj
.Rect
.Width
:= 7;
1554 Obj
.Rect
.Height
:= 3;
1560 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1561 positionChanged(); // this updates spatial accelerators
1562 RAngle
:= Random(360);
1563 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1565 if CurrentShell
>= High(gShells
) then
1572 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1575 GibsArray
: TGibsArray
;
1577 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1579 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1582 for a
:= 0 to High(GibsArray
) do
1583 with gGibs
[CurrentGib
] do
1586 ID
:= GibsArray
[a
].ID
;
1587 MaskID
:= GibsArray
[a
].MaskID
;
1590 Obj
.Rect
:= GibsArray
[a
].Rect
;
1591 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1592 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1593 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1594 positionChanged(); // this updates spatial accelerators
1595 RAngle
:= Random(360);
1597 if gBloodCount
> 0 then
1598 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1599 Random(48), Random(48), 150, 0, 0);
1601 if CurrentGib
>= High(gGibs
) then
1608 procedure g_Player_UpdatePhysicalObjects();
1614 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1619 if T
= SHELL_BULLET
then
1620 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1622 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1627 if gGibs
<> nil then
1628 for i
:= 0 to High(gGibs
) do
1629 if gGibs
[i
].alive
then
1633 mr
:= g_Obj_Move(@Obj
, True, False, True);
1634 positionChanged(); // this updates spatial accelerators
1636 if WordBool(mr
and MOVE_FALLOUT
) then
1642 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1643 if WordBool(mr
and MOVE_HITWALL
) then
1644 Obj
.Vel
.X
:= -(vel
.X
div 2);
1645 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1646 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1648 if (Obj
.Vel
.X
>= 0) then
1650 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1651 if RAngle
>= 360 then
1652 RAngle
:= RAngle
mod 360;
1653 end else begin // Counter-clockwise
1654 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1656 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1659 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1660 if gTime
mod (GAME_TICK
*3) = 0 then
1661 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1665 if gCorpses
<> nil then
1666 for i
:= 0 to High(gCorpses
) do
1667 if gCorpses
[i
] <> nil then
1668 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1674 gCorpses
[i
].Update();
1677 if gShells
<> nil then
1678 for i
:= 0 to High(gShells
) do
1679 if gShells
[i
].alive
then
1683 mr
:= g_Obj_Move(@Obj
, True, False, True);
1684 positionChanged(); // this updates spatial accelerators
1686 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1692 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1693 if WordBool(mr
and MOVE_HITWALL
) then
1695 Obj
.Vel
.X
:= -(vel
.X
div 2);
1696 if not WordBool(mr
and MOVE_INWATER
) then
1697 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1699 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1701 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1702 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1703 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1705 if RAngle
mod 90 <> 0 then
1706 RAngle
:= (RAngle
div 90) * 90;
1708 else if not WordBool(mr
and MOVE_INWATER
) then
1709 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1712 if (Obj
.Vel
.X
>= 0) then
1714 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1715 if RAngle
>= 360 then
1716 RAngle
:= RAngle
mod 360;
1717 end else begin // Counter-clockwise
1718 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1720 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1726 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1728 x
:= Obj
.X
+Obj
.Rect
.X
;
1729 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1730 w
:= Obj
.Rect
.Width
;
1731 h
:= Obj
.Rect
.Height
;
1734 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1736 if (dx
<> 0) or (dy
<> 0) then
1745 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1749 w
:= Obj
.Rect
.Width
;
1750 h
:= Obj
.Rect
.Height
;
1753 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1755 if (dx
<> 0) or (dy
<> 0) then
1764 procedure TGib
.positionChanged (); inline; begin end;
1765 procedure TShell
.positionChanged (); inline; begin end;
1768 procedure g_Player_DrawCorpses();
1773 if gGibs
<> nil then
1774 for i
:= 0 to High(gGibs
) do
1775 if gGibs
[i
].alive
then
1778 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1781 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1782 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1784 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1787 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1793 if gCorpses
<> nil then
1794 for i
:= 0 to High(gCorpses
) do
1795 if gCorpses
[i
] <> nil then
1799 procedure g_Player_DrawShells();
1804 if gShells
<> nil then
1805 for i
:= 0 to High(gShells
) do
1806 if gShells
[i
].alive
then
1809 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1815 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1819 procedure g_Player_RemoveAllCorpses();
1825 SetLength(gGibs
, MaxGibs
);
1826 SetLength(gShells
, MaxGibs
);
1830 if gCorpses
<> nil then
1831 for i
:= 0 to High(gCorpses
) do
1835 SetLength(gCorpses
, MaxCorpses
);
1838 procedure g_Player_Corpses_SaveState(var Mem
: TBinMemoryWriter
);
1843 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ:
1845 if gCorpses
<> nil then
1846 for i
:= 0 to High(gCorpses
) do
1847 if gCorpses
[i
] <> nil then
1850 Mem
:= TBinMemoryWriter
.Create((count
+1) * 128);
1852 // Êîëè÷åñòâî òðóïîâ:
1853 Mem
.WriteInt(count
);
1859 for i
:= 0 to High(gCorpses
) do
1860 if gCorpses
[i
] <> nil then
1863 Mem
.WriteString(gCorpses
[i
].FModelName
);
1865 b
:= gCorpses
[i
].Mess
;
1866 Mem
.WriteBoolean(b
);
1867 // Ñîõðàíÿåì äàííûå òðóïà:
1868 gCorpses
[i
].SaveState(Mem
);
1872 procedure g_Player_Corpses_LoadState(var Mem
: TBinMemoryReader
);
1881 g_Player_RemoveAllCorpses();
1883 // Êîëè÷åñòâî òðóïîâ:
1886 if count
> Length(gCorpses
) then
1888 raise EBinSizeError
.Create('g_Player_Corpses_LoadState: Too Many Corpses');
1895 for i
:= 0 to count
-1 do
1898 Mem
.ReadString(str
);
1902 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1903 // Çàãðóæàåì äàííûå òðóïà:
1904 gCorpses
[i
].LoadState(Mem
);
1910 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1912 procedure TPlayer
.BFGHit();
1914 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1915 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1916 if g_Game_IsServer
and g_Game_IsNet
then
1917 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1918 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1922 procedure TPlayer
.ChangeModel(ModelName
: string);
1924 locModel
: TPlayerModel
;
1926 locModel
:= g_PlayerModel_Get(ModelName
);
1927 if locModel
= nil then Exit
;
1933 procedure TPlayer
.SetModel(ModelName
: string);
1937 m
:= g_PlayerModel_Get(ModelName
);
1940 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1941 m
:= g_PlayerModel_Get('doomer');
1944 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1949 if FModel
<> nil then
1954 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1955 FModel
.Color
:= FColor
1957 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1958 FModel
.SetWeapon(FCurrWeap
);
1959 FModel
.SetFlag(FFlag
);
1960 SetDirection(FDirection
);
1963 procedure TPlayer
.SetColor(Color
: TRGB
);
1966 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1967 if FModel
<> nil then FModel
.Color
:= Color
;
1970 procedure TPlayer
.SwitchTeam
;
1972 if g_Game_IsClient
then
1974 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
1976 if gGameOn
and FAlive
then
1977 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
1979 if FTeam
= TEAM_RED
then
1981 ChangeTeam(TEAM_BLUE
);
1982 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
1983 if g_Game_IsNet
then
1984 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
1988 ChangeTeam(TEAM_RED
);
1989 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
1990 if g_Game_IsNet
then
1991 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
1993 FPreferredTeam
:= FTeam
;
1996 procedure TPlayer
.ChangeTeam(Team
: Byte);
2003 TEAM_RED
, TEAM_BLUE
:
2004 FModel
.Color
:= TEAMCOLOR
[Team
];
2006 FModel
.Color
:= FColor
;
2008 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2009 MH_SEND_PlayerStats(FUID
);
2013 procedure TPlayer.CollideItem();
2018 if gItems = nil then Exit;
2019 if not FAlive then Exit;
2021 for i := 0 to High(gItems) do
2024 if (ItemType <> ITEM_NONE) and alive then
2025 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2026 PLAYER_RECT.Height, @Obj) then
2028 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2030 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2031 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2032 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2033 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2034 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2036 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2037 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2038 (gGameSettings.GameType = GT_SINGLE) and
2039 (g_Player_GetCount() > 1)) then
2040 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2046 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2048 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2049 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2053 constructor TPlayer
.Create();
2064 FSawSound
:= TPlayableSound
.Create();
2065 FSawSoundIdle
:= TPlayableSound
.Create();
2066 FSawSoundHit
:= TPlayableSound
.Create();
2067 FSawSoundSelect
:= TPlayableSound
.Create();
2068 FJetSoundFly
:= TPlayableSound
.Create();
2069 FJetSoundOn
:= TPlayableSound
.Create();
2070 FJetSoundOff
:= TPlayableSound
.Create();
2072 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2073 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2074 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2075 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2076 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2077 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2078 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2080 FSpectatePlayer
:= -1;
2084 FSavedState
.WaitRecall
:= False;
2090 FActualModelName
:= 'doomer';
2093 FObj
.Rect
:= PLAYER_RECT
;
2095 FBFGFireCounter
:= -1;
2096 FJustTeleported
:= False;
2102 procedure TPlayer
.positionChanged (); inline;
2106 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2110 if (not g_Game_IsClient
) and (not FAlive
) then
2115 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2116 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2118 if not g_Game_IsClient
then
2121 if t
= HIT_TRAP
then
2123 // Ëîâóøêà óáèâàåò ñðàçó:
2125 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2127 if t
= HIT_SELF
then
2131 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2134 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2135 FMegaRulez
[MR_SUIT
] := 0;
2136 FMegaRulez
[MR_INVUL
] := 0;
2137 FMegaRulez
[MR_INVIS
] := 0;
2141 // Íî îò îñòàëüíîãî ñïàñàåò:
2142 if FMegaRulez
[MR_INVUL
] >= gTime
then
2149 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2150 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2151 (SpawnerUID
= FUID
) or
2152 (not SameTeam(FUID
, SpawnerUID
)) then
2154 FLastSpawnerUID
:= SpawnerUID
;
2156 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2157 if gBloodCount
> 0 then
2159 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2160 if value
div 4 <= c
then
2161 c
:= c
- (value
div 4)
2165 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2169 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2170 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2173 if t
= HIT_WATER
then
2174 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2175 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2180 Inc(FDamageBuffer
, value
);
2184 FPain
:= FPain
+ value
;
2187 if g_Game_IsServer
and g_Game_IsNet
then
2189 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2190 MH_SEND_PlayerStats(FUID
);
2191 MH_SEND_PlayerPos(False, FUID
);
2195 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2198 if g_Game_IsClient
then
2203 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2205 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2208 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2210 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2214 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2215 MH_SEND_PlayerStats(FUID
);
2218 destructor TPlayer
.Destroy();
2220 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2222 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2226 FSawSoundIdle
.Free();
2227 FSawSoundHit
.Free();
2228 FJetSoundFly
.Free();
2230 FJetSoundOff
.Free();
2236 procedure TPlayer
.DrawBubble();
2238 bubX
, bubY
: Integer;
2241 Rw
, Gw
, Bw
: SmallInt;
2244 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= D_LEFT
, -4, 18);
2245 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2253 1: // simple textual non-bubble
2255 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2256 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2257 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2260 2: // advanced pixel-perfect bubble
2262 if FTeam
= TEAM_RED
then
2265 if FTeam
= TEAM_BLUE
then
2268 3: // colored bubble
2270 Rb
:= FModel
.Color
.R
;
2271 Gb
:= FModel
.Color
.G
;
2272 Bb
:= FModel
.Color
.B
;
2273 Rw
:= Min(Rb
* 2 + 64, 255);
2274 Gw
:= Min(Gb
* 2 + 64, 255);
2275 Bw
:= Min(Bb
* 2 + 64, 255);
2276 if (Abs(Rw
- Rb
) < 32)
2277 or (Abs(Gw
- Gb
) < 32)
2278 or (Abs(Bw
- Bb
) < 32) then
2280 Rb
:= Max(Rw
div 2 - 16, 0);
2281 Gb
:= Max(Gw
div 2 - 16, 0);
2282 Bb
:= Max(Bw
div 2 - 16, 0);
2285 4: // custom textured bubble
2287 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2288 if FDirection
= D_RIGHT
then
2289 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2291 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, M_HORIZONTAL
);
2297 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2298 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2300 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2303 Dot
:= IfThen(FDirection
= D_LEFT
, 14, 5);
2304 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2305 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
);
2306 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
);
2307 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
);
2308 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
);
2312 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2313 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2314 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2317 procedure TPlayer
.Draw();
2325 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2326 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2328 e_GetTextureSize(ID
, @w
, @h
);
2329 if FDirection
= D_LEFT
then
2330 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2331 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False)
2333 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2334 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False);
2337 if FMegaRulez
[MR_INVIS
] > gTime
then
2339 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2340 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2342 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2343 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2347 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 200)
2349 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2352 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 254);
2355 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2358 if g_debug_Frames
then
2360 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2362 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2363 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2367 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2369 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2370 if gAimLine
and alive
and
2371 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2376 procedure TPlayer
.DrawAim();
2377 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2381 if isValidViewPort
and (self
= gPlayer1
) then
2383 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2386 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2387 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2389 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2393 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2398 wx
, wy
, xx
, yy
: Integer;
2402 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= D_LEFT
, 7, -7);
2403 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2412 1: begin // Chainsaw
2419 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2420 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2421 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2422 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2427 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2428 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2429 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2430 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2432 4: begin // Double Shotgun
2435 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2436 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2437 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2438 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2440 5: begin // Chaingun
2443 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2444 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2445 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2446 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2448 6: begin // Rocket Launcher
2451 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2452 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2453 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2454 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2456 7: begin // Plasmagun
2459 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2460 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2461 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2462 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2467 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2468 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2469 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2470 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2472 9: begin // Super Chaingun
2475 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2476 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2477 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2478 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2481 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2482 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2483 {$IF DEFINED(D2F_DEBUG)}
2484 drawCast(sz
, wx
, wy
, xx
, yy
);
2486 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2490 procedure TPlayer
.DrawGUI();
2493 X
, Y
, SY
, a
, p
, m
: Integer;
2497 stat
: TPlayerStatArray
;
2499 X
:= gPlayerScreenSize
.X
;
2500 SY
:= gPlayerScreenSize
.Y
;
2503 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2505 if gGameSettings
.GameMode
= GM_CTF
then
2509 if gGameSettings
.GameMode
= GM_CTF
then
2511 s
:= 'TEXTURE_PLAYER_REDFLAG';
2512 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2513 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2514 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2515 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2516 if g_Texture_Get(s
, ID
) then
2517 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2520 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2521 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2522 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2524 if gGameSettings
.GameMode
= GM_CTF
then
2526 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2527 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2528 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2529 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2530 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2531 if g_Texture_Get(s
, ID
) then
2532 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2535 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2536 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2537 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2540 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2541 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2544 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2545 e_Draw(ID
, X
+2, Y
, 0, True, False);
2547 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2551 s
:= IntToStr(Frags
);
2552 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2553 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2558 stat
:= g_Player_GetStats();
2563 for a
:= 0 to High(stat
) do
2564 if stat
[a
].Name
<> Name
then
2566 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2567 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2571 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2572 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2573 s
:= s
+IntToStr(Abs(Frags
-m
));
2575 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2576 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2579 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2581 s
:= IntToStr(Lives
);
2582 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2583 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2587 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2588 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2590 if R_BERSERK
in FRulez
then
2591 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2593 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2595 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2596 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2598 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2599 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2600 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2602 s
:= IntToStr(FArmor
);
2603 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2604 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2606 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2612 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2617 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2619 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2620 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2621 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2622 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2623 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2624 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2625 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2626 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2627 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2630 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2631 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2632 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2634 if R_KEY_RED
in FRulez
then
2635 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2637 if R_KEY_GREEN
in FRulez
then
2638 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2640 if R_KEY_BLUE
in FRulez
then
2641 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2643 if FJetFuel
> 0 then
2645 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2646 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2647 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2648 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2649 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2650 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2654 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2655 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2656 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2659 if gShowPing
and g_Game_IsClient
then
2661 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2662 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2668 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2669 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2670 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2673 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2674 s
:= _lc
[I_PLAYER_SPECT4
];
2675 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2676 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2677 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2683 procedure TPlayer
.DrawRulez();
2687 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2688 if FMegaRulez
[MR_INVUL
] >= gTime
then
2690 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2691 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2696 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2697 191, 191, 191, 0, B_INVERT
);
2700 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2701 if FMegaRulez
[MR_SUIT
] >= gTime
then
2703 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2704 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2709 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2710 0, 96, 0, 200, B_NONE
);
2713 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2714 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2716 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2717 255, 0, 0, 200, B_NONE
);
2721 procedure TPlayer
.DrawPain();
2725 if FPain
= 0 then Exit
;
2729 if a
< 15 then h
:= 0
2730 else if a
< 35 then h
:= 1
2731 else if a
< 55 then h
:= 2
2732 else if a
< 75 then h
:= 3
2733 else if a
< 95 then h
:= 4
2736 //if a > 255 then a := 255;
2738 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2739 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2742 procedure TPlayer
.DrawPickup();
2746 if FPickup
= 0 then Exit
;
2750 if a
< 15 then h
:= 1
2751 else if a
< 35 then h
:= 2
2752 else if a
< 55 then h
:= 3
2753 else if a
< 75 then h
:= 4
2756 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2759 procedure TPlayer
.Fire();
2761 f
, DidFire
: Boolean;
2762 wx
, wy
, xd
, yd
: Integer;
2765 if g_Game_IsClient
then Exit
;
2766 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2767 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2775 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2780 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2781 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2782 xd
:= wx
+IfThen(FDirection
= D_LEFT
, -30, 30);
2783 yd
:= wy
+firediry();
2788 if R_BERSERK
in FRulez
then
2790 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2791 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2792 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2795 locobj
.rect
.Width
:= 39;
2796 locobj
.rect
.Height
:= 52;
2797 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2798 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2799 locobj
.Accel
.X
:= xd
-wx
;
2800 locobj
.Accel
.y
:= yd
-wy
;
2802 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2803 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2805 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2809 FPain
:= min(FPain
+ 25, 50);
2810 end else g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2813 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2818 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2819 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2821 FSawSoundSelect
.Stop();
2823 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2825 else if not FSawSoundHit
.IsPlaying() then
2827 FSawSoundSelect
.Stop();
2828 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2831 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2837 if FAmmo
[A_BULLETS
] > 0 then
2839 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2840 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2841 Dec(FAmmo
[A_BULLETS
]);
2842 FFireAngle
:= FAngle
;
2845 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2846 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2850 if FAmmo
[A_SHELLS
] > 0 then
2852 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2853 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
2854 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2855 Dec(FAmmo
[A_SHELLS
]);
2856 FFireAngle
:= FAngle
;
2860 FShellType
:= SHELL_SHELL
;
2864 if FAmmo
[A_SHELLS
] >= 2 then
2866 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
2867 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2868 Dec(FAmmo
[A_SHELLS
], 2);
2869 FFireAngle
:= FAngle
;
2873 FShellType
:= SHELL_DBLSHELL
;
2877 if FAmmo
[A_BULLETS
] > 0 then
2879 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
2880 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
2881 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2882 Dec(FAmmo
[A_BULLETS
]);
2883 FFireAngle
:= FAngle
;
2886 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2887 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2890 WEAPON_ROCKETLAUNCHER
:
2891 if FAmmo
[A_ROCKETS
] > 0 then
2893 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
2894 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2895 Dec(FAmmo
[A_ROCKETS
]);
2896 FFireAngle
:= FAngle
;
2902 if FAmmo
[A_CELLS
] > 0 then
2904 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
2905 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2906 Dec(FAmmo
[A_CELLS
]);
2907 FFireAngle
:= FAngle
;
2913 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
2915 FBFGFireCounter
:= 17;
2916 if not FNoReload
then
2917 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
2918 Dec(FAmmo
[A_CELLS
], 40);
2922 WEAPON_SUPERPULEMET
:
2923 if FAmmo
[A_SHELLS
] > 0 then
2925 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2926 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
2927 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2928 Dec(FAmmo
[A_SHELLS
]);
2929 FFireAngle
:= FAngle
;
2932 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2933 GameVelX
, GameVelY
-2, SHELL_SHELL
);
2936 WEAPON_FLAMETHROWER
:
2937 if FAmmo
[A_FUEL
] > 0 then
2939 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
2940 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2942 FFireAngle
:= FAngle
;
2948 if g_Game_IsNet
then
2952 if FCurrWeap
<> WEAPON_BFG
then
2953 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
2955 if not FNoReload
then
2956 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
2959 MH_SEND_PlayerStats(FUID
);
2964 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
2965 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
2966 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
2969 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
2972 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
2973 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
2974 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
2975 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
2976 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
2981 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
2983 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
2984 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
2985 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
2988 procedure TPlayer
.JetpackOn
;
2992 FJetSoundOn
.SetPosition(0);
2993 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
2997 procedure TPlayer
.JetpackOff
;
3001 FJetSoundOff
.SetPosition(0);
3002 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3005 procedure TPlayer
.CatchFire(Attacker
: Word);
3008 FFireAttacker
:= Attacker
;
3009 if g_Game_IsNet
and g_Game_IsServer
then
3010 MH_SEND_PlayerStats(FUID
);
3013 procedure TPlayer
.Jump();
3015 if gFly
or FJetpack
then
3017 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3018 if FObj
.Vel
.Y
> -VEL_FLY
then
3019 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3022 if FJetFuel
> 0 then
3024 if (FJetFuel
< 1) and g_Game_IsServer
then
3028 if g_Game_IsNet
then
3029 MH_SEND_PlayerStats(FUID
);
3035 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3037 FCanJetpack
:= False;
3039 // Ïðûãàåì èëè âñïëûâàåì:
3040 if (CollideLevel(0, 1) or
3041 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3042 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3043 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3045 FObj
.Vel
.Y
:= -VEL_JUMP
;
3046 FCanJetpack
:= False;
3050 if BodyInLiquid(0, 0) then
3051 FObj
.Vel
.Y
:= -VEL_SW
3052 else if (FJetFuel
> 0) and FCanJetpack
and
3053 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3057 if g_Game_IsNet
then
3058 MH_SEND_PlayerStats(FUID
);
3063 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3065 a
, i
, k
, ab
, ar
: Byte;
3069 srv
, netsrv
: Boolean;
3075 procedure PushItem(t
: Byte);
3079 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3080 it
:= g_Items_ByIdx(id
);
3081 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3083 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3084 (FObj
.Vel
.Y
div 2)-Random(9));
3085 it
.positionChanged(); // this updates spatial accelerators
3089 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3091 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3092 (FObj
.Vel
.Y
div 2)-Random(6));
3094 else // -3..+3; -3..0
3096 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3097 (FObj
.Vel
.Y
div 2)-Random(4));
3099 it
.positionChanged(); // this updates spatial accelerators
3102 if g_Game_IsNet
and g_Game_IsServer
then
3103 MH_SEND_ItemSpawn(True, id
);
3107 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3108 Srv
:= g_Game_IsServer
;
3109 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3110 if Srv
then FDeath
:= FDeath
+ 1;
3115 if not FPhysics
then
3121 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3123 if FLives
> 0 then FLives
:= FLives
- 1;
3124 if FLives
= 0 then FNoRespawn
:= True;
3127 // Íîìåð òèïà ñìåðòè:
3130 K_SIMPLEKILL
: a
:= 1;
3132 K_EXTRAHARDKILL
: a
:= 3;
3137 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3139 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3146 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3148 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3149 K_EXTRAHARDKILL
, K_FALLKILL
:
3150 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3153 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3157 K_HARDKILL
, K_EXTRAHARDKILL
:
3161 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3162 if (KillType
<> K_FALLKILL
) and (Srv
) then
3163 g_Monsters_killedp();
3165 if SpawnerUID
= FUID
then
3167 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3172 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3175 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3176 begin // Óáèò äðóãèì èãðîêîì
3177 KP
:= g_Player_Get(SpawnerUID
);
3178 if (KP
<> nil) and Srv
then
3180 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3181 if SameTeam(FUID
, SpawnerUID
) then
3191 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3192 Inc(gTeamStat
[KP
.Team
].Goals
,
3193 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3195 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3198 plr
:= g_Player_Get(SpawnerUID
);
3206 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3210 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3214 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3219 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3220 begin // Óáèò ìîíñòðîì
3221 mon
:= g_Monsters_ByUID(SpawnerUID
);
3225 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
3229 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3233 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3237 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3242 else // Îñîáûå òèïû ñìåðòè
3245 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3246 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3247 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3248 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3249 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3250 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3256 for a
:= WP_FIRST
to WP_LAST
do
3260 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3261 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3262 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3263 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3264 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3265 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3266 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3267 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3268 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3277 if R_ITEM_BACKPACK
in FRulez
then
3278 PushItem(ITEM_AMMO_BACKPACK
);
3280 // Âûáðîñ ðàêåòíîãî ðàíöà:
3281 if FJetFuel
> 0 then
3282 PushItem(ITEM_JETPACK
);
3285 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3287 if R_KEY_RED
in FRulez
then
3288 PushItem(ITEM_KEY_RED
);
3290 if R_KEY_GREEN
in FRulez
then
3291 PushItem(ITEM_KEY_GREEN
);
3293 if R_KEY_BLUE
in FRulez
then
3294 PushItem(ITEM_KEY_BLUE
);
3301 g_Player_CreateCorpse(Self
);
3303 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3304 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3310 for i
:= Low(gPlayers
) to High(gPlayers
) do
3312 if gPlayers
[i
] = nil then continue
;
3313 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3316 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3317 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3322 OldLR
:= gLMSRespawn
;
3323 if (gGameSettings
.GameMode
= GM_COOP
) then
3327 // everyone is dead, restart the map
3328 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3330 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3331 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3332 gLMSRespawnTime
:= gTime
+ 5000;
3334 else if (a
= 1) then
3336 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3337 if (gPlayers
[k
] = gPlayer1
) or
3338 (gPlayers
[k
] = gPlayer2
) then
3339 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3340 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3341 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3344 else if (gGameSettings
.GameMode
= GM_TDM
) then
3346 if (ab
= 0) and (ar
<> 0) then
3349 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3351 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3352 Inc(gTeamStat
[TEAM_RED
].Goals
);
3353 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3354 gLMSRespawnTime
:= gTime
+ 5000;
3356 else if (ar
= 0) and (ab
<> 0) then
3359 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3361 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3362 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3363 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3364 gLMSRespawnTime
:= gTime
+ 5000;
3366 else if (ar
= 0) and (ab
= 0) then
3369 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3371 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3372 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3373 gLMSRespawnTime
:= gTime
+ 5000;
3376 else if (gGameSettings
.GameMode
= GM_DM
) then
3380 if gPlayers
[k
] <> nil then
3383 // survivor is the winner
3384 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3386 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3389 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3390 gLMSRespawnTime
:= gTime
+ 5000;
3392 else if (a
= 0) then
3394 // everyone is dead, restart the map
3395 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3397 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3398 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3399 gLMSRespawnTime
:= gTime
+ 5000;
3402 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3404 if NetMode
= NET_SERVER
then
3405 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3407 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3413 MH_SEND_PlayerStats(FUID
);
3414 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3415 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3418 if srv
and FNoRespawn
then Spectate(True);
3419 FWantsInGame
:= True;
3422 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3424 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3425 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3428 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3430 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3431 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3434 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3436 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3437 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3438 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3440 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3441 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3442 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3446 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3448 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3449 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3450 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3454 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3456 if g_Game_IsClient
then Exit
;
3457 if Weapon
> High(FWeapon
) then Exit
;
3458 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3461 procedure TPlayer
.resetWeaponQueue ();
3464 FNextWeapDelay
:= 0;
3467 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3471 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3472 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 0);
3473 WEAPON_PISTOL
, WEAPON_CHAINGUN
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_BULLETS
] > 0);
3474 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3475 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3476 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3477 else result
:= (weapon
< length(FWeapon
));
3481 // return 255 for "no switch"
3482 function TPlayer
.getNextWeaponIndex (): Byte;
3485 wantThisWeapon
: array[0..64] of Boolean;
3486 wwc
: Integer = 0; //HACK!
3489 result
:= 255; // default result: "no switch"
3490 // had weapon cycling on previous frame? remove that flag
3491 if (FNextWeap
and $2000) <> 0 then
3493 FNextWeap
:= FNextWeap
and $1FFF;
3494 FNextWeapDelay
:= 0;
3496 // cycling has priority
3497 if (FNextWeap
and $C000) <> 0 then
3499 if (FNextWeap
and $8000) <> 0 then
3503 FNextWeap
:= FNextWeap
or $2000; // we need this
3504 if FNextWeapDelay
> 0 then
3505 exit
; // cooldown time
3507 for i
:= 0 to High(FWeapon
) do
3509 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3510 if FWeapon
[cwi
] then
3512 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d', [FCurrWeap, cwi]), MSG_WARNING);
3513 result
:= Byte(cwi
);
3514 FNextWeapDelay
:= 10;
3522 for i
:= 0 to High(wantThisWeapon
) do
3523 wantThisWeapon
[i
] := false;
3524 for i
:= 0 to High(FWeapon
) do
3525 if (FNextWeap
and (1 shl i
)) <> 0 then
3527 wantThisWeapon
[i
] := true;
3530 // exclude currently selected weapon from the set
3531 wantThisWeapon
[FCurrWeap
] := false;
3532 // slow down alterations a little
3535 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3536 // more than one weapon requested, assume "alteration" and check alteration delay
3537 if FNextWeapDelay
> 0 then
3543 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3544 // but clear all counters if no weapon should be switched
3550 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3551 // try weapons in descending order
3552 for i
:= High(FWeapon
) downto 0 do
3554 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3559 FNextWeapDelay
:= 10; // anyway, 'cause why not
3563 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3567 procedure TPlayer
.RealizeCurrentWeapon();
3568 function switchAllowed (): Boolean;
3573 if FBFGFireCounter
<> -1 then
3575 if FTime
[T_SWITCH
] > gTime
then
3577 for i
:= WP_FIRST
to WP_LAST
do
3578 if FReloading
[i
] > 0 then
3586 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3587 //FNextWeap := FNextWeap and $1FFF;
3588 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3590 if not switchAllowed
then
3592 //HACK for weapon cycling
3593 if (FNextWeap
and $7000) <> 0 then FNextWeap
:= 0;
3597 nw
:= getNextWeaponIndex();
3598 if nw
= 255 then exit
; // don't reset anything here
3599 if nw
> High(FWeapon
) then
3601 // don't forget to reset queue here!
3602 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3610 FTime
[T_SWITCH
] := gTime
+156;
3611 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3612 FModel
.SetWeapon(FCurrWeap
);
3613 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3617 procedure TPlayer
.NextWeapon();
3619 if g_Game_IsClient
then Exit
;
3623 procedure TPlayer
.PrevWeapon();
3625 if g_Game_IsClient
then Exit
;
3629 procedure TPlayer
.SetWeapon(W
: Byte);
3631 if FCurrWeap
<> W
then
3632 if W
= WEAPON_SAW
then
3633 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3636 FModel
.SetWeapon(CurrWeap
);
3640 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3645 if g_Game_IsClient
then Exit
;
3647 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3648 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3653 if FHealth
< PLAYER_HP_SOFT
then
3655 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3659 if gFlash
= 2 then Inc(FPickup
, 5);
3663 if FHealth
< PLAYER_HP_SOFT
then
3665 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3669 if gFlash
= 2 then Inc(FPickup
, 5);
3673 if FArmor
< PLAYER_AP_SOFT
then
3675 FArmor
:= PLAYER_AP_SOFT
;
3678 if gFlash
= 2 then Inc(FPickup
, 5);
3682 if FArmor
< PLAYER_AP_LIMIT
then
3684 FArmor
:= PLAYER_AP_LIMIT
;
3687 if gFlash
= 2 then Inc(FPickup
, 5);
3691 if FHealth
< PLAYER_HP_LIMIT
then
3693 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3697 if gFlash
= 2 then Inc(FPickup
, 5);
3701 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3703 if FHealth
< PLAYER_HP_LIMIT
then
3704 FHealth
:= PLAYER_HP_LIMIT
;
3705 if FArmor
< PLAYER_AP_LIMIT
then
3706 FArmor
:= PLAYER_AP_LIMIT
;
3710 if gFlash
= 2 then Inc(FPickup
, 5);
3714 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3716 FWeapon
[WEAPON_SAW
] := True;
3718 if gFlash
= 2 then Inc(FPickup
, 5);
3719 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3722 ITEM_WEAPON_SHOTGUN1
:
3723 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3725 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3726 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3728 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3729 FWeapon
[WEAPON_SHOTGUN1
] := True;
3731 if gFlash
= 2 then Inc(FPickup
, 5);
3732 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3735 ITEM_WEAPON_SHOTGUN2
:
3736 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3738 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3740 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3741 FWeapon
[WEAPON_SHOTGUN2
] := True;
3743 if gFlash
= 2 then Inc(FPickup
, 5);
3744 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3747 ITEM_WEAPON_CHAINGUN
:
3748 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3750 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3752 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3753 FWeapon
[WEAPON_CHAINGUN
] := True;
3755 if gFlash
= 2 then Inc(FPickup
, 5);
3756 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3759 ITEM_WEAPON_ROCKETLAUNCHER
:
3760 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3762 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3764 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3765 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3767 if gFlash
= 2 then Inc(FPickup
, 5);
3768 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3772 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3774 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3776 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3777 FWeapon
[WEAPON_PLASMA
] := True;
3779 if gFlash
= 2 then Inc(FPickup
, 5);
3780 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3784 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3786 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3788 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3789 FWeapon
[WEAPON_BFG
] := True;
3791 if gFlash
= 2 then Inc(FPickup
, 5);
3792 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3795 ITEM_WEAPON_SUPERPULEMET
:
3796 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3798 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3800 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3801 FWeapon
[WEAPON_SUPERPULEMET
] := True;
3803 if gFlash
= 2 then Inc(FPickup
, 5);
3804 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3807 ITEM_WEAPON_FLAMETHROWER
:
3808 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
3810 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
3812 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3813 FWeapon
[WEAPON_FLAMETHROWER
] := True;
3815 if gFlash
= 2 then Inc(FPickup
, 5);
3816 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3820 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3822 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3825 if gFlash
= 2 then Inc(FPickup
, 5);
3828 ITEM_AMMO_BULLETS_BOX
:
3829 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3831 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3834 if gFlash
= 2 then Inc(FPickup
, 5);
3838 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3840 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3843 if gFlash
= 2 then Inc(FPickup
, 5);
3846 ITEM_AMMO_SHELLS_BOX
:
3847 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3849 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
3852 if gFlash
= 2 then Inc(FPickup
, 5);
3856 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3858 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3861 if gFlash
= 2 then Inc(FPickup
, 5);
3864 ITEM_AMMO_ROCKET_BOX
:
3865 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3867 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
3870 if gFlash
= 2 then Inc(FPickup
, 5);
3874 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3876 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3879 if gFlash
= 2 then Inc(FPickup
, 5);
3883 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3885 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
3888 if gFlash
= 2 then Inc(FPickup
, 5);
3892 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
3894 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3897 if gFlash
= 2 then Inc(FPickup
, 5);
3901 if not(R_ITEM_BACKPACK
in FRulez
) or
3902 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
3903 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
3904 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
3905 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
3906 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
3908 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
3909 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
3910 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
3911 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
3912 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
3914 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3915 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3916 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3917 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3918 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3919 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3920 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3921 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3923 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
3926 if gFlash
= 2 then Inc(FPickup
, 5);
3930 if not(R_KEY_RED
in FRulez
) then
3932 Include(FRulez
, R_KEY_RED
);
3934 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3935 if gFlash
= 2 then Inc(FPickup
, 5);
3936 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3940 if not(R_KEY_GREEN
in FRulez
) then
3942 Include(FRulez
, R_KEY_GREEN
);
3944 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3945 if gFlash
= 2 then Inc(FPickup
, 5);
3946 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3950 if not(R_KEY_BLUE
in FRulez
) then
3952 Include(FRulez
, R_KEY_BLUE
);
3954 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3955 if gFlash
= 2 then Inc(FPickup
, 5);
3956 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3960 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
3962 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
3966 if gFlash
= 2 then Inc(FPickup
, 5);
3970 if FAir
< AIR_MAX
then
3975 if gFlash
= 2 then Inc(FPickup
, 5);
3980 if not (R_BERSERK
in FRulez
) then
3982 Include(FRulez
, R_BERSERK
);
3983 if FBFGFireCounter
= -1 then
3985 FCurrWeap
:= WEAPON_KASTET
;
3987 FModel
.SetWeapon(WEAPON_KASTET
);
3991 if gFlash
= 2 then Inc(FPickup
, 5);
3992 FBerserk
:= gTime
+30000;
3997 if FHealth
< PLAYER_HP_SOFT
then
3999 FHealth
:= PLAYER_HP_SOFT
;
4000 FBerserk
:= gTime
+30000;
4008 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4010 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4013 if gFlash
= 2 then Inc(FPickup
, 5);
4017 if FHealth
< PLAYER_HP_LIMIT
then
4019 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4023 if gFlash
= 2 then Inc(FPickup
, 5);
4027 if FArmor
< PLAYER_AP_LIMIT
then
4029 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4032 if gFlash
= 2 then Inc(FPickup
, 5);
4036 if FJetFuel
< JET_MAX
then
4038 FJetFuel
:= JET_MAX
;
4041 if gFlash
= 2 then Inc(FPickup
, 5);
4045 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4047 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4050 if gFlash
= 2 then Inc(FPickup
, 5);
4055 procedure TPlayer
.Touch();
4059 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4062 // Áðîñèòü ôëàã òîâàðèùó:
4063 if gGameSettings
.GameMode
= GM_CTF
then
4068 procedure TPlayer
.Push(vx
, vy
: Integer);
4070 if (not FPhysics
) and FGhost
then
4072 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4073 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4074 if g_Game_IsNet
and g_Game_IsServer
then
4075 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4078 procedure TPlayer
.Reset(Force
: Boolean);
4084 FTime
[T_RESPAWN
] := 0;
4085 FTime
[T_FLAGCAP
] := 0;
4098 FSpectator
:= False;
4101 FSpectatePlayer
:= -1;
4102 FNoRespawn
:= False;
4104 FLives
:= gGameSettings
.MaxLives
;
4109 procedure TPlayer
.SoftReset();
4115 FBFGFireCounter
:= -1;
4123 SetAction(A_STAND
, True);
4126 function TPlayer
.GetRespawnPoint(): Byte;
4131 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4133 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4134 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4136 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4138 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4139 if Self
= gPlayer1
then
4140 c
:= RESPAWNPOINT_PLAYER1
4142 c
:= RESPAWNPOINT_PLAYER2
;
4143 if g_Map_GetPointCount(c
) > 0 then
4149 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4150 if Self
= gPlayer1
then
4151 c
:= RESPAWNPOINT_PLAYER2
4153 c
:= RESPAWNPOINT_PLAYER1
;
4154 if g_Map_GetPointCount(c
) > 0 then
4161 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4162 if Random(2) = 0 then
4163 c
:= RESPAWNPOINT_PLAYER1
4165 c
:= RESPAWNPOINT_PLAYER2
;
4166 if g_Map_GetPointCount(c
) > 0 then
4173 // Òî÷êà ëþáîé èç êîìàíä
4174 if Random(2) = 0 then
4175 c
:= RESPAWNPOINT_RED
4177 c
:= RESPAWNPOINT_BLUE
;
4178 if g_Map_GetPointCount(c
) > 0 then
4185 c
:= RESPAWNPOINT_DM
;
4186 if g_Map_GetPointCount(c
) > 0 then
4194 if gGameSettings
.GameMode
= GM_DM
then
4197 c
:= RESPAWNPOINT_DM
;
4198 if g_Map_GetPointCount(c
) > 0 then
4204 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4205 if Random(2) = 0 then
4206 c
:= RESPAWNPOINT_PLAYER1
4208 c
:= RESPAWNPOINT_PLAYER2
;
4209 if g_Map_GetPointCount(c
) > 0 then
4215 // Òî÷êà ëþáîé èç êîìàíä
4216 if Random(2) = 0 then
4217 c
:= RESPAWNPOINT_RED
4219 c
:= RESPAWNPOINT_BLUE
;
4220 if g_Map_GetPointCount(c
) > 0 then
4228 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4230 // Òî÷êà ñâîåé êîìàíäû
4231 c
:= RESPAWNPOINT_DM
;
4232 if FTeam
= TEAM_RED
then
4233 c
:= RESPAWNPOINT_RED
;
4234 if FTeam
= TEAM_BLUE
then
4235 c
:= RESPAWNPOINT_BLUE
;
4236 if g_Map_GetPointCount(c
) > 0 then
4243 c
:= RESPAWNPOINT_DM
;
4244 if g_Map_GetPointCount(c
) > 0 then
4250 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4251 if Random(2) = 0 then
4252 c
:= RESPAWNPOINT_PLAYER1
4254 c
:= RESPAWNPOINT_PLAYER2
;
4255 if g_Map_GetPointCount(c
) > 0 then
4261 // Òî÷êà äðóãîé êîìàíäû
4262 c
:= RESPAWNPOINT_DM
;
4263 if FTeam
= TEAM_RED
then
4264 c
:= RESPAWNPOINT_BLUE
;
4265 if FTeam
= TEAM_BLUE
then
4266 c
:= RESPAWNPOINT_RED
;
4267 if g_Map_GetPointCount(c
) > 0 then
4275 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4277 RespawnPoint
: TRespawnPoint
;
4282 if not g_Game_IsServer
then
4286 FWantsInGame
:= True;
4287 FJustTeleported
:= True;
4290 FTime
[T_RESPAWN
] := 0;
4294 // if server changes MaxLives we gotta be ready
4295 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4297 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4298 if FTime
[T_RESPAWN
] > gTime
then
4301 // Ïðîñðàë âñå æèçíè:
4304 if not FSpectator
then Spectate(True);
4305 FWantsInGame
:= True;
4309 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4310 begin // "Ñâîÿ èãðà"
4311 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4312 FRulez
:= FRulez
-[R_BERSERK
];
4314 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4316 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4317 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4320 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4321 c
:= GetRespawnPoint();
4326 // Âîñêðåøåíèå áåç îðóæèÿ:
4329 FHealth
:= PLAYER_HP_SOFT
;
4335 for a
:= WP_FIRST
to WP_LAST
do
4337 FWeapon
[a
] := False;
4341 FWeapon
[WEAPON_PISTOL
] := True;
4342 FWeapon
[WEAPON_KASTET
] := True;
4343 FCurrWeap
:= WEAPON_PISTOL
;
4346 FModel
.SetWeapon(FCurrWeap
);
4348 for b
:= A_BULLETS
to A_HIGH
do
4351 FAmmo
[A_BULLETS
] := 50;
4353 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4354 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4355 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4356 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4357 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4359 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4360 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4365 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4366 if not g_Map_GetPoint(c
, RespawnPoint
) then
4368 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4372 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4373 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4374 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4380 FDirection
:= RespawnPoint
.Direction
;
4381 if FDirection
= D_LEFT
then
4387 FBFGFireCounter
:= -1;
4392 SetAction(A_STAND
, True);
4393 FModel
.Direction
:= FDirection
;
4395 for a
:= Low(FTime
) to High(FTime
) do
4398 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4403 FCanJetpack
:= False;
4408 // Àíèìàöèÿ âîçðîæäåíèÿ:
4409 if (not gLoadGameMode
) and (not Silent
) then
4410 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4412 Anim
:= TAnimation
.Create(ID
, False, 3);
4413 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4414 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4418 FSpectator
:= False;
4421 FSpectatePlayer
:= -1;
4424 if g_Game_IsNet
then
4426 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4427 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4429 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4430 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4435 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4438 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4439 else if (not NoMove
) then
4441 GameX
:= gMapInfo
.Width
div 2;
4442 GameY
:= gMapInfo
.Height
div 2;
4451 FWantsInGame
:= False;
4456 if Self
= gPlayer1
then
4461 if Self
= gPlayer2
then
4468 if g_Game_IsNet
then
4469 MH_SEND_PlayerStats(FUID
);
4472 procedure TPlayer
.SwitchNoClip
;
4476 FGhost
:= not FGhost
;
4477 FPhysics
:= not FGhost
;
4489 procedure TPlayer
.Run(Direction
: TDirection
);
4493 if MAX_RUNVEL
> 8 then
4497 if Direction
= D_LEFT
then
4499 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4500 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4503 if FObj
.Vel
.X
< MAX_RUNVEL
then
4504 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4506 // Âîçìîæíî, ïèíàåì êóñêè:
4507 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4509 b
:= Abs(FObj
.Vel
.X
);
4510 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4511 for a
:= 0 to High(gGibs
) do
4513 if gGibs
[a
].alive
and
4514 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4515 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4518 if FObj
.Vel
.X
< 0 then
4520 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4524 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4526 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4534 procedure TPlayer
.SeeDown();
4536 SetAction(A_SEEDOWN
);
4538 if FDirection
= D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4540 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4543 procedure TPlayer
.SeeUp();
4547 if FDirection
= D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4549 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4552 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4560 A_ATTACK
: Prior
:= 2;
4561 A_SEEUP
: Prior
:= 1;
4562 A_SEEDOWN
: Prior
:= 1;
4563 A_ATTACKUP
: Prior
:= 2;
4564 A_ATTACKDOWN
: Prior
:= 2;
4569 if (Prior
> FActionPrior
) or Force
then
4570 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4572 FActionPrior
:= Prior
;
4573 FActionAnim
:= Action
;
4574 FActionForce
:= Force
;
4575 FActionChanged
:= True;
4578 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4581 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4583 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4584 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4585 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4586 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4589 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4596 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4598 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4599 if g_Game_IsServer
and g_Game_IsNet
then
4600 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4604 FJustTeleported
:= True;
4609 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4611 Anim
:= TAnimation
.Create(ID
, False, 3);
4614 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4615 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4616 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4617 if g_Game_IsServer
and g_Game_IsNet
then
4618 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4619 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4623 FObj
.X
:= X
-PLAYER_RECT
.X
;
4624 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4625 if FAlive
and FGhost
then
4631 if not g_Game_IsNet
then
4635 SetDirection(D_LEFT
);
4641 SetDirection(D_RIGHT
);
4647 if FDirection
= D_RIGHT
then
4649 SetDirection(D_LEFT
);
4654 SetDirection(D_RIGHT
);
4660 if not silent
and (Anim
<> nil) then
4662 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4663 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4666 if g_Game_IsServer
and g_Game_IsNet
then
4667 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4668 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4675 function nonz(a
: Single): Single;
4683 procedure TPlayer
.Update();
4686 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4687 blockmon
, headwater
, dospawn
: Boolean;
4692 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4693 AnyServer
:= g_Game_IsServer
;
4695 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4696 DoLerp(NetInterpLevel
+ 1)
4702 if FClientID
>= 0 then
4704 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4705 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4706 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4715 if FAlive
and (gFly
or FJetpack
) then
4718 if FDirection
= D_LEFT
then
4723 if FAlive
and (not FGhost
) then
4725 if FKeys
[KEY_UP
].Pressed
then
4727 if FKeys
[KEY_DOWN
].Pressed
then
4731 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4734 i
:= g_basic
.Sign(FIncCam
);
4735 FIncCam
:= Abs(FIncCam
);
4736 DecMin(FIncCam
, 5, 0);
4737 FIncCam
:= FIncCam
*i
;
4740 // no need to do that each second frame, weapon queue will take care of it
4741 if FAlive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4742 if FAlive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4744 if gTime
mod (GAME_TICK
*2) <> 0 then
4746 if (FObj
.Vel
.X
= 0) and FAlive
then
4748 if FKeys
[KEY_LEFT
].Pressed
then
4750 if FKeys
[KEY_RIGHT
].Pressed
then
4756 g_Obj_Move(@FObj
, True, True, True);
4757 positionChanged(); // this updates spatial accelerators
4763 FActionChanged
:= False;
4767 // Let alive player do some actions
4768 if FKeys
[KEY_LEFT
].Pressed
then Run(D_LEFT
);
4769 if FKeys
[KEY_RIGHT
].Pressed
then Run(D_RIGHT
);
4770 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
4771 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
4772 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
4773 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
4774 if FKeys
[KEY_JUMP
].Pressed
then Jump()
4777 if AnyServer
and FJetpack
then
4781 if NetServer
then MH_SEND_PlayerStats(FUID
);
4783 FCanJetpack
:= True;
4790 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
4792 if FKeys
[k
].Pressed
then
4800 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4803 if (FTime
[T_RESPAWN
] <= gTime
) and
4804 gGameOn
and (not FAlive
) then
4806 if (g_Player_GetCount() > 1) then
4810 gExit
:= EXIT_RESTART
;
4815 // Dead spectator actions
4818 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
4819 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
4823 if (FSpectatePlayer
>= High(gPlayers
)) then
4824 FSpectatePlayer
:= -1
4828 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
4829 if gPlayers
[I
] <> nil then
4830 if gPlayers
[I
].alive
then
4831 if gPlayers
[I
].UID
<> FUID
then
4833 FSpectatePlayer
:= I
;
4838 if not SetSpect
then FSpectatePlayer
:= -1;
4849 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
4851 FYTo
:= FObj
.Y
- 32;
4852 FSpectatePlayer
:= -1;
4854 if FKeys
[KEY_DOWN
].Pressed
then
4856 FYTo
:= FObj
.Y
+ 32;
4857 FSpectatePlayer
:= -1;
4859 if FKeys
[KEY_LEFT
].Pressed
then
4861 FXTo
:= FObj
.X
- 32;
4862 FSpectatePlayer
:= -1;
4864 if FKeys
[KEY_RIGHT
].Pressed
then
4866 FXTo
:= FObj
.X
+ 32;
4867 FSpectatePlayer
:= -1;
4870 if (FXTo
< -64) then
4872 else if (FXTo
> gMapInfo
.Width
+ 32) then
4873 FXTo
:= gMapInfo
.Width
+ 32;
4874 if (FYTo
< -72) then
4876 else if (FYTo
> gMapInfo
.Height
+ 32) then
4877 FYTo
:= gMapInfo
.Height
+ 32;
4882 g_Obj_Move(@FObj
, True, True, True);
4883 positionChanged(); // this updates spatial accelerators
4890 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
4891 if gPlayers
[FSpectatePlayer
] <> nil then
4892 if gPlayers
[FSpectatePlayer
].alive
then
4894 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
4895 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
4899 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
4900 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
4901 PANEL_BLOCKMON
, True);
4902 headwater
:= HeadInLiquid(0, 0);
4904 // Ñîïðîòèâëåíèå âîçäóõà:
4905 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
4906 if FObj
.Vel
.X
<> 0 then
4907 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
4909 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
4910 DecMin(FPain
, 5, 0);
4911 DecMin(FPickup
, 1, 0);
4913 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
4915 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
4916 FMegaRulez
[MR_SUIT
] := 0;
4917 FMegaRulez
[MR_INVUL
] := 0;
4918 FMegaRulez
[MR_INVIS
] := 0;
4919 Kill(K_FALLKILL
, 0, HIT_FALL
);
4926 if FCurrWeap
= WEAPON_SAW
then
4927 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
4928 FSawSoundSelect
.IsPlaying()) then
4929 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
4932 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
4933 (not FJetSoundOff
.IsPlaying()) then
4935 FJetSoundFly
.SetPosition(0);
4936 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
4939 for b
:= WP_FIRST
to WP_LAST
do
4940 if FReloading
[b
] > 0 then
4946 if FShellTimer
> -1 then
4947 if FShellTimer
= 0 then
4949 if FShellType
= SHELL_SHELL
then
4950 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4951 GameVelX
, GameVelY
-2, SHELL_SHELL
)
4952 else if FShellType
= SHELL_DBLSHELL
then
4954 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4955 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
4956 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4957 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
4960 end else Dec(FShellTimer
);
4962 if (FBFGFireCounter
> -1) then
4963 if FBFGFireCounter
= 0 then
4967 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
4968 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
4969 xd
:= wx
+IfThen(FDirection
= D_LEFT
, -30, 30);
4970 yd
:= wy
+firediry();
4971 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
4972 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
4973 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
4974 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
4975 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
4978 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
4979 FBFGFireCounter
:= -1;
4982 FBFGFireCounter
:= 0
4984 Dec(FBFGFireCounter
);
4986 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
4988 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
4990 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
4993 if (headwater
or blockmon
) then
4999 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5002 else if (FAir
mod 31 = 0) and not blockmon
then
5004 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5005 if Random(2) = 0 then
5006 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5008 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5010 end else if FAir
< AIR_DEF
then
5013 if FFireTime
> 0 then
5015 if BodyInLiquid(0, 0) then
5020 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5022 if FMegaRulez
[MR_SUIT
] = gTime
then
5029 if FFirePainTime
<= 0 then
5031 if g_Game_IsServer
then
5032 Damage(5, FFireAttacker
, 0, 0, HIT_FLAME
);
5033 FFirePainTime
:= 18;
5035 FFirePainTime
:= FFirePainTime
- 1;
5036 FFireTime
:= FFireTime
- 1;
5037 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5038 MH_SEND_PlayerStats(FUID
);
5042 if FDamageBuffer
> 0 then
5044 if FDamageBuffer
>= 9 then
5048 if FDamageBuffer
< 30 then i
:= 9
5049 else if FDamageBuffer
< 100 then i
:= 18
5053 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5054 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5055 FHealth
:= FHealth
-ii
;
5058 FHealth
:= FHealth
+FArmor
;
5063 if FHealth
<= 0 then
5064 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5065 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5066 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5070 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5071 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5072 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5073 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5080 end; // if FAlive then ...
5082 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5084 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5085 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5086 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5087 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5089 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5090 then SetAction(A_STAND
, True);
5092 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5094 for b
:= Low(FKeys
) to High(FKeys
) do
5095 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5099 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5101 x
:= FObj
.X
+PLAYER_RECT
.X
;
5102 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5103 w
:= PLAYER_RECT
.Width
;
5104 h
:= PLAYER_RECT
.Height
;
5108 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5110 if (dx
<> 0) or (dy
<> 0) then
5119 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5121 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5122 FObj
.Y
+PLAYER_RECT
.Y
,
5129 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5131 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5132 FObj
.Y
+PLAYER_RECT
.Y
,
5136 Panel
.Width
, Panel
.Height
);
5139 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5141 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5142 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5143 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5144 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5147 function g_Player_ValidName(Name
: string): Boolean;
5153 if gPlayers
= nil then Exit
;
5155 for a
:= 0 to High(gPlayers
) do
5156 if gPlayers
[a
] <> nil then
5157 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5164 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5168 d
:= FModel
.Direction
;
5170 FModel
.Direction
:= Direction
;
5171 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5173 FDirection
:= Direction
;
5176 function TPlayer
.GetKeys(): Byte;
5180 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5181 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5182 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5184 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5185 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5188 procedure TPlayer
.Use();
5192 if FTime
[T_USE
] > gTime
then Exit
;
5194 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5195 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5197 for a
:= 0 to High(gPlayers
) do
5198 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5199 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5200 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5201 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5203 gPlayers
[a
].Touch();
5204 if g_Game_IsNet
and g_Game_IsServer
then
5205 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5208 FTime
[T_USE
] := gTime
+120;
5211 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5215 WX
, WY
, XD
, YD
: Integer;
5226 if R_BERSERK
in FRulez
then
5228 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5229 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5230 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5233 locobj
.rect
.Width
:= 39;
5234 locobj
.rect
.Height
:= 52;
5235 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5236 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5237 locobj
.Accel
.X
:= xd
-wx
;
5238 locobj
.Accel
.y
:= yd
-wy
;
5240 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5241 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5243 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5247 FPain
:= min(FPain
+ 25, 50);
5249 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5254 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5255 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5257 FSawSoundSelect
.Stop();
5259 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5261 else if not FSawSoundHit
.IsPlaying() then
5263 FSawSoundSelect
.Stop();
5264 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5271 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5272 FFireAngle
:= FAngle
;
5274 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5275 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5280 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5281 FFireAngle
:= FAngle
;
5284 FShellType
:= SHELL_SHELL
;
5289 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5290 FFireAngle
:= FAngle
;
5293 FShellType
:= SHELL_DBLSHELL
;
5298 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5299 FFireAngle
:= FAngle
;
5301 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5302 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5305 WEAPON_ROCKETLAUNCHER
:
5307 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5308 FFireAngle
:= FAngle
;
5314 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5315 FFireAngle
:= FAngle
;
5321 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5322 FFireAngle
:= FAngle
;
5326 WEAPON_SUPERPULEMET
:
5328 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5329 FFireAngle
:= FAngle
;
5331 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5332 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5335 WEAPON_FLAMETHROWER
:
5337 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5338 FFireAngle
:= FAngle
;
5345 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5346 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5347 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5350 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5352 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5353 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5356 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5360 if NetInterpLevel
< 1 then
5370 AX
:= Abs(FXTo
- FObj
.X
);
5371 AY
:= Abs(FYTo
- FObj
.Y
);
5372 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5374 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5379 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5381 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5382 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5383 PANEL_LIFTUP
, False) then Result
:= -1
5385 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5386 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5387 PANEL_LIFTDOWN
, False) then Result
:= 1
5391 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5398 if Flag
= FLAG_NONE
then
5401 if not g_Game_IsServer
then Exit
;
5403 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5404 if (Flag
= FTeam
) and
5405 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5406 (FFlag
<> FLAG_NONE
) then
5408 if FFlag
= FLAG_RED
then
5409 s
:= _lc
[I_PLAYER_FLAG_RED
]
5411 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5413 evtype
:= FLAG_STATE_SCORED
;
5415 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5416 Insert('.', ts
, Length(ts
) + 1 - 3);
5417 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5419 g_Map_ResetFlag(FFlag
);
5420 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5422 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5425 if g_Game_IsNet
then
5427 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5431 gFlags
[FFlag
].CaptureTime
:= 0;
5436 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5437 if (Flag
= FTeam
) and
5438 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5440 if Flag
= FLAG_RED
then
5441 s
:= _lc
[I_PLAYER_FLAG_RED
]
5443 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5445 evtype
:= FLAG_STATE_RETURNED
;
5446 gFlags
[Flag
].CaptureTime
:= 0;
5448 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5450 g_Map_ResetFlag(Flag
);
5451 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5454 if g_Game_IsNet
then
5456 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5462 // Ïîäîáðàë ÷óæîé ôëàã:
5463 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5467 if Flag
= FLAG_RED
then
5468 s
:= _lc
[I_PLAYER_FLAG_RED
]
5470 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5472 evtype
:= FLAG_STATE_CAPTURED
;
5474 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5476 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5478 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5481 if g_Game_IsNet
then
5483 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5489 procedure TPlayer
.SetFlag(Flag
: Byte);
5492 if FModel
<> nil then
5493 FModel
.SetFlag(FFlag
);
5496 function TPlayer
.DropFlag(): Boolean;
5501 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5503 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5504 with gFlags
[FFlag
] do
5508 Direction
:= FDirection
;
5509 State
:= FLAG_STATE_DROPPED
;
5511 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5512 (FObj
.Vel
.Y
div 2)-2+Random(5));
5513 positionChanged(); // this updates spatial accelerators
5515 if FFlag
= FLAG_RED
then
5516 s
:= _lc
[I_PLAYER_FLAG_RED
]
5518 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5520 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5521 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5523 if g_Game_IsNet
then
5524 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5530 procedure TPlayer
.GetSecret();
5535 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5537 Assert(Key
<= High(FKeys
));
5539 FKeys
[Key
].Pressed
:= True;
5540 FKeys
[Key
].Time
:= Time
;
5543 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5545 Result
:= FKeys
[K
].Pressed
;
5548 procedure TPlayer
.ReleaseKeys();
5552 for a
:= Low(FKeys
) to High(FKeys
) do
5554 FKeys
[a
].Pressed
:= False;
5559 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5563 function TPlayer
.firediry(): Integer;
5565 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5566 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5570 procedure TPlayer
.RememberState();
5574 FSavedState
.Health
:= FHealth
;
5575 FSavedState
.Armor
:= FArmor
;
5576 FSavedState
.Air
:= FAir
;
5577 FSavedState
.JetFuel
:= FJetFuel
;
5578 FSavedState
.CurrWeap
:= FCurrWeap
;
5579 FSavedState
.NextWeap
:= FNextWeap
;
5580 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5583 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5585 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5587 FSavedState
.Rulez
:= FRulez
;
5588 FSavedState
.WaitRecall
:= True;
5591 procedure TPlayer
.RecallState();
5595 if not FSavedState
.WaitRecall
then Exit
;
5597 FHealth
:= FSavedState
.Health
;
5598 FArmor
:= FSavedState
.Armor
;
5599 FAir
:= FSavedState
.Air
;
5600 FJetFuel
:= FSavedState
.JetFuel
;
5601 FCurrWeap
:= FSavedState
.CurrWeap
;
5602 FNextWeap
:= FSavedState
.NextWeap
;
5603 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5606 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5608 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5610 FRulez
:= FSavedState
.Rulez
;
5611 FSavedState
.WaitRecall
:= False;
5613 if gGameSettings
.GameType
= GT_SERVER
then
5614 MH_SEND_PlayerStats(FUID
);
5617 procedure TPlayer
.SaveState(var Mem
: TBinMemoryWriter
);
5629 Mem
:= TBinMemoryWriter
.Create(i
);
5631 // Ñèãíàòóðà èãðîêà:
5632 sig
:= PLAYER_SIGNATURE
; // 'PLYR'
5633 Mem
.WriteDWORD(sig
);
5635 Mem
.WriteBoolean(FIamBot
);
5637 Mem
.WriteWord(FUID
);
5639 Mem
.WriteString(FName
, 32);
5641 Mem
.WriteByte(FTeam
);
5643 Mem
.WriteBoolean(FAlive
);
5644 // Èçðàñõîäîâàë ëè âñå æèçíè:
5645 Mem
.WriteBoolean(FNoRespawn
);
5647 if FDirection
= D_LEFT
then
5653 Mem
.WriteInt(FHealth
);
5655 Mem
.WriteByte(FLives
);
5657 Mem
.WriteInt(FArmor
);
5661 Mem
.WriteInt(FJetFuel
);
5663 Mem
.WriteInt(FPain
);
5665 Mem
.WriteInt(FKills
);
5667 Mem
.WriteInt(FMonsterKills
);
5669 Mem
.WriteInt(FFrags
);
5671 Mem
.WriteByte(FFragCombo
);
5672 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5673 Mem
.WriteDWORD(FLastFrag
);
5675 Mem
.WriteInt(FDeath
);
5676 // Êàêîé ôëàã íåñåò:
5677 Mem
.WriteByte(FFlag
);
5679 Mem
.WriteInt(FSecrets
);
5681 Mem
.WriteByte(FCurrWeap
);
5683 Mem
.WriteWord(FNextWeap
);
5685 Mem
.WriteByte(FNextWeapDelay
);
5686 // Âðåìÿ çàðÿäêè BFG:
5687 Mem
.WriteSmallInt(FBFGFireCounter
);
5689 Mem
.WriteInt(FDamageBuffer
);
5690 // Ïîñëåäíèé óäàðèâøèé:
5691 Mem
.WriteWord(FLastSpawnerUID
);
5692 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5693 Mem
.WriteByte(FLastHit
);
5695 Obj_SaveState(@FObj
, Mem
);
5696 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5697 for i
:= A_BULLETS
to A_HIGH
do
5698 Mem
.WriteWord(FAmmo
[i
]);
5699 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5700 for i
:= A_BULLETS
to A_HIGH
do
5701 Mem
.WriteWord(FMaxAmmo
[i
]);
5703 for i
:= WP_FIRST
to WP_LAST
do
5704 Mem
.WriteBoolean(FWeapon
[i
]);
5705 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5706 for i
:= WP_FIRST
to WP_LAST
do
5707 Mem
.WriteWord(FReloading
[i
]);
5709 if R_ITEM_BACKPACK
in FRulez
then
5714 // Íàëè÷èå êðàñíîãî êëþ÷à:
5715 if R_KEY_RED
in FRulez
then
5720 // Íàëè÷èå çåëåíîãî êëþ÷à:
5721 if R_KEY_GREEN
in FRulez
then
5726 // Íàëè÷èå ñèíåãî êëþ÷à:
5727 if R_KEY_BLUE
in FRulez
then
5732 // Íàëè÷èå áåðñåðêà:
5733 if R_BERSERK
in FRulez
then
5738 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5739 for i
:= MR_SUIT
to MR_MAX
do
5740 Mem
.WriteDWORD(FMegaRulez
[i
]);
5741 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5742 for i
:= T_RESPAWN
to T_FLAGCAP
do
5743 Mem
.WriteDWORD(FTime
[i
]);
5746 Mem
.WriteString(str
);
5756 procedure TPlayer
.LoadState(var Mem
: TBinMemoryReader
);
5766 // Ñèãíàòóðà èãðîêà:
5768 if sig
<> PLAYER_SIGNATURE
then // 'PLYR'
5770 raise EBinSizeError
.Create('TPlayer.LoadState: Wrong Player Signature');
5773 Mem
.ReadBoolean(FIamBot
);
5777 Mem
.ReadString(str
);
5778 if (Self
<> gPlayer1
) and (Self
<> gPlayer2
) then
5781 Mem
.ReadByte(FTeam
);
5783 Mem
.ReadBoolean(FAlive
);
5784 // Èçðàñõîäîâàë ëè âñå æèçíè:
5785 Mem
.ReadBoolean(FNoRespawn
);
5789 FDirection
:= D_LEFT
5791 FDirection
:= D_RIGHT
;
5793 Mem
.ReadInt(FHealth
);
5795 Mem
.ReadByte(FLives
);
5797 Mem
.ReadInt(FArmor
);
5801 Mem
.ReadInt(FJetFuel
);
5805 Mem
.ReadInt(FKills
);
5807 Mem
.ReadInt(FMonsterKills
);
5809 Mem
.ReadInt(FFrags
);
5811 Mem
.ReadByte(FFragCombo
);
5812 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5813 Mem
.ReadDWORD(FLastFrag
);
5815 Mem
.ReadInt(FDeath
);
5816 // Êàêîé ôëàã íåñåò:
5817 Mem
.ReadByte(FFlag
);
5819 Mem
.ReadInt(FSecrets
);
5821 Mem
.ReadByte(FCurrWeap
);
5823 Mem
.ReadWord(FNextWeap
);
5825 Mem
.ReadByte(FNextWeapDelay
);
5826 // Âðåìÿ çàðÿäêè BFG:
5827 Mem
.ReadSmallInt(FBFGFireCounter
);
5829 Mem
.ReadInt(FDamageBuffer
);
5830 // Ïîñëåäíèé óäàðèâøèé:
5831 Mem
.ReadWord(FLastSpawnerUID
);
5832 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5833 Mem
.ReadByte(FLastHit
);
5835 Obj_LoadState(@FObj
, Mem
);
5836 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5837 for i
:= A_BULLETS
to A_HIGH
do
5838 Mem
.ReadWord(FAmmo
[i
]);
5839 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5840 for i
:= A_BULLETS
to A_HIGH
do
5841 Mem
.ReadWord(FMaxAmmo
[i
]);
5843 for i
:= WP_FIRST
to WP_LAST
do
5844 Mem
.ReadBoolean(FWeapon
[i
]);
5845 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5846 for i
:= WP_FIRST
to WP_LAST
do
5847 Mem
.ReadWord(FReloading
[i
]);
5851 Include(FRulez
, R_ITEM_BACKPACK
);
5852 // Íàëè÷èå êðàñíîãî êëþ÷à:
5855 Include(FRulez
, R_KEY_RED
);
5856 // Íàëè÷èå çåëåíîãî êëþ÷à:
5859 Include(FRulez
, R_KEY_GREEN
);
5860 // Íàëè÷èå ñèíåãî êëþ÷à:
5863 Include(FRulez
, R_KEY_BLUE
);
5864 // Íàëè÷èå áåðñåðêà:
5867 Include(FRulez
, R_BERSERK
);
5868 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5869 for i
:= MR_SUIT
to MR_MAX
do
5870 Mem
.ReadDWORD(FMegaRulez
[i
]);
5871 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5872 for i
:= T_RESPAWN
to T_FLAGCAP
do
5873 Mem
.ReadDWORD(FTime
[i
]);
5875 Mem
.ReadString(str
);
5877 Mem
.ReadByte(FColor
.R
);
5878 Mem
.ReadByte(FColor
.G
);
5879 Mem
.ReadByte(FColor
.B
);
5880 if Self
= gPlayer1
then
5882 str
:= gPlayer1Settings
.Model
;
5883 FColor
:= gPlayer1Settings
.Color
;
5885 if Self
= gPlayer2
then
5887 str
:= gPlayer2Settings
.Model
;
5888 FColor
:= gPlayer2Settings
.Color
;
5890 // Îáíîâëÿåì ìîäåëü èãðîêà:
5892 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
5893 FModel
.Color
:= TEAMCOLOR
[FTeam
]
5895 FModel
.Color
:= FColor
;
5898 procedure TPlayer
.AllRulez(Health
: Boolean);
5904 FHealth
:= PLAYER_HP_LIMIT
;
5905 FArmor
:= PLAYER_AP_LIMIT
;
5909 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
5910 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
5911 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5914 procedure TPlayer
.RestoreHealthArmor();
5916 FHealth
:= PLAYER_HP_LIMIT
;
5917 FArmor
:= PLAYER_AP_LIMIT
;
5920 procedure TPlayer
.FragCombo();
5924 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
5926 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
5928 if FFragCombo
< 5 then
5930 Param
:= FUID
or (FFragCombo
shl 16);
5931 if (FComboEvnt
>= Low(gDelayedEvents
)) and
5932 (FComboEvnt
<= High(gDelayedEvents
)) and
5933 gDelayedEvents
[FComboEvnt
].Pending
and
5934 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
5935 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
5937 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
5938 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
5941 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
5949 procedure TPlayer
.GiveItem(ItemType
: Byte);
5953 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
5955 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
5959 if FAir
< AIR_MAX
then
5966 if not (R_BERSERK
in FRulez
) then
5968 Include(FRulez
, R_BERSERK
);
5969 if FBFGFireCounter
< 1 then
5971 FCurrWeap
:= WEAPON_KASTET
;
5973 FModel
.SetWeapon(WEAPON_KASTET
);
5977 FBerserk
:= gTime
+30000;
5979 if FHealth
< PLAYER_HP_SOFT
then
5981 FHealth
:= PLAYER_HP_SOFT
;
5982 FBerserk
:= gTime
+30000;
5987 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
5989 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
5993 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
5995 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
5999 if FJetFuel
< JET_MAX
then
6001 FJetFuel
:= JET_MAX
;
6004 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6005 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6007 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6008 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6010 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6012 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6014 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6015 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6018 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6019 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6020 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6021 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6022 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6023 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6024 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6025 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6026 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6028 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6029 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6030 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6031 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6032 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6033 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6034 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6035 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6036 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6039 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6040 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6041 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6042 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6043 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6045 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6046 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6047 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6048 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6049 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6051 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6052 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6053 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6054 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6056 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6059 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6060 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6061 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6063 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6064 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6069 if g_Game_IsNet
and g_Game_IsServer
then
6070 MH_SEND_PlayerStats(FUID
);
6073 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6078 if (Random(5) = 1) and (Times
= 1) then
6081 if BodyInLiquid(0, 0) then
6083 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6084 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6085 if Random(2) = 0 then
6086 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6088 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6092 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6094 for i
:= 1 to Times
do
6096 Anim
:= TAnimation
.Create(id
, False, 3);
6098 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6099 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6105 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6110 if (Random(10) = 1) and (Times
= 1) then
6113 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6115 for i
:= 1 to Times
do
6117 Anim
:= TAnimation
.Create(id
, False, 3);
6119 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6120 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6126 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6128 FSawSound
.Pause(Enable
);
6129 FSawSoundIdle
.Pause(Enable
);
6130 FSawSoundHit
.Pause(Enable
);
6131 FSawSoundSelect
.Pause(Enable
);
6136 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6141 FObj
.Rect
:= PLAYER_CORPSERECT
;
6142 FModelName
:= ModelName
;
6147 FState
:= CORPSE_STATE_MESS
;
6148 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6152 FState
:= CORPSE_STATE_NORMAL
;
6153 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6157 destructor TCorpse
.Destroy();
6164 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6166 procedure TCorpse
.positionChanged (); inline; begin end;
6168 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6170 if (dx
<> 0) or (dy
<> 0) then
6179 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6181 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6182 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6183 w
:= PLAYER_CORPSERECT
.Width
;
6184 h
:= PLAYER_CORPSERECT
.Height
;
6188 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6192 if FState
= CORPSE_STATE_REMOVEME
then
6195 FDamage
:= FDamage
+ Value
;
6197 if FDamage
> 150 then
6199 if FAnimation
<> nil then
6204 FState
:= CORPSE_STATE_REMOVEME
;
6206 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6207 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6208 FModelName
, FColor
);
6209 // Çâóê ìÿñà îò òðóïà:
6210 pm
:= g_PlayerModel_Get(FModelName
);
6211 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6217 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6218 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6219 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6220 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6221 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6226 procedure TCorpse
.Draw();
6228 if FState
= CORPSE_STATE_REMOVEME
then
6231 if FAnimation
<> nil then
6232 FAnimation
.Draw(FObj
.X
, FObj
.Y
, M_NONE
);
6234 if FAnimationMask
<> nil then
6237 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, M_NONE
);
6244 procedure TCorpse
.Update();
6248 if FState
= CORPSE_STATE_REMOVEME
then
6251 if gTime
mod (GAME_TICK
*2) <> 0 then
6253 g_Obj_Move(@FObj
, True, True, True);
6254 positionChanged(); // this updates spatial accelerators
6258 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6259 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6261 st
:= g_Obj_Move(@FObj
, True, True, True);
6262 positionChanged(); // this updates spatial accelerators
6264 if WordBool(st
and MOVE_FALLOUT
) then
6266 FState
:= CORPSE_STATE_REMOVEME
;
6270 if FAnimation
<> nil then
6271 FAnimation
.Update();
6272 if FAnimationMask
<> nil then
6273 FAnimationMask
.Update();
6276 procedure TCorpse
.SaveState(var Mem
: TBinMemoryWriter
);
6285 sig
:= CORPSE_SIGNATURE
; // 'CORP'
6286 Mem
.WriteDWORD(sig
);
6288 Mem
.WriteByte(FState
);
6289 // Íàêîïëåííûé óðîí:
6290 Mem
.WriteByte(FDamage
);
6292 Mem
.WriteByte(FColor
.R
);
6293 Mem
.WriteByte(FColor
.G
);
6294 Mem
.WriteByte(FColor
.B
);
6296 Obj_SaveState(@FObj
, Mem
);
6297 // Åñòü ëè àíèìàöèÿ:
6298 anim
:= FAnimation
<> nil;
6299 Mem
.WriteBoolean(anim
);
6300 // Åñëè åñòü - ñîõðàíÿåì:
6302 FAnimation
.SaveState(Mem
);
6303 // Åñòü ëè ìàñêà àíèìàöèè:
6304 anim
:= FAnimationMask
<> nil;
6305 Mem
.WriteBoolean(anim
);
6306 // Åñëè åñòü - ñîõðàíÿåì:
6308 FAnimationMask
.SaveState(Mem
);
6311 procedure TCorpse
.LoadState(var Mem
: TBinMemoryReader
);
6321 if sig
<> CORPSE_SIGNATURE
then // 'CORP'
6323 raise EBinSizeError
.Create('TCorpse.LoadState: Wrong Corpse Signature');
6326 Mem
.ReadByte(FState
);
6327 // Íàêîïëåííûé óðîí:
6328 Mem
.ReadByte(FDamage
);
6330 Mem
.ReadByte(FColor
.R
);
6331 Mem
.ReadByte(FColor
.G
);
6332 Mem
.ReadByte(FColor
.B
);
6334 Obj_LoadState(@FObj
, Mem
);
6335 // Åñòü ëè àíèìàöèÿ:
6336 Mem
.ReadBoolean(anim
);
6337 // Åñëè åñòü - çàãðóæàåì:
6340 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6341 FAnimation
.LoadState(Mem
);
6343 // Åñòü ëè ìàñêà àíèìàöèè:
6344 Mem
.ReadBoolean(anim
);
6345 // Åñëè åñòü - çàãðóæàåì:
6348 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6349 FAnimationMask
.LoadState(Mem
);
6355 constructor TBot
.Create();
6362 FSpectator
:= False;
6369 for a
:= WP_FIRST
to WP_LAST
do
6371 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6372 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6373 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6377 destructor TBot
.Destroy();
6380 inherited Destroy();
6383 procedure TBot
.Draw();
6387 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6388 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6391 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6393 inherited Respawn(Silent
, Force
);
6396 FSelectedWeapon
:= FCurrWeap
;
6401 procedure TBot
.UpdateCombat();
6414 TTargetRecord
= array of TTarget
;
6416 function Compare(a
, b
: TTarget
): Integer;
6418 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6421 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6423 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6424 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6426 if a
.Dist
> b
.Dist
then // B áëèæå
6428 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6431 else // Ñòðàííî -> A
6436 a
, x1
, y1
, x2
, y2
: Integer;
6437 targets
: TTargetRecord
;
6439 Target
, BestTarget
: TTarget
;
6440 firew
, fireh
: Integer;
6444 vsPlayer
, vsMonster
, ok
: Boolean;
6447 function monsUpdate (mon
: TMonster
): Boolean;
6449 result
:= false; // don't stop
6450 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6452 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6454 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6455 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6457 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6458 if g_TraceVector(x1
, y1
, x2
, y2
) then
6460 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6461 SetLength(targets
, Length(targets
)+1);
6462 with targets
[High(targets
)] do
6469 Rect
:= mon
.Obj
.Rect
;
6470 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6471 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6472 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6481 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6482 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6484 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6485 if FCurrWeap
<> FSelectedWeapon
then
6488 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6489 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6491 RemoveAIFlag('NEEDFIRE');
6494 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6495 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6496 else PressKey(KEY_FIRE
);
6500 // Êîîðäèíàòû ñòâîëà:
6501 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6502 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6504 Target
.UID
:= FTargetUID
;
6507 if Target
.UID
<> 0 then
6508 begin // Öåëü åñòü - íàñòðàèâàåì
6509 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6512 tpla
:= g_Player_Get(Target
.UID
);
6516 if (@FObj
) <> nil then
6523 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6524 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6525 Target
.Rect
:= PLAYER_RECT
;
6526 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6527 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6528 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6529 Target
.IsPlayer
:= True;
6533 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6536 mon
:= g_Monsters_ByUID(Target
.UID
);
6539 Target
.X
:= mon
.Obj
.X
;
6540 Target
.Y
:= mon
.Obj
.Y
;
6542 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6543 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6544 Target
.Rect
:= mon
.Obj
.Rect
;
6545 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6546 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6547 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6548 Target
.IsPlayer
:= False;
6555 begin // Öåëè íåò - îáíóëÿåì
6560 Target
.Visible
:= False;
6561 Target
.Line
:= False;
6562 Target
.IsPlayer
:= False;
6567 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6568 if (not Target
.Line
) or (not Target
.Visible
) then
6572 for a
:= 0 to High(gPlayers
) do
6573 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6574 (gPlayers
[a
].FUID
<> FUID
) and
6575 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6576 (not gPlayers
[a
].NoTarget
) and
6577 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6579 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6580 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6583 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6584 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6586 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6587 if g_TraceVector(x1
, y1
, x2
, y2
) then
6589 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6590 SetLength(targets
, Length(targets
)+1);
6591 with targets
[High(targets
)] do
6593 UID
:= gPlayers
[a
].FUID
;
6594 X
:= gPlayers
[a
].FObj
.X
;
6595 Y
:= gPlayers
[a
].FObj
.Y
;
6598 Rect
:= PLAYER_RECT
;
6599 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6600 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6601 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6609 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6612 // Åñëè åñòü âîçìîæíûå öåëè:
6613 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6614 if targets
<> nil then
6616 // Âûáèðàåì íàèëó÷øóþ öåëü:
6617 BestTarget
:= targets
[0];
6618 if Length(targets
) > 1 then
6619 for a
:= 1 to High(targets
) do
6620 if Compare(BestTarget
, targets
[a
]) = 1 then
6621 BestTarget
:= targets
[a
];
6623 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6624 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6625 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6627 Target
:= BestTarget
;
6629 if (Healthy() = 3) or ((Healthy() = 2)) then
6630 begin // Åñëè çäîðîâû - äîãîíÿåì
6631 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6632 SetAIFlag('GORIGHT', '1');
6633 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6634 SetAIFlag('GOLEFT', '1');
6637 begin // Åñëè ïîáèòû - óáåãàåì
6638 if ((RunDirection() = D_LEFT
) and (Target
.X
< FObj
.X
)) then
6639 SetAIFlag('GORIGHT', '1');
6640 if ((RunDirection() = D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6641 SetAIFlag('GOLEFT', '1');
6644 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6645 SelectWeapon(Abs(x1
-Target
.cX
));
6650 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6651 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6652 if Target
.UID
<> 0 then
6654 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6655 Target
.Y
+ Target
.Rect
.Y
) then
6656 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6657 if (Healthy() = 3) or ((Healthy() = 2)) then
6658 begin // Åñëè çäîðîâû - äîãîíÿåì
6659 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6660 SetAIFlag('GORIGHT', '1');
6661 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6662 SetAIFlag('GOLEFT', '1');
6665 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6667 if ((RunDirection() = D_LEFT
) and (Target
.X
< FObj
.X
)) then
6668 SetAIFlag('GORIGHT', '1');
6669 if ((RunDirection() = D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6670 SetAIFlag('GOLEFT', '1');
6674 begin // Öåëü ïîêà íà "ýêðàíå"
6675 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6676 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6677 FLastVisible
:= gTime
;
6678 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6679 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6681 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6682 SetAIFlag('GORIGHT', '1');
6683 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6684 SetAIFlag('GOLEFT', '1');
6688 // Âûáèðàåì óãîë ââåðõ:
6689 if FDirection
= D_LEFT
then
6690 angle
:= ANGLE_LEFTUP
6692 angle
:= ANGLE_RIGHTUP
;
6694 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6695 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6697 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6698 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6699 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6700 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6701 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6702 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6703 begin // òî íóæíî ñòðåëÿòü ââåðõ
6704 SetAIFlag('NEEDFIRE', '1');
6705 SetAIFlag('NEEDSEEUP', '1');
6708 // Âûáèðàåì óãîë âíèç:
6709 if FDirection
= D_LEFT
then
6710 angle
:= ANGLE_LEFTDOWN
6712 angle
:= ANGLE_RIGHTDOWN
;
6714 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6715 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6717 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6718 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6719 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6720 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6721 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6722 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6723 begin // òî íóæíî ñòðåëÿòü âíèç
6724 SetAIFlag('NEEDFIRE', '1');
6725 SetAIFlag('NEEDSEEDOWN', '1');
6728 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6729 if Target
.Visible
and
6730 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6731 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6733 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6734 if ((FDirection
= D_LEFT
) and (Target
.X
< FObj
.X
)) or
6735 ((FDirection
= D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6736 begin // òî íóæíî ñòðåëÿòü âïåðåä
6737 SetAIFlag('NEEDFIRE', '1');
6738 SetAIFlag('NEEDSEEDOWN', '');
6739 SetAIFlag('NEEDSEEUP', '');
6741 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6742 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6743 if GetRnd(FDifficult
.CloseJump
) then
6744 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6745 if Abs(FObj
.X
-Target
.X
) < 128 then
6749 if Random(a
) = 0 then
6750 SetAIFlag('NEEDJUMP', '1');
6754 // Åñëè öåëü âñå åùå åñòü:
6755 if Target
.UID
<> 0 then
6756 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
6757 Target
.UID
:= 0 // òî çàáûòü öåëü
6758 else // Åñëè âèäåëè íåäàâíî
6759 begin // íî öåëü óáèëè
6760 if Target
.IsPlayer
then
6761 begin // Öåëü - èãðîê
6762 pla
:= g_Player_Get(Target
.UID
);
6763 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
6764 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6765 Target
.UID
:= 0; // òî çàáûòü öåëü
6768 begin // Öåëü - ìîíñòð
6769 mon
:= g_Monsters_ByUID(Target
.UID
);
6770 if (mon
= nil) or (not mon
.alive
) then
6771 Target
.UID
:= 0; // òî çàáûòü öåëü
6774 end; // if Target.UID <> 0
6776 FTargetUID
:= Target
.UID
;
6778 // Åñëè âîçìîæíûõ öåëåé íåò:
6779 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
6780 if targets
= nil then
6781 if GetAIFlag('ATTACKLEFT') <> '' then
6782 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
6783 RemoveAIFlag('ATTACKLEFT');
6785 SetAIFlag('NEEDJUMP', '1');
6787 if RunDirection() = D_RIGHT
then
6788 begin // Èäåì íå â òó ñòîðîíó
6789 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6790 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
6791 SetAIFlag('NEEDFIRE', '1');
6792 SetAIFlag('GOLEFT', '1');
6796 begin // Èäåì â íóæíóþ ñòîðîíó
6797 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6798 SetAIFlag('NEEDFIRE', '1');
6799 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6800 SetAIFlag('GORIGHT', '1');
6804 if GetAIFlag('ATTACKRIGHT') <> '' then
6805 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
6806 RemoveAIFlag('ATTACKRIGHT');
6808 SetAIFlag('NEEDJUMP', '1');
6810 if RunDirection() = D_LEFT
then
6811 begin // Èäåì íå â òó ñòîðîíó
6812 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6813 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
6814 SetAIFlag('NEEDFIRE', '1');
6815 SetAIFlag('GORIGHT', '1');
6820 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6821 SetAIFlag('NEEDFIRE', '1');
6822 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6823 SetAIFlag('GOLEFT', '1');
6827 //HACK! (does it belongs there?)
6828 RealizeCurrentWeapon();
6830 // Åñëè åñòü âîçìîæíûå öåëè:
6831 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
6832 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6833 for a
:= 0 to High(targets
) do
6835 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
6836 if GetRnd(FDifficult
.DiagFire
) then
6838 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
6839 if FDirection
= D_LEFT
then
6840 angle
:= ANGLE_LEFTUP
6842 angle
:= ANGLE_RIGHTUP
;
6844 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6845 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6847 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6848 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6849 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6850 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6851 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6853 SetAIFlag('NEEDFIRE', '1');
6854 SetAIFlag('NEEDSEEUP', '1');
6857 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
6858 if FDirection
= D_LEFT
then
6859 angle
:= ANGLE_LEFTDOWN
6861 angle
:= ANGLE_RIGHTDOWN
;
6863 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6864 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6866 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6867 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6868 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6869 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6870 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6872 SetAIFlag('NEEDFIRE', '1');
6873 SetAIFlag('NEEDSEEDOWN', '1');
6877 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
6878 if targets
[a
].Line
and targets
[a
].Visible
and
6879 (((FDirection
= D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
6880 ((FDirection
= D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
6882 SetAIFlag('NEEDFIRE', '1');
6887 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
6888 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
6889 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
6890 40+GetInterval(FDifficult
.Cover
, 40)) then
6891 SetAIFlag('NEEDJUMP', '1');
6893 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
6894 ammo
:= GetAmmoByWeapon(FCurrWeap
);
6895 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
6896 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
6898 SetAIFlag('SELECTWEAPON', '1');
6900 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
6901 if GetAIFlag('SELECTWEAPON') = '1' then
6904 RemoveAIFlag('SELECTWEAPON');
6908 procedure TBot
.Update();
6921 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
6922 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
6924 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
6926 if g_debug_BotAIOff
= 3 then
6936 RealizeCurrentWeapon();
6943 procedure TBot
.ReleaseKey(Key
: Byte);
6952 function TBot
.KeyPressed(Key
: Word): Boolean;
6954 Result
:= FKeys
[Key
].Pressed
;
6957 function TBot
.GetAIFlag(aName
: String20
): String20
;
6963 aName
:= LowerCase(aName
);
6965 if FAIFlags
<> nil then
6966 for a
:= 0 to High(FAIFlags
) do
6967 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6969 Result
:= FAIFlags
[a
].Value
;
6974 procedure TBot
.RemoveAIFlag(aName
: String20
);
6978 if FAIFlags
= nil then Exit
;
6980 aName
:= LowerCase(aName
);
6982 for a
:= 0 to High(FAIFlags
) do
6983 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6985 if a
<> High(FAIFlags
) then
6986 for b
:= a
to High(FAIFlags
)-1 do
6987 FAIFlags
[b
] := FAIFlags
[b
+1];
6989 SetLength(FAIFlags
, Length(FAIFlags
)-1);
6994 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7002 aName
:= LowerCase(aName
);
7004 if FAIFlags
<> nil then
7005 for a
:= 0 to High(FAIFlags
) do
7006 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7012 if ok
then FAIFlags
[a
].Value
:= fValue
7015 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7016 with FAIFlags
[High(FAIFlags
)] do
7024 procedure TBot
.UpdateMove
;
7026 procedure GoLeft(Time
: Word = 1);
7028 ReleaseKey(KEY_LEFT
);
7029 ReleaseKey(KEY_RIGHT
);
7030 PressKey(KEY_LEFT
, Time
);
7031 SetDirection(D_LEFT
);
7034 procedure GoRight(Time
: Word = 1);
7036 ReleaseKey(KEY_LEFT
);
7037 ReleaseKey(KEY_RIGHT
);
7038 PressKey(KEY_RIGHT
, Time
);
7039 SetDirection(D_RIGHT
);
7042 function Rnd(a
: Word): Boolean;
7044 Result
:= Random(a
) = 0;
7047 procedure Turn(Time
: Word = 1200);
7049 if RunDirection() = D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7054 ReleaseKey(KEY_LEFT
);
7055 ReleaseKey(KEY_RIGHT
);
7058 function CanRunLeft(): Boolean;
7060 Result
:= not CollideLevel(-1, 0);
7063 function CanRunRight(): Boolean;
7065 Result
:= not CollideLevel(1, 0);
7068 function CanRun(): Boolean;
7070 if RunDirection() = D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7073 procedure Jump(Time
: Word = 30);
7075 PressKey(KEY_JUMP
, Time
);
7078 function NearHole(): Boolean;
7082 { TODO 5 : Ëåñòíèöû }
7083 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
7084 for x
:= 1 to PLAYER_RECT
.Width
do
7085 if (not StayOnStep(x
*sx
, 0)) and
7086 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7087 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7096 function BorderHole(): Boolean;
7100 { TODO 5 : Ëåñòíèöû }
7101 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
7102 for x
:= 1 to PLAYER_RECT
.Width
do
7103 if (not StayOnStep(x
*sx
, 0)) and
7104 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7105 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7107 for xx
:= x
to x
+32 do
7108 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7118 function NearDeepHole(): Boolean;
7124 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
7127 for x
:= 1 to PLAYER_RECT
.Width
do
7128 if (not StayOnStep(x
*sx
, 0)) and
7129 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7130 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7132 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7134 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7139 end else Result
:= False;
7142 function OverDeepHole(): Boolean;
7149 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7151 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7158 function OnGround(): Boolean;
7160 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7163 function OnLadder(): Boolean;
7165 Result
:= FullInStep(0, 0);
7168 function BelowLadder(): Boolean;
7170 Result
:= (FullInStep(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7171 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7172 (FullInStep(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7173 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7176 function BelowLiftUp(): Boolean;
7178 Result
:= ((FullInLift(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7179 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7180 ((FullInLift(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7181 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7184 function OnTopLift(): Boolean;
7186 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7189 function CanJumpOver(): Boolean;
7193 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
7197 if not CollideLevel(sx
, 0) then Exit
;
7199 for y
:= 1 to BOT_MAXJUMP
do
7200 if CollideLevel(0, -y
) then Exit
else
7201 if not CollideLevel(sx
, -y
) then
7208 function CanJumpUp(Dist
: ShortInt): Boolean;
7215 if CollideLevel(Dist
, 0) then Exit
;
7218 for y
:= 0 to BOT_MAXJUMP
do
7219 if CollideLevel(Dist
, -y
) then
7228 for yy
:= y
+1 to BOT_MAXJUMP
do
7229 if not CollideLevel(Dist
, -yy
) then
7238 for y
:= 0 to BOT_MAXJUMP
do
7239 if CollideLevel(0, -y
) then
7247 if y
< yy
then Exit
;
7252 function IsSafeTrigger(): Boolean;
7257 if gTriggers
= nil then
7259 for a
:= 0 to High(gTriggers
) do
7260 if Collide(gTriggers
[a
].X
,
7263 gTriggers
[a
].Height
) and
7264 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7265 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7266 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7267 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7268 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7273 // Âîçìîæíî, íàæèìàåì êíîïêó:
7274 if Rnd(16) and IsSafeTrigger() then
7277 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7278 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7280 ReleaseKey(KEY_LEFT
);
7281 ReleaseKey(KEY_RIGHT
);
7285 // Èäåì âëåâî, åñëè íàäî áûëî:
7286 if GetAIFlag('GOLEFT') <> '' then
7288 RemoveAIFlag('GOLEFT');
7289 if CanRunLeft() then
7293 // Èäåì âïðàâî, åñëè íàäî áûëî:
7294 if GetAIFlag('GORIGHT') <> '' then
7296 RemoveAIFlag('GORIGHT');
7297 if CanRunRight() then
7301 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7302 if FObj
.X
< -32 then
7305 if FObj
.X
+32 > gMapInfo
.Width
then
7308 // Ïðûãàåì, åñëè íàäî áûëî:
7309 if GetAIFlag('NEEDJUMP') <> '' then
7312 RemoveAIFlag('NEEDJUMP');
7315 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7316 if GetAIFlag('NEEDSEEUP') <> '' then
7319 ReleaseKey(KEY_DOWN
);
7320 PressKey(KEY_UP
, 20);
7321 RemoveAIFlag('NEEDSEEUP');
7324 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7325 if GetAIFlag('NEEDSEEDOWN') <> '' then
7328 ReleaseKey(KEY_DOWN
);
7329 PressKey(KEY_DOWN
, 20);
7330 RemoveAIFlag('NEEDSEEDOWN');
7333 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7334 if GetAIFlag('GOINHOLE') <> '' then
7335 if not OnGround() then
7337 ReleaseKey(KEY_LEFT
);
7338 ReleaseKey(KEY_RIGHT
);
7339 RemoveAIFlag('GOINHOLE');
7340 SetAIFlag('FALLINHOLE', '1');
7343 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7344 if GetAIFlag('FALLINHOLE') <> '' then
7346 RemoveAIFlag('FALLINHOLE');
7348 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7349 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7350 if GetAIFlag('FALLINHOLE') = '' then
7351 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7357 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7359 CanJumpUp(IfThen(RunDirection() = D_LEFT
, -1, 1)*32) and
7363 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7364 if OnGround() and NearHole() then
7365 if NearDeepHole() then // Åñëè ýòî áåçäíà
7367 0..3: Turn(); // Áåæèì îáðàòíî
7368 4: Jump(); // Ïðûãàåì
7369 5: begin // Ïðûãàåì îáðàòíî
7374 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7375 if GetAIFlag('GOINHOLE') = '' then
7377 0: Turn(); // Íå íóæíî òóäà
7378 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7379 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7380 if BorderHole() then
7381 SetAIFlag('GOINHOLE', '1');
7384 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7385 if (not CanRun()) and OnGround() then
7387 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7388 if CanJumpOver() or OnLadder() then
7390 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7391 if Random(2) = 0 then
7393 if IsSafeTrigger() then
7399 // Îñòàëîñü ìàëî âîçäóõà:
7400 if FAir
< 36 * 2 then
7403 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7404 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7405 if BodyInAcid(0, 0) then
7409 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7411 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7412 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7415 {function TBot.NeedItem(Item: Byte): Byte;
7420 procedure TBot
.SelectWeapon(Dist
: Integer);
7424 function HaveAmmo(weapon
: Byte): Boolean;
7427 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7428 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7429 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7430 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7431 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7432 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7433 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7434 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7435 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7436 else Result
:= True;
7441 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7443 if Dist
> BOT_LONGDIST
then
7444 begin // Äàëüíèé áîé
7446 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7448 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7452 else //if Dist > BOT_UNSAFEDIST then
7453 begin // Áëèæíèé áîé
7455 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7457 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7464 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7466 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7472 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7474 Result
:= inherited PickItem(ItemType
, force
, remove
);
7476 if Result
then SetAIFlag('SELECTWEAPON', '1');
7479 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7481 Result
:= inherited Heal(value
, Soft
);
7484 function TBot
.Healthy(): Byte;
7486 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7487 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7488 else if (FHealth
> 50) then Result
:= 2
7489 else if (FHealth
> 20) then Result
:= 1
7493 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7495 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7496 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7499 procedure TBot
.OnDamage(Angle
: SmallInt);
7507 if (Angle
= 0) or (Angle
= 180) then
7510 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7511 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7513 pla
:= g_Player_Get(FLastSpawnerUID
);
7514 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7515 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7518 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7519 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7521 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7522 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7523 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7528 SetAIFlag('ATTACKLEFT', '1')
7530 SetAIFlag('ATTACKRIGHT', '1');
7534 function TBot
.RunDirection(): TDirection
;
7536 if Abs(Vel
.X
) >= 1 then
7538 if Vel
.X
> 0 then Result
:= D_RIGHT
else Result
:= D_LEFT
;
7540 Result
:= FDirection
;
7543 function TBot
.GetRnd(a
: Byte): Boolean;
7545 if a
= 0 then Result
:= False
7546 else if a
= 255 then Result
:= True
7547 else Result
:= Random(256) > 255-a
;
7550 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7552 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7555 procedure TBot
.SaveState(var Mem
: TBinMemoryWriter
);
7561 inherited SaveState(Mem
);
7563 // Âûáðàííîå îðóæèå:
7564 Mem
.WriteByte(FSelectedWeapon
);
7566 Mem
.WriteWord(FTargetUID
);
7567 // Âðåìÿ ïîòåðè öåëè:
7568 Mem
.WriteDWORD(FLastVisible
);
7569 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7570 dw
:= Length(FAIFlags
);
7573 for i
:= 0 to Integer(dw
)-1 do
7575 Mem
.WriteString(FAIFlags
[i
].Name
, 20);
7576 Mem
.WriteString(FAIFlags
[i
].Value
, 20);
7578 // Íàñòðîéêè ñëîæíîñòè:
7580 Mem
.WriteMemory(p
, SizeOf(TDifficult
));
7583 procedure TBot
.LoadState(var Mem
: TBinMemoryReader
);
7589 inherited LoadState(Mem
);
7591 // Âûáðàííîå îðóæèå:
7592 Mem
.ReadByte(FSelectedWeapon
);
7594 Mem
.ReadWord(FTargetUID
);
7595 // Âðåìÿ ïîòåðè öåëè:
7596 Mem
.ReadDWORD(FLastVisible
);
7597 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7599 SetLength(FAIFlags
, dw
);
7601 for i
:= 0 to Integer(dw
)-1 do
7603 Mem
.ReadString(FAIFlags
[i
].Name
);
7604 Mem
.ReadString(FAIFlags
[i
].Value
);
7606 // Íàñòðîéêè ñëîæíîñòè:
7607 Mem
.ReadMemory(p
, dw
);
7608 if dw
<> SizeOf(TDifficult
) then
7610 raise EBinSizeError
.Create('TBot.LoadState: Wrong FDifficult Size');
7612 FDifficult
:= TDifficult(p
^);