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
: TAnimationState
;
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
: TAnimationState 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;
2148 FPunchAnim
:= TAnimationState
.Create(False, 1, 4);
2154 procedure TPlayer
.positionChanged (); inline;
2158 procedure TPlayer
.doDamage (v
: Integer);
2160 if (v
<= 0) then exit
;
2161 if (v
> 32767) then v
:= 32767;
2162 Damage(v
, 0, 0, 0, mEDamageType
);
2165 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2169 if (not g_Game_IsClient
) and (not FAlive
) then
2174 // Неуязвимость не спасает от ловушек:
2175 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2177 if not g_Game_IsClient
then
2180 if t
= HIT_TRAP
then
2182 // Ловушка убивает сразу:
2184 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2186 if t
= HIT_SELF
then
2190 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2193 // Обнулить действия примочек, чтобы фон пропал
2194 FMegaRulez
[MR_SUIT
] := 0;
2195 FMegaRulez
[MR_INVUL
] := 0;
2196 FMegaRulez
[MR_INVIS
] := 0;
2201 // Но от остального спасает:
2202 if FMegaRulez
[MR_INVUL
] >= gTime
then
2209 // Если есть урон своим, или ранил сам себя, или тебя ранил противник:
2210 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2211 (SpawnerUID
= FUID
) or
2212 (not SameTeam(FUID
, SpawnerUID
)) then
2214 FLastSpawnerUID
:= SpawnerUID
;
2216 // Кровь (пузырьки, если в воде):
2217 if gBloodCount
> 0 then
2219 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2220 if value
div 4 <= c
then
2221 c
:= c
- (value
div 4)
2225 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2229 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2230 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2233 if t
= HIT_WATER
then
2235 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2236 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2238 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
2239 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
2245 Inc(FDamageBuffer
, value
);
2249 FPain
:= FPain
+ value
;
2252 if g_Game_IsServer
and g_Game_IsNet
then
2254 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2255 MH_SEND_PlayerStats(FUID
);
2256 MH_SEND_PlayerPos(False, FUID
);
2260 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2263 if g_Game_IsClient
then
2268 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2270 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2273 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2275 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2279 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2280 MH_SEND_PlayerStats(FUID
);
2283 destructor TPlayer
.Destroy();
2285 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2287 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2291 FSawSoundIdle
.Free();
2292 FSawSoundHit
.Free();
2293 FSawSoundSelect
.Free();
2294 FFlameSoundOn
.Free();
2295 FFlameSoundOff
.Free();
2296 FFlameSoundWork
.Free();
2297 FJetSoundFly
.Free();
2299 FJetSoundOff
.Free();
2306 procedure TPlayer
.DoPunch();
2312 procedure TPlayer
.Fire();
2314 f
, DidFire
: Boolean;
2315 wx
, wy
, xd
, yd
: Integer;
2318 if g_Game_IsClient
then Exit
;
2319 // FBFGFireCounter - время перед выстрелом (для BFG)
2320 // FReloading - время после выстрела (для всего)
2328 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2333 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2334 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2335 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
2336 yd
:= wy
+firediry();
2342 if R_BERSERK
in FRulez
then
2344 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2345 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2346 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2349 locobj
.rect
.Width
:= 39;
2350 locobj
.rect
.Height
:= 52;
2351 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2352 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2353 locobj
.Accel
.X
:= xd
-wx
;
2354 locobj
.Accel
.y
:= yd
-wy
;
2356 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2357 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2359 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2361 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
2365 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2369 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2374 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2375 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2377 FSawSoundSelect
.Stop();
2379 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2381 else if not FSawSoundHit
.IsPlaying() then
2383 FSawSoundSelect
.Stop();
2384 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2387 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2393 if FAmmo
[A_BULLETS
] > 0 then
2395 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2396 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2397 Dec(FAmmo
[A_BULLETS
]);
2398 FFireAngle
:= FAngle
;
2401 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2402 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2406 if FAmmo
[A_SHELLS
] > 0 then
2408 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2409 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
2410 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2411 Dec(FAmmo
[A_SHELLS
]);
2412 FFireAngle
:= FAngle
;
2416 FShellType
:= SHELL_SHELL
;
2420 if FAmmo
[A_SHELLS
] >= 2 then
2422 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
2423 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2424 Dec(FAmmo
[A_SHELLS
], 2);
2425 FFireAngle
:= FAngle
;
2429 FShellType
:= SHELL_DBLSHELL
;
2433 if FAmmo
[A_BULLETS
] > 0 then
2435 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
2436 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
2437 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2438 Dec(FAmmo
[A_BULLETS
]);
2439 FFireAngle
:= FAngle
;
2442 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2443 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2446 WEAPON_ROCKETLAUNCHER
:
2447 if FAmmo
[A_ROCKETS
] > 0 then
2449 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
2450 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2451 Dec(FAmmo
[A_ROCKETS
]);
2452 FFireAngle
:= FAngle
;
2458 if FAmmo
[A_CELLS
] > 0 then
2460 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
2461 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2462 Dec(FAmmo
[A_CELLS
]);
2463 FFireAngle
:= FAngle
;
2469 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
2471 FBFGFireCounter
:= 17;
2472 if not FNoReload
then
2473 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
2474 Dec(FAmmo
[A_CELLS
], 40);
2478 WEAPON_SUPERPULEMET
:
2479 if FAmmo
[A_SHELLS
] > 0 then
2481 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2482 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
2483 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2484 Dec(FAmmo
[A_SHELLS
]);
2485 FFireAngle
:= FAngle
;
2488 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2489 GameVelX
, GameVelY
-2, SHELL_SHELL
);
2492 WEAPON_FLAMETHROWER
:
2493 if FAmmo
[A_FUEL
] > 0 then
2495 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
2497 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2499 FFireAngle
:= FAngle
;
2506 if g_Game_IsNet
and g_Game_IsServer
then MH_SEND_PlayerStats(FUID
);
2510 if g_Game_IsNet
then
2514 if FCurrWeap
<> WEAPON_BFG
then
2515 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
2517 if not FNoReload
then
2518 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
2521 MH_SEND_PlayerStats(FUID
);
2526 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
2527 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
2528 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
2531 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
2534 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
2535 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
2536 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
2537 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
2538 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
2543 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
2545 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
2546 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
2547 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
2550 procedure TPlayer
.FlamerOn
;
2552 FFlameSoundOff
.Stop();
2553 FFlameSoundOff
.SetPosition(0);
2556 if (not FFlameSoundOn
.IsPlaying()) and (not FFlameSoundWork
.IsPlaying()) then
2557 FFlameSoundWork
.PlayAt(FObj
.X
, FObj
.Y
);
2561 FFlameSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
2566 procedure TPlayer
.FlamerOff
;
2570 FFlameSoundOn
.Stop();
2571 FFlameSoundOn
.SetPosition(0);
2572 FFlameSoundWork
.Stop();
2573 FFlameSoundWork
.SetPosition(0);
2574 FFlameSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
2579 procedure TPlayer
.JetpackOn
;
2583 FJetSoundOn
.SetPosition(0);
2584 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
2588 procedure TPlayer
.JetpackOff
;
2592 FJetSoundOff
.SetPosition(0);
2593 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
2596 procedure TPlayer
.CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
2598 if Timeout
<= 0 then
2600 if (FMegaRulez
[MR_SUIT
] > gTime
) or (FMegaRulez
[MR_INVUL
] > gTime
) then
2601 exit
; // Не загораемся когда есть защита
2602 if g_Obj_CollidePanel(@FObj
, 0, 0, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
) then
2603 exit
; // Не подгораем в воде на всякий случай
2604 if FFireTime
<= 0 then
2605 g_Sound_PlayExAt('SOUND_IGNITE', FObj
.X
, FObj
.Y
);
2606 FFireTime
:= Timeout
;
2607 FFireAttacker
:= Attacker
;
2608 if g_Game_IsNet
and g_Game_IsServer
then
2609 MH_SEND_PlayerStats(FUID
);
2612 procedure TPlayer
.Jump();
2614 if gFly
or FJetpack
then
2616 // Полет (чит-код или джетпак):
2617 if FObj
.Vel
.Y
> -VEL_FLY
then
2618 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
2621 if FJetFuel
> 0 then
2623 if (FJetFuel
< 1) and g_Game_IsServer
then
2627 if g_Game_IsNet
then
2628 MH_SEND_PlayerStats(FUID
);
2634 // Не включать джетпак в режиме прохождения сквозь стены
2636 FCanJetpack
:= False;
2638 // Прыгаем или всплываем:
2639 if (CollideLevel(0, 1) or
2640 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
2641 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
2642 ) and (FObj
.Accel
.Y
= 0) then // Не прыгать, если есть вертикальное ускорение
2644 FObj
.Vel
.Y
:= -VEL_JUMP
;
2645 FCanJetpack
:= False;
2649 if BodyInLiquid(0, 0) then
2650 FObj
.Vel
.Y
:= -VEL_SW
2651 else if (FJetFuel
> 0) and FCanJetpack
and
2652 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
2656 if g_Game_IsNet
then
2657 MH_SEND_PlayerStats(FUID
);
2662 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
2664 a
, i
, k
, ab
, ar
: Byte;
2668 srv
, netsrv
: Boolean;
2674 procedure PushItem(t
: Byte);
2678 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
2679 it
:= g_Items_ByIdx(id
);
2680 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
2682 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
2683 (FObj
.Vel
.Y
div 2)-Random(9));
2684 it
.positionChanged(); // this updates spatial accelerators
2688 if KillType
= K_HARDKILL
then // -5..+5; -5..0
2690 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
2691 (FObj
.Vel
.Y
div 2)-Random(6));
2693 else // -3..+3; -3..0
2695 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
2696 (FObj
.Vel
.Y
div 2)-Random(4));
2698 it
.positionChanged(); // this updates spatial accelerators
2701 if g_Game_IsNet
and g_Game_IsServer
then
2702 MH_SEND_ItemSpawn(True, id
);
2706 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
2707 Srv
:= g_Game_IsServer
;
2708 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
2709 if Srv
then FDeath
:= FDeath
+ 1;
2714 if not FPhysics
then
2720 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2722 if FLives
> 0 then FLives
:= FLives
- 1;
2723 if FLives
= 0 then FNoRespawn
:= True;
2726 // Номер типа смерти:
2729 K_SIMPLEKILL
: a
:= 1;
2731 K_EXTRAHARDKILL
: a
:= 3;
2736 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
2738 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
2745 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
2747 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
2748 K_EXTRAHARDKILL
, K_FALLKILL
:
2749 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
2752 // Переключаем состояние:
2756 K_HARDKILL
, K_EXTRAHARDKILL
:
2760 // Реакция монстров на смерть игрока:
2761 if (KillType
<> K_FALLKILL
) and (Srv
) then
2762 g_Monsters_killedp();
2764 if SpawnerUID
= FUID
then
2768 if gGameSettings
.GameMode
= GM_TDM
then
2769 Dec(gTeamStat
[FTeam
].Score
);
2770 if DoFrags
or (gGameSettings
.GameMode
= GM_TDM
) then
2776 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
2779 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
2780 begin // Убит другим игроком
2781 KP
:= g_Player_Get(SpawnerUID
);
2782 if (KP
<> nil) and Srv
then
2784 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
2785 if SameTeam(FUID
, SpawnerUID
) then
2795 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
2796 Inc(gTeamStat
[KP
.Team
].Score
,
2797 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
2799 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
2802 plr
:= g_Player_Get(SpawnerUID
);
2810 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
2814 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
2818 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
2823 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
2824 begin // Убит монстром
2825 mon
:= g_Monsters_ByUID(SpawnerUID
);
2829 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
2833 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
2837 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
2841 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
2846 else // Особые типы смерти
2849 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
2850 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
2851 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
2852 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
2853 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
2854 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
2860 for a
:= WP_FIRST
to WP_LAST
do
2864 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
2865 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
2866 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
2867 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
2868 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
2869 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
2870 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
2871 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
2872 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
2881 if R_ITEM_BACKPACK
in FRulez
then
2882 PushItem(ITEM_AMMO_BACKPACK
);
2884 // Выброс ракетного ранца:
2885 if FJetFuel
> 0 then
2886 PushItem(ITEM_JETPACK
);
2889 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) or
2890 (not LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
)) then
2892 if R_KEY_RED
in FRulez
then
2893 PushItem(ITEM_KEY_RED
);
2895 if R_KEY_GREEN
in FRulez
then
2896 PushItem(ITEM_KEY_GREEN
);
2898 if R_KEY_BLUE
in FRulez
then
2899 PushItem(ITEM_KEY_BLUE
);
2903 DropFlag(KillType
= K_FALLKILL
);
2906 FCorpse
:= g_Player_CreateCorpse(Self
);
2908 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
2909 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2915 for i
:= Low(gPlayers
) to High(gPlayers
) do
2917 if gPlayers
[i
] = nil then continue
;
2918 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
2921 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
2922 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
2927 OldLR
:= gLMSRespawn
;
2928 if (gGameSettings
.GameMode
= GM_COOP
) then
2932 // everyone is dead, restart the map
2933 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
2935 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
2936 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2937 gLMSRespawnTime
:= gTime
+ 5000;
2939 else if (a
= 1) then
2941 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
2942 if (gPlayers
[k
] = gPlayer1
) or
2943 (gPlayers
[k
] = gPlayer2
) then
2944 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
2945 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
2946 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
2949 else if (gGameSettings
.GameMode
= GM_TDM
) then
2951 if (ab
= 0) and (ar
<> 0) then
2954 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
2956 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
2957 Inc(gTeamStat
[TEAM_RED
].Score
);
2958 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2959 gLMSRespawnTime
:= gTime
+ 5000;
2961 else if (ar
= 0) and (ab
<> 0) then
2964 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
2966 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
2967 Inc(gTeamStat
[TEAM_BLUE
].Score
);
2968 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2969 gLMSRespawnTime
:= gTime
+ 5000;
2971 else if (ar
= 0) and (ab
= 0) then
2974 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
2976 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
2977 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2978 gLMSRespawnTime
:= gTime
+ 5000;
2981 else if (gGameSettings
.GameMode
= GM_DM
) then
2985 if gPlayers
[k
] <> nil then
2988 // survivor is the winner
2989 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
2991 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
2994 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2995 gLMSRespawnTime
:= gTime
+ 5000;
2997 else if (a
= 0) then
2999 // everyone is dead, restart the map
3000 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3002 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3003 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3004 gLMSRespawnTime
:= gTime
+ 5000;
3007 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3009 if NetMode
= NET_SERVER
then
3010 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
)
3012 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3018 MH_SEND_PlayerStats(FUID
);
3019 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3020 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3023 if srv
and FNoRespawn
then Spectate(True);
3024 FWantsInGame
:= True;
3027 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3029 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3030 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3033 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3035 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3036 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3039 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3040 var Blood
: TModelBlood
;
3042 Blood
:= SELF
.FModel
.GetBlood();
3043 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3044 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3045 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3046 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
3047 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3048 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3049 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3050 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
3053 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3054 var Blood
: TModelBlood
;
3056 Blood
:= SELF
.FModel
.GetBlood();
3057 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3058 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3059 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3060 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
3063 procedure TPlayer
.ProcessWeaponAction(Action
: Byte);
3065 if g_Game_IsClient
then Exit
;
3067 WP_PREV
: PrevWeapon();
3068 WP_NEXT
: NextWeapon();
3072 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3074 if g_Game_IsClient
then Exit
;
3075 if Weapon
> High(FWeapon
) then Exit
;
3076 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3079 procedure TPlayer
.resetWeaponQueue ();
3082 FNextWeapDelay
:= 0;
3085 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3089 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3090 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
3091 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
3092 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3093 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3094 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3095 else result
:= (weapon
< length(FWeapon
));
3099 function TPlayer
.hasAmmoForShooting (weapon
: Byte): Boolean;
3103 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3104 WEAPON_SHOTGUN1
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
3105 WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 1);
3106 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
3107 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3108 WEAPON_PLASMA
: result
:= (FAmmo
[A_CELLS
] > 0);
3109 WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] >= 40);
3110 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3111 else result
:= (weapon
< length(FWeapon
));
3115 function TPlayer
.shouldSwitch (weapon
: Byte; hadWeapon
: Boolean): Boolean;
3118 if (weapon
> WP_LAST
+ 1) then
3123 if (FWeapSwitchMode
= 1) and not hadWeapon
then
3125 else if (FWeapSwitchMode
= 2) then
3126 result
:= (FWeapPreferences
[weapon
] > FWeapPreferences
[FCurrWeap
]);
3129 // return 255 for "no switch"
3130 function TPlayer
.getNextWeaponIndex (): Byte;
3133 wantThisWeapon
: array[0..64] of Boolean;
3134 wwc
: Integer = 0; //HACK!
3137 result
:= 255; // default result: "no switch"
3138 //e_LogWriteFln('FSWITCHTOEMPTY: %s', [FSwitchToEmpty], TMsgType.Notify);
3139 // had weapon cycling on previous frame? remove that flag
3140 if (FNextWeap
and $2000) <> 0 then
3142 FNextWeap
:= FNextWeap
and $1FFF;
3143 FNextWeapDelay
:= 0;
3145 // cycling has priority
3146 if (FNextWeap
and $C000) <> 0 then
3148 if (FNextWeap
and $8000) <> 0 then
3152 FNextWeap
:= FNextWeap
or $2000; // we need this
3153 if FNextWeapDelay
> 0 then
3154 exit
; // cooldown time
3156 for i
:= 0 to High(FWeapon
) do
3158 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3159 if FWeapon
[cwi
] and maySwitch(cwi
) then
3161 //e_LogWriteFln(' SWITCH: cur=%d; new=%d %s %s', [FCurrWeap, cwi, FSwitchToEmpty, hasAmmoForWeapon(cwi)], TMsgType.Notify);
3162 result
:= Byte(cwi
);
3163 FNextWeapDelay
:= WEAPON_DELAY
;
3171 for i
:= 0 to High(wantThisWeapon
) do
3172 wantThisWeapon
[i
] := false;
3173 for i
:= 0 to High(FWeapon
) do
3174 if (FNextWeap
and (1 shl i
)) <> 0 then
3176 wantThisWeapon
[i
] := true;
3180 // exclude currently selected weapon from the set
3181 wantThisWeapon
[FCurrWeap
] := false;
3182 // slow down alterations a little
3185 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3186 // more than one weapon requested, assume "alteration" and check alteration delay
3187 if FNextWeapDelay
> 0 then
3193 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3194 // but clear all counters if no weapon should be switched
3200 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3201 // try weapons in descending order
3202 for i
:= High(FWeapon
) downto 0 do
3204 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3209 FNextWeapDelay
:= WEAPON_DELAY
* 2; // anyway, 'cause why not
3210 //e_LogWriteFln('FOUND %s %s %s', [result, FSwitchToEmpty, hasAmmoForWeapon(i)], TMsgType.Notify);
3214 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3218 procedure TPlayer
.RealizeCurrentWeapon();
3219 function switchAllowed (): Boolean;
3224 if FBFGFireCounter
<> -1 then
3226 if FTime
[T_SWITCH
] > gTime
then
3228 for i
:= WP_FIRST
to WP_LAST
do
3229 if FReloading
[i
] > 0 then
3237 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3238 //FNextWeap := FNextWeap and $1FFF;
3239 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3241 if not switchAllowed
then
3243 //HACK for weapon cycling
3244 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3248 nw
:= getNextWeaponIndex();
3250 if nw
= 255 then exit
; // don't reset anything here
3251 if nw
> High(FWeapon
) then
3253 // don't forget to reset queue here!
3254 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3262 FTime
[T_SWITCH
] := gTime
+156;
3263 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3264 FModel
.SetWeapon(FCurrWeap
);
3265 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3269 procedure TPlayer
.NextWeapon();
3271 if g_Game_IsClient
then Exit
;
3275 procedure TPlayer
.PrevWeapon();
3277 if g_Game_IsClient
then Exit
;
3281 procedure TPlayer
.SetWeapon(W
: Byte);
3283 if FCurrWeap
<> W
then
3284 if W
= WEAPON_SAW
then
3285 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3288 FModel
.SetWeapon(CurrWeap
);
3292 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3295 switchWeapon
: Byte = 255;
3296 hadWeapon
: Boolean = False;
3299 if g_Game_IsClient
then Exit
;
3301 // a = true - место спавна предмета:
3302 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3306 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3308 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3312 if gFlash
= 2 then Inc(FPickup
, 5);
3316 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3318 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3322 if gFlash
= 2 then Inc(FPickup
, 5);
3326 if FArmor
< PLAYER_AP_SOFT
then
3328 FArmor
:= PLAYER_AP_SOFT
;
3331 if gFlash
= 2 then Inc(FPickup
, 5);
3335 if FArmor
< PLAYER_AP_LIMIT
then
3337 FArmor
:= PLAYER_AP_LIMIT
;
3340 if gFlash
= 2 then Inc(FPickup
, 5);
3344 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
3346 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3350 if gFlash
= 2 then Inc(FPickup
, 5);
3354 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) or (FFireTime
> 0) then
3356 if FHealth
< PLAYER_HP_LIMIT
then
3357 FHealth
:= PLAYER_HP_LIMIT
;
3358 if FArmor
< PLAYER_AP_LIMIT
then
3359 FArmor
:= PLAYER_AP_LIMIT
;
3363 if gFlash
= 2 then Inc(FPickup
, 5);
3367 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3369 hadWeapon
:= FWeapon
[WEAPON_SAW
];
3370 switchWeapon
:= WEAPON_SAW
;
3371 FWeapon
[WEAPON_SAW
] := True;
3373 if gFlash
= 2 then Inc(FPickup
, 5);
3374 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3377 ITEM_WEAPON_SHOTGUN1
:
3378 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3380 // Нужно, чтобы не взять все пули сразу:
3381 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3382 hadWeapon
:= FWeapon
[WEAPON_SHOTGUN1
];
3383 switchWeapon
:= WEAPON_SHOTGUN1
;
3384 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3385 FWeapon
[WEAPON_SHOTGUN1
] := 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_SHOTGUN2
:
3392 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3394 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3395 hadWeapon
:= FWeapon
[WEAPON_SHOTGUN2
];
3396 switchWeapon
:= WEAPON_SHOTGUN2
;
3397 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3398 FWeapon
[WEAPON_SHOTGUN2
] := True;
3400 if gFlash
= 2 then Inc(FPickup
, 5);
3401 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3404 ITEM_WEAPON_CHAINGUN
:
3405 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3407 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3408 hadWeapon
:= FWeapon
[WEAPON_CHAINGUN
];
3409 switchWeapon
:= WEAPON_CHAINGUN
;
3410 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3411 FWeapon
[WEAPON_CHAINGUN
] := True;
3413 if gFlash
= 2 then Inc(FPickup
, 5);
3414 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3417 ITEM_WEAPON_ROCKETLAUNCHER
:
3418 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3420 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3421 switchWeapon
:= WEAPON_ROCKETLAUNCHER
;
3422 hadWeapon
:= FWeapon
[WEAPON_ROCKETLAUNCHER
];
3423 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3424 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3426 if gFlash
= 2 then Inc(FPickup
, 5);
3427 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3431 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3433 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3434 switchWeapon
:= WEAPON_PLASMA
;
3435 hadWeapon
:= FWeapon
[WEAPON_PLASMA
];
3436 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3437 FWeapon
[WEAPON_PLASMA
] := True;
3439 if gFlash
= 2 then Inc(FPickup
, 5);
3440 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3444 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3446 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3447 switchWeapon
:= WEAPON_BFG
;
3448 hadWeapon
:= FWeapon
[WEAPON_BFG
];
3449 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3450 FWeapon
[WEAPON_BFG
] := True;
3452 if gFlash
= 2 then Inc(FPickup
, 5);
3453 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3456 ITEM_WEAPON_SUPERPULEMET
:
3457 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3459 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3460 switchWeapon
:= WEAPON_SUPERPULEMET
;
3461 hadWeapon
:= FWeapon
[WEAPON_SUPERPULEMET
];
3462 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3463 FWeapon
[WEAPON_SUPERPULEMET
] := True;
3465 if gFlash
= 2 then Inc(FPickup
, 5);
3466 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3469 ITEM_WEAPON_FLAMETHROWER
:
3470 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
3472 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
3473 switchWeapon
:= WEAPON_FLAMETHROWER
;
3474 hadWeapon
:= FWeapon
[WEAPON_FLAMETHROWER
];
3475 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3476 FWeapon
[WEAPON_FLAMETHROWER
] := True;
3478 if gFlash
= 2 then Inc(FPickup
, 5);
3479 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3483 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3485 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3488 if gFlash
= 2 then Inc(FPickup
, 5);
3491 ITEM_AMMO_BULLETS_BOX
:
3492 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3494 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3497 if gFlash
= 2 then Inc(FPickup
, 5);
3501 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3503 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3506 if gFlash
= 2 then Inc(FPickup
, 5);
3509 ITEM_AMMO_SHELLS_BOX
:
3510 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3512 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
3515 if gFlash
= 2 then Inc(FPickup
, 5);
3519 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3521 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3524 if gFlash
= 2 then Inc(FPickup
, 5);
3527 ITEM_AMMO_ROCKET_BOX
:
3528 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3530 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
3533 if gFlash
= 2 then Inc(FPickup
, 5);
3537 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3539 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3542 if gFlash
= 2 then Inc(FPickup
, 5);
3546 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3548 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
3551 if gFlash
= 2 then Inc(FPickup
, 5);
3555 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
3557 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3560 if gFlash
= 2 then Inc(FPickup
, 5);
3564 if not(R_ITEM_BACKPACK
in FRulez
) or
3565 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
3566 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
3567 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
3568 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
3569 (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) then
3571 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
3572 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
3573 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
3574 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
3575 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
3577 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3578 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3579 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3580 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3581 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3582 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3583 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3584 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3585 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
3586 IncMax(FAmmo
[A_FUEL
], 50, FMaxAmmo
[A_FUEL
]);
3588 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
3591 if gFlash
= 2 then Inc(FPickup
, 5);
3595 if not(R_KEY_RED
in FRulez
) then
3597 Include(FRulez
, R_KEY_RED
);
3599 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3600 if gFlash
= 2 then Inc(FPickup
, 5);
3601 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3605 if not(R_KEY_GREEN
in FRulez
) then
3607 Include(FRulez
, R_KEY_GREEN
);
3609 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3610 if gFlash
= 2 then Inc(FPickup
, 5);
3611 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3615 if not(R_KEY_BLUE
in FRulez
) then
3617 Include(FRulez
, R_KEY_BLUE
);
3619 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3620 if gFlash
= 2 then Inc(FPickup
, 5);
3621 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3625 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
3627 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
3631 if gFlash
= 2 then Inc(FPickup
, 5);
3635 if FAir
< AIR_MAX
then
3640 if gFlash
= 2 then Inc(FPickup
, 5);
3645 if not (R_BERSERK
in FRulez
) then
3647 Include(FRulez
, R_BERSERK
);
3648 if (FBFGFireCounter
= -1) then
3650 FCurrWeap
:= WEAPON_KASTET
;
3652 FModel
.SetWeapon(WEAPON_KASTET
);
3657 if gFlash
= 2 then Inc(FPickup
, 5);
3659 FBerserk
:= gTime
+30000;
3664 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3666 if FHealth
< PLAYER_HP_SOFT
then FHealth
:= PLAYER_HP_SOFT
;
3667 FBerserk
:= gTime
+30000;
3675 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
3677 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
3681 if gFlash
= 2 then Inc(FPickup
, 5);
3685 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
3687 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
3691 if gFlash
= 2 then Inc(FPickup
, 5);
3695 if FArmor
< PLAYER_AP_LIMIT
then
3697 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
3700 if gFlash
= 2 then Inc(FPickup
, 5);
3704 if FJetFuel
< JET_MAX
then
3706 FJetFuel
:= JET_MAX
;
3709 if gFlash
= 2 then Inc(FPickup
, 5);
3713 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
3715 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
3718 if gFlash
= 2 then Inc(FPickup
, 5);
3722 if (shouldSwitch(switchWeapon
, hadWeapon
)) then
3723 QueueWeaponSwitch(switchWeapon
);
3726 procedure TPlayer
.Touch();
3730 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
3733 // Бросить флаг товарищу:
3734 if gGameSettings
.GameMode
= GM_CTF
then
3739 procedure TPlayer
.Push(vx
, vy
: Integer);
3741 if (not FPhysics
) and FGhost
then
3743 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
3744 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
3745 if g_Game_IsNet
and g_Game_IsServer
then
3746 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
3749 procedure TPlayer
.Reset(Force
: Boolean);
3755 FTime
[T_RESPAWN
] := 0;
3756 FTime
[T_FLAGCAP
] := 0;
3772 FSpectator
:= False;
3775 FSpectatePlayer
:= -1;
3776 FNoRespawn
:= False;
3778 FLives
:= gGameSettings
.MaxLives
;
3783 procedure TPlayer
.SoftReset();
3791 FBFGFireCounter
:= -1;
3799 SetAction(A_STAND
, True);
3802 function TPlayer
.GetRespawnPoint(): Byte;
3807 // На будущее: FSpawn - игрок уже играл и перерождается
3809 // Одиночная игра/кооператив
3810 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
3812 if Self
= gPlayer1
then
3814 // player 1 should try to spawn on the player 1 point
3815 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) > 0 then
3816 Exit(RESPAWNPOINT_PLAYER1
)
3817 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) > 0 then
3818 Exit(RESPAWNPOINT_PLAYER2
);
3820 else if Self
= gPlayer2
then
3822 // player 2 should try to spawn on the player 2 point
3823 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) > 0 then
3824 Exit(RESPAWNPOINT_PLAYER2
)
3825 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) > 0 then
3826 Exit(RESPAWNPOINT_PLAYER1
);
3830 // other players randomly pick either the first or the second point
3831 c
:= IfThen((Random(2) = 0), RESPAWNPOINT_PLAYER1
, RESPAWNPOINT_PLAYER2
);
3832 if g_Map_GetPointCount(c
) > 0 then
3834 // try the other one
3835 c
:= IfThen((c
= RESPAWNPOINT_PLAYER1
), RESPAWNPOINT_PLAYER2
, RESPAWNPOINT_PLAYER1
);
3836 if g_Map_GetPointCount(c
) > 0 then
3842 if gGameSettings
.GameMode
= GM_DM
then
3844 // try DM points first
3845 if g_Map_GetPointCount(RESPAWNPOINT_DM
) > 0 then
3846 Exit(RESPAWNPOINT_DM
);
3850 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
3852 // try team points first
3853 c
:= RESPAWNPOINT_DM
;
3854 if FTeam
= TEAM_RED
then
3855 c
:= RESPAWNPOINT_RED
3856 else if FTeam
= TEAM_BLUE
then
3857 c
:= RESPAWNPOINT_BLUE
;
3858 if g_Map_GetPointCount(c
) > 0 then
3862 // still haven't found a spawnpoint, try random shit
3863 Result
:= g_Map_GetRandomPointType();
3866 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
3868 RespawnPoint
: TRespawnPoint
;
3874 FBFGFireCounter
:= -1;
3881 if not g_Game_IsServer
then
3885 FWantsInGame
:= True;
3886 FJustTeleported
:= True;
3889 FTime
[T_RESPAWN
] := 0;
3893 // if server changes MaxLives we gotta be ready
3894 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
3896 // Еще нельзя возродиться:
3897 if FTime
[T_RESPAWN
] > gTime
then
3900 // Просрал все жизни:
3903 if not FSpectator
then Spectate(True);
3904 FWantsInGame
:= True;
3908 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
3909 begin // "Своя игра"
3910 // Берсерк не сохраняется между уровнями:
3911 FRulez
:= FRulez
-[R_BERSERK
];
3913 else // "Одиночная игра"/"Кооп"
3915 // Берсерк и ключи не сохраняются между уровнями:
3916 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
3919 // Получаем точку спауна игрока:
3920 c
:= GetRespawnPoint();
3925 // Воскрешение без оружия:
3928 FHealth
:= Round(PLAYER_HP_SOFT
* (FHandicap
/ 100));
3934 for a
:= WP_FIRST
to WP_LAST
do
3936 FWeapon
[a
] := False;
3940 FWeapon
[WEAPON_PISTOL
] := True;
3941 FWeapon
[WEAPON_KASTET
] := True;
3942 FCurrWeap
:= WEAPON_PISTOL
;
3945 FModel
.SetWeapon(FCurrWeap
);
3947 for b
:= A_BULLETS
to A_HIGH
do
3950 FAmmo
[A_BULLETS
] := 50;
3952 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
3953 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
3954 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
3955 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
3956 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
3958 if (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) and
3959 LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
) then
3960 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
3965 // Получаем координаты точки возрождения:
3966 if not g_Map_GetPoint(c
, RespawnPoint
) then
3968 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3972 // Установка координат и сброс всех параметров:
3973 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
3974 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
3975 FObj
.oldX
:= FObj
.X
; // don't interpolate after respawn
3976 FObj
.oldY
:= FObj
.Y
;
3982 FDirection
:= RespawnPoint
.Direction
;
3983 if FDirection
= TDirection
.D_LEFT
then
3988 SetAction(A_STAND
, True);
3989 FModel
.Direction
:= FDirection
;
3991 for a
:= Low(FTime
) to High(FTime
) do
3994 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
3997 // Respawn invulnerability
3998 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.SpawnInvul
> 0) then
4000 FMegaRulez
[MR_INVUL
] := gTime
+ gGameSettings
.SpawnInvul
* 1000;
4001 FSpawnInvul
:= FMegaRulez
[MR_INVUL
];
4006 FCanJetpack
:= False;
4012 // Анимация возрождения:
4013 if (not gLoadGameMode
) and (not Silent
) then
4015 R_GFX_TELEPORT_FAST
,
4016 FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4017 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32
4020 FSpectator
:= False;
4023 FSpectatePlayer
:= -1;
4026 if (gPlayer1
= nil) and (gSpectLatchPID1
= FUID
) then
4028 if (gPlayer2
= nil) and (gSpectLatchPID2
= FUID
) then
4031 if g_Game_IsNet
then
4033 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4034 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4036 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4037 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4042 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4045 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4046 else if (not NoMove
) then
4048 GameX
:= gMapInfo
.Width
div 2;
4049 GameY
:= gMapInfo
.Height
div 2;
4058 FWantsInGame
:= False;
4064 if Self
= gPlayer1
then
4066 gSpectLatchPID1
:= FUID
;
4069 else if Self
= gPlayer2
then
4071 gSpectLatchPID2
:= FUID
;
4076 if g_Game_IsNet
then
4077 MH_SEND_PlayerStats(FUID
);
4080 procedure TPlayer
.SwitchNoClip
;
4084 FGhost
:= not FGhost
;
4085 FPhysics
:= not FGhost
;
4097 procedure TPlayer
.Run(Direction
: TDirection
);
4101 if MAX_RUNVEL
> 8 then
4105 if Direction
= TDirection
.D_LEFT
then
4107 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4108 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4111 if FObj
.Vel
.X
< MAX_RUNVEL
then
4112 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4114 // Возможно, пинаем куски:
4115 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4117 b
:= Abs(FObj
.Vel
.X
);
4118 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4119 for a
:= 0 to High(gGibs
) do
4121 if gGibs
[a
].alive
and
4122 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4123 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4126 if FObj
.Vel
.X
< 0 then
4128 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // налево
4132 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // направо
4134 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4142 procedure TPlayer
.SeeDown();
4144 SetAction(A_SEEDOWN
);
4146 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4148 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4151 procedure TPlayer
.SeeUp();
4155 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4157 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4160 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4168 A_ATTACK
: Prior
:= 2;
4169 A_SEEUP
: Prior
:= 1;
4170 A_SEEDOWN
: Prior
:= 1;
4171 A_ATTACKUP
: Prior
:= 2;
4172 A_ATTACKDOWN
: Prior
:= 2;
4177 if (Prior
> FActionPrior
) or Force
then
4178 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4180 FActionPrior
:= Prior
;
4181 FActionAnim
:= Action
;
4182 FActionForce
:= Force
;
4183 FActionChanged
:= True;
4186 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4189 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4191 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4192 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4193 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4194 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4197 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4201 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4203 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4204 if g_Game_IsServer
and g_Game_IsNet
then
4205 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4209 FJustTeleported
:= True;
4213 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4215 R_GFX_TELEPORT_FAST
,
4216 FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4217 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32
4219 if g_Game_IsServer
and g_Game_IsNet
then
4220 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4221 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4225 FObj
.X
:= X
-PLAYER_RECT
.X
;
4226 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4227 FObj
.oldX
:= FObj
.X
; // don't interpolate after respawn
4228 FObj
.oldY
:= FObj
.Y
;
4229 if FAlive
and FGhost
then
4235 if not g_Game_IsNet
then
4239 SetDirection(TDirection
.D_LEFT
);
4245 SetDirection(TDirection
.D_RIGHT
);
4251 if FDirection
= TDirection
.D_RIGHT
then
4253 SetDirection(TDirection
.D_LEFT
);
4258 SetDirection(TDirection
.D_RIGHT
);
4267 R_GFX_TELEPORT_FAST
,
4268 FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4269 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32
4271 if g_Game_IsServer
and g_Game_IsNet
then
4272 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4273 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4280 function nonz(a
: Single): Single;
4288 function TPlayer
.refreshCorpse(): Boolean;
4294 if FAlive
or FSpectator
then
4296 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
4298 for i
:= 0 to High(gCorpses
) do
4299 if gCorpses
[i
] <> nil then
4300 if gCorpses
[i
].FPlayerUID
= FUID
then
4308 function TPlayer
.getCameraObj(): TObj
;
4310 if (not FAlive
) and (not FSpectator
) and
4311 (FCorpse
>= 0) and (FCorpse
< Length(gCorpses
)) and
4312 (gCorpses
[FCorpse
] <> nil) and (gCorpses
[FCorpse
].FPlayerUID
= FUID
) then
4314 gCorpses
[FCorpse
].FObj
.slopeUpLeft
:= FObj
.slopeUpLeft
;
4315 Result
:= gCorpses
[FCorpse
].FObj
;
4323 procedure TPlayer
.PreUpdate();
4325 FSlopeOld
:= FObj
.slopeUpLeft
;
4326 FIncCamOld
:= FIncCam
;
4327 FObj
.oldX
:= FObj
.X
;
4328 FObj
.oldY
:= FObj
.Y
;
4331 procedure TPlayer
.Update();
4334 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4335 blockmon
, headwater
, dospawn
: Boolean;
4340 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4341 AnyServer
:= g_Game_IsServer
;
4343 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4344 DoLerp(NetInterpLevel
+ 1)
4350 if (FClientID
>= 0) and (NetClients
[FClientID
].Peer
<> nil) then
4352 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4353 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4354 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4365 if FPunchAnim
.played
then
4368 if FAlive
and (gFly
or FJetpack
) then
4371 if FDirection
= TDirection
.D_LEFT
then
4376 if FAlive
and (not FGhost
) then
4378 if FKeys
[KEY_UP
].Pressed
then
4380 if FKeys
[KEY_DOWN
].Pressed
then
4384 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4387 i
:= g_basic
.Sign(FIncCam
);
4388 FIncCam
:= Abs(FIncCam
);
4389 DecMin(FIncCam
, 5, 0);
4390 FIncCam
:= FIncCam
*i
;
4393 if gTime
mod (GAME_TICK
*2) <> 0 then
4395 if (FObj
.Vel
.X
= 0) and FAlive
then
4397 if FKeys
[KEY_LEFT
].Pressed
then
4398 Run(TDirection
.D_LEFT
);
4399 if FKeys
[KEY_RIGHT
].Pressed
then
4400 Run(TDirection
.D_RIGHT
);
4405 g_Obj_Move(@FObj
, True, True, True);
4406 positionChanged(); // this updates spatial accelerators
4412 FActionChanged
:= False;
4416 // Let alive player do some actions
4417 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
4418 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
4419 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire()
4425 if NetServer
then MH_SEND_PlayerStats(FUID
);
4428 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
4429 if FKeys
[KEY_JUMP
].Pressed
then Jump()
4432 if AnyServer
and FJetpack
then
4436 if NetServer
then MH_SEND_PlayerStats(FUID
);
4438 FCanJetpack
:= True;
4445 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
4447 if FKeys
[k
].Pressed
then
4455 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4458 if (FTime
[T_RESPAWN
] <= gTime
) and
4459 gGameOn
and (not FAlive
) then
4461 if (g_Player_GetCount() > 1) then
4465 gExit
:= EXIT_RESTART
;
4470 // Dead spectator actions
4473 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
4474 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
4478 if (FSpectatePlayer
>= High(gPlayers
)) then
4479 FSpectatePlayer
:= -1
4483 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
4484 if gPlayers
[I
] <> nil then
4485 if gPlayers
[I
].alive
then
4486 if gPlayers
[I
].UID
<> FUID
then
4488 FSpectatePlayer
:= I
;
4493 if not SetSpect
then FSpectatePlayer
:= -1;
4504 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
4506 FYTo
:= FObj
.Y
- 32;
4507 FSpectatePlayer
:= -1;
4509 if FKeys
[KEY_DOWN
].Pressed
then
4511 FYTo
:= FObj
.Y
+ 32;
4512 FSpectatePlayer
:= -1;
4514 if FKeys
[KEY_LEFT
].Pressed
then
4516 FXTo
:= FObj
.X
- 32;
4517 FSpectatePlayer
:= -1;
4519 if FKeys
[KEY_RIGHT
].Pressed
then
4521 FXTo
:= FObj
.X
+ 32;
4522 FSpectatePlayer
:= -1;
4525 if (FXTo
< -64) then
4527 else if (FXTo
> gMapInfo
.Width
+ 32) then
4528 FXTo
:= gMapInfo
.Width
+ 32;
4529 if (FYTo
< -72) then
4531 else if (FYTo
> gMapInfo
.Height
+ 32) then
4532 FYTo
:= gMapInfo
.Height
+ 32;
4537 g_Obj_Move(@FObj
, True, True, True);
4538 positionChanged(); // this updates spatial accelerators
4545 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
4546 if gPlayers
[FSpectatePlayer
] <> nil then
4547 if gPlayers
[FSpectatePlayer
].alive
then
4549 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
4550 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
4554 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
4555 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
4556 PANEL_BLOCKMON
, True);
4557 headwater
:= HeadInLiquid(0, 0);
4559 // Сопротивление воздуха:
4560 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
4561 if FObj
.Vel
.X
<> 0 then
4562 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
4564 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
4565 DecMin(FPain
, 5, 0);
4566 DecMin(FPickup
, 1, 0);
4568 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
4570 // Обнулить действия примочек, чтобы фон пропал
4571 FMegaRulez
[MR_SUIT
] := 0;
4572 FMegaRulez
[MR_INVUL
] := 0;
4573 FMegaRulez
[MR_INVIS
] := 0;
4574 Kill(K_FALLKILL
, 0, HIT_FALL
);
4581 if FCurrWeap
= WEAPON_SAW
then
4582 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
4583 FSawSoundSelect
.IsPlaying()) then
4584 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
4587 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
4588 (not FJetSoundOff
.IsPlaying()) then
4590 FJetSoundFly
.SetPosition(0);
4591 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
4594 for b
:= WP_FIRST
to WP_LAST
do
4595 if FReloading
[b
] > 0 then
4601 if FShellTimer
> -1 then
4602 if FShellTimer
= 0 then
4604 if FShellType
= SHELL_SHELL
then
4605 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4606 GameVelX
, GameVelY
-2, SHELL_SHELL
)
4607 else if FShellType
= SHELL_DBLSHELL
then
4609 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4610 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
4611 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4612 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
4615 end else Dec(FShellTimer
);
4617 if (FBFGFireCounter
> -1) then
4618 if FBFGFireCounter
= 0 then
4622 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
4623 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
4624 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
4625 yd
:= wy
+firediry();
4626 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
4627 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
4628 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
4629 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
4630 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
4633 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
4634 FBFGFireCounter
:= -1;
4637 FBFGFireCounter
:= 0
4639 Dec(FBFGFireCounter
);
4641 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
4643 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
4645 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
4648 if (headwater
or blockmon
) then
4654 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
4657 else if (FAir
mod 31 = 0) and not blockmon
then
4659 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
4661 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
4662 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
4664 end else if FAir
< AIR_DEF
then
4667 if FFireTime
> 0 then
4669 if BodyInLiquid(0, 0) then
4674 else if FMegaRulez
[MR_SUIT
] >= gTime
then
4676 if FMegaRulez
[MR_SUIT
] = gTime
then
4683 if FFirePainTime
<= 0 then
4685 if g_Game_IsServer
then
4686 Damage(2, FFireAttacker
, 0, 0, HIT_FLAME
);
4687 FFirePainTime
:= 12 - FFireTime
div 12;
4689 FFirePainTime
:= FFirePainTime
- 1;
4690 FFireTime
:= FFireTime
- 1;
4691 if ((FFireTime
mod 33) = 0) and (FMegaRulez
[MR_INVUL
] < gTime
) then
4692 FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
);
4693 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
4694 MH_SEND_PlayerStats(FUID
);
4698 if FDamageBuffer
> 0 then
4700 if FDamageBuffer
>= 9 then
4704 if FDamageBuffer
< 30 then i
:= 9
4705 else if FDamageBuffer
< 100 then i
:= 18
4709 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
4710 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
4711 FHealth
:= FHealth
-ii
;
4714 FHealth
:= FHealth
+FArmor
;
4719 if FHealth
<= 0 then
4720 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
4721 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
4722 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
4724 if FAlive
and ((FLastHit
<> HIT_FLAME
) or (FFireTime
<= 0)) then
4726 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
4727 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
4728 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
4729 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
4736 end; // if FAlive then ...
4738 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
4740 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
4741 FModel
.AnimState
.MinLength
:= i
;
4742 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
4744 if (FModel
.AnimState
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
4745 then SetAction(A_STAND
, True);
4747 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.GetFire()) then FModel
.Update
;
4749 for b
:= Low(FKeys
) to High(FKeys
) do
4750 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
4754 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
4756 x
:= FObj
.X
+PLAYER_RECT
.X
;
4757 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
4758 w
:= PLAYER_RECT
.Width
;
4759 h
:= PLAYER_RECT
.Height
;
4763 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
4765 if (dx
<> 0) or (dy
<> 0) then
4774 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
4776 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
4777 FObj
.Y
+PLAYER_RECT
.Y
,
4784 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
4786 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
4787 FObj
.Y
+PLAYER_RECT
.Y
,
4791 Panel
.Width
, Panel
.Height
);
4794 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
4796 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
4797 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
4798 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
4799 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
4802 function g_Player_ValidName(Name
: string): Boolean;
4808 if gPlayers
= nil then Exit
;
4810 for a
:= 0 to High(gPlayers
) do
4811 if gPlayers
[a
] <> nil then
4812 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
4819 procedure TPlayer
.SetDirection(Direction
: TDirection
);
4823 d
:= FModel
.Direction
;
4825 FModel
.Direction
:= Direction
;
4826 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
4828 FDirection
:= Direction
;
4831 function TPlayer
.GetKeys(): Byte;
4835 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
4836 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
4837 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
4839 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
4840 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
4843 procedure TPlayer
.Use();
4847 if FTime
[T_USE
] > gTime
then Exit
;
4849 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
4850 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
4852 for a
:= 0 to High(gPlayers
) do
4853 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
4854 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
4855 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
4856 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
4858 gPlayers
[a
].Touch();
4859 if g_Game_IsNet
and g_Game_IsServer
then
4860 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
4863 FTime
[T_USE
] := gTime
+120;
4866 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
4869 visible
: Boolean = True;
4870 WX
, WY
, XD
, YD
: Integer;
4882 if R_BERSERK
in FRulez
then
4884 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
4885 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
4886 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
4889 locobj
.rect
.Width
:= 39;
4890 locobj
.rect
.Height
:= 52;
4891 locobj
.Vel
.X
:= (xd
-wx
) div 2;
4892 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
4893 locobj
.Accel
.X
:= xd
-wx
;
4894 locobj
.Accel
.y
:= yd
-wy
;
4896 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
4897 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
4899 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
4903 FPain
:= min(FPain
+ 25, 50);
4905 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
4910 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
4911 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
4913 FSawSoundSelect
.Stop();
4915 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
4917 else if not FSawSoundHit
.IsPlaying() then
4919 FSawSoundSelect
.Stop();
4920 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
4926 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
4927 FFireAngle
:= FAngle
;
4928 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4929 GameVelX
, GameVelY
-2, SHELL_BULLET
);
4934 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
4935 FFireAngle
:= FAngle
;
4937 FShellType
:= SHELL_SHELL
;
4942 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
4943 FFireAngle
:= FAngle
;
4945 FShellType
:= SHELL_DBLSHELL
;
4950 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
4951 FFireAngle
:= FAngle
;
4952 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4953 GameVelX
, GameVelY
-2, SHELL_BULLET
);
4956 WEAPON_ROCKETLAUNCHER
:
4958 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
4959 FFireAngle
:= FAngle
;
4964 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
4965 FFireAngle
:= FAngle
;
4970 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
4971 FFireAngle
:= FAngle
;
4974 WEAPON_SUPERPULEMET
:
4976 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
4977 FFireAngle
:= FAngle
;
4978 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4979 GameVelX
, GameVelY
-2, SHELL_SHELL
);
4982 WEAPON_FLAMETHROWER
:
4984 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
4986 FFireAngle
:= FAngle
;
4990 if not visible
then Exit
;
4992 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
4993 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
4994 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
4997 procedure TPlayer
.DoLerp(Level
: Integer = 2);
4999 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5000 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5003 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5009 if FJustTeleported
or (NetInterpLevel
< 1) then
5013 if FJustTeleported
then
5015 FObj
.oldX
:= FObj
.X
;
5016 FObj
.oldY
:= FObj
.Y
;
5021 AX
:= Abs(FXTo
- FObj
.X
);
5022 AY
:= Abs(FYTo
- FObj
.Y
);
5023 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5025 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5030 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5032 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5033 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5034 PANEL_LIFTUP
, False) then Result
:= -1
5036 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5037 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5038 PANEL_LIFTDOWN
, False) then Result
:= 1
5042 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5049 if Flag
= FLAG_NONE
then
5052 if not g_Game_IsServer
then Exit
;
5054 // Принес чужой флаг на свою базу:
5055 if (Flag
= FTeam
) and
5056 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5057 (FFlag
<> FLAG_NONE
) then
5059 if FFlag
= FLAG_RED
then
5060 s
:= _lc
[I_PLAYER_FLAG_RED
]
5062 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5064 evtype
:= FLAG_STATE_SCORED
;
5066 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5067 Insert('.', ts
, Length(ts
) + 1 - 3);
5068 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5070 g_Map_ResetFlag(FFlag
);
5071 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5073 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5074 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5075 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5080 if not sound_cap_flag
[a
].IsPlaying() then
5081 sound_cap_flag
[a
].Play();
5083 gTeamStat
[FTeam
].Score
+= 1;
5086 if g_Game_IsNet
then
5088 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5092 gFlags
[FFlag
].CaptureTime
:= 0;
5097 // Подобрал свой флаг - вернул его на базу:
5098 if (Flag
= FTeam
) and
5099 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5101 if Flag
= FLAG_RED
then
5102 s
:= _lc
[I_PLAYER_FLAG_RED
]
5104 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5106 evtype
:= FLAG_STATE_RETURNED
;
5107 gFlags
[Flag
].CaptureTime
:= 0;
5109 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5111 g_Map_ResetFlag(Flag
);
5112 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5114 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5115 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5116 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5121 if not sound_ret_flag
[a
].IsPlaying() then
5122 sound_ret_flag
[a
].Play();
5125 if g_Game_IsNet
then
5127 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5133 // Подобрал чужой флаг:
5134 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5138 if Flag
= FLAG_RED
then
5139 s
:= _lc
[I_PLAYER_FLAG_RED
]
5141 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5143 evtype
:= FLAG_STATE_CAPTURED
;
5145 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5147 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5149 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5151 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5152 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5153 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5158 if not sound_get_flag
[a
].IsPlaying() then
5159 sound_get_flag
[a
].Play();
5162 if g_Game_IsNet
then
5164 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5170 procedure TPlayer
.SetFlag(Flag
: Byte);
5173 if FModel
<> nil then
5174 FModel
.SetFlag(FFlag
);
5177 function TPlayer
.TryDropFlag(): Boolean;
5179 if LongBool(gGameSettings
.Options
and GAME_OPTION_ALLOWDROPFLAG
) then
5180 Result
:= DropFlag(False, LongBool(gGameSettings
.Options
and GAME_OPTION_THROWFLAG
))
5185 function TPlayer
.DropFlag(Silent
: Boolean = True; DoThrow
: Boolean = False): Boolean;
5192 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5194 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5195 with gFlags
[FFlag
] do
5199 Direction
:= FDirection
;
5200 State
:= FLAG_STATE_DROPPED
;
5204 xv
:= FObj
.Vel
.X
+ IfThen(Direction
= TDirection
.D_RIGHT
, 10, -10);
5205 yv
:= FObj
.Vel
.Y
- 2;
5209 xv
:= (FObj
.Vel
.X
div 2);
5210 yv
:= (FObj
.Vel
.Y
div 2) - 2;
5212 g_Obj_Push(@Obj
, xv
, yv
);
5214 positionChanged(); // this updates spatial accelerators
5216 if FFlag
= FLAG_RED
then
5217 s
:= _lc
[I_PLAYER_FLAG_RED
]
5219 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5221 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5222 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5224 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5225 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5226 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5231 if (not Silent
) and (not sound_lost_flag
[a
].IsPlaying()) then
5232 sound_lost_flag
[a
].Play();
5234 if g_Game_IsNet
then
5235 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5241 procedure TPlayer
.GetSecret();
5243 if (self
= gPlayer1
) or (self
= gPlayer2
) then
5245 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [FName
]), True);
5246 g_Sound_PlayEx('SOUND_GAME_SECRET');
5251 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5253 Assert(Key
<= High(FKeys
));
5255 FKeys
[Key
].Pressed
:= True;
5256 FKeys
[Key
].Time
:= Time
;
5259 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5261 Result
:= FKeys
[K
].Pressed
;
5264 procedure TPlayer
.ReleaseKeys();
5268 for a
:= Low(FKeys
) to High(FKeys
) do
5270 FKeys
[a
].Pressed
:= False;
5275 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5279 function TPlayer
.firediry(): Integer;
5281 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5282 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5286 procedure TPlayer
.RememberState();
5289 SavedState
: TPlayerSavedState
;
5291 SavedState
.Health
:= FHealth
;
5292 SavedState
.Armor
:= FArmor
;
5293 SavedState
.Air
:= FAir
;
5294 SavedState
.JetFuel
:= FJetFuel
;
5295 SavedState
.CurrWeap
:= FCurrWeap
;
5296 SavedState
.NextWeap
:= FNextWeap
;
5297 SavedState
.NextWeapDelay
:= FNextWeapDelay
;
5298 for i
:= Low(FWeapon
) to High(FWeapon
) do
5299 SavedState
.Weapon
[i
] := FWeapon
[i
];
5300 for i
:= Low(FAmmo
) to High(FAmmo
) do
5301 SavedState
.Ammo
[i
] := FAmmo
[i
];
5302 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
5303 SavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5304 SavedState
.Rulez
:= FRulez
- [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5306 FSavedStateNum
:= -1;
5307 for i
:= Low(SavedStates
) to High(SavedStates
) do
5308 if not SavedStates
[i
].Used
then
5310 FSavedStateNum
:= i
;
5313 if FSavedStateNum
< 0 then
5315 SetLength(SavedStates
, Length(SavedStates
) + 1);
5316 FSavedStateNum
:= High(SavedStates
);
5319 SavedState
.Used
:= True;
5320 SavedStates
[FSavedStateNum
] := SavedState
;
5323 procedure TPlayer
.RecallState();
5326 SavedState
: TPlayerSavedState
;
5328 if(FSavedStateNum
< 0) or (FSavedStateNum
> High(SavedStates
)) then
5331 SavedState
:= SavedStates
[FSavedStateNum
];
5332 SavedStates
[FSavedStateNum
].Used
:= False;
5333 FSavedStateNum
:= -1;
5335 FHealth
:= SavedState
.Health
;
5336 FArmor
:= SavedState
.Armor
;
5337 FAir
:= SavedState
.Air
;
5338 FJetFuel
:= SavedState
.JetFuel
;
5339 FCurrWeap
:= SavedState
.CurrWeap
;
5340 FNextWeap
:= SavedState
.NextWeap
;
5341 FNextWeapDelay
:= SavedState
.NextWeapDelay
;
5342 for i
:= Low(FWeapon
) to High(FWeapon
) do
5343 FWeapon
[i
] := SavedState
.Weapon
[i
];
5344 for i
:= Low(FAmmo
) to High(FAmmo
) do
5345 FAmmo
[i
] := SavedState
.Ammo
[i
];
5346 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
5347 FMaxAmmo
[i
] := SavedState
.MaxAmmo
[i
];
5348 FRulez
:= SavedState
.Rulez
;
5350 if gGameSettings
.GameType
= GT_SERVER
then
5351 MH_SEND_PlayerStats(FUID
);
5354 procedure TPlayer
.SaveState (st
: TStream
);
5360 utils
.writeSign(st
, 'PLYR');
5361 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
5363 utils
.writeBool(st
, FIamBot
);
5365 utils
.writeInt(st
, Word(FUID
));
5367 utils
.writeStr(st
, FName
);
5369 utils
.writeInt(st
, Byte(FTeam
));
5371 utils
.writeBool(st
, FAlive
);
5372 // Израсходовал ли все жизни
5373 utils
.writeBool(st
, FNoRespawn
);
5375 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
5376 utils
.writeInt(st
, Byte(b
));
5378 utils
.writeInt(st
, LongInt(FHealth
));
5379 // Коэффициент инвалидности
5380 utils
.writeInt(st
, LongInt(FHandicap
));
5382 utils
.writeInt(st
, Byte(FLives
));
5384 utils
.writeInt(st
, LongInt(FArmor
));
5386 utils
.writeInt(st
, LongInt(FAir
));
5388 utils
.writeInt(st
, LongInt(FJetFuel
));
5390 utils
.writeInt(st
, LongInt(FPain
));
5392 utils
.writeInt(st
, LongInt(FKills
));
5394 utils
.writeInt(st
, LongInt(FMonsterKills
));
5396 utils
.writeInt(st
, LongInt(FFrags
));
5398 utils
.writeInt(st
, Byte(FFragCombo
));
5399 // Время последнего фрага
5400 utils
.writeInt(st
, LongWord(FLastFrag
));
5402 utils
.writeInt(st
, LongInt(FDeath
));
5404 utils
.writeInt(st
, Byte(FFlag
));
5406 utils
.writeInt(st
, LongInt(FSecrets
));
5408 utils
.writeInt(st
, Byte(FCurrWeap
));
5410 utils
.writeInt(st
, Word(FNextWeap
));
5412 utils
.writeInt(st
, Byte(FNextWeapDelay
));
5413 // Время зарядки BFG
5414 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
5416 utils
.writeInt(st
, LongInt(FDamageBuffer
));
5417 // Последний ударивший
5418 utils
.writeInt(st
, Word(FLastSpawnerUID
));
5419 // Тип последнего полученного урона
5420 utils
.writeInt(st
, Byte(FLastHit
));
5422 Obj_SaveState(st
, @FObj
);
5423 // Текущее количество патронов
5424 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
5425 // Максимальное количество патронов
5426 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
5428 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
5429 // Время перезарядки оружия
5430 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
5432 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
5433 // Наличие красного ключа
5434 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
5435 // Наличие зеленого ключа
5436 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
5437 // Наличие синего ключа
5438 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
5440 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
5441 // Время действия специальных предметов
5442 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
5443 // Время до повторного респауна, смены оружия, исользования, захвата флага
5444 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
5446 utils
.writeStr(st
, FModel
.GetName());
5448 utils
.writeInt(st
, Byte(FColor
.R
));
5449 utils
.writeInt(st
, Byte(FColor
.G
));
5450 utils
.writeInt(st
, Byte(FColor
.B
));
5454 procedure TPlayer
.LoadState (st
: TStream
);
5463 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
5464 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
5466 FIamBot
:= utils
.readBool(st
);
5468 FUID
:= utils
.readWord(st
);
5470 str
:= utils
.readStr(st
);
5471 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
5473 FTeam
:= utils
.readByte(st
);
5475 FAlive
:= utils
.readBool(st
);
5476 // Израсходовал ли все жизни
5477 FNoRespawn
:= utils
.readBool(st
);
5479 b
:= utils
.readByte(st
);
5480 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
5482 FHealth
:= utils
.readLongInt(st
);
5483 // Коэффициент инвалидности
5484 FHandicap
:= utils
.readLongInt(st
);
5486 FLives
:= utils
.readByte(st
);
5488 FArmor
:= utils
.readLongInt(st
);
5490 FAir
:= utils
.readLongInt(st
);
5492 FJetFuel
:= utils
.readLongInt(st
);
5494 FPain
:= utils
.readLongInt(st
);
5496 FKills
:= utils
.readLongInt(st
);
5498 FMonsterKills
:= utils
.readLongInt(st
);
5500 FFrags
:= utils
.readLongInt(st
);
5502 FFragCombo
:= utils
.readByte(st
);
5503 // Время последнего фрага
5504 FLastFrag
:= utils
.readLongWord(st
);
5506 FDeath
:= utils
.readLongInt(st
);
5508 FFlag
:= utils
.readByte(st
);
5510 FSecrets
:= utils
.readLongInt(st
);
5512 FCurrWeap
:= utils
.readByte(st
);
5514 FNextWeap
:= utils
.readWord(st
);
5516 FNextWeapDelay
:= utils
.readByte(st
);
5517 // Время зарядки BFG
5518 FBFGFireCounter
:= utils
.readSmallInt(st
);
5520 FDamageBuffer
:= utils
.readLongInt(st
);
5521 // Последний ударивший
5522 FLastSpawnerUID
:= utils
.readWord(st
);
5523 // Тип последнего полученного урона
5524 FLastHit
:= utils
.readByte(st
);
5526 Obj_LoadState(@FObj
, st
);
5527 // Текущее количество патронов
5528 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
5529 // Максимальное количество патронов
5530 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
5532 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
5533 // Время перезарядки оружия
5534 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
5536 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
5537 // Наличие красного ключа
5538 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
5539 // Наличие зеленого ключа
5540 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
5541 // Наличие синего ключа
5542 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
5544 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
5545 // Время действия специальных предметов
5546 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
5547 // Время до повторного респауна, смены оружия, исользования, захвата флага
5548 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
5550 str
:= utils
.readStr(st
);
5552 FColor
.R
:= utils
.readByte(st
);
5553 FColor
.G
:= utils
.readByte(st
);
5554 FColor
.B
:= utils
.readByte(st
);
5555 if (self
= gPlayer1
) then
5557 str
:= gPlayer1Settings
.Model
;
5558 FColor
:= gPlayer1Settings
.Color
;
5560 else if (self
= gPlayer2
) then
5562 str
:= gPlayer2Settings
.Model
;
5563 FColor
:= gPlayer2Settings
.Color
;
5565 // Обновляем модель игрока
5567 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
5568 FModel
.Color
:= TEAMCOLOR
[FTeam
]
5570 FModel
.Color
:= FColor
;
5574 procedure TPlayer
.AllRulez(Health
: Boolean);
5580 FHealth
:= PLAYER_HP_LIMIT
;
5581 FArmor
:= PLAYER_AP_LIMIT
;
5585 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
5586 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
5587 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5590 procedure TPlayer
.RestoreHealthArmor();
5592 FHealth
:= PLAYER_HP_LIMIT
;
5593 FArmor
:= PLAYER_AP_LIMIT
;
5596 procedure TPlayer
.FragCombo();
5600 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
5602 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
5604 if FFragCombo
< 5 then
5606 Param
:= FUID
or (FFragCombo
shl 16);
5607 if (FComboEvnt
>= Low(gDelayedEvents
)) and
5608 (FComboEvnt
<= High(gDelayedEvents
)) and
5609 gDelayedEvents
[FComboEvnt
].Pending
and
5610 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
5611 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
5613 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
5614 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
5617 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
5625 procedure TPlayer
.GiveItem(ItemType
: Byte);
5629 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
5631 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
5635 if FAir
< AIR_MAX
then
5642 if not (R_BERSERK
in FRulez
) then
5644 Include(FRulez
, R_BERSERK
);
5645 if FBFGFireCounter
< 1 then
5647 FCurrWeap
:= WEAPON_KASTET
;
5649 FModel
.SetWeapon(WEAPON_KASTET
);
5653 FBerserk
:= gTime
+30000;
5655 if FHealth
< PLAYER_HP_SOFT
then
5657 FHealth
:= PLAYER_HP_SOFT
;
5658 FBerserk
:= gTime
+30000;
5663 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
5665 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
5670 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
5672 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
5676 if FJetFuel
< JET_MAX
then
5678 FJetFuel
:= JET_MAX
;
5681 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
5682 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
5684 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
5685 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5687 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
5689 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
5691 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
5692 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5695 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
5696 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
5697 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
5698 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
5699 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
5700 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
5701 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
5702 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
5703 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
5705 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5706 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
5707 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5708 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
5709 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5710 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
5711 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5712 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
5713 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
5716 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
5717 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
5718 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
5719 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
5720 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
5722 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
5723 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
5724 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
5725 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
5726 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
5728 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5729 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5730 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5731 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5733 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
5736 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
5737 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
5738 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
5740 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
5741 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
5746 if g_Game_IsNet
and g_Game_IsServer
then
5747 MH_SEND_PlayerStats(FUID
);
5750 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
5753 if (Random(5) = 1) and (Times
= 1) then
5756 if BodyInLiquid(0, 0) then
5758 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
5759 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
5761 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5762 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5766 for i
:= 1 to Times
do
5770 Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(R_GFX_SMOKE_WIDTH
div 2),
5771 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2)
5776 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
5779 if (Random(10) = 1) and (Times
= 1) then
5782 for i
:= 1 to Times
do
5786 Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(R_GFX_FLAME_WIDTH
div 2),
5787 Obj
.Y
+8+Random(8+Times
*2)
5792 procedure TPlayer
.PauseSounds(Enable
: Boolean);
5794 FSawSound
.Pause(Enable
);
5795 FSawSoundIdle
.Pause(Enable
);
5796 FSawSoundHit
.Pause(Enable
);
5797 FSawSoundSelect
.Pause(Enable
);
5798 FFlameSoundOn
.Pause(Enable
);
5799 FFlameSoundOff
.Pause(Enable
);
5800 FFlameSoundWork
.Pause(Enable
);
5801 FJetSoundFly
.Pause(Enable
);
5802 FJetSoundOn
.Pause(Enable
);
5803 FJetSoundOff
.Pause(Enable
);
5808 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
5813 FObj
.Rect
:= PLAYER_CORPSERECT
;
5814 FModelName
:= ModelName
;
5819 FState
:= CORPSE_STATE_MESS
;
5820 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
5824 FState
:= CORPSE_STATE_NORMAL
;
5825 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
5829 destructor TCorpse
.Destroy();
5836 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
5838 procedure TCorpse
.positionChanged (); inline; begin end;
5840 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
5842 if (dx
<> 0) or (dy
<> 0) then
5851 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5853 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
5854 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
5855 w
:= PLAYER_CORPSERECT
.Width
;
5856 h
:= PLAYER_CORPSERECT
.Height
;
5860 procedure TCorpse
.Damage(Value
: Word; SpawnerUID
: Word; vx
, vy
: Integer);
5865 if FState
= CORPSE_STATE_REMOVEME
then
5868 FDamage
:= FDamage
+ Value
;
5870 if FDamage
> 150 then
5872 if FAnimation
<> nil then
5877 FState
:= CORPSE_STATE_REMOVEME
;
5879 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
5880 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
5881 FModelName
, FColor
);
5882 // Звук мяса от трупа:
5883 pm
:= g_PlayerModel_Get(FModelName
);
5884 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
5888 if (gBodyKillEvent
<> -1)
5889 and gDelayedEvents
[gBodyKillEvent
].Pending
then
5890 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
5891 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, SpawnerUID
);
5896 Blood
:= g_PlayerModel_GetBlood(FModelName
);
5897 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
5898 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
5899 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
5900 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
5901 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
5902 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
5906 procedure TCorpse
.Update();
5910 if FState
= CORPSE_STATE_REMOVEME
then
5913 FObj
.oldX
:= FObj
.X
;
5914 FObj
.oldY
:= FObj
.Y
;
5916 if gTime
mod (GAME_TICK
*2) <> 0 then
5918 g_Obj_Move(@FObj
, True, True, True);
5919 positionChanged(); // this updates spatial accelerators
5923 // Сопротивление воздуха для трупа:
5924 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5926 st
:= g_Obj_Move(@FObj
, True, True, True);
5927 positionChanged(); // this updates spatial accelerators
5929 if WordBool(st
and MOVE_FALLOUT
) then
5931 FState
:= CORPSE_STATE_REMOVEME
;
5935 if FAnimation
<> nil then
5936 FAnimation
.Update();
5937 if FAnimationMask
<> nil then
5938 FAnimationMask
.Update();
5942 procedure TCorpse
.SaveState (st
: TStream
);
5949 utils
.writeSign(st
, 'CORP');
5950 utils
.writeInt(st
, Byte(0));
5952 utils
.writeInt(st
, Byte(FState
));
5954 utils
.writeInt(st
, Byte(FDamage
));
5956 utils
.writeInt(st
, Byte(FColor
.R
));
5957 utils
.writeInt(st
, Byte(FColor
.G
));
5958 utils
.writeInt(st
, Byte(FColor
.B
));
5960 Obj_SaveState(st
, @FObj
);
5961 utils
.writeInt(st
, Word(FPlayerUID
));
5963 anim
:= (FAnimation
<> nil);
5964 utils
.writeBool(st
, anim
);
5965 // Если есть - сохраняем
5966 if anim
then FAnimation
.SaveState(st
);
5967 // Есть ли маска анимации
5968 anim
:= (FAnimationMask
<> nil);
5969 utils
.writeBool(st
, anim
);
5970 // Если есть - сохраняем
5971 if anim
then FAnimationMask
.SaveState(st
);
5975 procedure TCorpse
.LoadState (st
: TStream
);
5982 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
5983 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
5985 FState
:= utils
.readByte(st
);
5987 FDamage
:= utils
.readByte(st
);
5989 FColor
.R
:= utils
.readByte(st
);
5990 FColor
.G
:= utils
.readByte(st
);
5991 FColor
.B
:= utils
.readByte(st
);
5993 Obj_LoadState(@FObj
, st
);
5994 FPlayerUID
:= utils
.readWord(st
);
5996 anim
:= utils
.readBool(st
);
5997 // Если есть - загружаем
6000 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6001 FAnimation
.LoadState(st
);
6003 // Есть ли маска анимации
6004 anim
:= utils
.readBool(st
);
6005 // Если есть - загружаем
6008 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6009 FAnimationMask
.LoadState(st
);
6015 constructor TBot
.Create();
6022 FSpectator
:= False;
6029 for a
:= WP_FIRST
to WP_LAST
do
6031 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6032 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6033 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6037 destructor TBot
.Destroy();
6040 inherited Destroy();
6043 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6045 inherited Respawn(Silent
, Force
);
6048 FSelectedWeapon
:= FCurrWeap
;
6053 procedure TBot
.UpdateCombat();
6066 TTargetRecord
= array of TTarget
;
6068 function Compare(a
, b
: TTarget
): Integer;
6070 if a
.Line
and not b
.Line
then // A на линии огня
6073 if not a
.Line
and b
.Line
then // B на линии огня
6075 else // И A, и B на линии или не на линии огня
6076 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6078 if a
.Dist
> b
.Dist
then // B ближе
6080 else // A ближе или равноудаленно с B
6083 else // Странно -> A
6088 a
, x1
, y1
, x2
, y2
: Integer;
6089 targets
: TTargetRecord
;
6091 Target
, BestTarget
: TTarget
;
6092 firew
, fireh
: Integer;
6096 vsPlayer
, vsMonster
, ok
: Boolean;
6099 function monsUpdate (mon
: TMonster
): Boolean;
6101 result
:= false; // don't stop
6102 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6104 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6106 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6107 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6109 // Если монстр на экране и не прикрыт стеной
6110 if g_TraceVector(x1
, y1
, x2
, y2
) then
6112 // Добавляем к списку возможных целей
6113 SetLength(targets
, Length(targets
)+1);
6114 with targets
[High(targets
)] do
6121 Rect
:= mon
.Obj
.Rect
;
6122 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6123 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6124 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6133 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6134 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6136 // Если текущее оружие не то, что нужно, то меняем:
6137 if FCurrWeap
<> FSelectedWeapon
then
6140 // Если нужно стрелять и нужное оружие, то нажать "Стрелять":
6141 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6143 RemoveAIFlag('NEEDFIRE');
6146 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6147 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6148 else PressKey(KEY_FIRE
);
6152 // Координаты ствола:
6153 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6154 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6156 Target
.UID
:= FTargetUID
;
6159 if Target
.UID
<> 0 then
6160 begin // Цель есть - настраиваем
6161 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6164 tpla
:= g_Player_Get(Target
.UID
);
6168 if (@FObj
) <> nil then
6175 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6176 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6177 Target
.Rect
:= PLAYER_RECT
;
6178 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6179 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6180 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6181 Target
.IsPlayer
:= True;
6185 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6188 mon
:= g_Monsters_ByUID(Target
.UID
);
6191 Target
.X
:= mon
.Obj
.X
;
6192 Target
.Y
:= mon
.Obj
.Y
;
6194 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6195 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6196 Target
.Rect
:= mon
.Obj
.Rect
;
6197 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6198 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6199 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6200 Target
.IsPlayer
:= False;
6207 begin // Цели нет - обнуляем
6212 Target
.Visible
:= False;
6213 Target
.Line
:= False;
6214 Target
.IsPlayer
:= False;
6219 // Если цель не видима или не на линии огня, то ищем все возможные цели:
6220 if (not Target
.Line
) or (not Target
.Visible
) then
6224 for a
:= 0 to High(gPlayers
) do
6225 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6226 (gPlayers
[a
].FUID
<> FUID
) and
6227 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6228 (not gPlayers
[a
].NoTarget
) and
6229 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6231 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6232 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6235 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6236 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6238 // Если игрок на экране и не прикрыт стеной:
6239 if g_TraceVector(x1
, y1
, x2
, y2
) then
6241 // Добавляем к списку возможных целей:
6242 SetLength(targets
, Length(targets
)+1);
6243 with targets
[High(targets
)] do
6245 UID
:= gPlayers
[a
].FUID
;
6246 X
:= gPlayers
[a
].FObj
.X
;
6247 Y
:= gPlayers
[a
].FObj
.Y
;
6250 Rect
:= PLAYER_RECT
;
6251 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6252 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6253 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6261 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6264 // Если есть возможные цели:
6265 // (Выбираем лучшую, меняем оружие и бежим к ней/от нее)
6266 if targets
<> nil then
6268 // Выбираем наилучшую цель:
6269 BestTarget
:= targets
[0];
6270 if Length(targets
) > 1 then
6271 for a
:= 1 to High(targets
) do
6272 if Compare(BestTarget
, targets
[a
]) = 1 then
6273 BestTarget
:= targets
[a
];
6275 // Если лучшая цель "виднее" текущей, то текущая := лучшая:
6276 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6277 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6279 Target
:= BestTarget
;
6281 if (Healthy() = 3) or ((Healthy() = 2)) then
6282 begin // Если здоровы - догоняем
6283 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6284 SetAIFlag('GORIGHT', '1');
6285 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6286 SetAIFlag('GOLEFT', '1');
6289 begin // Если побиты - убегаем
6290 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6291 SetAIFlag('GORIGHT', '1');
6292 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6293 SetAIFlag('GOLEFT', '1');
6296 // Выбираем оружие на основе расстояния и приоритетов:
6297 SelectWeapon(Abs(x1
-Target
.cX
));
6302 // (Догоняем/убегаем, стреляем по направлению к цели)
6303 // (Если цель далеко, то хватит следить за ней)
6304 if Target
.UID
<> 0 then
6306 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6307 Target
.Y
+ Target
.Rect
.Y
) then
6308 begin // Цель сбежала с "экрана"
6309 if (Healthy() = 3) or ((Healthy() = 2)) then
6310 begin // Если здоровы - догоняем
6311 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6312 SetAIFlag('GORIGHT', '1');
6313 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6314 SetAIFlag('GOLEFT', '1');
6317 begin // Если побиты - забываем о цели и убегаем
6319 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6320 SetAIFlag('GORIGHT', '1');
6321 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6322 SetAIFlag('GOLEFT', '1');
6326 begin // Цель пока на "экране"
6327 // Если цель не загорожена стеной, то отмечаем, когда ее видели:
6328 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6329 FLastVisible
:= gTime
;
6330 // Если разница высот не велика, то догоняем:
6331 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6333 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6334 SetAIFlag('GORIGHT', '1');
6335 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6336 SetAIFlag('GOLEFT', '1');
6340 // Выбираем угол вверх:
6341 if FDirection
= TDirection
.D_LEFT
then
6342 angle
:= ANGLE_LEFTUP
6344 angle
:= ANGLE_RIGHTUP
;
6346 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6347 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6349 // Если при угле вверх можно попасть в приблизительное положение цели:
6350 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6351 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6352 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6353 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6354 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6355 begin // то нужно стрелять вверх
6356 SetAIFlag('NEEDFIRE', '1');
6357 SetAIFlag('NEEDSEEUP', '1');
6360 // Выбираем угол вниз:
6361 if FDirection
= TDirection
.D_LEFT
then
6362 angle
:= ANGLE_LEFTDOWN
6364 angle
:= ANGLE_RIGHTDOWN
;
6366 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6367 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6369 // Если при угле вниз можно попасть в приблизительное положение цели:
6370 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6371 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6372 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6373 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6374 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6375 begin // то нужно стрелять вниз
6376 SetAIFlag('NEEDFIRE', '1');
6377 SetAIFlag('NEEDSEEDOWN', '1');
6380 // Если цель видно и она на такой же высоте:
6381 if Target
.Visible
and
6382 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6383 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6385 // Если идем в сторону цели, то надо стрелять:
6386 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
6387 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6388 begin // то нужно стрелять вперед
6389 SetAIFlag('NEEDFIRE', '1');
6390 SetAIFlag('NEEDSEEDOWN', '');
6391 SetAIFlag('NEEDSEEUP', '');
6393 // Если цель в пределах "экрана" и сложность позволяет прыжки сближения:
6394 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6395 if GetRnd(FDifficult
.CloseJump
) then
6396 begin // то если повезет - прыгаем (особенно, если близко)
6397 if Abs(FObj
.X
-Target
.X
) < 128 then
6401 if Random(a
) = 0 then
6402 SetAIFlag('NEEDJUMP', '1');
6406 // Если цель все еще есть:
6407 if Target
.UID
<> 0 then
6408 if gTime
-FLastVisible
> 2000 then // Если видели давно
6409 Target
.UID
:= 0 // то забыть цель
6410 else // Если видели недавно
6411 begin // но цель убили
6412 if Target
.IsPlayer
then
6413 begin // Цель - игрок
6414 pla
:= g_Player_Get(Target
.UID
);
6415 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
6416 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6417 Target
.UID
:= 0; // то забыть цель
6420 begin // Цель - монстр
6421 mon
:= g_Monsters_ByUID(Target
.UID
);
6422 if (mon
= nil) or (not mon
.alive
) then
6423 Target
.UID
:= 0; // то забыть цель
6426 end; // if Target.UID <> 0
6428 FTargetUID
:= Target
.UID
;
6430 // Если возможных целей нет:
6431 // (Атака чего-нибудь слева или справа)
6432 if targets
= nil then
6433 if GetAIFlag('ATTACKLEFT') <> '' then
6434 begin // Если нужно атаковать налево
6435 RemoveAIFlag('ATTACKLEFT');
6437 SetAIFlag('NEEDJUMP', '1');
6439 if RunDirection() = TDirection
.D_RIGHT
then
6440 begin // Идем не в ту сторону
6441 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6442 begin // Если здоровы, то, возможно, стреляем бежим влево и стреляем
6443 SetAIFlag('NEEDFIRE', '1');
6444 SetAIFlag('GOLEFT', '1');
6448 begin // Идем в нужную сторону
6449 if GetRnd(FDifficult
.InvisFire
) then // Возможно, стреляем вслепую
6450 SetAIFlag('NEEDFIRE', '1');
6451 if Healthy() <= 1 then // Побиты - убегаем
6452 SetAIFlag('GORIGHT', '1');
6456 if GetAIFlag('ATTACKRIGHT') <> '' then
6457 begin // Если нужно атаковать направо
6458 RemoveAIFlag('ATTACKRIGHT');
6460 SetAIFlag('NEEDJUMP', '1');
6462 if RunDirection() = TDirection
.D_LEFT
then
6463 begin // Идем не в ту сторону
6464 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6465 begin // Если здоровы, то, возможно, бежим вправо и стреляем
6466 SetAIFlag('NEEDFIRE', '1');
6467 SetAIFlag('GORIGHT', '1');
6472 if GetRnd(FDifficult
.InvisFire
) then // Возможно, стреляем вслепую
6473 SetAIFlag('NEEDFIRE', '1');
6474 if Healthy() <= 1 then // Побиты - убегаем
6475 SetAIFlag('GOLEFT', '1');
6479 //HACK! (does it belongs there?)
6480 RealizeCurrentWeapon();
6482 // Если есть возможные цели:
6483 // (Стреляем по направлению к целям)
6484 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6485 for a
:= 0 to High(targets
) do
6487 // Если можем стрелять по диагонали:
6488 if GetRnd(FDifficult
.DiagFire
) then
6490 // Ищем цель сверху и стреляем, если есть:
6491 if FDirection
= TDirection
.D_LEFT
then
6492 angle
:= ANGLE_LEFTUP
6494 angle
:= ANGLE_RIGHTUP
;
6496 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6497 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6499 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6500 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6501 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6502 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6503 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6505 SetAIFlag('NEEDFIRE', '1');
6506 SetAIFlag('NEEDSEEUP', '1');
6509 // Ищем цель снизу и стреляем, если есть:
6510 if FDirection
= TDirection
.D_LEFT
then
6511 angle
:= ANGLE_LEFTDOWN
6513 angle
:= ANGLE_RIGHTDOWN
;
6515 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6516 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6518 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6519 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6520 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6521 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6522 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6524 SetAIFlag('NEEDFIRE', '1');
6525 SetAIFlag('NEEDSEEDOWN', '1');
6529 // Если цель "перед носом", то стреляем:
6530 if targets
[a
].Line
and targets
[a
].Visible
and
6531 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
6532 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
6534 SetAIFlag('NEEDFIRE', '1');
6539 // Если летит пуля, то, возможно, подпрыгиваем:
6540 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
6541 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
6542 40+GetInterval(FDifficult
.Cover
, 40)) then
6543 SetAIFlag('NEEDJUMP', '1');
6545 // Если кончились паторны, то нужно сменить оружие:
6546 ammo
:= GetAmmoByWeapon(FCurrWeap
);
6547 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
6548 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
6550 SetAIFlag('SELECTWEAPON', '1');
6552 // Если нужно сменить оружие, то выбираем нужное:
6553 if GetAIFlag('SELECTWEAPON') = '1' then
6556 RemoveAIFlag('SELECTWEAPON');
6560 procedure TBot
.Update();
6573 // Проверяем, отключён ли AI ботов
6574 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
6576 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
6578 if g_debug_BotAIOff
= 3 then
6588 RealizeCurrentWeapon();
6595 procedure TBot
.ReleaseKey(Key
: Byte);
6604 function TBot
.KeyPressed(Key
: Word): Boolean;
6606 Result
:= FKeys
[Key
].Pressed
;
6609 function TBot
.GetAIFlag(aName
: String20
): String20
;
6615 aName
:= LowerCase(aName
);
6617 if FAIFlags
<> nil then
6618 for a
:= 0 to High(FAIFlags
) do
6619 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6621 Result
:= FAIFlags
[a
].Value
;
6626 procedure TBot
.RemoveAIFlag(aName
: String20
);
6630 if FAIFlags
= nil then Exit
;
6632 aName
:= LowerCase(aName
);
6634 for a
:= 0 to High(FAIFlags
) do
6635 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6637 if a
<> High(FAIFlags
) then
6638 for b
:= a
to High(FAIFlags
)-1 do
6639 FAIFlags
[b
] := FAIFlags
[b
+1];
6641 SetLength(FAIFlags
, Length(FAIFlags
)-1);
6646 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
6654 aName
:= LowerCase(aName
);
6656 if FAIFlags
<> nil then
6657 for a
:= 0 to High(FAIFlags
) do
6658 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6664 if ok
then FAIFlags
[a
].Value
:= fValue
6667 SetLength(FAIFlags
, Length(FAIFlags
)+1);
6668 with FAIFlags
[High(FAIFlags
)] do
6676 procedure TBot
.UpdateMove
;
6678 procedure GoLeft(Time
: Word = 1);
6680 ReleaseKey(KEY_LEFT
);
6681 ReleaseKey(KEY_RIGHT
);
6682 PressKey(KEY_LEFT
, Time
);
6683 SetDirection(TDirection
.D_LEFT
);
6686 procedure GoRight(Time
: Word = 1);
6688 ReleaseKey(KEY_LEFT
);
6689 ReleaseKey(KEY_RIGHT
);
6690 PressKey(KEY_RIGHT
, Time
);
6691 SetDirection(TDirection
.D_RIGHT
);
6694 function Rnd(a
: Word): Boolean;
6696 Result
:= Random(a
) = 0;
6699 procedure Turn(Time
: Word = 1200);
6701 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
6706 ReleaseKey(KEY_LEFT
);
6707 ReleaseKey(KEY_RIGHT
);
6710 function CanRunLeft(): Boolean;
6712 Result
:= not CollideLevel(-1, 0);
6715 function CanRunRight(): Boolean;
6717 Result
:= not CollideLevel(1, 0);
6720 function CanRun(): Boolean;
6722 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
6725 procedure Jump(Time
: Word = 30);
6727 PressKey(KEY_JUMP
, Time
);
6730 function NearHole(): Boolean;
6734 { TODO 5 : Лестницы }
6735 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
6736 for x
:= 1 to PLAYER_RECT
.Width
do
6737 if (not StayOnStep(x
*sx
, 0)) and
6738 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6739 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6748 function BorderHole(): Boolean;
6752 { TODO 5 : Лестницы }
6753 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
6754 for x
:= 1 to PLAYER_RECT
.Width
do
6755 if (not StayOnStep(x
*sx
, 0)) and
6756 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6757 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6759 for xx
:= x
to x
+32 do
6760 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
6770 function NearDeepHole(): Boolean;
6776 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
6779 for x
:= 1 to PLAYER_RECT
.Width
do
6780 if (not StayOnStep(x
*sx
, 0)) and
6781 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6782 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6784 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6786 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
6791 end else Result
:= False;
6794 function OverDeepHole(): Boolean;
6801 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6803 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
6810 function OnGround(): Boolean;
6812 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
6815 function OnLadder(): Boolean;
6817 Result
:= FullInStep(0, 0);
6820 function BelowLadder(): Boolean;
6822 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
6823 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
6824 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
6825 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
6828 function BelowLiftUp(): Boolean;
6830 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
6831 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
6832 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
6833 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
6836 function OnTopLift(): Boolean;
6838 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
6841 function CanJumpOver(): Boolean;
6845 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
6849 if not CollideLevel(sx
, 0) then Exit
;
6851 for y
:= 1 to BOT_MAXJUMP
do
6852 if CollideLevel(0, -y
) then Exit
else
6853 if not CollideLevel(sx
, -y
) then
6860 function CanJumpUp(Dist
: ShortInt): Boolean;
6867 if CollideLevel(Dist
, 0) then Exit
;
6870 for y
:= 0 to BOT_MAXJUMP
do
6871 if CollideLevel(Dist
, -y
) then
6880 for yy
:= y
+1 to BOT_MAXJUMP
do
6881 if not CollideLevel(Dist
, -yy
) then
6890 for y
:= 0 to BOT_MAXJUMP
do
6891 if CollideLevel(0, -y
) then
6899 if y
< yy
then Exit
;
6904 function IsSafeTrigger(): Boolean;
6909 if gTriggers
= nil then
6911 for a
:= 0 to High(gTriggers
) do
6912 if Collide(gTriggers
[a
].X
,
6915 gTriggers
[a
].Height
) and
6916 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
6917 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
6918 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
6919 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
6920 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
6925 // Возможно, нажимаем кнопку:
6926 if Rnd(16) and IsSafeTrigger() then
6929 // Если под лифтом или ступеньками, то, возможно, прыгаем:
6930 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
6932 ReleaseKey(KEY_LEFT
);
6933 ReleaseKey(KEY_RIGHT
);
6937 // Идем влево, если надо было:
6938 if GetAIFlag('GOLEFT') <> '' then
6940 RemoveAIFlag('GOLEFT');
6941 if CanRunLeft() then
6945 // Идем вправо, если надо было:
6946 if GetAIFlag('GORIGHT') <> '' then
6948 RemoveAIFlag('GORIGHT');
6949 if CanRunRight() then
6953 // Если вылетели за карту, то пробуем вернуться:
6954 if FObj
.X
< -32 then
6957 if FObj
.X
+32 > gMapInfo
.Width
then
6960 // Прыгаем, если надо было:
6961 if GetAIFlag('NEEDJUMP') <> '' then
6964 RemoveAIFlag('NEEDJUMP');
6967 // Смотрим вверх, если надо было:
6968 if GetAIFlag('NEEDSEEUP') <> '' then
6971 ReleaseKey(KEY_DOWN
);
6972 PressKey(KEY_UP
, 20);
6973 RemoveAIFlag('NEEDSEEUP');
6976 // Смотрим вниз, если надо было:
6977 if GetAIFlag('NEEDSEEDOWN') <> '' then
6980 ReleaseKey(KEY_DOWN
);
6981 PressKey(KEY_DOWN
, 20);
6982 RemoveAIFlag('NEEDSEEDOWN');
6985 // Если нужно было в дыру и мы не на земле, то покорно летим:
6986 if GetAIFlag('GOINHOLE') <> '' then
6987 if not OnGround() then
6989 ReleaseKey(KEY_LEFT
);
6990 ReleaseKey(KEY_RIGHT
);
6991 RemoveAIFlag('GOINHOLE');
6992 SetAIFlag('FALLINHOLE', '1');
6995 // Если падали и достигли земли, то хватит падать:
6996 if GetAIFlag('FALLINHOLE') <> '' then
6998 RemoveAIFlag('FALLINHOLE');
7000 // Если летели прямо и сейчас не на лестнице или на вершине лифта, то отходим в сторону:
7001 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7002 if GetAIFlag('FALLINHOLE') = '' then
7003 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7009 // Если на земле и можно подпрыгнуть, то, возможно, прыгаем:
7011 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7015 // Если на земле и возле дыры (глубина > 2 ростов игрока):
7016 if OnGround() and NearHole() then
7017 if NearDeepHole() then // Если это бездна
7019 0..3: Turn(); // Бежим обратно
7020 4: Jump(); // Прыгаем
7021 5: begin // Прыгаем обратно
7026 else // Это не бездна и мы еще не летим туда
7027 if GetAIFlag('GOINHOLE') = '' then
7029 0: Turn(); // Не нужно туда
7030 1: Jump(); // Вдруг повезет - прыгаем
7031 else // Если яма с границей, то при случае можно туда прыгнуть
7032 if BorderHole() then
7033 SetAIFlag('GOINHOLE', '1');
7036 // Если на земле, но некуда идти:
7037 if (not CanRun()) and OnGround() then
7039 // Если мы на лестнице или можно перепрыгнуть, то прыгаем:
7040 if CanJumpOver() or OnLadder() then
7042 else // иначе попытаемся в другую сторону
7043 if Random(2) = 0 then
7045 if IsSafeTrigger() then
7051 // Осталось мало воздуха:
7052 if FAir
< 36 * 2 then
7055 // Выбираемся из кислоты, если нет костюма, обожглись, или мало здоровья:
7056 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7057 if BodyInAcid(0, 0) then
7061 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7063 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7064 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7067 {function TBot.NeedItem(Item: Byte): Byte;
7072 procedure TBot
.SelectWeapon(Dist
: Integer);
7076 function HaveAmmo(weapon
: Byte): Boolean;
7079 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7080 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7081 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7082 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7083 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7084 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7085 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7086 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7087 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7088 else Result
:= True;
7093 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7095 if Dist
> BOT_LONGDIST
then
7096 begin // Дальний бой
7098 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7100 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7104 else //if Dist > BOT_UNSAFEDIST then
7105 begin // Ближний бой
7107 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7109 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7116 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7118 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7124 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7126 Result
:= inherited PickItem(ItemType
, force
, remove
);
7128 if Result
then SetAIFlag('SELECTWEAPON', '1');
7131 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7133 Result
:= inherited Heal(value
, Soft
);
7136 function TBot
.Healthy(): Byte;
7138 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7139 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7140 else if (FHealth
> 50) then Result
:= 2
7141 else if (FHealth
> 20) then Result
:= 1
7145 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7147 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7148 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7151 procedure TBot
.OnDamage(Angle
: SmallInt);
7159 if (Angle
= 0) or (Angle
= 180) then
7162 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7163 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7165 pla
:= g_Player_Get(FLastSpawnerUID
);
7166 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7167 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7170 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7171 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7173 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7174 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7175 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7180 SetAIFlag('ATTACKLEFT', '1')
7182 SetAIFlag('ATTACKRIGHT', '1');
7186 function TBot
.RunDirection(): TDirection
;
7188 if Abs(Vel
.X
) >= 1 then
7190 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7192 Result
:= FDirection
;
7195 function TBot
.GetRnd(a
: Byte): Boolean;
7197 if a
= 0 then Result
:= False
7198 else if a
= 255 then Result
:= True
7199 else Result
:= Random(256) > 255-a
;
7202 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7204 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7208 procedure TDifficult
.save (st
: TStream
);
7210 utils
.writeInt(st
, Byte(DiagFire
));
7211 utils
.writeInt(st
, Byte(InvisFire
));
7212 utils
.writeInt(st
, Byte(DiagPrecision
));
7213 utils
.writeInt(st
, Byte(FlyPrecision
));
7214 utils
.writeInt(st
, Byte(Cover
));
7215 utils
.writeInt(st
, Byte(CloseJump
));
7216 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7217 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7220 procedure TDifficult
.load (st
: TStream
);
7222 DiagFire
:= utils
.readByte(st
);
7223 InvisFire
:= utils
.readByte(st
);
7224 DiagPrecision
:= utils
.readByte(st
);
7225 FlyPrecision
:= utils
.readByte(st
);
7226 Cover
:= utils
.readByte(st
);
7227 CloseJump
:= utils
.readByte(st
);
7228 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7229 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7233 procedure TBot
.SaveState (st
: TStream
);
7238 inherited SaveState(st
);
7239 utils
.writeSign(st
, 'BOT0');
7241 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7243 utils
.writeInt(st
, Word(FTargetUID
));
7244 // Время потери цели
7245 utils
.writeInt(st
, LongWord(FLastVisible
));
7246 // Количество флагов ИИ
7247 dw
:= Length(FAIFlags
);
7248 utils
.writeInt(st
, LongInt(dw
));
7250 for i
:= 0 to dw
-1 do
7252 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7253 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7255 // Настройки сложности
7256 FDifficult
.save(st
);
7260 procedure TBot
.LoadState (st
: TStream
);
7265 inherited LoadState(st
);
7266 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7268 FSelectedWeapon
:= utils
.readByte(st
);
7270 FTargetUID
:= utils
.readWord(st
);
7271 // Время потери цели
7272 FLastVisible
:= utils
.readLongWord(st
);
7273 // Количество флагов ИИ
7274 dw
:= utils
.readLongInt(st
);
7275 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7276 SetLength(FAIFlags
, dw
);
7278 for i
:= 0 to dw
-1 do
7280 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7281 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7283 // Настройки сложности
7284 FDifficult
.load(st
);
7289 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');
7290 conRegVar('player_indicator_style', @gPlayerIndicatorStyle
, 'Visual appearance of indicator', 'Visual appearance of indicator');