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 property Obj
: TObj read FObj
;
475 property State
: Byte read FState
;
476 property Mess
: Boolean read FMess
;
479 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
485 gPlayers
: Array of TPlayer
;
486 gCorpses
: Array of TCorpse
;
487 gGibs
: Array of TGib
;
488 gShells
: Array of TShell
;
489 gTeamStat
: TTeamStat
;
490 gFly
: Boolean = False;
491 gAimLine
: Boolean = False;
492 gChatBubble
: Byte = 0;
496 MAX_RUNVEL
: Integer = 8;
497 VEL_JUMP
: Integer = 10;
498 SHELL_TIMEOUT
: Cardinal = 60000;
500 function Lerp(X
, Y
, Factor
: Integer): Integer;
502 procedure g_Gibs_SetMax(Count
: Word);
503 function g_Gibs_GetMax(): Word;
504 procedure g_Corpses_SetMax(Count
: Word);
505 function g_Corpses_GetMax(): Word;
506 procedure g_Shells_SetMax(Count
: Word);
507 function g_Shells_GetMax(): Word;
509 procedure g_Player_Init();
510 procedure g_Player_Free();
511 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
512 function g_Player_CreateFromState(var Mem
: TBinMemoryReader
): Word;
513 procedure g_Player_Remove(UID
: Word);
514 procedure g_Player_ResetTeams();
515 procedure g_Player_UpdateAll();
516 procedure g_Player_DrawAll();
517 procedure g_Player_DrawDebug(p
: TPlayer
);
518 procedure g_Player_DrawHealth();
519 procedure g_Player_RememberAll();
520 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
521 function g_Player_Get(UID
: Word): TPlayer
;
522 function g_Player_GetCount(): Byte;
523 function g_Player_GetStats(): TPlayerStatArray
;
524 function g_Player_ValidName(Name
: String): Boolean;
525 procedure g_Player_CreateCorpse(Player
: TPlayer
);
526 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
527 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
528 procedure g_Player_UpdatePhysicalObjects();
529 procedure g_Player_DrawCorpses();
530 procedure g_Player_DrawShells();
531 procedure g_Player_RemoveAllCorpses();
532 procedure g_Player_Corpses_SaveState(var Mem
: TBinMemoryWriter
);
533 procedure g_Player_Corpses_LoadState(var Mem
: TBinMemoryReader
);
534 procedure g_Bot_Add(Team
, Difficult
: Byte);
535 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1);
536 procedure g_Bot_MixNames();
537 procedure g_Bot_RemoveAll();
542 e_log
, g_map
, g_items
, g_console
, SysUtils
, g_gfx
, Math
,
543 g_options
, g_triggers
, g_menu
, g_game
, g_grid
,
544 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
,
545 g_net
, g_netmsg
, g_window
, GL
, g_holmes
;
555 diag_precision
: Byte;
559 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
560 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
561 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
565 TIME_RESPAWN1
= 1500;
566 TIME_RESPAWN2
= 2000;
567 TIME_RESPAWN3
= 3000;
570 JET_MAX
= 540; // ~30 sec
571 PLAYER_SUIT_TIME
= 30000;
572 PLAYER_INVUL_TIME
= 30000;
573 PLAYER_INVIS_TIME
= 35000;
574 FRAG_COMBO_TIME
= 3000;
578 ANGLE_RIGHTDOWN
= -35;
580 ANGLE_LEFTDOWN
= -145;
581 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
582 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
585 BOT_UNSAFEDIST
= 128;
586 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
588 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
589 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
590 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
591 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
592 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
593 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
594 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
595 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
596 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
597 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
598 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
599 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
600 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
601 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
602 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
603 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
604 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
605 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
606 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
607 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
608 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
609 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
610 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
611 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
612 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
613 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
615 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
616 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
618 BOTNAMES_FILENAME
= 'botnames.txt';
619 BOTLIST_FILENAME
= 'botlist.txt';
623 MaxCorpses
: Word = 20;
624 MaxShells
: Word = 300;
625 CurrentGib
: Integer = 0;
626 CurrentShell
: Integer = 0;
627 BotNames
: Array of String;
628 BotList
: Array of TBotProfile
;
631 function Lerp(X
, Y
, Factor
: Integer): Integer;
633 Result
:= X
+ ((Y
- X
) div Factor
);
636 function SameTeam(UID1
, UID2
: Word): Boolean;
640 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
641 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
643 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
645 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
646 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
648 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
651 procedure g_Gibs_SetMax(Count
: Word);
654 SetLength(gGibs
, Count
);
656 if CurrentGib
>= Count
then
660 function g_Gibs_GetMax(): Word;
665 procedure g_Shells_SetMax(Count
: Word);
668 SetLength(gShells
, Count
);
670 if CurrentShell
>= Count
then
674 function g_Shells_GetMax(): Word;
680 procedure g_Corpses_SetMax(Count
: Word);
683 SetLength(gCorpses
, Count
);
686 function g_Corpses_GetMax(): Word;
688 Result
:= MaxCorpses
;
691 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
701 // Åñòü ëè ìåñòî â gPlayers:
702 if gPlayers
<> nil then
703 for a
:= 0 to High(gPlayers
) do
704 if gPlayers
[a
] = nil then
710 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
713 SetLength(gPlayers
, Length(gPlayers
)+1);
717 // Ñîçäàåì îáúåêò èãðîêà:
719 gPlayers
[a
] := TBot
.Create()
721 gPlayers
[a
] := TPlayer
.Create();
724 gPlayers
[a
].FActualModelName
:= ModelName
;
725 gPlayers
[a
].SetModel(ModelName
);
727 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
728 if gPlayers
[a
].FModel
= nil then
732 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
736 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
737 if Random(2) = 0 then
741 gPlayers
[a
].FPreferredTeam
:= Team
;
743 case gGameSettings
.GameMode
of
744 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
746 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
748 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
751 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
752 gPlayers
[a
].FColor
:= Color
;
753 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
754 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
756 gPlayers
[a
].FModel
.Color
:= Color
;
758 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
759 gPlayers
[a
].FAlive
:= False;
761 Result
:= gPlayers
[a
].FUID
;
764 function g_Player_CreateFromState(var Mem
: TBinMemoryReader
): Word;
777 if sig
<> PLAYER_SIGNATURE
then // 'PLYR'
779 raise EBinSizeError
.Create('g_Player_CreateFromState: Wrong Player Signature');
783 Mem
.ReadBoolean(Bot
);
788 // Åñòü ëè ìåñòî â gPlayers:
789 if gPlayers
<> nil then
790 for a
:= 0 to High(gPlayers
) do
791 if gPlayers
[a
] = nil then
797 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
800 SetLength(gPlayers
, Length(gPlayers
)+1);
804 // Ñîçäàåì îáúåêò èãðîêà:
806 gPlayers
[a
] := TBot
.Create()
808 gPlayers
[a
] := TPlayer
.Create();
809 gPlayers
[a
].FIamBot
:= Bot
;
810 gPlayers
[a
].FPhysics
:= True;
813 Mem
.ReadWord(gPlayers
[a
].FUID
);
815 Mem
.ReadString(gPlayers
[a
].FName
);
817 Mem
.ReadByte(gPlayers
[a
].FTeam
);
818 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
820 Mem
.ReadBoolean(gPlayers
[a
].FAlive
);
821 // Èçðàñõîäîâàë ëè âñå æèçíè:
822 Mem
.ReadBoolean(gPlayers
[a
].FNoRespawn
);
826 gPlayers
[a
].FDirection
:= D_LEFT
828 gPlayers
[a
].FDirection
:= D_RIGHT
;
830 Mem
.ReadInt(gPlayers
[a
].FHealth
);
832 Mem
.ReadByte(gPlayers
[a
].FLives
);
834 Mem
.ReadInt(gPlayers
[a
].FArmor
);
836 Mem
.ReadInt(gPlayers
[a
].FAir
);
838 Mem
.ReadInt(gPlayers
[a
].FJetFuel
);
840 Mem
.ReadInt(gPlayers
[a
].FPain
);
842 Mem
.ReadInt(gPlayers
[a
].FKills
);
844 Mem
.ReadInt(gPlayers
[a
].FMonsterKills
);
846 Mem
.ReadInt(gPlayers
[a
].FFrags
);
848 Mem
.ReadByte(gPlayers
[a
].FFragCombo
);
849 // Âðåìÿ ïîñëåäíåãî ôðàãà:
850 Mem
.ReadDWORD(gPlayers
[a
].FLastFrag
);
852 Mem
.ReadInt(gPlayers
[a
].FDeath
);
854 Mem
.ReadByte(gPlayers
[a
].FFlag
);
856 Mem
.ReadInt(gPlayers
[a
].FSecrets
);
858 Mem
.ReadByte(gPlayers
[a
].FCurrWeap
);
859 // Ñëåäóþùåå æåëàåìîå îðóæèå:
860 Mem
.ReadWord(gPlayers
[a
].FNextWeap
);
862 Mem
.ReadByte(gPlayers
[a
].FNextWeapDelay
);
863 // Âðåìÿ çàðÿäêè BFG:
864 Mem
.ReadSmallInt(gPlayers
[a
].FBFGFireCounter
);
866 Mem
.ReadInt(gPlayers
[a
].FDamageBuffer
);
867 // Ïîñëåäíèé óäàðèâøèé:
868 Mem
.ReadWord(gPlayers
[a
].FLastSpawnerUID
);
869 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
870 Mem
.ReadByte(gPlayers
[a
].FLastHit
);
872 Obj_LoadState(@gPlayers
[a
].FObj
, Mem
);
873 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
874 for i
:= A_BULLETS
to A_HIGH
do
875 Mem
.ReadWord(gPlayers
[a
].FAmmo
[i
]);
876 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
877 for i
:= A_BULLETS
to A_HIGH
do
878 Mem
.ReadWord(gPlayers
[a
].FMaxAmmo
[i
]);
880 for i
:= WP_FIRST
to WP_LAST
do
881 Mem
.ReadBoolean(gPlayers
[a
].FWeapon
[i
]);
882 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
883 for i
:= WP_FIRST
to WP_LAST
do
884 Mem
.ReadWord(gPlayers
[a
].FReloading
[i
]);
888 Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
889 // Íàëè÷èå êðàñíîãî êëþ÷à:
892 Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
893 // Íàëè÷èå çåëåíîãî êëþ÷à:
896 Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
897 // Íàëè÷èå ñèíåãî êëþ÷à:
900 Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
904 Include(gPlayers
[a
].FRulez
, R_BERSERK
);
905 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
906 for i
:= MR_SUIT
to MR_MAX
do
907 Mem
.ReadDWORD(gPlayers
[a
].FMegaRulez
[i
]);
908 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
909 for i
:= T_RESPAWN
to T_FLAGCAP
do
910 Mem
.ReadDWORD(gPlayers
[a
].FTime
[i
]);
913 Mem
.ReadString(gPlayers
[a
].FActualModelName
);
915 Mem
.ReadByte(gPlayers
[a
].FColor
.R
);
916 Mem
.ReadByte(gPlayers
[a
].FColor
.G
);
917 Mem
.ReadByte(gPlayers
[a
].FColor
.B
);
918 // Îáíîâëÿåì ìîäåëü èãðîêà:
919 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
921 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
922 if gPlayers
[a
].FModel
= nil then
926 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
930 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
931 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
932 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
934 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
936 Result
:= gPlayers
[a
].FUID
;
939 procedure g_Player_ResetTeams();
943 if g_Game_IsClient
then
945 if gPlayers
= nil then
947 for a
:= Low(gPlayers
) to High(gPlayers
) do
948 if gPlayers
[a
] <> nil then
949 case gGameSettings
.GameMode
of
951 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
953 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
954 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
955 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
958 gPlayers
[a
].ChangeTeam(TEAM_RED
)
960 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
963 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
967 procedure g_Bot_Add(Team
, Difficult
: Byte);
970 _name
, _model
: String;
973 if not g_Game_IsServer
then Exit
;
975 // Ñïèñîê íàçâàíèé ìîäåëåé:
976 m
:= g_PlayerModel_GetNames();
981 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
982 Team
:= TEAM_COOP
// COOP
984 if gGameSettings
.GameMode
= GM_DM
then
985 Team
:= TEAM_NONE
// DM
987 if Team
= TEAM_NONE
then // CTF / TDM
989 // Àâòîáàëàíñ êîìàíä:
993 for a
:= 0 to High(gPlayers
) do
994 if gPlayers
[a
] <> nil then
996 if gPlayers
[a
].Team
= TEAM_RED
then
999 if gPlayers
[a
].Team
= TEAM_BLUE
then
1009 if Random(2) = 0 then
1015 // Âûáèðàåì áîòó èìÿ:
1017 if BotNames
<> nil then
1018 for a
:= 0 to High(BotNames
) do
1019 if g_Player_ValidName(BotNames
[a
]) then
1021 _name
:= BotNames
[a
];
1025 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
1028 _name
:= Format('DFBOT%.2d', [Random(100)]);
1029 until g_Player_ValidName(_name
);
1031 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1032 _model
:= m
[Random(Length(m
))];
1035 with g_Player_Get(g_Player_Create(_model
,
1036 _RGB(Min(Random(9)*32, 255),
1037 Min(Random(9)*32, 255),
1038 Min(Random(9)*32, 255)),
1039 Team
, True)) as TBot
do
1044 1: FDifficult
:= DIFFICULT_EASY
;
1045 2: FDifficult
:= DIFFICULT_MEDIUM
;
1046 else FDifficult
:= DIFFICULT_HARD
;
1049 for a
:= WP_FIRST
to WP_LAST
do
1051 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1052 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1053 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1056 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1058 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1059 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1064 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1);
1067 _name
, _model
: String;
1070 if not g_Game_IsServer
then Exit
;
1072 // Ñïèñîê íàçâàíèé ìîäåëåé:
1073 m
:= g_PlayerModel_GetNames();
1078 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1079 Team
:= TEAM_COOP
// COOP
1081 if gGameSettings
.GameMode
= GM_DM
then
1082 Team
:= TEAM_NONE
// DM
1084 if Team
= TEAM_NONE
then
1085 Team
:= BotList
[num
].team
; // CTF / TDM
1087 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1088 lName
:= AnsiLowerCase(lName
);
1089 if (num
< 0) or (num
> Length(BotList
)-1) then
1091 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1092 for a
:= 0 to High(BotList
) do
1093 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1102 _name
:= BotList
[num
].name
;
1103 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1104 if not g_Player_ValidName(_name
) then
1106 _name
:= Format('DFBOT%.2d', [Random(100)]);
1107 until g_Player_ValidName(_name
);
1110 _model
:= BotList
[num
].model
;
1111 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1112 if not InSArray(_model
, m
) then
1113 _model
:= m
[Random(Length(m
))];
1116 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1120 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1121 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1122 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1123 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1124 FDifficult
.Cover
:= BotList
[num
].cover
;
1125 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1127 for a
:= WP_FIRST
to WP_LAST
do
1129 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1130 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1131 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1134 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1136 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1140 procedure g_Bot_RemoveAll();
1144 if not g_Game_IsServer
then Exit
;
1145 if gPlayers
= nil then Exit
;
1147 for a
:= 0 to High(gPlayers
) do
1148 if gPlayers
[a
] <> nil then
1149 if gPlayers
[a
] is TBot
then
1151 gPlayers
[a
].Lives
:= 0;
1152 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1153 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1154 g_Player_Remove(gPlayers
[a
].FUID
);
1160 procedure g_Bot_MixNames();
1165 if BotNames
<> nil then
1166 for a
:= 0 to High(BotNames
) do
1168 b
:= Random(Length(BotNames
));
1170 Botnames
[a
] := BotNames
[b
];
1175 procedure g_Player_Remove(UID
: Word);
1179 if gPlayers
= nil then Exit
;
1181 if g_Game_IsServer
and g_Game_IsNet
then
1182 MH_SEND_PlayerDelete(UID
);
1184 for i
:= 0 to High(gPlayers
) do
1185 if gPlayers
[i
] <> nil then
1186 if gPlayers
[i
].FUID
= UID
then
1188 if gPlayers
[i
] is TPlayer
then
1189 TPlayer(gPlayers
[i
]).Free()
1191 TBot(gPlayers
[i
]).Free();
1197 procedure g_Player_Init();
1207 if not FileExists(DataDir
+ BOTNAMES_FILENAME
) then
1210 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1211 AssignFile(F
, DataDir
+ BOTNAMES_FILENAME
);
1222 SetLength(BotNames
, Length(BotNames
)+1);
1223 BotNames
[High(BotNames
)] := s
;
1231 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1232 config
:= TConfig
.CreateFile(DataDir
+ BOTLIST_FILENAME
);
1236 while config
.SectionExists(IntToStr(a
)) do
1238 SetLength(BotList
, Length(BotList
)+1);
1240 with BotList
[High(BotList
)] do
1243 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1245 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1247 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1252 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1253 color
.R
:= StrToIntDef(sa
[0], 0);
1254 color
.G
:= StrToIntDef(sa
[1], 0);
1255 color
.B
:= StrToIntDef(sa
[2], 0);
1256 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1257 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1258 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1259 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1260 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1261 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1262 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1263 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1264 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1265 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1266 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1267 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1268 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1269 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1270 if Length(sa
) = 10 then
1272 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1273 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1274 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1275 if Length(sa
) = 10 then
1277 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1279 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1280 if Length(sa) = 10 then
1282 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1291 procedure g_Player_Free();
1295 if gPlayers
<> nil then
1297 for i
:= 0 to High(gPlayers
) do
1298 if gPlayers
[i
] <> nil then
1300 if gPlayers
[i
] is TPlayer
then
1301 TPlayer(gPlayers
[i
]).Free()
1303 TBot(gPlayers
[i
]).Free();
1314 procedure g_Player_UpdateAll();
1318 if gPlayers
= nil then Exit
;
1320 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1321 for i
:= 0 to High(gPlayers
) do
1323 if gPlayers
[i
] <> nil then
1325 if gPlayers
[i
] is TPlayer
then
1327 gPlayers
[i
].Update();
1328 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1332 // bot updates weapons in `UpdateCombat()`
1333 TBot(gPlayers
[i
]).Update();
1337 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1340 procedure g_Player_DrawAll();
1344 if gPlayers
= nil then Exit
;
1346 for i
:= 0 to High(gPlayers
) do
1347 if gPlayers
[i
] <> nil then
1348 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1349 else TBot(gPlayers
[i
]).Draw();
1352 procedure g_Player_DrawDebug(p
: TPlayer
);
1356 if p
= nil then Exit
;
1357 if (@p
.FObj
) = nil then Exit
;
1359 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1361 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1362 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1363 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1364 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1365 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1366 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1369 procedure g_Player_DrawHealth();
1374 if gPlayers
= nil then Exit
;
1375 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1377 for i
:= 0 to High(gPlayers
) do
1378 if gPlayers
[i
] <> nil then
1380 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1381 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1382 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1383 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1384 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1385 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1389 function g_Player_Get(UID
: Word): TPlayer
;
1395 if gPlayers
= nil then
1398 for a
:= 0 to High(gPlayers
) do
1399 if gPlayers
[a
] <> nil then
1400 if gPlayers
[a
].FUID
= UID
then
1402 Result
:= gPlayers
[a
];
1407 function g_Player_GetCount(): Byte;
1413 if gPlayers
= nil then
1416 for a
:= 0 to High(gPlayers
) do
1417 if gPlayers
[a
] <> nil then
1418 Result
:= Result
+ 1;
1421 function g_Player_GetStats(): TPlayerStatArray
;
1427 if gPlayers
= nil then Exit
;
1429 for a
:= 0 to High(gPlayers
) do
1430 if gPlayers
[a
] <> nil then
1432 SetLength(Result
, Length(Result
)+1);
1433 with Result
[High(Result
)] do
1435 Ping
:= gPlayers
[a
].FPing
;
1436 Loss
:= gPlayers
[a
].FLoss
;
1437 Name
:= gPlayers
[a
].FName
;
1438 Team
:= gPlayers
[a
].FTeam
;
1439 Frags
:= gPlayers
[a
].FFrags
;
1440 Deaths
:= gPlayers
[a
].FDeath
;
1441 Kills
:= gPlayers
[a
].FKills
;
1442 Color
:= gPlayers
[a
].FModel
.Color
;
1443 Lives
:= gPlayers
[a
].FLives
;
1444 Spectator
:= gPlayers
[a
].FSpectator
;
1449 procedure g_Player_RememberAll
;
1453 for i
:= Low(gPlayers
) to High(gPlayers
) do
1454 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1455 gPlayers
[i
].RememberState
;
1458 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1462 gTeamStat
[TEAM_RED
].Goals
:= 0;
1463 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1465 if gPlayers
<> nil then
1466 for i
:= 0 to High(gPlayers
) do
1467 if gPlayers
[i
] <> nil then
1469 gPlayers
[i
].Reset(Force
);
1471 if gPlayers
[i
] is TPlayer
then
1473 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1474 gPlayers
[i
].Respawn(Silent
)
1476 gPlayers
[i
].Spectate();
1479 TBot(gPlayers
[i
]).Respawn(Silent
);
1483 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1488 if Player
.alive
then
1490 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1495 if (FHealth
>= -50) or (gGibsCount
= 0) then
1497 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1501 for find_id
:= 0 to High(gCorpses
) do
1502 if gCorpses
[find_id
] = nil then
1509 find_id
:= Random(Length(gCorpses
));
1511 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1512 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1513 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1514 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1517 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1518 FObj
.Y
+ PLAYER_RECT_CY
,
1519 FModel
.Name
, FModel
.Color
);
1523 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1527 if (gShells
= nil) or (Length(gShells
) = 0) then
1530 with gShells
[CurrentShell
] do
1536 if T
= SHELL_BULLET
then
1538 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1542 Obj
.Rect
.Width
:= 4;
1543 Obj
.Rect
.Height
:= 2;
1547 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1551 Obj
.Rect
.Width
:= 7;
1552 Obj
.Rect
.Height
:= 3;
1558 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1559 positionChanged(); // this updates spatial accelerators
1560 RAngle
:= Random(360);
1561 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1563 if CurrentShell
>= High(gShells
) then
1570 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1573 GibsArray
: TGibsArray
;
1575 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1577 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1580 for a
:= 0 to High(GibsArray
) do
1581 with gGibs
[CurrentGib
] do
1584 ID
:= GibsArray
[a
].ID
;
1585 MaskID
:= GibsArray
[a
].MaskID
;
1588 Obj
.Rect
:= GibsArray
[a
].Rect
;
1589 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1590 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1591 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1592 positionChanged(); // this updates spatial accelerators
1593 RAngle
:= Random(360);
1595 if gBloodCount
> 0 then
1596 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1597 Random(48), Random(48), 150, 0, 0);
1599 if CurrentGib
>= High(gGibs
) then
1606 procedure g_Player_UpdatePhysicalObjects();
1612 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1617 if T
= SHELL_BULLET
then
1618 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1620 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1625 if gGibs
<> nil then
1626 for i
:= 0 to High(gGibs
) do
1627 if gGibs
[i
].alive
then
1631 mr
:= g_Obj_Move(@Obj
, True, False, True);
1632 positionChanged(); // this updates spatial accelerators
1634 if WordBool(mr
and MOVE_FALLOUT
) then
1640 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1641 if WordBool(mr
and MOVE_HITWALL
) then
1642 Obj
.Vel
.X
:= -(vel
.X
div 2);
1643 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1644 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1646 if (Obj
.Vel
.X
>= 0) then
1648 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1649 if RAngle
>= 360 then
1650 RAngle
:= RAngle
mod 360;
1651 end else begin // Counter-clockwise
1652 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1654 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1657 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1658 if gTime
mod (GAME_TICK
*3) = 0 then
1659 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1663 if gCorpses
<> nil then
1664 for i
:= 0 to High(gCorpses
) do
1665 if gCorpses
[i
] <> nil then
1666 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1672 gCorpses
[i
].Update();
1675 if gShells
<> nil then
1676 for i
:= 0 to High(gShells
) do
1677 if gShells
[i
].alive
then
1681 mr
:= g_Obj_Move(@Obj
, True, False, True);
1682 positionChanged(); // this updates spatial accelerators
1684 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1690 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1691 if WordBool(mr
and MOVE_HITWALL
) then
1693 Obj
.Vel
.X
:= -(vel
.X
div 2);
1694 if not WordBool(mr
and MOVE_INWATER
) then
1695 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1697 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1699 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1700 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1701 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1703 if RAngle
mod 90 <> 0 then
1704 RAngle
:= (RAngle
div 90) * 90;
1706 else if not WordBool(mr
and MOVE_INWATER
) then
1707 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1710 if (Obj
.Vel
.X
>= 0) then
1712 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1713 if RAngle
>= 360 then
1714 RAngle
:= RAngle
mod 360;
1715 end else begin // Counter-clockwise
1716 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1718 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1724 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1726 x
:= Obj
.X
+Obj
.Rect
.X
;
1727 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1728 w
:= Obj
.Rect
.Width
;
1729 h
:= Obj
.Rect
.Height
;
1732 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1734 if (dx
<> 0) or (dy
<> 0) then
1743 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1747 w
:= Obj
.Rect
.Width
;
1748 h
:= Obj
.Rect
.Height
;
1751 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1753 if (dx
<> 0) or (dy
<> 0) then
1762 procedure TGib
.positionChanged (); inline; begin end;
1763 procedure TShell
.positionChanged (); inline; begin end;
1766 procedure g_Player_DrawCorpses();
1771 if gGibs
<> nil then
1772 for i
:= 0 to High(gGibs
) do
1773 if gGibs
[i
].alive
then
1776 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1779 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1780 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1782 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1785 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1791 if gCorpses
<> nil then
1792 for i
:= 0 to High(gCorpses
) do
1793 if gCorpses
[i
] <> nil then
1797 procedure g_Player_DrawShells();
1802 if gShells
<> nil then
1803 for i
:= 0 to High(gShells
) do
1804 if gShells
[i
].alive
then
1807 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1813 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1817 procedure g_Player_RemoveAllCorpses();
1823 SetLength(gGibs
, MaxGibs
);
1824 SetLength(gShells
, MaxGibs
);
1828 if gCorpses
<> nil then
1829 for i
:= 0 to High(gCorpses
) do
1833 SetLength(gCorpses
, MaxCorpses
);
1836 procedure g_Player_Corpses_SaveState(var Mem
: TBinMemoryWriter
);
1841 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ:
1843 if gCorpses
<> nil then
1844 for i
:= 0 to High(gCorpses
) do
1845 if gCorpses
[i
] <> nil then
1848 Mem
:= TBinMemoryWriter
.Create((count
+1) * 128);
1850 // Êîëè÷åñòâî òðóïîâ:
1851 Mem
.WriteInt(count
);
1857 for i
:= 0 to High(gCorpses
) do
1858 if gCorpses
[i
] <> nil then
1861 Mem
.WriteString(gCorpses
[i
].FModelName
);
1863 b
:= gCorpses
[i
].Mess
;
1864 Mem
.WriteBoolean(b
);
1865 // Ñîõðàíÿåì äàííûå òðóïà:
1866 gCorpses
[i
].SaveState(Mem
);
1870 procedure g_Player_Corpses_LoadState(var Mem
: TBinMemoryReader
);
1879 g_Player_RemoveAllCorpses();
1881 // Êîëè÷åñòâî òðóïîâ:
1884 if count
> Length(gCorpses
) then
1886 raise EBinSizeError
.Create('g_Player_Corpses_LoadState: Too Many Corpses');
1893 for i
:= 0 to count
-1 do
1896 Mem
.ReadString(str
);
1900 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1901 // Çàãðóæàåì äàííûå òðóïà:
1902 gCorpses
[i
].LoadState(Mem
);
1908 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1910 procedure TPlayer
.BFGHit();
1912 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1913 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1914 if g_Game_IsServer
and g_Game_IsNet
then
1915 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1916 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1920 procedure TPlayer
.ChangeModel(ModelName
: string);
1922 locModel
: TPlayerModel
;
1924 locModel
:= g_PlayerModel_Get(ModelName
);
1925 if locModel
= nil then Exit
;
1931 procedure TPlayer
.SetModel(ModelName
: string);
1935 m
:= g_PlayerModel_Get(ModelName
);
1938 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1939 m
:= g_PlayerModel_Get('doomer');
1942 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1947 if FModel
<> nil then
1952 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1953 FModel
.Color
:= FColor
1955 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1956 FModel
.SetWeapon(FCurrWeap
);
1957 FModel
.SetFlag(FFlag
);
1958 SetDirection(FDirection
);
1961 procedure TPlayer
.SetColor(Color
: TRGB
);
1964 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1965 if FModel
<> nil then FModel
.Color
:= Color
;
1968 procedure TPlayer
.SwitchTeam
;
1970 if g_Game_IsClient
then
1972 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
1974 if gGameOn
and FAlive
then
1975 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
1977 if FTeam
= TEAM_RED
then
1979 ChangeTeam(TEAM_BLUE
);
1980 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
1981 if g_Game_IsNet
then
1982 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
1986 ChangeTeam(TEAM_RED
);
1987 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
1988 if g_Game_IsNet
then
1989 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
1991 FPreferredTeam
:= FTeam
;
1994 procedure TPlayer
.ChangeTeam(Team
: Byte);
2001 TEAM_RED
, TEAM_BLUE
:
2002 FModel
.Color
:= TEAMCOLOR
[Team
];
2004 FModel
.Color
:= FColor
;
2006 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2007 MH_SEND_PlayerStats(FUID
);
2011 procedure TPlayer.CollideItem();
2016 if gItems = nil then Exit;
2017 if not FAlive then Exit;
2019 for i := 0 to High(gItems) do
2022 if (ItemType <> ITEM_NONE) and alive then
2023 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2024 PLAYER_RECT.Height, @Obj) then
2026 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2028 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2029 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2030 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2031 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2032 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2034 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2035 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2036 (gGameSettings.GameType = GT_SINGLE) and
2037 (g_Player_GetCount() > 1)) then
2038 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2044 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2046 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2047 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2051 constructor TPlayer
.Create();
2062 FSawSound
:= TPlayableSound
.Create();
2063 FSawSoundIdle
:= TPlayableSound
.Create();
2064 FSawSoundHit
:= TPlayableSound
.Create();
2065 FSawSoundSelect
:= TPlayableSound
.Create();
2066 FJetSoundFly
:= TPlayableSound
.Create();
2067 FJetSoundOn
:= TPlayableSound
.Create();
2068 FJetSoundOff
:= TPlayableSound
.Create();
2070 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2071 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2072 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2073 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2074 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2075 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2076 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2078 FSpectatePlayer
:= -1;
2082 FSavedState
.WaitRecall
:= False;
2088 FActualModelName
:= 'doomer';
2091 FObj
.Rect
:= PLAYER_RECT
;
2093 FBFGFireCounter
:= -1;
2094 FJustTeleported
:= False;
2100 procedure TPlayer
.positionChanged (); inline;
2104 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2108 if (not g_Game_IsClient
) and (not FAlive
) then
2113 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2114 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2116 if not g_Game_IsClient
then
2119 if t
= HIT_TRAP
then
2121 // Ëîâóøêà óáèâàåò ñðàçó:
2123 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2125 if t
= HIT_SELF
then
2129 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2132 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2133 FMegaRulez
[MR_SUIT
] := 0;
2134 FMegaRulez
[MR_INVUL
] := 0;
2135 FMegaRulez
[MR_INVIS
] := 0;
2139 // Íî îò îñòàëüíîãî ñïàñàåò:
2140 if FMegaRulez
[MR_INVUL
] >= gTime
then
2147 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2148 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2149 (SpawnerUID
= FUID
) or
2150 (not SameTeam(FUID
, SpawnerUID
)) then
2152 FLastSpawnerUID
:= SpawnerUID
;
2154 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2155 if gBloodCount
> 0 then
2157 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2158 if value
div 4 <= c
then
2159 c
:= c
- (value
div 4)
2163 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2167 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2168 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2171 if t
= HIT_WATER
then
2172 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2173 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2178 Inc(FDamageBuffer
, value
);
2182 FPain
:= FPain
+ value
;
2185 if g_Game_IsServer
and g_Game_IsNet
then
2187 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2188 MH_SEND_PlayerStats(FUID
);
2189 MH_SEND_PlayerPos(False, FUID
);
2193 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2196 if g_Game_IsClient
then
2201 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2203 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2206 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2208 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2212 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2213 MH_SEND_PlayerStats(FUID
);
2216 destructor TPlayer
.Destroy();
2218 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2220 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2224 FSawSoundIdle
.Free();
2225 FSawSoundHit
.Free();
2226 FJetSoundFly
.Free();
2228 FJetSoundOff
.Free();
2234 procedure TPlayer
.DrawBubble();
2236 bubX
, bubY
: Integer;
2239 Rw
, Gw
, Bw
: SmallInt;
2242 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= D_LEFT
, -4, 18);
2243 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2251 1: // simple textual non-bubble
2253 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2254 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2255 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2258 2: // advanced pixel-perfect bubble
2260 if FTeam
= TEAM_RED
then
2263 if FTeam
= TEAM_BLUE
then
2266 3: // colored bubble
2268 Rb
:= FModel
.Color
.R
;
2269 Gb
:= FModel
.Color
.G
;
2270 Bb
:= FModel
.Color
.B
;
2271 Rw
:= Min(Rb
* 2 + 64, 255);
2272 Gw
:= Min(Gb
* 2 + 64, 255);
2273 Bw
:= Min(Bb
* 2 + 64, 255);
2274 if (Abs(Rw
- Rb
) < 32)
2275 or (Abs(Gw
- Gb
) < 32)
2276 or (Abs(Bw
- Bb
) < 32) then
2278 Rb
:= Max(Rw
div 2 - 16, 0);
2279 Gb
:= Max(Gw
div 2 - 16, 0);
2280 Bb
:= Max(Bw
div 2 - 16, 0);
2283 4: // custom textured bubble
2285 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2286 if FDirection
= D_RIGHT
then
2287 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2289 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, M_HORIZONTAL
);
2295 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2296 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2298 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2301 Dot
:= IfThen(FDirection
= D_LEFT
, 14, 5);
2302 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2303 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
);
2304 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
);
2305 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
);
2306 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
);
2310 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2311 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2312 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2315 procedure TPlayer
.Draw();
2323 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2324 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2326 e_GetTextureSize(ID
, @w
, @h
);
2327 if FDirection
= D_LEFT
then
2328 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2329 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False)
2331 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2332 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False);
2335 if FMegaRulez
[MR_INVIS
] > gTime
then
2337 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2338 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2340 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2341 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2345 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 200)
2347 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2350 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 254);
2353 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2356 if g_debug_Frames
then
2358 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2360 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2361 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2365 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2367 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2368 if gAimLine
and alive
and
2369 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2374 procedure TPlayer
.DrawAim();
2375 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2379 if isValidViewPort
and (self
= gPlayer1
) then
2381 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2384 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2385 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2387 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2391 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2396 wx
, wy
, xx
, yy
: Integer;
2400 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= D_LEFT
, 7, -7);
2401 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2410 1: begin // Chainsaw
2417 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2418 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2419 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2420 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2425 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2426 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2427 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2428 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2430 4: begin // Double Shotgun
2433 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2434 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2435 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2436 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2438 5: begin // Chaingun
2441 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2442 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2443 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2444 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2446 6: begin // Rocket Launcher
2449 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2450 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2451 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2452 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2454 7: begin // Plasmagun
2457 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2458 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2459 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2460 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2465 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2466 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2467 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2468 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2470 9: begin // Super Chaingun
2473 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2474 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2475 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2476 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2479 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2480 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2481 {$IF DEFINED(D2F_DEBUG)}
2482 drawCast(sz
, wx
, wy
, xx
, yy
);
2484 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2488 procedure TPlayer
.DrawGUI();
2491 X
, Y
, SY
, a
, p
, m
: Integer;
2495 stat
: TPlayerStatArray
;
2497 X
:= gPlayerScreenSize
.X
;
2498 SY
:= gPlayerScreenSize
.Y
;
2501 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2503 if gGameSettings
.GameMode
= GM_CTF
then
2507 if gGameSettings
.GameMode
= GM_CTF
then
2509 s
:= 'TEXTURE_PLAYER_REDFLAG';
2510 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2511 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2512 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2513 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2514 if g_Texture_Get(s
, ID
) then
2515 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2518 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2519 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2520 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2522 if gGameSettings
.GameMode
= GM_CTF
then
2524 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2525 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2526 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2527 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2528 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2529 if g_Texture_Get(s
, ID
) then
2530 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2533 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2534 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2535 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2538 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2539 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2542 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2543 e_Draw(ID
, X
+2, Y
, 0, True, False);
2545 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2549 s
:= IntToStr(Frags
);
2550 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2551 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2556 stat
:= g_Player_GetStats();
2561 for a
:= 0 to High(stat
) do
2562 if stat
[a
].Name
<> Name
then
2564 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2565 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2569 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2570 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2571 s
:= s
+IntToStr(Abs(Frags
-m
));
2573 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2574 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2577 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2579 s
:= IntToStr(Lives
);
2580 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2581 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2585 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2586 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2588 if R_BERSERK
in FRulez
then
2589 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2591 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2593 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2594 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2596 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2597 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2598 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2600 s
:= IntToStr(FArmor
);
2601 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2602 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2604 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2610 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2615 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2617 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2618 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2619 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2620 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2621 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2622 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2623 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2624 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2625 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2628 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2629 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2630 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2632 if R_KEY_RED
in FRulez
then
2633 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2635 if R_KEY_GREEN
in FRulez
then
2636 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2638 if R_KEY_BLUE
in FRulez
then
2639 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2641 if FJetFuel
> 0 then
2643 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2644 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2645 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2646 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2647 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2648 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2652 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2653 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2654 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2657 if gShowPing
and g_Game_IsClient
then
2659 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2660 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2666 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2667 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2668 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2671 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2672 s
:= _lc
[I_PLAYER_SPECT4
];
2673 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2674 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2675 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2681 procedure TPlayer
.DrawRulez();
2685 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2686 if FMegaRulez
[MR_INVUL
] >= gTime
then
2688 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2689 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2694 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2695 191, 191, 191, 0, B_INVERT
);
2698 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2699 if FMegaRulez
[MR_SUIT
] >= gTime
then
2701 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2702 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2707 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2708 0, 96, 0, 200, B_NONE
);
2711 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2712 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2714 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2715 255, 0, 0, 200, B_NONE
);
2719 procedure TPlayer
.DrawPain();
2723 if FPain
= 0 then Exit
;
2727 if a
< 15 then h
:= 0
2728 else if a
< 35 then h
:= 1
2729 else if a
< 55 then h
:= 2
2730 else if a
< 75 then h
:= 3
2731 else if a
< 95 then h
:= 4
2734 //if a > 255 then a := 255;
2736 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2737 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2740 procedure TPlayer
.DrawPickup();
2744 if FPickup
= 0 then Exit
;
2748 if a
< 15 then h
:= 1
2749 else if a
< 35 then h
:= 2
2750 else if a
< 55 then h
:= 3
2751 else if a
< 75 then h
:= 4
2754 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2757 procedure TPlayer
.Fire();
2759 f
, DidFire
: Boolean;
2760 wx
, wy
, xd
, yd
: Integer;
2763 if g_Game_IsClient
then Exit
;
2764 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2765 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2773 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2778 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2779 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2780 xd
:= wx
+IfThen(FDirection
= D_LEFT
, -30, 30);
2781 yd
:= wy
+firediry();
2786 if R_BERSERK
in FRulez
then
2788 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2789 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2790 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2793 locobj
.rect
.Width
:= 39;
2794 locobj
.rect
.Height
:= 52;
2795 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2796 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2797 locobj
.Accel
.X
:= xd
-wx
;
2798 locobj
.Accel
.y
:= yd
-wy
;
2800 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2801 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2803 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2807 FPain
:= min(FPain
+ 25, 50);
2808 end else g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2811 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2816 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2817 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2819 FSawSoundSelect
.Stop();
2821 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2823 else if not FSawSoundHit
.IsPlaying() then
2825 FSawSoundSelect
.Stop();
2826 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2829 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2835 if FAmmo
[A_BULLETS
] > 0 then
2837 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2838 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2839 Dec(FAmmo
[A_BULLETS
]);
2840 FFireAngle
:= FAngle
;
2843 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2844 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2848 if FAmmo
[A_SHELLS
] > 0 then
2850 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2851 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
2852 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2853 Dec(FAmmo
[A_SHELLS
]);
2854 FFireAngle
:= FAngle
;
2858 FShellType
:= SHELL_SHELL
;
2862 if FAmmo
[A_SHELLS
] >= 2 then
2864 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
2865 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2866 Dec(FAmmo
[A_SHELLS
], 2);
2867 FFireAngle
:= FAngle
;
2871 FShellType
:= SHELL_DBLSHELL
;
2875 if FAmmo
[A_BULLETS
] > 0 then
2877 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
2878 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
2879 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2880 Dec(FAmmo
[A_BULLETS
]);
2881 FFireAngle
:= FAngle
;
2884 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2885 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2888 WEAPON_ROCKETLAUNCHER
:
2889 if FAmmo
[A_ROCKETS
] > 0 then
2891 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
2892 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2893 Dec(FAmmo
[A_ROCKETS
]);
2894 FFireAngle
:= FAngle
;
2900 if FAmmo
[A_CELLS
] > 0 then
2902 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
2903 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2904 Dec(FAmmo
[A_CELLS
]);
2905 FFireAngle
:= FAngle
;
2911 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
2913 FBFGFireCounter
:= 17;
2914 if not FNoReload
then
2915 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
2916 Dec(FAmmo
[A_CELLS
], 40);
2920 WEAPON_SUPERPULEMET
:
2921 if FAmmo
[A_SHELLS
] > 0 then
2923 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2924 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
2925 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2926 Dec(FAmmo
[A_SHELLS
]);
2927 FFireAngle
:= FAngle
;
2930 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2931 GameVelX
, GameVelY
-2, SHELL_SHELL
);
2934 WEAPON_FLAMETHROWER
:
2935 if FAmmo
[A_FUEL
] > 0 then
2937 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
2938 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2940 FFireAngle
:= FAngle
;
2946 if g_Game_IsNet
then
2950 if FCurrWeap
<> WEAPON_BFG
then
2951 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
2953 if not FNoReload
then
2954 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
2957 MH_SEND_PlayerStats(FUID
);
2962 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
2963 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
2964 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
2967 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
2970 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
2971 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
2972 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
2973 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
2974 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
2979 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
2981 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
2982 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
2983 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
2986 procedure TPlayer
.JetpackOn
;
2990 FJetSoundOn
.SetPosition(0);
2991 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
2995 procedure TPlayer
.JetpackOff
;
2999 FJetSoundOff
.SetPosition(0);
3000 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3003 procedure TPlayer
.CatchFire(Attacker
: Word);
3006 FFireAttacker
:= Attacker
;
3007 if g_Game_IsNet
and g_Game_IsServer
then
3008 MH_SEND_PlayerStats(FUID
);
3011 procedure TPlayer
.Jump();
3013 if gFly
or FJetpack
then
3015 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3016 if FObj
.Vel
.Y
> -VEL_FLY
then
3017 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3020 if FJetFuel
> 0 then
3022 if (FJetFuel
< 1) and g_Game_IsServer
then
3026 if g_Game_IsNet
then
3027 MH_SEND_PlayerStats(FUID
);
3033 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3035 FCanJetpack
:= False;
3037 // Ïðûãàåì èëè âñïëûâàåì:
3038 if (CollideLevel(0, 1) or
3039 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3040 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3041 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3043 FObj
.Vel
.Y
:= -VEL_JUMP
;
3044 FCanJetpack
:= False;
3048 if BodyInLiquid(0, 0) then
3049 FObj
.Vel
.Y
:= -VEL_SW
3050 else if (FJetFuel
> 0) and FCanJetpack
and
3051 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3055 if g_Game_IsNet
then
3056 MH_SEND_PlayerStats(FUID
);
3061 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3063 a
, i
, k
, ab
, ar
: Byte;
3067 srv
, netsrv
: Boolean;
3073 procedure PushItem(t
: Byte);
3077 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3078 it
:= g_Items_ByIdx(id
);
3079 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3081 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3082 (FObj
.Vel
.Y
div 2)-Random(9));
3083 it
.positionChanged(); // this updates spatial accelerators
3087 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3089 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3090 (FObj
.Vel
.Y
div 2)-Random(6));
3092 else // -3..+3; -3..0
3094 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3095 (FObj
.Vel
.Y
div 2)-Random(4));
3097 it
.positionChanged(); // this updates spatial accelerators
3100 if g_Game_IsNet
and g_Game_IsServer
then
3101 MH_SEND_ItemSpawn(True, id
);
3105 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3106 Srv
:= g_Game_IsServer
;
3107 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3108 if Srv
then FDeath
:= FDeath
+ 1;
3113 if not FPhysics
then
3119 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3121 if FLives
> 0 then FLives
:= FLives
- 1;
3122 if FLives
= 0 then FNoRespawn
:= True;
3125 // Íîìåð òèïà ñìåðòè:
3128 K_SIMPLEKILL
: a
:= 1;
3130 K_EXTRAHARDKILL
: a
:= 3;
3135 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3137 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3144 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3146 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3147 K_EXTRAHARDKILL
, K_FALLKILL
:
3148 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3151 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3155 K_HARDKILL
, K_EXTRAHARDKILL
:
3159 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3160 if (KillType
<> K_FALLKILL
) and (Srv
) then
3161 g_Monsters_killedp();
3163 if SpawnerUID
= FUID
then
3165 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3170 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3173 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3174 begin // Óáèò äðóãèì èãðîêîì
3175 KP
:= g_Player_Get(SpawnerUID
);
3176 if (KP
<> nil) and Srv
then
3178 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3179 if SameTeam(FUID
, SpawnerUID
) then
3189 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3190 Inc(gTeamStat
[KP
.Team
].Goals
,
3191 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3193 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3196 plr
:= g_Player_Get(SpawnerUID
);
3204 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3208 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3212 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3217 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3218 begin // Óáèò ìîíñòðîì
3219 mon
:= g_Monsters_ByUID(SpawnerUID
);
3223 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
3227 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3231 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3235 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3240 else // Îñîáûå òèïû ñìåðòè
3243 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3244 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3245 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3246 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3247 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3248 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3254 for a
:= WP_FIRST
to WP_LAST
do
3258 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3259 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3260 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3261 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3262 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3263 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3264 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3265 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3266 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3275 if R_ITEM_BACKPACK
in FRulez
then
3276 PushItem(ITEM_AMMO_BACKPACK
);
3278 // Âûáðîñ ðàêåòíîãî ðàíöà:
3279 if FJetFuel
> 0 then
3280 PushItem(ITEM_JETPACK
);
3283 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3285 if R_KEY_RED
in FRulez
then
3286 PushItem(ITEM_KEY_RED
);
3288 if R_KEY_GREEN
in FRulez
then
3289 PushItem(ITEM_KEY_GREEN
);
3291 if R_KEY_BLUE
in FRulez
then
3292 PushItem(ITEM_KEY_BLUE
);
3299 g_Player_CreateCorpse(Self
);
3301 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3302 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3308 for i
:= Low(gPlayers
) to High(gPlayers
) do
3310 if gPlayers
[i
] = nil then continue
;
3311 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3314 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3315 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3320 OldLR
:= gLMSRespawn
;
3321 if (gGameSettings
.GameMode
= GM_COOP
) then
3325 // everyone is dead, restart the map
3326 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3328 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3329 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3330 gLMSRespawnTime
:= gTime
+ 5000;
3332 else if (a
= 1) then
3334 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3335 if (gPlayers
[k
] = gPlayer1
) or
3336 (gPlayers
[k
] = gPlayer2
) then
3337 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3338 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3339 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3342 else if (gGameSettings
.GameMode
= GM_TDM
) then
3344 if (ab
= 0) and (ar
<> 0) then
3347 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3349 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3350 Inc(gTeamStat
[TEAM_RED
].Goals
);
3351 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3352 gLMSRespawnTime
:= gTime
+ 5000;
3354 else if (ar
= 0) and (ab
<> 0) then
3357 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3359 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3360 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3361 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3362 gLMSRespawnTime
:= gTime
+ 5000;
3364 else if (ar
= 0) and (ab
= 0) then
3367 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3369 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3370 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3371 gLMSRespawnTime
:= gTime
+ 5000;
3374 else if (gGameSettings
.GameMode
= GM_DM
) then
3378 if gPlayers
[k
] <> nil then
3381 // survivor is the winner
3382 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3384 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3387 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3388 gLMSRespawnTime
:= gTime
+ 5000;
3390 else if (a
= 0) then
3392 // everyone is dead, restart the map
3393 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3395 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3396 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3397 gLMSRespawnTime
:= gTime
+ 5000;
3400 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3402 if NetMode
= NET_SERVER
then
3403 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3405 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3411 MH_SEND_PlayerStats(FUID
);
3412 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3413 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3416 if srv
and FNoRespawn
then Spectate(True);
3417 FWantsInGame
:= True;
3420 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3422 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3423 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3426 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3428 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3429 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3432 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3434 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3435 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3436 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3438 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3439 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3440 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3444 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3446 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3447 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3448 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3452 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3454 if g_Game_IsClient
then Exit
;
3455 if Weapon
> High(FWeapon
) then Exit
;
3456 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3459 procedure TPlayer
.resetWeaponQueue ();
3462 FNextWeapDelay
:= 0;
3465 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3469 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3470 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 0);
3471 WEAPON_PISTOL
, WEAPON_CHAINGUN
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_BULLETS
] > 0);
3472 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3473 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3474 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3475 else result
:= (weapon
< length(FWeapon
));
3479 // return 255 for "no switch"
3480 function TPlayer
.getNextWeaponIndex (): Byte;
3483 wantThisWeapon
: array[0..64] of Boolean;
3484 wwc
: Integer = 0; //HACK!
3487 result
:= 255; // default result: "no switch"
3488 // had weapon cycling on previous frame? remove that flag
3489 if (FNextWeap
and $2000) <> 0 then
3491 FNextWeap
:= FNextWeap
and $1FFF;
3492 FNextWeapDelay
:= 0;
3494 // cycling has priority
3495 if (FNextWeap
and $C000) <> 0 then
3497 if (FNextWeap
and $8000) <> 0 then
3501 FNextWeap
:= FNextWeap
or $2000; // we need this
3502 if FNextWeapDelay
> 0 then
3503 exit
; // cooldown time
3505 for i
:= 0 to High(FWeapon
) do
3507 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3508 if FWeapon
[cwi
] then
3510 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d', [FCurrWeap, cwi]), MSG_WARNING);
3511 result
:= Byte(cwi
);
3512 FNextWeapDelay
:= 10;
3520 for i
:= 0 to High(wantThisWeapon
) do
3521 wantThisWeapon
[i
] := false;
3522 for i
:= 0 to High(FWeapon
) do
3523 if (FNextWeap
and (1 shl i
)) <> 0 then
3525 wantThisWeapon
[i
] := true;
3528 // exclude currently selected weapon from the set
3529 wantThisWeapon
[FCurrWeap
] := false;
3530 // slow down alterations a little
3533 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3534 // more than one weapon requested, assume "alteration" and check alteration delay
3535 if FNextWeapDelay
> 0 then
3541 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3542 // but clear all counters if no weapon should be switched
3548 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3549 // try weapons in descending order
3550 for i
:= High(FWeapon
) downto 0 do
3552 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3557 FNextWeapDelay
:= 10; // anyway, 'cause why not
3561 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3565 procedure TPlayer
.RealizeCurrentWeapon();
3566 function switchAllowed (): Boolean;
3571 if FBFGFireCounter
<> -1 then
3573 if FTime
[T_SWITCH
] > gTime
then
3575 for i
:= WP_FIRST
to WP_LAST
do
3576 if FReloading
[i
] > 0 then
3584 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3585 //FNextWeap := FNextWeap and $1FFF;
3586 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3588 if not switchAllowed
then
3590 //HACK for weapon cycling
3591 if (FNextWeap
and $7000) <> 0 then FNextWeap
:= 0;
3595 nw
:= getNextWeaponIndex();
3596 if nw
= 255 then exit
; // don't reset anything here
3597 if nw
> High(FWeapon
) then
3599 // don't forget to reset queue here!
3600 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3608 FTime
[T_SWITCH
] := gTime
+156;
3609 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3610 FModel
.SetWeapon(FCurrWeap
);
3611 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3615 procedure TPlayer
.NextWeapon();
3617 if g_Game_IsClient
then Exit
;
3621 procedure TPlayer
.PrevWeapon();
3623 if g_Game_IsClient
then Exit
;
3627 procedure TPlayer
.SetWeapon(W
: Byte);
3629 if FCurrWeap
<> W
then
3630 if W
= WEAPON_SAW
then
3631 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3634 FModel
.SetWeapon(CurrWeap
);
3638 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3643 if g_Game_IsClient
then Exit
;
3645 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3646 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3651 if FHealth
< PLAYER_HP_SOFT
then
3653 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3657 if gFlash
= 2 then Inc(FPickup
, 5);
3661 if FHealth
< PLAYER_HP_SOFT
then
3663 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3667 if gFlash
= 2 then Inc(FPickup
, 5);
3671 if FArmor
< PLAYER_AP_SOFT
then
3673 FArmor
:= PLAYER_AP_SOFT
;
3676 if gFlash
= 2 then Inc(FPickup
, 5);
3680 if FArmor
< PLAYER_AP_LIMIT
then
3682 FArmor
:= PLAYER_AP_LIMIT
;
3685 if gFlash
= 2 then Inc(FPickup
, 5);
3689 if FHealth
< PLAYER_HP_LIMIT
then
3691 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3695 if gFlash
= 2 then Inc(FPickup
, 5);
3699 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3701 if FHealth
< PLAYER_HP_LIMIT
then
3702 FHealth
:= PLAYER_HP_LIMIT
;
3703 if FArmor
< PLAYER_AP_LIMIT
then
3704 FArmor
:= PLAYER_AP_LIMIT
;
3708 if gFlash
= 2 then Inc(FPickup
, 5);
3712 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3714 FWeapon
[WEAPON_SAW
] := True;
3716 if gFlash
= 2 then Inc(FPickup
, 5);
3717 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3720 ITEM_WEAPON_SHOTGUN1
:
3721 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3723 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3724 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3726 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3727 FWeapon
[WEAPON_SHOTGUN1
] := True;
3729 if gFlash
= 2 then Inc(FPickup
, 5);
3730 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3733 ITEM_WEAPON_SHOTGUN2
:
3734 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3736 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3738 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3739 FWeapon
[WEAPON_SHOTGUN2
] := True;
3741 if gFlash
= 2 then Inc(FPickup
, 5);
3742 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3745 ITEM_WEAPON_CHAINGUN
:
3746 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3748 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3750 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3751 FWeapon
[WEAPON_CHAINGUN
] := True;
3753 if gFlash
= 2 then Inc(FPickup
, 5);
3754 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3757 ITEM_WEAPON_ROCKETLAUNCHER
:
3758 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3760 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3762 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3763 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3765 if gFlash
= 2 then Inc(FPickup
, 5);
3766 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3770 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3772 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3774 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3775 FWeapon
[WEAPON_PLASMA
] := True;
3777 if gFlash
= 2 then Inc(FPickup
, 5);
3778 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3782 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3784 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3786 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3787 FWeapon
[WEAPON_BFG
] := True;
3789 if gFlash
= 2 then Inc(FPickup
, 5);
3790 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3793 ITEM_WEAPON_SUPERPULEMET
:
3794 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3796 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3798 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3799 FWeapon
[WEAPON_SUPERPULEMET
] := True;
3801 if gFlash
= 2 then Inc(FPickup
, 5);
3802 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3805 ITEM_WEAPON_FLAMETHROWER
:
3806 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
3808 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
3810 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3811 FWeapon
[WEAPON_FLAMETHROWER
] := True;
3813 if gFlash
= 2 then Inc(FPickup
, 5);
3814 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3818 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3820 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3823 if gFlash
= 2 then Inc(FPickup
, 5);
3826 ITEM_AMMO_BULLETS_BOX
:
3827 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3829 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3832 if gFlash
= 2 then Inc(FPickup
, 5);
3836 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3838 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3841 if gFlash
= 2 then Inc(FPickup
, 5);
3844 ITEM_AMMO_SHELLS_BOX
:
3845 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3847 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
3850 if gFlash
= 2 then Inc(FPickup
, 5);
3854 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3856 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3859 if gFlash
= 2 then Inc(FPickup
, 5);
3862 ITEM_AMMO_ROCKET_BOX
:
3863 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3865 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
3868 if gFlash
= 2 then Inc(FPickup
, 5);
3872 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3874 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3877 if gFlash
= 2 then Inc(FPickup
, 5);
3881 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3883 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
3886 if gFlash
= 2 then Inc(FPickup
, 5);
3890 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
3892 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3895 if gFlash
= 2 then Inc(FPickup
, 5);
3899 if not(R_ITEM_BACKPACK
in FRulez
) or
3900 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
3901 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
3902 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
3903 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
3904 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
3906 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
3907 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
3908 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
3909 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
3910 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
3912 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3913 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3914 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3915 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3916 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3917 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3918 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3919 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3921 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
3924 if gFlash
= 2 then Inc(FPickup
, 5);
3928 if not(R_KEY_RED
in FRulez
) then
3930 Include(FRulez
, R_KEY_RED
);
3932 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3933 if gFlash
= 2 then Inc(FPickup
, 5);
3934 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3938 if not(R_KEY_GREEN
in FRulez
) then
3940 Include(FRulez
, R_KEY_GREEN
);
3942 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3943 if gFlash
= 2 then Inc(FPickup
, 5);
3944 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3948 if not(R_KEY_BLUE
in FRulez
) then
3950 Include(FRulez
, R_KEY_BLUE
);
3952 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3953 if gFlash
= 2 then Inc(FPickup
, 5);
3954 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3958 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
3960 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
3964 if gFlash
= 2 then Inc(FPickup
, 5);
3968 if FAir
< AIR_MAX
then
3973 if gFlash
= 2 then Inc(FPickup
, 5);
3978 if not (R_BERSERK
in FRulez
) then
3980 Include(FRulez
, R_BERSERK
);
3981 if FBFGFireCounter
= -1 then
3983 FCurrWeap
:= WEAPON_KASTET
;
3985 FModel
.SetWeapon(WEAPON_KASTET
);
3989 if gFlash
= 2 then Inc(FPickup
, 5);
3990 FBerserk
:= gTime
+30000;
3995 if FHealth
< PLAYER_HP_SOFT
then
3997 FHealth
:= PLAYER_HP_SOFT
;
3998 FBerserk
:= gTime
+30000;
4006 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4008 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4011 if gFlash
= 2 then Inc(FPickup
, 5);
4015 if FHealth
< PLAYER_HP_LIMIT
then
4017 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4021 if gFlash
= 2 then Inc(FPickup
, 5);
4025 if FArmor
< PLAYER_AP_LIMIT
then
4027 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4030 if gFlash
= 2 then Inc(FPickup
, 5);
4034 if FJetFuel
< JET_MAX
then
4036 FJetFuel
:= JET_MAX
;
4039 if gFlash
= 2 then Inc(FPickup
, 5);
4043 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4045 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4048 if gFlash
= 2 then Inc(FPickup
, 5);
4053 procedure TPlayer
.Touch();
4057 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4060 // Áðîñèòü ôëàã òîâàðèùó:
4061 if gGameSettings
.GameMode
= GM_CTF
then
4066 procedure TPlayer
.Push(vx
, vy
: Integer);
4068 if (not FPhysics
) and FGhost
then
4070 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4071 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4072 if g_Game_IsNet
and g_Game_IsServer
then
4073 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4076 procedure TPlayer
.Reset(Force
: Boolean);
4082 FTime
[T_RESPAWN
] := 0;
4083 FTime
[T_FLAGCAP
] := 0;
4096 FSpectator
:= False;
4099 FSpectatePlayer
:= -1;
4100 FNoRespawn
:= False;
4102 FLives
:= gGameSettings
.MaxLives
;
4107 procedure TPlayer
.SoftReset();
4113 FBFGFireCounter
:= -1;
4121 SetAction(A_STAND
, True);
4124 function TPlayer
.GetRespawnPoint(): Byte;
4129 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4131 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4132 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4134 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4136 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4137 if Self
= gPlayer1
then
4138 c
:= RESPAWNPOINT_PLAYER1
4140 c
:= RESPAWNPOINT_PLAYER2
;
4141 if g_Map_GetPointCount(c
) > 0 then
4147 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4148 if Self
= gPlayer1
then
4149 c
:= RESPAWNPOINT_PLAYER2
4151 c
:= RESPAWNPOINT_PLAYER1
;
4152 if g_Map_GetPointCount(c
) > 0 then
4159 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4160 if Random(2) = 0 then
4161 c
:= RESPAWNPOINT_PLAYER1
4163 c
:= RESPAWNPOINT_PLAYER2
;
4164 if g_Map_GetPointCount(c
) > 0 then
4171 // Òî÷êà ëþáîé èç êîìàíä
4172 if Random(2) = 0 then
4173 c
:= RESPAWNPOINT_RED
4175 c
:= RESPAWNPOINT_BLUE
;
4176 if g_Map_GetPointCount(c
) > 0 then
4183 c
:= RESPAWNPOINT_DM
;
4184 if g_Map_GetPointCount(c
) > 0 then
4192 if gGameSettings
.GameMode
= GM_DM
then
4195 c
:= RESPAWNPOINT_DM
;
4196 if g_Map_GetPointCount(c
) > 0 then
4202 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4203 if Random(2) = 0 then
4204 c
:= RESPAWNPOINT_PLAYER1
4206 c
:= RESPAWNPOINT_PLAYER2
;
4207 if g_Map_GetPointCount(c
) > 0 then
4213 // Òî÷êà ëþáîé èç êîìàíä
4214 if Random(2) = 0 then
4215 c
:= RESPAWNPOINT_RED
4217 c
:= RESPAWNPOINT_BLUE
;
4218 if g_Map_GetPointCount(c
) > 0 then
4226 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4228 // Òî÷êà ñâîåé êîìàíäû
4229 c
:= RESPAWNPOINT_DM
;
4230 if FTeam
= TEAM_RED
then
4231 c
:= RESPAWNPOINT_RED
;
4232 if FTeam
= TEAM_BLUE
then
4233 c
:= RESPAWNPOINT_BLUE
;
4234 if g_Map_GetPointCount(c
) > 0 then
4241 c
:= RESPAWNPOINT_DM
;
4242 if g_Map_GetPointCount(c
) > 0 then
4248 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4249 if Random(2) = 0 then
4250 c
:= RESPAWNPOINT_PLAYER1
4252 c
:= RESPAWNPOINT_PLAYER2
;
4253 if g_Map_GetPointCount(c
) > 0 then
4259 // Òî÷êà äðóãîé êîìàíäû
4260 c
:= RESPAWNPOINT_DM
;
4261 if FTeam
= TEAM_RED
then
4262 c
:= RESPAWNPOINT_BLUE
;
4263 if FTeam
= TEAM_BLUE
then
4264 c
:= RESPAWNPOINT_RED
;
4265 if g_Map_GetPointCount(c
) > 0 then
4273 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4275 RespawnPoint
: TRespawnPoint
;
4280 if not g_Game_IsServer
then
4284 FWantsInGame
:= True;
4285 FJustTeleported
:= True;
4288 FTime
[T_RESPAWN
] := 0;
4292 // if server changes MaxLives we gotta be ready
4293 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4295 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4296 if FTime
[T_RESPAWN
] > gTime
then
4299 // Ïðîñðàë âñå æèçíè:
4302 if not FSpectator
then Spectate(True);
4303 FWantsInGame
:= True;
4307 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4308 begin // "Ñâîÿ èãðà"
4309 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4310 FRulez
:= FRulez
-[R_BERSERK
];
4312 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4314 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4315 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4318 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4319 c
:= GetRespawnPoint();
4324 // Âîñêðåøåíèå áåç îðóæèÿ:
4327 FHealth
:= PLAYER_HP_SOFT
;
4333 for a
:= WP_FIRST
to WP_LAST
do
4335 FWeapon
[a
] := False;
4339 FWeapon
[WEAPON_PISTOL
] := True;
4340 FWeapon
[WEAPON_KASTET
] := True;
4341 FCurrWeap
:= WEAPON_PISTOL
;
4344 FModel
.SetWeapon(FCurrWeap
);
4346 for b
:= A_BULLETS
to A_HIGH
do
4349 FAmmo
[A_BULLETS
] := 50;
4351 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4352 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4353 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4354 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4355 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4357 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4358 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4363 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4364 if not g_Map_GetPoint(c
, RespawnPoint
) then
4366 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4370 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4371 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4372 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4378 FDirection
:= RespawnPoint
.Direction
;
4379 if FDirection
= D_LEFT
then
4385 FBFGFireCounter
:= -1;
4390 SetAction(A_STAND
, True);
4391 FModel
.Direction
:= FDirection
;
4393 for a
:= Low(FTime
) to High(FTime
) do
4396 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4401 FCanJetpack
:= False;
4406 // Àíèìàöèÿ âîçðîæäåíèÿ:
4407 if (not gLoadGameMode
) and (not Silent
) then
4408 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4410 Anim
:= TAnimation
.Create(ID
, False, 3);
4411 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4412 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4416 FSpectator
:= False;
4419 FSpectatePlayer
:= -1;
4422 if g_Game_IsNet
then
4424 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4425 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4427 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4428 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4433 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4436 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4437 else if (not NoMove
) then
4439 GameX
:= gMapInfo
.Width
div 2;
4440 GameY
:= gMapInfo
.Height
div 2;
4449 FWantsInGame
:= False;
4454 if Self
= gPlayer1
then
4459 if Self
= gPlayer2
then
4466 if g_Game_IsNet
then
4467 MH_SEND_PlayerStats(FUID
);
4470 procedure TPlayer
.SwitchNoClip
;
4474 FGhost
:= not FGhost
;
4475 FPhysics
:= not FGhost
;
4487 procedure TPlayer
.Run(Direction
: TDirection
);
4491 if MAX_RUNVEL
> 8 then
4495 if Direction
= D_LEFT
then
4497 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4498 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4501 if FObj
.Vel
.X
< MAX_RUNVEL
then
4502 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4504 // Âîçìîæíî, ïèíàåì êóñêè:
4505 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4507 b
:= Abs(FObj
.Vel
.X
);
4508 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4509 for a
:= 0 to High(gGibs
) do
4511 if gGibs
[a
].alive
and
4512 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4513 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4516 if FObj
.Vel
.X
< 0 then
4518 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4522 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4524 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4532 procedure TPlayer
.SeeDown();
4534 SetAction(A_SEEDOWN
);
4536 if FDirection
= D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4538 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4541 procedure TPlayer
.SeeUp();
4545 if FDirection
= D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4547 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4550 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4558 A_ATTACK
: Prior
:= 2;
4559 A_SEEUP
: Prior
:= 1;
4560 A_SEEDOWN
: Prior
:= 1;
4561 A_ATTACKUP
: Prior
:= 2;
4562 A_ATTACKDOWN
: Prior
:= 2;
4567 if (Prior
> FActionPrior
) or Force
then
4568 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4570 FActionPrior
:= Prior
;
4571 FActionAnim
:= Action
;
4572 FActionForce
:= Force
;
4573 FActionChanged
:= True;
4576 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4579 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4581 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4582 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4583 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4584 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4587 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4594 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4596 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4597 if g_Game_IsServer
and g_Game_IsNet
then
4598 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4602 FJustTeleported
:= True;
4607 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4609 Anim
:= TAnimation
.Create(ID
, False, 3);
4612 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4613 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4614 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4615 if g_Game_IsServer
and g_Game_IsNet
then
4616 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4617 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4621 FObj
.X
:= X
-PLAYER_RECT
.X
;
4622 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4623 if FAlive
and FGhost
then
4629 if not g_Game_IsNet
then
4633 SetDirection(D_LEFT
);
4639 SetDirection(D_RIGHT
);
4645 if FDirection
= D_RIGHT
then
4647 SetDirection(D_LEFT
);
4652 SetDirection(D_RIGHT
);
4658 if not silent
and (Anim
<> nil) then
4660 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4661 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4664 if g_Game_IsServer
and g_Game_IsNet
then
4665 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4666 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4673 function nonz(a
: Single): Single;
4681 procedure TPlayer
.Update();
4684 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4685 blockmon
, headwater
, dospawn
: Boolean;
4690 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4691 AnyServer
:= g_Game_IsServer
;
4693 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4694 DoLerp(NetInterpLevel
+ 1)
4700 if FClientID
>= 0 then
4702 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4703 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4704 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4713 if FAlive
and (gFly
or FJetpack
) then
4716 if FDirection
= D_LEFT
then
4721 if FAlive
and (not FGhost
) then
4723 if FKeys
[KEY_UP
].Pressed
then
4725 if FKeys
[KEY_DOWN
].Pressed
then
4729 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4732 i
:= g_basic
.Sign(FIncCam
);
4733 FIncCam
:= Abs(FIncCam
);
4734 DecMin(FIncCam
, 5, 0);
4735 FIncCam
:= FIncCam
*i
;
4738 // no need to do that each second frame, weapon queue will take care of it
4739 if FAlive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4740 if FAlive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4742 if gTime
mod (GAME_TICK
*2) <> 0 then
4744 if (FObj
.Vel
.X
= 0) and FAlive
then
4746 if FKeys
[KEY_LEFT
].Pressed
then
4748 if FKeys
[KEY_RIGHT
].Pressed
then
4754 g_Obj_Move(@FObj
, True, True, True);
4755 positionChanged(); // this updates spatial accelerators
4761 FActionChanged
:= False;
4765 // Let alive player do some actions
4766 if FKeys
[KEY_LEFT
].Pressed
then Run(D_LEFT
);
4767 if FKeys
[KEY_RIGHT
].Pressed
then Run(D_RIGHT
);
4768 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
4769 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
4770 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
4771 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
4772 if FKeys
[KEY_JUMP
].Pressed
then Jump()
4775 if AnyServer
and FJetpack
then
4779 if NetServer
then MH_SEND_PlayerStats(FUID
);
4781 FCanJetpack
:= True;
4788 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
4790 if FKeys
[k
].Pressed
then
4798 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4801 if (FTime
[T_RESPAWN
] <= gTime
) and
4802 gGameOn
and (not FAlive
) then
4804 if (g_Player_GetCount() > 1) then
4808 gExit
:= EXIT_RESTART
;
4813 // Dead spectator actions
4816 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
4817 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
4821 if (FSpectatePlayer
>= High(gPlayers
)) then
4822 FSpectatePlayer
:= -1
4826 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
4827 if gPlayers
[I
] <> nil then
4828 if gPlayers
[I
].alive
then
4829 if gPlayers
[I
].UID
<> FUID
then
4831 FSpectatePlayer
:= I
;
4836 if not SetSpect
then FSpectatePlayer
:= -1;
4847 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
4849 FYTo
:= FObj
.Y
- 32;
4850 FSpectatePlayer
:= -1;
4852 if FKeys
[KEY_DOWN
].Pressed
then
4854 FYTo
:= FObj
.Y
+ 32;
4855 FSpectatePlayer
:= -1;
4857 if FKeys
[KEY_LEFT
].Pressed
then
4859 FXTo
:= FObj
.X
- 32;
4860 FSpectatePlayer
:= -1;
4862 if FKeys
[KEY_RIGHT
].Pressed
then
4864 FXTo
:= FObj
.X
+ 32;
4865 FSpectatePlayer
:= -1;
4868 if (FXTo
< -64) then
4870 else if (FXTo
> gMapInfo
.Width
+ 32) then
4871 FXTo
:= gMapInfo
.Width
+ 32;
4872 if (FYTo
< -72) then
4874 else if (FYTo
> gMapInfo
.Height
+ 32) then
4875 FYTo
:= gMapInfo
.Height
+ 32;
4880 g_Obj_Move(@FObj
, True, True, True);
4881 positionChanged(); // this updates spatial accelerators
4888 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
4889 if gPlayers
[FSpectatePlayer
] <> nil then
4890 if gPlayers
[FSpectatePlayer
].alive
then
4892 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
4893 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
4897 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
4898 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
4899 PANEL_BLOCKMON
, True);
4900 headwater
:= HeadInLiquid(0, 0);
4902 // Ñîïðîòèâëåíèå âîçäóõà:
4903 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
4904 if FObj
.Vel
.X
<> 0 then
4905 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
4907 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
4908 DecMin(FPain
, 5, 0);
4909 DecMin(FPickup
, 1, 0);
4911 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
4913 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
4914 FMegaRulez
[MR_SUIT
] := 0;
4915 FMegaRulez
[MR_INVUL
] := 0;
4916 FMegaRulez
[MR_INVIS
] := 0;
4917 Kill(K_FALLKILL
, 0, HIT_FALL
);
4924 if FCurrWeap
= WEAPON_SAW
then
4925 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
4926 FSawSoundSelect
.IsPlaying()) then
4927 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
4930 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
4931 (not FJetSoundOff
.IsPlaying()) then
4933 FJetSoundFly
.SetPosition(0);
4934 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
4937 for b
:= WP_FIRST
to WP_LAST
do
4938 if FReloading
[b
] > 0 then
4944 if FShellTimer
> -1 then
4945 if FShellTimer
= 0 then
4947 if FShellType
= SHELL_SHELL
then
4948 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4949 GameVelX
, GameVelY
-2, SHELL_SHELL
)
4950 else if FShellType
= SHELL_DBLSHELL
then
4952 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4953 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
4954 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4955 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
4958 end else Dec(FShellTimer
);
4960 if (FBFGFireCounter
> -1) then
4961 if FBFGFireCounter
= 0 then
4965 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
4966 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
4967 xd
:= wx
+IfThen(FDirection
= D_LEFT
, -30, 30);
4968 yd
:= wy
+firediry();
4969 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
4970 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
4971 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
4972 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
4973 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
4976 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
4977 FBFGFireCounter
:= -1;
4980 FBFGFireCounter
:= 0
4982 Dec(FBFGFireCounter
);
4984 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
4986 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
4988 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
4991 if (headwater
or blockmon
) then
4997 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5000 else if (FAir
mod 31 = 0) and not blockmon
then
5002 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5003 if Random(2) = 0 then
5004 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5006 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5008 end else if FAir
< AIR_DEF
then
5011 if FFireTime
> 0 then
5013 if BodyInLiquid(0, 0) then
5018 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5020 if FMegaRulez
[MR_SUIT
] = gTime
then
5027 if FFirePainTime
<= 0 then
5029 if g_Game_IsServer
then
5030 Damage(5, FFireAttacker
, 0, 0, HIT_FLAME
);
5031 FFirePainTime
:= 18;
5033 FFirePainTime
:= FFirePainTime
- 1;
5034 FFireTime
:= FFireTime
- 1;
5035 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5036 MH_SEND_PlayerStats(FUID
);
5040 if FDamageBuffer
> 0 then
5042 if FDamageBuffer
>= 9 then
5046 if FDamageBuffer
< 30 then i
:= 9
5047 else if FDamageBuffer
< 100 then i
:= 18
5051 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5052 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5053 FHealth
:= FHealth
-ii
;
5056 FHealth
:= FHealth
+FArmor
;
5061 if FHealth
<= 0 then
5062 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5063 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5064 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5068 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5069 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5070 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5071 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5078 end; // if FAlive then ...
5080 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5082 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5083 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5084 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5085 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5087 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5088 then SetAction(A_STAND
, True);
5090 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5092 for b
:= Low(FKeys
) to High(FKeys
) do
5093 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5097 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5099 x
:= FObj
.X
+PLAYER_RECT
.X
;
5100 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5101 w
:= PLAYER_RECT
.Width
;
5102 h
:= PLAYER_RECT
.Height
;
5106 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5108 if (dx
<> 0) or (dy
<> 0) then
5117 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5119 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5120 FObj
.Y
+PLAYER_RECT
.Y
,
5127 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5129 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5130 FObj
.Y
+PLAYER_RECT
.Y
,
5134 Panel
.Width
, Panel
.Height
);
5137 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5139 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5140 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5141 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5142 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5145 function g_Player_ValidName(Name
: string): Boolean;
5151 if gPlayers
= nil then Exit
;
5153 for a
:= 0 to High(gPlayers
) do
5154 if gPlayers
[a
] <> nil then
5155 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5162 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5166 d
:= FModel
.Direction
;
5168 FModel
.Direction
:= Direction
;
5169 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5171 FDirection
:= Direction
;
5174 function TPlayer
.GetKeys(): Byte;
5178 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5179 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5180 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5182 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5183 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5186 procedure TPlayer
.Use();
5190 if FTime
[T_USE
] > gTime
then Exit
;
5192 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5193 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5195 for a
:= 0 to High(gPlayers
) do
5196 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5197 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5198 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5199 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5201 gPlayers
[a
].Touch();
5202 if g_Game_IsNet
and g_Game_IsServer
then
5203 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5206 FTime
[T_USE
] := gTime
+120;
5209 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5213 WX
, WY
, XD
, YD
: Integer;
5224 if R_BERSERK
in FRulez
then
5226 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5227 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5228 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5231 locobj
.rect
.Width
:= 39;
5232 locobj
.rect
.Height
:= 52;
5233 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5234 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5235 locobj
.Accel
.X
:= xd
-wx
;
5236 locobj
.Accel
.y
:= yd
-wy
;
5238 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5239 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5241 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5245 FPain
:= min(FPain
+ 25, 50);
5247 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5252 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5253 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5255 FSawSoundSelect
.Stop();
5257 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5259 else if not FSawSoundHit
.IsPlaying() then
5261 FSawSoundSelect
.Stop();
5262 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5269 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5270 FFireAngle
:= FAngle
;
5272 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5273 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5278 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5279 FFireAngle
:= FAngle
;
5282 FShellType
:= SHELL_SHELL
;
5287 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5288 FFireAngle
:= FAngle
;
5291 FShellType
:= SHELL_DBLSHELL
;
5296 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5297 FFireAngle
:= FAngle
;
5299 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5300 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5303 WEAPON_ROCKETLAUNCHER
:
5305 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5306 FFireAngle
:= FAngle
;
5312 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5313 FFireAngle
:= FAngle
;
5319 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5320 FFireAngle
:= FAngle
;
5324 WEAPON_SUPERPULEMET
:
5326 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5327 FFireAngle
:= FAngle
;
5329 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5330 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5333 WEAPON_FLAMETHROWER
:
5335 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5336 FFireAngle
:= FAngle
;
5343 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5344 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5345 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5348 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5350 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5351 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5354 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5358 if NetInterpLevel
< 1 then
5368 AX
:= Abs(FXTo
- FObj
.X
);
5369 AY
:= Abs(FYTo
- FObj
.Y
);
5370 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5372 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5377 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5379 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5380 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5381 PANEL_LIFTUP
, False) then Result
:= -1
5383 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5384 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5385 PANEL_LIFTDOWN
, False) then Result
:= 1
5389 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5396 if Flag
= FLAG_NONE
then
5399 if not g_Game_IsServer
then Exit
;
5401 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5402 if (Flag
= FTeam
) and
5403 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5404 (FFlag
<> FLAG_NONE
) then
5406 if FFlag
= FLAG_RED
then
5407 s
:= _lc
[I_PLAYER_FLAG_RED
]
5409 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5411 evtype
:= FLAG_STATE_SCORED
;
5413 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5414 Insert('.', ts
, Length(ts
) + 1 - 3);
5415 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5417 g_Map_ResetFlag(FFlag
);
5418 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5420 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5423 if g_Game_IsNet
then
5425 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5429 gFlags
[FFlag
].CaptureTime
:= 0;
5434 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5435 if (Flag
= FTeam
) and
5436 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5438 if Flag
= FLAG_RED
then
5439 s
:= _lc
[I_PLAYER_FLAG_RED
]
5441 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5443 evtype
:= FLAG_STATE_RETURNED
;
5444 gFlags
[Flag
].CaptureTime
:= 0;
5446 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5448 g_Map_ResetFlag(Flag
);
5449 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5452 if g_Game_IsNet
then
5454 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5460 // Ïîäîáðàë ÷óæîé ôëàã:
5461 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5465 if Flag
= FLAG_RED
then
5466 s
:= _lc
[I_PLAYER_FLAG_RED
]
5468 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5470 evtype
:= FLAG_STATE_CAPTURED
;
5472 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5474 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5476 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5479 if g_Game_IsNet
then
5481 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5487 procedure TPlayer
.SetFlag(Flag
: Byte);
5490 if FModel
<> nil then
5491 FModel
.SetFlag(FFlag
);
5494 function TPlayer
.DropFlag(): Boolean;
5499 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5501 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5502 with gFlags
[FFlag
] do
5506 Direction
:= FDirection
;
5507 State
:= FLAG_STATE_DROPPED
;
5509 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5510 (FObj
.Vel
.Y
div 2)-2+Random(5));
5511 positionChanged(); // this updates spatial accelerators
5513 if FFlag
= FLAG_RED
then
5514 s
:= _lc
[I_PLAYER_FLAG_RED
]
5516 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5518 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5519 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5521 if g_Game_IsNet
then
5522 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5528 procedure TPlayer
.GetSecret();
5533 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5535 Assert(Key
<= High(FKeys
));
5537 FKeys
[Key
].Pressed
:= True;
5538 FKeys
[Key
].Time
:= Time
;
5541 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5543 Result
:= FKeys
[K
].Pressed
;
5546 procedure TPlayer
.ReleaseKeys();
5550 for a
:= Low(FKeys
) to High(FKeys
) do
5552 FKeys
[a
].Pressed
:= False;
5557 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5561 function TPlayer
.firediry(): Integer;
5563 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5564 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5568 procedure TPlayer
.RememberState();
5572 FSavedState
.Health
:= FHealth
;
5573 FSavedState
.Armor
:= FArmor
;
5574 FSavedState
.Air
:= FAir
;
5575 FSavedState
.JetFuel
:= FJetFuel
;
5576 FSavedState
.CurrWeap
:= FCurrWeap
;
5577 FSavedState
.NextWeap
:= FNextWeap
;
5578 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5581 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5583 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5585 FSavedState
.Rulez
:= FRulez
;
5586 FSavedState
.WaitRecall
:= True;
5589 procedure TPlayer
.RecallState();
5593 if not FSavedState
.WaitRecall
then Exit
;
5595 FHealth
:= FSavedState
.Health
;
5596 FArmor
:= FSavedState
.Armor
;
5597 FAir
:= FSavedState
.Air
;
5598 FJetFuel
:= FSavedState
.JetFuel
;
5599 FCurrWeap
:= FSavedState
.CurrWeap
;
5600 FNextWeap
:= FSavedState
.NextWeap
;
5601 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5604 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5606 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5608 FRulez
:= FSavedState
.Rulez
;
5609 FSavedState
.WaitRecall
:= False;
5611 if gGameSettings
.GameType
= GT_SERVER
then
5612 MH_SEND_PlayerStats(FUID
);
5615 procedure TPlayer
.SaveState(var Mem
: TBinMemoryWriter
);
5627 Mem
:= TBinMemoryWriter
.Create(i
);
5629 // Ñèãíàòóðà èãðîêà:
5630 sig
:= PLAYER_SIGNATURE
; // 'PLYR'
5631 Mem
.WriteDWORD(sig
);
5633 Mem
.WriteBoolean(FIamBot
);
5635 Mem
.WriteWord(FUID
);
5637 Mem
.WriteString(FName
, 32);
5639 Mem
.WriteByte(FTeam
);
5641 Mem
.WriteBoolean(FAlive
);
5642 // Èçðàñõîäîâàë ëè âñå æèçíè:
5643 Mem
.WriteBoolean(FNoRespawn
);
5645 if FDirection
= D_LEFT
then
5651 Mem
.WriteInt(FHealth
);
5653 Mem
.WriteByte(FLives
);
5655 Mem
.WriteInt(FArmor
);
5659 Mem
.WriteInt(FJetFuel
);
5661 Mem
.WriteInt(FPain
);
5663 Mem
.WriteInt(FKills
);
5665 Mem
.WriteInt(FMonsterKills
);
5667 Mem
.WriteInt(FFrags
);
5669 Mem
.WriteByte(FFragCombo
);
5670 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5671 Mem
.WriteDWORD(FLastFrag
);
5673 Mem
.WriteInt(FDeath
);
5674 // Êàêîé ôëàã íåñåò:
5675 Mem
.WriteByte(FFlag
);
5677 Mem
.WriteInt(FSecrets
);
5679 Mem
.WriteByte(FCurrWeap
);
5681 Mem
.WriteWord(FNextWeap
);
5683 Mem
.WriteByte(FNextWeapDelay
);
5684 // Âðåìÿ çàðÿäêè BFG:
5685 Mem
.WriteSmallInt(FBFGFireCounter
);
5687 Mem
.WriteInt(FDamageBuffer
);
5688 // Ïîñëåäíèé óäàðèâøèé:
5689 Mem
.WriteWord(FLastSpawnerUID
);
5690 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5691 Mem
.WriteByte(FLastHit
);
5693 Obj_SaveState(@FObj
, Mem
);
5694 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5695 for i
:= A_BULLETS
to A_HIGH
do
5696 Mem
.WriteWord(FAmmo
[i
]);
5697 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5698 for i
:= A_BULLETS
to A_HIGH
do
5699 Mem
.WriteWord(FMaxAmmo
[i
]);
5701 for i
:= WP_FIRST
to WP_LAST
do
5702 Mem
.WriteBoolean(FWeapon
[i
]);
5703 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5704 for i
:= WP_FIRST
to WP_LAST
do
5705 Mem
.WriteWord(FReloading
[i
]);
5707 if R_ITEM_BACKPACK
in FRulez
then
5712 // Íàëè÷èå êðàñíîãî êëþ÷à:
5713 if R_KEY_RED
in FRulez
then
5718 // Íàëè÷èå çåëåíîãî êëþ÷à:
5719 if R_KEY_GREEN
in FRulez
then
5724 // Íàëè÷èå ñèíåãî êëþ÷à:
5725 if R_KEY_BLUE
in FRulez
then
5730 // Íàëè÷èå áåðñåðêà:
5731 if R_BERSERK
in FRulez
then
5736 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5737 for i
:= MR_SUIT
to MR_MAX
do
5738 Mem
.WriteDWORD(FMegaRulez
[i
]);
5739 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5740 for i
:= T_RESPAWN
to T_FLAGCAP
do
5741 Mem
.WriteDWORD(FTime
[i
]);
5744 Mem
.WriteString(str
);
5754 procedure TPlayer
.LoadState(var Mem
: TBinMemoryReader
);
5764 // Ñèãíàòóðà èãðîêà:
5766 if sig
<> PLAYER_SIGNATURE
then // 'PLYR'
5768 raise EBinSizeError
.Create('TPlayer.LoadState: Wrong Player Signature');
5771 Mem
.ReadBoolean(FIamBot
);
5775 Mem
.ReadString(str
);
5776 if (Self
<> gPlayer1
) and (Self
<> gPlayer2
) then
5779 Mem
.ReadByte(FTeam
);
5781 Mem
.ReadBoolean(FAlive
);
5782 // Èçðàñõîäîâàë ëè âñå æèçíè:
5783 Mem
.ReadBoolean(FNoRespawn
);
5787 FDirection
:= D_LEFT
5789 FDirection
:= D_RIGHT
;
5791 Mem
.ReadInt(FHealth
);
5793 Mem
.ReadByte(FLives
);
5795 Mem
.ReadInt(FArmor
);
5799 Mem
.ReadInt(FJetFuel
);
5803 Mem
.ReadInt(FKills
);
5805 Mem
.ReadInt(FMonsterKills
);
5807 Mem
.ReadInt(FFrags
);
5809 Mem
.ReadByte(FFragCombo
);
5810 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5811 Mem
.ReadDWORD(FLastFrag
);
5813 Mem
.ReadInt(FDeath
);
5814 // Êàêîé ôëàã íåñåò:
5815 Mem
.ReadByte(FFlag
);
5817 Mem
.ReadInt(FSecrets
);
5819 Mem
.ReadByte(FCurrWeap
);
5821 Mem
.ReadWord(FNextWeap
);
5823 Mem
.ReadByte(FNextWeapDelay
);
5824 // Âðåìÿ çàðÿäêè BFG:
5825 Mem
.ReadSmallInt(FBFGFireCounter
);
5827 Mem
.ReadInt(FDamageBuffer
);
5828 // Ïîñëåäíèé óäàðèâøèé:
5829 Mem
.ReadWord(FLastSpawnerUID
);
5830 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5831 Mem
.ReadByte(FLastHit
);
5833 Obj_LoadState(@FObj
, Mem
);
5834 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5835 for i
:= A_BULLETS
to A_HIGH
do
5836 Mem
.ReadWord(FAmmo
[i
]);
5837 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5838 for i
:= A_BULLETS
to A_HIGH
do
5839 Mem
.ReadWord(FMaxAmmo
[i
]);
5841 for i
:= WP_FIRST
to WP_LAST
do
5842 Mem
.ReadBoolean(FWeapon
[i
]);
5843 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5844 for i
:= WP_FIRST
to WP_LAST
do
5845 Mem
.ReadWord(FReloading
[i
]);
5849 Include(FRulez
, R_ITEM_BACKPACK
);
5850 // Íàëè÷èå êðàñíîãî êëþ÷à:
5853 Include(FRulez
, R_KEY_RED
);
5854 // Íàëè÷èå çåëåíîãî êëþ÷à:
5857 Include(FRulez
, R_KEY_GREEN
);
5858 // Íàëè÷èå ñèíåãî êëþ÷à:
5861 Include(FRulez
, R_KEY_BLUE
);
5862 // Íàëè÷èå áåðñåðêà:
5865 Include(FRulez
, R_BERSERK
);
5866 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5867 for i
:= MR_SUIT
to MR_MAX
do
5868 Mem
.ReadDWORD(FMegaRulez
[i
]);
5869 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5870 for i
:= T_RESPAWN
to T_FLAGCAP
do
5871 Mem
.ReadDWORD(FTime
[i
]);
5873 Mem
.ReadString(str
);
5875 Mem
.ReadByte(FColor
.R
);
5876 Mem
.ReadByte(FColor
.G
);
5877 Mem
.ReadByte(FColor
.B
);
5878 if Self
= gPlayer1
then
5880 str
:= gPlayer1Settings
.Model
;
5881 FColor
:= gPlayer1Settings
.Color
;
5883 if Self
= gPlayer2
then
5885 str
:= gPlayer2Settings
.Model
;
5886 FColor
:= gPlayer2Settings
.Color
;
5888 // Îáíîâëÿåì ìîäåëü èãðîêà:
5890 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
5891 FModel
.Color
:= TEAMCOLOR
[FTeam
]
5893 FModel
.Color
:= FColor
;
5896 procedure TPlayer
.AllRulez(Health
: Boolean);
5902 FHealth
:= PLAYER_HP_LIMIT
;
5903 FArmor
:= PLAYER_AP_LIMIT
;
5907 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
5908 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
5909 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5912 procedure TPlayer
.RestoreHealthArmor();
5914 FHealth
:= PLAYER_HP_LIMIT
;
5915 FArmor
:= PLAYER_AP_LIMIT
;
5918 procedure TPlayer
.FragCombo();
5922 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
5924 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
5926 if FFragCombo
< 5 then
5928 Param
:= FUID
or (FFragCombo
shl 16);
5929 if (FComboEvnt
>= Low(gDelayedEvents
)) and
5930 (FComboEvnt
<= High(gDelayedEvents
)) and
5931 gDelayedEvents
[FComboEvnt
].Pending
and
5932 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
5933 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
5935 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
5936 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
5939 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
5947 procedure TPlayer
.GiveItem(ItemType
: Byte);
5951 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
5953 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
5957 if FAir
< AIR_MAX
then
5964 if not (R_BERSERK
in FRulez
) then
5966 Include(FRulez
, R_BERSERK
);
5967 if FBFGFireCounter
< 1 then
5969 FCurrWeap
:= WEAPON_KASTET
;
5971 FModel
.SetWeapon(WEAPON_KASTET
);
5975 FBerserk
:= gTime
+30000;
5977 if FHealth
< PLAYER_HP_SOFT
then
5979 FHealth
:= PLAYER_HP_SOFT
;
5980 FBerserk
:= gTime
+30000;
5985 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
5987 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
5991 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
5993 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
5997 if FJetFuel
< JET_MAX
then
5999 FJetFuel
:= JET_MAX
;
6002 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6003 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6005 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6006 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6008 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6010 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6012 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6013 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6016 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6017 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6018 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6019 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6020 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6021 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6022 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6023 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6024 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6026 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6027 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6028 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6029 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6030 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6031 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6032 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6033 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6034 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6037 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6038 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6039 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6040 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6041 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6043 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6044 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6045 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6046 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6047 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6049 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6050 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6051 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6052 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6054 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6057 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6058 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6059 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6061 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6062 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6067 if g_Game_IsNet
and g_Game_IsServer
then
6068 MH_SEND_PlayerStats(FUID
);
6071 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6076 if (Random(5) = 1) and (Times
= 1) then
6079 if BodyInLiquid(0, 0) then
6081 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6082 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6083 if Random(2) = 0 then
6084 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6086 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6090 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6092 for i
:= 1 to Times
do
6094 Anim
:= TAnimation
.Create(id
, False, 3);
6096 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6097 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6103 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6108 if (Random(10) = 1) and (Times
= 1) then
6111 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6113 for i
:= 1 to Times
do
6115 Anim
:= TAnimation
.Create(id
, False, 3);
6117 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6118 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6124 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6126 FSawSound
.Pause(Enable
);
6127 FSawSoundIdle
.Pause(Enable
);
6128 FSawSoundHit
.Pause(Enable
);
6129 FSawSoundSelect
.Pause(Enable
);
6134 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6139 FObj
.Rect
:= PLAYER_CORPSERECT
;
6140 FModelName
:= ModelName
;
6145 FState
:= CORPSE_STATE_MESS
;
6146 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6150 FState
:= CORPSE_STATE_NORMAL
;
6151 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6155 destructor TCorpse
.Destroy();
6162 procedure TCorpse
.positionChanged (); inline; begin end;
6164 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6166 if (dx
<> 0) or (dy
<> 0) then
6175 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6177 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6178 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6179 w
:= PLAYER_CORPSERECT
.Width
;
6180 h
:= PLAYER_CORPSERECT
.Height
;
6184 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6188 if FState
= CORPSE_STATE_REMOVEME
then
6191 FDamage
:= FDamage
+ Value
;
6193 if FDamage
> 150 then
6195 if FAnimation
<> nil then
6200 FState
:= CORPSE_STATE_REMOVEME
;
6202 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6203 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6204 FModelName
, FColor
);
6205 // Çâóê ìÿñà îò òðóïà:
6206 pm
:= g_PlayerModel_Get(FModelName
);
6207 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6213 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6214 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6215 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6216 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6217 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6222 procedure TCorpse
.Draw();
6224 if FState
= CORPSE_STATE_REMOVEME
then
6227 if FAnimation
<> nil then
6228 FAnimation
.Draw(FObj
.X
, FObj
.Y
, M_NONE
);
6230 if FAnimationMask
<> nil then
6233 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, M_NONE
);
6240 procedure TCorpse
.Update();
6244 if FState
= CORPSE_STATE_REMOVEME
then
6247 if gTime
mod (GAME_TICK
*2) <> 0 then
6249 g_Obj_Move(@FObj
, True, True, True);
6250 positionChanged(); // this updates spatial accelerators
6254 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6255 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6257 st
:= g_Obj_Move(@FObj
, True, True, True);
6258 positionChanged(); // this updates spatial accelerators
6260 if WordBool(st
and MOVE_FALLOUT
) then
6262 FState
:= CORPSE_STATE_REMOVEME
;
6266 if FAnimation
<> nil then
6267 FAnimation
.Update();
6268 if FAnimationMask
<> nil then
6269 FAnimationMask
.Update();
6272 procedure TCorpse
.SaveState(var Mem
: TBinMemoryWriter
);
6281 sig
:= CORPSE_SIGNATURE
; // 'CORP'
6282 Mem
.WriteDWORD(sig
);
6284 Mem
.WriteByte(FState
);
6285 // Íàêîïëåííûé óðîí:
6286 Mem
.WriteByte(FDamage
);
6288 Mem
.WriteByte(FColor
.R
);
6289 Mem
.WriteByte(FColor
.G
);
6290 Mem
.WriteByte(FColor
.B
);
6292 Obj_SaveState(@FObj
, Mem
);
6293 // Åñòü ëè àíèìàöèÿ:
6294 anim
:= FAnimation
<> nil;
6295 Mem
.WriteBoolean(anim
);
6296 // Åñëè åñòü - ñîõðàíÿåì:
6298 FAnimation
.SaveState(Mem
);
6299 // Åñòü ëè ìàñêà àíèìàöèè:
6300 anim
:= FAnimationMask
<> nil;
6301 Mem
.WriteBoolean(anim
);
6302 // Åñëè åñòü - ñîõðàíÿåì:
6304 FAnimationMask
.SaveState(Mem
);
6307 procedure TCorpse
.LoadState(var Mem
: TBinMemoryReader
);
6317 if sig
<> CORPSE_SIGNATURE
then // 'CORP'
6319 raise EBinSizeError
.Create('TCorpse.LoadState: Wrong Corpse Signature');
6322 Mem
.ReadByte(FState
);
6323 // Íàêîïëåííûé óðîí:
6324 Mem
.ReadByte(FDamage
);
6326 Mem
.ReadByte(FColor
.R
);
6327 Mem
.ReadByte(FColor
.G
);
6328 Mem
.ReadByte(FColor
.B
);
6330 Obj_LoadState(@FObj
, Mem
);
6331 // Åñòü ëè àíèìàöèÿ:
6332 Mem
.ReadBoolean(anim
);
6333 // Åñëè åñòü - çàãðóæàåì:
6336 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6337 FAnimation
.LoadState(Mem
);
6339 // Åñòü ëè ìàñêà àíèìàöèè:
6340 Mem
.ReadBoolean(anim
);
6341 // Åñëè åñòü - çàãðóæàåì:
6344 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6345 FAnimationMask
.LoadState(Mem
);
6351 constructor TBot
.Create();
6358 FSpectator
:= False;
6365 for a
:= WP_FIRST
to WP_LAST
do
6367 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6368 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6369 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6373 destructor TBot
.Destroy();
6376 inherited Destroy();
6379 procedure TBot
.Draw();
6383 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6384 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6387 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6389 inherited Respawn(Silent
, Force
);
6392 FSelectedWeapon
:= FCurrWeap
;
6397 procedure TBot
.UpdateCombat();
6410 TTargetRecord
= array of TTarget
;
6412 function Compare(a
, b
: TTarget
): Integer;
6414 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6417 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6419 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6420 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6422 if a
.Dist
> b
.Dist
then // B áëèæå
6424 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6427 else // Ñòðàííî -> A
6432 a
, x1
, y1
, x2
, y2
: Integer;
6433 targets
: TTargetRecord
;
6435 Target
, BestTarget
: TTarget
;
6436 firew
, fireh
: Integer;
6440 vsPlayer
, vsMonster
, ok
: Boolean;
6443 function monsUpdate (mon
: TMonster
): Boolean;
6445 result
:= false; // don't stop
6446 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6448 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6450 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6451 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6453 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6454 if g_TraceVector(x1
, y1
, x2
, y2
) then
6456 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6457 SetLength(targets
, Length(targets
)+1);
6458 with targets
[High(targets
)] do
6465 Rect
:= mon
.Obj
.Rect
;
6466 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6467 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6468 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6477 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6478 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6480 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6481 if FCurrWeap
<> FSelectedWeapon
then
6484 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6485 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6487 RemoveAIFlag('NEEDFIRE');
6490 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6491 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6492 else PressKey(KEY_FIRE
);
6496 // Êîîðäèíàòû ñòâîëà:
6497 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6498 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6500 Target
.UID
:= FTargetUID
;
6503 if Target
.UID
<> 0 then
6504 begin // Öåëü åñòü - íàñòðàèâàåì
6505 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6508 tpla
:= g_Player_Get(Target
.UID
);
6512 if (@FObj
) <> nil then
6519 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6520 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6521 Target
.Rect
:= PLAYER_RECT
;
6522 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6523 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6524 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6525 Target
.IsPlayer
:= True;
6529 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6532 mon
:= g_Monsters_ByUID(Target
.UID
);
6535 Target
.X
:= mon
.Obj
.X
;
6536 Target
.Y
:= mon
.Obj
.Y
;
6538 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6539 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6540 Target
.Rect
:= mon
.Obj
.Rect
;
6541 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6542 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6543 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6544 Target
.IsPlayer
:= False;
6551 begin // Öåëè íåò - îáíóëÿåì
6556 Target
.Visible
:= False;
6557 Target
.Line
:= False;
6558 Target
.IsPlayer
:= False;
6563 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6564 if (not Target
.Line
) or (not Target
.Visible
) then
6568 for a
:= 0 to High(gPlayers
) do
6569 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6570 (gPlayers
[a
].FUID
<> FUID
) and
6571 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6572 (not gPlayers
[a
].NoTarget
) and
6573 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6575 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6576 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6579 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6580 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6582 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6583 if g_TraceVector(x1
, y1
, x2
, y2
) then
6585 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6586 SetLength(targets
, Length(targets
)+1);
6587 with targets
[High(targets
)] do
6589 UID
:= gPlayers
[a
].FUID
;
6590 X
:= gPlayers
[a
].FObj
.X
;
6591 Y
:= gPlayers
[a
].FObj
.Y
;
6594 Rect
:= PLAYER_RECT
;
6595 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6596 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6597 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6605 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6608 // Åñëè åñòü âîçìîæíûå öåëè:
6609 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6610 if targets
<> nil then
6612 // Âûáèðàåì íàèëó÷øóþ öåëü:
6613 BestTarget
:= targets
[0];
6614 if Length(targets
) > 1 then
6615 for a
:= 1 to High(targets
) do
6616 if Compare(BestTarget
, targets
[a
]) = 1 then
6617 BestTarget
:= targets
[a
];
6619 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6620 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6621 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6623 Target
:= BestTarget
;
6625 if (Healthy() = 3) or ((Healthy() = 2)) then
6626 begin // Åñëè çäîðîâû - äîãîíÿåì
6627 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6628 SetAIFlag('GORIGHT', '1');
6629 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6630 SetAIFlag('GOLEFT', '1');
6633 begin // Åñëè ïîáèòû - óáåãàåì
6634 if ((RunDirection() = D_LEFT
) and (Target
.X
< FObj
.X
)) then
6635 SetAIFlag('GORIGHT', '1');
6636 if ((RunDirection() = D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6637 SetAIFlag('GOLEFT', '1');
6640 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6641 SelectWeapon(Abs(x1
-Target
.cX
));
6646 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6647 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6648 if Target
.UID
<> 0 then
6650 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6651 Target
.Y
+ Target
.Rect
.Y
) then
6652 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6653 if (Healthy() = 3) or ((Healthy() = 2)) then
6654 begin // Åñëè çäîðîâû - äîãîíÿåì
6655 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6656 SetAIFlag('GORIGHT', '1');
6657 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6658 SetAIFlag('GOLEFT', '1');
6661 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6663 if ((RunDirection() = D_LEFT
) and (Target
.X
< FObj
.X
)) then
6664 SetAIFlag('GORIGHT', '1');
6665 if ((RunDirection() = D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6666 SetAIFlag('GOLEFT', '1');
6670 begin // Öåëü ïîêà íà "ýêðàíå"
6671 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6672 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6673 FLastVisible
:= gTime
;
6674 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6675 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6677 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6678 SetAIFlag('GORIGHT', '1');
6679 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6680 SetAIFlag('GOLEFT', '1');
6684 // Âûáèðàåì óãîë ââåðõ:
6685 if FDirection
= D_LEFT
then
6686 angle
:= ANGLE_LEFTUP
6688 angle
:= ANGLE_RIGHTUP
;
6690 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6691 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6693 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6694 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6695 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6696 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6697 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6698 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6699 begin // òî íóæíî ñòðåëÿòü ââåðõ
6700 SetAIFlag('NEEDFIRE', '1');
6701 SetAIFlag('NEEDSEEUP', '1');
6704 // Âûáèðàåì óãîë âíèç:
6705 if FDirection
= D_LEFT
then
6706 angle
:= ANGLE_LEFTDOWN
6708 angle
:= ANGLE_RIGHTDOWN
;
6710 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6711 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6713 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6714 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6715 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6716 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6717 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6718 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6719 begin // òî íóæíî ñòðåëÿòü âíèç
6720 SetAIFlag('NEEDFIRE', '1');
6721 SetAIFlag('NEEDSEEDOWN', '1');
6724 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6725 if Target
.Visible
and
6726 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6727 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6729 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6730 if ((FDirection
= D_LEFT
) and (Target
.X
< FObj
.X
)) or
6731 ((FDirection
= D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6732 begin // òî íóæíî ñòðåëÿòü âïåðåä
6733 SetAIFlag('NEEDFIRE', '1');
6734 SetAIFlag('NEEDSEEDOWN', '');
6735 SetAIFlag('NEEDSEEUP', '');
6737 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6738 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6739 if GetRnd(FDifficult
.CloseJump
) then
6740 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6741 if Abs(FObj
.X
-Target
.X
) < 128 then
6745 if Random(a
) = 0 then
6746 SetAIFlag('NEEDJUMP', '1');
6750 // Åñëè öåëü âñå åùå åñòü:
6751 if Target
.UID
<> 0 then
6752 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
6753 Target
.UID
:= 0 // òî çàáûòü öåëü
6754 else // Åñëè âèäåëè íåäàâíî
6755 begin // íî öåëü óáèëè
6756 if Target
.IsPlayer
then
6757 begin // Öåëü - èãðîê
6758 pla
:= g_Player_Get(Target
.UID
);
6759 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
6760 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6761 Target
.UID
:= 0; // òî çàáûòü öåëü
6764 begin // Öåëü - ìîíñòð
6765 mon
:= g_Monsters_ByUID(Target
.UID
);
6766 if (mon
= nil) or (not mon
.alive
) then
6767 Target
.UID
:= 0; // òî çàáûòü öåëü
6770 end; // if Target.UID <> 0
6772 FTargetUID
:= Target
.UID
;
6774 // Åñëè âîçìîæíûõ öåëåé íåò:
6775 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
6776 if targets
= nil then
6777 if GetAIFlag('ATTACKLEFT') <> '' then
6778 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
6779 RemoveAIFlag('ATTACKLEFT');
6781 SetAIFlag('NEEDJUMP', '1');
6783 if RunDirection() = D_RIGHT
then
6784 begin // Èäåì íå â òó ñòîðîíó
6785 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6786 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
6787 SetAIFlag('NEEDFIRE', '1');
6788 SetAIFlag('GOLEFT', '1');
6792 begin // Èäåì â íóæíóþ ñòîðîíó
6793 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6794 SetAIFlag('NEEDFIRE', '1');
6795 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6796 SetAIFlag('GORIGHT', '1');
6800 if GetAIFlag('ATTACKRIGHT') <> '' then
6801 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
6802 RemoveAIFlag('ATTACKRIGHT');
6804 SetAIFlag('NEEDJUMP', '1');
6806 if RunDirection() = D_LEFT
then
6807 begin // Èäåì íå â òó ñòîðîíó
6808 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6809 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
6810 SetAIFlag('NEEDFIRE', '1');
6811 SetAIFlag('GORIGHT', '1');
6816 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6817 SetAIFlag('NEEDFIRE', '1');
6818 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6819 SetAIFlag('GOLEFT', '1');
6823 //HACK! (does it belongs there?)
6824 RealizeCurrentWeapon();
6826 // Åñëè åñòü âîçìîæíûå öåëè:
6827 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
6828 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6829 for a
:= 0 to High(targets
) do
6831 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
6832 if GetRnd(FDifficult
.DiagFire
) then
6834 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
6835 if FDirection
= D_LEFT
then
6836 angle
:= ANGLE_LEFTUP
6838 angle
:= ANGLE_RIGHTUP
;
6840 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6841 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6843 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6844 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6845 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6846 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6847 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6849 SetAIFlag('NEEDFIRE', '1');
6850 SetAIFlag('NEEDSEEUP', '1');
6853 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
6854 if FDirection
= D_LEFT
then
6855 angle
:= ANGLE_LEFTDOWN
6857 angle
:= ANGLE_RIGHTDOWN
;
6859 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6860 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6862 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6863 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6864 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6865 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6866 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6868 SetAIFlag('NEEDFIRE', '1');
6869 SetAIFlag('NEEDSEEDOWN', '1');
6873 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
6874 if targets
[a
].Line
and targets
[a
].Visible
and
6875 (((FDirection
= D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
6876 ((FDirection
= D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
6878 SetAIFlag('NEEDFIRE', '1');
6883 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
6884 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
6885 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
6886 40+GetInterval(FDifficult
.Cover
, 40)) then
6887 SetAIFlag('NEEDJUMP', '1');
6889 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
6890 ammo
:= GetAmmoByWeapon(FCurrWeap
);
6891 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
6892 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
6894 SetAIFlag('SELECTWEAPON', '1');
6896 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
6897 if GetAIFlag('SELECTWEAPON') = '1' then
6900 RemoveAIFlag('SELECTWEAPON');
6904 procedure TBot
.Update();
6917 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
6918 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
6920 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
6922 if g_debug_BotAIOff
= 3 then
6932 RealizeCurrentWeapon();
6939 procedure TBot
.ReleaseKey(Key
: Byte);
6948 function TBot
.KeyPressed(Key
: Word): Boolean;
6950 Result
:= FKeys
[Key
].Pressed
;
6953 function TBot
.GetAIFlag(aName
: String20
): String20
;
6959 aName
:= LowerCase(aName
);
6961 if FAIFlags
<> nil then
6962 for a
:= 0 to High(FAIFlags
) do
6963 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6965 Result
:= FAIFlags
[a
].Value
;
6970 procedure TBot
.RemoveAIFlag(aName
: String20
);
6974 if FAIFlags
= nil then Exit
;
6976 aName
:= LowerCase(aName
);
6978 for a
:= 0 to High(FAIFlags
) do
6979 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6981 if a
<> High(FAIFlags
) then
6982 for b
:= a
to High(FAIFlags
)-1 do
6983 FAIFlags
[b
] := FAIFlags
[b
+1];
6985 SetLength(FAIFlags
, Length(FAIFlags
)-1);
6990 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
6998 aName
:= LowerCase(aName
);
7000 if FAIFlags
<> nil then
7001 for a
:= 0 to High(FAIFlags
) do
7002 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7008 if ok
then FAIFlags
[a
].Value
:= fValue
7011 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7012 with FAIFlags
[High(FAIFlags
)] do
7020 procedure TBot
.UpdateMove
;
7022 procedure GoLeft(Time
: Word = 1);
7024 ReleaseKey(KEY_LEFT
);
7025 ReleaseKey(KEY_RIGHT
);
7026 PressKey(KEY_LEFT
, Time
);
7027 SetDirection(D_LEFT
);
7030 procedure GoRight(Time
: Word = 1);
7032 ReleaseKey(KEY_LEFT
);
7033 ReleaseKey(KEY_RIGHT
);
7034 PressKey(KEY_RIGHT
, Time
);
7035 SetDirection(D_RIGHT
);
7038 function Rnd(a
: Word): Boolean;
7040 Result
:= Random(a
) = 0;
7043 procedure Turn(Time
: Word = 1200);
7045 if RunDirection() = D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7050 ReleaseKey(KEY_LEFT
);
7051 ReleaseKey(KEY_RIGHT
);
7054 function CanRunLeft(): Boolean;
7056 Result
:= not CollideLevel(-1, 0);
7059 function CanRunRight(): Boolean;
7061 Result
:= not CollideLevel(1, 0);
7064 function CanRun(): Boolean;
7066 if RunDirection() = D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7069 procedure Jump(Time
: Word = 30);
7071 PressKey(KEY_JUMP
, Time
);
7074 function NearHole(): Boolean;
7078 { TODO 5 : Ëåñòíèöû }
7079 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
7080 for x
:= 1 to PLAYER_RECT
.Width
do
7081 if (not StayOnStep(x
*sx
, 0)) and
7082 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7083 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7092 function BorderHole(): Boolean;
7096 { TODO 5 : Ëåñòíèöû }
7097 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
7098 for x
:= 1 to PLAYER_RECT
.Width
do
7099 if (not StayOnStep(x
*sx
, 0)) and
7100 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7101 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7103 for xx
:= x
to x
+32 do
7104 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7114 function NearDeepHole(): Boolean;
7120 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
7123 for x
:= 1 to PLAYER_RECT
.Width
do
7124 if (not StayOnStep(x
*sx
, 0)) and
7125 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7126 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7128 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7130 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7135 end else Result
:= False;
7138 function OverDeepHole(): Boolean;
7145 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7147 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7154 function OnGround(): Boolean;
7156 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7159 function OnLadder(): Boolean;
7161 Result
:= FullInStep(0, 0);
7164 function BelowLadder(): Boolean;
7166 Result
:= (FullInStep(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7167 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7168 (FullInStep(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7169 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7172 function BelowLiftUp(): Boolean;
7174 Result
:= ((FullInLift(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7175 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7176 ((FullInLift(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7177 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7180 function OnTopLift(): Boolean;
7182 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7185 function CanJumpOver(): Boolean;
7189 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
7193 if not CollideLevel(sx
, 0) then Exit
;
7195 for y
:= 1 to BOT_MAXJUMP
do
7196 if CollideLevel(0, -y
) then Exit
else
7197 if not CollideLevel(sx
, -y
) then
7204 function CanJumpUp(Dist
: ShortInt): Boolean;
7211 if CollideLevel(Dist
, 0) then Exit
;
7214 for y
:= 0 to BOT_MAXJUMP
do
7215 if CollideLevel(Dist
, -y
) then
7224 for yy
:= y
+1 to BOT_MAXJUMP
do
7225 if not CollideLevel(Dist
, -yy
) then
7234 for y
:= 0 to BOT_MAXJUMP
do
7235 if CollideLevel(0, -y
) then
7243 if y
< yy
then Exit
;
7248 function IsSafeTrigger(): Boolean;
7253 if gTriggers
= nil then
7255 for a
:= 0 to High(gTriggers
) do
7256 if Collide(gTriggers
[a
].X
,
7259 gTriggers
[a
].Height
) and
7260 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7261 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7262 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7263 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7264 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7269 // Âîçìîæíî, íàæèìàåì êíîïêó:
7270 if Rnd(16) and IsSafeTrigger() then
7273 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7274 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7276 ReleaseKey(KEY_LEFT
);
7277 ReleaseKey(KEY_RIGHT
);
7281 // Èäåì âëåâî, åñëè íàäî áûëî:
7282 if GetAIFlag('GOLEFT') <> '' then
7284 RemoveAIFlag('GOLEFT');
7285 if CanRunLeft() then
7289 // Èäåì âïðàâî, åñëè íàäî áûëî:
7290 if GetAIFlag('GORIGHT') <> '' then
7292 RemoveAIFlag('GORIGHT');
7293 if CanRunRight() then
7297 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7298 if FObj
.X
< -32 then
7301 if FObj
.X
+32 > gMapInfo
.Width
then
7304 // Ïðûãàåì, åñëè íàäî áûëî:
7305 if GetAIFlag('NEEDJUMP') <> '' then
7308 RemoveAIFlag('NEEDJUMP');
7311 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7312 if GetAIFlag('NEEDSEEUP') <> '' then
7315 ReleaseKey(KEY_DOWN
);
7316 PressKey(KEY_UP
, 20);
7317 RemoveAIFlag('NEEDSEEUP');
7320 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7321 if GetAIFlag('NEEDSEEDOWN') <> '' then
7324 ReleaseKey(KEY_DOWN
);
7325 PressKey(KEY_DOWN
, 20);
7326 RemoveAIFlag('NEEDSEEDOWN');
7329 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7330 if GetAIFlag('GOINHOLE') <> '' then
7331 if not OnGround() then
7333 ReleaseKey(KEY_LEFT
);
7334 ReleaseKey(KEY_RIGHT
);
7335 RemoveAIFlag('GOINHOLE');
7336 SetAIFlag('FALLINHOLE', '1');
7339 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7340 if GetAIFlag('FALLINHOLE') <> '' then
7342 RemoveAIFlag('FALLINHOLE');
7344 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7345 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7346 if GetAIFlag('FALLINHOLE') = '' then
7347 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7353 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7355 CanJumpUp(IfThen(RunDirection() = D_LEFT
, -1, 1)*32) and
7359 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7360 if OnGround() and NearHole() then
7361 if NearDeepHole() then // Åñëè ýòî áåçäíà
7363 0..3: Turn(); // Áåæèì îáðàòíî
7364 4: Jump(); // Ïðûãàåì
7365 5: begin // Ïðûãàåì îáðàòíî
7370 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7371 if GetAIFlag('GOINHOLE') = '' then
7373 0: Turn(); // Íå íóæíî òóäà
7374 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7375 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7376 if BorderHole() then
7377 SetAIFlag('GOINHOLE', '1');
7380 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7381 if (not CanRun()) and OnGround() then
7383 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7384 if CanJumpOver() or OnLadder() then
7386 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7387 if Random(2) = 0 then
7389 if IsSafeTrigger() then
7395 // Îñòàëîñü ìàëî âîçäóõà:
7396 if FAir
< 36 * 2 then
7399 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7400 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7401 if BodyInAcid(0, 0) then
7405 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7407 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7408 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7411 {function TBot.NeedItem(Item: Byte): Byte;
7416 procedure TBot
.SelectWeapon(Dist
: Integer);
7420 function HaveAmmo(weapon
: Byte): Boolean;
7423 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7424 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7425 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7426 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7427 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7428 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7429 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7430 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7431 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7432 else Result
:= True;
7437 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7439 if Dist
> BOT_LONGDIST
then
7440 begin // Äàëüíèé áîé
7442 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7444 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7448 else //if Dist > BOT_UNSAFEDIST then
7449 begin // Áëèæíèé áîé
7451 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7453 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7460 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7462 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7468 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7470 Result
:= inherited PickItem(ItemType
, force
, remove
);
7472 if Result
then SetAIFlag('SELECTWEAPON', '1');
7475 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7477 Result
:= inherited Heal(value
, Soft
);
7480 function TBot
.Healthy(): Byte;
7482 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7483 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7484 else if (FHealth
> 50) then Result
:= 2
7485 else if (FHealth
> 20) then Result
:= 1
7489 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7491 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7492 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7495 procedure TBot
.OnDamage(Angle
: SmallInt);
7503 if (Angle
= 0) or (Angle
= 180) then
7506 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7507 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7509 pla
:= g_Player_Get(FLastSpawnerUID
);
7510 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7511 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7514 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7515 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7517 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7518 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7519 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7524 SetAIFlag('ATTACKLEFT', '1')
7526 SetAIFlag('ATTACKRIGHT', '1');
7530 function TBot
.RunDirection(): TDirection
;
7532 if Abs(Vel
.X
) >= 1 then
7534 if Vel
.X
> 0 then Result
:= D_RIGHT
else Result
:= D_LEFT
;
7536 Result
:= FDirection
;
7539 function TBot
.GetRnd(a
: Byte): Boolean;
7541 if a
= 0 then Result
:= False
7542 else if a
= 255 then Result
:= True
7543 else Result
:= Random(256) > 255-a
;
7546 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7548 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7551 procedure TBot
.SaveState(var Mem
: TBinMemoryWriter
);
7557 inherited SaveState(Mem
);
7559 // Âûáðàííîå îðóæèå:
7560 Mem
.WriteByte(FSelectedWeapon
);
7562 Mem
.WriteWord(FTargetUID
);
7563 // Âðåìÿ ïîòåðè öåëè:
7564 Mem
.WriteDWORD(FLastVisible
);
7565 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7566 dw
:= Length(FAIFlags
);
7569 for i
:= 0 to Integer(dw
)-1 do
7571 Mem
.WriteString(FAIFlags
[i
].Name
, 20);
7572 Mem
.WriteString(FAIFlags
[i
].Value
, 20);
7574 // Íàñòðîéêè ñëîæíîñòè:
7576 Mem
.WriteMemory(p
, SizeOf(TDifficult
));
7579 procedure TBot
.LoadState(var Mem
: TBinMemoryReader
);
7585 inherited LoadState(Mem
);
7587 // Âûáðàííîå îðóæèå:
7588 Mem
.ReadByte(FSelectedWeapon
);
7590 Mem
.ReadWord(FTargetUID
);
7591 // Âðåìÿ ïîòåðè öåëè:
7592 Mem
.ReadDWORD(FLastVisible
);
7593 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7595 SetLength(FAIFlags
, dw
);
7597 for i
:= 0 to Integer(dw
)-1 do
7599 Mem
.ReadString(FAIFlags
[i
].Name
);
7600 Mem
.ReadString(FAIFlags
[i
].Value
);
7602 // Íàñòðîéêè ñëîæíîñòè:
7603 Mem
.ReadMemory(p
, dw
);
7604 if dw
<> SizeOf(TDifficult
) then
7606 raise EBinSizeError
.Create('TBot.LoadState: Wrong FDifficult Size');
7608 FDifficult
:= TDifficult(p
^);