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;
533 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
534 procedure moveBy (dx
, dy
: Integer); inline;
536 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
548 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
549 procedure moveBy (dx
, dy
: Integer); inline;
551 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
554 TCorpse
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
561 FModel
: TPlayerModel
;
564 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
565 destructor Destroy(); override;
566 procedure Damage(Value
: Word; SpawnerUID
: Word; vx
, vy
: Integer);
568 procedure SaveState (st
: TStream
);
569 procedure LoadState (st
: TStream
);
571 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
572 procedure moveBy (dx
, dy
: Integer); inline;
574 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
576 function ObjPtr (): PObj
; inline;
578 property Obj
: TObj read FObj
; // copies object
579 property State
: Byte read FState
;
580 property Mess
: Boolean read FMess
;
581 property Model
: TPlayerModel read FModel
;
584 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
590 gPlayers
: Array of TPlayer
;
591 gCorpses
: Array of TCorpse
;
592 gGibs
: Array of TGib
;
593 gShells
: Array of TShell
;
594 gTeamStat
: TTeamStat
;
595 gFly
: Boolean = False;
596 gAimLine
: Boolean = False;
597 gChatBubble
: Integer = 0;
598 gPlayerIndicator
: Integer = 1;
599 gPlayerIndicatorStyle
: Integer = 0;
601 gSpectLatchPID1
: Word = 0;
602 gSpectLatchPID2
: Word = 0;
603 MAX_RUNVEL
: Integer = 8;
604 VEL_JUMP
: Integer = 10;
605 SHELL_TIMEOUT
: Cardinal = 60000;
607 function Lerp(X
, Y
, Factor
: Integer): Integer;
609 procedure g_Gibs_SetMax(Count
: Word);
610 function g_Gibs_GetMax(): Word;
611 procedure g_Corpses_SetMax(Count
: Word);
612 function g_Corpses_GetMax(): Word;
613 procedure g_Force_Model_Set(Mode
: Word);
614 function g_Force_Model_Get(): Word;
615 procedure g_Forced_Model_SetName(Model
: String);
616 function g_Forced_Model_GetName(): String;
617 procedure g_Shells_SetMax(Count
: Word);
618 function g_Shells_GetMax(): Word;
620 procedure g_Player_Init();
621 procedure g_Player_Free();
622 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
623 function g_Player_CreateFromState (st
: TStream
): Word;
624 procedure g_Player_Remove(UID
: Word);
625 procedure g_Player_ResetTeams();
626 procedure g_Player_PreUpdate();
627 procedure g_Player_UpdateAll();
628 procedure g_Player_RememberAll();
629 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
630 function g_Player_Get(UID
: Word): TPlayer
;
631 function g_Player_GetCount(): Byte;
632 function g_Player_GetStats(): TPlayerStatArray
;
633 function g_Player_ValidName(Name
: String): Boolean;
634 function g_Player_CreateCorpse(Player
: TPlayer
): Integer;
635 procedure g_Player_CreateGibs (fX
, fY
, mid
: Integer; fColor
: TRGB
);
636 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
637 procedure g_Player_UpdatePhysicalObjects();
638 procedure g_Player_RemoveAllCorpses();
639 procedure g_Player_Corpses_SaveState (st
: TStream
);
640 procedure g_Player_Corpses_LoadState (st
: TStream
);
641 procedure g_Player_ResetReady();
642 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
643 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
644 procedure g_Bot_MixNames();
645 procedure g_Bot_RemoveAll();
646 function g_Bot_GetCount(): Integer;
651 {$IFDEF ENABLE_HOLMES}
660 e_log
, g_map
, g_items
, g_console
, g_gfx
, Math
,
661 g_options
, g_triggers
, g_game
, g_grid
, e_res
,
662 wadreader
, g_monsters
, CONFIG
, g_language
,
666 const PLR_SAVE_VERSION
= 0;
676 diag_precision
: Byte;
680 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
681 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
682 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
686 TIME_RESPAWN1
= 1500;
687 TIME_RESPAWN2
= 2000;
688 TIME_RESPAWN3
= 3000;
689 PLAYER_SUIT_TIME
= 30000;
690 PLAYER_INVUL_TIME
= 30000;
691 PLAYER_INVIS_TIME
= 35000;
692 FRAG_COMBO_TIME
= 3000;
695 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
698 BOT_UNSAFEDIST
= 128;
699 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
700 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
701 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
702 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
703 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
704 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
705 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
706 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
707 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
708 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
709 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
710 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
711 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
712 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
713 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
714 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
715 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
716 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
717 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
718 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
719 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
720 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
721 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
722 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
723 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
724 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
726 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
727 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
729 BOTNAMES_FILENAME
= 'botnames.txt';
730 BOTLIST_FILENAME
= 'botlist.txt';
734 MaxCorpses
: Word = 20;
735 MaxShells
: Word = 300;
736 ForceModel
: Word = 0;
737 ForcedModelName
: String = STD_PLAYER_MODEL
;
738 CurrentGib
: Integer = 0;
739 CurrentShell
: Integer = 0;
740 BotNames
: Array of String;
741 BotList
: Array of TBotProfile
;
742 SavedStates
: Array of TPlayerSavedState
;
745 function Lerp(X
, Y
, Factor
: Integer): Integer;
747 Result
:= X
+ ((Y
- X
) div Factor
);
750 function SameTeam(UID1
, UID2
: Word): Boolean;
754 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
755 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
757 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
759 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
760 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
762 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
765 procedure g_Gibs_SetMax(Count
: Word);
768 SetLength(gGibs
, Count
);
770 if CurrentGib
>= Count
then
774 function g_Gibs_GetMax(): Word;
779 procedure g_Shells_SetMax(Count
: Word);
782 SetLength(gShells
, Count
);
784 if CurrentShell
>= Count
then
788 function g_Shells_GetMax(): Word;
794 procedure g_Corpses_SetMax(Count
: Word);
797 SetLength(gCorpses
, Count
);
800 function g_Corpses_GetMax(): Word;
802 Result
:= MaxCorpses
;
805 procedure g_Force_Model_Set(Mode
: Word);
810 function g_Force_Model_Get(): Word;
812 Result
:= ForceModel
;
815 procedure g_Forced_Model_SetName(Model
: String);
817 ForcedModelName
:= Model
;
820 function g_Forced_Model_GetName(): String;
822 Result
:= ForcedModelName
;
825 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
835 // Есть ли место в gPlayers:
836 if gPlayers
<> nil then
837 for a
:= 0 to High(gPlayers
) do
838 if gPlayers
[a
] = nil then
844 // Нет места - расширяем gPlayers:
847 SetLength(gPlayers
, Length(gPlayers
)+1);
851 // Создаем объект игрока:
853 gPlayers
[a
] := TBot
.Create()
855 gPlayers
[a
] := TPlayer
.Create();
858 gPlayers
[a
].FActualModelName
:= ModelName
;
859 gPlayers
[a
].SetModel(ModelName
);
860 if Bot
and (g_Force_Model_Get() <> 0) then
861 gPlayers
[a
].SetModel(g_Forced_Model_GetName());
863 // Нет модели - создание не возможно:
864 if gPlayers
[a
].FModel
= nil then
868 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
872 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
873 if Random(2) = 0 then
877 gPlayers
[a
].FPreferredTeam
:= Team
;
879 case gGameSettings
.GameMode
of
880 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
882 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
884 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
887 // Если командная игра - красим модель в цвет команды:
888 gPlayers
[a
].FColor
:= Color
;
889 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
890 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
892 gPlayers
[a
].FModel
.Color
:= Color
;
894 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
895 gPlayers
[a
].FAlive
:= False;
897 Result
:= gPlayers
[a
].FUID
;
900 function g_Player_CreateFromState (st
: TStream
): Word;
901 var a
: Integer; ok
, Bot
: Boolean; pos
: Int64;
905 // check signature and entity type
907 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
908 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
909 Bot
:= utils
.readBool(st
);
912 // find free player slot
914 for a
:= 0 to High(gPlayers
) do
915 if gPlayers
[a
] = nil then
921 // allocate player slot
924 SetLength(gPlayers
, Length(gPlayers
)+1);
928 // create entity and load state
931 gPlayers
[a
] := TBot
.Create();
932 if (g_Force_Model_Get() <> 0) then
933 gPlayers
[a
].SetModel(g_Forced_Model_GetName());
936 gPlayers
[a
] := TPlayer
.Create();
937 gPlayers
[a
].FPhysics
:= True; // ???
938 gPlayers
[a
].LoadState(st
);
940 result
:= gPlayers
[a
].FUID
;
944 procedure g_Player_ResetTeams();
948 if g_Game_IsClient
then
950 if gPlayers
= nil then
952 for a
:= Low(gPlayers
) to High(gPlayers
) do
953 if gPlayers
[a
] <> nil then
954 case gGameSettings
.GameMode
of
956 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
958 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
959 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
960 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
963 gPlayers
[a
].ChangeTeam(TEAM_RED
)
965 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
968 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
972 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
975 _name
, _model
: String;
978 if not g_Game_IsServer
then Exit
;
980 if (g_Bot_GetCount() >= gMaxBots
) then Exit
;
982 // Список названий моделей:
983 m
:= g_PlayerModel_GetNames();
988 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
989 Team
:= TEAM_COOP
// COOP
991 if gGameSettings
.GameMode
= GM_DM
then
992 Team
:= TEAM_NONE
// DM
994 if Team
= TEAM_NONE
then // CTF / TDM
996 // Автобаланс команд:
1000 for a
:= 0 to High(gPlayers
) do
1001 if gPlayers
[a
] <> nil then
1003 if gPlayers
[a
].Team
= TEAM_RED
then
1006 if gPlayers
[a
].Team
= TEAM_BLUE
then
1016 if Random(2) = 0 then
1022 // Выбираем боту имя:
1024 if BotNames
<> nil then
1025 for a
:= 0 to High(BotNames
) do
1026 if g_Player_ValidName(BotNames
[a
]) then
1028 _name
:= BotNames
[a
];
1032 // Выбираем случайную модель:
1033 _model
:= m
[Random(Length(m
))];
1036 with g_Player_Get(g_Player_Create(_model
,
1037 _RGB(Min(Random(9)*32, 255),
1038 Min(Random(9)*32, 255),
1039 Min(Random(9)*32, 255)),
1040 Team
, True)) as TBot
do
1042 // Если имени нет, делаем его из UID бота
1044 Name
:= Format('DFBOT%.5d', [UID
])
1049 1: FDifficult
:= DIFFICULT_EASY
;
1050 2: FDifficult
:= DIFFICULT_MEDIUM
;
1051 else FDifficult
:= DIFFICULT_HARD
;
1054 for a
:= WP_FIRST
to WP_LAST
do
1056 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1057 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1058 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1061 FHandicap
:= Handicap
;
1063 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1065 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1066 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1071 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
1074 _name
, _model
: String;
1077 if not g_Game_IsServer
then Exit
;
1079 if (g_Bot_GetCount() >= gMaxBots
) then Exit
;
1081 // Список названий моделей:
1082 m
:= g_PlayerModel_GetNames();
1087 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1088 Team
:= TEAM_COOP
// COOP
1090 if gGameSettings
.GameMode
= GM_DM
then
1091 Team
:= TEAM_NONE
// DM
1093 if Team
= TEAM_NONE
then
1094 Team
:= BotList
[num
].team
; // CTF / TDM
1096 // Выбираем настройки бота из списка по номеру или имени:
1097 lName
:= AnsiLowerCase(lName
);
1098 if (num
< 0) or (num
> Length(BotList
)-1) then
1100 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1101 for a
:= 0 to High(BotList
) do
1102 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1111 _name
:= BotList
[num
].name
;
1112 // Занято - выбираем случайное:
1113 if not g_Player_ValidName(_name
) then
1115 _name
:= Format('DFBOT%.2d', [Random(100)]);
1116 until g_Player_ValidName(_name
);
1119 _model
:= BotList
[num
].model
;
1120 // Нет такой - выбираем случайную:
1121 if not InSArray(_model
, m
) then
1122 _model
:= m
[Random(Length(m
))];
1125 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1129 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1130 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1131 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1132 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1133 FDifficult
.Cover
:= BotList
[num
].cover
;
1134 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1136 FHandicap
:= Handicap
;
1138 for a
:= WP_FIRST
to WP_LAST
do
1140 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1141 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1142 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1145 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1147 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1151 procedure g_Bot_RemoveAll();
1155 if not g_Game_IsServer
then Exit
;
1156 if gPlayers
= nil then Exit
;
1158 for a
:= 0 to High(gPlayers
) do
1159 if gPlayers
[a
] <> nil then
1160 if gPlayers
[a
] is TBot
then
1162 gPlayers
[a
].Lives
:= 0;
1163 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1164 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1165 g_Player_Remove(gPlayers
[a
].FUID
);
1171 procedure g_Bot_MixNames();
1176 if BotNames
<> nil then
1177 for a
:= 0 to High(BotNames
) do
1179 b
:= Random(Length(BotNames
));
1181 Botnames
[a
] := BotNames
[b
];
1186 procedure g_Player_Remove(UID
: Word);
1190 if gPlayers
= nil then Exit
;
1192 if g_Game_IsServer
and g_Game_IsNet
then
1193 MH_SEND_PlayerDelete(UID
);
1195 for i
:= 0 to High(gPlayers
) do
1196 if gPlayers
[i
] <> nil then
1197 if gPlayers
[i
].FUID
= UID
then
1199 if gPlayers
[i
] is TPlayer
then
1200 TPlayer(gPlayers
[i
]).Free()
1202 TBot(gPlayers
[i
]).Free();
1208 procedure g_Player_Init();
1219 path
:= BOTNAMES_FILENAME
;
1220 if e_FindResource(DataDirs
, path
) = false then
1223 // Читаем возможные имена ботов из файла:
1224 AssignFile(F
, path
);
1235 SetLength(BotNames
, Length(BotNames
)+1);
1236 BotNames
[High(BotNames
)] := s
;
1244 // Читаем файл с параметрами ботов:
1245 config
:= TConfig
.CreateFile(path
);
1249 while config
.SectionExists(IntToStr(a
)) do
1251 SetLength(BotList
, Length(BotList
)+1);
1253 with BotList
[High(BotList
)] do
1256 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1258 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1260 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1265 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1266 color
.R
:= StrToIntDef(sa
[0], 0);
1267 color
.G
:= StrToIntDef(sa
[1], 0);
1268 color
.B
:= StrToIntDef(sa
[2], 0);
1269 // Вероятность стрельбы под углом:
1270 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1271 // Вероятность ответного огня по невидимому сопернику:
1272 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1273 // Точность стрельбы под углом:
1274 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1275 // Точность стрельбы в полете:
1276 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1277 // Точность уклонения от снарядов:
1278 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1279 // Вероятность прыжка при приближении соперника:
1280 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1281 // Приоритеты оружия для дальнего боя:
1282 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1283 if Length(sa
) = 10 then
1285 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1286 // Приоритеты оружия для ближнего боя:
1287 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1288 if Length(sa
) = 10 then
1290 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1292 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1293 if Length(sa) = 10 then
1295 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1302 SetLength(SavedStates
, 0);
1305 procedure g_Player_Free();
1309 if gPlayers
<> nil then
1311 for i
:= 0 to High(gPlayers
) do
1312 if gPlayers
[i
] <> nil then
1314 if gPlayers
[i
] is TPlayer
then
1315 TPlayer(gPlayers
[i
]).Free()
1317 TBot(gPlayers
[i
]).Free();
1326 SetLength(SavedStates
, 0);
1329 procedure g_Player_PreUpdate();
1333 if gPlayers
= nil then Exit
;
1334 for i
:= 0 to High(gPlayers
) do
1335 if gPlayers
[i
] <> nil then
1336 gPlayers
[i
].PreUpdate();
1339 procedure g_Player_UpdateAll();
1343 if gPlayers
= nil then Exit
;
1345 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1346 for i
:= 0 to High(gPlayers
) do
1348 if gPlayers
[i
] <> nil then
1350 if gPlayers
[i
] is TPlayer
then
1352 gPlayers
[i
].Update();
1353 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1357 // bot updates weapons in `UpdateCombat()`
1358 TBot(gPlayers
[i
]).Update();
1362 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1365 function g_Player_Get(UID
: Word): TPlayer
;
1371 if gPlayers
= nil then
1374 for a
:= 0 to High(gPlayers
) do
1375 if gPlayers
[a
] <> nil then
1376 if gPlayers
[a
].FUID
= UID
then
1378 Result
:= gPlayers
[a
];
1383 function g_Player_GetCount(): Byte;
1389 if gPlayers
= nil then
1392 for a
:= 0 to High(gPlayers
) do
1393 if gPlayers
[a
] <> nil then
1394 Result
:= Result
+ 1;
1397 function g_Bot_GetCount(): Integer;
1403 if gPlayers
= nil then
1406 for a
:= 0 to High(gPlayers
) do
1407 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] is TBot
) then
1408 Result
:= Result
+ 1;
1411 function g_Player_GetStats(): TPlayerStatArray
;
1417 if gPlayers
= nil then Exit
;
1419 for a
:= 0 to High(gPlayers
) do
1420 if gPlayers
[a
] <> nil then
1422 SetLength(Result
, Length(Result
)+1);
1423 with Result
[High(Result
)] do
1426 Ping
:= gPlayers
[a
].FPing
;
1427 Loss
:= gPlayers
[a
].FLoss
;
1428 Name
:= gPlayers
[a
].FName
;
1429 Team
:= gPlayers
[a
].FTeam
;
1430 Frags
:= gPlayers
[a
].FFrags
;
1431 Deaths
:= gPlayers
[a
].FDeath
;
1432 Kills
:= gPlayers
[a
].FKills
;
1433 Color
:= gPlayers
[a
].FModel
.Color
;
1434 Lives
:= gPlayers
[a
].FLives
;
1435 Spectator
:= gPlayers
[a
].FSpectator
;
1436 UID
:= gPlayers
[a
].FUID
;
1441 procedure g_Player_ResetReady();
1445 if not g_Game_IsServer
then Exit
;
1446 if gPlayers
= nil then Exit
;
1448 for a
:= 0 to High(gPlayers
) do
1449 if gPlayers
[a
] <> nil then
1451 gPlayers
[a
].FReady
:= False;
1452 if g_Game_IsNet
then
1453 MH_SEND_GameEvent(NET_EV_INTER_READY
, gPlayers
[a
].UID
, 'N');
1457 procedure g_Player_RememberAll
;
1461 for i
:= Low(gPlayers
) to High(gPlayers
) do
1462 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1463 gPlayers
[i
].RememberState
;
1466 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1470 gTeamStat
[TEAM_RED
].Score
:= 0;
1471 gTeamStat
[TEAM_BLUE
].Score
:= 0;
1473 if gPlayers
<> nil then
1474 for i
:= 0 to High(gPlayers
) do
1475 if gPlayers
[i
] <> nil then
1477 gPlayers
[i
].Reset(Force
);
1479 if gPlayers
[i
] is TPlayer
then
1481 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1482 gPlayers
[i
].Respawn(Silent
)
1484 gPlayers
[i
].Spectate();
1487 TBot(gPlayers
[i
]).Respawn(Silent
);
1491 function g_Player_CreateCorpse(Player
: TPlayer
): Integer;
1499 if Player
.alive
then
1502 // Разрываем связь с прежним трупом:
1503 i
:= Player
.FCorpse
;
1504 if (i
>= 0) and (i
< Length(gCorpses
)) then
1506 if (gCorpses
[i
] <> nil) and (gCorpses
[i
].FPlayerUID
= Player
.FUID
) then
1507 gCorpses
[i
].FPlayerUID
:= 0;
1510 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1515 if (FHealth
>= -50) or (gGibsCount
= 0) then
1517 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1521 for find_id
:= 0 to High(gCorpses
) do
1522 if gCorpses
[find_id
] = nil then
1529 find_id
:= Random(Length(gCorpses
));
1531 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.GetName(), FHealth
< -20);
1532 gCorpses
[find_id
].FModel
.Color
:= FModel
.Color
;
1533 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1534 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1535 gCorpses
[find_id
].FPlayerUID
:= FUID
;
1540 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
, FObj
.Y
+ PLAYER_RECT_CY
, FModel
.id
, FModel
.Color
);
1544 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1546 if (gShells
= nil) or (Length(gShells
) = 0) then
1549 with gShells
[CurrentShell
] do
1554 if T
= SHELL_BULLET
then
1556 Obj
.Rect
.Width
:= 4;
1557 Obj
.Rect
.Height
:= 2;
1561 Obj
.Rect
.Width
:= 7;
1562 Obj
.Rect
.Height
:= 3;
1568 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1569 positionChanged(); // this updates spatial accelerators
1570 RAngle
:= Random(360);
1571 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1573 if CurrentShell
>= High(gShells
) then
1580 procedure g_Player_CreateGibs (fX
, fY
, mid
: Integer; fColor
: TRGB
);
1583 GibsArray
: TGibsArray
;
1588 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1590 if not g_PlayerModel_GetGibs(mid
, GibsArray
) then
1592 Blood
:= PlayerModelsArray
[mid
].Blood
;
1594 for a
:= 0 to High(GibsArray
) do
1595 with gGibs
[CurrentGib
] do
1598 GibID
:= GibsArray
[a
];
1603 Obj
.Rect
:= r_Render_GetGibRect(ModelID
, GibID
);
1607 Obj
.Rect
.Width
:= 16;
1608 Obj
.Rect
.Height
:= 16;
1610 Obj
.X
:= fX
- Obj
.Rect
.X
- (Obj
.Rect
.Width
div 2);
1611 Obj
.Y
:= fY
- Obj
.Rect
.Y
- (Obj
.Rect
.Height
div 2);
1612 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1613 positionChanged(); // this updates spatial accelerators
1614 RAngle
:= Random(360);
1616 if gBloodCount
> 0 then
1617 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1618 Random(48), Random(48), Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
1620 if CurrentGib
>= High(gGibs
) then
1627 procedure g_Player_UpdatePhysicalObjects();
1633 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1638 if T
= SHELL_BULLET
then
1639 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1641 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1646 if gGibs
<> nil then
1647 for i
:= 0 to High(gGibs
) do
1648 if gGibs
[i
].alive
then
1655 mr
:= g_Obj_Move(@Obj
, True, False, True);
1656 positionChanged(); // this updates spatial accelerators
1658 if WordBool(mr
and MOVE_FALLOUT
) then
1664 // Отлетает от удара о стену/потолок/пол:
1665 if WordBool(mr
and MOVE_HITWALL
) then
1666 Obj
.Vel
.X
:= -(vel
.X
div 2);
1667 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1668 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1670 if (Obj
.Vel
.X
>= 0) then
1672 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1673 if RAngle
>= 360 then
1674 RAngle
:= RAngle
mod 360;
1675 end else begin // Counter-clockwise
1676 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1678 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1681 // Сопротивление воздуха для куска трупа:
1682 if gTime
mod (GAME_TICK
*3) = 0 then
1683 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1687 if gCorpses
<> nil then
1688 for i
:= 0 to High(gCorpses
) do
1689 if gCorpses
[i
] <> nil then
1690 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1696 gCorpses
[i
].Update();
1699 if gShells
<> nil then
1700 for i
:= 0 to High(gShells
) do
1701 if gShells
[i
].alive
then
1708 mr
:= g_Obj_Move(@Obj
, True, False, True);
1709 positionChanged(); // this updates spatial accelerators
1711 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1717 // Отлетает от удара о стену/потолок/пол:
1718 if WordBool(mr
and MOVE_HITWALL
) then
1720 Obj
.Vel
.X
:= -(vel
.X
div 2);
1721 if not WordBool(mr
and MOVE_INWATER
) then
1722 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1724 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1726 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1727 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1728 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1730 if RAngle
mod 90 <> 0 then
1731 RAngle
:= (RAngle
div 90) * 90;
1733 else if not WordBool(mr
and MOVE_INWATER
) then
1734 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1737 if (Obj
.Vel
.X
>= 0) then
1739 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1740 if RAngle
>= 360 then
1741 RAngle
:= RAngle
mod 360;
1742 end else begin // Counter-clockwise
1743 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1745 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1751 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1753 x
:= Obj
.X
+Obj
.Rect
.X
;
1754 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1755 w
:= Obj
.Rect
.Width
;
1756 h
:= Obj
.Rect
.Height
;
1759 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1761 if (dx
<> 0) or (dy
<> 0) then
1770 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1774 w
:= Obj
.Rect
.Width
;
1775 h
:= Obj
.Rect
.Height
;
1778 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1780 if (dx
<> 0) or (dy
<> 0) then
1789 procedure TGib
.positionChanged (); inline; begin end;
1790 procedure TShell
.positionChanged (); inline; begin end;
1793 procedure g_Player_RemoveAllCorpses();
1799 SetLength(gGibs
, MaxGibs
);
1800 SetLength(gShells
, MaxGibs
);
1804 if gCorpses
<> nil then
1805 for i
:= 0 to High(gCorpses
) do
1809 SetLength(gCorpses
, MaxCorpses
);
1812 procedure g_Player_Corpses_SaveState (st
: TStream
);
1816 // Считаем количество существующих трупов
1818 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1820 // Количество трупов
1821 utils
.writeInt(st
, LongInt(count
));
1823 if (count
= 0) then exit
;
1826 for i
:= 0 to High(gCorpses
) do
1828 if gCorpses
[i
] <> nil then
1831 utils
.writeStr(st
, gCorpses
[i
].FModel
.GetName());
1833 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1834 // Сохраняем данные трупа:
1835 gCorpses
[i
].SaveState(st
);
1841 procedure g_Player_Corpses_LoadState (st
: TStream
);
1849 g_Player_RemoveAllCorpses();
1851 // Количество трупов:
1852 count
:= utils
.readLongInt(st
);
1853 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1855 if (count
= 0) then exit
;
1858 for i
:= 0 to count
-1 do
1861 str
:= utils
.readStr(st
);
1863 b
:= utils
.readBool(st
);
1865 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1866 // Загружаем данные трупа
1867 gCorpses
[i
].LoadState(st
);
1874 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1876 procedure TPlayer
.BFGHit();
1878 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1879 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1880 if g_Game_IsServer
and g_Game_IsNet
then
1881 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1882 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1886 procedure TPlayer
.ChangeModel(ModelName
: string);
1888 locModel
: TPlayerModel
;
1890 locModel
:= g_PlayerModel_Get(ModelName
);
1891 if locModel
= nil then Exit
;
1897 procedure TPlayer
.SetModel(ModelName
: string);
1901 m
:= g_PlayerModel_Get(ModelName
);
1904 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1905 m
:= g_PlayerModel_Get('doomer');
1908 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1913 if FModel
<> nil then
1918 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1919 FModel
.Color
:= FColor
1921 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1922 FModel
.SetWeapon(FCurrWeap
);
1923 FModel
.SetFlag(FFlag
);
1924 SetDirection(FDirection
);
1927 procedure TPlayer
.SetColor(Color
: TRGB
);
1930 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1931 if FModel
<> nil then FModel
.Color
:= Color
;
1936 function TPlayer
.GetColor(): TRGB
;
1938 result
:= FModel
.Color
;
1941 procedure TPlayer
.SetWeaponPrefs(Prefs
: Array of Byte);
1945 for i
:= WP_FIRST
to WP_LAST
+ 1 do
1947 if (Prefs
[i
] > WP_LAST
+ 1) then
1948 FWeapPreferences
[i
] := 0
1950 FWeapPreferences
[i
] := Prefs
[i
];
1954 procedure TPlayer
.SetWeaponPref(Weapon
, Pref
: Byte);
1956 if (Weapon
> WP_LAST
+ 1) then
1958 else if (Pref
<= WP_LAST
+ 1) and (Weapon
<= WP_LAST
+ 1) then
1959 FWeapPreferences
[Weapon
] := Pref
1960 else if (Weapon
<= WP_LAST
+ 1) and (Pref
> WP_LAST
+ 1) then
1961 FWeapPreferences
[Weapon
] := 0;
1964 function TPlayer
.GetWeaponPref(Weapon
: Byte) : Byte;
1966 if (Weapon
> WP_LAST
+ 1) then
1968 else if (FWeapPreferences
[Weapon
] > WP_LAST
+ 1) then
1971 result
:= FWeapPreferences
[Weapon
];
1974 function TPlayer
.GetMorePrefered() : Byte;
1976 testedWeap
, i
: Byte;
1978 testedWeap
:= FCurrWeap
;
1979 for i
:= WP_FIRST
to WP_LAST
do
1980 if FWeapon
[i
] and maySwitch(i
) and (FWeapPreferences
[i
] > FWeapPreferences
[testedWeap
]) then
1982 if (R_BERSERK
in FRulez
) and (FWeapPreferences
[WP_LAST
+ 1] > FWeapPreferences
[testedWeap
]) then
1983 testedWeap
:= WEAPON_KASTET
;
1984 result
:= testedWeap
;
1987 function TPlayer
.maySwitch(Weapon
: Byte) : Boolean;
1990 if (Weapon
= WEAPON_KASTET
) and (FSkipFist
<> 0) then
1992 if (FSkipFist
= 1) and (not (R_BERSERK
in FRulez
)) then
1995 else if (FSwitchToEmpty
= 0) and (not hasAmmoForShooting(Weapon
)) then
1999 procedure TPlayer
.SwitchTeam
;
2001 if g_Game_IsClient
then
2003 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
2005 if gGameOn
and FAlive
then
2006 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
2008 if FTeam
= TEAM_RED
then
2010 ChangeTeam(TEAM_BLUE
);
2011 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
2012 if g_Game_IsNet
then
2013 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
2017 ChangeTeam(TEAM_RED
);
2018 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
2019 if g_Game_IsNet
then
2020 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
2022 FPreferredTeam
:= FTeam
;
2025 procedure TPlayer
.ChangeTeam(Team
: Byte);
2032 TEAM_RED
, TEAM_BLUE
:
2033 FModel
.Color
:= TEAMCOLOR
[Team
];
2035 FModel
.Color
:= FColor
;
2037 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2038 MH_SEND_PlayerStats(FUID
);
2042 procedure TPlayer.CollideItem();
2047 if gItems = nil then Exit;
2048 if not FAlive then Exit;
2050 for i := 0 to High(gItems) do
2053 if (ItemType <> ITEM_NONE) and alive then
2054 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2055 PLAYER_RECT.Height, @Obj) then
2057 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2059 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2060 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2061 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2062 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2063 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2065 // Надо убрать с карты, если это не ключ, которым нужно поделится с другим игроком:
2066 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2067 (gGameSettings.GameType = GT_SINGLE) and
2068 (g_Player_GetCount() > 1)) then
2069 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2075 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2077 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2078 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2082 constructor TPlayer
.Create();
2088 mEDamageType
:= HIT_SOME
;
2094 FSawSound
:= TPlayableSound
.Create();
2095 FSawSoundIdle
:= TPlayableSound
.Create();
2096 FSawSoundHit
:= TPlayableSound
.Create();
2097 FSawSoundSelect
:= TPlayableSound
.Create();
2098 FFlameSoundOn
:= TPlayableSound
.Create();
2099 FFlameSoundOff
:= TPlayableSound
.Create();
2100 FFlameSoundWork
:= TPlayableSound
.Create();
2101 FJetSoundFly
:= TPlayableSound
.Create();
2102 FJetSoundOn
:= TPlayableSound
.Create();
2103 FJetSoundOff
:= TPlayableSound
.Create();
2105 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2106 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2107 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2108 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2109 FFlameSoundOn
.SetByName('SOUND_WEAPON_FLAMEON');
2110 FFlameSoundOff
.SetByName('SOUND_WEAPON_FLAMEOFF');
2111 FFlameSoundWork
.SetByName('SOUND_WEAPON_FLAMEWORK');
2112 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2113 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2114 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2116 FSpectatePlayer
:= -1;
2120 FSavedStateNum
:= -1;
2128 FActualModelName
:= 'doomer';
2131 FObj
.Rect
:= PLAYER_RECT
;
2133 FBFGFireCounter
:= -1;
2134 FJustTeleported
:= False;
2137 FWaitForFirstSpawn
:= false;
2138 FPunchAnim
:= TAnimationState
.Create(False, 1, 4);
2144 procedure TPlayer
.positionChanged (); inline;
2148 procedure TPlayer
.doDamage (v
: Integer);
2150 if (v
<= 0) then exit
;
2151 if (v
> 32767) then v
:= 32767;
2152 Damage(v
, 0, 0, 0, mEDamageType
);
2155 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2159 if (not g_Game_IsClient
) and (not FAlive
) then
2164 // Неуязвимость не спасает от ловушек:
2165 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2167 if not g_Game_IsClient
then
2170 if t
= HIT_TRAP
then
2172 // Ловушка убивает сразу:
2174 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2176 if t
= HIT_SELF
then
2180 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2183 // Обнулить действия примочек, чтобы фон пропал
2184 FMegaRulez
[MR_SUIT
] := 0;
2185 FMegaRulez
[MR_INVUL
] := 0;
2186 FMegaRulez
[MR_INVIS
] := 0;
2191 // Но от остального спасает:
2192 if FMegaRulez
[MR_INVUL
] >= gTime
then
2199 // Если есть урон своим, или ранил сам себя, или тебя ранил противник:
2200 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2201 (SpawnerUID
= FUID
) or
2202 (not SameTeam(FUID
, SpawnerUID
)) then
2204 FLastSpawnerUID
:= SpawnerUID
;
2206 // Кровь (пузырьки, если в воде):
2207 if gBloodCount
> 0 then
2209 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2210 if value
div 4 <= c
then
2211 c
:= c
- (value
div 4)
2215 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2219 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2220 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2223 if t
= HIT_WATER
then
2225 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2226 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2228 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
2229 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
2235 Inc(FDamageBuffer
, value
);
2239 FPain
:= FPain
+ value
;
2242 if g_Game_IsServer
and g_Game_IsNet
then
2244 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2245 MH_SEND_PlayerStats(FUID
);
2246 MH_SEND_PlayerPos(False, FUID
);
2250 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2253 if g_Game_IsClient
then
2258 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2260 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2263 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2265 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2269 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2270 MH_SEND_PlayerStats(FUID
);
2273 destructor TPlayer
.Destroy();
2275 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2277 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2281 FSawSoundIdle
.Free();
2282 FSawSoundHit
.Free();
2283 FSawSoundSelect
.Free();
2284 FFlameSoundOn
.Free();
2285 FFlameSoundOff
.Free();
2286 FFlameSoundWork
.Free();
2287 FJetSoundFly
.Free();
2289 FJetSoundOff
.Free();
2296 procedure TPlayer
.DoPunch();
2302 procedure TPlayer
.Fire();
2304 f
, DidFire
: Boolean;
2305 wx
, wy
, xd
, yd
: Integer;
2308 if g_Game_IsClient
then Exit
;
2309 // FBFGFireCounter - время перед выстрелом (для BFG)
2310 // FReloading - время после выстрела (для всего)
2318 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2323 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2324 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2325 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
2326 yd
:= wy
+firediry();
2332 if R_BERSERK
in FRulez
then
2334 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2335 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2336 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2339 locobj
.rect
.Width
:= 39;
2340 locobj
.rect
.Height
:= 52;
2341 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2342 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2343 locobj
.Accel
.X
:= xd
-wx
;
2344 locobj
.Accel
.y
:= yd
-wy
;
2346 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2347 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2349 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2351 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
2355 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2359 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2364 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2365 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2367 FSawSoundSelect
.Stop();
2369 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2371 else if not FSawSoundHit
.IsPlaying() then
2373 FSawSoundSelect
.Stop();
2374 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2377 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2383 if FAmmo
[A_BULLETS
] > 0 then
2385 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2386 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2387 Dec(FAmmo
[A_BULLETS
]);
2388 FFireAngle
:= FAngle
;
2391 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2392 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2396 if FAmmo
[A_SHELLS
] > 0 then
2398 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2399 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
2400 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2401 Dec(FAmmo
[A_SHELLS
]);
2402 FFireAngle
:= FAngle
;
2406 FShellType
:= SHELL_SHELL
;
2410 if FAmmo
[A_SHELLS
] >= 2 then
2412 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
2413 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2414 Dec(FAmmo
[A_SHELLS
], 2);
2415 FFireAngle
:= FAngle
;
2419 FShellType
:= SHELL_DBLSHELL
;
2423 if FAmmo
[A_BULLETS
] > 0 then
2425 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
2426 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
2427 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2428 Dec(FAmmo
[A_BULLETS
]);
2429 FFireAngle
:= FAngle
;
2432 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2433 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2436 WEAPON_ROCKETLAUNCHER
:
2437 if FAmmo
[A_ROCKETS
] > 0 then
2439 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
2440 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2441 Dec(FAmmo
[A_ROCKETS
]);
2442 FFireAngle
:= FAngle
;
2448 if FAmmo
[A_CELLS
] > 0 then
2450 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
2451 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2452 Dec(FAmmo
[A_CELLS
]);
2453 FFireAngle
:= FAngle
;
2459 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
2461 FBFGFireCounter
:= 17;
2462 if not FNoReload
then
2463 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
2464 Dec(FAmmo
[A_CELLS
], 40);
2468 WEAPON_SUPERPULEMET
:
2469 if FAmmo
[A_SHELLS
] > 0 then
2471 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2472 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
2473 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2474 Dec(FAmmo
[A_SHELLS
]);
2475 FFireAngle
:= FAngle
;
2478 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2479 GameVelX
, GameVelY
-2, SHELL_SHELL
);
2482 WEAPON_FLAMETHROWER
:
2483 if FAmmo
[A_FUEL
] > 0 then
2485 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
2487 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2489 FFireAngle
:= FAngle
;
2496 if g_Game_IsNet
and g_Game_IsServer
then MH_SEND_PlayerStats(FUID
);
2500 if g_Game_IsNet
then
2504 if FCurrWeap
<> WEAPON_BFG
then
2505 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
2507 if not FNoReload
then
2508 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
2511 MH_SEND_PlayerStats(FUID
);
2516 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
2517 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
2518 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
2521 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
2524 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
2525 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
2526 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
2527 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
2528 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
2533 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
2535 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
2536 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
2537 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
2540 procedure TPlayer
.FlamerOn
;
2542 FFlameSoundOff
.Stop();
2543 FFlameSoundOff
.SetPosition(0);
2546 if (not FFlameSoundOn
.IsPlaying()) and (not FFlameSoundWork
.IsPlaying()) then
2547 FFlameSoundWork
.PlayAt(FObj
.X
, FObj
.Y
);
2551 FFlameSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
2556 procedure TPlayer
.FlamerOff
;
2560 FFlameSoundOn
.Stop();
2561 FFlameSoundOn
.SetPosition(0);
2562 FFlameSoundWork
.Stop();
2563 FFlameSoundWork
.SetPosition(0);
2564 FFlameSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
2569 procedure TPlayer
.JetpackOn
;
2573 FJetSoundOn
.SetPosition(0);
2574 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
2578 procedure TPlayer
.JetpackOff
;
2582 FJetSoundOff
.SetPosition(0);
2583 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
2586 procedure TPlayer
.CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
2588 if Timeout
<= 0 then
2590 if (FMegaRulez
[MR_SUIT
] > gTime
) or (FMegaRulez
[MR_INVUL
] > gTime
) then
2591 exit
; // Не загораемся когда есть защита
2592 if g_Obj_CollidePanel(@FObj
, 0, 0, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
) then
2593 exit
; // Не подгораем в воде на всякий случай
2594 if FFireTime
<= 0 then
2595 g_Sound_PlayExAt('SOUND_IGNITE', FObj
.X
, FObj
.Y
);
2596 FFireTime
:= Timeout
;
2597 FFireAttacker
:= Attacker
;
2598 if g_Game_IsNet
and g_Game_IsServer
then
2599 MH_SEND_PlayerStats(FUID
);
2602 procedure TPlayer
.Jump();
2604 if gFly
or FJetpack
then
2606 // Полет (чит-код или джетпак):
2607 if FObj
.Vel
.Y
> -VEL_FLY
then
2608 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
2611 if FJetFuel
> 0 then
2613 if (FJetFuel
< 1) and g_Game_IsServer
then
2617 if g_Game_IsNet
then
2618 MH_SEND_PlayerStats(FUID
);
2624 // Не включать джетпак в режиме прохождения сквозь стены
2626 FCanJetpack
:= False;
2628 // Прыгаем или всплываем:
2629 if (CollideLevel(0, 1) or
2630 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
2631 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
2632 ) and (FObj
.Accel
.Y
= 0) then // Не прыгать, если есть вертикальное ускорение
2634 FObj
.Vel
.Y
:= -VEL_JUMP
;
2635 FCanJetpack
:= False;
2639 if BodyInLiquid(0, 0) then
2640 FObj
.Vel
.Y
:= -VEL_SW
2641 else if (FJetFuel
> 0) and FCanJetpack
and
2642 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
2646 if g_Game_IsNet
then
2647 MH_SEND_PlayerStats(FUID
);
2652 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
2654 a
, i
, k
, ab
, ar
: Byte;
2658 srv
, netsrv
: Boolean;
2664 procedure PushItem(t
: Byte);
2668 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
2669 it
:= g_Items_ByIdx(id
);
2670 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
2672 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
2673 (FObj
.Vel
.Y
div 2)-Random(9));
2674 it
.positionChanged(); // this updates spatial accelerators
2678 if KillType
= K_HARDKILL
then // -5..+5; -5..0
2680 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
2681 (FObj
.Vel
.Y
div 2)-Random(6));
2683 else // -3..+3; -3..0
2685 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
2686 (FObj
.Vel
.Y
div 2)-Random(4));
2688 it
.positionChanged(); // this updates spatial accelerators
2691 if g_Game_IsNet
and g_Game_IsServer
then
2692 MH_SEND_ItemSpawn(True, id
);
2696 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
2697 Srv
:= g_Game_IsServer
;
2698 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
2699 if Srv
then FDeath
:= FDeath
+ 1;
2704 if not FPhysics
then
2710 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2712 if FLives
> 0 then FLives
:= FLives
- 1;
2713 if FLives
= 0 then FNoRespawn
:= True;
2716 // Номер типа смерти:
2719 K_SIMPLEKILL
: a
:= 1;
2721 K_EXTRAHARDKILL
: a
:= 3;
2726 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
2728 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
2735 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
2737 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
2738 K_EXTRAHARDKILL
, K_FALLKILL
:
2739 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
2742 // Переключаем состояние:
2746 K_HARDKILL
, K_EXTRAHARDKILL
:
2750 // Реакция монстров на смерть игрока:
2751 if (KillType
<> K_FALLKILL
) and (Srv
) then
2752 g_Monsters_killedp();
2754 if SpawnerUID
= FUID
then
2758 if gGameSettings
.GameMode
= GM_TDM
then
2759 Dec(gTeamStat
[FTeam
].Score
);
2760 if DoFrags
or (gGameSettings
.GameMode
= GM_TDM
) then
2766 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
2769 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
2770 begin // Убит другим игроком
2771 KP
:= g_Player_Get(SpawnerUID
);
2772 if (KP
<> nil) and Srv
then
2774 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
2775 if SameTeam(FUID
, SpawnerUID
) then
2785 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
2786 Inc(gTeamStat
[KP
.Team
].Score
,
2787 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
2789 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
2792 plr
:= g_Player_Get(SpawnerUID
);
2800 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
2804 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
2808 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
2813 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
2814 begin // Убит монстром
2815 mon
:= g_Monsters_ByUID(SpawnerUID
);
2819 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
2823 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
2827 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
2831 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
2836 else // Особые типы смерти
2839 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
2840 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
2841 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
2842 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
2843 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
2844 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
2850 for a
:= WP_FIRST
to WP_LAST
do
2854 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
2855 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
2856 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
2857 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
2858 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
2859 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
2860 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
2861 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
2862 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
2871 if R_ITEM_BACKPACK
in FRulez
then
2872 PushItem(ITEM_AMMO_BACKPACK
);
2874 // Выброс ракетного ранца:
2875 if FJetFuel
> 0 then
2876 PushItem(ITEM_JETPACK
);
2879 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) or
2880 (not LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
)) then
2882 if R_KEY_RED
in FRulez
then
2883 PushItem(ITEM_KEY_RED
);
2885 if R_KEY_GREEN
in FRulez
then
2886 PushItem(ITEM_KEY_GREEN
);
2888 if R_KEY_BLUE
in FRulez
then
2889 PushItem(ITEM_KEY_BLUE
);
2893 DropFlag(KillType
= K_FALLKILL
);
2896 FCorpse
:= g_Player_CreateCorpse(Self
);
2898 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
2899 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2905 for i
:= Low(gPlayers
) to High(gPlayers
) do
2907 if gPlayers
[i
] = nil then continue
;
2908 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
2911 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
2912 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
2917 OldLR
:= gLMSRespawn
;
2918 if (gGameSettings
.GameMode
= GM_COOP
) then
2922 // everyone is dead, restart the map
2923 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
2925 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
2926 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2927 gLMSRespawnTime
:= gTime
+ 5000;
2929 else if (a
= 1) then
2931 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
2932 if (gPlayers
[k
] = gPlayer1
) or
2933 (gPlayers
[k
] = gPlayer2
) then
2934 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
2935 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
2936 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
2939 else if (gGameSettings
.GameMode
= GM_TDM
) then
2941 if (ab
= 0) and (ar
<> 0) then
2944 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
2946 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
2947 Inc(gTeamStat
[TEAM_RED
].Score
);
2948 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2949 gLMSRespawnTime
:= gTime
+ 5000;
2951 else if (ar
= 0) and (ab
<> 0) then
2954 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
2956 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
2957 Inc(gTeamStat
[TEAM_BLUE
].Score
);
2958 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2959 gLMSRespawnTime
:= gTime
+ 5000;
2961 else if (ar
= 0) and (ab
= 0) then
2964 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
2966 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
2967 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2968 gLMSRespawnTime
:= gTime
+ 5000;
2971 else if (gGameSettings
.GameMode
= GM_DM
) then
2975 if gPlayers
[k
] <> nil then
2978 // survivor is the winner
2979 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
2981 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
2984 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2985 gLMSRespawnTime
:= gTime
+ 5000;
2987 else if (a
= 0) then
2989 // everyone is dead, restart the map
2990 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
2992 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
2993 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2994 gLMSRespawnTime
:= gTime
+ 5000;
2997 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
2999 if NetMode
= NET_SERVER
then
3000 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
)
3002 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3008 MH_SEND_PlayerStats(FUID
);
3009 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3010 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3013 if srv
and FNoRespawn
then Spectate(True);
3014 FWantsInGame
:= True;
3017 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3019 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3020 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3023 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3025 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3026 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3029 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3030 var Blood
: TModelBlood
;
3032 Blood
:= SELF
.FModel
.GetBlood();
3033 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3034 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3035 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3036 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
3037 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3038 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3039 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3040 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
3043 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3044 var Blood
: TModelBlood
;
3046 Blood
:= SELF
.FModel
.GetBlood();
3047 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3048 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3049 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3050 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
3053 procedure TPlayer
.ProcessWeaponAction(Action
: Byte);
3055 if g_Game_IsClient
then Exit
;
3057 WP_PREV
: PrevWeapon();
3058 WP_NEXT
: NextWeapon();
3062 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3064 if g_Game_IsClient
then Exit
;
3065 if Weapon
> High(FWeapon
) then Exit
;
3066 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3069 procedure TPlayer
.resetWeaponQueue ();
3072 FNextWeapDelay
:= 0;
3075 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3079 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3080 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
3081 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
3082 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3083 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3084 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3085 else result
:= (weapon
< length(FWeapon
));
3089 function TPlayer
.hasAmmoForShooting (weapon
: Byte): Boolean;
3093 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3094 WEAPON_SHOTGUN1
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
3095 WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 1);
3096 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
3097 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3098 WEAPON_PLASMA
: result
:= (FAmmo
[A_CELLS
] > 0);
3099 WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] >= 40);
3100 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3101 else result
:= (weapon
< length(FWeapon
));
3105 function TPlayer
.shouldSwitch (weapon
: Byte; hadWeapon
: Boolean): Boolean;
3108 if (weapon
> WP_LAST
+ 1) then
3113 if (FWeapSwitchMode
= 1) and not hadWeapon
then
3115 else if (FWeapSwitchMode
= 2) then
3116 result
:= (FWeapPreferences
[weapon
] > FWeapPreferences
[FCurrWeap
]);
3119 // return 255 for "no switch"
3120 function TPlayer
.getNextWeaponIndex (): Byte;
3123 wantThisWeapon
: array[0..64] of Boolean;
3124 wwc
: Integer = 0; //HACK!
3127 result
:= 255; // default result: "no switch"
3128 //e_LogWriteFln('FSWITCHTOEMPTY: %s', [FSwitchToEmpty], TMsgType.Notify);
3129 // had weapon cycling on previous frame? remove that flag
3130 if (FNextWeap
and $2000) <> 0 then
3132 FNextWeap
:= FNextWeap
and $1FFF;
3133 FNextWeapDelay
:= 0;
3135 // cycling has priority
3136 if (FNextWeap
and $C000) <> 0 then
3138 if (FNextWeap
and $8000) <> 0 then
3142 FNextWeap
:= FNextWeap
or $2000; // we need this
3143 if FNextWeapDelay
> 0 then
3144 exit
; // cooldown time
3146 for i
:= 0 to High(FWeapon
) do
3148 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3149 if FWeapon
[cwi
] and maySwitch(cwi
) then
3151 //e_LogWriteFln(' SWITCH: cur=%d; new=%d %s %s', [FCurrWeap, cwi, FSwitchToEmpty, hasAmmoForWeapon(cwi)], TMsgType.Notify);
3152 result
:= Byte(cwi
);
3153 FNextWeapDelay
:= WEAPON_DELAY
;
3161 for i
:= 0 to High(wantThisWeapon
) do
3162 wantThisWeapon
[i
] := false;
3163 for i
:= 0 to High(FWeapon
) do
3164 if (FNextWeap
and (1 shl i
)) <> 0 then
3166 wantThisWeapon
[i
] := true;
3170 // exclude currently selected weapon from the set
3171 wantThisWeapon
[FCurrWeap
] := false;
3172 // slow down alterations a little
3175 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3176 // more than one weapon requested, assume "alteration" and check alteration delay
3177 if FNextWeapDelay
> 0 then
3183 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3184 // but clear all counters if no weapon should be switched
3190 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3191 // try weapons in descending order
3192 for i
:= High(FWeapon
) downto 0 do
3194 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3199 FNextWeapDelay
:= WEAPON_DELAY
* 2; // anyway, 'cause why not
3200 //e_LogWriteFln('FOUND %s %s %s', [result, FSwitchToEmpty, hasAmmoForWeapon(i)], TMsgType.Notify);
3204 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3208 procedure TPlayer
.RealizeCurrentWeapon();
3209 function switchAllowed (): Boolean;
3214 if FBFGFireCounter
<> -1 then
3216 if FTime
[T_SWITCH
] > gTime
then
3218 for i
:= WP_FIRST
to WP_LAST
do
3219 if FReloading
[i
] > 0 then
3227 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3228 //FNextWeap := FNextWeap and $1FFF;
3229 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3231 if not switchAllowed
then
3233 //HACK for weapon cycling
3234 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3238 nw
:= getNextWeaponIndex();
3240 if nw
= 255 then exit
; // don't reset anything here
3241 if nw
> High(FWeapon
) then
3243 // don't forget to reset queue here!
3244 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3252 FTime
[T_SWITCH
] := gTime
+156;
3253 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3254 FModel
.SetWeapon(FCurrWeap
);
3255 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3259 procedure TPlayer
.NextWeapon();
3261 if g_Game_IsClient
then Exit
;
3265 procedure TPlayer
.PrevWeapon();
3267 if g_Game_IsClient
then Exit
;
3271 procedure TPlayer
.SetWeapon(W
: Byte);
3273 if FCurrWeap
<> W
then
3274 if W
= WEAPON_SAW
then
3275 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3278 FModel
.SetWeapon(CurrWeap
);
3282 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3285 switchWeapon
: Byte = 255;
3286 hadWeapon
: Boolean = False;
3289 if g_Game_IsClient
then Exit
;
3291 // a = true - место спавна предмета:
3292 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3296 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3298 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3302 if gFlash
= 2 then Inc(FPickup
, 5);
3306 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3308 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3312 if gFlash
= 2 then Inc(FPickup
, 5);
3316 if FArmor
< PLAYER_AP_SOFT
then
3318 FArmor
:= PLAYER_AP_SOFT
;
3321 if gFlash
= 2 then Inc(FPickup
, 5);
3325 if FArmor
< PLAYER_AP_LIMIT
then
3327 FArmor
:= PLAYER_AP_LIMIT
;
3330 if gFlash
= 2 then Inc(FPickup
, 5);
3334 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
3336 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3340 if gFlash
= 2 then Inc(FPickup
, 5);
3344 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) or (FFireTime
> 0) then
3346 if FHealth
< PLAYER_HP_LIMIT
then
3347 FHealth
:= PLAYER_HP_LIMIT
;
3348 if FArmor
< PLAYER_AP_LIMIT
then
3349 FArmor
:= PLAYER_AP_LIMIT
;
3353 if gFlash
= 2 then Inc(FPickup
, 5);
3357 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3359 hadWeapon
:= FWeapon
[WEAPON_SAW
];
3360 switchWeapon
:= WEAPON_SAW
;
3361 FWeapon
[WEAPON_SAW
] := True;
3363 if gFlash
= 2 then Inc(FPickup
, 5);
3364 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3367 ITEM_WEAPON_SHOTGUN1
:
3368 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3370 // Нужно, чтобы не взять все пули сразу:
3371 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3372 hadWeapon
:= FWeapon
[WEAPON_SHOTGUN1
];
3373 switchWeapon
:= WEAPON_SHOTGUN1
;
3374 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3375 FWeapon
[WEAPON_SHOTGUN1
] := True;
3377 if gFlash
= 2 then Inc(FPickup
, 5);
3378 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3381 ITEM_WEAPON_SHOTGUN2
:
3382 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3384 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3385 hadWeapon
:= FWeapon
[WEAPON_SHOTGUN2
];
3386 switchWeapon
:= WEAPON_SHOTGUN2
;
3387 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3388 FWeapon
[WEAPON_SHOTGUN2
] := True;
3390 if gFlash
= 2 then Inc(FPickup
, 5);
3391 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3394 ITEM_WEAPON_CHAINGUN
:
3395 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3397 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3398 hadWeapon
:= FWeapon
[WEAPON_CHAINGUN
];
3399 switchWeapon
:= WEAPON_CHAINGUN
;
3400 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3401 FWeapon
[WEAPON_CHAINGUN
] := True;
3403 if gFlash
= 2 then Inc(FPickup
, 5);
3404 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3407 ITEM_WEAPON_ROCKETLAUNCHER
:
3408 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3410 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3411 switchWeapon
:= WEAPON_ROCKETLAUNCHER
;
3412 hadWeapon
:= FWeapon
[WEAPON_ROCKETLAUNCHER
];
3413 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3414 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3416 if gFlash
= 2 then Inc(FPickup
, 5);
3417 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3421 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3423 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3424 switchWeapon
:= WEAPON_PLASMA
;
3425 hadWeapon
:= FWeapon
[WEAPON_PLASMA
];
3426 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3427 FWeapon
[WEAPON_PLASMA
] := True;
3429 if gFlash
= 2 then Inc(FPickup
, 5);
3430 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3434 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3436 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3437 switchWeapon
:= WEAPON_BFG
;
3438 hadWeapon
:= FWeapon
[WEAPON_BFG
];
3439 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3440 FWeapon
[WEAPON_BFG
] := True;
3442 if gFlash
= 2 then Inc(FPickup
, 5);
3443 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3446 ITEM_WEAPON_SUPERPULEMET
:
3447 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3449 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3450 switchWeapon
:= WEAPON_SUPERPULEMET
;
3451 hadWeapon
:= FWeapon
[WEAPON_SUPERPULEMET
];
3452 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3453 FWeapon
[WEAPON_SUPERPULEMET
] := True;
3455 if gFlash
= 2 then Inc(FPickup
, 5);
3456 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3459 ITEM_WEAPON_FLAMETHROWER
:
3460 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
3462 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
3463 switchWeapon
:= WEAPON_FLAMETHROWER
;
3464 hadWeapon
:= FWeapon
[WEAPON_FLAMETHROWER
];
3465 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3466 FWeapon
[WEAPON_FLAMETHROWER
] := True;
3468 if gFlash
= 2 then Inc(FPickup
, 5);
3469 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3473 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3475 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3478 if gFlash
= 2 then Inc(FPickup
, 5);
3481 ITEM_AMMO_BULLETS_BOX
:
3482 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3484 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3487 if gFlash
= 2 then Inc(FPickup
, 5);
3491 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3493 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3496 if gFlash
= 2 then Inc(FPickup
, 5);
3499 ITEM_AMMO_SHELLS_BOX
:
3500 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3502 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
3505 if gFlash
= 2 then Inc(FPickup
, 5);
3509 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3511 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3514 if gFlash
= 2 then Inc(FPickup
, 5);
3517 ITEM_AMMO_ROCKET_BOX
:
3518 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3520 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
3523 if gFlash
= 2 then Inc(FPickup
, 5);
3527 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3529 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3532 if gFlash
= 2 then Inc(FPickup
, 5);
3536 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3538 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
3541 if gFlash
= 2 then Inc(FPickup
, 5);
3545 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
3547 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3550 if gFlash
= 2 then Inc(FPickup
, 5);
3554 if not(R_ITEM_BACKPACK
in FRulez
) or
3555 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
3556 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
3557 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
3558 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
3559 (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) then
3561 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
3562 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
3563 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
3564 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
3565 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
3567 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3568 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3569 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3570 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3571 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3572 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3573 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3574 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3575 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
3576 IncMax(FAmmo
[A_FUEL
], 50, FMaxAmmo
[A_FUEL
]);
3578 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
3581 if gFlash
= 2 then Inc(FPickup
, 5);
3585 if not(R_KEY_RED
in FRulez
) then
3587 Include(FRulez
, R_KEY_RED
);
3589 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3590 if gFlash
= 2 then Inc(FPickup
, 5);
3591 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3595 if not(R_KEY_GREEN
in FRulez
) then
3597 Include(FRulez
, R_KEY_GREEN
);
3599 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3600 if gFlash
= 2 then Inc(FPickup
, 5);
3601 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3605 if not(R_KEY_BLUE
in FRulez
) then
3607 Include(FRulez
, R_KEY_BLUE
);
3609 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3610 if gFlash
= 2 then Inc(FPickup
, 5);
3611 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3615 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
3617 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
3621 if gFlash
= 2 then Inc(FPickup
, 5);
3625 if FAir
< AIR_MAX
then
3630 if gFlash
= 2 then Inc(FPickup
, 5);
3635 if not (R_BERSERK
in FRulez
) then
3637 Include(FRulez
, R_BERSERK
);
3638 if (FBFGFireCounter
= -1) then
3640 FCurrWeap
:= WEAPON_KASTET
;
3642 FModel
.SetWeapon(WEAPON_KASTET
);
3647 if gFlash
= 2 then Inc(FPickup
, 5);
3649 FBerserk
:= gTime
+30000;
3654 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3656 if FHealth
< PLAYER_HP_SOFT
then FHealth
:= PLAYER_HP_SOFT
;
3657 FBerserk
:= gTime
+30000;
3665 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
3667 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
3671 if gFlash
= 2 then Inc(FPickup
, 5);
3675 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
3677 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
3681 if gFlash
= 2 then Inc(FPickup
, 5);
3685 if FArmor
< PLAYER_AP_LIMIT
then
3687 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
3690 if gFlash
= 2 then Inc(FPickup
, 5);
3694 if FJetFuel
< JET_MAX
then
3696 FJetFuel
:= JET_MAX
;
3699 if gFlash
= 2 then Inc(FPickup
, 5);
3703 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
3705 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
3708 if gFlash
= 2 then Inc(FPickup
, 5);
3712 if (shouldSwitch(switchWeapon
, hadWeapon
)) then
3713 QueueWeaponSwitch(switchWeapon
);
3716 procedure TPlayer
.Touch();
3720 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
3723 // Бросить флаг товарищу:
3724 if gGameSettings
.GameMode
= GM_CTF
then
3729 procedure TPlayer
.Push(vx
, vy
: Integer);
3731 if (not FPhysics
) and FGhost
then
3733 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
3734 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
3735 if g_Game_IsNet
and g_Game_IsServer
then
3736 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
3739 procedure TPlayer
.Reset(Force
: Boolean);
3745 FTime
[T_RESPAWN
] := 0;
3746 FTime
[T_FLAGCAP
] := 0;
3762 FSpectator
:= False;
3765 FSpectatePlayer
:= -1;
3766 FNoRespawn
:= False;
3768 FLives
:= gGameSettings
.MaxLives
;
3773 procedure TPlayer
.SoftReset();
3781 FBFGFireCounter
:= -1;
3789 SetAction(A_STAND
, True);
3792 function TPlayer
.GetRespawnPoint(): Byte;
3797 // На будущее: FSpawn - игрок уже играл и перерождается
3799 // Одиночная игра/кооператив
3800 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
3802 if Self
= gPlayer1
then
3804 // player 1 should try to spawn on the player 1 point
3805 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) > 0 then
3806 Exit(RESPAWNPOINT_PLAYER1
)
3807 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) > 0 then
3808 Exit(RESPAWNPOINT_PLAYER2
);
3810 else if Self
= gPlayer2
then
3812 // player 2 should try to spawn on the player 2 point
3813 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) > 0 then
3814 Exit(RESPAWNPOINT_PLAYER2
)
3815 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) > 0 then
3816 Exit(RESPAWNPOINT_PLAYER1
);
3820 // other players randomly pick either the first or the second point
3821 c
:= IfThen((Random(2) = 0), RESPAWNPOINT_PLAYER1
, RESPAWNPOINT_PLAYER2
);
3822 if g_Map_GetPointCount(c
) > 0 then
3824 // try the other one
3825 c
:= IfThen((c
= RESPAWNPOINT_PLAYER1
), RESPAWNPOINT_PLAYER2
, RESPAWNPOINT_PLAYER1
);
3826 if g_Map_GetPointCount(c
) > 0 then
3832 if gGameSettings
.GameMode
= GM_DM
then
3834 // try DM points first
3835 if g_Map_GetPointCount(RESPAWNPOINT_DM
) > 0 then
3836 Exit(RESPAWNPOINT_DM
);
3840 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
3842 // try team points first
3843 c
:= RESPAWNPOINT_DM
;
3844 if FTeam
= TEAM_RED
then
3845 c
:= RESPAWNPOINT_RED
3846 else if FTeam
= TEAM_BLUE
then
3847 c
:= RESPAWNPOINT_BLUE
;
3848 if g_Map_GetPointCount(c
) > 0 then
3852 // still haven't found a spawnpoint, try random shit
3853 Result
:= g_Map_GetRandomPointType();
3856 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
3858 RespawnPoint
: TRespawnPoint
;
3864 FBFGFireCounter
:= -1;
3871 if not g_Game_IsServer
then
3875 FWantsInGame
:= True;
3876 FJustTeleported
:= True;
3879 FTime
[T_RESPAWN
] := 0;
3883 // if server changes MaxLives we gotta be ready
3884 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
3886 // Еще нельзя возродиться:
3887 if FTime
[T_RESPAWN
] > gTime
then
3890 // Просрал все жизни:
3893 if not FSpectator
then Spectate(True);
3894 FWantsInGame
:= True;
3898 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
3899 begin // "Своя игра"
3900 // Берсерк не сохраняется между уровнями:
3901 FRulez
:= FRulez
-[R_BERSERK
];
3903 else // "Одиночная игра"/"Кооп"
3905 // Берсерк и ключи не сохраняются между уровнями:
3906 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
3909 // Получаем точку спауна игрока:
3910 c
:= GetRespawnPoint();
3915 // Воскрешение без оружия:
3918 FHealth
:= Round(PLAYER_HP_SOFT
* (FHandicap
/ 100));
3924 for a
:= WP_FIRST
to WP_LAST
do
3926 FWeapon
[a
] := False;
3930 FWeapon
[WEAPON_PISTOL
] := True;
3931 FWeapon
[WEAPON_KASTET
] := True;
3932 FCurrWeap
:= WEAPON_PISTOL
;
3935 FModel
.SetWeapon(FCurrWeap
);
3937 for b
:= A_BULLETS
to A_HIGH
do
3940 FAmmo
[A_BULLETS
] := 50;
3942 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
3943 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
3944 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
3945 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
3946 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
3948 if (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) and
3949 LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
) then
3950 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
3955 // Получаем координаты точки возрождения:
3956 if not g_Map_GetPoint(c
, RespawnPoint
) then
3958 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3962 // Установка координат и сброс всех параметров:
3963 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
3964 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
3965 FObj
.oldX
:= FObj
.X
; // don't interpolate after respawn
3966 FObj
.oldY
:= FObj
.Y
;
3972 FDirection
:= RespawnPoint
.Direction
;
3973 if FDirection
= TDirection
.D_LEFT
then
3978 SetAction(A_STAND
, True);
3979 FModel
.Direction
:= FDirection
;
3981 for a
:= Low(FTime
) to High(FTime
) do
3984 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
3987 // Respawn invulnerability
3988 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.SpawnInvul
> 0) then
3990 FMegaRulez
[MR_INVUL
] := gTime
+ gGameSettings
.SpawnInvul
* 1000;
3991 FSpawnInvul
:= FMegaRulez
[MR_INVUL
];
3996 FCanJetpack
:= False;
4002 // Анимация возрождения:
4003 if (not gLoadGameMode
) and (not Silent
) then
4005 R_GFX_TELEPORT_FAST
,
4006 FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4007 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32
4010 FSpectator
:= False;
4013 FSpectatePlayer
:= -1;
4016 if (gPlayer1
= nil) and (gSpectLatchPID1
= FUID
) then
4018 if (gPlayer2
= nil) and (gSpectLatchPID2
= FUID
) then
4021 if g_Game_IsNet
then
4023 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4024 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4026 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4027 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4032 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4035 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4036 else if (not NoMove
) then
4038 GameX
:= gMapInfo
.Width
div 2;
4039 GameY
:= gMapInfo
.Height
div 2;
4048 FWantsInGame
:= False;
4054 if Self
= gPlayer1
then
4056 gSpectLatchPID1
:= FUID
;
4059 else if Self
= gPlayer2
then
4061 gSpectLatchPID2
:= FUID
;
4066 if g_Game_IsNet
then
4067 MH_SEND_PlayerStats(FUID
);
4070 procedure TPlayer
.SwitchNoClip
;
4074 FGhost
:= not FGhost
;
4075 FPhysics
:= not FGhost
;
4087 procedure TPlayer
.Run(Direction
: TDirection
);
4091 if MAX_RUNVEL
> 8 then
4095 if Direction
= TDirection
.D_LEFT
then
4097 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4098 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4101 if FObj
.Vel
.X
< MAX_RUNVEL
then
4102 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4104 // Возможно, пинаем куски:
4105 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4107 b
:= Abs(FObj
.Vel
.X
);
4108 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4109 for a
:= 0 to High(gGibs
) do
4111 if gGibs
[a
].alive
and
4112 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4113 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4116 if FObj
.Vel
.X
< 0 then
4118 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // налево
4122 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // направо
4124 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4132 procedure TPlayer
.SeeDown();
4134 SetAction(A_SEEDOWN
);
4136 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4138 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4141 procedure TPlayer
.SeeUp();
4145 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4147 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4150 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4158 A_ATTACK
: Prior
:= 2;
4159 A_SEEUP
: Prior
:= 1;
4160 A_SEEDOWN
: Prior
:= 1;
4161 A_ATTACKUP
: Prior
:= 2;
4162 A_ATTACKDOWN
: Prior
:= 2;
4167 if (Prior
> FActionPrior
) or Force
then
4168 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4170 FActionPrior
:= Prior
;
4171 FActionAnim
:= Action
;
4172 FActionForce
:= Force
;
4173 FActionChanged
:= True;
4176 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4179 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4181 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4182 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4183 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4184 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4187 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4191 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4193 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4194 if g_Game_IsServer
and g_Game_IsNet
then
4195 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4199 FJustTeleported
:= True;
4203 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4205 R_GFX_TELEPORT_FAST
,
4206 FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4207 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32
4209 if g_Game_IsServer
and g_Game_IsNet
then
4210 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4211 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4215 FObj
.X
:= X
-PLAYER_RECT
.X
;
4216 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4217 FObj
.oldX
:= FObj
.X
; // don't interpolate after respawn
4218 FObj
.oldY
:= FObj
.Y
;
4219 if FAlive
and FGhost
then
4225 if not g_Game_IsNet
then
4229 SetDirection(TDirection
.D_LEFT
);
4235 SetDirection(TDirection
.D_RIGHT
);
4241 if FDirection
= TDirection
.D_RIGHT
then
4243 SetDirection(TDirection
.D_LEFT
);
4248 SetDirection(TDirection
.D_RIGHT
);
4257 R_GFX_TELEPORT_FAST
,
4258 FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4259 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32
4261 if g_Game_IsServer
and g_Game_IsNet
then
4262 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4263 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4270 function nonz(a
: Single): Single;
4278 function TPlayer
.refreshCorpse(): Boolean;
4284 if FAlive
or FSpectator
then
4286 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
4288 for i
:= 0 to High(gCorpses
) do
4289 if gCorpses
[i
] <> nil then
4290 if gCorpses
[i
].FPlayerUID
= FUID
then
4298 function TPlayer
.getCameraObj(): TObj
;
4300 if (not FAlive
) and (not FSpectator
) and
4301 (FCorpse
>= 0) and (FCorpse
< Length(gCorpses
)) and
4302 (gCorpses
[FCorpse
] <> nil) and (gCorpses
[FCorpse
].FPlayerUID
= FUID
) then
4304 gCorpses
[FCorpse
].FObj
.slopeUpLeft
:= FObj
.slopeUpLeft
;
4305 Result
:= gCorpses
[FCorpse
].FObj
;
4313 procedure TPlayer
.PreUpdate();
4315 FSlopeOld
:= FObj
.slopeUpLeft
;
4316 FIncCamOld
:= FIncCam
;
4317 FObj
.oldX
:= FObj
.X
;
4318 FObj
.oldY
:= FObj
.Y
;
4321 procedure TPlayer
.Update();
4324 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4325 blockmon
, headwater
, dospawn
: Boolean;
4330 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4331 AnyServer
:= g_Game_IsServer
;
4333 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4334 DoLerp(NetInterpLevel
+ 1)
4340 if (FClientID
>= 0) and (NetClients
[FClientID
].Peer
<> nil) then
4342 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4343 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4344 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4355 if FPunchAnim
.played
then
4358 if FAlive
and (gFly
or FJetpack
) then
4361 if FDirection
= TDirection
.D_LEFT
then
4366 if FAlive
and (not FGhost
) then
4368 if FKeys
[KEY_UP
].Pressed
then
4370 if FKeys
[KEY_DOWN
].Pressed
then
4374 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4377 i
:= g_basic
.Sign(FIncCam
);
4378 FIncCam
:= Abs(FIncCam
);
4379 DecMin(FIncCam
, 5, 0);
4380 FIncCam
:= FIncCam
*i
;
4383 if gTime
mod (GAME_TICK
*2) <> 0 then
4385 if (FObj
.Vel
.X
= 0) and FAlive
then
4387 if FKeys
[KEY_LEFT
].Pressed
then
4388 Run(TDirection
.D_LEFT
);
4389 if FKeys
[KEY_RIGHT
].Pressed
then
4390 Run(TDirection
.D_RIGHT
);
4395 g_Obj_Move(@FObj
, True, True, True);
4396 positionChanged(); // this updates spatial accelerators
4402 FActionChanged
:= False;
4406 // Let alive player do some actions
4407 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
4408 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
4409 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire()
4415 if NetServer
then MH_SEND_PlayerStats(FUID
);
4418 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
4419 if FKeys
[KEY_JUMP
].Pressed
then Jump()
4422 if AnyServer
and FJetpack
then
4426 if NetServer
then MH_SEND_PlayerStats(FUID
);
4428 FCanJetpack
:= True;
4435 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
4437 if FKeys
[k
].Pressed
then
4445 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4448 if (FTime
[T_RESPAWN
] <= gTime
) and
4449 gGameOn
and (not FAlive
) then
4451 if (g_Player_GetCount() > 1) then
4455 gExit
:= EXIT_RESTART
;
4460 // Dead spectator actions
4463 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
4464 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
4468 if (FSpectatePlayer
>= High(gPlayers
)) then
4469 FSpectatePlayer
:= -1
4473 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
4474 if gPlayers
[I
] <> nil then
4475 if gPlayers
[I
].alive
then
4476 if gPlayers
[I
].UID
<> FUID
then
4478 FSpectatePlayer
:= I
;
4483 if not SetSpect
then FSpectatePlayer
:= -1;
4494 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
4496 FYTo
:= FObj
.Y
- 32;
4497 FSpectatePlayer
:= -1;
4499 if FKeys
[KEY_DOWN
].Pressed
then
4501 FYTo
:= FObj
.Y
+ 32;
4502 FSpectatePlayer
:= -1;
4504 if FKeys
[KEY_LEFT
].Pressed
then
4506 FXTo
:= FObj
.X
- 32;
4507 FSpectatePlayer
:= -1;
4509 if FKeys
[KEY_RIGHT
].Pressed
then
4511 FXTo
:= FObj
.X
+ 32;
4512 FSpectatePlayer
:= -1;
4515 if (FXTo
< -64) then
4517 else if (FXTo
> gMapInfo
.Width
+ 32) then
4518 FXTo
:= gMapInfo
.Width
+ 32;
4519 if (FYTo
< -72) then
4521 else if (FYTo
> gMapInfo
.Height
+ 32) then
4522 FYTo
:= gMapInfo
.Height
+ 32;
4527 g_Obj_Move(@FObj
, True, True, True);
4528 positionChanged(); // this updates spatial accelerators
4535 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
4536 if gPlayers
[FSpectatePlayer
] <> nil then
4537 if gPlayers
[FSpectatePlayer
].alive
then
4539 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
4540 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
4544 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
4545 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
4546 PANEL_BLOCKMON
, True);
4547 headwater
:= HeadInLiquid(0, 0);
4549 // Сопротивление воздуха:
4550 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
4551 if FObj
.Vel
.X
<> 0 then
4552 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
4554 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
4555 DecMin(FPain
, 5, 0);
4556 DecMin(FPickup
, 1, 0);
4558 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
4560 // Обнулить действия примочек, чтобы фон пропал
4561 FMegaRulez
[MR_SUIT
] := 0;
4562 FMegaRulez
[MR_INVUL
] := 0;
4563 FMegaRulez
[MR_INVIS
] := 0;
4564 Kill(K_FALLKILL
, 0, HIT_FALL
);
4571 if FCurrWeap
= WEAPON_SAW
then
4572 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
4573 FSawSoundSelect
.IsPlaying()) then
4574 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
4577 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
4578 (not FJetSoundOff
.IsPlaying()) then
4580 FJetSoundFly
.SetPosition(0);
4581 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
4584 for b
:= WP_FIRST
to WP_LAST
do
4585 if FReloading
[b
] > 0 then
4591 if FShellTimer
> -1 then
4592 if FShellTimer
= 0 then
4594 if FShellType
= SHELL_SHELL
then
4595 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4596 GameVelX
, GameVelY
-2, SHELL_SHELL
)
4597 else if FShellType
= SHELL_DBLSHELL
then
4599 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4600 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
4601 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4602 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
4605 end else Dec(FShellTimer
);
4607 if (FBFGFireCounter
> -1) then
4608 if FBFGFireCounter
= 0 then
4612 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
4613 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
4614 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
4615 yd
:= wy
+firediry();
4616 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
4617 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
4618 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
4619 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
4620 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
4623 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
4624 FBFGFireCounter
:= -1;
4627 FBFGFireCounter
:= 0
4629 Dec(FBFGFireCounter
);
4631 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
4633 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
4635 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
4638 if (headwater
or blockmon
) then
4644 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
4647 else if (FAir
mod 31 = 0) and not blockmon
then
4649 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
4651 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
4652 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
4654 end else if FAir
< AIR_DEF
then
4657 if FFireTime
> 0 then
4659 if BodyInLiquid(0, 0) then
4664 else if FMegaRulez
[MR_SUIT
] >= gTime
then
4666 if FMegaRulez
[MR_SUIT
] = gTime
then
4673 if FFirePainTime
<= 0 then
4675 if g_Game_IsServer
then
4676 Damage(2, FFireAttacker
, 0, 0, HIT_FLAME
);
4677 FFirePainTime
:= 12 - FFireTime
div 12;
4679 FFirePainTime
:= FFirePainTime
- 1;
4680 FFireTime
:= FFireTime
- 1;
4681 if ((FFireTime
mod 33) = 0) and (FMegaRulez
[MR_INVUL
] < gTime
) then
4682 FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
);
4683 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
4684 MH_SEND_PlayerStats(FUID
);
4688 if FDamageBuffer
> 0 then
4690 if FDamageBuffer
>= 9 then
4694 if FDamageBuffer
< 30 then i
:= 9
4695 else if FDamageBuffer
< 100 then i
:= 18
4699 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
4700 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
4701 FHealth
:= FHealth
-ii
;
4704 FHealth
:= FHealth
+FArmor
;
4709 if FHealth
<= 0 then
4710 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
4711 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
4712 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
4714 if FAlive
and ((FLastHit
<> HIT_FLAME
) or (FFireTime
<= 0)) then
4716 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
4717 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
4718 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
4719 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
4726 end; // if FAlive then ...
4728 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
4730 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
4731 FModel
.AnimState
.MinLength
:= i
;
4732 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
4734 if (FModel
.AnimState
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
4735 then SetAction(A_STAND
, True);
4737 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.GetFire()) then FModel
.Update
;
4739 for b
:= Low(FKeys
) to High(FKeys
) do
4740 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
4744 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
4746 x
:= FObj
.X
+PLAYER_RECT
.X
;
4747 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
4748 w
:= PLAYER_RECT
.Width
;
4749 h
:= PLAYER_RECT
.Height
;
4753 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
4755 if (dx
<> 0) or (dy
<> 0) then
4764 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
4766 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
4767 FObj
.Y
+PLAYER_RECT
.Y
,
4774 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
4776 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
4777 FObj
.Y
+PLAYER_RECT
.Y
,
4781 Panel
.Width
, Panel
.Height
);
4784 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
4786 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
4787 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
4788 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
4789 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
4792 function g_Player_ValidName(Name
: string): Boolean;
4798 if gPlayers
= nil then Exit
;
4800 for a
:= 0 to High(gPlayers
) do
4801 if gPlayers
[a
] <> nil then
4802 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
4809 procedure TPlayer
.SetDirection(Direction
: TDirection
);
4813 d
:= FModel
.Direction
;
4815 FModel
.Direction
:= Direction
;
4816 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
4818 FDirection
:= Direction
;
4821 function TPlayer
.GetKeys(): Byte;
4825 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
4826 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
4827 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
4829 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
4830 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
4833 procedure TPlayer
.Use();
4837 if FTime
[T_USE
] > gTime
then Exit
;
4839 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
4840 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
4842 for a
:= 0 to High(gPlayers
) do
4843 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
4844 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
4845 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
4846 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
4848 gPlayers
[a
].Touch();
4849 if g_Game_IsNet
and g_Game_IsServer
then
4850 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
4853 FTime
[T_USE
] := gTime
+120;
4856 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
4859 visible
: Boolean = True;
4860 WX
, WY
, XD
, YD
: Integer;
4872 if R_BERSERK
in FRulez
then
4874 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
4875 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
4876 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
4879 locobj
.rect
.Width
:= 39;
4880 locobj
.rect
.Height
:= 52;
4881 locobj
.Vel
.X
:= (xd
-wx
) div 2;
4882 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
4883 locobj
.Accel
.X
:= xd
-wx
;
4884 locobj
.Accel
.y
:= yd
-wy
;
4886 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
4887 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
4889 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
4893 FPain
:= min(FPain
+ 25, 50);
4895 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
4900 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
4901 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
4903 FSawSoundSelect
.Stop();
4905 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
4907 else if not FSawSoundHit
.IsPlaying() then
4909 FSawSoundSelect
.Stop();
4910 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
4916 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
4917 FFireAngle
:= FAngle
;
4918 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4919 GameVelX
, GameVelY
-2, SHELL_BULLET
);
4924 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
4925 FFireAngle
:= FAngle
;
4927 FShellType
:= SHELL_SHELL
;
4932 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
4933 FFireAngle
:= FAngle
;
4935 FShellType
:= SHELL_DBLSHELL
;
4940 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
4941 FFireAngle
:= FAngle
;
4942 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4943 GameVelX
, GameVelY
-2, SHELL_BULLET
);
4946 WEAPON_ROCKETLAUNCHER
:
4948 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
4949 FFireAngle
:= FAngle
;
4954 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
4955 FFireAngle
:= FAngle
;
4960 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
4961 FFireAngle
:= FAngle
;
4964 WEAPON_SUPERPULEMET
:
4966 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
4967 FFireAngle
:= FAngle
;
4968 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4969 GameVelX
, GameVelY
-2, SHELL_SHELL
);
4972 WEAPON_FLAMETHROWER
:
4974 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
4976 FFireAngle
:= FAngle
;
4980 if not visible
then Exit
;
4982 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
4983 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
4984 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
4987 procedure TPlayer
.DoLerp(Level
: Integer = 2);
4989 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
4990 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
4993 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
4999 if FJustTeleported
or (NetInterpLevel
< 1) then
5003 if FJustTeleported
then
5005 FObj
.oldX
:= FObj
.X
;
5006 FObj
.oldY
:= FObj
.Y
;
5011 AX
:= Abs(FXTo
- FObj
.X
);
5012 AY
:= Abs(FYTo
- FObj
.Y
);
5013 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5015 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5020 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5022 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5023 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5024 PANEL_LIFTUP
, False) then Result
:= -1
5026 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5027 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5028 PANEL_LIFTDOWN
, False) then Result
:= 1
5032 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5039 if Flag
= FLAG_NONE
then
5042 if not g_Game_IsServer
then Exit
;
5044 // Принес чужой флаг на свою базу:
5045 if (Flag
= FTeam
) and
5046 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5047 (FFlag
<> FLAG_NONE
) then
5049 if FFlag
= FLAG_RED
then
5050 s
:= _lc
[I_PLAYER_FLAG_RED
]
5052 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5054 evtype
:= FLAG_STATE_SCORED
;
5056 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5057 Insert('.', ts
, Length(ts
) + 1 - 3);
5058 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5060 g_Map_ResetFlag(FFlag
);
5061 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5063 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5064 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5065 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5070 if not sound_cap_flag
[a
].IsPlaying() then
5071 sound_cap_flag
[a
].Play();
5073 gTeamStat
[FTeam
].Score
+= 1;
5076 if g_Game_IsNet
then
5078 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5082 gFlags
[FFlag
].CaptureTime
:= 0;
5087 // Подобрал свой флаг - вернул его на базу:
5088 if (Flag
= FTeam
) and
5089 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5091 if Flag
= FLAG_RED
then
5092 s
:= _lc
[I_PLAYER_FLAG_RED
]
5094 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5096 evtype
:= FLAG_STATE_RETURNED
;
5097 gFlags
[Flag
].CaptureTime
:= 0;
5099 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5101 g_Map_ResetFlag(Flag
);
5102 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [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 sound_ret_flag
[a
].IsPlaying() then
5112 sound_ret_flag
[a
].Play();
5115 if g_Game_IsNet
then
5117 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5123 // Подобрал чужой флаг:
5124 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5128 if Flag
= FLAG_RED
then
5129 s
:= _lc
[I_PLAYER_FLAG_RED
]
5131 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5133 evtype
:= FLAG_STATE_CAPTURED
;
5135 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5137 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5139 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5141 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5142 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5143 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5148 if not sound_get_flag
[a
].IsPlaying() then
5149 sound_get_flag
[a
].Play();
5152 if g_Game_IsNet
then
5154 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5160 procedure TPlayer
.SetFlag(Flag
: Byte);
5163 if FModel
<> nil then
5164 FModel
.SetFlag(FFlag
);
5167 function TPlayer
.TryDropFlag(): Boolean;
5169 if LongBool(gGameSettings
.Options
and GAME_OPTION_ALLOWDROPFLAG
) then
5170 Result
:= DropFlag(False, LongBool(gGameSettings
.Options
and GAME_OPTION_THROWFLAG
))
5175 function TPlayer
.DropFlag(Silent
: Boolean = True; DoThrow
: Boolean = False): Boolean;
5182 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5184 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5185 with gFlags
[FFlag
] do
5189 Direction
:= FDirection
;
5190 State
:= FLAG_STATE_DROPPED
;
5194 xv
:= FObj
.Vel
.X
+ IfThen(Direction
= TDirection
.D_RIGHT
, 10, -10);
5195 yv
:= FObj
.Vel
.Y
- 2;
5199 xv
:= (FObj
.Vel
.X
div 2);
5200 yv
:= (FObj
.Vel
.Y
div 2) - 2;
5202 g_Obj_Push(@Obj
, xv
, yv
);
5204 positionChanged(); // this updates spatial accelerators
5206 if FFlag
= FLAG_RED
then
5207 s
:= _lc
[I_PLAYER_FLAG_RED
]
5209 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5211 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5212 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5214 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5215 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5216 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5221 if (not Silent
) and (not sound_lost_flag
[a
].IsPlaying()) then
5222 sound_lost_flag
[a
].Play();
5224 if g_Game_IsNet
then
5225 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5231 procedure TPlayer
.GetSecret();
5233 if (self
= gPlayer1
) or (self
= gPlayer2
) then
5235 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [FName
]), True);
5236 g_Sound_PlayEx('SOUND_GAME_SECRET');
5241 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5243 Assert(Key
<= High(FKeys
));
5245 FKeys
[Key
].Pressed
:= True;
5246 FKeys
[Key
].Time
:= Time
;
5249 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5251 Result
:= FKeys
[K
].Pressed
;
5254 procedure TPlayer
.ReleaseKeys();
5258 for a
:= Low(FKeys
) to High(FKeys
) do
5260 FKeys
[a
].Pressed
:= False;
5265 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5269 function TPlayer
.firediry(): Integer;
5271 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5272 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5276 procedure TPlayer
.RememberState();
5279 SavedState
: TPlayerSavedState
;
5281 SavedState
.Health
:= FHealth
;
5282 SavedState
.Armor
:= FArmor
;
5283 SavedState
.Air
:= FAir
;
5284 SavedState
.JetFuel
:= FJetFuel
;
5285 SavedState
.CurrWeap
:= FCurrWeap
;
5286 SavedState
.NextWeap
:= FNextWeap
;
5287 SavedState
.NextWeapDelay
:= FNextWeapDelay
;
5288 for i
:= Low(FWeapon
) to High(FWeapon
) do
5289 SavedState
.Weapon
[i
] := FWeapon
[i
];
5290 for i
:= Low(FAmmo
) to High(FAmmo
) do
5291 SavedState
.Ammo
[i
] := FAmmo
[i
];
5292 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
5293 SavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5294 SavedState
.Rulez
:= FRulez
- [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5296 FSavedStateNum
:= -1;
5297 for i
:= Low(SavedStates
) to High(SavedStates
) do
5298 if not SavedStates
[i
].Used
then
5300 FSavedStateNum
:= i
;
5303 if FSavedStateNum
< 0 then
5305 SetLength(SavedStates
, Length(SavedStates
) + 1);
5306 FSavedStateNum
:= High(SavedStates
);
5309 SavedState
.Used
:= True;
5310 SavedStates
[FSavedStateNum
] := SavedState
;
5313 procedure TPlayer
.RecallState();
5316 SavedState
: TPlayerSavedState
;
5318 if(FSavedStateNum
< 0) or (FSavedStateNum
> High(SavedStates
)) then
5321 SavedState
:= SavedStates
[FSavedStateNum
];
5322 SavedStates
[FSavedStateNum
].Used
:= False;
5323 FSavedStateNum
:= -1;
5325 FHealth
:= SavedState
.Health
;
5326 FArmor
:= SavedState
.Armor
;
5327 FAir
:= SavedState
.Air
;
5328 FJetFuel
:= SavedState
.JetFuel
;
5329 FCurrWeap
:= SavedState
.CurrWeap
;
5330 FNextWeap
:= SavedState
.NextWeap
;
5331 FNextWeapDelay
:= SavedState
.NextWeapDelay
;
5332 for i
:= Low(FWeapon
) to High(FWeapon
) do
5333 FWeapon
[i
] := SavedState
.Weapon
[i
];
5334 for i
:= Low(FAmmo
) to High(FAmmo
) do
5335 FAmmo
[i
] := SavedState
.Ammo
[i
];
5336 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
5337 FMaxAmmo
[i
] := SavedState
.MaxAmmo
[i
];
5338 FRulez
:= SavedState
.Rulez
;
5340 if gGameSettings
.GameType
= GT_SERVER
then
5341 MH_SEND_PlayerStats(FUID
);
5344 procedure TPlayer
.SaveState (st
: TStream
);
5350 utils
.writeSign(st
, 'PLYR');
5351 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
5353 utils
.writeBool(st
, FIamBot
);
5355 utils
.writeInt(st
, Word(FUID
));
5357 utils
.writeStr(st
, FName
);
5359 utils
.writeInt(st
, Byte(FTeam
));
5361 utils
.writeBool(st
, FAlive
);
5362 // Израсходовал ли все жизни
5363 utils
.writeBool(st
, FNoRespawn
);
5365 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
5366 utils
.writeInt(st
, Byte(b
));
5368 utils
.writeInt(st
, LongInt(FHealth
));
5369 // Коэффициент инвалидности
5370 utils
.writeInt(st
, LongInt(FHandicap
));
5372 utils
.writeInt(st
, Byte(FLives
));
5374 utils
.writeInt(st
, LongInt(FArmor
));
5376 utils
.writeInt(st
, LongInt(FAir
));
5378 utils
.writeInt(st
, LongInt(FJetFuel
));
5380 utils
.writeInt(st
, LongInt(FPain
));
5382 utils
.writeInt(st
, LongInt(FKills
));
5384 utils
.writeInt(st
, LongInt(FMonsterKills
));
5386 utils
.writeInt(st
, LongInt(FFrags
));
5388 utils
.writeInt(st
, Byte(FFragCombo
));
5389 // Время последнего фрага
5390 utils
.writeInt(st
, LongWord(FLastFrag
));
5392 utils
.writeInt(st
, LongInt(FDeath
));
5394 utils
.writeInt(st
, Byte(FFlag
));
5396 utils
.writeInt(st
, LongInt(FSecrets
));
5398 utils
.writeInt(st
, Byte(FCurrWeap
));
5400 utils
.writeInt(st
, Word(FNextWeap
));
5402 utils
.writeInt(st
, Byte(FNextWeapDelay
));
5403 // Время зарядки BFG
5404 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
5406 utils
.writeInt(st
, LongInt(FDamageBuffer
));
5407 // Последний ударивший
5408 utils
.writeInt(st
, Word(FLastSpawnerUID
));
5409 // Тип последнего полученного урона
5410 utils
.writeInt(st
, Byte(FLastHit
));
5412 Obj_SaveState(st
, @FObj
);
5413 // Текущее количество патронов
5414 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
5415 // Максимальное количество патронов
5416 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
5418 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
5419 // Время перезарядки оружия
5420 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
5422 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
5423 // Наличие красного ключа
5424 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
5425 // Наличие зеленого ключа
5426 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
5427 // Наличие синего ключа
5428 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
5430 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
5431 // Время действия специальных предметов
5432 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
5433 // Время до повторного респауна, смены оружия, исользования, захвата флага
5434 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
5436 utils
.writeStr(st
, FModel
.GetName());
5438 utils
.writeInt(st
, Byte(FColor
.R
));
5439 utils
.writeInt(st
, Byte(FColor
.G
));
5440 utils
.writeInt(st
, Byte(FColor
.B
));
5444 procedure TPlayer
.LoadState (st
: TStream
);
5453 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
5454 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
5456 FIamBot
:= utils
.readBool(st
);
5458 FUID
:= utils
.readWord(st
);
5460 str
:= utils
.readStr(st
);
5461 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
5463 FTeam
:= utils
.readByte(st
);
5465 FAlive
:= utils
.readBool(st
);
5466 // Израсходовал ли все жизни
5467 FNoRespawn
:= utils
.readBool(st
);
5469 b
:= utils
.readByte(st
);
5470 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
5472 FHealth
:= utils
.readLongInt(st
);
5473 // Коэффициент инвалидности
5474 FHandicap
:= utils
.readLongInt(st
);
5476 FLives
:= utils
.readByte(st
);
5478 FArmor
:= utils
.readLongInt(st
);
5480 FAir
:= utils
.readLongInt(st
);
5482 FJetFuel
:= utils
.readLongInt(st
);
5484 FPain
:= utils
.readLongInt(st
);
5486 FKills
:= utils
.readLongInt(st
);
5488 FMonsterKills
:= utils
.readLongInt(st
);
5490 FFrags
:= utils
.readLongInt(st
);
5492 FFragCombo
:= utils
.readByte(st
);
5493 // Время последнего фрага
5494 FLastFrag
:= utils
.readLongWord(st
);
5496 FDeath
:= utils
.readLongInt(st
);
5498 FFlag
:= utils
.readByte(st
);
5500 FSecrets
:= utils
.readLongInt(st
);
5502 FCurrWeap
:= utils
.readByte(st
);
5504 FNextWeap
:= utils
.readWord(st
);
5506 FNextWeapDelay
:= utils
.readByte(st
);
5507 // Время зарядки BFG
5508 FBFGFireCounter
:= utils
.readSmallInt(st
);
5510 FDamageBuffer
:= utils
.readLongInt(st
);
5511 // Последний ударивший
5512 FLastSpawnerUID
:= utils
.readWord(st
);
5513 // Тип последнего полученного урона
5514 FLastHit
:= utils
.readByte(st
);
5516 Obj_LoadState(@FObj
, st
);
5517 // Текущее количество патронов
5518 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
5519 // Максимальное количество патронов
5520 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
5522 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
5523 // Время перезарядки оружия
5524 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
5526 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
5527 // Наличие красного ключа
5528 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
5529 // Наличие зеленого ключа
5530 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
5531 // Наличие синего ключа
5532 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
5534 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
5535 // Время действия специальных предметов
5536 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
5537 // Время до повторного респауна, смены оружия, исользования, захвата флага
5538 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
5540 str
:= utils
.readStr(st
);
5542 FColor
.R
:= utils
.readByte(st
);
5543 FColor
.G
:= utils
.readByte(st
);
5544 FColor
.B
:= utils
.readByte(st
);
5545 if (self
= gPlayer1
) then
5547 str
:= gPlayer1Settings
.Model
;
5548 FColor
:= gPlayer1Settings
.Color
;
5550 else if (self
= gPlayer2
) then
5552 str
:= gPlayer2Settings
.Model
;
5553 FColor
:= gPlayer2Settings
.Color
;
5555 // Обновляем модель игрока
5557 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
5558 FModel
.Color
:= TEAMCOLOR
[FTeam
]
5560 FModel
.Color
:= FColor
;
5564 procedure TPlayer
.AllRulez(Health
: Boolean);
5570 FHealth
:= PLAYER_HP_LIMIT
;
5571 FArmor
:= PLAYER_AP_LIMIT
;
5575 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
5576 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
5577 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5580 procedure TPlayer
.RestoreHealthArmor();
5582 FHealth
:= PLAYER_HP_LIMIT
;
5583 FArmor
:= PLAYER_AP_LIMIT
;
5586 procedure TPlayer
.FragCombo();
5590 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
5592 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
5594 if FFragCombo
< 5 then
5596 Param
:= FUID
or (FFragCombo
shl 16);
5597 if (FComboEvnt
>= Low(gDelayedEvents
)) and
5598 (FComboEvnt
<= High(gDelayedEvents
)) and
5599 gDelayedEvents
[FComboEvnt
].Pending
and
5600 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
5601 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
5603 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
5604 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
5607 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
5615 procedure TPlayer
.GiveItem(ItemType
: Byte);
5619 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
5621 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
5625 if FAir
< AIR_MAX
then
5632 if not (R_BERSERK
in FRulez
) then
5634 Include(FRulez
, R_BERSERK
);
5635 if FBFGFireCounter
< 1 then
5637 FCurrWeap
:= WEAPON_KASTET
;
5639 FModel
.SetWeapon(WEAPON_KASTET
);
5643 FBerserk
:= gTime
+30000;
5645 if FHealth
< PLAYER_HP_SOFT
then
5647 FHealth
:= PLAYER_HP_SOFT
;
5648 FBerserk
:= gTime
+30000;
5653 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
5655 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
5660 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
5662 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
5666 if FJetFuel
< JET_MAX
then
5668 FJetFuel
:= JET_MAX
;
5671 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
5672 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
5674 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
5675 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5677 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
5679 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
5681 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
5682 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5685 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
5686 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
5687 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
5688 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
5689 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
5690 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
5691 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
5692 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
5693 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
5695 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5696 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
5697 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5698 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
5699 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5700 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
5701 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5702 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
5703 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
5706 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
5707 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
5708 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
5709 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
5710 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
5712 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
5713 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
5714 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
5715 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
5716 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
5718 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5719 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5720 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5721 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5723 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
5726 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
5727 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
5728 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
5730 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
5731 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
5736 if g_Game_IsNet
and g_Game_IsServer
then
5737 MH_SEND_PlayerStats(FUID
);
5740 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
5743 if (Random(5) = 1) and (Times
= 1) then
5746 if BodyInLiquid(0, 0) then
5748 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
5749 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
5751 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5752 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5756 for i
:= 1 to Times
do
5760 Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(R_GFX_SMOKE_WIDTH
div 2),
5761 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2)
5766 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
5769 if (Random(10) = 1) and (Times
= 1) then
5772 for i
:= 1 to Times
do
5776 Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(R_GFX_FLAME_WIDTH
div 2),
5777 Obj
.Y
+8+Random(8+Times
*2)
5782 procedure TPlayer
.PauseSounds(Enable
: Boolean);
5784 FSawSound
.Pause(Enable
);
5785 FSawSoundIdle
.Pause(Enable
);
5786 FSawSoundHit
.Pause(Enable
);
5787 FSawSoundSelect
.Pause(Enable
);
5788 FFlameSoundOn
.Pause(Enable
);
5789 FFlameSoundOff
.Pause(Enable
);
5790 FFlameSoundWork
.Pause(Enable
);
5791 FJetSoundFly
.Pause(Enable
);
5792 FJetSoundOn
.Pause(Enable
);
5793 FJetSoundOff
.Pause(Enable
);
5798 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
5803 FObj
.Rect
:= PLAYER_CORPSERECT
;
5805 FModel
:= g_PlayerModel_Get(ModelName
);
5809 FState
:= CORPSE_STATE_MESS
;
5810 FModel
.ChangeAnimation(A_DIE2
);
5814 FState
:= CORPSE_STATE_NORMAL
;
5815 FModel
.ChangeAnimation(A_DIE1
);
5819 destructor TCorpse
.Destroy();
5825 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
5827 procedure TCorpse
.positionChanged (); inline; begin end;
5829 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
5831 if (dx
<> 0) or (dy
<> 0) then
5840 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5842 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
5843 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
5844 w
:= PLAYER_CORPSERECT
.Width
;
5845 h
:= PLAYER_CORPSERECT
.Height
;
5849 procedure TCorpse
.Damage(Value
: Word; SpawnerUID
: Word; vx
, vy
: Integer);
5850 var Blood
: TModelBlood
;
5852 if FState
= CORPSE_STATE_REMOVEME
then
5855 FDamage
:= FDamage
+ Value
;
5857 if FDamage
> 150 then
5859 if FModel
<> nil then
5861 FState
:= CORPSE_STATE_REMOVEME
;
5863 g_Player_CreateGibs(
5864 FObj
.X
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
div 2),
5865 FObj
.Y
+ FObj
.Rect
.Y
+ (FObj
.Rect
.Height
div 2),
5870 // Звук мяса от трупа:
5871 FModel
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
5874 if (gBodyKillEvent
<> -1) and gDelayedEvents
[gBodyKillEvent
].Pending
then
5875 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
5876 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, SpawnerUID
);
5884 Blood
:= FModel
.GetBlood();
5885 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
5886 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
5887 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
5888 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
5889 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
5890 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
5894 procedure TCorpse
.Update();
5898 if FState
= CORPSE_STATE_REMOVEME
then
5901 FObj
.oldX
:= FObj
.X
;
5902 FObj
.oldY
:= FObj
.Y
;
5904 if gTime
mod (GAME_TICK
*2) <> 0 then
5906 g_Obj_Move(@FObj
, True, True, True);
5907 positionChanged(); // this updates spatial accelerators
5911 // Сопротивление воздуха для трупа:
5912 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5914 st
:= g_Obj_Move(@FObj
, True, True, True);
5915 positionChanged(); // this updates spatial accelerators
5917 if WordBool(st
and MOVE_FALLOUT
) then
5919 FState
:= CORPSE_STATE_REMOVEME
;
5923 if FModel
<> nil then
5928 procedure TCorpse
.SaveState (st
: TStream
);
5934 utils
.writeSign(st
, 'CORP');
5935 utils
.writeInt(st
, Byte(0));
5937 utils
.writeInt(st
, Byte(FState
));
5939 utils
.writeInt(st
, Byte(FDamage
));
5941 utils
.writeInt(st
, Byte(FModel
.Color
.R
));
5942 utils
.writeInt(st
, Byte(FModel
.Color
.G
));
5943 utils
.writeInt(st
, Byte(FModel
.Color
.B
));
5945 Obj_SaveState(st
, @FObj
);
5946 utils
.writeInt(st
, Word(FPlayerUID
));
5948 anim
:= (FModel
<> nil);
5949 utils
.writeBool(st
, anim
);
5950 if anim
then FModel
.AnimState
.SaveState(st
, 0, False);
5951 // animation for mask (same as animation, compat with older saves)
5952 anim
:= (FModel
<> nil);
5953 utils
.writeBool(st
, anim
);
5954 if anim
then FModel
.AnimState
.SaveState(st
, 0, False);
5958 procedure TCorpse
.LoadState (st
: TStream
);
5959 var anim
, blending
: Boolean; r
, g
, b
, alpha
: Byte; stub
: TAnimationState
;
5964 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
5965 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
5967 FState
:= utils
.readByte(st
);
5969 FDamage
:= utils
.readByte(st
);
5971 r
:= utils
.readByte(st
);
5972 g
:= utils
.readByte(st
);
5973 b
:= utils
.readByte(st
);
5974 FModel
.SetColor(r
, g
, b
);
5976 Obj_LoadState(@FObj
, st
);
5977 FPlayerUID
:= utils
.readWord(st
);
5979 stub
:= TAnimationState
.Create(False, 0, 0);
5980 anim
:= utils
.readBool(st
);
5983 stub
.LoadState(st
, alpha
, blending
);
5984 FModel
.AnimState
.CurrentFrame
:= Min(stub
.CurrentFrame
, FModel
.AnimState
.Length
);
5991 // animation for mask (same as animation, compat with older saves)
5992 anim
:= utils
.readBool(st
);
5993 if anim
then stub
.LoadState(st
, alpha
, blending
);
5999 constructor TBot
.Create();
6006 FSpectator
:= False;
6013 for a
:= WP_FIRST
to WP_LAST
do
6015 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6016 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6017 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6021 destructor TBot
.Destroy();
6024 inherited Destroy();
6027 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6029 inherited Respawn(Silent
, Force
);
6032 FSelectedWeapon
:= FCurrWeap
;
6037 procedure TBot
.UpdateCombat();
6050 TTargetRecord
= array of TTarget
;
6052 function Compare(a
, b
: TTarget
): Integer;
6054 if a
.Line
and not b
.Line
then // A на линии огня
6057 if not a
.Line
and b
.Line
then // B на линии огня
6059 else // И A, и B на линии или не на линии огня
6060 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6062 if a
.Dist
> b
.Dist
then // B ближе
6064 else // A ближе или равноудаленно с B
6067 else // Странно -> A
6072 a
, x1
, y1
, x2
, y2
: Integer;
6073 targets
: TTargetRecord
;
6075 Target
, BestTarget
: TTarget
;
6076 firew
, fireh
: Integer;
6080 vsPlayer
, vsMonster
, ok
: Boolean;
6083 function monsUpdate (mon
: TMonster
): Boolean;
6085 result
:= false; // don't stop
6086 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6088 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6090 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6091 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6093 // Если монстр на экране и не прикрыт стеной
6094 if g_TraceVector(x1
, y1
, x2
, y2
) then
6096 // Добавляем к списку возможных целей
6097 SetLength(targets
, Length(targets
)+1);
6098 with targets
[High(targets
)] do
6105 Rect
:= mon
.Obj
.Rect
;
6106 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6107 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6108 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6117 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6118 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6120 // Если текущее оружие не то, что нужно, то меняем:
6121 if FCurrWeap
<> FSelectedWeapon
then
6124 // Если нужно стрелять и нужное оружие, то нажать "Стрелять":
6125 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6127 RemoveAIFlag('NEEDFIRE');
6130 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6131 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6132 else PressKey(KEY_FIRE
);
6136 // Координаты ствола:
6137 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6138 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6140 Target
.UID
:= FTargetUID
;
6143 if Target
.UID
<> 0 then
6144 begin // Цель есть - настраиваем
6145 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6148 tpla
:= g_Player_Get(Target
.UID
);
6152 if (@FObj
) <> nil then
6159 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6160 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6161 Target
.Rect
:= PLAYER_RECT
;
6162 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6163 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6164 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6165 Target
.IsPlayer
:= True;
6169 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6172 mon
:= g_Monsters_ByUID(Target
.UID
);
6175 Target
.X
:= mon
.Obj
.X
;
6176 Target
.Y
:= mon
.Obj
.Y
;
6178 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6179 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6180 Target
.Rect
:= mon
.Obj
.Rect
;
6181 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6182 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6183 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6184 Target
.IsPlayer
:= False;
6191 begin // Цели нет - обнуляем
6196 Target
.Visible
:= False;
6197 Target
.Line
:= False;
6198 Target
.IsPlayer
:= False;
6203 // Если цель не видима или не на линии огня, то ищем все возможные цели:
6204 if (not Target
.Line
) or (not Target
.Visible
) then
6208 for a
:= 0 to High(gPlayers
) do
6209 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6210 (gPlayers
[a
].FUID
<> FUID
) and
6211 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6212 (not gPlayers
[a
].NoTarget
) and
6213 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6215 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6216 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6219 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6220 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6222 // Если игрок на экране и не прикрыт стеной:
6223 if g_TraceVector(x1
, y1
, x2
, y2
) then
6225 // Добавляем к списку возможных целей:
6226 SetLength(targets
, Length(targets
)+1);
6227 with targets
[High(targets
)] do
6229 UID
:= gPlayers
[a
].FUID
;
6230 X
:= gPlayers
[a
].FObj
.X
;
6231 Y
:= gPlayers
[a
].FObj
.Y
;
6234 Rect
:= PLAYER_RECT
;
6235 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6236 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6237 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6245 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6248 // Если есть возможные цели:
6249 // (Выбираем лучшую, меняем оружие и бежим к ней/от нее)
6250 if targets
<> nil then
6252 // Выбираем наилучшую цель:
6253 BestTarget
:= targets
[0];
6254 if Length(targets
) > 1 then
6255 for a
:= 1 to High(targets
) do
6256 if Compare(BestTarget
, targets
[a
]) = 1 then
6257 BestTarget
:= targets
[a
];
6259 // Если лучшая цель "виднее" текущей, то текущая := лучшая:
6260 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6261 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6263 Target
:= BestTarget
;
6265 if (Healthy() = 3) or ((Healthy() = 2)) then
6266 begin // Если здоровы - догоняем
6267 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6268 SetAIFlag('GORIGHT', '1');
6269 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6270 SetAIFlag('GOLEFT', '1');
6273 begin // Если побиты - убегаем
6274 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6275 SetAIFlag('GORIGHT', '1');
6276 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6277 SetAIFlag('GOLEFT', '1');
6280 // Выбираем оружие на основе расстояния и приоритетов:
6281 SelectWeapon(Abs(x1
-Target
.cX
));
6286 // (Догоняем/убегаем, стреляем по направлению к цели)
6287 // (Если цель далеко, то хватит следить за ней)
6288 if Target
.UID
<> 0 then
6290 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6291 Target
.Y
+ Target
.Rect
.Y
) then
6292 begin // Цель сбежала с "экрана"
6293 if (Healthy() = 3) or ((Healthy() = 2)) then
6294 begin // Если здоровы - догоняем
6295 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6296 SetAIFlag('GORIGHT', '1');
6297 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6298 SetAIFlag('GOLEFT', '1');
6301 begin // Если побиты - забываем о цели и убегаем
6303 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6304 SetAIFlag('GORIGHT', '1');
6305 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6306 SetAIFlag('GOLEFT', '1');
6310 begin // Цель пока на "экране"
6311 // Если цель не загорожена стеной, то отмечаем, когда ее видели:
6312 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6313 FLastVisible
:= gTime
;
6314 // Если разница высот не велика, то догоняем:
6315 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6317 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6318 SetAIFlag('GORIGHT', '1');
6319 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6320 SetAIFlag('GOLEFT', '1');
6324 // Выбираем угол вверх:
6325 if FDirection
= TDirection
.D_LEFT
then
6326 angle
:= ANGLE_LEFTUP
6328 angle
:= ANGLE_RIGHTUP
;
6330 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6331 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6333 // Если при угле вверх можно попасть в приблизительное положение цели:
6334 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6335 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6336 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6337 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6338 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6339 begin // то нужно стрелять вверх
6340 SetAIFlag('NEEDFIRE', '1');
6341 SetAIFlag('NEEDSEEUP', '1');
6344 // Выбираем угол вниз:
6345 if FDirection
= TDirection
.D_LEFT
then
6346 angle
:= ANGLE_LEFTDOWN
6348 angle
:= ANGLE_RIGHTDOWN
;
6350 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6351 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6353 // Если при угле вниз можно попасть в приблизительное положение цели:
6354 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6355 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6356 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6357 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6358 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6359 begin // то нужно стрелять вниз
6360 SetAIFlag('NEEDFIRE', '1');
6361 SetAIFlag('NEEDSEEDOWN', '1');
6364 // Если цель видно и она на такой же высоте:
6365 if Target
.Visible
and
6366 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6367 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6369 // Если идем в сторону цели, то надо стрелять:
6370 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
6371 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6372 begin // то нужно стрелять вперед
6373 SetAIFlag('NEEDFIRE', '1');
6374 SetAIFlag('NEEDSEEDOWN', '');
6375 SetAIFlag('NEEDSEEUP', '');
6377 // Если цель в пределах "экрана" и сложность позволяет прыжки сближения:
6378 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6379 if GetRnd(FDifficult
.CloseJump
) then
6380 begin // то если повезет - прыгаем (особенно, если близко)
6381 if Abs(FObj
.X
-Target
.X
) < 128 then
6385 if Random(a
) = 0 then
6386 SetAIFlag('NEEDJUMP', '1');
6390 // Если цель все еще есть:
6391 if Target
.UID
<> 0 then
6392 if gTime
-FLastVisible
> 2000 then // Если видели давно
6393 Target
.UID
:= 0 // то забыть цель
6394 else // Если видели недавно
6395 begin // но цель убили
6396 if Target
.IsPlayer
then
6397 begin // Цель - игрок
6398 pla
:= g_Player_Get(Target
.UID
);
6399 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
6400 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6401 Target
.UID
:= 0; // то забыть цель
6404 begin // Цель - монстр
6405 mon
:= g_Monsters_ByUID(Target
.UID
);
6406 if (mon
= nil) or (not mon
.alive
) then
6407 Target
.UID
:= 0; // то забыть цель
6410 end; // if Target.UID <> 0
6412 FTargetUID
:= Target
.UID
;
6414 // Если возможных целей нет:
6415 // (Атака чего-нибудь слева или справа)
6416 if targets
= nil then
6417 if GetAIFlag('ATTACKLEFT') <> '' then
6418 begin // Если нужно атаковать налево
6419 RemoveAIFlag('ATTACKLEFT');
6421 SetAIFlag('NEEDJUMP', '1');
6423 if RunDirection() = TDirection
.D_RIGHT
then
6424 begin // Идем не в ту сторону
6425 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6426 begin // Если здоровы, то, возможно, стреляем бежим влево и стреляем
6427 SetAIFlag('NEEDFIRE', '1');
6428 SetAIFlag('GOLEFT', '1');
6432 begin // Идем в нужную сторону
6433 if GetRnd(FDifficult
.InvisFire
) then // Возможно, стреляем вслепую
6434 SetAIFlag('NEEDFIRE', '1');
6435 if Healthy() <= 1 then // Побиты - убегаем
6436 SetAIFlag('GORIGHT', '1');
6440 if GetAIFlag('ATTACKRIGHT') <> '' then
6441 begin // Если нужно атаковать направо
6442 RemoveAIFlag('ATTACKRIGHT');
6444 SetAIFlag('NEEDJUMP', '1');
6446 if RunDirection() = TDirection
.D_LEFT
then
6447 begin // Идем не в ту сторону
6448 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6449 begin // Если здоровы, то, возможно, бежим вправо и стреляем
6450 SetAIFlag('NEEDFIRE', '1');
6451 SetAIFlag('GORIGHT', '1');
6456 if GetRnd(FDifficult
.InvisFire
) then // Возможно, стреляем вслепую
6457 SetAIFlag('NEEDFIRE', '1');
6458 if Healthy() <= 1 then // Побиты - убегаем
6459 SetAIFlag('GOLEFT', '1');
6463 //HACK! (does it belongs there?)
6464 RealizeCurrentWeapon();
6466 // Если есть возможные цели:
6467 // (Стреляем по направлению к целям)
6468 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6469 for a
:= 0 to High(targets
) do
6471 // Если можем стрелять по диагонали:
6472 if GetRnd(FDifficult
.DiagFire
) then
6474 // Ищем цель сверху и стреляем, если есть:
6475 if FDirection
= TDirection
.D_LEFT
then
6476 angle
:= ANGLE_LEFTUP
6478 angle
:= ANGLE_RIGHTUP
;
6480 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6481 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6483 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6484 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6485 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6486 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6487 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6489 SetAIFlag('NEEDFIRE', '1');
6490 SetAIFlag('NEEDSEEUP', '1');
6493 // Ищем цель снизу и стреляем, если есть:
6494 if FDirection
= TDirection
.D_LEFT
then
6495 angle
:= ANGLE_LEFTDOWN
6497 angle
:= ANGLE_RIGHTDOWN
;
6499 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6500 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6502 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6503 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6504 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6505 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6506 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6508 SetAIFlag('NEEDFIRE', '1');
6509 SetAIFlag('NEEDSEEDOWN', '1');
6513 // Если цель "перед носом", то стреляем:
6514 if targets
[a
].Line
and targets
[a
].Visible
and
6515 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
6516 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
6518 SetAIFlag('NEEDFIRE', '1');
6523 // Если летит пуля, то, возможно, подпрыгиваем:
6524 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
6525 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
6526 40+GetInterval(FDifficult
.Cover
, 40)) then
6527 SetAIFlag('NEEDJUMP', '1');
6529 // Если кончились паторны, то нужно сменить оружие:
6530 ammo
:= GetAmmoByWeapon(FCurrWeap
);
6531 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
6532 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
6534 SetAIFlag('SELECTWEAPON', '1');
6536 // Если нужно сменить оружие, то выбираем нужное:
6537 if GetAIFlag('SELECTWEAPON') = '1' then
6540 RemoveAIFlag('SELECTWEAPON');
6544 procedure TBot
.Update();
6557 // Проверяем, отключён ли AI ботов
6558 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
6560 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
6562 if g_debug_BotAIOff
= 3 then
6572 RealizeCurrentWeapon();
6579 procedure TBot
.ReleaseKey(Key
: Byte);
6588 function TBot
.KeyPressed(Key
: Word): Boolean;
6590 Result
:= FKeys
[Key
].Pressed
;
6593 function TBot
.GetAIFlag(aName
: String20
): String20
;
6599 aName
:= LowerCase(aName
);
6601 if FAIFlags
<> nil then
6602 for a
:= 0 to High(FAIFlags
) do
6603 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6605 Result
:= FAIFlags
[a
].Value
;
6610 procedure TBot
.RemoveAIFlag(aName
: String20
);
6614 if FAIFlags
= nil then Exit
;
6616 aName
:= LowerCase(aName
);
6618 for a
:= 0 to High(FAIFlags
) do
6619 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6621 if a
<> High(FAIFlags
) then
6622 for b
:= a
to High(FAIFlags
)-1 do
6623 FAIFlags
[b
] := FAIFlags
[b
+1];
6625 SetLength(FAIFlags
, Length(FAIFlags
)-1);
6630 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
6638 aName
:= LowerCase(aName
);
6640 if FAIFlags
<> nil then
6641 for a
:= 0 to High(FAIFlags
) do
6642 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6648 if ok
then FAIFlags
[a
].Value
:= fValue
6651 SetLength(FAIFlags
, Length(FAIFlags
)+1);
6652 with FAIFlags
[High(FAIFlags
)] do
6660 procedure TBot
.UpdateMove
;
6662 procedure GoLeft(Time
: Word = 1);
6664 ReleaseKey(KEY_LEFT
);
6665 ReleaseKey(KEY_RIGHT
);
6666 PressKey(KEY_LEFT
, Time
);
6667 SetDirection(TDirection
.D_LEFT
);
6670 procedure GoRight(Time
: Word = 1);
6672 ReleaseKey(KEY_LEFT
);
6673 ReleaseKey(KEY_RIGHT
);
6674 PressKey(KEY_RIGHT
, Time
);
6675 SetDirection(TDirection
.D_RIGHT
);
6678 function Rnd(a
: Word): Boolean;
6680 Result
:= Random(a
) = 0;
6683 procedure Turn(Time
: Word = 1200);
6685 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
6690 ReleaseKey(KEY_LEFT
);
6691 ReleaseKey(KEY_RIGHT
);
6694 function CanRunLeft(): Boolean;
6696 Result
:= not CollideLevel(-1, 0);
6699 function CanRunRight(): Boolean;
6701 Result
:= not CollideLevel(1, 0);
6704 function CanRun(): Boolean;
6706 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
6709 procedure Jump(Time
: Word = 30);
6711 PressKey(KEY_JUMP
, Time
);
6714 function NearHole(): Boolean;
6718 { TODO 5 : Лестницы }
6719 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
6720 for x
:= 1 to PLAYER_RECT
.Width
do
6721 if (not StayOnStep(x
*sx
, 0)) and
6722 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6723 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6732 function BorderHole(): Boolean;
6736 { TODO 5 : Лестницы }
6737 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
6738 for x
:= 1 to PLAYER_RECT
.Width
do
6739 if (not StayOnStep(x
*sx
, 0)) and
6740 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6741 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6743 for xx
:= x
to x
+32 do
6744 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
6754 function NearDeepHole(): Boolean;
6760 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
6763 for x
:= 1 to PLAYER_RECT
.Width
do
6764 if (not StayOnStep(x
*sx
, 0)) and
6765 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6766 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6768 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6770 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
6775 end else Result
:= False;
6778 function OverDeepHole(): Boolean;
6785 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6787 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
6794 function OnGround(): Boolean;
6796 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
6799 function OnLadder(): Boolean;
6801 Result
:= FullInStep(0, 0);
6804 function BelowLadder(): Boolean;
6806 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
6807 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
6808 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
6809 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
6812 function BelowLiftUp(): Boolean;
6814 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
6815 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
6816 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
6817 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
6820 function OnTopLift(): Boolean;
6822 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
6825 function CanJumpOver(): Boolean;
6829 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
6833 if not CollideLevel(sx
, 0) then Exit
;
6835 for y
:= 1 to BOT_MAXJUMP
do
6836 if CollideLevel(0, -y
) then Exit
else
6837 if not CollideLevel(sx
, -y
) then
6844 function CanJumpUp(Dist
: ShortInt): Boolean;
6851 if CollideLevel(Dist
, 0) then Exit
;
6854 for y
:= 0 to BOT_MAXJUMP
do
6855 if CollideLevel(Dist
, -y
) then
6864 for yy
:= y
+1 to BOT_MAXJUMP
do
6865 if not CollideLevel(Dist
, -yy
) then
6874 for y
:= 0 to BOT_MAXJUMP
do
6875 if CollideLevel(0, -y
) then
6883 if y
< yy
then Exit
;
6888 function IsSafeTrigger(): Boolean;
6893 if gTriggers
= nil then
6895 for a
:= 0 to High(gTriggers
) do
6896 if Collide(gTriggers
[a
].X
,
6899 gTriggers
[a
].Height
) and
6900 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
6901 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
6902 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
6903 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
6904 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
6909 // Возможно, нажимаем кнопку:
6910 if Rnd(16) and IsSafeTrigger() then
6913 // Если под лифтом или ступеньками, то, возможно, прыгаем:
6914 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
6916 ReleaseKey(KEY_LEFT
);
6917 ReleaseKey(KEY_RIGHT
);
6921 // Идем влево, если надо было:
6922 if GetAIFlag('GOLEFT') <> '' then
6924 RemoveAIFlag('GOLEFT');
6925 if CanRunLeft() then
6929 // Идем вправо, если надо было:
6930 if GetAIFlag('GORIGHT') <> '' then
6932 RemoveAIFlag('GORIGHT');
6933 if CanRunRight() then
6937 // Если вылетели за карту, то пробуем вернуться:
6938 if FObj
.X
< -32 then
6941 if FObj
.X
+32 > gMapInfo
.Width
then
6944 // Прыгаем, если надо было:
6945 if GetAIFlag('NEEDJUMP') <> '' then
6948 RemoveAIFlag('NEEDJUMP');
6951 // Смотрим вверх, если надо было:
6952 if GetAIFlag('NEEDSEEUP') <> '' then
6955 ReleaseKey(KEY_DOWN
);
6956 PressKey(KEY_UP
, 20);
6957 RemoveAIFlag('NEEDSEEUP');
6960 // Смотрим вниз, если надо было:
6961 if GetAIFlag('NEEDSEEDOWN') <> '' then
6964 ReleaseKey(KEY_DOWN
);
6965 PressKey(KEY_DOWN
, 20);
6966 RemoveAIFlag('NEEDSEEDOWN');
6969 // Если нужно было в дыру и мы не на земле, то покорно летим:
6970 if GetAIFlag('GOINHOLE') <> '' then
6971 if not OnGround() then
6973 ReleaseKey(KEY_LEFT
);
6974 ReleaseKey(KEY_RIGHT
);
6975 RemoveAIFlag('GOINHOLE');
6976 SetAIFlag('FALLINHOLE', '1');
6979 // Если падали и достигли земли, то хватит падать:
6980 if GetAIFlag('FALLINHOLE') <> '' then
6982 RemoveAIFlag('FALLINHOLE');
6984 // Если летели прямо и сейчас не на лестнице или на вершине лифта, то отходим в сторону:
6985 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
6986 if GetAIFlag('FALLINHOLE') = '' then
6987 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
6993 // Если на земле и можно подпрыгнуть, то, возможно, прыгаем:
6995 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
6999 // Если на земле и возле дыры (глубина > 2 ростов игрока):
7000 if OnGround() and NearHole() then
7001 if NearDeepHole() then // Если это бездна
7003 0..3: Turn(); // Бежим обратно
7004 4: Jump(); // Прыгаем
7005 5: begin // Прыгаем обратно
7010 else // Это не бездна и мы еще не летим туда
7011 if GetAIFlag('GOINHOLE') = '' then
7013 0: Turn(); // Не нужно туда
7014 1: Jump(); // Вдруг повезет - прыгаем
7015 else // Если яма с границей, то при случае можно туда прыгнуть
7016 if BorderHole() then
7017 SetAIFlag('GOINHOLE', '1');
7020 // Если на земле, но некуда идти:
7021 if (not CanRun()) and OnGround() then
7023 // Если мы на лестнице или можно перепрыгнуть, то прыгаем:
7024 if CanJumpOver() or OnLadder() then
7026 else // иначе попытаемся в другую сторону
7027 if Random(2) = 0 then
7029 if IsSafeTrigger() then
7035 // Осталось мало воздуха:
7036 if FAir
< 36 * 2 then
7039 // Выбираемся из кислоты, если нет костюма, обожглись, или мало здоровья:
7040 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7041 if BodyInAcid(0, 0) then
7045 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7047 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7048 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7051 {function TBot.NeedItem(Item: Byte): Byte;
7056 procedure TBot
.SelectWeapon(Dist
: Integer);
7060 function HaveAmmo(weapon
: Byte): Boolean;
7063 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7064 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7065 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7066 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7067 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7068 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7069 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7070 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7071 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7072 else Result
:= True;
7077 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7079 if Dist
> BOT_LONGDIST
then
7080 begin // Дальний бой
7082 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7084 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7088 else //if Dist > BOT_UNSAFEDIST then
7089 begin // Ближний бой
7091 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7093 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7100 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7102 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7108 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7110 Result
:= inherited PickItem(ItemType
, force
, remove
);
7112 if Result
then SetAIFlag('SELECTWEAPON', '1');
7115 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7117 Result
:= inherited Heal(value
, Soft
);
7120 function TBot
.Healthy(): Byte;
7122 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7123 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7124 else if (FHealth
> 50) then Result
:= 2
7125 else if (FHealth
> 20) then Result
:= 1
7129 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7131 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7132 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7135 procedure TBot
.OnDamage(Angle
: SmallInt);
7143 if (Angle
= 0) or (Angle
= 180) then
7146 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7147 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7149 pla
:= g_Player_Get(FLastSpawnerUID
);
7150 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7151 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7154 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7155 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7157 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7158 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7159 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7164 SetAIFlag('ATTACKLEFT', '1')
7166 SetAIFlag('ATTACKRIGHT', '1');
7170 function TBot
.RunDirection(): TDirection
;
7172 if Abs(Vel
.X
) >= 1 then
7174 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7176 Result
:= FDirection
;
7179 function TBot
.GetRnd(a
: Byte): Boolean;
7181 if a
= 0 then Result
:= False
7182 else if a
= 255 then Result
:= True
7183 else Result
:= Random(256) > 255-a
;
7186 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7188 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7192 procedure TDifficult
.save (st
: TStream
);
7194 utils
.writeInt(st
, Byte(DiagFire
));
7195 utils
.writeInt(st
, Byte(InvisFire
));
7196 utils
.writeInt(st
, Byte(DiagPrecision
));
7197 utils
.writeInt(st
, Byte(FlyPrecision
));
7198 utils
.writeInt(st
, Byte(Cover
));
7199 utils
.writeInt(st
, Byte(CloseJump
));
7200 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7201 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7204 procedure TDifficult
.load (st
: TStream
);
7206 DiagFire
:= utils
.readByte(st
);
7207 InvisFire
:= utils
.readByte(st
);
7208 DiagPrecision
:= utils
.readByte(st
);
7209 FlyPrecision
:= utils
.readByte(st
);
7210 Cover
:= utils
.readByte(st
);
7211 CloseJump
:= utils
.readByte(st
);
7212 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7213 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7217 procedure TBot
.SaveState (st
: TStream
);
7222 inherited SaveState(st
);
7223 utils
.writeSign(st
, 'BOT0');
7225 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7227 utils
.writeInt(st
, Word(FTargetUID
));
7228 // Время потери цели
7229 utils
.writeInt(st
, LongWord(FLastVisible
));
7230 // Количество флагов ИИ
7231 dw
:= Length(FAIFlags
);
7232 utils
.writeInt(st
, LongInt(dw
));
7234 for i
:= 0 to dw
-1 do
7236 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7237 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7239 // Настройки сложности
7240 FDifficult
.save(st
);
7244 procedure TBot
.LoadState (st
: TStream
);
7249 inherited LoadState(st
);
7250 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7252 FSelectedWeapon
:= utils
.readByte(st
);
7254 FTargetUID
:= utils
.readWord(st
);
7255 // Время потери цели
7256 FLastVisible
:= utils
.readLongWord(st
);
7257 // Количество флагов ИИ
7258 dw
:= utils
.readLongInt(st
);
7259 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7260 SetLength(FAIFlags
, dw
);
7262 for i
:= 0 to dw
-1 do
7264 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7265 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7267 // Настройки сложности
7268 FDifficult
.load(st
);
7273 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');
7274 conRegVar('player_indicator_style', @gPlayerIndicatorStyle
, 'Visual appearance of indicator', 'Visual appearance of indicator');