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}
663 e_log
, g_map
, g_items
, g_console
, Math
,
664 g_options
, g_triggers
, g_game
, g_grid
, e_res
,
665 wadreader
, g_monsters
, CONFIG
, g_language
,
669 const PLR_SAVE_VERSION
= 0;
679 diag_precision
: Byte;
683 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
684 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
685 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
689 TIME_RESPAWN1
= 1500;
690 TIME_RESPAWN2
= 2000;
691 TIME_RESPAWN3
= 3000;
692 PLAYER_SUIT_TIME
= 30000;
693 PLAYER_INVUL_TIME
= 30000;
694 PLAYER_INVIS_TIME
= 35000;
695 FRAG_COMBO_TIME
= 3000;
698 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
701 BOT_UNSAFEDIST
= 128;
702 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
703 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
704 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
705 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
706 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
707 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
708 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
709 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
710 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
711 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
712 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
713 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
714 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
715 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
716 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
717 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
718 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
719 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
720 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
721 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
722 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
723 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
724 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
725 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
726 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
727 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
729 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
730 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
732 BOTNAMES_FILENAME
= 'botnames.txt';
733 BOTLIST_FILENAME
= 'botlist.txt';
737 MaxCorpses
: Word = 20;
738 MaxShells
: Word = 300;
739 ForceModel
: Word = 0;
740 ForcedModelName
: String = STD_PLAYER_MODEL
;
741 CurrentGib
: Integer = 0;
742 CurrentShell
: Integer = 0;
743 BotNames
: Array of String;
744 BotList
: Array of TBotProfile
;
745 SavedStates
: Array of TPlayerSavedState
;
748 function Lerp(X
, Y
, Factor
: Integer): Integer;
750 Result
:= X
+ ((Y
- X
) div Factor
);
753 function SameTeam(UID1
, UID2
: Word): Boolean;
757 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
758 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
760 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
762 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
763 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
765 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
768 procedure g_Gibs_SetMax(Count
: Word);
771 SetLength(gGibs
, Count
);
773 if CurrentGib
>= Count
then
777 function g_Gibs_GetMax(): Word;
782 procedure g_Shells_SetMax(Count
: Word);
785 SetLength(gShells
, Count
);
787 if CurrentShell
>= Count
then
791 function g_Shells_GetMax(): Word;
797 procedure g_Corpses_SetMax(Count
: Word);
800 SetLength(gCorpses
, Count
);
803 function g_Corpses_GetMax(): Word;
805 Result
:= MaxCorpses
;
808 procedure g_Force_Model_Set(Mode
: Word);
813 function g_Force_Model_Get(): Word;
815 Result
:= ForceModel
;
818 procedure g_Forced_Model_SetName(Model
: String);
820 ForcedModelName
:= Model
;
823 function g_Forced_Model_GetName(): String;
825 Result
:= ForcedModelName
;
828 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
838 // Есть ли место в gPlayers:
839 if gPlayers
<> nil then
840 for a
:= 0 to High(gPlayers
) do
841 if gPlayers
[a
] = nil then
847 // Нет места - расширяем gPlayers:
850 SetLength(gPlayers
, Length(gPlayers
)+1);
854 // Создаем объект игрока:
856 gPlayers
[a
] := TBot
.Create()
858 gPlayers
[a
] := TPlayer
.Create();
861 gPlayers
[a
].FActualModelName
:= ModelName
;
862 gPlayers
[a
].SetModel(ModelName
);
863 if Bot
and (g_Force_Model_Get() <> 0) then
864 gPlayers
[a
].SetModel(g_Forced_Model_GetName());
866 // Нет модели - создание не возможно:
867 if gPlayers
[a
].FModel
= nil then
871 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
875 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
876 if Random(2) = 0 then
880 gPlayers
[a
].FPreferredTeam
:= Team
;
882 case gGameSettings
.GameMode
of
883 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
885 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
887 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
890 // Если командная игра - красим модель в цвет команды:
891 gPlayers
[a
].FColor
:= Color
;
892 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
893 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
895 gPlayers
[a
].FModel
.Color
:= Color
;
897 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
898 gPlayers
[a
].FAlive
:= False;
900 Result
:= gPlayers
[a
].FUID
;
903 function g_Player_CreateFromState (st
: TStream
): Word;
904 var a
: Integer; ok
, Bot
: Boolean; pos
: Int64;
908 // check signature and entity type
910 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
911 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
912 Bot
:= utils
.readBool(st
);
915 // find free player slot
917 for a
:= 0 to High(gPlayers
) do
918 if gPlayers
[a
] = nil then
924 // allocate player slot
927 SetLength(gPlayers
, Length(gPlayers
)+1);
931 // create entity and load state
934 gPlayers
[a
] := TBot
.Create();
935 if (g_Force_Model_Get() <> 0) then
936 gPlayers
[a
].SetModel(g_Forced_Model_GetName());
939 gPlayers
[a
] := TPlayer
.Create();
940 gPlayers
[a
].FPhysics
:= True; // ???
941 gPlayers
[a
].LoadState(st
);
943 result
:= gPlayers
[a
].FUID
;
947 procedure g_Player_ResetTeams();
951 if g_Game_IsClient
then
953 if gPlayers
= nil then
955 for a
:= Low(gPlayers
) to High(gPlayers
) do
956 if gPlayers
[a
] <> nil then
957 case gGameSettings
.GameMode
of
959 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
961 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
962 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
963 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
966 gPlayers
[a
].ChangeTeam(TEAM_RED
)
968 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
971 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
975 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
978 _name
, _model
: String;
981 if not g_Game_IsServer
then Exit
;
983 if (g_Bot_GetCount() >= gMaxBots
) then Exit
;
985 // Список названий моделей:
986 m
:= g_PlayerModel_GetNames();
991 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
992 Team
:= TEAM_COOP
// COOP
994 if gGameSettings
.GameMode
= GM_DM
then
995 Team
:= TEAM_NONE
// DM
997 if Team
= TEAM_NONE
then // CTF / TDM
999 // Автобаланс команд:
1003 for a
:= 0 to High(gPlayers
) do
1004 if gPlayers
[a
] <> nil then
1006 if gPlayers
[a
].Team
= TEAM_RED
then
1009 if gPlayers
[a
].Team
= TEAM_BLUE
then
1019 if Random(2) = 0 then
1025 // Выбираем боту имя:
1027 if BotNames
<> nil then
1028 for a
:= 0 to High(BotNames
) do
1029 if g_Player_ValidName(BotNames
[a
]) then
1031 _name
:= BotNames
[a
];
1035 // Выбираем случайную модель:
1036 _model
:= m
[Random(Length(m
))];
1039 with g_Player_Get(g_Player_Create(_model
,
1040 _RGB(Min(Random(9)*32, 255),
1041 Min(Random(9)*32, 255),
1042 Min(Random(9)*32, 255)),
1043 Team
, True)) as TBot
do
1045 // Если имени нет, делаем его из UID бота
1047 Name
:= Format('DFBOT%.5d', [UID
])
1052 1: FDifficult
:= DIFFICULT_EASY
;
1053 2: FDifficult
:= DIFFICULT_MEDIUM
;
1054 else FDifficult
:= DIFFICULT_HARD
;
1057 for a
:= WP_FIRST
to WP_LAST
do
1059 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1060 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1061 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1064 FHandicap
:= Handicap
;
1066 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1068 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1069 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1074 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
1077 _name
, _model
: String;
1080 if not g_Game_IsServer
then Exit
;
1082 if (g_Bot_GetCount() >= gMaxBots
) then Exit
;
1084 // Список названий моделей:
1085 m
:= g_PlayerModel_GetNames();
1090 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1091 Team
:= TEAM_COOP
// COOP
1093 if gGameSettings
.GameMode
= GM_DM
then
1094 Team
:= TEAM_NONE
// DM
1096 if Team
= TEAM_NONE
then
1097 Team
:= BotList
[num
].team
; // CTF / TDM
1099 // Выбираем настройки бота из списка по номеру или имени:
1100 lName
:= AnsiLowerCase(lName
);
1101 if (num
< 0) or (num
> Length(BotList
)-1) then
1103 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1104 for a
:= 0 to High(BotList
) do
1105 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1114 _name
:= BotList
[num
].name
;
1115 // Занято - выбираем случайное:
1116 if not g_Player_ValidName(_name
) then
1118 _name
:= Format('DFBOT%.2d', [Random(100)]);
1119 until g_Player_ValidName(_name
);
1122 _model
:= BotList
[num
].model
;
1123 // Нет такой - выбираем случайную:
1124 if not InSArray(_model
, m
) then
1125 _model
:= m
[Random(Length(m
))];
1128 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1132 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1133 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1134 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1135 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1136 FDifficult
.Cover
:= BotList
[num
].cover
;
1137 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1139 FHandicap
:= Handicap
;
1141 for a
:= WP_FIRST
to WP_LAST
do
1143 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1144 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1145 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1148 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1150 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1154 procedure g_Bot_RemoveAll();
1158 if not g_Game_IsServer
then Exit
;
1159 if gPlayers
= nil then Exit
;
1161 for a
:= 0 to High(gPlayers
) do
1162 if gPlayers
[a
] <> nil then
1163 if gPlayers
[a
] is TBot
then
1165 gPlayers
[a
].Lives
:= 0;
1166 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1167 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1168 g_Player_Remove(gPlayers
[a
].FUID
);
1174 procedure g_Bot_MixNames();
1179 if BotNames
<> nil then
1180 for a
:= 0 to High(BotNames
) do
1182 b
:= Random(Length(BotNames
));
1184 Botnames
[a
] := BotNames
[b
];
1189 procedure g_Player_Remove(UID
: Word);
1193 if gPlayers
= nil then Exit
;
1195 if g_Game_IsServer
and g_Game_IsNet
then
1196 MH_SEND_PlayerDelete(UID
);
1198 for i
:= 0 to High(gPlayers
) do
1199 if gPlayers
[i
] <> nil then
1200 if gPlayers
[i
].FUID
= UID
then
1202 if gPlayers
[i
] is TPlayer
then
1203 TPlayer(gPlayers
[i
]).Free()
1205 TBot(gPlayers
[i
]).Free();
1211 procedure g_Player_Init();
1222 path
:= BOTNAMES_FILENAME
;
1223 if e_FindResource(DataDirs
, path
) = false then
1226 // Читаем возможные имена ботов из файла:
1227 AssignFile(F
, path
);
1238 SetLength(BotNames
, Length(BotNames
)+1);
1239 BotNames
[High(BotNames
)] := s
;
1247 // Читаем файл с параметрами ботов:
1248 config
:= TConfig
.CreateFile(path
);
1252 while config
.SectionExists(IntToStr(a
)) do
1254 SetLength(BotList
, Length(BotList
)+1);
1256 with BotList
[High(BotList
)] do
1259 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1261 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1263 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1268 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1269 color
.R
:= StrToIntDef(sa
[0], 0);
1270 color
.G
:= StrToIntDef(sa
[1], 0);
1271 color
.B
:= StrToIntDef(sa
[2], 0);
1272 // Вероятность стрельбы под углом:
1273 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1274 // Вероятность ответного огня по невидимому сопернику:
1275 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1276 // Точность стрельбы под углом:
1277 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1278 // Точность стрельбы в полете:
1279 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1280 // Точность уклонения от снарядов:
1281 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1282 // Вероятность прыжка при приближении соперника:
1283 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1284 // Приоритеты оружия для дальнего боя:
1285 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1286 if Length(sa
) = 10 then
1288 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1289 // Приоритеты оружия для ближнего боя:
1290 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1291 if Length(sa
) = 10 then
1293 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1295 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1296 if Length(sa) = 10 then
1298 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1305 SetLength(SavedStates
, 0);
1308 procedure g_Player_Free();
1312 if gPlayers
<> nil then
1314 for i
:= 0 to High(gPlayers
) do
1315 if gPlayers
[i
] <> nil then
1317 if gPlayers
[i
] is TPlayer
then
1318 TPlayer(gPlayers
[i
]).Free()
1320 TBot(gPlayers
[i
]).Free();
1329 SetLength(SavedStates
, 0);
1332 procedure g_Player_PreUpdate();
1336 if gPlayers
= nil then Exit
;
1337 for i
:= 0 to High(gPlayers
) do
1338 if gPlayers
[i
] <> nil then
1339 gPlayers
[i
].PreUpdate();
1342 procedure g_Player_UpdateAll();
1346 if gPlayers
= nil then Exit
;
1348 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1349 for i
:= 0 to High(gPlayers
) do
1351 if gPlayers
[i
] <> nil then
1353 if gPlayers
[i
] is TPlayer
then
1355 gPlayers
[i
].Update();
1356 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1360 // bot updates weapons in `UpdateCombat()`
1361 TBot(gPlayers
[i
]).Update();
1365 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1368 function g_Player_Get(UID
: Word): TPlayer
;
1374 if gPlayers
= nil then
1377 for a
:= 0 to High(gPlayers
) do
1378 if gPlayers
[a
] <> nil then
1379 if gPlayers
[a
].FUID
= UID
then
1381 Result
:= gPlayers
[a
];
1386 function g_Player_GetCount(): Byte;
1392 if gPlayers
= nil then
1395 for a
:= 0 to High(gPlayers
) do
1396 if gPlayers
[a
] <> nil then
1397 Result
:= Result
+ 1;
1400 function g_Bot_GetCount(): Integer;
1406 if gPlayers
= nil then
1409 for a
:= 0 to High(gPlayers
) do
1410 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] is TBot
) then
1411 Result
:= Result
+ 1;
1414 function g_Player_GetStats(): TPlayerStatArray
;
1420 if gPlayers
= nil then Exit
;
1422 for a
:= 0 to High(gPlayers
) do
1423 if gPlayers
[a
] <> nil then
1425 SetLength(Result
, Length(Result
)+1);
1426 with Result
[High(Result
)] do
1429 Ping
:= gPlayers
[a
].FPing
;
1430 Loss
:= gPlayers
[a
].FLoss
;
1431 Name
:= gPlayers
[a
].FName
;
1432 Team
:= gPlayers
[a
].FTeam
;
1433 Frags
:= gPlayers
[a
].FFrags
;
1434 Deaths
:= gPlayers
[a
].FDeath
;
1435 Kills
:= gPlayers
[a
].FKills
;
1436 Color
:= gPlayers
[a
].FModel
.Color
;
1437 Lives
:= gPlayers
[a
].FLives
;
1438 Spectator
:= gPlayers
[a
].FSpectator
;
1439 UID
:= gPlayers
[a
].FUID
;
1444 procedure g_Player_ResetReady();
1448 if not g_Game_IsServer
then Exit
;
1449 if gPlayers
= nil then Exit
;
1451 for a
:= 0 to High(gPlayers
) do
1452 if gPlayers
[a
] <> nil then
1454 gPlayers
[a
].FReady
:= False;
1455 if g_Game_IsNet
then
1456 MH_SEND_GameEvent(NET_EV_INTER_READY
, gPlayers
[a
].UID
, 'N');
1460 procedure g_Player_RememberAll
;
1464 for i
:= Low(gPlayers
) to High(gPlayers
) do
1465 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1466 gPlayers
[i
].RememberState
;
1469 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1473 gTeamStat
[TEAM_RED
].Score
:= 0;
1474 gTeamStat
[TEAM_BLUE
].Score
:= 0;
1476 if gPlayers
<> nil then
1477 for i
:= 0 to High(gPlayers
) do
1478 if gPlayers
[i
] <> nil then
1480 gPlayers
[i
].Reset(Force
);
1482 if gPlayers
[i
] is TPlayer
then
1484 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1485 gPlayers
[i
].Respawn(Silent
)
1487 gPlayers
[i
].Spectate();
1490 TBot(gPlayers
[i
]).Respawn(Silent
);
1494 function g_Player_CreateCorpse(Player
: TPlayer
): Integer;
1502 if Player
.alive
then
1505 // Разрываем связь с прежним трупом:
1506 i
:= Player
.FCorpse
;
1507 if (i
>= 0) and (i
< Length(gCorpses
)) then
1509 if (gCorpses
[i
] <> nil) and (gCorpses
[i
].FPlayerUID
= Player
.FUID
) then
1510 gCorpses
[i
].FPlayerUID
:= 0;
1513 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1518 if (FHealth
>= -50) or (gGibsCount
= 0) then
1520 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1524 for find_id
:= 0 to High(gCorpses
) do
1525 if gCorpses
[find_id
] = nil then
1532 find_id
:= Random(Length(gCorpses
));
1534 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.GetName(), FHealth
< -20);
1535 gCorpses
[find_id
].FModel
.Color
:= FModel
.Color
;
1536 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1537 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1538 gCorpses
[find_id
].FPlayerUID
:= FUID
;
1543 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
, FObj
.Y
+ PLAYER_RECT_CY
, FModel
.id
, FModel
.Color
);
1547 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1549 if (gShells
= nil) or (Length(gShells
) = 0) then
1552 with gShells
[CurrentShell
] do
1557 if T
= SHELL_BULLET
then
1559 Obj
.Rect
.Width
:= 4;
1560 Obj
.Rect
.Height
:= 2;
1564 Obj
.Rect
.Width
:= 7;
1565 Obj
.Rect
.Height
:= 3;
1571 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1572 positionChanged(); // this updates spatial accelerators
1573 RAngle
:= Random(360);
1574 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1576 if CurrentShell
>= High(gShells
) then
1583 procedure g_Player_CreateGibs (fX
, fY
, mid
: Integer; fColor
: TRGB
);
1586 GibsArray
: TGibsArray
;
1593 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1595 if not g_PlayerModel_GetGibs(mid
, GibsArray
) then
1599 Blood
:= PlayerModelsArray
[mid
].Blood
;
1602 for a
:= 0 to High(GibsArray
) do
1603 with gGibs
[CurrentGib
] do
1606 GibID
:= GibsArray
[a
];
1611 Obj
.Rect
:= r_Render_GetGibRect(ModelID
, GibID
);
1615 Obj
.Rect
.Width
:= 16;
1616 Obj
.Rect
.Height
:= 16;
1618 Obj
.X
:= fX
- Obj
.Rect
.X
- (Obj
.Rect
.Width
div 2);
1619 Obj
.Y
:= fY
- Obj
.Rect
.Y
- (Obj
.Rect
.Height
div 2);
1620 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1621 positionChanged(); // this updates spatial accelerators
1622 RAngle
:= Random(360);
1625 if gBloodCount
> 0 then
1630 16 * gBloodCount
+ Random(5 * gBloodCount
),
1643 if CurrentGib
>= High(gGibs
) then
1650 procedure g_Player_UpdatePhysicalObjects();
1656 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1661 if T
= SHELL_BULLET
then
1662 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1664 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1669 if gGibs
<> nil then
1670 for i
:= 0 to High(gGibs
) do
1671 if gGibs
[i
].alive
then
1678 mr
:= g_Obj_Move(@Obj
, True, False, True);
1679 positionChanged(); // this updates spatial accelerators
1681 if WordBool(mr
and MOVE_FALLOUT
) then
1687 // Отлетает от удара о стену/потолок/пол:
1688 if WordBool(mr
and MOVE_HITWALL
) then
1689 Obj
.Vel
.X
:= -(vel
.X
div 2);
1690 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1691 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1693 if (Obj
.Vel
.X
>= 0) then
1695 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1696 if RAngle
>= 360 then
1697 RAngle
:= RAngle
mod 360;
1698 end else begin // Counter-clockwise
1699 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1701 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1704 // Сопротивление воздуха для куска трупа:
1705 if gTime
mod (GAME_TICK
*3) = 0 then
1706 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1710 if gCorpses
<> nil then
1711 for i
:= 0 to High(gCorpses
) do
1712 if gCorpses
[i
] <> nil then
1713 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1719 gCorpses
[i
].Update();
1722 if gShells
<> nil then
1723 for i
:= 0 to High(gShells
) do
1724 if gShells
[i
].alive
then
1731 mr
:= g_Obj_Move(@Obj
, True, False, True);
1732 positionChanged(); // this updates spatial accelerators
1734 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1740 // Отлетает от удара о стену/потолок/пол:
1741 if WordBool(mr
and MOVE_HITWALL
) then
1743 Obj
.Vel
.X
:= -(vel
.X
div 2);
1744 if not WordBool(mr
and MOVE_INWATER
) then
1745 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1747 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1749 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1750 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1751 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1753 if RAngle
mod 90 <> 0 then
1754 RAngle
:= (RAngle
div 90) * 90;
1756 else if not WordBool(mr
and MOVE_INWATER
) then
1757 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1760 if (Obj
.Vel
.X
>= 0) then
1762 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1763 if RAngle
>= 360 then
1764 RAngle
:= RAngle
mod 360;
1765 end else begin // Counter-clockwise
1766 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1768 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1774 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1776 x
:= Obj
.X
+Obj
.Rect
.X
;
1777 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1778 w
:= Obj
.Rect
.Width
;
1779 h
:= Obj
.Rect
.Height
;
1782 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1784 if (dx
<> 0) or (dy
<> 0) then
1793 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1797 w
:= Obj
.Rect
.Width
;
1798 h
:= Obj
.Rect
.Height
;
1801 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1803 if (dx
<> 0) or (dy
<> 0) then
1812 procedure TGib
.positionChanged (); inline; begin end;
1813 procedure TShell
.positionChanged (); inline; begin end;
1816 procedure g_Player_RemoveAllCorpses();
1822 SetLength(gGibs
, MaxGibs
);
1823 SetLength(gShells
, MaxGibs
);
1827 if gCorpses
<> nil then
1828 for i
:= 0 to High(gCorpses
) do
1832 SetLength(gCorpses
, MaxCorpses
);
1835 procedure g_Player_Corpses_SaveState (st
: TStream
);
1839 // Считаем количество существующих трупов
1841 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1843 // Количество трупов
1844 utils
.writeInt(st
, LongInt(count
));
1846 if (count
= 0) then exit
;
1849 for i
:= 0 to High(gCorpses
) do
1851 if gCorpses
[i
] <> nil then
1854 utils
.writeStr(st
, gCorpses
[i
].FModel
.GetName());
1856 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1857 // Сохраняем данные трупа:
1858 gCorpses
[i
].SaveState(st
);
1864 procedure g_Player_Corpses_LoadState (st
: TStream
);
1872 g_Player_RemoveAllCorpses();
1874 // Количество трупов:
1875 count
:= utils
.readLongInt(st
);
1876 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1878 if (count
= 0) then exit
;
1881 for i
:= 0 to count
-1 do
1884 str
:= utils
.readStr(st
);
1886 b
:= utils
.readBool(st
);
1888 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1889 // Загружаем данные трупа
1890 gCorpses
[i
].LoadState(st
);
1897 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1899 procedure TPlayer
.BFGHit();
1901 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1902 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1903 if g_Game_IsServer
and g_Game_IsNet
then
1904 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1905 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1909 procedure TPlayer
.ChangeModel(ModelName
: string);
1911 locModel
: TPlayerModel
;
1913 locModel
:= g_PlayerModel_Get(ModelName
);
1914 if locModel
= nil then Exit
;
1920 procedure TPlayer
.SetModel(ModelName
: string);
1924 m
:= g_PlayerModel_Get(ModelName
);
1927 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1928 m
:= g_PlayerModel_Get('doomer');
1931 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1936 if FModel
<> nil then
1941 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1942 FModel
.Color
:= FColor
1944 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1945 FModel
.SetWeapon(FCurrWeap
);
1946 FModel
.SetFlag(FFlag
);
1947 SetDirection(FDirection
);
1950 procedure TPlayer
.SetColor(Color
: TRGB
);
1953 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1954 if FModel
<> nil then FModel
.Color
:= Color
;
1959 function TPlayer
.GetColor(): TRGB
;
1961 result
:= FModel
.Color
;
1964 procedure TPlayer
.SetWeaponPrefs(Prefs
: Array of Byte);
1968 for i
:= WP_FIRST
to WP_LAST
+ 1 do
1970 if (Prefs
[i
] > WP_LAST
+ 1) then
1971 FWeapPreferences
[i
] := 0
1973 FWeapPreferences
[i
] := Prefs
[i
];
1977 procedure TPlayer
.SetWeaponPref(Weapon
, Pref
: Byte);
1979 if (Weapon
> WP_LAST
+ 1) then
1981 else if (Pref
<= WP_LAST
+ 1) and (Weapon
<= WP_LAST
+ 1) then
1982 FWeapPreferences
[Weapon
] := Pref
1983 else if (Weapon
<= WP_LAST
+ 1) and (Pref
> WP_LAST
+ 1) then
1984 FWeapPreferences
[Weapon
] := 0;
1987 function TPlayer
.GetWeaponPref(Weapon
: Byte) : Byte;
1989 if (Weapon
> WP_LAST
+ 1) then
1991 else if (FWeapPreferences
[Weapon
] > WP_LAST
+ 1) then
1994 result
:= FWeapPreferences
[Weapon
];
1997 function TPlayer
.GetMorePrefered() : Byte;
1999 testedWeap
, i
: Byte;
2001 testedWeap
:= FCurrWeap
;
2002 for i
:= WP_FIRST
to WP_LAST
do
2003 if FWeapon
[i
] and maySwitch(i
) and (FWeapPreferences
[i
] > FWeapPreferences
[testedWeap
]) then
2005 if (R_BERSERK
in FRulez
) and (FWeapPreferences
[WP_LAST
+ 1] > FWeapPreferences
[testedWeap
]) then
2006 testedWeap
:= WEAPON_KASTET
;
2007 result
:= testedWeap
;
2010 function TPlayer
.maySwitch(Weapon
: Byte) : Boolean;
2013 if (Weapon
= WEAPON_KASTET
) and (FSkipFist
<> 0) then
2015 if (FSkipFist
= 1) and (not (R_BERSERK
in FRulez
)) then
2018 else if (FSwitchToEmpty
= 0) and (not hasAmmoForShooting(Weapon
)) then
2022 procedure TPlayer
.SwitchTeam
;
2024 if g_Game_IsClient
then
2026 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
2028 if gGameOn
and FAlive
then
2029 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
2031 if FTeam
= TEAM_RED
then
2033 ChangeTeam(TEAM_BLUE
);
2034 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
2035 if g_Game_IsNet
then
2036 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
2040 ChangeTeam(TEAM_RED
);
2041 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
2042 if g_Game_IsNet
then
2043 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
2045 FPreferredTeam
:= FTeam
;
2048 procedure TPlayer
.ChangeTeam(Team
: Byte);
2055 TEAM_RED
, TEAM_BLUE
:
2056 FModel
.Color
:= TEAMCOLOR
[Team
];
2058 FModel
.Color
:= FColor
;
2060 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2061 MH_SEND_PlayerStats(FUID
);
2065 procedure TPlayer.CollideItem();
2070 if gItems = nil then Exit;
2071 if not FAlive then Exit;
2073 for i := 0 to High(gItems) do
2076 if (ItemType <> ITEM_NONE) and alive then
2077 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2078 PLAYER_RECT.Height, @Obj) then
2080 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2082 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2083 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2084 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2085 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2086 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2088 // Надо убрать с карты, если это не ключ, которым нужно поделится с другим игроком:
2089 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2090 (gGameSettings.GameType = GT_SINGLE) and
2091 (g_Player_GetCount() > 1)) then
2092 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2098 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2100 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2101 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2105 constructor TPlayer
.Create();
2111 mEDamageType
:= HIT_SOME
;
2117 FSawSound
:= TPlayableSound
.Create();
2118 FSawSoundIdle
:= TPlayableSound
.Create();
2119 FSawSoundHit
:= TPlayableSound
.Create();
2120 FSawSoundSelect
:= TPlayableSound
.Create();
2121 FFlameSoundOn
:= TPlayableSound
.Create();
2122 FFlameSoundOff
:= TPlayableSound
.Create();
2123 FFlameSoundWork
:= TPlayableSound
.Create();
2124 FJetSoundFly
:= TPlayableSound
.Create();
2125 FJetSoundOn
:= TPlayableSound
.Create();
2126 FJetSoundOff
:= TPlayableSound
.Create();
2128 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2129 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2130 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2131 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2132 FFlameSoundOn
.SetByName('SOUND_WEAPON_FLAMEON');
2133 FFlameSoundOff
.SetByName('SOUND_WEAPON_FLAMEOFF');
2134 FFlameSoundWork
.SetByName('SOUND_WEAPON_FLAMEWORK');
2135 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2136 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2137 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2139 FSpectatePlayer
:= -1;
2143 FSavedStateNum
:= -1;
2151 FActualModelName
:= 'doomer';
2154 FObj
.Rect
:= PLAYER_RECT
;
2156 FBFGFireCounter
:= -1;
2157 FJustTeleported
:= False;
2160 FWaitForFirstSpawn
:= false;
2161 FPunchAnim
:= TAnimationState
.Create(False, 1, 4);
2167 procedure TPlayer
.positionChanged (); inline;
2171 procedure TPlayer
.doDamage (v
: Integer);
2173 if (v
<= 0) then exit
;
2174 if (v
> 32767) then v
:= 32767;
2175 Damage(v
, 0, 0, 0, mEDamageType
);
2178 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2182 if (not g_Game_IsClient
) and (not FAlive
) then
2187 // Неуязвимость не спасает от ловушек:
2188 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2190 if not g_Game_IsClient
then
2193 if t
= HIT_TRAP
then
2195 // Ловушка убивает сразу:
2197 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2199 if t
= HIT_SELF
then
2203 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2206 // Обнулить действия примочек, чтобы фон пропал
2207 FMegaRulez
[MR_SUIT
] := 0;
2208 FMegaRulez
[MR_INVUL
] := 0;
2209 FMegaRulez
[MR_INVIS
] := 0;
2214 // Но от остального спасает:
2215 if FMegaRulez
[MR_INVUL
] >= gTime
then
2222 // Если есть урон своим, или ранил сам себя, или тебя ранил противник:
2223 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2224 (SpawnerUID
= FUID
) or
2225 (not SameTeam(FUID
, SpawnerUID
)) then
2227 FLastSpawnerUID
:= SpawnerUID
;
2229 // Кровь (пузырьки, если в воде):
2230 if gBloodCount
> 0 then
2232 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2233 if value
div 4 <= c
then
2234 c
:= c
- (value
div 4)
2238 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2242 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2243 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2247 if t
= HIT_WATER
then
2249 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2250 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2252 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
2253 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
2260 Inc(FDamageBuffer
, value
);
2264 FPain
:= FPain
+ value
;
2267 if g_Game_IsServer
and g_Game_IsNet
then
2269 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2270 MH_SEND_PlayerStats(FUID
);
2271 MH_SEND_PlayerPos(False, FUID
);
2275 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2278 if g_Game_IsClient
then
2283 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2285 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2288 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2290 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2294 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2295 MH_SEND_PlayerStats(FUID
);
2298 destructor TPlayer
.Destroy();
2300 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2302 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2306 FSawSoundIdle
.Free();
2307 FSawSoundHit
.Free();
2308 FSawSoundSelect
.Free();
2309 FFlameSoundOn
.Free();
2310 FFlameSoundOff
.Free();
2311 FFlameSoundWork
.Free();
2312 FJetSoundFly
.Free();
2314 FJetSoundOff
.Free();
2321 procedure TPlayer
.DoPunch();
2327 procedure TPlayer
.Fire();
2329 f
, DidFire
: Boolean;
2330 wx
, wy
, xd
, yd
: Integer;
2333 if g_Game_IsClient
then Exit
;
2334 // FBFGFireCounter - время перед выстрелом (для BFG)
2335 // FReloading - время после выстрела (для всего)
2343 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2348 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2349 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2350 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
2351 yd
:= wy
+firediry();
2357 if R_BERSERK
in FRulez
then
2359 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2360 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2361 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2364 locobj
.rect
.Width
:= 39;
2365 locobj
.rect
.Height
:= 52;
2366 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2367 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2368 locobj
.Accel
.X
:= xd
-wx
;
2369 locobj
.Accel
.y
:= yd
-wy
;
2371 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2372 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2374 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2376 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
2380 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2384 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2389 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2390 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2392 FSawSoundSelect
.Stop();
2394 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2396 else if not FSawSoundHit
.IsPlaying() then
2398 FSawSoundSelect
.Stop();
2399 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2402 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2408 if FAmmo
[A_BULLETS
] > 0 then
2410 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2411 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2412 Dec(FAmmo
[A_BULLETS
]);
2413 FFireAngle
:= FAngle
;
2416 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2417 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2421 if FAmmo
[A_SHELLS
] > 0 then
2423 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2424 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
2425 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2426 Dec(FAmmo
[A_SHELLS
]);
2427 FFireAngle
:= FAngle
;
2431 FShellType
:= SHELL_SHELL
;
2435 if FAmmo
[A_SHELLS
] >= 2 then
2437 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
2438 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2439 Dec(FAmmo
[A_SHELLS
], 2);
2440 FFireAngle
:= FAngle
;
2444 FShellType
:= SHELL_DBLSHELL
;
2448 if FAmmo
[A_BULLETS
] > 0 then
2450 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
2451 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
2452 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2453 Dec(FAmmo
[A_BULLETS
]);
2454 FFireAngle
:= FAngle
;
2457 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2458 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2461 WEAPON_ROCKETLAUNCHER
:
2462 if FAmmo
[A_ROCKETS
] > 0 then
2464 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
2465 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2466 Dec(FAmmo
[A_ROCKETS
]);
2467 FFireAngle
:= FAngle
;
2473 if FAmmo
[A_CELLS
] > 0 then
2475 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
2476 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2477 Dec(FAmmo
[A_CELLS
]);
2478 FFireAngle
:= FAngle
;
2484 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
2486 FBFGFireCounter
:= 17;
2487 if not FNoReload
then
2488 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
2489 Dec(FAmmo
[A_CELLS
], 40);
2493 WEAPON_SUPERPULEMET
:
2494 if FAmmo
[A_SHELLS
] > 0 then
2496 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2497 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
2498 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2499 Dec(FAmmo
[A_SHELLS
]);
2500 FFireAngle
:= FAngle
;
2503 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2504 GameVelX
, GameVelY
-2, SHELL_SHELL
);
2507 WEAPON_FLAMETHROWER
:
2508 if FAmmo
[A_FUEL
] > 0 then
2510 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
2512 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2514 FFireAngle
:= FAngle
;
2521 if g_Game_IsNet
and g_Game_IsServer
then MH_SEND_PlayerStats(FUID
);
2525 if g_Game_IsNet
then
2529 if FCurrWeap
<> WEAPON_BFG
then
2530 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
2532 if not FNoReload
then
2533 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
2536 MH_SEND_PlayerStats(FUID
);
2541 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
2542 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
2543 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
2546 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
2549 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
2550 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
2551 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
2552 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
2553 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
2558 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
2560 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
2561 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
2562 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
2565 procedure TPlayer
.FlamerOn
;
2567 FFlameSoundOff
.Stop();
2568 FFlameSoundOff
.SetPosition(0);
2571 if (not FFlameSoundOn
.IsPlaying()) and (not FFlameSoundWork
.IsPlaying()) then
2572 FFlameSoundWork
.PlayAt(FObj
.X
, FObj
.Y
);
2576 FFlameSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
2581 procedure TPlayer
.FlamerOff
;
2585 FFlameSoundOn
.Stop();
2586 FFlameSoundOn
.SetPosition(0);
2587 FFlameSoundWork
.Stop();
2588 FFlameSoundWork
.SetPosition(0);
2589 FFlameSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
2594 procedure TPlayer
.JetpackOn
;
2598 FJetSoundOn
.SetPosition(0);
2599 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
2603 procedure TPlayer
.JetpackOff
;
2607 FJetSoundOff
.SetPosition(0);
2608 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
2611 procedure TPlayer
.CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
2613 if Timeout
<= 0 then
2615 if (FMegaRulez
[MR_SUIT
] > gTime
) or (FMegaRulez
[MR_INVUL
] > gTime
) then
2616 exit
; // Не загораемся когда есть защита
2617 if g_Obj_CollidePanel(@FObj
, 0, 0, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
) then
2618 exit
; // Не подгораем в воде на всякий случай
2619 if FFireTime
<= 0 then
2620 g_Sound_PlayExAt('SOUND_IGNITE', FObj
.X
, FObj
.Y
);
2621 FFireTime
:= Timeout
;
2622 FFireAttacker
:= Attacker
;
2623 if g_Game_IsNet
and g_Game_IsServer
then
2624 MH_SEND_PlayerStats(FUID
);
2627 procedure TPlayer
.Jump();
2629 if gFly
or FJetpack
then
2631 // Полет (чит-код или джетпак):
2632 if FObj
.Vel
.Y
> -VEL_FLY
then
2633 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
2636 if FJetFuel
> 0 then
2638 if (FJetFuel
< 1) and g_Game_IsServer
then
2642 if g_Game_IsNet
then
2643 MH_SEND_PlayerStats(FUID
);
2649 // Не включать джетпак в режиме прохождения сквозь стены
2651 FCanJetpack
:= False;
2653 // Прыгаем или всплываем:
2654 if (CollideLevel(0, 1) or
2655 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
2656 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
2657 ) and (FObj
.Accel
.Y
= 0) then // Не прыгать, если есть вертикальное ускорение
2659 FObj
.Vel
.Y
:= -VEL_JUMP
;
2660 FCanJetpack
:= False;
2664 if BodyInLiquid(0, 0) then
2665 FObj
.Vel
.Y
:= -VEL_SW
2666 else if (FJetFuel
> 0) and FCanJetpack
and
2667 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
2671 if g_Game_IsNet
then
2672 MH_SEND_PlayerStats(FUID
);
2677 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
2679 a
, i
, k
, ab
, ar
: Byte;
2683 srv
, netsrv
: Boolean;
2689 procedure PushItem(t
: Byte);
2693 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
2694 it
:= g_Items_ByIdx(id
);
2695 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
2697 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
2698 (FObj
.Vel
.Y
div 2)-Random(9));
2699 it
.positionChanged(); // this updates spatial accelerators
2703 if KillType
= K_HARDKILL
then // -5..+5; -5..0
2705 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
2706 (FObj
.Vel
.Y
div 2)-Random(6));
2708 else // -3..+3; -3..0
2710 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
2711 (FObj
.Vel
.Y
div 2)-Random(4));
2713 it
.positionChanged(); // this updates spatial accelerators
2716 if g_Game_IsNet
and g_Game_IsServer
then
2717 MH_SEND_ItemSpawn(True, id
);
2721 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
2722 Srv
:= g_Game_IsServer
;
2723 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
2724 if Srv
then FDeath
:= FDeath
+ 1;
2729 if not FPhysics
then
2735 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2737 if FLives
> 0 then FLives
:= FLives
- 1;
2738 if FLives
= 0 then FNoRespawn
:= True;
2741 // Номер типа смерти:
2744 K_SIMPLEKILL
: a
:= 1;
2746 K_EXTRAHARDKILL
: a
:= 3;
2751 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
2753 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
2760 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
2762 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
2763 K_EXTRAHARDKILL
, K_FALLKILL
:
2764 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
2767 // Переключаем состояние:
2771 K_HARDKILL
, K_EXTRAHARDKILL
:
2775 // Реакция монстров на смерть игрока:
2776 if (KillType
<> K_FALLKILL
) and (Srv
) then
2777 g_Monsters_killedp();
2779 if SpawnerUID
= FUID
then
2783 if gGameSettings
.GameMode
= GM_TDM
then
2784 Dec(gTeamStat
[FTeam
].Score
);
2785 if DoFrags
or (gGameSettings
.GameMode
= GM_TDM
) then
2791 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
2794 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
2795 begin // Убит другим игроком
2796 KP
:= g_Player_Get(SpawnerUID
);
2797 if (KP
<> nil) and Srv
then
2799 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
2800 if SameTeam(FUID
, SpawnerUID
) then
2810 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
2811 Inc(gTeamStat
[KP
.Team
].Score
,
2812 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
2814 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
2817 plr
:= g_Player_Get(SpawnerUID
);
2825 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
2829 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
2833 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
2838 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
2839 begin // Убит монстром
2840 mon
:= g_Monsters_ByUID(SpawnerUID
);
2844 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
2848 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
2852 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
2856 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
2861 else // Особые типы смерти
2864 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
2865 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
2866 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
2867 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
2868 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
2869 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
2875 for a
:= WP_FIRST
to WP_LAST
do
2879 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
2880 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
2881 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
2882 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
2883 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
2884 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
2885 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
2886 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
2887 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
2896 if R_ITEM_BACKPACK
in FRulez
then
2897 PushItem(ITEM_AMMO_BACKPACK
);
2899 // Выброс ракетного ранца:
2900 if FJetFuel
> 0 then
2901 PushItem(ITEM_JETPACK
);
2904 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) or
2905 (not LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
)) then
2907 if R_KEY_RED
in FRulez
then
2908 PushItem(ITEM_KEY_RED
);
2910 if R_KEY_GREEN
in FRulez
then
2911 PushItem(ITEM_KEY_GREEN
);
2913 if R_KEY_BLUE
in FRulez
then
2914 PushItem(ITEM_KEY_BLUE
);
2918 DropFlag(KillType
= K_FALLKILL
);
2921 FCorpse
:= g_Player_CreateCorpse(Self
);
2923 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
2924 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2930 for i
:= Low(gPlayers
) to High(gPlayers
) do
2932 if gPlayers
[i
] = nil then continue
;
2933 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
2936 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
2937 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
2942 OldLR
:= gLMSRespawn
;
2943 if (gGameSettings
.GameMode
= GM_COOP
) then
2947 // everyone is dead, restart the map
2948 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
2950 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
2951 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2952 gLMSRespawnTime
:= gTime
+ 5000;
2954 else if (a
= 1) then
2956 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
2957 if (gPlayers
[k
] = gPlayer1
) or
2958 (gPlayers
[k
] = gPlayer2
) then
2959 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
2960 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
2961 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
2964 else if (gGameSettings
.GameMode
= GM_TDM
) then
2966 if (ab
= 0) and (ar
<> 0) then
2969 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
2971 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
2972 Inc(gTeamStat
[TEAM_RED
].Score
);
2973 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2974 gLMSRespawnTime
:= gTime
+ 5000;
2976 else if (ar
= 0) and (ab
<> 0) then
2979 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
2981 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
2982 Inc(gTeamStat
[TEAM_BLUE
].Score
);
2983 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2984 gLMSRespawnTime
:= gTime
+ 5000;
2986 else if (ar
= 0) and (ab
= 0) then
2989 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
2991 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
2992 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2993 gLMSRespawnTime
:= gTime
+ 5000;
2996 else if (gGameSettings
.GameMode
= GM_DM
) then
3000 if gPlayers
[k
] <> nil then
3003 // survivor is the winner
3004 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3006 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3009 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3010 gLMSRespawnTime
:= gTime
+ 5000;
3012 else if (a
= 0) then
3014 // everyone is dead, restart the map
3015 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3017 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3018 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3019 gLMSRespawnTime
:= gTime
+ 5000;
3022 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3024 if NetMode
= NET_SERVER
then
3025 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
)
3027 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3033 MH_SEND_PlayerStats(FUID
);
3034 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3035 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3038 if srv
and FNoRespawn
then Spectate(True);
3039 FWantsInGame
:= True;
3042 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3044 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3045 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3048 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3050 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3051 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3054 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3056 var Blood
: TModelBlood
;
3060 Blood
:= SELF
.FModel
.GetBlood();
3061 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3062 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3063 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3064 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
3065 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3066 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3067 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3068 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
3072 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3074 var Blood
: TModelBlood
;
3078 Blood
:= SELF
.FModel
.GetBlood();
3079 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3080 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3081 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3082 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
3086 procedure TPlayer
.ProcessWeaponAction(Action
: Byte);
3088 if g_Game_IsClient
then Exit
;
3090 WP_PREV
: PrevWeapon();
3091 WP_NEXT
: NextWeapon();
3095 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3097 if g_Game_IsClient
then Exit
;
3098 if Weapon
> High(FWeapon
) then Exit
;
3099 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3102 procedure TPlayer
.resetWeaponQueue ();
3105 FNextWeapDelay
:= 0;
3108 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3112 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3113 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
3114 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
3115 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3116 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3117 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3118 else result
:= (weapon
< length(FWeapon
));
3122 function TPlayer
.hasAmmoForShooting (weapon
: Byte): Boolean;
3126 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3127 WEAPON_SHOTGUN1
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
3128 WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 1);
3129 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
3130 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3131 WEAPON_PLASMA
: result
:= (FAmmo
[A_CELLS
] > 0);
3132 WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] >= 40);
3133 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3134 else result
:= (weapon
< length(FWeapon
));
3138 function TPlayer
.shouldSwitch (weapon
: Byte; hadWeapon
: Boolean): Boolean;
3141 if (weapon
> WP_LAST
+ 1) then
3146 if (FWeapSwitchMode
= 1) and not hadWeapon
then
3148 else if (FWeapSwitchMode
= 2) then
3149 result
:= (FWeapPreferences
[weapon
] > FWeapPreferences
[FCurrWeap
]);
3152 // return 255 for "no switch"
3153 function TPlayer
.getNextWeaponIndex (): Byte;
3156 wantThisWeapon
: array[0..64] of Boolean;
3157 wwc
: Integer = 0; //HACK!
3160 result
:= 255; // default result: "no switch"
3161 //e_LogWriteFln('FSWITCHTOEMPTY: %s', [FSwitchToEmpty], TMsgType.Notify);
3162 // had weapon cycling on previous frame? remove that flag
3163 if (FNextWeap
and $2000) <> 0 then
3165 FNextWeap
:= FNextWeap
and $1FFF;
3166 FNextWeapDelay
:= 0;
3168 // cycling has priority
3169 if (FNextWeap
and $C000) <> 0 then
3171 if (FNextWeap
and $8000) <> 0 then
3175 FNextWeap
:= FNextWeap
or $2000; // we need this
3176 if FNextWeapDelay
> 0 then
3177 exit
; // cooldown time
3179 for i
:= 0 to High(FWeapon
) do
3181 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3182 if FWeapon
[cwi
] and maySwitch(cwi
) then
3184 //e_LogWriteFln(' SWITCH: cur=%d; new=%d %s %s', [FCurrWeap, cwi, FSwitchToEmpty, hasAmmoForWeapon(cwi)], TMsgType.Notify);
3185 result
:= Byte(cwi
);
3186 FNextWeapDelay
:= WEAPON_DELAY
;
3194 for i
:= 0 to High(wantThisWeapon
) do
3195 wantThisWeapon
[i
] := false;
3196 for i
:= 0 to High(FWeapon
) do
3197 if (FNextWeap
and (1 shl i
)) <> 0 then
3199 wantThisWeapon
[i
] := true;
3203 // exclude currently selected weapon from the set
3204 wantThisWeapon
[FCurrWeap
] := false;
3205 // slow down alterations a little
3208 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3209 // more than one weapon requested, assume "alteration" and check alteration delay
3210 if FNextWeapDelay
> 0 then
3216 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3217 // but clear all counters if no weapon should be switched
3223 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3224 // try weapons in descending order
3225 for i
:= High(FWeapon
) downto 0 do
3227 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3232 FNextWeapDelay
:= WEAPON_DELAY
* 2; // anyway, 'cause why not
3233 //e_LogWriteFln('FOUND %s %s %s', [result, FSwitchToEmpty, hasAmmoForWeapon(i)], TMsgType.Notify);
3237 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3241 procedure TPlayer
.RealizeCurrentWeapon();
3242 function switchAllowed (): Boolean;
3247 if FBFGFireCounter
<> -1 then
3249 if FTime
[T_SWITCH
] > gTime
then
3251 for i
:= WP_FIRST
to WP_LAST
do
3252 if FReloading
[i
] > 0 then
3260 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3261 //FNextWeap := FNextWeap and $1FFF;
3262 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3264 if not switchAllowed
then
3266 //HACK for weapon cycling
3267 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3271 nw
:= getNextWeaponIndex();
3273 if nw
= 255 then exit
; // don't reset anything here
3274 if nw
> High(FWeapon
) then
3276 // don't forget to reset queue here!
3277 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3285 FTime
[T_SWITCH
] := gTime
+156;
3286 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3287 FModel
.SetWeapon(FCurrWeap
);
3288 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3292 procedure TPlayer
.NextWeapon();
3294 if g_Game_IsClient
then Exit
;
3298 procedure TPlayer
.PrevWeapon();
3300 if g_Game_IsClient
then Exit
;
3304 procedure TPlayer
.SetWeapon(W
: Byte);
3306 if FCurrWeap
<> W
then
3307 if W
= WEAPON_SAW
then
3308 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3311 FModel
.SetWeapon(CurrWeap
);
3315 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3318 switchWeapon
: Byte = 255;
3319 hadWeapon
: Boolean = False;
3322 if g_Game_IsClient
then Exit
;
3324 // a = true - место спавна предмета:
3325 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3329 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3331 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3335 if gFlash
= 2 then Inc(FPickup
, 5);
3339 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3341 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3345 if gFlash
= 2 then Inc(FPickup
, 5);
3349 if FArmor
< PLAYER_AP_SOFT
then
3351 FArmor
:= PLAYER_AP_SOFT
;
3354 if gFlash
= 2 then Inc(FPickup
, 5);
3358 if FArmor
< PLAYER_AP_LIMIT
then
3360 FArmor
:= PLAYER_AP_LIMIT
;
3363 if gFlash
= 2 then Inc(FPickup
, 5);
3367 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
3369 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3373 if gFlash
= 2 then Inc(FPickup
, 5);
3377 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) or (FFireTime
> 0) then
3379 if FHealth
< PLAYER_HP_LIMIT
then
3380 FHealth
:= PLAYER_HP_LIMIT
;
3381 if FArmor
< PLAYER_AP_LIMIT
then
3382 FArmor
:= PLAYER_AP_LIMIT
;
3386 if gFlash
= 2 then Inc(FPickup
, 5);
3390 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3392 hadWeapon
:= FWeapon
[WEAPON_SAW
];
3393 switchWeapon
:= WEAPON_SAW
;
3394 FWeapon
[WEAPON_SAW
] := True;
3396 if gFlash
= 2 then Inc(FPickup
, 5);
3397 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3400 ITEM_WEAPON_SHOTGUN1
:
3401 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3403 // Нужно, чтобы не взять все пули сразу:
3404 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3405 hadWeapon
:= FWeapon
[WEAPON_SHOTGUN1
];
3406 switchWeapon
:= WEAPON_SHOTGUN1
;
3407 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3408 FWeapon
[WEAPON_SHOTGUN1
] := True;
3410 if gFlash
= 2 then Inc(FPickup
, 5);
3411 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3414 ITEM_WEAPON_SHOTGUN2
:
3415 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3417 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3418 hadWeapon
:= FWeapon
[WEAPON_SHOTGUN2
];
3419 switchWeapon
:= WEAPON_SHOTGUN2
;
3420 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3421 FWeapon
[WEAPON_SHOTGUN2
] := True;
3423 if gFlash
= 2 then Inc(FPickup
, 5);
3424 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3427 ITEM_WEAPON_CHAINGUN
:
3428 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3430 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3431 hadWeapon
:= FWeapon
[WEAPON_CHAINGUN
];
3432 switchWeapon
:= WEAPON_CHAINGUN
;
3433 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3434 FWeapon
[WEAPON_CHAINGUN
] := True;
3436 if gFlash
= 2 then Inc(FPickup
, 5);
3437 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3440 ITEM_WEAPON_ROCKETLAUNCHER
:
3441 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3443 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3444 switchWeapon
:= WEAPON_ROCKETLAUNCHER
;
3445 hadWeapon
:= FWeapon
[WEAPON_ROCKETLAUNCHER
];
3446 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3447 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3449 if gFlash
= 2 then Inc(FPickup
, 5);
3450 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3454 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3456 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3457 switchWeapon
:= WEAPON_PLASMA
;
3458 hadWeapon
:= FWeapon
[WEAPON_PLASMA
];
3459 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3460 FWeapon
[WEAPON_PLASMA
] := True;
3462 if gFlash
= 2 then Inc(FPickup
, 5);
3463 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3467 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3469 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3470 switchWeapon
:= WEAPON_BFG
;
3471 hadWeapon
:= FWeapon
[WEAPON_BFG
];
3472 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3473 FWeapon
[WEAPON_BFG
] := True;
3475 if gFlash
= 2 then Inc(FPickup
, 5);
3476 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3479 ITEM_WEAPON_SUPERPULEMET
:
3480 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3482 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3483 switchWeapon
:= WEAPON_SUPERPULEMET
;
3484 hadWeapon
:= FWeapon
[WEAPON_SUPERPULEMET
];
3485 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3486 FWeapon
[WEAPON_SUPERPULEMET
] := True;
3488 if gFlash
= 2 then Inc(FPickup
, 5);
3489 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3492 ITEM_WEAPON_FLAMETHROWER
:
3493 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
3495 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
3496 switchWeapon
:= WEAPON_FLAMETHROWER
;
3497 hadWeapon
:= FWeapon
[WEAPON_FLAMETHROWER
];
3498 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3499 FWeapon
[WEAPON_FLAMETHROWER
] := True;
3501 if gFlash
= 2 then Inc(FPickup
, 5);
3502 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3506 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3508 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3511 if gFlash
= 2 then Inc(FPickup
, 5);
3514 ITEM_AMMO_BULLETS_BOX
:
3515 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3517 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3520 if gFlash
= 2 then Inc(FPickup
, 5);
3524 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3526 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3529 if gFlash
= 2 then Inc(FPickup
, 5);
3532 ITEM_AMMO_SHELLS_BOX
:
3533 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3535 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
3538 if gFlash
= 2 then Inc(FPickup
, 5);
3542 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3544 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3547 if gFlash
= 2 then Inc(FPickup
, 5);
3550 ITEM_AMMO_ROCKET_BOX
:
3551 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3553 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
3556 if gFlash
= 2 then Inc(FPickup
, 5);
3560 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3562 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3565 if gFlash
= 2 then Inc(FPickup
, 5);
3569 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3571 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
3574 if gFlash
= 2 then Inc(FPickup
, 5);
3578 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
3580 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3583 if gFlash
= 2 then Inc(FPickup
, 5);
3587 if not(R_ITEM_BACKPACK
in FRulez
) or
3588 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
3589 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
3590 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
3591 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
3592 (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) then
3594 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
3595 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
3596 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
3597 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
3598 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
3600 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3601 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3602 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3603 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3604 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3605 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3606 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3607 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3608 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
3609 IncMax(FAmmo
[A_FUEL
], 50, FMaxAmmo
[A_FUEL
]);
3611 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
3614 if gFlash
= 2 then Inc(FPickup
, 5);
3618 if not(R_KEY_RED
in FRulez
) then
3620 Include(FRulez
, R_KEY_RED
);
3622 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3623 if gFlash
= 2 then Inc(FPickup
, 5);
3624 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3628 if not(R_KEY_GREEN
in FRulez
) then
3630 Include(FRulez
, R_KEY_GREEN
);
3632 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3633 if gFlash
= 2 then Inc(FPickup
, 5);
3634 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3638 if not(R_KEY_BLUE
in FRulez
) then
3640 Include(FRulez
, R_KEY_BLUE
);
3642 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3643 if gFlash
= 2 then Inc(FPickup
, 5);
3644 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3648 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
3650 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
3654 if gFlash
= 2 then Inc(FPickup
, 5);
3658 if FAir
< AIR_MAX
then
3663 if gFlash
= 2 then Inc(FPickup
, 5);
3668 if not (R_BERSERK
in FRulez
) then
3670 Include(FRulez
, R_BERSERK
);
3671 if (FBFGFireCounter
= -1) then
3673 FCurrWeap
:= WEAPON_KASTET
;
3675 FModel
.SetWeapon(WEAPON_KASTET
);
3680 if gFlash
= 2 then Inc(FPickup
, 5);
3682 FBerserk
:= gTime
+30000;
3687 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3689 if FHealth
< PLAYER_HP_SOFT
then FHealth
:= PLAYER_HP_SOFT
;
3690 FBerserk
:= gTime
+30000;
3698 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
3700 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
3704 if gFlash
= 2 then Inc(FPickup
, 5);
3708 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
3710 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
3714 if gFlash
= 2 then Inc(FPickup
, 5);
3718 if FArmor
< PLAYER_AP_LIMIT
then
3720 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
3723 if gFlash
= 2 then Inc(FPickup
, 5);
3727 if FJetFuel
< JET_MAX
then
3729 FJetFuel
:= JET_MAX
;
3732 if gFlash
= 2 then Inc(FPickup
, 5);
3736 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
3738 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
3741 if gFlash
= 2 then Inc(FPickup
, 5);
3745 if (shouldSwitch(switchWeapon
, hadWeapon
)) then
3746 QueueWeaponSwitch(switchWeapon
);
3749 procedure TPlayer
.Touch();
3753 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
3756 // Бросить флаг товарищу:
3757 if gGameSettings
.GameMode
= GM_CTF
then
3762 procedure TPlayer
.Push(vx
, vy
: Integer);
3764 if (not FPhysics
) and FGhost
then
3766 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
3767 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
3768 if g_Game_IsNet
and g_Game_IsServer
then
3769 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
3772 procedure TPlayer
.Reset(Force
: Boolean);
3778 FTime
[T_RESPAWN
] := 0;
3779 FTime
[T_FLAGCAP
] := 0;
3795 FSpectator
:= False;
3798 FSpectatePlayer
:= -1;
3799 FNoRespawn
:= False;
3801 FLives
:= gGameSettings
.MaxLives
;
3806 procedure TPlayer
.SoftReset();
3814 FBFGFireCounter
:= -1;
3822 SetAction(A_STAND
, True);
3825 function TPlayer
.GetRespawnPoint(): Byte;
3830 // На будущее: FSpawn - игрок уже играл и перерождается
3832 // Одиночная игра/кооператив
3833 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
3835 if Self
= gPlayer1
then
3837 // player 1 should try to spawn on the player 1 point
3838 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) > 0 then
3839 Exit(RESPAWNPOINT_PLAYER1
)
3840 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) > 0 then
3841 Exit(RESPAWNPOINT_PLAYER2
);
3843 else if Self
= gPlayer2
then
3845 // player 2 should try to spawn on the player 2 point
3846 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) > 0 then
3847 Exit(RESPAWNPOINT_PLAYER2
)
3848 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) > 0 then
3849 Exit(RESPAWNPOINT_PLAYER1
);
3853 // other players randomly pick either the first or the second point
3854 c
:= IfThen((Random(2) = 0), RESPAWNPOINT_PLAYER1
, RESPAWNPOINT_PLAYER2
);
3855 if g_Map_GetPointCount(c
) > 0 then
3857 // try the other one
3858 c
:= IfThen((c
= RESPAWNPOINT_PLAYER1
), RESPAWNPOINT_PLAYER2
, RESPAWNPOINT_PLAYER1
);
3859 if g_Map_GetPointCount(c
) > 0 then
3865 if gGameSettings
.GameMode
= GM_DM
then
3867 // try DM points first
3868 if g_Map_GetPointCount(RESPAWNPOINT_DM
) > 0 then
3869 Exit(RESPAWNPOINT_DM
);
3873 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
3875 // try team points first
3876 c
:= RESPAWNPOINT_DM
;
3877 if FTeam
= TEAM_RED
then
3878 c
:= RESPAWNPOINT_RED
3879 else if FTeam
= TEAM_BLUE
then
3880 c
:= RESPAWNPOINT_BLUE
;
3881 if g_Map_GetPointCount(c
) > 0 then
3885 // still haven't found a spawnpoint, try random shit
3886 Result
:= g_Map_GetRandomPointType();
3889 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
3891 RespawnPoint
: TRespawnPoint
;
3897 FBFGFireCounter
:= -1;
3904 if not g_Game_IsServer
then
3908 FWantsInGame
:= True;
3909 FJustTeleported
:= True;
3912 FTime
[T_RESPAWN
] := 0;
3916 // if server changes MaxLives we gotta be ready
3917 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
3919 // Еще нельзя возродиться:
3920 if FTime
[T_RESPAWN
] > gTime
then
3923 // Просрал все жизни:
3926 if not FSpectator
then Spectate(True);
3927 FWantsInGame
:= True;
3931 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
3932 begin // "Своя игра"
3933 // Берсерк не сохраняется между уровнями:
3934 FRulez
:= FRulez
-[R_BERSERK
];
3936 else // "Одиночная игра"/"Кооп"
3938 // Берсерк и ключи не сохраняются между уровнями:
3939 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
3942 // Получаем точку спауна игрока:
3943 c
:= GetRespawnPoint();
3948 // Воскрешение без оружия:
3951 FHealth
:= Round(PLAYER_HP_SOFT
* (FHandicap
/ 100));
3957 for a
:= WP_FIRST
to WP_LAST
do
3959 FWeapon
[a
] := False;
3963 FWeapon
[WEAPON_PISTOL
] := True;
3964 FWeapon
[WEAPON_KASTET
] := True;
3965 FCurrWeap
:= WEAPON_PISTOL
;
3968 FModel
.SetWeapon(FCurrWeap
);
3970 for b
:= A_BULLETS
to A_HIGH
do
3973 FAmmo
[A_BULLETS
] := 50;
3975 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
3976 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
3977 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
3978 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
3979 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
3981 if (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) and
3982 LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
) then
3983 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
3988 // Получаем координаты точки возрождения:
3989 if not g_Map_GetPoint(c
, RespawnPoint
) then
3991 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3995 // Установка координат и сброс всех параметров:
3996 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
3997 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
3998 FObj
.oldX
:= FObj
.X
; // don't interpolate after respawn
3999 FObj
.oldY
:= FObj
.Y
;
4005 FDirection
:= RespawnPoint
.Direction
;
4006 if FDirection
= TDirection
.D_LEFT
then
4011 SetAction(A_STAND
, True);
4012 FModel
.Direction
:= FDirection
;
4014 for a
:= Low(FTime
) to High(FTime
) do
4017 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4020 // Respawn invulnerability
4021 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.SpawnInvul
> 0) then
4023 FMegaRulez
[MR_INVUL
] := gTime
+ gGameSettings
.SpawnInvul
* 1000;
4024 FSpawnInvul
:= FMegaRulez
[MR_INVUL
];
4029 FCanJetpack
:= False;
4036 // Анимация возрождения:
4037 if (not gLoadGameMode
) and (not Silent
) then
4040 R_GFX_TELEPORT_FAST
,
4041 FObj
.X
+ PLAYER_RECT
.X
+ (PLAYER_RECT
.Width
div 2) - 32,
4042 FObj
.Y
+ PLAYER_RECT
.Y
+ (PLAYER_RECT
.Height
div 2) - 32
4047 FSpectator
:= False;
4050 FSpectatePlayer
:= -1;
4053 if (gPlayer1
= nil) and (gSpectLatchPID1
= FUID
) then
4055 if (gPlayer2
= nil) and (gSpectLatchPID2
= FUID
) then
4058 if g_Game_IsNet
then
4060 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4061 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4063 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4064 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4069 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4072 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4073 else if (not NoMove
) then
4075 GameX
:= gMapInfo
.Width
div 2;
4076 GameY
:= gMapInfo
.Height
div 2;
4085 FWantsInGame
:= False;
4091 if Self
= gPlayer1
then
4093 gSpectLatchPID1
:= FUID
;
4096 else if Self
= gPlayer2
then
4098 gSpectLatchPID2
:= FUID
;
4103 if g_Game_IsNet
then
4104 MH_SEND_PlayerStats(FUID
);
4107 procedure TPlayer
.SwitchNoClip
;
4111 FGhost
:= not FGhost
;
4112 FPhysics
:= not FGhost
;
4124 procedure TPlayer
.Run(Direction
: TDirection
);
4128 if MAX_RUNVEL
> 8 then
4132 if Direction
= TDirection
.D_LEFT
then
4134 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4135 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4138 if FObj
.Vel
.X
< MAX_RUNVEL
then
4139 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4141 // Возможно, пинаем куски:
4142 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4144 b
:= Abs(FObj
.Vel
.X
);
4145 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4146 for a
:= 0 to High(gGibs
) do
4148 if gGibs
[a
].alive
and
4149 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4150 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4153 if FObj
.Vel
.X
< 0 then
4155 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // налево
4159 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // направо
4161 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4169 procedure TPlayer
.SeeDown();
4171 SetAction(A_SEEDOWN
);
4173 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4175 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4178 procedure TPlayer
.SeeUp();
4182 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4184 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4187 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4195 A_ATTACK
: Prior
:= 2;
4196 A_SEEUP
: Prior
:= 1;
4197 A_SEEDOWN
: Prior
:= 1;
4198 A_ATTACKUP
: Prior
:= 2;
4199 A_ATTACKDOWN
: Prior
:= 2;
4204 if (Prior
> FActionPrior
) or Force
then
4205 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4207 FActionPrior
:= Prior
;
4208 FActionAnim
:= Action
;
4209 FActionForce
:= Force
;
4210 FActionChanged
:= True;
4213 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4216 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4218 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4219 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4220 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4221 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4224 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4228 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4230 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4231 if g_Game_IsServer
and g_Game_IsNet
then
4232 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4236 FJustTeleported
:= True;
4240 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4243 R_GFX_TELEPORT_FAST
,
4244 FObj
.X
+ PLAYER_RECT
.X
+ (PLAYER_RECT
.Width
div 2) - 32,
4245 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, 1,
4254 FObj
.X
:= X
-PLAYER_RECT
.X
;
4255 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4256 FObj
.oldX
:= FObj
.X
; // don't interpolate after respawn
4257 FObj
.oldY
:= FObj
.Y
;
4258 if FAlive
and FGhost
then
4264 if not g_Game_IsNet
then
4268 SetDirection(TDirection
.D_LEFT
);
4274 SetDirection(TDirection
.D_RIGHT
);
4280 if FDirection
= TDirection
.D_RIGHT
then
4282 SetDirection(TDirection
.D_LEFT
);
4287 SetDirection(TDirection
.D_RIGHT
);
4297 R_GFX_TELEPORT_FAST
,
4298 FObj
.X
+ PLAYER_RECT
.X
+ (PLAYER_RECT
.Width
div 2) - 32,
4299 FObj
.Y
+ PLAYER_RECT
.Y
+ (PLAYER_RECT
.Height
div 2) - 32
4302 if g_Game_IsServer
and g_Game_IsNet
then
4303 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4304 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4311 function nonz(a
: Single): Single;
4319 function TPlayer
.refreshCorpse(): Boolean;
4325 if FAlive
or FSpectator
then
4327 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
4329 for i
:= 0 to High(gCorpses
) do
4330 if gCorpses
[i
] <> nil then
4331 if gCorpses
[i
].FPlayerUID
= FUID
then
4339 function TPlayer
.getCameraObj(): TObj
;
4341 if (not FAlive
) and (not FSpectator
) and
4342 (FCorpse
>= 0) and (FCorpse
< Length(gCorpses
)) and
4343 (gCorpses
[FCorpse
] <> nil) and (gCorpses
[FCorpse
].FPlayerUID
= FUID
) then
4345 gCorpses
[FCorpse
].FObj
.slopeUpLeft
:= FObj
.slopeUpLeft
;
4346 Result
:= gCorpses
[FCorpse
].FObj
;
4354 procedure TPlayer
.PreUpdate();
4356 FSlopeOld
:= FObj
.slopeUpLeft
;
4357 FIncCamOld
:= FIncCam
;
4358 FObj
.oldX
:= FObj
.X
;
4359 FObj
.oldY
:= FObj
.Y
;
4362 procedure TPlayer
.Update();
4365 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4366 blockmon
, headwater
, dospawn
: Boolean;
4371 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4372 AnyServer
:= g_Game_IsServer
;
4374 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4375 DoLerp(NetInterpLevel
+ 1)
4381 if (FClientID
>= 0) and (NetClients
[FClientID
].Peer
<> nil) then
4383 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4384 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4385 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4396 if FPunchAnim
.played
then
4399 if FAlive
and (gFly
or FJetpack
) then
4402 if FDirection
= TDirection
.D_LEFT
then
4407 if FAlive
and (not FGhost
) then
4409 if FKeys
[KEY_UP
].Pressed
then
4411 if FKeys
[KEY_DOWN
].Pressed
then
4415 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4418 i
:= g_basic
.Sign(FIncCam
);
4419 FIncCam
:= Abs(FIncCam
);
4420 DecMin(FIncCam
, 5, 0);
4421 FIncCam
:= FIncCam
*i
;
4424 if gTime
mod (GAME_TICK
*2) <> 0 then
4426 if (FObj
.Vel
.X
= 0) and FAlive
then
4428 if FKeys
[KEY_LEFT
].Pressed
then
4429 Run(TDirection
.D_LEFT
);
4430 if FKeys
[KEY_RIGHT
].Pressed
then
4431 Run(TDirection
.D_RIGHT
);
4436 g_Obj_Move(@FObj
, True, True, True);
4437 positionChanged(); // this updates spatial accelerators
4443 FActionChanged
:= False;
4447 // Let alive player do some actions
4448 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
4449 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
4450 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire()
4456 if NetServer
then MH_SEND_PlayerStats(FUID
);
4459 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
4460 if FKeys
[KEY_JUMP
].Pressed
then Jump()
4463 if AnyServer
and FJetpack
then
4467 if NetServer
then MH_SEND_PlayerStats(FUID
);
4469 FCanJetpack
:= True;
4476 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
4478 if FKeys
[k
].Pressed
then
4486 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4489 if (FTime
[T_RESPAWN
] <= gTime
) and
4490 gGameOn
and (not FAlive
) then
4492 if (g_Player_GetCount() > 1) then
4496 gExit
:= EXIT_RESTART
;
4501 // Dead spectator actions
4504 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
4505 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
4509 if (FSpectatePlayer
>= High(gPlayers
)) then
4510 FSpectatePlayer
:= -1
4514 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
4515 if gPlayers
[I
] <> nil then
4516 if gPlayers
[I
].alive
then
4517 if gPlayers
[I
].UID
<> FUID
then
4519 FSpectatePlayer
:= I
;
4524 if not SetSpect
then FSpectatePlayer
:= -1;
4535 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
4537 FYTo
:= FObj
.Y
- 32;
4538 FSpectatePlayer
:= -1;
4540 if FKeys
[KEY_DOWN
].Pressed
then
4542 FYTo
:= FObj
.Y
+ 32;
4543 FSpectatePlayer
:= -1;
4545 if FKeys
[KEY_LEFT
].Pressed
then
4547 FXTo
:= FObj
.X
- 32;
4548 FSpectatePlayer
:= -1;
4550 if FKeys
[KEY_RIGHT
].Pressed
then
4552 FXTo
:= FObj
.X
+ 32;
4553 FSpectatePlayer
:= -1;
4556 if (FXTo
< -64) then
4558 else if (FXTo
> gMapInfo
.Width
+ 32) then
4559 FXTo
:= gMapInfo
.Width
+ 32;
4560 if (FYTo
< -72) then
4562 else if (FYTo
> gMapInfo
.Height
+ 32) then
4563 FYTo
:= gMapInfo
.Height
+ 32;
4568 g_Obj_Move(@FObj
, True, True, True);
4569 positionChanged(); // this updates spatial accelerators
4576 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
4577 if gPlayers
[FSpectatePlayer
] <> nil then
4578 if gPlayers
[FSpectatePlayer
].alive
then
4580 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
4581 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
4585 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
4586 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
4587 PANEL_BLOCKMON
, True);
4588 headwater
:= HeadInLiquid(0, 0);
4590 // Сопротивление воздуха:
4591 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
4592 if FObj
.Vel
.X
<> 0 then
4593 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
4595 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
4596 DecMin(FPain
, 5, 0);
4597 DecMin(FPickup
, 1, 0);
4599 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
4601 // Обнулить действия примочек, чтобы фон пропал
4602 FMegaRulez
[MR_SUIT
] := 0;
4603 FMegaRulez
[MR_INVUL
] := 0;
4604 FMegaRulez
[MR_INVIS
] := 0;
4605 Kill(K_FALLKILL
, 0, HIT_FALL
);
4612 if FCurrWeap
= WEAPON_SAW
then
4613 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
4614 FSawSoundSelect
.IsPlaying()) then
4615 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
4618 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
4619 (not FJetSoundOff
.IsPlaying()) then
4621 FJetSoundFly
.SetPosition(0);
4622 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
4625 for b
:= WP_FIRST
to WP_LAST
do
4626 if FReloading
[b
] > 0 then
4632 if FShellTimer
> -1 then
4633 if FShellTimer
= 0 then
4635 if FShellType
= SHELL_SHELL
then
4636 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4637 GameVelX
, GameVelY
-2, SHELL_SHELL
)
4638 else if FShellType
= SHELL_DBLSHELL
then
4640 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4641 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
4642 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4643 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
4646 end else Dec(FShellTimer
);
4648 if (FBFGFireCounter
> -1) then
4649 if FBFGFireCounter
= 0 then
4653 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
4654 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
4655 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
4656 yd
:= wy
+firediry();
4657 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
4658 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
4659 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
4660 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
4661 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
4664 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
4665 FBFGFireCounter
:= -1;
4668 FBFGFireCounter
:= 0
4670 Dec(FBFGFireCounter
);
4672 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
4674 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
4676 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
4679 if (headwater
or blockmon
) then
4685 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
4688 else if (FAir
mod 31 = 0) and not blockmon
then
4691 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
4694 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
4695 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
4697 end else if FAir
< AIR_DEF
then
4700 if FFireTime
> 0 then
4702 if BodyInLiquid(0, 0) then
4707 else if FMegaRulez
[MR_SUIT
] >= gTime
then
4709 if FMegaRulez
[MR_SUIT
] = gTime
then
4716 if FFirePainTime
<= 0 then
4718 if g_Game_IsServer
then
4719 Damage(2, FFireAttacker
, 0, 0, HIT_FLAME
);
4720 FFirePainTime
:= 12 - FFireTime
div 12;
4722 FFirePainTime
:= FFirePainTime
- 1;
4723 FFireTime
:= FFireTime
- 1;
4724 if ((FFireTime
mod 33) = 0) and (FMegaRulez
[MR_INVUL
] < gTime
) then
4725 FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
);
4726 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
4727 MH_SEND_PlayerStats(FUID
);
4731 if FDamageBuffer
> 0 then
4733 if FDamageBuffer
>= 9 then
4737 if FDamageBuffer
< 30 then i
:= 9
4738 else if FDamageBuffer
< 100 then i
:= 18
4742 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
4743 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
4744 FHealth
:= FHealth
-ii
;
4747 FHealth
:= FHealth
+FArmor
;
4752 if FHealth
<= 0 then
4753 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
4754 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
4755 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
4757 if FAlive
and ((FLastHit
<> HIT_FLAME
) or (FFireTime
<= 0)) then
4759 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
4760 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
4761 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
4762 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
4769 end; // if FAlive then ...
4771 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
4773 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
4774 FModel
.AnimState
.MinLength
:= i
;
4775 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
4777 if (FModel
.AnimState
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
4778 then SetAction(A_STAND
, True);
4780 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.GetFire()) then FModel
.Update
;
4782 for b
:= Low(FKeys
) to High(FKeys
) do
4783 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
4787 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
4789 x
:= FObj
.X
+PLAYER_RECT
.X
;
4790 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
4791 w
:= PLAYER_RECT
.Width
;
4792 h
:= PLAYER_RECT
.Height
;
4796 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
4798 if (dx
<> 0) or (dy
<> 0) then
4807 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
4809 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
4810 FObj
.Y
+PLAYER_RECT
.Y
,
4817 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
4819 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
4820 FObj
.Y
+PLAYER_RECT
.Y
,
4824 Panel
.Width
, Panel
.Height
);
4827 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
4829 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
4830 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
4831 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
4832 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
4835 function g_Player_ValidName(Name
: string): Boolean;
4841 if gPlayers
= nil then Exit
;
4843 for a
:= 0 to High(gPlayers
) do
4844 if gPlayers
[a
] <> nil then
4845 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
4852 procedure TPlayer
.SetDirection(Direction
: TDirection
);
4856 d
:= FModel
.Direction
;
4858 FModel
.Direction
:= Direction
;
4859 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
4861 FDirection
:= Direction
;
4864 function TPlayer
.GetKeys(): Byte;
4868 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
4869 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
4870 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
4872 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
4873 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
4876 procedure TPlayer
.Use();
4880 if FTime
[T_USE
] > gTime
then Exit
;
4882 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
4883 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
4885 for a
:= 0 to High(gPlayers
) do
4886 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
4887 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
4888 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
4889 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
4891 gPlayers
[a
].Touch();
4892 if g_Game_IsNet
and g_Game_IsServer
then
4893 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
4896 FTime
[T_USE
] := gTime
+120;
4899 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
4902 visible
: Boolean = True;
4903 WX
, WY
, XD
, YD
: Integer;
4915 if R_BERSERK
in FRulez
then
4917 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
4918 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
4919 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
4922 locobj
.rect
.Width
:= 39;
4923 locobj
.rect
.Height
:= 52;
4924 locobj
.Vel
.X
:= (xd
-wx
) div 2;
4925 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
4926 locobj
.Accel
.X
:= xd
-wx
;
4927 locobj
.Accel
.y
:= yd
-wy
;
4929 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
4930 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
4932 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
4936 FPain
:= min(FPain
+ 25, 50);
4938 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
4943 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
4944 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
4946 FSawSoundSelect
.Stop();
4948 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
4950 else if not FSawSoundHit
.IsPlaying() then
4952 FSawSoundSelect
.Stop();
4953 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
4959 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
4960 FFireAngle
:= FAngle
;
4961 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4962 GameVelX
, GameVelY
-2, SHELL_BULLET
);
4967 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
4968 FFireAngle
:= FAngle
;
4970 FShellType
:= SHELL_SHELL
;
4975 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
4976 FFireAngle
:= FAngle
;
4978 FShellType
:= SHELL_DBLSHELL
;
4983 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
4984 FFireAngle
:= FAngle
;
4985 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4986 GameVelX
, GameVelY
-2, SHELL_BULLET
);
4989 WEAPON_ROCKETLAUNCHER
:
4991 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
4992 FFireAngle
:= FAngle
;
4997 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
4998 FFireAngle
:= FAngle
;
5003 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5004 FFireAngle
:= FAngle
;
5007 WEAPON_SUPERPULEMET
:
5009 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5010 FFireAngle
:= FAngle
;
5011 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5012 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5015 WEAPON_FLAMETHROWER
:
5017 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5019 FFireAngle
:= FAngle
;
5023 if not visible
then Exit
;
5025 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5026 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5027 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5030 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5032 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5033 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5036 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5042 if FJustTeleported
or (NetInterpLevel
< 1) then
5046 if FJustTeleported
then
5048 FObj
.oldX
:= FObj
.X
;
5049 FObj
.oldY
:= FObj
.Y
;
5054 AX
:= Abs(FXTo
- FObj
.X
);
5055 AY
:= Abs(FYTo
- FObj
.Y
);
5056 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5058 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5063 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5065 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5066 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5067 PANEL_LIFTUP
, False) then Result
:= -1
5069 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5070 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5071 PANEL_LIFTDOWN
, False) then Result
:= 1
5075 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5082 if Flag
= FLAG_NONE
then
5085 if not g_Game_IsServer
then Exit
;
5087 // Принес чужой флаг на свою базу:
5088 if (Flag
= FTeam
) and
5089 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5090 (FFlag
<> FLAG_NONE
) then
5092 if FFlag
= FLAG_RED
then
5093 s
:= _lc
[I_PLAYER_FLAG_RED
]
5095 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5097 evtype
:= FLAG_STATE_SCORED
;
5099 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5100 Insert('.', ts
, Length(ts
) + 1 - 3);
5101 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5103 g_Map_ResetFlag(FFlag
);
5104 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5106 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5107 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5108 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5113 if not sound_cap_flag
[a
].IsPlaying() then
5114 sound_cap_flag
[a
].Play();
5116 gTeamStat
[FTeam
].Score
+= 1;
5119 if g_Game_IsNet
then
5121 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5125 gFlags
[FFlag
].CaptureTime
:= 0;
5130 // Подобрал свой флаг - вернул его на базу:
5131 if (Flag
= FTeam
) and
5132 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5134 if Flag
= FLAG_RED
then
5135 s
:= _lc
[I_PLAYER_FLAG_RED
]
5137 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5139 evtype
:= FLAG_STATE_RETURNED
;
5140 gFlags
[Flag
].CaptureTime
:= 0;
5142 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5144 g_Map_ResetFlag(Flag
);
5145 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5147 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5148 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5149 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5154 if not sound_ret_flag
[a
].IsPlaying() then
5155 sound_ret_flag
[a
].Play();
5158 if g_Game_IsNet
then
5160 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5166 // Подобрал чужой флаг:
5167 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5171 if Flag
= FLAG_RED
then
5172 s
:= _lc
[I_PLAYER_FLAG_RED
]
5174 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5176 evtype
:= FLAG_STATE_CAPTURED
;
5178 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5180 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5182 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5184 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5185 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5186 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5191 if not sound_get_flag
[a
].IsPlaying() then
5192 sound_get_flag
[a
].Play();
5195 if g_Game_IsNet
then
5197 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5203 procedure TPlayer
.SetFlag(Flag
: Byte);
5206 if FModel
<> nil then
5207 FModel
.SetFlag(FFlag
);
5210 function TPlayer
.TryDropFlag(): Boolean;
5212 if LongBool(gGameSettings
.Options
and GAME_OPTION_ALLOWDROPFLAG
) then
5213 Result
:= DropFlag(False, LongBool(gGameSettings
.Options
and GAME_OPTION_THROWFLAG
))
5218 function TPlayer
.DropFlag(Silent
: Boolean = True; DoThrow
: Boolean = False): Boolean;
5225 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5227 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5228 with gFlags
[FFlag
] do
5232 Direction
:= FDirection
;
5233 State
:= FLAG_STATE_DROPPED
;
5237 xv
:= FObj
.Vel
.X
+ IfThen(Direction
= TDirection
.D_RIGHT
, 10, -10);
5238 yv
:= FObj
.Vel
.Y
- 2;
5242 xv
:= (FObj
.Vel
.X
div 2);
5243 yv
:= (FObj
.Vel
.Y
div 2) - 2;
5245 g_Obj_Push(@Obj
, xv
, yv
);
5247 positionChanged(); // this updates spatial accelerators
5249 if FFlag
= FLAG_RED
then
5250 s
:= _lc
[I_PLAYER_FLAG_RED
]
5252 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5254 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5255 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5257 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5258 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5259 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5264 if (not Silent
) and (not sound_lost_flag
[a
].IsPlaying()) then
5265 sound_lost_flag
[a
].Play();
5267 if g_Game_IsNet
then
5268 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5274 procedure TPlayer
.GetSecret();
5276 if (self
= gPlayer1
) or (self
= gPlayer2
) then
5278 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [FName
]), True);
5279 g_Sound_PlayEx('SOUND_GAME_SECRET');
5284 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5286 Assert(Key
<= High(FKeys
));
5288 FKeys
[Key
].Pressed
:= True;
5289 FKeys
[Key
].Time
:= Time
;
5292 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5294 Result
:= FKeys
[K
].Pressed
;
5297 procedure TPlayer
.ReleaseKeys();
5301 for a
:= Low(FKeys
) to High(FKeys
) do
5303 FKeys
[a
].Pressed
:= False;
5308 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5312 function TPlayer
.firediry(): Integer;
5314 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5315 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5319 procedure TPlayer
.RememberState();
5322 SavedState
: TPlayerSavedState
;
5324 SavedState
.Health
:= FHealth
;
5325 SavedState
.Armor
:= FArmor
;
5326 SavedState
.Air
:= FAir
;
5327 SavedState
.JetFuel
:= FJetFuel
;
5328 SavedState
.CurrWeap
:= FCurrWeap
;
5329 SavedState
.NextWeap
:= FNextWeap
;
5330 SavedState
.NextWeapDelay
:= FNextWeapDelay
;
5331 for i
:= Low(FWeapon
) to High(FWeapon
) do
5332 SavedState
.Weapon
[i
] := FWeapon
[i
];
5333 for i
:= Low(FAmmo
) to High(FAmmo
) do
5334 SavedState
.Ammo
[i
] := FAmmo
[i
];
5335 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
5336 SavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5337 SavedState
.Rulez
:= FRulez
- [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5339 FSavedStateNum
:= -1;
5340 for i
:= Low(SavedStates
) to High(SavedStates
) do
5341 if not SavedStates
[i
].Used
then
5343 FSavedStateNum
:= i
;
5346 if FSavedStateNum
< 0 then
5348 SetLength(SavedStates
, Length(SavedStates
) + 1);
5349 FSavedStateNum
:= High(SavedStates
);
5352 SavedState
.Used
:= True;
5353 SavedStates
[FSavedStateNum
] := SavedState
;
5356 procedure TPlayer
.RecallState();
5359 SavedState
: TPlayerSavedState
;
5361 if(FSavedStateNum
< 0) or (FSavedStateNum
> High(SavedStates
)) then
5364 SavedState
:= SavedStates
[FSavedStateNum
];
5365 SavedStates
[FSavedStateNum
].Used
:= False;
5366 FSavedStateNum
:= -1;
5368 FHealth
:= SavedState
.Health
;
5369 FArmor
:= SavedState
.Armor
;
5370 FAir
:= SavedState
.Air
;
5371 FJetFuel
:= SavedState
.JetFuel
;
5372 FCurrWeap
:= SavedState
.CurrWeap
;
5373 FNextWeap
:= SavedState
.NextWeap
;
5374 FNextWeapDelay
:= SavedState
.NextWeapDelay
;
5375 for i
:= Low(FWeapon
) to High(FWeapon
) do
5376 FWeapon
[i
] := SavedState
.Weapon
[i
];
5377 for i
:= Low(FAmmo
) to High(FAmmo
) do
5378 FAmmo
[i
] := SavedState
.Ammo
[i
];
5379 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
5380 FMaxAmmo
[i
] := SavedState
.MaxAmmo
[i
];
5381 FRulez
:= SavedState
.Rulez
;
5383 if gGameSettings
.GameType
= GT_SERVER
then
5384 MH_SEND_PlayerStats(FUID
);
5387 procedure TPlayer
.SaveState (st
: TStream
);
5393 utils
.writeSign(st
, 'PLYR');
5394 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
5396 utils
.writeBool(st
, FIamBot
);
5398 utils
.writeInt(st
, Word(FUID
));
5400 utils
.writeStr(st
, FName
);
5402 utils
.writeInt(st
, Byte(FTeam
));
5404 utils
.writeBool(st
, FAlive
);
5405 // Израсходовал ли все жизни
5406 utils
.writeBool(st
, FNoRespawn
);
5408 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
5409 utils
.writeInt(st
, Byte(b
));
5411 utils
.writeInt(st
, LongInt(FHealth
));
5412 // Коэффициент инвалидности
5413 utils
.writeInt(st
, LongInt(FHandicap
));
5415 utils
.writeInt(st
, Byte(FLives
));
5417 utils
.writeInt(st
, LongInt(FArmor
));
5419 utils
.writeInt(st
, LongInt(FAir
));
5421 utils
.writeInt(st
, LongInt(FJetFuel
));
5423 utils
.writeInt(st
, LongInt(FPain
));
5425 utils
.writeInt(st
, LongInt(FKills
));
5427 utils
.writeInt(st
, LongInt(FMonsterKills
));
5429 utils
.writeInt(st
, LongInt(FFrags
));
5431 utils
.writeInt(st
, Byte(FFragCombo
));
5432 // Время последнего фрага
5433 utils
.writeInt(st
, LongWord(FLastFrag
));
5435 utils
.writeInt(st
, LongInt(FDeath
));
5437 utils
.writeInt(st
, Byte(FFlag
));
5439 utils
.writeInt(st
, LongInt(FSecrets
));
5441 utils
.writeInt(st
, Byte(FCurrWeap
));
5443 utils
.writeInt(st
, Word(FNextWeap
));
5445 utils
.writeInt(st
, Byte(FNextWeapDelay
));
5446 // Время зарядки BFG
5447 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
5449 utils
.writeInt(st
, LongInt(FDamageBuffer
));
5450 // Последний ударивший
5451 utils
.writeInt(st
, Word(FLastSpawnerUID
));
5452 // Тип последнего полученного урона
5453 utils
.writeInt(st
, Byte(FLastHit
));
5455 Obj_SaveState(st
, @FObj
);
5456 // Текущее количество патронов
5457 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
5458 // Максимальное количество патронов
5459 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
5461 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
5462 // Время перезарядки оружия
5463 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
5465 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
5466 // Наличие красного ключа
5467 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
5468 // Наличие зеленого ключа
5469 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
5470 // Наличие синего ключа
5471 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
5473 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
5474 // Время действия специальных предметов
5475 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
5476 // Время до повторного респауна, смены оружия, исользования, захвата флага
5477 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
5479 utils
.writeStr(st
, FModel
.GetName());
5481 utils
.writeInt(st
, Byte(FColor
.R
));
5482 utils
.writeInt(st
, Byte(FColor
.G
));
5483 utils
.writeInt(st
, Byte(FColor
.B
));
5487 procedure TPlayer
.LoadState (st
: TStream
);
5496 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
5497 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
5499 FIamBot
:= utils
.readBool(st
);
5501 FUID
:= utils
.readWord(st
);
5503 str
:= utils
.readStr(st
);
5504 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
5506 FTeam
:= utils
.readByte(st
);
5508 FAlive
:= utils
.readBool(st
);
5509 // Израсходовал ли все жизни
5510 FNoRespawn
:= utils
.readBool(st
);
5512 b
:= utils
.readByte(st
);
5513 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
5515 FHealth
:= utils
.readLongInt(st
);
5516 // Коэффициент инвалидности
5517 FHandicap
:= utils
.readLongInt(st
);
5519 FLives
:= utils
.readByte(st
);
5521 FArmor
:= utils
.readLongInt(st
);
5523 FAir
:= utils
.readLongInt(st
);
5525 FJetFuel
:= utils
.readLongInt(st
);
5527 FPain
:= utils
.readLongInt(st
);
5529 FKills
:= utils
.readLongInt(st
);
5531 FMonsterKills
:= utils
.readLongInt(st
);
5533 FFrags
:= utils
.readLongInt(st
);
5535 FFragCombo
:= utils
.readByte(st
);
5536 // Время последнего фрага
5537 FLastFrag
:= utils
.readLongWord(st
);
5539 FDeath
:= utils
.readLongInt(st
);
5541 FFlag
:= utils
.readByte(st
);
5543 FSecrets
:= utils
.readLongInt(st
);
5545 FCurrWeap
:= utils
.readByte(st
);
5547 FNextWeap
:= utils
.readWord(st
);
5549 FNextWeapDelay
:= utils
.readByte(st
);
5550 // Время зарядки BFG
5551 FBFGFireCounter
:= utils
.readSmallInt(st
);
5553 FDamageBuffer
:= utils
.readLongInt(st
);
5554 // Последний ударивший
5555 FLastSpawnerUID
:= utils
.readWord(st
);
5556 // Тип последнего полученного урона
5557 FLastHit
:= utils
.readByte(st
);
5559 Obj_LoadState(@FObj
, st
);
5560 // Текущее количество патронов
5561 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
5562 // Максимальное количество патронов
5563 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
5565 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
5566 // Время перезарядки оружия
5567 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
5569 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
5570 // Наличие красного ключа
5571 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
5572 // Наличие зеленого ключа
5573 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
5574 // Наличие синего ключа
5575 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
5577 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
5578 // Время действия специальных предметов
5579 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
5580 // Время до повторного респауна, смены оружия, исользования, захвата флага
5581 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
5583 str
:= utils
.readStr(st
);
5585 FColor
.R
:= utils
.readByte(st
);
5586 FColor
.G
:= utils
.readByte(st
);
5587 FColor
.B
:= utils
.readByte(st
);
5588 if (self
= gPlayer1
) then
5590 str
:= gPlayer1Settings
.Model
;
5591 FColor
:= gPlayer1Settings
.Color
;
5593 else if (self
= gPlayer2
) then
5595 str
:= gPlayer2Settings
.Model
;
5596 FColor
:= gPlayer2Settings
.Color
;
5598 // Обновляем модель игрока
5600 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
5601 FModel
.Color
:= TEAMCOLOR
[FTeam
]
5603 FModel
.Color
:= FColor
;
5607 procedure TPlayer
.AllRulez(Health
: Boolean);
5613 FHealth
:= PLAYER_HP_LIMIT
;
5614 FArmor
:= PLAYER_AP_LIMIT
;
5618 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
5619 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
5620 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5623 procedure TPlayer
.RestoreHealthArmor();
5625 FHealth
:= PLAYER_HP_LIMIT
;
5626 FArmor
:= PLAYER_AP_LIMIT
;
5629 procedure TPlayer
.FragCombo();
5633 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
5635 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
5637 if FFragCombo
< 5 then
5639 Param
:= FUID
or (FFragCombo
shl 16);
5640 if (FComboEvnt
>= Low(gDelayedEvents
)) and
5641 (FComboEvnt
<= High(gDelayedEvents
)) and
5642 gDelayedEvents
[FComboEvnt
].Pending
and
5643 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
5644 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
5646 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
5647 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
5650 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
5658 procedure TPlayer
.GiveItem(ItemType
: Byte);
5662 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
5664 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
5668 if FAir
< AIR_MAX
then
5675 if not (R_BERSERK
in FRulez
) then
5677 Include(FRulez
, R_BERSERK
);
5678 if FBFGFireCounter
< 1 then
5680 FCurrWeap
:= WEAPON_KASTET
;
5682 FModel
.SetWeapon(WEAPON_KASTET
);
5686 FBerserk
:= gTime
+30000;
5688 if FHealth
< PLAYER_HP_SOFT
then
5690 FHealth
:= PLAYER_HP_SOFT
;
5691 FBerserk
:= gTime
+30000;
5696 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
5698 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
5703 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
5705 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
5709 if FJetFuel
< JET_MAX
then
5711 FJetFuel
:= JET_MAX
;
5714 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
5715 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
5717 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
5718 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5720 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
5722 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
5724 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
5725 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5728 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
5729 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
5730 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
5731 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
5732 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
5733 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
5734 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
5735 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
5736 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
5738 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5739 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
5740 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5741 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
5742 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5743 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
5744 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5745 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
5746 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
5749 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
5750 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
5751 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
5752 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
5753 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
5755 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
5756 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
5757 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
5758 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
5759 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
5761 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5762 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5763 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5764 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5766 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
5769 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
5770 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
5771 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
5773 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
5774 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
5779 if g_Game_IsNet
and g_Game_IsServer
then
5780 MH_SEND_PlayerStats(FUID
);
5783 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
5786 if (Random(5) = 1) and (Times
= 1) then
5789 if BodyInLiquid(0, 0) then
5792 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
5793 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
5796 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5797 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5801 for i
:= 1 to Times
do
5806 Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(R_GFX_SMOKE_WIDTH
div 2),
5807 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2)
5813 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
5816 if (Random(10) = 1) and (Times
= 1) then
5819 for i
:= 1 to Times
do
5824 Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(R_GFX_FLAME_WIDTH
div 2),
5825 Obj
.Y
+8+Random(8+Times
*2)
5831 procedure TPlayer
.PauseSounds(Enable
: Boolean);
5833 FSawSound
.Pause(Enable
);
5834 FSawSoundIdle
.Pause(Enable
);
5835 FSawSoundHit
.Pause(Enable
);
5836 FSawSoundSelect
.Pause(Enable
);
5837 FFlameSoundOn
.Pause(Enable
);
5838 FFlameSoundOff
.Pause(Enable
);
5839 FFlameSoundWork
.Pause(Enable
);
5840 FJetSoundFly
.Pause(Enable
);
5841 FJetSoundOn
.Pause(Enable
);
5842 FJetSoundOff
.Pause(Enable
);
5847 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
5852 FObj
.Rect
:= PLAYER_CORPSERECT
;
5854 FModel
:= g_PlayerModel_Get(ModelName
);
5858 FState
:= CORPSE_STATE_MESS
;
5859 FModel
.ChangeAnimation(A_DIE2
);
5863 FState
:= CORPSE_STATE_NORMAL
;
5864 FModel
.ChangeAnimation(A_DIE1
);
5868 destructor TCorpse
.Destroy();
5874 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
5876 procedure TCorpse
.positionChanged (); inline; begin end;
5878 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
5880 if (dx
<> 0) or (dy
<> 0) then
5889 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5891 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
5892 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
5893 w
:= PLAYER_CORPSERECT
.Width
;
5894 h
:= PLAYER_CORPSERECT
.Height
;
5898 procedure TCorpse
.Damage(Value
: Word; SpawnerUID
: Word; vx
, vy
: Integer);
5900 var Blood
: TModelBlood
;
5903 if FState
= CORPSE_STATE_REMOVEME
then
5906 FDamage
:= FDamage
+ Value
;
5908 if FDamage
> 150 then
5910 if FModel
<> nil then
5912 FState
:= CORPSE_STATE_REMOVEME
;
5914 g_Player_CreateGibs(
5915 FObj
.X
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
div 2),
5916 FObj
.Y
+ FObj
.Rect
.Y
+ (FObj
.Rect
.Height
div 2),
5921 // Звук мяса от трупа:
5922 FModel
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
5925 if (gBodyKillEvent
<> -1) and gDelayedEvents
[gBodyKillEvent
].Pending
then
5926 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
5927 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, SpawnerUID
);
5935 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
5936 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
5938 Blood
:= FModel
.GetBlood();
5939 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
5940 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
5941 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
5942 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
5947 procedure TCorpse
.Update();
5951 if FState
= CORPSE_STATE_REMOVEME
then
5954 FObj
.oldX
:= FObj
.X
;
5955 FObj
.oldY
:= FObj
.Y
;
5957 if gTime
mod (GAME_TICK
*2) <> 0 then
5959 g_Obj_Move(@FObj
, True, True, True);
5960 positionChanged(); // this updates spatial accelerators
5964 // Сопротивление воздуха для трупа:
5965 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5967 st
:= g_Obj_Move(@FObj
, True, True, True);
5968 positionChanged(); // this updates spatial accelerators
5970 if WordBool(st
and MOVE_FALLOUT
) then
5972 FState
:= CORPSE_STATE_REMOVEME
;
5976 if FModel
<> nil then
5981 procedure TCorpse
.SaveState (st
: TStream
);
5987 utils
.writeSign(st
, 'CORP');
5988 utils
.writeInt(st
, Byte(0));
5990 utils
.writeInt(st
, Byte(FState
));
5992 utils
.writeInt(st
, Byte(FDamage
));
5994 utils
.writeInt(st
, Byte(FModel
.Color
.R
));
5995 utils
.writeInt(st
, Byte(FModel
.Color
.G
));
5996 utils
.writeInt(st
, Byte(FModel
.Color
.B
));
5998 Obj_SaveState(st
, @FObj
);
5999 utils
.writeInt(st
, Word(FPlayerUID
));
6001 anim
:= (FModel
<> nil);
6002 utils
.writeBool(st
, anim
);
6003 if anim
then FModel
.AnimState
.SaveState(st
, 0, False);
6004 // animation for mask (same as animation, compat with older saves)
6005 anim
:= (FModel
<> nil);
6006 utils
.writeBool(st
, anim
);
6007 if anim
then FModel
.AnimState
.SaveState(st
, 0, False);
6011 procedure TCorpse
.LoadState (st
: TStream
);
6012 var anim
, blending
: Boolean; r
, g
, b
, alpha
: Byte; stub
: TAnimationState
;
6017 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6018 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6020 FState
:= utils
.readByte(st
);
6022 FDamage
:= utils
.readByte(st
);
6024 r
:= utils
.readByte(st
);
6025 g
:= utils
.readByte(st
);
6026 b
:= utils
.readByte(st
);
6027 FModel
.SetColor(r
, g
, b
);
6029 Obj_LoadState(@FObj
, st
);
6030 FPlayerUID
:= utils
.readWord(st
);
6032 stub
:= TAnimationState
.Create(False, 0, 0);
6033 anim
:= utils
.readBool(st
);
6036 stub
.LoadState(st
, alpha
, blending
);
6037 FModel
.AnimState
.CurrentFrame
:= Min(stub
.CurrentFrame
, FModel
.AnimState
.Length
);
6044 // animation for mask (same as animation, compat with older saves)
6045 anim
:= utils
.readBool(st
);
6046 if anim
then stub
.LoadState(st
, alpha
, blending
);
6052 constructor TBot
.Create();
6059 FSpectator
:= False;
6066 for a
:= WP_FIRST
to WP_LAST
do
6068 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6069 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6070 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6074 destructor TBot
.Destroy();
6077 inherited Destroy();
6080 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6082 inherited Respawn(Silent
, Force
);
6085 FSelectedWeapon
:= FCurrWeap
;
6090 procedure TBot
.UpdateCombat();
6103 TTargetRecord
= array of TTarget
;
6105 function Compare(a
, b
: TTarget
): Integer;
6107 if a
.Line
and not b
.Line
then // A на линии огня
6110 if not a
.Line
and b
.Line
then // B на линии огня
6112 else // И A, и B на линии или не на линии огня
6113 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6115 if a
.Dist
> b
.Dist
then // B ближе
6117 else // A ближе или равноудаленно с B
6120 else // Странно -> A
6125 a
, x1
, y1
, x2
, y2
: Integer;
6126 targets
: TTargetRecord
;
6128 Target
, BestTarget
: TTarget
;
6129 firew
, fireh
: Integer;
6133 vsPlayer
, vsMonster
, ok
: Boolean;
6136 function monsUpdate (mon
: TMonster
): Boolean;
6138 result
:= false; // don't stop
6139 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6141 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6143 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6144 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6146 // Если монстр на экране и не прикрыт стеной
6147 if g_TraceVector(x1
, y1
, x2
, y2
) then
6149 // Добавляем к списку возможных целей
6150 SetLength(targets
, Length(targets
)+1);
6151 with targets
[High(targets
)] do
6158 Rect
:= mon
.Obj
.Rect
;
6159 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6160 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6161 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6170 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6171 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6173 // Если текущее оружие не то, что нужно, то меняем:
6174 if FCurrWeap
<> FSelectedWeapon
then
6177 // Если нужно стрелять и нужное оружие, то нажать "Стрелять":
6178 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6180 RemoveAIFlag('NEEDFIRE');
6183 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6184 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6185 else PressKey(KEY_FIRE
);
6189 // Координаты ствола:
6190 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6191 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6193 Target
.UID
:= FTargetUID
;
6196 if Target
.UID
<> 0 then
6197 begin // Цель есть - настраиваем
6198 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6201 tpla
:= g_Player_Get(Target
.UID
);
6205 if (@FObj
) <> nil then
6212 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6213 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6214 Target
.Rect
:= PLAYER_RECT
;
6215 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6216 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6217 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6218 Target
.IsPlayer
:= True;
6222 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6225 mon
:= g_Monsters_ByUID(Target
.UID
);
6228 Target
.X
:= mon
.Obj
.X
;
6229 Target
.Y
:= mon
.Obj
.Y
;
6231 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6232 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6233 Target
.Rect
:= mon
.Obj
.Rect
;
6234 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6235 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6236 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6237 Target
.IsPlayer
:= False;
6244 begin // Цели нет - обнуляем
6249 Target
.Visible
:= False;
6250 Target
.Line
:= False;
6251 Target
.IsPlayer
:= False;
6256 // Если цель не видима или не на линии огня, то ищем все возможные цели:
6257 if (not Target
.Line
) or (not Target
.Visible
) then
6261 for a
:= 0 to High(gPlayers
) do
6262 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6263 (gPlayers
[a
].FUID
<> FUID
) and
6264 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6265 (not gPlayers
[a
].NoTarget
) and
6266 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6268 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6269 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6272 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6273 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6275 // Если игрок на экране и не прикрыт стеной:
6276 if g_TraceVector(x1
, y1
, x2
, y2
) then
6278 // Добавляем к списку возможных целей:
6279 SetLength(targets
, Length(targets
)+1);
6280 with targets
[High(targets
)] do
6282 UID
:= gPlayers
[a
].FUID
;
6283 X
:= gPlayers
[a
].FObj
.X
;
6284 Y
:= gPlayers
[a
].FObj
.Y
;
6287 Rect
:= PLAYER_RECT
;
6288 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6289 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6290 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6298 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6301 // Если есть возможные цели:
6302 // (Выбираем лучшую, меняем оружие и бежим к ней/от нее)
6303 if targets
<> nil then
6305 // Выбираем наилучшую цель:
6306 BestTarget
:= targets
[0];
6307 if Length(targets
) > 1 then
6308 for a
:= 1 to High(targets
) do
6309 if Compare(BestTarget
, targets
[a
]) = 1 then
6310 BestTarget
:= targets
[a
];
6312 // Если лучшая цель "виднее" текущей, то текущая := лучшая:
6313 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6314 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6316 Target
:= BestTarget
;
6318 if (Healthy() = 3) or ((Healthy() = 2)) then
6319 begin // Если здоровы - догоняем
6320 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6321 SetAIFlag('GORIGHT', '1');
6322 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6323 SetAIFlag('GOLEFT', '1');
6326 begin // Если побиты - убегаем
6327 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6328 SetAIFlag('GORIGHT', '1');
6329 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6330 SetAIFlag('GOLEFT', '1');
6333 // Выбираем оружие на основе расстояния и приоритетов:
6334 SelectWeapon(Abs(x1
-Target
.cX
));
6339 // (Догоняем/убегаем, стреляем по направлению к цели)
6340 // (Если цель далеко, то хватит следить за ней)
6341 if Target
.UID
<> 0 then
6343 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6344 Target
.Y
+ Target
.Rect
.Y
) then
6345 begin // Цель сбежала с "экрана"
6346 if (Healthy() = 3) or ((Healthy() = 2)) then
6347 begin // Если здоровы - догоняем
6348 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6349 SetAIFlag('GORIGHT', '1');
6350 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6351 SetAIFlag('GOLEFT', '1');
6354 begin // Если побиты - забываем о цели и убегаем
6356 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6357 SetAIFlag('GORIGHT', '1');
6358 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6359 SetAIFlag('GOLEFT', '1');
6363 begin // Цель пока на "экране"
6364 // Если цель не загорожена стеной, то отмечаем, когда ее видели:
6365 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6366 FLastVisible
:= gTime
;
6367 // Если разница высот не велика, то догоняем:
6368 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6370 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6371 SetAIFlag('GORIGHT', '1');
6372 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6373 SetAIFlag('GOLEFT', '1');
6377 // Выбираем угол вверх:
6378 if FDirection
= TDirection
.D_LEFT
then
6379 angle
:= ANGLE_LEFTUP
6381 angle
:= ANGLE_RIGHTUP
;
6383 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6384 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6386 // Если при угле вверх можно попасть в приблизительное положение цели:
6387 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6388 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6389 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6390 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6391 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6392 begin // то нужно стрелять вверх
6393 SetAIFlag('NEEDFIRE', '1');
6394 SetAIFlag('NEEDSEEUP', '1');
6397 // Выбираем угол вниз:
6398 if FDirection
= TDirection
.D_LEFT
then
6399 angle
:= ANGLE_LEFTDOWN
6401 angle
:= ANGLE_RIGHTDOWN
;
6403 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6404 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6406 // Если при угле вниз можно попасть в приблизительное положение цели:
6407 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6408 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6409 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6410 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6411 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6412 begin // то нужно стрелять вниз
6413 SetAIFlag('NEEDFIRE', '1');
6414 SetAIFlag('NEEDSEEDOWN', '1');
6417 // Если цель видно и она на такой же высоте:
6418 if Target
.Visible
and
6419 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6420 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6422 // Если идем в сторону цели, то надо стрелять:
6423 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
6424 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6425 begin // то нужно стрелять вперед
6426 SetAIFlag('NEEDFIRE', '1');
6427 SetAIFlag('NEEDSEEDOWN', '');
6428 SetAIFlag('NEEDSEEUP', '');
6430 // Если цель в пределах "экрана" и сложность позволяет прыжки сближения:
6431 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6432 if GetRnd(FDifficult
.CloseJump
) then
6433 begin // то если повезет - прыгаем (особенно, если близко)
6434 if Abs(FObj
.X
-Target
.X
) < 128 then
6438 if Random(a
) = 0 then
6439 SetAIFlag('NEEDJUMP', '1');
6443 // Если цель все еще есть:
6444 if Target
.UID
<> 0 then
6445 if gTime
-FLastVisible
> 2000 then // Если видели давно
6446 Target
.UID
:= 0 // то забыть цель
6447 else // Если видели недавно
6448 begin // но цель убили
6449 if Target
.IsPlayer
then
6450 begin // Цель - игрок
6451 pla
:= g_Player_Get(Target
.UID
);
6452 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
6453 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6454 Target
.UID
:= 0; // то забыть цель
6457 begin // Цель - монстр
6458 mon
:= g_Monsters_ByUID(Target
.UID
);
6459 if (mon
= nil) or (not mon
.alive
) then
6460 Target
.UID
:= 0; // то забыть цель
6463 end; // if Target.UID <> 0
6465 FTargetUID
:= Target
.UID
;
6467 // Если возможных целей нет:
6468 // (Атака чего-нибудь слева или справа)
6469 if targets
= nil then
6470 if GetAIFlag('ATTACKLEFT') <> '' then
6471 begin // Если нужно атаковать налево
6472 RemoveAIFlag('ATTACKLEFT');
6474 SetAIFlag('NEEDJUMP', '1');
6476 if RunDirection() = TDirection
.D_RIGHT
then
6477 begin // Идем не в ту сторону
6478 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6479 begin // Если здоровы, то, возможно, стреляем бежим влево и стреляем
6480 SetAIFlag('NEEDFIRE', '1');
6481 SetAIFlag('GOLEFT', '1');
6485 begin // Идем в нужную сторону
6486 if GetRnd(FDifficult
.InvisFire
) then // Возможно, стреляем вслепую
6487 SetAIFlag('NEEDFIRE', '1');
6488 if Healthy() <= 1 then // Побиты - убегаем
6489 SetAIFlag('GORIGHT', '1');
6493 if GetAIFlag('ATTACKRIGHT') <> '' then
6494 begin // Если нужно атаковать направо
6495 RemoveAIFlag('ATTACKRIGHT');
6497 SetAIFlag('NEEDJUMP', '1');
6499 if RunDirection() = TDirection
.D_LEFT
then
6500 begin // Идем не в ту сторону
6501 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6502 begin // Если здоровы, то, возможно, бежим вправо и стреляем
6503 SetAIFlag('NEEDFIRE', '1');
6504 SetAIFlag('GORIGHT', '1');
6509 if GetRnd(FDifficult
.InvisFire
) then // Возможно, стреляем вслепую
6510 SetAIFlag('NEEDFIRE', '1');
6511 if Healthy() <= 1 then // Побиты - убегаем
6512 SetAIFlag('GOLEFT', '1');
6516 //HACK! (does it belongs there?)
6517 RealizeCurrentWeapon();
6519 // Если есть возможные цели:
6520 // (Стреляем по направлению к целям)
6521 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6522 for a
:= 0 to High(targets
) do
6524 // Если можем стрелять по диагонали:
6525 if GetRnd(FDifficult
.DiagFire
) then
6527 // Ищем цель сверху и стреляем, если есть:
6528 if FDirection
= TDirection
.D_LEFT
then
6529 angle
:= ANGLE_LEFTUP
6531 angle
:= ANGLE_RIGHTUP
;
6533 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6534 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6536 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6537 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6538 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6539 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6540 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6542 SetAIFlag('NEEDFIRE', '1');
6543 SetAIFlag('NEEDSEEUP', '1');
6546 // Ищем цель снизу и стреляем, если есть:
6547 if FDirection
= TDirection
.D_LEFT
then
6548 angle
:= ANGLE_LEFTDOWN
6550 angle
:= ANGLE_RIGHTDOWN
;
6552 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6553 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6555 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6556 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6557 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6558 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6559 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6561 SetAIFlag('NEEDFIRE', '1');
6562 SetAIFlag('NEEDSEEDOWN', '1');
6566 // Если цель "перед носом", то стреляем:
6567 if targets
[a
].Line
and targets
[a
].Visible
and
6568 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
6569 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
6571 SetAIFlag('NEEDFIRE', '1');
6576 // Если летит пуля, то, возможно, подпрыгиваем:
6577 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
6578 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
6579 40+GetInterval(FDifficult
.Cover
, 40)) then
6580 SetAIFlag('NEEDJUMP', '1');
6582 // Если кончились паторны, то нужно сменить оружие:
6583 ammo
:= GetAmmoByWeapon(FCurrWeap
);
6584 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
6585 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
6587 SetAIFlag('SELECTWEAPON', '1');
6589 // Если нужно сменить оружие, то выбираем нужное:
6590 if GetAIFlag('SELECTWEAPON') = '1' then
6593 RemoveAIFlag('SELECTWEAPON');
6597 procedure TBot
.Update();
6610 // Проверяем, отключён ли AI ботов
6611 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
6613 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
6615 if g_debug_BotAIOff
= 3 then
6625 RealizeCurrentWeapon();
6632 procedure TBot
.ReleaseKey(Key
: Byte);
6641 function TBot
.KeyPressed(Key
: Word): Boolean;
6643 Result
:= FKeys
[Key
].Pressed
;
6646 function TBot
.GetAIFlag(aName
: String20
): String20
;
6652 aName
:= LowerCase(aName
);
6654 if FAIFlags
<> nil then
6655 for a
:= 0 to High(FAIFlags
) do
6656 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6658 Result
:= FAIFlags
[a
].Value
;
6663 procedure TBot
.RemoveAIFlag(aName
: String20
);
6667 if FAIFlags
= nil then Exit
;
6669 aName
:= LowerCase(aName
);
6671 for a
:= 0 to High(FAIFlags
) do
6672 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6674 if a
<> High(FAIFlags
) then
6675 for b
:= a
to High(FAIFlags
)-1 do
6676 FAIFlags
[b
] := FAIFlags
[b
+1];
6678 SetLength(FAIFlags
, Length(FAIFlags
)-1);
6683 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
6691 aName
:= LowerCase(aName
);
6693 if FAIFlags
<> nil then
6694 for a
:= 0 to High(FAIFlags
) do
6695 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6701 if ok
then FAIFlags
[a
].Value
:= fValue
6704 SetLength(FAIFlags
, Length(FAIFlags
)+1);
6705 with FAIFlags
[High(FAIFlags
)] do
6713 procedure TBot
.UpdateMove
;
6715 procedure GoLeft(Time
: Word = 1);
6717 ReleaseKey(KEY_LEFT
);
6718 ReleaseKey(KEY_RIGHT
);
6719 PressKey(KEY_LEFT
, Time
);
6720 SetDirection(TDirection
.D_LEFT
);
6723 procedure GoRight(Time
: Word = 1);
6725 ReleaseKey(KEY_LEFT
);
6726 ReleaseKey(KEY_RIGHT
);
6727 PressKey(KEY_RIGHT
, Time
);
6728 SetDirection(TDirection
.D_RIGHT
);
6731 function Rnd(a
: Word): Boolean;
6733 Result
:= Random(a
) = 0;
6736 procedure Turn(Time
: Word = 1200);
6738 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
6743 ReleaseKey(KEY_LEFT
);
6744 ReleaseKey(KEY_RIGHT
);
6747 function CanRunLeft(): Boolean;
6749 Result
:= not CollideLevel(-1, 0);
6752 function CanRunRight(): Boolean;
6754 Result
:= not CollideLevel(1, 0);
6757 function CanRun(): Boolean;
6759 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
6762 procedure Jump(Time
: Word = 30);
6764 PressKey(KEY_JUMP
, Time
);
6767 function NearHole(): Boolean;
6771 { TODO 5 : Лестницы }
6772 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
6773 for x
:= 1 to PLAYER_RECT
.Width
do
6774 if (not StayOnStep(x
*sx
, 0)) and
6775 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6776 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6785 function BorderHole(): Boolean;
6789 { TODO 5 : Лестницы }
6790 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
6791 for x
:= 1 to PLAYER_RECT
.Width
do
6792 if (not StayOnStep(x
*sx
, 0)) and
6793 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6794 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6796 for xx
:= x
to x
+32 do
6797 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
6807 function NearDeepHole(): Boolean;
6813 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
6816 for x
:= 1 to PLAYER_RECT
.Width
do
6817 if (not StayOnStep(x
*sx
, 0)) and
6818 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6819 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6821 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6823 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
6828 end else Result
:= False;
6831 function OverDeepHole(): Boolean;
6838 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6840 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
6847 function OnGround(): Boolean;
6849 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
6852 function OnLadder(): Boolean;
6854 Result
:= FullInStep(0, 0);
6857 function BelowLadder(): Boolean;
6859 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
6860 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
6861 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
6862 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
6865 function BelowLiftUp(): Boolean;
6867 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
6868 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
6869 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
6870 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
6873 function OnTopLift(): Boolean;
6875 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
6878 function CanJumpOver(): Boolean;
6882 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
6886 if not CollideLevel(sx
, 0) then Exit
;
6888 for y
:= 1 to BOT_MAXJUMP
do
6889 if CollideLevel(0, -y
) then Exit
else
6890 if not CollideLevel(sx
, -y
) then
6897 function CanJumpUp(Dist
: ShortInt): Boolean;
6904 if CollideLevel(Dist
, 0) then Exit
;
6907 for y
:= 0 to BOT_MAXJUMP
do
6908 if CollideLevel(Dist
, -y
) then
6917 for yy
:= y
+1 to BOT_MAXJUMP
do
6918 if not CollideLevel(Dist
, -yy
) then
6927 for y
:= 0 to BOT_MAXJUMP
do
6928 if CollideLevel(0, -y
) then
6936 if y
< yy
then Exit
;
6941 function IsSafeTrigger(): Boolean;
6946 if gTriggers
= nil then
6948 for a
:= 0 to High(gTriggers
) do
6949 if Collide(gTriggers
[a
].X
,
6952 gTriggers
[a
].Height
) and
6953 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
6954 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
6955 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
6956 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
6957 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
6962 // Возможно, нажимаем кнопку:
6963 if Rnd(16) and IsSafeTrigger() then
6966 // Если под лифтом или ступеньками, то, возможно, прыгаем:
6967 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
6969 ReleaseKey(KEY_LEFT
);
6970 ReleaseKey(KEY_RIGHT
);
6974 // Идем влево, если надо было:
6975 if GetAIFlag('GOLEFT') <> '' then
6977 RemoveAIFlag('GOLEFT');
6978 if CanRunLeft() then
6982 // Идем вправо, если надо было:
6983 if GetAIFlag('GORIGHT') <> '' then
6985 RemoveAIFlag('GORIGHT');
6986 if CanRunRight() then
6990 // Если вылетели за карту, то пробуем вернуться:
6991 if FObj
.X
< -32 then
6994 if FObj
.X
+32 > gMapInfo
.Width
then
6997 // Прыгаем, если надо было:
6998 if GetAIFlag('NEEDJUMP') <> '' then
7001 RemoveAIFlag('NEEDJUMP');
7004 // Смотрим вверх, если надо было:
7005 if GetAIFlag('NEEDSEEUP') <> '' then
7008 ReleaseKey(KEY_DOWN
);
7009 PressKey(KEY_UP
, 20);
7010 RemoveAIFlag('NEEDSEEUP');
7013 // Смотрим вниз, если надо было:
7014 if GetAIFlag('NEEDSEEDOWN') <> '' then
7017 ReleaseKey(KEY_DOWN
);
7018 PressKey(KEY_DOWN
, 20);
7019 RemoveAIFlag('NEEDSEEDOWN');
7022 // Если нужно было в дыру и мы не на земле, то покорно летим:
7023 if GetAIFlag('GOINHOLE') <> '' then
7024 if not OnGround() then
7026 ReleaseKey(KEY_LEFT
);
7027 ReleaseKey(KEY_RIGHT
);
7028 RemoveAIFlag('GOINHOLE');
7029 SetAIFlag('FALLINHOLE', '1');
7032 // Если падали и достигли земли, то хватит падать:
7033 if GetAIFlag('FALLINHOLE') <> '' then
7035 RemoveAIFlag('FALLINHOLE');
7037 // Если летели прямо и сейчас не на лестнице или на вершине лифта, то отходим в сторону:
7038 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7039 if GetAIFlag('FALLINHOLE') = '' then
7040 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7046 // Если на земле и можно подпрыгнуть, то, возможно, прыгаем:
7048 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7052 // Если на земле и возле дыры (глубина > 2 ростов игрока):
7053 if OnGround() and NearHole() then
7054 if NearDeepHole() then // Если это бездна
7056 0..3: Turn(); // Бежим обратно
7057 4: Jump(); // Прыгаем
7058 5: begin // Прыгаем обратно
7063 else // Это не бездна и мы еще не летим туда
7064 if GetAIFlag('GOINHOLE') = '' then
7066 0: Turn(); // Не нужно туда
7067 1: Jump(); // Вдруг повезет - прыгаем
7068 else // Если яма с границей, то при случае можно туда прыгнуть
7069 if BorderHole() then
7070 SetAIFlag('GOINHOLE', '1');
7073 // Если на земле, но некуда идти:
7074 if (not CanRun()) and OnGround() then
7076 // Если мы на лестнице или можно перепрыгнуть, то прыгаем:
7077 if CanJumpOver() or OnLadder() then
7079 else // иначе попытаемся в другую сторону
7080 if Random(2) = 0 then
7082 if IsSafeTrigger() then
7088 // Осталось мало воздуха:
7089 if FAir
< 36 * 2 then
7092 // Выбираемся из кислоты, если нет костюма, обожглись, или мало здоровья:
7093 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7094 if BodyInAcid(0, 0) then
7098 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7100 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7101 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7104 {function TBot.NeedItem(Item: Byte): Byte;
7109 procedure TBot
.SelectWeapon(Dist
: Integer);
7113 function HaveAmmo(weapon
: Byte): Boolean;
7116 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7117 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7118 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7119 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7120 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7121 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7122 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7123 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7124 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7125 else Result
:= True;
7130 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7132 if Dist
> BOT_LONGDIST
then
7133 begin // Дальний бой
7135 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7137 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7141 else //if Dist > BOT_UNSAFEDIST then
7142 begin // Ближний бой
7144 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7146 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7153 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7155 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7161 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7163 Result
:= inherited PickItem(ItemType
, force
, remove
);
7165 if Result
then SetAIFlag('SELECTWEAPON', '1');
7168 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7170 Result
:= inherited Heal(value
, Soft
);
7173 function TBot
.Healthy(): Byte;
7175 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7176 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7177 else if (FHealth
> 50) then Result
:= 2
7178 else if (FHealth
> 20) then Result
:= 1
7182 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7184 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7185 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7188 procedure TBot
.OnDamage(Angle
: SmallInt);
7196 if (Angle
= 0) or (Angle
= 180) then
7199 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7200 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7202 pla
:= g_Player_Get(FLastSpawnerUID
);
7203 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7204 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7207 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7208 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7210 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7211 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7212 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7217 SetAIFlag('ATTACKLEFT', '1')
7219 SetAIFlag('ATTACKRIGHT', '1');
7223 function TBot
.RunDirection(): TDirection
;
7225 if Abs(Vel
.X
) >= 1 then
7227 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7229 Result
:= FDirection
;
7232 function TBot
.GetRnd(a
: Byte): Boolean;
7234 if a
= 0 then Result
:= False
7235 else if a
= 255 then Result
:= True
7236 else Result
:= Random(256) > 255-a
;
7239 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7241 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7245 procedure TDifficult
.save (st
: TStream
);
7247 utils
.writeInt(st
, Byte(DiagFire
));
7248 utils
.writeInt(st
, Byte(InvisFire
));
7249 utils
.writeInt(st
, Byte(DiagPrecision
));
7250 utils
.writeInt(st
, Byte(FlyPrecision
));
7251 utils
.writeInt(st
, Byte(Cover
));
7252 utils
.writeInt(st
, Byte(CloseJump
));
7253 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7254 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7257 procedure TDifficult
.load (st
: TStream
);
7259 DiagFire
:= utils
.readByte(st
);
7260 InvisFire
:= utils
.readByte(st
);
7261 DiagPrecision
:= utils
.readByte(st
);
7262 FlyPrecision
:= utils
.readByte(st
);
7263 Cover
:= utils
.readByte(st
);
7264 CloseJump
:= utils
.readByte(st
);
7265 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7266 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7270 procedure TBot
.SaveState (st
: TStream
);
7275 inherited SaveState(st
);
7276 utils
.writeSign(st
, 'BOT0');
7278 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7280 utils
.writeInt(st
, Word(FTargetUID
));
7281 // Время потери цели
7282 utils
.writeInt(st
, LongWord(FLastVisible
));
7283 // Количество флагов ИИ
7284 dw
:= Length(FAIFlags
);
7285 utils
.writeInt(st
, LongInt(dw
));
7287 for i
:= 0 to dw
-1 do
7289 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7290 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7292 // Настройки сложности
7293 FDifficult
.save(st
);
7297 procedure TBot
.LoadState (st
: TStream
);
7302 inherited LoadState(st
);
7303 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7305 FSelectedWeapon
:= utils
.readByte(st
);
7307 FTargetUID
:= utils
.readWord(st
);
7308 // Время потери цели
7309 FLastVisible
:= utils
.readLongWord(st
);
7310 // Количество флагов ИИ
7311 dw
:= utils
.readLongInt(st
);
7312 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7313 SetLength(FAIFlags
, dw
);
7315 for i
:= 0 to dw
-1 do
7317 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7318 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7320 // Настройки сложности
7321 FDifficult
.load(st
);
7326 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');
7327 conRegVar('player_indicator_style', @gPlayerIndicatorStyle
, 'Visual appearance of indicator', 'Visual appearance of indicator');