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
,
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;
531 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
532 procedure moveBy (dx
, dy
: Integer); inline;
534 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
537 TCorpse
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
544 FModel
: TPlayerModel
;
547 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
548 destructor Destroy(); override;
549 procedure Damage(Value
: Word; SpawnerUID
: Word; vx
, vy
: Integer);
551 procedure SaveState (st
: TStream
);
552 procedure LoadState (st
: TStream
);
554 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
555 procedure moveBy (dx
, dy
: Integer); inline;
557 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
559 function ObjPtr (): PObj
; inline;
561 property Obj
: TObj read FObj
; // copies object
562 property State
: Byte read FState
;
563 property Mess
: Boolean read FMess
;
564 property Model
: TPlayerModel read FModel
;
567 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
573 gPlayers
: Array of TPlayer
;
574 gCorpses
: Array of TCorpse
;
575 gShells
: Array of TShell
;
576 gTeamStat
: TTeamStat
;
577 gFly
: Boolean = False;
578 gAimLine
: Boolean = False;
579 gChatBubble
: Integer = 0;
580 gPlayerIndicator
: Integer = 1;
581 gPlayerIndicatorStyle
: Integer = 0;
583 gSpectLatchPID1
: Word = 0;
584 gSpectLatchPID2
: Word = 0;
585 MAX_RUNVEL
: Integer = 8;
586 VEL_JUMP
: Integer = 10;
587 SHELL_TIMEOUT
: Cardinal = 60000;
589 function Lerp(X
, Y
, Factor
: Integer): Integer;
591 procedure g_Corpses_SetMax(Count
: Word);
592 function g_Corpses_GetMax(): Word;
593 procedure g_Force_Model_Set(Mode
: Word);
594 function g_Force_Model_Get(): Word;
595 procedure g_Forced_Model_SetName(Model
: String);
596 function g_Forced_Model_GetName(): String;
597 procedure g_Shells_SetMax(Count
: Word);
598 function g_Shells_GetMax(): Word;
600 procedure g_Player_Init();
601 procedure g_Player_Free();
602 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
603 function g_Player_CreateFromState (st
: TStream
): Word;
604 procedure g_Player_Remove(UID
: Word);
605 procedure g_Player_ResetTeams();
606 procedure g_Player_PreUpdate();
607 procedure g_Player_UpdateAll();
608 procedure g_Player_RememberAll();
609 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
610 function g_Player_Get(UID
: Word): TPlayer
;
611 function g_Player_GetCount(): Byte;
612 function g_Player_GetStats(): TPlayerStatArray
;
613 function g_Player_ValidName(Name
: String): Boolean;
614 function g_Player_CreateCorpse(Player
: TPlayer
): Integer;
615 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
616 procedure g_Player_UpdatePhysicalObjects();
617 procedure g_Player_RemoveAllCorpses();
618 procedure g_Player_Corpses_SaveState (st
: TStream
);
619 procedure g_Player_Corpses_LoadState (st
: TStream
);
620 procedure g_Player_ResetReady();
621 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
622 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
623 procedure g_Bot_MixNames();
624 procedure g_Bot_RemoveAll();
625 function g_Bot_GetCount(): Integer;
630 {$IFDEF ENABLE_HOLMES}
645 e_log
, g_map
, g_items
, g_console
, Math
,
646 g_options
, g_triggers
, g_game
, g_grid
, e_res
,
647 wadreader
, g_monsters
, CONFIG
, g_language
,
651 const PLR_SAVE_VERSION
= 0;
661 diag_precision
: Byte;
665 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
666 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
667 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
671 TIME_RESPAWN1
= 1500;
672 TIME_RESPAWN2
= 2000;
673 TIME_RESPAWN3
= 3000;
674 PLAYER_SUIT_TIME
= 30000;
675 PLAYER_INVUL_TIME
= 30000;
676 PLAYER_INVIS_TIME
= 35000;
677 FRAG_COMBO_TIME
= 3000;
680 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
683 BOT_UNSAFEDIST
= 128;
684 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
685 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
686 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
687 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
688 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
689 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
690 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
691 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
692 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
693 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
694 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
695 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
696 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
697 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
698 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
699 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
700 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
701 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
702 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
703 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
704 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
705 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
706 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
707 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
708 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
709 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
711 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
712 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
714 BOTNAMES_FILENAME
= 'botnames.txt';
715 BOTLIST_FILENAME
= 'botlist.txt';
718 MaxCorpses
: Word = 20;
719 MaxShells
: Word = 300;
720 ForceModel
: Word = 0;
721 ForcedModelName
: String = STD_PLAYER_MODEL
;
722 CurrentShell
: Integer = 0;
723 BotNames
: Array of String;
724 BotList
: Array of TBotProfile
;
725 SavedStates
: Array of TPlayerSavedState
;
728 function Lerp(X
, Y
, Factor
: Integer): Integer;
730 Result
:= X
+ ((Y
- X
) div Factor
);
733 function SameTeam(UID1
, UID2
: Word): Boolean;
737 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
738 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
740 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
742 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
743 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
745 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
748 procedure g_Shells_SetMax(Count
: Word);
751 SetLength(gShells
, Count
);
753 if CurrentShell
>= Count
then
757 function g_Shells_GetMax(): Word;
763 procedure g_Corpses_SetMax(Count
: Word);
766 SetLength(gCorpses
, Count
);
769 function g_Corpses_GetMax(): Word;
771 Result
:= MaxCorpses
;
774 procedure g_Force_Model_Set(Mode
: Word);
779 function g_Force_Model_Get(): Word;
781 Result
:= ForceModel
;
784 procedure g_Forced_Model_SetName(Model
: String);
786 ForcedModelName
:= Model
;
789 function g_Forced_Model_GetName(): String;
791 Result
:= ForcedModelName
;
794 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
804 // Есть ли место в gPlayers:
805 if gPlayers
<> nil then
806 for a
:= 0 to High(gPlayers
) do
807 if gPlayers
[a
] = nil then
813 // Нет места - расширяем gPlayers:
816 SetLength(gPlayers
, Length(gPlayers
)+1);
820 // Создаем объект игрока:
822 gPlayers
[a
] := TBot
.Create()
824 gPlayers
[a
] := TPlayer
.Create();
827 gPlayers
[a
].FActualModelName
:= ModelName
;
828 gPlayers
[a
].SetModel(ModelName
);
829 if Bot
and (g_Force_Model_Get() <> 0) then
830 gPlayers
[a
].SetModel(g_Forced_Model_GetName());
832 // Нет модели - создание не возможно:
833 if gPlayers
[a
].FModel
= nil then
837 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
841 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
842 if Random(2) = 0 then
846 gPlayers
[a
].FPreferredTeam
:= Team
;
848 case gGameSettings
.GameMode
of
849 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
851 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
853 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
856 // Если командная игра - красим модель в цвет команды:
857 gPlayers
[a
].FColor
:= Color
;
858 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
859 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
861 gPlayers
[a
].FModel
.Color
:= Color
;
863 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
864 gPlayers
[a
].FAlive
:= False;
866 Result
:= gPlayers
[a
].FUID
;
869 function g_Player_CreateFromState (st
: TStream
): Word;
870 var a
: Integer; ok
, Bot
: Boolean; pos
: Int64;
874 // check signature and entity type
876 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
877 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
878 Bot
:= utils
.readBool(st
);
881 // find free player slot
883 for a
:= 0 to High(gPlayers
) do
884 if gPlayers
[a
] = nil then
890 // allocate player slot
893 SetLength(gPlayers
, Length(gPlayers
)+1);
897 // create entity and load state
900 gPlayers
[a
] := TBot
.Create();
901 if (g_Force_Model_Get() <> 0) then
902 gPlayers
[a
].SetModel(g_Forced_Model_GetName());
905 gPlayers
[a
] := TPlayer
.Create();
906 gPlayers
[a
].FPhysics
:= True; // ???
907 gPlayers
[a
].LoadState(st
);
909 result
:= gPlayers
[a
].FUID
;
913 procedure g_Player_ResetTeams();
917 if g_Game_IsClient
then
919 if gPlayers
= nil then
921 for a
:= Low(gPlayers
) to High(gPlayers
) do
922 if gPlayers
[a
] <> nil then
923 case gGameSettings
.GameMode
of
925 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
927 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
928 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
929 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
932 gPlayers
[a
].ChangeTeam(TEAM_RED
)
934 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
937 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
941 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
944 _name
, _model
: String;
947 if not g_Game_IsServer
then Exit
;
949 if (g_Bot_GetCount() >= gMaxBots
) then Exit
;
951 // Список названий моделей:
952 m
:= g_PlayerModel_GetNames();
957 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
958 Team
:= TEAM_COOP
// COOP
960 if gGameSettings
.GameMode
= GM_DM
then
961 Team
:= TEAM_NONE
// DM
963 if Team
= TEAM_NONE
then // CTF / TDM
965 // Автобаланс команд:
969 for a
:= 0 to High(gPlayers
) do
970 if gPlayers
[a
] <> nil then
972 if gPlayers
[a
].Team
= TEAM_RED
then
975 if gPlayers
[a
].Team
= TEAM_BLUE
then
985 if Random(2) = 0 then
991 // Выбираем боту имя:
993 if BotNames
<> nil then
994 for a
:= 0 to High(BotNames
) do
995 if g_Player_ValidName(BotNames
[a
]) then
997 _name
:= BotNames
[a
];
1001 // Выбираем случайную модель:
1002 _model
:= m
[Random(Length(m
))];
1005 with g_Player_Get(g_Player_Create(_model
,
1006 _RGB(Min(Random(9)*32, 255),
1007 Min(Random(9)*32, 255),
1008 Min(Random(9)*32, 255)),
1009 Team
, True)) as TBot
do
1011 // Если имени нет, делаем его из UID бота
1013 Name
:= Format('DFBOT%.5d', [UID
])
1018 1: FDifficult
:= DIFFICULT_EASY
;
1019 2: FDifficult
:= DIFFICULT_MEDIUM
;
1020 else FDifficult
:= DIFFICULT_HARD
;
1023 for a
:= WP_FIRST
to WP_LAST
do
1025 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1026 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1027 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1030 FHandicap
:= Handicap
;
1032 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1034 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1035 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1040 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
1043 _name
, _model
: String;
1046 if not g_Game_IsServer
then Exit
;
1048 if (g_Bot_GetCount() >= gMaxBots
) then Exit
;
1050 // Список названий моделей:
1051 m
:= g_PlayerModel_GetNames();
1056 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1057 Team
:= TEAM_COOP
// COOP
1059 if gGameSettings
.GameMode
= GM_DM
then
1060 Team
:= TEAM_NONE
// DM
1062 if Team
= TEAM_NONE
then
1063 Team
:= BotList
[num
].team
; // CTF / TDM
1065 // Выбираем настройки бота из списка по номеру или имени:
1066 lName
:= AnsiLowerCase(lName
);
1067 if (num
< 0) or (num
> Length(BotList
)-1) then
1069 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1070 for a
:= 0 to High(BotList
) do
1071 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1080 _name
:= BotList
[num
].name
;
1081 // Занято - выбираем случайное:
1082 if not g_Player_ValidName(_name
) then
1084 _name
:= Format('DFBOT%.2d', [Random(100)]);
1085 until g_Player_ValidName(_name
);
1088 _model
:= BotList
[num
].model
;
1089 // Нет такой - выбираем случайную:
1090 if not InSArray(_model
, m
) then
1091 _model
:= m
[Random(Length(m
))];
1094 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1098 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1099 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1100 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1101 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1102 FDifficult
.Cover
:= BotList
[num
].cover
;
1103 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1105 FHandicap
:= Handicap
;
1107 for a
:= WP_FIRST
to WP_LAST
do
1109 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1110 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1111 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1114 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1116 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1120 procedure g_Bot_RemoveAll();
1124 if not g_Game_IsServer
then Exit
;
1125 if gPlayers
= nil then Exit
;
1127 for a
:= 0 to High(gPlayers
) do
1128 if gPlayers
[a
] <> nil then
1129 if gPlayers
[a
] is TBot
then
1131 gPlayers
[a
].Lives
:= 0;
1132 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1133 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1134 g_Player_Remove(gPlayers
[a
].FUID
);
1140 procedure g_Bot_MixNames();
1145 if BotNames
<> nil then
1146 for a
:= 0 to High(BotNames
) do
1148 b
:= Random(Length(BotNames
));
1150 Botnames
[a
] := BotNames
[b
];
1155 procedure g_Player_Remove(UID
: Word);
1159 if gPlayers
= nil then Exit
;
1161 if g_Game_IsServer
and g_Game_IsNet
then
1162 MH_SEND_PlayerDelete(UID
);
1164 for i
:= 0 to High(gPlayers
) do
1165 if gPlayers
[i
] <> nil then
1166 if gPlayers
[i
].FUID
= UID
then
1168 if gPlayers
[i
] is TPlayer
then
1169 TPlayer(gPlayers
[i
]).Free()
1171 TBot(gPlayers
[i
]).Free();
1177 procedure g_Player_Init();
1188 path
:= BOTNAMES_FILENAME
;
1189 if e_FindResource(DataDirs
, path
) = false then
1192 // Читаем возможные имена ботов из файла:
1193 AssignFile(F
, path
);
1204 SetLength(BotNames
, Length(BotNames
)+1);
1205 BotNames
[High(BotNames
)] := s
;
1213 // Читаем файл с параметрами ботов:
1214 config
:= TConfig
.CreateFile(path
);
1218 while config
.SectionExists(IntToStr(a
)) do
1220 SetLength(BotList
, Length(BotList
)+1);
1222 with BotList
[High(BotList
)] do
1225 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1227 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1229 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1234 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1235 color
.R
:= StrToIntDef(sa
[0], 0);
1236 color
.G
:= StrToIntDef(sa
[1], 0);
1237 color
.B
:= StrToIntDef(sa
[2], 0);
1238 // Вероятность стрельбы под углом:
1239 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1240 // Вероятность ответного огня по невидимому сопернику:
1241 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1242 // Точность стрельбы под углом:
1243 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1244 // Точность стрельбы в полете:
1245 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1246 // Точность уклонения от снарядов:
1247 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1248 // Вероятность прыжка при приближении соперника:
1249 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1250 // Приоритеты оружия для дальнего боя:
1251 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1252 if Length(sa
) = 10 then
1254 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1255 // Приоритеты оружия для ближнего боя:
1256 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1257 if Length(sa
) = 10 then
1259 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1261 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1262 if Length(sa) = 10 then
1264 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1271 SetLength(SavedStates
, 0);
1274 procedure g_Player_Free();
1278 if gPlayers
<> nil then
1280 for i
:= 0 to High(gPlayers
) do
1281 if gPlayers
[i
] <> nil then
1283 if gPlayers
[i
] is TPlayer
then
1284 TPlayer(gPlayers
[i
]).Free()
1286 TBot(gPlayers
[i
]).Free();
1295 SetLength(SavedStates
, 0);
1298 procedure g_Player_PreUpdate();
1302 if gPlayers
= nil then Exit
;
1303 for i
:= 0 to High(gPlayers
) do
1304 if gPlayers
[i
] <> nil then
1305 gPlayers
[i
].PreUpdate();
1308 procedure g_Player_UpdateAll();
1312 if gPlayers
= nil then Exit
;
1314 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1315 for i
:= 0 to High(gPlayers
) do
1317 if gPlayers
[i
] <> nil then
1319 if gPlayers
[i
] is TPlayer
then
1321 gPlayers
[i
].Update();
1322 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1326 // bot updates weapons in `UpdateCombat()`
1327 TBot(gPlayers
[i
]).Update();
1331 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1334 function g_Player_Get(UID
: Word): TPlayer
;
1340 if gPlayers
= nil then
1343 for a
:= 0 to High(gPlayers
) do
1344 if gPlayers
[a
] <> nil then
1345 if gPlayers
[a
].FUID
= UID
then
1347 Result
:= gPlayers
[a
];
1352 function g_Player_GetCount(): Byte;
1358 if gPlayers
= nil then
1361 for a
:= 0 to High(gPlayers
) do
1362 if gPlayers
[a
] <> nil then
1363 Result
:= Result
+ 1;
1366 function g_Bot_GetCount(): Integer;
1372 if gPlayers
= nil then
1375 for a
:= 0 to High(gPlayers
) do
1376 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] is TBot
) then
1377 Result
:= Result
+ 1;
1380 function g_Player_GetStats(): TPlayerStatArray
;
1386 if gPlayers
= nil then Exit
;
1388 for a
:= 0 to High(gPlayers
) do
1389 if gPlayers
[a
] <> nil then
1391 SetLength(Result
, Length(Result
)+1);
1392 with Result
[High(Result
)] do
1395 Ping
:= gPlayers
[a
].FPing
;
1396 Loss
:= gPlayers
[a
].FLoss
;
1397 Name
:= gPlayers
[a
].FName
;
1398 Team
:= gPlayers
[a
].FTeam
;
1399 Frags
:= gPlayers
[a
].FFrags
;
1400 Deaths
:= gPlayers
[a
].FDeath
;
1401 Kills
:= gPlayers
[a
].FKills
;
1402 Color
:= gPlayers
[a
].FModel
.Color
;
1403 Lives
:= gPlayers
[a
].FLives
;
1404 Spectator
:= gPlayers
[a
].FSpectator
;
1405 UID
:= gPlayers
[a
].FUID
;
1410 procedure g_Player_ResetReady();
1414 if not g_Game_IsServer
then Exit
;
1415 if gPlayers
= nil then Exit
;
1417 for a
:= 0 to High(gPlayers
) do
1418 if gPlayers
[a
] <> nil then
1420 gPlayers
[a
].FReady
:= False;
1421 if g_Game_IsNet
then
1422 MH_SEND_GameEvent(NET_EV_INTER_READY
, gPlayers
[a
].UID
, 'N');
1426 procedure g_Player_RememberAll
;
1430 for i
:= Low(gPlayers
) to High(gPlayers
) do
1431 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1432 gPlayers
[i
].RememberState
;
1435 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1439 gTeamStat
[TEAM_RED
].Score
:= 0;
1440 gTeamStat
[TEAM_BLUE
].Score
:= 0;
1442 if gPlayers
<> nil then
1443 for i
:= 0 to High(gPlayers
) do
1444 if gPlayers
[i
] <> nil then
1446 gPlayers
[i
].Reset(Force
);
1448 if gPlayers
[i
] is TPlayer
then
1450 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1451 gPlayers
[i
].Respawn(Silent
)
1453 gPlayers
[i
].Spectate();
1456 TBot(gPlayers
[i
]).Respawn(Silent
);
1460 function g_Player_CreateCorpse(Player
: TPlayer
): Integer;
1468 if Player
.alive
then
1471 // Разрываем связь с прежним трупом:
1472 i
:= Player
.FCorpse
;
1473 if (i
>= 0) and (i
< Length(gCorpses
)) then
1475 if (gCorpses
[i
] <> nil) and (gCorpses
[i
].FPlayerUID
= Player
.FUID
) then
1476 gCorpses
[i
].FPlayerUID
:= 0;
1479 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1484 {$IFDEF ENABLE_GIBS}
1485 if (FHealth
< -50) and (gGibsCount
> 0) then
1487 g_Gibs_Create(FObj
.X
+ PLAYER_RECT_CX
, FObj
.Y
+ PLAYER_RECT_CY
, FModel
.id
, FModel
.Color
);
1492 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1496 for find_id
:= 0 to High(gCorpses
) do
1497 if gCorpses
[find_id
] = nil then
1504 find_id
:= Random(Length(gCorpses
));
1506 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.GetName(), FHealth
< -20);
1507 gCorpses
[find_id
].FModel
.Color
:= FModel
.Color
;
1508 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1509 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1510 gCorpses
[find_id
].FPlayerUID
:= FUID
;
1517 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1519 if (gShells
= nil) or (Length(gShells
) = 0) then
1522 with gShells
[CurrentShell
] do
1527 if T
= SHELL_BULLET
then
1529 Obj
.Rect
.Width
:= 4;
1530 Obj
.Rect
.Height
:= 2;
1534 Obj
.Rect
.Width
:= 7;
1535 Obj
.Rect
.Height
:= 3;
1541 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1542 positionChanged(); // this updates spatial accelerators
1543 RAngle
:= Random(360);
1544 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1546 if CurrentShell
>= High(gShells
) then
1553 procedure g_Player_UpdatePhysicalObjects();
1559 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1564 if T
= SHELL_BULLET
then
1565 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1567 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1572 if gCorpses
<> nil then
1573 for i
:= 0 to High(gCorpses
) do
1574 if gCorpses
[i
] <> nil then
1575 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1581 gCorpses
[i
].Update();
1584 if gShells
<> nil then
1585 for i
:= 0 to High(gShells
) do
1586 if gShells
[i
].alive
then
1593 mr
:= g_Obj_Move(@Obj
, True, False, True);
1594 positionChanged(); // this updates spatial accelerators
1596 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1602 // Отлетает от удара о стену/потолок/пол:
1603 if WordBool(mr
and MOVE_HITWALL
) then
1605 Obj
.Vel
.X
:= -(vel
.X
div 2);
1606 if not WordBool(mr
and MOVE_INWATER
) then
1607 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1609 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1611 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1612 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1613 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1615 if RAngle
mod 90 <> 0 then
1616 RAngle
:= (RAngle
div 90) * 90;
1618 else if not WordBool(mr
and MOVE_INWATER
) then
1619 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1622 if (Obj
.Vel
.X
>= 0) then
1624 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1625 if RAngle
>= 360 then
1626 RAngle
:= RAngle
mod 360;
1627 end else begin // Counter-clockwise
1628 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1630 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1635 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1639 w
:= Obj
.Rect
.Width
;
1640 h
:= Obj
.Rect
.Height
;
1643 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1645 if (dx
<> 0) or (dy
<> 0) then
1653 procedure TShell
.positionChanged (); inline; begin end;
1656 procedure g_Player_RemoveAllCorpses();
1658 {$IFDEF ENABLE_GIBS}
1659 var maxgibs
: Integer;
1662 {$IFDEF ENABLE_GIBS}
1663 maxgibs
:= g_Gibs_GetMax();
1665 g_Gibs_SetMax(maxgibs
);
1668 SetLength(gShells
, MaxShells
);
1671 if gCorpses
<> nil then
1672 for i
:= 0 to High(gCorpses
) do
1676 SetLength(gCorpses
, MaxCorpses
);
1679 procedure g_Player_Corpses_SaveState (st
: TStream
);
1683 // Считаем количество существующих трупов
1685 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1687 // Количество трупов
1688 utils
.writeInt(st
, LongInt(count
));
1690 if (count
= 0) then exit
;
1693 for i
:= 0 to High(gCorpses
) do
1695 if gCorpses
[i
] <> nil then
1698 utils
.writeStr(st
, gCorpses
[i
].FModel
.GetName());
1700 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1701 // Сохраняем данные трупа:
1702 gCorpses
[i
].SaveState(st
);
1708 procedure g_Player_Corpses_LoadState (st
: TStream
);
1716 g_Player_RemoveAllCorpses();
1718 // Количество трупов:
1719 count
:= utils
.readLongInt(st
);
1720 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1722 if (count
= 0) then exit
;
1725 for i
:= 0 to count
-1 do
1728 str
:= utils
.readStr(st
);
1730 b
:= utils
.readBool(st
);
1732 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1733 // Загружаем данные трупа
1734 gCorpses
[i
].LoadState(st
);
1741 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1743 procedure TPlayer
.BFGHit();
1745 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1746 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1747 if g_Game_IsServer
and g_Game_IsNet
then
1748 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1749 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1753 procedure TPlayer
.ChangeModel(ModelName
: string);
1755 locModel
: TPlayerModel
;
1757 locModel
:= g_PlayerModel_Get(ModelName
);
1758 if locModel
= nil then Exit
;
1764 procedure TPlayer
.SetModel(ModelName
: string);
1768 m
:= g_PlayerModel_Get(ModelName
);
1771 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1772 m
:= g_PlayerModel_Get('doomer');
1775 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1780 if FModel
<> nil then
1785 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1786 FModel
.Color
:= FColor
1788 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1789 FModel
.SetWeapon(FCurrWeap
);
1790 FModel
.SetFlag(FFlag
);
1791 SetDirection(FDirection
);
1794 procedure TPlayer
.SetColor(Color
: TRGB
);
1797 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1798 if FModel
<> nil then FModel
.Color
:= Color
;
1803 function TPlayer
.GetColor(): TRGB
;
1805 result
:= FModel
.Color
;
1808 procedure TPlayer
.SetWeaponPrefs(Prefs
: Array of Byte);
1812 for i
:= WP_FIRST
to WP_LAST
+ 1 do
1814 if (Prefs
[i
] > WP_LAST
+ 1) then
1815 FWeapPreferences
[i
] := 0
1817 FWeapPreferences
[i
] := Prefs
[i
];
1821 procedure TPlayer
.SetWeaponPref(Weapon
, Pref
: Byte);
1823 if (Weapon
> WP_LAST
+ 1) then
1825 else if (Pref
<= WP_LAST
+ 1) and (Weapon
<= WP_LAST
+ 1) then
1826 FWeapPreferences
[Weapon
] := Pref
1827 else if (Weapon
<= WP_LAST
+ 1) and (Pref
> WP_LAST
+ 1) then
1828 FWeapPreferences
[Weapon
] := 0;
1831 function TPlayer
.GetWeaponPref(Weapon
: Byte) : Byte;
1833 if (Weapon
> WP_LAST
+ 1) then
1835 else if (FWeapPreferences
[Weapon
] > WP_LAST
+ 1) then
1838 result
:= FWeapPreferences
[Weapon
];
1841 function TPlayer
.GetMorePrefered() : Byte;
1843 testedWeap
, i
: Byte;
1845 testedWeap
:= FCurrWeap
;
1846 for i
:= WP_FIRST
to WP_LAST
do
1847 if FWeapon
[i
] and maySwitch(i
) and (FWeapPreferences
[i
] > FWeapPreferences
[testedWeap
]) then
1849 if (R_BERSERK
in FRulez
) and (FWeapPreferences
[WP_LAST
+ 1] > FWeapPreferences
[testedWeap
]) then
1850 testedWeap
:= WEAPON_KASTET
;
1851 result
:= testedWeap
;
1854 function TPlayer
.maySwitch(Weapon
: Byte) : Boolean;
1857 if (Weapon
= WEAPON_KASTET
) and (FSkipFist
<> 0) then
1859 if (FSkipFist
= 1) and (not (R_BERSERK
in FRulez
)) then
1862 else if (FSwitchToEmpty
= 0) and (not hasAmmoForShooting(Weapon
)) then
1866 procedure TPlayer
.SwitchTeam
;
1868 if g_Game_IsClient
then
1870 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
1872 if gGameOn
and FAlive
then
1873 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
1875 if FTeam
= TEAM_RED
then
1877 ChangeTeam(TEAM_BLUE
);
1878 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
1879 if g_Game_IsNet
then
1880 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
1884 ChangeTeam(TEAM_RED
);
1885 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
1886 if g_Game_IsNet
then
1887 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
1889 FPreferredTeam
:= FTeam
;
1892 procedure TPlayer
.ChangeTeam(Team
: Byte);
1899 TEAM_RED
, TEAM_BLUE
:
1900 FModel
.Color
:= TEAMCOLOR
[Team
];
1902 FModel
.Color
:= FColor
;
1904 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
1905 MH_SEND_PlayerStats(FUID
);
1909 procedure TPlayer.CollideItem();
1914 if gItems = nil then Exit;
1915 if not FAlive then Exit;
1917 for i := 0 to High(gItems) do
1920 if (ItemType <> ITEM_NONE) and alive then
1921 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
1922 PLAYER_RECT.Height, @Obj) then
1924 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
1926 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
1927 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
1928 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
1929 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
1930 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
1932 // Надо убрать с карты, если это не ключ, которым нужно поделится с другим игроком:
1933 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
1934 (gGameSettings.GameType = GT_SINGLE) and
1935 (g_Player_GetCount() > 1)) then
1936 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
1942 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
1944 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
1945 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
1949 constructor TPlayer
.Create();
1955 mEDamageType
:= HIT_SOME
;
1961 FSawSound
:= TPlayableSound
.Create();
1962 FSawSoundIdle
:= TPlayableSound
.Create();
1963 FSawSoundHit
:= TPlayableSound
.Create();
1964 FSawSoundSelect
:= TPlayableSound
.Create();
1965 FFlameSoundOn
:= TPlayableSound
.Create();
1966 FFlameSoundOff
:= TPlayableSound
.Create();
1967 FFlameSoundWork
:= TPlayableSound
.Create();
1968 FJetSoundFly
:= TPlayableSound
.Create();
1969 FJetSoundOn
:= TPlayableSound
.Create();
1970 FJetSoundOff
:= TPlayableSound
.Create();
1972 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
1973 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
1974 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
1975 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
1976 FFlameSoundOn
.SetByName('SOUND_WEAPON_FLAMEON');
1977 FFlameSoundOff
.SetByName('SOUND_WEAPON_FLAMEOFF');
1978 FFlameSoundWork
.SetByName('SOUND_WEAPON_FLAMEWORK');
1979 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
1980 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
1981 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
1983 FSpectatePlayer
:= -1;
1987 FSavedStateNum
:= -1;
1995 FActualModelName
:= 'doomer';
1998 FObj
.Rect
:= PLAYER_RECT
;
2000 FBFGFireCounter
:= -1;
2001 FJustTeleported
:= False;
2004 FWaitForFirstSpawn
:= false;
2005 FPunchAnim
:= TAnimationState
.Create(False, 1, 4);
2011 procedure TPlayer
.positionChanged (); inline;
2015 procedure TPlayer
.doDamage (v
: Integer);
2017 if (v
<= 0) then exit
;
2018 if (v
> 32767) then v
:= 32767;
2019 Damage(v
, 0, 0, 0, mEDamageType
);
2022 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2026 if (not g_Game_IsClient
) and (not FAlive
) then
2031 // Неуязвимость не спасает от ловушек:
2032 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2034 if not g_Game_IsClient
then
2037 if t
= HIT_TRAP
then
2039 // Ловушка убивает сразу:
2041 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2043 if t
= HIT_SELF
then
2047 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2050 // Обнулить действия примочек, чтобы фон пропал
2051 FMegaRulez
[MR_SUIT
] := 0;
2052 FMegaRulez
[MR_INVUL
] := 0;
2053 FMegaRulez
[MR_INVIS
] := 0;
2058 // Но от остального спасает:
2059 if FMegaRulez
[MR_INVUL
] >= gTime
then
2066 // Если есть урон своим, или ранил сам себя, или тебя ранил противник:
2067 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2068 (SpawnerUID
= FUID
) or
2069 (not SameTeam(FUID
, SpawnerUID
)) then
2071 FLastSpawnerUID
:= SpawnerUID
;
2073 // Кровь (пузырьки, если в воде):
2074 if gBloodCount
> 0 then
2076 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2077 if value
div 4 <= c
then
2078 c
:= c
- (value
div 4)
2082 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2086 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2087 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2091 if t
= HIT_WATER
then
2093 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2094 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2096 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
2097 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
2104 Inc(FDamageBuffer
, value
);
2108 FPain
:= FPain
+ value
;
2111 if g_Game_IsServer
and g_Game_IsNet
then
2113 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2114 MH_SEND_PlayerStats(FUID
);
2115 MH_SEND_PlayerPos(False, FUID
);
2119 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2122 if g_Game_IsClient
then
2127 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2129 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2132 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2134 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2138 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2139 MH_SEND_PlayerStats(FUID
);
2142 destructor TPlayer
.Destroy();
2144 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2146 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2150 FSawSoundIdle
.Free();
2151 FSawSoundHit
.Free();
2152 FSawSoundSelect
.Free();
2153 FFlameSoundOn
.Free();
2154 FFlameSoundOff
.Free();
2155 FFlameSoundWork
.Free();
2156 FJetSoundFly
.Free();
2158 FJetSoundOff
.Free();
2165 procedure TPlayer
.DoPunch();
2171 procedure TPlayer
.Fire();
2173 f
, DidFire
: Boolean;
2174 wx
, wy
, xd
, yd
: Integer;
2177 if g_Game_IsClient
then Exit
;
2178 // FBFGFireCounter - время перед выстрелом (для BFG)
2179 // FReloading - время после выстрела (для всего)
2187 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2192 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2193 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2194 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
2195 yd
:= wy
+firediry();
2201 if R_BERSERK
in FRulez
then
2203 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2204 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2205 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2208 locobj
.rect
.Width
:= 39;
2209 locobj
.rect
.Height
:= 52;
2210 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2211 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2212 locobj
.Accel
.X
:= xd
-wx
;
2213 locobj
.Accel
.y
:= yd
-wy
;
2215 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2216 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2218 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2220 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
2224 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2228 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2233 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2234 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2236 FSawSoundSelect
.Stop();
2238 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2240 else if not FSawSoundHit
.IsPlaying() then
2242 FSawSoundSelect
.Stop();
2243 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2246 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2252 if FAmmo
[A_BULLETS
] > 0 then
2254 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2255 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2256 Dec(FAmmo
[A_BULLETS
]);
2257 FFireAngle
:= FAngle
;
2260 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2261 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2265 if FAmmo
[A_SHELLS
] > 0 then
2267 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2268 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
2269 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2270 Dec(FAmmo
[A_SHELLS
]);
2271 FFireAngle
:= FAngle
;
2275 FShellType
:= SHELL_SHELL
;
2279 if FAmmo
[A_SHELLS
] >= 2 then
2281 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
2282 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2283 Dec(FAmmo
[A_SHELLS
], 2);
2284 FFireAngle
:= FAngle
;
2288 FShellType
:= SHELL_DBLSHELL
;
2292 if FAmmo
[A_BULLETS
] > 0 then
2294 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
2295 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
2296 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2297 Dec(FAmmo
[A_BULLETS
]);
2298 FFireAngle
:= FAngle
;
2301 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2302 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2305 WEAPON_ROCKETLAUNCHER
:
2306 if FAmmo
[A_ROCKETS
] > 0 then
2308 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
2309 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2310 Dec(FAmmo
[A_ROCKETS
]);
2311 FFireAngle
:= FAngle
;
2317 if FAmmo
[A_CELLS
] > 0 then
2319 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
2320 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2321 Dec(FAmmo
[A_CELLS
]);
2322 FFireAngle
:= FAngle
;
2328 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
2330 FBFGFireCounter
:= 17;
2331 if not FNoReload
then
2332 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
2333 Dec(FAmmo
[A_CELLS
], 40);
2337 WEAPON_SUPERPULEMET
:
2338 if FAmmo
[A_SHELLS
] > 0 then
2340 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2341 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
2342 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2343 Dec(FAmmo
[A_SHELLS
]);
2344 FFireAngle
:= FAngle
;
2347 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2348 GameVelX
, GameVelY
-2, SHELL_SHELL
);
2351 WEAPON_FLAMETHROWER
:
2352 if FAmmo
[A_FUEL
] > 0 then
2354 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
2356 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2358 FFireAngle
:= FAngle
;
2365 if g_Game_IsNet
and g_Game_IsServer
then MH_SEND_PlayerStats(FUID
);
2369 if g_Game_IsNet
then
2373 if FCurrWeap
<> WEAPON_BFG
then
2374 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
2376 if not FNoReload
then
2377 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
2380 MH_SEND_PlayerStats(FUID
);
2385 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
2386 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
2387 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
2390 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
2393 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
2394 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
2395 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
2396 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
2397 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
2402 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
2404 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
2405 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
2406 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
2409 procedure TPlayer
.FlamerOn
;
2411 FFlameSoundOff
.Stop();
2412 FFlameSoundOff
.SetPosition(0);
2415 if (not FFlameSoundOn
.IsPlaying()) and (not FFlameSoundWork
.IsPlaying()) then
2416 FFlameSoundWork
.PlayAt(FObj
.X
, FObj
.Y
);
2420 FFlameSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
2425 procedure TPlayer
.FlamerOff
;
2429 FFlameSoundOn
.Stop();
2430 FFlameSoundOn
.SetPosition(0);
2431 FFlameSoundWork
.Stop();
2432 FFlameSoundWork
.SetPosition(0);
2433 FFlameSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
2438 procedure TPlayer
.JetpackOn
;
2442 FJetSoundOn
.SetPosition(0);
2443 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
2447 procedure TPlayer
.JetpackOff
;
2451 FJetSoundOff
.SetPosition(0);
2452 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
2455 procedure TPlayer
.CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
2457 if Timeout
<= 0 then
2459 if (FMegaRulez
[MR_SUIT
] > gTime
) or (FMegaRulez
[MR_INVUL
] > gTime
) then
2460 exit
; // Не загораемся когда есть защита
2461 if g_Obj_CollidePanel(@FObj
, 0, 0, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
) then
2462 exit
; // Не подгораем в воде на всякий случай
2463 if FFireTime
<= 0 then
2464 g_Sound_PlayExAt('SOUND_IGNITE', FObj
.X
, FObj
.Y
);
2465 FFireTime
:= Timeout
;
2466 FFireAttacker
:= Attacker
;
2467 if g_Game_IsNet
and g_Game_IsServer
then
2468 MH_SEND_PlayerStats(FUID
);
2471 procedure TPlayer
.Jump();
2473 if gFly
or FJetpack
then
2475 // Полет (чит-код или джетпак):
2476 if FObj
.Vel
.Y
> -VEL_FLY
then
2477 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
2480 if FJetFuel
> 0 then
2482 if (FJetFuel
< 1) and g_Game_IsServer
then
2486 if g_Game_IsNet
then
2487 MH_SEND_PlayerStats(FUID
);
2493 // Не включать джетпак в режиме прохождения сквозь стены
2495 FCanJetpack
:= False;
2497 // Прыгаем или всплываем:
2498 if (CollideLevel(0, 1) or
2499 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
2500 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
2501 ) and (FObj
.Accel
.Y
= 0) then // Не прыгать, если есть вертикальное ускорение
2503 FObj
.Vel
.Y
:= -VEL_JUMP
;
2504 FCanJetpack
:= False;
2508 if BodyInLiquid(0, 0) then
2509 FObj
.Vel
.Y
:= -VEL_SW
2510 else if (FJetFuel
> 0) and FCanJetpack
and
2511 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
2515 if g_Game_IsNet
then
2516 MH_SEND_PlayerStats(FUID
);
2521 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
2523 a
, i
, k
, ab
, ar
: Byte;
2527 srv
, netsrv
: Boolean;
2533 procedure PushItem(t
: Byte);
2537 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
2538 it
:= g_Items_ByIdx(id
);
2539 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
2541 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
2542 (FObj
.Vel
.Y
div 2)-Random(9));
2543 it
.positionChanged(); // this updates spatial accelerators
2547 if KillType
= K_HARDKILL
then // -5..+5; -5..0
2549 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
2550 (FObj
.Vel
.Y
div 2)-Random(6));
2552 else // -3..+3; -3..0
2554 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
2555 (FObj
.Vel
.Y
div 2)-Random(4));
2557 it
.positionChanged(); // this updates spatial accelerators
2560 if g_Game_IsNet
and g_Game_IsServer
then
2561 MH_SEND_ItemSpawn(True, id
);
2565 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
2566 Srv
:= g_Game_IsServer
;
2567 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
2568 if Srv
then FDeath
:= FDeath
+ 1;
2573 if not FPhysics
then
2579 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2581 if FLives
> 0 then FLives
:= FLives
- 1;
2582 if FLives
= 0 then FNoRespawn
:= True;
2585 // Номер типа смерти:
2588 K_SIMPLEKILL
: a
:= 1;
2590 K_EXTRAHARDKILL
: a
:= 3;
2595 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
2597 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
2604 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
2606 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
2607 K_EXTRAHARDKILL
, K_FALLKILL
:
2608 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
2611 // Переключаем состояние:
2615 K_HARDKILL
, K_EXTRAHARDKILL
:
2619 // Реакция монстров на смерть игрока:
2620 if (KillType
<> K_FALLKILL
) and (Srv
) then
2621 g_Monsters_killedp();
2623 if SpawnerUID
= FUID
then
2627 if gGameSettings
.GameMode
= GM_TDM
then
2628 Dec(gTeamStat
[FTeam
].Score
);
2629 if DoFrags
or (gGameSettings
.GameMode
= GM_TDM
) then
2635 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
2638 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
2639 begin // Убит другим игроком
2640 KP
:= g_Player_Get(SpawnerUID
);
2641 if (KP
<> nil) and Srv
then
2643 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
2644 if SameTeam(FUID
, SpawnerUID
) then
2654 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
2655 Inc(gTeamStat
[KP
.Team
].Score
,
2656 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
2658 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
2661 plr
:= g_Player_Get(SpawnerUID
);
2669 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
2673 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
2677 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
2682 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
2683 begin // Убит монстром
2684 mon
:= g_Monsters_ByUID(SpawnerUID
);
2688 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
2692 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
2696 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
2700 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
2705 else // Особые типы смерти
2708 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
2709 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
2710 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
2711 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
2712 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
2713 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
2719 for a
:= WP_FIRST
to WP_LAST
do
2723 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
2724 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
2725 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
2726 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
2727 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
2728 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
2729 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
2730 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
2731 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
2740 if R_ITEM_BACKPACK
in FRulez
then
2741 PushItem(ITEM_AMMO_BACKPACK
);
2743 // Выброс ракетного ранца:
2744 if FJetFuel
> 0 then
2745 PushItem(ITEM_JETPACK
);
2748 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) or
2749 (not LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
)) then
2751 if R_KEY_RED
in FRulez
then
2752 PushItem(ITEM_KEY_RED
);
2754 if R_KEY_GREEN
in FRulez
then
2755 PushItem(ITEM_KEY_GREEN
);
2757 if R_KEY_BLUE
in FRulez
then
2758 PushItem(ITEM_KEY_BLUE
);
2762 DropFlag(KillType
= K_FALLKILL
);
2765 FCorpse
:= g_Player_CreateCorpse(Self
);
2767 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
2768 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2774 for i
:= Low(gPlayers
) to High(gPlayers
) do
2776 if gPlayers
[i
] = nil then continue
;
2777 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
2780 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
2781 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
2786 OldLR
:= gLMSRespawn
;
2787 if (gGameSettings
.GameMode
= GM_COOP
) then
2791 // everyone is dead, restart the map
2792 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
2794 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
2795 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2796 gLMSRespawnTime
:= gTime
+ 5000;
2798 else if (a
= 1) then
2800 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
2801 if (gPlayers
[k
] = gPlayer1
) or
2802 (gPlayers
[k
] = gPlayer2
) then
2803 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
2804 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
2805 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
2808 else if (gGameSettings
.GameMode
= GM_TDM
) then
2810 if (ab
= 0) and (ar
<> 0) then
2813 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
2815 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
2816 Inc(gTeamStat
[TEAM_RED
].Score
);
2817 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2818 gLMSRespawnTime
:= gTime
+ 5000;
2820 else if (ar
= 0) and (ab
<> 0) then
2823 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
2825 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
2826 Inc(gTeamStat
[TEAM_BLUE
].Score
);
2827 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2828 gLMSRespawnTime
:= gTime
+ 5000;
2830 else if (ar
= 0) and (ab
= 0) then
2833 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
2835 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
2836 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2837 gLMSRespawnTime
:= gTime
+ 5000;
2840 else if (gGameSettings
.GameMode
= GM_DM
) then
2844 if gPlayers
[k
] <> nil then
2847 // survivor is the winner
2848 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
2850 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
2853 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2854 gLMSRespawnTime
:= gTime
+ 5000;
2856 else if (a
= 0) then
2858 // everyone is dead, restart the map
2859 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
2861 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
2862 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2863 gLMSRespawnTime
:= gTime
+ 5000;
2866 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
2868 if NetMode
= NET_SERVER
then
2869 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
)
2871 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
2877 MH_SEND_PlayerStats(FUID
);
2878 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
2879 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
2882 if srv
and FNoRespawn
then Spectate(True);
2883 FWantsInGame
:= True;
2886 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
2888 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
2889 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
2892 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
2894 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
2895 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
2898 procedure TPlayer
.MakeBloodSimple(Count
: Word);
2900 var Blood
: TModelBlood
;
2904 Blood
:= SELF
.FModel
.GetBlood();
2905 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
2906 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
2907 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
2908 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
2909 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
2910 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
2911 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
2912 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
2916 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
2918 var Blood
: TModelBlood
;
2922 Blood
:= SELF
.FModel
.GetBlood();
2923 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2924 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
2925 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
2926 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
2930 procedure TPlayer
.ProcessWeaponAction(Action
: Byte);
2932 if g_Game_IsClient
then Exit
;
2934 WP_PREV
: PrevWeapon();
2935 WP_NEXT
: NextWeapon();
2939 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
2941 if g_Game_IsClient
then Exit
;
2942 if Weapon
> High(FWeapon
) then Exit
;
2943 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
2946 procedure TPlayer
.resetWeaponQueue ();
2949 FNextWeapDelay
:= 0;
2952 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
2956 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
2957 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
2958 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
2959 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
2960 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
2961 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
2962 else result
:= (weapon
< length(FWeapon
));
2966 function TPlayer
.hasAmmoForShooting (weapon
: Byte): Boolean;
2970 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
2971 WEAPON_SHOTGUN1
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
2972 WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 1);
2973 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
2974 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
2975 WEAPON_PLASMA
: result
:= (FAmmo
[A_CELLS
] > 0);
2976 WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] >= 40);
2977 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
2978 else result
:= (weapon
< length(FWeapon
));
2982 function TPlayer
.shouldSwitch (weapon
: Byte; hadWeapon
: Boolean): Boolean;
2985 if (weapon
> WP_LAST
+ 1) then
2990 if (FWeapSwitchMode
= 1) and not hadWeapon
then
2992 else if (FWeapSwitchMode
= 2) then
2993 result
:= (FWeapPreferences
[weapon
] > FWeapPreferences
[FCurrWeap
]);
2996 // return 255 for "no switch"
2997 function TPlayer
.getNextWeaponIndex (): Byte;
3000 wantThisWeapon
: array[0..64] of Boolean;
3001 wwc
: Integer = 0; //HACK!
3004 result
:= 255; // default result: "no switch"
3005 //e_LogWriteFln('FSWITCHTOEMPTY: %s', [FSwitchToEmpty], TMsgType.Notify);
3006 // had weapon cycling on previous frame? remove that flag
3007 if (FNextWeap
and $2000) <> 0 then
3009 FNextWeap
:= FNextWeap
and $1FFF;
3010 FNextWeapDelay
:= 0;
3012 // cycling has priority
3013 if (FNextWeap
and $C000) <> 0 then
3015 if (FNextWeap
and $8000) <> 0 then
3019 FNextWeap
:= FNextWeap
or $2000; // we need this
3020 if FNextWeapDelay
> 0 then
3021 exit
; // cooldown time
3023 for i
:= 0 to High(FWeapon
) do
3025 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3026 if FWeapon
[cwi
] and maySwitch(cwi
) then
3028 //e_LogWriteFln(' SWITCH: cur=%d; new=%d %s %s', [FCurrWeap, cwi, FSwitchToEmpty, hasAmmoForWeapon(cwi)], TMsgType.Notify);
3029 result
:= Byte(cwi
);
3030 FNextWeapDelay
:= WEAPON_DELAY
;
3038 for i
:= 0 to High(wantThisWeapon
) do
3039 wantThisWeapon
[i
] := false;
3040 for i
:= 0 to High(FWeapon
) do
3041 if (FNextWeap
and (1 shl i
)) <> 0 then
3043 wantThisWeapon
[i
] := true;
3047 // exclude currently selected weapon from the set
3048 wantThisWeapon
[FCurrWeap
] := false;
3049 // slow down alterations a little
3052 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3053 // more than one weapon requested, assume "alteration" and check alteration delay
3054 if FNextWeapDelay
> 0 then
3060 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3061 // but clear all counters if no weapon should be switched
3067 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3068 // try weapons in descending order
3069 for i
:= High(FWeapon
) downto 0 do
3071 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3076 FNextWeapDelay
:= WEAPON_DELAY
* 2; // anyway, 'cause why not
3077 //e_LogWriteFln('FOUND %s %s %s', [result, FSwitchToEmpty, hasAmmoForWeapon(i)], TMsgType.Notify);
3081 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3085 procedure TPlayer
.RealizeCurrentWeapon();
3086 function switchAllowed (): Boolean;
3091 if FBFGFireCounter
<> -1 then
3093 if FTime
[T_SWITCH
] > gTime
then
3095 for i
:= WP_FIRST
to WP_LAST
do
3096 if FReloading
[i
] > 0 then
3104 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3105 //FNextWeap := FNextWeap and $1FFF;
3106 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3108 if not switchAllowed
then
3110 //HACK for weapon cycling
3111 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3115 nw
:= getNextWeaponIndex();
3117 if nw
= 255 then exit
; // don't reset anything here
3118 if nw
> High(FWeapon
) then
3120 // don't forget to reset queue here!
3121 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3129 FTime
[T_SWITCH
] := gTime
+156;
3130 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3131 FModel
.SetWeapon(FCurrWeap
);
3132 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3136 procedure TPlayer
.NextWeapon();
3138 if g_Game_IsClient
then Exit
;
3142 procedure TPlayer
.PrevWeapon();
3144 if g_Game_IsClient
then Exit
;
3148 procedure TPlayer
.SetWeapon(W
: Byte);
3150 if FCurrWeap
<> W
then
3151 if W
= WEAPON_SAW
then
3152 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3155 FModel
.SetWeapon(CurrWeap
);
3159 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3162 switchWeapon
: Byte = 255;
3163 hadWeapon
: Boolean = False;
3166 if g_Game_IsClient
then Exit
;
3168 // a = true - место спавна предмета:
3169 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3173 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3175 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3179 if gFlash
= 2 then Inc(FPickup
, 5);
3183 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3185 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3189 if gFlash
= 2 then Inc(FPickup
, 5);
3193 if FArmor
< PLAYER_AP_SOFT
then
3195 FArmor
:= PLAYER_AP_SOFT
;
3198 if gFlash
= 2 then Inc(FPickup
, 5);
3202 if FArmor
< PLAYER_AP_LIMIT
then
3204 FArmor
:= PLAYER_AP_LIMIT
;
3207 if gFlash
= 2 then Inc(FPickup
, 5);
3211 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
3213 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3217 if gFlash
= 2 then Inc(FPickup
, 5);
3221 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) or (FFireTime
> 0) then
3223 if FHealth
< PLAYER_HP_LIMIT
then
3224 FHealth
:= PLAYER_HP_LIMIT
;
3225 if FArmor
< PLAYER_AP_LIMIT
then
3226 FArmor
:= PLAYER_AP_LIMIT
;
3230 if gFlash
= 2 then Inc(FPickup
, 5);
3234 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3236 hadWeapon
:= FWeapon
[WEAPON_SAW
];
3237 switchWeapon
:= WEAPON_SAW
;
3238 FWeapon
[WEAPON_SAW
] := True;
3240 if gFlash
= 2 then Inc(FPickup
, 5);
3241 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3244 ITEM_WEAPON_SHOTGUN1
:
3245 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3247 // Нужно, чтобы не взять все пули сразу:
3248 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3249 hadWeapon
:= FWeapon
[WEAPON_SHOTGUN1
];
3250 switchWeapon
:= WEAPON_SHOTGUN1
;
3251 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3252 FWeapon
[WEAPON_SHOTGUN1
] := True;
3254 if gFlash
= 2 then Inc(FPickup
, 5);
3255 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3258 ITEM_WEAPON_SHOTGUN2
:
3259 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3261 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3262 hadWeapon
:= FWeapon
[WEAPON_SHOTGUN2
];
3263 switchWeapon
:= WEAPON_SHOTGUN2
;
3264 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3265 FWeapon
[WEAPON_SHOTGUN2
] := True;
3267 if gFlash
= 2 then Inc(FPickup
, 5);
3268 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3271 ITEM_WEAPON_CHAINGUN
:
3272 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3274 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3275 hadWeapon
:= FWeapon
[WEAPON_CHAINGUN
];
3276 switchWeapon
:= WEAPON_CHAINGUN
;
3277 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3278 FWeapon
[WEAPON_CHAINGUN
] := True;
3280 if gFlash
= 2 then Inc(FPickup
, 5);
3281 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3284 ITEM_WEAPON_ROCKETLAUNCHER
:
3285 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3287 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3288 switchWeapon
:= WEAPON_ROCKETLAUNCHER
;
3289 hadWeapon
:= FWeapon
[WEAPON_ROCKETLAUNCHER
];
3290 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3291 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3293 if gFlash
= 2 then Inc(FPickup
, 5);
3294 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3298 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3300 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3301 switchWeapon
:= WEAPON_PLASMA
;
3302 hadWeapon
:= FWeapon
[WEAPON_PLASMA
];
3303 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3304 FWeapon
[WEAPON_PLASMA
] := True;
3306 if gFlash
= 2 then Inc(FPickup
, 5);
3307 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3311 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3313 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3314 switchWeapon
:= WEAPON_BFG
;
3315 hadWeapon
:= FWeapon
[WEAPON_BFG
];
3316 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3317 FWeapon
[WEAPON_BFG
] := True;
3319 if gFlash
= 2 then Inc(FPickup
, 5);
3320 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3323 ITEM_WEAPON_SUPERPULEMET
:
3324 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3326 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3327 switchWeapon
:= WEAPON_SUPERPULEMET
;
3328 hadWeapon
:= FWeapon
[WEAPON_SUPERPULEMET
];
3329 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3330 FWeapon
[WEAPON_SUPERPULEMET
] := True;
3332 if gFlash
= 2 then Inc(FPickup
, 5);
3333 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3336 ITEM_WEAPON_FLAMETHROWER
:
3337 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
3339 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
3340 switchWeapon
:= WEAPON_FLAMETHROWER
;
3341 hadWeapon
:= FWeapon
[WEAPON_FLAMETHROWER
];
3342 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3343 FWeapon
[WEAPON_FLAMETHROWER
] := True;
3345 if gFlash
= 2 then Inc(FPickup
, 5);
3346 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3350 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3352 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3355 if gFlash
= 2 then Inc(FPickup
, 5);
3358 ITEM_AMMO_BULLETS_BOX
:
3359 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3361 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3364 if gFlash
= 2 then Inc(FPickup
, 5);
3368 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3370 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3373 if gFlash
= 2 then Inc(FPickup
, 5);
3376 ITEM_AMMO_SHELLS_BOX
:
3377 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3379 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
3382 if gFlash
= 2 then Inc(FPickup
, 5);
3386 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3388 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3391 if gFlash
= 2 then Inc(FPickup
, 5);
3394 ITEM_AMMO_ROCKET_BOX
:
3395 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3397 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
3400 if gFlash
= 2 then Inc(FPickup
, 5);
3404 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3406 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3409 if gFlash
= 2 then Inc(FPickup
, 5);
3413 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3415 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
3418 if gFlash
= 2 then Inc(FPickup
, 5);
3422 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
3424 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3427 if gFlash
= 2 then Inc(FPickup
, 5);
3431 if not(R_ITEM_BACKPACK
in FRulez
) or
3432 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
3433 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
3434 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
3435 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
3436 (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) then
3438 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
3439 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
3440 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
3441 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
3442 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
3444 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3445 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3446 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3447 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3448 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3449 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3450 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3451 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3452 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
3453 IncMax(FAmmo
[A_FUEL
], 50, FMaxAmmo
[A_FUEL
]);
3455 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
3458 if gFlash
= 2 then Inc(FPickup
, 5);
3462 if not(R_KEY_RED
in FRulez
) then
3464 Include(FRulez
, R_KEY_RED
);
3466 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3467 if gFlash
= 2 then Inc(FPickup
, 5);
3468 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3472 if not(R_KEY_GREEN
in FRulez
) then
3474 Include(FRulez
, R_KEY_GREEN
);
3476 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3477 if gFlash
= 2 then Inc(FPickup
, 5);
3478 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3482 if not(R_KEY_BLUE
in FRulez
) then
3484 Include(FRulez
, R_KEY_BLUE
);
3486 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3487 if gFlash
= 2 then Inc(FPickup
, 5);
3488 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3492 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
3494 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
3498 if gFlash
= 2 then Inc(FPickup
, 5);
3502 if FAir
< AIR_MAX
then
3507 if gFlash
= 2 then Inc(FPickup
, 5);
3512 if not (R_BERSERK
in FRulez
) then
3514 Include(FRulez
, R_BERSERK
);
3515 if (FBFGFireCounter
= -1) then
3517 FCurrWeap
:= WEAPON_KASTET
;
3519 FModel
.SetWeapon(WEAPON_KASTET
);
3524 if gFlash
= 2 then Inc(FPickup
, 5);
3526 FBerserk
:= gTime
+30000;
3531 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3533 if FHealth
< PLAYER_HP_SOFT
then FHealth
:= PLAYER_HP_SOFT
;
3534 FBerserk
:= gTime
+30000;
3542 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
3544 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
3548 if gFlash
= 2 then Inc(FPickup
, 5);
3552 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
3554 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
3558 if gFlash
= 2 then Inc(FPickup
, 5);
3562 if FArmor
< PLAYER_AP_LIMIT
then
3564 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
3567 if gFlash
= 2 then Inc(FPickup
, 5);
3571 if FJetFuel
< JET_MAX
then
3573 FJetFuel
:= JET_MAX
;
3576 if gFlash
= 2 then Inc(FPickup
, 5);
3580 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
3582 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
3585 if gFlash
= 2 then Inc(FPickup
, 5);
3589 if (shouldSwitch(switchWeapon
, hadWeapon
)) then
3590 QueueWeaponSwitch(switchWeapon
);
3593 procedure TPlayer
.Touch();
3597 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
3600 // Бросить флаг товарищу:
3601 if gGameSettings
.GameMode
= GM_CTF
then
3606 procedure TPlayer
.Push(vx
, vy
: Integer);
3608 if (not FPhysics
) and FGhost
then
3610 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
3611 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
3612 if g_Game_IsNet
and g_Game_IsServer
then
3613 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
3616 procedure TPlayer
.Reset(Force
: Boolean);
3622 FTime
[T_RESPAWN
] := 0;
3623 FTime
[T_FLAGCAP
] := 0;
3639 FSpectator
:= False;
3642 FSpectatePlayer
:= -1;
3643 FNoRespawn
:= False;
3645 FLives
:= gGameSettings
.MaxLives
;
3650 procedure TPlayer
.SoftReset();
3658 FBFGFireCounter
:= -1;
3666 SetAction(A_STAND
, True);
3669 function TPlayer
.GetRespawnPoint(): Byte;
3674 // На будущее: FSpawn - игрок уже играл и перерождается
3676 // Одиночная игра/кооператив
3677 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
3679 if Self
= gPlayer1
then
3681 // player 1 should try to spawn on the player 1 point
3682 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) > 0 then
3683 Exit(RESPAWNPOINT_PLAYER1
)
3684 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) > 0 then
3685 Exit(RESPAWNPOINT_PLAYER2
);
3687 else if Self
= gPlayer2
then
3689 // player 2 should try to spawn on the player 2 point
3690 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) > 0 then
3691 Exit(RESPAWNPOINT_PLAYER2
)
3692 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) > 0 then
3693 Exit(RESPAWNPOINT_PLAYER1
);
3697 // other players randomly pick either the first or the second point
3698 c
:= IfThen((Random(2) = 0), RESPAWNPOINT_PLAYER1
, RESPAWNPOINT_PLAYER2
);
3699 if g_Map_GetPointCount(c
) > 0 then
3701 // try the other one
3702 c
:= IfThen((c
= RESPAWNPOINT_PLAYER1
), RESPAWNPOINT_PLAYER2
, RESPAWNPOINT_PLAYER1
);
3703 if g_Map_GetPointCount(c
) > 0 then
3709 if gGameSettings
.GameMode
= GM_DM
then
3711 // try DM points first
3712 if g_Map_GetPointCount(RESPAWNPOINT_DM
) > 0 then
3713 Exit(RESPAWNPOINT_DM
);
3717 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
3719 // try team points first
3720 c
:= RESPAWNPOINT_DM
;
3721 if FTeam
= TEAM_RED
then
3722 c
:= RESPAWNPOINT_RED
3723 else if FTeam
= TEAM_BLUE
then
3724 c
:= RESPAWNPOINT_BLUE
;
3725 if g_Map_GetPointCount(c
) > 0 then
3729 // still haven't found a spawnpoint, try random shit
3730 Result
:= g_Map_GetRandomPointType();
3733 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
3735 RespawnPoint
: TRespawnPoint
;
3741 FBFGFireCounter
:= -1;
3748 if not g_Game_IsServer
then
3752 FWantsInGame
:= True;
3753 FJustTeleported
:= True;
3756 FTime
[T_RESPAWN
] := 0;
3760 // if server changes MaxLives we gotta be ready
3761 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
3763 // Еще нельзя возродиться:
3764 if FTime
[T_RESPAWN
] > gTime
then
3767 // Просрал все жизни:
3770 if not FSpectator
then Spectate(True);
3771 FWantsInGame
:= True;
3775 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
3776 begin // "Своя игра"
3777 // Берсерк не сохраняется между уровнями:
3778 FRulez
:= FRulez
-[R_BERSERK
];
3780 else // "Одиночная игра"/"Кооп"
3782 // Берсерк и ключи не сохраняются между уровнями:
3783 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
3786 // Получаем точку спауна игрока:
3787 c
:= GetRespawnPoint();
3792 // Воскрешение без оружия:
3795 FHealth
:= Round(PLAYER_HP_SOFT
* (FHandicap
/ 100));
3801 for a
:= WP_FIRST
to WP_LAST
do
3803 FWeapon
[a
] := False;
3807 FWeapon
[WEAPON_PISTOL
] := True;
3808 FWeapon
[WEAPON_KASTET
] := True;
3809 FCurrWeap
:= WEAPON_PISTOL
;
3812 FModel
.SetWeapon(FCurrWeap
);
3814 for b
:= A_BULLETS
to A_HIGH
do
3817 FAmmo
[A_BULLETS
] := 50;
3819 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
3820 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
3821 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
3822 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
3823 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
3825 if (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) and
3826 LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
) then
3827 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
3832 // Получаем координаты точки возрождения:
3833 if not g_Map_GetPoint(c
, RespawnPoint
) then
3835 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3839 // Установка координат и сброс всех параметров:
3840 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
3841 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
3842 FObj
.oldX
:= FObj
.X
; // don't interpolate after respawn
3843 FObj
.oldY
:= FObj
.Y
;
3849 FDirection
:= RespawnPoint
.Direction
;
3850 if FDirection
= TDirection
.D_LEFT
then
3855 SetAction(A_STAND
, True);
3856 FModel
.Direction
:= FDirection
;
3858 for a
:= Low(FTime
) to High(FTime
) do
3861 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
3864 // Respawn invulnerability
3865 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.SpawnInvul
> 0) then
3867 FMegaRulez
[MR_INVUL
] := gTime
+ gGameSettings
.SpawnInvul
* 1000;
3868 FSpawnInvul
:= FMegaRulez
[MR_INVUL
];
3873 FCanJetpack
:= False;
3880 // Анимация возрождения:
3881 if (not gLoadGameMode
) and (not Silent
) then
3884 R_GFX_TELEPORT_FAST
,
3885 FObj
.X
+ PLAYER_RECT
.X
+ (PLAYER_RECT
.Width
div 2) - 32,
3886 FObj
.Y
+ PLAYER_RECT
.Y
+ (PLAYER_RECT
.Height
div 2) - 32
3891 FSpectator
:= False;
3894 FSpectatePlayer
:= -1;
3897 if (gPlayer1
= nil) and (gSpectLatchPID1
= FUID
) then
3899 if (gPlayer2
= nil) and (gSpectLatchPID2
= FUID
) then
3902 if g_Game_IsNet
then
3904 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
3905 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
3907 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
3908 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
3913 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
3916 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
3917 else if (not NoMove
) then
3919 GameX
:= gMapInfo
.Width
div 2;
3920 GameY
:= gMapInfo
.Height
div 2;
3929 FWantsInGame
:= False;
3935 if Self
= gPlayer1
then
3937 gSpectLatchPID1
:= FUID
;
3940 else if Self
= gPlayer2
then
3942 gSpectLatchPID2
:= FUID
;
3947 if g_Game_IsNet
then
3948 MH_SEND_PlayerStats(FUID
);
3951 procedure TPlayer
.SwitchNoClip
;
3955 FGhost
:= not FGhost
;
3956 FPhysics
:= not FGhost
;
3968 procedure TPlayer
.Run(Direction
: TDirection
);
3969 {$IFDEF ENABLE_GIBS}
3973 if MAX_RUNVEL
> 8 then
3977 if Direction
= TDirection
.D_LEFT
then
3979 if FObj
.Vel
.X
> -MAX_RUNVEL
then
3980 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
3983 if FObj
.Vel
.X
< MAX_RUNVEL
then
3984 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
3986 {$IFDEF ENABLE_GIBS}
3987 // Возможно, пинаем куски:
3988 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
3990 b
:= Abs(FObj
.Vel
.X
);
3991 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
3992 for a
:= 0 to High(gGibs
) do
3994 if gGibs
[a
].alive
and
3995 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
3996 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
3999 if FObj
.Vel
.X
< 0 then
4001 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // налево
4005 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // направо
4007 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4016 procedure TPlayer
.SeeDown();
4018 SetAction(A_SEEDOWN
);
4020 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4022 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4025 procedure TPlayer
.SeeUp();
4029 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4031 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4034 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4042 A_ATTACK
: Prior
:= 2;
4043 A_SEEUP
: Prior
:= 1;
4044 A_SEEDOWN
: Prior
:= 1;
4045 A_ATTACKUP
: Prior
:= 2;
4046 A_ATTACKDOWN
: Prior
:= 2;
4051 if (Prior
> FActionPrior
) or Force
then
4052 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4054 FActionPrior
:= Prior
;
4055 FActionAnim
:= Action
;
4056 FActionForce
:= Force
;
4057 FActionChanged
:= True;
4060 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4063 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4065 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4066 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4067 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4068 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4071 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4075 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4077 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4078 if g_Game_IsServer
and g_Game_IsNet
then
4079 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4083 FJustTeleported
:= True;
4087 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4090 R_GFX_TELEPORT_FAST
,
4091 FObj
.X
+ PLAYER_RECT
.X
+ (PLAYER_RECT
.Width
div 2) - 32,
4092 FObj
.Y
+ PLAYER_RECT
.Y
+ (PLAYER_RECT
.Height
div 2) - 32
4095 if g_Game_IsServer
and g_Game_IsNet
then
4096 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4097 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4101 FObj
.X
:= X
-PLAYER_RECT
.X
;
4102 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4103 FObj
.oldX
:= FObj
.X
; // don't interpolate after respawn
4104 FObj
.oldY
:= FObj
.Y
;
4105 if FAlive
and FGhost
then
4111 if not g_Game_IsNet
then
4115 SetDirection(TDirection
.D_LEFT
);
4121 SetDirection(TDirection
.D_RIGHT
);
4127 if FDirection
= TDirection
.D_RIGHT
then
4129 SetDirection(TDirection
.D_LEFT
);
4134 SetDirection(TDirection
.D_RIGHT
);
4144 R_GFX_TELEPORT_FAST
,
4145 FObj
.X
+ PLAYER_RECT
.X
+ (PLAYER_RECT
.Width
div 2) - 32,
4146 FObj
.Y
+ PLAYER_RECT
.Y
+ (PLAYER_RECT
.Height
div 2) - 32
4149 if g_Game_IsServer
and g_Game_IsNet
then
4150 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4151 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4158 function nonz(a
: Single): Single;
4166 function TPlayer
.refreshCorpse(): Boolean;
4172 if FAlive
or FSpectator
then
4174 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
4176 for i
:= 0 to High(gCorpses
) do
4177 if gCorpses
[i
] <> nil then
4178 if gCorpses
[i
].FPlayerUID
= FUID
then
4186 function TPlayer
.getCameraObj(): TObj
;
4188 if (not FAlive
) and (not FSpectator
) and
4189 (FCorpse
>= 0) and (FCorpse
< Length(gCorpses
)) and
4190 (gCorpses
[FCorpse
] <> nil) and (gCorpses
[FCorpse
].FPlayerUID
= FUID
) then
4192 gCorpses
[FCorpse
].FObj
.slopeUpLeft
:= FObj
.slopeUpLeft
;
4193 Result
:= gCorpses
[FCorpse
].FObj
;
4201 procedure TPlayer
.PreUpdate();
4203 FSlopeOld
:= FObj
.slopeUpLeft
;
4204 FIncCamOld
:= FIncCam
;
4205 FObj
.oldX
:= FObj
.X
;
4206 FObj
.oldY
:= FObj
.Y
;
4209 procedure TPlayer
.Update();
4212 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4213 blockmon
, headwater
, dospawn
: Boolean;
4218 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4219 AnyServer
:= g_Game_IsServer
;
4221 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4222 DoLerp(NetInterpLevel
+ 1)
4228 if (FClientID
>= 0) and (NetClients
[FClientID
].Peer
<> nil) then
4230 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4231 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4232 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4243 if FPunchAnim
.played
then
4246 if FAlive
and (gFly
or FJetpack
) then
4249 if FDirection
= TDirection
.D_LEFT
then
4254 if FAlive
and (not FGhost
) then
4256 if FKeys
[KEY_UP
].Pressed
then
4258 if FKeys
[KEY_DOWN
].Pressed
then
4262 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4265 i
:= g_basic
.Sign(FIncCam
);
4266 FIncCam
:= Abs(FIncCam
);
4267 DecMin(FIncCam
, 5, 0);
4268 FIncCam
:= FIncCam
*i
;
4271 if gTime
mod (GAME_TICK
*2) <> 0 then
4273 if (FObj
.Vel
.X
= 0) and FAlive
then
4275 if FKeys
[KEY_LEFT
].Pressed
then
4276 Run(TDirection
.D_LEFT
);
4277 if FKeys
[KEY_RIGHT
].Pressed
then
4278 Run(TDirection
.D_RIGHT
);
4283 g_Obj_Move(@FObj
, True, True, True);
4284 positionChanged(); // this updates spatial accelerators
4290 FActionChanged
:= False;
4294 // Let alive player do some actions
4295 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
4296 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
4297 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire()
4303 if NetServer
then MH_SEND_PlayerStats(FUID
);
4306 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
4307 if FKeys
[KEY_JUMP
].Pressed
then Jump()
4310 if AnyServer
and FJetpack
then
4314 if NetServer
then MH_SEND_PlayerStats(FUID
);
4316 FCanJetpack
:= True;
4323 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
4325 if FKeys
[k
].Pressed
then
4333 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4336 if (FTime
[T_RESPAWN
] <= gTime
) and
4337 gGameOn
and (not FAlive
) then
4339 if (g_Player_GetCount() > 1) then
4343 gExit
:= EXIT_RESTART
;
4348 // Dead spectator actions
4351 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
4352 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
4356 if (FSpectatePlayer
>= High(gPlayers
)) then
4357 FSpectatePlayer
:= -1
4361 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
4362 if gPlayers
[I
] <> nil then
4363 if gPlayers
[I
].alive
then
4364 if gPlayers
[I
].UID
<> FUID
then
4366 FSpectatePlayer
:= I
;
4371 if not SetSpect
then FSpectatePlayer
:= -1;
4382 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
4384 FYTo
:= FObj
.Y
- 32;
4385 FSpectatePlayer
:= -1;
4387 if FKeys
[KEY_DOWN
].Pressed
then
4389 FYTo
:= FObj
.Y
+ 32;
4390 FSpectatePlayer
:= -1;
4392 if FKeys
[KEY_LEFT
].Pressed
then
4394 FXTo
:= FObj
.X
- 32;
4395 FSpectatePlayer
:= -1;
4397 if FKeys
[KEY_RIGHT
].Pressed
then
4399 FXTo
:= FObj
.X
+ 32;
4400 FSpectatePlayer
:= -1;
4403 if (FXTo
< -64) then
4405 else if (FXTo
> gMapInfo
.Width
+ 32) then
4406 FXTo
:= gMapInfo
.Width
+ 32;
4407 if (FYTo
< -72) then
4409 else if (FYTo
> gMapInfo
.Height
+ 32) then
4410 FYTo
:= gMapInfo
.Height
+ 32;
4415 g_Obj_Move(@FObj
, True, True, True);
4416 positionChanged(); // this updates spatial accelerators
4423 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
4424 if gPlayers
[FSpectatePlayer
] <> nil then
4425 if gPlayers
[FSpectatePlayer
].alive
then
4427 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
4428 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
4432 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
4433 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
4434 PANEL_BLOCKMON
, True);
4435 headwater
:= HeadInLiquid(0, 0);
4437 // Сопротивление воздуха:
4438 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
4439 if FObj
.Vel
.X
<> 0 then
4440 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
4442 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
4443 DecMin(FPain
, 5, 0);
4444 DecMin(FPickup
, 1, 0);
4446 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
4448 // Обнулить действия примочек, чтобы фон пропал
4449 FMegaRulez
[MR_SUIT
] := 0;
4450 FMegaRulez
[MR_INVUL
] := 0;
4451 FMegaRulez
[MR_INVIS
] := 0;
4452 Kill(K_FALLKILL
, 0, HIT_FALL
);
4459 if FCurrWeap
= WEAPON_SAW
then
4460 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
4461 FSawSoundSelect
.IsPlaying()) then
4462 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
4465 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
4466 (not FJetSoundOff
.IsPlaying()) then
4468 FJetSoundFly
.SetPosition(0);
4469 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
4472 for b
:= WP_FIRST
to WP_LAST
do
4473 if FReloading
[b
] > 0 then
4479 if FShellTimer
> -1 then
4480 if FShellTimer
= 0 then
4482 if FShellType
= SHELL_SHELL
then
4483 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4484 GameVelX
, GameVelY
-2, SHELL_SHELL
)
4485 else if FShellType
= SHELL_DBLSHELL
then
4487 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4488 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
4489 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4490 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
4493 end else Dec(FShellTimer
);
4495 if (FBFGFireCounter
> -1) then
4496 if FBFGFireCounter
= 0 then
4500 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
4501 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
4502 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
4503 yd
:= wy
+firediry();
4504 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
4505 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
4506 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
4507 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
4508 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
4511 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
4512 FBFGFireCounter
:= -1;
4515 FBFGFireCounter
:= 0
4517 Dec(FBFGFireCounter
);
4519 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
4521 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
4523 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
4526 if (headwater
or blockmon
) then
4532 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
4535 else if (FAir
mod 31 = 0) and not blockmon
then
4538 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
4541 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
4542 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
4544 end else if FAir
< AIR_DEF
then
4547 if FFireTime
> 0 then
4549 if BodyInLiquid(0, 0) then
4554 else if FMegaRulez
[MR_SUIT
] >= gTime
then
4556 if FMegaRulez
[MR_SUIT
] = gTime
then
4563 if FFirePainTime
<= 0 then
4565 if g_Game_IsServer
then
4566 Damage(2, FFireAttacker
, 0, 0, HIT_FLAME
);
4567 FFirePainTime
:= 12 - FFireTime
div 12;
4569 FFirePainTime
:= FFirePainTime
- 1;
4570 FFireTime
:= FFireTime
- 1;
4571 if ((FFireTime
mod 33) = 0) and (FMegaRulez
[MR_INVUL
] < gTime
) then
4572 FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
);
4573 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
4574 MH_SEND_PlayerStats(FUID
);
4578 if FDamageBuffer
> 0 then
4580 if FDamageBuffer
>= 9 then
4584 if FDamageBuffer
< 30 then i
:= 9
4585 else if FDamageBuffer
< 100 then i
:= 18
4589 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
4590 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
4591 FHealth
:= FHealth
-ii
;
4594 FHealth
:= FHealth
+FArmor
;
4599 if FHealth
<= 0 then
4600 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
4601 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
4602 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
4604 if FAlive
and ((FLastHit
<> HIT_FLAME
) or (FFireTime
<= 0)) then
4606 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
4607 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
4608 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
4609 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
4616 end; // if FAlive then ...
4618 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
4620 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
4621 FModel
.AnimState
.MinLength
:= i
;
4622 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
4624 if (FModel
.AnimState
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
4625 then SetAction(A_STAND
, True);
4627 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.GetFire()) then FModel
.Update
;
4629 for b
:= Low(FKeys
) to High(FKeys
) do
4630 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
4634 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
4636 x
:= FObj
.X
+PLAYER_RECT
.X
;
4637 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
4638 w
:= PLAYER_RECT
.Width
;
4639 h
:= PLAYER_RECT
.Height
;
4643 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
4645 if (dx
<> 0) or (dy
<> 0) then
4654 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
4656 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
4657 FObj
.Y
+PLAYER_RECT
.Y
,
4664 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
4666 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
4667 FObj
.Y
+PLAYER_RECT
.Y
,
4671 Panel
.Width
, Panel
.Height
);
4674 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
4676 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
4677 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
4678 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
4679 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
4682 function g_Player_ValidName(Name
: string): Boolean;
4688 if gPlayers
= nil then Exit
;
4690 for a
:= 0 to High(gPlayers
) do
4691 if gPlayers
[a
] <> nil then
4692 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
4699 procedure TPlayer
.SetDirection(Direction
: TDirection
);
4703 d
:= FModel
.Direction
;
4705 FModel
.Direction
:= Direction
;
4706 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
4708 FDirection
:= Direction
;
4711 function TPlayer
.GetKeys(): Byte;
4715 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
4716 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
4717 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
4719 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
4720 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
4723 procedure TPlayer
.Use();
4727 if FTime
[T_USE
] > gTime
then Exit
;
4729 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
4730 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
4732 for a
:= 0 to High(gPlayers
) do
4733 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
4734 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
4735 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
4736 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
4738 gPlayers
[a
].Touch();
4739 if g_Game_IsNet
and g_Game_IsServer
then
4740 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
4743 FTime
[T_USE
] := gTime
+120;
4746 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
4749 visible
: Boolean = True;
4750 WX
, WY
, XD
, YD
: Integer;
4762 if R_BERSERK
in FRulez
then
4764 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
4765 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
4766 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
4769 locobj
.rect
.Width
:= 39;
4770 locobj
.rect
.Height
:= 52;
4771 locobj
.Vel
.X
:= (xd
-wx
) div 2;
4772 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
4773 locobj
.Accel
.X
:= xd
-wx
;
4774 locobj
.Accel
.y
:= yd
-wy
;
4776 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
4777 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
4779 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
4783 FPain
:= min(FPain
+ 25, 50);
4785 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
4790 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
4791 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
4793 FSawSoundSelect
.Stop();
4795 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
4797 else if not FSawSoundHit
.IsPlaying() then
4799 FSawSoundSelect
.Stop();
4800 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
4806 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
4807 FFireAngle
:= FAngle
;
4808 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4809 GameVelX
, GameVelY
-2, SHELL_BULLET
);
4814 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
4815 FFireAngle
:= FAngle
;
4817 FShellType
:= SHELL_SHELL
;
4822 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
4823 FFireAngle
:= FAngle
;
4825 FShellType
:= SHELL_DBLSHELL
;
4830 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
4831 FFireAngle
:= FAngle
;
4832 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4833 GameVelX
, GameVelY
-2, SHELL_BULLET
);
4836 WEAPON_ROCKETLAUNCHER
:
4838 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
4839 FFireAngle
:= FAngle
;
4844 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
4845 FFireAngle
:= FAngle
;
4850 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
4851 FFireAngle
:= FAngle
;
4854 WEAPON_SUPERPULEMET
:
4856 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
4857 FFireAngle
:= FAngle
;
4858 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4859 GameVelX
, GameVelY
-2, SHELL_SHELL
);
4862 WEAPON_FLAMETHROWER
:
4864 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
4866 FFireAngle
:= FAngle
;
4870 if not visible
then Exit
;
4872 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
4873 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
4874 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
4877 procedure TPlayer
.DoLerp(Level
: Integer = 2);
4879 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
4880 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
4883 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
4889 if FJustTeleported
or (NetInterpLevel
< 1) then
4893 if FJustTeleported
then
4895 FObj
.oldX
:= FObj
.X
;
4896 FObj
.oldY
:= FObj
.Y
;
4901 AX
:= Abs(FXTo
- FObj
.X
);
4902 AY
:= Abs(FYTo
- FObj
.Y
);
4903 if (AX
> 32) or (AX
<= NetInterpLevel
) then
4905 if (AY
> 32) or (AY
<= NetInterpLevel
) then
4910 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
4912 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
4913 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
4914 PANEL_LIFTUP
, False) then Result
:= -1
4916 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
4917 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
4918 PANEL_LIFTDOWN
, False) then Result
:= 1
4922 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
4929 if Flag
= FLAG_NONE
then
4932 if not g_Game_IsServer
then Exit
;
4934 // Принес чужой флаг на свою базу:
4935 if (Flag
= FTeam
) and
4936 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
4937 (FFlag
<> FLAG_NONE
) then
4939 if FFlag
= FLAG_RED
then
4940 s
:= _lc
[I_PLAYER_FLAG_RED
]
4942 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
4944 evtype
:= FLAG_STATE_SCORED
;
4946 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
4947 Insert('.', ts
, Length(ts
) + 1 - 3);
4948 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
4950 g_Map_ResetFlag(FFlag
);
4951 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
4953 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
4954 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
4955 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
4960 if not sound_cap_flag
[a
].IsPlaying() then
4961 sound_cap_flag
[a
].Play();
4963 gTeamStat
[FTeam
].Score
+= 1;
4966 if g_Game_IsNet
then
4968 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
4972 gFlags
[FFlag
].CaptureTime
:= 0;
4977 // Подобрал свой флаг - вернул его на базу:
4978 if (Flag
= FTeam
) and
4979 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
4981 if Flag
= FLAG_RED
then
4982 s
:= _lc
[I_PLAYER_FLAG_RED
]
4984 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
4986 evtype
:= FLAG_STATE_RETURNED
;
4987 gFlags
[Flag
].CaptureTime
:= 0;
4989 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
4991 g_Map_ResetFlag(Flag
);
4992 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
4994 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
4995 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
4996 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5001 if not sound_ret_flag
[a
].IsPlaying() then
5002 sound_ret_flag
[a
].Play();
5005 if g_Game_IsNet
then
5007 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5013 // Подобрал чужой флаг:
5014 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5018 if Flag
= FLAG_RED
then
5019 s
:= _lc
[I_PLAYER_FLAG_RED
]
5021 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5023 evtype
:= FLAG_STATE_CAPTURED
;
5025 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5027 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5029 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5031 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5032 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5033 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5038 if not sound_get_flag
[a
].IsPlaying() then
5039 sound_get_flag
[a
].Play();
5042 if g_Game_IsNet
then
5044 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5050 procedure TPlayer
.SetFlag(Flag
: Byte);
5053 if FModel
<> nil then
5054 FModel
.SetFlag(FFlag
);
5057 function TPlayer
.TryDropFlag(): Boolean;
5059 if LongBool(gGameSettings
.Options
and GAME_OPTION_ALLOWDROPFLAG
) then
5060 Result
:= DropFlag(False, LongBool(gGameSettings
.Options
and GAME_OPTION_THROWFLAG
))
5065 function TPlayer
.DropFlag(Silent
: Boolean = True; DoThrow
: Boolean = False): Boolean;
5072 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5074 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5075 with gFlags
[FFlag
] do
5079 Direction
:= FDirection
;
5080 State
:= FLAG_STATE_DROPPED
;
5084 xv
:= FObj
.Vel
.X
+ IfThen(Direction
= TDirection
.D_RIGHT
, 10, -10);
5085 yv
:= FObj
.Vel
.Y
- 2;
5089 xv
:= (FObj
.Vel
.X
div 2);
5090 yv
:= (FObj
.Vel
.Y
div 2) - 2;
5092 g_Obj_Push(@Obj
, xv
, yv
);
5094 positionChanged(); // this updates spatial accelerators
5096 if FFlag
= FLAG_RED
then
5097 s
:= _lc
[I_PLAYER_FLAG_RED
]
5099 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5101 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5102 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5104 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5105 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5106 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5111 if (not Silent
) and (not sound_lost_flag
[a
].IsPlaying()) then
5112 sound_lost_flag
[a
].Play();
5114 if g_Game_IsNet
then
5115 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5121 procedure TPlayer
.GetSecret();
5123 if (self
= gPlayer1
) or (self
= gPlayer2
) then
5125 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [FName
]), True);
5126 g_Sound_PlayEx('SOUND_GAME_SECRET');
5131 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5133 Assert(Key
<= High(FKeys
));
5135 FKeys
[Key
].Pressed
:= True;
5136 FKeys
[Key
].Time
:= Time
;
5139 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5141 Result
:= FKeys
[K
].Pressed
;
5144 procedure TPlayer
.ReleaseKeys();
5148 for a
:= Low(FKeys
) to High(FKeys
) do
5150 FKeys
[a
].Pressed
:= False;
5155 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5159 function TPlayer
.firediry(): Integer;
5161 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5162 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5166 procedure TPlayer
.RememberState();
5169 SavedState
: TPlayerSavedState
;
5171 SavedState
.Health
:= FHealth
;
5172 SavedState
.Armor
:= FArmor
;
5173 SavedState
.Air
:= FAir
;
5174 SavedState
.JetFuel
:= FJetFuel
;
5175 SavedState
.CurrWeap
:= FCurrWeap
;
5176 SavedState
.NextWeap
:= FNextWeap
;
5177 SavedState
.NextWeapDelay
:= FNextWeapDelay
;
5178 for i
:= Low(FWeapon
) to High(FWeapon
) do
5179 SavedState
.Weapon
[i
] := FWeapon
[i
];
5180 for i
:= Low(FAmmo
) to High(FAmmo
) do
5181 SavedState
.Ammo
[i
] := FAmmo
[i
];
5182 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
5183 SavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5184 SavedState
.Rulez
:= FRulez
- [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5186 FSavedStateNum
:= -1;
5187 for i
:= Low(SavedStates
) to High(SavedStates
) do
5188 if not SavedStates
[i
].Used
then
5190 FSavedStateNum
:= i
;
5193 if FSavedStateNum
< 0 then
5195 SetLength(SavedStates
, Length(SavedStates
) + 1);
5196 FSavedStateNum
:= High(SavedStates
);
5199 SavedState
.Used
:= True;
5200 SavedStates
[FSavedStateNum
] := SavedState
;
5203 procedure TPlayer
.RecallState();
5206 SavedState
: TPlayerSavedState
;
5208 if(FSavedStateNum
< 0) or (FSavedStateNum
> High(SavedStates
)) then
5211 SavedState
:= SavedStates
[FSavedStateNum
];
5212 SavedStates
[FSavedStateNum
].Used
:= False;
5213 FSavedStateNum
:= -1;
5215 FHealth
:= SavedState
.Health
;
5216 FArmor
:= SavedState
.Armor
;
5217 FAir
:= SavedState
.Air
;
5218 FJetFuel
:= SavedState
.JetFuel
;
5219 FCurrWeap
:= SavedState
.CurrWeap
;
5220 FNextWeap
:= SavedState
.NextWeap
;
5221 FNextWeapDelay
:= SavedState
.NextWeapDelay
;
5222 for i
:= Low(FWeapon
) to High(FWeapon
) do
5223 FWeapon
[i
] := SavedState
.Weapon
[i
];
5224 for i
:= Low(FAmmo
) to High(FAmmo
) do
5225 FAmmo
[i
] := SavedState
.Ammo
[i
];
5226 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
5227 FMaxAmmo
[i
] := SavedState
.MaxAmmo
[i
];
5228 FRulez
:= SavedState
.Rulez
;
5230 if gGameSettings
.GameType
= GT_SERVER
then
5231 MH_SEND_PlayerStats(FUID
);
5234 procedure TPlayer
.SaveState (st
: TStream
);
5240 utils
.writeSign(st
, 'PLYR');
5241 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
5243 utils
.writeBool(st
, FIamBot
);
5245 utils
.writeInt(st
, Word(FUID
));
5247 utils
.writeStr(st
, FName
);
5249 utils
.writeInt(st
, Byte(FTeam
));
5251 utils
.writeBool(st
, FAlive
);
5252 // Израсходовал ли все жизни
5253 utils
.writeBool(st
, FNoRespawn
);
5255 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
5256 utils
.writeInt(st
, Byte(b
));
5258 utils
.writeInt(st
, LongInt(FHealth
));
5259 // Коэффициент инвалидности
5260 utils
.writeInt(st
, LongInt(FHandicap
));
5262 utils
.writeInt(st
, Byte(FLives
));
5264 utils
.writeInt(st
, LongInt(FArmor
));
5266 utils
.writeInt(st
, LongInt(FAir
));
5268 utils
.writeInt(st
, LongInt(FJetFuel
));
5270 utils
.writeInt(st
, LongInt(FPain
));
5272 utils
.writeInt(st
, LongInt(FKills
));
5274 utils
.writeInt(st
, LongInt(FMonsterKills
));
5276 utils
.writeInt(st
, LongInt(FFrags
));
5278 utils
.writeInt(st
, Byte(FFragCombo
));
5279 // Время последнего фрага
5280 utils
.writeInt(st
, LongWord(FLastFrag
));
5282 utils
.writeInt(st
, LongInt(FDeath
));
5284 utils
.writeInt(st
, Byte(FFlag
));
5286 utils
.writeInt(st
, LongInt(FSecrets
));
5288 utils
.writeInt(st
, Byte(FCurrWeap
));
5290 utils
.writeInt(st
, Word(FNextWeap
));
5292 utils
.writeInt(st
, Byte(FNextWeapDelay
));
5293 // Время зарядки BFG
5294 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
5296 utils
.writeInt(st
, LongInt(FDamageBuffer
));
5297 // Последний ударивший
5298 utils
.writeInt(st
, Word(FLastSpawnerUID
));
5299 // Тип последнего полученного урона
5300 utils
.writeInt(st
, Byte(FLastHit
));
5302 Obj_SaveState(st
, @FObj
);
5303 // Текущее количество патронов
5304 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
5305 // Максимальное количество патронов
5306 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
5308 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
5309 // Время перезарядки оружия
5310 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
5312 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
5313 // Наличие красного ключа
5314 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
5315 // Наличие зеленого ключа
5316 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
5317 // Наличие синего ключа
5318 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
5320 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
5321 // Время действия специальных предметов
5322 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
5323 // Время до повторного респауна, смены оружия, исользования, захвата флага
5324 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
5326 utils
.writeStr(st
, FModel
.GetName());
5328 utils
.writeInt(st
, Byte(FColor
.R
));
5329 utils
.writeInt(st
, Byte(FColor
.G
));
5330 utils
.writeInt(st
, Byte(FColor
.B
));
5334 procedure TPlayer
.LoadState (st
: TStream
);
5343 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
5344 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
5346 FIamBot
:= utils
.readBool(st
);
5348 FUID
:= utils
.readWord(st
);
5350 str
:= utils
.readStr(st
);
5351 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
5353 FTeam
:= utils
.readByte(st
);
5355 FAlive
:= utils
.readBool(st
);
5356 // Израсходовал ли все жизни
5357 FNoRespawn
:= utils
.readBool(st
);
5359 b
:= utils
.readByte(st
);
5360 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
5362 FHealth
:= utils
.readLongInt(st
);
5363 // Коэффициент инвалидности
5364 FHandicap
:= utils
.readLongInt(st
);
5366 FLives
:= utils
.readByte(st
);
5368 FArmor
:= utils
.readLongInt(st
);
5370 FAir
:= utils
.readLongInt(st
);
5372 FJetFuel
:= utils
.readLongInt(st
);
5374 FPain
:= utils
.readLongInt(st
);
5376 FKills
:= utils
.readLongInt(st
);
5378 FMonsterKills
:= utils
.readLongInt(st
);
5380 FFrags
:= utils
.readLongInt(st
);
5382 FFragCombo
:= utils
.readByte(st
);
5383 // Время последнего фрага
5384 FLastFrag
:= utils
.readLongWord(st
);
5386 FDeath
:= utils
.readLongInt(st
);
5388 FFlag
:= utils
.readByte(st
);
5390 FSecrets
:= utils
.readLongInt(st
);
5392 FCurrWeap
:= utils
.readByte(st
);
5394 FNextWeap
:= utils
.readWord(st
);
5396 FNextWeapDelay
:= utils
.readByte(st
);
5397 // Время зарядки BFG
5398 FBFGFireCounter
:= utils
.readSmallInt(st
);
5400 FDamageBuffer
:= utils
.readLongInt(st
);
5401 // Последний ударивший
5402 FLastSpawnerUID
:= utils
.readWord(st
);
5403 // Тип последнего полученного урона
5404 FLastHit
:= utils
.readByte(st
);
5406 Obj_LoadState(@FObj
, st
);
5407 // Текущее количество патронов
5408 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
5409 // Максимальное количество патронов
5410 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
5412 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
5413 // Время перезарядки оружия
5414 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
5416 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
5417 // Наличие красного ключа
5418 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
5419 // Наличие зеленого ключа
5420 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
5421 // Наличие синего ключа
5422 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
5424 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
5425 // Время действия специальных предметов
5426 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
5427 // Время до повторного респауна, смены оружия, исользования, захвата флага
5428 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
5430 str
:= utils
.readStr(st
);
5432 FColor
.R
:= utils
.readByte(st
);
5433 FColor
.G
:= utils
.readByte(st
);
5434 FColor
.B
:= utils
.readByte(st
);
5435 if (self
= gPlayer1
) then
5437 str
:= gPlayer1Settings
.Model
;
5438 FColor
:= gPlayer1Settings
.Color
;
5440 else if (self
= gPlayer2
) then
5442 str
:= gPlayer2Settings
.Model
;
5443 FColor
:= gPlayer2Settings
.Color
;
5445 // Обновляем модель игрока
5447 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
5448 FModel
.Color
:= TEAMCOLOR
[FTeam
]
5450 FModel
.Color
:= FColor
;
5454 procedure TPlayer
.AllRulez(Health
: Boolean);
5460 FHealth
:= PLAYER_HP_LIMIT
;
5461 FArmor
:= PLAYER_AP_LIMIT
;
5465 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
5466 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
5467 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5470 procedure TPlayer
.RestoreHealthArmor();
5472 FHealth
:= PLAYER_HP_LIMIT
;
5473 FArmor
:= PLAYER_AP_LIMIT
;
5476 procedure TPlayer
.FragCombo();
5480 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
5482 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
5484 if FFragCombo
< 5 then
5486 Param
:= FUID
or (FFragCombo
shl 16);
5487 if (FComboEvnt
>= Low(gDelayedEvents
)) and
5488 (FComboEvnt
<= High(gDelayedEvents
)) and
5489 gDelayedEvents
[FComboEvnt
].Pending
and
5490 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
5491 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
5493 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
5494 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
5497 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
5505 procedure TPlayer
.GiveItem(ItemType
: Byte);
5509 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
5511 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
5515 if FAir
< AIR_MAX
then
5522 if not (R_BERSERK
in FRulez
) then
5524 Include(FRulez
, R_BERSERK
);
5525 if FBFGFireCounter
< 1 then
5527 FCurrWeap
:= WEAPON_KASTET
;
5529 FModel
.SetWeapon(WEAPON_KASTET
);
5533 FBerserk
:= gTime
+30000;
5535 if FHealth
< PLAYER_HP_SOFT
then
5537 FHealth
:= PLAYER_HP_SOFT
;
5538 FBerserk
:= gTime
+30000;
5543 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
5545 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
5550 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
5552 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
5556 if FJetFuel
< JET_MAX
then
5558 FJetFuel
:= JET_MAX
;
5561 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
5562 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
5564 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
5565 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5567 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
5569 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
5571 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
5572 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5575 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
5576 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
5577 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
5578 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
5579 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
5580 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
5581 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
5582 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
5583 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
5585 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5586 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
5587 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5588 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
5589 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5590 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
5591 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5592 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
5593 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
5596 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
5597 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
5598 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
5599 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
5600 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
5602 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
5603 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
5604 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
5605 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
5606 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
5608 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5609 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5610 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5611 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5613 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
5616 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
5617 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
5618 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
5620 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
5621 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
5626 if g_Game_IsNet
and g_Game_IsServer
then
5627 MH_SEND_PlayerStats(FUID
);
5630 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
5633 if (Random(5) = 1) and (Times
= 1) then
5636 if BodyInLiquid(0, 0) then
5639 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
5640 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
5643 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5644 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5648 for i
:= 1 to Times
do
5653 Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(R_GFX_SMOKE_WIDTH
div 2),
5654 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2)
5660 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
5663 if (Random(10) = 1) and (Times
= 1) then
5666 for i
:= 1 to Times
do
5671 Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(R_GFX_FLAME_WIDTH
div 2),
5672 Obj
.Y
+8+Random(8+Times
*2)
5678 procedure TPlayer
.PauseSounds(Enable
: Boolean);
5680 FSawSound
.Pause(Enable
);
5681 FSawSoundIdle
.Pause(Enable
);
5682 FSawSoundHit
.Pause(Enable
);
5683 FSawSoundSelect
.Pause(Enable
);
5684 FFlameSoundOn
.Pause(Enable
);
5685 FFlameSoundOff
.Pause(Enable
);
5686 FFlameSoundWork
.Pause(Enable
);
5687 FJetSoundFly
.Pause(Enable
);
5688 FJetSoundOn
.Pause(Enable
);
5689 FJetSoundOff
.Pause(Enable
);
5694 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
5699 FObj
.Rect
:= PLAYER_CORPSERECT
;
5701 FModel
:= g_PlayerModel_Get(ModelName
);
5705 FState
:= CORPSE_STATE_MESS
;
5706 FModel
.ChangeAnimation(A_DIE2
);
5710 FState
:= CORPSE_STATE_NORMAL
;
5711 FModel
.ChangeAnimation(A_DIE1
);
5715 destructor TCorpse
.Destroy();
5721 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
5723 procedure TCorpse
.positionChanged (); inline; begin end;
5725 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
5727 if (dx
<> 0) or (dy
<> 0) then
5736 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5738 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
5739 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
5740 w
:= PLAYER_CORPSERECT
.Width
;
5741 h
:= PLAYER_CORPSERECT
.Height
;
5745 procedure TCorpse
.Damage(Value
: Word; SpawnerUID
: Word; vx
, vy
: Integer);
5747 var Blood
: TModelBlood
;
5750 if FState
= CORPSE_STATE_REMOVEME
then
5753 FDamage
:= FDamage
+ Value
;
5755 {$IFDEF ENABLE_GIBS}
5756 if FDamage
> 150 then
5758 if FModel
<> nil then
5760 FState
:= CORPSE_STATE_REMOVEME
;
5763 FObj
.X
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
div 2),
5764 FObj
.Y
+ FObj
.Rect
.Y
+ (FObj
.Rect
.Height
div 2),
5769 // Звук мяса от трупа:
5770 FModel
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
5773 if (gBodyKillEvent
<> -1) and gDelayedEvents
[gBodyKillEvent
].Pending
then
5774 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
5775 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, SpawnerUID
);
5784 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
5785 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
5787 Blood
:= FModel
.GetBlood();
5788 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
5789 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
5790 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
5791 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
5796 procedure TCorpse
.Update();
5800 if FState
= CORPSE_STATE_REMOVEME
then
5803 FObj
.oldX
:= FObj
.X
;
5804 FObj
.oldY
:= FObj
.Y
;
5806 if gTime
mod (GAME_TICK
*2) <> 0 then
5808 g_Obj_Move(@FObj
, True, True, True);
5809 positionChanged(); // this updates spatial accelerators
5813 // Сопротивление воздуха для трупа:
5814 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5816 st
:= g_Obj_Move(@FObj
, True, True, True);
5817 positionChanged(); // this updates spatial accelerators
5819 if WordBool(st
and MOVE_FALLOUT
) then
5821 FState
:= CORPSE_STATE_REMOVEME
;
5825 if FModel
<> nil then
5830 procedure TCorpse
.SaveState (st
: TStream
);
5836 utils
.writeSign(st
, 'CORP');
5837 utils
.writeInt(st
, Byte(0));
5839 utils
.writeInt(st
, Byte(FState
));
5841 utils
.writeInt(st
, Byte(FDamage
));
5843 utils
.writeInt(st
, Byte(FModel
.Color
.R
));
5844 utils
.writeInt(st
, Byte(FModel
.Color
.G
));
5845 utils
.writeInt(st
, Byte(FModel
.Color
.B
));
5847 Obj_SaveState(st
, @FObj
);
5848 utils
.writeInt(st
, Word(FPlayerUID
));
5850 anim
:= (FModel
<> nil);
5851 utils
.writeBool(st
, anim
);
5852 if anim
then FModel
.AnimState
.SaveState(st
, 0, False);
5853 // animation for mask (same as animation, compat with older saves)
5854 anim
:= (FModel
<> nil);
5855 utils
.writeBool(st
, anim
);
5856 if anim
then FModel
.AnimState
.SaveState(st
, 0, False);
5860 procedure TCorpse
.LoadState (st
: TStream
);
5861 var anim
, blending
: Boolean; r
, g
, b
, alpha
: Byte; stub
: TAnimationState
;
5866 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
5867 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
5869 FState
:= utils
.readByte(st
);
5871 FDamage
:= utils
.readByte(st
);
5873 r
:= utils
.readByte(st
);
5874 g
:= utils
.readByte(st
);
5875 b
:= utils
.readByte(st
);
5876 FModel
.SetColor(r
, g
, b
);
5878 Obj_LoadState(@FObj
, st
);
5879 FPlayerUID
:= utils
.readWord(st
);
5881 stub
:= TAnimationState
.Create(False, 0, 0);
5882 anim
:= utils
.readBool(st
);
5885 stub
.LoadState(st
, alpha
, blending
);
5886 FModel
.AnimState
.CurrentFrame
:= Min(stub
.CurrentFrame
, FModel
.AnimState
.Length
);
5893 // animation for mask (same as animation, compat with older saves)
5894 anim
:= utils
.readBool(st
);
5895 if anim
then stub
.LoadState(st
, alpha
, blending
);
5901 constructor TBot
.Create();
5908 FSpectator
:= False;
5915 for a
:= WP_FIRST
to WP_LAST
do
5917 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
5918 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
5919 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
5923 destructor TBot
.Destroy();
5926 inherited Destroy();
5929 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
5931 inherited Respawn(Silent
, Force
);
5934 FSelectedWeapon
:= FCurrWeap
;
5939 procedure TBot
.UpdateCombat();
5952 TTargetRecord
= array of TTarget
;
5954 function Compare(a
, b
: TTarget
): Integer;
5956 if a
.Line
and not b
.Line
then // A на линии огня
5959 if not a
.Line
and b
.Line
then // B на линии огня
5961 else // И A, и B на линии или не на линии огня
5962 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
5964 if a
.Dist
> b
.Dist
then // B ближе
5966 else // A ближе или равноудаленно с B
5969 else // Странно -> A
5974 a
, x1
, y1
, x2
, y2
: Integer;
5975 targets
: TTargetRecord
;
5977 Target
, BestTarget
: TTarget
;
5978 firew
, fireh
: Integer;
5982 vsPlayer
, vsMonster
, ok
: Boolean;
5985 function monsUpdate (mon
: TMonster
): Boolean;
5987 result
:= false; // don't stop
5988 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
5990 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
5992 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
5993 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
5995 // Если монстр на экране и не прикрыт стеной
5996 if g_TraceVector(x1
, y1
, x2
, y2
) then
5998 // Добавляем к списку возможных целей
5999 SetLength(targets
, Length(targets
)+1);
6000 with targets
[High(targets
)] do
6007 Rect
:= mon
.Obj
.Rect
;
6008 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6009 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6010 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6019 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6020 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6022 // Если текущее оружие не то, что нужно, то меняем:
6023 if FCurrWeap
<> FSelectedWeapon
then
6026 // Если нужно стрелять и нужное оружие, то нажать "Стрелять":
6027 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6029 RemoveAIFlag('NEEDFIRE');
6032 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6033 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6034 else PressKey(KEY_FIRE
);
6038 // Координаты ствола:
6039 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6040 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6042 Target
.UID
:= FTargetUID
;
6045 if Target
.UID
<> 0 then
6046 begin // Цель есть - настраиваем
6047 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6050 tpla
:= g_Player_Get(Target
.UID
);
6054 if (@FObj
) <> nil then
6061 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6062 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6063 Target
.Rect
:= PLAYER_RECT
;
6064 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6065 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6066 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6067 Target
.IsPlayer
:= True;
6071 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6074 mon
:= g_Monsters_ByUID(Target
.UID
);
6077 Target
.X
:= mon
.Obj
.X
;
6078 Target
.Y
:= mon
.Obj
.Y
;
6080 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6081 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6082 Target
.Rect
:= mon
.Obj
.Rect
;
6083 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6084 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6085 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6086 Target
.IsPlayer
:= False;
6093 begin // Цели нет - обнуляем
6098 Target
.Visible
:= False;
6099 Target
.Line
:= False;
6100 Target
.IsPlayer
:= False;
6105 // Если цель не видима или не на линии огня, то ищем все возможные цели:
6106 if (not Target
.Line
) or (not Target
.Visible
) then
6110 for a
:= 0 to High(gPlayers
) do
6111 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6112 (gPlayers
[a
].FUID
<> FUID
) and
6113 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6114 (not gPlayers
[a
].NoTarget
) and
6115 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6117 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6118 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6121 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6122 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6124 // Если игрок на экране и не прикрыт стеной:
6125 if g_TraceVector(x1
, y1
, x2
, y2
) then
6127 // Добавляем к списку возможных целей:
6128 SetLength(targets
, Length(targets
)+1);
6129 with targets
[High(targets
)] do
6131 UID
:= gPlayers
[a
].FUID
;
6132 X
:= gPlayers
[a
].FObj
.X
;
6133 Y
:= gPlayers
[a
].FObj
.Y
;
6136 Rect
:= PLAYER_RECT
;
6137 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6138 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6139 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6147 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6150 // Если есть возможные цели:
6151 // (Выбираем лучшую, меняем оружие и бежим к ней/от нее)
6152 if targets
<> nil then
6154 // Выбираем наилучшую цель:
6155 BestTarget
:= targets
[0];
6156 if Length(targets
) > 1 then
6157 for a
:= 1 to High(targets
) do
6158 if Compare(BestTarget
, targets
[a
]) = 1 then
6159 BestTarget
:= targets
[a
];
6161 // Если лучшая цель "виднее" текущей, то текущая := лучшая:
6162 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6163 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6165 Target
:= BestTarget
;
6167 if (Healthy() = 3) or ((Healthy() = 2)) then
6168 begin // Если здоровы - догоняем
6169 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6170 SetAIFlag('GORIGHT', '1');
6171 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6172 SetAIFlag('GOLEFT', '1');
6175 begin // Если побиты - убегаем
6176 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6177 SetAIFlag('GORIGHT', '1');
6178 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6179 SetAIFlag('GOLEFT', '1');
6182 // Выбираем оружие на основе расстояния и приоритетов:
6183 SelectWeapon(Abs(x1
-Target
.cX
));
6188 // (Догоняем/убегаем, стреляем по направлению к цели)
6189 // (Если цель далеко, то хватит следить за ней)
6190 if Target
.UID
<> 0 then
6192 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6193 Target
.Y
+ Target
.Rect
.Y
) then
6194 begin // Цель сбежала с "экрана"
6195 if (Healthy() = 3) or ((Healthy() = 2)) then
6196 begin // Если здоровы - догоняем
6197 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6198 SetAIFlag('GORIGHT', '1');
6199 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6200 SetAIFlag('GOLEFT', '1');
6203 begin // Если побиты - забываем о цели и убегаем
6205 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6206 SetAIFlag('GORIGHT', '1');
6207 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6208 SetAIFlag('GOLEFT', '1');
6212 begin // Цель пока на "экране"
6213 // Если цель не загорожена стеной, то отмечаем, когда ее видели:
6214 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6215 FLastVisible
:= gTime
;
6216 // Если разница высот не велика, то догоняем:
6217 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6219 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6220 SetAIFlag('GORIGHT', '1');
6221 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6222 SetAIFlag('GOLEFT', '1');
6226 // Выбираем угол вверх:
6227 if FDirection
= TDirection
.D_LEFT
then
6228 angle
:= ANGLE_LEFTUP
6230 angle
:= ANGLE_RIGHTUP
;
6232 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6233 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6235 // Если при угле вверх можно попасть в приблизительное положение цели:
6236 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6237 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6238 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6239 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6240 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6241 begin // то нужно стрелять вверх
6242 SetAIFlag('NEEDFIRE', '1');
6243 SetAIFlag('NEEDSEEUP', '1');
6246 // Выбираем угол вниз:
6247 if FDirection
= TDirection
.D_LEFT
then
6248 angle
:= ANGLE_LEFTDOWN
6250 angle
:= ANGLE_RIGHTDOWN
;
6252 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6253 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6255 // Если при угле вниз можно попасть в приблизительное положение цели:
6256 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6257 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6258 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6259 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6260 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6261 begin // то нужно стрелять вниз
6262 SetAIFlag('NEEDFIRE', '1');
6263 SetAIFlag('NEEDSEEDOWN', '1');
6266 // Если цель видно и она на такой же высоте:
6267 if Target
.Visible
and
6268 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6269 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6271 // Если идем в сторону цели, то надо стрелять:
6272 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
6273 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6274 begin // то нужно стрелять вперед
6275 SetAIFlag('NEEDFIRE', '1');
6276 SetAIFlag('NEEDSEEDOWN', '');
6277 SetAIFlag('NEEDSEEUP', '');
6279 // Если цель в пределах "экрана" и сложность позволяет прыжки сближения:
6280 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6281 if GetRnd(FDifficult
.CloseJump
) then
6282 begin // то если повезет - прыгаем (особенно, если близко)
6283 if Abs(FObj
.X
-Target
.X
) < 128 then
6287 if Random(a
) = 0 then
6288 SetAIFlag('NEEDJUMP', '1');
6292 // Если цель все еще есть:
6293 if Target
.UID
<> 0 then
6294 if gTime
-FLastVisible
> 2000 then // Если видели давно
6295 Target
.UID
:= 0 // то забыть цель
6296 else // Если видели недавно
6297 begin // но цель убили
6298 if Target
.IsPlayer
then
6299 begin // Цель - игрок
6300 pla
:= g_Player_Get(Target
.UID
);
6301 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
6302 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6303 Target
.UID
:= 0; // то забыть цель
6306 begin // Цель - монстр
6307 mon
:= g_Monsters_ByUID(Target
.UID
);
6308 if (mon
= nil) or (not mon
.alive
) then
6309 Target
.UID
:= 0; // то забыть цель
6312 end; // if Target.UID <> 0
6314 FTargetUID
:= Target
.UID
;
6316 // Если возможных целей нет:
6317 // (Атака чего-нибудь слева или справа)
6318 if targets
= nil then
6319 if GetAIFlag('ATTACKLEFT') <> '' then
6320 begin // Если нужно атаковать налево
6321 RemoveAIFlag('ATTACKLEFT');
6323 SetAIFlag('NEEDJUMP', '1');
6325 if RunDirection() = TDirection
.D_RIGHT
then
6326 begin // Идем не в ту сторону
6327 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6328 begin // Если здоровы, то, возможно, стреляем бежим влево и стреляем
6329 SetAIFlag('NEEDFIRE', '1');
6330 SetAIFlag('GOLEFT', '1');
6334 begin // Идем в нужную сторону
6335 if GetRnd(FDifficult
.InvisFire
) then // Возможно, стреляем вслепую
6336 SetAIFlag('NEEDFIRE', '1');
6337 if Healthy() <= 1 then // Побиты - убегаем
6338 SetAIFlag('GORIGHT', '1');
6342 if GetAIFlag('ATTACKRIGHT') <> '' then
6343 begin // Если нужно атаковать направо
6344 RemoveAIFlag('ATTACKRIGHT');
6346 SetAIFlag('NEEDJUMP', '1');
6348 if RunDirection() = TDirection
.D_LEFT
then
6349 begin // Идем не в ту сторону
6350 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6351 begin // Если здоровы, то, возможно, бежим вправо и стреляем
6352 SetAIFlag('NEEDFIRE', '1');
6353 SetAIFlag('GORIGHT', '1');
6358 if GetRnd(FDifficult
.InvisFire
) then // Возможно, стреляем вслепую
6359 SetAIFlag('NEEDFIRE', '1');
6360 if Healthy() <= 1 then // Побиты - убегаем
6361 SetAIFlag('GOLEFT', '1');
6365 //HACK! (does it belongs there?)
6366 RealizeCurrentWeapon();
6368 // Если есть возможные цели:
6369 // (Стреляем по направлению к целям)
6370 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6371 for a
:= 0 to High(targets
) do
6373 // Если можем стрелять по диагонали:
6374 if GetRnd(FDifficult
.DiagFire
) then
6376 // Ищем цель сверху и стреляем, если есть:
6377 if FDirection
= TDirection
.D_LEFT
then
6378 angle
:= ANGLE_LEFTUP
6380 angle
:= ANGLE_RIGHTUP
;
6382 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6383 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6385 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6386 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6387 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6388 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6389 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6391 SetAIFlag('NEEDFIRE', '1');
6392 SetAIFlag('NEEDSEEUP', '1');
6395 // Ищем цель снизу и стреляем, если есть:
6396 if FDirection
= TDirection
.D_LEFT
then
6397 angle
:= ANGLE_LEFTDOWN
6399 angle
:= ANGLE_RIGHTDOWN
;
6401 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6402 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6404 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6405 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6406 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6407 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6408 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6410 SetAIFlag('NEEDFIRE', '1');
6411 SetAIFlag('NEEDSEEDOWN', '1');
6415 // Если цель "перед носом", то стреляем:
6416 if targets
[a
].Line
and targets
[a
].Visible
and
6417 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
6418 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
6420 SetAIFlag('NEEDFIRE', '1');
6425 // Если летит пуля, то, возможно, подпрыгиваем:
6426 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
6427 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
6428 40+GetInterval(FDifficult
.Cover
, 40)) then
6429 SetAIFlag('NEEDJUMP', '1');
6431 // Если кончились паторны, то нужно сменить оружие:
6432 ammo
:= GetAmmoByWeapon(FCurrWeap
);
6433 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
6434 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
6436 SetAIFlag('SELECTWEAPON', '1');
6438 // Если нужно сменить оружие, то выбираем нужное:
6439 if GetAIFlag('SELECTWEAPON') = '1' then
6442 RemoveAIFlag('SELECTWEAPON');
6446 procedure TBot
.Update();
6459 // Проверяем, отключён ли AI ботов
6460 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
6462 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
6464 if g_debug_BotAIOff
= 3 then
6474 RealizeCurrentWeapon();
6481 procedure TBot
.ReleaseKey(Key
: Byte);
6490 function TBot
.KeyPressed(Key
: Word): Boolean;
6492 Result
:= FKeys
[Key
].Pressed
;
6495 function TBot
.GetAIFlag(aName
: String20
): String20
;
6501 aName
:= LowerCase(aName
);
6503 if FAIFlags
<> nil then
6504 for a
:= 0 to High(FAIFlags
) do
6505 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6507 Result
:= FAIFlags
[a
].Value
;
6512 procedure TBot
.RemoveAIFlag(aName
: String20
);
6516 if FAIFlags
= nil then Exit
;
6518 aName
:= LowerCase(aName
);
6520 for a
:= 0 to High(FAIFlags
) do
6521 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6523 if a
<> High(FAIFlags
) then
6524 for b
:= a
to High(FAIFlags
)-1 do
6525 FAIFlags
[b
] := FAIFlags
[b
+1];
6527 SetLength(FAIFlags
, Length(FAIFlags
)-1);
6532 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
6540 aName
:= LowerCase(aName
);
6542 if FAIFlags
<> nil then
6543 for a
:= 0 to High(FAIFlags
) do
6544 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6550 if ok
then FAIFlags
[a
].Value
:= fValue
6553 SetLength(FAIFlags
, Length(FAIFlags
)+1);
6554 with FAIFlags
[High(FAIFlags
)] do
6562 procedure TBot
.UpdateMove
;
6564 procedure GoLeft(Time
: Word = 1);
6566 ReleaseKey(KEY_LEFT
);
6567 ReleaseKey(KEY_RIGHT
);
6568 PressKey(KEY_LEFT
, Time
);
6569 SetDirection(TDirection
.D_LEFT
);
6572 procedure GoRight(Time
: Word = 1);
6574 ReleaseKey(KEY_LEFT
);
6575 ReleaseKey(KEY_RIGHT
);
6576 PressKey(KEY_RIGHT
, Time
);
6577 SetDirection(TDirection
.D_RIGHT
);
6580 function Rnd(a
: Word): Boolean;
6582 Result
:= Random(a
) = 0;
6585 procedure Turn(Time
: Word = 1200);
6587 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
6592 ReleaseKey(KEY_LEFT
);
6593 ReleaseKey(KEY_RIGHT
);
6596 function CanRunLeft(): Boolean;
6598 Result
:= not CollideLevel(-1, 0);
6601 function CanRunRight(): Boolean;
6603 Result
:= not CollideLevel(1, 0);
6606 function CanRun(): Boolean;
6608 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
6611 procedure Jump(Time
: Word = 30);
6613 PressKey(KEY_JUMP
, Time
);
6616 function NearHole(): Boolean;
6620 { TODO 5 : Лестницы }
6621 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
6622 for x
:= 1 to PLAYER_RECT
.Width
do
6623 if (not StayOnStep(x
*sx
, 0)) and
6624 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6625 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6634 function BorderHole(): Boolean;
6638 { TODO 5 : Лестницы }
6639 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
6640 for x
:= 1 to PLAYER_RECT
.Width
do
6641 if (not StayOnStep(x
*sx
, 0)) and
6642 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6643 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6645 for xx
:= x
to x
+32 do
6646 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
6656 function NearDeepHole(): Boolean;
6662 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
6665 for x
:= 1 to PLAYER_RECT
.Width
do
6666 if (not StayOnStep(x
*sx
, 0)) and
6667 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6668 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6670 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6672 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
6677 end else Result
:= False;
6680 function OverDeepHole(): Boolean;
6687 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6689 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
6696 function OnGround(): Boolean;
6698 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
6701 function OnLadder(): Boolean;
6703 Result
:= FullInStep(0, 0);
6706 function BelowLadder(): Boolean;
6708 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
6709 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
6710 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
6711 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
6714 function BelowLiftUp(): Boolean;
6716 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
6717 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
6718 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
6719 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
6722 function OnTopLift(): Boolean;
6724 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
6727 function CanJumpOver(): Boolean;
6731 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
6735 if not CollideLevel(sx
, 0) then Exit
;
6737 for y
:= 1 to BOT_MAXJUMP
do
6738 if CollideLevel(0, -y
) then Exit
else
6739 if not CollideLevel(sx
, -y
) then
6746 function CanJumpUp(Dist
: ShortInt): Boolean;
6753 if CollideLevel(Dist
, 0) then Exit
;
6756 for y
:= 0 to BOT_MAXJUMP
do
6757 if CollideLevel(Dist
, -y
) then
6766 for yy
:= y
+1 to BOT_MAXJUMP
do
6767 if not CollideLevel(Dist
, -yy
) then
6776 for y
:= 0 to BOT_MAXJUMP
do
6777 if CollideLevel(0, -y
) then
6785 if y
< yy
then Exit
;
6790 function IsSafeTrigger(): Boolean;
6795 if gTriggers
= nil then
6797 for a
:= 0 to High(gTriggers
) do
6798 if Collide(gTriggers
[a
].X
,
6801 gTriggers
[a
].Height
) and
6802 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
6803 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
6804 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
6805 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
6806 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
6811 // Возможно, нажимаем кнопку:
6812 if Rnd(16) and IsSafeTrigger() then
6815 // Если под лифтом или ступеньками, то, возможно, прыгаем:
6816 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
6818 ReleaseKey(KEY_LEFT
);
6819 ReleaseKey(KEY_RIGHT
);
6823 // Идем влево, если надо было:
6824 if GetAIFlag('GOLEFT') <> '' then
6826 RemoveAIFlag('GOLEFT');
6827 if CanRunLeft() then
6831 // Идем вправо, если надо было:
6832 if GetAIFlag('GORIGHT') <> '' then
6834 RemoveAIFlag('GORIGHT');
6835 if CanRunRight() then
6839 // Если вылетели за карту, то пробуем вернуться:
6840 if FObj
.X
< -32 then
6843 if FObj
.X
+32 > gMapInfo
.Width
then
6846 // Прыгаем, если надо было:
6847 if GetAIFlag('NEEDJUMP') <> '' then
6850 RemoveAIFlag('NEEDJUMP');
6853 // Смотрим вверх, если надо было:
6854 if GetAIFlag('NEEDSEEUP') <> '' then
6857 ReleaseKey(KEY_DOWN
);
6858 PressKey(KEY_UP
, 20);
6859 RemoveAIFlag('NEEDSEEUP');
6862 // Смотрим вниз, если надо было:
6863 if GetAIFlag('NEEDSEEDOWN') <> '' then
6866 ReleaseKey(KEY_DOWN
);
6867 PressKey(KEY_DOWN
, 20);
6868 RemoveAIFlag('NEEDSEEDOWN');
6871 // Если нужно было в дыру и мы не на земле, то покорно летим:
6872 if GetAIFlag('GOINHOLE') <> '' then
6873 if not OnGround() then
6875 ReleaseKey(KEY_LEFT
);
6876 ReleaseKey(KEY_RIGHT
);
6877 RemoveAIFlag('GOINHOLE');
6878 SetAIFlag('FALLINHOLE', '1');
6881 // Если падали и достигли земли, то хватит падать:
6882 if GetAIFlag('FALLINHOLE') <> '' then
6884 RemoveAIFlag('FALLINHOLE');
6886 // Если летели прямо и сейчас не на лестнице или на вершине лифта, то отходим в сторону:
6887 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
6888 if GetAIFlag('FALLINHOLE') = '' then
6889 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
6895 // Если на земле и можно подпрыгнуть, то, возможно, прыгаем:
6897 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
6901 // Если на земле и возле дыры (глубина > 2 ростов игрока):
6902 if OnGround() and NearHole() then
6903 if NearDeepHole() then // Если это бездна
6905 0..3: Turn(); // Бежим обратно
6906 4: Jump(); // Прыгаем
6907 5: begin // Прыгаем обратно
6912 else // Это не бездна и мы еще не летим туда
6913 if GetAIFlag('GOINHOLE') = '' then
6915 0: Turn(); // Не нужно туда
6916 1: Jump(); // Вдруг повезет - прыгаем
6917 else // Если яма с границей, то при случае можно туда прыгнуть
6918 if BorderHole() then
6919 SetAIFlag('GOINHOLE', '1');
6922 // Если на земле, но некуда идти:
6923 if (not CanRun()) and OnGround() then
6925 // Если мы на лестнице или можно перепрыгнуть, то прыгаем:
6926 if CanJumpOver() or OnLadder() then
6928 else // иначе попытаемся в другую сторону
6929 if Random(2) = 0 then
6931 if IsSafeTrigger() then
6937 // Осталось мало воздуха:
6938 if FAir
< 36 * 2 then
6941 // Выбираемся из кислоты, если нет костюма, обожглись, или мало здоровья:
6942 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
6943 if BodyInAcid(0, 0) then
6947 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
6949 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
6950 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
6953 {function TBot.NeedItem(Item: Byte): Byte;
6958 procedure TBot
.SelectWeapon(Dist
: Integer);
6962 function HaveAmmo(weapon
: Byte): Boolean;
6965 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
6966 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
6967 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
6968 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
6969 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
6970 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
6971 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
6972 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
6973 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
6974 else Result
:= True;
6979 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
6981 if Dist
> BOT_LONGDIST
then
6982 begin // Дальний бой
6984 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
6986 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
6990 else //if Dist > BOT_UNSAFEDIST then
6991 begin // Ближний бой
6993 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
6995 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7002 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7004 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7010 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7012 Result
:= inherited PickItem(ItemType
, force
, remove
);
7014 if Result
then SetAIFlag('SELECTWEAPON', '1');
7017 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7019 Result
:= inherited Heal(value
, Soft
);
7022 function TBot
.Healthy(): Byte;
7024 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7025 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7026 else if (FHealth
> 50) then Result
:= 2
7027 else if (FHealth
> 20) then Result
:= 1
7031 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7033 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7034 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7037 procedure TBot
.OnDamage(Angle
: SmallInt);
7045 if (Angle
= 0) or (Angle
= 180) then
7048 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7049 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7051 pla
:= g_Player_Get(FLastSpawnerUID
);
7052 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7053 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7056 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7057 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7059 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7060 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7061 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7066 SetAIFlag('ATTACKLEFT', '1')
7068 SetAIFlag('ATTACKRIGHT', '1');
7072 function TBot
.RunDirection(): TDirection
;
7074 if Abs(Vel
.X
) >= 1 then
7076 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7078 Result
:= FDirection
;
7081 function TBot
.GetRnd(a
: Byte): Boolean;
7083 if a
= 0 then Result
:= False
7084 else if a
= 255 then Result
:= True
7085 else Result
:= Random(256) > 255-a
;
7088 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7090 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7094 procedure TDifficult
.save (st
: TStream
);
7096 utils
.writeInt(st
, Byte(DiagFire
));
7097 utils
.writeInt(st
, Byte(InvisFire
));
7098 utils
.writeInt(st
, Byte(DiagPrecision
));
7099 utils
.writeInt(st
, Byte(FlyPrecision
));
7100 utils
.writeInt(st
, Byte(Cover
));
7101 utils
.writeInt(st
, Byte(CloseJump
));
7102 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7103 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7106 procedure TDifficult
.load (st
: TStream
);
7108 DiagFire
:= utils
.readByte(st
);
7109 InvisFire
:= utils
.readByte(st
);
7110 DiagPrecision
:= utils
.readByte(st
);
7111 FlyPrecision
:= utils
.readByte(st
);
7112 Cover
:= utils
.readByte(st
);
7113 CloseJump
:= utils
.readByte(st
);
7114 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7115 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7119 procedure TBot
.SaveState (st
: TStream
);
7124 inherited SaveState(st
);
7125 utils
.writeSign(st
, 'BOT0');
7127 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7129 utils
.writeInt(st
, Word(FTargetUID
));
7130 // Время потери цели
7131 utils
.writeInt(st
, LongWord(FLastVisible
));
7132 // Количество флагов ИИ
7133 dw
:= Length(FAIFlags
);
7134 utils
.writeInt(st
, LongInt(dw
));
7136 for i
:= 0 to dw
-1 do
7138 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7139 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7141 // Настройки сложности
7142 FDifficult
.save(st
);
7146 procedure TBot
.LoadState (st
: TStream
);
7151 inherited LoadState(st
);
7152 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7154 FSelectedWeapon
:= utils
.readByte(st
);
7156 FTargetUID
:= utils
.readWord(st
);
7157 // Время потери цели
7158 FLastVisible
:= utils
.readLongWord(st
);
7159 // Количество флагов ИИ
7160 dw
:= utils
.readLongInt(st
);
7161 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7162 SetLength(FAIFlags
, dw
);
7164 for i
:= 0 to dw
-1 do
7166 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7167 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7169 // Настройки сложности
7170 FDifficult
.load(st
);
7175 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');
7176 conRegVar('player_indicator_style', @gPlayerIndicatorStyle
, 'Visual appearance of indicator', 'Visual appearance of indicator');