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);
123 TPlayerStatArray
= Array of TPlayerStat
;
125 TPlayerSavedState
= record
133 Ammo
: Array [A_BULLETS
..A_HIGH
] of Word;
134 MaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
135 Weapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
136 Rulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
145 TPlayer
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
153 FDirection
: TDirection
;
161 FMonsterKills
: Integer;
167 FCanJetpack
: Boolean;
173 FNextWeapDelay
: Byte; // frames
174 FBFGFireCounter
: SmallInt;
175 FLastSpawnerUID
: Word;
179 FSpectatePlayer
: Integer;
180 FFirePainTime
: Integer;
183 FSavedStateNum
: Integer;
185 FModel
: TPlayerModel
;
186 FPunchAnim
: TAnimation
;
189 FActionForce
: Boolean;
190 FActionChanged
: Boolean;
192 FFireAngle
: SmallInt;
196 FShellTimer
: Integer;
198 FSawSound
: TPlayableSound
;
199 FSawSoundIdle
: TPlayableSound
;
200 FSawSoundHit
: TPlayableSound
;
201 FSawSoundSelect
: TPlayableSound
;
202 FFlameSoundOn
: TPlayableSound
;
203 FFlameSoundOff
: TPlayableSound
;
204 FFlameSoundWork
: TPlayableSound
;
205 FJetSoundOn
: TPlayableSound
;
206 FJetSoundOff
: TPlayableSound
;
207 FJetSoundFly
: TPlayableSound
;
211 FJustTeleported
: Boolean;
213 mEDamageType
: Integer;
216 function CollideLevel(XInc
, YInc
: Integer): Boolean;
217 function StayOnStep(XInc
, YInc
: Integer): Boolean;
218 function HeadInLiquid(XInc
, YInc
: Integer): Boolean;
219 function BodyInLiquid(XInc
, YInc
: Integer): Boolean;
220 function BodyInAcid(XInc
, YInc
: Integer): Boolean;
221 function FullInLift(XInc
, YInc
: Integer): Integer;
222 {procedure CollideItem();}
223 procedure FlySmoke(Times
: DWORD
= 1);
224 procedure OnFireFlame(Times
: DWORD
= 1);
225 function GetAmmoByWeapon(Weapon
: Byte): Word;
226 procedure SetAction(Action
: Byte; Force
: Boolean = False);
227 procedure OnDamage(Angle
: SmallInt); virtual;
228 function firediry(): Integer;
231 procedure Run(Direction
: TDirection
);
232 procedure NextWeapon();
233 procedure PrevWeapon();
240 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
241 procedure resetWeaponQueue ();
242 function hasAmmoForWeapon (weapon
: Byte): Boolean;
243 function hasAmmoForShooting (weapon
: Byte): Boolean;
244 function shouldSwitch (weapon
: Byte; hadWeapon
: Boolean) : Boolean;
246 procedure doDamage (v
: Integer);
248 function refreshCorpse(): Boolean;
251 FDamageBuffer
: Integer;
253 FAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
254 FMaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
255 FWeapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
256 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
258 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
259 FReloading
: Array [WP_FIRST
..WP_LAST
] of Word;
260 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
261 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
262 FWeapSwitchMode
: Byte;
263 FWeapPreferences
: Array [WP_FIRST
.. WP_LAST
+1] of Byte;
264 FSwitchToEmpty
: Byte;
267 FPreferredTeam
: Byte;
270 FWantsInGame
: Boolean;
275 FActualModelName
: string;
282 FSpawnInvul
: Integer;
284 FWaitForFirstSpawn
: Boolean; // set to `true` in server, used to spawn a player on first full state request
287 // debug: viewport offset
288 viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer;
290 function isValidViewPort (): Boolean; inline;
292 constructor Create(); virtual;
293 destructor Destroy(); override;
294 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
295 function GetRespawnPoint(): Byte;
296 procedure PressKey(Key
: Byte; Time
: Word = 1);
297 procedure ReleaseKeys();
298 procedure SetModel(ModelName
: String);
299 procedure SetColor(Color
: TRGB
);
300 function GetColor(): TRGB
;
301 procedure SetWeapon(W
: Byte);
302 function IsKeyPressed(K
: Byte): Boolean;
303 function GetKeys(): Byte;
304 function PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean; virtual;
305 procedure SetWeaponPrefs(Prefs
: Array of Byte);
306 procedure SetWeaponPref(Weapon
, Pref
: Byte);
307 function GetWeaponPref(Weapon
: Byte) : Byte;
308 function GetMorePrefered() : Byte;
309 function MaySwitch(Weapon
: Byte) : Boolean;
310 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
311 function Collide(Panel
: TPanel
): Boolean; overload
;
312 function Collide(X
, Y
: Integer): Boolean; overload
;
313 procedure SetDirection(Direction
: TDirection
);
314 procedure GetSecret();
315 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
317 procedure Push(vx
, vy
: Integer);
318 procedure ChangeModel(ModelName
: String);
319 procedure SwitchTeam
;
320 procedure ChangeTeam(Team
: Byte);
322 function GetFlag(Flag
: Byte): Boolean;
323 procedure SetFlag(Flag
: Byte);
324 function DropFlag(Silent
: Boolean = True; DoThrow
: Boolean = False): Boolean;
325 function TryDropFlag(): Boolean;
326 procedure AllRulez(Health
: Boolean);
327 procedure RestoreHealthArmor();
328 procedure FragCombo();
329 procedure GiveItem(ItemType
: Byte);
330 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
331 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
332 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
333 procedure MakeBloodSimple(Count
: Word);
334 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
335 procedure Reset(Force
: Boolean);
336 procedure Spectate(NoMove
: Boolean = False);
337 procedure SwitchNoClip
;
338 procedure SoftReset();
339 procedure Draw(); virtual;
340 procedure DrawPain();
341 procedure DrawPickup();
342 procedure DrawRulez();
344 procedure DrawIndicator(Color
: TRGB
);
345 procedure DrawBubble();
347 procedure PreUpdate();
348 procedure Update(); virtual;
349 procedure RememberState();
350 procedure RecallState();
351 procedure SaveState (st
: TStream
); virtual;
352 procedure LoadState (st
: TStream
); virtual;
353 procedure PauseSounds(Enable
: Boolean);
354 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
355 procedure DoLerp(Level
: Integer = 2);
356 procedure SetLerp(XTo
, YTo
: Integer);
357 procedure ProcessWeaponAction(Action
: Byte);
358 procedure QueueWeaponSwitch(Weapon
: Byte);
359 procedure RealizeCurrentWeapon();
363 procedure JetpackOff
;
364 procedure CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
366 //WARNING! this does nothing for now, but still call it!
367 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
369 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
370 procedure moveBy (dx
, dy
: Integer); inline;
372 function getCameraObj(): TObj
;
375 property Vel
: TPoint2i read FObj
.Vel
;
376 property Obj
: TObj read FObj
;
378 property Name
: String read FName write FName
;
379 property Model
: TPlayerModel read FModel
;
380 property Health
: Integer read FHealth write FHealth
;
381 property Lives
: Byte read FLives write FLives
;
382 property Armor
: Integer read FArmor write FArmor
;
383 property Air
: Integer read FAir write FAir
;
384 property JetFuel
: Integer read FJetFuel write FJetFuel
;
385 property Frags
: Integer read FFrags write FFrags
;
386 property Death
: Integer read FDeath write FDeath
;
387 property Kills
: Integer read FKills write FKills
;
388 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
389 property WeapSwitchMode
: Byte read FWeapSwitchMode write FWeapSwitchMode
;
390 property SwitchToEmpty
: Byte read FSwitchToEmpty write FSwitchToEmpty
;
391 property SkipFist
: Byte read FSkipFist write FSkipFist
;
392 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
393 property Secrets
: Integer read FSecrets
;
394 property GodMode
: Boolean read FGodMode write FGodMode
;
395 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
396 property NoReload
: Boolean read FNoReload write FNoReload
;
397 property alive
: Boolean read FAlive write FAlive
;
398 property Flag
: Byte read FFlag
;
399 property Team
: Byte read FTeam write FTeam
;
400 property Direction
: TDirection read FDirection
;
401 property GameX
: Integer read FObj
.X write FObj
.X
;
402 property GameY
: Integer read FObj
.Y write FObj
.Y
;
403 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
404 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
405 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
406 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
407 property IncCam
: Integer read FIncCam write FIncCam
;
408 property IncCamOld
: Integer read FIncCamOld write FIncCamOld
;
409 property SlopeOld
: Integer read FSlopeOld write FSlopeOld
;
410 property UID
: Word read FUID write FUID
;
411 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
412 property NetTime
: LongWord read FNetTime write FNetTime
;
415 property eName
: String read FName write FName
;
416 property eHealth
: Integer read FHealth write FHealth
;
417 property eLives
: Byte read FLives write FLives
;
418 property eArmor
: Integer read FArmor write FArmor
;
419 property eAir
: Integer read FAir write FAir
;
420 property eJetFuel
: Integer read FJetFuel write FJetFuel
;
421 property eFrags
: Integer read FFrags write FFrags
;
422 property eDeath
: Integer read FDeath write FDeath
;
423 property eKills
: Integer read FKills write FKills
;
424 property eCurrWeap
: Byte read FCurrWeap write FCurrWeap
;
425 property eMonsterKills
: Integer read FMonsterKills write FMonsterKills
;
426 property eSecrets
: Integer read FSecrets write FSecrets
;
427 property eGodMode
: Boolean read FGodMode write FGodMode
;
428 property eNoTarget
: Boolean read FNoTarget write FNoTarget
;
429 property eNoReload
: Boolean read FNoReload write FNoReload
;
430 property eAlive
: Boolean read FAlive write FAlive
;
431 property eFlag
: Byte read FFlag
;
432 property eTeam
: Byte read FTeam write FTeam
;
433 property eDirection
: TDirection read FDirection
;
434 property eGameX
: Integer read FObj
.X write FObj
.X
;
435 property eGameY
: Integer read FObj
.Y write FObj
.Y
;
436 property eGameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
437 property eGameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
438 property eGameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
439 property eGameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
440 property eIncCam
: Integer read FIncCam write FIncCam
;
441 property eUID
: Word read FUID
;
442 property eJustTeleported
: Boolean read FJustTeleported
;
443 property eNetTime
: LongWord read FNetTime
;
445 // set this before assigning something to `eDamage`
446 property eDamageType
: Integer read mEDamageType write mEDamageType
;
447 property eDamage
: Integer write doDamage
;
458 WeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
459 CloseWeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
460 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
463 procedure save (st
: TStream
);
464 procedure load (st
: TStream
);
472 TBot
= class(TPlayer
)
474 FSelectedWeapon
: Byte;
477 FAIFlags
: Array of TAIFlag
;
478 FDifficult
: TDifficult
;
480 function GetRnd(a
: Byte): Boolean;
481 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
482 function RunDirection(): TDirection
;
483 function FullInStep(XInc
, YInc
: Integer): Boolean;
484 //function NeedItem(Item: Byte): Byte;
485 procedure SelectWeapon(Dist
: Integer);
486 procedure SetAIFlag(aName
, fValue
: String20
);
487 function GetAIFlag(aName
: String20
): String20
;
488 procedure RemoveAIFlag(aName
: String20
);
489 function Healthy(): Byte;
490 procedure UpdateMove();
491 procedure UpdateCombat();
492 function KeyPressed(Key
: Word): Boolean;
493 procedure ReleaseKey(Key
: Byte);
494 function TargetOnScreen(TX
, TY
: Integer): Boolean;
495 procedure OnDamage(Angle
: SmallInt); override;
498 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
499 constructor Create(); override;
500 destructor Destroy(); override;
501 procedure Draw(); override;
502 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
503 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
504 procedure Update(); override;
505 procedure SaveState (st
: TStream
); override;
506 procedure LoadState (st
: TStream
); override;
518 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
519 procedure moveBy (dx
, dy
: Integer); inline;
521 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
535 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
536 procedure moveBy (dx
, dy
: Integer); inline;
538 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
541 TCorpse
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
550 FAnimation
: TAnimation
;
551 FAnimationMask
: TAnimation
;
554 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
555 destructor Destroy(); override;
556 procedure Damage(Value
: Word; SpawnerUID
: Word; vx
, vy
: Integer);
559 procedure SaveState (st
: TStream
);
560 procedure LoadState (st
: TStream
);
562 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
563 procedure moveBy (dx
, dy
: Integer); inline;
565 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
567 function ObjPtr (): PObj
; inline;
569 property Obj
: TObj read FObj
; // copies object
570 property State
: Byte read FState
;
571 property Mess
: Boolean read FMess
;
574 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
580 gPlayers
: Array of TPlayer
;
581 gCorpses
: Array of TCorpse
;
582 gGibs
: Array of TGib
;
583 gShells
: Array of TShell
;
584 gTeamStat
: TTeamStat
;
585 gFly
: Boolean = False;
586 gAimLine
: Boolean = False;
587 gChatBubble
: Integer = 0;
588 gPlayerIndicator
: Integer = 1;
589 gPlayerIndicatorStyle
: Integer = 0;
591 gSpectLatchPID1
: Word = 0;
592 gSpectLatchPID2
: Word = 0;
593 MAX_RUNVEL
: Integer = 8;
594 VEL_JUMP
: Integer = 10;
595 SHELL_TIMEOUT
: Cardinal = 60000;
597 function Lerp(X
, Y
, Factor
: Integer): Integer;
599 procedure g_Gibs_SetMax(Count
: Word);
600 function g_Gibs_GetMax(): Word;
601 procedure g_Corpses_SetMax(Count
: Word);
602 function g_Corpses_GetMax(): Word;
603 procedure g_Force_Model_Set(Mode
: Word);
604 function g_Force_Model_Get(): Word;
605 procedure g_Forced_Model_SetName(Model
: String);
606 function g_Forced_Model_GetName(): String;
607 procedure g_Shells_SetMax(Count
: Word);
608 function g_Shells_GetMax(): Word;
610 procedure g_Player_Init();
611 procedure g_Player_Free();
612 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
613 function g_Player_CreateFromState (st
: TStream
): Word;
614 procedure g_Player_Remove(UID
: Word);
615 procedure g_Player_ResetTeams();
616 procedure g_Player_PreUpdate();
617 procedure g_Player_UpdateAll();
618 procedure g_Player_DrawAll();
619 procedure g_Player_DrawDebug(p
: TPlayer
);
620 procedure g_Player_DrawHealth();
621 procedure g_Player_RememberAll();
622 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
623 function g_Player_Get(UID
: Word): TPlayer
;
624 function g_Player_GetCount(): Byte;
625 function g_Player_GetStats(): TPlayerStatArray
;
626 function g_Player_ExistingName(Name
: String): Boolean;
627 function g_Player_CreateCorpse(Player
: TPlayer
): Integer;
628 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
629 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
630 procedure g_Player_UpdatePhysicalObjects();
631 procedure g_Player_DrawCorpses();
632 procedure g_Player_DrawShells();
633 procedure g_Player_RemoveAllCorpses();
634 procedure g_Player_Corpses_SaveState (st
: TStream
);
635 procedure g_Player_Corpses_LoadState (st
: TStream
);
636 procedure g_Player_ResetReady();
637 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
638 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
639 procedure g_Bot_MixNames();
640 procedure g_Bot_RemoveAll();
641 function g_Bot_GetCount(): Integer;
646 {$INCLUDE ../nogl/noGLuses.inc}
647 {$IFDEF ENABLE_HOLMES}
650 e_log
, g_map
, g_items
, g_console
, g_gfx
, Math
,
651 g_options
, g_triggers
, g_menu
, g_game
, g_grid
, e_res
,
652 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
,
653 g_net
, g_netmsg
, g_window
,
656 const PLR_SAVE_VERSION
= 0;
666 diag_precision
: Byte;
670 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
671 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
672 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
676 TIME_RESPAWN1
= 1500;
677 TIME_RESPAWN2
= 2000;
678 TIME_RESPAWN3
= 3000;
681 JET_MAX
= 540; // ~30 sec
682 PLAYER_SUIT_TIME
= 30000;
683 PLAYER_INVUL_TIME
= 30000;
684 PLAYER_INVIS_TIME
= 35000;
685 FRAG_COMBO_TIME
= 3000;
689 ANGLE_RIGHTDOWN
= -35;
691 ANGLE_LEFTDOWN
= -145;
692 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
693 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
696 BOT_UNSAFEDIST
= 128;
697 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
699 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
700 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
701 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
702 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
703 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
704 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
705 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
706 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
707 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
708 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
709 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
710 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
711 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
712 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
713 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
714 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
715 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
716 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
717 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
718 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
719 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
720 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
721 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
722 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
723 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
724 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
726 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
727 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
729 BOTNAMES_FILENAME
= 'botnames.txt';
730 BOTLIST_FILENAME
= 'botlist.txt';
734 MaxCorpses
: Word = 20;
735 MaxShells
: Word = 300;
736 ForceModel
: Word = 0;
737 ForcedModelName
: String = STD_PLAYER_MODEL
;
738 CurrentGib
: Integer = 0;
739 CurrentShell
: Integer = 0;
740 BotNames
: Array of String;
741 BotList
: Array of TBotProfile
;
742 SavedStates
: Array of TPlayerSavedState
;
745 function Lerp(X
, Y
, Factor
: Integer): Integer;
747 Result
:= X
+ ((Y
- X
) div Factor
);
750 function SameTeam(UID1
, UID2
: Word): Boolean;
754 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
755 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
757 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
759 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
760 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
762 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
765 procedure g_Gibs_SetMax(Count
: Word);
768 SetLength(gGibs
, Count
);
770 if CurrentGib
>= Count
then
774 function g_Gibs_GetMax(): Word;
779 procedure g_Shells_SetMax(Count
: Word);
782 SetLength(gShells
, Count
);
784 if CurrentShell
>= Count
then
788 function g_Shells_GetMax(): Word;
794 procedure g_Corpses_SetMax(Count
: Word);
797 SetLength(gCorpses
, Count
);
800 function g_Corpses_GetMax(): Word;
802 Result
:= MaxCorpses
;
805 procedure g_Force_Model_Set(Mode
: Word);
810 function g_Force_Model_Get(): Word;
812 Result
:= ForceModel
;
815 procedure g_Forced_Model_SetName(Model
: String);
817 ForcedModelName
:= Model
;
820 function g_Forced_Model_GetName(): String;
822 Result
:= ForcedModelName
;
825 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
835 // Åñòü ëè ìåñòî â gPlayers:
836 if gPlayers
<> nil then
837 for a
:= 0 to High(gPlayers
) do
838 if gPlayers
[a
] = nil then
844 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
847 SetLength(gPlayers
, Length(gPlayers
)+1);
851 // Ñîçäàåì îáúåêò èãðîêà:
853 gPlayers
[a
] := TBot
.Create()
855 gPlayers
[a
] := TPlayer
.Create();
858 gPlayers
[a
].FActualModelName
:= ModelName
;
859 gPlayers
[a
].SetModel(ModelName
);
860 if Bot
and (g_Force_Model_Get() <> 0) then
861 gPlayers
[a
].SetModel(g_Forced_Model_GetName());
863 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
864 if gPlayers
[a
].FModel
= nil then
868 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
872 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
873 if Random(2) = 0 then
877 gPlayers
[a
].FPreferredTeam
:= Team
;
879 case gGameSettings
.GameMode
of
880 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
882 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
884 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
887 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
888 gPlayers
[a
].FColor
:= Color
;
889 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
890 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
892 gPlayers
[a
].FModel
.Color
:= Color
;
894 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
895 gPlayers
[a
].FAlive
:= False;
897 Result
:= gPlayers
[a
].FUID
;
900 function g_Player_CreateFromState (st
: TStream
): Word;
901 var a
: Integer; ok
, Bot
: Boolean; pos
: Int64;
905 // check signature and entity type
907 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
908 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
909 Bot
:= utils
.readBool(st
);
912 // find free player slot
914 for a
:= 0 to High(gPlayers
) do
915 if gPlayers
[a
] = nil then
921 // allocate player slot
924 SetLength(gPlayers
, Length(gPlayers
)+1);
928 // create entity and load state
931 gPlayers
[a
] := TBot
.Create();
932 if (g_Force_Model_Get() <> 0) then
933 gPlayers
[a
].SetModel(g_Forced_Model_GetName());
936 gPlayers
[a
] := TPlayer
.Create();
937 gPlayers
[a
].FPhysics
:= True; // ???
938 gPlayers
[a
].LoadState(st
);
940 result
:= gPlayers
[a
].FUID
;
944 procedure g_Player_ResetTeams();
948 if g_Game_IsClient
then
950 if gPlayers
= nil then
952 for a
:= Low(gPlayers
) to High(gPlayers
) do
953 if gPlayers
[a
] <> nil then
954 case gGameSettings
.GameMode
of
956 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
958 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
959 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
960 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
963 gPlayers
[a
].ChangeTeam(TEAM_RED
)
965 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
968 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
972 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
975 _name
, _model
: String;
978 if not g_Game_IsServer
then Exit
;
980 // Íå äîáàâëÿåì áîòîâ åñëè ëèìèò óæå äîñòèãíóò
981 if (g_Bot_GetCount() >= gMaxBots
) then Exit
;
983 // Ñïèñîê íàçâàíèé ìîäåëåé:
984 m
:= g_PlayerModel_GetNames();
989 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
990 Team
:= TEAM_COOP
// COOP
992 if gGameSettings
.GameMode
= GM_DM
then
993 Team
:= TEAM_NONE
// DM
995 if Team
= TEAM_NONE
then // CTF / TDM
997 // Àâòîáàëàíñ êîìàíä:
1001 for a
:= 0 to High(gPlayers
) do
1002 if gPlayers
[a
] <> nil then
1004 if gPlayers
[a
].Team
= TEAM_RED
then
1007 if gPlayers
[a
].Team
= TEAM_BLUE
then
1017 if Random(2) = 0 then
1023 // Âûáèðàåì áîòó èìÿ:
1025 if BotNames
<> nil then
1026 for a
:= 0 to High(BotNames
) do
1027 if g_Player_ExistingName(BotNames
[a
]) then
1029 _name
:= BotNames
[a
];
1033 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1034 _model
:= m
[Random(Length(m
))];
1037 with g_Player_Get(g_Player_Create(_model
,
1038 _RGB(Min(Random(9)*32, 255),
1039 Min(Random(9)*32, 255),
1040 Min(Random(9)*32, 255)),
1041 Team
, True)) as TBot
do
1043 // Åñëè èìåíè íåò, äåëàåì åãî èç UID áîòà
1045 Name
:= Format('DFBOT%.5d', [UID
])
1050 1: FDifficult
:= DIFFICULT_EASY
;
1051 2: FDifficult
:= DIFFICULT_MEDIUM
;
1052 else FDifficult
:= DIFFICULT_HARD
;
1055 for a
:= WP_FIRST
to WP_LAST
do
1057 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1058 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1059 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1062 FHandicap
:= Handicap
;
1064 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1066 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1067 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1072 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
1075 _name
, _model
: String;
1078 if not g_Game_IsServer
then Exit
;
1080 // Íå äîáàâëÿåì áîòîâ åñëè ëèìèò óæå äîñòèãíóò
1081 if (g_Bot_GetCount() >= gMaxBots
) then Exit
;
1083 // Ñïèñîê íàçâàíèé ìîäåëåé:
1084 m
:= g_PlayerModel_GetNames();
1089 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1090 Team
:= TEAM_COOP
// COOP
1092 if gGameSettings
.GameMode
= GM_DM
then
1093 Team
:= TEAM_NONE
// DM
1095 if Team
= TEAM_NONE
then
1096 Team
:= BotList
[num
].team
; // CTF / TDM
1098 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1100 num
:= Random(Length(BotList
))
1103 if (num
< 0) or (num
> Length(BotList
)-1) then
1105 if (num
= -1) and (BotList
<> nil) then
1106 lName
:= AnsiLowerCase(lName
);
1107 for a
:= 0 to High(BotList
) do
1108 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1118 _name
:= BotList
[num
].name
;
1119 if (_name
= '') and (BotNames
<> nil) then
1120 for a
:= 0 to High(BotNames
) do
1121 if g_Player_ExistingName(BotNames
[a
]) then
1123 _name
:= BotNames
[a
];
1128 _model
:= BotList
[num
].model
;
1129 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1130 if not InSArray(_model
, m
) then
1131 _model
:= m
[Random(Length(m
))];
1134 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1136 // Åñëè èìåíè íåò, äåëàåì åãî èç UID áîòà
1138 then Name
:= Format('DFBOT%.5d', [UID
])
1141 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1142 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1143 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1144 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1145 FDifficult
.Cover
:= BotList
[num
].cover
;
1146 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1148 FHandicap
:= Handicap
;
1150 for a
:= WP_FIRST
to WP_LAST
do
1152 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1153 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1154 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1157 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1159 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1163 procedure g_Bot_RemoveAll();
1167 if not g_Game_IsServer
then Exit
;
1168 if gPlayers
= nil then Exit
;
1170 for a
:= 0 to High(gPlayers
) do
1171 if gPlayers
[a
] <> nil then
1172 if gPlayers
[a
] is TBot
then
1174 gPlayers
[a
].Lives
:= 0;
1175 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1176 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1177 g_Player_Remove(gPlayers
[a
].FUID
);
1183 procedure g_Bot_MixNames();
1188 if BotNames
<> nil then
1189 for a
:= 0 to High(BotNames
) do
1191 b
:= Random(Length(BotNames
));
1193 Botnames
[a
] := BotNames
[b
];
1198 procedure g_Player_Remove(UID
: Word);
1202 if gPlayers
= nil then Exit
;
1204 if g_Game_IsServer
and g_Game_IsNet
then
1205 MH_SEND_PlayerDelete(UID
);
1207 for i
:= 0 to High(gPlayers
) do
1208 if gPlayers
[i
] <> nil then
1209 if gPlayers
[i
].FUID
= UID
then
1211 if gPlayers
[i
] is TPlayer
then
1212 TPlayer(gPlayers
[i
]).Free()
1214 TBot(gPlayers
[i
]).Free();
1220 procedure g_Player_Init();
1232 path
:= BOTNAMES_FILENAME
;
1233 if e_FindResource(DataDirs
, path
) then
1235 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1236 AssignFile(F
, path
);
1247 SetLength(BotNames
, Length(BotNames
)+1);
1248 BotNames
[High(BotNames
)] := s
;
1257 path
:= BOTLIST_FILENAME
;
1258 if e_FindResource(DataDirs
, path
) then
1260 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1261 config
:= TConfig
.CreateFile(path
);
1264 while config
.SectionExists(IntToStr(a
)) do
1266 SetLength(BotList
, Length(BotList
)+1);
1268 with BotList
[High(BotList
)] do
1270 name
:= config
.ReadStr(IntToStr(a
), 'name', ''); // Èìÿ áîòà
1271 model
:= config
.ReadStr(IntToStr(a
), 'model', ''); // Ìîäåëü
1274 s
:= config
.ReadStr(IntToStr(a
), 'team', '');
1277 else if s
= 'blue' then
1283 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1285 color
.R
:= StrToIntDef(sa
[0], 0);
1286 color
.G
:= StrToIntDef(sa
[1], 0);
1287 color
.B
:= StrToIntDef(sa
[2], 0);
1289 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0); // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì
1290 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0); // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó
1291 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0); // Òî÷íîñòü ñòðåëüáû ïîä óãëîì
1292 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0); // Òî÷íîñòü ñòðåëüáû â ïîëåòå
1293 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0); // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ
1294 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0); // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà
1296 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ
1297 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1298 if Length(sa
) = 10 then
1300 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1302 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ
1303 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1304 if Length(sa
) = 10 then
1306 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1308 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1309 if Length(sa) = 10 then
1311 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1320 SetLength(SavedStates
, 0);
1323 procedure g_Player_Free();
1327 if gPlayers
<> nil then
1329 for i
:= 0 to High(gPlayers
) do
1330 if gPlayers
[i
] <> nil then
1332 if gPlayers
[i
] is TPlayer
then
1333 TPlayer(gPlayers
[i
]).Free()
1335 TBot(gPlayers
[i
]).Free();
1344 SetLength(SavedStates
, 0);
1347 procedure g_Player_PreUpdate();
1351 if gPlayers
= nil then Exit
;
1352 for i
:= 0 to High(gPlayers
) do
1353 if gPlayers
[i
] <> nil then
1354 gPlayers
[i
].PreUpdate();
1357 procedure g_Player_UpdateAll();
1361 if gPlayers
= nil then Exit
;
1363 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1364 for i
:= 0 to High(gPlayers
) do
1366 if gPlayers
[i
] <> nil then
1368 if gPlayers
[i
] is TPlayer
then
1370 gPlayers
[i
].Update();
1371 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1375 // bot updates weapons in `UpdateCombat()`
1376 TBot(gPlayers
[i
]).Update();
1380 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1383 procedure g_Player_DrawAll();
1387 if gPlayers
= nil then Exit
;
1389 for i
:= 0 to High(gPlayers
) do
1390 if gPlayers
[i
] <> nil then
1391 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1392 else TBot(gPlayers
[i
]).Draw();
1395 procedure g_Player_DrawDebug(p
: TPlayer
);
1399 if p
= nil then Exit
;
1400 if (@p
.FObj
) = nil then Exit
;
1402 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1404 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1405 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1406 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1407 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1408 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1409 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1410 e_TextureFontPrint(0, fH
* 6, 'Old X: ' + IntToStr(p
.FObj
.oldX
), gStdFont
);
1411 e_TextureFontPrint(0, fH
* 7, 'Old Y: ' + IntToStr(p
.FObj
.oldY
), gStdFont
);
1414 procedure g_Player_DrawHealth();
1419 if gPlayers
= nil then Exit
;
1420 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1422 for i
:= 0 to High(gPlayers
) do
1423 if gPlayers
[i
] <> nil then
1425 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1426 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1427 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1428 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1429 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1430 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1434 function g_Player_Get(UID
: Word): TPlayer
;
1440 if gPlayers
= nil then
1443 for a
:= 0 to High(gPlayers
) do
1444 if gPlayers
[a
] <> nil then
1445 if gPlayers
[a
].FUID
= UID
then
1447 Result
:= gPlayers
[a
];
1452 function g_Player_GetCount(): Byte;
1458 if gPlayers
= nil then
1461 for a
:= 0 to High(gPlayers
) do
1462 if gPlayers
[a
] <> nil then
1463 Result
:= Result
+ 1;
1466 function g_Bot_GetCount(): Integer;
1472 if gPlayers
= nil then
1475 for a
:= 0 to High(gPlayers
) do
1476 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] is TBot
) then
1477 Result
:= Result
+ 1;
1480 function g_Player_GetStats(): TPlayerStatArray
;
1486 if gPlayers
= nil then Exit
;
1488 for a
:= 0 to High(gPlayers
) do
1489 if gPlayers
[a
] <> nil then
1491 SetLength(Result
, Length(Result
)+1);
1492 with Result
[High(Result
)] do
1495 Ping
:= gPlayers
[a
].FPing
;
1496 Loss
:= gPlayers
[a
].FLoss
;
1497 Name
:= gPlayers
[a
].FName
;
1498 Team
:= gPlayers
[a
].FTeam
;
1499 Frags
:= gPlayers
[a
].FFrags
;
1500 Deaths
:= gPlayers
[a
].FDeath
;
1501 Kills
:= gPlayers
[a
].FKills
;
1502 Color
:= gPlayers
[a
].FModel
.Color
;
1503 Lives
:= gPlayers
[a
].FLives
;
1504 Spectator
:= gPlayers
[a
].FSpectator
;
1505 UID
:= gPlayers
[a
].FUID
;
1510 procedure g_Player_ResetReady();
1514 if not g_Game_IsServer
then Exit
;
1515 if gPlayers
= nil then Exit
;
1517 for a
:= 0 to High(gPlayers
) do
1518 if gPlayers
[a
] <> nil then
1520 gPlayers
[a
].FReady
:= False;
1521 if g_Game_IsNet
then
1522 MH_SEND_GameEvent(NET_EV_INTER_READY
, gPlayers
[a
].UID
, 'N');
1526 procedure g_Player_RememberAll
;
1530 for i
:= Low(gPlayers
) to High(gPlayers
) do
1531 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1532 gPlayers
[i
].RememberState
;
1535 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1539 gTeamStat
[TEAM_RED
].Score
:= 0;
1540 gTeamStat
[TEAM_BLUE
].Score
:= 0;
1542 if gPlayers
<> nil then
1543 for i
:= 0 to High(gPlayers
) do
1544 if gPlayers
[i
] <> nil then
1546 gPlayers
[i
].Reset(Force
);
1548 if gPlayers
[i
] is TPlayer
then
1550 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1551 gPlayers
[i
].Respawn(Silent
)
1553 gPlayers
[i
].Spectate();
1556 TBot(gPlayers
[i
]).Respawn(Silent
);
1560 function g_Player_CreateCorpse(Player
: TPlayer
): Integer;
1568 if Player
.alive
then
1571 // Ðàçðûâàåì ñâÿçü ñ ïðåæíèì òðóïîì:
1572 i
:= Player
.FCorpse
;
1573 if (i
>= 0) and (i
< Length(gCorpses
)) then
1575 if (gCorpses
[i
] <> nil) and (gCorpses
[i
].FPlayerUID
= Player
.FUID
) then
1576 gCorpses
[i
].FPlayerUID
:= 0;
1579 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1584 if (FHealth
>= -50) or (gGibsCount
= 0) then
1586 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1590 for find_id
:= 0 to High(gCorpses
) do
1591 if gCorpses
[find_id
] = nil then
1598 find_id
:= Random(Length(gCorpses
));
1600 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1601 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1602 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1603 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1604 gCorpses
[find_id
].FPlayerUID
:= FUID
;
1609 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1610 FObj
.Y
+ PLAYER_RECT_CY
,
1611 FModel
.Name
, FModel
.Color
);
1615 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1619 if (gShells
= nil) or (Length(gShells
) = 0) then
1622 with gShells
[CurrentShell
] do
1628 if T
= SHELL_BULLET
then
1630 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1634 Obj
.Rect
.Width
:= 4;
1635 Obj
.Rect
.Height
:= 2;
1639 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1643 Obj
.Rect
.Width
:= 7;
1644 Obj
.Rect
.Height
:= 3;
1650 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1651 positionChanged(); // this updates spatial accelerators
1652 RAngle
:= Random(360);
1653 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1655 if CurrentShell
>= High(gShells
) then
1662 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1665 GibsArray
: TGibsArray
;
1668 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1670 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1672 Blood
:= g_PlayerModel_GetBlood(ModelName
);
1674 for a
:= 0 to High(GibsArray
) do
1675 with gGibs
[CurrentGib
] do
1678 ID
:= GibsArray
[a
].ID
;
1679 MaskID
:= GibsArray
[a
].MaskID
;
1682 Obj
.Rect
:= GibsArray
[a
].Rect
;
1683 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1684 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1685 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1686 positionChanged(); // this updates spatial accelerators
1687 RAngle
:= Random(360);
1689 if gBloodCount
> 0 then
1690 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1691 Random(48), Random(48), Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
1693 if CurrentGib
>= High(gGibs
) then
1700 procedure g_Player_UpdatePhysicalObjects();
1706 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1711 if T
= SHELL_BULLET
then
1712 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1714 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1719 if gGibs
<> nil then
1720 for i
:= 0 to High(gGibs
) do
1721 if gGibs
[i
].alive
then
1728 mr
:= g_Obj_Move(@Obj
, True, False, True);
1729 positionChanged(); // this updates spatial accelerators
1731 if WordBool(mr
and MOVE_FALLOUT
) then
1737 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1738 if WordBool(mr
and MOVE_HITWALL
) then
1739 Obj
.Vel
.X
:= -(vel
.X
div 2);
1740 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1741 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1743 if (Obj
.Vel
.X
>= 0) then
1745 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1746 if RAngle
>= 360 then
1747 RAngle
:= RAngle
mod 360;
1748 end else begin // Counter-clockwise
1749 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1751 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1754 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1755 if gTime
mod (GAME_TICK
*3) = 0 then
1756 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1760 if gCorpses
<> nil then
1761 for i
:= 0 to High(gCorpses
) do
1762 if gCorpses
[i
] <> nil then
1763 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1769 gCorpses
[i
].Update();
1772 if gShells
<> nil then
1773 for i
:= 0 to High(gShells
) do
1774 if gShells
[i
].alive
then
1781 mr
:= g_Obj_Move(@Obj
, True, False, True);
1782 positionChanged(); // this updates spatial accelerators
1784 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1790 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1791 if WordBool(mr
and MOVE_HITWALL
) then
1793 Obj
.Vel
.X
:= -(vel
.X
div 2);
1794 if not WordBool(mr
and MOVE_INWATER
) then
1795 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1797 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1799 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1800 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1801 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1803 if RAngle
mod 90 <> 0 then
1804 RAngle
:= (RAngle
div 90) * 90;
1806 else if not WordBool(mr
and MOVE_INWATER
) then
1807 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1810 if (Obj
.Vel
.X
>= 0) then
1812 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1813 if RAngle
>= 360 then
1814 RAngle
:= RAngle
mod 360;
1815 end else begin // Counter-clockwise
1816 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1818 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1824 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1826 x
:= Obj
.X
+Obj
.Rect
.X
;
1827 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1828 w
:= Obj
.Rect
.Width
;
1829 h
:= Obj
.Rect
.Height
;
1832 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1834 if (dx
<> 0) or (dy
<> 0) then
1843 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1847 w
:= Obj
.Rect
.Width
;
1848 h
:= Obj
.Rect
.Height
;
1851 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1853 if (dx
<> 0) or (dy
<> 0) then
1862 procedure TGib
.positionChanged (); inline; begin end;
1863 procedure TShell
.positionChanged (); inline; begin end;
1866 procedure g_Player_DrawCorpses();
1871 if gGibs
<> nil then
1872 for i
:= 0 to High(gGibs
) do
1873 if gGibs
[i
].alive
then
1876 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1879 Obj
.lerp(gLerpFactor
, fX
, fY
);
1881 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1882 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1884 e_DrawAdv(ID
, fX
, fY
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1887 e_DrawAdv(MaskID
, fX
, fY
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1893 if gCorpses
<> nil then
1894 for i
:= 0 to High(gCorpses
) do
1895 if gCorpses
[i
] <> nil then
1899 procedure g_Player_DrawShells();
1904 if gShells
<> nil then
1905 for i
:= 0 to High(gShells
) do
1906 if gShells
[i
].alive
then
1909 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1912 Obj
.lerp(gLerpFactor
, fX
, fY
);
1917 e_DrawAdv(SpriteID
, fX
, fY
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1921 procedure g_Player_RemoveAllCorpses();
1927 SetLength(gGibs
, MaxGibs
);
1928 SetLength(gShells
, MaxGibs
);
1932 if gCorpses
<> nil then
1933 for i
:= 0 to High(gCorpses
) do
1937 SetLength(gCorpses
, MaxCorpses
);
1940 procedure g_Player_Corpses_SaveState (st
: TStream
);
1944 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ
1946 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1948 // Êîëè÷åñòâî òðóïîâ
1949 utils
.writeInt(st
, LongInt(count
));
1951 if (count
= 0) then exit
;
1954 for i
:= 0 to High(gCorpses
) do
1956 if gCorpses
[i
] <> nil then
1959 utils
.writeStr(st
, gCorpses
[i
].FModelName
);
1961 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1962 // Ñîõðàíÿåì äàííûå òðóïà:
1963 gCorpses
[i
].SaveState(st
);
1969 procedure g_Player_Corpses_LoadState (st
: TStream
);
1977 g_Player_RemoveAllCorpses();
1979 // Êîëè÷åñòâî òðóïîâ:
1980 count
:= utils
.readLongInt(st
);
1981 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1983 if (count
= 0) then exit
;
1986 for i
:= 0 to count
-1 do
1989 str
:= utils
.readStr(st
);
1991 b
:= utils
.readBool(st
);
1993 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1994 // Çàãðóæàåì äàííûå òðóïà
1995 gCorpses
[i
].LoadState(st
);
2002 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
2004 procedure TPlayer
.BFGHit();
2006 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
2007 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
2008 if g_Game_IsServer
and g_Game_IsNet
then
2009 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
2010 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
2014 procedure TPlayer
.ChangeModel(ModelName
: string);
2016 locModel
: TPlayerModel
;
2018 locModel
:= g_PlayerModel_Get(ModelName
);
2019 if locModel
= nil then Exit
;
2025 procedure TPlayer
.SetModel(ModelName
: string);
2029 m
:= g_PlayerModel_Get(ModelName
);
2032 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
2033 m
:= g_PlayerModel_Get('doomer');
2036 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
2041 if FModel
<> nil then
2046 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2047 FModel
.Color
:= FColor
2049 FModel
.Color
:= TEAMCOLOR
[FTeam
];
2050 FModel
.SetWeapon(FCurrWeap
);
2051 FModel
.SetFlag(FFlag
);
2052 SetDirection(FDirection
);
2055 procedure TPlayer
.SetColor(Color
: TRGB
);
2058 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2059 if FModel
<> nil then FModel
.Color
:= Color
;
2064 function TPlayer
.GetColor(): TRGB
;
2066 result
:= FModel
.Color
;
2069 procedure TPlayer
.SetWeaponPrefs(Prefs
: Array of Byte);
2073 for i
:= WP_FIRST
to WP_LAST
+ 1 do
2075 if (Prefs
[i
] > WP_LAST
+ 1) then
2076 FWeapPreferences
[i
] := 0
2078 FWeapPreferences
[i
] := Prefs
[i
];
2082 procedure TPlayer
.SetWeaponPref(Weapon
, Pref
: Byte);
2084 if (Weapon
> WP_LAST
+ 1) then
2086 else if (Pref
<= WP_LAST
+ 1) and (Weapon
<= WP_LAST
+ 1) then
2087 FWeapPreferences
[Weapon
] := Pref
2088 else if (Weapon
<= WP_LAST
+ 1) and (Pref
> WP_LAST
+ 1) then
2089 FWeapPreferences
[Weapon
] := 0;
2092 function TPlayer
.GetWeaponPref(Weapon
: Byte) : Byte;
2094 if (Weapon
> WP_LAST
+ 1) then
2096 else if (FWeapPreferences
[Weapon
] > WP_LAST
+ 1) then
2099 result
:= FWeapPreferences
[Weapon
];
2102 function TPlayer
.GetMorePrefered() : Byte;
2104 testedWeap
, i
: Byte;
2106 testedWeap
:= FCurrWeap
;
2107 for i
:= WP_FIRST
to WP_LAST
do
2108 if FWeapon
[i
] and maySwitch(i
) and (FWeapPreferences
[i
] > FWeapPreferences
[testedWeap
]) then
2110 if (R_BERSERK
in FRulez
) and (FWeapPreferences
[WP_LAST
+ 1] > FWeapPreferences
[testedWeap
]) then
2111 testedWeap
:= WEAPON_KASTET
;
2112 result
:= testedWeap
;
2115 function TPlayer
.maySwitch(Weapon
: Byte) : Boolean;
2118 if (Weapon
= WEAPON_KASTET
) and (FSkipFist
<> 0) then
2120 if (FSkipFist
= 1) and (not (R_BERSERK
in FRulez
)) then
2123 else if (FSwitchToEmpty
= 0) and (not hasAmmoForShooting(Weapon
)) then
2127 procedure TPlayer
.SwitchTeam
;
2129 if g_Game_IsClient
then
2131 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
2133 if gGameOn
and FAlive
then
2134 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
2136 if FTeam
= TEAM_RED
then
2138 ChangeTeam(TEAM_BLUE
);
2139 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
2140 if g_Game_IsNet
then
2141 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
2145 ChangeTeam(TEAM_RED
);
2146 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
2147 if g_Game_IsNet
then
2148 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
2150 FPreferredTeam
:= FTeam
;
2153 procedure TPlayer
.ChangeTeam(Team
: Byte);
2160 TEAM_RED
, TEAM_BLUE
:
2161 FModel
.Color
:= TEAMCOLOR
[Team
];
2163 FModel
.Color
:= FColor
;
2165 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2166 MH_SEND_PlayerStats(FUID
);
2170 procedure TPlayer.CollideItem();
2175 if gItems = nil then Exit;
2176 if not FAlive then Exit;
2178 for i := 0 to High(gItems) do
2181 if (ItemType <> ITEM_NONE) and alive then
2182 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2183 PLAYER_RECT.Height, @Obj) then
2185 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2187 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2188 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2189 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2190 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2191 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2193 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2194 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2195 (gGameSettings.GameType = GT_SINGLE) and
2196 (g_Player_GetCount() > 1)) then
2197 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2203 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2205 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2206 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2210 constructor TPlayer
.Create();
2216 mEDamageType
:= HIT_SOME
;
2222 FSawSound
:= TPlayableSound
.Create();
2223 FSawSoundIdle
:= TPlayableSound
.Create();
2224 FSawSoundHit
:= TPlayableSound
.Create();
2225 FSawSoundSelect
:= TPlayableSound
.Create();
2226 FFlameSoundOn
:= TPlayableSound
.Create();
2227 FFlameSoundOff
:= TPlayableSound
.Create();
2228 FFlameSoundWork
:= TPlayableSound
.Create();
2229 FJetSoundFly
:= TPlayableSound
.Create();
2230 FJetSoundOn
:= TPlayableSound
.Create();
2231 FJetSoundOff
:= TPlayableSound
.Create();
2233 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2234 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2235 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2236 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2237 FFlameSoundOn
.SetByName('SOUND_WEAPON_FLAMEON');
2238 FFlameSoundOff
.SetByName('SOUND_WEAPON_FLAMEOFF');
2239 FFlameSoundWork
.SetByName('SOUND_WEAPON_FLAMEWORK');
2240 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2241 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2242 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2244 FSpectatePlayer
:= -1;
2248 FSavedStateNum
:= -1;
2256 FActualModelName
:= 'doomer';
2259 FObj
.Rect
:= PLAYER_RECT
;
2261 FBFGFireCounter
:= -1;
2262 FJustTeleported
:= False;
2265 FWaitForFirstSpawn
:= false;
2270 procedure TPlayer
.positionChanged (); inline;
2274 procedure TPlayer
.doDamage (v
: Integer);
2276 if (v
<= 0) then exit
;
2277 if (v
> 32767) then v
:= 32767;
2278 Damage(v
, 0, 0, 0, mEDamageType
);
2281 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2285 if (not g_Game_IsClient
) and (not FAlive
) then
2290 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2291 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2293 if not g_Game_IsClient
then
2296 if t
= HIT_TRAP
then
2298 // Ëîâóøêà óáèâàåò ñðàçó:
2300 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2302 if t
= HIT_SELF
then
2306 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2309 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2310 FMegaRulez
[MR_SUIT
] := 0;
2311 FMegaRulez
[MR_INVUL
] := 0;
2312 FMegaRulez
[MR_INVIS
] := 0;
2317 // Íî îò îñòàëüíîãî ñïàñàåò:
2318 if FMegaRulez
[MR_INVUL
] >= gTime
then
2325 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2326 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2327 (SpawnerUID
= FUID
) or
2328 (not SameTeam(FUID
, SpawnerUID
)) then
2330 FLastSpawnerUID
:= SpawnerUID
;
2332 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2333 if gBloodCount
> 0 then
2335 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2336 if value
div 4 <= c
then
2337 c
:= c
- (value
div 4)
2341 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2345 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2346 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2349 if t
= HIT_WATER
then
2351 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2352 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2354 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
2355 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
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 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2844 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2849 stat
:= g_Player_GetStats();
2854 for a
:= 0 to High(stat
) do
2855 if stat
[a
].Name
<> Name
then
2857 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2858 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2862 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2863 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2864 s
:= s
+IntToStr(Abs(Frags
-m
));
2866 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2867 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2870 if gLMSRespawn
> LMS_RESPAWN_NONE
then
2872 s
:= _lc
[I_GAME_WARMUP
];
2873 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2874 s
:= s
+ ': ' + IntToStr((gLMSRespawnTime
- gTime
) div 1000);
2875 e_CharFont_PrintEx(gMenuFont
, X
-64-tw
, SY
-32, s
, _RGB(0, 255, 0));
2877 else if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2879 s
:= IntToStr(Lives
);
2880 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2881 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2885 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2886 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2888 if R_BERSERK
in FRulez
then
2889 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2891 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2893 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2894 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2896 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2897 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2898 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2900 s
:= IntToStr(FArmor
);
2901 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2902 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2904 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2910 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2915 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2917 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2918 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2919 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2920 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2921 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2922 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2923 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2924 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2925 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2928 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2929 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2930 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2932 if R_KEY_RED
in FRulez
then
2933 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2935 if R_KEY_GREEN
in FRulez
then
2936 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2938 if R_KEY_BLUE
in FRulez
then
2939 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2941 if FJetFuel
> 0 then
2943 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2944 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2945 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2946 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2947 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2948 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2952 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2953 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2954 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2957 if gShowPing
and g_Game_IsClient
then
2959 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2960 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2966 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2967 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2968 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2971 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2972 s
:= _lc
[I_PLAYER_SPECT4
];
2973 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2974 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2975 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2981 procedure TPlayer
.DrawRulez();
2985 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2986 if (FMegaRulez
[MR_INVUL
] >= gTime
) and (FSpawnInvul
< gTime
) then
2988 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2989 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2994 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2995 191, 191, 191, 0, TBlending
.Invert
);
2998 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2999 if FMegaRulez
[MR_SUIT
] >= gTime
then
3001 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
3002 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
3007 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
3008 0, 96, 0, 200, TBlending
.None
);
3011 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
3012 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
3014 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
3015 255, 0, 0, 200, TBlending
.None
);
3019 procedure TPlayer
.DrawPain();
3023 if FPain
= 0 then Exit
;
3027 if a
< 15 then h
:= 0
3028 else if a
< 35 then h
:= 1
3029 else if a
< 55 then h
:= 2
3030 else if a
< 75 then h
:= 3
3031 else if a
< 95 then h
:= 4
3034 //if a > 255 then a := 255;
3036 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
3037 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
3040 procedure TPlayer
.DrawPickup();
3044 if FPickup
= 0 then Exit
;
3048 if a
< 15 then h
:= 1
3049 else if a
< 35 then h
:= 2
3050 else if a
< 55 then h
:= 3
3051 else if a
< 75 then h
:= 4
3054 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
3057 procedure TPlayer
.DoPunch();
3062 if FPunchAnim
<> nil then begin
3067 st
:= 'FRAMES_PUNCH';
3068 if R_BERSERK
in FRulez
then
3069 st
:= st
+ '_BERSERK';
3070 if FKeys
[KEY_UP
].Pressed
then
3072 else if FKeys
[KEY_DOWN
].Pressed
then
3074 g_Frames_Get(id
, st
);
3075 FPunchAnim
:= TAnimation
.Create(id
, False, 1);
3078 procedure TPlayer
.Fire();
3080 f
, DidFire
: Boolean;
3081 wx
, wy
, xd
, yd
: Integer;
3084 if g_Game_IsClient
then Exit
;
3085 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
3086 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
3094 if FReloading
[FCurrWeap
] <> 0 then Exit
;
3099 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
3100 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
3101 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
3102 yd
:= wy
+firediry();
3108 if R_BERSERK
in FRulez
then
3110 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
3111 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
3112 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
3115 locobj
.rect
.Width
:= 39;
3116 locobj
.rect
.Height
:= 52;
3117 locobj
.Vel
.X
:= (xd
-wx
) div 2;
3118 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
3119 locobj
.Accel
.X
:= xd
-wx
;
3120 locobj
.Accel
.y
:= yd
-wy
;
3122 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
3123 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
3125 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
3127 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
3131 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
3135 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3140 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
3141 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
3143 FSawSoundSelect
.Stop();
3145 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
3147 else if not FSawSoundHit
.IsPlaying() then
3149 FSawSoundSelect
.Stop();
3150 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
3153 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3159 if FAmmo
[A_BULLETS
] > 0 then
3161 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
3162 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3163 Dec(FAmmo
[A_BULLETS
]);
3164 FFireAngle
:= FAngle
;
3167 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3168 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3172 if FAmmo
[A_SHELLS
] > 0 then
3174 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3175 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
3176 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3177 Dec(FAmmo
[A_SHELLS
]);
3178 FFireAngle
:= FAngle
;
3182 FShellType
:= SHELL_SHELL
;
3186 if FAmmo
[A_SHELLS
] >= 2 then
3188 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
3189 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3190 Dec(FAmmo
[A_SHELLS
], 2);
3191 FFireAngle
:= FAngle
;
3195 FShellType
:= SHELL_DBLSHELL
;
3199 if FAmmo
[A_BULLETS
] > 0 then
3201 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
3202 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
3203 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3204 Dec(FAmmo
[A_BULLETS
]);
3205 FFireAngle
:= FAngle
;
3208 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3209 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3212 WEAPON_ROCKETLAUNCHER
:
3213 if FAmmo
[A_ROCKETS
] > 0 then
3215 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
3216 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3217 Dec(FAmmo
[A_ROCKETS
]);
3218 FFireAngle
:= FAngle
;
3224 if FAmmo
[A_CELLS
] > 0 then
3226 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
3227 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3228 Dec(FAmmo
[A_CELLS
]);
3229 FFireAngle
:= FAngle
;
3235 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
3237 FBFGFireCounter
:= 17;
3238 if not FNoReload
then
3239 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
3240 Dec(FAmmo
[A_CELLS
], 40);
3244 WEAPON_SUPERPULEMET
:
3245 if FAmmo
[A_SHELLS
] > 0 then
3247 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3248 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
3249 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3250 Dec(FAmmo
[A_SHELLS
]);
3251 FFireAngle
:= FAngle
;
3254 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3255 GameVelX
, GameVelY
-2, SHELL_SHELL
);
3258 WEAPON_FLAMETHROWER
:
3259 if FAmmo
[A_FUEL
] > 0 then
3261 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
3263 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3265 FFireAngle
:= FAngle
;
3272 if g_Game_IsNet
and g_Game_IsServer
then MH_SEND_PlayerStats(FUID
);
3276 if g_Game_IsNet
then
3280 if FCurrWeap
<> WEAPON_BFG
then
3281 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
3283 if not FNoReload
then
3284 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
3287 MH_SEND_PlayerStats(FUID
);
3292 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
3293 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
3294 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
3297 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
3300 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
3301 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
3302 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
3303 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
3304 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
3309 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
3311 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
3312 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
3313 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
3316 procedure TPlayer
.FlamerOn
;
3318 FFlameSoundOff
.Stop();
3319 FFlameSoundOff
.SetPosition(0);
3322 if (not FFlameSoundOn
.IsPlaying()) and (not FFlameSoundWork
.IsPlaying()) then
3323 FFlameSoundWork
.PlayAt(FObj
.X
, FObj
.Y
);
3327 FFlameSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3332 procedure TPlayer
.FlamerOff
;
3336 FFlameSoundOn
.Stop();
3337 FFlameSoundOn
.SetPosition(0);
3338 FFlameSoundWork
.Stop();
3339 FFlameSoundWork
.SetPosition(0);
3340 FFlameSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3345 procedure TPlayer
.JetpackOn
;
3349 FJetSoundOn
.SetPosition(0);
3350 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3354 procedure TPlayer
.JetpackOff
;
3358 FJetSoundOff
.SetPosition(0);
3359 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3362 procedure TPlayer
.CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
3364 if Timeout
<= 0 then
3366 if (FMegaRulez
[MR_SUIT
] > gTime
) or (FMegaRulez
[MR_INVUL
] > gTime
) then
3367 exit
; // Íå çàãîðàåìñÿ êîãäà åñòü çàùèòà
3368 if g_Obj_CollidePanel(@FObj
, 0, 0, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
) then
3369 exit
; // Íå ïîäãîðàåì â âîäå íà âñÿêèé ñëó÷àé
3370 if FFireTime
<= 0 then
3371 g_Sound_PlayExAt('SOUND_IGNITE', FObj
.X
, FObj
.Y
);
3372 FFireTime
:= Timeout
;
3373 FFireAttacker
:= Attacker
;
3374 if g_Game_IsNet
and g_Game_IsServer
then
3375 MH_SEND_PlayerStats(FUID
);
3378 procedure TPlayer
.Jump();
3380 if gFly
or FJetpack
then
3382 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3383 if FObj
.Vel
.Y
> -VEL_FLY
then
3384 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3387 if FJetFuel
> 0 then
3389 if (FJetFuel
< 1) and g_Game_IsServer
then
3393 if g_Game_IsNet
then
3394 MH_SEND_PlayerStats(FUID
);
3400 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3402 FCanJetpack
:= False;
3404 // Ïðûãàåì èëè âñïëûâàåì:
3405 if (CollideLevel(0, 1) or
3406 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3407 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3408 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3410 FObj
.Vel
.Y
:= -VEL_JUMP
;
3411 FCanJetpack
:= False;
3415 if BodyInLiquid(0, 0) then
3416 FObj
.Vel
.Y
:= -VEL_SW
3417 else if (FJetFuel
> 0) and FCanJetpack
and
3418 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3422 if g_Game_IsNet
then
3423 MH_SEND_PlayerStats(FUID
);
3428 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3430 a
, i
, k
, ab
, ar
: Byte;
3434 srv
, netsrv
: Boolean;
3440 procedure PushItem(t
: Byte);
3444 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3445 it
:= g_Items_ByIdx(id
);
3446 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3448 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3449 (FObj
.Vel
.Y
div 2)-Random(9));
3450 it
.positionChanged(); // this updates spatial accelerators
3454 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3456 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3457 (FObj
.Vel
.Y
div 2)-Random(6));
3459 else // -3..+3; -3..0
3461 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3462 (FObj
.Vel
.Y
div 2)-Random(4));
3464 it
.positionChanged(); // this updates spatial accelerators
3467 if g_Game_IsNet
and g_Game_IsServer
then
3468 MH_SEND_ItemSpawn(True, id
);
3472 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3473 Srv
:= g_Game_IsServer
;
3474 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3475 if Srv
then FDeath
:= FDeath
+ 1;
3480 if not FPhysics
then
3486 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3488 if FLives
> 0 then FLives
:= FLives
- 1;
3489 if FLives
= 0 then FNoRespawn
:= True;
3492 // Íîìåð òèïà ñìåðòè:
3495 K_SIMPLEKILL
: a
:= 1;
3497 K_EXTRAHARDKILL
: a
:= 3;
3502 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3504 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3511 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3513 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3514 K_EXTRAHARDKILL
, K_FALLKILL
:
3515 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3518 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3522 K_HARDKILL
, K_EXTRAHARDKILL
:
3526 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3527 if (KillType
<> K_FALLKILL
) and (Srv
) then
3528 g_Monsters_killedp();
3530 if SpawnerUID
= FUID
then
3534 if gGameSettings
.GameMode
= GM_TDM
then
3535 Dec(gTeamStat
[FTeam
].Score
);
3536 if DoFrags
or (gGameSettings
.GameMode
= GM_TDM
) then
3542 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3545 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3546 begin // Óáèò äðóãèì èãðîêîì
3547 KP
:= g_Player_Get(SpawnerUID
);
3548 if (KP
<> nil) and Srv
then
3550 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3551 if SameTeam(FUID
, SpawnerUID
) then
3561 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3562 Inc(gTeamStat
[KP
.Team
].Score
,
3563 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3565 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3568 plr
:= g_Player_Get(SpawnerUID
);
3576 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3580 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3584 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3589 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3590 begin // Óáèò ìîíñòðîì
3591 mon
:= g_Monsters_ByUID(SpawnerUID
);
3595 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
3599 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3603 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3607 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3612 else // Îñîáûå òèïû ñìåðòè
3615 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3616 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3617 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3618 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3619 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3620 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3626 for a
:= WP_FIRST
to WP_LAST
do
3630 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3631 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3632 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3633 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3634 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3635 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3636 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3637 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3638 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3647 if R_ITEM_BACKPACK
in FRulez
then
3648 PushItem(ITEM_AMMO_BACKPACK
);
3650 // Âûáðîñ ðàêåòíîãî ðàíöà:
3651 if FJetFuel
> 0 then
3652 PushItem(ITEM_JETPACK
);
3655 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) or
3656 (not LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
)) then
3658 if R_KEY_RED
in FRulez
then
3659 PushItem(ITEM_KEY_RED
);
3661 if R_KEY_GREEN
in FRulez
then
3662 PushItem(ITEM_KEY_GREEN
);
3664 if R_KEY_BLUE
in FRulez
then
3665 PushItem(ITEM_KEY_BLUE
);
3669 DropFlag(KillType
= K_FALLKILL
);
3672 FCorpse
:= g_Player_CreateCorpse(Self
);
3674 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3675 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3681 for i
:= Low(gPlayers
) to High(gPlayers
) do
3683 if gPlayers
[i
] = nil then continue
;
3684 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3687 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3688 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3693 OldLR
:= gLMSRespawn
;
3694 if (gGameSettings
.GameMode
= GM_COOP
) then
3698 // everyone is dead, restart the map
3699 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3701 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3702 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3703 gLMSRespawnTime
:= gTime
+ 5000;
3705 else if (a
= 1) then
3707 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3708 if (gPlayers
[k
] = gPlayer1
) or
3709 (gPlayers
[k
] = gPlayer2
) then
3710 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3711 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3712 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3715 else if (gGameSettings
.GameMode
= GM_TDM
) then
3717 if (ab
= 0) and (ar
<> 0) then
3720 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3722 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3723 Inc(gTeamStat
[TEAM_RED
].Score
);
3724 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3725 gLMSRespawnTime
:= gTime
+ 5000;
3727 else if (ar
= 0) and (ab
<> 0) then
3730 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3732 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3733 Inc(gTeamStat
[TEAM_BLUE
].Score
);
3734 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3735 gLMSRespawnTime
:= gTime
+ 5000;
3737 else if (ar
= 0) and (ab
= 0) then
3740 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3742 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3743 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3744 gLMSRespawnTime
:= gTime
+ 5000;
3747 else if (gGameSettings
.GameMode
= GM_DM
) then
3751 if gPlayers
[k
] <> nil then
3754 // survivor is the winner
3755 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3757 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3760 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3761 gLMSRespawnTime
:= gTime
+ 5000;
3763 else if (a
= 0) then
3765 // everyone is dead, restart the map
3766 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3768 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3769 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3770 gLMSRespawnTime
:= gTime
+ 5000;
3773 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3775 if NetMode
= NET_SERVER
then
3776 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
)
3778 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3784 MH_SEND_PlayerStats(FUID
);
3785 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3786 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3789 if srv
and FNoRespawn
then Spectate(True);
3790 FWantsInGame
:= True;
3793 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3795 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3796 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3799 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3801 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3802 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3805 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3807 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3808 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3809 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3810 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3811 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3812 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3813 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3814 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3817 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3819 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3820 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3821 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3822 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3825 procedure TPlayer
.ProcessWeaponAction(Action
: Byte);
3827 if g_Game_IsClient
then Exit
;
3829 WP_PREV
: PrevWeapon();
3830 WP_NEXT
: NextWeapon();
3834 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3836 if g_Game_IsClient
then Exit
;
3837 if Weapon
> High(FWeapon
) then Exit
;
3838 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3841 procedure TPlayer
.resetWeaponQueue ();
3844 FNextWeapDelay
:= 0;
3847 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3851 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3852 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
3853 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
3854 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3855 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3856 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3857 else result
:= (weapon
< length(FWeapon
));
3861 function TPlayer
.hasAmmoForShooting (weapon
: Byte): Boolean;
3865 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3866 WEAPON_SHOTGUN1
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
3867 WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 1);
3868 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
3869 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3870 WEAPON_PLASMA
: result
:= (FAmmo
[A_CELLS
] > 0);
3871 WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] >= 40);
3872 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3873 else result
:= (weapon
< length(FWeapon
));
3877 function TPlayer
.shouldSwitch (weapon
: Byte; hadWeapon
: Boolean): Boolean;
3880 if (weapon
> WP_LAST
+ 1) then
3885 if (FWeapSwitchMode
= 1) and not hadWeapon
then
3887 else if (FWeapSwitchMode
= 2) then
3888 result
:= (FWeapPreferences
[weapon
] > FWeapPreferences
[FCurrWeap
]);
3891 // return 255 for "no switch"
3892 function TPlayer
.getNextWeaponIndex (): Byte;
3895 wantThisWeapon
: array[0..64] of Boolean;
3896 wwc
: Integer = 0; //HACK!
3899 result
:= 255; // default result: "no switch"
3900 //e_LogWriteFln('FSWITCHTOEMPTY: %s', [FSwitchToEmpty], TMsgType.Notify);
3901 // had weapon cycling on previous frame? remove that flag
3902 if (FNextWeap
and $2000) <> 0 then
3904 FNextWeap
:= FNextWeap
and $1FFF;
3905 FNextWeapDelay
:= 0;
3907 // cycling has priority
3908 if (FNextWeap
and $C000) <> 0 then
3910 if (FNextWeap
and $8000) <> 0 then
3914 FNextWeap
:= FNextWeap
or $2000; // we need this
3915 if FNextWeapDelay
> 0 then
3916 exit
; // cooldown time
3918 for i
:= 0 to High(FWeapon
) do
3920 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3921 if FWeapon
[cwi
] and maySwitch(cwi
) then
3923 //e_LogWriteFln(' SWITCH: cur=%d; new=%d %s %s', [FCurrWeap, cwi, FSwitchToEmpty, hasAmmoForWeapon(cwi)], TMsgType.Notify);
3924 result
:= Byte(cwi
);
3925 FNextWeapDelay
:= WEAPON_DELAY
;
3933 for i
:= 0 to High(wantThisWeapon
) do
3934 wantThisWeapon
[i
] := false;
3935 for i
:= 0 to High(FWeapon
) do
3936 if (FNextWeap
and (1 shl i
)) <> 0 then
3938 wantThisWeapon
[i
] := true;
3942 // exclude currently selected weapon from the set
3943 wantThisWeapon
[FCurrWeap
] := false;
3944 // slow down alterations a little
3947 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3948 // more than one weapon requested, assume "alteration" and check alteration delay
3949 if FNextWeapDelay
> 0 then
3955 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3956 // but clear all counters if no weapon should be switched
3962 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3963 // try weapons in descending order
3964 for i
:= High(FWeapon
) downto 0 do
3966 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3971 FNextWeapDelay
:= WEAPON_DELAY
* 2; // anyway, 'cause why not
3972 //e_LogWriteFln('FOUND %s %s %s', [result, FSwitchToEmpty, hasAmmoForWeapon(i)], TMsgType.Notify);
3976 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3980 procedure TPlayer
.RealizeCurrentWeapon();
3981 function switchAllowed (): Boolean;
3986 if FBFGFireCounter
<> -1 then
3988 if FTime
[T_SWITCH
] > gTime
then
3990 for i
:= WP_FIRST
to WP_LAST
do
3991 if FReloading
[i
] > 0 then
3999 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
4000 //FNextWeap := FNextWeap and $1FFF;
4001 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
4003 if not switchAllowed
then
4005 //HACK for weapon cycling
4006 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
4010 nw
:= getNextWeaponIndex();
4012 if nw
= 255 then exit
; // don't reset anything here
4013 if nw
> High(FWeapon
) then
4015 // don't forget to reset queue here!
4016 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
4024 FTime
[T_SWITCH
] := gTime
+156;
4025 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
4026 FModel
.SetWeapon(FCurrWeap
);
4027 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
4031 procedure TPlayer
.NextWeapon();
4033 if g_Game_IsClient
then Exit
;
4037 procedure TPlayer
.PrevWeapon();
4039 if g_Game_IsClient
then Exit
;
4043 procedure TPlayer
.SetWeapon(W
: Byte);
4045 if FCurrWeap
<> W
then
4046 if W
= WEAPON_SAW
then
4047 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
4050 FModel
.SetWeapon(CurrWeap
);
4054 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
4057 switchWeapon
: Byte = 255;
4058 hadWeapon
: Boolean = False;
4061 if g_Game_IsClient
then Exit
;
4063 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
4064 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
4068 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
4070 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
4074 if gFlash
= 2 then Inc(FPickup
, 5);
4078 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
4080 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
4084 if gFlash
= 2 then Inc(FPickup
, 5);
4088 if FArmor
< PLAYER_AP_SOFT
then
4090 FArmor
:= PLAYER_AP_SOFT
;
4093 if gFlash
= 2 then Inc(FPickup
, 5);
4097 if FArmor
< PLAYER_AP_LIMIT
then
4099 FArmor
:= PLAYER_AP_LIMIT
;
4102 if gFlash
= 2 then Inc(FPickup
, 5);
4106 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
4108 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
4112 if gFlash
= 2 then Inc(FPickup
, 5);
4116 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) or (FFireTime
> 0) then
4118 if FHealth
< PLAYER_HP_LIMIT
then
4119 FHealth
:= PLAYER_HP_LIMIT
;
4120 if FArmor
< PLAYER_AP_LIMIT
then
4121 FArmor
:= PLAYER_AP_LIMIT
;
4125 if gFlash
= 2 then Inc(FPickup
, 5);
4129 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
4131 hadWeapon
:= FWeapon
[WEAPON_SAW
];
4132 switchWeapon
:= WEAPON_SAW
;
4133 FWeapon
[WEAPON_SAW
] := True;
4135 if gFlash
= 2 then Inc(FPickup
, 5);
4136 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4139 ITEM_WEAPON_SHOTGUN1
:
4140 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
4142 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
4143 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
4144 hadWeapon
:= FWeapon
[WEAPON_SHOTGUN1
];
4145 switchWeapon
:= WEAPON_SHOTGUN1
;
4146 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4147 FWeapon
[WEAPON_SHOTGUN1
] := True;
4149 if gFlash
= 2 then Inc(FPickup
, 5);
4150 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4153 ITEM_WEAPON_SHOTGUN2
:
4154 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
4156 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
4157 hadWeapon
:= FWeapon
[WEAPON_SHOTGUN2
];
4158 switchWeapon
:= WEAPON_SHOTGUN2
;
4159 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4160 FWeapon
[WEAPON_SHOTGUN2
] := True;
4162 if gFlash
= 2 then Inc(FPickup
, 5);
4163 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4166 ITEM_WEAPON_CHAINGUN
:
4167 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
4169 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
4170 hadWeapon
:= FWeapon
[WEAPON_CHAINGUN
];
4171 switchWeapon
:= WEAPON_CHAINGUN
;
4172 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4173 FWeapon
[WEAPON_CHAINGUN
] := True;
4175 if gFlash
= 2 then Inc(FPickup
, 5);
4176 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4179 ITEM_WEAPON_ROCKETLAUNCHER
:
4180 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
4182 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
4183 switchWeapon
:= WEAPON_ROCKETLAUNCHER
;
4184 hadWeapon
:= FWeapon
[WEAPON_ROCKETLAUNCHER
];
4185 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
4186 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
4188 if gFlash
= 2 then Inc(FPickup
, 5);
4189 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4193 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
4195 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
4196 switchWeapon
:= WEAPON_PLASMA
;
4197 hadWeapon
:= FWeapon
[WEAPON_PLASMA
];
4198 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4199 FWeapon
[WEAPON_PLASMA
] := True;
4201 if gFlash
= 2 then Inc(FPickup
, 5);
4202 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4206 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
4208 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
4209 switchWeapon
:= WEAPON_BFG
;
4210 hadWeapon
:= FWeapon
[WEAPON_BFG
];
4211 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4212 FWeapon
[WEAPON_BFG
] := True;
4214 if gFlash
= 2 then Inc(FPickup
, 5);
4215 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4218 ITEM_WEAPON_SUPERPULEMET
:
4219 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
4221 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
4222 switchWeapon
:= WEAPON_SUPERPULEMET
;
4223 hadWeapon
:= FWeapon
[WEAPON_SUPERPULEMET
];
4224 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4225 FWeapon
[WEAPON_SUPERPULEMET
] := True;
4227 if gFlash
= 2 then Inc(FPickup
, 5);
4228 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4231 ITEM_WEAPON_FLAMETHROWER
:
4232 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
4234 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
4235 switchWeapon
:= WEAPON_FLAMETHROWER
;
4236 hadWeapon
:= FWeapon
[WEAPON_FLAMETHROWER
];
4237 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4238 FWeapon
[WEAPON_FLAMETHROWER
] := True;
4240 if gFlash
= 2 then Inc(FPickup
, 5);
4241 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4245 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4247 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4250 if gFlash
= 2 then Inc(FPickup
, 5);
4253 ITEM_AMMO_BULLETS_BOX
:
4254 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4256 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4259 if gFlash
= 2 then Inc(FPickup
, 5);
4263 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4265 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4268 if gFlash
= 2 then Inc(FPickup
, 5);
4271 ITEM_AMMO_SHELLS_BOX
:
4272 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4274 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
4277 if gFlash
= 2 then Inc(FPickup
, 5);
4281 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4283 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4286 if gFlash
= 2 then Inc(FPickup
, 5);
4289 ITEM_AMMO_ROCKET_BOX
:
4290 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4292 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
4295 if gFlash
= 2 then Inc(FPickup
, 5);
4299 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4301 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4304 if gFlash
= 2 then Inc(FPickup
, 5);
4308 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4310 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4313 if gFlash
= 2 then Inc(FPickup
, 5);
4317 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4319 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4322 if gFlash
= 2 then Inc(FPickup
, 5);
4326 if not(R_ITEM_BACKPACK
in FRulez
) or
4327 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4328 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4329 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4330 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4331 (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) then
4333 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4334 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4335 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4336 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4337 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4339 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4340 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4341 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4342 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4343 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4344 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4345 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4346 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4347 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4348 IncMax(FAmmo
[A_FUEL
], 50, FMaxAmmo
[A_FUEL
]);
4350 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
4353 if gFlash
= 2 then Inc(FPickup
, 5);
4357 if not(R_KEY_RED
in FRulez
) then
4359 Include(FRulez
, R_KEY_RED
);
4361 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4362 if gFlash
= 2 then Inc(FPickup
, 5);
4363 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4367 if not(R_KEY_GREEN
in FRulez
) then
4369 Include(FRulez
, R_KEY_GREEN
);
4371 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4372 if gFlash
= 2 then Inc(FPickup
, 5);
4373 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4377 if not(R_KEY_BLUE
in FRulez
) then
4379 Include(FRulez
, R_KEY_BLUE
);
4381 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4382 if gFlash
= 2 then Inc(FPickup
, 5);
4383 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4387 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4389 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4393 if gFlash
= 2 then Inc(FPickup
, 5);
4397 if FAir
< AIR_MAX
then
4402 if gFlash
= 2 then Inc(FPickup
, 5);
4407 if not (R_BERSERK
in FRulez
) then
4409 Include(FRulez
, R_BERSERK
);
4410 if (FBFGFireCounter
= -1) then
4412 FCurrWeap
:= WEAPON_KASTET
;
4414 FModel
.SetWeapon(WEAPON_KASTET
);
4419 if gFlash
= 2 then Inc(FPickup
, 5);
4421 FBerserk
:= gTime
+30000;
4426 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
4428 if FHealth
< PLAYER_HP_SOFT
then FHealth
:= PLAYER_HP_SOFT
;
4429 FBerserk
:= gTime
+30000;
4437 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4439 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4443 if gFlash
= 2 then Inc(FPickup
, 5);
4447 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
4449 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4453 if gFlash
= 2 then Inc(FPickup
, 5);
4457 if FArmor
< PLAYER_AP_LIMIT
then
4459 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4462 if gFlash
= 2 then Inc(FPickup
, 5);
4466 if FJetFuel
< JET_MAX
then
4468 FJetFuel
:= JET_MAX
;
4471 if gFlash
= 2 then Inc(FPickup
, 5);
4475 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4477 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4480 if gFlash
= 2 then Inc(FPickup
, 5);
4484 if (shouldSwitch(switchWeapon
, hadWeapon
)) then
4485 QueueWeaponSwitch(switchWeapon
);
4488 procedure TPlayer
.Touch();
4492 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4495 // Áðîñèòü ôëàã òîâàðèùó:
4496 if gGameSettings
.GameMode
= GM_CTF
then
4501 procedure TPlayer
.Push(vx
, vy
: Integer);
4503 if (not FPhysics
) and FGhost
then
4505 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4506 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4507 if g_Game_IsNet
and g_Game_IsServer
then
4508 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4511 procedure TPlayer
.Reset(Force
: Boolean);
4517 FTime
[T_RESPAWN
] := 0;
4518 FTime
[T_FLAGCAP
] := 0;
4534 FSpectator
:= False;
4537 FSpectatePlayer
:= -1;
4538 FNoRespawn
:= False;
4540 FLives
:= gGameSettings
.MaxLives
;
4545 procedure TPlayer
.SoftReset();
4553 FBFGFireCounter
:= -1;
4561 SetAction(A_STAND
, True);
4564 function TPlayer
.GetRespawnPoint(): Byte;
4569 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4571 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4572 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4574 if Self
= gPlayer1
then
4576 // player 1 should try to spawn on the player 1 point
4577 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) > 0 then
4578 Exit(RESPAWNPOINT_PLAYER1
)
4579 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) > 0 then
4580 Exit(RESPAWNPOINT_PLAYER2
);
4582 else if Self
= gPlayer2
then
4584 // player 2 should try to spawn on the player 2 point
4585 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) > 0 then
4586 Exit(RESPAWNPOINT_PLAYER2
)
4587 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) > 0 then
4588 Exit(RESPAWNPOINT_PLAYER1
);
4592 // other players randomly pick either the first or the second point
4593 c
:= IfThen((Random(2) = 0), RESPAWNPOINT_PLAYER1
, RESPAWNPOINT_PLAYER2
);
4594 if g_Map_GetPointCount(c
) > 0 then
4596 // try the other one
4597 c
:= IfThen((c
= RESPAWNPOINT_PLAYER1
), RESPAWNPOINT_PLAYER2
, RESPAWNPOINT_PLAYER1
);
4598 if g_Map_GetPointCount(c
) > 0 then
4604 if gGameSettings
.GameMode
= GM_DM
then
4606 // try DM points first
4607 if g_Map_GetPointCount(RESPAWNPOINT_DM
) > 0 then
4608 Exit(RESPAWNPOINT_DM
);
4612 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4614 // try team points first
4615 c
:= RESPAWNPOINT_DM
;
4616 if FTeam
= TEAM_RED
then
4617 c
:= RESPAWNPOINT_RED
4618 else if FTeam
= TEAM_BLUE
then
4619 c
:= RESPAWNPOINT_BLUE
;
4620 if g_Map_GetPointCount(c
) > 0 then
4624 // still haven't found a spawnpoint, try random shit
4625 Result
:= g_Map_GetRandomPointType();
4628 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4630 RespawnPoint
: TRespawnPoint
;
4638 FBFGFireCounter
:= -1;
4645 if not g_Game_IsServer
then
4649 FWantsInGame
:= True;
4650 FJustTeleported
:= True;
4653 FTime
[T_RESPAWN
] := 0;
4657 // if server changes MaxLives we gotta be ready
4658 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4660 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4661 if FTime
[T_RESPAWN
] > gTime
then
4664 // Ïðîñðàë âñå æèçíè:
4667 if not FSpectator
then Spectate(True);
4668 FWantsInGame
:= True;
4672 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4673 begin // "Ñâîÿ èãðà"
4674 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4675 FRulez
:= FRulez
-[R_BERSERK
];
4677 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4679 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4680 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4683 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4684 c
:= GetRespawnPoint();
4689 // Âîñêðåøåíèå áåç îðóæèÿ:
4692 FHealth
:= Round(PLAYER_HP_SOFT
* (FHandicap
/ 100));
4698 for a
:= WP_FIRST
to WP_LAST
do
4700 FWeapon
[a
] := False;
4704 FWeapon
[WEAPON_PISTOL
] := True;
4705 FWeapon
[WEAPON_KASTET
] := True;
4706 FCurrWeap
:= WEAPON_PISTOL
;
4709 FModel
.SetWeapon(FCurrWeap
);
4711 for b
:= A_BULLETS
to A_HIGH
do
4714 FAmmo
[A_BULLETS
] := 50;
4716 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4717 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4718 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4719 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4720 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4722 if (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) and
4723 LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
) then
4724 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4729 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4730 if not g_Map_GetPoint(c
, RespawnPoint
) then
4732 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4736 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4737 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4738 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4739 FObj
.oldX
:= FObj
.X
; // don't interpolate after respawn
4740 FObj
.oldY
:= FObj
.Y
;
4746 FDirection
:= RespawnPoint
.Direction
;
4747 if FDirection
= TDirection
.D_LEFT
then
4752 SetAction(A_STAND
, True);
4753 FModel
.Direction
:= FDirection
;
4755 for a
:= Low(FTime
) to High(FTime
) do
4758 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4761 // Respawn invulnerability
4762 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.SpawnInvul
> 0) then
4764 FMegaRulez
[MR_INVUL
] := gTime
+ gGameSettings
.SpawnInvul
* 1000;
4765 FSpawnInvul
:= FMegaRulez
[MR_INVUL
];
4770 FCanJetpack
:= False;
4776 // Àíèìàöèÿ âîçðîæäåíèÿ:
4777 if (not gLoadGameMode
) and (not Silent
) then
4778 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4780 Anim
:= TAnimation
.Create(ID
, False, 3);
4781 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4782 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4786 FSpectator
:= False;
4789 FSpectatePlayer
:= -1;
4792 if (gPlayer1
= nil) and (gSpectLatchPID1
= FUID
) then
4794 if (gPlayer2
= nil) and (gSpectLatchPID2
= FUID
) then
4797 if g_Game_IsNet
then
4799 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4800 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4802 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4803 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4808 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4811 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4812 else if (not NoMove
) then
4814 GameX
:= gMapInfo
.Width
div 2;
4815 GameY
:= gMapInfo
.Height
div 2;
4824 FWantsInGame
:= False;
4830 if Self
= gPlayer1
then
4832 gSpectLatchPID1
:= FUID
;
4835 else if Self
= gPlayer2
then
4837 gSpectLatchPID2
:= FUID
;
4842 if g_Game_IsNet
then
4843 MH_SEND_PlayerStats(FUID
);
4846 procedure TPlayer
.SwitchNoClip
;
4850 FGhost
:= not FGhost
;
4851 FPhysics
:= not FGhost
;
4863 procedure TPlayer
.Run(Direction
: TDirection
);
4867 if MAX_RUNVEL
> 8 then
4871 if Direction
= TDirection
.D_LEFT
then
4873 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4874 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4877 if FObj
.Vel
.X
< MAX_RUNVEL
then
4878 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4880 // Âîçìîæíî, ïèíàåì êóñêè:
4881 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4883 b
:= Abs(FObj
.Vel
.X
);
4884 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4885 for a
:= 0 to High(gGibs
) do
4887 if gGibs
[a
].alive
and
4888 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4889 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4892 if FObj
.Vel
.X
< 0 then
4894 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4898 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4900 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4908 procedure TPlayer
.SeeDown();
4910 SetAction(A_SEEDOWN
);
4912 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4914 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4917 procedure TPlayer
.SeeUp();
4921 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4923 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4926 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4934 A_ATTACK
: Prior
:= 2;
4935 A_SEEUP
: Prior
:= 1;
4936 A_SEEDOWN
: Prior
:= 1;
4937 A_ATTACKUP
: Prior
:= 2;
4938 A_ATTACKDOWN
: Prior
:= 2;
4943 if (Prior
> FActionPrior
) or Force
then
4944 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4946 FActionPrior
:= Prior
;
4947 FActionAnim
:= Action
;
4948 FActionForce
:= Force
;
4949 FActionChanged
:= True;
4952 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4955 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4957 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4958 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4959 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4960 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4963 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4970 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4972 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4973 if g_Game_IsServer
and g_Game_IsNet
then
4974 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4978 FJustTeleported
:= True;
4983 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4985 Anim
:= TAnimation
.Create(ID
, False, 3);
4988 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4989 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4990 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4991 if g_Game_IsServer
and g_Game_IsNet
then
4992 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4993 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4997 FObj
.X
:= X
-PLAYER_RECT
.X
;
4998 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4999 FObj
.oldX
:= FObj
.X
; // don't interpolate after respawn
5000 FObj
.oldY
:= FObj
.Y
;
5001 if FAlive
and FGhost
then
5007 if not g_Game_IsNet
then
5011 SetDirection(TDirection
.D_LEFT
);
5017 SetDirection(TDirection
.D_RIGHT
);
5023 if FDirection
= TDirection
.D_RIGHT
then
5025 SetDirection(TDirection
.D_LEFT
);
5030 SetDirection(TDirection
.D_RIGHT
);
5036 if not silent
and (Anim
<> nil) then
5038 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
5039 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
5042 if g_Game_IsServer
and g_Game_IsNet
then
5043 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
5044 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
5051 function nonz(a
: Single): Single;
5059 function TPlayer
.refreshCorpse(): Boolean;
5065 if FAlive
or FSpectator
then
5067 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
5069 for i
:= 0 to High(gCorpses
) do
5070 if gCorpses
[i
] <> nil then
5071 if gCorpses
[i
].FPlayerUID
= FUID
then
5079 function TPlayer
.getCameraObj(): TObj
;
5081 if (not FAlive
) and (not FSpectator
) and
5082 (FCorpse
>= 0) and (FCorpse
< Length(gCorpses
)) and
5083 (gCorpses
[FCorpse
] <> nil) and (gCorpses
[FCorpse
].FPlayerUID
= FUID
) then
5085 gCorpses
[FCorpse
].FObj
.slopeUpLeft
:= FObj
.slopeUpLeft
;
5086 Result
:= gCorpses
[FCorpse
].FObj
;
5094 procedure TPlayer
.PreUpdate();
5096 FSlopeOld
:= FObj
.slopeUpLeft
;
5097 FIncCamOld
:= FIncCam
;
5098 FObj
.oldX
:= FObj
.X
;
5099 FObj
.oldY
:= FObj
.Y
;
5102 procedure TPlayer
.Update();
5105 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
5106 blockmon
, headwater
, dospawn
: Boolean;
5111 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
5112 AnyServer
:= g_Game_IsServer
;
5114 if g_Game_IsClient
and (NetInterpLevel
> 0) then
5115 DoLerp(NetInterpLevel
+ 1)
5121 if (FClientID
>= 0) and (NetClients
[FClientID
].Peer
<> nil) then
5123 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
5124 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
5125 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
5134 if FAlive
and (FPunchAnim
<> nil) then
5135 FPunchAnim
.Update();
5137 if FAlive
and (gFly
or FJetpack
) then
5140 if FDirection
= TDirection
.D_LEFT
then
5145 if FAlive
and (not FGhost
) then
5147 if FKeys
[KEY_UP
].Pressed
then
5149 if FKeys
[KEY_DOWN
].Pressed
then
5153 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
5156 i
:= g_basic
.Sign(FIncCam
);
5157 FIncCam
:= Abs(FIncCam
);
5158 DecMin(FIncCam
, 5, 0);
5159 FIncCam
:= FIncCam
*i
;
5162 if gTime
mod (GAME_TICK
*2) <> 0 then
5164 if (FObj
.Vel
.X
= 0) and FAlive
then
5166 if FKeys
[KEY_LEFT
].Pressed
then
5167 Run(TDirection
.D_LEFT
);
5168 if FKeys
[KEY_RIGHT
].Pressed
then
5169 Run(TDirection
.D_RIGHT
);
5174 g_Obj_Move(@FObj
, True, True, True);
5175 positionChanged(); // this updates spatial accelerators
5181 FActionChanged
:= False;
5185 // Let alive player do some actions
5186 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
5187 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
5188 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire()
5194 if NetServer
then MH_SEND_PlayerStats(FUID
);
5197 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
5198 if FKeys
[KEY_JUMP
].Pressed
then Jump()
5201 if AnyServer
and FJetpack
then
5205 if NetServer
then MH_SEND_PlayerStats(FUID
);
5207 FCanJetpack
:= True;
5214 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
5216 if FKeys
[k
].Pressed
then
5224 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5227 if (FTime
[T_RESPAWN
] <= gTime
) and
5228 gGameOn
and (not FAlive
) then
5230 if (g_Player_GetCount() > 1) then
5234 gExit
:= EXIT_RESTART
;
5239 // Dead spectator actions
5242 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
5243 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
5247 if (FSpectatePlayer
>= High(gPlayers
)) then
5248 FSpectatePlayer
:= -1
5252 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
5253 if gPlayers
[I
] <> nil then
5254 if gPlayers
[I
].alive
then
5255 if gPlayers
[I
].UID
<> FUID
then
5257 FSpectatePlayer
:= I
;
5262 if not SetSpect
then FSpectatePlayer
:= -1;
5273 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5275 FYTo
:= FObj
.Y
- 32;
5276 FSpectatePlayer
:= -1;
5278 if FKeys
[KEY_DOWN
].Pressed
then
5280 FYTo
:= FObj
.Y
+ 32;
5281 FSpectatePlayer
:= -1;
5283 if FKeys
[KEY_LEFT
].Pressed
then
5285 FXTo
:= FObj
.X
- 32;
5286 FSpectatePlayer
:= -1;
5288 if FKeys
[KEY_RIGHT
].Pressed
then
5290 FXTo
:= FObj
.X
+ 32;
5291 FSpectatePlayer
:= -1;
5294 if (FXTo
< -64) then
5296 else if (FXTo
> gMapInfo
.Width
+ 32) then
5297 FXTo
:= gMapInfo
.Width
+ 32;
5298 if (FYTo
< -72) then
5300 else if (FYTo
> gMapInfo
.Height
+ 32) then
5301 FYTo
:= gMapInfo
.Height
+ 32;
5306 g_Obj_Move(@FObj
, True, True, True);
5307 positionChanged(); // this updates spatial accelerators
5314 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5315 if gPlayers
[FSpectatePlayer
] <> nil then
5316 if gPlayers
[FSpectatePlayer
].alive
then
5318 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
5319 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
5323 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5324 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5325 PANEL_BLOCKMON
, True);
5326 headwater
:= HeadInLiquid(0, 0);
5328 // Ñîïðîòèâëåíèå âîçäóõà:
5329 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5330 if FObj
.Vel
.X
<> 0 then
5331 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5333 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5334 DecMin(FPain
, 5, 0);
5335 DecMin(FPickup
, 1, 0);
5337 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5339 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5340 FMegaRulez
[MR_SUIT
] := 0;
5341 FMegaRulez
[MR_INVUL
] := 0;
5342 FMegaRulez
[MR_INVIS
] := 0;
5343 Kill(K_FALLKILL
, 0, HIT_FALL
);
5350 if FCurrWeap
= WEAPON_SAW
then
5351 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5352 FSawSoundSelect
.IsPlaying()) then
5353 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5356 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5357 (not FJetSoundOff
.IsPlaying()) then
5359 FJetSoundFly
.SetPosition(0);
5360 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5363 for b
:= WP_FIRST
to WP_LAST
do
5364 if FReloading
[b
] > 0 then
5370 if FShellTimer
> -1 then
5371 if FShellTimer
= 0 then
5373 if FShellType
= SHELL_SHELL
then
5374 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5375 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5376 else if FShellType
= SHELL_DBLSHELL
then
5378 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5379 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5380 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5381 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5384 end else Dec(FShellTimer
);
5386 if (FBFGFireCounter
> -1) then
5387 if FBFGFireCounter
= 0 then
5391 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5392 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5393 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5394 yd
:= wy
+firediry();
5395 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5396 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5397 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5398 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5399 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5402 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5403 FBFGFireCounter
:= -1;
5406 FBFGFireCounter
:= 0
5408 Dec(FBFGFireCounter
);
5410 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5412 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5414 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5417 if (headwater
or blockmon
) then
5423 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5426 else if (FAir
mod 31 = 0) and not blockmon
then
5428 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5430 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5431 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5433 end else if FAir
< AIR_DEF
then
5436 if FFireTime
> 0 then
5438 if BodyInLiquid(0, 0) then
5443 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5445 if FMegaRulez
[MR_SUIT
] = gTime
then
5452 if FFirePainTime
<= 0 then
5454 if g_Game_IsServer
then
5455 Damage(2, FFireAttacker
, 0, 0, HIT_FLAME
);
5456 FFirePainTime
:= 12 - FFireTime
div 12;
5458 FFirePainTime
:= FFirePainTime
- 1;
5459 FFireTime
:= FFireTime
- 1;
5460 if ((FFireTime
mod 33) = 0) and (FMegaRulez
[MR_INVUL
] < gTime
) then
5461 FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
);
5462 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5463 MH_SEND_PlayerStats(FUID
);
5467 if FDamageBuffer
> 0 then
5469 if FDamageBuffer
>= 9 then
5473 if FDamageBuffer
< 30 then i
:= 9
5474 else if FDamageBuffer
< 100 then i
:= 18
5478 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5479 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5480 FHealth
:= FHealth
-ii
;
5483 FHealth
:= FHealth
+FArmor
;
5488 if FHealth
<= 0 then
5489 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5490 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5491 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5493 if FAlive
and ((FLastHit
<> HIT_FLAME
) or (FFireTime
<= 0)) then
5495 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5496 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5497 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5498 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5505 end; // if FAlive then ...
5507 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5509 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5510 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5511 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5512 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5514 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5515 then SetAction(A_STAND
, True);
5517 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5519 for b
:= Low(FKeys
) to High(FKeys
) do
5520 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5524 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5526 x
:= FObj
.X
+PLAYER_RECT
.X
;
5527 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5528 w
:= PLAYER_RECT
.Width
;
5529 h
:= PLAYER_RECT
.Height
;
5533 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5535 if (dx
<> 0) or (dy
<> 0) then
5544 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5546 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5547 FObj
.Y
+PLAYER_RECT
.Y
,
5554 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5556 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5557 FObj
.Y
+PLAYER_RECT
.Y
,
5561 Panel
.Width
, Panel
.Height
);
5564 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5566 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5567 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5568 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5569 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5572 function g_Player_ExistingName(Name
: string): Boolean;
5578 if gPlayers
= nil then Exit
;
5580 for a
:= 0 to High(gPlayers
) do
5581 if gPlayers
[a
] <> nil then
5582 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5589 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5593 d
:= FModel
.Direction
;
5595 FModel
.Direction
:= Direction
;
5596 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5598 FDirection
:= Direction
;
5601 function TPlayer
.GetKeys(): Byte;
5605 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5606 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5607 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5609 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5610 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5613 procedure TPlayer
.Use();
5617 if FTime
[T_USE
] > gTime
then Exit
;
5619 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5620 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5622 for a
:= 0 to High(gPlayers
) do
5623 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5624 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5625 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5626 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5628 gPlayers
[a
].Touch();
5629 if g_Game_IsNet
and g_Game_IsServer
then
5630 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5633 FTime
[T_USE
] := gTime
+120;
5636 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5639 visible
: Boolean = True;
5640 WX
, WY
, XD
, YD
: Integer;
5652 if R_BERSERK
in FRulez
then
5654 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5655 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5656 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5659 locobj
.rect
.Width
:= 39;
5660 locobj
.rect
.Height
:= 52;
5661 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5662 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5663 locobj
.Accel
.X
:= xd
-wx
;
5664 locobj
.Accel
.y
:= yd
-wy
;
5666 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5667 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5669 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5673 FPain
:= min(FPain
+ 25, 50);
5675 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5680 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5681 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5683 FSawSoundSelect
.Stop();
5685 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5687 else if not FSawSoundHit
.IsPlaying() then
5689 FSawSoundSelect
.Stop();
5690 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5696 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5697 FFireAngle
:= FAngle
;
5698 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5699 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5704 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5705 FFireAngle
:= FAngle
;
5707 FShellType
:= SHELL_SHELL
;
5712 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5713 FFireAngle
:= FAngle
;
5715 FShellType
:= SHELL_DBLSHELL
;
5720 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5721 FFireAngle
:= FAngle
;
5722 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5723 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5726 WEAPON_ROCKETLAUNCHER
:
5728 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5729 FFireAngle
:= FAngle
;
5734 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5735 FFireAngle
:= FAngle
;
5740 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5741 FFireAngle
:= FAngle
;
5744 WEAPON_SUPERPULEMET
:
5746 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5747 FFireAngle
:= FAngle
;
5748 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5749 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5752 WEAPON_FLAMETHROWER
:
5754 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5756 FFireAngle
:= FAngle
;
5760 if not visible
then Exit
;
5762 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5763 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5764 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5767 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5769 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5770 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5773 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5779 if FJustTeleported
or (NetInterpLevel
< 1) then
5783 if FJustTeleported
then
5785 FObj
.oldX
:= FObj
.X
;
5786 FObj
.oldY
:= FObj
.Y
;
5791 AX
:= Abs(FXTo
- FObj
.X
);
5792 AY
:= Abs(FYTo
- FObj
.Y
);
5793 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5795 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5800 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5802 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5803 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5804 PANEL_LIFTUP
, False) then Result
:= -1
5806 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5807 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5808 PANEL_LIFTDOWN
, False) then Result
:= 1
5812 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5819 if Flag
= FLAG_NONE
then
5822 if not g_Game_IsServer
then Exit
;
5824 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5825 if (Flag
= FTeam
) and
5826 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5827 (FFlag
<> FLAG_NONE
) then
5829 if FFlag
= FLAG_RED
then
5830 s
:= _lc
[I_PLAYER_FLAG_RED
]
5832 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5834 evtype
:= FLAG_STATE_SCORED
;
5836 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5837 Insert('.', ts
, Length(ts
) + 1 - 3);
5838 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5840 g_Map_ResetFlag(FFlag
);
5841 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5843 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5844 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5845 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5850 if not sound_cap_flag
[a
].IsPlaying() then
5851 sound_cap_flag
[a
].Play();
5853 gTeamStat
[FTeam
].Score
+= 1;
5856 if g_Game_IsNet
then
5858 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5862 gFlags
[FFlag
].CaptureTime
:= 0;
5867 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5868 if (Flag
= FTeam
) and
5869 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5871 if Flag
= FLAG_RED
then
5872 s
:= _lc
[I_PLAYER_FLAG_RED
]
5874 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5876 evtype
:= FLAG_STATE_RETURNED
;
5877 gFlags
[Flag
].CaptureTime
:= 0;
5879 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5881 g_Map_ResetFlag(Flag
);
5882 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5884 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5885 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5886 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5891 if not sound_ret_flag
[a
].IsPlaying() then
5892 sound_ret_flag
[a
].Play();
5895 if g_Game_IsNet
then
5897 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5903 // Ïîäîáðàë ÷óæîé ôëàã:
5904 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5908 if Flag
= FLAG_RED
then
5909 s
:= _lc
[I_PLAYER_FLAG_RED
]
5911 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5913 evtype
:= FLAG_STATE_CAPTURED
;
5915 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5917 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5919 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5921 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5922 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5923 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5928 if not sound_get_flag
[a
].IsPlaying() then
5929 sound_get_flag
[a
].Play();
5932 if g_Game_IsNet
then
5934 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5940 procedure TPlayer
.SetFlag(Flag
: Byte);
5943 if FModel
<> nil then
5944 FModel
.SetFlag(FFlag
);
5947 function TPlayer
.TryDropFlag(): Boolean;
5949 if LongBool(gGameSettings
.Options
and GAME_OPTION_ALLOWDROPFLAG
) then
5950 Result
:= DropFlag(False, LongBool(gGameSettings
.Options
and GAME_OPTION_THROWFLAG
))
5955 function TPlayer
.DropFlag(Silent
: Boolean = True; DoThrow
: Boolean = False): Boolean;
5962 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5964 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5965 with gFlags
[FFlag
] do
5969 Direction
:= FDirection
;
5970 State
:= FLAG_STATE_DROPPED
;
5974 xv
:= FObj
.Vel
.X
+ IfThen(Direction
= TDirection
.D_RIGHT
, 10, -10);
5975 yv
:= FObj
.Vel
.Y
- 2;
5979 xv
:= (FObj
.Vel
.X
div 2);
5980 yv
:= (FObj
.Vel
.Y
div 2) - 2;
5982 g_Obj_Push(@Obj
, xv
, yv
);
5984 positionChanged(); // this updates spatial accelerators
5986 if FFlag
= FLAG_RED
then
5987 s
:= _lc
[I_PLAYER_FLAG_RED
]
5989 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5991 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5992 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5994 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5995 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5996 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
6001 if (not Silent
) and (not sound_lost_flag
[a
].IsPlaying()) then
6002 sound_lost_flag
[a
].Play();
6004 if g_Game_IsNet
then
6005 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
6011 procedure TPlayer
.GetSecret();
6013 if (self
= gPlayer1
) or (self
= gPlayer2
) then
6015 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [FName
]), True);
6016 g_Sound_PlayEx('SOUND_GAME_SECRET');
6021 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
6023 Assert(Key
<= High(FKeys
));
6025 FKeys
[Key
].Pressed
:= True;
6026 FKeys
[Key
].Time
:= Time
;
6029 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
6031 Result
:= FKeys
[K
].Pressed
;
6034 procedure TPlayer
.ReleaseKeys();
6038 for a
:= Low(FKeys
) to High(FKeys
) do
6040 FKeys
[a
].Pressed
:= False;
6045 procedure TPlayer
.OnDamage(Angle
: SmallInt);
6049 function TPlayer
.firediry(): Integer;
6051 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
6052 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
6056 procedure TPlayer
.RememberState();
6059 SavedState
: TPlayerSavedState
;
6061 SavedState
.Health
:= FHealth
;
6062 SavedState
.Armor
:= FArmor
;
6063 SavedState
.Air
:= FAir
;
6064 SavedState
.JetFuel
:= FJetFuel
;
6065 SavedState
.CurrWeap
:= FCurrWeap
;
6066 SavedState
.NextWeap
:= FNextWeap
;
6067 SavedState
.NextWeapDelay
:= FNextWeapDelay
;
6068 for i
:= Low(FWeapon
) to High(FWeapon
) do
6069 SavedState
.Weapon
[i
] := FWeapon
[i
];
6070 for i
:= Low(FAmmo
) to High(FAmmo
) do
6071 SavedState
.Ammo
[i
] := FAmmo
[i
];
6072 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
6073 SavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
6074 SavedState
.Rulez
:= FRulez
- [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6076 FSavedStateNum
:= -1;
6077 for i
:= Low(SavedStates
) to High(SavedStates
) do
6078 if not SavedStates
[i
].Used
then
6080 FSavedStateNum
:= i
;
6083 if FSavedStateNum
< 0 then
6085 SetLength(SavedStates
, Length(SavedStates
) + 1);
6086 FSavedStateNum
:= High(SavedStates
);
6089 SavedState
.Used
:= True;
6090 SavedStates
[FSavedStateNum
] := SavedState
;
6093 procedure TPlayer
.RecallState();
6096 SavedState
: TPlayerSavedState
;
6098 if(FSavedStateNum
< 0) or (FSavedStateNum
> High(SavedStates
)) then
6101 SavedState
:= SavedStates
[FSavedStateNum
];
6102 SavedStates
[FSavedStateNum
].Used
:= False;
6103 FSavedStateNum
:= -1;
6105 FHealth
:= SavedState
.Health
;
6106 FArmor
:= SavedState
.Armor
;
6107 FAir
:= SavedState
.Air
;
6108 FJetFuel
:= SavedState
.JetFuel
;
6109 FCurrWeap
:= SavedState
.CurrWeap
;
6110 FNextWeap
:= SavedState
.NextWeap
;
6111 FNextWeapDelay
:= SavedState
.NextWeapDelay
;
6112 for i
:= Low(FWeapon
) to High(FWeapon
) do
6113 FWeapon
[i
] := SavedState
.Weapon
[i
];
6114 for i
:= Low(FAmmo
) to High(FAmmo
) do
6115 FAmmo
[i
] := SavedState
.Ammo
[i
];
6116 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
6117 FMaxAmmo
[i
] := SavedState
.MaxAmmo
[i
];
6118 FRulez
:= SavedState
.Rulez
;
6120 if gGameSettings
.GameType
= GT_SERVER
then
6121 MH_SEND_PlayerStats(FUID
);
6124 procedure TPlayer
.SaveState (st
: TStream
);
6130 utils
.writeSign(st
, 'PLYR');
6131 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
6133 utils
.writeBool(st
, FIamBot
);
6135 utils
.writeInt(st
, Word(FUID
));
6137 utils
.writeStr(st
, FName
);
6139 utils
.writeInt(st
, Byte(FTeam
));
6141 utils
.writeBool(st
, FAlive
);
6142 // Èçðàñõîäîâàë ëè âñå æèçíè
6143 utils
.writeBool(st
, FNoRespawn
);
6145 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
6146 utils
.writeInt(st
, Byte(b
));
6148 utils
.writeInt(st
, LongInt(FHealth
));
6149 // Êîýôôèöèåíò èíâàëèäíîñòè
6150 utils
.writeInt(st
, LongInt(FHandicap
));
6152 utils
.writeInt(st
, Byte(FLives
));
6154 utils
.writeInt(st
, LongInt(FArmor
));
6156 utils
.writeInt(st
, LongInt(FAir
));
6158 utils
.writeInt(st
, LongInt(FJetFuel
));
6160 utils
.writeInt(st
, LongInt(FPain
));
6162 utils
.writeInt(st
, LongInt(FKills
));
6164 utils
.writeInt(st
, LongInt(FMonsterKills
));
6166 utils
.writeInt(st
, LongInt(FFrags
));
6168 utils
.writeInt(st
, Byte(FFragCombo
));
6169 // Âðåìÿ ïîñëåäíåãî ôðàãà
6170 utils
.writeInt(st
, LongWord(FLastFrag
));
6172 utils
.writeInt(st
, LongInt(FDeath
));
6174 utils
.writeInt(st
, Byte(FFlag
));
6176 utils
.writeInt(st
, LongInt(FSecrets
));
6178 utils
.writeInt(st
, Byte(FCurrWeap
));
6180 utils
.writeInt(st
, Word(FNextWeap
));
6182 utils
.writeInt(st
, Byte(FNextWeapDelay
));
6183 // Âðåìÿ çàðÿäêè BFG
6184 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
6186 utils
.writeInt(st
, LongInt(FDamageBuffer
));
6187 // Ïîñëåäíèé óäàðèâøèé
6188 utils
.writeInt(st
, Word(FLastSpawnerUID
));
6189 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6190 utils
.writeInt(st
, Byte(FLastHit
));
6192 Obj_SaveState(st
, @FObj
);
6193 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6194 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
6195 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6196 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
6198 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
6199 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6200 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
6202 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
6203 // Íàëè÷èå êðàñíîãî êëþ÷à
6204 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
6205 // Íàëè÷èå çåëåíîãî êëþ÷à
6206 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
6207 // Íàëè÷èå ñèíåãî êëþ÷à
6208 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
6210 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
6211 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6212 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
6213 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6214 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
6216 utils
.writeStr(st
, FModel
.Name
);
6218 utils
.writeInt(st
, Byte(FColor
.R
));
6219 utils
.writeInt(st
, Byte(FColor
.G
));
6220 utils
.writeInt(st
, Byte(FColor
.B
));
6224 procedure TPlayer
.LoadState (st
: TStream
);
6233 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
6234 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
6236 FIamBot
:= utils
.readBool(st
);
6238 FUID
:= utils
.readWord(st
);
6240 str
:= utils
.readStr(st
);
6241 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
6243 FTeam
:= utils
.readByte(st
);
6245 FAlive
:= utils
.readBool(st
);
6246 // Èçðàñõîäîâàë ëè âñå æèçíè
6247 FNoRespawn
:= utils
.readBool(st
);
6249 b
:= utils
.readByte(st
);
6250 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
6252 FHealth
:= utils
.readLongInt(st
);
6253 // Êîýôôèöèåíò èíâàëèäíîñòè
6254 FHandicap
:= utils
.readLongInt(st
);
6256 FLives
:= utils
.readByte(st
);
6258 FArmor
:= utils
.readLongInt(st
);
6260 FAir
:= utils
.readLongInt(st
);
6262 FJetFuel
:= utils
.readLongInt(st
);
6264 FPain
:= utils
.readLongInt(st
);
6266 FKills
:= utils
.readLongInt(st
);
6268 FMonsterKills
:= utils
.readLongInt(st
);
6270 FFrags
:= utils
.readLongInt(st
);
6272 FFragCombo
:= utils
.readByte(st
);
6273 // Âðåìÿ ïîñëåäíåãî ôðàãà
6274 FLastFrag
:= utils
.readLongWord(st
);
6276 FDeath
:= utils
.readLongInt(st
);
6278 FFlag
:= utils
.readByte(st
);
6280 FSecrets
:= utils
.readLongInt(st
);
6282 FCurrWeap
:= utils
.readByte(st
);
6284 FNextWeap
:= utils
.readWord(st
);
6286 FNextWeapDelay
:= utils
.readByte(st
);
6287 // Âðåìÿ çàðÿäêè BFG
6288 FBFGFireCounter
:= utils
.readSmallInt(st
);
6290 FDamageBuffer
:= utils
.readLongInt(st
);
6291 // Ïîñëåäíèé óäàðèâøèé
6292 FLastSpawnerUID
:= utils
.readWord(st
);
6293 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6294 FLastHit
:= utils
.readByte(st
);
6296 Obj_LoadState(@FObj
, st
);
6297 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6298 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
6299 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6300 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
6302 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
6303 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6304 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
6306 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
6307 // Íàëè÷èå êðàñíîãî êëþ÷à
6308 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
6309 // Íàëè÷èå çåëåíîãî êëþ÷à
6310 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
6311 // Íàëè÷èå ñèíåãî êëþ÷à
6312 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
6314 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
6315 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6316 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
6317 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6318 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
6320 str
:= utils
.readStr(st
);
6322 FColor
.R
:= utils
.readByte(st
);
6323 FColor
.G
:= utils
.readByte(st
);
6324 FColor
.B
:= utils
.readByte(st
);
6325 if (self
= gPlayer1
) then
6327 str
:= gPlayer1Settings
.Model
;
6328 FColor
:= gPlayer1Settings
.Color
;
6330 else if (self
= gPlayer2
) then
6332 str
:= gPlayer2Settings
.Model
;
6333 FColor
:= gPlayer2Settings
.Color
;
6335 // Îáíîâëÿåì ìîäåëü èãðîêà
6337 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
6338 FModel
.Color
:= TEAMCOLOR
[FTeam
]
6340 FModel
.Color
:= FColor
;
6344 procedure TPlayer
.AllRulez(Health
: Boolean);
6350 FHealth
:= PLAYER_HP_LIMIT
;
6351 FArmor
:= PLAYER_AP_LIMIT
;
6355 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
6356 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
6357 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6360 procedure TPlayer
.RestoreHealthArmor();
6362 FHealth
:= PLAYER_HP_LIMIT
;
6363 FArmor
:= PLAYER_AP_LIMIT
;
6366 procedure TPlayer
.FragCombo();
6370 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6372 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6374 if FFragCombo
< 5 then
6376 Param
:= FUID
or (FFragCombo
shl 16);
6377 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6378 (FComboEvnt
<= High(gDelayedEvents
)) and
6379 gDelayedEvents
[FComboEvnt
].Pending
and
6380 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6381 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6383 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6384 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6387 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6395 procedure TPlayer
.GiveItem(ItemType
: Byte);
6399 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6401 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6405 if FAir
< AIR_MAX
then
6412 if not (R_BERSERK
in FRulez
) then
6414 Include(FRulez
, R_BERSERK
);
6415 if FBFGFireCounter
< 1 then
6417 FCurrWeap
:= WEAPON_KASTET
;
6419 FModel
.SetWeapon(WEAPON_KASTET
);
6423 FBerserk
:= gTime
+30000;
6425 if FHealth
< PLAYER_HP_SOFT
then
6427 FHealth
:= PLAYER_HP_SOFT
;
6428 FBerserk
:= gTime
+30000;
6433 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6435 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6440 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6442 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6446 if FJetFuel
< JET_MAX
then
6448 FJetFuel
:= JET_MAX
;
6451 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6452 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6454 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6455 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6457 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6459 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6461 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6462 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6465 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6466 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6467 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6468 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6469 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6470 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6471 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6472 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6473 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6475 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6476 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6477 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6478 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6479 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6480 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6481 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6482 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6483 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6486 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6487 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6488 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6489 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6490 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6492 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6493 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6494 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6495 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6496 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6498 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6499 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6500 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6501 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6503 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6506 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6507 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6508 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6510 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6511 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6516 if g_Game_IsNet
and g_Game_IsServer
then
6517 MH_SEND_PlayerStats(FUID
);
6520 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6525 if (Random(5) = 1) and (Times
= 1) then
6528 if BodyInLiquid(0, 0) then
6530 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6531 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6533 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6534 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6538 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6540 for i
:= 1 to Times
do
6542 Anim
:= TAnimation
.Create(id
, False, 3);
6544 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6545 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6551 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6556 if (Random(10) = 1) and (Times
= 1) then
6559 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6561 for i
:= 1 to Times
do
6563 Anim
:= TAnimation
.Create(id
, False, 3);
6565 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6566 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6572 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6574 FSawSound
.Pause(Enable
);
6575 FSawSoundIdle
.Pause(Enable
);
6576 FSawSoundHit
.Pause(Enable
);
6577 FSawSoundSelect
.Pause(Enable
);
6578 FFlameSoundOn
.Pause(Enable
);
6579 FFlameSoundOff
.Pause(Enable
);
6580 FFlameSoundWork
.Pause(Enable
);
6581 FJetSoundFly
.Pause(Enable
);
6582 FJetSoundOn
.Pause(Enable
);
6583 FJetSoundOff
.Pause(Enable
);
6588 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6593 FObj
.Rect
:= PLAYER_CORPSERECT
;
6594 FModelName
:= ModelName
;
6599 FState
:= CORPSE_STATE_MESS
;
6600 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6604 FState
:= CORPSE_STATE_NORMAL
;
6605 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6609 destructor TCorpse
.Destroy();
6616 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6618 procedure TCorpse
.positionChanged (); inline; begin end;
6620 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6622 if (dx
<> 0) or (dy
<> 0) then
6631 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6633 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6634 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6635 w
:= PLAYER_CORPSERECT
.Width
;
6636 h
:= PLAYER_CORPSERECT
.Height
;
6640 procedure TCorpse
.Damage(Value
: Word; SpawnerUID
: Word; vx
, vy
: Integer);
6645 if FState
= CORPSE_STATE_REMOVEME
then
6648 FDamage
:= FDamage
+ Value
;
6650 if FDamage
> 150 then
6652 if FAnimation
<> nil then
6657 FState
:= CORPSE_STATE_REMOVEME
;
6659 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6660 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6661 FModelName
, FColor
);
6662 // Çâóê ìÿñà îò òðóïà:
6663 pm
:= g_PlayerModel_Get(FModelName
);
6664 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6668 if (gBodyKillEvent
<> -1)
6669 and gDelayedEvents
[gBodyKillEvent
].Pending
then
6670 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
6671 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, SpawnerUID
);
6676 Blood
:= g_PlayerModel_GetBlood(FModelName
);
6677 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6678 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6679 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6680 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6681 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6682 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
6686 procedure TCorpse
.Draw();
6690 if FState
= CORPSE_STATE_REMOVEME
then
6693 FObj
.lerp(gLerpFactor
, fX
, fY
);
6695 if FAnimation
<> nil then
6696 FAnimation
.Draw(fX
, fY
, TMirrorType
.None
);
6698 if FAnimationMask
<> nil then
6701 FAnimationMask
.Draw(fX
, fY
, TMirrorType
.None
);
6708 procedure TCorpse
.Update();
6712 if FState
= CORPSE_STATE_REMOVEME
then
6715 FObj
.oldX
:= FObj
.X
;
6716 FObj
.oldY
:= FObj
.Y
;
6718 if gTime
mod (GAME_TICK
*2) <> 0 then
6720 g_Obj_Move(@FObj
, True, True, True);
6721 positionChanged(); // this updates spatial accelerators
6725 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6726 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6728 st
:= g_Obj_Move(@FObj
, True, True, True);
6729 positionChanged(); // this updates spatial accelerators
6731 if WordBool(st
and MOVE_FALLOUT
) then
6733 FState
:= CORPSE_STATE_REMOVEME
;
6737 if FAnimation
<> nil then
6738 FAnimation
.Update();
6739 if FAnimationMask
<> nil then
6740 FAnimationMask
.Update();
6744 procedure TCorpse
.SaveState (st
: TStream
);
6751 utils
.writeSign(st
, 'CORP');
6752 utils
.writeInt(st
, Byte(0));
6754 utils
.writeInt(st
, Byte(FState
));
6756 utils
.writeInt(st
, Byte(FDamage
));
6758 utils
.writeInt(st
, Byte(FColor
.R
));
6759 utils
.writeInt(st
, Byte(FColor
.G
));
6760 utils
.writeInt(st
, Byte(FColor
.B
));
6762 Obj_SaveState(st
, @FObj
);
6763 utils
.writeInt(st
, Word(FPlayerUID
));
6765 anim
:= (FAnimation
<> nil);
6766 utils
.writeBool(st
, anim
);
6767 // Åñëè åñòü - ñîõðàíÿåì
6768 if anim
then FAnimation
.SaveState(st
);
6769 // Åñòü ëè ìàñêà àíèìàöèè
6770 anim
:= (FAnimationMask
<> nil);
6771 utils
.writeBool(st
, anim
);
6772 // Åñëè åñòü - ñîõðàíÿåì
6773 if anim
then FAnimationMask
.SaveState(st
);
6777 procedure TCorpse
.LoadState (st
: TStream
);
6784 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6785 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6787 FState
:= utils
.readByte(st
);
6789 FDamage
:= utils
.readByte(st
);
6791 FColor
.R
:= utils
.readByte(st
);
6792 FColor
.G
:= utils
.readByte(st
);
6793 FColor
.B
:= utils
.readByte(st
);
6795 Obj_LoadState(@FObj
, st
);
6796 FPlayerUID
:= utils
.readWord(st
);
6798 anim
:= utils
.readBool(st
);
6799 // Åñëè åñòü - çàãðóæàåì
6802 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6803 FAnimation
.LoadState(st
);
6805 // Åñòü ëè ìàñêà àíèìàöèè
6806 anim
:= utils
.readBool(st
);
6807 // Åñëè åñòü - çàãðóæàåì
6810 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6811 FAnimationMask
.LoadState(st
);
6817 constructor TBot
.Create();
6824 FSpectator
:= False;
6831 for a
:= WP_FIRST
to WP_LAST
do
6833 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6834 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6835 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6839 destructor TBot
.Destroy();
6842 inherited Destroy();
6845 procedure TBot
.Draw();
6849 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6850 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6853 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6855 inherited Respawn(Silent
, Force
);
6858 FSelectedWeapon
:= FCurrWeap
;
6863 procedure TBot
.UpdateCombat();
6876 TTargetRecord
= array of TTarget
;
6878 function Compare(a
, b
: TTarget
): Integer;
6880 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6883 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6885 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6886 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6888 if a
.Dist
> b
.Dist
then // B áëèæå
6890 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6893 else // Ñòðàííî -> A
6898 a
, x1
, y1
, x2
, y2
: Integer;
6899 targets
: TTargetRecord
;
6901 Target
, BestTarget
: TTarget
;
6902 firew
, fireh
: Integer;
6906 vsPlayer
, vsMonster
, ok
: Boolean;
6909 function monsUpdate (mon
: TMonster
): Boolean;
6911 result
:= false; // don't stop
6912 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6914 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6916 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6917 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6919 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6920 if g_TraceVector(x1
, y1
, x2
, y2
) then
6922 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6923 SetLength(targets
, Length(targets
)+1);
6924 with targets
[High(targets
)] do
6931 Rect
:= mon
.Obj
.Rect
;
6932 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6933 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6934 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6943 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6944 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6946 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6947 if FCurrWeap
<> FSelectedWeapon
then
6950 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6951 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6953 RemoveAIFlag('NEEDFIRE');
6956 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6957 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6958 else PressKey(KEY_FIRE
);
6962 // Êîîðäèíàòû ñòâîëà:
6963 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6964 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6966 Target
.UID
:= FTargetUID
;
6969 if Target
.UID
<> 0 then
6970 begin // Öåëü åñòü - íàñòðàèâàåì
6971 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6974 tpla
:= g_Player_Get(Target
.UID
);
6978 if (@FObj
) <> nil then
6985 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6986 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6987 Target
.Rect
:= PLAYER_RECT
;
6988 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6989 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6990 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6991 Target
.IsPlayer
:= True;
6995 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6998 mon
:= g_Monsters_ByUID(Target
.UID
);
7001 Target
.X
:= mon
.Obj
.X
;
7002 Target
.Y
:= mon
.Obj
.Y
;
7004 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
7005 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
7006 Target
.Rect
:= mon
.Obj
.Rect
;
7007 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
7008 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
7009 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
7010 Target
.IsPlayer
:= False;
7017 begin // Öåëè íåò - îáíóëÿåì
7022 Target
.Visible
:= False;
7023 Target
.Line
:= False;
7024 Target
.IsPlayer
:= False;
7029 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
7030 if (not Target
.Line
) or (not Target
.Visible
) then
7034 for a
:= 0 to High(gPlayers
) do
7035 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
7036 (gPlayers
[a
].FUID
<> FUID
) and
7037 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
7038 (not gPlayers
[a
].NoTarget
) and
7039 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
7041 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
7042 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
7045 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
7046 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
7048 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
7049 if g_TraceVector(x1
, y1
, x2
, y2
) then
7051 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
7052 SetLength(targets
, Length(targets
)+1);
7053 with targets
[High(targets
)] do
7055 UID
:= gPlayers
[a
].FUID
;
7056 X
:= gPlayers
[a
].FObj
.X
;
7057 Y
:= gPlayers
[a
].FObj
.Y
;
7060 Rect
:= PLAYER_RECT
;
7061 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
7062 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
7063 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
7071 if vsMonster
then g_Mons_ForEach(monsUpdate
);
7074 // Åñëè åñòü âîçìîæíûå öåëè:
7075 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
7076 if targets
<> nil then
7078 // Âûáèðàåì íàèëó÷øóþ öåëü:
7079 BestTarget
:= targets
[0];
7080 if Length(targets
) > 1 then
7081 for a
:= 1 to High(targets
) do
7082 if Compare(BestTarget
, targets
[a
]) = 1 then
7083 BestTarget
:= targets
[a
];
7085 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
7086 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
7087 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
7089 Target
:= BestTarget
;
7091 if (Healthy() = 3) or ((Healthy() = 2)) then
7092 begin // Åñëè çäîðîâû - äîãîíÿåì
7093 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
7094 SetAIFlag('GORIGHT', '1');
7095 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
7096 SetAIFlag('GOLEFT', '1');
7099 begin // Åñëè ïîáèòû - óáåãàåì
7100 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
7101 SetAIFlag('GORIGHT', '1');
7102 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
7103 SetAIFlag('GOLEFT', '1');
7106 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
7107 SelectWeapon(Abs(x1
-Target
.cX
));
7112 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
7113 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
7114 if Target
.UID
<> 0 then
7116 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
7117 Target
.Y
+ Target
.Rect
.Y
) then
7118 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
7119 if (Healthy() = 3) or ((Healthy() = 2)) then
7120 begin // Åñëè çäîðîâû - äîãîíÿåì
7121 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
7122 SetAIFlag('GORIGHT', '1');
7123 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
7124 SetAIFlag('GOLEFT', '1');
7127 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
7129 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
7130 SetAIFlag('GORIGHT', '1');
7131 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
7132 SetAIFlag('GOLEFT', '1');
7136 begin // Öåëü ïîêà íà "ýêðàíå"
7137 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
7138 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7139 FLastVisible
:= gTime
;
7140 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
7141 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
7143 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
7144 SetAIFlag('GORIGHT', '1');
7145 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
7146 SetAIFlag('GOLEFT', '1');
7150 // Âûáèðàåì óãîë ââåðõ:
7151 if FDirection
= TDirection
.D_LEFT
then
7152 angle
:= ANGLE_LEFTUP
7154 angle
:= ANGLE_RIGHTUP
;
7156 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7157 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7159 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7160 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7161 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
7162 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7163 Target
.Rect
.Width
, Target
.Rect
.Height
) and
7164 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7165 begin // òî íóæíî ñòðåëÿòü ââåðõ
7166 SetAIFlag('NEEDFIRE', '1');
7167 SetAIFlag('NEEDSEEUP', '1');
7170 // Âûáèðàåì óãîë âíèç:
7171 if FDirection
= TDirection
.D_LEFT
then
7172 angle
:= ANGLE_LEFTDOWN
7174 angle
:= ANGLE_RIGHTDOWN
;
7176 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7177 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7179 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7180 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7181 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7182 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7183 Target
.Rect
.Width
, Target
.Rect
.Height
) and
7184 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7185 begin // òî íóæíî ñòðåëÿòü âíèç
7186 SetAIFlag('NEEDFIRE', '1');
7187 SetAIFlag('NEEDSEEDOWN', '1');
7190 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
7191 if Target
.Visible
and
7192 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
7193 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
7195 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
7196 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
7197 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
7198 begin // òî íóæíî ñòðåëÿòü âïåðåä
7199 SetAIFlag('NEEDFIRE', '1');
7200 SetAIFlag('NEEDSEEDOWN', '');
7201 SetAIFlag('NEEDSEEUP', '');
7203 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
7204 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
7205 if GetRnd(FDifficult
.CloseJump
) then
7206 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
7207 if Abs(FObj
.X
-Target
.X
) < 128 then
7211 if Random(a
) = 0 then
7212 SetAIFlag('NEEDJUMP', '1');
7216 // Åñëè öåëü âñå åùå åñòü:
7217 if Target
.UID
<> 0 then
7218 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
7219 Target
.UID
:= 0 // òî çàáûòü öåëü
7220 else // Åñëè âèäåëè íåäàâíî
7221 begin // íî öåëü óáèëè
7222 if Target
.IsPlayer
then
7223 begin // Öåëü - èãðîê
7224 pla
:= g_Player_Get(Target
.UID
);
7225 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
7226 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
7227 Target
.UID
:= 0; // òî çàáûòü öåëü
7230 begin // Öåëü - ìîíñòð
7231 mon
:= g_Monsters_ByUID(Target
.UID
);
7232 if (mon
= nil) or (not mon
.alive
) then
7233 Target
.UID
:= 0; // òî çàáûòü öåëü
7236 end; // if Target.UID <> 0
7238 FTargetUID
:= Target
.UID
;
7240 // Åñëè âîçìîæíûõ öåëåé íåò:
7241 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
7242 if targets
= nil then
7243 if GetAIFlag('ATTACKLEFT') <> '' then
7244 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
7245 RemoveAIFlag('ATTACKLEFT');
7247 SetAIFlag('NEEDJUMP', '1');
7249 if RunDirection() = TDirection
.D_RIGHT
then
7250 begin // Èäåì íå â òó ñòîðîíó
7251 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7252 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
7253 SetAIFlag('NEEDFIRE', '1');
7254 SetAIFlag('GOLEFT', '1');
7258 begin // Èäåì â íóæíóþ ñòîðîíó
7259 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7260 SetAIFlag('NEEDFIRE', '1');
7261 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7262 SetAIFlag('GORIGHT', '1');
7266 if GetAIFlag('ATTACKRIGHT') <> '' then
7267 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
7268 RemoveAIFlag('ATTACKRIGHT');
7270 SetAIFlag('NEEDJUMP', '1');
7272 if RunDirection() = TDirection
.D_LEFT
then
7273 begin // Èäåì íå â òó ñòîðîíó
7274 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7275 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
7276 SetAIFlag('NEEDFIRE', '1');
7277 SetAIFlag('GORIGHT', '1');
7282 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7283 SetAIFlag('NEEDFIRE', '1');
7284 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7285 SetAIFlag('GOLEFT', '1');
7289 //HACK! (does it belongs there?)
7290 RealizeCurrentWeapon();
7292 // Åñëè åñòü âîçìîæíûå öåëè:
7293 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7294 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7295 for a
:= 0 to High(targets
) do
7297 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7298 if GetRnd(FDifficult
.DiagFire
) then
7300 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7301 if FDirection
= TDirection
.D_LEFT
then
7302 angle
:= ANGLE_LEFTUP
7304 angle
:= ANGLE_RIGHTUP
;
7306 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7307 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7309 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7310 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7311 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7312 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7313 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7315 SetAIFlag('NEEDFIRE', '1');
7316 SetAIFlag('NEEDSEEUP', '1');
7319 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7320 if FDirection
= TDirection
.D_LEFT
then
7321 angle
:= ANGLE_LEFTDOWN
7323 angle
:= ANGLE_RIGHTDOWN
;
7325 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7326 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7328 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7329 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7330 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7331 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7332 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7334 SetAIFlag('NEEDFIRE', '1');
7335 SetAIFlag('NEEDSEEDOWN', '1');
7339 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7340 if targets
[a
].Line
and targets
[a
].Visible
and
7341 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
7342 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
7344 SetAIFlag('NEEDFIRE', '1');
7349 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7350 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
7351 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
7352 40+GetInterval(FDifficult
.Cover
, 40)) then
7353 SetAIFlag('NEEDJUMP', '1');
7355 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7356 ammo
:= GetAmmoByWeapon(FCurrWeap
);
7357 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
7358 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
7360 SetAIFlag('SELECTWEAPON', '1');
7362 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7363 if GetAIFlag('SELECTWEAPON') = '1' then
7366 RemoveAIFlag('SELECTWEAPON');
7370 procedure TBot
.Update();
7383 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7384 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7386 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7388 if g_debug_BotAIOff
= 3 then
7398 RealizeCurrentWeapon();
7405 procedure TBot
.ReleaseKey(Key
: Byte);
7414 function TBot
.KeyPressed(Key
: Word): Boolean;
7416 Result
:= FKeys
[Key
].Pressed
;
7419 function TBot
.GetAIFlag(aName
: String20
): String20
;
7425 aName
:= LowerCase(aName
);
7427 if FAIFlags
<> nil then
7428 for a
:= 0 to High(FAIFlags
) do
7429 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7431 Result
:= FAIFlags
[a
].Value
;
7436 procedure TBot
.RemoveAIFlag(aName
: String20
);
7440 if FAIFlags
= nil then Exit
;
7442 aName
:= LowerCase(aName
);
7444 for a
:= 0 to High(FAIFlags
) do
7445 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7447 if a
<> High(FAIFlags
) then
7448 for b
:= a
to High(FAIFlags
)-1 do
7449 FAIFlags
[b
] := FAIFlags
[b
+1];
7451 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7456 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7464 aName
:= LowerCase(aName
);
7466 if FAIFlags
<> nil then
7467 for a
:= 0 to High(FAIFlags
) do
7468 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7474 if ok
then FAIFlags
[a
].Value
:= fValue
7477 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7478 with FAIFlags
[High(FAIFlags
)] do
7486 procedure TBot
.UpdateMove
;
7488 procedure GoLeft(Time
: Word = 1);
7490 ReleaseKey(KEY_LEFT
);
7491 ReleaseKey(KEY_RIGHT
);
7492 PressKey(KEY_LEFT
, Time
);
7493 SetDirection(TDirection
.D_LEFT
);
7496 procedure GoRight(Time
: Word = 1);
7498 ReleaseKey(KEY_LEFT
);
7499 ReleaseKey(KEY_RIGHT
);
7500 PressKey(KEY_RIGHT
, Time
);
7501 SetDirection(TDirection
.D_RIGHT
);
7504 function Rnd(a
: Word): Boolean;
7506 Result
:= Random(a
) = 0;
7509 procedure Turn(Time
: Word = 1200);
7511 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7516 ReleaseKey(KEY_LEFT
);
7517 ReleaseKey(KEY_RIGHT
);
7520 function CanRunLeft(): Boolean;
7522 Result
:= not CollideLevel(-1, 0);
7525 function CanRunRight(): Boolean;
7527 Result
:= not CollideLevel(1, 0);
7530 function CanRun(): Boolean;
7532 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7535 procedure Jump(Time
: Word = 30);
7537 PressKey(KEY_JUMP
, Time
);
7540 function NearHole(): Boolean;
7544 { TODO 5 : Ëåñòíèöû }
7545 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7546 for x
:= 1 to PLAYER_RECT
.Width
do
7547 if (not StayOnStep(x
*sx
, 0)) and
7548 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7549 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7558 function BorderHole(): Boolean;
7562 { TODO 5 : Ëåñòíèöû }
7563 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7564 for x
:= 1 to PLAYER_RECT
.Width
do
7565 if (not StayOnStep(x
*sx
, 0)) and
7566 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7567 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7569 for xx
:= x
to x
+32 do
7570 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7580 function NearDeepHole(): Boolean;
7586 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7589 for x
:= 1 to PLAYER_RECT
.Width
do
7590 if (not StayOnStep(x
*sx
, 0)) and
7591 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7592 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7594 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7596 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7601 end else Result
:= False;
7604 function OverDeepHole(): Boolean;
7611 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7613 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7620 function OnGround(): Boolean;
7622 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7625 function OnLadder(): Boolean;
7627 Result
:= FullInStep(0, 0);
7630 function BelowLadder(): Boolean;
7632 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7633 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7634 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7635 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7638 function BelowLiftUp(): Boolean;
7640 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7641 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7642 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7643 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7646 function OnTopLift(): Boolean;
7648 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7651 function CanJumpOver(): Boolean;
7655 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7659 if not CollideLevel(sx
, 0) then Exit
;
7661 for y
:= 1 to BOT_MAXJUMP
do
7662 if CollideLevel(0, -y
) then Exit
else
7663 if not CollideLevel(sx
, -y
) then
7670 function CanJumpUp(Dist
: ShortInt): Boolean;
7677 if CollideLevel(Dist
, 0) then Exit
;
7680 for y
:= 0 to BOT_MAXJUMP
do
7681 if CollideLevel(Dist
, -y
) then
7690 for yy
:= y
+1 to BOT_MAXJUMP
do
7691 if not CollideLevel(Dist
, -yy
) then
7700 for y
:= 0 to BOT_MAXJUMP
do
7701 if CollideLevel(0, -y
) then
7709 if y
< yy
then Exit
;
7714 function IsSafeTrigger(): Boolean;
7719 if gTriggers
= nil then
7721 for a
:= 0 to High(gTriggers
) do
7722 if Collide(gTriggers
[a
].X
,
7725 gTriggers
[a
].Height
) and
7726 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7727 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7728 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7729 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7730 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7735 // Âîçìîæíî, íàæèìàåì êíîïêó:
7736 if Rnd(16) and IsSafeTrigger() then
7739 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7740 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7742 ReleaseKey(KEY_LEFT
);
7743 ReleaseKey(KEY_RIGHT
);
7747 // Èäåì âëåâî, åñëè íàäî áûëî:
7748 if GetAIFlag('GOLEFT') <> '' then
7750 RemoveAIFlag('GOLEFT');
7751 if CanRunLeft() then
7755 // Èäåì âïðàâî, åñëè íàäî áûëî:
7756 if GetAIFlag('GORIGHT') <> '' then
7758 RemoveAIFlag('GORIGHT');
7759 if CanRunRight() then
7763 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7764 if FObj
.X
< -32 then
7767 if FObj
.X
+32 > gMapInfo
.Width
then
7770 // Ïðûãàåì, åñëè íàäî áûëî:
7771 if GetAIFlag('NEEDJUMP') <> '' then
7774 RemoveAIFlag('NEEDJUMP');
7777 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7778 if GetAIFlag('NEEDSEEUP') <> '' then
7781 ReleaseKey(KEY_DOWN
);
7782 PressKey(KEY_UP
, 20);
7783 RemoveAIFlag('NEEDSEEUP');
7786 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7787 if GetAIFlag('NEEDSEEDOWN') <> '' then
7790 ReleaseKey(KEY_DOWN
);
7791 PressKey(KEY_DOWN
, 20);
7792 RemoveAIFlag('NEEDSEEDOWN');
7795 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7796 if GetAIFlag('GOINHOLE') <> '' then
7797 if not OnGround() then
7799 ReleaseKey(KEY_LEFT
);
7800 ReleaseKey(KEY_RIGHT
);
7801 RemoveAIFlag('GOINHOLE');
7802 SetAIFlag('FALLINHOLE', '1');
7805 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7806 if GetAIFlag('FALLINHOLE') <> '' then
7808 RemoveAIFlag('FALLINHOLE');
7810 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7811 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7812 if GetAIFlag('FALLINHOLE') = '' then
7813 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7819 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7821 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7825 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7826 if OnGround() and NearHole() then
7827 if NearDeepHole() then // Åñëè ýòî áåçäíà
7829 0..3: Turn(); // Áåæèì îáðàòíî
7830 4: Jump(); // Ïðûãàåì
7831 5: begin // Ïðûãàåì îáðàòíî
7836 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7837 if GetAIFlag('GOINHOLE') = '' then
7839 0: Turn(); // Íå íóæíî òóäà
7840 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7841 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7842 if BorderHole() then
7843 SetAIFlag('GOINHOLE', '1');
7846 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7847 if (not CanRun()) and OnGround() then
7849 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7850 if CanJumpOver() or OnLadder() then
7852 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7853 if Random(2) = 0 then
7855 if IsSafeTrigger() then
7861 // Îñòàëîñü ìàëî âîçäóõà:
7862 if FAir
< 36 * 2 then
7865 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7866 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7867 if BodyInAcid(0, 0) then
7871 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7873 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7874 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7877 {function TBot.NeedItem(Item: Byte): Byte;
7882 procedure TBot
.SelectWeapon(Dist
: Integer);
7886 function HaveAmmo(weapon
: Byte): Boolean;
7889 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7890 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7891 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7892 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7893 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7894 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7895 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7896 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7897 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7898 else Result
:= True;
7903 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7905 if Dist
> BOT_LONGDIST
then
7906 begin // Äàëüíèé áîé
7908 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7910 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7914 else //if Dist > BOT_UNSAFEDIST then
7915 begin // Áëèæíèé áîé
7917 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7919 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7926 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7928 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7934 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7936 Result
:= inherited PickItem(ItemType
, force
, remove
);
7938 if Result
then SetAIFlag('SELECTWEAPON', '1');
7941 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7943 Result
:= inherited Heal(value
, Soft
);
7946 function TBot
.Healthy(): Byte;
7948 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7949 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7950 else if (FHealth
> 50) then Result
:= 2
7951 else if (FHealth
> 20) then Result
:= 1
7955 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7957 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7958 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7961 procedure TBot
.OnDamage(Angle
: SmallInt);
7969 if (Angle
= 0) or (Angle
= 180) then
7972 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7973 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7975 pla
:= g_Player_Get(FLastSpawnerUID
);
7976 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7977 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7980 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7981 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7983 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7984 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7985 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7990 SetAIFlag('ATTACKLEFT', '1')
7992 SetAIFlag('ATTACKRIGHT', '1');
7996 function TBot
.RunDirection(): TDirection
;
7998 if Abs(Vel
.X
) >= 1 then
8000 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
8002 Result
:= FDirection
;
8005 function TBot
.GetRnd(a
: Byte): Boolean;
8007 if a
= 0 then Result
:= False
8008 else if a
= 255 then Result
:= True
8009 else Result
:= Random(256) > 255-a
;
8012 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
8014 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
8018 procedure TDifficult
.save (st
: TStream
);
8020 utils
.writeInt(st
, Byte(DiagFire
));
8021 utils
.writeInt(st
, Byte(InvisFire
));
8022 utils
.writeInt(st
, Byte(DiagPrecision
));
8023 utils
.writeInt(st
, Byte(FlyPrecision
));
8024 utils
.writeInt(st
, Byte(Cover
));
8025 utils
.writeInt(st
, Byte(CloseJump
));
8026 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
8027 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
8030 procedure TDifficult
.load (st
: TStream
);
8032 DiagFire
:= utils
.readByte(st
);
8033 InvisFire
:= utils
.readByte(st
);
8034 DiagPrecision
:= utils
.readByte(st
);
8035 FlyPrecision
:= utils
.readByte(st
);
8036 Cover
:= utils
.readByte(st
);
8037 CloseJump
:= utils
.readByte(st
);
8038 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
8039 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
8043 procedure TBot
.SaveState (st
: TStream
);
8048 inherited SaveState(st
);
8049 utils
.writeSign(st
, 'BOT0');
8051 utils
.writeInt(st
, Byte(FSelectedWeapon
));
8053 utils
.writeInt(st
, Word(FTargetUID
));
8054 // Âðåìÿ ïîòåðè öåëè
8055 utils
.writeInt(st
, LongWord(FLastVisible
));
8056 // Êîëè÷åñòâî ôëàãîâ ÈÈ
8057 dw
:= Length(FAIFlags
);
8058 utils
.writeInt(st
, LongInt(dw
));
8060 for i
:= 0 to dw
-1 do
8062 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
8063 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
8065 // Íàñòðîéêè ñëîæíîñòè
8066 FDifficult
.save(st
);
8070 procedure TBot
.LoadState (st
: TStream
);
8075 inherited LoadState(st
);
8076 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
8078 FSelectedWeapon
:= utils
.readByte(st
);
8080 FTargetUID
:= utils
.readWord(st
);
8081 // Âðåìÿ ïîòåðè öåëè
8082 FLastVisible
:= utils
.readLongWord(st
);
8083 // Êîëè÷åñòâî ôëàãîâ ÈÈ
8084 dw
:= utils
.readLongInt(st
);
8085 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
8086 SetLength(FAIFlags
, dw
);
8088 for i
:= 0 to dw
-1 do
8090 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
8091 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
8093 // Íàñòðîéêè ñëîæíîñòè
8094 FDifficult
.load(st
);
8099 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');
8100 conRegVar('player_indicator_style', @gPlayerIndicatorStyle
, 'Visual appearance of indicator', 'Visual appearance of indicator');