1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
23 {$IFDEF USE_MEMPOOL}mempool
,{$ENDIF}
24 g_base
, g_playermodel
, g_basic
, g_textures
,
25 g_weapons
, g_phys
, g_sound
, g_saveload
, MAPDEF
,
26 g_panel
, r_playermodel
;
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);
109 JET_MAX
= 540; // ~30 sec
111 ANGLE_RIGHTDOWN
= -35;
113 ANGLE_LEFTDOWN
= -145;
114 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
115 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
134 TPlayerStatArray
= Array of TPlayerStat
;
136 TPlayerSavedState
= record
144 Ammo
: Array [A_BULLETS
..A_HIGH
] of Word;
145 MaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
146 Weapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
147 Rulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
156 TPlayer
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
164 FDirection
: TDirection
;
172 FMonsterKills
: Integer;
178 FCanJetpack
: Boolean;
184 FNextWeapDelay
: Byte; // frames
185 FBFGFireCounter
: SmallInt;
186 FLastSpawnerUID
: Word;
190 FSpectatePlayer
: Integer;
191 FFirePainTime
: Integer;
194 FSavedStateNum
: Integer;
196 FModel
: TPlayerModel
;
197 FPunchAnim
: TAnimation
;
200 FActionForce
: Boolean;
201 FActionChanged
: Boolean;
203 FFireAngle
: SmallInt;
207 FShellTimer
: Integer;
209 FSawSound
: TPlayableSound
;
210 FSawSoundIdle
: TPlayableSound
;
211 FSawSoundHit
: TPlayableSound
;
212 FSawSoundSelect
: TPlayableSound
;
213 FFlameSoundOn
: TPlayableSound
;
214 FFlameSoundOff
: TPlayableSound
;
215 FFlameSoundWork
: TPlayableSound
;
216 FJetSoundOn
: TPlayableSound
;
217 FJetSoundOff
: TPlayableSound
;
218 FJetSoundFly
: TPlayableSound
;
222 FJustTeleported
: Boolean;
224 mEDamageType
: Integer;
227 function CollideLevel(XInc
, YInc
: Integer): Boolean;
228 function StayOnStep(XInc
, YInc
: Integer): Boolean;
229 function HeadInLiquid(XInc
, YInc
: Integer): Boolean;
230 function BodyInLiquid(XInc
, YInc
: Integer): Boolean;
231 function BodyInAcid(XInc
, YInc
: Integer): Boolean;
232 function FullInLift(XInc
, YInc
: Integer): Integer;
233 {procedure CollideItem();}
234 procedure FlySmoke(Times
: DWORD
= 1);
235 procedure OnFireFlame(Times
: DWORD
= 1);
236 procedure SetAction(Action
: Byte; Force
: Boolean = False);
237 procedure OnDamage(Angle
: SmallInt); virtual;
238 function firediry(): Integer;
241 procedure Run(Direction
: TDirection
);
242 procedure NextWeapon();
243 procedure PrevWeapon();
250 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
251 procedure resetWeaponQueue ();
252 function hasAmmoForWeapon (weapon
: Byte): Boolean;
253 function hasAmmoForShooting (weapon
: Byte): Boolean;
254 function shouldSwitch (weapon
: Byte; hadWeapon
: Boolean) : Boolean;
256 procedure doDamage (v
: Integer);
258 function refreshCorpse(): Boolean;
261 FDamageBuffer
: Integer;
263 FAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
264 FMaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
265 FWeapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
266 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
268 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
269 FReloading
: Array [WP_FIRST
..WP_LAST
] of Word;
270 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
271 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
272 FWeapSwitchMode
: Byte;
273 FWeapPreferences
: Array [WP_FIRST
.. WP_LAST
+1] of Byte;
274 FSwitchToEmpty
: Byte;
277 FPreferredTeam
: Byte;
280 FWantsInGame
: Boolean;
285 FActualModelName
: string;
292 FSpawnInvul
: Integer;
294 FWaitForFirstSpawn
: Boolean; // set to `true` in server, used to spawn a player on first full state request
297 // debug: viewport offset
298 viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer;
300 function isValidViewPort (): Boolean; inline;
302 constructor Create(); virtual;
303 destructor Destroy(); override;
304 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
305 function GetRespawnPoint(): Byte;
306 procedure PressKey(Key
: Byte; Time
: Word = 1);
307 procedure ReleaseKeys();
308 procedure SetModel(ModelName
: String);
309 procedure SetColor(Color
: TRGB
);
310 function GetColor(): TRGB
;
311 procedure SetWeapon(W
: Byte);
312 function IsKeyPressed(K
: Byte): Boolean;
313 function GetKeys(): Byte;
314 function PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean; virtual;
315 procedure SetWeaponPrefs(Prefs
: Array of Byte);
316 procedure SetWeaponPref(Weapon
, Pref
: Byte);
317 function GetWeaponPref(Weapon
: Byte) : Byte;
318 function GetMorePrefered() : Byte;
319 function MaySwitch(Weapon
: Byte) : Boolean;
320 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
321 function Collide(Panel
: TPanel
): Boolean; overload
;
322 function Collide(X
, Y
: Integer): Boolean; overload
;
323 procedure SetDirection(Direction
: TDirection
);
324 procedure GetSecret();
325 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
327 procedure Push(vx
, vy
: Integer);
328 procedure ChangeModel(ModelName
: String);
329 procedure SwitchTeam
;
330 procedure ChangeTeam(Team
: Byte);
332 function GetFlag(Flag
: Byte): Boolean;
333 procedure SetFlag(Flag
: Byte);
334 function DropFlag(Silent
: Boolean = True; DoThrow
: Boolean = False): Boolean;
335 function TryDropFlag(): Boolean;
336 procedure AllRulez(Health
: Boolean);
337 procedure RestoreHealthArmor();
338 procedure FragCombo();
339 procedure GiveItem(ItemType
: Byte);
340 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
341 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
342 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
343 procedure MakeBloodSimple(Count
: Word);
344 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
345 procedure Reset(Force
: Boolean);
346 procedure Spectate(NoMove
: Boolean = False);
347 procedure SwitchNoClip
;
348 procedure SoftReset();
349 procedure PreUpdate();
350 procedure Update(); virtual;
351 procedure RememberState();
352 procedure RecallState();
353 procedure SaveState (st
: TStream
); virtual;
354 procedure LoadState (st
: TStream
); virtual;
355 procedure PauseSounds(Enable
: Boolean);
356 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
357 procedure DoLerp(Level
: Integer = 2);
358 procedure SetLerp(XTo
, YTo
: Integer);
359 procedure ProcessWeaponAction(Action
: Byte);
360 procedure QueueWeaponSwitch(Weapon
: Byte);
361 procedure RealizeCurrentWeapon();
365 procedure JetpackOff
;
366 procedure CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
368 //WARNING! this does nothing for now, but still call it!
369 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
371 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
372 procedure moveBy (dx
, dy
: Integer); inline;
374 function getCameraObj(): TObj
;
376 function GetAmmoByWeapon(Weapon
: Byte): Word; // private state
379 property Vel
: TPoint2i read FObj
.Vel
;
380 property Obj
: TObj read FObj
;
382 property Name
: String read FName write FName
;
383 property Model
: TPlayerModel read FModel
;
384 property Health
: Integer read FHealth write FHealth
;
385 property Lives
: Byte read FLives write FLives
;
386 property Armor
: Integer read FArmor write FArmor
;
387 property Air
: Integer read FAir write FAir
;
388 property JetFuel
: Integer read FJetFuel write FJetFuel
;
389 property Frags
: Integer read FFrags write FFrags
;
390 property Death
: Integer read FDeath write FDeath
;
391 property Kills
: Integer read FKills write FKills
;
392 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
393 property WeapSwitchMode
: Byte read FWeapSwitchMode write FWeapSwitchMode
;
394 property SwitchToEmpty
: Byte read FSwitchToEmpty write FSwitchToEmpty
;
395 property SkipFist
: Byte read FSkipFist write FSkipFist
;
396 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
397 property Secrets
: Integer read FSecrets
;
398 property GodMode
: Boolean read FGodMode write FGodMode
;
399 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
400 property NoReload
: Boolean read FNoReload write FNoReload
;
401 property alive
: Boolean read FAlive write FAlive
;
402 property Flag
: Byte read FFlag
;
403 property Team
: Byte read FTeam write FTeam
;
404 property Direction
: TDirection read FDirection
;
405 property GameX
: Integer read FObj
.X write FObj
.X
;
406 property GameY
: Integer read FObj
.Y write FObj
.Y
;
407 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
408 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
409 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
410 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
411 property IncCam
: Integer read FIncCam write FIncCam
;
412 property IncCamOld
: Integer read FIncCamOld write FIncCamOld
;
413 property SlopeOld
: Integer read FSlopeOld write FSlopeOld
;
414 property UID
: Word read FUID write FUID
;
415 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
416 property NetTime
: LongWord read FNetTime write FNetTime
;
419 property Angle_
: SmallInt read FAngle
;
420 property Spectator
: Boolean read FSpectator
;
421 property NoRespawn
: Boolean read FNoRespawn
;
422 property Berserk
: Integer read FBerserk
;
423 property Pain
: Integer read FPain
;
424 property Pickup
: Integer read FPickup
;
425 property PunchAnim
: TAnimation read FPunchAnim write FPunchAnim
;
426 property SpawnInvul
: Integer read FSpawnInvul
;
427 property Ghost
: Boolean read FGhost
;
430 property eName
: String read FName write FName
;
431 property eHealth
: Integer read FHealth write FHealth
;
432 property eLives
: Byte read FLives write FLives
;
433 property eArmor
: Integer read FArmor write FArmor
;
434 property eAir
: Integer read FAir write FAir
;
435 property eJetFuel
: Integer read FJetFuel write FJetFuel
;
436 property eFrags
: Integer read FFrags write FFrags
;
437 property eDeath
: Integer read FDeath write FDeath
;
438 property eKills
: Integer read FKills write FKills
;
439 property eCurrWeap
: Byte read FCurrWeap write FCurrWeap
;
440 property eMonsterKills
: Integer read FMonsterKills write FMonsterKills
;
441 property eSecrets
: Integer read FSecrets write FSecrets
;
442 property eGodMode
: Boolean read FGodMode write FGodMode
;
443 property eNoTarget
: Boolean read FNoTarget write FNoTarget
;
444 property eNoReload
: Boolean read FNoReload write FNoReload
;
445 property eAlive
: Boolean read FAlive write FAlive
;
446 property eFlag
: Byte read FFlag
;
447 property eTeam
: Byte read FTeam write FTeam
;
448 property eDirection
: TDirection read FDirection
;
449 property eGameX
: Integer read FObj
.X write FObj
.X
;
450 property eGameY
: Integer read FObj
.Y write FObj
.Y
;
451 property eGameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
452 property eGameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
453 property eGameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
454 property eGameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
455 property eIncCam
: Integer read FIncCam write FIncCam
;
456 property eUID
: Word read FUID
;
457 property eJustTeleported
: Boolean read FJustTeleported
;
458 property eNetTime
: LongWord read FNetTime
;
460 // set this before assigning something to `eDamage`
461 property eDamageType
: Integer read mEDamageType write mEDamageType
;
462 property eDamage
: Integer write doDamage
;
473 WeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
474 CloseWeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
475 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
478 procedure save (st
: TStream
);
479 procedure load (st
: TStream
);
487 TBot
= class(TPlayer
)
489 FSelectedWeapon
: Byte;
492 FAIFlags
: Array of TAIFlag
;
493 FDifficult
: TDifficult
;
495 function GetRnd(a
: Byte): Boolean;
496 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
497 function RunDirection(): TDirection
;
498 function FullInStep(XInc
, YInc
: Integer): Boolean;
499 //function NeedItem(Item: Byte): Byte;
500 procedure SelectWeapon(Dist
: Integer);
501 procedure SetAIFlag(aName
, fValue
: String20
);
502 function GetAIFlag(aName
: String20
): String20
;
503 procedure RemoveAIFlag(aName
: String20
);
504 function Healthy(): Byte;
505 procedure UpdateMove();
506 procedure UpdateCombat();
507 function KeyPressed(Key
: Word): Boolean;
508 procedure ReleaseKey(Key
: Byte);
509 function TargetOnScreen(TX
, TY
: Integer): Boolean;
510 procedure OnDamage(Angle
: SmallInt); override;
513 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
514 constructor Create(); override;
515 destructor Destroy(); override;
516 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
517 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
518 procedure Update(); override;
519 procedure SaveState (st
: TStream
); override;
520 procedure LoadState (st
: TStream
); override;
533 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
534 procedure moveBy (dx
, dy
: Integer); inline;
536 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
550 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
551 procedure moveBy (dx
, dy
: Integer); inline;
553 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
556 TCorpse
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
565 FAnimation
: TAnimation
;
566 FAnimationMask
: TAnimation
;
569 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
570 destructor Destroy(); override;
571 procedure Damage(Value
: Word; SpawnerUID
: Word; vx
, vy
: Integer);
573 procedure SaveState (st
: TStream
);
574 procedure LoadState (st
: TStream
);
576 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
577 procedure moveBy (dx
, dy
: Integer); inline;
579 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
581 function ObjPtr (): PObj
; inline;
583 property Obj
: TObj read FObj
; // copies object
584 property State
: Byte read FState
;
585 property Mess
: Boolean read FMess
;
588 property Color
: TRGB read FColor
;
589 property Animation
: TAnimation read FAnimation
;
590 property AnimationMask
: TAnimation read FAnimationMask
;
593 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
599 gPlayers
: Array of TPlayer
;
600 gCorpses
: Array of TCorpse
;
601 gGibs
: Array of TGib
;
602 gShells
: Array of TShell
;
603 gTeamStat
: TTeamStat
;
604 gFly
: Boolean = False;
605 gAimLine
: Boolean = False;
606 gChatBubble
: Integer = 0;
607 gPlayerIndicator
: Integer = 1;
608 gPlayerIndicatorStyle
: Integer = 0;
610 gSpectLatchPID1
: Word = 0;
611 gSpectLatchPID2
: Word = 0;
612 MAX_RUNVEL
: Integer = 8;
613 VEL_JUMP
: Integer = 10;
614 SHELL_TIMEOUT
: Cardinal = 60000;
616 function Lerp(X
, Y
, Factor
: Integer): Integer;
618 procedure g_Gibs_SetMax(Count
: Word);
619 function g_Gibs_GetMax(): Word;
620 procedure g_Corpses_SetMax(Count
: Word);
621 function g_Corpses_GetMax(): Word;
622 procedure g_Force_Model_Set(Mode
: Word);
623 function g_Force_Model_Get(): Word;
624 procedure g_Forced_Model_SetName(Model
: String);
625 function g_Forced_Model_GetName(): String;
626 procedure g_Shells_SetMax(Count
: Word);
627 function g_Shells_GetMax(): Word;
629 procedure g_Player_Init();
630 procedure g_Player_Free();
631 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
632 function g_Player_CreateFromState (st
: TStream
): Word;
633 procedure g_Player_Remove(UID
: Word);
634 procedure g_Player_ResetTeams();
635 procedure g_Player_PreUpdate();
636 procedure g_Player_UpdateAll();
637 procedure g_Player_RememberAll();
638 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
639 function g_Player_Get(UID
: Word): TPlayer
;
640 function g_Player_GetCount(): Byte;
641 function g_Player_GetStats(): TPlayerStatArray
;
642 function g_Player_ValidName(Name
: String): Boolean;
643 function g_Player_CreateCorpse(Player
: TPlayer
): Integer;
644 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
645 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
646 procedure g_Player_UpdatePhysicalObjects();
647 procedure g_Player_RemoveAllCorpses();
648 procedure g_Player_Corpses_SaveState (st
: TStream
);
649 procedure g_Player_Corpses_LoadState (st
: TStream
);
650 procedure g_Player_ResetReady();
651 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
652 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
653 procedure g_Bot_MixNames();
654 procedure g_Bot_RemoveAll();
655 function g_Bot_GetCount(): Integer;
660 {$IFDEF ENABLE_HOLMES}
663 e_log
, g_map
, g_items
, g_console
, g_gfx
, Math
, r_textures
, r_animations
, r_gfx
,
664 g_options
, g_triggers
, g_menu
, g_game
, g_grid
, e_res
,
665 wadreader
, g_monsters
, CONFIG
, g_language
,
669 const PLR_SAVE_VERSION
= 0;
679 diag_precision
: Byte;
683 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
684 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
685 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
689 TIME_RESPAWN1
= 1500;
690 TIME_RESPAWN2
= 2000;
691 TIME_RESPAWN3
= 3000;
692 PLAYER_SUIT_TIME
= 30000;
693 PLAYER_INVUL_TIME
= 30000;
694 PLAYER_INVIS_TIME
= 35000;
695 FRAG_COMBO_TIME
= 3000;
698 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
701 BOT_UNSAFEDIST
= 128;
702 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
703 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
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_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
706 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
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 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
709 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
710 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
711 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
712 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
713 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
714 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
715 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
716 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
717 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
718 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
719 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
720 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
721 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
722 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
723 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
724 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
725 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
726 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
727 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
729 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
730 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
732 BOTNAMES_FILENAME
= 'botnames.txt';
733 BOTLIST_FILENAME
= 'botlist.txt';
737 MaxCorpses
: Word = 20;
738 MaxShells
: Word = 300;
739 ForceModel
: Word = 0;
740 ForcedModelName
: String = STD_PLAYER_MODEL
;
741 CurrentGib
: Integer = 0;
742 CurrentShell
: Integer = 0;
743 BotNames
: Array of String;
744 BotList
: Array of TBotProfile
;
745 SavedStates
: Array of TPlayerSavedState
;
748 function Lerp(X
, Y
, Factor
: Integer): Integer;
750 Result
:= X
+ ((Y
- X
) div Factor
);
753 function SameTeam(UID1
, UID2
: Word): Boolean;
757 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
758 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
760 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
762 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
763 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
765 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
768 procedure g_Gibs_SetMax(Count
: Word);
771 SetLength(gGibs
, Count
);
773 if CurrentGib
>= Count
then
777 function g_Gibs_GetMax(): Word;
782 procedure g_Shells_SetMax(Count
: Word);
785 SetLength(gShells
, Count
);
787 if CurrentShell
>= Count
then
791 function g_Shells_GetMax(): Word;
797 procedure g_Corpses_SetMax(Count
: Word);
800 SetLength(gCorpses
, Count
);
803 function g_Corpses_GetMax(): Word;
805 Result
:= MaxCorpses
;
808 procedure g_Force_Model_Set(Mode
: Word);
813 function g_Force_Model_Get(): Word;
815 Result
:= ForceModel
;
818 procedure g_Forced_Model_SetName(Model
: String);
820 ForcedModelName
:= Model
;
823 function g_Forced_Model_GetName(): String;
825 Result
:= ForcedModelName
;
828 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
838 // Есть ли место в gPlayers:
839 if gPlayers
<> nil then
840 for a
:= 0 to High(gPlayers
) do
841 if gPlayers
[a
] = nil then
847 // Нет места - расширяем gPlayers:
850 SetLength(gPlayers
, Length(gPlayers
)+1);
854 // Создаем объект игрока:
856 gPlayers
[a
] := TBot
.Create()
858 gPlayers
[a
] := TPlayer
.Create();
861 gPlayers
[a
].FActualModelName
:= ModelName
;
862 gPlayers
[a
].SetModel(ModelName
);
863 if Bot
and (g_Force_Model_Get() <> 0) then
864 gPlayers
[a
].SetModel(g_Forced_Model_GetName());
866 // Нет модели - создание не возможно:
867 if gPlayers
[a
].FModel
= nil then
871 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
875 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
876 if Random(2) = 0 then
880 gPlayers
[a
].FPreferredTeam
:= Team
;
882 case gGameSettings
.GameMode
of
883 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
885 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
887 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
890 // Если командная игра - красим модель в цвет команды:
891 gPlayers
[a
].FColor
:= Color
;
892 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
893 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
895 gPlayers
[a
].FModel
.Color
:= Color
;
897 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
898 gPlayers
[a
].FAlive
:= False;
900 Result
:= gPlayers
[a
].FUID
;
903 function g_Player_CreateFromState (st
: TStream
): Word;
904 var a
: Integer; ok
, Bot
: Boolean; pos
: Int64;
908 // check signature and entity type
910 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
911 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
912 Bot
:= utils
.readBool(st
);
915 // find free player slot
917 for a
:= 0 to High(gPlayers
) do
918 if gPlayers
[a
] = nil then
924 // allocate player slot
927 SetLength(gPlayers
, Length(gPlayers
)+1);
931 // create entity and load state
934 gPlayers
[a
] := TBot
.Create();
935 if (g_Force_Model_Get() <> 0) then
936 gPlayers
[a
].SetModel(g_Forced_Model_GetName());
939 gPlayers
[a
] := TPlayer
.Create();
940 gPlayers
[a
].FPhysics
:= True; // ???
941 gPlayers
[a
].LoadState(st
);
943 result
:= gPlayers
[a
].FUID
;
947 procedure g_Player_ResetTeams();
951 if g_Game_IsClient
then
953 if gPlayers
= nil then
955 for a
:= Low(gPlayers
) to High(gPlayers
) do
956 if gPlayers
[a
] <> nil then
957 case gGameSettings
.GameMode
of
959 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
961 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
962 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
963 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
966 gPlayers
[a
].ChangeTeam(TEAM_RED
)
968 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
971 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
975 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
978 _name
, _model
: String;
981 if not g_Game_IsServer
then Exit
;
983 if (g_Bot_GetCount() >= gMaxBots
) then Exit
;
985 // Список названий моделей:
986 m
:= g_PlayerModel_GetNames();
991 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
992 Team
:= TEAM_COOP
// COOP
994 if gGameSettings
.GameMode
= GM_DM
then
995 Team
:= TEAM_NONE
// DM
997 if Team
= TEAM_NONE
then // CTF / TDM
999 // Автобаланс команд:
1003 for a
:= 0 to High(gPlayers
) do
1004 if gPlayers
[a
] <> nil then
1006 if gPlayers
[a
].Team
= TEAM_RED
then
1009 if gPlayers
[a
].Team
= TEAM_BLUE
then
1019 if Random(2) = 0 then
1025 // Выбираем боту имя:
1027 if BotNames
<> nil then
1028 for a
:= 0 to High(BotNames
) do
1029 if g_Player_ValidName(BotNames
[a
]) then
1031 _name
:= BotNames
[a
];
1035 // Выбираем случайную модель:
1036 _model
:= m
[Random(Length(m
))];
1039 with g_Player_Get(g_Player_Create(_model
,
1040 _RGB(Min(Random(9)*32, 255),
1041 Min(Random(9)*32, 255),
1042 Min(Random(9)*32, 255)),
1043 Team
, True)) as TBot
do
1045 // Если имени нет, делаем его из UID бота
1047 Name
:= Format('DFBOT%.5d', [UID
])
1052 1: FDifficult
:= DIFFICULT_EASY
;
1053 2: FDifficult
:= DIFFICULT_MEDIUM
;
1054 else FDifficult
:= DIFFICULT_HARD
;
1057 for a
:= WP_FIRST
to WP_LAST
do
1059 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1060 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1061 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1064 FHandicap
:= Handicap
;
1066 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1068 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1069 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1074 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
1077 _name
, _model
: String;
1080 if not g_Game_IsServer
then Exit
;
1082 if (g_Bot_GetCount() >= gMaxBots
) then Exit
;
1084 // Список названий моделей:
1085 m
:= g_PlayerModel_GetNames();
1090 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1091 Team
:= TEAM_COOP
// COOP
1093 if gGameSettings
.GameMode
= GM_DM
then
1094 Team
:= TEAM_NONE
// DM
1096 if Team
= TEAM_NONE
then
1097 Team
:= BotList
[num
].team
; // CTF / TDM
1099 // Выбираем настройки бота из списка по номеру или имени:
1100 lName
:= AnsiLowerCase(lName
);
1101 if (num
< 0) or (num
> Length(BotList
)-1) then
1103 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1104 for a
:= 0 to High(BotList
) do
1105 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1114 _name
:= BotList
[num
].name
;
1115 // Занято - выбираем случайное:
1116 if not g_Player_ValidName(_name
) then
1118 _name
:= Format('DFBOT%.2d', [Random(100)]);
1119 until g_Player_ValidName(_name
);
1122 _model
:= BotList
[num
].model
;
1123 // Нет такой - выбираем случайную:
1124 if not InSArray(_model
, m
) then
1125 _model
:= m
[Random(Length(m
))];
1128 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1132 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1133 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1134 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1135 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1136 FDifficult
.Cover
:= BotList
[num
].cover
;
1137 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1139 FHandicap
:= Handicap
;
1141 for a
:= WP_FIRST
to WP_LAST
do
1143 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1144 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1145 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1148 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1150 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1154 procedure g_Bot_RemoveAll();
1158 if not g_Game_IsServer
then Exit
;
1159 if gPlayers
= nil then Exit
;
1161 for a
:= 0 to High(gPlayers
) do
1162 if gPlayers
[a
] <> nil then
1163 if gPlayers
[a
] is TBot
then
1165 gPlayers
[a
].Lives
:= 0;
1166 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1167 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1168 g_Player_Remove(gPlayers
[a
].FUID
);
1174 procedure g_Bot_MixNames();
1179 if BotNames
<> nil then
1180 for a
:= 0 to High(BotNames
) do
1182 b
:= Random(Length(BotNames
));
1184 Botnames
[a
] := BotNames
[b
];
1189 procedure g_Player_Remove(UID
: Word);
1193 if gPlayers
= nil then Exit
;
1195 if g_Game_IsServer
and g_Game_IsNet
then
1196 MH_SEND_PlayerDelete(UID
);
1198 for i
:= 0 to High(gPlayers
) do
1199 if gPlayers
[i
] <> nil then
1200 if gPlayers
[i
].FUID
= UID
then
1202 if gPlayers
[i
] is TPlayer
then
1203 TPlayer(gPlayers
[i
]).Free()
1205 TBot(gPlayers
[i
]).Free();
1211 procedure g_Player_Init();
1222 path
:= BOTNAMES_FILENAME
;
1223 if e_FindResource(DataDirs
, path
) = false then
1226 // Читаем возможные имена ботов из файла:
1227 AssignFile(F
, path
);
1238 SetLength(BotNames
, Length(BotNames
)+1);
1239 BotNames
[High(BotNames
)] := s
;
1247 // Читаем файл с параметрами ботов:
1248 config
:= TConfig
.CreateFile(path
);
1252 while config
.SectionExists(IntToStr(a
)) do
1254 SetLength(BotList
, Length(BotList
)+1);
1256 with BotList
[High(BotList
)] do
1259 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1261 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1263 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1268 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1269 color
.R
:= StrToIntDef(sa
[0], 0);
1270 color
.G
:= StrToIntDef(sa
[1], 0);
1271 color
.B
:= StrToIntDef(sa
[2], 0);
1272 // Вероятность стрельбы под углом:
1273 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1274 // Вероятность ответного огня по невидимому сопернику:
1275 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1276 // Точность стрельбы под углом:
1277 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1278 // Точность стрельбы в полете:
1279 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1280 // Точность уклонения от снарядов:
1281 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1282 // Вероятность прыжка при приближении соперника:
1283 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1284 // Приоритеты оружия для дальнего боя:
1285 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1286 if Length(sa
) = 10 then
1288 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1289 // Приоритеты оружия для ближнего боя:
1290 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1291 if Length(sa
) = 10 then
1293 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1295 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1296 if Length(sa) = 10 then
1298 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1305 SetLength(SavedStates
, 0);
1308 procedure g_Player_Free();
1312 if gPlayers
<> nil then
1314 for i
:= 0 to High(gPlayers
) do
1315 if gPlayers
[i
] <> nil then
1317 if gPlayers
[i
] is TPlayer
then
1318 TPlayer(gPlayers
[i
]).Free()
1320 TBot(gPlayers
[i
]).Free();
1329 SetLength(SavedStates
, 0);
1332 procedure g_Player_PreUpdate();
1336 if gPlayers
= nil then Exit
;
1337 for i
:= 0 to High(gPlayers
) do
1338 if gPlayers
[i
] <> nil then
1339 gPlayers
[i
].PreUpdate();
1342 procedure g_Player_UpdateAll();
1346 if gPlayers
= nil then Exit
;
1348 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1349 for i
:= 0 to High(gPlayers
) do
1351 if gPlayers
[i
] <> nil then
1353 if gPlayers
[i
] is TPlayer
then
1355 gPlayers
[i
].Update();
1356 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1360 // bot updates weapons in `UpdateCombat()`
1361 TBot(gPlayers
[i
]).Update();
1365 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1368 function g_Player_Get(UID
: Word): TPlayer
;
1374 if gPlayers
= nil then
1377 for a
:= 0 to High(gPlayers
) do
1378 if gPlayers
[a
] <> nil then
1379 if gPlayers
[a
].FUID
= UID
then
1381 Result
:= gPlayers
[a
];
1386 function g_Player_GetCount(): Byte;
1392 if gPlayers
= nil then
1395 for a
:= 0 to High(gPlayers
) do
1396 if gPlayers
[a
] <> nil then
1397 Result
:= Result
+ 1;
1400 function g_Bot_GetCount(): Integer;
1406 if gPlayers
= nil then
1409 for a
:= 0 to High(gPlayers
) do
1410 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] is TBot
) then
1411 Result
:= Result
+ 1;
1414 function g_Player_GetStats(): TPlayerStatArray
;
1420 if gPlayers
= nil then Exit
;
1422 for a
:= 0 to High(gPlayers
) do
1423 if gPlayers
[a
] <> nil then
1425 SetLength(Result
, Length(Result
)+1);
1426 with Result
[High(Result
)] do
1429 Ping
:= gPlayers
[a
].FPing
;
1430 Loss
:= gPlayers
[a
].FLoss
;
1431 Name
:= gPlayers
[a
].FName
;
1432 Team
:= gPlayers
[a
].FTeam
;
1433 Frags
:= gPlayers
[a
].FFrags
;
1434 Deaths
:= gPlayers
[a
].FDeath
;
1435 Kills
:= gPlayers
[a
].FKills
;
1436 Color
:= gPlayers
[a
].FModel
.Color
;
1437 Lives
:= gPlayers
[a
].FLives
;
1438 Spectator
:= gPlayers
[a
].FSpectator
;
1439 UID
:= gPlayers
[a
].FUID
;
1444 procedure g_Player_ResetReady();
1448 if not g_Game_IsServer
then Exit
;
1449 if gPlayers
= nil then Exit
;
1451 for a
:= 0 to High(gPlayers
) do
1452 if gPlayers
[a
] <> nil then
1454 gPlayers
[a
].FReady
:= False;
1455 if g_Game_IsNet
then
1456 MH_SEND_GameEvent(NET_EV_INTER_READY
, gPlayers
[a
].UID
, 'N');
1460 procedure g_Player_RememberAll
;
1464 for i
:= Low(gPlayers
) to High(gPlayers
) do
1465 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1466 gPlayers
[i
].RememberState
;
1469 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1473 gTeamStat
[TEAM_RED
].Score
:= 0;
1474 gTeamStat
[TEAM_BLUE
].Score
:= 0;
1476 if gPlayers
<> nil then
1477 for i
:= 0 to High(gPlayers
) do
1478 if gPlayers
[i
] <> nil then
1480 gPlayers
[i
].Reset(Force
);
1482 if gPlayers
[i
] is TPlayer
then
1484 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1485 gPlayers
[i
].Respawn(Silent
)
1487 gPlayers
[i
].Spectate();
1490 TBot(gPlayers
[i
]).Respawn(Silent
);
1494 function g_Player_CreateCorpse(Player
: TPlayer
): Integer;
1502 if Player
.alive
then
1505 // Разрываем связь с прежним трупом:
1506 i
:= Player
.FCorpse
;
1507 if (i
>= 0) and (i
< Length(gCorpses
)) then
1509 if (gCorpses
[i
] <> nil) and (gCorpses
[i
].FPlayerUID
= Player
.FUID
) then
1510 gCorpses
[i
].FPlayerUID
:= 0;
1513 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1518 if (FHealth
>= -50) or (gGibsCount
= 0) then
1520 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1524 for find_id
:= 0 to High(gCorpses
) do
1525 if gCorpses
[find_id
] = nil then
1532 find_id
:= Random(Length(gCorpses
));
1534 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.GetName(), FHealth
< -20);
1535 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1536 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1537 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1538 gCorpses
[find_id
].FPlayerUID
:= FUID
;
1543 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1544 FObj
.Y
+ PLAYER_RECT_CY
,
1545 FModel
.GetName(), FModel
.Color
);
1549 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1553 if (gShells
= nil) or (Length(gShells
) = 0) then
1556 with gShells
[CurrentShell
] do
1562 if T
= SHELL_BULLET
then
1564 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1568 Obj
.Rect
.Width
:= 4;
1569 Obj
.Rect
.Height
:= 2;
1573 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1577 Obj
.Rect
.Width
:= 7;
1578 Obj
.Rect
.Height
:= 3;
1584 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1585 positionChanged(); // this updates spatial accelerators
1586 RAngle
:= Random(360);
1587 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1589 if CurrentShell
>= High(gShells
) then
1596 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1599 GibsArray
: TGibsArray
;
1602 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1604 mid
:= g_PlayerModel_GetIndex(ModelName
);
1607 if not g_PlayerModel_GetGibs(mid
, GibsArray
) then
1609 Blood
:= PlayerModelsArray
[mid
].Blood
;
1611 for a
:= 0 to High(GibsArray
) do
1612 with gGibs
[CurrentGib
] do
1615 GibID
:= GibsArray
[a
];
1619 Obj
.Rect
:= r_PlayerModel_GetGibRect(ModelID
, GibID
);
1620 Obj
.X
:= fX
- Obj
.Rect
.X
- (Obj
.Rect
.Width
div 2);
1621 Obj
.Y
:= fY
- Obj
.Rect
.Y
- (Obj
.Rect
.Height
div 2);
1622 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1623 positionChanged(); // this updates spatial accelerators
1624 RAngle
:= Random(360);
1626 if gBloodCount
> 0 then
1627 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1628 Random(48), Random(48), Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
1630 if CurrentGib
>= High(gGibs
) then
1637 procedure g_Player_UpdatePhysicalObjects();
1643 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1648 if T
= SHELL_BULLET
then
1649 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1651 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1656 if gGibs
<> nil then
1657 for i
:= 0 to High(gGibs
) do
1658 if gGibs
[i
].alive
then
1665 mr
:= g_Obj_Move(@Obj
, True, False, True);
1666 positionChanged(); // this updates spatial accelerators
1668 if WordBool(mr
and MOVE_FALLOUT
) then
1674 // Отлетает от удара о стену/потолок/пол:
1675 if WordBool(mr
and MOVE_HITWALL
) then
1676 Obj
.Vel
.X
:= -(vel
.X
div 2);
1677 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1678 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1680 if (Obj
.Vel
.X
>= 0) then
1682 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1683 if RAngle
>= 360 then
1684 RAngle
:= RAngle
mod 360;
1685 end else begin // Counter-clockwise
1686 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1688 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1691 // Сопротивление воздуха для куска трупа:
1692 if gTime
mod (GAME_TICK
*3) = 0 then
1693 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1697 if gCorpses
<> nil then
1698 for i
:= 0 to High(gCorpses
) do
1699 if gCorpses
[i
] <> nil then
1700 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1706 gCorpses
[i
].Update();
1709 if gShells
<> nil then
1710 for i
:= 0 to High(gShells
) do
1711 if gShells
[i
].alive
then
1718 mr
:= g_Obj_Move(@Obj
, True, False, True);
1719 positionChanged(); // this updates spatial accelerators
1721 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1727 // Отлетает от удара о стену/потолок/пол:
1728 if WordBool(mr
and MOVE_HITWALL
) then
1730 Obj
.Vel
.X
:= -(vel
.X
div 2);
1731 if not WordBool(mr
and MOVE_INWATER
) then
1732 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1734 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1736 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1737 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1738 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1740 if RAngle
mod 90 <> 0 then
1741 RAngle
:= (RAngle
div 90) * 90;
1743 else if not WordBool(mr
and MOVE_INWATER
) then
1744 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1747 if (Obj
.Vel
.X
>= 0) then
1749 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1750 if RAngle
>= 360 then
1751 RAngle
:= RAngle
mod 360;
1752 end else begin // Counter-clockwise
1753 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1755 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1761 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1763 x
:= Obj
.X
+Obj
.Rect
.X
;
1764 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1765 w
:= Obj
.Rect
.Width
;
1766 h
:= Obj
.Rect
.Height
;
1769 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1771 if (dx
<> 0) or (dy
<> 0) then
1780 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1784 w
:= Obj
.Rect
.Width
;
1785 h
:= Obj
.Rect
.Height
;
1788 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1790 if (dx
<> 0) or (dy
<> 0) then
1799 procedure TGib
.positionChanged (); inline; begin end;
1800 procedure TShell
.positionChanged (); inline; begin end;
1803 procedure g_Player_RemoveAllCorpses();
1809 SetLength(gGibs
, MaxGibs
);
1810 SetLength(gShells
, MaxGibs
);
1814 if gCorpses
<> nil then
1815 for i
:= 0 to High(gCorpses
) do
1819 SetLength(gCorpses
, MaxCorpses
);
1822 procedure g_Player_Corpses_SaveState (st
: TStream
);
1826 // Считаем количество существующих трупов
1828 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1830 // Количество трупов
1831 utils
.writeInt(st
, LongInt(count
));
1833 if (count
= 0) then exit
;
1836 for i
:= 0 to High(gCorpses
) do
1838 if gCorpses
[i
] <> nil then
1841 utils
.writeStr(st
, gCorpses
[i
].FModelName
);
1843 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1844 // Сохраняем данные трупа:
1845 gCorpses
[i
].SaveState(st
);
1851 procedure g_Player_Corpses_LoadState (st
: TStream
);
1859 g_Player_RemoveAllCorpses();
1861 // Количество трупов:
1862 count
:= utils
.readLongInt(st
);
1863 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1865 if (count
= 0) then exit
;
1868 for i
:= 0 to count
-1 do
1871 str
:= utils
.readStr(st
);
1873 b
:= utils
.readBool(st
);
1875 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1876 // Загружаем данные трупа
1877 gCorpses
[i
].LoadState(st
);
1884 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1886 procedure TPlayer
.BFGHit();
1888 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1889 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1890 if g_Game_IsServer
and g_Game_IsNet
then
1891 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1892 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1896 procedure TPlayer
.ChangeModel(ModelName
: string);
1898 locModel
: TPlayerModel
;
1900 locModel
:= g_PlayerModel_Get(ModelName
);
1901 if locModel
= nil then Exit
;
1907 procedure TPlayer
.SetModel(ModelName
: string);
1911 m
:= g_PlayerModel_Get(ModelName
);
1914 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1915 m
:= g_PlayerModel_Get('doomer');
1918 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1923 if FModel
<> nil then
1928 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1929 FModel
.Color
:= FColor
1931 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1932 FModel
.SetWeapon(FCurrWeap
);
1933 FModel
.SetFlag(FFlag
);
1934 SetDirection(FDirection
);
1937 procedure TPlayer
.SetColor(Color
: TRGB
);
1940 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1941 if FModel
<> nil then FModel
.Color
:= Color
;
1946 function TPlayer
.GetColor(): TRGB
;
1948 result
:= FModel
.Color
;
1951 procedure TPlayer
.SetWeaponPrefs(Prefs
: Array of Byte);
1955 for i
:= WP_FIRST
to WP_LAST
+ 1 do
1957 if (Prefs
[i
] > WP_LAST
+ 1) then
1958 FWeapPreferences
[i
] := 0
1960 FWeapPreferences
[i
] := Prefs
[i
];
1964 procedure TPlayer
.SetWeaponPref(Weapon
, Pref
: Byte);
1966 if (Weapon
> WP_LAST
+ 1) then
1968 else if (Pref
<= WP_LAST
+ 1) and (Weapon
<= WP_LAST
+ 1) then
1969 FWeapPreferences
[Weapon
] := Pref
1970 else if (Weapon
<= WP_LAST
+ 1) and (Pref
> WP_LAST
+ 1) then
1971 FWeapPreferences
[Weapon
] := 0;
1974 function TPlayer
.GetWeaponPref(Weapon
: Byte) : Byte;
1976 if (Weapon
> WP_LAST
+ 1) then
1978 else if (FWeapPreferences
[Weapon
] > WP_LAST
+ 1) then
1981 result
:= FWeapPreferences
[Weapon
];
1984 function TPlayer
.GetMorePrefered() : Byte;
1986 testedWeap
, i
: Byte;
1988 testedWeap
:= FCurrWeap
;
1989 for i
:= WP_FIRST
to WP_LAST
do
1990 if FWeapon
[i
] and maySwitch(i
) and (FWeapPreferences
[i
] > FWeapPreferences
[testedWeap
]) then
1992 if (R_BERSERK
in FRulez
) and (FWeapPreferences
[WP_LAST
+ 1] > FWeapPreferences
[testedWeap
]) then
1993 testedWeap
:= WEAPON_KASTET
;
1994 result
:= testedWeap
;
1997 function TPlayer
.maySwitch(Weapon
: Byte) : Boolean;
2000 if (Weapon
= WEAPON_KASTET
) and (FSkipFist
<> 0) then
2002 if (FSkipFist
= 1) and (not (R_BERSERK
in FRulez
)) then
2005 else if (FSwitchToEmpty
= 0) and (not hasAmmoForShooting(Weapon
)) then
2009 procedure TPlayer
.SwitchTeam
;
2011 if g_Game_IsClient
then
2013 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
2015 if gGameOn
and FAlive
then
2016 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
2018 if FTeam
= TEAM_RED
then
2020 ChangeTeam(TEAM_BLUE
);
2021 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
2022 if g_Game_IsNet
then
2023 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
2027 ChangeTeam(TEAM_RED
);
2028 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
2029 if g_Game_IsNet
then
2030 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
2032 FPreferredTeam
:= FTeam
;
2035 procedure TPlayer
.ChangeTeam(Team
: Byte);
2042 TEAM_RED
, TEAM_BLUE
:
2043 FModel
.Color
:= TEAMCOLOR
[Team
];
2045 FModel
.Color
:= FColor
;
2047 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2048 MH_SEND_PlayerStats(FUID
);
2052 procedure TPlayer.CollideItem();
2057 if gItems = nil then Exit;
2058 if not FAlive then Exit;
2060 for i := 0 to High(gItems) do
2063 if (ItemType <> ITEM_NONE) and alive then
2064 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2065 PLAYER_RECT.Height, @Obj) then
2067 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2069 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2070 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2071 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2072 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2073 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2075 // Надо убрать с карты, если это не ключ, которым нужно поделится с другим игроком:
2076 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2077 (gGameSettings.GameType = GT_SINGLE) and
2078 (g_Player_GetCount() > 1)) then
2079 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2085 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2087 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2088 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2092 constructor TPlayer
.Create();
2098 mEDamageType
:= HIT_SOME
;
2104 FSawSound
:= TPlayableSound
.Create();
2105 FSawSoundIdle
:= TPlayableSound
.Create();
2106 FSawSoundHit
:= TPlayableSound
.Create();
2107 FSawSoundSelect
:= TPlayableSound
.Create();
2108 FFlameSoundOn
:= TPlayableSound
.Create();
2109 FFlameSoundOff
:= TPlayableSound
.Create();
2110 FFlameSoundWork
:= TPlayableSound
.Create();
2111 FJetSoundFly
:= TPlayableSound
.Create();
2112 FJetSoundOn
:= TPlayableSound
.Create();
2113 FJetSoundOff
:= TPlayableSound
.Create();
2115 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2116 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2117 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2118 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2119 FFlameSoundOn
.SetByName('SOUND_WEAPON_FLAMEON');
2120 FFlameSoundOff
.SetByName('SOUND_WEAPON_FLAMEOFF');
2121 FFlameSoundWork
.SetByName('SOUND_WEAPON_FLAMEWORK');
2122 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2123 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2124 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2126 FSpectatePlayer
:= -1;
2130 FSavedStateNum
:= -1;
2138 FActualModelName
:= 'doomer';
2141 FObj
.Rect
:= PLAYER_RECT
;
2143 FBFGFireCounter
:= -1;
2144 FJustTeleported
:= False;
2147 FWaitForFirstSpawn
:= false;
2152 procedure TPlayer
.positionChanged (); inline;
2156 procedure TPlayer
.doDamage (v
: Integer);
2158 if (v
<= 0) then exit
;
2159 if (v
> 32767) then v
:= 32767;
2160 Damage(v
, 0, 0, 0, mEDamageType
);
2163 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2167 if (not g_Game_IsClient
) and (not FAlive
) then
2172 // Неуязвимость не спасает от ловушек:
2173 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2175 if not g_Game_IsClient
then
2178 if t
= HIT_TRAP
then
2180 // Ловушка убивает сразу:
2182 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2184 if t
= HIT_SELF
then
2188 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2191 // Обнулить действия примочек, чтобы фон пропал
2192 FMegaRulez
[MR_SUIT
] := 0;
2193 FMegaRulez
[MR_INVUL
] := 0;
2194 FMegaRulez
[MR_INVIS
] := 0;
2199 // Но от остального спасает:
2200 if FMegaRulez
[MR_INVUL
] >= gTime
then
2207 // Если есть урон своим, или ранил сам себя, или тебя ранил противник:
2208 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2209 (SpawnerUID
= FUID
) or
2210 (not SameTeam(FUID
, SpawnerUID
)) then
2212 FLastSpawnerUID
:= SpawnerUID
;
2214 // Кровь (пузырьки, если в воде):
2215 if gBloodCount
> 0 then
2217 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2218 if value
div 4 <= c
then
2219 c
:= c
- (value
div 4)
2223 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2227 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2228 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2231 if t
= HIT_WATER
then
2233 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2234 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2236 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
2237 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
2243 Inc(FDamageBuffer
, value
);
2247 FPain
:= FPain
+ value
;
2250 if g_Game_IsServer
and g_Game_IsNet
then
2252 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2253 MH_SEND_PlayerStats(FUID
);
2254 MH_SEND_PlayerPos(False, FUID
);
2258 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2261 if g_Game_IsClient
then
2266 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2268 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2271 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2273 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2277 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2278 MH_SEND_PlayerStats(FUID
);
2281 destructor TPlayer
.Destroy();
2283 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2285 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2289 FSawSoundIdle
.Free();
2290 FSawSoundHit
.Free();
2291 FSawSoundSelect
.Free();
2292 FFlameSoundOn
.Free();
2293 FFlameSoundOff
.Free();
2294 FFlameSoundWork
.Free();
2295 FJetSoundFly
.Free();
2297 FJetSoundOff
.Free();
2299 if FPunchAnim
<> nil then
2305 procedure TPlayer
.DoPunch();
2310 if FPunchAnim
<> nil then begin
2315 st
:= 'FRAMES_PUNCH';
2316 if R_BERSERK
in FRulez
then
2317 st
:= st
+ '_BERSERK';
2318 if FKeys
[KEY_UP
].Pressed
then
2320 else if FKeys
[KEY_DOWN
].Pressed
then
2322 g_Frames_Get(id
, st
);
2323 FPunchAnim
:= TAnimation
.Create(id
, False, 1);
2326 procedure TPlayer
.Fire();
2328 f
, DidFire
: Boolean;
2329 wx
, wy
, xd
, yd
: Integer;
2332 if g_Game_IsClient
then Exit
;
2333 // FBFGFireCounter - время перед выстрелом (для BFG)
2334 // FReloading - время после выстрела (для всего)
2342 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2347 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2348 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2349 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
2350 yd
:= wy
+firediry();
2356 if R_BERSERK
in FRulez
then
2358 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2359 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2360 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2363 locobj
.rect
.Width
:= 39;
2364 locobj
.rect
.Height
:= 52;
2365 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2366 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2367 locobj
.Accel
.X
:= xd
-wx
;
2368 locobj
.Accel
.y
:= yd
-wy
;
2370 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2371 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2373 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2375 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
2379 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2383 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2388 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2389 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2391 FSawSoundSelect
.Stop();
2393 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2395 else if not FSawSoundHit
.IsPlaying() then
2397 FSawSoundSelect
.Stop();
2398 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2401 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2407 if FAmmo
[A_BULLETS
] > 0 then
2409 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2410 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2411 Dec(FAmmo
[A_BULLETS
]);
2412 FFireAngle
:= FAngle
;
2415 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2416 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2420 if FAmmo
[A_SHELLS
] > 0 then
2422 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2423 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
2424 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2425 Dec(FAmmo
[A_SHELLS
]);
2426 FFireAngle
:= FAngle
;
2430 FShellType
:= SHELL_SHELL
;
2434 if FAmmo
[A_SHELLS
] >= 2 then
2436 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
2437 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2438 Dec(FAmmo
[A_SHELLS
], 2);
2439 FFireAngle
:= FAngle
;
2443 FShellType
:= SHELL_DBLSHELL
;
2447 if FAmmo
[A_BULLETS
] > 0 then
2449 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
2450 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
2451 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2452 Dec(FAmmo
[A_BULLETS
]);
2453 FFireAngle
:= FAngle
;
2456 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2457 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2460 WEAPON_ROCKETLAUNCHER
:
2461 if FAmmo
[A_ROCKETS
] > 0 then
2463 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
2464 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2465 Dec(FAmmo
[A_ROCKETS
]);
2466 FFireAngle
:= FAngle
;
2472 if FAmmo
[A_CELLS
] > 0 then
2474 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
2475 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2476 Dec(FAmmo
[A_CELLS
]);
2477 FFireAngle
:= FAngle
;
2483 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
2485 FBFGFireCounter
:= 17;
2486 if not FNoReload
then
2487 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
2488 Dec(FAmmo
[A_CELLS
], 40);
2492 WEAPON_SUPERPULEMET
:
2493 if FAmmo
[A_SHELLS
] > 0 then
2495 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2496 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
2497 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2498 Dec(FAmmo
[A_SHELLS
]);
2499 FFireAngle
:= FAngle
;
2502 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2503 GameVelX
, GameVelY
-2, SHELL_SHELL
);
2506 WEAPON_FLAMETHROWER
:
2507 if FAmmo
[A_FUEL
] > 0 then
2509 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
2511 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2513 FFireAngle
:= FAngle
;
2520 if g_Game_IsNet
and g_Game_IsServer
then MH_SEND_PlayerStats(FUID
);
2524 if g_Game_IsNet
then
2528 if FCurrWeap
<> WEAPON_BFG
then
2529 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
2531 if not FNoReload
then
2532 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
2535 MH_SEND_PlayerStats(FUID
);
2540 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
2541 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
2542 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
2545 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
2548 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
2549 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
2550 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
2551 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
2552 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
2557 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
2559 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
2560 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
2561 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
2564 procedure TPlayer
.FlamerOn
;
2566 FFlameSoundOff
.Stop();
2567 FFlameSoundOff
.SetPosition(0);
2570 if (not FFlameSoundOn
.IsPlaying()) and (not FFlameSoundWork
.IsPlaying()) then
2571 FFlameSoundWork
.PlayAt(FObj
.X
, FObj
.Y
);
2575 FFlameSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
2580 procedure TPlayer
.FlamerOff
;
2584 FFlameSoundOn
.Stop();
2585 FFlameSoundOn
.SetPosition(0);
2586 FFlameSoundWork
.Stop();
2587 FFlameSoundWork
.SetPosition(0);
2588 FFlameSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
2593 procedure TPlayer
.JetpackOn
;
2597 FJetSoundOn
.SetPosition(0);
2598 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
2602 procedure TPlayer
.JetpackOff
;
2606 FJetSoundOff
.SetPosition(0);
2607 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
2610 procedure TPlayer
.CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
2612 if Timeout
<= 0 then
2614 if (FMegaRulez
[MR_SUIT
] > gTime
) or (FMegaRulez
[MR_INVUL
] > gTime
) then
2615 exit
; // Не загораемся когда есть защита
2616 if g_Obj_CollidePanel(@FObj
, 0, 0, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
) then
2617 exit
; // Не подгораем в воде на всякий случай
2618 if FFireTime
<= 0 then
2619 g_Sound_PlayExAt('SOUND_IGNITE', FObj
.X
, FObj
.Y
);
2620 FFireTime
:= Timeout
;
2621 FFireAttacker
:= Attacker
;
2622 if g_Game_IsNet
and g_Game_IsServer
then
2623 MH_SEND_PlayerStats(FUID
);
2626 procedure TPlayer
.Jump();
2628 if gFly
or FJetpack
then
2630 // Полет (чит-код или джетпак):
2631 if FObj
.Vel
.Y
> -VEL_FLY
then
2632 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
2635 if FJetFuel
> 0 then
2637 if (FJetFuel
< 1) and g_Game_IsServer
then
2641 if g_Game_IsNet
then
2642 MH_SEND_PlayerStats(FUID
);
2648 // Не включать джетпак в режиме прохождения сквозь стены
2650 FCanJetpack
:= False;
2652 // Прыгаем или всплываем:
2653 if (CollideLevel(0, 1) or
2654 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
2655 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
2656 ) and (FObj
.Accel
.Y
= 0) then // Не прыгать, если есть вертикальное ускорение
2658 FObj
.Vel
.Y
:= -VEL_JUMP
;
2659 FCanJetpack
:= False;
2663 if BodyInLiquid(0, 0) then
2664 FObj
.Vel
.Y
:= -VEL_SW
2665 else if (FJetFuel
> 0) and FCanJetpack
and
2666 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
2670 if g_Game_IsNet
then
2671 MH_SEND_PlayerStats(FUID
);
2676 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
2678 a
, i
, k
, ab
, ar
: Byte;
2682 srv
, netsrv
: Boolean;
2688 procedure PushItem(t
: Byte);
2692 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
2693 it
:= g_Items_ByIdx(id
);
2694 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
2696 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
2697 (FObj
.Vel
.Y
div 2)-Random(9));
2698 it
.positionChanged(); // this updates spatial accelerators
2702 if KillType
= K_HARDKILL
then // -5..+5; -5..0
2704 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
2705 (FObj
.Vel
.Y
div 2)-Random(6));
2707 else // -3..+3; -3..0
2709 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
2710 (FObj
.Vel
.Y
div 2)-Random(4));
2712 it
.positionChanged(); // this updates spatial accelerators
2715 if g_Game_IsNet
and g_Game_IsServer
then
2716 MH_SEND_ItemSpawn(True, id
);
2720 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
2721 Srv
:= g_Game_IsServer
;
2722 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
2723 if Srv
then FDeath
:= FDeath
+ 1;
2728 if not FPhysics
then
2734 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2736 if FLives
> 0 then FLives
:= FLives
- 1;
2737 if FLives
= 0 then FNoRespawn
:= True;
2740 // Номер типа смерти:
2743 K_SIMPLEKILL
: a
:= 1;
2745 K_EXTRAHARDKILL
: a
:= 3;
2750 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
2752 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
2759 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
2761 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
2762 K_EXTRAHARDKILL
, K_FALLKILL
:
2763 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
2766 // Переключаем состояние:
2770 K_HARDKILL
, K_EXTRAHARDKILL
:
2774 // Реакция монстров на смерть игрока:
2775 if (KillType
<> K_FALLKILL
) and (Srv
) then
2776 g_Monsters_killedp();
2778 if SpawnerUID
= FUID
then
2782 if gGameSettings
.GameMode
= GM_TDM
then
2783 Dec(gTeamStat
[FTeam
].Score
);
2784 if DoFrags
or (gGameSettings
.GameMode
= GM_TDM
) then
2790 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
2793 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
2794 begin // Убит другим игроком
2795 KP
:= g_Player_Get(SpawnerUID
);
2796 if (KP
<> nil) and Srv
then
2798 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
2799 if SameTeam(FUID
, SpawnerUID
) then
2809 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
2810 Inc(gTeamStat
[KP
.Team
].Score
,
2811 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
2813 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
2816 plr
:= g_Player_Get(SpawnerUID
);
2824 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
2828 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
2832 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
2837 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
2838 begin // Убит монстром
2839 mon
:= g_Monsters_ByUID(SpawnerUID
);
2843 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
2847 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
2851 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
2855 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
2860 else // Особые типы смерти
2863 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
2864 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
2865 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
2866 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
2867 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
2868 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
2874 for a
:= WP_FIRST
to WP_LAST
do
2878 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
2879 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
2880 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
2881 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
2882 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
2883 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
2884 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
2885 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
2886 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
2895 if R_ITEM_BACKPACK
in FRulez
then
2896 PushItem(ITEM_AMMO_BACKPACK
);
2898 // Выброс ракетного ранца:
2899 if FJetFuel
> 0 then
2900 PushItem(ITEM_JETPACK
);
2903 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) or
2904 (not LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
)) then
2906 if R_KEY_RED
in FRulez
then
2907 PushItem(ITEM_KEY_RED
);
2909 if R_KEY_GREEN
in FRulez
then
2910 PushItem(ITEM_KEY_GREEN
);
2912 if R_KEY_BLUE
in FRulez
then
2913 PushItem(ITEM_KEY_BLUE
);
2917 DropFlag(KillType
= K_FALLKILL
);
2920 FCorpse
:= g_Player_CreateCorpse(Self
);
2922 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
2923 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2929 for i
:= Low(gPlayers
) to High(gPlayers
) do
2931 if gPlayers
[i
] = nil then continue
;
2932 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
2935 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
2936 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
2941 OldLR
:= gLMSRespawn
;
2942 if (gGameSettings
.GameMode
= GM_COOP
) then
2946 // everyone is dead, restart the map
2947 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
2949 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
2950 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2951 gLMSRespawnTime
:= gTime
+ 5000;
2953 else if (a
= 1) then
2955 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
2956 if (gPlayers
[k
] = gPlayer1
) or
2957 (gPlayers
[k
] = gPlayer2
) then
2958 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
2959 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
2960 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
2963 else if (gGameSettings
.GameMode
= GM_TDM
) then
2965 if (ab
= 0) and (ar
<> 0) then
2968 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
2970 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
2971 Inc(gTeamStat
[TEAM_RED
].Score
);
2972 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2973 gLMSRespawnTime
:= gTime
+ 5000;
2975 else if (ar
= 0) and (ab
<> 0) then
2978 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
2980 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
2981 Inc(gTeamStat
[TEAM_BLUE
].Score
);
2982 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2983 gLMSRespawnTime
:= gTime
+ 5000;
2985 else if (ar
= 0) and (ab
= 0) then
2988 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
2990 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
2991 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2992 gLMSRespawnTime
:= gTime
+ 5000;
2995 else if (gGameSettings
.GameMode
= GM_DM
) then
2999 if gPlayers
[k
] <> nil then
3002 // survivor is the winner
3003 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3005 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3008 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3009 gLMSRespawnTime
:= gTime
+ 5000;
3011 else if (a
= 0) then
3013 // everyone is dead, restart the map
3014 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3016 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3017 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3018 gLMSRespawnTime
:= gTime
+ 5000;
3021 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3023 if NetMode
= NET_SERVER
then
3024 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
)
3026 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3032 MH_SEND_PlayerStats(FUID
);
3033 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3034 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3037 if srv
and FNoRespawn
then Spectate(True);
3038 FWantsInGame
:= True;
3041 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3043 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3044 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3047 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3049 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3050 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3053 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3054 var Blood
: TModelBlood
;
3056 Blood
:= SELF
.FModel
.GetBlood();
3057 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3058 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3059 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3060 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
3061 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3062 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3063 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3064 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
3067 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3068 var Blood
: TModelBlood
;
3070 Blood
:= SELF
.FModel
.GetBlood();
3071 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3072 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3073 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3074 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
3077 procedure TPlayer
.ProcessWeaponAction(Action
: Byte);
3079 if g_Game_IsClient
then Exit
;
3081 WP_PREV
: PrevWeapon();
3082 WP_NEXT
: NextWeapon();
3086 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3088 if g_Game_IsClient
then Exit
;
3089 if Weapon
> High(FWeapon
) then Exit
;
3090 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3093 procedure TPlayer
.resetWeaponQueue ();
3096 FNextWeapDelay
:= 0;
3099 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3103 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3104 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
3105 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
3106 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3107 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3108 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3109 else result
:= (weapon
< length(FWeapon
));
3113 function TPlayer
.hasAmmoForShooting (weapon
: Byte): Boolean;
3117 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3118 WEAPON_SHOTGUN1
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
3119 WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 1);
3120 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
3121 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3122 WEAPON_PLASMA
: result
:= (FAmmo
[A_CELLS
] > 0);
3123 WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] >= 40);
3124 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3125 else result
:= (weapon
< length(FWeapon
));
3129 function TPlayer
.shouldSwitch (weapon
: Byte; hadWeapon
: Boolean): Boolean;
3132 if (weapon
> WP_LAST
+ 1) then
3137 if (FWeapSwitchMode
= 1) and not hadWeapon
then
3139 else if (FWeapSwitchMode
= 2) then
3140 result
:= (FWeapPreferences
[weapon
] > FWeapPreferences
[FCurrWeap
]);
3143 // return 255 for "no switch"
3144 function TPlayer
.getNextWeaponIndex (): Byte;
3147 wantThisWeapon
: array[0..64] of Boolean;
3148 wwc
: Integer = 0; //HACK!
3151 result
:= 255; // default result: "no switch"
3152 //e_LogWriteFln('FSWITCHTOEMPTY: %s', [FSwitchToEmpty], TMsgType.Notify);
3153 // had weapon cycling on previous frame? remove that flag
3154 if (FNextWeap
and $2000) <> 0 then
3156 FNextWeap
:= FNextWeap
and $1FFF;
3157 FNextWeapDelay
:= 0;
3159 // cycling has priority
3160 if (FNextWeap
and $C000) <> 0 then
3162 if (FNextWeap
and $8000) <> 0 then
3166 FNextWeap
:= FNextWeap
or $2000; // we need this
3167 if FNextWeapDelay
> 0 then
3168 exit
; // cooldown time
3170 for i
:= 0 to High(FWeapon
) do
3172 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3173 if FWeapon
[cwi
] and maySwitch(cwi
) then
3175 //e_LogWriteFln(' SWITCH: cur=%d; new=%d %s %s', [FCurrWeap, cwi, FSwitchToEmpty, hasAmmoForWeapon(cwi)], TMsgType.Notify);
3176 result
:= Byte(cwi
);
3177 FNextWeapDelay
:= WEAPON_DELAY
;
3185 for i
:= 0 to High(wantThisWeapon
) do
3186 wantThisWeapon
[i
] := false;
3187 for i
:= 0 to High(FWeapon
) do
3188 if (FNextWeap
and (1 shl i
)) <> 0 then
3190 wantThisWeapon
[i
] := true;
3194 // exclude currently selected weapon from the set
3195 wantThisWeapon
[FCurrWeap
] := false;
3196 // slow down alterations a little
3199 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3200 // more than one weapon requested, assume "alteration" and check alteration delay
3201 if FNextWeapDelay
> 0 then
3207 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3208 // but clear all counters if no weapon should be switched
3214 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3215 // try weapons in descending order
3216 for i
:= High(FWeapon
) downto 0 do
3218 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3223 FNextWeapDelay
:= WEAPON_DELAY
* 2; // anyway, 'cause why not
3224 //e_LogWriteFln('FOUND %s %s %s', [result, FSwitchToEmpty, hasAmmoForWeapon(i)], TMsgType.Notify);
3228 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3232 procedure TPlayer
.RealizeCurrentWeapon();
3233 function switchAllowed (): Boolean;
3238 if FBFGFireCounter
<> -1 then
3240 if FTime
[T_SWITCH
] > gTime
then
3242 for i
:= WP_FIRST
to WP_LAST
do
3243 if FReloading
[i
] > 0 then
3251 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3252 //FNextWeap := FNextWeap and $1FFF;
3253 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3255 if not switchAllowed
then
3257 //HACK for weapon cycling
3258 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3262 nw
:= getNextWeaponIndex();
3264 if nw
= 255 then exit
; // don't reset anything here
3265 if nw
> High(FWeapon
) then
3267 // don't forget to reset queue here!
3268 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3276 FTime
[T_SWITCH
] := gTime
+156;
3277 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3278 FModel
.SetWeapon(FCurrWeap
);
3279 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3283 procedure TPlayer
.NextWeapon();
3285 if g_Game_IsClient
then Exit
;
3289 procedure TPlayer
.PrevWeapon();
3291 if g_Game_IsClient
then Exit
;
3295 procedure TPlayer
.SetWeapon(W
: Byte);
3297 if FCurrWeap
<> W
then
3298 if W
= WEAPON_SAW
then
3299 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3302 FModel
.SetWeapon(CurrWeap
);
3306 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3309 switchWeapon
: Byte = 255;
3310 hadWeapon
: Boolean = False;
3313 if g_Game_IsClient
then Exit
;
3315 // a = true - место спавна предмета:
3316 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3320 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3322 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3326 if gFlash
= 2 then Inc(FPickup
, 5);
3330 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3332 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3336 if gFlash
= 2 then Inc(FPickup
, 5);
3340 if FArmor
< PLAYER_AP_SOFT
then
3342 FArmor
:= PLAYER_AP_SOFT
;
3345 if gFlash
= 2 then Inc(FPickup
, 5);
3349 if FArmor
< PLAYER_AP_LIMIT
then
3351 FArmor
:= PLAYER_AP_LIMIT
;
3354 if gFlash
= 2 then Inc(FPickup
, 5);
3358 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
3360 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3364 if gFlash
= 2 then Inc(FPickup
, 5);
3368 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) or (FFireTime
> 0) then
3370 if FHealth
< PLAYER_HP_LIMIT
then
3371 FHealth
:= PLAYER_HP_LIMIT
;
3372 if FArmor
< PLAYER_AP_LIMIT
then
3373 FArmor
:= PLAYER_AP_LIMIT
;
3377 if gFlash
= 2 then Inc(FPickup
, 5);
3381 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3383 hadWeapon
:= FWeapon
[WEAPON_SAW
];
3384 switchWeapon
:= WEAPON_SAW
;
3385 FWeapon
[WEAPON_SAW
] := True;
3387 if gFlash
= 2 then Inc(FPickup
, 5);
3388 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3391 ITEM_WEAPON_SHOTGUN1
:
3392 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3394 // Нужно, чтобы не взять все пули сразу:
3395 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3396 hadWeapon
:= FWeapon
[WEAPON_SHOTGUN1
];
3397 switchWeapon
:= WEAPON_SHOTGUN1
;
3398 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3399 FWeapon
[WEAPON_SHOTGUN1
] := True;
3401 if gFlash
= 2 then Inc(FPickup
, 5);
3402 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3405 ITEM_WEAPON_SHOTGUN2
:
3406 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3408 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3409 hadWeapon
:= FWeapon
[WEAPON_SHOTGUN2
];
3410 switchWeapon
:= WEAPON_SHOTGUN2
;
3411 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3412 FWeapon
[WEAPON_SHOTGUN2
] := True;
3414 if gFlash
= 2 then Inc(FPickup
, 5);
3415 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3418 ITEM_WEAPON_CHAINGUN
:
3419 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3421 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3422 hadWeapon
:= FWeapon
[WEAPON_CHAINGUN
];
3423 switchWeapon
:= WEAPON_CHAINGUN
;
3424 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3425 FWeapon
[WEAPON_CHAINGUN
] := True;
3427 if gFlash
= 2 then Inc(FPickup
, 5);
3428 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3431 ITEM_WEAPON_ROCKETLAUNCHER
:
3432 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3434 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3435 switchWeapon
:= WEAPON_ROCKETLAUNCHER
;
3436 hadWeapon
:= FWeapon
[WEAPON_ROCKETLAUNCHER
];
3437 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3438 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3440 if gFlash
= 2 then Inc(FPickup
, 5);
3441 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3445 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3447 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3448 switchWeapon
:= WEAPON_PLASMA
;
3449 hadWeapon
:= FWeapon
[WEAPON_PLASMA
];
3450 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3451 FWeapon
[WEAPON_PLASMA
] := True;
3453 if gFlash
= 2 then Inc(FPickup
, 5);
3454 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3458 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3460 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3461 switchWeapon
:= WEAPON_BFG
;
3462 hadWeapon
:= FWeapon
[WEAPON_BFG
];
3463 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3464 FWeapon
[WEAPON_BFG
] := True;
3466 if gFlash
= 2 then Inc(FPickup
, 5);
3467 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3470 ITEM_WEAPON_SUPERPULEMET
:
3471 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3473 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3474 switchWeapon
:= WEAPON_SUPERPULEMET
;
3475 hadWeapon
:= FWeapon
[WEAPON_SUPERPULEMET
];
3476 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3477 FWeapon
[WEAPON_SUPERPULEMET
] := True;
3479 if gFlash
= 2 then Inc(FPickup
, 5);
3480 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3483 ITEM_WEAPON_FLAMETHROWER
:
3484 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
3486 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
3487 switchWeapon
:= WEAPON_FLAMETHROWER
;
3488 hadWeapon
:= FWeapon
[WEAPON_FLAMETHROWER
];
3489 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3490 FWeapon
[WEAPON_FLAMETHROWER
] := True;
3492 if gFlash
= 2 then Inc(FPickup
, 5);
3493 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3497 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3499 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3502 if gFlash
= 2 then Inc(FPickup
, 5);
3505 ITEM_AMMO_BULLETS_BOX
:
3506 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3508 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3511 if gFlash
= 2 then Inc(FPickup
, 5);
3515 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3517 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3520 if gFlash
= 2 then Inc(FPickup
, 5);
3523 ITEM_AMMO_SHELLS_BOX
:
3524 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3526 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
3529 if gFlash
= 2 then Inc(FPickup
, 5);
3533 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3535 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3538 if gFlash
= 2 then Inc(FPickup
, 5);
3541 ITEM_AMMO_ROCKET_BOX
:
3542 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3544 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
3547 if gFlash
= 2 then Inc(FPickup
, 5);
3551 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3553 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3556 if gFlash
= 2 then Inc(FPickup
, 5);
3560 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3562 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
3565 if gFlash
= 2 then Inc(FPickup
, 5);
3569 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
3571 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3574 if gFlash
= 2 then Inc(FPickup
, 5);
3578 if not(R_ITEM_BACKPACK
in FRulez
) or
3579 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
3580 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
3581 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
3582 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
3583 (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) then
3585 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
3586 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
3587 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
3588 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
3589 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
3591 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3592 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3593 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3594 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3595 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3596 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3597 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3598 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3599 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
3600 IncMax(FAmmo
[A_FUEL
], 50, FMaxAmmo
[A_FUEL
]);
3602 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
3605 if gFlash
= 2 then Inc(FPickup
, 5);
3609 if not(R_KEY_RED
in FRulez
) then
3611 Include(FRulez
, R_KEY_RED
);
3613 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3614 if gFlash
= 2 then Inc(FPickup
, 5);
3615 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3619 if not(R_KEY_GREEN
in FRulez
) then
3621 Include(FRulez
, R_KEY_GREEN
);
3623 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3624 if gFlash
= 2 then Inc(FPickup
, 5);
3625 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3629 if not(R_KEY_BLUE
in FRulez
) then
3631 Include(FRulez
, R_KEY_BLUE
);
3633 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3634 if gFlash
= 2 then Inc(FPickup
, 5);
3635 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3639 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
3641 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
3645 if gFlash
= 2 then Inc(FPickup
, 5);
3649 if FAir
< AIR_MAX
then
3654 if gFlash
= 2 then Inc(FPickup
, 5);
3659 if not (R_BERSERK
in FRulez
) then
3661 Include(FRulez
, R_BERSERK
);
3662 if (FBFGFireCounter
= -1) then
3664 FCurrWeap
:= WEAPON_KASTET
;
3666 FModel
.SetWeapon(WEAPON_KASTET
);
3671 if gFlash
= 2 then Inc(FPickup
, 5);
3673 FBerserk
:= gTime
+30000;
3678 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3680 if FHealth
< PLAYER_HP_SOFT
then FHealth
:= PLAYER_HP_SOFT
;
3681 FBerserk
:= gTime
+30000;
3689 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
3691 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
3695 if gFlash
= 2 then Inc(FPickup
, 5);
3699 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
3701 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
3705 if gFlash
= 2 then Inc(FPickup
, 5);
3709 if FArmor
< PLAYER_AP_LIMIT
then
3711 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
3714 if gFlash
= 2 then Inc(FPickup
, 5);
3718 if FJetFuel
< JET_MAX
then
3720 FJetFuel
:= JET_MAX
;
3723 if gFlash
= 2 then Inc(FPickup
, 5);
3727 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
3729 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
3732 if gFlash
= 2 then Inc(FPickup
, 5);
3736 if (shouldSwitch(switchWeapon
, hadWeapon
)) then
3737 QueueWeaponSwitch(switchWeapon
);
3740 procedure TPlayer
.Touch();
3744 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
3747 // Бросить флаг товарищу:
3748 if gGameSettings
.GameMode
= GM_CTF
then
3753 procedure TPlayer
.Push(vx
, vy
: Integer);
3755 if (not FPhysics
) and FGhost
then
3757 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
3758 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
3759 if g_Game_IsNet
and g_Game_IsServer
then
3760 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
3763 procedure TPlayer
.Reset(Force
: Boolean);
3769 FTime
[T_RESPAWN
] := 0;
3770 FTime
[T_FLAGCAP
] := 0;
3786 FSpectator
:= False;
3789 FSpectatePlayer
:= -1;
3790 FNoRespawn
:= False;
3792 FLives
:= gGameSettings
.MaxLives
;
3797 procedure TPlayer
.SoftReset();
3805 FBFGFireCounter
:= -1;
3813 SetAction(A_STAND
, True);
3816 function TPlayer
.GetRespawnPoint(): Byte;
3821 // На будущее: FSpawn - игрок уже играл и перерождается
3823 // Одиночная игра/кооператив
3824 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
3826 if Self
= gPlayer1
then
3828 // player 1 should try to spawn on the player 1 point
3829 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) > 0 then
3830 Exit(RESPAWNPOINT_PLAYER1
)
3831 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) > 0 then
3832 Exit(RESPAWNPOINT_PLAYER2
);
3834 else if Self
= gPlayer2
then
3836 // player 2 should try to spawn on the player 2 point
3837 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) > 0 then
3838 Exit(RESPAWNPOINT_PLAYER2
)
3839 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) > 0 then
3840 Exit(RESPAWNPOINT_PLAYER1
);
3844 // other players randomly pick either the first or the second point
3845 c
:= IfThen((Random(2) = 0), RESPAWNPOINT_PLAYER1
, RESPAWNPOINT_PLAYER2
);
3846 if g_Map_GetPointCount(c
) > 0 then
3848 // try the other one
3849 c
:= IfThen((c
= RESPAWNPOINT_PLAYER1
), RESPAWNPOINT_PLAYER2
, RESPAWNPOINT_PLAYER1
);
3850 if g_Map_GetPointCount(c
) > 0 then
3856 if gGameSettings
.GameMode
= GM_DM
then
3858 // try DM points first
3859 if g_Map_GetPointCount(RESPAWNPOINT_DM
) > 0 then
3860 Exit(RESPAWNPOINT_DM
);
3864 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
3866 // try team points first
3867 c
:= RESPAWNPOINT_DM
;
3868 if FTeam
= TEAM_RED
then
3869 c
:= RESPAWNPOINT_RED
3870 else if FTeam
= TEAM_BLUE
then
3871 c
:= RESPAWNPOINT_BLUE
;
3872 if g_Map_GetPointCount(c
) > 0 then
3876 // still haven't found a spawnpoint, try random shit
3877 Result
:= g_Map_GetRandomPointType();
3880 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
3882 RespawnPoint
: TRespawnPoint
;
3888 FBFGFireCounter
:= -1;
3895 if not g_Game_IsServer
then
3899 FWantsInGame
:= True;
3900 FJustTeleported
:= True;
3903 FTime
[T_RESPAWN
] := 0;
3907 // if server changes MaxLives we gotta be ready
3908 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
3910 // Еще нельзя возродиться:
3911 if FTime
[T_RESPAWN
] > gTime
then
3914 // Просрал все жизни:
3917 if not FSpectator
then Spectate(True);
3918 FWantsInGame
:= True;
3922 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
3923 begin // "Своя игра"
3924 // Берсерк не сохраняется между уровнями:
3925 FRulez
:= FRulez
-[R_BERSERK
];
3927 else // "Одиночная игра"/"Кооп"
3929 // Берсерк и ключи не сохраняются между уровнями:
3930 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
3933 // Получаем точку спауна игрока:
3934 c
:= GetRespawnPoint();
3939 // Воскрешение без оружия:
3942 FHealth
:= Round(PLAYER_HP_SOFT
* (FHandicap
/ 100));
3948 for a
:= WP_FIRST
to WP_LAST
do
3950 FWeapon
[a
] := False;
3954 FWeapon
[WEAPON_PISTOL
] := True;
3955 FWeapon
[WEAPON_KASTET
] := True;
3956 FCurrWeap
:= WEAPON_PISTOL
;
3959 FModel
.SetWeapon(FCurrWeap
);
3961 for b
:= A_BULLETS
to A_HIGH
do
3964 FAmmo
[A_BULLETS
] := 50;
3966 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
3967 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
3968 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
3969 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
3970 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
3972 if (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) and
3973 LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
) then
3974 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
3979 // Получаем координаты точки возрождения:
3980 if not g_Map_GetPoint(c
, RespawnPoint
) then
3982 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3986 // Установка координат и сброс всех параметров:
3987 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
3988 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
3989 FObj
.oldX
:= FObj
.X
; // don't interpolate after respawn
3990 FObj
.oldY
:= FObj
.Y
;
3996 FDirection
:= RespawnPoint
.Direction
;
3997 if FDirection
= TDirection
.D_LEFT
then
4002 SetAction(A_STAND
, True);
4003 FModel
.Direction
:= FDirection
;
4005 for a
:= Low(FTime
) to High(FTime
) do
4008 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4011 // Respawn invulnerability
4012 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.SpawnInvul
> 0) then
4014 FMegaRulez
[MR_INVUL
] := gTime
+ gGameSettings
.SpawnInvul
* 1000;
4015 FSpawnInvul
:= FMegaRulez
[MR_INVUL
];
4020 FCanJetpack
:= False;
4026 // Анимация возрождения:
4027 if (not gLoadGameMode
) and (not Silent
) then
4029 R_GFX_TELEPORT_FAST
,
4030 FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4031 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32
4034 FSpectator
:= False;
4037 FSpectatePlayer
:= -1;
4040 if (gPlayer1
= nil) and (gSpectLatchPID1
= FUID
) then
4042 if (gPlayer2
= nil) and (gSpectLatchPID2
= FUID
) then
4045 if g_Game_IsNet
then
4047 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4048 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4050 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4051 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4056 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4059 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4060 else if (not NoMove
) then
4062 GameX
:= gMapInfo
.Width
div 2;
4063 GameY
:= gMapInfo
.Height
div 2;
4072 FWantsInGame
:= False;
4078 if Self
= gPlayer1
then
4080 gSpectLatchPID1
:= FUID
;
4083 else if Self
= gPlayer2
then
4085 gSpectLatchPID2
:= FUID
;
4090 if g_Game_IsNet
then
4091 MH_SEND_PlayerStats(FUID
);
4094 procedure TPlayer
.SwitchNoClip
;
4098 FGhost
:= not FGhost
;
4099 FPhysics
:= not FGhost
;
4111 procedure TPlayer
.Run(Direction
: TDirection
);
4115 if MAX_RUNVEL
> 8 then
4119 if Direction
= TDirection
.D_LEFT
then
4121 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4122 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4125 if FObj
.Vel
.X
< MAX_RUNVEL
then
4126 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4128 // Возможно, пинаем куски:
4129 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4131 b
:= Abs(FObj
.Vel
.X
);
4132 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4133 for a
:= 0 to High(gGibs
) do
4135 if gGibs
[a
].alive
and
4136 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4137 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4140 if FObj
.Vel
.X
< 0 then
4142 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // налево
4146 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // направо
4148 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4156 procedure TPlayer
.SeeDown();
4158 SetAction(A_SEEDOWN
);
4160 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4162 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4165 procedure TPlayer
.SeeUp();
4169 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4171 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4174 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4182 A_ATTACK
: Prior
:= 2;
4183 A_SEEUP
: Prior
:= 1;
4184 A_SEEDOWN
: Prior
:= 1;
4185 A_ATTACKUP
: Prior
:= 2;
4186 A_ATTACKDOWN
: Prior
:= 2;
4191 if (Prior
> FActionPrior
) or Force
then
4192 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4194 FActionPrior
:= Prior
;
4195 FActionAnim
:= Action
;
4196 FActionForce
:= Force
;
4197 FActionChanged
:= True;
4200 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4203 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4205 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4206 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4207 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4208 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4211 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4215 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4217 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4218 if g_Game_IsServer
and g_Game_IsNet
then
4219 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4223 FJustTeleported
:= True;
4227 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4229 R_GFX_TELEPORT_FAST
,
4230 FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4231 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32
4233 if g_Game_IsServer
and g_Game_IsNet
then
4234 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4235 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4239 FObj
.X
:= X
-PLAYER_RECT
.X
;
4240 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4241 FObj
.oldX
:= FObj
.X
; // don't interpolate after respawn
4242 FObj
.oldY
:= FObj
.Y
;
4243 if FAlive
and FGhost
then
4249 if not g_Game_IsNet
then
4253 SetDirection(TDirection
.D_LEFT
);
4259 SetDirection(TDirection
.D_RIGHT
);
4265 if FDirection
= TDirection
.D_RIGHT
then
4267 SetDirection(TDirection
.D_LEFT
);
4272 SetDirection(TDirection
.D_RIGHT
);
4281 R_GFX_TELEPORT_FAST
,
4282 FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4283 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32
4285 if g_Game_IsServer
and g_Game_IsNet
then
4286 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4287 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4294 function nonz(a
: Single): Single;
4302 function TPlayer
.refreshCorpse(): Boolean;
4308 if FAlive
or FSpectator
then
4310 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
4312 for i
:= 0 to High(gCorpses
) do
4313 if gCorpses
[i
] <> nil then
4314 if gCorpses
[i
].FPlayerUID
= FUID
then
4322 function TPlayer
.getCameraObj(): TObj
;
4324 if (not FAlive
) and (not FSpectator
) and
4325 (FCorpse
>= 0) and (FCorpse
< Length(gCorpses
)) and
4326 (gCorpses
[FCorpse
] <> nil) and (gCorpses
[FCorpse
].FPlayerUID
= FUID
) then
4328 gCorpses
[FCorpse
].FObj
.slopeUpLeft
:= FObj
.slopeUpLeft
;
4329 Result
:= gCorpses
[FCorpse
].FObj
;
4337 procedure TPlayer
.PreUpdate();
4339 FSlopeOld
:= FObj
.slopeUpLeft
;
4340 FIncCamOld
:= FIncCam
;
4341 FObj
.oldX
:= FObj
.X
;
4342 FObj
.oldY
:= FObj
.Y
;
4345 procedure TPlayer
.Update();
4348 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4349 blockmon
, headwater
, dospawn
: Boolean;
4354 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4355 AnyServer
:= g_Game_IsServer
;
4357 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4358 DoLerp(NetInterpLevel
+ 1)
4364 if (FClientID
>= 0) and (NetClients
[FClientID
].Peer
<> nil) then
4366 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4367 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4368 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4377 if FAlive
and (FPunchAnim
<> nil) then
4378 FPunchAnim
.Update();
4380 if FAlive
and (gFly
or FJetpack
) then
4383 if FDirection
= TDirection
.D_LEFT
then
4388 if FAlive
and (not FGhost
) then
4390 if FKeys
[KEY_UP
].Pressed
then
4392 if FKeys
[KEY_DOWN
].Pressed
then
4396 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4399 i
:= g_basic
.Sign(FIncCam
);
4400 FIncCam
:= Abs(FIncCam
);
4401 DecMin(FIncCam
, 5, 0);
4402 FIncCam
:= FIncCam
*i
;
4405 if gTime
mod (GAME_TICK
*2) <> 0 then
4407 if (FObj
.Vel
.X
= 0) and FAlive
then
4409 if FKeys
[KEY_LEFT
].Pressed
then
4410 Run(TDirection
.D_LEFT
);
4411 if FKeys
[KEY_RIGHT
].Pressed
then
4412 Run(TDirection
.D_RIGHT
);
4417 g_Obj_Move(@FObj
, True, True, True);
4418 positionChanged(); // this updates spatial accelerators
4424 FActionChanged
:= False;
4428 // Let alive player do some actions
4429 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
4430 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
4431 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire()
4437 if NetServer
then MH_SEND_PlayerStats(FUID
);
4440 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
4441 if FKeys
[KEY_JUMP
].Pressed
then Jump()
4444 if AnyServer
and FJetpack
then
4448 if NetServer
then MH_SEND_PlayerStats(FUID
);
4450 FCanJetpack
:= True;
4457 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
4459 if FKeys
[k
].Pressed
then
4467 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4470 if (FTime
[T_RESPAWN
] <= gTime
) and
4471 gGameOn
and (not FAlive
) then
4473 if (g_Player_GetCount() > 1) then
4477 gExit
:= EXIT_RESTART
;
4482 // Dead spectator actions
4485 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
4486 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
4490 if (FSpectatePlayer
>= High(gPlayers
)) then
4491 FSpectatePlayer
:= -1
4495 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
4496 if gPlayers
[I
] <> nil then
4497 if gPlayers
[I
].alive
then
4498 if gPlayers
[I
].UID
<> FUID
then
4500 FSpectatePlayer
:= I
;
4505 if not SetSpect
then FSpectatePlayer
:= -1;
4516 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
4518 FYTo
:= FObj
.Y
- 32;
4519 FSpectatePlayer
:= -1;
4521 if FKeys
[KEY_DOWN
].Pressed
then
4523 FYTo
:= FObj
.Y
+ 32;
4524 FSpectatePlayer
:= -1;
4526 if FKeys
[KEY_LEFT
].Pressed
then
4528 FXTo
:= FObj
.X
- 32;
4529 FSpectatePlayer
:= -1;
4531 if FKeys
[KEY_RIGHT
].Pressed
then
4533 FXTo
:= FObj
.X
+ 32;
4534 FSpectatePlayer
:= -1;
4537 if (FXTo
< -64) then
4539 else if (FXTo
> gMapInfo
.Width
+ 32) then
4540 FXTo
:= gMapInfo
.Width
+ 32;
4541 if (FYTo
< -72) then
4543 else if (FYTo
> gMapInfo
.Height
+ 32) then
4544 FYTo
:= gMapInfo
.Height
+ 32;
4549 g_Obj_Move(@FObj
, True, True, True);
4550 positionChanged(); // this updates spatial accelerators
4557 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
4558 if gPlayers
[FSpectatePlayer
] <> nil then
4559 if gPlayers
[FSpectatePlayer
].alive
then
4561 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
4562 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
4566 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
4567 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
4568 PANEL_BLOCKMON
, True);
4569 headwater
:= HeadInLiquid(0, 0);
4571 // Сопротивление воздуха:
4572 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
4573 if FObj
.Vel
.X
<> 0 then
4574 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
4576 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
4577 DecMin(FPain
, 5, 0);
4578 DecMin(FPickup
, 1, 0);
4580 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
4582 // Обнулить действия примочек, чтобы фон пропал
4583 FMegaRulez
[MR_SUIT
] := 0;
4584 FMegaRulez
[MR_INVUL
] := 0;
4585 FMegaRulez
[MR_INVIS
] := 0;
4586 Kill(K_FALLKILL
, 0, HIT_FALL
);
4593 if FCurrWeap
= WEAPON_SAW
then
4594 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
4595 FSawSoundSelect
.IsPlaying()) then
4596 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
4599 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
4600 (not FJetSoundOff
.IsPlaying()) then
4602 FJetSoundFly
.SetPosition(0);
4603 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
4606 for b
:= WP_FIRST
to WP_LAST
do
4607 if FReloading
[b
] > 0 then
4613 if FShellTimer
> -1 then
4614 if FShellTimer
= 0 then
4616 if FShellType
= SHELL_SHELL
then
4617 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4618 GameVelX
, GameVelY
-2, SHELL_SHELL
)
4619 else if FShellType
= SHELL_DBLSHELL
then
4621 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4622 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
4623 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4624 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
4627 end else Dec(FShellTimer
);
4629 if (FBFGFireCounter
> -1) then
4630 if FBFGFireCounter
= 0 then
4634 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
4635 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
4636 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
4637 yd
:= wy
+firediry();
4638 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
4639 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
4640 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
4641 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
4642 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
4645 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
4646 FBFGFireCounter
:= -1;
4649 FBFGFireCounter
:= 0
4651 Dec(FBFGFireCounter
);
4653 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
4655 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
4657 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
4660 if (headwater
or blockmon
) then
4666 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
4669 else if (FAir
mod 31 = 0) and not blockmon
then
4671 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
4673 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
4674 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
4676 end else if FAir
< AIR_DEF
then
4679 if FFireTime
> 0 then
4681 if BodyInLiquid(0, 0) then
4686 else if FMegaRulez
[MR_SUIT
] >= gTime
then
4688 if FMegaRulez
[MR_SUIT
] = gTime
then
4695 if FFirePainTime
<= 0 then
4697 if g_Game_IsServer
then
4698 Damage(2, FFireAttacker
, 0, 0, HIT_FLAME
);
4699 FFirePainTime
:= 12 - FFireTime
div 12;
4701 FFirePainTime
:= FFirePainTime
- 1;
4702 FFireTime
:= FFireTime
- 1;
4703 if ((FFireTime
mod 33) = 0) and (FMegaRulez
[MR_INVUL
] < gTime
) then
4704 FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
);
4705 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
4706 MH_SEND_PlayerStats(FUID
);
4710 if FDamageBuffer
> 0 then
4712 if FDamageBuffer
>= 9 then
4716 if FDamageBuffer
< 30 then i
:= 9
4717 else if FDamageBuffer
< 100 then i
:= 18
4721 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
4722 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
4723 FHealth
:= FHealth
-ii
;
4726 FHealth
:= FHealth
+FArmor
;
4731 if FHealth
<= 0 then
4732 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
4733 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
4734 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
4736 if FAlive
and ((FLastHit
<> HIT_FLAME
) or (FFireTime
<= 0)) then
4738 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
4739 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
4740 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
4741 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
4748 end; // if FAlive then ...
4750 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
4752 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
4753 FModel
.AnimState
.MinLength
:= i
;
4754 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
4756 if (FModel
.AnimState
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
4757 then SetAction(A_STAND
, True);
4759 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.GetFire()) then FModel
.Update
;
4761 for b
:= Low(FKeys
) to High(FKeys
) do
4762 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
4766 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
4768 x
:= FObj
.X
+PLAYER_RECT
.X
;
4769 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
4770 w
:= PLAYER_RECT
.Width
;
4771 h
:= PLAYER_RECT
.Height
;
4775 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
4777 if (dx
<> 0) or (dy
<> 0) then
4786 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
4788 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
4789 FObj
.Y
+PLAYER_RECT
.Y
,
4796 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
4798 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
4799 FObj
.Y
+PLAYER_RECT
.Y
,
4803 Panel
.Width
, Panel
.Height
);
4806 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
4808 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
4809 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
4810 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
4811 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
4814 function g_Player_ValidName(Name
: string): Boolean;
4820 if gPlayers
= nil then Exit
;
4822 for a
:= 0 to High(gPlayers
) do
4823 if gPlayers
[a
] <> nil then
4824 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
4831 procedure TPlayer
.SetDirection(Direction
: TDirection
);
4835 d
:= FModel
.Direction
;
4837 FModel
.Direction
:= Direction
;
4838 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
4840 FDirection
:= Direction
;
4843 function TPlayer
.GetKeys(): Byte;
4847 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
4848 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
4849 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
4851 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
4852 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
4855 procedure TPlayer
.Use();
4859 if FTime
[T_USE
] > gTime
then Exit
;
4861 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
4862 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
4864 for a
:= 0 to High(gPlayers
) do
4865 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
4866 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
4867 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
4868 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
4870 gPlayers
[a
].Touch();
4871 if g_Game_IsNet
and g_Game_IsServer
then
4872 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
4875 FTime
[T_USE
] := gTime
+120;
4878 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
4881 visible
: Boolean = True;
4882 WX
, WY
, XD
, YD
: Integer;
4894 if R_BERSERK
in FRulez
then
4896 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
4897 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
4898 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
4901 locobj
.rect
.Width
:= 39;
4902 locobj
.rect
.Height
:= 52;
4903 locobj
.Vel
.X
:= (xd
-wx
) div 2;
4904 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
4905 locobj
.Accel
.X
:= xd
-wx
;
4906 locobj
.Accel
.y
:= yd
-wy
;
4908 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
4909 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
4911 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
4915 FPain
:= min(FPain
+ 25, 50);
4917 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
4922 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
4923 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
4925 FSawSoundSelect
.Stop();
4927 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
4929 else if not FSawSoundHit
.IsPlaying() then
4931 FSawSoundSelect
.Stop();
4932 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
4938 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
4939 FFireAngle
:= FAngle
;
4940 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4941 GameVelX
, GameVelY
-2, SHELL_BULLET
);
4946 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
4947 FFireAngle
:= FAngle
;
4949 FShellType
:= SHELL_SHELL
;
4954 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
4955 FFireAngle
:= FAngle
;
4957 FShellType
:= SHELL_DBLSHELL
;
4962 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
4963 FFireAngle
:= FAngle
;
4964 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4965 GameVelX
, GameVelY
-2, SHELL_BULLET
);
4968 WEAPON_ROCKETLAUNCHER
:
4970 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
4971 FFireAngle
:= FAngle
;
4976 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
4977 FFireAngle
:= FAngle
;
4982 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
4983 FFireAngle
:= FAngle
;
4986 WEAPON_SUPERPULEMET
:
4988 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
4989 FFireAngle
:= FAngle
;
4990 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4991 GameVelX
, GameVelY
-2, SHELL_SHELL
);
4994 WEAPON_FLAMETHROWER
:
4996 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
4998 FFireAngle
:= FAngle
;
5002 if not visible
then Exit
;
5004 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5005 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5006 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5009 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5011 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5012 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5015 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5021 if FJustTeleported
or (NetInterpLevel
< 1) then
5025 if FJustTeleported
then
5027 FObj
.oldX
:= FObj
.X
;
5028 FObj
.oldY
:= FObj
.Y
;
5033 AX
:= Abs(FXTo
- FObj
.X
);
5034 AY
:= Abs(FYTo
- FObj
.Y
);
5035 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5037 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5042 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5044 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5045 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5046 PANEL_LIFTUP
, False) then Result
:= -1
5048 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5049 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5050 PANEL_LIFTDOWN
, False) then Result
:= 1
5054 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5061 if Flag
= FLAG_NONE
then
5064 if not g_Game_IsServer
then Exit
;
5066 // Принес чужой флаг на свою базу:
5067 if (Flag
= FTeam
) and
5068 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5069 (FFlag
<> FLAG_NONE
) then
5071 if FFlag
= FLAG_RED
then
5072 s
:= _lc
[I_PLAYER_FLAG_RED
]
5074 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5076 evtype
:= FLAG_STATE_SCORED
;
5078 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5079 Insert('.', ts
, Length(ts
) + 1 - 3);
5080 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5082 g_Map_ResetFlag(FFlag
);
5083 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5085 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5086 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5087 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5092 if not sound_cap_flag
[a
].IsPlaying() then
5093 sound_cap_flag
[a
].Play();
5095 gTeamStat
[FTeam
].Score
+= 1;
5098 if g_Game_IsNet
then
5100 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5104 gFlags
[FFlag
].CaptureTime
:= 0;
5109 // Подобрал свой флаг - вернул его на базу:
5110 if (Flag
= FTeam
) and
5111 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5113 if Flag
= FLAG_RED
then
5114 s
:= _lc
[I_PLAYER_FLAG_RED
]
5116 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5118 evtype
:= FLAG_STATE_RETURNED
;
5119 gFlags
[Flag
].CaptureTime
:= 0;
5121 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5123 g_Map_ResetFlag(Flag
);
5124 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5126 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5127 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5128 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5133 if not sound_ret_flag
[a
].IsPlaying() then
5134 sound_ret_flag
[a
].Play();
5137 if g_Game_IsNet
then
5139 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5145 // Подобрал чужой флаг:
5146 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5150 if Flag
= FLAG_RED
then
5151 s
:= _lc
[I_PLAYER_FLAG_RED
]
5153 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5155 evtype
:= FLAG_STATE_CAPTURED
;
5157 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5159 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5161 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5163 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5164 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5165 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5170 if not sound_get_flag
[a
].IsPlaying() then
5171 sound_get_flag
[a
].Play();
5174 if g_Game_IsNet
then
5176 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5182 procedure TPlayer
.SetFlag(Flag
: Byte);
5185 if FModel
<> nil then
5186 FModel
.SetFlag(FFlag
);
5189 function TPlayer
.TryDropFlag(): Boolean;
5191 if LongBool(gGameSettings
.Options
and GAME_OPTION_ALLOWDROPFLAG
) then
5192 Result
:= DropFlag(False, LongBool(gGameSettings
.Options
and GAME_OPTION_THROWFLAG
))
5197 function TPlayer
.DropFlag(Silent
: Boolean = True; DoThrow
: Boolean = False): Boolean;
5204 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5206 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5207 with gFlags
[FFlag
] do
5211 Direction
:= FDirection
;
5212 State
:= FLAG_STATE_DROPPED
;
5216 xv
:= FObj
.Vel
.X
+ IfThen(Direction
= TDirection
.D_RIGHT
, 10, -10);
5217 yv
:= FObj
.Vel
.Y
- 2;
5221 xv
:= (FObj
.Vel
.X
div 2);
5222 yv
:= (FObj
.Vel
.Y
div 2) - 2;
5224 g_Obj_Push(@Obj
, xv
, yv
);
5226 positionChanged(); // this updates spatial accelerators
5228 if FFlag
= FLAG_RED
then
5229 s
:= _lc
[I_PLAYER_FLAG_RED
]
5231 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5233 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5234 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5236 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5237 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5238 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5243 if (not Silent
) and (not sound_lost_flag
[a
].IsPlaying()) then
5244 sound_lost_flag
[a
].Play();
5246 if g_Game_IsNet
then
5247 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5253 procedure TPlayer
.GetSecret();
5255 if (self
= gPlayer1
) or (self
= gPlayer2
) then
5257 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [FName
]), True);
5258 g_Sound_PlayEx('SOUND_GAME_SECRET');
5263 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5265 Assert(Key
<= High(FKeys
));
5267 FKeys
[Key
].Pressed
:= True;
5268 FKeys
[Key
].Time
:= Time
;
5271 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5273 Result
:= FKeys
[K
].Pressed
;
5276 procedure TPlayer
.ReleaseKeys();
5280 for a
:= Low(FKeys
) to High(FKeys
) do
5282 FKeys
[a
].Pressed
:= False;
5287 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5291 function TPlayer
.firediry(): Integer;
5293 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5294 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5298 procedure TPlayer
.RememberState();
5301 SavedState
: TPlayerSavedState
;
5303 SavedState
.Health
:= FHealth
;
5304 SavedState
.Armor
:= FArmor
;
5305 SavedState
.Air
:= FAir
;
5306 SavedState
.JetFuel
:= FJetFuel
;
5307 SavedState
.CurrWeap
:= FCurrWeap
;
5308 SavedState
.NextWeap
:= FNextWeap
;
5309 SavedState
.NextWeapDelay
:= FNextWeapDelay
;
5310 for i
:= Low(FWeapon
) to High(FWeapon
) do
5311 SavedState
.Weapon
[i
] := FWeapon
[i
];
5312 for i
:= Low(FAmmo
) to High(FAmmo
) do
5313 SavedState
.Ammo
[i
] := FAmmo
[i
];
5314 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
5315 SavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5316 SavedState
.Rulez
:= FRulez
- [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5318 FSavedStateNum
:= -1;
5319 for i
:= Low(SavedStates
) to High(SavedStates
) do
5320 if not SavedStates
[i
].Used
then
5322 FSavedStateNum
:= i
;
5325 if FSavedStateNum
< 0 then
5327 SetLength(SavedStates
, Length(SavedStates
) + 1);
5328 FSavedStateNum
:= High(SavedStates
);
5331 SavedState
.Used
:= True;
5332 SavedStates
[FSavedStateNum
] := SavedState
;
5335 procedure TPlayer
.RecallState();
5338 SavedState
: TPlayerSavedState
;
5340 if(FSavedStateNum
< 0) or (FSavedStateNum
> High(SavedStates
)) then
5343 SavedState
:= SavedStates
[FSavedStateNum
];
5344 SavedStates
[FSavedStateNum
].Used
:= False;
5345 FSavedStateNum
:= -1;
5347 FHealth
:= SavedState
.Health
;
5348 FArmor
:= SavedState
.Armor
;
5349 FAir
:= SavedState
.Air
;
5350 FJetFuel
:= SavedState
.JetFuel
;
5351 FCurrWeap
:= SavedState
.CurrWeap
;
5352 FNextWeap
:= SavedState
.NextWeap
;
5353 FNextWeapDelay
:= SavedState
.NextWeapDelay
;
5354 for i
:= Low(FWeapon
) to High(FWeapon
) do
5355 FWeapon
[i
] := SavedState
.Weapon
[i
];
5356 for i
:= Low(FAmmo
) to High(FAmmo
) do
5357 FAmmo
[i
] := SavedState
.Ammo
[i
];
5358 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
5359 FMaxAmmo
[i
] := SavedState
.MaxAmmo
[i
];
5360 FRulez
:= SavedState
.Rulez
;
5362 if gGameSettings
.GameType
= GT_SERVER
then
5363 MH_SEND_PlayerStats(FUID
);
5366 procedure TPlayer
.SaveState (st
: TStream
);
5372 utils
.writeSign(st
, 'PLYR');
5373 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
5375 utils
.writeBool(st
, FIamBot
);
5377 utils
.writeInt(st
, Word(FUID
));
5379 utils
.writeStr(st
, FName
);
5381 utils
.writeInt(st
, Byte(FTeam
));
5383 utils
.writeBool(st
, FAlive
);
5384 // Израсходовал ли все жизни
5385 utils
.writeBool(st
, FNoRespawn
);
5387 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
5388 utils
.writeInt(st
, Byte(b
));
5390 utils
.writeInt(st
, LongInt(FHealth
));
5391 // Коэффициент инвалидности
5392 utils
.writeInt(st
, LongInt(FHandicap
));
5394 utils
.writeInt(st
, Byte(FLives
));
5396 utils
.writeInt(st
, LongInt(FArmor
));
5398 utils
.writeInt(st
, LongInt(FAir
));
5400 utils
.writeInt(st
, LongInt(FJetFuel
));
5402 utils
.writeInt(st
, LongInt(FPain
));
5404 utils
.writeInt(st
, LongInt(FKills
));
5406 utils
.writeInt(st
, LongInt(FMonsterKills
));
5408 utils
.writeInt(st
, LongInt(FFrags
));
5410 utils
.writeInt(st
, Byte(FFragCombo
));
5411 // Время последнего фрага
5412 utils
.writeInt(st
, LongWord(FLastFrag
));
5414 utils
.writeInt(st
, LongInt(FDeath
));
5416 utils
.writeInt(st
, Byte(FFlag
));
5418 utils
.writeInt(st
, LongInt(FSecrets
));
5420 utils
.writeInt(st
, Byte(FCurrWeap
));
5422 utils
.writeInt(st
, Word(FNextWeap
));
5424 utils
.writeInt(st
, Byte(FNextWeapDelay
));
5425 // Время зарядки BFG
5426 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
5428 utils
.writeInt(st
, LongInt(FDamageBuffer
));
5429 // Последний ударивший
5430 utils
.writeInt(st
, Word(FLastSpawnerUID
));
5431 // Тип последнего полученного урона
5432 utils
.writeInt(st
, Byte(FLastHit
));
5434 Obj_SaveState(st
, @FObj
);
5435 // Текущее количество патронов
5436 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
5437 // Максимальное количество патронов
5438 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
5440 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
5441 // Время перезарядки оружия
5442 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
5444 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
5445 // Наличие красного ключа
5446 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
5447 // Наличие зеленого ключа
5448 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
5449 // Наличие синего ключа
5450 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
5452 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
5453 // Время действия специальных предметов
5454 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
5455 // Время до повторного респауна, смены оружия, исользования, захвата флага
5456 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
5458 utils
.writeStr(st
, FModel
.GetName());
5460 utils
.writeInt(st
, Byte(FColor
.R
));
5461 utils
.writeInt(st
, Byte(FColor
.G
));
5462 utils
.writeInt(st
, Byte(FColor
.B
));
5466 procedure TPlayer
.LoadState (st
: TStream
);
5475 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
5476 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
5478 FIamBot
:= utils
.readBool(st
);
5480 FUID
:= utils
.readWord(st
);
5482 str
:= utils
.readStr(st
);
5483 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
5485 FTeam
:= utils
.readByte(st
);
5487 FAlive
:= utils
.readBool(st
);
5488 // Израсходовал ли все жизни
5489 FNoRespawn
:= utils
.readBool(st
);
5491 b
:= utils
.readByte(st
);
5492 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
5494 FHealth
:= utils
.readLongInt(st
);
5495 // Коэффициент инвалидности
5496 FHandicap
:= utils
.readLongInt(st
);
5498 FLives
:= utils
.readByte(st
);
5500 FArmor
:= utils
.readLongInt(st
);
5502 FAir
:= utils
.readLongInt(st
);
5504 FJetFuel
:= utils
.readLongInt(st
);
5506 FPain
:= utils
.readLongInt(st
);
5508 FKills
:= utils
.readLongInt(st
);
5510 FMonsterKills
:= utils
.readLongInt(st
);
5512 FFrags
:= utils
.readLongInt(st
);
5514 FFragCombo
:= utils
.readByte(st
);
5515 // Время последнего фрага
5516 FLastFrag
:= utils
.readLongWord(st
);
5518 FDeath
:= utils
.readLongInt(st
);
5520 FFlag
:= utils
.readByte(st
);
5522 FSecrets
:= utils
.readLongInt(st
);
5524 FCurrWeap
:= utils
.readByte(st
);
5526 FNextWeap
:= utils
.readWord(st
);
5528 FNextWeapDelay
:= utils
.readByte(st
);
5529 // Время зарядки BFG
5530 FBFGFireCounter
:= utils
.readSmallInt(st
);
5532 FDamageBuffer
:= utils
.readLongInt(st
);
5533 // Последний ударивший
5534 FLastSpawnerUID
:= utils
.readWord(st
);
5535 // Тип последнего полученного урона
5536 FLastHit
:= utils
.readByte(st
);
5538 Obj_LoadState(@FObj
, st
);
5539 // Текущее количество патронов
5540 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
5541 // Максимальное количество патронов
5542 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
5544 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
5545 // Время перезарядки оружия
5546 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
5548 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
5549 // Наличие красного ключа
5550 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
5551 // Наличие зеленого ключа
5552 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
5553 // Наличие синего ключа
5554 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
5556 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
5557 // Время действия специальных предметов
5558 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
5559 // Время до повторного респауна, смены оружия, исользования, захвата флага
5560 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
5562 str
:= utils
.readStr(st
);
5564 FColor
.R
:= utils
.readByte(st
);
5565 FColor
.G
:= utils
.readByte(st
);
5566 FColor
.B
:= utils
.readByte(st
);
5567 if (self
= gPlayer1
) then
5569 str
:= gPlayer1Settings
.Model
;
5570 FColor
:= gPlayer1Settings
.Color
;
5572 else if (self
= gPlayer2
) then
5574 str
:= gPlayer2Settings
.Model
;
5575 FColor
:= gPlayer2Settings
.Color
;
5577 // Обновляем модель игрока
5579 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
5580 FModel
.Color
:= TEAMCOLOR
[FTeam
]
5582 FModel
.Color
:= FColor
;
5586 procedure TPlayer
.AllRulez(Health
: Boolean);
5592 FHealth
:= PLAYER_HP_LIMIT
;
5593 FArmor
:= PLAYER_AP_LIMIT
;
5597 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
5598 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
5599 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5602 procedure TPlayer
.RestoreHealthArmor();
5604 FHealth
:= PLAYER_HP_LIMIT
;
5605 FArmor
:= PLAYER_AP_LIMIT
;
5608 procedure TPlayer
.FragCombo();
5612 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
5614 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
5616 if FFragCombo
< 5 then
5618 Param
:= FUID
or (FFragCombo
shl 16);
5619 if (FComboEvnt
>= Low(gDelayedEvents
)) and
5620 (FComboEvnt
<= High(gDelayedEvents
)) and
5621 gDelayedEvents
[FComboEvnt
].Pending
and
5622 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
5623 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
5625 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
5626 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
5629 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
5637 procedure TPlayer
.GiveItem(ItemType
: Byte);
5641 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
5643 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
5647 if FAir
< AIR_MAX
then
5654 if not (R_BERSERK
in FRulez
) then
5656 Include(FRulez
, R_BERSERK
);
5657 if FBFGFireCounter
< 1 then
5659 FCurrWeap
:= WEAPON_KASTET
;
5661 FModel
.SetWeapon(WEAPON_KASTET
);
5665 FBerserk
:= gTime
+30000;
5667 if FHealth
< PLAYER_HP_SOFT
then
5669 FHealth
:= PLAYER_HP_SOFT
;
5670 FBerserk
:= gTime
+30000;
5675 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
5677 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
5682 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
5684 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
5688 if FJetFuel
< JET_MAX
then
5690 FJetFuel
:= JET_MAX
;
5693 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
5694 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
5696 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
5697 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5699 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
5701 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
5703 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
5704 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5707 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
5708 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
5709 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
5710 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
5711 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
5712 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
5713 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
5714 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
5715 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
5717 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5718 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
5719 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5720 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
5721 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5722 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
5723 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5724 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
5725 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
5728 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
5729 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
5730 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
5731 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
5732 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
5734 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
5735 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
5736 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
5737 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
5738 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
5740 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5741 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5742 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5743 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5745 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
5748 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
5749 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
5750 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
5752 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
5753 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
5758 if g_Game_IsNet
and g_Game_IsServer
then
5759 MH_SEND_PlayerStats(FUID
);
5762 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
5765 if (Random(5) = 1) and (Times
= 1) then
5768 if BodyInLiquid(0, 0) then
5770 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
5771 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
5773 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5774 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5778 for i
:= 1 to Times
do
5782 Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(R_GFX_SMOKE_WIDTH
div 2),
5783 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2)
5788 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
5791 if (Random(10) = 1) and (Times
= 1) then
5794 for i
:= 1 to Times
do
5798 Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(R_GFX_FLAME_WIDTH
div 2),
5799 Obj
.Y
+8+Random(8+Times
*2)
5804 procedure TPlayer
.PauseSounds(Enable
: Boolean);
5806 FSawSound
.Pause(Enable
);
5807 FSawSoundIdle
.Pause(Enable
);
5808 FSawSoundHit
.Pause(Enable
);
5809 FSawSoundSelect
.Pause(Enable
);
5810 FFlameSoundOn
.Pause(Enable
);
5811 FFlameSoundOff
.Pause(Enable
);
5812 FFlameSoundWork
.Pause(Enable
);
5813 FJetSoundFly
.Pause(Enable
);
5814 FJetSoundOn
.Pause(Enable
);
5815 FJetSoundOff
.Pause(Enable
);
5820 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
5825 FObj
.Rect
:= PLAYER_CORPSERECT
;
5826 FModelName
:= ModelName
;
5831 FState
:= CORPSE_STATE_MESS
;
5832 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
5836 FState
:= CORPSE_STATE_NORMAL
;
5837 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
5841 destructor TCorpse
.Destroy();
5848 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
5850 procedure TCorpse
.positionChanged (); inline; begin end;
5852 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
5854 if (dx
<> 0) or (dy
<> 0) then
5863 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5865 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
5866 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
5867 w
:= PLAYER_CORPSERECT
.Width
;
5868 h
:= PLAYER_CORPSERECT
.Height
;
5872 procedure TCorpse
.Damage(Value
: Word; SpawnerUID
: Word; vx
, vy
: Integer);
5877 if FState
= CORPSE_STATE_REMOVEME
then
5880 FDamage
:= FDamage
+ Value
;
5882 if FDamage
> 150 then
5884 if FAnimation
<> nil then
5889 FState
:= CORPSE_STATE_REMOVEME
;
5891 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
5892 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
5893 FModelName
, FColor
);
5894 // Звук мяса от трупа:
5895 pm
:= g_PlayerModel_Get(FModelName
);
5896 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
5900 if (gBodyKillEvent
<> -1)
5901 and gDelayedEvents
[gBodyKillEvent
].Pending
then
5902 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
5903 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, SpawnerUID
);
5908 Blood
:= g_PlayerModel_GetBlood(FModelName
);
5909 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
5910 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
5911 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
5912 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
5913 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
5914 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
5918 procedure TCorpse
.Update();
5922 if FState
= CORPSE_STATE_REMOVEME
then
5925 FObj
.oldX
:= FObj
.X
;
5926 FObj
.oldY
:= FObj
.Y
;
5928 if gTime
mod (GAME_TICK
*2) <> 0 then
5930 g_Obj_Move(@FObj
, True, True, True);
5931 positionChanged(); // this updates spatial accelerators
5935 // Сопротивление воздуха для трупа:
5936 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5938 st
:= g_Obj_Move(@FObj
, True, True, True);
5939 positionChanged(); // this updates spatial accelerators
5941 if WordBool(st
and MOVE_FALLOUT
) then
5943 FState
:= CORPSE_STATE_REMOVEME
;
5947 if FAnimation
<> nil then
5948 FAnimation
.Update();
5949 if FAnimationMask
<> nil then
5950 FAnimationMask
.Update();
5954 procedure TCorpse
.SaveState (st
: TStream
);
5961 utils
.writeSign(st
, 'CORP');
5962 utils
.writeInt(st
, Byte(0));
5964 utils
.writeInt(st
, Byte(FState
));
5966 utils
.writeInt(st
, Byte(FDamage
));
5968 utils
.writeInt(st
, Byte(FColor
.R
));
5969 utils
.writeInt(st
, Byte(FColor
.G
));
5970 utils
.writeInt(st
, Byte(FColor
.B
));
5972 Obj_SaveState(st
, @FObj
);
5973 utils
.writeInt(st
, Word(FPlayerUID
));
5975 anim
:= (FAnimation
<> nil);
5976 utils
.writeBool(st
, anim
);
5977 // Если есть - сохраняем
5978 if anim
then FAnimation
.SaveState(st
);
5979 // Есть ли маска анимации
5980 anim
:= (FAnimationMask
<> nil);
5981 utils
.writeBool(st
, anim
);
5982 // Если есть - сохраняем
5983 if anim
then FAnimationMask
.SaveState(st
);
5987 procedure TCorpse
.LoadState (st
: TStream
);
5994 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
5995 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
5997 FState
:= utils
.readByte(st
);
5999 FDamage
:= utils
.readByte(st
);
6001 FColor
.R
:= utils
.readByte(st
);
6002 FColor
.G
:= utils
.readByte(st
);
6003 FColor
.B
:= utils
.readByte(st
);
6005 Obj_LoadState(@FObj
, st
);
6006 FPlayerUID
:= utils
.readWord(st
);
6008 anim
:= utils
.readBool(st
);
6009 // Если есть - загружаем
6012 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6013 FAnimation
.LoadState(st
);
6015 // Есть ли маска анимации
6016 anim
:= utils
.readBool(st
);
6017 // Если есть - загружаем
6020 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6021 FAnimationMask
.LoadState(st
);
6027 constructor TBot
.Create();
6034 FSpectator
:= False;
6041 for a
:= WP_FIRST
to WP_LAST
do
6043 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6044 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6045 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6049 destructor TBot
.Destroy();
6052 inherited Destroy();
6055 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6057 inherited Respawn(Silent
, Force
);
6060 FSelectedWeapon
:= FCurrWeap
;
6065 procedure TBot
.UpdateCombat();
6078 TTargetRecord
= array of TTarget
;
6080 function Compare(a
, b
: TTarget
): Integer;
6082 if a
.Line
and not b
.Line
then // A на линии огня
6085 if not a
.Line
and b
.Line
then // B на линии огня
6087 else // И A, и B на линии или не на линии огня
6088 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6090 if a
.Dist
> b
.Dist
then // B ближе
6092 else // A ближе или равноудаленно с B
6095 else // Странно -> A
6100 a
, x1
, y1
, x2
, y2
: Integer;
6101 targets
: TTargetRecord
;
6103 Target
, BestTarget
: TTarget
;
6104 firew
, fireh
: Integer;
6108 vsPlayer
, vsMonster
, ok
: Boolean;
6111 function monsUpdate (mon
: TMonster
): Boolean;
6113 result
:= false; // don't stop
6114 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6116 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6118 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6119 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6121 // Если монстр на экране и не прикрыт стеной
6122 if g_TraceVector(x1
, y1
, x2
, y2
) then
6124 // Добавляем к списку возможных целей
6125 SetLength(targets
, Length(targets
)+1);
6126 with targets
[High(targets
)] do
6133 Rect
:= mon
.Obj
.Rect
;
6134 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6135 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6136 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6145 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6146 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6148 // Если текущее оружие не то, что нужно, то меняем:
6149 if FCurrWeap
<> FSelectedWeapon
then
6152 // Если нужно стрелять и нужное оружие, то нажать "Стрелять":
6153 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6155 RemoveAIFlag('NEEDFIRE');
6158 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6159 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6160 else PressKey(KEY_FIRE
);
6164 // Координаты ствола:
6165 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6166 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6168 Target
.UID
:= FTargetUID
;
6171 if Target
.UID
<> 0 then
6172 begin // Цель есть - настраиваем
6173 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6176 tpla
:= g_Player_Get(Target
.UID
);
6180 if (@FObj
) <> nil then
6187 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6188 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6189 Target
.Rect
:= PLAYER_RECT
;
6190 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6191 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6192 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6193 Target
.IsPlayer
:= True;
6197 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6200 mon
:= g_Monsters_ByUID(Target
.UID
);
6203 Target
.X
:= mon
.Obj
.X
;
6204 Target
.Y
:= mon
.Obj
.Y
;
6206 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6207 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6208 Target
.Rect
:= mon
.Obj
.Rect
;
6209 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6210 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6211 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6212 Target
.IsPlayer
:= False;
6219 begin // Цели нет - обнуляем
6224 Target
.Visible
:= False;
6225 Target
.Line
:= False;
6226 Target
.IsPlayer
:= False;
6231 // Если цель не видима или не на линии огня, то ищем все возможные цели:
6232 if (not Target
.Line
) or (not Target
.Visible
) then
6236 for a
:= 0 to High(gPlayers
) do
6237 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6238 (gPlayers
[a
].FUID
<> FUID
) and
6239 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6240 (not gPlayers
[a
].NoTarget
) and
6241 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6243 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6244 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6247 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6248 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6250 // Если игрок на экране и не прикрыт стеной:
6251 if g_TraceVector(x1
, y1
, x2
, y2
) then
6253 // Добавляем к списку возможных целей:
6254 SetLength(targets
, Length(targets
)+1);
6255 with targets
[High(targets
)] do
6257 UID
:= gPlayers
[a
].FUID
;
6258 X
:= gPlayers
[a
].FObj
.X
;
6259 Y
:= gPlayers
[a
].FObj
.Y
;
6262 Rect
:= PLAYER_RECT
;
6263 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6264 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6265 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6273 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6276 // Если есть возможные цели:
6277 // (Выбираем лучшую, меняем оружие и бежим к ней/от нее)
6278 if targets
<> nil then
6280 // Выбираем наилучшую цель:
6281 BestTarget
:= targets
[0];
6282 if Length(targets
) > 1 then
6283 for a
:= 1 to High(targets
) do
6284 if Compare(BestTarget
, targets
[a
]) = 1 then
6285 BestTarget
:= targets
[a
];
6287 // Если лучшая цель "виднее" текущей, то текущая := лучшая:
6288 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6289 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6291 Target
:= BestTarget
;
6293 if (Healthy() = 3) or ((Healthy() = 2)) then
6294 begin // Если здоровы - догоняем
6295 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6296 SetAIFlag('GORIGHT', '1');
6297 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6298 SetAIFlag('GOLEFT', '1');
6301 begin // Если побиты - убегаем
6302 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6303 SetAIFlag('GORIGHT', '1');
6304 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6305 SetAIFlag('GOLEFT', '1');
6308 // Выбираем оружие на основе расстояния и приоритетов:
6309 SelectWeapon(Abs(x1
-Target
.cX
));
6314 // (Догоняем/убегаем, стреляем по направлению к цели)
6315 // (Если цель далеко, то хватит следить за ней)
6316 if Target
.UID
<> 0 then
6318 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6319 Target
.Y
+ Target
.Rect
.Y
) then
6320 begin // Цель сбежала с "экрана"
6321 if (Healthy() = 3) or ((Healthy() = 2)) then
6322 begin // Если здоровы - догоняем
6323 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6324 SetAIFlag('GORIGHT', '1');
6325 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6326 SetAIFlag('GOLEFT', '1');
6329 begin // Если побиты - забываем о цели и убегаем
6331 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6332 SetAIFlag('GORIGHT', '1');
6333 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6334 SetAIFlag('GOLEFT', '1');
6338 begin // Цель пока на "экране"
6339 // Если цель не загорожена стеной, то отмечаем, когда ее видели:
6340 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6341 FLastVisible
:= gTime
;
6342 // Если разница высот не велика, то догоняем:
6343 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6345 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6346 SetAIFlag('GORIGHT', '1');
6347 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6348 SetAIFlag('GOLEFT', '1');
6352 // Выбираем угол вверх:
6353 if FDirection
= TDirection
.D_LEFT
then
6354 angle
:= ANGLE_LEFTUP
6356 angle
:= ANGLE_RIGHTUP
;
6358 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6359 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6361 // Если при угле вверх можно попасть в приблизительное положение цели:
6362 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6363 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6364 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6365 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6366 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6367 begin // то нужно стрелять вверх
6368 SetAIFlag('NEEDFIRE', '1');
6369 SetAIFlag('NEEDSEEUP', '1');
6372 // Выбираем угол вниз:
6373 if FDirection
= TDirection
.D_LEFT
then
6374 angle
:= ANGLE_LEFTDOWN
6376 angle
:= ANGLE_RIGHTDOWN
;
6378 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6379 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6381 // Если при угле вниз можно попасть в приблизительное положение цели:
6382 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6383 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6384 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6385 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6386 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6387 begin // то нужно стрелять вниз
6388 SetAIFlag('NEEDFIRE', '1');
6389 SetAIFlag('NEEDSEEDOWN', '1');
6392 // Если цель видно и она на такой же высоте:
6393 if Target
.Visible
and
6394 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6395 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6397 // Если идем в сторону цели, то надо стрелять:
6398 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
6399 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6400 begin // то нужно стрелять вперед
6401 SetAIFlag('NEEDFIRE', '1');
6402 SetAIFlag('NEEDSEEDOWN', '');
6403 SetAIFlag('NEEDSEEUP', '');
6405 // Если цель в пределах "экрана" и сложность позволяет прыжки сближения:
6406 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6407 if GetRnd(FDifficult
.CloseJump
) then
6408 begin // то если повезет - прыгаем (особенно, если близко)
6409 if Abs(FObj
.X
-Target
.X
) < 128 then
6413 if Random(a
) = 0 then
6414 SetAIFlag('NEEDJUMP', '1');
6418 // Если цель все еще есть:
6419 if Target
.UID
<> 0 then
6420 if gTime
-FLastVisible
> 2000 then // Если видели давно
6421 Target
.UID
:= 0 // то забыть цель
6422 else // Если видели недавно
6423 begin // но цель убили
6424 if Target
.IsPlayer
then
6425 begin // Цель - игрок
6426 pla
:= g_Player_Get(Target
.UID
);
6427 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
6428 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6429 Target
.UID
:= 0; // то забыть цель
6432 begin // Цель - монстр
6433 mon
:= g_Monsters_ByUID(Target
.UID
);
6434 if (mon
= nil) or (not mon
.alive
) then
6435 Target
.UID
:= 0; // то забыть цель
6438 end; // if Target.UID <> 0
6440 FTargetUID
:= Target
.UID
;
6442 // Если возможных целей нет:
6443 // (Атака чего-нибудь слева или справа)
6444 if targets
= nil then
6445 if GetAIFlag('ATTACKLEFT') <> '' then
6446 begin // Если нужно атаковать налево
6447 RemoveAIFlag('ATTACKLEFT');
6449 SetAIFlag('NEEDJUMP', '1');
6451 if RunDirection() = TDirection
.D_RIGHT
then
6452 begin // Идем не в ту сторону
6453 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6454 begin // Если здоровы, то, возможно, стреляем бежим влево и стреляем
6455 SetAIFlag('NEEDFIRE', '1');
6456 SetAIFlag('GOLEFT', '1');
6460 begin // Идем в нужную сторону
6461 if GetRnd(FDifficult
.InvisFire
) then // Возможно, стреляем вслепую
6462 SetAIFlag('NEEDFIRE', '1');
6463 if Healthy() <= 1 then // Побиты - убегаем
6464 SetAIFlag('GORIGHT', '1');
6468 if GetAIFlag('ATTACKRIGHT') <> '' then
6469 begin // Если нужно атаковать направо
6470 RemoveAIFlag('ATTACKRIGHT');
6472 SetAIFlag('NEEDJUMP', '1');
6474 if RunDirection() = TDirection
.D_LEFT
then
6475 begin // Идем не в ту сторону
6476 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6477 begin // Если здоровы, то, возможно, бежим вправо и стреляем
6478 SetAIFlag('NEEDFIRE', '1');
6479 SetAIFlag('GORIGHT', '1');
6484 if GetRnd(FDifficult
.InvisFire
) then // Возможно, стреляем вслепую
6485 SetAIFlag('NEEDFIRE', '1');
6486 if Healthy() <= 1 then // Побиты - убегаем
6487 SetAIFlag('GOLEFT', '1');
6491 //HACK! (does it belongs there?)
6492 RealizeCurrentWeapon();
6494 // Если есть возможные цели:
6495 // (Стреляем по направлению к целям)
6496 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6497 for a
:= 0 to High(targets
) do
6499 // Если можем стрелять по диагонали:
6500 if GetRnd(FDifficult
.DiagFire
) then
6502 // Ищем цель сверху и стреляем, если есть:
6503 if FDirection
= TDirection
.D_LEFT
then
6504 angle
:= ANGLE_LEFTUP
6506 angle
:= ANGLE_RIGHTUP
;
6508 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6509 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6511 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6512 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6513 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6514 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6515 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6517 SetAIFlag('NEEDFIRE', '1');
6518 SetAIFlag('NEEDSEEUP', '1');
6521 // Ищем цель снизу и стреляем, если есть:
6522 if FDirection
= TDirection
.D_LEFT
then
6523 angle
:= ANGLE_LEFTDOWN
6525 angle
:= ANGLE_RIGHTDOWN
;
6527 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6528 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6530 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6531 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6532 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6533 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6534 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6536 SetAIFlag('NEEDFIRE', '1');
6537 SetAIFlag('NEEDSEEDOWN', '1');
6541 // Если цель "перед носом", то стреляем:
6542 if targets
[a
].Line
and targets
[a
].Visible
and
6543 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
6544 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
6546 SetAIFlag('NEEDFIRE', '1');
6551 // Если летит пуля, то, возможно, подпрыгиваем:
6552 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
6553 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
6554 40+GetInterval(FDifficult
.Cover
, 40)) then
6555 SetAIFlag('NEEDJUMP', '1');
6557 // Если кончились паторны, то нужно сменить оружие:
6558 ammo
:= GetAmmoByWeapon(FCurrWeap
);
6559 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
6560 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
6562 SetAIFlag('SELECTWEAPON', '1');
6564 // Если нужно сменить оружие, то выбираем нужное:
6565 if GetAIFlag('SELECTWEAPON') = '1' then
6568 RemoveAIFlag('SELECTWEAPON');
6572 procedure TBot
.Update();
6585 // Проверяем, отключён ли AI ботов
6586 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
6588 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
6590 if g_debug_BotAIOff
= 3 then
6600 RealizeCurrentWeapon();
6607 procedure TBot
.ReleaseKey(Key
: Byte);
6616 function TBot
.KeyPressed(Key
: Word): Boolean;
6618 Result
:= FKeys
[Key
].Pressed
;
6621 function TBot
.GetAIFlag(aName
: String20
): String20
;
6627 aName
:= LowerCase(aName
);
6629 if FAIFlags
<> nil then
6630 for a
:= 0 to High(FAIFlags
) do
6631 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6633 Result
:= FAIFlags
[a
].Value
;
6638 procedure TBot
.RemoveAIFlag(aName
: String20
);
6642 if FAIFlags
= nil then Exit
;
6644 aName
:= LowerCase(aName
);
6646 for a
:= 0 to High(FAIFlags
) do
6647 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6649 if a
<> High(FAIFlags
) then
6650 for b
:= a
to High(FAIFlags
)-1 do
6651 FAIFlags
[b
] := FAIFlags
[b
+1];
6653 SetLength(FAIFlags
, Length(FAIFlags
)-1);
6658 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
6666 aName
:= LowerCase(aName
);
6668 if FAIFlags
<> nil then
6669 for a
:= 0 to High(FAIFlags
) do
6670 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6676 if ok
then FAIFlags
[a
].Value
:= fValue
6679 SetLength(FAIFlags
, Length(FAIFlags
)+1);
6680 with FAIFlags
[High(FAIFlags
)] do
6688 procedure TBot
.UpdateMove
;
6690 procedure GoLeft(Time
: Word = 1);
6692 ReleaseKey(KEY_LEFT
);
6693 ReleaseKey(KEY_RIGHT
);
6694 PressKey(KEY_LEFT
, Time
);
6695 SetDirection(TDirection
.D_LEFT
);
6698 procedure GoRight(Time
: Word = 1);
6700 ReleaseKey(KEY_LEFT
);
6701 ReleaseKey(KEY_RIGHT
);
6702 PressKey(KEY_RIGHT
, Time
);
6703 SetDirection(TDirection
.D_RIGHT
);
6706 function Rnd(a
: Word): Boolean;
6708 Result
:= Random(a
) = 0;
6711 procedure Turn(Time
: Word = 1200);
6713 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
6718 ReleaseKey(KEY_LEFT
);
6719 ReleaseKey(KEY_RIGHT
);
6722 function CanRunLeft(): Boolean;
6724 Result
:= not CollideLevel(-1, 0);
6727 function CanRunRight(): Boolean;
6729 Result
:= not CollideLevel(1, 0);
6732 function CanRun(): Boolean;
6734 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
6737 procedure Jump(Time
: Word = 30);
6739 PressKey(KEY_JUMP
, Time
);
6742 function NearHole(): Boolean;
6746 { TODO 5 : Лестницы }
6747 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
6748 for x
:= 1 to PLAYER_RECT
.Width
do
6749 if (not StayOnStep(x
*sx
, 0)) and
6750 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6751 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6760 function BorderHole(): Boolean;
6764 { TODO 5 : Лестницы }
6765 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
6766 for x
:= 1 to PLAYER_RECT
.Width
do
6767 if (not StayOnStep(x
*sx
, 0)) and
6768 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6769 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6771 for xx
:= x
to x
+32 do
6772 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
6782 function NearDeepHole(): Boolean;
6788 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
6791 for x
:= 1 to PLAYER_RECT
.Width
do
6792 if (not StayOnStep(x
*sx
, 0)) and
6793 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6794 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6796 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6798 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
6803 end else Result
:= False;
6806 function OverDeepHole(): Boolean;
6813 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6815 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
6822 function OnGround(): Boolean;
6824 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
6827 function OnLadder(): Boolean;
6829 Result
:= FullInStep(0, 0);
6832 function BelowLadder(): Boolean;
6834 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
6835 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
6836 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
6837 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
6840 function BelowLiftUp(): Boolean;
6842 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
6843 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
6844 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
6845 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
6848 function OnTopLift(): Boolean;
6850 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
6853 function CanJumpOver(): Boolean;
6857 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
6861 if not CollideLevel(sx
, 0) then Exit
;
6863 for y
:= 1 to BOT_MAXJUMP
do
6864 if CollideLevel(0, -y
) then Exit
else
6865 if not CollideLevel(sx
, -y
) then
6872 function CanJumpUp(Dist
: ShortInt): Boolean;
6879 if CollideLevel(Dist
, 0) then Exit
;
6882 for y
:= 0 to BOT_MAXJUMP
do
6883 if CollideLevel(Dist
, -y
) then
6892 for yy
:= y
+1 to BOT_MAXJUMP
do
6893 if not CollideLevel(Dist
, -yy
) then
6902 for y
:= 0 to BOT_MAXJUMP
do
6903 if CollideLevel(0, -y
) then
6911 if y
< yy
then Exit
;
6916 function IsSafeTrigger(): Boolean;
6921 if gTriggers
= nil then
6923 for a
:= 0 to High(gTriggers
) do
6924 if Collide(gTriggers
[a
].X
,
6927 gTriggers
[a
].Height
) and
6928 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
6929 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
6930 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
6931 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
6932 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
6937 // Возможно, нажимаем кнопку:
6938 if Rnd(16) and IsSafeTrigger() then
6941 // Если под лифтом или ступеньками, то, возможно, прыгаем:
6942 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
6944 ReleaseKey(KEY_LEFT
);
6945 ReleaseKey(KEY_RIGHT
);
6949 // Идем влево, если надо было:
6950 if GetAIFlag('GOLEFT') <> '' then
6952 RemoveAIFlag('GOLEFT');
6953 if CanRunLeft() then
6957 // Идем вправо, если надо было:
6958 if GetAIFlag('GORIGHT') <> '' then
6960 RemoveAIFlag('GORIGHT');
6961 if CanRunRight() then
6965 // Если вылетели за карту, то пробуем вернуться:
6966 if FObj
.X
< -32 then
6969 if FObj
.X
+32 > gMapInfo
.Width
then
6972 // Прыгаем, если надо было:
6973 if GetAIFlag('NEEDJUMP') <> '' then
6976 RemoveAIFlag('NEEDJUMP');
6979 // Смотрим вверх, если надо было:
6980 if GetAIFlag('NEEDSEEUP') <> '' then
6983 ReleaseKey(KEY_DOWN
);
6984 PressKey(KEY_UP
, 20);
6985 RemoveAIFlag('NEEDSEEUP');
6988 // Смотрим вниз, если надо было:
6989 if GetAIFlag('NEEDSEEDOWN') <> '' then
6992 ReleaseKey(KEY_DOWN
);
6993 PressKey(KEY_DOWN
, 20);
6994 RemoveAIFlag('NEEDSEEDOWN');
6997 // Если нужно было в дыру и мы не на земле, то покорно летим:
6998 if GetAIFlag('GOINHOLE') <> '' then
6999 if not OnGround() then
7001 ReleaseKey(KEY_LEFT
);
7002 ReleaseKey(KEY_RIGHT
);
7003 RemoveAIFlag('GOINHOLE');
7004 SetAIFlag('FALLINHOLE', '1');
7007 // Если падали и достигли земли, то хватит падать:
7008 if GetAIFlag('FALLINHOLE') <> '' then
7010 RemoveAIFlag('FALLINHOLE');
7012 // Если летели прямо и сейчас не на лестнице или на вершине лифта, то отходим в сторону:
7013 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7014 if GetAIFlag('FALLINHOLE') = '' then
7015 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7021 // Если на земле и можно подпрыгнуть, то, возможно, прыгаем:
7023 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7027 // Если на земле и возле дыры (глубина > 2 ростов игрока):
7028 if OnGround() and NearHole() then
7029 if NearDeepHole() then // Если это бездна
7031 0..3: Turn(); // Бежим обратно
7032 4: Jump(); // Прыгаем
7033 5: begin // Прыгаем обратно
7038 else // Это не бездна и мы еще не летим туда
7039 if GetAIFlag('GOINHOLE') = '' then
7041 0: Turn(); // Не нужно туда
7042 1: Jump(); // Вдруг повезет - прыгаем
7043 else // Если яма с границей, то при случае можно туда прыгнуть
7044 if BorderHole() then
7045 SetAIFlag('GOINHOLE', '1');
7048 // Если на земле, но некуда идти:
7049 if (not CanRun()) and OnGround() then
7051 // Если мы на лестнице или можно перепрыгнуть, то прыгаем:
7052 if CanJumpOver() or OnLadder() then
7054 else // иначе попытаемся в другую сторону
7055 if Random(2) = 0 then
7057 if IsSafeTrigger() then
7063 // Осталось мало воздуха:
7064 if FAir
< 36 * 2 then
7067 // Выбираемся из кислоты, если нет костюма, обожглись, или мало здоровья:
7068 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7069 if BodyInAcid(0, 0) then
7073 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7075 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7076 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7079 {function TBot.NeedItem(Item: Byte): Byte;
7084 procedure TBot
.SelectWeapon(Dist
: Integer);
7088 function HaveAmmo(weapon
: Byte): Boolean;
7091 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7092 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7093 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7094 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7095 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7096 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7097 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7098 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7099 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7100 else Result
:= True;
7105 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7107 if Dist
> BOT_LONGDIST
then
7108 begin // Дальний бой
7110 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7112 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7116 else //if Dist > BOT_UNSAFEDIST then
7117 begin // Ближний бой
7119 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7121 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7128 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7130 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7136 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7138 Result
:= inherited PickItem(ItemType
, force
, remove
);
7140 if Result
then SetAIFlag('SELECTWEAPON', '1');
7143 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7145 Result
:= inherited Heal(value
, Soft
);
7148 function TBot
.Healthy(): Byte;
7150 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7151 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7152 else if (FHealth
> 50) then Result
:= 2
7153 else if (FHealth
> 20) then Result
:= 1
7157 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7159 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7160 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7163 procedure TBot
.OnDamage(Angle
: SmallInt);
7171 if (Angle
= 0) or (Angle
= 180) then
7174 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7175 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7177 pla
:= g_Player_Get(FLastSpawnerUID
);
7178 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7179 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7182 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7183 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7185 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7186 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7187 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7192 SetAIFlag('ATTACKLEFT', '1')
7194 SetAIFlag('ATTACKRIGHT', '1');
7198 function TBot
.RunDirection(): TDirection
;
7200 if Abs(Vel
.X
) >= 1 then
7202 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7204 Result
:= FDirection
;
7207 function TBot
.GetRnd(a
: Byte): Boolean;
7209 if a
= 0 then Result
:= False
7210 else if a
= 255 then Result
:= True
7211 else Result
:= Random(256) > 255-a
;
7214 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7216 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7220 procedure TDifficult
.save (st
: TStream
);
7222 utils
.writeInt(st
, Byte(DiagFire
));
7223 utils
.writeInt(st
, Byte(InvisFire
));
7224 utils
.writeInt(st
, Byte(DiagPrecision
));
7225 utils
.writeInt(st
, Byte(FlyPrecision
));
7226 utils
.writeInt(st
, Byte(Cover
));
7227 utils
.writeInt(st
, Byte(CloseJump
));
7228 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7229 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7232 procedure TDifficult
.load (st
: TStream
);
7234 DiagFire
:= utils
.readByte(st
);
7235 InvisFire
:= utils
.readByte(st
);
7236 DiagPrecision
:= utils
.readByte(st
);
7237 FlyPrecision
:= utils
.readByte(st
);
7238 Cover
:= utils
.readByte(st
);
7239 CloseJump
:= utils
.readByte(st
);
7240 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7241 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7245 procedure TBot
.SaveState (st
: TStream
);
7250 inherited SaveState(st
);
7251 utils
.writeSign(st
, 'BOT0');
7253 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7255 utils
.writeInt(st
, Word(FTargetUID
));
7256 // Время потери цели
7257 utils
.writeInt(st
, LongWord(FLastVisible
));
7258 // Количество флагов ИИ
7259 dw
:= Length(FAIFlags
);
7260 utils
.writeInt(st
, LongInt(dw
));
7262 for i
:= 0 to dw
-1 do
7264 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7265 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7267 // Настройки сложности
7268 FDifficult
.save(st
);
7272 procedure TBot
.LoadState (st
: TStream
);
7277 inherited LoadState(st
);
7278 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7280 FSelectedWeapon
:= utils
.readByte(st
);
7282 FTargetUID
:= utils
.readWord(st
);
7283 // Время потери цели
7284 FLastVisible
:= utils
.readLongWord(st
);
7285 // Количество флагов ИИ
7286 dw
:= utils
.readLongInt(st
);
7287 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7288 SetLength(FAIFlags
, dw
);
7290 for i
:= 0 to dw
-1 do
7292 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7293 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7295 // Настройки сложности
7296 FDifficult
.load(st
);
7301 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');
7302 conRegVar('player_indicator_style', @gPlayerIndicatorStyle
, 'Visual appearance of indicator', 'Visual appearance of indicator');