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 e_graphics
, g_playermodel
, g_basic
, g_textures
,
25 g_weapons
, g_phys
, g_sound
, g_saveload
, MAPDEF
,
61 AmmoLimits
: Array [0..1] of Array [A_BULLETS
..A_HIGH
] of Word =
62 ((200, 50, 50, 300, 100),
63 (400, 100, 100, 600, 200));
84 ANGLE_NONE
= Low(SmallInt);
86 CORPSE_STATE_REMOVEME
= 0;
87 CORPSE_STATE_NORMAL
= 1;
88 CORPSE_STATE_MESS
= 2;
90 PLAYER_RECT
: TRectWH
= (X
:15; Y
:12; Width
:34; Height
:52);
91 PLAYER_RECT_CX
= 15+(34 div 2);
92 PLAYER_RECT_CY
= 12+(52 div 2);
93 PLAYER_CORPSERECT
: TRectWH
= (X
:15; Y
:48; Width
:34; Height
:16);
96 PLAYER_HP_LIMIT
= 200;
98 PLAYER_AP_LIMIT
= 200;
102 PLAYER_BURN_TIME
= 110;
104 PLAYER1_DEF_COLOR
: TRGB
= (R
:64; G
:175; B
:48);
105 PLAYER2_DEF_COLOR
: TRGB
= (R
:96; G
:96; B
:96);
124 TPlayerStatArray
= Array of TPlayerStat
;
126 TPlayerSavedState
= record
134 Ammo
: Array [A_BULLETS
..A_HIGH
] of Word;
135 MaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
136 Weapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
137 Rulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
146 TPlayer
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
154 FDirection
: TDirection
;
162 FMonsterKills
: Integer;
169 FCanJetpack
: Boolean;
175 FNextWeapDelay
: Byte; // frames
176 FBFGFireCounter
: SmallInt;
177 FLastSpawnerUID
: Word;
181 FSpectatePlayer
: Integer;
182 FFirePainTime
: Integer;
185 FSavedStateNum
: Integer;
187 FModel
: TPlayerModel
;
188 FPunchAnim
: TAnimation
;
191 FActionForce
: Boolean;
192 FActionChanged
: Boolean;
194 FFireAngle
: SmallInt;
198 FShellTimer
: Integer;
200 FSawSound
: TPlayableSound
;
201 FSawSoundIdle
: TPlayableSound
;
202 FSawSoundHit
: TPlayableSound
;
203 FSawSoundSelect
: TPlayableSound
;
204 FFlameSoundOn
: TPlayableSound
;
205 FFlameSoundOff
: TPlayableSound
;
206 FFlameSoundWork
: TPlayableSound
;
207 FJetSoundOn
: TPlayableSound
;
208 FJetSoundOff
: TPlayableSound
;
209 FJetSoundFly
: TPlayableSound
;
213 FJustTeleported
: Boolean;
215 mEDamageType
: Integer;
218 function CollideLevel(XInc
, YInc
: Integer): Boolean;
219 function StayOnStep(XInc
, YInc
: Integer): Boolean;
220 function HeadInLiquid(XInc
, YInc
: Integer): Boolean;
221 function BodyInLiquid(XInc
, YInc
: Integer): Boolean;
222 function BodyInAcid(XInc
, YInc
: Integer): Boolean;
223 function FullInLift(XInc
, YInc
: Integer): Integer;
224 {procedure CollideItem();}
225 procedure FlySmoke(Times
: DWORD
= 1);
226 procedure OnFireFlame(Times
: DWORD
= 1);
227 function GetAmmoByWeapon(Weapon
: Byte): Word;
228 procedure SetAction(Action
: Byte; Force
: Boolean = False);
229 procedure OnDamage(Angle
: SmallInt); virtual;
230 function firediry(): Integer;
233 procedure Run(Direction
: TDirection
);
234 procedure NextWeapon();
235 procedure PrevWeapon();
242 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
243 procedure resetWeaponQueue ();
244 function hasAmmoForWeapon (weapon
: Byte): Boolean;
245 function hasAmmoForShooting (weapon
: Byte): Boolean;
246 function shouldSwitch (weapon
: Byte; hadWeapon
: Boolean) : Boolean;
248 procedure doDamage (v
: Integer);
250 function refreshCorpse(): Boolean;
253 FDamageBuffer
: Integer;
255 FAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
256 FMaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
257 FWeapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
258 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
260 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
261 FReloading
: Array [WP_FIRST
..WP_LAST
] of Word;
262 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
263 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
264 FWeapSwitchMode
: Byte;
265 FWeapPreferences
: Array [WP_FIRST
.. WP_LAST
+1] of Byte;
266 FSwitchToEmpty
: Byte;
269 FPreferredTeam
: Byte;
272 FWantsInGame
: Boolean;
277 FActualModelName
: string;
284 FSpawnInvul
: Integer;
286 FWaitForFirstSpawn
: Boolean; // set to `true` in server, used to spawn a player on first full state request
289 // debug: viewport offset
290 viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer;
292 function isValidViewPort (): Boolean; inline;
294 constructor Create(); virtual;
295 destructor Destroy(); override;
296 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
297 function GetRespawnPoint(): Byte;
298 procedure PressKey(Key
: Byte; Time
: Word = 1);
299 procedure ReleaseKeys();
300 procedure SetModel(ModelName
: String);
301 procedure SetColor(Color
: TRGB
);
302 function GetColor(): TRGB
;
303 procedure SetWeapon(W
: Byte);
304 function IsKeyPressed(K
: Byte): Boolean;
305 function GetKeys(): Byte;
306 function PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean; virtual;
307 procedure SetWeaponPrefs(Prefs
: Array of Byte);
308 procedure SetWeaponPref(Weapon
, Pref
: Byte);
309 function GetWeaponPref(Weapon
: Byte) : Byte;
310 function GetMorePrefered() : Byte;
311 function MaySwitch(Weapon
: Byte) : Boolean;
312 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
313 function Collide(Panel
: TPanel
): Boolean; overload
;
314 function Collide(X
, Y
: Integer): Boolean; overload
;
315 procedure SetDirection(Direction
: TDirection
);
316 procedure GetSecret();
317 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
319 procedure Push(vx
, vy
: Integer);
320 procedure ChangeModel(ModelName
: String);
321 procedure SwitchTeam
;
322 procedure ChangeTeam(Team
: Byte);
324 function GetFlag(Flag
: Byte): Boolean;
325 procedure SetFlag(Flag
: Byte);
326 function DropFlag(Silent
: Boolean = True; DoThrow
: Boolean = False): Boolean;
327 function TryDropFlag(): Boolean;
328 procedure AllRulez(Health
: Boolean);
329 procedure RestoreHealthArmor();
330 procedure FragCombo();
331 procedure GiveItem(ItemType
: Byte);
332 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
333 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
334 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
335 procedure MakeBloodSimple(Count
: Word);
336 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
337 procedure Reset(Force
: Boolean);
338 procedure Spectate(NoMove
: Boolean = False);
339 procedure SwitchNoClip
;
340 procedure SoftReset();
341 procedure Draw(); virtual;
342 procedure DrawPain();
343 procedure DrawPickup();
344 procedure DrawRulez();
346 procedure DrawIndicator(Color
: TRGB
);
347 procedure DrawBubble();
349 procedure PreUpdate();
350 procedure Update(); virtual;
351 procedure RememberState();
352 procedure RecallState();
353 procedure SaveState (st
: TStream
); virtual;
354 procedure LoadState (st
: TStream
); virtual;
355 procedure PauseSounds(Enable
: Boolean);
356 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
357 procedure DoLerp(Level
: Integer = 2);
358 procedure SetLerp(XTo
, YTo
: Integer);
359 procedure ProcessWeaponAction(Action
: Byte);
360 procedure QueueWeaponSwitch(Weapon
: Byte);
361 procedure RealizeCurrentWeapon();
365 procedure JetpackOff
;
366 procedure CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
368 //WARNING! this does nothing for now, but still call it!
369 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
371 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
372 procedure moveBy (dx
, dy
: Integer); inline;
374 function getCameraObj(): TObj
;
377 property Vel
: TPoint2i read FObj
.Vel
;
378 property Obj
: TObj read FObj
;
380 property Name
: String read FName write FName
;
381 property Model
: TPlayerModel read FModel
;
382 property Health
: Integer read FHealth write FHealth
;
383 property Lives
: Byte read FLives write FLives
;
384 property Armor
: Integer read FArmor write FArmor
;
385 property Air
: Integer read FAir write FAir
;
386 property JetFuel
: Integer read FJetFuel write FJetFuel
;
387 property Frags
: Integer read FFrags write FFrags
;
388 property Assists
: Integer read FAssists write FAssists
;
389 property Death
: Integer read FDeath write FDeath
;
390 property Kills
: Integer read FKills write FKills
;
391 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
392 property WeapSwitchMode
: Byte read FWeapSwitchMode write FWeapSwitchMode
;
393 property SwitchToEmpty
: Byte read FSwitchToEmpty write FSwitchToEmpty
;
394 property SkipFist
: Byte read FSkipFist write FSkipFist
;
395 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
396 property Secrets
: Integer read FSecrets
;
397 property GodMode
: Boolean read FGodMode write FGodMode
;
398 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
399 property NoReload
: Boolean read FNoReload write FNoReload
;
400 property alive
: Boolean read FAlive write FAlive
;
401 property Flag
: Byte read FFlag
;
402 property Team
: Byte read FTeam write FTeam
;
403 property Direction
: TDirection read FDirection
;
404 property GameX
: Integer read FObj
.X write FObj
.X
;
405 property GameY
: Integer read FObj
.Y write FObj
.Y
;
406 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
407 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
408 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
409 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
410 property IncCam
: Integer read FIncCam write FIncCam
;
411 property IncCamOld
: Integer read FIncCamOld write FIncCamOld
;
412 property SlopeOld
: Integer read FSlopeOld write FSlopeOld
;
413 property UID
: Word read FUID write FUID
;
414 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
415 property NetTime
: LongWord read FNetTime write FNetTime
;
418 property eName
: String read FName write FName
;
419 property eHealth
: Integer read FHealth write FHealth
;
420 property eLives
: Byte read FLives write FLives
;
421 property eArmor
: Integer read FArmor write FArmor
;
422 property eAir
: Integer read FAir write FAir
;
423 property eJetFuel
: Integer read FJetFuel write FJetFuel
;
424 property eFrags
: Integer read FFrags write FFrags
;
425 property eAssists
: Integer read FAssists write FAssists
;
426 property eDeath
: Integer read FDeath write FDeath
;
427 property eKills
: Integer read FKills write FKills
;
428 property eCurrWeap
: Byte read FCurrWeap write FCurrWeap
;
429 property eMonsterKills
: Integer read FMonsterKills write FMonsterKills
;
430 property eSecrets
: Integer read FSecrets write FSecrets
;
431 property eGodMode
: Boolean read FGodMode write FGodMode
;
432 property eNoTarget
: Boolean read FNoTarget write FNoTarget
;
433 property eNoReload
: Boolean read FNoReload write FNoReload
;
434 property eAlive
: Boolean read FAlive write FAlive
;
435 property eFlag
: Byte read FFlag
;
436 property eTeam
: Byte read FTeam write FTeam
;
437 property eDirection
: TDirection read FDirection
;
438 property eGameX
: Integer read FObj
.X write FObj
.X
;
439 property eGameY
: Integer read FObj
.Y write FObj
.Y
;
440 property eGameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
441 property eGameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
442 property eGameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
443 property eGameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
444 property eIncCam
: Integer read FIncCam write FIncCam
;
445 property eUID
: Word read FUID
;
446 property eJustTeleported
: Boolean read FJustTeleported
;
447 property eNetTime
: LongWord read FNetTime
;
449 // set this before assigning something to `eDamage`
450 property eDamageType
: Integer read mEDamageType write mEDamageType
;
451 property eDamage
: Integer write doDamage
;
462 WeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
463 CloseWeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
464 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
467 procedure save (st
: TStream
);
468 procedure load (st
: TStream
);
476 TBot
= class(TPlayer
)
478 FSelectedWeapon
: Byte;
481 FAIFlags
: Array of TAIFlag
;
482 FDifficult
: TDifficult
;
484 function GetRnd(a
: Byte): Boolean;
485 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
486 function RunDirection(): TDirection
;
487 function FullInStep(XInc
, YInc
: Integer): Boolean;
488 //function NeedItem(Item: Byte): Byte;
489 procedure SelectWeapon(Dist
: Integer);
490 procedure SetAIFlag(aName
, fValue
: String20
);
491 function GetAIFlag(aName
: String20
): String20
;
492 procedure RemoveAIFlag(aName
: String20
);
493 function Healthy(): Byte;
494 procedure UpdateMove();
495 procedure UpdateCombat();
496 function KeyPressed(Key
: Word): Boolean;
497 procedure ReleaseKey(Key
: Byte);
498 function TargetOnScreen(TX
, TY
: Integer): Boolean;
499 procedure OnDamage(Angle
: SmallInt); override;
502 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
503 constructor Create(); override;
504 destructor Destroy(); override;
505 procedure Draw(); override;
506 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
507 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
508 procedure Update(); override;
509 procedure SaveState (st
: TStream
); override;
510 procedure LoadState (st
: TStream
); override;
522 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
523 procedure moveBy (dx
, dy
: Integer); inline;
525 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
539 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
540 procedure moveBy (dx
, dy
: Integer); inline;
542 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
545 TCorpse
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
554 FAnimation
: TAnimation
;
555 FAnimationMask
: TAnimation
;
558 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
559 destructor Destroy(); override;
560 procedure Damage(Value
: Word; SpawnerUID
: Word; vx
, vy
: Integer);
563 procedure SaveState (st
: TStream
);
564 procedure LoadState (st
: TStream
);
566 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
567 procedure moveBy (dx
, dy
: Integer); inline;
569 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
571 function ObjPtr (): PObj
; inline;
573 property Obj
: TObj read FObj
; // copies object
574 property State
: Byte read FState
;
575 property Mess
: Boolean read FMess
;
578 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
584 gPlayers
: Array of TPlayer
;
585 gCorpses
: Array of TCorpse
;
586 gGibs
: Array of TGib
;
587 gShells
: Array of TShell
;
588 gTeamStat
: TTeamStat
;
589 gFly
: Boolean = False;
590 gAimLine
: Boolean = False;
591 gChatBubble
: Integer = 0;
592 gPlayerIndicator
: Integer = 1;
593 gPlayerIndicatorStyle
: Integer = 0;
595 gSpectLatchPID1
: Word = 0;
596 gSpectLatchPID2
: Word = 0;
597 MAX_RUNVEL
: Integer = 8;
598 VEL_JUMP
: Integer = 10;
599 SHELL_TIMEOUT
: Cardinal = 60000;
601 function Lerp(X
, Y
, Factor
: Integer): Integer;
603 procedure g_Gibs_SetMax(Count
: Word);
604 function g_Gibs_GetMax(): Word;
605 procedure g_Corpses_SetMax(Count
: Word);
606 function g_Corpses_GetMax(): Word;
607 procedure g_Force_Model_Set(Mode
: Word);
608 function g_Force_Model_Get(): Word;
609 procedure g_Forced_Model_SetName(Model
: String);
610 function g_Forced_Model_GetName(): String;
611 procedure g_Shells_SetMax(Count
: Word);
612 function g_Shells_GetMax(): Word;
614 procedure g_Player_Init();
615 procedure g_Player_Free();
616 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
617 function g_Player_CreateFromState (st
: TStream
): Word;
618 procedure g_Player_Remove(UID
: Word);
619 procedure g_Player_ResetTeams();
620 procedure g_Player_PreUpdate();
621 procedure g_Player_UpdateAll();
622 procedure g_Player_DrawAll();
623 procedure g_Player_DrawDebug(p
: TPlayer
);
624 procedure g_Player_DrawHealth();
625 procedure g_Player_RememberAll();
626 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
627 function g_Player_Get(UID
: Word): TPlayer
;
628 function g_Player_GetCount(): Byte;
629 function g_Player_GetStats(): TPlayerStatArray
;
630 function g_Player_ExistingName(Name
: String): Boolean;
631 function g_Player_CreateCorpse(Player
: TPlayer
): Integer;
632 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
633 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
634 procedure g_Player_UpdatePhysicalObjects();
635 procedure g_Player_DrawCorpses();
636 procedure g_Player_DrawShells();
637 procedure g_Player_RemoveAllCorpses();
638 procedure g_Player_Corpses_SaveState (st
: TStream
);
639 procedure g_Player_Corpses_LoadState (st
: TStream
);
640 procedure g_Player_ResetReady();
641 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
642 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
643 procedure g_Bot_MixNames();
644 procedure g_Bot_RemoveAll();
645 function g_Bot_GetCount(): Integer;
650 {$INCLUDE ../nogl/noGLuses.inc}
651 {$IFDEF ENABLE_HOLMES}
654 e_log
, g_map
, g_items
, g_console
, g_gfx
, Math
,
655 g_options
, g_triggers
, g_menu
, g_game
, g_grid
, e_res
,
656 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
,
657 g_net
, g_netmsg
, g_window
,
660 const PLR_SAVE_VERSION
= 0;
670 diag_precision
: Byte;
674 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
675 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
676 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
680 TIME_RESPAWN1
= 1500;
681 TIME_RESPAWN2
= 2000;
682 TIME_RESPAWN3
= 3000;
685 JET_MAX
= 540; // ~30 sec
686 PLAYER_SUIT_TIME
= 30000;
687 PLAYER_INVUL_TIME
= 30000;
688 PLAYER_INVIS_TIME
= 35000;
689 FRAG_COMBO_TIME
= 3000;
693 ANGLE_RIGHTDOWN
= -35;
695 ANGLE_LEFTDOWN
= -145;
696 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
697 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
700 BOT_UNSAFEDIST
= 128;
701 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
703 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
704 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
705 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
706 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
707 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
708 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
709 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
710 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
711 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
712 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
713 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
714 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
715 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
716 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
717 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
718 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
719 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
720 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
721 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
722 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
723 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
724 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
725 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
726 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
727 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
728 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
730 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
731 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
733 BOTNAMES_FILENAME
= 'botnames.txt';
734 BOTLIST_FILENAME
= 'botlist.txt';
738 MaxCorpses
: Word = 20;
739 MaxShells
: Word = 300;
740 ForceModel
: Word = 0;
741 ForcedModelName
: String = STD_PLAYER_MODEL
;
742 CurrentGib
: Integer = 0;
743 CurrentShell
: Integer = 0;
744 BotNames
: Array of String;
745 BotList
: Array of TBotProfile
;
746 SavedStates
: Array of TPlayerSavedState
;
749 function Lerp(X
, Y
, Factor
: Integer): Integer;
751 Result
:= X
+ ((Y
- X
) div Factor
);
754 function SameTeam(UID1
, UID2
: Word): Boolean;
758 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
759 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
761 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
763 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
764 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
766 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
769 procedure g_Gibs_SetMax(Count
: Word);
772 SetLength(gGibs
, Count
);
774 if CurrentGib
>= Count
then
778 function g_Gibs_GetMax(): Word;
783 procedure g_Shells_SetMax(Count
: Word);
786 SetLength(gShells
, Count
);
788 if CurrentShell
>= Count
then
792 function g_Shells_GetMax(): Word;
798 procedure g_Corpses_SetMax(Count
: Word);
801 SetLength(gCorpses
, Count
);
804 function g_Corpses_GetMax(): Word;
806 Result
:= MaxCorpses
;
809 procedure g_Force_Model_Set(Mode
: Word);
814 function g_Force_Model_Get(): Word;
816 Result
:= ForceModel
;
819 procedure g_Forced_Model_SetName(Model
: String);
821 ForcedModelName
:= Model
;
824 function g_Forced_Model_GetName(): String;
826 Result
:= ForcedModelName
;
829 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
839 // Åñòü ëè ìåñòî â gPlayers:
840 if gPlayers
<> nil then
841 for a
:= 0 to High(gPlayers
) do
842 if gPlayers
[a
] = nil then
848 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
851 SetLength(gPlayers
, Length(gPlayers
)+1);
855 // Ñîçäàåì îáúåêò èãðîêà:
857 gPlayers
[a
] := TBot
.Create()
859 gPlayers
[a
] := TPlayer
.Create();
862 gPlayers
[a
].FActualModelName
:= ModelName
;
863 gPlayers
[a
].SetModel(ModelName
);
864 if Bot
and (g_Force_Model_Get() <> 0) then
865 gPlayers
[a
].SetModel(g_Forced_Model_GetName());
867 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
868 if gPlayers
[a
].FModel
= nil then
872 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
876 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
877 if Random(2) = 0 then
881 gPlayers
[a
].FPreferredTeam
:= Team
;
883 case gGameSettings
.GameMode
of
884 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
886 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
888 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
891 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
892 gPlayers
[a
].FColor
:= Color
;
893 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
894 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
896 gPlayers
[a
].FModel
.Color
:= Color
;
898 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
899 gPlayers
[a
].FAlive
:= False;
901 Result
:= gPlayers
[a
].FUID
;
904 function g_Player_CreateFromState (st
: TStream
): Word;
905 var a
: Integer; ok
, Bot
: Boolean; pos
: Int64;
909 // check signature and entity type
911 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
912 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
913 Bot
:= utils
.readBool(st
);
916 // find free player slot
918 for a
:= 0 to High(gPlayers
) do
919 if gPlayers
[a
] = nil then
925 // allocate player slot
928 SetLength(gPlayers
, Length(gPlayers
)+1);
932 // create entity and load state
935 gPlayers
[a
] := TBot
.Create();
936 if (g_Force_Model_Get() <> 0) then
937 gPlayers
[a
].SetModel(g_Forced_Model_GetName());
940 gPlayers
[a
] := TPlayer
.Create();
941 gPlayers
[a
].FPhysics
:= True; // ???
942 gPlayers
[a
].LoadState(st
);
944 result
:= gPlayers
[a
].FUID
;
948 procedure g_Player_ResetTeams();
952 if g_Game_IsClient
then
954 if gPlayers
= nil then
956 for a
:= Low(gPlayers
) to High(gPlayers
) do
957 if gPlayers
[a
] <> nil then
958 case gGameSettings
.GameMode
of
960 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
962 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
963 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
964 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
967 gPlayers
[a
].ChangeTeam(TEAM_RED
)
969 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
972 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
976 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
979 _name
, _model
: String;
982 if not g_Game_IsServer
then Exit
;
984 // Íå äîáàâëÿåì áîòîâ åñëè ëèìèò óæå äîñòèãíóò
985 if (g_Bot_GetCount() >= gMaxBots
) then Exit
;
987 // Ñïèñîê íàçâàíèé ìîäåëåé:
988 m
:= g_PlayerModel_GetNames();
993 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
994 Team
:= TEAM_COOP
// COOP
996 if gGameSettings
.GameMode
= GM_DM
then
997 Team
:= TEAM_NONE
// DM
999 if Team
= TEAM_NONE
then // CTF / TDM
1001 // Àâòîáàëàíñ êîìàíä:
1005 for a
:= 0 to High(gPlayers
) do
1006 if gPlayers
[a
] <> nil then
1008 if gPlayers
[a
].Team
= TEAM_RED
then
1011 if gPlayers
[a
].Team
= TEAM_BLUE
then
1021 if Random(2) = 0 then
1027 // Âûáèðàåì áîòó èìÿ:
1029 if BotNames
<> nil then
1030 for a
:= 0 to High(BotNames
) do
1031 if g_Player_ExistingName(BotNames
[a
]) then
1033 _name
:= BotNames
[a
];
1037 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1038 _model
:= m
[Random(Length(m
))];
1041 with g_Player_Get(g_Player_Create(_model
,
1042 _RGB(Min(Random(9)*32, 255),
1043 Min(Random(9)*32, 255),
1044 Min(Random(9)*32, 255)),
1045 Team
, True)) as TBot
do
1047 // Åñëè èìåíè íåò, äåëàåì åãî èç UID áîòà
1049 Name
:= Format('DFBOT%.5d', [UID
])
1054 1: FDifficult
:= DIFFICULT_EASY
;
1055 2: FDifficult
:= DIFFICULT_MEDIUM
;
1056 else FDifficult
:= DIFFICULT_HARD
;
1059 for a
:= WP_FIRST
to WP_LAST
do
1061 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1062 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1063 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1066 FHandicap
:= Handicap
;
1068 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1070 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1071 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1076 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
1079 _name
, _model
: String;
1082 if not g_Game_IsServer
then Exit
;
1084 // Íå äîáàâëÿåì áîòîâ åñëè ëèìèò óæå äîñòèãíóò
1085 if (g_Bot_GetCount() >= gMaxBots
) then Exit
;
1087 // Ñïèñîê íàçâàíèé ìîäåëåé:
1088 m
:= g_PlayerModel_GetNames();
1093 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1094 Team
:= TEAM_COOP
// COOP
1096 if gGameSettings
.GameMode
= GM_DM
then
1097 Team
:= TEAM_NONE
// DM
1099 if Team
= TEAM_NONE
then
1100 Team
:= BotList
[num
].team
; // CTF / TDM
1102 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1104 num
:= Random(Length(BotList
))
1107 if (num
< 0) or (num
> Length(BotList
)-1) then
1109 if (num
= -1) and (BotList
<> nil) then
1110 lName
:= AnsiLowerCase(lName
);
1111 for a
:= 0 to High(BotList
) do
1112 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1122 _name
:= BotList
[num
].name
;
1123 if (_name
= '') and (BotNames
<> nil) then
1124 for a
:= 0 to High(BotNames
) do
1125 if g_Player_ExistingName(BotNames
[a
]) then
1127 _name
:= BotNames
[a
];
1132 _model
:= BotList
[num
].model
;
1133 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1134 if not InSArray(_model
, m
) then
1135 _model
:= m
[Random(Length(m
))];
1138 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1140 // Åñëè èìåíè íåò, äåëàåì åãî èç UID áîòà
1142 then Name
:= Format('DFBOT%.5d', [UID
])
1145 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1146 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1147 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1148 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1149 FDifficult
.Cover
:= BotList
[num
].cover
;
1150 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1152 FHandicap
:= Handicap
;
1154 for a
:= WP_FIRST
to WP_LAST
do
1156 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1157 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1158 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1161 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1163 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1167 procedure g_Bot_RemoveAll();
1171 if not g_Game_IsServer
then Exit
;
1172 if gPlayers
= nil then Exit
;
1174 for a
:= 0 to High(gPlayers
) do
1175 if gPlayers
[a
] <> nil then
1176 if gPlayers
[a
] is TBot
then
1178 gPlayers
[a
].Lives
:= 0;
1179 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1180 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1181 g_Player_Remove(gPlayers
[a
].FUID
);
1187 procedure g_Bot_MixNames();
1192 if BotNames
<> nil then
1193 for a
:= 0 to High(BotNames
) do
1195 b
:= Random(Length(BotNames
));
1197 Botnames
[a
] := BotNames
[b
];
1202 procedure g_Player_Remove(UID
: Word);
1206 if gPlayers
= nil then Exit
;
1208 if g_Game_IsServer
and g_Game_IsNet
then
1209 MH_SEND_PlayerDelete(UID
);
1211 for i
:= 0 to High(gPlayers
) do
1212 if gPlayers
[i
] <> nil then
1213 if gPlayers
[i
].FUID
= UID
then
1215 if gPlayers
[i
] is TPlayer
then
1216 TPlayer(gPlayers
[i
]).Free()
1218 TBot(gPlayers
[i
]).Free();
1224 procedure g_Player_Init();
1236 path
:= BOTNAMES_FILENAME
;
1237 if e_FindResource(DataDirs
, path
) then
1239 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1240 AssignFile(F
, path
);
1251 SetLength(BotNames
, Length(BotNames
)+1);
1252 BotNames
[High(BotNames
)] := s
;
1261 path
:= BOTLIST_FILENAME
;
1262 if e_FindResource(DataDirs
, path
) then
1264 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1265 config
:= TConfig
.CreateFile(path
);
1268 while config
.SectionExists(IntToStr(a
)) do
1270 SetLength(BotList
, Length(BotList
)+1);
1272 with BotList
[High(BotList
)] do
1274 name
:= config
.ReadStr(IntToStr(a
), 'name', ''); // Èìÿ áîòà
1275 model
:= config
.ReadStr(IntToStr(a
), 'model', ''); // Ìîäåëü
1278 s
:= config
.ReadStr(IntToStr(a
), 'team', '');
1281 else if s
= 'blue' then
1287 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1289 color
.R
:= StrToIntDef(sa
[0], 0);
1290 color
.G
:= StrToIntDef(sa
[1], 0);
1291 color
.B
:= StrToIntDef(sa
[2], 0);
1293 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0); // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì
1294 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0); // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó
1295 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0); // Òî÷íîñòü ñòðåëüáû ïîä óãëîì
1296 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0); // Òî÷íîñòü ñòðåëüáû â ïîëåòå
1297 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0); // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ
1298 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0); // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà
1300 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ
1301 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1302 if Length(sa
) = 10 then
1304 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1306 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ
1307 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1308 if Length(sa
) = 10 then
1310 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1312 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1313 if Length(sa) = 10 then
1315 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1324 SetLength(SavedStates
, 0);
1327 procedure g_Player_Free();
1331 if gPlayers
<> nil then
1333 for i
:= 0 to High(gPlayers
) do
1334 if gPlayers
[i
] <> nil then
1336 if gPlayers
[i
] is TPlayer
then
1337 TPlayer(gPlayers
[i
]).Free()
1339 TBot(gPlayers
[i
]).Free();
1348 SetLength(SavedStates
, 0);
1351 procedure g_Player_PreUpdate();
1355 if gPlayers
= nil then Exit
;
1356 for i
:= 0 to High(gPlayers
) do
1357 if gPlayers
[i
] <> nil then
1358 gPlayers
[i
].PreUpdate();
1361 procedure g_Player_UpdateAll();
1365 if gPlayers
= nil then Exit
;
1367 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1368 for i
:= 0 to High(gPlayers
) do
1370 if gPlayers
[i
] <> nil then
1372 if gPlayers
[i
] is TPlayer
then
1374 gPlayers
[i
].Update();
1375 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1379 // bot updates weapons in `UpdateCombat()`
1380 TBot(gPlayers
[i
]).Update();
1384 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1387 procedure g_Player_DrawAll();
1391 if gPlayers
= nil then Exit
;
1393 for i
:= 0 to High(gPlayers
) do
1394 if gPlayers
[i
] <> nil then
1395 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1396 else TBot(gPlayers
[i
]).Draw();
1399 procedure g_Player_DrawDebug(p
: TPlayer
);
1403 if p
= nil then Exit
;
1404 if (@p
.FObj
) = nil then Exit
;
1406 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1408 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1409 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1410 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1411 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1412 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1413 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1414 e_TextureFontPrint(0, fH
* 6, 'Old X: ' + IntToStr(p
.FObj
.oldX
), gStdFont
);
1415 e_TextureFontPrint(0, fH
* 7, 'Old Y: ' + IntToStr(p
.FObj
.oldY
), gStdFont
);
1418 procedure g_Player_DrawHealth();
1423 if gPlayers
= nil then Exit
;
1424 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1426 for i
:= 0 to High(gPlayers
) do
1427 if gPlayers
[i
] <> nil then
1429 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1430 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1431 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1432 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1433 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1434 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1438 function g_Player_Get(UID
: Word): TPlayer
;
1444 if gPlayers
= nil then
1447 for a
:= 0 to High(gPlayers
) do
1448 if gPlayers
[a
] <> nil then
1449 if gPlayers
[a
].FUID
= UID
then
1451 Result
:= gPlayers
[a
];
1456 function g_Player_GetCount(): Byte;
1462 if gPlayers
= nil then
1465 for a
:= 0 to High(gPlayers
) do
1466 if gPlayers
[a
] <> nil then
1467 Result
:= Result
+ 1;
1470 function g_Bot_GetCount(): Integer;
1476 if gPlayers
= nil then
1479 for a
:= 0 to High(gPlayers
) do
1480 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] is TBot
) then
1481 Result
:= Result
+ 1;
1484 function g_Player_GetStats(): TPlayerStatArray
;
1490 if gPlayers
= nil then Exit
;
1492 for a
:= 0 to High(gPlayers
) do
1493 if gPlayers
[a
] <> nil then
1495 SetLength(Result
, Length(Result
)+1);
1496 with Result
[High(Result
)] do
1499 Ping
:= gPlayers
[a
].FPing
;
1500 Loss
:= gPlayers
[a
].FLoss
;
1501 Name
:= gPlayers
[a
].FName
;
1502 Team
:= gPlayers
[a
].FTeam
;
1503 Frags
:= gPlayers
[a
].FFrags
;
1504 Assists
:= gPlayers
[a
].FAssists
;
1505 Deaths
:= gPlayers
[a
].FDeath
;
1506 Kills
:= gPlayers
[a
].FKills
;
1507 Color
:= gPlayers
[a
].FModel
.Color
;
1508 Lives
:= gPlayers
[a
].FLives
;
1509 Spectator
:= gPlayers
[a
].FSpectator
;
1510 UID
:= gPlayers
[a
].FUID
;
1515 procedure g_Player_ResetReady();
1519 if not g_Game_IsServer
then Exit
;
1520 if gPlayers
= nil then Exit
;
1522 for a
:= 0 to High(gPlayers
) do
1523 if gPlayers
[a
] <> nil then
1525 gPlayers
[a
].FReady
:= False;
1526 if g_Game_IsNet
then
1527 MH_SEND_GameEvent(NET_EV_INTER_READY
, gPlayers
[a
].UID
, 'N');
1531 procedure g_Player_RememberAll
;
1535 for i
:= Low(gPlayers
) to High(gPlayers
) do
1536 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1537 gPlayers
[i
].RememberState
;
1540 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1544 gTeamStat
[TEAM_RED
].Score
:= 0;
1545 gTeamStat
[TEAM_BLUE
].Score
:= 0;
1547 if gPlayers
<> nil then
1548 for i
:= 0 to High(gPlayers
) do
1549 if gPlayers
[i
] <> nil then
1551 gPlayers
[i
].Reset(Force
);
1553 if gPlayers
[i
] is TPlayer
then
1555 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1556 gPlayers
[i
].Respawn(Silent
)
1558 gPlayers
[i
].Spectate();
1561 TBot(gPlayers
[i
]).Respawn(Silent
);
1565 function g_Player_CreateCorpse(Player
: TPlayer
): Integer;
1573 if Player
.alive
then
1576 // Ðàçðûâàåì ñâÿçü ñ ïðåæíèì òðóïîì:
1577 i
:= Player
.FCorpse
;
1578 if (i
>= 0) and (i
< Length(gCorpses
)) then
1580 if (gCorpses
[i
] <> nil) and (gCorpses
[i
].FPlayerUID
= Player
.FUID
) then
1581 gCorpses
[i
].FPlayerUID
:= 0;
1584 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1589 if (FHealth
>= -50) or (gGibsCount
= 0) then
1591 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1595 for find_id
:= 0 to High(gCorpses
) do
1596 if gCorpses
[find_id
] = nil then
1603 find_id
:= Random(Length(gCorpses
));
1605 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1606 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1607 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1608 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1609 gCorpses
[find_id
].FPlayerUID
:= FUID
;
1614 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1615 FObj
.Y
+ PLAYER_RECT_CY
,
1616 FModel
.Name
, FModel
.Color
);
1620 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1624 if (gShells
= nil) or (Length(gShells
) = 0) then
1627 with gShells
[CurrentShell
] do
1633 if T
= SHELL_BULLET
then
1635 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1639 Obj
.Rect
.Width
:= 4;
1640 Obj
.Rect
.Height
:= 2;
1644 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1648 Obj
.Rect
.Width
:= 7;
1649 Obj
.Rect
.Height
:= 3;
1655 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1656 positionChanged(); // this updates spatial accelerators
1657 RAngle
:= Random(360);
1658 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1660 if CurrentShell
>= High(gShells
) then
1667 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1670 GibsArray
: TGibsArray
;
1673 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1675 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1677 Blood
:= g_PlayerModel_GetBlood(ModelName
);
1679 for a
:= 0 to High(GibsArray
) do
1680 with gGibs
[CurrentGib
] do
1683 ID
:= GibsArray
[a
].ID
;
1684 MaskID
:= GibsArray
[a
].MaskID
;
1687 Obj
.Rect
:= GibsArray
[a
].Rect
;
1688 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1689 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1690 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1691 positionChanged(); // this updates spatial accelerators
1692 RAngle
:= Random(360);
1694 if gBloodCount
> 0 then
1695 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1696 Random(48), Random(48), Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
1698 if CurrentGib
>= High(gGibs
) then
1705 procedure g_Player_UpdatePhysicalObjects();
1711 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1716 if T
= SHELL_BULLET
then
1717 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1719 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1724 if gGibs
<> nil then
1725 for i
:= 0 to High(gGibs
) do
1726 if gGibs
[i
].alive
then
1733 mr
:= g_Obj_Move(@Obj
, True, False, True);
1734 positionChanged(); // this updates spatial accelerators
1736 if WordBool(mr
and MOVE_FALLOUT
) then
1742 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1743 if WordBool(mr
and MOVE_HITWALL
) then
1744 Obj
.Vel
.X
:= -(vel
.X
div 2);
1745 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1746 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1748 if (Obj
.Vel
.X
>= 0) then
1750 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1751 if RAngle
>= 360 then
1752 RAngle
:= RAngle
mod 360;
1753 end else begin // Counter-clockwise
1754 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1756 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1759 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1760 if gTime
mod (GAME_TICK
*3) = 0 then
1761 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1765 if gCorpses
<> nil then
1766 for i
:= 0 to High(gCorpses
) do
1767 if gCorpses
[i
] <> nil then
1768 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1774 gCorpses
[i
].Update();
1777 if gShells
<> nil then
1778 for i
:= 0 to High(gShells
) do
1779 if gShells
[i
].alive
then
1786 mr
:= g_Obj_Move(@Obj
, True, False, True);
1787 positionChanged(); // this updates spatial accelerators
1789 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1795 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1796 if WordBool(mr
and MOVE_HITWALL
) then
1798 Obj
.Vel
.X
:= -(vel
.X
div 2);
1799 if not WordBool(mr
and MOVE_INWATER
) then
1800 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1802 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1804 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1805 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1806 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1808 if RAngle
mod 90 <> 0 then
1809 RAngle
:= (RAngle
div 90) * 90;
1811 else if not WordBool(mr
and MOVE_INWATER
) then
1812 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1815 if (Obj
.Vel
.X
>= 0) then
1817 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1818 if RAngle
>= 360 then
1819 RAngle
:= RAngle
mod 360;
1820 end else begin // Counter-clockwise
1821 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1823 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1829 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1831 x
:= Obj
.X
+Obj
.Rect
.X
;
1832 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1833 w
:= Obj
.Rect
.Width
;
1834 h
:= Obj
.Rect
.Height
;
1837 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1839 if (dx
<> 0) or (dy
<> 0) then
1848 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1852 w
:= Obj
.Rect
.Width
;
1853 h
:= Obj
.Rect
.Height
;
1856 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1858 if (dx
<> 0) or (dy
<> 0) then
1867 procedure TGib
.positionChanged (); inline; begin end;
1868 procedure TShell
.positionChanged (); inline; begin end;
1871 procedure g_Player_DrawCorpses();
1876 if gGibs
<> nil then
1877 for i
:= 0 to High(gGibs
) do
1878 if gGibs
[i
].alive
then
1881 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1884 Obj
.lerp(gLerpFactor
, fX
, fY
);
1886 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1887 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1889 e_DrawAdv(ID
, fX
, fY
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1892 e_DrawAdv(MaskID
, fX
, fY
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1898 if gCorpses
<> nil then
1899 for i
:= 0 to High(gCorpses
) do
1900 if gCorpses
[i
] <> nil then
1904 procedure g_Player_DrawShells();
1909 if gShells
<> nil then
1910 for i
:= 0 to High(gShells
) do
1911 if gShells
[i
].alive
then
1914 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1917 Obj
.lerp(gLerpFactor
, fX
, fY
);
1922 e_DrawAdv(SpriteID
, fX
, fY
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1926 procedure g_Player_RemoveAllCorpses();
1932 SetLength(gGibs
, MaxGibs
);
1933 SetLength(gShells
, MaxGibs
);
1937 if gCorpses
<> nil then
1938 for i
:= 0 to High(gCorpses
) do
1942 SetLength(gCorpses
, MaxCorpses
);
1945 procedure g_Player_Corpses_SaveState (st
: TStream
);
1949 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ
1951 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1953 // Êîëè÷åñòâî òðóïîâ
1954 utils
.writeInt(st
, LongInt(count
));
1956 if (count
= 0) then exit
;
1959 for i
:= 0 to High(gCorpses
) do
1961 if gCorpses
[i
] <> nil then
1964 utils
.writeStr(st
, gCorpses
[i
].FModelName
);
1966 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1967 // Ñîõðàíÿåì äàííûå òðóïà:
1968 gCorpses
[i
].SaveState(st
);
1974 procedure g_Player_Corpses_LoadState (st
: TStream
);
1982 g_Player_RemoveAllCorpses();
1984 // Êîëè÷åñòâî òðóïîâ:
1985 count
:= utils
.readLongInt(st
);
1986 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1988 if (count
= 0) then exit
;
1991 for i
:= 0 to count
-1 do
1994 str
:= utils
.readStr(st
);
1996 b
:= utils
.readBool(st
);
1998 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1999 // Çàãðóæàåì äàííûå òðóïà
2000 gCorpses
[i
].LoadState(st
);
2007 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
2009 procedure TPlayer
.BFGHit();
2011 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
2012 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
2013 if g_Game_IsServer
and g_Game_IsNet
then
2014 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
2015 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
2019 procedure TPlayer
.ChangeModel(ModelName
: string);
2021 locModel
: TPlayerModel
;
2023 locModel
:= g_PlayerModel_Get(ModelName
);
2024 if locModel
= nil then Exit
;
2030 procedure TPlayer
.SetModel(ModelName
: string);
2034 m
:= g_PlayerModel_Get(ModelName
);
2037 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
2038 m
:= g_PlayerModel_Get('doomer');
2041 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
2046 if FModel
<> nil then
2051 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2052 FModel
.Color
:= FColor
2054 FModel
.Color
:= TEAMCOLOR
[FTeam
];
2055 FModel
.SetWeapon(FCurrWeap
);
2056 FModel
.SetFlag(FFlag
);
2057 SetDirection(FDirection
);
2060 procedure TPlayer
.SetColor(Color
: TRGB
);
2063 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2064 if FModel
<> nil then FModel
.Color
:= Color
;
2069 function TPlayer
.GetColor(): TRGB
;
2071 result
:= FModel
.Color
;
2074 procedure TPlayer
.SetWeaponPrefs(Prefs
: Array of Byte);
2078 for i
:= WP_FIRST
to WP_LAST
+ 1 do
2080 if (Prefs
[i
] > WP_LAST
+ 1) then
2081 FWeapPreferences
[i
] := 0
2083 FWeapPreferences
[i
] := Prefs
[i
];
2087 procedure TPlayer
.SetWeaponPref(Weapon
, Pref
: Byte);
2089 if (Weapon
> WP_LAST
+ 1) then
2091 else if (Pref
<= WP_LAST
+ 1) and (Weapon
<= WP_LAST
+ 1) then
2092 FWeapPreferences
[Weapon
] := Pref
2093 else if (Weapon
<= WP_LAST
+ 1) and (Pref
> WP_LAST
+ 1) then
2094 FWeapPreferences
[Weapon
] := 0;
2097 function TPlayer
.GetWeaponPref(Weapon
: Byte) : Byte;
2099 if (Weapon
> WP_LAST
+ 1) then
2101 else if (FWeapPreferences
[Weapon
] > WP_LAST
+ 1) then
2104 result
:= FWeapPreferences
[Weapon
];
2107 function TPlayer
.GetMorePrefered() : Byte;
2109 testedWeap
, i
: Byte;
2111 testedWeap
:= FCurrWeap
;
2112 for i
:= WP_FIRST
to WP_LAST
do
2113 if FWeapon
[i
] and maySwitch(i
) and (FWeapPreferences
[i
] > FWeapPreferences
[testedWeap
]) then
2115 if (R_BERSERK
in FRulez
) and (FWeapPreferences
[WP_LAST
+ 1] > FWeapPreferences
[testedWeap
]) then
2116 testedWeap
:= WEAPON_KASTET
;
2117 result
:= testedWeap
;
2120 function TPlayer
.maySwitch(Weapon
: Byte) : Boolean;
2123 if (Weapon
= WEAPON_KASTET
) and (FSkipFist
<> 0) then
2125 if (FSkipFist
= 1) and (not (R_BERSERK
in FRulez
)) then
2128 else if (FSwitchToEmpty
= 0) and (not hasAmmoForShooting(Weapon
)) then
2132 procedure TPlayer
.SwitchTeam
;
2134 if g_Game_IsClient
then
2136 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
2138 if gGameOn
and FAlive
then
2139 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
2141 if FTeam
= TEAM_RED
then
2143 ChangeTeam(TEAM_BLUE
);
2144 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
2145 if g_Game_IsNet
then
2146 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
2150 ChangeTeam(TEAM_RED
);
2151 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
2152 if g_Game_IsNet
then
2153 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
2155 FPreferredTeam
:= FTeam
;
2158 procedure TPlayer
.ChangeTeam(Team
: Byte);
2165 TEAM_RED
, TEAM_BLUE
:
2166 FModel
.Color
:= TEAMCOLOR
[Team
];
2168 FModel
.Color
:= FColor
;
2170 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2171 MH_SEND_PlayerStats(FUID
);
2175 procedure TPlayer.CollideItem();
2180 if gItems = nil then Exit;
2181 if not FAlive then Exit;
2183 for i := 0 to High(gItems) do
2186 if (ItemType <> ITEM_NONE) and alive then
2187 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2188 PLAYER_RECT.Height, @Obj) then
2190 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2192 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2193 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2194 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2195 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2196 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2198 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2199 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2200 (gGameSettings.GameType = GT_SINGLE) and
2201 (g_Player_GetCount() > 1)) then
2202 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2208 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2210 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2211 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2215 constructor TPlayer
.Create();
2221 mEDamageType
:= HIT_SOME
;
2227 FSawSound
:= TPlayableSound
.Create();
2228 FSawSoundIdle
:= TPlayableSound
.Create();
2229 FSawSoundHit
:= TPlayableSound
.Create();
2230 FSawSoundSelect
:= TPlayableSound
.Create();
2231 FFlameSoundOn
:= TPlayableSound
.Create();
2232 FFlameSoundOff
:= TPlayableSound
.Create();
2233 FFlameSoundWork
:= TPlayableSound
.Create();
2234 FJetSoundFly
:= TPlayableSound
.Create();
2235 FJetSoundOn
:= TPlayableSound
.Create();
2236 FJetSoundOff
:= TPlayableSound
.Create();
2238 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2239 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2240 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2241 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2242 FFlameSoundOn
.SetByName('SOUND_WEAPON_FLAMEON');
2243 FFlameSoundOff
.SetByName('SOUND_WEAPON_FLAMEOFF');
2244 FFlameSoundWork
.SetByName('SOUND_WEAPON_FLAMEWORK');
2245 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2246 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2247 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2249 FSpectatePlayer
:= -1;
2253 FSavedStateNum
:= -1;
2261 FActualModelName
:= 'doomer';
2264 FObj
.Rect
:= PLAYER_RECT
;
2266 FBFGFireCounter
:= -1;
2267 FJustTeleported
:= False;
2270 FWaitForFirstSpawn
:= false;
2275 procedure TPlayer
.positionChanged (); inline;
2279 procedure TPlayer
.doDamage (v
: Integer);
2281 if (v
<= 0) then exit
;
2282 if (v
> 32767) then v
:= 32767;
2283 Damage(v
, 0, 0, 0, mEDamageType
);
2286 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2290 if (not g_Game_IsClient
) and (not FAlive
) then
2295 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2296 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2298 if not g_Game_IsClient
then
2301 if t
= HIT_TRAP
then
2303 // Ëîâóøêà óáèâàåò ñðàçó:
2305 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2307 if t
= HIT_SELF
then
2311 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2314 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2315 FMegaRulez
[MR_SUIT
] := 0;
2316 FMegaRulez
[MR_INVUL
] := 0;
2317 FMegaRulez
[MR_INVIS
] := 0;
2322 // Íî îò îñòàëüíîãî ñïàñàåò:
2323 if FMegaRulez
[MR_INVUL
] >= gTime
then
2330 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2331 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2332 (SpawnerUID
= FUID
) or
2333 (not SameTeam(FUID
, SpawnerUID
)) then
2335 FLastSpawnerUID
:= SpawnerUID
;
2337 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2338 if gBloodCount
> 0 then
2340 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2341 if value
div 4 <= c
then
2342 c
:= c
- (value
div 4)
2346 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2350 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2351 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2354 if t
= HIT_WATER
then
2355 g_Game_Effect_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2356 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2361 Inc(FDamageBuffer
, value
);
2365 FPain
:= FPain
+ value
;
2368 if g_Game_IsServer
and g_Game_IsNet
then
2370 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2371 MH_SEND_PlayerStats(FUID
);
2372 MH_SEND_PlayerPos(False, FUID
);
2376 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2379 if g_Game_IsClient
then
2384 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2386 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2389 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2391 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2395 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2396 MH_SEND_PlayerStats(FUID
);
2399 destructor TPlayer
.Destroy();
2401 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2403 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2407 FSawSoundIdle
.Free();
2408 FSawSoundHit
.Free();
2409 FSawSoundSelect
.Free();
2410 FFlameSoundOn
.Free();
2411 FFlameSoundOff
.Free();
2412 FFlameSoundWork
.Free();
2413 FJetSoundFly
.Free();
2415 FJetSoundOff
.Free();
2417 if FPunchAnim
<> nil then
2423 procedure TPlayer
.DrawIndicator(Color
: TRGB
);
2425 indX
, indY
, fX
, fY
, fSlope
: Integer;
2435 FObj
.lerp(gLerpFactor
, fX
, fY
);
2436 fSlope
:= nlerp(FSlopeOld
, FObj
.slopeUpLeft
, gLerpFactor
);
2438 case gPlayerIndicatorStyle
of
2441 if g_Texture_Get('TEXTURE_PLAYER_INDICATOR', ID
) then
2443 e_GetTextureSize(ID
, @indW
, @indH
);
2447 if (FObj
.X
+ FObj
.Rect
.X
) < 0 then
2450 indX
:= fX
+ FObj
.Rect
.X
+ FObj
.Rect
.Width
;
2451 indY
:= fY
+ FObj
.Rect
.Y
+ (FObj
.Rect
.Height
- indW
) div 2;
2454 else if (FObj
.X
+ FObj
.Rect
.X
+ FObj
.Rect
.Width
) > Max(gMapInfo
.Width
, gPlayerScreenSize
.X
) then
2457 indX
:= fX
+ FObj
.Rect
.X
- indH
;
2458 indY
:= fY
+ FObj
.Rect
.Y
+ (FObj
.Rect
.Height
- indW
) div 2;
2461 else if (FObj
.Y
- indH
) < 0 then
2464 indX
:= fX
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
- indW
) div 2;
2465 indY
:= fY
+ FObj
.Rect
.Y
+ FObj
.Rect
.Height
;
2471 indX
:= fX
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
- indW
) div 2;
2475 indY
:= indY
+ fSlope
;
2476 indX
:= EnsureRange(indX
, 0, Max(gMapInfo
.Width
, gPlayerScreenSize
.X
) - indW
);
2477 indY
:= EnsureRange(indY
, 0, Max(gMapInfo
.Height
, gPlayerScreenSize
.Y
) - indH
);
2481 e_DrawAdv(ID
, indX
, indY
, 0, True, False, indA
, @a
);
2488 e_TextureFontGetSize(gStdFont
, nW
, nH
);
2489 indX
:= fX
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
- Length(FName
) * nW
) div 2;
2490 indY
:= fY
- nH
+ fSlope
;
2491 e_TextureFontPrintEx(indX
, indY
, FName
, gStdFont
, Color
.R
, Color
.G
, Color
.B
, 1.0, True);
2497 procedure TPlayer
.DrawBubble();
2499 bubX
, bubY
, fX
, fY
: Integer;
2502 Rw
, Gw
, Bw
: SmallInt;
2506 CObj
:= getCameraObj();
2507 CObj
.lerp(gLerpFactor
, fX
, fY
);
2508 // NB: _F_Obj.Rect is used to keep the bubble higher; this is not a mistake
2509 bubX
:= fX
+FObj
.Rect
.X
+ IfThen(FDirection
= TDirection
.D_LEFT
, -4, 18);
2510 bubY
:= fY
+FObj
.Rect
.Y
- 18;
2518 1: // simple textual non-bubble
2520 bubX
:= fX
+FObj
.Rect
.X
- 11;
2521 bubY
:= fY
+FObj
.Rect
.Y
- 17;
2522 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2525 2: // advanced pixel-perfect bubble
2527 if FTeam
= TEAM_RED
then
2530 if FTeam
= TEAM_BLUE
then
2533 3: // colored bubble
2535 Rb
:= FModel
.Color
.R
;
2536 Gb
:= FModel
.Color
.G
;
2537 Bb
:= FModel
.Color
.B
;
2538 Rw
:= Min(Rb
* 2 + 64, 255);
2539 Gw
:= Min(Gb
* 2 + 64, 255);
2540 Bw
:= Min(Bb
* 2 + 64, 255);
2541 if (Abs(Rw
- Rb
) < 32)
2542 or (Abs(Gw
- Gb
) < 32)
2543 or (Abs(Bw
- Bb
) < 32) then
2545 Rb
:= Max(Rw
div 2 - 16, 0);
2546 Gb
:= Max(Gw
div 2 - 16, 0);
2547 Bb
:= Max(Bw
div 2 - 16, 0);
2550 4: // custom textured bubble
2552 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2553 if FDirection
= TDirection
.D_RIGHT
then
2554 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2556 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, TMirrorType
.Horizontal
);
2562 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2563 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2565 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2568 Dot
:= IfThen(FDirection
= TDirection
.D_LEFT
, 14, 5);
2569 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2570 e_DrawLine(1, bubX
+ IfThen(FDirection
= TDirection
.D_LEFT
, Dot
- 1, Dot
+ 1), bubY
+ 13, bubX
+ IfThen(FDirection
= TDirection
.D_LEFT
, Dot
- 1, Dot
+ 1), bubY
+ 15, Rw
, Gw
, Bw
);
2571 e_DrawLine(1, bubX
+ IfThen(FDirection
= TDirection
.D_LEFT
, Dot
- 2, Dot
+ 2), bubY
+ 13, bubX
+ IfThen(FDirection
= TDirection
.D_LEFT
, Dot
- 2, Dot
+ 2), bubY
+ 14, Rw
, Gw
, Bw
);
2572 e_DrawLine(1, bubX
+ IfThen(FDirection
= TDirection
.D_LEFT
, Dot
- 3, Dot
+ 3), bubY
+ 13, bubX
+ IfThen(FDirection
= TDirection
.D_LEFT
, Dot
- 3, Dot
+ 3), bubY
+ 13, Rw
, Gw
, Bw
);
2573 e_DrawLine(1, bubX
+ IfThen(FDirection
= TDirection
.D_LEFT
, Dot
- 3, Dot
+ 3), bubY
+ 14, bubX
+ IfThen(FDirection
= TDirection
.D_LEFT
, Dot
- 1, Dot
+ 1), bubY
+ 16, Rb
, Gb
, Bb
);
2577 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2578 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2579 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2582 procedure TPlayer
.Draw();
2587 Mirror
: TMirrorType
;
2588 fX
, fY
, fSlope
: Integer;
2590 FObj
.lerp(gLerpFactor
, fX
, fY
);
2591 fSlope
:= nlerp(FSlopeOld
, FObj
.slopeUpLeft
, gLerpFactor
);
2595 if Direction
= TDirection
.D_RIGHT
then
2596 Mirror
:= TMirrorType
.None
2598 Mirror
:= TMirrorType
.Horizontal
;
2600 if FPunchAnim
<> nil then
2602 FPunchAnim
.Draw(fX
+IfThen(Direction
= TDirection
.D_LEFT
, 15-FObj
.Rect
.X
, FObj
.Rect
.X
-15),
2603 fY
+fSlope
+FObj
.Rect
.Y
-11, Mirror
);
2604 if FPunchAnim
.played
then
2611 if (FMegaRulez
[MR_INVUL
] > gTime
) and ((gPlayerDrawn
<> Self
) or (FSpawnInvul
>= gTime
)) then
2612 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2614 e_GetTextureSize(ID
, @w
, @h
);
2615 if FDirection
= TDirection
.D_LEFT
then
2616 e_Draw(ID
, fX
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2617 fY
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+fSlope
, 0, True, False)
2619 e_Draw(ID
, fX
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2620 fY
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+fSlope
, 0, True, False);
2623 if FMegaRulez
[MR_INVIS
] > gTime
then
2625 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2626 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2628 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2629 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2633 FModel
.Draw(fX
, fY
+fSlope
, 200)
2635 FModel
.Draw(fX
, fY
+fSlope
);
2638 FModel
.Draw(fX
, fY
+fSlope
, 254);
2641 FModel
.Draw(fX
, fY
+fSlope
);
2644 if g_debug_Frames
then
2646 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2648 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2649 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2653 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2654 if (FMegaRulez
[MR_INVIS
] <= gTime
) or ((gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2655 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
)))) then
2657 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2658 if gAimLine
and alive
and
2659 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2664 procedure TPlayer
.DrawAim();
2665 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2670 {$IFDEF ENABLE_HOLMES}
2671 if isValidViewPort
and (self
= gPlayer1
) then
2673 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2677 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2678 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2680 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2684 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2689 wx
, wy
, xx
, yy
: Integer;
2693 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= TDirection
.D_LEFT
, 7, -7);
2694 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2703 1: begin // Chainsaw
2710 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2711 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2712 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2713 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2718 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2719 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2720 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2721 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2723 4: begin // Double Shotgun
2726 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2727 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2728 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2729 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2731 5: begin // Chaingun
2734 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2735 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2736 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2737 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2739 6: begin // Rocket Launcher
2742 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2743 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2744 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2745 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2747 7: begin // Plasmagun
2750 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2751 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2752 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2753 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2758 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2759 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2760 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2761 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2763 9: begin // Super Chaingun
2766 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2767 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2768 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2769 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2772 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2773 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2774 {$IF DEFINED(D2F_DEBUG)}
2775 drawCast(sz
, wx
, wy
, xx
, yy
);
2777 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2781 procedure TPlayer
.DrawGUI();
2784 X
, Y
, SY
, a
, p
, m
: Integer;
2788 stat
: TPlayerStatArray
;
2790 X
:= gPlayerScreenSize
.X
;
2791 SY
:= gPlayerScreenSize
.Y
;
2794 if gShowScore
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2796 if gGameSettings
.GameMode
= GM_CTF
then
2800 if gGameSettings
.GameMode
= GM_CTF
then
2802 s
:= 'TEXTURE_PLAYER_REDFLAG';
2803 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2804 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2805 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2806 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2807 if g_Texture_Get(s
, ID
) then
2808 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2811 s
:= IntToStr(gTeamStat
[TEAM_RED
].Score
);
2812 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2813 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2815 if gGameSettings
.GameMode
= GM_CTF
then
2817 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2818 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2819 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2820 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2821 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2822 if g_Texture_Get(s
, ID
) then
2823 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2826 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Score
);
2827 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2828 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2831 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2832 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2835 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2836 e_Draw(ID
, X
+2, Y
, 0, True, False);
2838 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2842 s
:= IntToStr(Frags
);
2843 t
:= IntToStr(Assists
);
2844 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2845 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2851 stat
:= g_Player_GetStats();
2856 for a
:= 0 to High(stat
) do
2857 if stat
[a
].Name
<> Name
then
2859 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2860 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2864 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2865 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2866 s
:= s
+IntToStr(Abs(Frags
-m
));
2868 t
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2869 if Assists
>= m
then t
:= t
+'+' else t
:= t
+'-';
2870 t
:= t
+IntToStr(Abs(Assists
-m
));
2872 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2873 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2876 if gLMSRespawn
> LMS_RESPAWN_NONE
then
2878 s
:= _lc
[I_GAME_WARMUP
];
2879 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2880 s
:= s
+ ': ' + IntToStr((gLMSRespawnTime
- gTime
) div 1000);
2881 e_CharFont_PrintEx(gMenuFont
, X
-64-tw
, SY
-32, s
, _RGB(0, 255, 0));
2883 else if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2885 s
:= IntToStr(Lives
);
2886 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2887 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2891 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2892 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2894 if R_BERSERK
in FRulez
then
2895 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2897 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2899 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2900 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2902 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2903 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2904 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2906 s
:= IntToStr(FArmor
);
2907 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2908 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2910 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2916 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2921 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2923 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2924 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2925 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2926 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2927 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2928 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2929 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2930 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2931 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2934 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2935 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2936 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2938 if R_KEY_RED
in FRulez
then
2939 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2941 if R_KEY_GREEN
in FRulez
then
2942 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2944 if R_KEY_BLUE
in FRulez
then
2945 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2947 if FJetFuel
> 0 then
2949 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2950 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2951 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2952 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2953 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2954 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2958 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2959 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2960 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2963 if gShowPing
and g_Game_IsClient
then
2965 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2966 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2972 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2973 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2974 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2977 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2978 s
:= _lc
[I_PLAYER_SPECT4
];
2979 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2980 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2981 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2987 procedure TPlayer
.DrawRulez();
2991 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2992 if (FMegaRulez
[MR_INVUL
] >= gTime
) and (FSpawnInvul
< gTime
) then
2994 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2995 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
3000 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
3001 191, 191, 191, 0, TBlending
.Invert
);
3004 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
3005 if FMegaRulez
[MR_SUIT
] >= gTime
then
3007 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
3008 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
3013 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
3014 0, 96, 0, 200, TBlending
.None
);
3017 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
3018 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
3020 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
3021 255, 0, 0, 200, TBlending
.None
);
3025 procedure TPlayer
.DrawPain();
3029 if FPain
= 0 then Exit
;
3033 if a
< 15 then h
:= 0
3034 else if a
< 35 then h
:= 1
3035 else if a
< 55 then h
:= 2
3036 else if a
< 75 then h
:= 3
3037 else if a
< 95 then h
:= 4
3040 //if a > 255 then a := 255;
3042 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
3043 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
3046 procedure TPlayer
.DrawPickup();
3050 if FPickup
= 0 then Exit
;
3054 if a
< 15 then h
:= 1
3055 else if a
< 35 then h
:= 2
3056 else if a
< 55 then h
:= 3
3057 else if a
< 75 then h
:= 4
3060 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
3063 procedure TPlayer
.DoPunch();
3068 if FPunchAnim
<> nil then begin
3073 st
:= 'FRAMES_PUNCH';
3074 if R_BERSERK
in FRulez
then
3075 st
:= st
+ '_BERSERK';
3076 if FKeys
[KEY_UP
].Pressed
then
3078 else if FKeys
[KEY_DOWN
].Pressed
then
3080 g_Frames_Get(id
, st
);
3081 FPunchAnim
:= TAnimation
.Create(id
, False, 1);
3084 procedure TPlayer
.Fire();
3086 f
, DidFire
: Boolean;
3087 wx
, wy
, xd
, yd
: Integer;
3090 if g_Game_IsClient
then Exit
;
3091 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
3092 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
3100 if FReloading
[FCurrWeap
] <> 0 then Exit
;
3105 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
3106 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
3107 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
3108 yd
:= wy
+firediry();
3114 if R_BERSERK
in FRulez
then
3116 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
3117 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
3118 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
3121 locobj
.rect
.Width
:= 39;
3122 locobj
.rect
.Height
:= 52;
3123 locobj
.Vel
.X
:= (xd
-wx
) div 2;
3124 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
3125 locobj
.Accel
.X
:= xd
-wx
;
3126 locobj
.Accel
.y
:= yd
-wy
;
3128 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
3129 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
3131 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
3133 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
3137 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
3141 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3146 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
3147 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
3149 FSawSoundSelect
.Stop();
3151 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
3153 else if not FSawSoundHit
.IsPlaying() then
3155 FSawSoundSelect
.Stop();
3156 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
3159 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3165 if FAmmo
[A_BULLETS
] > 0 then
3167 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
3168 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3169 Dec(FAmmo
[A_BULLETS
]);
3170 FFireAngle
:= FAngle
;
3173 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3174 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3178 if FAmmo
[A_SHELLS
] > 0 then
3180 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3181 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
3182 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3183 Dec(FAmmo
[A_SHELLS
]);
3184 FFireAngle
:= FAngle
;
3188 FShellType
:= SHELL_SHELL
;
3192 if FAmmo
[A_SHELLS
] >= 2 then
3194 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
3195 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3196 Dec(FAmmo
[A_SHELLS
], 2);
3197 FFireAngle
:= FAngle
;
3201 FShellType
:= SHELL_DBLSHELL
;
3205 if FAmmo
[A_BULLETS
] > 0 then
3207 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
3208 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
3209 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3210 Dec(FAmmo
[A_BULLETS
]);
3211 FFireAngle
:= FAngle
;
3214 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3215 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3218 WEAPON_ROCKETLAUNCHER
:
3219 if FAmmo
[A_ROCKETS
] > 0 then
3221 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
3222 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3223 Dec(FAmmo
[A_ROCKETS
]);
3224 FFireAngle
:= FAngle
;
3230 if FAmmo
[A_CELLS
] > 0 then
3232 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
3233 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3234 Dec(FAmmo
[A_CELLS
]);
3235 FFireAngle
:= FAngle
;
3241 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
3243 FBFGFireCounter
:= 17;
3244 if not FNoReload
then
3245 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
3246 Dec(FAmmo
[A_CELLS
], 40);
3250 WEAPON_SUPERPULEMET
:
3251 if FAmmo
[A_SHELLS
] > 0 then
3253 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3254 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
3255 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3256 Dec(FAmmo
[A_SHELLS
]);
3257 FFireAngle
:= FAngle
;
3260 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3261 GameVelX
, GameVelY
-2, SHELL_SHELL
);
3264 WEAPON_FLAMETHROWER
:
3265 if FAmmo
[A_FUEL
] > 0 then
3267 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
3269 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3271 FFireAngle
:= FAngle
;
3278 if g_Game_IsNet
and g_Game_IsServer
then MH_SEND_PlayerStats(FUID
);
3282 if g_Game_IsNet
then
3286 if FCurrWeap
<> WEAPON_BFG
then
3287 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
3289 if not FNoReload
then
3290 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
3293 MH_SEND_PlayerStats(FUID
);
3298 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
3299 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
3300 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
3303 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
3306 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
3307 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
3308 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
3309 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
3310 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
3315 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
3317 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
3318 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
3319 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
3322 procedure TPlayer
.FlamerOn
;
3324 FFlameSoundOff
.Stop();
3325 FFlameSoundOff
.SetPosition(0);
3328 if (not FFlameSoundOn
.IsPlaying()) and (not FFlameSoundWork
.IsPlaying()) then
3329 FFlameSoundWork
.PlayAt(FObj
.X
, FObj
.Y
);
3333 FFlameSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3338 procedure TPlayer
.FlamerOff
;
3342 FFlameSoundOn
.Stop();
3343 FFlameSoundOn
.SetPosition(0);
3344 FFlameSoundWork
.Stop();
3345 FFlameSoundWork
.SetPosition(0);
3346 FFlameSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3351 procedure TPlayer
.JetpackOn
;
3355 FJetSoundOn
.SetPosition(0);
3356 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3360 procedure TPlayer
.JetpackOff
;
3364 FJetSoundOff
.SetPosition(0);
3365 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3368 procedure TPlayer
.CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
3370 if Timeout
<= 0 then
3372 if (FMegaRulez
[MR_SUIT
] > gTime
) or (FMegaRulez
[MR_INVUL
] > gTime
) then
3373 exit
; // Íå çàãîðàåìñÿ êîãäà åñòü çàùèòà
3374 if g_Obj_CollidePanel(@FObj
, 0, 0, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
) then
3375 exit
; // Íå ïîäãîðàåì â âîäå íà âñÿêèé ñëó÷àé
3376 if FFireTime
<= 0 then
3377 g_Sound_PlayExAt('SOUND_IGNITE', FObj
.X
, FObj
.Y
);
3378 FFireTime
:= Timeout
;
3379 FFireAttacker
:= Attacker
;
3380 if g_Game_IsNet
and g_Game_IsServer
then
3381 MH_SEND_PlayerStats(FUID
);
3384 procedure TPlayer
.Jump();
3386 if gFly
or FJetpack
then
3388 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3389 if FObj
.Vel
.Y
> -VEL_FLY
then
3390 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3393 if FJetFuel
> 0 then
3395 if (FJetFuel
< 1) and g_Game_IsServer
then
3399 if g_Game_IsNet
then
3400 MH_SEND_PlayerStats(FUID
);
3406 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3408 FCanJetpack
:= False;
3410 // Ïðûãàåì èëè âñïëûâàåì:
3411 if (CollideLevel(0, 1) or
3412 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3413 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3414 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3416 FObj
.Vel
.Y
:= -VEL_JUMP
;
3417 FCanJetpack
:= False;
3421 if BodyInLiquid(0, 0) then
3422 FObj
.Vel
.Y
:= -VEL_SW
3423 else if (FJetFuel
> 0) and FCanJetpack
and
3424 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3428 if g_Game_IsNet
then
3429 MH_SEND_PlayerStats(FUID
);
3434 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3436 a
, i
, k
, ab
, ar
: Byte;
3440 srv
, netsrv
: Boolean;
3447 procedure PushItem(t
: Byte);
3451 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3452 it
:= g_Items_ByIdx(id
);
3453 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3455 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3456 (FObj
.Vel
.Y
div 2)-Random(9));
3457 it
.positionChanged(); // this updates spatial accelerators
3461 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3463 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3464 (FObj
.Vel
.Y
div 2)-Random(6));
3466 else // -3..+3; -3..0
3468 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3469 (FObj
.Vel
.Y
div 2)-Random(4));
3471 it
.positionChanged(); // this updates spatial accelerators
3474 if g_Game_IsNet
and g_Game_IsServer
then
3475 MH_SEND_ItemSpawn(True, id
);
3479 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3480 DoAssists
:= (gGameSettings
.GameMode
= GM_TDM
) or (gGameSettings
.GameMode
= GM_CTF
);
3481 Srv
:= g_Game_IsServer
;
3482 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3483 if Srv
then FDeath
:= FDeath
+ 1;
3488 if not FPhysics
then
3494 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3496 if FLives
> 0 then FLives
:= FLives
- 1;
3497 if FLives
= 0 then FNoRespawn
:= True;
3500 // Íîìåð òèïà ñìåðòè:
3503 K_SIMPLEKILL
: a
:= 1;
3505 K_EXTRAHARDKILL
: a
:= 3;
3510 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3512 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3519 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3521 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3522 K_EXTRAHARDKILL
, K_FALLKILL
:
3523 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3526 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3530 K_HARDKILL
, K_EXTRAHARDKILL
:
3534 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3535 if (KillType
<> K_FALLKILL
) and (Srv
) then
3536 g_Monsters_killedp();
3538 if SpawnerUID
= FUID
then
3542 if gGameSettings
.GameMode
= GM_TDM
then
3543 Dec(gTeamStat
[FTeam
].Score
);
3544 if DoFrags
or (gGameSettings
.GameMode
= GM_TDM
) then
3550 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3553 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3554 begin // Óáèò äðóãèì èãðîêîì
3555 KP
:= g_Player_Get(SpawnerUID
);
3556 if (KP
<> nil) and Srv
then
3558 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3559 if SameTeam(FUID
, SpawnerUID
) then
3570 if (DoAssists
or (gGameSettings
.GameMode
= GM_TDM
)) then
3578 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3579 Inc(gTeamStat
[KP
.Team
].Score
,
3580 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3582 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3585 plr
:= g_Player_Get(SpawnerUID
);
3593 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3597 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3601 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3606 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3607 begin // Óáèò ìîíñòðîì
3608 mon
:= g_Monsters_ByUID(SpawnerUID
);
3612 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
3616 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3620 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3624 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3629 else // Îñîáûå òèïû ñìåðòè
3632 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3633 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3634 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3635 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3636 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3637 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3643 for a
:= WP_FIRST
to WP_LAST
do
3647 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3648 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3649 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3650 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3651 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3652 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3653 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3654 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3655 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3664 if R_ITEM_BACKPACK
in FRulez
then
3665 PushItem(ITEM_AMMO_BACKPACK
);
3667 // Âûáðîñ ðàêåòíîãî ðàíöà:
3668 if FJetFuel
> 0 then
3669 PushItem(ITEM_JETPACK
);
3672 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) or
3673 (not LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
)) then
3675 if R_KEY_RED
in FRulez
then
3676 PushItem(ITEM_KEY_RED
);
3678 if R_KEY_GREEN
in FRulez
then
3679 PushItem(ITEM_KEY_GREEN
);
3681 if R_KEY_BLUE
in FRulez
then
3682 PushItem(ITEM_KEY_BLUE
);
3686 DropFlag(KillType
= K_FALLKILL
);
3689 FCorpse
:= g_Player_CreateCorpse(Self
);
3691 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3692 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3698 for i
:= Low(gPlayers
) to High(gPlayers
) do
3700 if gPlayers
[i
] = nil then continue
;
3701 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3704 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3705 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3710 OldLR
:= gLMSRespawn
;
3711 if (gGameSettings
.GameMode
= GM_COOP
) then
3715 // everyone is dead, restart the map
3716 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3718 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3719 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3720 gLMSRespawnTime
:= gTime
+ 5000;
3722 else if (a
= 1) then
3724 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3725 if (gPlayers
[k
] = gPlayer1
) or
3726 (gPlayers
[k
] = gPlayer2
) then
3727 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3728 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3729 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3732 else if (gGameSettings
.GameMode
= GM_TDM
) then
3734 if (ab
= 0) and (ar
<> 0) then
3737 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3739 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3740 Inc(gTeamStat
[TEAM_RED
].Score
);
3741 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3742 gLMSRespawnTime
:= gTime
+ 5000;
3744 else if (ar
= 0) and (ab
<> 0) then
3747 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3749 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3750 Inc(gTeamStat
[TEAM_BLUE
].Score
);
3751 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3752 gLMSRespawnTime
:= gTime
+ 5000;
3754 else if (ar
= 0) and (ab
= 0) then
3757 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3759 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3760 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3761 gLMSRespawnTime
:= gTime
+ 5000;
3764 else if (gGameSettings
.GameMode
= GM_DM
) then
3768 if gPlayers
[k
] <> nil then
3771 // survivor is the winner
3772 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3774 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3777 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3778 gLMSRespawnTime
:= gTime
+ 5000;
3780 else if (a
= 0) then
3782 // everyone is dead, restart the map
3783 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3785 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3786 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3787 gLMSRespawnTime
:= gTime
+ 5000;
3790 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3792 if NetMode
= NET_SERVER
then
3793 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
)
3795 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3801 MH_SEND_PlayerStats(FUID
);
3802 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3803 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3806 if srv
and FNoRespawn
then Spectate(True);
3807 FWantsInGame
:= True;
3810 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3812 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3813 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3816 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3818 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3819 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3822 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3824 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3825 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3826 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3827 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3828 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3829 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3830 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3831 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3834 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3836 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3837 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3838 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3839 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3842 procedure TPlayer
.ProcessWeaponAction(Action
: Byte);
3844 if g_Game_IsClient
then Exit
;
3846 WP_PREV
: PrevWeapon();
3847 WP_NEXT
: NextWeapon();
3851 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3853 if g_Game_IsClient
then Exit
;
3854 if Weapon
> High(FWeapon
) then Exit
;
3855 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3858 procedure TPlayer
.resetWeaponQueue ();
3861 FNextWeapDelay
:= 0;
3864 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3868 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3869 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
3870 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
3871 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3872 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3873 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3874 else result
:= (weapon
< length(FWeapon
));
3878 function TPlayer
.hasAmmoForShooting (weapon
: Byte): Boolean;
3882 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3883 WEAPON_SHOTGUN1
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
3884 WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 1);
3885 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
3886 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3887 WEAPON_PLASMA
: result
:= (FAmmo
[A_CELLS
] > 0);
3888 WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] >= 40);
3889 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3890 else result
:= (weapon
< length(FWeapon
));
3894 function TPlayer
.shouldSwitch (weapon
: Byte; hadWeapon
: Boolean): Boolean;
3897 if (weapon
> WP_LAST
+ 1) then
3902 if (FWeapSwitchMode
= 1) and not hadWeapon
then
3904 else if (FWeapSwitchMode
= 2) then
3905 result
:= (FWeapPreferences
[weapon
] > FWeapPreferences
[FCurrWeap
]);
3908 // return 255 for "no switch"
3909 function TPlayer
.getNextWeaponIndex (): Byte;
3912 wantThisWeapon
: array[0..64] of Boolean;
3913 wwc
: Integer = 0; //HACK!
3916 result
:= 255; // default result: "no switch"
3917 //e_LogWriteFln('FSWITCHTOEMPTY: %s', [FSwitchToEmpty], TMsgType.Notify);
3918 // had weapon cycling on previous frame? remove that flag
3919 if (FNextWeap
and $2000) <> 0 then
3921 FNextWeap
:= FNextWeap
and $1FFF;
3922 FNextWeapDelay
:= 0;
3924 // cycling has priority
3925 if (FNextWeap
and $C000) <> 0 then
3927 if (FNextWeap
and $8000) <> 0 then
3931 FNextWeap
:= FNextWeap
or $2000; // we need this
3932 if FNextWeapDelay
> 0 then
3933 exit
; // cooldown time
3935 for i
:= 0 to High(FWeapon
) do
3937 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3938 if FWeapon
[cwi
] and maySwitch(cwi
) then
3940 //e_LogWriteFln(' SWITCH: cur=%d; new=%d %s %s', [FCurrWeap, cwi, FSwitchToEmpty, hasAmmoForWeapon(cwi)], TMsgType.Notify);
3941 result
:= Byte(cwi
);
3942 FNextWeapDelay
:= WEAPON_DELAY
;
3950 for i
:= 0 to High(wantThisWeapon
) do
3951 wantThisWeapon
[i
] := false;
3952 for i
:= 0 to High(FWeapon
) do
3953 if (FNextWeap
and (1 shl i
)) <> 0 then
3955 wantThisWeapon
[i
] := true;
3959 // exclude currently selected weapon from the set
3960 wantThisWeapon
[FCurrWeap
] := false;
3961 // slow down alterations a little
3964 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3965 // more than one weapon requested, assume "alteration" and check alteration delay
3966 if FNextWeapDelay
> 0 then
3972 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3973 // but clear all counters if no weapon should be switched
3979 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3980 // try weapons in descending order
3981 for i
:= High(FWeapon
) downto 0 do
3983 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3988 FNextWeapDelay
:= WEAPON_DELAY
* 2; // anyway, 'cause why not
3989 //e_LogWriteFln('FOUND %s %s %s', [result, FSwitchToEmpty, hasAmmoForWeapon(i)], TMsgType.Notify);
3993 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3997 procedure TPlayer
.RealizeCurrentWeapon();
3998 function switchAllowed (): Boolean;
4003 if FBFGFireCounter
<> -1 then
4005 if FTime
[T_SWITCH
] > gTime
then
4007 for i
:= WP_FIRST
to WP_LAST
do
4008 if FReloading
[i
] > 0 then
4016 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
4017 //FNextWeap := FNextWeap and $1FFF;
4018 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
4020 if not switchAllowed
then
4022 //HACK for weapon cycling
4023 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
4027 nw
:= getNextWeaponIndex();
4029 if nw
= 255 then exit
; // don't reset anything here
4030 if nw
> High(FWeapon
) then
4032 // don't forget to reset queue here!
4033 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
4041 FTime
[T_SWITCH
] := gTime
+156;
4042 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
4043 FModel
.SetWeapon(FCurrWeap
);
4044 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
4048 procedure TPlayer
.NextWeapon();
4050 if g_Game_IsClient
then Exit
;
4054 procedure TPlayer
.PrevWeapon();
4056 if g_Game_IsClient
then Exit
;
4060 procedure TPlayer
.SetWeapon(W
: Byte);
4062 if FCurrWeap
<> W
then
4063 if W
= WEAPON_SAW
then
4064 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
4067 FModel
.SetWeapon(CurrWeap
);
4071 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
4074 switchWeapon
: Byte = 255;
4075 hadWeapon
: Boolean = False;
4078 if g_Game_IsClient
then Exit
;
4080 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
4081 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
4085 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
4087 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
4091 if gFlash
= 2 then Inc(FPickup
, 5);
4095 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
4097 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
4101 if gFlash
= 2 then Inc(FPickup
, 5);
4105 if FArmor
< PLAYER_AP_SOFT
then
4107 FArmor
:= PLAYER_AP_SOFT
;
4110 if gFlash
= 2 then Inc(FPickup
, 5);
4114 if FArmor
< PLAYER_AP_LIMIT
then
4116 FArmor
:= PLAYER_AP_LIMIT
;
4119 if gFlash
= 2 then Inc(FPickup
, 5);
4123 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
4125 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
4129 if gFlash
= 2 then Inc(FPickup
, 5);
4133 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) or (FFireTime
> 0) then
4135 if FHealth
< PLAYER_HP_LIMIT
then
4136 FHealth
:= PLAYER_HP_LIMIT
;
4137 if FArmor
< PLAYER_AP_LIMIT
then
4138 FArmor
:= PLAYER_AP_LIMIT
;
4142 if gFlash
= 2 then Inc(FPickup
, 5);
4146 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
4148 hadWeapon
:= FWeapon
[WEAPON_SAW
];
4149 switchWeapon
:= WEAPON_SAW
;
4150 FWeapon
[WEAPON_SAW
] := True;
4152 if gFlash
= 2 then Inc(FPickup
, 5);
4153 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4156 ITEM_WEAPON_SHOTGUN1
:
4157 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
4159 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
4160 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
4161 hadWeapon
:= FWeapon
[WEAPON_SHOTGUN1
];
4162 switchWeapon
:= WEAPON_SHOTGUN1
;
4163 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4164 FWeapon
[WEAPON_SHOTGUN1
] := True;
4166 if gFlash
= 2 then Inc(FPickup
, 5);
4167 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4170 ITEM_WEAPON_SHOTGUN2
:
4171 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
4173 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
4174 hadWeapon
:= FWeapon
[WEAPON_SHOTGUN2
];
4175 switchWeapon
:= WEAPON_SHOTGUN2
;
4176 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4177 FWeapon
[WEAPON_SHOTGUN2
] := True;
4179 if gFlash
= 2 then Inc(FPickup
, 5);
4180 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4183 ITEM_WEAPON_CHAINGUN
:
4184 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
4186 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
4187 hadWeapon
:= FWeapon
[WEAPON_CHAINGUN
];
4188 switchWeapon
:= WEAPON_CHAINGUN
;
4189 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4190 FWeapon
[WEAPON_CHAINGUN
] := True;
4192 if gFlash
= 2 then Inc(FPickup
, 5);
4193 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4196 ITEM_WEAPON_ROCKETLAUNCHER
:
4197 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
4199 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
4200 switchWeapon
:= WEAPON_ROCKETLAUNCHER
;
4201 hadWeapon
:= FWeapon
[WEAPON_ROCKETLAUNCHER
];
4202 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
4203 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
4205 if gFlash
= 2 then Inc(FPickup
, 5);
4206 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4210 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
4212 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
4213 switchWeapon
:= WEAPON_PLASMA
;
4214 hadWeapon
:= FWeapon
[WEAPON_PLASMA
];
4215 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4216 FWeapon
[WEAPON_PLASMA
] := True;
4218 if gFlash
= 2 then Inc(FPickup
, 5);
4219 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4223 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
4225 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
4226 switchWeapon
:= WEAPON_BFG
;
4227 hadWeapon
:= FWeapon
[WEAPON_BFG
];
4228 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4229 FWeapon
[WEAPON_BFG
] := True;
4231 if gFlash
= 2 then Inc(FPickup
, 5);
4232 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4235 ITEM_WEAPON_SUPERPULEMET
:
4236 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
4238 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
4239 switchWeapon
:= WEAPON_SUPERPULEMET
;
4240 hadWeapon
:= FWeapon
[WEAPON_SUPERPULEMET
];
4241 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4242 FWeapon
[WEAPON_SUPERPULEMET
] := True;
4244 if gFlash
= 2 then Inc(FPickup
, 5);
4245 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4248 ITEM_WEAPON_FLAMETHROWER
:
4249 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
4251 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
4252 switchWeapon
:= WEAPON_FLAMETHROWER
;
4253 hadWeapon
:= FWeapon
[WEAPON_FLAMETHROWER
];
4254 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4255 FWeapon
[WEAPON_FLAMETHROWER
] := True;
4257 if gFlash
= 2 then Inc(FPickup
, 5);
4258 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4262 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4264 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4267 if gFlash
= 2 then Inc(FPickup
, 5);
4270 ITEM_AMMO_BULLETS_BOX
:
4271 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4273 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4276 if gFlash
= 2 then Inc(FPickup
, 5);
4280 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4282 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4285 if gFlash
= 2 then Inc(FPickup
, 5);
4288 ITEM_AMMO_SHELLS_BOX
:
4289 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4291 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
4294 if gFlash
= 2 then Inc(FPickup
, 5);
4298 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4300 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4303 if gFlash
= 2 then Inc(FPickup
, 5);
4306 ITEM_AMMO_ROCKET_BOX
:
4307 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4309 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
4312 if gFlash
= 2 then Inc(FPickup
, 5);
4316 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4318 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4321 if gFlash
= 2 then Inc(FPickup
, 5);
4325 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4327 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4330 if gFlash
= 2 then Inc(FPickup
, 5);
4334 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4336 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4339 if gFlash
= 2 then Inc(FPickup
, 5);
4343 if not(R_ITEM_BACKPACK
in FRulez
) or
4344 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4345 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4346 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4347 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4348 (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) then
4350 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4351 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4352 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4353 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4354 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4356 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4357 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4358 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4359 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4360 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4361 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4362 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4363 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4364 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4365 IncMax(FAmmo
[A_FUEL
], 50, FMaxAmmo
[A_FUEL
]);
4367 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
4370 if gFlash
= 2 then Inc(FPickup
, 5);
4374 if not(R_KEY_RED
in FRulez
) then
4376 Include(FRulez
, R_KEY_RED
);
4378 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4379 if gFlash
= 2 then Inc(FPickup
, 5);
4380 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4384 if not(R_KEY_GREEN
in FRulez
) then
4386 Include(FRulez
, R_KEY_GREEN
);
4388 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4389 if gFlash
= 2 then Inc(FPickup
, 5);
4390 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4394 if not(R_KEY_BLUE
in FRulez
) then
4396 Include(FRulez
, R_KEY_BLUE
);
4398 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4399 if gFlash
= 2 then Inc(FPickup
, 5);
4400 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4404 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4406 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4410 if gFlash
= 2 then Inc(FPickup
, 5);
4414 if FAir
< AIR_MAX
then
4419 if gFlash
= 2 then Inc(FPickup
, 5);
4424 if not (R_BERSERK
in FRulez
) then
4426 Include(FRulez
, R_BERSERK
);
4427 if (FBFGFireCounter
= -1) then
4429 FCurrWeap
:= WEAPON_KASTET
;
4431 FModel
.SetWeapon(WEAPON_KASTET
);
4436 if gFlash
= 2 then Inc(FPickup
, 5);
4438 FBerserk
:= gTime
+30000;
4443 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
4445 if FHealth
< PLAYER_HP_SOFT
then FHealth
:= PLAYER_HP_SOFT
;
4446 FBerserk
:= gTime
+30000;
4454 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4456 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4460 if gFlash
= 2 then Inc(FPickup
, 5);
4464 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
4466 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4470 if gFlash
= 2 then Inc(FPickup
, 5);
4474 if FArmor
< PLAYER_AP_LIMIT
then
4476 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4479 if gFlash
= 2 then Inc(FPickup
, 5);
4483 if FJetFuel
< JET_MAX
then
4485 FJetFuel
:= JET_MAX
;
4488 if gFlash
= 2 then Inc(FPickup
, 5);
4492 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4494 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4497 if gFlash
= 2 then Inc(FPickup
, 5);
4501 if (shouldSwitch(switchWeapon
, hadWeapon
)) then
4502 QueueWeaponSwitch(switchWeapon
);
4505 procedure TPlayer
.Touch();
4509 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4512 // Áðîñèòü ôëàã òîâàðèùó:
4513 if gGameSettings
.GameMode
= GM_CTF
then
4518 procedure TPlayer
.Push(vx
, vy
: Integer);
4520 if (not FPhysics
) and FGhost
then
4522 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4523 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4524 if g_Game_IsNet
and g_Game_IsServer
then
4525 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4528 procedure TPlayer
.Reset(Force
: Boolean);
4534 FTime
[T_RESPAWN
] := 0;
4535 FTime
[T_FLAGCAP
] := 0;
4552 FSpectator
:= False;
4555 FSpectatePlayer
:= -1;
4556 FNoRespawn
:= False;
4558 FLives
:= gGameSettings
.MaxLives
;
4563 procedure TPlayer
.SoftReset();
4571 FBFGFireCounter
:= -1;
4579 SetAction(A_STAND
, True);
4582 function TPlayer
.GetRespawnPoint(): Byte;
4587 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4589 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4590 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4592 if Self
= gPlayer1
then
4594 // player 1 should try to spawn on the player 1 point
4595 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) > 0 then
4596 Exit(RESPAWNPOINT_PLAYER1
)
4597 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) > 0 then
4598 Exit(RESPAWNPOINT_PLAYER2
);
4600 else if Self
= gPlayer2
then
4602 // player 2 should try to spawn on the player 2 point
4603 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) > 0 then
4604 Exit(RESPAWNPOINT_PLAYER2
)
4605 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) > 0 then
4606 Exit(RESPAWNPOINT_PLAYER1
);
4610 // other players randomly pick either the first or the second point
4611 c
:= IfThen((Random(2) = 0), RESPAWNPOINT_PLAYER1
, RESPAWNPOINT_PLAYER2
);
4612 if g_Map_GetPointCount(c
) > 0 then
4614 // try the other one
4615 c
:= IfThen((c
= RESPAWNPOINT_PLAYER1
), RESPAWNPOINT_PLAYER2
, RESPAWNPOINT_PLAYER1
);
4616 if g_Map_GetPointCount(c
) > 0 then
4622 if gGameSettings
.GameMode
= GM_DM
then
4624 // try DM points first
4625 if g_Map_GetPointCount(RESPAWNPOINT_DM
) > 0 then
4626 Exit(RESPAWNPOINT_DM
);
4630 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4632 // try team points first
4633 c
:= RESPAWNPOINT_DM
;
4634 if FTeam
= TEAM_RED
then
4635 c
:= RESPAWNPOINT_RED
4636 else if FTeam
= TEAM_BLUE
then
4637 c
:= RESPAWNPOINT_BLUE
;
4638 if g_Map_GetPointCount(c
) > 0 then
4642 // still haven't found a spawnpoint, try random shit
4643 Result
:= g_Map_GetRandomPointType();
4646 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4648 RespawnPoint
: TRespawnPoint
;
4656 FBFGFireCounter
:= -1;
4663 if not g_Game_IsServer
then
4667 FWantsInGame
:= True;
4668 FJustTeleported
:= True;
4671 FTime
[T_RESPAWN
] := 0;
4675 // if server changes MaxLives we gotta be ready
4676 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4678 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4679 if FTime
[T_RESPAWN
] > gTime
then
4682 // Ïðîñðàë âñå æèçíè:
4685 if not FSpectator
then Spectate(True);
4686 FWantsInGame
:= True;
4690 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4691 begin // "Ñâîÿ èãðà"
4692 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4693 FRulez
:= FRulez
-[R_BERSERK
];
4695 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4697 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4698 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4701 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4702 c
:= GetRespawnPoint();
4707 // Âîñêðåøåíèå áåç îðóæèÿ:
4710 FHealth
:= Round(PLAYER_HP_SOFT
* (FHandicap
/ 100));
4716 for a
:= WP_FIRST
to WP_LAST
do
4718 FWeapon
[a
] := False;
4722 FWeapon
[WEAPON_PISTOL
] := True;
4723 FWeapon
[WEAPON_KASTET
] := True;
4724 FCurrWeap
:= WEAPON_PISTOL
;
4727 FModel
.SetWeapon(FCurrWeap
);
4729 for b
:= A_BULLETS
to A_HIGH
do
4732 FAmmo
[A_BULLETS
] := 50;
4734 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4735 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4736 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4737 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4738 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4740 if (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) and
4741 LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
) then
4742 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4747 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4748 if not g_Map_GetPoint(c
, RespawnPoint
) then
4750 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4754 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4755 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4756 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4757 FObj
.oldX
:= FObj
.X
; // don't interpolate after respawn
4758 FObj
.oldY
:= FObj
.Y
;
4764 FDirection
:= RespawnPoint
.Direction
;
4765 if FDirection
= TDirection
.D_LEFT
then
4770 SetAction(A_STAND
, True);
4771 FModel
.Direction
:= FDirection
;
4773 for a
:= Low(FTime
) to High(FTime
) do
4776 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4779 // Respawn invulnerability
4780 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.SpawnInvul
> 0) then
4782 FMegaRulez
[MR_INVUL
] := gTime
+ gGameSettings
.SpawnInvul
* 1000;
4783 FSpawnInvul
:= FMegaRulez
[MR_INVUL
];
4788 FCanJetpack
:= False;
4794 // Àíèìàöèÿ âîçðîæäåíèÿ:
4795 if (not gLoadGameMode
) and (not Silent
) then
4796 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4798 Anim
:= TAnimation
.Create(ID
, False, 3);
4799 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4800 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4804 FSpectator
:= False;
4807 FSpectatePlayer
:= -1;
4810 if (gPlayer1
= nil) and (gSpectLatchPID1
= FUID
) then
4812 if (gPlayer2
= nil) and (gSpectLatchPID2
= FUID
) then
4815 if g_Game_IsNet
then
4817 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4818 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4820 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4821 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4826 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4829 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4830 else if (not NoMove
) then
4832 GameX
:= gMapInfo
.Width
div 2;
4833 GameY
:= gMapInfo
.Height
div 2;
4842 FWantsInGame
:= False;
4848 if Self
= gPlayer1
then
4850 gSpectLatchPID1
:= FUID
;
4853 else if Self
= gPlayer2
then
4855 gSpectLatchPID2
:= FUID
;
4860 if g_Game_IsNet
then
4861 MH_SEND_PlayerStats(FUID
);
4864 procedure TPlayer
.SwitchNoClip
;
4868 FGhost
:= not FGhost
;
4869 FPhysics
:= not FGhost
;
4881 procedure TPlayer
.Run(Direction
: TDirection
);
4885 if MAX_RUNVEL
> 8 then
4889 if Direction
= TDirection
.D_LEFT
then
4891 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4892 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4895 if FObj
.Vel
.X
< MAX_RUNVEL
then
4896 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4898 // Âîçìîæíî, ïèíàåì êóñêè:
4899 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4901 b
:= Abs(FObj
.Vel
.X
);
4902 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4903 for a
:= 0 to High(gGibs
) do
4905 if gGibs
[a
].alive
and
4906 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4907 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4910 if FObj
.Vel
.X
< 0 then
4912 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4916 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4918 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4926 procedure TPlayer
.SeeDown();
4928 SetAction(A_SEEDOWN
);
4930 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4932 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4935 procedure TPlayer
.SeeUp();
4939 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4941 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4944 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4952 A_ATTACK
: Prior
:= 2;
4953 A_SEEUP
: Prior
:= 1;
4954 A_SEEDOWN
: Prior
:= 1;
4955 A_ATTACKUP
: Prior
:= 2;
4956 A_ATTACKDOWN
: Prior
:= 2;
4961 if (Prior
> FActionPrior
) or Force
then
4962 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4964 FActionPrior
:= Prior
;
4965 FActionAnim
:= Action
;
4966 FActionForce
:= Force
;
4967 FActionChanged
:= True;
4970 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4973 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4975 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4976 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4977 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4978 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4981 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4988 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4990 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4991 if g_Game_IsServer
and g_Game_IsNet
then
4992 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4996 FJustTeleported
:= True;
5001 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
5003 Anim
:= TAnimation
.Create(ID
, False, 3);
5006 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
5007 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
5008 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
5009 if g_Game_IsServer
and g_Game_IsNet
then
5010 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
5011 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
5015 FObj
.X
:= X
-PLAYER_RECT
.X
;
5016 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
5017 FObj
.oldX
:= FObj
.X
; // don't interpolate after respawn
5018 FObj
.oldY
:= FObj
.Y
;
5019 if FAlive
and FGhost
then
5025 if not g_Game_IsNet
then
5029 SetDirection(TDirection
.D_LEFT
);
5035 SetDirection(TDirection
.D_RIGHT
);
5041 if FDirection
= TDirection
.D_RIGHT
then
5043 SetDirection(TDirection
.D_LEFT
);
5048 SetDirection(TDirection
.D_RIGHT
);
5054 if not silent
and (Anim
<> nil) then
5056 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
5057 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
5060 if g_Game_IsServer
and g_Game_IsNet
then
5061 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
5062 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
5069 function nonz(a
: Single): Single;
5077 function TPlayer
.refreshCorpse(): Boolean;
5083 if FAlive
or FSpectator
then
5085 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
5087 for i
:= 0 to High(gCorpses
) do
5088 if gCorpses
[i
] <> nil then
5089 if gCorpses
[i
].FPlayerUID
= FUID
then
5097 function TPlayer
.getCameraObj(): TObj
;
5099 if (not FAlive
) and (not FSpectator
) and
5100 (FCorpse
>= 0) and (FCorpse
< Length(gCorpses
)) and
5101 (gCorpses
[FCorpse
] <> nil) and (gCorpses
[FCorpse
].FPlayerUID
= FUID
) then
5103 gCorpses
[FCorpse
].FObj
.slopeUpLeft
:= FObj
.slopeUpLeft
;
5104 Result
:= gCorpses
[FCorpse
].FObj
;
5112 procedure TPlayer
.PreUpdate();
5114 FSlopeOld
:= FObj
.slopeUpLeft
;
5115 FIncCamOld
:= FIncCam
;
5116 FObj
.oldX
:= FObj
.X
;
5117 FObj
.oldY
:= FObj
.Y
;
5120 procedure TPlayer
.Update();
5123 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
5124 blockmon
, headwater
, dospawn
: Boolean;
5129 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
5130 AnyServer
:= g_Game_IsServer
;
5132 if g_Game_IsClient
and (NetInterpLevel
> 0) then
5133 DoLerp(NetInterpLevel
+ 1)
5139 if (FClientID
>= 0) and (NetClients
[FClientID
].Peer
<> nil) then
5141 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
5142 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
5143 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
5152 if FAlive
and (FPunchAnim
<> nil) then
5153 FPunchAnim
.Update();
5155 if FAlive
and (gFly
or FJetpack
) then
5158 if FDirection
= TDirection
.D_LEFT
then
5163 if FAlive
and (not FGhost
) then
5165 if FKeys
[KEY_UP
].Pressed
then
5167 if FKeys
[KEY_DOWN
].Pressed
then
5171 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
5174 i
:= g_basic
.Sign(FIncCam
);
5175 FIncCam
:= Abs(FIncCam
);
5176 DecMin(FIncCam
, 5, 0);
5177 FIncCam
:= FIncCam
*i
;
5180 if gTime
mod (GAME_TICK
*2) <> 0 then
5182 if (FObj
.Vel
.X
= 0) and FAlive
then
5184 if FKeys
[KEY_LEFT
].Pressed
then
5185 Run(TDirection
.D_LEFT
);
5186 if FKeys
[KEY_RIGHT
].Pressed
then
5187 Run(TDirection
.D_RIGHT
);
5192 g_Obj_Move(@FObj
, True, True, True);
5193 positionChanged(); // this updates spatial accelerators
5199 FActionChanged
:= False;
5203 // Let alive player do some actions
5204 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
5205 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
5206 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire()
5212 if NetServer
then MH_SEND_PlayerStats(FUID
);
5215 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
5216 if FKeys
[KEY_JUMP
].Pressed
then Jump()
5219 if AnyServer
and FJetpack
then
5223 if NetServer
then MH_SEND_PlayerStats(FUID
);
5225 FCanJetpack
:= True;
5232 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
5234 if FKeys
[k
].Pressed
then
5242 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5245 if (FTime
[T_RESPAWN
] <= gTime
) and
5246 gGameOn
and (not FAlive
) then
5248 if (g_Player_GetCount() > 1) then
5252 gExit
:= EXIT_RESTART
;
5257 // Dead spectator actions
5260 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
5261 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
5265 if (FSpectatePlayer
>= High(gPlayers
)) then
5266 FSpectatePlayer
:= -1
5270 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
5271 if gPlayers
[I
] <> nil then
5272 if gPlayers
[I
].alive
then
5273 if gPlayers
[I
].UID
<> FUID
then
5275 FSpectatePlayer
:= I
;
5280 if not SetSpect
then FSpectatePlayer
:= -1;
5291 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5293 FYTo
:= FObj
.Y
- 32;
5294 FSpectatePlayer
:= -1;
5296 if FKeys
[KEY_DOWN
].Pressed
then
5298 FYTo
:= FObj
.Y
+ 32;
5299 FSpectatePlayer
:= -1;
5301 if FKeys
[KEY_LEFT
].Pressed
then
5303 FXTo
:= FObj
.X
- 32;
5304 FSpectatePlayer
:= -1;
5306 if FKeys
[KEY_RIGHT
].Pressed
then
5308 FXTo
:= FObj
.X
+ 32;
5309 FSpectatePlayer
:= -1;
5312 if (FXTo
< -64) then
5314 else if (FXTo
> gMapInfo
.Width
+ 32) then
5315 FXTo
:= gMapInfo
.Width
+ 32;
5316 if (FYTo
< -72) then
5318 else if (FYTo
> gMapInfo
.Height
+ 32) then
5319 FYTo
:= gMapInfo
.Height
+ 32;
5324 g_Obj_Move(@FObj
, True, True, True);
5325 positionChanged(); // this updates spatial accelerators
5332 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5333 if gPlayers
[FSpectatePlayer
] <> nil then
5334 if gPlayers
[FSpectatePlayer
].alive
then
5336 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
5337 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
5341 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5342 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5343 PANEL_BLOCKMON
, True);
5344 headwater
:= HeadInLiquid(0, 0);
5346 // Ñîïðîòèâëåíèå âîçäóõà:
5347 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5348 if FObj
.Vel
.X
<> 0 then
5349 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5351 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5352 DecMin(FPain
, 5, 0);
5353 DecMin(FPickup
, 1, 0);
5355 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5357 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5358 FMegaRulez
[MR_SUIT
] := 0;
5359 FMegaRulez
[MR_INVUL
] := 0;
5360 FMegaRulez
[MR_INVIS
] := 0;
5361 Kill(K_FALLKILL
, 0, HIT_FALL
);
5368 if FCurrWeap
= WEAPON_SAW
then
5369 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5370 FSawSoundSelect
.IsPlaying()) then
5371 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5374 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5375 (not FJetSoundOff
.IsPlaying()) then
5377 FJetSoundFly
.SetPosition(0);
5378 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5381 for b
:= WP_FIRST
to WP_LAST
do
5382 if FReloading
[b
] > 0 then
5388 if FShellTimer
> -1 then
5389 if FShellTimer
= 0 then
5391 if FShellType
= SHELL_SHELL
then
5392 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5393 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5394 else if FShellType
= SHELL_DBLSHELL
then
5396 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5397 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5398 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5399 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5402 end else Dec(FShellTimer
);
5404 if (FBFGFireCounter
> -1) then
5405 if FBFGFireCounter
= 0 then
5409 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5410 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5411 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5412 yd
:= wy
+firediry();
5413 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5414 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5415 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5416 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5417 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5420 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5421 FBFGFireCounter
:= -1;
5424 FBFGFireCounter
:= 0
5426 Dec(FBFGFireCounter
);
5428 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5430 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5432 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5435 if (headwater
or blockmon
) then
5441 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5444 else if (FAir
mod 31 = 0) and not blockmon
then
5445 g_Game_Effect_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
5446 FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5447 end else if FAir
< AIR_DEF
then
5450 if FFireTime
> 0 then
5452 if BodyInLiquid(0, 0) then
5457 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5459 if FMegaRulez
[MR_SUIT
] = gTime
then
5466 if FFirePainTime
<= 0 then
5468 if g_Game_IsServer
then
5469 Damage(2, FFireAttacker
, 0, 0, HIT_FLAME
);
5470 FFirePainTime
:= 12 - FFireTime
div 12;
5472 FFirePainTime
:= FFirePainTime
- 1;
5473 FFireTime
:= FFireTime
- 1;
5474 if ((FFireTime
mod 33) = 0) and (FMegaRulez
[MR_INVUL
] < gTime
) then
5475 FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
);
5476 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5477 MH_SEND_PlayerStats(FUID
);
5481 if FDamageBuffer
> 0 then
5483 if FDamageBuffer
>= 9 then
5487 if FDamageBuffer
< 30 then i
:= 9
5488 else if FDamageBuffer
< 100 then i
:= 18
5492 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5493 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5494 FHealth
:= FHealth
-ii
;
5497 FHealth
:= FHealth
+FArmor
;
5502 if FHealth
<= 0 then
5503 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5504 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5505 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5507 if FAlive
and ((FLastHit
<> HIT_FLAME
) or (FFireTime
<= 0)) then
5509 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5510 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5511 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5512 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5519 end; // if FAlive then ...
5521 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5523 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5524 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5525 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5526 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5528 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5529 then SetAction(A_STAND
, True);
5531 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5533 for b
:= Low(FKeys
) to High(FKeys
) do
5534 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5538 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5540 x
:= FObj
.X
+PLAYER_RECT
.X
;
5541 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5542 w
:= PLAYER_RECT
.Width
;
5543 h
:= PLAYER_RECT
.Height
;
5547 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5549 if (dx
<> 0) or (dy
<> 0) then
5558 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5560 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5561 FObj
.Y
+PLAYER_RECT
.Y
,
5568 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5570 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5571 FObj
.Y
+PLAYER_RECT
.Y
,
5575 Panel
.Width
, Panel
.Height
);
5578 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5580 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5581 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5582 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5583 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5586 function g_Player_ExistingName(Name
: string): Boolean;
5592 if gPlayers
= nil then Exit
;
5594 for a
:= 0 to High(gPlayers
) do
5595 if gPlayers
[a
] <> nil then
5596 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5603 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5607 d
:= FModel
.Direction
;
5609 FModel
.Direction
:= Direction
;
5610 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5612 FDirection
:= Direction
;
5615 function TPlayer
.GetKeys(): Byte;
5619 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5620 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5621 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5623 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5624 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5627 procedure TPlayer
.Use();
5631 if FTime
[T_USE
] > gTime
then Exit
;
5633 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5634 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5636 for a
:= 0 to High(gPlayers
) do
5637 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5638 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5639 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5640 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5642 gPlayers
[a
].Touch();
5643 if g_Game_IsNet
and g_Game_IsServer
then
5644 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5647 FTime
[T_USE
] := gTime
+120;
5650 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5653 visible
: Boolean = True;
5654 WX
, WY
, XD
, YD
: Integer;
5666 if R_BERSERK
in FRulez
then
5668 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5669 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5670 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5673 locobj
.rect
.Width
:= 39;
5674 locobj
.rect
.Height
:= 52;
5675 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5676 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5677 locobj
.Accel
.X
:= xd
-wx
;
5678 locobj
.Accel
.y
:= yd
-wy
;
5680 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5681 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5683 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5687 FPain
:= min(FPain
+ 25, 50);
5689 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5694 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5695 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5697 FSawSoundSelect
.Stop();
5699 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5701 else if not FSawSoundHit
.IsPlaying() then
5703 FSawSoundSelect
.Stop();
5704 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5710 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5711 FFireAngle
:= FAngle
;
5712 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5713 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5718 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5719 FFireAngle
:= FAngle
;
5721 FShellType
:= SHELL_SHELL
;
5726 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5727 FFireAngle
:= FAngle
;
5729 FShellType
:= SHELL_DBLSHELL
;
5734 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5735 FFireAngle
:= FAngle
;
5736 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5737 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5740 WEAPON_ROCKETLAUNCHER
:
5742 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5743 FFireAngle
:= FAngle
;
5748 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5749 FFireAngle
:= FAngle
;
5754 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5755 FFireAngle
:= FAngle
;
5758 WEAPON_SUPERPULEMET
:
5760 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5761 FFireAngle
:= FAngle
;
5762 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5763 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5766 WEAPON_FLAMETHROWER
:
5768 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5770 FFireAngle
:= FAngle
;
5774 if not visible
then Exit
;
5776 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5777 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5778 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5781 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5783 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5784 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5787 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5793 if FJustTeleported
or (NetInterpLevel
< 1) then
5797 if FJustTeleported
then
5799 FObj
.oldX
:= FObj
.X
;
5800 FObj
.oldY
:= FObj
.Y
;
5805 AX
:= Abs(FXTo
- FObj
.X
);
5806 AY
:= Abs(FYTo
- FObj
.Y
);
5807 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5809 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5814 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5816 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5817 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5818 PANEL_LIFTUP
, False) then Result
:= -1
5820 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5821 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5822 PANEL_LIFTDOWN
, False) then Result
:= 1
5826 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5833 if Flag
= FLAG_NONE
then
5836 if not g_Game_IsServer
then Exit
;
5838 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5839 if (Flag
= FTeam
) and
5840 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5841 (FFlag
<> FLAG_NONE
) then
5843 if FFlag
= FLAG_RED
then
5844 s
:= _lc
[I_PLAYER_FLAG_RED
]
5846 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5848 evtype
:= FLAG_STATE_SCORED
;
5850 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5851 Insert('.', ts
, Length(ts
) + 1 - 3);
5852 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5854 g_Map_ResetFlag(FFlag
);
5855 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5857 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5858 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5859 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5864 if not sound_cap_flag
[a
].IsPlaying() then
5865 sound_cap_flag
[a
].Play();
5867 gTeamStat
[FTeam
].Score
+= 1;
5870 if g_Game_IsNet
then
5872 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5876 gFlags
[FFlag
].CaptureTime
:= 0;
5881 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5882 if (Flag
= FTeam
) and
5883 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5885 if Flag
= FLAG_RED
then
5886 s
:= _lc
[I_PLAYER_FLAG_RED
]
5888 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5890 evtype
:= FLAG_STATE_RETURNED
;
5891 gFlags
[Flag
].CaptureTime
:= 0;
5893 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5895 g_Map_ResetFlag(Flag
);
5896 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5898 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5899 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5900 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5905 if not sound_ret_flag
[a
].IsPlaying() then
5906 sound_ret_flag
[a
].Play();
5909 if g_Game_IsNet
then
5911 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5917 // Ïîäîáðàë ÷óæîé ôëàã:
5918 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5922 if Flag
= FLAG_RED
then
5923 s
:= _lc
[I_PLAYER_FLAG_RED
]
5925 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5927 evtype
:= FLAG_STATE_CAPTURED
;
5929 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5931 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5933 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5935 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5936 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5937 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5942 if not sound_get_flag
[a
].IsPlaying() then
5943 sound_get_flag
[a
].Play();
5946 if g_Game_IsNet
then
5948 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5954 procedure TPlayer
.SetFlag(Flag
: Byte);
5957 if FModel
<> nil then
5958 FModel
.SetFlag(FFlag
);
5961 function TPlayer
.TryDropFlag(): Boolean;
5963 if LongBool(gGameSettings
.Options
and GAME_OPTION_ALLOWDROPFLAG
) then
5964 Result
:= DropFlag(False, LongBool(gGameSettings
.Options
and GAME_OPTION_THROWFLAG
))
5969 function TPlayer
.DropFlag(Silent
: Boolean = True; DoThrow
: Boolean = False): Boolean;
5976 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5978 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5979 with gFlags
[FFlag
] do
5983 Direction
:= FDirection
;
5984 State
:= FLAG_STATE_DROPPED
;
5988 xv
:= FObj
.Vel
.X
+ IfThen(Direction
= TDirection
.D_RIGHT
, 10, -10);
5989 yv
:= FObj
.Vel
.Y
- 2;
5993 xv
:= (FObj
.Vel
.X
div 2);
5994 yv
:= (FObj
.Vel
.Y
div 2) - 2;
5996 g_Obj_Push(@Obj
, xv
, yv
);
5998 positionChanged(); // this updates spatial accelerators
6000 if FFlag
= FLAG_RED
then
6001 s
:= _lc
[I_PLAYER_FLAG_RED
]
6003 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
6005 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
6006 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
6008 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
6009 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
6010 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
6015 if (not Silent
) and (not sound_lost_flag
[a
].IsPlaying()) then
6016 sound_lost_flag
[a
].Play();
6018 if g_Game_IsNet
then
6019 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
6025 procedure TPlayer
.GetSecret();
6027 if (self
= gPlayer1
) or (self
= gPlayer2
) then
6029 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [FName
]), True);
6030 g_Sound_PlayEx('SOUND_GAME_SECRET');
6035 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
6037 Assert(Key
<= High(FKeys
));
6039 FKeys
[Key
].Pressed
:= True;
6040 FKeys
[Key
].Time
:= Time
;
6043 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
6045 Result
:= FKeys
[K
].Pressed
;
6048 procedure TPlayer
.ReleaseKeys();
6052 for a
:= Low(FKeys
) to High(FKeys
) do
6054 FKeys
[a
].Pressed
:= False;
6059 procedure TPlayer
.OnDamage(Angle
: SmallInt);
6063 function TPlayer
.firediry(): Integer;
6065 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
6066 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
6070 procedure TPlayer
.RememberState();
6073 SavedState
: TPlayerSavedState
;
6075 SavedState
.Health
:= FHealth
;
6076 SavedState
.Armor
:= FArmor
;
6077 SavedState
.Air
:= FAir
;
6078 SavedState
.JetFuel
:= FJetFuel
;
6079 SavedState
.CurrWeap
:= FCurrWeap
;
6080 SavedState
.NextWeap
:= FNextWeap
;
6081 SavedState
.NextWeapDelay
:= FNextWeapDelay
;
6082 for i
:= Low(FWeapon
) to High(FWeapon
) do
6083 SavedState
.Weapon
[i
] := FWeapon
[i
];
6084 for i
:= Low(FAmmo
) to High(FAmmo
) do
6085 SavedState
.Ammo
[i
] := FAmmo
[i
];
6086 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
6087 SavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
6088 SavedState
.Rulez
:= FRulez
- [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6090 FSavedStateNum
:= -1;
6091 for i
:= Low(SavedStates
) to High(SavedStates
) do
6092 if not SavedStates
[i
].Used
then
6094 FSavedStateNum
:= i
;
6097 if FSavedStateNum
< 0 then
6099 SetLength(SavedStates
, Length(SavedStates
) + 1);
6100 FSavedStateNum
:= High(SavedStates
);
6103 SavedState
.Used
:= True;
6104 SavedStates
[FSavedStateNum
] := SavedState
;
6107 procedure TPlayer
.RecallState();
6110 SavedState
: TPlayerSavedState
;
6112 if(FSavedStateNum
< 0) or (FSavedStateNum
> High(SavedStates
)) then
6115 SavedState
:= SavedStates
[FSavedStateNum
];
6116 SavedStates
[FSavedStateNum
].Used
:= False;
6117 FSavedStateNum
:= -1;
6119 FHealth
:= SavedState
.Health
;
6120 FArmor
:= SavedState
.Armor
;
6121 FAir
:= SavedState
.Air
;
6122 FJetFuel
:= SavedState
.JetFuel
;
6123 FCurrWeap
:= SavedState
.CurrWeap
;
6124 FNextWeap
:= SavedState
.NextWeap
;
6125 FNextWeapDelay
:= SavedState
.NextWeapDelay
;
6126 for i
:= Low(FWeapon
) to High(FWeapon
) do
6127 FWeapon
[i
] := SavedState
.Weapon
[i
];
6128 for i
:= Low(FAmmo
) to High(FAmmo
) do
6129 FAmmo
[i
] := SavedState
.Ammo
[i
];
6130 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
6131 FMaxAmmo
[i
] := SavedState
.MaxAmmo
[i
];
6132 FRulez
:= SavedState
.Rulez
;
6134 if gGameSettings
.GameType
= GT_SERVER
then
6135 MH_SEND_PlayerStats(FUID
);
6138 procedure TPlayer
.SaveState (st
: TStream
);
6144 utils
.writeSign(st
, 'PLYR');
6145 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
6147 utils
.writeBool(st
, FIamBot
);
6149 utils
.writeInt(st
, Word(FUID
));
6151 utils
.writeStr(st
, FName
);
6153 utils
.writeInt(st
, Byte(FTeam
));
6155 utils
.writeBool(st
, FAlive
);
6156 // Èçðàñõîäîâàë ëè âñå æèçíè
6157 utils
.writeBool(st
, FNoRespawn
);
6159 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
6160 utils
.writeInt(st
, Byte(b
));
6162 utils
.writeInt(st
, LongInt(FHealth
));
6163 // Êîýôôèöèåíò èíâàëèäíîñòè
6164 utils
.writeInt(st
, LongInt(FHandicap
));
6166 utils
.writeInt(st
, Byte(FLives
));
6168 utils
.writeInt(st
, LongInt(FArmor
));
6170 utils
.writeInt(st
, LongInt(FAir
));
6172 utils
.writeInt(st
, LongInt(FJetFuel
));
6174 utils
.writeInt(st
, LongInt(FPain
));
6176 utils
.writeInt(st
, LongInt(FKills
));
6178 utils
.writeInt(st
, LongInt(FMonsterKills
));
6180 utils
.writeInt(st
, LongInt(FFrags
));
6182 utils
.writeInt(st
, LongInt(FAssists
));
6184 utils
.writeInt(st
, Byte(FFragCombo
));
6185 // Âðåìÿ ïîñëåäíåãî ôðàãà
6186 utils
.writeInt(st
, LongWord(FLastFrag
));
6188 utils
.writeInt(st
, LongInt(FDeath
));
6190 utils
.writeInt(st
, Byte(FFlag
));
6192 utils
.writeInt(st
, LongInt(FSecrets
));
6194 utils
.writeInt(st
, Byte(FCurrWeap
));
6196 utils
.writeInt(st
, Word(FNextWeap
));
6198 utils
.writeInt(st
, Byte(FNextWeapDelay
));
6199 // Âðåìÿ çàðÿäêè BFG
6200 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
6202 utils
.writeInt(st
, LongInt(FDamageBuffer
));
6203 // Ïîñëåäíèé óäàðèâøèé
6204 utils
.writeInt(st
, Word(FLastSpawnerUID
));
6205 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6206 utils
.writeInt(st
, Byte(FLastHit
));
6208 Obj_SaveState(st
, @FObj
);
6209 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6210 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
6211 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6212 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
6214 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
6215 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6216 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
6218 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
6219 // Íàëè÷èå êðàñíîãî êëþ÷à
6220 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
6221 // Íàëè÷èå çåëåíîãî êëþ÷à
6222 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
6223 // Íàëè÷èå ñèíåãî êëþ÷à
6224 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
6226 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
6227 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6228 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
6229 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6230 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
6232 utils
.writeStr(st
, FModel
.Name
);
6234 utils
.writeInt(st
, Byte(FColor
.R
));
6235 utils
.writeInt(st
, Byte(FColor
.G
));
6236 utils
.writeInt(st
, Byte(FColor
.B
));
6240 procedure TPlayer
.LoadState (st
: TStream
);
6249 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
6250 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
6252 FIamBot
:= utils
.readBool(st
);
6254 FUID
:= utils
.readWord(st
);
6256 str
:= utils
.readStr(st
);
6257 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
6259 FTeam
:= utils
.readByte(st
);
6261 FAlive
:= utils
.readBool(st
);
6262 // Èçðàñõîäîâàë ëè âñå æèçíè
6263 FNoRespawn
:= utils
.readBool(st
);
6265 b
:= utils
.readByte(st
);
6266 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
6268 FHealth
:= utils
.readLongInt(st
);
6269 // Êîýôôèöèåíò èíâàëèäíîñòè
6270 FHandicap
:= utils
.readLongInt(st
);
6272 FLives
:= utils
.readByte(st
);
6274 FArmor
:= utils
.readLongInt(st
);
6276 FAir
:= utils
.readLongInt(st
);
6278 FJetFuel
:= utils
.readLongInt(st
);
6280 FPain
:= utils
.readLongInt(st
);
6282 FKills
:= utils
.readLongInt(st
);
6284 FMonsterKills
:= utils
.readLongInt(st
);
6286 FFrags
:= utils
.readLongInt(st
);
6288 FAssists
:= utils
.readLongInt(st
);
6290 FFragCombo
:= utils
.readByte(st
);
6291 // Âðåìÿ ïîñëåäíåãî ôðàãà
6292 FLastFrag
:= utils
.readLongWord(st
);
6294 FDeath
:= utils
.readLongInt(st
);
6296 FFlag
:= utils
.readByte(st
);
6298 FSecrets
:= utils
.readLongInt(st
);
6300 FCurrWeap
:= utils
.readByte(st
);
6302 FNextWeap
:= utils
.readWord(st
);
6304 FNextWeapDelay
:= utils
.readByte(st
);
6305 // Âðåìÿ çàðÿäêè BFG
6306 FBFGFireCounter
:= utils
.readSmallInt(st
);
6308 FDamageBuffer
:= utils
.readLongInt(st
);
6309 // Ïîñëåäíèé óäàðèâøèé
6310 FLastSpawnerUID
:= utils
.readWord(st
);
6311 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6312 FLastHit
:= utils
.readByte(st
);
6314 Obj_LoadState(@FObj
, st
);
6315 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6316 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
6317 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6318 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
6320 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
6321 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6322 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
6324 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
6325 // Íàëè÷èå êðàñíîãî êëþ÷à
6326 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
6327 // Íàëè÷èå çåëåíîãî êëþ÷à
6328 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
6329 // Íàëè÷èå ñèíåãî êëþ÷à
6330 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
6332 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
6333 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6334 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
6335 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6336 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
6338 str
:= utils
.readStr(st
);
6340 FColor
.R
:= utils
.readByte(st
);
6341 FColor
.G
:= utils
.readByte(st
);
6342 FColor
.B
:= utils
.readByte(st
);
6343 if (self
= gPlayer1
) then
6345 str
:= gPlayer1Settings
.Model
;
6346 FColor
:= gPlayer1Settings
.Color
;
6348 else if (self
= gPlayer2
) then
6350 str
:= gPlayer2Settings
.Model
;
6351 FColor
:= gPlayer2Settings
.Color
;
6353 // Îáíîâëÿåì ìîäåëü èãðîêà
6355 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
6356 FModel
.Color
:= TEAMCOLOR
[FTeam
]
6358 FModel
.Color
:= FColor
;
6362 procedure TPlayer
.AllRulez(Health
: Boolean);
6368 FHealth
:= PLAYER_HP_LIMIT
;
6369 FArmor
:= PLAYER_AP_LIMIT
;
6373 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
6374 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
6375 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6378 procedure TPlayer
.RestoreHealthArmor();
6380 FHealth
:= PLAYER_HP_LIMIT
;
6381 FArmor
:= PLAYER_AP_LIMIT
;
6384 procedure TPlayer
.FragCombo();
6388 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6390 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6392 if FFragCombo
< 5 then
6394 Param
:= FUID
or (FFragCombo
shl 16);
6395 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6396 (FComboEvnt
<= High(gDelayedEvents
)) and
6397 gDelayedEvents
[FComboEvnt
].Pending
and
6398 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6399 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6401 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6402 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6405 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6413 procedure TPlayer
.GiveItem(ItemType
: Byte);
6417 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6419 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6423 if FAir
< AIR_MAX
then
6430 if not (R_BERSERK
in FRulez
) then
6432 Include(FRulez
, R_BERSERK
);
6433 if FBFGFireCounter
< 1 then
6435 FCurrWeap
:= WEAPON_KASTET
;
6437 FModel
.SetWeapon(WEAPON_KASTET
);
6441 FBerserk
:= gTime
+30000;
6443 if FHealth
< PLAYER_HP_SOFT
then
6445 FHealth
:= PLAYER_HP_SOFT
;
6446 FBerserk
:= gTime
+30000;
6451 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6453 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6458 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6460 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6464 if FJetFuel
< JET_MAX
then
6466 FJetFuel
:= JET_MAX
;
6469 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6470 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6472 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6473 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6475 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6477 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6479 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6480 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6483 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6484 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6485 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6486 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6487 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6488 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6489 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6490 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6491 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6493 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6494 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6495 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6496 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6497 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6498 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6499 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6500 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6501 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6504 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6505 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6506 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6507 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6508 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6510 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6511 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6512 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6513 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6514 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6516 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6517 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6518 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6519 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6521 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6524 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6525 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6526 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6528 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6529 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6534 if g_Game_IsNet
and g_Game_IsServer
then
6535 MH_SEND_PlayerStats(FUID
);
6538 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6543 if (Random(5) = 1) and (Times
= 1) then
6546 if BodyInLiquid(0, 0) then
6548 g_Game_Effect_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6549 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6553 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6555 for i
:= 1 to Times
do
6557 Anim
:= TAnimation
.Create(id
, False, 3);
6559 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6560 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6566 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6571 if (Random(10) = 1) and (Times
= 1) then
6574 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6576 for i
:= 1 to Times
do
6578 Anim
:= TAnimation
.Create(id
, False, 3);
6580 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6581 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6587 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6589 FSawSound
.Pause(Enable
);
6590 FSawSoundIdle
.Pause(Enable
);
6591 FSawSoundHit
.Pause(Enable
);
6592 FSawSoundSelect
.Pause(Enable
);
6593 FFlameSoundOn
.Pause(Enable
);
6594 FFlameSoundOff
.Pause(Enable
);
6595 FFlameSoundWork
.Pause(Enable
);
6596 FJetSoundFly
.Pause(Enable
);
6597 FJetSoundOn
.Pause(Enable
);
6598 FJetSoundOff
.Pause(Enable
);
6603 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6608 FObj
.Rect
:= PLAYER_CORPSERECT
;
6609 FModelName
:= ModelName
;
6614 FState
:= CORPSE_STATE_MESS
;
6615 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6619 FState
:= CORPSE_STATE_NORMAL
;
6620 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6624 destructor TCorpse
.Destroy();
6631 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6633 procedure TCorpse
.positionChanged (); inline; begin end;
6635 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6637 if (dx
<> 0) or (dy
<> 0) then
6646 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6648 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6649 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6650 w
:= PLAYER_CORPSERECT
.Width
;
6651 h
:= PLAYER_CORPSERECT
.Height
;
6655 procedure TCorpse
.Damage(Value
: Word; SpawnerUID
: Word; vx
, vy
: Integer);
6660 if FState
= CORPSE_STATE_REMOVEME
then
6663 FDamage
:= FDamage
+ Value
;
6665 if FDamage
> 150 then
6667 if FAnimation
<> nil then
6672 FState
:= CORPSE_STATE_REMOVEME
;
6674 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6675 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6676 FModelName
, FColor
);
6677 // Çâóê ìÿñà îò òðóïà:
6678 pm
:= g_PlayerModel_Get(FModelName
);
6679 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6683 if (gBodyKillEvent
<> -1)
6684 and gDelayedEvents
[gBodyKillEvent
].Pending
then
6685 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
6686 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, SpawnerUID
);
6691 Blood
:= g_PlayerModel_GetBlood(FModelName
);
6692 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6693 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6694 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6695 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6696 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6697 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
6701 procedure TCorpse
.Draw();
6705 if FState
= CORPSE_STATE_REMOVEME
then
6708 FObj
.lerp(gLerpFactor
, fX
, fY
);
6710 if FAnimation
<> nil then
6711 FAnimation
.Draw(fX
, fY
, TMirrorType
.None
);
6713 if FAnimationMask
<> nil then
6716 FAnimationMask
.Draw(fX
, fY
, TMirrorType
.None
);
6723 procedure TCorpse
.Update();
6727 if FState
= CORPSE_STATE_REMOVEME
then
6730 FObj
.oldX
:= FObj
.X
;
6731 FObj
.oldY
:= FObj
.Y
;
6733 if gTime
mod (GAME_TICK
*2) <> 0 then
6735 g_Obj_Move(@FObj
, True, True, True);
6736 positionChanged(); // this updates spatial accelerators
6740 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6741 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6743 st
:= g_Obj_Move(@FObj
, True, True, True);
6744 positionChanged(); // this updates spatial accelerators
6746 if WordBool(st
and MOVE_FALLOUT
) then
6748 FState
:= CORPSE_STATE_REMOVEME
;
6752 if FAnimation
<> nil then
6753 FAnimation
.Update();
6754 if FAnimationMask
<> nil then
6755 FAnimationMask
.Update();
6759 procedure TCorpse
.SaveState (st
: TStream
);
6766 utils
.writeSign(st
, 'CORP');
6767 utils
.writeInt(st
, Byte(0));
6769 utils
.writeInt(st
, Byte(FState
));
6771 utils
.writeInt(st
, Byte(FDamage
));
6773 utils
.writeInt(st
, Byte(FColor
.R
));
6774 utils
.writeInt(st
, Byte(FColor
.G
));
6775 utils
.writeInt(st
, Byte(FColor
.B
));
6777 Obj_SaveState(st
, @FObj
);
6778 utils
.writeInt(st
, Word(FPlayerUID
));
6780 anim
:= (FAnimation
<> nil);
6781 utils
.writeBool(st
, anim
);
6782 // Åñëè åñòü - ñîõðàíÿåì
6783 if anim
then FAnimation
.SaveState(st
);
6784 // Åñòü ëè ìàñêà àíèìàöèè
6785 anim
:= (FAnimationMask
<> nil);
6786 utils
.writeBool(st
, anim
);
6787 // Åñëè åñòü - ñîõðàíÿåì
6788 if anim
then FAnimationMask
.SaveState(st
);
6792 procedure TCorpse
.LoadState (st
: TStream
);
6799 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6800 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6802 FState
:= utils
.readByte(st
);
6804 FDamage
:= utils
.readByte(st
);
6806 FColor
.R
:= utils
.readByte(st
);
6807 FColor
.G
:= utils
.readByte(st
);
6808 FColor
.B
:= utils
.readByte(st
);
6810 Obj_LoadState(@FObj
, st
);
6811 FPlayerUID
:= utils
.readWord(st
);
6813 anim
:= utils
.readBool(st
);
6814 // Åñëè åñòü - çàãðóæàåì
6817 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6818 FAnimation
.LoadState(st
);
6820 // Åñòü ëè ìàñêà àíèìàöèè
6821 anim
:= utils
.readBool(st
);
6822 // Åñëè åñòü - çàãðóæàåì
6825 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6826 FAnimationMask
.LoadState(st
);
6832 constructor TBot
.Create();
6839 FSpectator
:= False;
6846 for a
:= WP_FIRST
to WP_LAST
do
6848 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6849 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6850 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6854 destructor TBot
.Destroy();
6857 inherited Destroy();
6860 procedure TBot
.Draw();
6864 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6865 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6868 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6870 inherited Respawn(Silent
, Force
);
6873 FSelectedWeapon
:= FCurrWeap
;
6878 procedure TBot
.UpdateCombat();
6891 TTargetRecord
= array of TTarget
;
6893 function Compare(a
, b
: TTarget
): Integer;
6895 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6898 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6900 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6901 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6903 if a
.Dist
> b
.Dist
then // B áëèæå
6905 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6908 else // Ñòðàííî -> A
6913 a
, x1
, y1
, x2
, y2
: Integer;
6914 targets
: TTargetRecord
;
6916 Target
, BestTarget
: TTarget
;
6917 firew
, fireh
: Integer;
6921 vsPlayer
, vsMonster
, ok
: Boolean;
6924 function monsUpdate (mon
: TMonster
): Boolean;
6926 result
:= false; // don't stop
6927 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6929 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6931 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6932 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6934 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6935 if g_TraceVector(x1
, y1
, x2
, y2
) then
6937 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6938 SetLength(targets
, Length(targets
)+1);
6939 with targets
[High(targets
)] do
6946 Rect
:= mon
.Obj
.Rect
;
6947 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6948 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6949 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6958 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6959 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6961 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6962 if FCurrWeap
<> FSelectedWeapon
then
6965 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6966 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6968 RemoveAIFlag('NEEDFIRE');
6971 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6972 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6973 else PressKey(KEY_FIRE
);
6977 // Êîîðäèíàòû ñòâîëà:
6978 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6979 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6981 Target
.UID
:= FTargetUID
;
6984 if Target
.UID
<> 0 then
6985 begin // Öåëü åñòü - íàñòðàèâàåì
6986 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6989 tpla
:= g_Player_Get(Target
.UID
);
6993 if (@FObj
) <> nil then
7000 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
7001 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
7002 Target
.Rect
:= PLAYER_RECT
;
7003 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
7004 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
7005 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
7006 Target
.IsPlayer
:= True;
7010 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
7013 mon
:= g_Monsters_ByUID(Target
.UID
);
7016 Target
.X
:= mon
.Obj
.X
;
7017 Target
.Y
:= mon
.Obj
.Y
;
7019 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
7020 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
7021 Target
.Rect
:= mon
.Obj
.Rect
;
7022 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
7023 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
7024 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
7025 Target
.IsPlayer
:= False;
7032 begin // Öåëè íåò - îáíóëÿåì
7037 Target
.Visible
:= False;
7038 Target
.Line
:= False;
7039 Target
.IsPlayer
:= False;
7044 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
7045 if (not Target
.Line
) or (not Target
.Visible
) then
7049 for a
:= 0 to High(gPlayers
) do
7050 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
7051 (gPlayers
[a
].FUID
<> FUID
) and
7052 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
7053 (not gPlayers
[a
].NoTarget
) and
7054 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
7056 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
7057 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
7060 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
7061 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
7063 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
7064 if g_TraceVector(x1
, y1
, x2
, y2
) then
7066 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
7067 SetLength(targets
, Length(targets
)+1);
7068 with targets
[High(targets
)] do
7070 UID
:= gPlayers
[a
].FUID
;
7071 X
:= gPlayers
[a
].FObj
.X
;
7072 Y
:= gPlayers
[a
].FObj
.Y
;
7075 Rect
:= PLAYER_RECT
;
7076 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
7077 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
7078 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
7086 if vsMonster
then g_Mons_ForEach(monsUpdate
);
7089 // Åñëè åñòü âîçìîæíûå öåëè:
7090 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
7091 if targets
<> nil then
7093 // Âûáèðàåì íàèëó÷øóþ öåëü:
7094 BestTarget
:= targets
[0];
7095 if Length(targets
) > 1 then
7096 for a
:= 1 to High(targets
) do
7097 if Compare(BestTarget
, targets
[a
]) = 1 then
7098 BestTarget
:= targets
[a
];
7100 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
7101 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
7102 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
7104 Target
:= BestTarget
;
7106 if (Healthy() = 3) or ((Healthy() = 2)) then
7107 begin // Åñëè çäîðîâû - äîãîíÿåì
7108 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
7109 SetAIFlag('GORIGHT', '1');
7110 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
7111 SetAIFlag('GOLEFT', '1');
7114 begin // Åñëè ïîáèòû - óáåãàåì
7115 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
7116 SetAIFlag('GORIGHT', '1');
7117 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
7118 SetAIFlag('GOLEFT', '1');
7121 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
7122 SelectWeapon(Abs(x1
-Target
.cX
));
7127 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
7128 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
7129 if Target
.UID
<> 0 then
7131 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
7132 Target
.Y
+ Target
.Rect
.Y
) then
7133 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
7134 if (Healthy() = 3) or ((Healthy() = 2)) then
7135 begin // Åñëè çäîðîâû - äîãîíÿåì
7136 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
7137 SetAIFlag('GORIGHT', '1');
7138 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
7139 SetAIFlag('GOLEFT', '1');
7142 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
7144 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
7145 SetAIFlag('GORIGHT', '1');
7146 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
7147 SetAIFlag('GOLEFT', '1');
7151 begin // Öåëü ïîêà íà "ýêðàíå"
7152 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
7153 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7154 FLastVisible
:= gTime
;
7155 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
7156 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
7158 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
7159 SetAIFlag('GORIGHT', '1');
7160 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
7161 SetAIFlag('GOLEFT', '1');
7165 // Âûáèðàåì óãîë ââåðõ:
7166 if FDirection
= TDirection
.D_LEFT
then
7167 angle
:= ANGLE_LEFTUP
7169 angle
:= ANGLE_RIGHTUP
;
7171 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7172 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7174 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7175 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7176 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
7177 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7178 Target
.Rect
.Width
, Target
.Rect
.Height
) and
7179 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7180 begin // òî íóæíî ñòðåëÿòü ââåðõ
7181 SetAIFlag('NEEDFIRE', '1');
7182 SetAIFlag('NEEDSEEUP', '1');
7185 // Âûáèðàåì óãîë âíèç:
7186 if FDirection
= TDirection
.D_LEFT
then
7187 angle
:= ANGLE_LEFTDOWN
7189 angle
:= ANGLE_RIGHTDOWN
;
7191 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7192 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7194 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7195 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7196 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7197 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7198 Target
.Rect
.Width
, Target
.Rect
.Height
) and
7199 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7200 begin // òî íóæíî ñòðåëÿòü âíèç
7201 SetAIFlag('NEEDFIRE', '1');
7202 SetAIFlag('NEEDSEEDOWN', '1');
7205 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
7206 if Target
.Visible
and
7207 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
7208 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
7210 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
7211 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
7212 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
7213 begin // òî íóæíî ñòðåëÿòü âïåðåä
7214 SetAIFlag('NEEDFIRE', '1');
7215 SetAIFlag('NEEDSEEDOWN', '');
7216 SetAIFlag('NEEDSEEUP', '');
7218 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
7219 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
7220 if GetRnd(FDifficult
.CloseJump
) then
7221 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
7222 if Abs(FObj
.X
-Target
.X
) < 128 then
7226 if Random(a
) = 0 then
7227 SetAIFlag('NEEDJUMP', '1');
7231 // Åñëè öåëü âñå åùå åñòü:
7232 if Target
.UID
<> 0 then
7233 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
7234 Target
.UID
:= 0 // òî çàáûòü öåëü
7235 else // Åñëè âèäåëè íåäàâíî
7236 begin // íî öåëü óáèëè
7237 if Target
.IsPlayer
then
7238 begin // Öåëü - èãðîê
7239 pla
:= g_Player_Get(Target
.UID
);
7240 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
7241 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
7242 Target
.UID
:= 0; // òî çàáûòü öåëü
7245 begin // Öåëü - ìîíñòð
7246 mon
:= g_Monsters_ByUID(Target
.UID
);
7247 if (mon
= nil) or (not mon
.alive
) then
7248 Target
.UID
:= 0; // òî çàáûòü öåëü
7251 end; // if Target.UID <> 0
7253 FTargetUID
:= Target
.UID
;
7255 // Åñëè âîçìîæíûõ öåëåé íåò:
7256 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
7257 if targets
= nil then
7258 if GetAIFlag('ATTACKLEFT') <> '' then
7259 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
7260 RemoveAIFlag('ATTACKLEFT');
7262 SetAIFlag('NEEDJUMP', '1');
7264 if RunDirection() = TDirection
.D_RIGHT
then
7265 begin // Èäåì íå â òó ñòîðîíó
7266 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7267 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
7268 SetAIFlag('NEEDFIRE', '1');
7269 SetAIFlag('GOLEFT', '1');
7273 begin // Èäåì â íóæíóþ ñòîðîíó
7274 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7275 SetAIFlag('NEEDFIRE', '1');
7276 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7277 SetAIFlag('GORIGHT', '1');
7281 if GetAIFlag('ATTACKRIGHT') <> '' then
7282 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
7283 RemoveAIFlag('ATTACKRIGHT');
7285 SetAIFlag('NEEDJUMP', '1');
7287 if RunDirection() = TDirection
.D_LEFT
then
7288 begin // Èäåì íå â òó ñòîðîíó
7289 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7290 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
7291 SetAIFlag('NEEDFIRE', '1');
7292 SetAIFlag('GORIGHT', '1');
7297 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7298 SetAIFlag('NEEDFIRE', '1');
7299 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7300 SetAIFlag('GOLEFT', '1');
7304 //HACK! (does it belongs there?)
7305 RealizeCurrentWeapon();
7307 // Åñëè åñòü âîçìîæíûå öåëè:
7308 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7309 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7310 for a
:= 0 to High(targets
) do
7312 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7313 if GetRnd(FDifficult
.DiagFire
) then
7315 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7316 if FDirection
= TDirection
.D_LEFT
then
7317 angle
:= ANGLE_LEFTUP
7319 angle
:= ANGLE_RIGHTUP
;
7321 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7322 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7324 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7325 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7326 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7327 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7328 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7330 SetAIFlag('NEEDFIRE', '1');
7331 SetAIFlag('NEEDSEEUP', '1');
7334 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7335 if FDirection
= TDirection
.D_LEFT
then
7336 angle
:= ANGLE_LEFTDOWN
7338 angle
:= ANGLE_RIGHTDOWN
;
7340 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7341 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7343 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7344 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7345 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7346 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7347 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7349 SetAIFlag('NEEDFIRE', '1');
7350 SetAIFlag('NEEDSEEDOWN', '1');
7354 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7355 if targets
[a
].Line
and targets
[a
].Visible
and
7356 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
7357 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
7359 SetAIFlag('NEEDFIRE', '1');
7364 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7365 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
7366 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
7367 40+GetInterval(FDifficult
.Cover
, 40)) then
7368 SetAIFlag('NEEDJUMP', '1');
7370 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7371 ammo
:= GetAmmoByWeapon(FCurrWeap
);
7372 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
7373 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
7375 SetAIFlag('SELECTWEAPON', '1');
7377 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7378 if GetAIFlag('SELECTWEAPON') = '1' then
7381 RemoveAIFlag('SELECTWEAPON');
7385 procedure TBot
.Update();
7398 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7399 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7401 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7403 if g_debug_BotAIOff
= 3 then
7413 RealizeCurrentWeapon();
7420 procedure TBot
.ReleaseKey(Key
: Byte);
7429 function TBot
.KeyPressed(Key
: Word): Boolean;
7431 Result
:= FKeys
[Key
].Pressed
;
7434 function TBot
.GetAIFlag(aName
: String20
): String20
;
7440 aName
:= LowerCase(aName
);
7442 if FAIFlags
<> nil then
7443 for a
:= 0 to High(FAIFlags
) do
7444 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7446 Result
:= FAIFlags
[a
].Value
;
7451 procedure TBot
.RemoveAIFlag(aName
: String20
);
7455 if FAIFlags
= nil then Exit
;
7457 aName
:= LowerCase(aName
);
7459 for a
:= 0 to High(FAIFlags
) do
7460 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7462 if a
<> High(FAIFlags
) then
7463 for b
:= a
to High(FAIFlags
)-1 do
7464 FAIFlags
[b
] := FAIFlags
[b
+1];
7466 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7471 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7479 aName
:= LowerCase(aName
);
7481 if FAIFlags
<> nil then
7482 for a
:= 0 to High(FAIFlags
) do
7483 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7489 if ok
then FAIFlags
[a
].Value
:= fValue
7492 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7493 with FAIFlags
[High(FAIFlags
)] do
7501 procedure TBot
.UpdateMove
;
7503 procedure GoLeft(Time
: Word = 1);
7505 ReleaseKey(KEY_LEFT
);
7506 ReleaseKey(KEY_RIGHT
);
7507 PressKey(KEY_LEFT
, Time
);
7508 SetDirection(TDirection
.D_LEFT
);
7511 procedure GoRight(Time
: Word = 1);
7513 ReleaseKey(KEY_LEFT
);
7514 ReleaseKey(KEY_RIGHT
);
7515 PressKey(KEY_RIGHT
, Time
);
7516 SetDirection(TDirection
.D_RIGHT
);
7519 function Rnd(a
: Word): Boolean;
7521 Result
:= Random(a
) = 0;
7524 procedure Turn(Time
: Word = 1200);
7526 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7531 ReleaseKey(KEY_LEFT
);
7532 ReleaseKey(KEY_RIGHT
);
7535 function CanRunLeft(): Boolean;
7537 Result
:= not CollideLevel(-1, 0);
7540 function CanRunRight(): Boolean;
7542 Result
:= not CollideLevel(1, 0);
7545 function CanRun(): Boolean;
7547 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7550 procedure Jump(Time
: Word = 30);
7552 PressKey(KEY_JUMP
, Time
);
7555 function NearHole(): Boolean;
7559 { TODO 5 : Ëåñòíèöû }
7560 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7561 for x
:= 1 to PLAYER_RECT
.Width
do
7562 if (not StayOnStep(x
*sx
, 0)) and
7563 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7564 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7573 function BorderHole(): Boolean;
7577 { TODO 5 : Ëåñòíèöû }
7578 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7579 for x
:= 1 to PLAYER_RECT
.Width
do
7580 if (not StayOnStep(x
*sx
, 0)) and
7581 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7582 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7584 for xx
:= x
to x
+32 do
7585 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7595 function NearDeepHole(): Boolean;
7601 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7604 for x
:= 1 to PLAYER_RECT
.Width
do
7605 if (not StayOnStep(x
*sx
, 0)) and
7606 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7607 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7609 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7611 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7616 end else Result
:= False;
7619 function OverDeepHole(): Boolean;
7626 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7628 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7635 function OnGround(): Boolean;
7637 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7640 function OnLadder(): Boolean;
7642 Result
:= FullInStep(0, 0);
7645 function BelowLadder(): Boolean;
7647 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7648 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7649 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7650 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7653 function BelowLiftUp(): Boolean;
7655 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7656 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7657 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7658 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7661 function OnTopLift(): Boolean;
7663 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7666 function CanJumpOver(): Boolean;
7670 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7674 if not CollideLevel(sx
, 0) then Exit
;
7676 for y
:= 1 to BOT_MAXJUMP
do
7677 if CollideLevel(0, -y
) then Exit
else
7678 if not CollideLevel(sx
, -y
) then
7685 function CanJumpUp(Dist
: ShortInt): Boolean;
7692 if CollideLevel(Dist
, 0) then Exit
;
7695 for y
:= 0 to BOT_MAXJUMP
do
7696 if CollideLevel(Dist
, -y
) then
7705 for yy
:= y
+1 to BOT_MAXJUMP
do
7706 if not CollideLevel(Dist
, -yy
) then
7715 for y
:= 0 to BOT_MAXJUMP
do
7716 if CollideLevel(0, -y
) then
7724 if y
< yy
then Exit
;
7729 function IsSafeTrigger(): Boolean;
7734 if gTriggers
= nil then
7736 for a
:= 0 to High(gTriggers
) do
7737 if Collide(gTriggers
[a
].X
,
7740 gTriggers
[a
].Height
) and
7741 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7742 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7743 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7744 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7745 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7750 // Âîçìîæíî, íàæèìàåì êíîïêó:
7751 if Rnd(16) and IsSafeTrigger() then
7754 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7755 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7757 ReleaseKey(KEY_LEFT
);
7758 ReleaseKey(KEY_RIGHT
);
7762 // Èäåì âëåâî, åñëè íàäî áûëî:
7763 if GetAIFlag('GOLEFT') <> '' then
7765 RemoveAIFlag('GOLEFT');
7766 if CanRunLeft() then
7770 // Èäåì âïðàâî, åñëè íàäî áûëî:
7771 if GetAIFlag('GORIGHT') <> '' then
7773 RemoveAIFlag('GORIGHT');
7774 if CanRunRight() then
7778 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7779 if FObj
.X
< -32 then
7782 if FObj
.X
+32 > gMapInfo
.Width
then
7785 // Ïðûãàåì, åñëè íàäî áûëî:
7786 if GetAIFlag('NEEDJUMP') <> '' then
7789 RemoveAIFlag('NEEDJUMP');
7792 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7793 if GetAIFlag('NEEDSEEUP') <> '' then
7796 ReleaseKey(KEY_DOWN
);
7797 PressKey(KEY_UP
, 20);
7798 RemoveAIFlag('NEEDSEEUP');
7801 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7802 if GetAIFlag('NEEDSEEDOWN') <> '' then
7805 ReleaseKey(KEY_DOWN
);
7806 PressKey(KEY_DOWN
, 20);
7807 RemoveAIFlag('NEEDSEEDOWN');
7810 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7811 if GetAIFlag('GOINHOLE') <> '' then
7812 if not OnGround() then
7814 ReleaseKey(KEY_LEFT
);
7815 ReleaseKey(KEY_RIGHT
);
7816 RemoveAIFlag('GOINHOLE');
7817 SetAIFlag('FALLINHOLE', '1');
7820 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7821 if GetAIFlag('FALLINHOLE') <> '' then
7823 RemoveAIFlag('FALLINHOLE');
7825 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7826 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7827 if GetAIFlag('FALLINHOLE') = '' then
7828 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7834 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7836 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7840 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7841 if OnGround() and NearHole() then
7842 if NearDeepHole() then // Åñëè ýòî áåçäíà
7844 0..3: Turn(); // Áåæèì îáðàòíî
7845 4: Jump(); // Ïðûãàåì
7846 5: begin // Ïðûãàåì îáðàòíî
7851 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7852 if GetAIFlag('GOINHOLE') = '' then
7854 0: Turn(); // Íå íóæíî òóäà
7855 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7856 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7857 if BorderHole() then
7858 SetAIFlag('GOINHOLE', '1');
7861 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7862 if (not CanRun()) and OnGround() then
7864 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7865 if CanJumpOver() or OnLadder() then
7867 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7868 if Random(2) = 0 then
7870 if IsSafeTrigger() then
7876 // Îñòàëîñü ìàëî âîçäóõà:
7877 if FAir
< 36 * 2 then
7880 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7881 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7882 if BodyInAcid(0, 0) then
7886 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7888 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7889 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7892 {function TBot.NeedItem(Item: Byte): Byte;
7897 procedure TBot
.SelectWeapon(Dist
: Integer);
7901 function HaveAmmo(weapon
: Byte): Boolean;
7904 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7905 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7906 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7907 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7908 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7909 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7910 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7911 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7912 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7913 else Result
:= True;
7918 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7920 if Dist
> BOT_LONGDIST
then
7921 begin // Äàëüíèé áîé
7923 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7925 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7929 else //if Dist > BOT_UNSAFEDIST then
7930 begin // Áëèæíèé áîé
7932 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7934 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7941 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7943 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7949 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7951 Result
:= inherited PickItem(ItemType
, force
, remove
);
7953 if Result
then SetAIFlag('SELECTWEAPON', '1');
7956 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7958 Result
:= inherited Heal(value
, Soft
);
7961 function TBot
.Healthy(): Byte;
7963 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7964 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7965 else if (FHealth
> 50) then Result
:= 2
7966 else if (FHealth
> 20) then Result
:= 1
7970 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7972 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7973 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7976 procedure TBot
.OnDamage(Angle
: SmallInt);
7984 if (Angle
= 0) or (Angle
= 180) then
7987 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7988 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7990 pla
:= g_Player_Get(FLastSpawnerUID
);
7991 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7992 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7995 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7996 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7998 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7999 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
8000 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
8005 SetAIFlag('ATTACKLEFT', '1')
8007 SetAIFlag('ATTACKRIGHT', '1');
8011 function TBot
.RunDirection(): TDirection
;
8013 if Abs(Vel
.X
) >= 1 then
8015 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
8017 Result
:= FDirection
;
8020 function TBot
.GetRnd(a
: Byte): Boolean;
8022 if a
= 0 then Result
:= False
8023 else if a
= 255 then Result
:= True
8024 else Result
:= Random(256) > 255-a
;
8027 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
8029 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
8033 procedure TDifficult
.save (st
: TStream
);
8035 utils
.writeInt(st
, Byte(DiagFire
));
8036 utils
.writeInt(st
, Byte(InvisFire
));
8037 utils
.writeInt(st
, Byte(DiagPrecision
));
8038 utils
.writeInt(st
, Byte(FlyPrecision
));
8039 utils
.writeInt(st
, Byte(Cover
));
8040 utils
.writeInt(st
, Byte(CloseJump
));
8041 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
8042 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
8045 procedure TDifficult
.load (st
: TStream
);
8047 DiagFire
:= utils
.readByte(st
);
8048 InvisFire
:= utils
.readByte(st
);
8049 DiagPrecision
:= utils
.readByte(st
);
8050 FlyPrecision
:= utils
.readByte(st
);
8051 Cover
:= utils
.readByte(st
);
8052 CloseJump
:= utils
.readByte(st
);
8053 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
8054 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
8058 procedure TBot
.SaveState (st
: TStream
);
8063 inherited SaveState(st
);
8064 utils
.writeSign(st
, 'BOT0');
8066 utils
.writeInt(st
, Byte(FSelectedWeapon
));
8068 utils
.writeInt(st
, Word(FTargetUID
));
8069 // Âðåìÿ ïîòåðè öåëè
8070 utils
.writeInt(st
, LongWord(FLastVisible
));
8071 // Êîëè÷åñòâî ôëàãîâ ÈÈ
8072 dw
:= Length(FAIFlags
);
8073 utils
.writeInt(st
, LongInt(dw
));
8075 for i
:= 0 to dw
-1 do
8077 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
8078 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
8080 // Íàñòðîéêè ñëîæíîñòè
8081 FDifficult
.save(st
);
8085 procedure TBot
.LoadState (st
: TStream
);
8090 inherited LoadState(st
);
8091 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
8093 FSelectedWeapon
:= utils
.readByte(st
);
8095 FTargetUID
:= utils
.readWord(st
);
8096 // Âðåìÿ ïîòåðè öåëè
8097 FLastVisible
:= utils
.readLongWord(st
);
8098 // Êîëè÷åñòâî ôëàãîâ ÈÈ
8099 dw
:= utils
.readLongInt(st
);
8100 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
8101 SetLength(FAIFlags
, dw
);
8103 for i
:= 0 to dw
-1 do
8105 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
8106 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
8108 // Íàñòðîéêè ñëîæíîñòè
8109 FDifficult
.load(st
);
8114 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');
8115 conRegVar('player_indicator_style', @gPlayerIndicatorStyle
, 'Visual appearance of indicator', 'Visual appearance of indicator');