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, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
23 {$IFDEF USE_MEMPOOL}mempool
,{$ENDIF}
24 g_base
, g_playermodel
, g_basic
, g_textures
,
25 g_weapons
, g_phys
, g_sound
, g_saveload
, MAPDEF
,
58 AmmoLimits
: Array [0..1] of Array [A_BULLETS
..A_HIGH
] of Word =
59 ((200, 50, 50, 300, 100),
60 (400, 100, 100, 600, 200));
81 ANGLE_NONE
= Low(SmallInt);
83 CORPSE_STATE_REMOVEME
= 0;
84 CORPSE_STATE_NORMAL
= 1;
85 CORPSE_STATE_MESS
= 2;
87 PLAYER_RECT
: TRectWH
= (X
:15; Y
:12; Width
:34; Height
:52);
88 PLAYER_RECT_CX
= 15+(34 div 2);
89 PLAYER_RECT_CY
= 12+(52 div 2);
90 PLAYER_CORPSERECT
: TRectWH
= (X
:15; Y
:48; Width
:34; Height
:16);
93 PLAYER_HP_LIMIT
= 200;
95 PLAYER_AP_LIMIT
= 200;
99 PLAYER_BURN_TIME
= 110;
101 PLAYER1_DEF_COLOR
: TRGB
= (R
:64; G
:175; B
:48);
102 PLAYER2_DEF_COLOR
: TRGB
= (R
:96; G
:96; B
:96);
106 JET_MAX
= 540; // ~30 sec
108 ANGLE_RIGHTDOWN
= -35;
110 ANGLE_LEFTDOWN
= -145;
111 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
112 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
131 TPlayerStatArray
= Array of TPlayerStat
;
133 TPlayerSavedState
= record
141 Ammo
: Array [A_BULLETS
..A_HIGH
] of Word;
142 MaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
143 Weapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
144 Rulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
153 TPlayer
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
161 FDirection
: TDirection
;
169 FMonsterKills
: Integer;
175 FCanJetpack
: Boolean;
181 FNextWeapDelay
: Byte; // frames
182 FBFGFireCounter
: SmallInt;
183 FLastSpawnerUID
: Word;
187 FSpectatePlayer
: Integer;
188 FFirePainTime
: Integer;
191 FSavedStateNum
: Integer;
193 FModel
: TPlayerModel
;
194 FPunchAnim
: TAnimationState
;
197 FActionForce
: Boolean;
198 FActionChanged
: Boolean;
200 FFireAngle
: SmallInt;
204 FShellTimer
: Integer;
206 FSawSound
: TPlayableSound
;
207 FSawSoundIdle
: TPlayableSound
;
208 FSawSoundHit
: TPlayableSound
;
209 FSawSoundSelect
: TPlayableSound
;
210 FFlameSoundOn
: TPlayableSound
;
211 FFlameSoundOff
: TPlayableSound
;
212 FFlameSoundWork
: TPlayableSound
;
213 FJetSoundOn
: TPlayableSound
;
214 FJetSoundOff
: TPlayableSound
;
215 FJetSoundFly
: TPlayableSound
;
219 FJustTeleported
: Boolean;
221 mEDamageType
: Integer;
224 function CollideLevel(XInc
, YInc
: Integer): Boolean;
225 function StayOnStep(XInc
, YInc
: Integer): Boolean;
226 function HeadInLiquid(XInc
, YInc
: Integer): Boolean;
227 function BodyInLiquid(XInc
, YInc
: Integer): Boolean;
228 function BodyInAcid(XInc
, YInc
: Integer): Boolean;
229 function FullInLift(XInc
, YInc
: Integer): Integer;
230 {procedure CollideItem();}
231 procedure FlySmoke(Times
: DWORD
= 1);
232 procedure OnFireFlame(Times
: DWORD
= 1);
233 procedure SetAction(Action
: Byte; Force
: Boolean = False);
234 procedure OnDamage(Angle
: SmallInt); virtual;
235 function firediry(): Integer;
238 procedure Run(Direction
: TDirection
);
239 procedure NextWeapon();
240 procedure PrevWeapon();
247 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
248 procedure resetWeaponQueue ();
249 function hasAmmoForWeapon (weapon
: Byte): Boolean;
251 procedure doDamage (v
: Integer);
253 function refreshCorpse(): Boolean;
256 FDamageBuffer
: Integer;
258 FAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
259 FMaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
260 FWeapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
261 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
263 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
264 FReloading
: Array [WP_FIRST
..WP_LAST
] of Word;
265 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
266 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
268 FPreferredTeam
: Byte;
271 FWantsInGame
: Boolean;
276 FActualModelName
: string;
283 FSpawnInvul
: Integer;
285 FWaitForFirstSpawn
: Boolean; // set to `true` in server, used to spawn a player on first full state request
288 // debug: viewport offset
289 viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer;
291 function isValidViewPort (): Boolean; inline;
293 constructor Create(); virtual;
294 destructor Destroy(); override;
295 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
296 function GetRespawnPoint(): Byte;
297 procedure PressKey(Key
: Byte; Time
: Word = 1);
298 procedure ReleaseKeys();
299 procedure SetModel(ModelName
: String);
300 procedure SetColor(Color
: TRGB
);
301 function GetColor(): TRGB
;
302 procedure SetWeapon(W
: Byte);
303 function IsKeyPressed(K
: Byte): Boolean;
304 function GetKeys(): Byte;
305 function PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean; virtual;
306 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
307 function Collide(Panel
: TPanel
): Boolean; overload
;
308 function Collide(X
, Y
: Integer): Boolean; overload
;
309 procedure SetDirection(Direction
: TDirection
);
310 procedure GetSecret();
311 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
313 procedure Push(vx
, vy
: Integer);
314 procedure ChangeModel(ModelName
: String);
315 procedure SwitchTeam
;
316 procedure ChangeTeam(Team
: Byte);
318 function GetFlag(Flag
: Byte): Boolean;
319 procedure SetFlag(Flag
: Byte);
320 function DropFlag(Silent
: Boolean = True): Boolean;
321 procedure AllRulez(Health
: Boolean);
322 procedure RestoreHealthArmor();
323 procedure FragCombo();
324 procedure GiveItem(ItemType
: Byte);
325 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
326 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
327 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
328 procedure MakeBloodSimple(Count
: Word);
329 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
330 procedure Reset(Force
: Boolean);
331 procedure Spectate(NoMove
: Boolean = False);
332 procedure SwitchNoClip
;
333 procedure SoftReset();
334 procedure PreUpdate();
335 procedure Update(); virtual;
336 procedure RememberState();
337 procedure RecallState();
338 procedure SaveState (st
: TStream
); virtual;
339 procedure LoadState (st
: TStream
); virtual;
340 procedure PauseSounds(Enable
: Boolean);
341 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
342 procedure DoLerp(Level
: Integer = 2);
343 procedure SetLerp(XTo
, YTo
: Integer);
344 procedure QueueWeaponSwitch(Weapon
: Byte);
345 procedure RealizeCurrentWeapon();
349 procedure JetpackOff
;
350 procedure CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
352 //WARNING! this does nothing for now, but still call it!
353 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
355 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
356 procedure moveBy (dx
, dy
: Integer); inline;
358 function getCameraObj(): TObj
;
360 function GetAmmoByWeapon(Weapon
: Byte): Word; // private state
363 property Vel
: TPoint2i read FObj
.Vel
;
364 property Obj
: TObj read FObj
;
366 property Name
: String read FName write FName
;
367 property Model
: TPlayerModel read FModel
;
368 property Health
: Integer read FHealth write FHealth
;
369 property Lives
: Byte read FLives write FLives
;
370 property Armor
: Integer read FArmor write FArmor
;
371 property Air
: Integer read FAir write FAir
;
372 property JetFuel
: Integer read FJetFuel write FJetFuel
;
373 property Frags
: Integer read FFrags write FFrags
;
374 property Death
: Integer read FDeath write FDeath
;
375 property Kills
: Integer read FKills write FKills
;
376 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
377 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
378 property Secrets
: Integer read FSecrets
;
379 property GodMode
: Boolean read FGodMode write FGodMode
;
380 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
381 property NoReload
: Boolean read FNoReload write FNoReload
;
382 property alive
: Boolean read FAlive write FAlive
;
383 property Flag
: Byte read FFlag
;
384 property Team
: Byte read FTeam write FTeam
;
385 property Direction
: TDirection read FDirection
;
386 property GameX
: Integer read FObj
.X write FObj
.X
;
387 property GameY
: Integer read FObj
.Y write FObj
.Y
;
388 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
389 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
390 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
391 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
392 property IncCam
: Integer read FIncCam write FIncCam
;
393 property IncCamOld
: Integer read FIncCamOld write FIncCamOld
;
394 property SlopeOld
: Integer read FSlopeOld write FSlopeOld
;
395 property UID
: Word read FUID write FUID
;
396 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
397 property NetTime
: LongWord read FNetTime write FNetTime
;
400 property Angle_
: SmallInt read FAngle
;
401 property Spectator
: Boolean read FSpectator
;
402 property NoRespawn
: Boolean read FNoRespawn
;
403 property Berserk
: Integer read FBerserk
;
404 property Pain
: Integer read FPain
;
405 property Pickup
: Integer read FPickup
;
406 property PunchAnim
: TAnimationState read FPunchAnim write FPunchAnim
;
407 property SpawnInvul
: Integer read FSpawnInvul
;
408 property Ghost
: Boolean read FGhost
;
411 property eName
: String read FName write FName
;
412 property eHealth
: Integer read FHealth write FHealth
;
413 property eLives
: Byte read FLives write FLives
;
414 property eArmor
: Integer read FArmor write FArmor
;
415 property eAir
: Integer read FAir write FAir
;
416 property eJetFuel
: Integer read FJetFuel write FJetFuel
;
417 property eFrags
: Integer read FFrags write FFrags
;
418 property eDeath
: Integer read FDeath write FDeath
;
419 property eKills
: Integer read FKills write FKills
;
420 property eCurrWeap
: Byte read FCurrWeap write FCurrWeap
;
421 property eMonsterKills
: Integer read FMonsterKills write FMonsterKills
;
422 property eSecrets
: Integer read FSecrets write FSecrets
;
423 property eGodMode
: Boolean read FGodMode write FGodMode
;
424 property eNoTarget
: Boolean read FNoTarget write FNoTarget
;
425 property eNoReload
: Boolean read FNoReload write FNoReload
;
426 property eAlive
: Boolean read FAlive write FAlive
;
427 property eFlag
: Byte read FFlag
;
428 property eTeam
: Byte read FTeam write FTeam
;
429 property eDirection
: TDirection read FDirection
;
430 property eGameX
: Integer read FObj
.X write FObj
.X
;
431 property eGameY
: Integer read FObj
.Y write FObj
.Y
;
432 property eGameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
433 property eGameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
434 property eGameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
435 property eGameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
436 property eIncCam
: Integer read FIncCam write FIncCam
;
437 property eUID
: Word read FUID
;
438 property eJustTeleported
: Boolean read FJustTeleported
;
439 property eNetTime
: LongWord read FNetTime
;
441 // set this before assigning something to `eDamage`
442 property eDamageType
: Integer read mEDamageType write mEDamageType
;
443 property eDamage
: Integer write doDamage
;
454 WeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
455 CloseWeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
456 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
459 procedure save (st
: TStream
);
460 procedure load (st
: TStream
);
468 TBot
= class(TPlayer
)
470 FSelectedWeapon
: Byte;
473 FAIFlags
: Array of TAIFlag
;
474 FDifficult
: TDifficult
;
476 function GetRnd(a
: Byte): Boolean;
477 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
478 function RunDirection(): TDirection
;
479 function FullInStep(XInc
, YInc
: Integer): Boolean;
480 //function NeedItem(Item: Byte): Byte;
481 procedure SelectWeapon(Dist
: Integer);
482 procedure SetAIFlag(aName
, fValue
: String20
);
483 function GetAIFlag(aName
: String20
): String20
;
484 procedure RemoveAIFlag(aName
: String20
);
485 function Healthy(): Byte;
486 procedure UpdateMove();
487 procedure UpdateCombat();
488 function KeyPressed(Key
: Word): Boolean;
489 procedure ReleaseKey(Key
: Byte);
490 function TargetOnScreen(TX
, TY
: Integer): Boolean;
491 procedure OnDamage(Angle
: SmallInt); override;
494 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
495 constructor Create(); override;
496 destructor Destroy(); override;
497 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
498 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
499 procedure Update(); override;
500 procedure SaveState (st
: TStream
); override;
501 procedure LoadState (st
: TStream
); override;
512 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
513 procedure moveBy (dx
, dy
: Integer); inline;
515 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
518 TCorpse
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
525 FModel
: TPlayerModel
;
528 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
529 destructor Destroy(); override;
530 procedure Damage(Value
: Word; SpawnerUID
: Word; vx
, vy
: Integer);
532 procedure SaveState (st
: TStream
);
533 procedure LoadState (st
: TStream
);
535 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
536 procedure moveBy (dx
, dy
: Integer); inline;
538 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
540 function ObjPtr (): PObj
; inline;
542 property Obj
: TObj read FObj
; // copies object
543 property State
: Byte read FState
;
544 property Mess
: Boolean read FMess
;
545 property Model
: TPlayerModel read FModel
;
548 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
554 gPlayers
: Array of TPlayer
;
555 gCorpses
: Array of TCorpse
;
556 gShells
: Array of TShell
;
557 gTeamStat
: TTeamStat
;
558 gFly
: Boolean = False;
559 gAimLine
: Boolean = False;
560 gChatBubble
: Integer = 0;
561 gPlayerIndicator
: Integer = 1;
562 gPlayerIndicatorStyle
: Integer = 0;
564 gSpectLatchPID1
: Word = 0;
565 gSpectLatchPID2
: Word = 0;
566 MAX_RUNVEL
: Integer = 8;
567 VEL_JUMP
: Integer = 10;
568 SHELL_TIMEOUT
: Cardinal = 60000;
570 function Lerp(X
, Y
, Factor
: Integer): Integer;
572 procedure g_Corpses_SetMax(Count
: Word);
573 function g_Corpses_GetMax(): Word;
574 procedure g_Shells_SetMax(Count
: Word);
575 function g_Shells_GetMax(): Word;
577 procedure g_Player_Init();
578 procedure g_Player_Free();
579 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
580 function g_Player_CreateFromState (st
: TStream
): Word;
581 procedure g_Player_Remove(UID
: Word);
582 procedure g_Player_ResetTeams();
583 procedure g_Player_PreUpdate();
584 procedure g_Player_UpdateAll();
585 procedure g_Player_RememberAll();
586 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
587 function g_Player_Get(UID
: Word): TPlayer
;
588 function g_Player_GetCount(): Byte;
589 function g_Player_GetStats(): TPlayerStatArray
;
590 function g_Player_ValidName(Name
: String): Boolean;
591 function g_Player_CreateCorpse(Player
: TPlayer
): Integer;
592 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
593 procedure g_Player_UpdatePhysicalObjects();
594 procedure g_Player_RemoveAllCorpses();
595 procedure g_Player_Corpses_SaveState (st
: TStream
);
596 procedure g_Player_Corpses_LoadState (st
: TStream
);
597 procedure g_Player_ResetReady();
598 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
599 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
600 procedure g_Bot_MixNames();
601 procedure g_Bot_RemoveAll();
606 {$IFDEF ENABLE_HOLMES}
621 e_log
, g_map
, g_items
, g_console
, Math
,
622 g_options
, g_triggers
, g_game
, g_grid
, e_res
,
623 wadreader
, g_monsters
, CONFIG
, g_language
,
627 const PLR_SAVE_VERSION
= 0;
637 diag_precision
: Byte;
641 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
642 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
643 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
647 TIME_RESPAWN1
= 1500;
648 TIME_RESPAWN2
= 2000;
649 TIME_RESPAWN3
= 3000;
650 PLAYER_SUIT_TIME
= 30000;
651 PLAYER_INVUL_TIME
= 30000;
652 PLAYER_INVIS_TIME
= 35000;
653 FRAG_COMBO_TIME
= 3000;
656 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
659 BOT_UNSAFEDIST
= 128;
660 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
661 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
662 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
663 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
664 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
665 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
666 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
667 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
668 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
669 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
670 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
671 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
672 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
673 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
674 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
675 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
676 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
677 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
678 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
679 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
680 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
681 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
682 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
683 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
684 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
685 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
687 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
688 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
690 BOTNAMES_FILENAME
= 'botnames.txt';
691 BOTLIST_FILENAME
= 'botlist.txt';
694 MaxCorpses
: Word = 20;
695 MaxShells
: Word = 300;
696 CurrentShell
: Integer = 0;
697 BotNames
: Array of String;
698 BotList
: Array of TBotProfile
;
699 SavedStates
: Array of TPlayerSavedState
;
702 function Lerp(X
, Y
, Factor
: Integer): Integer;
704 Result
:= X
+ ((Y
- X
) div Factor
);
707 function SameTeam(UID1
, UID2
: Word): Boolean;
711 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
712 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
714 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
716 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
717 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
719 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
722 procedure g_Shells_SetMax(Count
: Word);
725 SetLength(gShells
, Count
);
727 if CurrentShell
>= Count
then
731 function g_Shells_GetMax(): Word;
737 procedure g_Corpses_SetMax(Count
: Word);
740 SetLength(gCorpses
, Count
);
743 function g_Corpses_GetMax(): Word;
745 Result
:= MaxCorpses
;
748 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
758 // Есть ли место в gPlayers:
759 if gPlayers
<> nil then
760 for a
:= 0 to High(gPlayers
) do
761 if gPlayers
[a
] = nil then
767 // Нет места - расширяем gPlayers:
770 SetLength(gPlayers
, Length(gPlayers
)+1);
774 // Создаем объект игрока:
776 gPlayers
[a
] := TBot
.Create()
778 gPlayers
[a
] := TPlayer
.Create();
781 gPlayers
[a
].FActualModelName
:= ModelName
;
782 gPlayers
[a
].SetModel(ModelName
);
784 // Нет модели - создание не возможно:
785 if gPlayers
[a
].FModel
= nil then
789 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
793 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
794 if Random(2) = 0 then
798 gPlayers
[a
].FPreferredTeam
:= Team
;
800 case gGameSettings
.GameMode
of
801 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
803 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
805 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
808 // Если командная игра - красим модель в цвет команды:
809 gPlayers
[a
].FColor
:= Color
;
810 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
811 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
813 gPlayers
[a
].FModel
.Color
:= Color
;
815 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
816 gPlayers
[a
].FAlive
:= False;
818 Result
:= gPlayers
[a
].FUID
;
821 function g_Player_CreateFromState (st
: TStream
): Word;
828 if (st
= nil) then exit
; //???
831 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
832 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
835 Bot
:= utils
.readBool(st
);
840 // Есть ли место в gPlayers:
841 for a
:= 0 to High(gPlayers
) do if (gPlayers
[a
] = nil) then begin ok
:= true; break
; end;
843 // Нет места - расширяем gPlayers
846 SetLength(gPlayers
, Length(gPlayers
)+1);
850 // Создаем объект игрока
852 gPlayers
[a
] := TBot
.Create()
854 gPlayers
[a
] := TPlayer
.Create();
855 gPlayers
[a
].FIamBot
:= Bot
;
856 gPlayers
[a
].FPhysics
:= True;
859 gPlayers
[a
].FUID
:= utils
.readWord(st
);
861 gPlayers
[a
].FName
:= utils
.readStr(st
);
863 gPlayers
[a
].FTeam
:= utils
.readByte(st
);
864 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
866 gPlayers
[a
].FAlive
:= utils
.readBool(st
);
867 // Израсходовал ли все жизни
868 gPlayers
[a
].FNoRespawn
:= utils
.readBool(st
);
870 b
:= utils
.readByte(st
);
871 if b
= 1 then gPlayers
[a
].FDirection
:= TDirection
.D_LEFT
else gPlayers
[a
].FDirection
:= TDirection
.D_RIGHT
; // b = 2
873 gPlayers
[a
].FHealth
:= utils
.readLongInt(st
);
875 gPlayers
[a
].FHandicap
:= utils
.readLongInt(st
);
877 gPlayers
[a
].FLives
:= utils
.readByte(st
);
879 gPlayers
[a
].FArmor
:= utils
.readLongInt(st
);
881 gPlayers
[a
].FAir
:= utils
.readLongInt(st
);
883 gPlayers
[a
].FJetFuel
:= utils
.readLongInt(st
);
885 gPlayers
[a
].FPain
:= utils
.readLongInt(st
);
887 gPlayers
[a
].FKills
:= utils
.readLongInt(st
);
889 gPlayers
[a
].FMonsterKills
:= utils
.readLongInt(st
);
891 gPlayers
[a
].FFrags
:= utils
.readLongInt(st
);
893 gPlayers
[a
].FFragCombo
:= utils
.readByte(st
);
894 // Время последнего фрага
895 gPlayers
[a
].FLastFrag
:= utils
.readLongWord(st
);
897 gPlayers
[a
].FDeath
:= utils
.readLongInt(st
);
899 gPlayers
[a
].FFlag
:= utils
.readByte(st
);
901 gPlayers
[a
].FSecrets
:= utils
.readLongInt(st
);
903 gPlayers
[a
].FCurrWeap
:= utils
.readByte(st
);
904 // Следующее желаемое оружие
905 gPlayers
[a
].FNextWeap
:= utils
.readWord(st
);
907 gPlayers
[a
].FNextWeapDelay
:= utils
.readByte(st
);
909 gPlayers
[a
].FBFGFireCounter
:= utils
.readSmallInt(st
);
911 gPlayers
[a
].FDamageBuffer
:= utils
.readLongInt(st
);
912 // Последний ударивший
913 gPlayers
[a
].FLastSpawnerUID
:= utils
.readWord(st
);
914 // Тип последнего полученного урона
915 gPlayers
[a
].FLastHit
:= utils
.readByte(st
);
917 Obj_LoadState(@gPlayers
[a
].FObj
, st
);
918 // Текущее количество патронов
919 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FAmmo
[i
] := utils
.readWord(st
);
920 // Максимальное количество патронов
921 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FMaxAmmo
[i
] := utils
.readWord(st
);
923 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FWeapon
[i
] := utils
.readBool(st
);
924 // Время перезарядки оружия
925 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FReloading
[i
] := utils
.readWord(st
);
927 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
928 // Наличие красного ключа
929 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
930 // Наличие зеленого ключа
931 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
932 // Наличие синего ключа
933 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
935 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_BERSERK
);
936 // Время действия специальных предметов
937 for i
:= MR_SUIT
to MR_MAX
do gPlayers
[a
].FMegaRulez
[i
] := utils
.readLongWord(st
);
938 // Время до повторного респауна, смены оружия, исользования, захвата флага
939 for i
:= T_RESPAWN
to T_FLAGCAP
do gPlayers
[a
].FTime
[i
] := utils
.readLongWord(st
);
942 gPlayers
[a
].FActualModelName
:= utils
.readStr(st
);
944 gPlayers
[a
].FColor
.R
:= utils
.readByte(st
);
945 gPlayers
[a
].FColor
.G
:= utils
.readByte(st
);
946 gPlayers
[a
].FColor
.B
:= utils
.readByte(st
);
947 // Обновляем модель игрока
948 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
950 // Нет модели - создание невозможно
951 if (gPlayers
[a
].FModel
= nil) then
955 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
959 // Если командная игра - красим модель в цвет команды
960 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
961 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
963 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
965 result
:= gPlayers
[a
].FUID
;
969 procedure g_Player_ResetTeams();
973 if g_Game_IsClient
then
975 if gPlayers
= nil then
977 for a
:= Low(gPlayers
) to High(gPlayers
) do
978 if gPlayers
[a
] <> nil then
979 case gGameSettings
.GameMode
of
981 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
983 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
984 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
985 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
988 gPlayers
[a
].ChangeTeam(TEAM_RED
)
990 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
993 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
997 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
1000 _name
, _model
: String;
1003 if not g_Game_IsServer
then Exit
;
1005 // Список названий моделей:
1006 m
:= g_PlayerModel_GetNames();
1011 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1012 Team
:= TEAM_COOP
// COOP
1014 if gGameSettings
.GameMode
= GM_DM
then
1015 Team
:= TEAM_NONE
// DM
1017 if Team
= TEAM_NONE
then // CTF / TDM
1019 // Автобаланс команд:
1023 for a
:= 0 to High(gPlayers
) do
1024 if gPlayers
[a
] <> nil then
1026 if gPlayers
[a
].Team
= TEAM_RED
then
1029 if gPlayers
[a
].Team
= TEAM_BLUE
then
1039 if Random(2) = 0 then
1045 // Выбираем боту имя:
1047 if BotNames
<> nil then
1048 for a
:= 0 to High(BotNames
) do
1049 if g_Player_ValidName(BotNames
[a
]) then
1051 _name
:= BotNames
[a
];
1055 // Выбираем случайную модель:
1056 _model
:= m
[Random(Length(m
))];
1059 with g_Player_Get(g_Player_Create(_model
,
1060 _RGB(Min(Random(9)*32, 255),
1061 Min(Random(9)*32, 255),
1062 Min(Random(9)*32, 255)),
1063 Team
, True)) as TBot
do
1065 // Если имени нет, делаем его из UID бота
1067 Name
:= Format('DFBOT%.5d', [UID
])
1072 1: FDifficult
:= DIFFICULT_EASY
;
1073 2: FDifficult
:= DIFFICULT_MEDIUM
;
1074 else FDifficult
:= DIFFICULT_HARD
;
1077 for a
:= WP_FIRST
to WP_LAST
do
1079 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1080 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1081 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1084 FHandicap
:= Handicap
;
1086 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1088 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1089 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1094 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
1097 _name
, _model
: String;
1100 if not g_Game_IsServer
then Exit
;
1102 // Список названий моделей:
1103 m
:= g_PlayerModel_GetNames();
1108 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1109 Team
:= TEAM_COOP
// COOP
1111 if gGameSettings
.GameMode
= GM_DM
then
1112 Team
:= TEAM_NONE
// DM
1114 if Team
= TEAM_NONE
then
1115 Team
:= BotList
[num
].team
; // CTF / TDM
1117 // Выбираем настройки бота из списка по номеру или имени:
1118 lName
:= AnsiLowerCase(lName
);
1119 if (num
< 0) or (num
> Length(BotList
)-1) then
1121 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1122 for a
:= 0 to High(BotList
) do
1123 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1132 _name
:= BotList
[num
].name
;
1133 // Занято - выбираем случайное:
1134 if not g_Player_ValidName(_name
) then
1136 _name
:= Format('DFBOT%.2d', [Random(100)]);
1137 until g_Player_ValidName(_name
);
1140 _model
:= BotList
[num
].model
;
1141 // Нет такой - выбираем случайную:
1142 if not InSArray(_model
, m
) then
1143 _model
:= m
[Random(Length(m
))];
1146 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1150 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1151 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1152 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1153 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1154 FDifficult
.Cover
:= BotList
[num
].cover
;
1155 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1157 FHandicap
:= Handicap
;
1159 for a
:= WP_FIRST
to WP_LAST
do
1161 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1162 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1163 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1166 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1168 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1172 procedure g_Bot_RemoveAll();
1176 if not g_Game_IsServer
then Exit
;
1177 if gPlayers
= nil then Exit
;
1179 for a
:= 0 to High(gPlayers
) do
1180 if gPlayers
[a
] <> nil then
1181 if gPlayers
[a
] is TBot
then
1183 gPlayers
[a
].Lives
:= 0;
1184 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1185 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1186 g_Player_Remove(gPlayers
[a
].FUID
);
1192 procedure g_Bot_MixNames();
1197 if BotNames
<> nil then
1198 for a
:= 0 to High(BotNames
) do
1200 b
:= Random(Length(BotNames
));
1202 Botnames
[a
] := BotNames
[b
];
1207 procedure g_Player_Remove(UID
: Word);
1211 if gPlayers
= nil then Exit
;
1213 if g_Game_IsServer
and g_Game_IsNet
then
1214 MH_SEND_PlayerDelete(UID
);
1216 for i
:= 0 to High(gPlayers
) do
1217 if gPlayers
[i
] <> nil then
1218 if gPlayers
[i
].FUID
= UID
then
1220 if gPlayers
[i
] is TPlayer
then
1221 TPlayer(gPlayers
[i
]).Free()
1223 TBot(gPlayers
[i
]).Free();
1229 procedure g_Player_Init();
1240 path
:= BOTNAMES_FILENAME
;
1241 if e_FindResource(DataDirs
, path
) = false then
1244 // Читаем возможные имена ботов из файла:
1245 AssignFile(F
, path
);
1256 SetLength(BotNames
, Length(BotNames
)+1);
1257 BotNames
[High(BotNames
)] := s
;
1265 // Читаем файл с параметрами ботов:
1266 config
:= TConfig
.CreateFile(path
);
1270 while config
.SectionExists(IntToStr(a
)) do
1272 SetLength(BotList
, Length(BotList
)+1);
1274 with BotList
[High(BotList
)] do
1277 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1279 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1281 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1286 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1287 color
.R
:= StrToIntDef(sa
[0], 0);
1288 color
.G
:= StrToIntDef(sa
[1], 0);
1289 color
.B
:= StrToIntDef(sa
[2], 0);
1290 // Вероятность стрельбы под углом:
1291 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1292 // Вероятность ответного огня по невидимому сопернику:
1293 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1294 // Точность стрельбы под углом:
1295 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1296 // Точность стрельбы в полете:
1297 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1298 // Точность уклонения от снарядов:
1299 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1300 // Вероятность прыжка при приближении соперника:
1301 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1302 // Приоритеты оружия для дальнего боя:
1303 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1304 if Length(sa
) = 10 then
1306 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1307 // Приоритеты оружия для ближнего боя:
1308 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1309 if Length(sa
) = 10 then
1311 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1313 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1314 if Length(sa) = 10 then
1316 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1323 SetLength(SavedStates
, 0);
1326 procedure g_Player_Free();
1330 if gPlayers
<> nil then
1332 for i
:= 0 to High(gPlayers
) do
1333 if gPlayers
[i
] <> nil then
1335 if gPlayers
[i
] is TPlayer
then
1336 TPlayer(gPlayers
[i
]).Free()
1338 TBot(gPlayers
[i
]).Free();
1347 SetLength(SavedStates
, 0);
1350 procedure g_Player_PreUpdate();
1354 if gPlayers
= nil then Exit
;
1355 for i
:= 0 to High(gPlayers
) do
1356 if gPlayers
[i
] <> nil then
1357 gPlayers
[i
].PreUpdate();
1360 procedure g_Player_UpdateAll();
1364 if gPlayers
= nil then Exit
;
1366 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1367 for i
:= 0 to High(gPlayers
) do
1369 if gPlayers
[i
] <> nil then
1371 if gPlayers
[i
] is TPlayer
then
1373 gPlayers
[i
].Update();
1374 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1378 // bot updates weapons in `UpdateCombat()`
1379 TBot(gPlayers
[i
]).Update();
1383 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1386 function g_Player_Get(UID
: Word): TPlayer
;
1392 if gPlayers
= nil then
1395 for a
:= 0 to High(gPlayers
) do
1396 if gPlayers
[a
] <> nil then
1397 if gPlayers
[a
].FUID
= UID
then
1399 Result
:= gPlayers
[a
];
1404 function g_Player_GetCount(): Byte;
1410 if gPlayers
= nil then
1413 for a
:= 0 to High(gPlayers
) do
1414 if gPlayers
[a
] <> nil then
1415 Result
:= Result
+ 1;
1418 function g_Player_GetStats(): TPlayerStatArray
;
1424 if gPlayers
= nil then Exit
;
1426 for a
:= 0 to High(gPlayers
) do
1427 if gPlayers
[a
] <> nil then
1429 SetLength(Result
, Length(Result
)+1);
1430 with Result
[High(Result
)] do
1433 Ping
:= gPlayers
[a
].FPing
;
1434 Loss
:= gPlayers
[a
].FLoss
;
1435 Name
:= gPlayers
[a
].FName
;
1436 Team
:= gPlayers
[a
].FTeam
;
1437 Frags
:= gPlayers
[a
].FFrags
;
1438 Deaths
:= gPlayers
[a
].FDeath
;
1439 Kills
:= gPlayers
[a
].FKills
;
1440 Color
:= gPlayers
[a
].FModel
.Color
;
1441 Lives
:= gPlayers
[a
].FLives
;
1442 Spectator
:= gPlayers
[a
].FSpectator
;
1443 UID
:= gPlayers
[a
].FUID
;
1448 procedure g_Player_ResetReady();
1452 if not g_Game_IsServer
then Exit
;
1453 if gPlayers
= nil then Exit
;
1455 for a
:= 0 to High(gPlayers
) do
1456 if gPlayers
[a
] <> nil then
1458 gPlayers
[a
].FReady
:= False;
1459 if g_Game_IsNet
then
1460 MH_SEND_GameEvent(NET_EV_INTER_READY
, gPlayers
[a
].UID
, 'N');
1464 procedure g_Player_RememberAll
;
1468 for i
:= Low(gPlayers
) to High(gPlayers
) do
1469 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1470 gPlayers
[i
].RememberState
;
1473 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1477 gTeamStat
[TEAM_RED
].Goals
:= 0;
1478 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1480 if gPlayers
<> nil then
1481 for i
:= 0 to High(gPlayers
) do
1482 if gPlayers
[i
] <> nil then
1484 gPlayers
[i
].Reset(Force
);
1486 if gPlayers
[i
] is TPlayer
then
1488 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1489 gPlayers
[i
].Respawn(Silent
)
1491 gPlayers
[i
].Spectate();
1494 TBot(gPlayers
[i
]).Respawn(Silent
);
1498 function g_Player_CreateCorpse(Player
: TPlayer
): Integer;
1506 if Player
.alive
then
1509 // Разрываем связь с прежним трупом:
1510 i
:= Player
.FCorpse
;
1511 if (i
>= 0) and (i
< Length(gCorpses
)) then
1513 if (gCorpses
[i
] <> nil) and (gCorpses
[i
].FPlayerUID
= Player
.FUID
) then
1514 gCorpses
[i
].FPlayerUID
:= 0;
1517 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1522 {$IFDEF ENABLE_GIBS}
1523 if (FHealth
< -50) and (gGibsCount
> 0) then
1525 g_Gibs_Create(FObj
.X
+ PLAYER_RECT_CX
, FObj
.Y
+ PLAYER_RECT_CY
, FModel
.id
, FModel
.Color
);
1530 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1534 for find_id
:= 0 to High(gCorpses
) do
1535 if gCorpses
[find_id
] = nil then
1542 find_id
:= Random(Length(gCorpses
));
1544 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.GetName(), FHealth
< -20);
1545 gCorpses
[find_id
].FModel
.Color
:= FModel
.Color
;
1546 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1547 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1548 gCorpses
[find_id
].FPlayerUID
:= FUID
;
1555 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1557 if (gShells
= nil) or (Length(gShells
) = 0) then
1560 with gShells
[CurrentShell
] do
1565 if T
= SHELL_BULLET
then
1567 Obj
.Rect
.Width
:= 4;
1568 Obj
.Rect
.Height
:= 2;
1572 Obj
.Rect
.Width
:= 7;
1573 Obj
.Rect
.Height
:= 3;
1579 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1580 positionChanged(); // this updates spatial accelerators
1581 RAngle
:= Random(360);
1582 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1584 if CurrentShell
>= High(gShells
) then
1591 procedure g_Player_UpdatePhysicalObjects();
1597 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1602 if T
= SHELL_BULLET
then
1603 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1605 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1610 if gCorpses
<> nil then
1611 for i
:= 0 to High(gCorpses
) do
1612 if gCorpses
[i
] <> nil then
1613 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1619 gCorpses
[i
].Update();
1622 if gShells
<> nil then
1623 for i
:= 0 to High(gShells
) do
1624 if gShells
[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
) or (gShells
[i
].Timeout
< gTime
) then
1640 // Отлетает от удара о стену/потолок/пол:
1641 if WordBool(mr
and MOVE_HITWALL
) then
1643 Obj
.Vel
.X
:= -(vel
.X
div 2);
1644 if not WordBool(mr
and MOVE_INWATER
) then
1645 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1647 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1649 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1650 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1651 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1653 if RAngle
mod 90 <> 0 then
1654 RAngle
:= (RAngle
div 90) * 90;
1656 else if not WordBool(mr
and MOVE_INWATER
) then
1657 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1660 if (Obj
.Vel
.X
>= 0) then
1662 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1663 if RAngle
>= 360 then
1664 RAngle
:= RAngle
mod 360;
1665 end else begin // Counter-clockwise
1666 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1668 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1673 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1677 w
:= Obj
.Rect
.Width
;
1678 h
:= Obj
.Rect
.Height
;
1681 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1683 if (dx
<> 0) or (dy
<> 0) then
1691 procedure TShell
.positionChanged (); inline; begin end;
1694 procedure g_Player_RemoveAllCorpses();
1696 {$IFDEF ENABLE_GIBS}
1697 var maxgibs
: Integer;
1700 {$IFDEF ENABLE_GIBS}
1701 maxgibs
:= g_Gibs_GetMax();
1703 g_Gibs_SetMax(maxgibs
);
1706 SetLength(gShells
, MaxShells
);
1709 if gCorpses
<> nil then
1710 for i
:= 0 to High(gCorpses
) do
1714 SetLength(gCorpses
, MaxCorpses
);
1717 procedure g_Player_Corpses_SaveState (st
: TStream
);
1721 // Считаем количество существующих трупов
1723 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1725 // Количество трупов
1726 utils
.writeInt(st
, LongInt(count
));
1728 if (count
= 0) then exit
;
1731 for i
:= 0 to High(gCorpses
) do
1733 if gCorpses
[i
] <> nil then
1736 utils
.writeStr(st
, gCorpses
[i
].FModel
.GetName());
1738 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1739 // Сохраняем данные трупа:
1740 gCorpses
[i
].SaveState(st
);
1746 procedure g_Player_Corpses_LoadState (st
: TStream
);
1754 g_Player_RemoveAllCorpses();
1756 // Количество трупов:
1757 count
:= utils
.readLongInt(st
);
1758 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1760 if (count
= 0) then exit
;
1763 for i
:= 0 to count
-1 do
1766 str
:= utils
.readStr(st
);
1768 b
:= utils
.readBool(st
);
1770 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1771 // Загружаем данные трупа
1772 gCorpses
[i
].LoadState(st
);
1779 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1781 procedure TPlayer
.BFGHit();
1783 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1784 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1785 if g_Game_IsServer
and g_Game_IsNet
then
1786 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1787 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1791 procedure TPlayer
.ChangeModel(ModelName
: string);
1793 locModel
: TPlayerModel
;
1795 locModel
:= g_PlayerModel_Get(ModelName
);
1796 if locModel
= nil then Exit
;
1802 procedure TPlayer
.SetModel(ModelName
: string);
1806 m
:= g_PlayerModel_Get(ModelName
);
1809 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1810 m
:= g_PlayerModel_Get('doomer');
1813 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1818 if FModel
<> nil then
1823 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1824 FModel
.Color
:= FColor
1826 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1827 FModel
.SetWeapon(FCurrWeap
);
1828 FModel
.SetFlag(FFlag
);
1829 SetDirection(FDirection
);
1832 procedure TPlayer
.SetColor(Color
: TRGB
);
1835 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1836 if FModel
<> nil then FModel
.Color
:= Color
;
1839 function TPlayer
.GetColor(): TRGB
;
1841 result
:= FModel
.Color
;
1844 procedure TPlayer
.SwitchTeam
;
1846 if g_Game_IsClient
then
1848 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
1850 if gGameOn
and FAlive
then
1851 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
1853 if FTeam
= TEAM_RED
then
1855 ChangeTeam(TEAM_BLUE
);
1856 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
1857 if g_Game_IsNet
then
1858 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
1862 ChangeTeam(TEAM_RED
);
1863 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
1864 if g_Game_IsNet
then
1865 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
1867 FPreferredTeam
:= FTeam
;
1870 procedure TPlayer
.ChangeTeam(Team
: Byte);
1877 TEAM_RED
, TEAM_BLUE
:
1878 FModel
.Color
:= TEAMCOLOR
[Team
];
1880 FModel
.Color
:= FColor
;
1882 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
1883 MH_SEND_PlayerStats(FUID
);
1887 procedure TPlayer.CollideItem();
1892 if gItems = nil then Exit;
1893 if not FAlive then Exit;
1895 for i := 0 to High(gItems) do
1898 if (ItemType <> ITEM_NONE) and alive then
1899 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
1900 PLAYER_RECT.Height, @Obj) then
1902 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
1904 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
1905 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
1906 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
1907 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
1908 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
1910 // Надо убрать с карты, если это не ключ, которым нужно поделится с другим игроком:
1911 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
1912 (gGameSettings.GameType = GT_SINGLE) and
1913 (g_Player_GetCount() > 1)) then
1914 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
1920 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
1922 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
1923 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
1927 constructor TPlayer
.Create();
1933 mEDamageType
:= HIT_SOME
;
1939 FSawSound
:= TPlayableSound
.Create();
1940 FSawSoundIdle
:= TPlayableSound
.Create();
1941 FSawSoundHit
:= TPlayableSound
.Create();
1942 FSawSoundSelect
:= TPlayableSound
.Create();
1943 FFlameSoundOn
:= TPlayableSound
.Create();
1944 FFlameSoundOff
:= TPlayableSound
.Create();
1945 FFlameSoundWork
:= TPlayableSound
.Create();
1946 FJetSoundFly
:= TPlayableSound
.Create();
1947 FJetSoundOn
:= TPlayableSound
.Create();
1948 FJetSoundOff
:= TPlayableSound
.Create();
1950 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
1951 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
1952 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
1953 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
1954 FFlameSoundOn
.SetByName('SOUND_WEAPON_FLAMEON');
1955 FFlameSoundOff
.SetByName('SOUND_WEAPON_FLAMEOFF');
1956 FFlameSoundWork
.SetByName('SOUND_WEAPON_FLAMEWORK');
1957 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
1958 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
1959 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
1961 FSpectatePlayer
:= -1;
1965 FSavedStateNum
:= -1;
1973 FActualModelName
:= 'doomer';
1976 FObj
.Rect
:= PLAYER_RECT
;
1978 FBFGFireCounter
:= -1;
1979 FJustTeleported
:= False;
1982 FWaitForFirstSpawn
:= false;
1983 FPunchAnim
:= TAnimationState
.Create(False, 1, 4);
1989 procedure TPlayer
.positionChanged (); inline;
1993 procedure TPlayer
.doDamage (v
: Integer);
1995 if (v
<= 0) then exit
;
1996 if (v
> 32767) then v
:= 32767;
1997 Damage(v
, 0, 0, 0, mEDamageType
);
2000 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2004 if (not g_Game_IsClient
) and (not FAlive
) then
2009 // Неуязвимость не спасает от ловушек:
2010 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2012 if not g_Game_IsClient
then
2015 if t
= HIT_TRAP
then
2017 // Ловушка убивает сразу:
2019 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2021 if t
= HIT_SELF
then
2025 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2028 // Обнулить действия примочек, чтобы фон пропал
2029 FMegaRulez
[MR_SUIT
] := 0;
2030 FMegaRulez
[MR_INVUL
] := 0;
2031 FMegaRulez
[MR_INVIS
] := 0;
2036 // Но от остального спасает:
2037 if FMegaRulez
[MR_INVUL
] >= gTime
then
2044 // Если есть урон своим, или ранил сам себя, или тебя ранил противник:
2045 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2046 (SpawnerUID
= FUID
) or
2047 (not SameTeam(FUID
, SpawnerUID
)) then
2049 FLastSpawnerUID
:= SpawnerUID
;
2051 // Кровь (пузырьки, если в воде):
2052 if gBloodCount
> 0 then
2054 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2055 if value
div 4 <= c
then
2056 c
:= c
- (value
div 4)
2060 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2064 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2065 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2069 if t
= HIT_WATER
then
2071 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2072 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2079 Inc(FDamageBuffer
, value
);
2083 FPain
:= FPain
+ value
;
2086 if g_Game_IsServer
and g_Game_IsNet
then
2088 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2089 MH_SEND_PlayerStats(FUID
);
2090 MH_SEND_PlayerPos(False, FUID
);
2094 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2097 if g_Game_IsClient
then
2102 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2104 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2107 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2109 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2113 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2114 MH_SEND_PlayerStats(FUID
);
2117 destructor TPlayer
.Destroy();
2119 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2121 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2125 FSawSoundIdle
.Free();
2126 FSawSoundHit
.Free();
2127 FSawSoundSelect
.Free();
2128 FFlameSoundOn
.Free();
2129 FFlameSoundOff
.Free();
2130 FFlameSoundWork
.Free();
2131 FJetSoundFly
.Free();
2133 FJetSoundOff
.Free();
2140 procedure TPlayer
.DoPunch();
2146 procedure TPlayer
.Fire();
2148 f
, DidFire
: Boolean;
2149 wx
, wy
, xd
, yd
: Integer;
2152 if g_Game_IsClient
then Exit
;
2153 // FBFGFireCounter - время перед выстрелом (для BFG)
2154 // FReloading - время после выстрела (для всего)
2162 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2167 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2168 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2169 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
2170 yd
:= wy
+firediry();
2176 if R_BERSERK
in FRulez
then
2178 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2179 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2180 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2183 locobj
.rect
.Width
:= 39;
2184 locobj
.rect
.Height
:= 52;
2185 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2186 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2187 locobj
.Accel
.X
:= xd
-wx
;
2188 locobj
.Accel
.y
:= yd
-wy
;
2190 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2191 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2193 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2195 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
2199 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2203 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2208 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2209 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2211 FSawSoundSelect
.Stop();
2213 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2215 else if not FSawSoundHit
.IsPlaying() then
2217 FSawSoundSelect
.Stop();
2218 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2221 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2227 if FAmmo
[A_BULLETS
] > 0 then
2229 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2230 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2231 Dec(FAmmo
[A_BULLETS
]);
2232 FFireAngle
:= FAngle
;
2235 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2236 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2240 if FAmmo
[A_SHELLS
] > 0 then
2242 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2243 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
2244 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2245 Dec(FAmmo
[A_SHELLS
]);
2246 FFireAngle
:= FAngle
;
2250 FShellType
:= SHELL_SHELL
;
2254 if FAmmo
[A_SHELLS
] >= 2 then
2256 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
2257 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2258 Dec(FAmmo
[A_SHELLS
], 2);
2259 FFireAngle
:= FAngle
;
2263 FShellType
:= SHELL_DBLSHELL
;
2267 if FAmmo
[A_BULLETS
] > 0 then
2269 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
2270 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
2271 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2272 Dec(FAmmo
[A_BULLETS
]);
2273 FFireAngle
:= FAngle
;
2276 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2277 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2280 WEAPON_ROCKETLAUNCHER
:
2281 if FAmmo
[A_ROCKETS
] > 0 then
2283 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
2284 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2285 Dec(FAmmo
[A_ROCKETS
]);
2286 FFireAngle
:= FAngle
;
2292 if FAmmo
[A_CELLS
] > 0 then
2294 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
2295 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2296 Dec(FAmmo
[A_CELLS
]);
2297 FFireAngle
:= FAngle
;
2303 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
2305 FBFGFireCounter
:= 17;
2306 if not FNoReload
then
2307 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
2308 Dec(FAmmo
[A_CELLS
], 40);
2312 WEAPON_SUPERPULEMET
:
2313 if FAmmo
[A_SHELLS
] > 0 then
2315 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2316 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
2317 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2318 Dec(FAmmo
[A_SHELLS
]);
2319 FFireAngle
:= FAngle
;
2322 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2323 GameVelX
, GameVelY
-2, SHELL_SHELL
);
2326 WEAPON_FLAMETHROWER
:
2327 if FAmmo
[A_FUEL
] > 0 then
2329 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
2331 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2333 FFireAngle
:= FAngle
;
2340 if g_Game_IsNet
and g_Game_IsServer
then MH_SEND_PlayerStats(FUID
);
2344 if g_Game_IsNet
then
2348 if FCurrWeap
<> WEAPON_BFG
then
2349 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
2351 if not FNoReload
then
2352 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
2355 MH_SEND_PlayerStats(FUID
);
2360 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
2361 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
2362 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
2365 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
2368 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
2369 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
2370 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
2371 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
2372 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
2377 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
2379 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
2380 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
2381 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
2384 procedure TPlayer
.FlamerOn
;
2386 FFlameSoundOff
.Stop();
2387 FFlameSoundOff
.SetPosition(0);
2390 if (not FFlameSoundOn
.IsPlaying()) and (not FFlameSoundWork
.IsPlaying()) then
2391 FFlameSoundWork
.PlayAt(FObj
.X
, FObj
.Y
);
2395 FFlameSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
2400 procedure TPlayer
.FlamerOff
;
2404 FFlameSoundOn
.Stop();
2405 FFlameSoundOn
.SetPosition(0);
2406 FFlameSoundWork
.Stop();
2407 FFlameSoundWork
.SetPosition(0);
2408 FFlameSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
2413 procedure TPlayer
.JetpackOn
;
2417 FJetSoundOn
.SetPosition(0);
2418 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
2422 procedure TPlayer
.JetpackOff
;
2426 FJetSoundOff
.SetPosition(0);
2427 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
2430 procedure TPlayer
.CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
2432 if Timeout
<= 0 then
2434 if (FMegaRulez
[MR_SUIT
] > gTime
) or (FMegaRulez
[MR_INVUL
] > gTime
) then
2435 exit
; // Не загораемся когда есть защита
2436 if g_Obj_CollidePanel(@FObj
, 0, 0, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
) then
2437 exit
; // Не подгораем в воде на всякий случай
2438 if FFireTime
<= 0 then
2439 g_Sound_PlayExAt('SOUND_IGNITE', FObj
.X
, FObj
.Y
);
2440 FFireTime
:= Timeout
;
2441 FFireAttacker
:= Attacker
;
2442 if g_Game_IsNet
and g_Game_IsServer
then
2443 MH_SEND_PlayerStats(FUID
);
2446 procedure TPlayer
.Jump();
2448 if gFly
or FJetpack
then
2450 // Полет (чит-код или джетпак):
2451 if FObj
.Vel
.Y
> -VEL_FLY
then
2452 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
2455 if FJetFuel
> 0 then
2457 if (FJetFuel
< 1) and g_Game_IsServer
then
2461 if g_Game_IsNet
then
2462 MH_SEND_PlayerStats(FUID
);
2468 // Не включать джетпак в режиме прохождения сквозь стены
2470 FCanJetpack
:= False;
2472 // Прыгаем или всплываем:
2473 if (CollideLevel(0, 1) or
2474 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
2475 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
2476 ) and (FObj
.Accel
.Y
= 0) then // Не прыгать, если есть вертикальное ускорение
2478 FObj
.Vel
.Y
:= -VEL_JUMP
;
2479 FCanJetpack
:= False;
2483 if BodyInLiquid(0, 0) then
2484 FObj
.Vel
.Y
:= -VEL_SW
2485 else if (FJetFuel
> 0) and FCanJetpack
and
2486 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
2490 if g_Game_IsNet
then
2491 MH_SEND_PlayerStats(FUID
);
2496 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
2498 a
, i
, k
, ab
, ar
: Byte;
2502 srv
, netsrv
: Boolean;
2508 procedure PushItem(t
: Byte);
2512 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
2513 it
:= g_Items_ByIdx(id
);
2514 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
2516 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
2517 (FObj
.Vel
.Y
div 2)-Random(9));
2518 it
.positionChanged(); // this updates spatial accelerators
2522 if KillType
= K_HARDKILL
then // -5..+5; -5..0
2524 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
2525 (FObj
.Vel
.Y
div 2)-Random(6));
2527 else // -3..+3; -3..0
2529 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
2530 (FObj
.Vel
.Y
div 2)-Random(4));
2532 it
.positionChanged(); // this updates spatial accelerators
2535 if g_Game_IsNet
and g_Game_IsServer
then
2536 MH_SEND_ItemSpawn(True, id
);
2540 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
2541 Srv
:= g_Game_IsServer
;
2542 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
2543 if Srv
then FDeath
:= FDeath
+ 1;
2548 if not FPhysics
then
2554 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2556 if FLives
> 0 then FLives
:= FLives
- 1;
2557 if FLives
= 0 then FNoRespawn
:= True;
2560 // Номер типа смерти:
2563 K_SIMPLEKILL
: a
:= 1;
2565 K_EXTRAHARDKILL
: a
:= 3;
2570 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
2572 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
2579 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
2581 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
2582 K_EXTRAHARDKILL
, K_FALLKILL
:
2583 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
2586 // Переключаем состояние:
2590 K_HARDKILL
, K_EXTRAHARDKILL
:
2594 // Реакция монстров на смерть игрока:
2595 if (KillType
<> K_FALLKILL
) and (Srv
) then
2596 g_Monsters_killedp();
2598 if SpawnerUID
= FUID
then
2600 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
2605 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
2608 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
2609 begin // Убит другим игроком
2610 KP
:= g_Player_Get(SpawnerUID
);
2611 if (KP
<> nil) and Srv
then
2613 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
2614 if SameTeam(FUID
, SpawnerUID
) then
2624 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
2625 Inc(gTeamStat
[KP
.Team
].Goals
,
2626 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
2628 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
2631 plr
:= g_Player_Get(SpawnerUID
);
2639 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
2643 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
2647 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
2652 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
2653 begin // Убит монстром
2654 mon
:= g_Monsters_ByUID(SpawnerUID
);
2658 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
2662 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
2666 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
2670 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
2675 else // Особые типы смерти
2678 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
2679 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
2680 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
2681 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
2682 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
2683 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
2689 for a
:= WP_FIRST
to WP_LAST
do
2693 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
2694 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
2695 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
2696 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
2697 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
2698 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
2699 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
2700 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
2701 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
2710 if R_ITEM_BACKPACK
in FRulez
then
2711 PushItem(ITEM_AMMO_BACKPACK
);
2713 // Выброс ракетного ранца:
2714 if FJetFuel
> 0 then
2715 PushItem(ITEM_JETPACK
);
2718 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) or
2719 (not LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
)) then
2721 if R_KEY_RED
in FRulez
then
2722 PushItem(ITEM_KEY_RED
);
2724 if R_KEY_GREEN
in FRulez
then
2725 PushItem(ITEM_KEY_GREEN
);
2727 if R_KEY_BLUE
in FRulez
then
2728 PushItem(ITEM_KEY_BLUE
);
2732 DropFlag(KillType
= K_FALLKILL
);
2735 FCorpse
:= g_Player_CreateCorpse(Self
);
2737 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
2738 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2744 for i
:= Low(gPlayers
) to High(gPlayers
) do
2746 if gPlayers
[i
] = nil then continue
;
2747 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
2750 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
2751 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
2756 OldLR
:= gLMSRespawn
;
2757 if (gGameSettings
.GameMode
= GM_COOP
) then
2761 // everyone is dead, restart the map
2762 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
2764 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
2765 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2766 gLMSRespawnTime
:= gTime
+ 5000;
2768 else if (a
= 1) then
2770 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
2771 if (gPlayers
[k
] = gPlayer1
) or
2772 (gPlayers
[k
] = gPlayer2
) then
2773 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
2774 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
2775 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
2778 else if (gGameSettings
.GameMode
= GM_TDM
) then
2780 if (ab
= 0) and (ar
<> 0) then
2783 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
2785 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
2786 Inc(gTeamStat
[TEAM_RED
].Goals
);
2787 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2788 gLMSRespawnTime
:= gTime
+ 5000;
2790 else if (ar
= 0) and (ab
<> 0) then
2793 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
2795 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
2796 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
2797 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2798 gLMSRespawnTime
:= gTime
+ 5000;
2800 else if (ar
= 0) and (ab
= 0) then
2803 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
2805 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
2806 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2807 gLMSRespawnTime
:= gTime
+ 5000;
2810 else if (gGameSettings
.GameMode
= GM_DM
) then
2814 if gPlayers
[k
] <> nil then
2817 // survivor is the winner
2818 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
2820 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
2823 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2824 gLMSRespawnTime
:= gTime
+ 5000;
2826 else if (a
= 0) then
2828 // everyone is dead, restart the map
2829 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
2831 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
2832 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2833 gLMSRespawnTime
:= gTime
+ 5000;
2836 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
2838 if NetMode
= NET_SERVER
then
2839 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
)
2841 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
2847 MH_SEND_PlayerStats(FUID
);
2848 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
2849 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
2852 if srv
and FNoRespawn
then Spectate(True);
2853 FWantsInGame
:= True;
2856 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
2858 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
2859 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
2862 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
2864 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
2865 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
2868 procedure TPlayer
.MakeBloodSimple(Count
: Word);
2870 var Blood
: TModelBlood
;
2874 Blood
:= SELF
.FModel
.GetBlood();
2875 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
2876 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
2877 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
2878 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
2879 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
2880 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
2881 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
2882 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
2886 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
2888 var Blood
: TModelBlood
;
2892 Blood
:= SELF
.FModel
.GetBlood();
2893 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2894 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
2895 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
2896 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
2900 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
2902 if g_Game_IsClient
then Exit
;
2903 if Weapon
> High(FWeapon
) then Exit
;
2904 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
2907 procedure TPlayer
.resetWeaponQueue ();
2910 FNextWeapDelay
:= 0;
2913 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
2917 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
2918 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
2919 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
2920 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
2921 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
2922 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
2923 else result
:= (weapon
< length(FWeapon
));
2927 // return 255 for "no switch"
2928 function TPlayer
.getNextWeaponIndex (): Byte;
2931 wantThisWeapon
: array[0..64] of Boolean;
2932 wwc
: Integer = 0; //HACK!
2935 result
:= 255; // default result: "no switch"
2936 // had weapon cycling on previous frame? remove that flag
2937 if (FNextWeap
and $2000) <> 0 then
2939 FNextWeap
:= FNextWeap
and $1FFF;
2940 FNextWeapDelay
:= 0;
2942 // cycling has priority
2943 if (FNextWeap
and $C000) <> 0 then
2945 if (FNextWeap
and $8000) <> 0 then
2949 FNextWeap
:= FNextWeap
or $2000; // we need this
2950 if FNextWeapDelay
> 0 then
2951 exit
; // cooldown time
2953 for i
:= 0 to High(FWeapon
) do
2955 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
2956 if FWeapon
[cwi
] then
2958 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d', [FCurrWeap, cwi]), MSG_WARNING);
2959 result
:= Byte(cwi
);
2960 FNextWeapDelay
:= WEAPON_DELAY
;
2968 for i
:= 0 to High(wantThisWeapon
) do
2969 wantThisWeapon
[i
] := false;
2970 for i
:= 0 to High(FWeapon
) do
2971 if (FNextWeap
and (1 shl i
)) <> 0 then
2973 wantThisWeapon
[i
] := true;
2976 // exclude currently selected weapon from the set
2977 wantThisWeapon
[FCurrWeap
] := false;
2978 // slow down alterations a little
2981 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
2982 // more than one weapon requested, assume "alteration" and check alteration delay
2983 if FNextWeapDelay
> 0 then
2989 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
2990 // but clear all counters if no weapon should be switched
2996 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
2997 // try weapons in descending order
2998 for i
:= High(FWeapon
) downto 0 do
3000 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3005 FNextWeapDelay
:= WEAPON_DELAY
* 2; // anyway, 'cause why not
3009 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3013 procedure TPlayer
.RealizeCurrentWeapon();
3014 function switchAllowed (): Boolean;
3019 if FBFGFireCounter
<> -1 then
3021 if FTime
[T_SWITCH
] > gTime
then
3023 for i
:= WP_FIRST
to WP_LAST
do
3024 if FReloading
[i
] > 0 then
3032 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3033 //FNextWeap := FNextWeap and $1FFF;
3034 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3036 if not switchAllowed
then
3038 //HACK for weapon cycling
3039 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3043 nw
:= getNextWeaponIndex();
3044 if nw
= 255 then exit
; // don't reset anything here
3045 if nw
> High(FWeapon
) then
3047 // don't forget to reset queue here!
3048 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3056 FTime
[T_SWITCH
] := gTime
+156;
3057 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3058 FModel
.SetWeapon(FCurrWeap
);
3059 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3063 procedure TPlayer
.NextWeapon();
3065 if g_Game_IsClient
then Exit
;
3069 procedure TPlayer
.PrevWeapon();
3071 if g_Game_IsClient
then Exit
;
3075 procedure TPlayer
.SetWeapon(W
: Byte);
3077 if FCurrWeap
<> W
then
3078 if W
= WEAPON_SAW
then
3079 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3082 FModel
.SetWeapon(CurrWeap
);
3086 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3088 function allowBerserkSwitching (): Boolean;
3090 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3092 if gBerserkAutoswitch
then exit
;
3093 if not conIsCheatsEnabled
then exit
;
3101 if g_Game_IsClient
then Exit
;
3103 // a = true - место спавна предмета:
3104 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3109 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3111 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3115 if gFlash
= 2 then Inc(FPickup
, 5);
3119 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3121 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3125 if gFlash
= 2 then Inc(FPickup
, 5);
3129 if FArmor
< PLAYER_AP_SOFT
then
3131 FArmor
:= PLAYER_AP_SOFT
;
3134 if gFlash
= 2 then Inc(FPickup
, 5);
3138 if FArmor
< PLAYER_AP_LIMIT
then
3140 FArmor
:= PLAYER_AP_LIMIT
;
3143 if gFlash
= 2 then Inc(FPickup
, 5);
3147 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
3149 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3153 if gFlash
= 2 then Inc(FPickup
, 5);
3157 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) or (FFireTime
> 0) then
3159 if FHealth
< PLAYER_HP_LIMIT
then
3160 FHealth
:= PLAYER_HP_LIMIT
;
3161 if FArmor
< PLAYER_AP_LIMIT
then
3162 FArmor
:= PLAYER_AP_LIMIT
;
3166 if gFlash
= 2 then Inc(FPickup
, 5);
3170 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3172 FWeapon
[WEAPON_SAW
] := True;
3174 if gFlash
= 2 then Inc(FPickup
, 5);
3175 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3178 ITEM_WEAPON_SHOTGUN1
:
3179 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3181 // Нужно, чтобы не взять все пули сразу:
3182 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3184 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3185 FWeapon
[WEAPON_SHOTGUN1
] := True;
3187 if gFlash
= 2 then Inc(FPickup
, 5);
3188 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3191 ITEM_WEAPON_SHOTGUN2
:
3192 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3194 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3196 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3197 FWeapon
[WEAPON_SHOTGUN2
] := True;
3199 if gFlash
= 2 then Inc(FPickup
, 5);
3200 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3203 ITEM_WEAPON_CHAINGUN
:
3204 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3206 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3208 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3209 FWeapon
[WEAPON_CHAINGUN
] := True;
3211 if gFlash
= 2 then Inc(FPickup
, 5);
3212 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3215 ITEM_WEAPON_ROCKETLAUNCHER
:
3216 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3218 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3220 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3221 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3223 if gFlash
= 2 then Inc(FPickup
, 5);
3224 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3228 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3230 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3232 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3233 FWeapon
[WEAPON_PLASMA
] := True;
3235 if gFlash
= 2 then Inc(FPickup
, 5);
3236 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3240 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3242 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3244 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3245 FWeapon
[WEAPON_BFG
] := True;
3247 if gFlash
= 2 then Inc(FPickup
, 5);
3248 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3251 ITEM_WEAPON_SUPERPULEMET
:
3252 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3254 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3256 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3257 FWeapon
[WEAPON_SUPERPULEMET
] := True;
3259 if gFlash
= 2 then Inc(FPickup
, 5);
3260 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3263 ITEM_WEAPON_FLAMETHROWER
:
3264 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
3266 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
3268 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3269 FWeapon
[WEAPON_FLAMETHROWER
] := True;
3271 if gFlash
= 2 then Inc(FPickup
, 5);
3272 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3276 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3278 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3281 if gFlash
= 2 then Inc(FPickup
, 5);
3284 ITEM_AMMO_BULLETS_BOX
:
3285 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3287 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3290 if gFlash
= 2 then Inc(FPickup
, 5);
3294 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3296 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3299 if gFlash
= 2 then Inc(FPickup
, 5);
3302 ITEM_AMMO_SHELLS_BOX
:
3303 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3305 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
3308 if gFlash
= 2 then Inc(FPickup
, 5);
3312 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3314 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3317 if gFlash
= 2 then Inc(FPickup
, 5);
3320 ITEM_AMMO_ROCKET_BOX
:
3321 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3323 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
3326 if gFlash
= 2 then Inc(FPickup
, 5);
3330 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3332 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3335 if gFlash
= 2 then Inc(FPickup
, 5);
3339 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3341 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
3344 if gFlash
= 2 then Inc(FPickup
, 5);
3348 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
3350 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3353 if gFlash
= 2 then Inc(FPickup
, 5);
3357 if not(R_ITEM_BACKPACK
in FRulez
) or
3358 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
3359 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
3360 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
3361 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
3362 (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) then
3364 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
3365 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
3366 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
3367 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
3368 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
3370 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3371 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3372 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3373 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3374 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3375 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3376 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3377 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3378 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
3379 IncMax(FAmmo
[A_FUEL
], 50, FMaxAmmo
[A_FUEL
]);
3381 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
3384 if gFlash
= 2 then Inc(FPickup
, 5);
3388 if not(R_KEY_RED
in FRulez
) then
3390 Include(FRulez
, R_KEY_RED
);
3392 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3393 if gFlash
= 2 then Inc(FPickup
, 5);
3394 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3398 if not(R_KEY_GREEN
in FRulez
) then
3400 Include(FRulez
, R_KEY_GREEN
);
3402 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3403 if gFlash
= 2 then Inc(FPickup
, 5);
3404 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3408 if not(R_KEY_BLUE
in FRulez
) then
3410 Include(FRulez
, R_KEY_BLUE
);
3412 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3413 if gFlash
= 2 then Inc(FPickup
, 5);
3414 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3418 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
3420 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
3424 if gFlash
= 2 then Inc(FPickup
, 5);
3428 if FAir
< AIR_MAX
then
3433 if gFlash
= 2 then Inc(FPickup
, 5);
3438 if not (R_BERSERK
in FRulez
) then
3440 Include(FRulez
, R_BERSERK
);
3441 if allowBerserkSwitching
then
3443 FCurrWeap
:= WEAPON_KASTET
;
3445 FModel
.SetWeapon(WEAPON_KASTET
);
3450 if gFlash
= 2 then Inc(FPickup
, 5);
3452 FBerserk
:= gTime
+30000;
3457 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3459 if FHealth
< PLAYER_HP_SOFT
then FHealth
:= PLAYER_HP_SOFT
;
3460 FBerserk
:= gTime
+30000;
3468 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
3470 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
3474 if gFlash
= 2 then Inc(FPickup
, 5);
3478 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
3480 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
3484 if gFlash
= 2 then Inc(FPickup
, 5);
3488 if FArmor
< PLAYER_AP_LIMIT
then
3490 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
3493 if gFlash
= 2 then Inc(FPickup
, 5);
3497 if FJetFuel
< JET_MAX
then
3499 FJetFuel
:= JET_MAX
;
3502 if gFlash
= 2 then Inc(FPickup
, 5);
3506 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
3508 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
3511 if gFlash
= 2 then Inc(FPickup
, 5);
3516 procedure TPlayer
.Touch();
3520 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
3523 // Бросить флаг товарищу:
3524 if gGameSettings
.GameMode
= GM_CTF
then
3529 procedure TPlayer
.Push(vx
, vy
: Integer);
3531 if (not FPhysics
) and FGhost
then
3533 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
3534 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
3535 if g_Game_IsNet
and g_Game_IsServer
then
3536 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
3539 procedure TPlayer
.Reset(Force
: Boolean);
3545 FTime
[T_RESPAWN
] := 0;
3546 FTime
[T_FLAGCAP
] := 0;
3562 FSpectator
:= False;
3565 FSpectatePlayer
:= -1;
3566 FNoRespawn
:= False;
3568 FLives
:= gGameSettings
.MaxLives
;
3573 procedure TPlayer
.SoftReset();
3581 FBFGFireCounter
:= -1;
3589 SetAction(A_STAND
, True);
3592 function TPlayer
.GetRespawnPoint(): Byte;
3597 // На будущее: FSpawn - игрок уже играл и перерождается
3599 // Одиночная игра/кооператив
3600 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
3602 if Self
= gPlayer1
then
3604 // player 1 should try to spawn on the player 1 point
3605 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) > 0 then
3606 Exit(RESPAWNPOINT_PLAYER1
)
3607 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) > 0 then
3608 Exit(RESPAWNPOINT_PLAYER2
);
3610 else if Self
= gPlayer2
then
3612 // player 2 should try to spawn on the player 2 point
3613 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) > 0 then
3614 Exit(RESPAWNPOINT_PLAYER2
)
3615 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) > 0 then
3616 Exit(RESPAWNPOINT_PLAYER1
);
3620 // other players randomly pick either the first or the second point
3621 c
:= IfThen((Random(2) = 0), RESPAWNPOINT_PLAYER1
, RESPAWNPOINT_PLAYER2
);
3622 if g_Map_GetPointCount(c
) > 0 then
3624 // try the other one
3625 c
:= IfThen((c
= RESPAWNPOINT_PLAYER1
), RESPAWNPOINT_PLAYER2
, RESPAWNPOINT_PLAYER1
);
3626 if g_Map_GetPointCount(c
) > 0 then
3632 if gGameSettings
.GameMode
= GM_DM
then
3634 // try DM points first
3635 if g_Map_GetPointCount(RESPAWNPOINT_DM
) > 0 then
3636 Exit(RESPAWNPOINT_DM
);
3640 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
3642 // try team points first
3643 c
:= RESPAWNPOINT_DM
;
3644 if FTeam
= TEAM_RED
then
3645 c
:= RESPAWNPOINT_RED
3646 else if FTeam
= TEAM_BLUE
then
3647 c
:= RESPAWNPOINT_BLUE
;
3648 if g_Map_GetPointCount(c
) > 0 then
3652 // still haven't found a spawnpoint, try random shit
3653 Result
:= g_Map_GetRandomPointType();
3656 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
3658 RespawnPoint
: TRespawnPoint
;
3664 FBFGFireCounter
:= -1;
3671 if not g_Game_IsServer
then
3675 FWantsInGame
:= True;
3676 FJustTeleported
:= True;
3679 FTime
[T_RESPAWN
] := 0;
3683 // if server changes MaxLives we gotta be ready
3684 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
3686 // Еще нельзя возродиться:
3687 if FTime
[T_RESPAWN
] > gTime
then
3690 // Просрал все жизни:
3693 if not FSpectator
then Spectate(True);
3694 FWantsInGame
:= True;
3698 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
3699 begin // "Своя игра"
3700 // Берсерк не сохраняется между уровнями:
3701 FRulez
:= FRulez
-[R_BERSERK
];
3703 else // "Одиночная игра"/"Кооп"
3705 // Берсерк и ключи не сохраняются между уровнями:
3706 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
3709 // Получаем точку спауна игрока:
3710 c
:= GetRespawnPoint();
3715 // Воскрешение без оружия:
3718 FHealth
:= Round(PLAYER_HP_SOFT
* (FHandicap
/ 100));
3724 for a
:= WP_FIRST
to WP_LAST
do
3726 FWeapon
[a
] := False;
3730 FWeapon
[WEAPON_PISTOL
] := True;
3731 FWeapon
[WEAPON_KASTET
] := True;
3732 FCurrWeap
:= WEAPON_PISTOL
;
3735 FModel
.SetWeapon(FCurrWeap
);
3737 for b
:= A_BULLETS
to A_HIGH
do
3740 FAmmo
[A_BULLETS
] := 50;
3742 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
3743 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
3744 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
3745 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
3746 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
3748 if (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) and
3749 LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
) then
3750 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
3755 // Получаем координаты точки возрождения:
3756 if not g_Map_GetPoint(c
, RespawnPoint
) then
3758 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3762 // Установка координат и сброс всех параметров:
3763 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
3764 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
3765 FObj
.oldX
:= FObj
.X
; // don't interpolate after respawn
3766 FObj
.oldY
:= FObj
.Y
;
3772 FDirection
:= RespawnPoint
.Direction
;
3773 if FDirection
= TDirection
.D_LEFT
then
3778 SetAction(A_STAND
, True);
3779 FModel
.Direction
:= FDirection
;
3781 for a
:= Low(FTime
) to High(FTime
) do
3784 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
3787 // Respawn invulnerability
3788 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.SpawnInvul
> 0) then
3790 FMegaRulez
[MR_INVUL
] := gTime
+ gGameSettings
.SpawnInvul
* 1000;
3791 FSpawnInvul
:= FMegaRulez
[MR_INVUL
];
3796 FCanJetpack
:= False;
3803 // Анимация возрождения:
3804 if (not gLoadGameMode
) and (not Silent
) then
3807 R_GFX_TELEPORT_FAST
,
3808 FObj
.X
+ PLAYER_RECT
.X
+ (PLAYER_RECT
.Width
div 2) - 32,
3809 FObj
.Y
+ PLAYER_RECT
.Y
+ (PLAYER_RECT
.Height
div 2) - 32
3814 FSpectator
:= False;
3817 FSpectatePlayer
:= -1;
3820 if (gPlayer1
= nil) and (gSpectLatchPID1
= FUID
) then
3822 if (gPlayer2
= nil) and (gSpectLatchPID2
= FUID
) then
3825 if g_Game_IsNet
then
3827 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
3828 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
3830 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
3831 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
3836 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
3839 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
3840 else if (not NoMove
) then
3842 GameX
:= gMapInfo
.Width
div 2;
3843 GameY
:= gMapInfo
.Height
div 2;
3852 FWantsInGame
:= False;
3858 if Self
= gPlayer1
then
3860 gSpectLatchPID1
:= FUID
;
3863 else if Self
= gPlayer2
then
3865 gSpectLatchPID2
:= FUID
;
3870 if g_Game_IsNet
then
3871 MH_SEND_PlayerStats(FUID
);
3874 procedure TPlayer
.SwitchNoClip
;
3878 FGhost
:= not FGhost
;
3879 FPhysics
:= not FGhost
;
3891 procedure TPlayer
.Run(Direction
: TDirection
);
3892 {$IFDEF ENABLE_GIBS}
3896 if MAX_RUNVEL
> 8 then
3900 if Direction
= TDirection
.D_LEFT
then
3902 if FObj
.Vel
.X
> -MAX_RUNVEL
then
3903 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
3906 if FObj
.Vel
.X
< MAX_RUNVEL
then
3907 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
3909 {$IFDEF ENABLE_GIBS}
3910 // Возможно, пинаем куски:
3911 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
3913 b
:= Abs(FObj
.Vel
.X
);
3914 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
3915 for a
:= 0 to High(gGibs
) do
3917 if gGibs
[a
].alive
and
3918 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
3919 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
3922 if FObj
.Vel
.X
< 0 then
3924 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // налево
3928 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // направо
3930 gGibs
[a
].positionChanged(); // this updates spatial accelerators
3939 procedure TPlayer
.SeeDown();
3941 SetAction(A_SEEDOWN
);
3943 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
3945 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
3948 procedure TPlayer
.SeeUp();
3952 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
3954 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
3957 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
3965 A_ATTACK
: Prior
:= 2;
3966 A_SEEUP
: Prior
:= 1;
3967 A_SEEDOWN
: Prior
:= 1;
3968 A_ATTACKUP
: Prior
:= 2;
3969 A_ATTACKDOWN
: Prior
:= 2;
3974 if (Prior
> FActionPrior
) or Force
then
3975 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
3977 FActionPrior
:= Prior
;
3978 FActionAnim
:= Action
;
3979 FActionForce
:= Force
;
3980 FActionChanged
:= True;
3983 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
3986 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
3988 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
3989 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
3990 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
3991 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
3994 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
3998 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4000 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4001 if g_Game_IsServer
and g_Game_IsNet
then
4002 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4006 FJustTeleported
:= True;
4010 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4013 R_GFX_TELEPORT_FAST
,
4014 FObj
.X
+ PLAYER_RECT
.X
+ (PLAYER_RECT
.Width
div 2) - 32,
4015 FObj
.Y
+ PLAYER_RECT
.Y
+ (PLAYER_RECT
.Height
div 2) - 32
4018 if g_Game_IsServer
and g_Game_IsNet
then
4019 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4020 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4024 FObj
.X
:= X
-PLAYER_RECT
.X
;
4025 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4026 FObj
.oldX
:= FObj
.X
; // don't interpolate after respawn
4027 FObj
.oldY
:= FObj
.Y
;
4028 if FAlive
and FGhost
then
4034 if not g_Game_IsNet
then
4038 SetDirection(TDirection
.D_LEFT
);
4044 SetDirection(TDirection
.D_RIGHT
);
4050 if FDirection
= TDirection
.D_RIGHT
then
4052 SetDirection(TDirection
.D_LEFT
);
4057 SetDirection(TDirection
.D_RIGHT
);
4067 R_GFX_TELEPORT_FAST
,
4068 FObj
.X
+ PLAYER_RECT
.X
+ (PLAYER_RECT
.Width
div 2) - 32,
4069 FObj
.Y
+ PLAYER_RECT
.Y
+ (PLAYER_RECT
.Height
div 2) - 32
4072 if g_Game_IsServer
and g_Game_IsNet
then
4073 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4074 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4081 function nonz(a
: Single): Single;
4089 function TPlayer
.refreshCorpse(): Boolean;
4095 if FAlive
or FSpectator
then
4097 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
4099 for i
:= 0 to High(gCorpses
) do
4100 if gCorpses
[i
] <> nil then
4101 if gCorpses
[i
].FPlayerUID
= FUID
then
4109 function TPlayer
.getCameraObj(): TObj
;
4111 if (not FAlive
) and (not FSpectator
) and
4112 (FCorpse
>= 0) and (FCorpse
< Length(gCorpses
)) and
4113 (gCorpses
[FCorpse
] <> nil) and (gCorpses
[FCorpse
].FPlayerUID
= FUID
) then
4115 gCorpses
[FCorpse
].FObj
.slopeUpLeft
:= FObj
.slopeUpLeft
;
4116 Result
:= gCorpses
[FCorpse
].FObj
;
4124 procedure TPlayer
.PreUpdate();
4126 FSlopeOld
:= FObj
.slopeUpLeft
;
4127 FIncCamOld
:= FIncCam
;
4128 FObj
.oldX
:= FObj
.X
;
4129 FObj
.oldY
:= FObj
.Y
;
4132 procedure TPlayer
.Update();
4135 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4136 blockmon
, headwater
, dospawn
: Boolean;
4141 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4142 AnyServer
:= g_Game_IsServer
;
4144 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4145 DoLerp(NetInterpLevel
+ 1)
4151 if FClientID
>= 0 then
4153 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4154 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4155 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4166 if FPunchAnim
.played
then
4169 if FAlive
and (gFly
or FJetpack
) then
4172 if FDirection
= TDirection
.D_LEFT
then
4177 if FAlive
and (not FGhost
) then
4179 if FKeys
[KEY_UP
].Pressed
then
4181 if FKeys
[KEY_DOWN
].Pressed
then
4185 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4188 i
:= g_basic
.Sign(FIncCam
);
4189 FIncCam
:= Abs(FIncCam
);
4190 DecMin(FIncCam
, 5, 0);
4191 FIncCam
:= FIncCam
*i
;
4194 // no need to do that each second frame, weapon queue will take care of it
4195 if FAlive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4196 if FAlive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4198 if gTime
mod (GAME_TICK
*2) <> 0 then
4200 if (FObj
.Vel
.X
= 0) and FAlive
then
4202 if FKeys
[KEY_LEFT
].Pressed
then
4203 Run(TDirection
.D_LEFT
);
4204 if FKeys
[KEY_RIGHT
].Pressed
then
4205 Run(TDirection
.D_RIGHT
);
4210 g_Obj_Move(@FObj
, True, True, True);
4211 positionChanged(); // this updates spatial accelerators
4217 FActionChanged
:= False;
4221 // Let alive player do some actions
4222 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
4223 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
4224 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
4225 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
4226 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire()
4232 if NetServer
then MH_SEND_PlayerStats(FUID
);
4235 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
4236 if FKeys
[KEY_JUMP
].Pressed
then Jump()
4239 if AnyServer
and FJetpack
then
4243 if NetServer
then MH_SEND_PlayerStats(FUID
);
4245 FCanJetpack
:= True;
4252 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
4254 if FKeys
[k
].Pressed
then
4262 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4265 if (FTime
[T_RESPAWN
] <= gTime
) and
4266 gGameOn
and (not FAlive
) then
4268 if (g_Player_GetCount() > 1) then
4272 gExit
:= EXIT_RESTART
;
4277 // Dead spectator actions
4280 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
4281 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
4285 if (FSpectatePlayer
>= High(gPlayers
)) then
4286 FSpectatePlayer
:= -1
4290 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
4291 if gPlayers
[I
] <> nil then
4292 if gPlayers
[I
].alive
then
4293 if gPlayers
[I
].UID
<> FUID
then
4295 FSpectatePlayer
:= I
;
4300 if not SetSpect
then FSpectatePlayer
:= -1;
4311 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
4313 FYTo
:= FObj
.Y
- 32;
4314 FSpectatePlayer
:= -1;
4316 if FKeys
[KEY_DOWN
].Pressed
then
4318 FYTo
:= FObj
.Y
+ 32;
4319 FSpectatePlayer
:= -1;
4321 if FKeys
[KEY_LEFT
].Pressed
then
4323 FXTo
:= FObj
.X
- 32;
4324 FSpectatePlayer
:= -1;
4326 if FKeys
[KEY_RIGHT
].Pressed
then
4328 FXTo
:= FObj
.X
+ 32;
4329 FSpectatePlayer
:= -1;
4332 if (FXTo
< -64) then
4334 else if (FXTo
> gMapInfo
.Width
+ 32) then
4335 FXTo
:= gMapInfo
.Width
+ 32;
4336 if (FYTo
< -72) then
4338 else if (FYTo
> gMapInfo
.Height
+ 32) then
4339 FYTo
:= gMapInfo
.Height
+ 32;
4344 g_Obj_Move(@FObj
, True, True, True);
4345 positionChanged(); // this updates spatial accelerators
4352 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
4353 if gPlayers
[FSpectatePlayer
] <> nil then
4354 if gPlayers
[FSpectatePlayer
].alive
then
4356 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
4357 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
4361 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
4362 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
4363 PANEL_BLOCKMON
, True);
4364 headwater
:= HeadInLiquid(0, 0);
4366 // Сопротивление воздуха:
4367 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
4368 if FObj
.Vel
.X
<> 0 then
4369 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
4371 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
4372 DecMin(FPain
, 5, 0);
4373 DecMin(FPickup
, 1, 0);
4375 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
4377 // Обнулить действия примочек, чтобы фон пропал
4378 FMegaRulez
[MR_SUIT
] := 0;
4379 FMegaRulez
[MR_INVUL
] := 0;
4380 FMegaRulez
[MR_INVIS
] := 0;
4381 Kill(K_FALLKILL
, 0, HIT_FALL
);
4388 if FCurrWeap
= WEAPON_SAW
then
4389 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
4390 FSawSoundSelect
.IsPlaying()) then
4391 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
4394 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
4395 (not FJetSoundOff
.IsPlaying()) then
4397 FJetSoundFly
.SetPosition(0);
4398 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
4401 for b
:= WP_FIRST
to WP_LAST
do
4402 if FReloading
[b
] > 0 then
4408 if FShellTimer
> -1 then
4409 if FShellTimer
= 0 then
4411 if FShellType
= SHELL_SHELL
then
4412 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4413 GameVelX
, GameVelY
-2, SHELL_SHELL
)
4414 else if FShellType
= SHELL_DBLSHELL
then
4416 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4417 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
4418 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4419 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
4422 end else Dec(FShellTimer
);
4424 if (FBFGFireCounter
> -1) then
4425 if FBFGFireCounter
= 0 then
4429 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
4430 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
4431 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
4432 yd
:= wy
+firediry();
4433 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
4434 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
4435 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
4436 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
4437 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
4440 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
4441 FBFGFireCounter
:= -1;
4444 FBFGFireCounter
:= 0
4446 Dec(FBFGFireCounter
);
4448 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
4450 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
4452 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
4455 if (headwater
or blockmon
) then
4461 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
4464 else if (FAir
mod 31 = 0) and not blockmon
then
4467 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
4469 if Random(2) = 0 then
4470 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
4472 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
4474 end else if FAir
< AIR_DEF
then
4477 if FFireTime
> 0 then
4479 if BodyInLiquid(0, 0) then
4484 else if FMegaRulez
[MR_SUIT
] >= gTime
then
4486 if FMegaRulez
[MR_SUIT
] = gTime
then
4493 if FFirePainTime
<= 0 then
4495 if g_Game_IsServer
then
4496 Damage(2, FFireAttacker
, 0, 0, HIT_FLAME
);
4497 FFirePainTime
:= 12 - FFireTime
div 12;
4499 FFirePainTime
:= FFirePainTime
- 1;
4500 FFireTime
:= FFireTime
- 1;
4501 if ((FFireTime
mod 33) = 0) and (FMegaRulez
[MR_INVUL
] < gTime
) then
4502 FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
);
4503 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
4504 MH_SEND_PlayerStats(FUID
);
4508 if FDamageBuffer
> 0 then
4510 if FDamageBuffer
>= 9 then
4514 if FDamageBuffer
< 30 then i
:= 9
4515 else if FDamageBuffer
< 100 then i
:= 18
4519 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
4520 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
4521 FHealth
:= FHealth
-ii
;
4524 FHealth
:= FHealth
+FArmor
;
4529 if FHealth
<= 0 then
4530 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
4531 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
4532 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
4534 if FAlive
and ((FLastHit
<> HIT_FLAME
) or (FFireTime
<= 0)) then
4536 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
4537 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
4538 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
4539 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
4546 end; // if FAlive then ...
4548 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
4550 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
4551 FModel
.AnimState
.MinLength
:= i
;
4552 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
4554 if (FModel
.AnimState
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
4555 then SetAction(A_STAND
, True);
4557 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.GetFire()) then FModel
.Update
;
4559 for b
:= Low(FKeys
) to High(FKeys
) do
4560 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
4564 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
4566 x
:= FObj
.X
+PLAYER_RECT
.X
;
4567 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
4568 w
:= PLAYER_RECT
.Width
;
4569 h
:= PLAYER_RECT
.Height
;
4573 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
4575 if (dx
<> 0) or (dy
<> 0) then
4584 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
4586 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
4587 FObj
.Y
+PLAYER_RECT
.Y
,
4594 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
4596 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
4597 FObj
.Y
+PLAYER_RECT
.Y
,
4601 Panel
.Width
, Panel
.Height
);
4604 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
4606 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
4607 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
4608 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
4609 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
4612 function g_Player_ValidName(Name
: string): Boolean;
4618 if gPlayers
= nil then Exit
;
4620 for a
:= 0 to High(gPlayers
) do
4621 if gPlayers
[a
] <> nil then
4622 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
4629 procedure TPlayer
.SetDirection(Direction
: TDirection
);
4633 d
:= FModel
.Direction
;
4635 FModel
.Direction
:= Direction
;
4636 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
4638 FDirection
:= Direction
;
4641 function TPlayer
.GetKeys(): Byte;
4645 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
4646 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
4647 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
4649 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
4650 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
4653 procedure TPlayer
.Use();
4657 if FTime
[T_USE
] > gTime
then Exit
;
4659 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
4660 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
4662 for a
:= 0 to High(gPlayers
) do
4663 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
4664 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
4665 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
4666 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
4668 gPlayers
[a
].Touch();
4669 if g_Game_IsNet
and g_Game_IsServer
then
4670 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
4673 FTime
[T_USE
] := gTime
+120;
4676 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
4680 WX
, WY
, XD
, YD
: Integer;
4692 if R_BERSERK
in FRulez
then
4694 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
4695 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
4696 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
4699 locobj
.rect
.Width
:= 39;
4700 locobj
.rect
.Height
:= 52;
4701 locobj
.Vel
.X
:= (xd
-wx
) div 2;
4702 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
4703 locobj
.Accel
.X
:= xd
-wx
;
4704 locobj
.Accel
.y
:= yd
-wy
;
4706 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
4707 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
4709 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
4713 FPain
:= min(FPain
+ 25, 50);
4715 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
4720 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
4721 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
4723 FSawSoundSelect
.Stop();
4725 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
4727 else if not FSawSoundHit
.IsPlaying() then
4729 FSawSoundSelect
.Stop();
4730 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
4737 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
4738 FFireAngle
:= FAngle
;
4740 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4741 GameVelX
, GameVelY
-2, SHELL_BULLET
);
4746 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
4747 FFireAngle
:= FAngle
;
4750 FShellType
:= SHELL_SHELL
;
4755 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
4756 FFireAngle
:= FAngle
;
4759 FShellType
:= SHELL_DBLSHELL
;
4764 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
4765 FFireAngle
:= FAngle
;
4767 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4768 GameVelX
, GameVelY
-2, SHELL_BULLET
);
4771 WEAPON_ROCKETLAUNCHER
:
4773 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
4774 FFireAngle
:= FAngle
;
4780 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
4781 FFireAngle
:= FAngle
;
4787 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
4788 FFireAngle
:= FAngle
;
4792 WEAPON_SUPERPULEMET
:
4794 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
4795 FFireAngle
:= FAngle
;
4797 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4798 GameVelX
, GameVelY
-2, SHELL_SHELL
);
4801 WEAPON_FLAMETHROWER
:
4803 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
4805 FFireAngle
:= FAngle
;
4812 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
4813 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
4814 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
4817 procedure TPlayer
.DoLerp(Level
: Integer = 2);
4819 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
4820 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
4823 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
4829 if FJustTeleported
or (NetInterpLevel
< 1) then
4833 if FJustTeleported
then
4835 FObj
.oldX
:= FObj
.X
;
4836 FObj
.oldY
:= FObj
.Y
;
4841 AX
:= Abs(FXTo
- FObj
.X
);
4842 AY
:= Abs(FYTo
- FObj
.Y
);
4843 if (AX
> 32) or (AX
<= NetInterpLevel
) then
4845 if (AY
> 32) or (AY
<= NetInterpLevel
) then
4850 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
4852 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
4853 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
4854 PANEL_LIFTUP
, False) then Result
:= -1
4856 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
4857 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
4858 PANEL_LIFTDOWN
, False) then Result
:= 1
4862 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
4869 if Flag
= FLAG_NONE
then
4872 if not g_Game_IsServer
then Exit
;
4874 // Принес чужой флаг на свою базу:
4875 if (Flag
= FTeam
) and
4876 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
4877 (FFlag
<> FLAG_NONE
) then
4879 if FFlag
= FLAG_RED
then
4880 s
:= _lc
[I_PLAYER_FLAG_RED
]
4882 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
4884 evtype
:= FLAG_STATE_SCORED
;
4886 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
4887 Insert('.', ts
, Length(ts
) + 1 - 3);
4888 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
4890 g_Map_ResetFlag(FFlag
);
4891 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
4893 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
4894 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
4895 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
4900 if not sound_cap_flag
[a
].IsPlaying() then
4901 sound_cap_flag
[a
].Play();
4903 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
4906 if g_Game_IsNet
then
4908 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
4912 gFlags
[FFlag
].CaptureTime
:= 0;
4917 // Подобрал свой флаг - вернул его на базу:
4918 if (Flag
= FTeam
) and
4919 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
4921 if Flag
= FLAG_RED
then
4922 s
:= _lc
[I_PLAYER_FLAG_RED
]
4924 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
4926 evtype
:= FLAG_STATE_RETURNED
;
4927 gFlags
[Flag
].CaptureTime
:= 0;
4929 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
4931 g_Map_ResetFlag(Flag
);
4932 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
4934 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
4935 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
4936 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
4941 if not sound_ret_flag
[a
].IsPlaying() then
4942 sound_ret_flag
[a
].Play();
4945 if g_Game_IsNet
then
4947 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
4953 // Подобрал чужой флаг:
4954 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
4958 if Flag
= FLAG_RED
then
4959 s
:= _lc
[I_PLAYER_FLAG_RED
]
4961 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
4963 evtype
:= FLAG_STATE_CAPTURED
;
4965 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
4967 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
4969 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
4971 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
4972 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
4973 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
4978 if not sound_get_flag
[a
].IsPlaying() then
4979 sound_get_flag
[a
].Play();
4982 if g_Game_IsNet
then
4984 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
4990 procedure TPlayer
.SetFlag(Flag
: Byte);
4993 if FModel
<> nil then
4994 FModel
.SetFlag(FFlag
);
4997 function TPlayer
.DropFlag(Silent
: Boolean = True): Boolean;
5003 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5005 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5006 with gFlags
[FFlag
] do
5010 Direction
:= FDirection
;
5011 State
:= FLAG_STATE_DROPPED
;
5013 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5014 (FObj
.Vel
.Y
div 2)-2+Random(5));
5015 positionChanged(); // this updates spatial accelerators
5017 if FFlag
= FLAG_RED
then
5018 s
:= _lc
[I_PLAYER_FLAG_RED
]
5020 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5022 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5023 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5025 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5026 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5027 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5032 if (not Silent
) and (not sound_lost_flag
[a
].IsPlaying()) then
5033 sound_lost_flag
[a
].Play();
5035 if g_Game_IsNet
then
5036 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5042 procedure TPlayer
.GetSecret();
5044 if (self
= gPlayer1
) or (self
= gPlayer2
) then
5046 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [FName
]), True);
5047 g_Sound_PlayEx('SOUND_GAME_SECRET');
5052 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5054 Assert(Key
<= High(FKeys
));
5056 FKeys
[Key
].Pressed
:= True;
5057 FKeys
[Key
].Time
:= Time
;
5060 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5062 Result
:= FKeys
[K
].Pressed
;
5065 procedure TPlayer
.ReleaseKeys();
5069 for a
:= Low(FKeys
) to High(FKeys
) do
5071 FKeys
[a
].Pressed
:= False;
5076 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5080 function TPlayer
.firediry(): Integer;
5082 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5083 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5087 procedure TPlayer
.RememberState();
5090 SavedState
: TPlayerSavedState
;
5092 SavedState
.Health
:= FHealth
;
5093 SavedState
.Armor
:= FArmor
;
5094 SavedState
.Air
:= FAir
;
5095 SavedState
.JetFuel
:= FJetFuel
;
5096 SavedState
.CurrWeap
:= FCurrWeap
;
5097 SavedState
.NextWeap
:= FNextWeap
;
5098 SavedState
.NextWeapDelay
:= FNextWeapDelay
;
5099 for i
:= Low(FWeapon
) to High(FWeapon
) do
5100 SavedState
.Weapon
[i
] := FWeapon
[i
];
5101 for i
:= Low(FAmmo
) to High(FAmmo
) do
5102 SavedState
.Ammo
[i
] := FAmmo
[i
];
5103 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
5104 SavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5105 SavedState
.Rulez
:= FRulez
- [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5107 FSavedStateNum
:= -1;
5108 for i
:= Low(SavedStates
) to High(SavedStates
) do
5109 if not SavedStates
[i
].Used
then
5111 FSavedStateNum
:= i
;
5114 if FSavedStateNum
< 0 then
5116 SetLength(SavedStates
, Length(SavedStates
) + 1);
5117 FSavedStateNum
:= High(SavedStates
);
5120 SavedState
.Used
:= True;
5121 SavedStates
[FSavedStateNum
] := SavedState
;
5124 procedure TPlayer
.RecallState();
5127 SavedState
: TPlayerSavedState
;
5129 if(FSavedStateNum
< 0) or (FSavedStateNum
> High(SavedStates
)) then
5132 SavedState
:= SavedStates
[FSavedStateNum
];
5133 SavedStates
[FSavedStateNum
].Used
:= False;
5134 FSavedStateNum
:= -1;
5136 FHealth
:= SavedState
.Health
;
5137 FArmor
:= SavedState
.Armor
;
5138 FAir
:= SavedState
.Air
;
5139 FJetFuel
:= SavedState
.JetFuel
;
5140 FCurrWeap
:= SavedState
.CurrWeap
;
5141 FNextWeap
:= SavedState
.NextWeap
;
5142 FNextWeapDelay
:= SavedState
.NextWeapDelay
;
5143 for i
:= Low(FWeapon
) to High(FWeapon
) do
5144 FWeapon
[i
] := SavedState
.Weapon
[i
];
5145 for i
:= Low(FAmmo
) to High(FAmmo
) do
5146 FAmmo
[i
] := SavedState
.Ammo
[i
];
5147 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
5148 FMaxAmmo
[i
] := SavedState
.MaxAmmo
[i
];
5149 FRulez
:= SavedState
.Rulez
;
5151 if gGameSettings
.GameType
= GT_SERVER
then
5152 MH_SEND_PlayerStats(FUID
);
5155 procedure TPlayer
.SaveState (st
: TStream
);
5161 utils
.writeSign(st
, 'PLYR');
5162 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
5164 utils
.writeBool(st
, FIamBot
);
5166 utils
.writeInt(st
, Word(FUID
));
5168 utils
.writeStr(st
, FName
);
5170 utils
.writeInt(st
, Byte(FTeam
));
5172 utils
.writeBool(st
, FAlive
);
5173 // Израсходовал ли все жизни
5174 utils
.writeBool(st
, FNoRespawn
);
5176 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
5177 utils
.writeInt(st
, Byte(b
));
5179 utils
.writeInt(st
, LongInt(FHealth
));
5180 // Коэффициент инвалидности
5181 utils
.writeInt(st
, LongInt(FHandicap
));
5183 utils
.writeInt(st
, Byte(FLives
));
5185 utils
.writeInt(st
, LongInt(FArmor
));
5187 utils
.writeInt(st
, LongInt(FAir
));
5189 utils
.writeInt(st
, LongInt(FJetFuel
));
5191 utils
.writeInt(st
, LongInt(FPain
));
5193 utils
.writeInt(st
, LongInt(FKills
));
5195 utils
.writeInt(st
, LongInt(FMonsterKills
));
5197 utils
.writeInt(st
, LongInt(FFrags
));
5199 utils
.writeInt(st
, Byte(FFragCombo
));
5200 // Время последнего фрага
5201 utils
.writeInt(st
, LongWord(FLastFrag
));
5203 utils
.writeInt(st
, LongInt(FDeath
));
5205 utils
.writeInt(st
, Byte(FFlag
));
5207 utils
.writeInt(st
, LongInt(FSecrets
));
5209 utils
.writeInt(st
, Byte(FCurrWeap
));
5211 utils
.writeInt(st
, Word(FNextWeap
));
5213 utils
.writeInt(st
, Byte(FNextWeapDelay
));
5214 // Время зарядки BFG
5215 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
5217 utils
.writeInt(st
, LongInt(FDamageBuffer
));
5218 // Последний ударивший
5219 utils
.writeInt(st
, Word(FLastSpawnerUID
));
5220 // Тип последнего полученного урона
5221 utils
.writeInt(st
, Byte(FLastHit
));
5223 Obj_SaveState(st
, @FObj
);
5224 // Текущее количество патронов
5225 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
5226 // Максимальное количество патронов
5227 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
5229 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
5230 // Время перезарядки оружия
5231 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
5233 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
5234 // Наличие красного ключа
5235 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
5236 // Наличие зеленого ключа
5237 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
5238 // Наличие синего ключа
5239 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
5241 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
5242 // Время действия специальных предметов
5243 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
5244 // Время до повторного респауна, смены оружия, исользования, захвата флага
5245 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
5247 utils
.writeStr(st
, FModel
.GetName());
5249 utils
.writeInt(st
, Byte(FColor
.R
));
5250 utils
.writeInt(st
, Byte(FColor
.G
));
5251 utils
.writeInt(st
, Byte(FColor
.B
));
5255 procedure TPlayer
.LoadState (st
: TStream
);
5264 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
5265 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
5267 FIamBot
:= utils
.readBool(st
);
5269 FUID
:= utils
.readWord(st
);
5271 str
:= utils
.readStr(st
);
5272 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
5274 FTeam
:= utils
.readByte(st
);
5276 FAlive
:= utils
.readBool(st
);
5277 // Израсходовал ли все жизни
5278 FNoRespawn
:= utils
.readBool(st
);
5280 b
:= utils
.readByte(st
);
5281 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
5283 FHealth
:= utils
.readLongInt(st
);
5284 // Коэффициент инвалидности
5285 FHandicap
:= utils
.readLongInt(st
);
5287 FLives
:= utils
.readByte(st
);
5289 FArmor
:= utils
.readLongInt(st
);
5291 FAir
:= utils
.readLongInt(st
);
5293 FJetFuel
:= utils
.readLongInt(st
);
5295 FPain
:= utils
.readLongInt(st
);
5297 FKills
:= utils
.readLongInt(st
);
5299 FMonsterKills
:= utils
.readLongInt(st
);
5301 FFrags
:= utils
.readLongInt(st
);
5303 FFragCombo
:= utils
.readByte(st
);
5304 // Время последнего фрага
5305 FLastFrag
:= utils
.readLongWord(st
);
5307 FDeath
:= utils
.readLongInt(st
);
5309 FFlag
:= utils
.readByte(st
);
5311 FSecrets
:= utils
.readLongInt(st
);
5313 FCurrWeap
:= utils
.readByte(st
);
5315 FNextWeap
:= utils
.readWord(st
);
5317 FNextWeapDelay
:= utils
.readByte(st
);
5318 // Время зарядки BFG
5319 FBFGFireCounter
:= utils
.readSmallInt(st
);
5321 FDamageBuffer
:= utils
.readLongInt(st
);
5322 // Последний ударивший
5323 FLastSpawnerUID
:= utils
.readWord(st
);
5324 // Тип последнего полученного урона
5325 FLastHit
:= utils
.readByte(st
);
5327 Obj_LoadState(@FObj
, st
);
5328 // Текущее количество патронов
5329 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
5330 // Максимальное количество патронов
5331 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
5333 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
5334 // Время перезарядки оружия
5335 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
5337 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
5338 // Наличие красного ключа
5339 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
5340 // Наличие зеленого ключа
5341 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
5342 // Наличие синего ключа
5343 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
5345 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
5346 // Время действия специальных предметов
5347 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
5348 // Время до повторного респауна, смены оружия, исользования, захвата флага
5349 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
5351 str
:= utils
.readStr(st
);
5353 FColor
.R
:= utils
.readByte(st
);
5354 FColor
.G
:= utils
.readByte(st
);
5355 FColor
.B
:= utils
.readByte(st
);
5356 if (self
= gPlayer1
) then
5358 str
:= gPlayer1Settings
.Model
;
5359 FColor
:= gPlayer1Settings
.Color
;
5361 else if (self
= gPlayer2
) then
5363 str
:= gPlayer2Settings
.Model
;
5364 FColor
:= gPlayer2Settings
.Color
;
5366 // Обновляем модель игрока
5368 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
5369 FModel
.Color
:= TEAMCOLOR
[FTeam
]
5371 FModel
.Color
:= FColor
;
5375 procedure TPlayer
.AllRulez(Health
: Boolean);
5381 FHealth
:= PLAYER_HP_LIMIT
;
5382 FArmor
:= PLAYER_AP_LIMIT
;
5386 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
5387 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
5388 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5391 procedure TPlayer
.RestoreHealthArmor();
5393 FHealth
:= PLAYER_HP_LIMIT
;
5394 FArmor
:= PLAYER_AP_LIMIT
;
5397 procedure TPlayer
.FragCombo();
5401 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
5403 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
5405 if FFragCombo
< 5 then
5407 Param
:= FUID
or (FFragCombo
shl 16);
5408 if (FComboEvnt
>= Low(gDelayedEvents
)) and
5409 (FComboEvnt
<= High(gDelayedEvents
)) and
5410 gDelayedEvents
[FComboEvnt
].Pending
and
5411 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
5412 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
5414 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
5415 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
5418 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
5426 procedure TPlayer
.GiveItem(ItemType
: Byte);
5430 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
5432 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
5436 if FAir
< AIR_MAX
then
5443 if not (R_BERSERK
in FRulez
) then
5445 Include(FRulez
, R_BERSERK
);
5446 if FBFGFireCounter
< 1 then
5448 FCurrWeap
:= WEAPON_KASTET
;
5450 FModel
.SetWeapon(WEAPON_KASTET
);
5454 FBerserk
:= gTime
+30000;
5456 if FHealth
< PLAYER_HP_SOFT
then
5458 FHealth
:= PLAYER_HP_SOFT
;
5459 FBerserk
:= gTime
+30000;
5464 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
5466 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
5471 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
5473 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
5477 if FJetFuel
< JET_MAX
then
5479 FJetFuel
:= JET_MAX
;
5482 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
5483 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
5485 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
5486 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5488 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
5490 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
5492 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
5493 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5496 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
5497 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
5498 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
5499 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
5500 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
5501 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
5502 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
5503 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
5504 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
5506 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5507 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
5508 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5509 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
5510 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5511 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
5512 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5513 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
5514 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
5517 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
5518 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
5519 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
5520 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
5521 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
5523 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
5524 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
5525 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
5526 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
5527 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
5529 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5530 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5531 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5532 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5534 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
5537 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
5538 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
5539 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
5541 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
5542 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
5547 if g_Game_IsNet
and g_Game_IsServer
then
5548 MH_SEND_PlayerStats(FUID
);
5551 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
5554 if (Random(5) = 1) and (Times
= 1) then
5557 if BodyInLiquid(0, 0) then
5560 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
5561 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
5563 if Random(2) = 0 then
5564 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5566 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5570 for i
:= 1 to Times
do
5575 Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(R_GFX_SMOKE_WIDTH
div 2),
5576 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2)
5582 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
5585 if (Random(10) = 1) and (Times
= 1) then
5588 for i
:= 1 to Times
do
5593 Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(R_GFX_FLAME_WIDTH
div 2),
5594 Obj
.Y
+8+Random(8+Times
*2)
5600 procedure TPlayer
.PauseSounds(Enable
: Boolean);
5602 FSawSound
.Pause(Enable
);
5603 FSawSoundIdle
.Pause(Enable
);
5604 FSawSoundHit
.Pause(Enable
);
5605 FSawSoundSelect
.Pause(Enable
);
5606 FFlameSoundOn
.Pause(Enable
);
5607 FFlameSoundOff
.Pause(Enable
);
5608 FFlameSoundWork
.Pause(Enable
);
5609 FJetSoundFly
.Pause(Enable
);
5610 FJetSoundOn
.Pause(Enable
);
5611 FJetSoundOff
.Pause(Enable
);
5616 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
5621 FObj
.Rect
:= PLAYER_CORPSERECT
;
5623 FModel
:= g_PlayerModel_Get(ModelName
);
5627 FState
:= CORPSE_STATE_MESS
;
5628 FModel
.ChangeAnimation(A_DIE2
);
5632 FState
:= CORPSE_STATE_NORMAL
;
5633 FModel
.ChangeAnimation(A_DIE1
);
5637 destructor TCorpse
.Destroy();
5643 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
5645 procedure TCorpse
.positionChanged (); inline; begin end;
5647 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
5649 if (dx
<> 0) or (dy
<> 0) then
5658 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5660 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
5661 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
5662 w
:= PLAYER_CORPSERECT
.Width
;
5663 h
:= PLAYER_CORPSERECT
.Height
;
5667 procedure TCorpse
.Damage(Value
: Word; SpawnerUID
: Word; vx
, vy
: Integer);
5669 var Blood
: TModelBlood
;
5672 if FState
= CORPSE_STATE_REMOVEME
then
5675 FDamage
:= FDamage
+ Value
;
5677 {$IFDEF ENABLE_GIBS}
5678 if FDamage
> 150 then
5680 if FModel
<> nil then
5682 FState
:= CORPSE_STATE_REMOVEME
;
5685 FObj
.X
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
div 2),
5686 FObj
.Y
+ FObj
.Rect
.Y
+ (FObj
.Rect
.Height
div 2),
5691 // Звук мяса от трупа:
5692 FModel
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
5695 if (gBodyKillEvent
<> -1) and gDelayedEvents
[gBodyKillEvent
].Pending
then
5696 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
5697 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, SpawnerUID
);
5706 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
5707 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
5709 Blood
:= FModel
.GetBlood();
5710 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
5711 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
5712 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
5713 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
5718 procedure TCorpse
.Update();
5722 if FState
= CORPSE_STATE_REMOVEME
then
5725 FObj
.oldX
:= FObj
.X
;
5726 FObj
.oldY
:= FObj
.Y
;
5728 if gTime
mod (GAME_TICK
*2) <> 0 then
5730 g_Obj_Move(@FObj
, True, True, True);
5731 positionChanged(); // this updates spatial accelerators
5735 // Сопротивление воздуха для трупа:
5736 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5738 st
:= g_Obj_Move(@FObj
, True, True, True);
5739 positionChanged(); // this updates spatial accelerators
5741 if WordBool(st
and MOVE_FALLOUT
) then
5743 FState
:= CORPSE_STATE_REMOVEME
;
5747 if FModel
<> nil then
5752 procedure TCorpse
.SaveState (st
: TStream
);
5758 utils
.writeSign(st
, 'CORP');
5759 utils
.writeInt(st
, Byte(0));
5761 utils
.writeInt(st
, Byte(FState
));
5763 utils
.writeInt(st
, Byte(FDamage
));
5765 utils
.writeInt(st
, Byte(FModel
.Color
.R
));
5766 utils
.writeInt(st
, Byte(FModel
.Color
.G
));
5767 utils
.writeInt(st
, Byte(FModel
.Color
.B
));
5769 Obj_SaveState(st
, @FObj
);
5770 utils
.writeInt(st
, Word(FPlayerUID
));
5772 anim
:= (FModel
<> nil);
5773 utils
.writeBool(st
, anim
);
5774 if anim
then FModel
.AnimState
.SaveState(st
, 0, False);
5775 // animation for mask (same as animation, compat with older saves)
5776 anim
:= (FModel
<> nil);
5777 utils
.writeBool(st
, anim
);
5778 if anim
then FModel
.AnimState
.SaveState(st
, 0, False);
5782 procedure TCorpse
.LoadState (st
: TStream
);
5783 var anim
, blending
: Boolean; r
, g
, b
, alpha
: Byte; stub
: TAnimationState
;
5788 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
5789 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
5791 FState
:= utils
.readByte(st
);
5793 FDamage
:= utils
.readByte(st
);
5795 r
:= utils
.readByte(st
);
5796 g
:= utils
.readByte(st
);
5797 b
:= utils
.readByte(st
);
5798 FModel
.SetColor(r
, g
, b
);
5800 Obj_LoadState(@FObj
, st
);
5801 FPlayerUID
:= utils
.readWord(st
);
5803 stub
:= TAnimationState
.Create(False, 0, 0);
5804 anim
:= utils
.readBool(st
);
5807 stub
.LoadState(st
, alpha
, blending
);
5808 FModel
.AnimState
.CurrentFrame
:= Min(stub
.CurrentFrame
, FModel
.AnimState
.Length
);
5815 // animation for mask (same as animation, compat with older saves)
5816 anim
:= utils
.readBool(st
);
5817 if anim
then stub
.LoadState(st
, alpha
, blending
);
5823 constructor TBot
.Create();
5830 FSpectator
:= False;
5837 for a
:= WP_FIRST
to WP_LAST
do
5839 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
5840 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
5841 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
5845 destructor TBot
.Destroy();
5848 inherited Destroy();
5851 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
5853 inherited Respawn(Silent
, Force
);
5856 FSelectedWeapon
:= FCurrWeap
;
5861 procedure TBot
.UpdateCombat();
5874 TTargetRecord
= array of TTarget
;
5876 function Compare(a
, b
: TTarget
): Integer;
5878 if a
.Line
and not b
.Line
then // A на линии огня
5881 if not a
.Line
and b
.Line
then // B на линии огня
5883 else // И A, и B на линии или не на линии огня
5884 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
5886 if a
.Dist
> b
.Dist
then // B ближе
5888 else // A ближе или равноудаленно с B
5891 else // Странно -> A
5896 a
, x1
, y1
, x2
, y2
: Integer;
5897 targets
: TTargetRecord
;
5899 Target
, BestTarget
: TTarget
;
5900 firew
, fireh
: Integer;
5904 vsPlayer
, vsMonster
, ok
: Boolean;
5907 function monsUpdate (mon
: TMonster
): Boolean;
5909 result
:= false; // don't stop
5910 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
5912 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
5914 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
5915 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
5917 // Если монстр на экране и не прикрыт стеной
5918 if g_TraceVector(x1
, y1
, x2
, y2
) then
5920 // Добавляем к списку возможных целей
5921 SetLength(targets
, Length(targets
)+1);
5922 with targets
[High(targets
)] do
5929 Rect
:= mon
.Obj
.Rect
;
5930 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
5931 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
5932 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
5941 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
5942 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
5944 // Если текущее оружие не то, что нужно, то меняем:
5945 if FCurrWeap
<> FSelectedWeapon
then
5948 // Если нужно стрелять и нужное оружие, то нажать "Стрелять":
5949 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
5951 RemoveAIFlag('NEEDFIRE');
5954 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
5955 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
5956 else PressKey(KEY_FIRE
);
5960 // Координаты ствола:
5961 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
5962 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
5964 Target
.UID
:= FTargetUID
;
5967 if Target
.UID
<> 0 then
5968 begin // Цель есть - настраиваем
5969 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
5972 tpla
:= g_Player_Get(Target
.UID
);
5976 if (@FObj
) <> nil then
5983 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
5984 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
5985 Target
.Rect
:= PLAYER_RECT
;
5986 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
5987 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
5988 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
5989 Target
.IsPlayer
:= True;
5993 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
5996 mon
:= g_Monsters_ByUID(Target
.UID
);
5999 Target
.X
:= mon
.Obj
.X
;
6000 Target
.Y
:= mon
.Obj
.Y
;
6002 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6003 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6004 Target
.Rect
:= mon
.Obj
.Rect
;
6005 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6006 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6007 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6008 Target
.IsPlayer
:= False;
6015 begin // Цели нет - обнуляем
6020 Target
.Visible
:= False;
6021 Target
.Line
:= False;
6022 Target
.IsPlayer
:= False;
6027 // Если цель не видима или не на линии огня, то ищем все возможные цели:
6028 if (not Target
.Line
) or (not Target
.Visible
) then
6032 for a
:= 0 to High(gPlayers
) do
6033 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6034 (gPlayers
[a
].FUID
<> FUID
) and
6035 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6036 (not gPlayers
[a
].NoTarget
) and
6037 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6039 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6040 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6043 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6044 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6046 // Если игрок на экране и не прикрыт стеной:
6047 if g_TraceVector(x1
, y1
, x2
, y2
) then
6049 // Добавляем к списку возможных целей:
6050 SetLength(targets
, Length(targets
)+1);
6051 with targets
[High(targets
)] do
6053 UID
:= gPlayers
[a
].FUID
;
6054 X
:= gPlayers
[a
].FObj
.X
;
6055 Y
:= gPlayers
[a
].FObj
.Y
;
6058 Rect
:= PLAYER_RECT
;
6059 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6060 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6061 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6069 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6072 // Если есть возможные цели:
6073 // (Выбираем лучшую, меняем оружие и бежим к ней/от нее)
6074 if targets
<> nil then
6076 // Выбираем наилучшую цель:
6077 BestTarget
:= targets
[0];
6078 if Length(targets
) > 1 then
6079 for a
:= 1 to High(targets
) do
6080 if Compare(BestTarget
, targets
[a
]) = 1 then
6081 BestTarget
:= targets
[a
];
6083 // Если лучшая цель "виднее" текущей, то текущая := лучшая:
6084 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6085 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6087 Target
:= BestTarget
;
6089 if (Healthy() = 3) or ((Healthy() = 2)) then
6090 begin // Если здоровы - догоняем
6091 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6092 SetAIFlag('GORIGHT', '1');
6093 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6094 SetAIFlag('GOLEFT', '1');
6097 begin // Если побиты - убегаем
6098 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6099 SetAIFlag('GORIGHT', '1');
6100 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6101 SetAIFlag('GOLEFT', '1');
6104 // Выбираем оружие на основе расстояния и приоритетов:
6105 SelectWeapon(Abs(x1
-Target
.cX
));
6110 // (Догоняем/убегаем, стреляем по направлению к цели)
6111 // (Если цель далеко, то хватит следить за ней)
6112 if Target
.UID
<> 0 then
6114 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6115 Target
.Y
+ Target
.Rect
.Y
) then
6116 begin // Цель сбежала с "экрана"
6117 if (Healthy() = 3) or ((Healthy() = 2)) then
6118 begin // Если здоровы - догоняем
6119 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6120 SetAIFlag('GORIGHT', '1');
6121 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6122 SetAIFlag('GOLEFT', '1');
6125 begin // Если побиты - забываем о цели и убегаем
6127 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6128 SetAIFlag('GORIGHT', '1');
6129 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6130 SetAIFlag('GOLEFT', '1');
6134 begin // Цель пока на "экране"
6135 // Если цель не загорожена стеной, то отмечаем, когда ее видели:
6136 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6137 FLastVisible
:= gTime
;
6138 // Если разница высот не велика, то догоняем:
6139 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6141 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6142 SetAIFlag('GORIGHT', '1');
6143 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6144 SetAIFlag('GOLEFT', '1');
6148 // Выбираем угол вверх:
6149 if FDirection
= TDirection
.D_LEFT
then
6150 angle
:= ANGLE_LEFTUP
6152 angle
:= ANGLE_RIGHTUP
;
6154 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6155 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6157 // Если при угле вверх можно попасть в приблизительное положение цели:
6158 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6159 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6160 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6161 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6162 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6163 begin // то нужно стрелять вверх
6164 SetAIFlag('NEEDFIRE', '1');
6165 SetAIFlag('NEEDSEEUP', '1');
6168 // Выбираем угол вниз:
6169 if FDirection
= TDirection
.D_LEFT
then
6170 angle
:= ANGLE_LEFTDOWN
6172 angle
:= ANGLE_RIGHTDOWN
;
6174 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6175 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6177 // Если при угле вниз можно попасть в приблизительное положение цели:
6178 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6179 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6180 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6181 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6182 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6183 begin // то нужно стрелять вниз
6184 SetAIFlag('NEEDFIRE', '1');
6185 SetAIFlag('NEEDSEEDOWN', '1');
6188 // Если цель видно и она на такой же высоте:
6189 if Target
.Visible
and
6190 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6191 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6193 // Если идем в сторону цели, то надо стрелять:
6194 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
6195 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6196 begin // то нужно стрелять вперед
6197 SetAIFlag('NEEDFIRE', '1');
6198 SetAIFlag('NEEDSEEDOWN', '');
6199 SetAIFlag('NEEDSEEUP', '');
6201 // Если цель в пределах "экрана" и сложность позволяет прыжки сближения:
6202 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6203 if GetRnd(FDifficult
.CloseJump
) then
6204 begin // то если повезет - прыгаем (особенно, если близко)
6205 if Abs(FObj
.X
-Target
.X
) < 128 then
6209 if Random(a
) = 0 then
6210 SetAIFlag('NEEDJUMP', '1');
6214 // Если цель все еще есть:
6215 if Target
.UID
<> 0 then
6216 if gTime
-FLastVisible
> 2000 then // Если видели давно
6217 Target
.UID
:= 0 // то забыть цель
6218 else // Если видели недавно
6219 begin // но цель убили
6220 if Target
.IsPlayer
then
6221 begin // Цель - игрок
6222 pla
:= g_Player_Get(Target
.UID
);
6223 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
6224 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6225 Target
.UID
:= 0; // то забыть цель
6228 begin // Цель - монстр
6229 mon
:= g_Monsters_ByUID(Target
.UID
);
6230 if (mon
= nil) or (not mon
.alive
) then
6231 Target
.UID
:= 0; // то забыть цель
6234 end; // if Target.UID <> 0
6236 FTargetUID
:= Target
.UID
;
6238 // Если возможных целей нет:
6239 // (Атака чего-нибудь слева или справа)
6240 if targets
= nil then
6241 if GetAIFlag('ATTACKLEFT') <> '' then
6242 begin // Если нужно атаковать налево
6243 RemoveAIFlag('ATTACKLEFT');
6245 SetAIFlag('NEEDJUMP', '1');
6247 if RunDirection() = TDirection
.D_RIGHT
then
6248 begin // Идем не в ту сторону
6249 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6250 begin // Если здоровы, то, возможно, стреляем бежим влево и стреляем
6251 SetAIFlag('NEEDFIRE', '1');
6252 SetAIFlag('GOLEFT', '1');
6256 begin // Идем в нужную сторону
6257 if GetRnd(FDifficult
.InvisFire
) then // Возможно, стреляем вслепую
6258 SetAIFlag('NEEDFIRE', '1');
6259 if Healthy() <= 1 then // Побиты - убегаем
6260 SetAIFlag('GORIGHT', '1');
6264 if GetAIFlag('ATTACKRIGHT') <> '' then
6265 begin // Если нужно атаковать направо
6266 RemoveAIFlag('ATTACKRIGHT');
6268 SetAIFlag('NEEDJUMP', '1');
6270 if RunDirection() = TDirection
.D_LEFT
then
6271 begin // Идем не в ту сторону
6272 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6273 begin // Если здоровы, то, возможно, бежим вправо и стреляем
6274 SetAIFlag('NEEDFIRE', '1');
6275 SetAIFlag('GORIGHT', '1');
6280 if GetRnd(FDifficult
.InvisFire
) then // Возможно, стреляем вслепую
6281 SetAIFlag('NEEDFIRE', '1');
6282 if Healthy() <= 1 then // Побиты - убегаем
6283 SetAIFlag('GOLEFT', '1');
6287 //HACK! (does it belongs there?)
6288 RealizeCurrentWeapon();
6290 // Если есть возможные цели:
6291 // (Стреляем по направлению к целям)
6292 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6293 for a
:= 0 to High(targets
) do
6295 // Если можем стрелять по диагонали:
6296 if GetRnd(FDifficult
.DiagFire
) then
6298 // Ищем цель сверху и стреляем, если есть:
6299 if FDirection
= TDirection
.D_LEFT
then
6300 angle
:= ANGLE_LEFTUP
6302 angle
:= ANGLE_RIGHTUP
;
6304 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6305 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6307 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6308 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6309 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6310 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6311 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6313 SetAIFlag('NEEDFIRE', '1');
6314 SetAIFlag('NEEDSEEUP', '1');
6317 // Ищем цель снизу и стреляем, если есть:
6318 if FDirection
= TDirection
.D_LEFT
then
6319 angle
:= ANGLE_LEFTDOWN
6321 angle
:= ANGLE_RIGHTDOWN
;
6323 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6324 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6326 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6327 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6328 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6329 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6330 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6332 SetAIFlag('NEEDFIRE', '1');
6333 SetAIFlag('NEEDSEEDOWN', '1');
6337 // Если цель "перед носом", то стреляем:
6338 if targets
[a
].Line
and targets
[a
].Visible
and
6339 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
6340 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
6342 SetAIFlag('NEEDFIRE', '1');
6347 // Если летит пуля, то, возможно, подпрыгиваем:
6348 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
6349 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
6350 40+GetInterval(FDifficult
.Cover
, 40)) then
6351 SetAIFlag('NEEDJUMP', '1');
6353 // Если кончились паторны, то нужно сменить оружие:
6354 ammo
:= GetAmmoByWeapon(FCurrWeap
);
6355 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
6356 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
6358 SetAIFlag('SELECTWEAPON', '1');
6360 // Если нужно сменить оружие, то выбираем нужное:
6361 if GetAIFlag('SELECTWEAPON') = '1' then
6364 RemoveAIFlag('SELECTWEAPON');
6368 procedure TBot
.Update();
6381 // Проверяем, отключён ли AI ботов
6382 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
6384 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
6386 if g_debug_BotAIOff
= 3 then
6396 RealizeCurrentWeapon();
6403 procedure TBot
.ReleaseKey(Key
: Byte);
6412 function TBot
.KeyPressed(Key
: Word): Boolean;
6414 Result
:= FKeys
[Key
].Pressed
;
6417 function TBot
.GetAIFlag(aName
: String20
): String20
;
6423 aName
:= LowerCase(aName
);
6425 if FAIFlags
<> nil then
6426 for a
:= 0 to High(FAIFlags
) do
6427 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6429 Result
:= FAIFlags
[a
].Value
;
6434 procedure TBot
.RemoveAIFlag(aName
: String20
);
6438 if FAIFlags
= nil then Exit
;
6440 aName
:= LowerCase(aName
);
6442 for a
:= 0 to High(FAIFlags
) do
6443 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6445 if a
<> High(FAIFlags
) then
6446 for b
:= a
to High(FAIFlags
)-1 do
6447 FAIFlags
[b
] := FAIFlags
[b
+1];
6449 SetLength(FAIFlags
, Length(FAIFlags
)-1);
6454 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
6462 aName
:= LowerCase(aName
);
6464 if FAIFlags
<> nil then
6465 for a
:= 0 to High(FAIFlags
) do
6466 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6472 if ok
then FAIFlags
[a
].Value
:= fValue
6475 SetLength(FAIFlags
, Length(FAIFlags
)+1);
6476 with FAIFlags
[High(FAIFlags
)] do
6484 procedure TBot
.UpdateMove
;
6486 procedure GoLeft(Time
: Word = 1);
6488 ReleaseKey(KEY_LEFT
);
6489 ReleaseKey(KEY_RIGHT
);
6490 PressKey(KEY_LEFT
, Time
);
6491 SetDirection(TDirection
.D_LEFT
);
6494 procedure GoRight(Time
: Word = 1);
6496 ReleaseKey(KEY_LEFT
);
6497 ReleaseKey(KEY_RIGHT
);
6498 PressKey(KEY_RIGHT
, Time
);
6499 SetDirection(TDirection
.D_RIGHT
);
6502 function Rnd(a
: Word): Boolean;
6504 Result
:= Random(a
) = 0;
6507 procedure Turn(Time
: Word = 1200);
6509 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
6514 ReleaseKey(KEY_LEFT
);
6515 ReleaseKey(KEY_RIGHT
);
6518 function CanRunLeft(): Boolean;
6520 Result
:= not CollideLevel(-1, 0);
6523 function CanRunRight(): Boolean;
6525 Result
:= not CollideLevel(1, 0);
6528 function CanRun(): Boolean;
6530 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
6533 procedure Jump(Time
: Word = 30);
6535 PressKey(KEY_JUMP
, Time
);
6538 function NearHole(): Boolean;
6542 { TODO 5 : Лестницы }
6543 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
6544 for x
:= 1 to PLAYER_RECT
.Width
do
6545 if (not StayOnStep(x
*sx
, 0)) and
6546 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6547 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6556 function BorderHole(): Boolean;
6560 { TODO 5 : Лестницы }
6561 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
6562 for x
:= 1 to PLAYER_RECT
.Width
do
6563 if (not StayOnStep(x
*sx
, 0)) and
6564 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6565 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6567 for xx
:= x
to x
+32 do
6568 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
6578 function NearDeepHole(): Boolean;
6584 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
6587 for x
:= 1 to PLAYER_RECT
.Width
do
6588 if (not StayOnStep(x
*sx
, 0)) and
6589 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6590 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6592 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6594 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
6599 end else Result
:= False;
6602 function OverDeepHole(): Boolean;
6609 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6611 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
6618 function OnGround(): Boolean;
6620 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
6623 function OnLadder(): Boolean;
6625 Result
:= FullInStep(0, 0);
6628 function BelowLadder(): Boolean;
6630 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
6631 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
6632 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
6633 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
6636 function BelowLiftUp(): Boolean;
6638 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
6639 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
6640 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
6641 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
6644 function OnTopLift(): Boolean;
6646 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
6649 function CanJumpOver(): Boolean;
6653 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
6657 if not CollideLevel(sx
, 0) then Exit
;
6659 for y
:= 1 to BOT_MAXJUMP
do
6660 if CollideLevel(0, -y
) then Exit
else
6661 if not CollideLevel(sx
, -y
) then
6668 function CanJumpUp(Dist
: ShortInt): Boolean;
6675 if CollideLevel(Dist
, 0) then Exit
;
6678 for y
:= 0 to BOT_MAXJUMP
do
6679 if CollideLevel(Dist
, -y
) then
6688 for yy
:= y
+1 to BOT_MAXJUMP
do
6689 if not CollideLevel(Dist
, -yy
) then
6698 for y
:= 0 to BOT_MAXJUMP
do
6699 if CollideLevel(0, -y
) then
6707 if y
< yy
then Exit
;
6712 function IsSafeTrigger(): Boolean;
6717 if gTriggers
= nil then
6719 for a
:= 0 to High(gTriggers
) do
6720 if Collide(gTriggers
[a
].X
,
6723 gTriggers
[a
].Height
) and
6724 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
6725 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
6726 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
6727 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
6728 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
6733 // Возможно, нажимаем кнопку:
6734 if Rnd(16) and IsSafeTrigger() then
6737 // Если под лифтом или ступеньками, то, возможно, прыгаем:
6738 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
6740 ReleaseKey(KEY_LEFT
);
6741 ReleaseKey(KEY_RIGHT
);
6745 // Идем влево, если надо было:
6746 if GetAIFlag('GOLEFT') <> '' then
6748 RemoveAIFlag('GOLEFT');
6749 if CanRunLeft() then
6753 // Идем вправо, если надо было:
6754 if GetAIFlag('GORIGHT') <> '' then
6756 RemoveAIFlag('GORIGHT');
6757 if CanRunRight() then
6761 // Если вылетели за карту, то пробуем вернуться:
6762 if FObj
.X
< -32 then
6765 if FObj
.X
+32 > gMapInfo
.Width
then
6768 // Прыгаем, если надо было:
6769 if GetAIFlag('NEEDJUMP') <> '' then
6772 RemoveAIFlag('NEEDJUMP');
6775 // Смотрим вверх, если надо было:
6776 if GetAIFlag('NEEDSEEUP') <> '' then
6779 ReleaseKey(KEY_DOWN
);
6780 PressKey(KEY_UP
, 20);
6781 RemoveAIFlag('NEEDSEEUP');
6784 // Смотрим вниз, если надо было:
6785 if GetAIFlag('NEEDSEEDOWN') <> '' then
6788 ReleaseKey(KEY_DOWN
);
6789 PressKey(KEY_DOWN
, 20);
6790 RemoveAIFlag('NEEDSEEDOWN');
6793 // Если нужно было в дыру и мы не на земле, то покорно летим:
6794 if GetAIFlag('GOINHOLE') <> '' then
6795 if not OnGround() then
6797 ReleaseKey(KEY_LEFT
);
6798 ReleaseKey(KEY_RIGHT
);
6799 RemoveAIFlag('GOINHOLE');
6800 SetAIFlag('FALLINHOLE', '1');
6803 // Если падали и достигли земли, то хватит падать:
6804 if GetAIFlag('FALLINHOLE') <> '' then
6806 RemoveAIFlag('FALLINHOLE');
6808 // Если летели прямо и сейчас не на лестнице или на вершине лифта, то отходим в сторону:
6809 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
6810 if GetAIFlag('FALLINHOLE') = '' then
6811 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
6817 // Если на земле и можно подпрыгнуть, то, возможно, прыгаем:
6819 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
6823 // Если на земле и возле дыры (глубина > 2 ростов игрока):
6824 if OnGround() and NearHole() then
6825 if NearDeepHole() then // Если это бездна
6827 0..3: Turn(); // Бежим обратно
6828 4: Jump(); // Прыгаем
6829 5: begin // Прыгаем обратно
6834 else // Это не бездна и мы еще не летим туда
6835 if GetAIFlag('GOINHOLE') = '' then
6837 0: Turn(); // Не нужно туда
6838 1: Jump(); // Вдруг повезет - прыгаем
6839 else // Если яма с границей, то при случае можно туда прыгнуть
6840 if BorderHole() then
6841 SetAIFlag('GOINHOLE', '1');
6844 // Если на земле, но некуда идти:
6845 if (not CanRun()) and OnGround() then
6847 // Если мы на лестнице или можно перепрыгнуть, то прыгаем:
6848 if CanJumpOver() or OnLadder() then
6850 else // иначе попытаемся в другую сторону
6851 if Random(2) = 0 then
6853 if IsSafeTrigger() then
6859 // Осталось мало воздуха:
6860 if FAir
< 36 * 2 then
6863 // Выбираемся из кислоты, если нет костюма, обожглись, или мало здоровья:
6864 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
6865 if BodyInAcid(0, 0) then
6869 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
6871 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
6872 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
6875 {function TBot.NeedItem(Item: Byte): Byte;
6880 procedure TBot
.SelectWeapon(Dist
: Integer);
6884 function HaveAmmo(weapon
: Byte): Boolean;
6887 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
6888 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
6889 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
6890 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
6891 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
6892 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
6893 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
6894 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
6895 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
6896 else Result
:= True;
6901 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
6903 if Dist
> BOT_LONGDIST
then
6904 begin // Дальний бой
6906 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
6908 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
6912 else //if Dist > BOT_UNSAFEDIST then
6913 begin // Ближний бой
6915 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
6917 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
6924 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
6926 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
6932 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
6934 Result
:= inherited PickItem(ItemType
, force
, remove
);
6936 if Result
then SetAIFlag('SELECTWEAPON', '1');
6939 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
6941 Result
:= inherited Heal(value
, Soft
);
6944 function TBot
.Healthy(): Byte;
6946 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
6947 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
6948 else if (FHealth
> 50) then Result
:= 2
6949 else if (FHealth
> 20) then Result
:= 1
6953 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
6955 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
6956 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
6959 procedure TBot
.OnDamage(Angle
: SmallInt);
6967 if (Angle
= 0) or (Angle
= 180) then
6970 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
6971 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
6973 pla
:= g_Player_Get(FLastSpawnerUID
);
6974 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
6975 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
6978 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
6979 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
6981 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
6982 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
6983 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
6988 SetAIFlag('ATTACKLEFT', '1')
6990 SetAIFlag('ATTACKRIGHT', '1');
6994 function TBot
.RunDirection(): TDirection
;
6996 if Abs(Vel
.X
) >= 1 then
6998 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7000 Result
:= FDirection
;
7003 function TBot
.GetRnd(a
: Byte): Boolean;
7005 if a
= 0 then Result
:= False
7006 else if a
= 255 then Result
:= True
7007 else Result
:= Random(256) > 255-a
;
7010 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7012 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7016 procedure TDifficult
.save (st
: TStream
);
7018 utils
.writeInt(st
, Byte(DiagFire
));
7019 utils
.writeInt(st
, Byte(InvisFire
));
7020 utils
.writeInt(st
, Byte(DiagPrecision
));
7021 utils
.writeInt(st
, Byte(FlyPrecision
));
7022 utils
.writeInt(st
, Byte(Cover
));
7023 utils
.writeInt(st
, Byte(CloseJump
));
7024 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7025 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7028 procedure TDifficult
.load (st
: TStream
);
7030 DiagFire
:= utils
.readByte(st
);
7031 InvisFire
:= utils
.readByte(st
);
7032 DiagPrecision
:= utils
.readByte(st
);
7033 FlyPrecision
:= utils
.readByte(st
);
7034 Cover
:= utils
.readByte(st
);
7035 CloseJump
:= utils
.readByte(st
);
7036 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7037 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7041 procedure TBot
.SaveState (st
: TStream
);
7046 inherited SaveState(st
);
7047 utils
.writeSign(st
, 'BOT0');
7049 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7051 utils
.writeInt(st
, Word(FTargetUID
));
7052 // Время потери цели
7053 utils
.writeInt(st
, LongWord(FLastVisible
));
7054 // Количество флагов ИИ
7055 dw
:= Length(FAIFlags
);
7056 utils
.writeInt(st
, LongInt(dw
));
7058 for i
:= 0 to dw
-1 do
7060 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7061 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7063 // Настройки сложности
7064 FDifficult
.save(st
);
7068 procedure TBot
.LoadState (st
: TStream
);
7073 inherited LoadState(st
);
7074 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7076 FSelectedWeapon
:= utils
.readByte(st
);
7078 FTargetUID
:= utils
.readWord(st
);
7079 // Время потери цели
7080 FLastVisible
:= utils
.readLongWord(st
);
7081 // Количество флагов ИИ
7082 dw
:= utils
.readLongInt(st
);
7083 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7084 SetLength(FAIFlags
, dw
);
7086 for i
:= 0 to dw
-1 do
7088 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7089 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7091 // Настройки сложности
7092 FDifficult
.load(st
);
7097 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);
7098 conRegVar('player_indicator', @gPlayerIndicator
, 'Draw indicator only for current player, also for teammates, or not at all', 'Draw indicator only for current player, also for teammates, or not at all');
7099 conRegVar('player_indicator_style', @gPlayerIndicatorStyle
, 'Visual appearance of indicator', 'Visual appearance of indicator');