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}
654 e_log
, g_map
, g_items
, g_console
, g_gfx
, Math
, r_playermodel
, r_gfx
,
655 g_options
, g_triggers
, g_menu
, g_game
, g_grid
, e_res
,
656 wadreader
, g_monsters
, CONFIG
, g_language
,
660 const PLR_SAVE_VERSION
= 0;
670 diag_precision
: Byte;
674 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
675 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
676 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
680 TIME_RESPAWN1
= 1500;
681 TIME_RESPAWN2
= 2000;
682 TIME_RESPAWN3
= 3000;
683 PLAYER_SUIT_TIME
= 30000;
684 PLAYER_INVUL_TIME
= 30000;
685 PLAYER_INVIS_TIME
= 35000;
686 FRAG_COMBO_TIME
= 3000;
689 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
692 BOT_UNSAFEDIST
= 128;
693 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
694 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
695 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
696 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
697 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
698 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
699 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
700 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
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 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
703 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
704 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
705 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
706 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
707 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
708 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
709 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
710 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
711 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
712 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
713 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
714 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
715 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
716 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
717 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
718 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
720 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
721 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
723 BOTNAMES_FILENAME
= 'botnames.txt';
724 BOTLIST_FILENAME
= 'botlist.txt';
728 MaxCorpses
: Word = 20;
729 MaxShells
: Word = 300;
730 ForceModel
: Word = 0;
731 ForcedModelName
: String = STD_PLAYER_MODEL
;
732 CurrentGib
: Integer = 0;
733 CurrentShell
: Integer = 0;
734 BotNames
: Array of String;
735 BotList
: Array of TBotProfile
;
736 SavedStates
: Array of TPlayerSavedState
;
739 function Lerp(X
, Y
, Factor
: Integer): Integer;
741 Result
:= X
+ ((Y
- X
) div Factor
);
744 function SameTeam(UID1
, UID2
: Word): Boolean;
748 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
749 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
751 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
753 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
754 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
756 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
759 procedure g_Gibs_SetMax(Count
: Word);
762 SetLength(gGibs
, Count
);
764 if CurrentGib
>= Count
then
768 function g_Gibs_GetMax(): Word;
773 procedure g_Shells_SetMax(Count
: Word);
776 SetLength(gShells
, Count
);
778 if CurrentShell
>= Count
then
782 function g_Shells_GetMax(): Word;
788 procedure g_Corpses_SetMax(Count
: Word);
791 SetLength(gCorpses
, Count
);
794 function g_Corpses_GetMax(): Word;
796 Result
:= MaxCorpses
;
799 procedure g_Force_Model_Set(Mode
: Word);
804 function g_Force_Model_Get(): Word;
806 Result
:= ForceModel
;
809 procedure g_Forced_Model_SetName(Model
: String);
811 ForcedModelName
:= Model
;
814 function g_Forced_Model_GetName(): String;
816 Result
:= ForcedModelName
;
819 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
829 // Есть ли место в gPlayers:
830 if gPlayers
<> nil then
831 for a
:= 0 to High(gPlayers
) do
832 if gPlayers
[a
] = nil then
838 // Нет места - расширяем gPlayers:
841 SetLength(gPlayers
, Length(gPlayers
)+1);
845 // Создаем объект игрока:
847 gPlayers
[a
] := TBot
.Create()
849 gPlayers
[a
] := TPlayer
.Create();
852 gPlayers
[a
].FActualModelName
:= ModelName
;
853 gPlayers
[a
].SetModel(ModelName
);
854 if Bot
and (g_Force_Model_Get() <> 0) then
855 gPlayers
[a
].SetModel(g_Forced_Model_GetName());
857 // Нет модели - создание не возможно:
858 if gPlayers
[a
].FModel
= nil then
862 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
866 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
867 if Random(2) = 0 then
871 gPlayers
[a
].FPreferredTeam
:= Team
;
873 case gGameSettings
.GameMode
of
874 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
876 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
878 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
881 // Если командная игра - красим модель в цвет команды:
882 gPlayers
[a
].FColor
:= Color
;
883 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
884 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
886 gPlayers
[a
].FModel
.Color
:= Color
;
888 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
889 gPlayers
[a
].FAlive
:= False;
891 Result
:= gPlayers
[a
].FUID
;
894 function g_Player_CreateFromState (st
: TStream
): Word;
895 var a
: Integer; ok
, Bot
: Boolean; pos
: Int64;
899 // check signature and entity type
901 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
902 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
903 Bot
:= utils
.readBool(st
);
906 // find free player slot
908 for a
:= 0 to High(gPlayers
) do
909 if gPlayers
[a
] = nil then
915 // allocate player slot
918 SetLength(gPlayers
, Length(gPlayers
)+1);
922 // create entity and load state
925 gPlayers
[a
] := TBot
.Create();
926 if (g_Force_Model_Get() <> 0) then
927 gPlayers
[a
].SetModel(g_Forced_Model_GetName());
930 gPlayers
[a
] := TPlayer
.Create();
931 gPlayers
[a
].FPhysics
:= True; // ???
932 gPlayers
[a
].LoadState(st
);
934 result
:= gPlayers
[a
].FUID
;
938 procedure g_Player_ResetTeams();
942 if g_Game_IsClient
then
944 if gPlayers
= nil then
946 for a
:= Low(gPlayers
) to High(gPlayers
) do
947 if gPlayers
[a
] <> nil then
948 case gGameSettings
.GameMode
of
950 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
952 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
953 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
954 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
957 gPlayers
[a
].ChangeTeam(TEAM_RED
)
959 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
962 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
966 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
969 _name
, _model
: String;
972 if not g_Game_IsServer
then Exit
;
974 if (g_Bot_GetCount() >= gMaxBots
) then Exit
;
976 // Список названий моделей:
977 m
:= g_PlayerModel_GetNames();
982 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
983 Team
:= TEAM_COOP
// COOP
985 if gGameSettings
.GameMode
= GM_DM
then
986 Team
:= TEAM_NONE
// DM
988 if Team
= TEAM_NONE
then // CTF / TDM
990 // Автобаланс команд:
994 for a
:= 0 to High(gPlayers
) do
995 if gPlayers
[a
] <> nil then
997 if gPlayers
[a
].Team
= TEAM_RED
then
1000 if gPlayers
[a
].Team
= TEAM_BLUE
then
1010 if Random(2) = 0 then
1016 // Выбираем боту имя:
1018 if BotNames
<> nil then
1019 for a
:= 0 to High(BotNames
) do
1020 if g_Player_ValidName(BotNames
[a
]) then
1022 _name
:= BotNames
[a
];
1026 // Выбираем случайную модель:
1027 _model
:= m
[Random(Length(m
))];
1030 with g_Player_Get(g_Player_Create(_model
,
1031 _RGB(Min(Random(9)*32, 255),
1032 Min(Random(9)*32, 255),
1033 Min(Random(9)*32, 255)),
1034 Team
, True)) as TBot
do
1036 // Если имени нет, делаем его из UID бота
1038 Name
:= Format('DFBOT%.5d', [UID
])
1043 1: FDifficult
:= DIFFICULT_EASY
;
1044 2: FDifficult
:= DIFFICULT_MEDIUM
;
1045 else FDifficult
:= DIFFICULT_HARD
;
1048 for a
:= WP_FIRST
to WP_LAST
do
1050 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1051 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1052 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1055 FHandicap
:= Handicap
;
1057 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1059 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1060 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1065 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
1068 _name
, _model
: String;
1071 if not g_Game_IsServer
then Exit
;
1073 if (g_Bot_GetCount() >= gMaxBots
) then Exit
;
1075 // Список названий моделей:
1076 m
:= g_PlayerModel_GetNames();
1081 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1082 Team
:= TEAM_COOP
// COOP
1084 if gGameSettings
.GameMode
= GM_DM
then
1085 Team
:= TEAM_NONE
// DM
1087 if Team
= TEAM_NONE
then
1088 Team
:= BotList
[num
].team
; // CTF / TDM
1090 // Выбираем настройки бота из списка по номеру или имени:
1091 lName
:= AnsiLowerCase(lName
);
1092 if (num
< 0) or (num
> Length(BotList
)-1) then
1094 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1095 for a
:= 0 to High(BotList
) do
1096 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1105 _name
:= BotList
[num
].name
;
1106 // Занято - выбираем случайное:
1107 if not g_Player_ValidName(_name
) then
1109 _name
:= Format('DFBOT%.2d', [Random(100)]);
1110 until g_Player_ValidName(_name
);
1113 _model
:= BotList
[num
].model
;
1114 // Нет такой - выбираем случайную:
1115 if not InSArray(_model
, m
) then
1116 _model
:= m
[Random(Length(m
))];
1119 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1123 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1124 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1125 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1126 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1127 FDifficult
.Cover
:= BotList
[num
].cover
;
1128 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1130 FHandicap
:= Handicap
;
1132 for a
:= WP_FIRST
to WP_LAST
do
1134 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1135 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1136 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1139 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1141 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1145 procedure g_Bot_RemoveAll();
1149 if not g_Game_IsServer
then Exit
;
1150 if gPlayers
= nil then Exit
;
1152 for a
:= 0 to High(gPlayers
) do
1153 if gPlayers
[a
] <> nil then
1154 if gPlayers
[a
] is TBot
then
1156 gPlayers
[a
].Lives
:= 0;
1157 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1158 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1159 g_Player_Remove(gPlayers
[a
].FUID
);
1165 procedure g_Bot_MixNames();
1170 if BotNames
<> nil then
1171 for a
:= 0 to High(BotNames
) do
1173 b
:= Random(Length(BotNames
));
1175 Botnames
[a
] := BotNames
[b
];
1180 procedure g_Player_Remove(UID
: Word);
1184 if gPlayers
= nil then Exit
;
1186 if g_Game_IsServer
and g_Game_IsNet
then
1187 MH_SEND_PlayerDelete(UID
);
1189 for i
:= 0 to High(gPlayers
) do
1190 if gPlayers
[i
] <> nil then
1191 if gPlayers
[i
].FUID
= UID
then
1193 if gPlayers
[i
] is TPlayer
then
1194 TPlayer(gPlayers
[i
]).Free()
1196 TBot(gPlayers
[i
]).Free();
1202 procedure g_Player_Init();
1213 path
:= BOTNAMES_FILENAME
;
1214 if e_FindResource(DataDirs
, path
) = false then
1217 // Читаем возможные имена ботов из файла:
1218 AssignFile(F
, path
);
1229 SetLength(BotNames
, Length(BotNames
)+1);
1230 BotNames
[High(BotNames
)] := s
;
1238 // Читаем файл с параметрами ботов:
1239 config
:= TConfig
.CreateFile(path
);
1243 while config
.SectionExists(IntToStr(a
)) do
1245 SetLength(BotList
, Length(BotList
)+1);
1247 with BotList
[High(BotList
)] do
1250 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1252 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1254 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1259 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1260 color
.R
:= StrToIntDef(sa
[0], 0);
1261 color
.G
:= StrToIntDef(sa
[1], 0);
1262 color
.B
:= StrToIntDef(sa
[2], 0);
1263 // Вероятность стрельбы под углом:
1264 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1265 // Вероятность ответного огня по невидимому сопернику:
1266 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1267 // Точность стрельбы под углом:
1268 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1269 // Точность стрельбы в полете:
1270 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1271 // Точность уклонения от снарядов:
1272 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1273 // Вероятность прыжка при приближении соперника:
1274 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1275 // Приоритеты оружия для дальнего боя:
1276 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1277 if Length(sa
) = 10 then
1279 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1280 // Приоритеты оружия для ближнего боя:
1281 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1282 if Length(sa
) = 10 then
1284 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1286 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1287 if Length(sa) = 10 then
1289 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1296 SetLength(SavedStates
, 0);
1299 procedure g_Player_Free();
1303 if gPlayers
<> nil then
1305 for i
:= 0 to High(gPlayers
) do
1306 if gPlayers
[i
] <> nil then
1308 if gPlayers
[i
] is TPlayer
then
1309 TPlayer(gPlayers
[i
]).Free()
1311 TBot(gPlayers
[i
]).Free();
1320 SetLength(SavedStates
, 0);
1323 procedure g_Player_PreUpdate();
1327 if gPlayers
= nil then Exit
;
1328 for i
:= 0 to High(gPlayers
) do
1329 if gPlayers
[i
] <> nil then
1330 gPlayers
[i
].PreUpdate();
1333 procedure g_Player_UpdateAll();
1337 if gPlayers
= nil then Exit
;
1339 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1340 for i
:= 0 to High(gPlayers
) do
1342 if gPlayers
[i
] <> nil then
1344 if gPlayers
[i
] is TPlayer
then
1346 gPlayers
[i
].Update();
1347 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1351 // bot updates weapons in `UpdateCombat()`
1352 TBot(gPlayers
[i
]).Update();
1356 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1359 function g_Player_Get(UID
: Word): TPlayer
;
1365 if gPlayers
= nil then
1368 for a
:= 0 to High(gPlayers
) do
1369 if gPlayers
[a
] <> nil then
1370 if gPlayers
[a
].FUID
= UID
then
1372 Result
:= gPlayers
[a
];
1377 function g_Player_GetCount(): Byte;
1383 if gPlayers
= nil then
1386 for a
:= 0 to High(gPlayers
) do
1387 if gPlayers
[a
] <> nil then
1388 Result
:= Result
+ 1;
1391 function g_Bot_GetCount(): Integer;
1397 if gPlayers
= nil then
1400 for a
:= 0 to High(gPlayers
) do
1401 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] is TBot
) then
1402 Result
:= Result
+ 1;
1405 function g_Player_GetStats(): TPlayerStatArray
;
1411 if gPlayers
= nil then Exit
;
1413 for a
:= 0 to High(gPlayers
) do
1414 if gPlayers
[a
] <> nil then
1416 SetLength(Result
, Length(Result
)+1);
1417 with Result
[High(Result
)] do
1420 Ping
:= gPlayers
[a
].FPing
;
1421 Loss
:= gPlayers
[a
].FLoss
;
1422 Name
:= gPlayers
[a
].FName
;
1423 Team
:= gPlayers
[a
].FTeam
;
1424 Frags
:= gPlayers
[a
].FFrags
;
1425 Deaths
:= gPlayers
[a
].FDeath
;
1426 Kills
:= gPlayers
[a
].FKills
;
1427 Color
:= gPlayers
[a
].FModel
.Color
;
1428 Lives
:= gPlayers
[a
].FLives
;
1429 Spectator
:= gPlayers
[a
].FSpectator
;
1430 UID
:= gPlayers
[a
].FUID
;
1435 procedure g_Player_ResetReady();
1439 if not g_Game_IsServer
then Exit
;
1440 if gPlayers
= nil then Exit
;
1442 for a
:= 0 to High(gPlayers
) do
1443 if gPlayers
[a
] <> nil then
1445 gPlayers
[a
].FReady
:= False;
1446 if g_Game_IsNet
then
1447 MH_SEND_GameEvent(NET_EV_INTER_READY
, gPlayers
[a
].UID
, 'N');
1451 procedure g_Player_RememberAll
;
1455 for i
:= Low(gPlayers
) to High(gPlayers
) do
1456 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1457 gPlayers
[i
].RememberState
;
1460 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1464 gTeamStat
[TEAM_RED
].Score
:= 0;
1465 gTeamStat
[TEAM_BLUE
].Score
:= 0;
1467 if gPlayers
<> nil then
1468 for i
:= 0 to High(gPlayers
) do
1469 if gPlayers
[i
] <> nil then
1471 gPlayers
[i
].Reset(Force
);
1473 if gPlayers
[i
] is TPlayer
then
1475 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1476 gPlayers
[i
].Respawn(Silent
)
1478 gPlayers
[i
].Spectate();
1481 TBot(gPlayers
[i
]).Respawn(Silent
);
1485 function g_Player_CreateCorpse(Player
: TPlayer
): Integer;
1493 if Player
.alive
then
1496 // Разрываем связь с прежним трупом:
1497 i
:= Player
.FCorpse
;
1498 if (i
>= 0) and (i
< Length(gCorpses
)) then
1500 if (gCorpses
[i
] <> nil) and (gCorpses
[i
].FPlayerUID
= Player
.FUID
) then
1501 gCorpses
[i
].FPlayerUID
:= 0;
1504 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1509 if (FHealth
>= -50) or (gGibsCount
= 0) then
1511 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1515 for find_id
:= 0 to High(gCorpses
) do
1516 if gCorpses
[find_id
] = nil then
1523 find_id
:= Random(Length(gCorpses
));
1525 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.GetName(), FHealth
< -20);
1526 gCorpses
[find_id
].FModel
.Color
:= FModel
.Color
;
1527 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1528 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1529 gCorpses
[find_id
].FPlayerUID
:= FUID
;
1534 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
, FObj
.Y
+ PLAYER_RECT_CY
, FModel
.id
, FModel
.Color
);
1538 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1540 if (gShells
= nil) or (Length(gShells
) = 0) then
1543 with gShells
[CurrentShell
] do
1548 if T
= SHELL_BULLET
then
1550 Obj
.Rect
.Width
:= 4;
1551 Obj
.Rect
.Height
:= 2;
1555 Obj
.Rect
.Width
:= 7;
1556 Obj
.Rect
.Height
:= 3;
1562 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1563 positionChanged(); // this updates spatial accelerators
1564 RAngle
:= Random(360);
1565 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1567 if CurrentShell
>= High(gShells
) then
1574 procedure g_Player_CreateGibs (fX
, fY
, mid
: Integer; fColor
: TRGB
);
1577 GibsArray
: TGibsArray
;
1582 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1584 if not g_PlayerModel_GetGibs(mid
, GibsArray
) then
1586 Blood
:= PlayerModelsArray
[mid
].Blood
;
1588 for a
:= 0 to High(GibsArray
) do
1589 with gGibs
[CurrentGib
] do
1592 GibID
:= GibsArray
[a
];
1596 Obj
.Rect
:= r_PlayerModel_GetGibRect(ModelID
, GibID
);
1597 Obj
.X
:= fX
- Obj
.Rect
.X
- (Obj
.Rect
.Width
div 2);
1598 Obj
.Y
:= fY
- Obj
.Rect
.Y
- (Obj
.Rect
.Height
div 2);
1599 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1600 positionChanged(); // this updates spatial accelerators
1601 RAngle
:= Random(360);
1603 if gBloodCount
> 0 then
1604 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1605 Random(48), Random(48), Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
1607 if CurrentGib
>= High(gGibs
) then
1614 procedure g_Player_UpdatePhysicalObjects();
1620 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1625 if T
= SHELL_BULLET
then
1626 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1628 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1633 if gGibs
<> nil then
1634 for i
:= 0 to High(gGibs
) do
1635 if gGibs
[i
].alive
then
1642 mr
:= g_Obj_Move(@Obj
, True, False, True);
1643 positionChanged(); // this updates spatial accelerators
1645 if WordBool(mr
and MOVE_FALLOUT
) then
1651 // Отлетает от удара о стену/потолок/пол:
1652 if WordBool(mr
and MOVE_HITWALL
) then
1653 Obj
.Vel
.X
:= -(vel
.X
div 2);
1654 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1655 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1657 if (Obj
.Vel
.X
>= 0) then
1659 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1660 if RAngle
>= 360 then
1661 RAngle
:= RAngle
mod 360;
1662 end else begin // Counter-clockwise
1663 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1665 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1668 // Сопротивление воздуха для куска трупа:
1669 if gTime
mod (GAME_TICK
*3) = 0 then
1670 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1674 if gCorpses
<> nil then
1675 for i
:= 0 to High(gCorpses
) do
1676 if gCorpses
[i
] <> nil then
1677 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1683 gCorpses
[i
].Update();
1686 if gShells
<> nil then
1687 for i
:= 0 to High(gShells
) do
1688 if gShells
[i
].alive
then
1695 mr
:= g_Obj_Move(@Obj
, True, False, True);
1696 positionChanged(); // this updates spatial accelerators
1698 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1704 // Отлетает от удара о стену/потолок/пол:
1705 if WordBool(mr
and MOVE_HITWALL
) then
1707 Obj
.Vel
.X
:= -(vel
.X
div 2);
1708 if not WordBool(mr
and MOVE_INWATER
) then
1709 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1711 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1713 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1714 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1715 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1717 if RAngle
mod 90 <> 0 then
1718 RAngle
:= (RAngle
div 90) * 90;
1720 else if not WordBool(mr
and MOVE_INWATER
) then
1721 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1724 if (Obj
.Vel
.X
>= 0) then
1726 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1727 if RAngle
>= 360 then
1728 RAngle
:= RAngle
mod 360;
1729 end else begin // Counter-clockwise
1730 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1732 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1738 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1740 x
:= Obj
.X
+Obj
.Rect
.X
;
1741 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1742 w
:= Obj
.Rect
.Width
;
1743 h
:= Obj
.Rect
.Height
;
1746 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1748 if (dx
<> 0) or (dy
<> 0) then
1757 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1761 w
:= Obj
.Rect
.Width
;
1762 h
:= Obj
.Rect
.Height
;
1765 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1767 if (dx
<> 0) or (dy
<> 0) then
1776 procedure TGib
.positionChanged (); inline; begin end;
1777 procedure TShell
.positionChanged (); inline; begin end;
1780 procedure g_Player_RemoveAllCorpses();
1786 SetLength(gGibs
, MaxGibs
);
1787 SetLength(gShells
, MaxGibs
);
1791 if gCorpses
<> nil then
1792 for i
:= 0 to High(gCorpses
) do
1796 SetLength(gCorpses
, MaxCorpses
);
1799 procedure g_Player_Corpses_SaveState (st
: TStream
);
1803 // Считаем количество существующих трупов
1805 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1807 // Количество трупов
1808 utils
.writeInt(st
, LongInt(count
));
1810 if (count
= 0) then exit
;
1813 for i
:= 0 to High(gCorpses
) do
1815 if gCorpses
[i
] <> nil then
1818 utils
.writeStr(st
, gCorpses
[i
].FModel
.GetName());
1820 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1821 // Сохраняем данные трупа:
1822 gCorpses
[i
].SaveState(st
);
1828 procedure g_Player_Corpses_LoadState (st
: TStream
);
1836 g_Player_RemoveAllCorpses();
1838 // Количество трупов:
1839 count
:= utils
.readLongInt(st
);
1840 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1842 if (count
= 0) then exit
;
1845 for i
:= 0 to count
-1 do
1848 str
:= utils
.readStr(st
);
1850 b
:= utils
.readBool(st
);
1852 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1853 // Загружаем данные трупа
1854 gCorpses
[i
].LoadState(st
);
1861 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1863 procedure TPlayer
.BFGHit();
1865 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1866 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1867 if g_Game_IsServer
and g_Game_IsNet
then
1868 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1869 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1873 procedure TPlayer
.ChangeModel(ModelName
: string);
1875 locModel
: TPlayerModel
;
1877 locModel
:= g_PlayerModel_Get(ModelName
);
1878 if locModel
= nil then Exit
;
1884 procedure TPlayer
.SetModel(ModelName
: string);
1888 m
:= g_PlayerModel_Get(ModelName
);
1891 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1892 m
:= g_PlayerModel_Get('doomer');
1895 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1900 if FModel
<> nil then
1905 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1906 FModel
.Color
:= FColor
1908 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1909 FModel
.SetWeapon(FCurrWeap
);
1910 FModel
.SetFlag(FFlag
);
1911 SetDirection(FDirection
);
1914 procedure TPlayer
.SetColor(Color
: TRGB
);
1917 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1918 if FModel
<> nil then FModel
.Color
:= Color
;
1923 function TPlayer
.GetColor(): TRGB
;
1925 result
:= FModel
.Color
;
1928 procedure TPlayer
.SetWeaponPrefs(Prefs
: Array of Byte);
1932 for i
:= WP_FIRST
to WP_LAST
+ 1 do
1934 if (Prefs
[i
] > WP_LAST
+ 1) then
1935 FWeapPreferences
[i
] := 0
1937 FWeapPreferences
[i
] := Prefs
[i
];
1941 procedure TPlayer
.SetWeaponPref(Weapon
, Pref
: Byte);
1943 if (Weapon
> WP_LAST
+ 1) then
1945 else if (Pref
<= WP_LAST
+ 1) and (Weapon
<= WP_LAST
+ 1) then
1946 FWeapPreferences
[Weapon
] := Pref
1947 else if (Weapon
<= WP_LAST
+ 1) and (Pref
> WP_LAST
+ 1) then
1948 FWeapPreferences
[Weapon
] := 0;
1951 function TPlayer
.GetWeaponPref(Weapon
: Byte) : Byte;
1953 if (Weapon
> WP_LAST
+ 1) then
1955 else if (FWeapPreferences
[Weapon
] > WP_LAST
+ 1) then
1958 result
:= FWeapPreferences
[Weapon
];
1961 function TPlayer
.GetMorePrefered() : Byte;
1963 testedWeap
, i
: Byte;
1965 testedWeap
:= FCurrWeap
;
1966 for i
:= WP_FIRST
to WP_LAST
do
1967 if FWeapon
[i
] and maySwitch(i
) and (FWeapPreferences
[i
] > FWeapPreferences
[testedWeap
]) then
1969 if (R_BERSERK
in FRulez
) and (FWeapPreferences
[WP_LAST
+ 1] > FWeapPreferences
[testedWeap
]) then
1970 testedWeap
:= WEAPON_KASTET
;
1971 result
:= testedWeap
;
1974 function TPlayer
.maySwitch(Weapon
: Byte) : Boolean;
1977 if (Weapon
= WEAPON_KASTET
) and (FSkipFist
<> 0) then
1979 if (FSkipFist
= 1) and (not (R_BERSERK
in FRulez
)) then
1982 else if (FSwitchToEmpty
= 0) and (not hasAmmoForShooting(Weapon
)) then
1986 procedure TPlayer
.SwitchTeam
;
1988 if g_Game_IsClient
then
1990 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
1992 if gGameOn
and FAlive
then
1993 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
1995 if FTeam
= TEAM_RED
then
1997 ChangeTeam(TEAM_BLUE
);
1998 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
1999 if g_Game_IsNet
then
2000 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
2004 ChangeTeam(TEAM_RED
);
2005 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
2006 if g_Game_IsNet
then
2007 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
2009 FPreferredTeam
:= FTeam
;
2012 procedure TPlayer
.ChangeTeam(Team
: Byte);
2019 TEAM_RED
, TEAM_BLUE
:
2020 FModel
.Color
:= TEAMCOLOR
[Team
];
2022 FModel
.Color
:= FColor
;
2024 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2025 MH_SEND_PlayerStats(FUID
);
2029 procedure TPlayer.CollideItem();
2034 if gItems = nil then Exit;
2035 if not FAlive then Exit;
2037 for i := 0 to High(gItems) do
2040 if (ItemType <> ITEM_NONE) and alive then
2041 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2042 PLAYER_RECT.Height, @Obj) then
2044 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2046 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2047 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2048 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2049 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2050 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2052 // Надо убрать с карты, если это не ключ, которым нужно поделится с другим игроком:
2053 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2054 (gGameSettings.GameType = GT_SINGLE) and
2055 (g_Player_GetCount() > 1)) then
2056 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2062 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2064 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2065 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2069 constructor TPlayer
.Create();
2075 mEDamageType
:= HIT_SOME
;
2081 FSawSound
:= TPlayableSound
.Create();
2082 FSawSoundIdle
:= TPlayableSound
.Create();
2083 FSawSoundHit
:= TPlayableSound
.Create();
2084 FSawSoundSelect
:= TPlayableSound
.Create();
2085 FFlameSoundOn
:= TPlayableSound
.Create();
2086 FFlameSoundOff
:= TPlayableSound
.Create();
2087 FFlameSoundWork
:= TPlayableSound
.Create();
2088 FJetSoundFly
:= TPlayableSound
.Create();
2089 FJetSoundOn
:= TPlayableSound
.Create();
2090 FJetSoundOff
:= TPlayableSound
.Create();
2092 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2093 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2094 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2095 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2096 FFlameSoundOn
.SetByName('SOUND_WEAPON_FLAMEON');
2097 FFlameSoundOff
.SetByName('SOUND_WEAPON_FLAMEOFF');
2098 FFlameSoundWork
.SetByName('SOUND_WEAPON_FLAMEWORK');
2099 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2100 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2101 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2103 FSpectatePlayer
:= -1;
2107 FSavedStateNum
:= -1;
2115 FActualModelName
:= 'doomer';
2118 FObj
.Rect
:= PLAYER_RECT
;
2120 FBFGFireCounter
:= -1;
2121 FJustTeleported
:= False;
2124 FWaitForFirstSpawn
:= false;
2125 FPunchAnim
:= TAnimationState
.Create(False, 1, 4);
2131 procedure TPlayer
.positionChanged (); inline;
2135 procedure TPlayer
.doDamage (v
: Integer);
2137 if (v
<= 0) then exit
;
2138 if (v
> 32767) then v
:= 32767;
2139 Damage(v
, 0, 0, 0, mEDamageType
);
2142 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2146 if (not g_Game_IsClient
) and (not FAlive
) then
2151 // Неуязвимость не спасает от ловушек:
2152 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2154 if not g_Game_IsClient
then
2157 if t
= HIT_TRAP
then
2159 // Ловушка убивает сразу:
2161 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2163 if t
= HIT_SELF
then
2167 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2170 // Обнулить действия примочек, чтобы фон пропал
2171 FMegaRulez
[MR_SUIT
] := 0;
2172 FMegaRulez
[MR_INVUL
] := 0;
2173 FMegaRulez
[MR_INVIS
] := 0;
2178 // Но от остального спасает:
2179 if FMegaRulez
[MR_INVUL
] >= gTime
then
2186 // Если есть урон своим, или ранил сам себя, или тебя ранил противник:
2187 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2188 (SpawnerUID
= FUID
) or
2189 (not SameTeam(FUID
, SpawnerUID
)) then
2191 FLastSpawnerUID
:= SpawnerUID
;
2193 // Кровь (пузырьки, если в воде):
2194 if gBloodCount
> 0 then
2196 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2197 if value
div 4 <= c
then
2198 c
:= c
- (value
div 4)
2202 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2206 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2207 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2210 if t
= HIT_WATER
then
2212 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2213 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2215 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
2216 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
2222 Inc(FDamageBuffer
, value
);
2226 FPain
:= FPain
+ value
;
2229 if g_Game_IsServer
and g_Game_IsNet
then
2231 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2232 MH_SEND_PlayerStats(FUID
);
2233 MH_SEND_PlayerPos(False, FUID
);
2237 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2240 if g_Game_IsClient
then
2245 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2247 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2250 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2252 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2256 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2257 MH_SEND_PlayerStats(FUID
);
2260 destructor TPlayer
.Destroy();
2262 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2264 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2268 FSawSoundIdle
.Free();
2269 FSawSoundHit
.Free();
2270 FSawSoundSelect
.Free();
2271 FFlameSoundOn
.Free();
2272 FFlameSoundOff
.Free();
2273 FFlameSoundWork
.Free();
2274 FJetSoundFly
.Free();
2276 FJetSoundOff
.Free();
2283 procedure TPlayer
.DoPunch();
2289 procedure TPlayer
.Fire();
2291 f
, DidFire
: Boolean;
2292 wx
, wy
, xd
, yd
: Integer;
2295 if g_Game_IsClient
then Exit
;
2296 // FBFGFireCounter - время перед выстрелом (для BFG)
2297 // FReloading - время после выстрела (для всего)
2305 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2310 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2311 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2312 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
2313 yd
:= wy
+firediry();
2319 if R_BERSERK
in FRulez
then
2321 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2322 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2323 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2326 locobj
.rect
.Width
:= 39;
2327 locobj
.rect
.Height
:= 52;
2328 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2329 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2330 locobj
.Accel
.X
:= xd
-wx
;
2331 locobj
.Accel
.y
:= yd
-wy
;
2333 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2334 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2336 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2338 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
2342 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2346 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2351 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2352 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2354 FSawSoundSelect
.Stop();
2356 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2358 else if not FSawSoundHit
.IsPlaying() then
2360 FSawSoundSelect
.Stop();
2361 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2364 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2370 if FAmmo
[A_BULLETS
] > 0 then
2372 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2373 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2374 Dec(FAmmo
[A_BULLETS
]);
2375 FFireAngle
:= FAngle
;
2378 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2379 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2383 if FAmmo
[A_SHELLS
] > 0 then
2385 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2386 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
2387 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2388 Dec(FAmmo
[A_SHELLS
]);
2389 FFireAngle
:= FAngle
;
2393 FShellType
:= SHELL_SHELL
;
2397 if FAmmo
[A_SHELLS
] >= 2 then
2399 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
2400 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2401 Dec(FAmmo
[A_SHELLS
], 2);
2402 FFireAngle
:= FAngle
;
2406 FShellType
:= SHELL_DBLSHELL
;
2410 if FAmmo
[A_BULLETS
] > 0 then
2412 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
2413 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
2414 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2415 Dec(FAmmo
[A_BULLETS
]);
2416 FFireAngle
:= FAngle
;
2419 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2420 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2423 WEAPON_ROCKETLAUNCHER
:
2424 if FAmmo
[A_ROCKETS
] > 0 then
2426 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
2427 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2428 Dec(FAmmo
[A_ROCKETS
]);
2429 FFireAngle
:= FAngle
;
2435 if FAmmo
[A_CELLS
] > 0 then
2437 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
2438 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2439 Dec(FAmmo
[A_CELLS
]);
2440 FFireAngle
:= FAngle
;
2446 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
2448 FBFGFireCounter
:= 17;
2449 if not FNoReload
then
2450 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
2451 Dec(FAmmo
[A_CELLS
], 40);
2455 WEAPON_SUPERPULEMET
:
2456 if FAmmo
[A_SHELLS
] > 0 then
2458 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2459 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
2460 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2461 Dec(FAmmo
[A_SHELLS
]);
2462 FFireAngle
:= FAngle
;
2465 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2466 GameVelX
, GameVelY
-2, SHELL_SHELL
);
2469 WEAPON_FLAMETHROWER
:
2470 if FAmmo
[A_FUEL
] > 0 then
2472 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
2474 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2476 FFireAngle
:= FAngle
;
2483 if g_Game_IsNet
and g_Game_IsServer
then MH_SEND_PlayerStats(FUID
);
2487 if g_Game_IsNet
then
2491 if FCurrWeap
<> WEAPON_BFG
then
2492 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
2494 if not FNoReload
then
2495 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
2498 MH_SEND_PlayerStats(FUID
);
2503 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
2504 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
2505 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
2508 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
2511 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
2512 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
2513 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
2514 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
2515 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
2520 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
2522 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
2523 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
2524 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
2527 procedure TPlayer
.FlamerOn
;
2529 FFlameSoundOff
.Stop();
2530 FFlameSoundOff
.SetPosition(0);
2533 if (not FFlameSoundOn
.IsPlaying()) and (not FFlameSoundWork
.IsPlaying()) then
2534 FFlameSoundWork
.PlayAt(FObj
.X
, FObj
.Y
);
2538 FFlameSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
2543 procedure TPlayer
.FlamerOff
;
2547 FFlameSoundOn
.Stop();
2548 FFlameSoundOn
.SetPosition(0);
2549 FFlameSoundWork
.Stop();
2550 FFlameSoundWork
.SetPosition(0);
2551 FFlameSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
2556 procedure TPlayer
.JetpackOn
;
2560 FJetSoundOn
.SetPosition(0);
2561 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
2565 procedure TPlayer
.JetpackOff
;
2569 FJetSoundOff
.SetPosition(0);
2570 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
2573 procedure TPlayer
.CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
2575 if Timeout
<= 0 then
2577 if (FMegaRulez
[MR_SUIT
] > gTime
) or (FMegaRulez
[MR_INVUL
] > gTime
) then
2578 exit
; // Не загораемся когда есть защита
2579 if g_Obj_CollidePanel(@FObj
, 0, 0, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
) then
2580 exit
; // Не подгораем в воде на всякий случай
2581 if FFireTime
<= 0 then
2582 g_Sound_PlayExAt('SOUND_IGNITE', FObj
.X
, FObj
.Y
);
2583 FFireTime
:= Timeout
;
2584 FFireAttacker
:= Attacker
;
2585 if g_Game_IsNet
and g_Game_IsServer
then
2586 MH_SEND_PlayerStats(FUID
);
2589 procedure TPlayer
.Jump();
2591 if gFly
or FJetpack
then
2593 // Полет (чит-код или джетпак):
2594 if FObj
.Vel
.Y
> -VEL_FLY
then
2595 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
2598 if FJetFuel
> 0 then
2600 if (FJetFuel
< 1) and g_Game_IsServer
then
2604 if g_Game_IsNet
then
2605 MH_SEND_PlayerStats(FUID
);
2611 // Не включать джетпак в режиме прохождения сквозь стены
2613 FCanJetpack
:= False;
2615 // Прыгаем или всплываем:
2616 if (CollideLevel(0, 1) or
2617 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
2618 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
2619 ) and (FObj
.Accel
.Y
= 0) then // Не прыгать, если есть вертикальное ускорение
2621 FObj
.Vel
.Y
:= -VEL_JUMP
;
2622 FCanJetpack
:= False;
2626 if BodyInLiquid(0, 0) then
2627 FObj
.Vel
.Y
:= -VEL_SW
2628 else if (FJetFuel
> 0) and FCanJetpack
and
2629 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
2633 if g_Game_IsNet
then
2634 MH_SEND_PlayerStats(FUID
);
2639 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
2641 a
, i
, k
, ab
, ar
: Byte;
2645 srv
, netsrv
: Boolean;
2651 procedure PushItem(t
: Byte);
2655 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
2656 it
:= g_Items_ByIdx(id
);
2657 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
2659 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
2660 (FObj
.Vel
.Y
div 2)-Random(9));
2661 it
.positionChanged(); // this updates spatial accelerators
2665 if KillType
= K_HARDKILL
then // -5..+5; -5..0
2667 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
2668 (FObj
.Vel
.Y
div 2)-Random(6));
2670 else // -3..+3; -3..0
2672 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
2673 (FObj
.Vel
.Y
div 2)-Random(4));
2675 it
.positionChanged(); // this updates spatial accelerators
2678 if g_Game_IsNet
and g_Game_IsServer
then
2679 MH_SEND_ItemSpawn(True, id
);
2683 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
2684 Srv
:= g_Game_IsServer
;
2685 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
2686 if Srv
then FDeath
:= FDeath
+ 1;
2691 if not FPhysics
then
2697 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2699 if FLives
> 0 then FLives
:= FLives
- 1;
2700 if FLives
= 0 then FNoRespawn
:= True;
2703 // Номер типа смерти:
2706 K_SIMPLEKILL
: a
:= 1;
2708 K_EXTRAHARDKILL
: a
:= 3;
2713 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
2715 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
2722 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
2724 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
2725 K_EXTRAHARDKILL
, K_FALLKILL
:
2726 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
2729 // Переключаем состояние:
2733 K_HARDKILL
, K_EXTRAHARDKILL
:
2737 // Реакция монстров на смерть игрока:
2738 if (KillType
<> K_FALLKILL
) and (Srv
) then
2739 g_Monsters_killedp();
2741 if SpawnerUID
= FUID
then
2745 if gGameSettings
.GameMode
= GM_TDM
then
2746 Dec(gTeamStat
[FTeam
].Score
);
2747 if DoFrags
or (gGameSettings
.GameMode
= GM_TDM
) then
2753 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
2756 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
2757 begin // Убит другим игроком
2758 KP
:= g_Player_Get(SpawnerUID
);
2759 if (KP
<> nil) and Srv
then
2761 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
2762 if SameTeam(FUID
, SpawnerUID
) then
2772 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
2773 Inc(gTeamStat
[KP
.Team
].Score
,
2774 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
2776 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
2779 plr
:= g_Player_Get(SpawnerUID
);
2787 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
2791 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
2795 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
2800 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
2801 begin // Убит монстром
2802 mon
:= g_Monsters_ByUID(SpawnerUID
);
2806 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
2810 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
2814 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
2818 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
2823 else // Особые типы смерти
2826 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
2827 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
2828 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
2829 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
2830 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
2831 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
2837 for a
:= WP_FIRST
to WP_LAST
do
2841 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
2842 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
2843 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
2844 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
2845 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
2846 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
2847 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
2848 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
2849 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
2858 if R_ITEM_BACKPACK
in FRulez
then
2859 PushItem(ITEM_AMMO_BACKPACK
);
2861 // Выброс ракетного ранца:
2862 if FJetFuel
> 0 then
2863 PushItem(ITEM_JETPACK
);
2866 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) or
2867 (not LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
)) then
2869 if R_KEY_RED
in FRulez
then
2870 PushItem(ITEM_KEY_RED
);
2872 if R_KEY_GREEN
in FRulez
then
2873 PushItem(ITEM_KEY_GREEN
);
2875 if R_KEY_BLUE
in FRulez
then
2876 PushItem(ITEM_KEY_BLUE
);
2880 DropFlag(KillType
= K_FALLKILL
);
2883 FCorpse
:= g_Player_CreateCorpse(Self
);
2885 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
2886 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2892 for i
:= Low(gPlayers
) to High(gPlayers
) do
2894 if gPlayers
[i
] = nil then continue
;
2895 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
2898 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
2899 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
2904 OldLR
:= gLMSRespawn
;
2905 if (gGameSettings
.GameMode
= GM_COOP
) then
2909 // everyone is dead, restart the map
2910 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
2912 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
2913 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2914 gLMSRespawnTime
:= gTime
+ 5000;
2916 else if (a
= 1) then
2918 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
2919 if (gPlayers
[k
] = gPlayer1
) or
2920 (gPlayers
[k
] = gPlayer2
) then
2921 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
2922 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
2923 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
2926 else if (gGameSettings
.GameMode
= GM_TDM
) then
2928 if (ab
= 0) and (ar
<> 0) then
2931 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
2933 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
2934 Inc(gTeamStat
[TEAM_RED
].Score
);
2935 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2936 gLMSRespawnTime
:= gTime
+ 5000;
2938 else if (ar
= 0) and (ab
<> 0) then
2941 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
2943 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
2944 Inc(gTeamStat
[TEAM_BLUE
].Score
);
2945 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2946 gLMSRespawnTime
:= gTime
+ 5000;
2948 else if (ar
= 0) and (ab
= 0) then
2951 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
2953 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
2954 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2955 gLMSRespawnTime
:= gTime
+ 5000;
2958 else if (gGameSettings
.GameMode
= GM_DM
) then
2962 if gPlayers
[k
] <> nil then
2965 // survivor is the winner
2966 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
2968 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
2971 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2972 gLMSRespawnTime
:= gTime
+ 5000;
2974 else if (a
= 0) then
2976 // everyone is dead, restart the map
2977 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
2979 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
2980 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2981 gLMSRespawnTime
:= gTime
+ 5000;
2984 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
2986 if NetMode
= NET_SERVER
then
2987 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
)
2989 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
2995 MH_SEND_PlayerStats(FUID
);
2996 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
2997 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3000 if srv
and FNoRespawn
then Spectate(True);
3001 FWantsInGame
:= True;
3004 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3006 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3007 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3010 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3012 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3013 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3016 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3017 var Blood
: TModelBlood
;
3019 Blood
:= SELF
.FModel
.GetBlood();
3020 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3021 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3022 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3023 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
3024 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3025 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3026 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3027 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
3030 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3031 var Blood
: TModelBlood
;
3033 Blood
:= SELF
.FModel
.GetBlood();
3034 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3035 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3036 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3037 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
3040 procedure TPlayer
.ProcessWeaponAction(Action
: Byte);
3042 if g_Game_IsClient
then Exit
;
3044 WP_PREV
: PrevWeapon();
3045 WP_NEXT
: NextWeapon();
3049 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3051 if g_Game_IsClient
then Exit
;
3052 if Weapon
> High(FWeapon
) then Exit
;
3053 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3056 procedure TPlayer
.resetWeaponQueue ();
3059 FNextWeapDelay
:= 0;
3062 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3066 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3067 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
3068 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
3069 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3070 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3071 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3072 else result
:= (weapon
< length(FWeapon
));
3076 function TPlayer
.hasAmmoForShooting (weapon
: Byte): Boolean;
3080 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3081 WEAPON_SHOTGUN1
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
3082 WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 1);
3083 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
3084 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3085 WEAPON_PLASMA
: result
:= (FAmmo
[A_CELLS
] > 0);
3086 WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] >= 40);
3087 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3088 else result
:= (weapon
< length(FWeapon
));
3092 function TPlayer
.shouldSwitch (weapon
: Byte; hadWeapon
: Boolean): Boolean;
3095 if (weapon
> WP_LAST
+ 1) then
3100 if (FWeapSwitchMode
= 1) and not hadWeapon
then
3102 else if (FWeapSwitchMode
= 2) then
3103 result
:= (FWeapPreferences
[weapon
] > FWeapPreferences
[FCurrWeap
]);
3106 // return 255 for "no switch"
3107 function TPlayer
.getNextWeaponIndex (): Byte;
3110 wantThisWeapon
: array[0..64] of Boolean;
3111 wwc
: Integer = 0; //HACK!
3114 result
:= 255; // default result: "no switch"
3115 //e_LogWriteFln('FSWITCHTOEMPTY: %s', [FSwitchToEmpty], TMsgType.Notify);
3116 // had weapon cycling on previous frame? remove that flag
3117 if (FNextWeap
and $2000) <> 0 then
3119 FNextWeap
:= FNextWeap
and $1FFF;
3120 FNextWeapDelay
:= 0;
3122 // cycling has priority
3123 if (FNextWeap
and $C000) <> 0 then
3125 if (FNextWeap
and $8000) <> 0 then
3129 FNextWeap
:= FNextWeap
or $2000; // we need this
3130 if FNextWeapDelay
> 0 then
3131 exit
; // cooldown time
3133 for i
:= 0 to High(FWeapon
) do
3135 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3136 if FWeapon
[cwi
] and maySwitch(cwi
) then
3138 //e_LogWriteFln(' SWITCH: cur=%d; new=%d %s %s', [FCurrWeap, cwi, FSwitchToEmpty, hasAmmoForWeapon(cwi)], TMsgType.Notify);
3139 result
:= Byte(cwi
);
3140 FNextWeapDelay
:= WEAPON_DELAY
;
3148 for i
:= 0 to High(wantThisWeapon
) do
3149 wantThisWeapon
[i
] := false;
3150 for i
:= 0 to High(FWeapon
) do
3151 if (FNextWeap
and (1 shl i
)) <> 0 then
3153 wantThisWeapon
[i
] := true;
3157 // exclude currently selected weapon from the set
3158 wantThisWeapon
[FCurrWeap
] := false;
3159 // slow down alterations a little
3162 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3163 // more than one weapon requested, assume "alteration" and check alteration delay
3164 if FNextWeapDelay
> 0 then
3170 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3171 // but clear all counters if no weapon should be switched
3177 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3178 // try weapons in descending order
3179 for i
:= High(FWeapon
) downto 0 do
3181 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3186 FNextWeapDelay
:= WEAPON_DELAY
* 2; // anyway, 'cause why not
3187 //e_LogWriteFln('FOUND %s %s %s', [result, FSwitchToEmpty, hasAmmoForWeapon(i)], TMsgType.Notify);
3191 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3195 procedure TPlayer
.RealizeCurrentWeapon();
3196 function switchAllowed (): Boolean;
3201 if FBFGFireCounter
<> -1 then
3203 if FTime
[T_SWITCH
] > gTime
then
3205 for i
:= WP_FIRST
to WP_LAST
do
3206 if FReloading
[i
] > 0 then
3214 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3215 //FNextWeap := FNextWeap and $1FFF;
3216 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3218 if not switchAllowed
then
3220 //HACK for weapon cycling
3221 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3225 nw
:= getNextWeaponIndex();
3227 if nw
= 255 then exit
; // don't reset anything here
3228 if nw
> High(FWeapon
) then
3230 // don't forget to reset queue here!
3231 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3239 FTime
[T_SWITCH
] := gTime
+156;
3240 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3241 FModel
.SetWeapon(FCurrWeap
);
3242 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3246 procedure TPlayer
.NextWeapon();
3248 if g_Game_IsClient
then Exit
;
3252 procedure TPlayer
.PrevWeapon();
3254 if g_Game_IsClient
then Exit
;
3258 procedure TPlayer
.SetWeapon(W
: Byte);
3260 if FCurrWeap
<> W
then
3261 if W
= WEAPON_SAW
then
3262 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3265 FModel
.SetWeapon(CurrWeap
);
3269 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3272 switchWeapon
: Byte = 255;
3273 hadWeapon
: Boolean = False;
3276 if g_Game_IsClient
then Exit
;
3278 // a = true - место спавна предмета:
3279 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3283 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3285 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3289 if gFlash
= 2 then Inc(FPickup
, 5);
3293 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3295 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3299 if gFlash
= 2 then Inc(FPickup
, 5);
3303 if FArmor
< PLAYER_AP_SOFT
then
3305 FArmor
:= PLAYER_AP_SOFT
;
3308 if gFlash
= 2 then Inc(FPickup
, 5);
3312 if FArmor
< PLAYER_AP_LIMIT
then
3314 FArmor
:= PLAYER_AP_LIMIT
;
3317 if gFlash
= 2 then Inc(FPickup
, 5);
3321 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
3323 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3327 if gFlash
= 2 then Inc(FPickup
, 5);
3331 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) or (FFireTime
> 0) then
3333 if FHealth
< PLAYER_HP_LIMIT
then
3334 FHealth
:= PLAYER_HP_LIMIT
;
3335 if FArmor
< PLAYER_AP_LIMIT
then
3336 FArmor
:= PLAYER_AP_LIMIT
;
3340 if gFlash
= 2 then Inc(FPickup
, 5);
3344 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3346 hadWeapon
:= FWeapon
[WEAPON_SAW
];
3347 switchWeapon
:= WEAPON_SAW
;
3348 FWeapon
[WEAPON_SAW
] := True;
3350 if gFlash
= 2 then Inc(FPickup
, 5);
3351 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3354 ITEM_WEAPON_SHOTGUN1
:
3355 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3357 // Нужно, чтобы не взять все пули сразу:
3358 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3359 hadWeapon
:= FWeapon
[WEAPON_SHOTGUN1
];
3360 switchWeapon
:= WEAPON_SHOTGUN1
;
3361 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3362 FWeapon
[WEAPON_SHOTGUN1
] := True;
3364 if gFlash
= 2 then Inc(FPickup
, 5);
3365 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3368 ITEM_WEAPON_SHOTGUN2
:
3369 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3371 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3372 hadWeapon
:= FWeapon
[WEAPON_SHOTGUN2
];
3373 switchWeapon
:= WEAPON_SHOTGUN2
;
3374 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3375 FWeapon
[WEAPON_SHOTGUN2
] := 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_CHAINGUN
:
3382 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3384 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3385 hadWeapon
:= FWeapon
[WEAPON_CHAINGUN
];
3386 switchWeapon
:= WEAPON_CHAINGUN
;
3387 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3388 FWeapon
[WEAPON_CHAINGUN
] := 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_ROCKETLAUNCHER
:
3395 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3397 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3398 switchWeapon
:= WEAPON_ROCKETLAUNCHER
;
3399 hadWeapon
:= FWeapon
[WEAPON_ROCKETLAUNCHER
];
3400 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3401 FWeapon
[WEAPON_ROCKETLAUNCHER
] := 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');
3408 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3410 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3411 switchWeapon
:= WEAPON_PLASMA
;
3412 hadWeapon
:= FWeapon
[WEAPON_PLASMA
];
3413 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3414 FWeapon
[WEAPON_PLASMA
] := 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_BFG
] then
3423 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3424 switchWeapon
:= WEAPON_BFG
;
3425 hadWeapon
:= FWeapon
[WEAPON_BFG
];
3426 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3427 FWeapon
[WEAPON_BFG
] := 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');
3433 ITEM_WEAPON_SUPERPULEMET
:
3434 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3436 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3437 switchWeapon
:= WEAPON_SUPERPULEMET
;
3438 hadWeapon
:= FWeapon
[WEAPON_SUPERPULEMET
];
3439 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3440 FWeapon
[WEAPON_SUPERPULEMET
] := 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_FLAMETHROWER
:
3447 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
3449 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
3450 switchWeapon
:= WEAPON_FLAMETHROWER
;
3451 hadWeapon
:= FWeapon
[WEAPON_FLAMETHROWER
];
3452 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3453 FWeapon
[WEAPON_FLAMETHROWER
] := 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');
3460 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3462 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3465 if gFlash
= 2 then Inc(FPickup
, 5);
3468 ITEM_AMMO_BULLETS_BOX
:
3469 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3471 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3474 if gFlash
= 2 then Inc(FPickup
, 5);
3478 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3480 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3483 if gFlash
= 2 then Inc(FPickup
, 5);
3486 ITEM_AMMO_SHELLS_BOX
:
3487 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3489 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
3492 if gFlash
= 2 then Inc(FPickup
, 5);
3496 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3498 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3501 if gFlash
= 2 then Inc(FPickup
, 5);
3504 ITEM_AMMO_ROCKET_BOX
:
3505 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3507 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
3510 if gFlash
= 2 then Inc(FPickup
, 5);
3514 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3516 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3519 if gFlash
= 2 then Inc(FPickup
, 5);
3523 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3525 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
3528 if gFlash
= 2 then Inc(FPickup
, 5);
3532 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
3534 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3537 if gFlash
= 2 then Inc(FPickup
, 5);
3541 if not(R_ITEM_BACKPACK
in FRulez
) or
3542 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
3543 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
3544 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
3545 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
3546 (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) then
3548 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
3549 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
3550 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
3551 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
3552 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
3554 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3555 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3556 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3557 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3558 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3559 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3560 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3561 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3562 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
3563 IncMax(FAmmo
[A_FUEL
], 50, FMaxAmmo
[A_FUEL
]);
3565 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
3568 if gFlash
= 2 then Inc(FPickup
, 5);
3572 if not(R_KEY_RED
in FRulez
) then
3574 Include(FRulez
, R_KEY_RED
);
3576 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3577 if gFlash
= 2 then Inc(FPickup
, 5);
3578 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3582 if not(R_KEY_GREEN
in FRulez
) then
3584 Include(FRulez
, R_KEY_GREEN
);
3586 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3587 if gFlash
= 2 then Inc(FPickup
, 5);
3588 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3592 if not(R_KEY_BLUE
in FRulez
) then
3594 Include(FRulez
, R_KEY_BLUE
);
3596 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3597 if gFlash
= 2 then Inc(FPickup
, 5);
3598 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3602 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
3604 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
3608 if gFlash
= 2 then Inc(FPickup
, 5);
3612 if FAir
< AIR_MAX
then
3617 if gFlash
= 2 then Inc(FPickup
, 5);
3622 if not (R_BERSERK
in FRulez
) then
3624 Include(FRulez
, R_BERSERK
);
3625 if (FBFGFireCounter
= -1) then
3627 FCurrWeap
:= WEAPON_KASTET
;
3629 FModel
.SetWeapon(WEAPON_KASTET
);
3634 if gFlash
= 2 then Inc(FPickup
, 5);
3636 FBerserk
:= gTime
+30000;
3641 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3643 if FHealth
< PLAYER_HP_SOFT
then FHealth
:= PLAYER_HP_SOFT
;
3644 FBerserk
:= gTime
+30000;
3652 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
3654 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
3658 if gFlash
= 2 then Inc(FPickup
, 5);
3662 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
3664 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
3668 if gFlash
= 2 then Inc(FPickup
, 5);
3672 if FArmor
< PLAYER_AP_LIMIT
then
3674 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
3677 if gFlash
= 2 then Inc(FPickup
, 5);
3681 if FJetFuel
< JET_MAX
then
3683 FJetFuel
:= JET_MAX
;
3686 if gFlash
= 2 then Inc(FPickup
, 5);
3690 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
3692 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
3695 if gFlash
= 2 then Inc(FPickup
, 5);
3699 if (shouldSwitch(switchWeapon
, hadWeapon
)) then
3700 QueueWeaponSwitch(switchWeapon
);
3703 procedure TPlayer
.Touch();
3707 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
3710 // Бросить флаг товарищу:
3711 if gGameSettings
.GameMode
= GM_CTF
then
3716 procedure TPlayer
.Push(vx
, vy
: Integer);
3718 if (not FPhysics
) and FGhost
then
3720 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
3721 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
3722 if g_Game_IsNet
and g_Game_IsServer
then
3723 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
3726 procedure TPlayer
.Reset(Force
: Boolean);
3732 FTime
[T_RESPAWN
] := 0;
3733 FTime
[T_FLAGCAP
] := 0;
3749 FSpectator
:= False;
3752 FSpectatePlayer
:= -1;
3753 FNoRespawn
:= False;
3755 FLives
:= gGameSettings
.MaxLives
;
3760 procedure TPlayer
.SoftReset();
3768 FBFGFireCounter
:= -1;
3776 SetAction(A_STAND
, True);
3779 function TPlayer
.GetRespawnPoint(): Byte;
3784 // На будущее: FSpawn - игрок уже играл и перерождается
3786 // Одиночная игра/кооператив
3787 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
3789 if Self
= gPlayer1
then
3791 // player 1 should try to spawn on the player 1 point
3792 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) > 0 then
3793 Exit(RESPAWNPOINT_PLAYER1
)
3794 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) > 0 then
3795 Exit(RESPAWNPOINT_PLAYER2
);
3797 else if Self
= gPlayer2
then
3799 // player 2 should try to spawn on the player 2 point
3800 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) > 0 then
3801 Exit(RESPAWNPOINT_PLAYER2
)
3802 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) > 0 then
3803 Exit(RESPAWNPOINT_PLAYER1
);
3807 // other players randomly pick either the first or the second point
3808 c
:= IfThen((Random(2) = 0), RESPAWNPOINT_PLAYER1
, RESPAWNPOINT_PLAYER2
);
3809 if g_Map_GetPointCount(c
) > 0 then
3811 // try the other one
3812 c
:= IfThen((c
= RESPAWNPOINT_PLAYER1
), RESPAWNPOINT_PLAYER2
, RESPAWNPOINT_PLAYER1
);
3813 if g_Map_GetPointCount(c
) > 0 then
3819 if gGameSettings
.GameMode
= GM_DM
then
3821 // try DM points first
3822 if g_Map_GetPointCount(RESPAWNPOINT_DM
) > 0 then
3823 Exit(RESPAWNPOINT_DM
);
3827 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
3829 // try team points first
3830 c
:= RESPAWNPOINT_DM
;
3831 if FTeam
= TEAM_RED
then
3832 c
:= RESPAWNPOINT_RED
3833 else if FTeam
= TEAM_BLUE
then
3834 c
:= RESPAWNPOINT_BLUE
;
3835 if g_Map_GetPointCount(c
) > 0 then
3839 // still haven't found a spawnpoint, try random shit
3840 Result
:= g_Map_GetRandomPointType();
3843 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
3845 RespawnPoint
: TRespawnPoint
;
3851 FBFGFireCounter
:= -1;
3858 if not g_Game_IsServer
then
3862 FWantsInGame
:= True;
3863 FJustTeleported
:= True;
3866 FTime
[T_RESPAWN
] := 0;
3870 // if server changes MaxLives we gotta be ready
3871 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
3873 // Еще нельзя возродиться:
3874 if FTime
[T_RESPAWN
] > gTime
then
3877 // Просрал все жизни:
3880 if not FSpectator
then Spectate(True);
3881 FWantsInGame
:= True;
3885 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
3886 begin // "Своя игра"
3887 // Берсерк не сохраняется между уровнями:
3888 FRulez
:= FRulez
-[R_BERSERK
];
3890 else // "Одиночная игра"/"Кооп"
3892 // Берсерк и ключи не сохраняются между уровнями:
3893 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
3896 // Получаем точку спауна игрока:
3897 c
:= GetRespawnPoint();
3902 // Воскрешение без оружия:
3905 FHealth
:= Round(PLAYER_HP_SOFT
* (FHandicap
/ 100));
3911 for a
:= WP_FIRST
to WP_LAST
do
3913 FWeapon
[a
] := False;
3917 FWeapon
[WEAPON_PISTOL
] := True;
3918 FWeapon
[WEAPON_KASTET
] := True;
3919 FCurrWeap
:= WEAPON_PISTOL
;
3922 FModel
.SetWeapon(FCurrWeap
);
3924 for b
:= A_BULLETS
to A_HIGH
do
3927 FAmmo
[A_BULLETS
] := 50;
3929 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
3930 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
3931 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
3932 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
3933 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
3935 if (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) and
3936 LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
) then
3937 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
3942 // Получаем координаты точки возрождения:
3943 if not g_Map_GetPoint(c
, RespawnPoint
) then
3945 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3949 // Установка координат и сброс всех параметров:
3950 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
3951 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
3952 FObj
.oldX
:= FObj
.X
; // don't interpolate after respawn
3953 FObj
.oldY
:= FObj
.Y
;
3959 FDirection
:= RespawnPoint
.Direction
;
3960 if FDirection
= TDirection
.D_LEFT
then
3965 SetAction(A_STAND
, True);
3966 FModel
.Direction
:= FDirection
;
3968 for a
:= Low(FTime
) to High(FTime
) do
3971 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
3974 // Respawn invulnerability
3975 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.SpawnInvul
> 0) then
3977 FMegaRulez
[MR_INVUL
] := gTime
+ gGameSettings
.SpawnInvul
* 1000;
3978 FSpawnInvul
:= FMegaRulez
[MR_INVUL
];
3983 FCanJetpack
:= False;
3989 // Анимация возрождения:
3990 if (not gLoadGameMode
) and (not Silent
) then
3992 R_GFX_TELEPORT_FAST
,
3993 FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
3994 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32
3997 FSpectator
:= False;
4000 FSpectatePlayer
:= -1;
4003 if (gPlayer1
= nil) and (gSpectLatchPID1
= FUID
) then
4005 if (gPlayer2
= nil) and (gSpectLatchPID2
= FUID
) then
4008 if g_Game_IsNet
then
4010 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4011 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4013 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4014 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4019 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4022 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4023 else if (not NoMove
) then
4025 GameX
:= gMapInfo
.Width
div 2;
4026 GameY
:= gMapInfo
.Height
div 2;
4035 FWantsInGame
:= False;
4041 if Self
= gPlayer1
then
4043 gSpectLatchPID1
:= FUID
;
4046 else if Self
= gPlayer2
then
4048 gSpectLatchPID2
:= FUID
;
4053 if g_Game_IsNet
then
4054 MH_SEND_PlayerStats(FUID
);
4057 procedure TPlayer
.SwitchNoClip
;
4061 FGhost
:= not FGhost
;
4062 FPhysics
:= not FGhost
;
4074 procedure TPlayer
.Run(Direction
: TDirection
);
4078 if MAX_RUNVEL
> 8 then
4082 if Direction
= TDirection
.D_LEFT
then
4084 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4085 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4088 if FObj
.Vel
.X
< MAX_RUNVEL
then
4089 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4091 // Возможно, пинаем куски:
4092 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4094 b
:= Abs(FObj
.Vel
.X
);
4095 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4096 for a
:= 0 to High(gGibs
) do
4098 if gGibs
[a
].alive
and
4099 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4100 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4103 if FObj
.Vel
.X
< 0 then
4105 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // налево
4109 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // направо
4111 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4119 procedure TPlayer
.SeeDown();
4121 SetAction(A_SEEDOWN
);
4123 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4125 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4128 procedure TPlayer
.SeeUp();
4132 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4134 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4137 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4145 A_ATTACK
: Prior
:= 2;
4146 A_SEEUP
: Prior
:= 1;
4147 A_SEEDOWN
: Prior
:= 1;
4148 A_ATTACKUP
: Prior
:= 2;
4149 A_ATTACKDOWN
: Prior
:= 2;
4154 if (Prior
> FActionPrior
) or Force
then
4155 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4157 FActionPrior
:= Prior
;
4158 FActionAnim
:= Action
;
4159 FActionForce
:= Force
;
4160 FActionChanged
:= True;
4163 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4166 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4168 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4169 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4170 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4171 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4174 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4178 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4180 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4181 if g_Game_IsServer
and g_Game_IsNet
then
4182 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4186 FJustTeleported
:= True;
4190 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4192 R_GFX_TELEPORT_FAST
,
4193 FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4194 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32
4196 if g_Game_IsServer
and g_Game_IsNet
then
4197 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4198 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4202 FObj
.X
:= X
-PLAYER_RECT
.X
;
4203 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4204 FObj
.oldX
:= FObj
.X
; // don't interpolate after respawn
4205 FObj
.oldY
:= FObj
.Y
;
4206 if FAlive
and FGhost
then
4212 if not g_Game_IsNet
then
4216 SetDirection(TDirection
.D_LEFT
);
4222 SetDirection(TDirection
.D_RIGHT
);
4228 if FDirection
= TDirection
.D_RIGHT
then
4230 SetDirection(TDirection
.D_LEFT
);
4235 SetDirection(TDirection
.D_RIGHT
);
4244 R_GFX_TELEPORT_FAST
,
4245 FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4246 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32
4248 if g_Game_IsServer
and g_Game_IsNet
then
4249 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4250 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4257 function nonz(a
: Single): Single;
4265 function TPlayer
.refreshCorpse(): Boolean;
4271 if FAlive
or FSpectator
then
4273 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
4275 for i
:= 0 to High(gCorpses
) do
4276 if gCorpses
[i
] <> nil then
4277 if gCorpses
[i
].FPlayerUID
= FUID
then
4285 function TPlayer
.getCameraObj(): TObj
;
4287 if (not FAlive
) and (not FSpectator
) and
4288 (FCorpse
>= 0) and (FCorpse
< Length(gCorpses
)) and
4289 (gCorpses
[FCorpse
] <> nil) and (gCorpses
[FCorpse
].FPlayerUID
= FUID
) then
4291 gCorpses
[FCorpse
].FObj
.slopeUpLeft
:= FObj
.slopeUpLeft
;
4292 Result
:= gCorpses
[FCorpse
].FObj
;
4300 procedure TPlayer
.PreUpdate();
4302 FSlopeOld
:= FObj
.slopeUpLeft
;
4303 FIncCamOld
:= FIncCam
;
4304 FObj
.oldX
:= FObj
.X
;
4305 FObj
.oldY
:= FObj
.Y
;
4308 procedure TPlayer
.Update();
4311 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4312 blockmon
, headwater
, dospawn
: Boolean;
4317 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4318 AnyServer
:= g_Game_IsServer
;
4320 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4321 DoLerp(NetInterpLevel
+ 1)
4327 if (FClientID
>= 0) and (NetClients
[FClientID
].Peer
<> nil) then
4329 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4330 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4331 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4342 if FPunchAnim
.played
then
4345 if FAlive
and (gFly
or FJetpack
) then
4348 if FDirection
= TDirection
.D_LEFT
then
4353 if FAlive
and (not FGhost
) then
4355 if FKeys
[KEY_UP
].Pressed
then
4357 if FKeys
[KEY_DOWN
].Pressed
then
4361 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4364 i
:= g_basic
.Sign(FIncCam
);
4365 FIncCam
:= Abs(FIncCam
);
4366 DecMin(FIncCam
, 5, 0);
4367 FIncCam
:= FIncCam
*i
;
4370 if gTime
mod (GAME_TICK
*2) <> 0 then
4372 if (FObj
.Vel
.X
= 0) and FAlive
then
4374 if FKeys
[KEY_LEFT
].Pressed
then
4375 Run(TDirection
.D_LEFT
);
4376 if FKeys
[KEY_RIGHT
].Pressed
then
4377 Run(TDirection
.D_RIGHT
);
4382 g_Obj_Move(@FObj
, True, True, True);
4383 positionChanged(); // this updates spatial accelerators
4389 FActionChanged
:= False;
4393 // Let alive player do some actions
4394 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
4395 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
4396 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire()
4402 if NetServer
then MH_SEND_PlayerStats(FUID
);
4405 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
4406 if FKeys
[KEY_JUMP
].Pressed
then Jump()
4409 if AnyServer
and FJetpack
then
4413 if NetServer
then MH_SEND_PlayerStats(FUID
);
4415 FCanJetpack
:= True;
4422 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
4424 if FKeys
[k
].Pressed
then
4432 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4435 if (FTime
[T_RESPAWN
] <= gTime
) and
4436 gGameOn
and (not FAlive
) then
4438 if (g_Player_GetCount() > 1) then
4442 gExit
:= EXIT_RESTART
;
4447 // Dead spectator actions
4450 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
4451 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
4455 if (FSpectatePlayer
>= High(gPlayers
)) then
4456 FSpectatePlayer
:= -1
4460 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
4461 if gPlayers
[I
] <> nil then
4462 if gPlayers
[I
].alive
then
4463 if gPlayers
[I
].UID
<> FUID
then
4465 FSpectatePlayer
:= I
;
4470 if not SetSpect
then FSpectatePlayer
:= -1;
4481 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
4483 FYTo
:= FObj
.Y
- 32;
4484 FSpectatePlayer
:= -1;
4486 if FKeys
[KEY_DOWN
].Pressed
then
4488 FYTo
:= FObj
.Y
+ 32;
4489 FSpectatePlayer
:= -1;
4491 if FKeys
[KEY_LEFT
].Pressed
then
4493 FXTo
:= FObj
.X
- 32;
4494 FSpectatePlayer
:= -1;
4496 if FKeys
[KEY_RIGHT
].Pressed
then
4498 FXTo
:= FObj
.X
+ 32;
4499 FSpectatePlayer
:= -1;
4502 if (FXTo
< -64) then
4504 else if (FXTo
> gMapInfo
.Width
+ 32) then
4505 FXTo
:= gMapInfo
.Width
+ 32;
4506 if (FYTo
< -72) then
4508 else if (FYTo
> gMapInfo
.Height
+ 32) then
4509 FYTo
:= gMapInfo
.Height
+ 32;
4514 g_Obj_Move(@FObj
, True, True, True);
4515 positionChanged(); // this updates spatial accelerators
4522 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
4523 if gPlayers
[FSpectatePlayer
] <> nil then
4524 if gPlayers
[FSpectatePlayer
].alive
then
4526 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
4527 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
4531 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
4532 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
4533 PANEL_BLOCKMON
, True);
4534 headwater
:= HeadInLiquid(0, 0);
4536 // Сопротивление воздуха:
4537 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
4538 if FObj
.Vel
.X
<> 0 then
4539 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
4541 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
4542 DecMin(FPain
, 5, 0);
4543 DecMin(FPickup
, 1, 0);
4545 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
4547 // Обнулить действия примочек, чтобы фон пропал
4548 FMegaRulez
[MR_SUIT
] := 0;
4549 FMegaRulez
[MR_INVUL
] := 0;
4550 FMegaRulez
[MR_INVIS
] := 0;
4551 Kill(K_FALLKILL
, 0, HIT_FALL
);
4558 if FCurrWeap
= WEAPON_SAW
then
4559 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
4560 FSawSoundSelect
.IsPlaying()) then
4561 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
4564 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
4565 (not FJetSoundOff
.IsPlaying()) then
4567 FJetSoundFly
.SetPosition(0);
4568 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
4571 for b
:= WP_FIRST
to WP_LAST
do
4572 if FReloading
[b
] > 0 then
4578 if FShellTimer
> -1 then
4579 if FShellTimer
= 0 then
4581 if FShellType
= SHELL_SHELL
then
4582 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4583 GameVelX
, GameVelY
-2, SHELL_SHELL
)
4584 else if FShellType
= SHELL_DBLSHELL
then
4586 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4587 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
4588 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4589 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
4592 end else Dec(FShellTimer
);
4594 if (FBFGFireCounter
> -1) then
4595 if FBFGFireCounter
= 0 then
4599 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
4600 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
4601 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
4602 yd
:= wy
+firediry();
4603 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
4604 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
4605 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
4606 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
4607 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
4610 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
4611 FBFGFireCounter
:= -1;
4614 FBFGFireCounter
:= 0
4616 Dec(FBFGFireCounter
);
4618 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
4620 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
4622 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
4625 if (headwater
or blockmon
) then
4631 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
4634 else if (FAir
mod 31 = 0) and not blockmon
then
4636 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
4638 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
4639 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
4641 end else if FAir
< AIR_DEF
then
4644 if FFireTime
> 0 then
4646 if BodyInLiquid(0, 0) then
4651 else if FMegaRulez
[MR_SUIT
] >= gTime
then
4653 if FMegaRulez
[MR_SUIT
] = gTime
then
4660 if FFirePainTime
<= 0 then
4662 if g_Game_IsServer
then
4663 Damage(2, FFireAttacker
, 0, 0, HIT_FLAME
);
4664 FFirePainTime
:= 12 - FFireTime
div 12;
4666 FFirePainTime
:= FFirePainTime
- 1;
4667 FFireTime
:= FFireTime
- 1;
4668 if ((FFireTime
mod 33) = 0) and (FMegaRulez
[MR_INVUL
] < gTime
) then
4669 FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
);
4670 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
4671 MH_SEND_PlayerStats(FUID
);
4675 if FDamageBuffer
> 0 then
4677 if FDamageBuffer
>= 9 then
4681 if FDamageBuffer
< 30 then i
:= 9
4682 else if FDamageBuffer
< 100 then i
:= 18
4686 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
4687 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
4688 FHealth
:= FHealth
-ii
;
4691 FHealth
:= FHealth
+FArmor
;
4696 if FHealth
<= 0 then
4697 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
4698 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
4699 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
4701 if FAlive
and ((FLastHit
<> HIT_FLAME
) or (FFireTime
<= 0)) then
4703 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
4704 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
4705 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
4706 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
4713 end; // if FAlive then ...
4715 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
4717 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
4718 FModel
.AnimState
.MinLength
:= i
;
4719 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
4721 if (FModel
.AnimState
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
4722 then SetAction(A_STAND
, True);
4724 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.GetFire()) then FModel
.Update
;
4726 for b
:= Low(FKeys
) to High(FKeys
) do
4727 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
4731 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
4733 x
:= FObj
.X
+PLAYER_RECT
.X
;
4734 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
4735 w
:= PLAYER_RECT
.Width
;
4736 h
:= PLAYER_RECT
.Height
;
4740 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
4742 if (dx
<> 0) or (dy
<> 0) then
4751 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
4753 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
4754 FObj
.Y
+PLAYER_RECT
.Y
,
4761 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
4763 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
4764 FObj
.Y
+PLAYER_RECT
.Y
,
4768 Panel
.Width
, Panel
.Height
);
4771 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
4773 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
4774 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
4775 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
4776 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
4779 function g_Player_ValidName(Name
: string): Boolean;
4785 if gPlayers
= nil then Exit
;
4787 for a
:= 0 to High(gPlayers
) do
4788 if gPlayers
[a
] <> nil then
4789 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
4796 procedure TPlayer
.SetDirection(Direction
: TDirection
);
4800 d
:= FModel
.Direction
;
4802 FModel
.Direction
:= Direction
;
4803 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
4805 FDirection
:= Direction
;
4808 function TPlayer
.GetKeys(): Byte;
4812 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
4813 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
4814 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
4816 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
4817 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
4820 procedure TPlayer
.Use();
4824 if FTime
[T_USE
] > gTime
then Exit
;
4826 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
4827 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
4829 for a
:= 0 to High(gPlayers
) do
4830 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
4831 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
4832 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
4833 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
4835 gPlayers
[a
].Touch();
4836 if g_Game_IsNet
and g_Game_IsServer
then
4837 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
4840 FTime
[T_USE
] := gTime
+120;
4843 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
4846 visible
: Boolean = True;
4847 WX
, WY
, XD
, YD
: Integer;
4859 if R_BERSERK
in FRulez
then
4861 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
4862 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
4863 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
4866 locobj
.rect
.Width
:= 39;
4867 locobj
.rect
.Height
:= 52;
4868 locobj
.Vel
.X
:= (xd
-wx
) div 2;
4869 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
4870 locobj
.Accel
.X
:= xd
-wx
;
4871 locobj
.Accel
.y
:= yd
-wy
;
4873 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
4874 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
4876 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
4880 FPain
:= min(FPain
+ 25, 50);
4882 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
4887 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
4888 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
4890 FSawSoundSelect
.Stop();
4892 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
4894 else if not FSawSoundHit
.IsPlaying() then
4896 FSawSoundSelect
.Stop();
4897 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
4903 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
4904 FFireAngle
:= FAngle
;
4905 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4906 GameVelX
, GameVelY
-2, SHELL_BULLET
);
4911 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
4912 FFireAngle
:= FAngle
;
4914 FShellType
:= SHELL_SHELL
;
4919 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
4920 FFireAngle
:= FAngle
;
4922 FShellType
:= SHELL_DBLSHELL
;
4927 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
4928 FFireAngle
:= FAngle
;
4929 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4930 GameVelX
, GameVelY
-2, SHELL_BULLET
);
4933 WEAPON_ROCKETLAUNCHER
:
4935 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
4936 FFireAngle
:= FAngle
;
4941 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
4942 FFireAngle
:= FAngle
;
4947 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
4948 FFireAngle
:= FAngle
;
4951 WEAPON_SUPERPULEMET
:
4953 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
4954 FFireAngle
:= FAngle
;
4955 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4956 GameVelX
, GameVelY
-2, SHELL_SHELL
);
4959 WEAPON_FLAMETHROWER
:
4961 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
4963 FFireAngle
:= FAngle
;
4967 if not visible
then Exit
;
4969 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
4970 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
4971 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
4974 procedure TPlayer
.DoLerp(Level
: Integer = 2);
4976 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
4977 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
4980 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
4986 if FJustTeleported
or (NetInterpLevel
< 1) then
4990 if FJustTeleported
then
4992 FObj
.oldX
:= FObj
.X
;
4993 FObj
.oldY
:= FObj
.Y
;
4998 AX
:= Abs(FXTo
- FObj
.X
);
4999 AY
:= Abs(FYTo
- FObj
.Y
);
5000 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5002 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5007 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5009 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5010 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5011 PANEL_LIFTUP
, False) then Result
:= -1
5013 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5014 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5015 PANEL_LIFTDOWN
, False) then Result
:= 1
5019 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5026 if Flag
= FLAG_NONE
then
5029 if not g_Game_IsServer
then Exit
;
5031 // Принес чужой флаг на свою базу:
5032 if (Flag
= FTeam
) and
5033 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5034 (FFlag
<> FLAG_NONE
) then
5036 if FFlag
= FLAG_RED
then
5037 s
:= _lc
[I_PLAYER_FLAG_RED
]
5039 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5041 evtype
:= FLAG_STATE_SCORED
;
5043 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5044 Insert('.', ts
, Length(ts
) + 1 - 3);
5045 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5047 g_Map_ResetFlag(FFlag
);
5048 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5050 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5051 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5052 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5057 if not sound_cap_flag
[a
].IsPlaying() then
5058 sound_cap_flag
[a
].Play();
5060 gTeamStat
[FTeam
].Score
+= 1;
5063 if g_Game_IsNet
then
5065 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5069 gFlags
[FFlag
].CaptureTime
:= 0;
5074 // Подобрал свой флаг - вернул его на базу:
5075 if (Flag
= FTeam
) and
5076 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5078 if Flag
= FLAG_RED
then
5079 s
:= _lc
[I_PLAYER_FLAG_RED
]
5081 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5083 evtype
:= FLAG_STATE_RETURNED
;
5084 gFlags
[Flag
].CaptureTime
:= 0;
5086 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5088 g_Map_ResetFlag(Flag
);
5089 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5091 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5092 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5093 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5098 if not sound_ret_flag
[a
].IsPlaying() then
5099 sound_ret_flag
[a
].Play();
5102 if g_Game_IsNet
then
5104 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5110 // Подобрал чужой флаг:
5111 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5115 if Flag
= FLAG_RED
then
5116 s
:= _lc
[I_PLAYER_FLAG_RED
]
5118 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5120 evtype
:= FLAG_STATE_CAPTURED
;
5122 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5124 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5126 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5128 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5129 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5130 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5135 if not sound_get_flag
[a
].IsPlaying() then
5136 sound_get_flag
[a
].Play();
5139 if g_Game_IsNet
then
5141 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5147 procedure TPlayer
.SetFlag(Flag
: Byte);
5150 if FModel
<> nil then
5151 FModel
.SetFlag(FFlag
);
5154 function TPlayer
.TryDropFlag(): Boolean;
5156 if LongBool(gGameSettings
.Options
and GAME_OPTION_ALLOWDROPFLAG
) then
5157 Result
:= DropFlag(False, LongBool(gGameSettings
.Options
and GAME_OPTION_THROWFLAG
))
5162 function TPlayer
.DropFlag(Silent
: Boolean = True; DoThrow
: Boolean = False): Boolean;
5169 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5171 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5172 with gFlags
[FFlag
] do
5176 Direction
:= FDirection
;
5177 State
:= FLAG_STATE_DROPPED
;
5181 xv
:= FObj
.Vel
.X
+ IfThen(Direction
= TDirection
.D_RIGHT
, 10, -10);
5182 yv
:= FObj
.Vel
.Y
- 2;
5186 xv
:= (FObj
.Vel
.X
div 2);
5187 yv
:= (FObj
.Vel
.Y
div 2) - 2;
5189 g_Obj_Push(@Obj
, xv
, yv
);
5191 positionChanged(); // this updates spatial accelerators
5193 if FFlag
= FLAG_RED
then
5194 s
:= _lc
[I_PLAYER_FLAG_RED
]
5196 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5198 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5199 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5201 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5202 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5203 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5208 if (not Silent
) and (not sound_lost_flag
[a
].IsPlaying()) then
5209 sound_lost_flag
[a
].Play();
5211 if g_Game_IsNet
then
5212 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5218 procedure TPlayer
.GetSecret();
5220 if (self
= gPlayer1
) or (self
= gPlayer2
) then
5222 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [FName
]), True);
5223 g_Sound_PlayEx('SOUND_GAME_SECRET');
5228 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5230 Assert(Key
<= High(FKeys
));
5232 FKeys
[Key
].Pressed
:= True;
5233 FKeys
[Key
].Time
:= Time
;
5236 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5238 Result
:= FKeys
[K
].Pressed
;
5241 procedure TPlayer
.ReleaseKeys();
5245 for a
:= Low(FKeys
) to High(FKeys
) do
5247 FKeys
[a
].Pressed
:= False;
5252 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5256 function TPlayer
.firediry(): Integer;
5258 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5259 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5263 procedure TPlayer
.RememberState();
5266 SavedState
: TPlayerSavedState
;
5268 SavedState
.Health
:= FHealth
;
5269 SavedState
.Armor
:= FArmor
;
5270 SavedState
.Air
:= FAir
;
5271 SavedState
.JetFuel
:= FJetFuel
;
5272 SavedState
.CurrWeap
:= FCurrWeap
;
5273 SavedState
.NextWeap
:= FNextWeap
;
5274 SavedState
.NextWeapDelay
:= FNextWeapDelay
;
5275 for i
:= Low(FWeapon
) to High(FWeapon
) do
5276 SavedState
.Weapon
[i
] := FWeapon
[i
];
5277 for i
:= Low(FAmmo
) to High(FAmmo
) do
5278 SavedState
.Ammo
[i
] := FAmmo
[i
];
5279 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
5280 SavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5281 SavedState
.Rulez
:= FRulez
- [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5283 FSavedStateNum
:= -1;
5284 for i
:= Low(SavedStates
) to High(SavedStates
) do
5285 if not SavedStates
[i
].Used
then
5287 FSavedStateNum
:= i
;
5290 if FSavedStateNum
< 0 then
5292 SetLength(SavedStates
, Length(SavedStates
) + 1);
5293 FSavedStateNum
:= High(SavedStates
);
5296 SavedState
.Used
:= True;
5297 SavedStates
[FSavedStateNum
] := SavedState
;
5300 procedure TPlayer
.RecallState();
5303 SavedState
: TPlayerSavedState
;
5305 if(FSavedStateNum
< 0) or (FSavedStateNum
> High(SavedStates
)) then
5308 SavedState
:= SavedStates
[FSavedStateNum
];
5309 SavedStates
[FSavedStateNum
].Used
:= False;
5310 FSavedStateNum
:= -1;
5312 FHealth
:= SavedState
.Health
;
5313 FArmor
:= SavedState
.Armor
;
5314 FAir
:= SavedState
.Air
;
5315 FJetFuel
:= SavedState
.JetFuel
;
5316 FCurrWeap
:= SavedState
.CurrWeap
;
5317 FNextWeap
:= SavedState
.NextWeap
;
5318 FNextWeapDelay
:= SavedState
.NextWeapDelay
;
5319 for i
:= Low(FWeapon
) to High(FWeapon
) do
5320 FWeapon
[i
] := SavedState
.Weapon
[i
];
5321 for i
:= Low(FAmmo
) to High(FAmmo
) do
5322 FAmmo
[i
] := SavedState
.Ammo
[i
];
5323 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
5324 FMaxAmmo
[i
] := SavedState
.MaxAmmo
[i
];
5325 FRulez
:= SavedState
.Rulez
;
5327 if gGameSettings
.GameType
= GT_SERVER
then
5328 MH_SEND_PlayerStats(FUID
);
5331 procedure TPlayer
.SaveState (st
: TStream
);
5337 utils
.writeSign(st
, 'PLYR');
5338 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
5340 utils
.writeBool(st
, FIamBot
);
5342 utils
.writeInt(st
, Word(FUID
));
5344 utils
.writeStr(st
, FName
);
5346 utils
.writeInt(st
, Byte(FTeam
));
5348 utils
.writeBool(st
, FAlive
);
5349 // Израсходовал ли все жизни
5350 utils
.writeBool(st
, FNoRespawn
);
5352 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
5353 utils
.writeInt(st
, Byte(b
));
5355 utils
.writeInt(st
, LongInt(FHealth
));
5356 // Коэффициент инвалидности
5357 utils
.writeInt(st
, LongInt(FHandicap
));
5359 utils
.writeInt(st
, Byte(FLives
));
5361 utils
.writeInt(st
, LongInt(FArmor
));
5363 utils
.writeInt(st
, LongInt(FAir
));
5365 utils
.writeInt(st
, LongInt(FJetFuel
));
5367 utils
.writeInt(st
, LongInt(FPain
));
5369 utils
.writeInt(st
, LongInt(FKills
));
5371 utils
.writeInt(st
, LongInt(FMonsterKills
));
5373 utils
.writeInt(st
, LongInt(FFrags
));
5375 utils
.writeInt(st
, Byte(FFragCombo
));
5376 // Время последнего фрага
5377 utils
.writeInt(st
, LongWord(FLastFrag
));
5379 utils
.writeInt(st
, LongInt(FDeath
));
5381 utils
.writeInt(st
, Byte(FFlag
));
5383 utils
.writeInt(st
, LongInt(FSecrets
));
5385 utils
.writeInt(st
, Byte(FCurrWeap
));
5387 utils
.writeInt(st
, Word(FNextWeap
));
5389 utils
.writeInt(st
, Byte(FNextWeapDelay
));
5390 // Время зарядки BFG
5391 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
5393 utils
.writeInt(st
, LongInt(FDamageBuffer
));
5394 // Последний ударивший
5395 utils
.writeInt(st
, Word(FLastSpawnerUID
));
5396 // Тип последнего полученного урона
5397 utils
.writeInt(st
, Byte(FLastHit
));
5399 Obj_SaveState(st
, @FObj
);
5400 // Текущее количество патронов
5401 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
5402 // Максимальное количество патронов
5403 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
5405 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
5406 // Время перезарядки оружия
5407 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
5409 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
5410 // Наличие красного ключа
5411 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
5412 // Наличие зеленого ключа
5413 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
5414 // Наличие синего ключа
5415 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
5417 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
5418 // Время действия специальных предметов
5419 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
5420 // Время до повторного респауна, смены оружия, исользования, захвата флага
5421 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
5423 utils
.writeStr(st
, FModel
.GetName());
5425 utils
.writeInt(st
, Byte(FColor
.R
));
5426 utils
.writeInt(st
, Byte(FColor
.G
));
5427 utils
.writeInt(st
, Byte(FColor
.B
));
5431 procedure TPlayer
.LoadState (st
: TStream
);
5440 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
5441 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
5443 FIamBot
:= utils
.readBool(st
);
5445 FUID
:= utils
.readWord(st
);
5447 str
:= utils
.readStr(st
);
5448 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
5450 FTeam
:= utils
.readByte(st
);
5452 FAlive
:= utils
.readBool(st
);
5453 // Израсходовал ли все жизни
5454 FNoRespawn
:= utils
.readBool(st
);
5456 b
:= utils
.readByte(st
);
5457 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
5459 FHealth
:= utils
.readLongInt(st
);
5460 // Коэффициент инвалидности
5461 FHandicap
:= utils
.readLongInt(st
);
5463 FLives
:= utils
.readByte(st
);
5465 FArmor
:= utils
.readLongInt(st
);
5467 FAir
:= utils
.readLongInt(st
);
5469 FJetFuel
:= utils
.readLongInt(st
);
5471 FPain
:= utils
.readLongInt(st
);
5473 FKills
:= utils
.readLongInt(st
);
5475 FMonsterKills
:= utils
.readLongInt(st
);
5477 FFrags
:= utils
.readLongInt(st
);
5479 FFragCombo
:= utils
.readByte(st
);
5480 // Время последнего фрага
5481 FLastFrag
:= utils
.readLongWord(st
);
5483 FDeath
:= utils
.readLongInt(st
);
5485 FFlag
:= utils
.readByte(st
);
5487 FSecrets
:= utils
.readLongInt(st
);
5489 FCurrWeap
:= utils
.readByte(st
);
5491 FNextWeap
:= utils
.readWord(st
);
5493 FNextWeapDelay
:= utils
.readByte(st
);
5494 // Время зарядки BFG
5495 FBFGFireCounter
:= utils
.readSmallInt(st
);
5497 FDamageBuffer
:= utils
.readLongInt(st
);
5498 // Последний ударивший
5499 FLastSpawnerUID
:= utils
.readWord(st
);
5500 // Тип последнего полученного урона
5501 FLastHit
:= utils
.readByte(st
);
5503 Obj_LoadState(@FObj
, st
);
5504 // Текущее количество патронов
5505 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
5506 // Максимальное количество патронов
5507 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
5509 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
5510 // Время перезарядки оружия
5511 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
5513 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
5514 // Наличие красного ключа
5515 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
5516 // Наличие зеленого ключа
5517 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
5518 // Наличие синего ключа
5519 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
5521 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
5522 // Время действия специальных предметов
5523 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
5524 // Время до повторного респауна, смены оружия, исользования, захвата флага
5525 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
5527 str
:= utils
.readStr(st
);
5529 FColor
.R
:= utils
.readByte(st
);
5530 FColor
.G
:= utils
.readByte(st
);
5531 FColor
.B
:= utils
.readByte(st
);
5532 if (self
= gPlayer1
) then
5534 str
:= gPlayer1Settings
.Model
;
5535 FColor
:= gPlayer1Settings
.Color
;
5537 else if (self
= gPlayer2
) then
5539 str
:= gPlayer2Settings
.Model
;
5540 FColor
:= gPlayer2Settings
.Color
;
5542 // Обновляем модель игрока
5544 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
5545 FModel
.Color
:= TEAMCOLOR
[FTeam
]
5547 FModel
.Color
:= FColor
;
5551 procedure TPlayer
.AllRulez(Health
: Boolean);
5557 FHealth
:= PLAYER_HP_LIMIT
;
5558 FArmor
:= PLAYER_AP_LIMIT
;
5562 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
5563 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
5564 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5567 procedure TPlayer
.RestoreHealthArmor();
5569 FHealth
:= PLAYER_HP_LIMIT
;
5570 FArmor
:= PLAYER_AP_LIMIT
;
5573 procedure TPlayer
.FragCombo();
5577 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
5579 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
5581 if FFragCombo
< 5 then
5583 Param
:= FUID
or (FFragCombo
shl 16);
5584 if (FComboEvnt
>= Low(gDelayedEvents
)) and
5585 (FComboEvnt
<= High(gDelayedEvents
)) and
5586 gDelayedEvents
[FComboEvnt
].Pending
and
5587 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
5588 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
5590 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
5591 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
5594 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
5602 procedure TPlayer
.GiveItem(ItemType
: Byte);
5606 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
5608 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
5612 if FAir
< AIR_MAX
then
5619 if not (R_BERSERK
in FRulez
) then
5621 Include(FRulez
, R_BERSERK
);
5622 if FBFGFireCounter
< 1 then
5624 FCurrWeap
:= WEAPON_KASTET
;
5626 FModel
.SetWeapon(WEAPON_KASTET
);
5630 FBerserk
:= gTime
+30000;
5632 if FHealth
< PLAYER_HP_SOFT
then
5634 FHealth
:= PLAYER_HP_SOFT
;
5635 FBerserk
:= gTime
+30000;
5640 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
5642 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
5647 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
5649 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
5653 if FJetFuel
< JET_MAX
then
5655 FJetFuel
:= JET_MAX
;
5658 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
5659 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
5661 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
5662 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5664 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
5666 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
5668 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
5669 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5672 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
5673 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
5674 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
5675 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
5676 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
5677 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
5678 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
5679 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
5680 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
5682 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5683 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
5684 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5685 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
5686 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5687 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
5688 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5689 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
5690 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
5693 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
5694 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
5695 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
5696 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
5697 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
5699 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
5700 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
5701 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
5702 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
5703 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
5705 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5706 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5707 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5708 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5710 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
5713 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
5714 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
5715 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
5717 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
5718 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
5723 if g_Game_IsNet
and g_Game_IsServer
then
5724 MH_SEND_PlayerStats(FUID
);
5727 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
5730 if (Random(5) = 1) and (Times
= 1) then
5733 if BodyInLiquid(0, 0) then
5735 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
5736 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
5738 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5739 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5743 for i
:= 1 to Times
do
5747 Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(R_GFX_SMOKE_WIDTH
div 2),
5748 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2)
5753 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
5756 if (Random(10) = 1) and (Times
= 1) then
5759 for i
:= 1 to Times
do
5763 Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(R_GFX_FLAME_WIDTH
div 2),
5764 Obj
.Y
+8+Random(8+Times
*2)
5769 procedure TPlayer
.PauseSounds(Enable
: Boolean);
5771 FSawSound
.Pause(Enable
);
5772 FSawSoundIdle
.Pause(Enable
);
5773 FSawSoundHit
.Pause(Enable
);
5774 FSawSoundSelect
.Pause(Enable
);
5775 FFlameSoundOn
.Pause(Enable
);
5776 FFlameSoundOff
.Pause(Enable
);
5777 FFlameSoundWork
.Pause(Enable
);
5778 FJetSoundFly
.Pause(Enable
);
5779 FJetSoundOn
.Pause(Enable
);
5780 FJetSoundOff
.Pause(Enable
);
5785 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
5790 FObj
.Rect
:= PLAYER_CORPSERECT
;
5792 FModel
:= g_PlayerModel_Get(ModelName
);
5796 FState
:= CORPSE_STATE_MESS
;
5797 FModel
.ChangeAnimation(A_DIE2
);
5801 FState
:= CORPSE_STATE_NORMAL
;
5802 FModel
.ChangeAnimation(A_DIE1
);
5806 destructor TCorpse
.Destroy();
5812 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
5814 procedure TCorpse
.positionChanged (); inline; begin end;
5816 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
5818 if (dx
<> 0) or (dy
<> 0) then
5827 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5829 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
5830 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
5831 w
:= PLAYER_CORPSERECT
.Width
;
5832 h
:= PLAYER_CORPSERECT
.Height
;
5836 procedure TCorpse
.Damage(Value
: Word; SpawnerUID
: Word; vx
, vy
: Integer);
5837 var Blood
: TModelBlood
;
5839 if FState
= CORPSE_STATE_REMOVEME
then
5842 FDamage
:= FDamage
+ Value
;
5844 if FDamage
> 150 then
5846 if FModel
<> nil then
5848 FState
:= CORPSE_STATE_REMOVEME
;
5850 g_Player_CreateGibs(
5851 FObj
.X
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
div 2),
5852 FObj
.Y
+ FObj
.Rect
.Y
+ (FObj
.Rect
.Height
div 2),
5857 // Звук мяса от трупа:
5858 FModel
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
5861 if (gBodyKillEvent
<> -1) and gDelayedEvents
[gBodyKillEvent
].Pending
then
5862 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
5863 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, SpawnerUID
);
5871 Blood
:= FModel
.GetBlood();
5872 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
5873 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
5874 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
5875 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
5876 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
5877 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
5881 procedure TCorpse
.Update();
5885 if FState
= CORPSE_STATE_REMOVEME
then
5888 FObj
.oldX
:= FObj
.X
;
5889 FObj
.oldY
:= FObj
.Y
;
5891 if gTime
mod (GAME_TICK
*2) <> 0 then
5893 g_Obj_Move(@FObj
, True, True, True);
5894 positionChanged(); // this updates spatial accelerators
5898 // Сопротивление воздуха для трупа:
5899 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5901 st
:= g_Obj_Move(@FObj
, True, True, True);
5902 positionChanged(); // this updates spatial accelerators
5904 if WordBool(st
and MOVE_FALLOUT
) then
5906 FState
:= CORPSE_STATE_REMOVEME
;
5910 if FModel
<> nil then
5915 procedure TCorpse
.SaveState (st
: TStream
);
5921 utils
.writeSign(st
, 'CORP');
5922 utils
.writeInt(st
, Byte(0));
5924 utils
.writeInt(st
, Byte(FState
));
5926 utils
.writeInt(st
, Byte(FDamage
));
5928 utils
.writeInt(st
, Byte(FModel
.Color
.R
));
5929 utils
.writeInt(st
, Byte(FModel
.Color
.G
));
5930 utils
.writeInt(st
, Byte(FModel
.Color
.B
));
5932 Obj_SaveState(st
, @FObj
);
5933 utils
.writeInt(st
, Word(FPlayerUID
));
5935 anim
:= (FModel
<> nil);
5936 utils
.writeBool(st
, anim
);
5937 if anim
then FModel
.AnimState
.SaveState(st
);
5938 // animation for mask (same as animation, compat with older saves)
5939 anim
:= (FModel
<> nil);
5940 utils
.writeBool(st
, anim
);
5941 if anim
then FModel
.AnimState
.SaveState(st
);
5945 procedure TCorpse
.LoadState (st
: TStream
);
5946 var anim
: Boolean; r
, g
, b
: Byte; stub
: TAnimationState
;
5951 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
5952 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
5954 FState
:= utils
.readByte(st
);
5956 FDamage
:= utils
.readByte(st
);
5958 r
:= utils
.readByte(st
);
5959 g
:= utils
.readByte(st
);
5960 b
:= utils
.readByte(st
);
5961 FModel
.SetColor(r
, g
, b
);
5963 Obj_LoadState(@FObj
, st
);
5964 FPlayerUID
:= utils
.readWord(st
);
5966 stub
:= TAnimationState
.Create(False, 0, 0);
5967 anim
:= utils
.readBool(st
);
5971 FModel
.AnimState
.CurrentFrame
:= Min(stub
.CurrentFrame
, FModel
.AnimState
.Length
);
5978 // animation for mask (same as animation, compat with older saves)
5979 anim
:= utils
.readBool(st
);
5980 if anim
then stub
.LoadState(st
);
5986 constructor TBot
.Create();
5993 FSpectator
:= False;
6000 for a
:= WP_FIRST
to WP_LAST
do
6002 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6003 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6004 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6008 destructor TBot
.Destroy();
6011 inherited Destroy();
6014 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6016 inherited Respawn(Silent
, Force
);
6019 FSelectedWeapon
:= FCurrWeap
;
6024 procedure TBot
.UpdateCombat();
6037 TTargetRecord
= array of TTarget
;
6039 function Compare(a
, b
: TTarget
): Integer;
6041 if a
.Line
and not b
.Line
then // A на линии огня
6044 if not a
.Line
and b
.Line
then // B на линии огня
6046 else // И A, и B на линии или не на линии огня
6047 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6049 if a
.Dist
> b
.Dist
then // B ближе
6051 else // A ближе или равноудаленно с B
6054 else // Странно -> A
6059 a
, x1
, y1
, x2
, y2
: Integer;
6060 targets
: TTargetRecord
;
6062 Target
, BestTarget
: TTarget
;
6063 firew
, fireh
: Integer;
6067 vsPlayer
, vsMonster
, ok
: Boolean;
6070 function monsUpdate (mon
: TMonster
): Boolean;
6072 result
:= false; // don't stop
6073 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6075 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6077 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6078 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6080 // Если монстр на экране и не прикрыт стеной
6081 if g_TraceVector(x1
, y1
, x2
, y2
) then
6083 // Добавляем к списку возможных целей
6084 SetLength(targets
, Length(targets
)+1);
6085 with targets
[High(targets
)] do
6092 Rect
:= mon
.Obj
.Rect
;
6093 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6094 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6095 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6104 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6105 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6107 // Если текущее оружие не то, что нужно, то меняем:
6108 if FCurrWeap
<> FSelectedWeapon
then
6111 // Если нужно стрелять и нужное оружие, то нажать "Стрелять":
6112 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6114 RemoveAIFlag('NEEDFIRE');
6117 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6118 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6119 else PressKey(KEY_FIRE
);
6123 // Координаты ствола:
6124 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6125 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6127 Target
.UID
:= FTargetUID
;
6130 if Target
.UID
<> 0 then
6131 begin // Цель есть - настраиваем
6132 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6135 tpla
:= g_Player_Get(Target
.UID
);
6139 if (@FObj
) <> nil then
6146 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6147 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6148 Target
.Rect
:= PLAYER_RECT
;
6149 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6150 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6151 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6152 Target
.IsPlayer
:= True;
6156 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6159 mon
:= g_Monsters_ByUID(Target
.UID
);
6162 Target
.X
:= mon
.Obj
.X
;
6163 Target
.Y
:= mon
.Obj
.Y
;
6165 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6166 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6167 Target
.Rect
:= mon
.Obj
.Rect
;
6168 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6169 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6170 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6171 Target
.IsPlayer
:= False;
6178 begin // Цели нет - обнуляем
6183 Target
.Visible
:= False;
6184 Target
.Line
:= False;
6185 Target
.IsPlayer
:= False;
6190 // Если цель не видима или не на линии огня, то ищем все возможные цели:
6191 if (not Target
.Line
) or (not Target
.Visible
) then
6195 for a
:= 0 to High(gPlayers
) do
6196 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6197 (gPlayers
[a
].FUID
<> FUID
) and
6198 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6199 (not gPlayers
[a
].NoTarget
) and
6200 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6202 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6203 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6206 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6207 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6209 // Если игрок на экране и не прикрыт стеной:
6210 if g_TraceVector(x1
, y1
, x2
, y2
) then
6212 // Добавляем к списку возможных целей:
6213 SetLength(targets
, Length(targets
)+1);
6214 with targets
[High(targets
)] do
6216 UID
:= gPlayers
[a
].FUID
;
6217 X
:= gPlayers
[a
].FObj
.X
;
6218 Y
:= gPlayers
[a
].FObj
.Y
;
6221 Rect
:= PLAYER_RECT
;
6222 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6223 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6224 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6232 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6235 // Если есть возможные цели:
6236 // (Выбираем лучшую, меняем оружие и бежим к ней/от нее)
6237 if targets
<> nil then
6239 // Выбираем наилучшую цель:
6240 BestTarget
:= targets
[0];
6241 if Length(targets
) > 1 then
6242 for a
:= 1 to High(targets
) do
6243 if Compare(BestTarget
, targets
[a
]) = 1 then
6244 BestTarget
:= targets
[a
];
6246 // Если лучшая цель "виднее" текущей, то текущая := лучшая:
6247 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6248 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6250 Target
:= BestTarget
;
6252 if (Healthy() = 3) or ((Healthy() = 2)) then
6253 begin // Если здоровы - догоняем
6254 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6255 SetAIFlag('GORIGHT', '1');
6256 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6257 SetAIFlag('GOLEFT', '1');
6260 begin // Если побиты - убегаем
6261 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6262 SetAIFlag('GORIGHT', '1');
6263 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6264 SetAIFlag('GOLEFT', '1');
6267 // Выбираем оружие на основе расстояния и приоритетов:
6268 SelectWeapon(Abs(x1
-Target
.cX
));
6273 // (Догоняем/убегаем, стреляем по направлению к цели)
6274 // (Если цель далеко, то хватит следить за ней)
6275 if Target
.UID
<> 0 then
6277 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6278 Target
.Y
+ Target
.Rect
.Y
) then
6279 begin // Цель сбежала с "экрана"
6280 if (Healthy() = 3) or ((Healthy() = 2)) then
6281 begin // Если здоровы - догоняем
6282 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6283 SetAIFlag('GORIGHT', '1');
6284 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6285 SetAIFlag('GOLEFT', '1');
6288 begin // Если побиты - забываем о цели и убегаем
6290 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6291 SetAIFlag('GORIGHT', '1');
6292 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6293 SetAIFlag('GOLEFT', '1');
6297 begin // Цель пока на "экране"
6298 // Если цель не загорожена стеной, то отмечаем, когда ее видели:
6299 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6300 FLastVisible
:= gTime
;
6301 // Если разница высот не велика, то догоняем:
6302 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6304 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6305 SetAIFlag('GORIGHT', '1');
6306 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6307 SetAIFlag('GOLEFT', '1');
6311 // Выбираем угол вверх:
6312 if FDirection
= TDirection
.D_LEFT
then
6313 angle
:= ANGLE_LEFTUP
6315 angle
:= ANGLE_RIGHTUP
;
6317 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6318 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6320 // Если при угле вверх можно попасть в приблизительное положение цели:
6321 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6322 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6323 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6324 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6325 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6326 begin // то нужно стрелять вверх
6327 SetAIFlag('NEEDFIRE', '1');
6328 SetAIFlag('NEEDSEEUP', '1');
6331 // Выбираем угол вниз:
6332 if FDirection
= TDirection
.D_LEFT
then
6333 angle
:= ANGLE_LEFTDOWN
6335 angle
:= ANGLE_RIGHTDOWN
;
6337 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6338 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6340 // Если при угле вниз можно попасть в приблизительное положение цели:
6341 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6342 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6343 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6344 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6345 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6346 begin // то нужно стрелять вниз
6347 SetAIFlag('NEEDFIRE', '1');
6348 SetAIFlag('NEEDSEEDOWN', '1');
6351 // Если цель видно и она на такой же высоте:
6352 if Target
.Visible
and
6353 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6354 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6356 // Если идем в сторону цели, то надо стрелять:
6357 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
6358 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6359 begin // то нужно стрелять вперед
6360 SetAIFlag('NEEDFIRE', '1');
6361 SetAIFlag('NEEDSEEDOWN', '');
6362 SetAIFlag('NEEDSEEUP', '');
6364 // Если цель в пределах "экрана" и сложность позволяет прыжки сближения:
6365 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6366 if GetRnd(FDifficult
.CloseJump
) then
6367 begin // то если повезет - прыгаем (особенно, если близко)
6368 if Abs(FObj
.X
-Target
.X
) < 128 then
6372 if Random(a
) = 0 then
6373 SetAIFlag('NEEDJUMP', '1');
6377 // Если цель все еще есть:
6378 if Target
.UID
<> 0 then
6379 if gTime
-FLastVisible
> 2000 then // Если видели давно
6380 Target
.UID
:= 0 // то забыть цель
6381 else // Если видели недавно
6382 begin // но цель убили
6383 if Target
.IsPlayer
then
6384 begin // Цель - игрок
6385 pla
:= g_Player_Get(Target
.UID
);
6386 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
6387 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6388 Target
.UID
:= 0; // то забыть цель
6391 begin // Цель - монстр
6392 mon
:= g_Monsters_ByUID(Target
.UID
);
6393 if (mon
= nil) or (not mon
.alive
) then
6394 Target
.UID
:= 0; // то забыть цель
6397 end; // if Target.UID <> 0
6399 FTargetUID
:= Target
.UID
;
6401 // Если возможных целей нет:
6402 // (Атака чего-нибудь слева или справа)
6403 if targets
= nil then
6404 if GetAIFlag('ATTACKLEFT') <> '' then
6405 begin // Если нужно атаковать налево
6406 RemoveAIFlag('ATTACKLEFT');
6408 SetAIFlag('NEEDJUMP', '1');
6410 if RunDirection() = TDirection
.D_RIGHT
then
6411 begin // Идем не в ту сторону
6412 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6413 begin // Если здоровы, то, возможно, стреляем бежим влево и стреляем
6414 SetAIFlag('NEEDFIRE', '1');
6415 SetAIFlag('GOLEFT', '1');
6419 begin // Идем в нужную сторону
6420 if GetRnd(FDifficult
.InvisFire
) then // Возможно, стреляем вслепую
6421 SetAIFlag('NEEDFIRE', '1');
6422 if Healthy() <= 1 then // Побиты - убегаем
6423 SetAIFlag('GORIGHT', '1');
6427 if GetAIFlag('ATTACKRIGHT') <> '' then
6428 begin // Если нужно атаковать направо
6429 RemoveAIFlag('ATTACKRIGHT');
6431 SetAIFlag('NEEDJUMP', '1');
6433 if RunDirection() = TDirection
.D_LEFT
then
6434 begin // Идем не в ту сторону
6435 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6436 begin // Если здоровы, то, возможно, бежим вправо и стреляем
6437 SetAIFlag('NEEDFIRE', '1');
6438 SetAIFlag('GORIGHT', '1');
6443 if GetRnd(FDifficult
.InvisFire
) then // Возможно, стреляем вслепую
6444 SetAIFlag('NEEDFIRE', '1');
6445 if Healthy() <= 1 then // Побиты - убегаем
6446 SetAIFlag('GOLEFT', '1');
6450 //HACK! (does it belongs there?)
6451 RealizeCurrentWeapon();
6453 // Если есть возможные цели:
6454 // (Стреляем по направлению к целям)
6455 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6456 for a
:= 0 to High(targets
) do
6458 // Если можем стрелять по диагонали:
6459 if GetRnd(FDifficult
.DiagFire
) then
6461 // Ищем цель сверху и стреляем, если есть:
6462 if FDirection
= TDirection
.D_LEFT
then
6463 angle
:= ANGLE_LEFTUP
6465 angle
:= ANGLE_RIGHTUP
;
6467 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6468 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6470 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6471 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6472 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6473 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6474 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6476 SetAIFlag('NEEDFIRE', '1');
6477 SetAIFlag('NEEDSEEUP', '1');
6480 // Ищем цель снизу и стреляем, если есть:
6481 if FDirection
= TDirection
.D_LEFT
then
6482 angle
:= ANGLE_LEFTDOWN
6484 angle
:= ANGLE_RIGHTDOWN
;
6486 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6487 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6489 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6490 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6491 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6492 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6493 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6495 SetAIFlag('NEEDFIRE', '1');
6496 SetAIFlag('NEEDSEEDOWN', '1');
6500 // Если цель "перед носом", то стреляем:
6501 if targets
[a
].Line
and targets
[a
].Visible
and
6502 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
6503 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
6505 SetAIFlag('NEEDFIRE', '1');
6510 // Если летит пуля, то, возможно, подпрыгиваем:
6511 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
6512 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
6513 40+GetInterval(FDifficult
.Cover
, 40)) then
6514 SetAIFlag('NEEDJUMP', '1');
6516 // Если кончились паторны, то нужно сменить оружие:
6517 ammo
:= GetAmmoByWeapon(FCurrWeap
);
6518 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
6519 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
6521 SetAIFlag('SELECTWEAPON', '1');
6523 // Если нужно сменить оружие, то выбираем нужное:
6524 if GetAIFlag('SELECTWEAPON') = '1' then
6527 RemoveAIFlag('SELECTWEAPON');
6531 procedure TBot
.Update();
6544 // Проверяем, отключён ли AI ботов
6545 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
6547 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
6549 if g_debug_BotAIOff
= 3 then
6559 RealizeCurrentWeapon();
6566 procedure TBot
.ReleaseKey(Key
: Byte);
6575 function TBot
.KeyPressed(Key
: Word): Boolean;
6577 Result
:= FKeys
[Key
].Pressed
;
6580 function TBot
.GetAIFlag(aName
: String20
): String20
;
6586 aName
:= LowerCase(aName
);
6588 if FAIFlags
<> nil then
6589 for a
:= 0 to High(FAIFlags
) do
6590 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6592 Result
:= FAIFlags
[a
].Value
;
6597 procedure TBot
.RemoveAIFlag(aName
: String20
);
6601 if FAIFlags
= nil then Exit
;
6603 aName
:= LowerCase(aName
);
6605 for a
:= 0 to High(FAIFlags
) do
6606 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6608 if a
<> High(FAIFlags
) then
6609 for b
:= a
to High(FAIFlags
)-1 do
6610 FAIFlags
[b
] := FAIFlags
[b
+1];
6612 SetLength(FAIFlags
, Length(FAIFlags
)-1);
6617 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
6625 aName
:= LowerCase(aName
);
6627 if FAIFlags
<> nil then
6628 for a
:= 0 to High(FAIFlags
) do
6629 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6635 if ok
then FAIFlags
[a
].Value
:= fValue
6638 SetLength(FAIFlags
, Length(FAIFlags
)+1);
6639 with FAIFlags
[High(FAIFlags
)] do
6647 procedure TBot
.UpdateMove
;
6649 procedure GoLeft(Time
: Word = 1);
6651 ReleaseKey(KEY_LEFT
);
6652 ReleaseKey(KEY_RIGHT
);
6653 PressKey(KEY_LEFT
, Time
);
6654 SetDirection(TDirection
.D_LEFT
);
6657 procedure GoRight(Time
: Word = 1);
6659 ReleaseKey(KEY_LEFT
);
6660 ReleaseKey(KEY_RIGHT
);
6661 PressKey(KEY_RIGHT
, Time
);
6662 SetDirection(TDirection
.D_RIGHT
);
6665 function Rnd(a
: Word): Boolean;
6667 Result
:= Random(a
) = 0;
6670 procedure Turn(Time
: Word = 1200);
6672 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
6677 ReleaseKey(KEY_LEFT
);
6678 ReleaseKey(KEY_RIGHT
);
6681 function CanRunLeft(): Boolean;
6683 Result
:= not CollideLevel(-1, 0);
6686 function CanRunRight(): Boolean;
6688 Result
:= not CollideLevel(1, 0);
6691 function CanRun(): Boolean;
6693 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
6696 procedure Jump(Time
: Word = 30);
6698 PressKey(KEY_JUMP
, Time
);
6701 function NearHole(): Boolean;
6705 { TODO 5 : Лестницы }
6706 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
6707 for x
:= 1 to PLAYER_RECT
.Width
do
6708 if (not StayOnStep(x
*sx
, 0)) and
6709 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6710 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6719 function BorderHole(): Boolean;
6723 { TODO 5 : Лестницы }
6724 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
6725 for x
:= 1 to PLAYER_RECT
.Width
do
6726 if (not StayOnStep(x
*sx
, 0)) and
6727 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6728 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6730 for xx
:= x
to x
+32 do
6731 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
6741 function NearDeepHole(): Boolean;
6747 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
6750 for x
:= 1 to PLAYER_RECT
.Width
do
6751 if (not StayOnStep(x
*sx
, 0)) and
6752 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6753 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6755 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6757 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
6762 end else Result
:= False;
6765 function OverDeepHole(): Boolean;
6772 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6774 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
6781 function OnGround(): Boolean;
6783 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
6786 function OnLadder(): Boolean;
6788 Result
:= FullInStep(0, 0);
6791 function BelowLadder(): Boolean;
6793 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
6794 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
6795 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
6796 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
6799 function BelowLiftUp(): Boolean;
6801 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
6802 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
6803 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
6804 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
6807 function OnTopLift(): Boolean;
6809 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
6812 function CanJumpOver(): Boolean;
6816 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
6820 if not CollideLevel(sx
, 0) then Exit
;
6822 for y
:= 1 to BOT_MAXJUMP
do
6823 if CollideLevel(0, -y
) then Exit
else
6824 if not CollideLevel(sx
, -y
) then
6831 function CanJumpUp(Dist
: ShortInt): Boolean;
6838 if CollideLevel(Dist
, 0) then Exit
;
6841 for y
:= 0 to BOT_MAXJUMP
do
6842 if CollideLevel(Dist
, -y
) then
6851 for yy
:= y
+1 to BOT_MAXJUMP
do
6852 if not CollideLevel(Dist
, -yy
) then
6861 for y
:= 0 to BOT_MAXJUMP
do
6862 if CollideLevel(0, -y
) then
6870 if y
< yy
then Exit
;
6875 function IsSafeTrigger(): Boolean;
6880 if gTriggers
= nil then
6882 for a
:= 0 to High(gTriggers
) do
6883 if Collide(gTriggers
[a
].X
,
6886 gTriggers
[a
].Height
) and
6887 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
6888 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
6889 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
6890 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
6891 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
6896 // Возможно, нажимаем кнопку:
6897 if Rnd(16) and IsSafeTrigger() then
6900 // Если под лифтом или ступеньками, то, возможно, прыгаем:
6901 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
6903 ReleaseKey(KEY_LEFT
);
6904 ReleaseKey(KEY_RIGHT
);
6908 // Идем влево, если надо было:
6909 if GetAIFlag('GOLEFT') <> '' then
6911 RemoveAIFlag('GOLEFT');
6912 if CanRunLeft() then
6916 // Идем вправо, если надо было:
6917 if GetAIFlag('GORIGHT') <> '' then
6919 RemoveAIFlag('GORIGHT');
6920 if CanRunRight() then
6924 // Если вылетели за карту, то пробуем вернуться:
6925 if FObj
.X
< -32 then
6928 if FObj
.X
+32 > gMapInfo
.Width
then
6931 // Прыгаем, если надо было:
6932 if GetAIFlag('NEEDJUMP') <> '' then
6935 RemoveAIFlag('NEEDJUMP');
6938 // Смотрим вверх, если надо было:
6939 if GetAIFlag('NEEDSEEUP') <> '' then
6942 ReleaseKey(KEY_DOWN
);
6943 PressKey(KEY_UP
, 20);
6944 RemoveAIFlag('NEEDSEEUP');
6947 // Смотрим вниз, если надо было:
6948 if GetAIFlag('NEEDSEEDOWN') <> '' then
6951 ReleaseKey(KEY_DOWN
);
6952 PressKey(KEY_DOWN
, 20);
6953 RemoveAIFlag('NEEDSEEDOWN');
6956 // Если нужно было в дыру и мы не на земле, то покорно летим:
6957 if GetAIFlag('GOINHOLE') <> '' then
6958 if not OnGround() then
6960 ReleaseKey(KEY_LEFT
);
6961 ReleaseKey(KEY_RIGHT
);
6962 RemoveAIFlag('GOINHOLE');
6963 SetAIFlag('FALLINHOLE', '1');
6966 // Если падали и достигли земли, то хватит падать:
6967 if GetAIFlag('FALLINHOLE') <> '' then
6969 RemoveAIFlag('FALLINHOLE');
6971 // Если летели прямо и сейчас не на лестнице или на вершине лифта, то отходим в сторону:
6972 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
6973 if GetAIFlag('FALLINHOLE') = '' then
6974 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
6980 // Если на земле и можно подпрыгнуть, то, возможно, прыгаем:
6982 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
6986 // Если на земле и возле дыры (глубина > 2 ростов игрока):
6987 if OnGround() and NearHole() then
6988 if NearDeepHole() then // Если это бездна
6990 0..3: Turn(); // Бежим обратно
6991 4: Jump(); // Прыгаем
6992 5: begin // Прыгаем обратно
6997 else // Это не бездна и мы еще не летим туда
6998 if GetAIFlag('GOINHOLE') = '' then
7000 0: Turn(); // Не нужно туда
7001 1: Jump(); // Вдруг повезет - прыгаем
7002 else // Если яма с границей, то при случае можно туда прыгнуть
7003 if BorderHole() then
7004 SetAIFlag('GOINHOLE', '1');
7007 // Если на земле, но некуда идти:
7008 if (not CanRun()) and OnGround() then
7010 // Если мы на лестнице или можно перепрыгнуть, то прыгаем:
7011 if CanJumpOver() or OnLadder() then
7013 else // иначе попытаемся в другую сторону
7014 if Random(2) = 0 then
7016 if IsSafeTrigger() then
7022 // Осталось мало воздуха:
7023 if FAir
< 36 * 2 then
7026 // Выбираемся из кислоты, если нет костюма, обожглись, или мало здоровья:
7027 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7028 if BodyInAcid(0, 0) then
7032 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7034 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7035 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7038 {function TBot.NeedItem(Item: Byte): Byte;
7043 procedure TBot
.SelectWeapon(Dist
: Integer);
7047 function HaveAmmo(weapon
: Byte): Boolean;
7050 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7051 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7052 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7053 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7054 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7055 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7056 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7057 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7058 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7059 else Result
:= True;
7064 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7066 if Dist
> BOT_LONGDIST
then
7067 begin // Дальний бой
7069 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7071 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7075 else //if Dist > BOT_UNSAFEDIST then
7076 begin // Ближний бой
7078 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7080 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7087 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7089 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7095 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7097 Result
:= inherited PickItem(ItemType
, force
, remove
);
7099 if Result
then SetAIFlag('SELECTWEAPON', '1');
7102 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7104 Result
:= inherited Heal(value
, Soft
);
7107 function TBot
.Healthy(): Byte;
7109 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7110 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7111 else if (FHealth
> 50) then Result
:= 2
7112 else if (FHealth
> 20) then Result
:= 1
7116 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7118 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7119 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7122 procedure TBot
.OnDamage(Angle
: SmallInt);
7130 if (Angle
= 0) or (Angle
= 180) then
7133 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7134 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7136 pla
:= g_Player_Get(FLastSpawnerUID
);
7137 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7138 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7141 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7142 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7144 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7145 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7146 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7151 SetAIFlag('ATTACKLEFT', '1')
7153 SetAIFlag('ATTACKRIGHT', '1');
7157 function TBot
.RunDirection(): TDirection
;
7159 if Abs(Vel
.X
) >= 1 then
7161 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7163 Result
:= FDirection
;
7166 function TBot
.GetRnd(a
: Byte): Boolean;
7168 if a
= 0 then Result
:= False
7169 else if a
= 255 then Result
:= True
7170 else Result
:= Random(256) > 255-a
;
7173 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7175 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7179 procedure TDifficult
.save (st
: TStream
);
7181 utils
.writeInt(st
, Byte(DiagFire
));
7182 utils
.writeInt(st
, Byte(InvisFire
));
7183 utils
.writeInt(st
, Byte(DiagPrecision
));
7184 utils
.writeInt(st
, Byte(FlyPrecision
));
7185 utils
.writeInt(st
, Byte(Cover
));
7186 utils
.writeInt(st
, Byte(CloseJump
));
7187 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7188 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7191 procedure TDifficult
.load (st
: TStream
);
7193 DiagFire
:= utils
.readByte(st
);
7194 InvisFire
:= utils
.readByte(st
);
7195 DiagPrecision
:= utils
.readByte(st
);
7196 FlyPrecision
:= utils
.readByte(st
);
7197 Cover
:= utils
.readByte(st
);
7198 CloseJump
:= utils
.readByte(st
);
7199 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7200 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7204 procedure TBot
.SaveState (st
: TStream
);
7209 inherited SaveState(st
);
7210 utils
.writeSign(st
, 'BOT0');
7212 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7214 utils
.writeInt(st
, Word(FTargetUID
));
7215 // Время потери цели
7216 utils
.writeInt(st
, LongWord(FLastVisible
));
7217 // Количество флагов ИИ
7218 dw
:= Length(FAIFlags
);
7219 utils
.writeInt(st
, LongInt(dw
));
7221 for i
:= 0 to dw
-1 do
7223 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7224 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7226 // Настройки сложности
7227 FDifficult
.save(st
);
7231 procedure TBot
.LoadState (st
: TStream
);
7236 inherited LoadState(st
);
7237 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7239 FSelectedWeapon
:= utils
.readByte(st
);
7241 FTargetUID
:= utils
.readWord(st
);
7242 // Время потери цели
7243 FLastVisible
:= utils
.readLongWord(st
);
7244 // Количество флагов ИИ
7245 dw
:= utils
.readLongInt(st
);
7246 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7247 SetLength(FAIFlags
, dw
);
7249 for i
:= 0 to dw
-1 do
7251 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7252 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7254 // Настройки сложности
7255 FDifficult
.load(st
);
7260 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');
7261 conRegVar('player_indicator_style', @gPlayerIndicatorStyle
, 'Visual appearance of indicator', 'Visual appearance of indicator');