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 e_graphics
, g_playermodel
, g_basic
, g_textures
,
25 g_weapons
, g_phys
, g_sound
, g_saveload
, MAPDEF
,
58 AmmoLimits
: Array [0..1] of Array [A_BULLETS
..A_HIGH
] of Word =
59 ((200, 50, 50, 300, 100),
60 (400, 100, 100, 600, 200));
81 ANGLE_NONE
= Low(SmallInt);
83 CORPSE_STATE_REMOVEME
= 0;
84 CORPSE_STATE_NORMAL
= 1;
85 CORPSE_STATE_MESS
= 2;
87 PLAYER_RECT
: TRectWH
= (X
:15; Y
:12; Width
:34; Height
:52);
88 PLAYER_RECT_CX
= 15+(34 div 2);
89 PLAYER_RECT_CY
= 12+(52 div 2);
90 PLAYER_CORPSERECT
: TRectWH
= (X
:15; Y
:48; Width
:34; Height
:16);
93 PLAYER_HP_LIMIT
= 200;
95 PLAYER_AP_LIMIT
= 200;
99 PLAYER_BURN_TIME
= 110;
101 PLAYER1_DEF_COLOR
: TRGB
= (R
:64; G
:175; B
:48);
102 PLAYER2_DEF_COLOR
: TRGB
= (R
:96; G
:96; B
:96);
119 TPlayerStatArray
= Array of TPlayerStat
;
121 TPlayerSavedState
= record
129 Ammo
: Array [A_BULLETS
..A_HIGH
] of Word;
130 MaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
131 Weapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
132 Rulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
141 TPlayer
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
149 FDirection
: TDirection
;
157 FMonsterKills
: Integer;
163 FCanJetpack
: Boolean;
169 FNextWeapDelay
: Byte; // frames
170 FBFGFireCounter
: SmallInt;
171 FLastSpawnerUID
: Word;
175 FSpectatePlayer
: Integer;
176 FFirePainTime
: Integer;
179 FSavedStateNum
: Integer;
181 FModel
: TPlayerModel
;
182 FPunchAnim
: TAnimation
;
185 FActionForce
: Boolean;
186 FActionChanged
: Boolean;
188 FFireAngle
: SmallInt;
190 FShellTimer
: Integer;
192 FSawSound
: TPlayableSound
;
193 FSawSoundIdle
: TPlayableSound
;
194 FSawSoundHit
: TPlayableSound
;
195 FSawSoundSelect
: TPlayableSound
;
196 FFlameSoundOn
: TPlayableSound
;
197 FFlameSoundOff
: TPlayableSound
;
198 FFlameSoundWork
: TPlayableSound
;
199 FJetSoundOn
: TPlayableSound
;
200 FJetSoundOff
: TPlayableSound
;
201 FJetSoundFly
: TPlayableSound
;
205 FJustTeleported
: Boolean;
207 mEDamageType
: Integer;
210 function CollideLevel(XInc
, YInc
: Integer): Boolean;
211 function StayOnStep(XInc
, YInc
: Integer): Boolean;
212 function HeadInLiquid(XInc
, YInc
: Integer): Boolean;
213 function BodyInLiquid(XInc
, YInc
: Integer): Boolean;
214 function BodyInAcid(XInc
, YInc
: Integer): Boolean;
215 function FullInLift(XInc
, YInc
: Integer): Integer;
216 {procedure CollideItem();}
217 procedure FlySmoke(Times
: DWORD
= 1);
218 procedure OnFireFlame(Times
: DWORD
= 1);
219 function GetAmmoByWeapon(Weapon
: Byte): Word;
220 procedure SetAction(Action
: Byte; Force
: Boolean = False);
221 procedure OnDamage(Angle
: SmallInt); virtual;
222 function firediry(): Integer;
225 procedure Run(Direction
: TDirection
);
226 procedure NextWeapon();
227 procedure PrevWeapon();
234 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
235 procedure resetWeaponQueue ();
236 function hasAmmoForWeapon (weapon
: Byte): Boolean;
238 procedure doDamage (v
: Integer);
240 function followCorpse(): Boolean;
243 FDamageBuffer
: Integer;
245 FAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
246 FMaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
247 FWeapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
248 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
250 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
251 FReloading
: Array [WP_FIRST
..WP_LAST
] of Word;
252 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
253 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
255 FPreferredTeam
: Byte;
258 FWantsInGame
: Boolean;
263 FActualModelName
: string;
270 FSpawnInvul
: Integer;
272 FWaitForFirstSpawn
: Boolean; // set to `true` in server, used to spawn a player on first full state request
274 // debug: viewport offset
275 viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer;
277 function isValidViewPort (): Boolean; inline;
279 constructor Create(); virtual;
280 destructor Destroy(); override;
281 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
282 function GetRespawnPoint(): Byte;
283 procedure PressKey(Key
: Byte; Time
: Word = 1);
284 procedure ReleaseKeys();
285 procedure SetModel(ModelName
: String);
286 procedure SetColor(Color
: TRGB
);
287 function GetColor(): TRGB
;
288 procedure SetWeapon(W
: Byte);
289 function IsKeyPressed(K
: Byte): Boolean;
290 function GetKeys(): Byte;
291 function PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean; virtual;
292 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
293 function Collide(Panel
: TPanel
): Boolean; overload
;
294 function Collide(X
, Y
: Integer): Boolean; overload
;
295 procedure SetDirection(Direction
: TDirection
);
296 procedure GetSecret();
297 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
299 procedure Push(vx
, vy
: Integer);
300 procedure ChangeModel(ModelName
: String);
301 procedure SwitchTeam
;
302 procedure ChangeTeam(Team
: Byte);
304 function GetFlag(Flag
: Byte): Boolean;
305 procedure SetFlag(Flag
: Byte);
306 function DropFlag(Silent
: Boolean = True): Boolean;
307 procedure AllRulez(Health
: Boolean);
308 procedure RestoreHealthArmor();
309 procedure FragCombo();
310 procedure GiveItem(ItemType
: Byte);
311 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
312 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
313 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
314 procedure MakeBloodSimple(Count
: Word);
315 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
316 procedure Reset(Force
: Boolean);
317 procedure Spectate(NoMove
: Boolean = False);
318 procedure SwitchNoClip
;
319 procedure SoftReset();
320 procedure Draw(); virtual;
321 procedure DrawPain();
322 procedure DrawPickup();
323 procedure DrawRulez();
325 procedure DrawIndicator(Color
: TRGB
);
326 procedure DrawBubble();
328 procedure Update(); virtual;
329 procedure RememberState();
330 procedure RecallState();
331 procedure SaveState (st
: TStream
); virtual;
332 procedure LoadState (st
: TStream
); virtual;
333 procedure PauseSounds(Enable
: Boolean);
334 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
335 procedure DoLerp(Level
: Integer = 2);
336 procedure SetLerp(XTo
, YTo
: Integer);
337 procedure QueueWeaponSwitch(Weapon
: Byte);
338 procedure RealizeCurrentWeapon();
342 procedure JetpackOff
;
343 procedure CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
345 //WARNING! this does nothing for now, but still call it!
346 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
348 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
349 procedure moveBy (dx
, dy
: Integer); inline;
352 property Vel
: TPoint2i read FObj
.Vel
;
353 property Obj
: TObj read FObj
;
355 property Name
: String read FName write FName
;
356 property Model
: TPlayerModel read FModel
;
357 property Health
: Integer read FHealth write FHealth
;
358 property Lives
: Byte read FLives write FLives
;
359 property Armor
: Integer read FArmor write FArmor
;
360 property Air
: Integer read FAir write FAir
;
361 property JetFuel
: Integer read FJetFuel write FJetFuel
;
362 property Frags
: Integer read FFrags write FFrags
;
363 property Death
: Integer read FDeath write FDeath
;
364 property Kills
: Integer read FKills write FKills
;
365 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
366 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
367 property Secrets
: Integer read FSecrets
;
368 property GodMode
: Boolean read FGodMode write FGodMode
;
369 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
370 property NoReload
: Boolean read FNoReload write FNoReload
;
371 property alive
: Boolean read FAlive write FAlive
;
372 property Flag
: Byte read FFlag
;
373 property Team
: Byte read FTeam write FTeam
;
374 property Direction
: TDirection read FDirection
;
375 property GameX
: Integer read FObj
.X write FObj
.X
;
376 property GameY
: Integer read FObj
.Y write FObj
.Y
;
377 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
378 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
379 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
380 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
381 property IncCam
: Integer read FIncCam write FIncCam
;
382 property UID
: Word read FUID write FUID
;
383 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
384 property NetTime
: LongWord read FNetTime write FNetTime
;
387 property eName
: String read FName write FName
;
388 property eHealth
: Integer read FHealth write FHealth
;
389 property eLives
: Byte read FLives write FLives
;
390 property eArmor
: Integer read FArmor write FArmor
;
391 property eAir
: Integer read FAir write FAir
;
392 property eJetFuel
: Integer read FJetFuel write FJetFuel
;
393 property eFrags
: Integer read FFrags write FFrags
;
394 property eDeath
: Integer read FDeath write FDeath
;
395 property eKills
: Integer read FKills write FKills
;
396 property eCurrWeap
: Byte read FCurrWeap write FCurrWeap
;
397 property eMonsterKills
: Integer read FMonsterKills write FMonsterKills
;
398 property eSecrets
: Integer read FSecrets write FSecrets
;
399 property eGodMode
: Boolean read FGodMode write FGodMode
;
400 property eNoTarget
: Boolean read FNoTarget write FNoTarget
;
401 property eNoReload
: Boolean read FNoReload write FNoReload
;
402 property eAlive
: Boolean read FAlive write FAlive
;
403 property eFlag
: Byte read FFlag
;
404 property eTeam
: Byte read FTeam write FTeam
;
405 property eDirection
: TDirection read FDirection
;
406 property eGameX
: Integer read FObj
.X write FObj
.X
;
407 property eGameY
: Integer read FObj
.Y write FObj
.Y
;
408 property eGameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
409 property eGameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
410 property eGameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
411 property eGameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
412 property eIncCam
: Integer read FIncCam write FIncCam
;
413 property eUID
: Word read FUID
;
414 property eJustTeleported
: Boolean read FJustTeleported
;
415 property eNetTime
: LongWord read FNetTime
;
417 // set this before assigning something to `eDamage`
418 property eDamageType
: Integer read mEDamageType write mEDamageType
;
419 property eDamage
: Integer write doDamage
;
430 WeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
431 CloseWeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
432 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
435 procedure save (st
: TStream
);
436 procedure load (st
: TStream
);
444 TBot
= class(TPlayer
)
446 FSelectedWeapon
: Byte;
449 FAIFlags
: Array of TAIFlag
;
450 FDifficult
: TDifficult
;
452 function GetRnd(a
: Byte): Boolean;
453 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
454 function RunDirection(): TDirection
;
455 function FullInStep(XInc
, YInc
: Integer): Boolean;
456 //function NeedItem(Item: Byte): Byte;
457 procedure SelectWeapon(Dist
: Integer);
458 procedure SetAIFlag(aName
, fValue
: String20
);
459 function GetAIFlag(aName
: String20
): String20
;
460 procedure RemoveAIFlag(aName
: String20
);
461 function Healthy(): Byte;
462 procedure UpdateMove();
463 procedure UpdateCombat();
464 function KeyPressed(Key
: Word): Boolean;
465 procedure ReleaseKey(Key
: Byte);
466 function TargetOnScreen(TX
, TY
: Integer): Boolean;
467 procedure OnDamage(Angle
: SmallInt); override;
470 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
471 constructor Create(); override;
472 destructor Destroy(); override;
473 procedure Draw(); override;
474 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
475 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
476 procedure Update(); override;
477 procedure SaveState (st
: TStream
); override;
478 procedure LoadState (st
: TStream
); override;
490 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
491 procedure moveBy (dx
, dy
: Integer); inline;
493 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
507 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
508 procedure moveBy (dx
, dy
: Integer); inline;
510 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
513 TCorpse
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
522 FAnimation
: TAnimation
;
523 FAnimationMask
: TAnimation
;
526 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
527 destructor Destroy(); override;
528 procedure Damage(Value
: Word; vx
, vy
: Integer);
531 procedure SaveState (st
: TStream
);
532 procedure LoadState (st
: TStream
);
534 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
535 procedure moveBy (dx
, dy
: Integer); inline;
537 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
539 function ObjPtr (): PObj
; inline;
541 property Obj
: TObj read FObj
; // copies object
542 property State
: Byte read FState
;
543 property Mess
: Boolean read FMess
;
546 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
552 gPlayers
: Array of TPlayer
;
553 gCorpses
: Array of TCorpse
;
554 gGibs
: Array of TGib
;
555 gShells
: Array of TShell
;
556 gTeamStat
: TTeamStat
;
557 gFly
: Boolean = False;
558 gAimLine
: Boolean = False;
559 gChatBubble
: Integer = 0;
560 gPlayerIndicator
: Integer = 1;
561 gPlayerIndicatorStyle
: Integer = 0;
563 gSpectLatchPID1
: Word = 0;
564 gSpectLatchPID2
: Word = 0;
565 MAX_RUNVEL
: Integer = 8;
566 VEL_JUMP
: Integer = 10;
567 SHELL_TIMEOUT
: Cardinal = 60000;
569 function Lerp(X
, Y
, Factor
: Integer): Integer;
571 procedure g_Gibs_SetMax(Count
: Word);
572 function g_Gibs_GetMax(): Word;
573 procedure g_Corpses_SetMax(Count
: Word);
574 function g_Corpses_GetMax(): Word;
575 procedure g_Shells_SetMax(Count
: Word);
576 function g_Shells_GetMax(): Word;
578 procedure g_Player_Init();
579 procedure g_Player_Free();
580 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
581 function g_Player_CreateFromState (st
: TStream
): Word;
582 procedure g_Player_Remove(UID
: Word);
583 procedure g_Player_ResetTeams();
584 procedure g_Player_UpdateAll();
585 procedure g_Player_DrawAll();
586 procedure g_Player_DrawDebug(p
: TPlayer
);
587 procedure g_Player_DrawHealth();
588 procedure g_Player_RememberAll();
589 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
590 function g_Player_Get(UID
: Word): TPlayer
;
591 function g_Player_GetCount(): Byte;
592 function g_Player_GetStats(): TPlayerStatArray
;
593 function g_Player_ValidName(Name
: String): Boolean;
594 procedure g_Player_CreateCorpse(Player
: TPlayer
);
595 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
596 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
597 procedure g_Player_UpdatePhysicalObjects();
598 procedure g_Player_DrawCorpses();
599 procedure g_Player_DrawShells();
600 procedure g_Player_RemoveAllCorpses();
601 procedure g_Player_Corpses_SaveState (st
: TStream
);
602 procedure g_Player_Corpses_LoadState (st
: TStream
);
603 procedure g_Player_ResetReady();
604 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
605 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
606 procedure g_Bot_MixNames();
607 procedure g_Bot_RemoveAll();
612 {$INCLUDE ../nogl/noGLuses.inc}
613 {$IFDEF ENABLE_HOLMES}
616 e_log
, g_map
, g_items
, g_console
, g_gfx
, Math
,
617 g_options
, g_triggers
, g_menu
, g_game
, g_grid
, e_res
,
618 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
,
619 g_net
, g_netmsg
, g_window
,
622 const PLR_SAVE_VERSION
= 0;
632 diag_precision
: Byte;
636 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
637 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
638 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
642 TIME_RESPAWN1
= 1500;
643 TIME_RESPAWN2
= 2000;
644 TIME_RESPAWN3
= 3000;
647 JET_MAX
= 540; // ~30 sec
648 PLAYER_SUIT_TIME
= 30000;
649 PLAYER_INVUL_TIME
= 30000;
650 PLAYER_INVIS_TIME
= 35000;
651 FRAG_COMBO_TIME
= 3000;
655 ANGLE_RIGHTDOWN
= -35;
657 ANGLE_LEFTDOWN
= -145;
658 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
659 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
662 BOT_UNSAFEDIST
= 128;
663 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
665 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
666 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
667 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
668 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
669 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
670 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
671 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
672 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
673 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
674 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
675 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
676 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
677 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
678 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
679 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
680 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
681 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
682 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
683 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
684 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
685 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
686 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
687 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
688 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
689 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
690 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
692 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
693 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
695 BOTNAMES_FILENAME
= 'botnames.txt';
696 BOTLIST_FILENAME
= 'botlist.txt';
700 MaxCorpses
: Word = 20;
701 MaxShells
: Word = 300;
702 CurrentGib
: Integer = 0;
703 CurrentShell
: Integer = 0;
704 BotNames
: Array of String;
705 BotList
: Array of TBotProfile
;
706 SavedStates
: Array of TPlayerSavedState
;
709 function Lerp(X
, Y
, Factor
: Integer): Integer;
711 Result
:= X
+ ((Y
- X
) div Factor
);
714 function SameTeam(UID1
, UID2
: Word): Boolean;
718 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
719 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
721 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
723 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
724 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
726 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
729 procedure g_Gibs_SetMax(Count
: Word);
732 SetLength(gGibs
, Count
);
734 if CurrentGib
>= Count
then
738 function g_Gibs_GetMax(): Word;
743 procedure g_Shells_SetMax(Count
: Word);
746 SetLength(gShells
, Count
);
748 if CurrentShell
>= Count
then
752 function g_Shells_GetMax(): Word;
758 procedure g_Corpses_SetMax(Count
: Word);
761 SetLength(gCorpses
, Count
);
764 function g_Corpses_GetMax(): Word;
766 Result
:= MaxCorpses
;
769 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
779 // Åñòü ëè ìåñòî â gPlayers:
780 if gPlayers
<> nil then
781 for a
:= 0 to High(gPlayers
) do
782 if gPlayers
[a
] = nil then
788 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
791 SetLength(gPlayers
, Length(gPlayers
)+1);
795 // Ñîçäàåì îáúåêò èãðîêà:
797 gPlayers
[a
] := TBot
.Create()
799 gPlayers
[a
] := TPlayer
.Create();
802 gPlayers
[a
].FActualModelName
:= ModelName
;
803 gPlayers
[a
].SetModel(ModelName
);
805 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
806 if gPlayers
[a
].FModel
= nil then
810 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
814 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
815 if Random(2) = 0 then
819 gPlayers
[a
].FPreferredTeam
:= Team
;
821 case gGameSettings
.GameMode
of
822 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
824 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
826 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
829 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
830 gPlayers
[a
].FColor
:= Color
;
831 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
832 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
834 gPlayers
[a
].FModel
.Color
:= Color
;
836 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
837 gPlayers
[a
].FAlive
:= False;
839 Result
:= gPlayers
[a
].FUID
;
842 function g_Player_CreateFromState (st
: TStream
): Word;
849 if (st
= nil) then exit
; //???
852 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
853 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
856 Bot
:= utils
.readBool(st
);
861 // Åñòü ëè ìåñòî â gPlayers:
862 for a
:= 0 to High(gPlayers
) do if (gPlayers
[a
] = nil) then begin ok
:= true; break
; end;
864 // Íåò ìåñòà - ðàñøèðÿåì gPlayers
867 SetLength(gPlayers
, Length(gPlayers
)+1);
871 // Ñîçäàåì îáúåêò èãðîêà
873 gPlayers
[a
] := TBot
.Create()
875 gPlayers
[a
] := TPlayer
.Create();
876 gPlayers
[a
].FIamBot
:= Bot
;
877 gPlayers
[a
].FPhysics
:= True;
880 gPlayers
[a
].FUID
:= utils
.readWord(st
);
882 gPlayers
[a
].FName
:= utils
.readStr(st
);
884 gPlayers
[a
].FTeam
:= utils
.readByte(st
);
885 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
887 gPlayers
[a
].FAlive
:= utils
.readBool(st
);
888 // Èçðàñõîäîâàë ëè âñå æèçíè
889 gPlayers
[a
].FNoRespawn
:= utils
.readBool(st
);
891 b
:= utils
.readByte(st
);
892 if b
= 1 then gPlayers
[a
].FDirection
:= TDirection
.D_LEFT
else gPlayers
[a
].FDirection
:= TDirection
.D_RIGHT
; // b = 2
894 gPlayers
[a
].FHealth
:= utils
.readLongInt(st
);
896 gPlayers
[a
].FHandicap
:= utils
.readLongInt(st
);
898 gPlayers
[a
].FLives
:= utils
.readByte(st
);
900 gPlayers
[a
].FArmor
:= utils
.readLongInt(st
);
902 gPlayers
[a
].FAir
:= utils
.readLongInt(st
);
904 gPlayers
[a
].FJetFuel
:= utils
.readLongInt(st
);
906 gPlayers
[a
].FPain
:= utils
.readLongInt(st
);
908 gPlayers
[a
].FKills
:= utils
.readLongInt(st
);
910 gPlayers
[a
].FMonsterKills
:= utils
.readLongInt(st
);
912 gPlayers
[a
].FFrags
:= utils
.readLongInt(st
);
914 gPlayers
[a
].FFragCombo
:= utils
.readByte(st
);
915 // Âðåìÿ ïîñëåäíåãî ôðàãà
916 gPlayers
[a
].FLastFrag
:= utils
.readLongWord(st
);
918 gPlayers
[a
].FDeath
:= utils
.readLongInt(st
);
920 gPlayers
[a
].FFlag
:= utils
.readByte(st
);
922 gPlayers
[a
].FSecrets
:= utils
.readLongInt(st
);
924 gPlayers
[a
].FCurrWeap
:= utils
.readByte(st
);
925 // Ñëåäóþùåå æåëàåìîå îðóæèå
926 gPlayers
[a
].FNextWeap
:= utils
.readWord(st
);
928 gPlayers
[a
].FNextWeapDelay
:= utils
.readByte(st
);
930 gPlayers
[a
].FBFGFireCounter
:= utils
.readSmallInt(st
);
932 gPlayers
[a
].FDamageBuffer
:= utils
.readLongInt(st
);
933 // Ïîñëåäíèé óäàðèâøèé
934 gPlayers
[a
].FLastSpawnerUID
:= utils
.readWord(st
);
935 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
936 gPlayers
[a
].FLastHit
:= utils
.readByte(st
);
938 Obj_LoadState(@gPlayers
[a
].FObj
, st
);
939 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
940 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FAmmo
[i
] := utils
.readWord(st
);
941 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
942 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FMaxAmmo
[i
] := utils
.readWord(st
);
944 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FWeapon
[i
] := utils
.readBool(st
);
945 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
946 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FReloading
[i
] := utils
.readWord(st
);
948 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
949 // Íàëè÷èå êðàñíîãî êëþ÷à
950 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
951 // Íàëè÷èå çåëåíîãî êëþ÷à
952 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
953 // Íàëè÷èå ñèíåãî êëþ÷à
954 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
956 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_BERSERK
);
957 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
958 for i
:= MR_SUIT
to MR_MAX
do gPlayers
[a
].FMegaRulez
[i
] := utils
.readLongWord(st
);
959 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
960 for i
:= T_RESPAWN
to T_FLAGCAP
do gPlayers
[a
].FTime
[i
] := utils
.readLongWord(st
);
963 gPlayers
[a
].FActualModelName
:= utils
.readStr(st
);
965 gPlayers
[a
].FColor
.R
:= utils
.readByte(st
);
966 gPlayers
[a
].FColor
.G
:= utils
.readByte(st
);
967 gPlayers
[a
].FColor
.B
:= utils
.readByte(st
);
968 // Îáíîâëÿåì ìîäåëü èãðîêà
969 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
971 // Íåò ìîäåëè - ñîçäàíèå íåâîçìîæíî
972 if (gPlayers
[a
].FModel
= nil) then
976 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
980 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû
981 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
982 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
984 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
986 result
:= gPlayers
[a
].FUID
;
990 procedure g_Player_ResetTeams();
994 if g_Game_IsClient
then
996 if gPlayers
= nil then
998 for a
:= Low(gPlayers
) to High(gPlayers
) do
999 if gPlayers
[a
] <> nil then
1000 case gGameSettings
.GameMode
of
1002 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
1004 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
1005 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
1006 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
1009 gPlayers
[a
].ChangeTeam(TEAM_RED
)
1011 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
1014 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
1018 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
1021 _name
, _model
: String;
1024 if not g_Game_IsServer
then Exit
;
1026 // Ñïèñîê íàçâàíèé ìîäåëåé:
1027 m
:= g_PlayerModel_GetNames();
1032 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1033 Team
:= TEAM_COOP
// COOP
1035 if gGameSettings
.GameMode
= GM_DM
then
1036 Team
:= TEAM_NONE
// DM
1038 if Team
= TEAM_NONE
then // CTF / TDM
1040 // Àâòîáàëàíñ êîìàíä:
1044 for a
:= 0 to High(gPlayers
) do
1045 if gPlayers
[a
] <> nil then
1047 if gPlayers
[a
].Team
= TEAM_RED
then
1050 if gPlayers
[a
].Team
= TEAM_BLUE
then
1060 if Random(2) = 0 then
1066 // Âûáèðàåì áîòó èìÿ:
1068 if BotNames
<> nil then
1069 for a
:= 0 to High(BotNames
) do
1070 if g_Player_ValidName(BotNames
[a
]) then
1072 _name
:= BotNames
[a
];
1076 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1077 _model
:= m
[Random(Length(m
))];
1080 with g_Player_Get(g_Player_Create(_model
,
1081 _RGB(Min(Random(9)*32, 255),
1082 Min(Random(9)*32, 255),
1083 Min(Random(9)*32, 255)),
1084 Team
, True)) as TBot
do
1086 // Åñëè èìåíè íåò, äåëàåì åãî èç UID áîòà
1088 Name
:= Format('DFBOT%.5d', [UID
])
1093 1: FDifficult
:= DIFFICULT_EASY
;
1094 2: FDifficult
:= DIFFICULT_MEDIUM
;
1095 else FDifficult
:= DIFFICULT_HARD
;
1098 for a
:= WP_FIRST
to WP_LAST
do
1100 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1101 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1102 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1105 FHandicap
:= Handicap
;
1107 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1109 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1110 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1115 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
1118 _name
, _model
: String;
1121 if not g_Game_IsServer
then Exit
;
1123 // Ñïèñîê íàçâàíèé ìîäåëåé:
1124 m
:= g_PlayerModel_GetNames();
1129 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1130 Team
:= TEAM_COOP
// COOP
1132 if gGameSettings
.GameMode
= GM_DM
then
1133 Team
:= TEAM_NONE
// DM
1135 if Team
= TEAM_NONE
then
1136 Team
:= BotList
[num
].team
; // CTF / TDM
1138 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1139 lName
:= AnsiLowerCase(lName
);
1140 if (num
< 0) or (num
> Length(BotList
)-1) then
1142 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1143 for a
:= 0 to High(BotList
) do
1144 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1153 _name
:= BotList
[num
].name
;
1154 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1155 if not g_Player_ValidName(_name
) then
1157 _name
:= Format('DFBOT%.2d', [Random(100)]);
1158 until g_Player_ValidName(_name
);
1161 _model
:= BotList
[num
].model
;
1162 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1163 if not InSArray(_model
, m
) then
1164 _model
:= m
[Random(Length(m
))];
1167 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1171 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1172 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1173 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1174 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1175 FDifficult
.Cover
:= BotList
[num
].cover
;
1176 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1178 FHandicap
:= Handicap
;
1180 for a
:= WP_FIRST
to WP_LAST
do
1182 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1183 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1184 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1187 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1189 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1193 procedure g_Bot_RemoveAll();
1197 if not g_Game_IsServer
then Exit
;
1198 if gPlayers
= nil then Exit
;
1200 for a
:= 0 to High(gPlayers
) do
1201 if gPlayers
[a
] <> nil then
1202 if gPlayers
[a
] is TBot
then
1204 gPlayers
[a
].Lives
:= 0;
1205 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1206 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1207 g_Player_Remove(gPlayers
[a
].FUID
);
1213 procedure g_Bot_MixNames();
1218 if BotNames
<> nil then
1219 for a
:= 0 to High(BotNames
) do
1221 b
:= Random(Length(BotNames
));
1223 Botnames
[a
] := BotNames
[b
];
1228 procedure g_Player_Remove(UID
: Word);
1232 if gPlayers
= nil then Exit
;
1234 if g_Game_IsServer
and g_Game_IsNet
then
1235 MH_SEND_PlayerDelete(UID
);
1237 for i
:= 0 to High(gPlayers
) do
1238 if gPlayers
[i
] <> nil then
1239 if gPlayers
[i
].FUID
= UID
then
1241 if gPlayers
[i
] is TPlayer
then
1242 TPlayer(gPlayers
[i
]).Free()
1244 TBot(gPlayers
[i
]).Free();
1250 procedure g_Player_Init();
1261 path
:= BOTNAMES_FILENAME
;
1262 if e_FindResource(DataDirs
, path
) = false then
1265 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1266 AssignFile(F
, path
);
1277 SetLength(BotNames
, Length(BotNames
)+1);
1278 BotNames
[High(BotNames
)] := s
;
1286 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1287 config
:= TConfig
.CreateFile(path
);
1291 while config
.SectionExists(IntToStr(a
)) do
1293 SetLength(BotList
, Length(BotList
)+1);
1295 with BotList
[High(BotList
)] do
1298 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1300 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1302 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1307 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1308 color
.R
:= StrToIntDef(sa
[0], 0);
1309 color
.G
:= StrToIntDef(sa
[1], 0);
1310 color
.B
:= StrToIntDef(sa
[2], 0);
1311 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1312 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1313 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1314 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1315 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1316 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1317 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1318 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1319 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1320 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1321 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1322 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1323 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1324 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1325 if Length(sa
) = 10 then
1327 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1328 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1329 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1330 if Length(sa
) = 10 then
1332 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1334 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1335 if Length(sa) = 10 then
1337 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1344 SetLength(SavedStates
, 0);
1347 procedure g_Player_Free();
1351 if gPlayers
<> nil then
1353 for i
:= 0 to High(gPlayers
) do
1354 if gPlayers
[i
] <> nil then
1356 if gPlayers
[i
] is TPlayer
then
1357 TPlayer(gPlayers
[i
]).Free()
1359 TBot(gPlayers
[i
]).Free();
1368 SetLength(SavedStates
, 0);
1371 procedure g_Player_UpdateAll();
1375 if gPlayers
= nil then Exit
;
1377 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1378 for i
:= 0 to High(gPlayers
) do
1380 if gPlayers
[i
] <> nil then
1382 if gPlayers
[i
] is TPlayer
then
1384 gPlayers
[i
].Update();
1385 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1389 // bot updates weapons in `UpdateCombat()`
1390 TBot(gPlayers
[i
]).Update();
1394 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1397 procedure g_Player_DrawAll();
1401 if gPlayers
= nil then Exit
;
1403 for i
:= 0 to High(gPlayers
) do
1404 if gPlayers
[i
] <> nil then
1405 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1406 else TBot(gPlayers
[i
]).Draw();
1409 procedure g_Player_DrawDebug(p
: TPlayer
);
1413 if p
= nil then Exit
;
1414 if (@p
.FObj
) = nil then Exit
;
1416 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1418 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1419 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1420 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1421 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1422 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1423 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1426 procedure g_Player_DrawHealth();
1431 if gPlayers
= nil then Exit
;
1432 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1434 for i
:= 0 to High(gPlayers
) do
1435 if gPlayers
[i
] <> nil then
1437 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1438 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1439 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1440 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1441 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1442 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1446 function g_Player_Get(UID
: Word): TPlayer
;
1452 if gPlayers
= nil then
1455 for a
:= 0 to High(gPlayers
) do
1456 if gPlayers
[a
] <> nil then
1457 if gPlayers
[a
].FUID
= UID
then
1459 Result
:= gPlayers
[a
];
1464 function g_Player_GetCount(): Byte;
1470 if gPlayers
= nil then
1473 for a
:= 0 to High(gPlayers
) do
1474 if gPlayers
[a
] <> nil then
1475 Result
:= Result
+ 1;
1478 function g_Player_GetStats(): TPlayerStatArray
;
1484 if gPlayers
= nil then Exit
;
1486 for a
:= 0 to High(gPlayers
) do
1487 if gPlayers
[a
] <> nil then
1489 SetLength(Result
, Length(Result
)+1);
1490 with Result
[High(Result
)] do
1493 Ping
:= gPlayers
[a
].FPing
;
1494 Loss
:= gPlayers
[a
].FLoss
;
1495 Name
:= gPlayers
[a
].FName
;
1496 Team
:= gPlayers
[a
].FTeam
;
1497 Frags
:= gPlayers
[a
].FFrags
;
1498 Deaths
:= gPlayers
[a
].FDeath
;
1499 Kills
:= gPlayers
[a
].FKills
;
1500 Color
:= gPlayers
[a
].FModel
.Color
;
1501 Lives
:= gPlayers
[a
].FLives
;
1502 Spectator
:= gPlayers
[a
].FSpectator
;
1507 procedure g_Player_ResetReady();
1511 if not g_Game_IsServer
then Exit
;
1512 if gPlayers
= nil then Exit
;
1514 for a
:= 0 to High(gPlayers
) do
1515 if gPlayers
[a
] <> nil then
1517 gPlayers
[a
].FReady
:= False;
1518 if g_Game_IsNet
then
1519 MH_SEND_GameEvent(NET_EV_INTER_READY
, gPlayers
[a
].UID
, 'N');
1523 procedure g_Player_RememberAll
;
1527 for i
:= Low(gPlayers
) to High(gPlayers
) do
1528 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1529 gPlayers
[i
].RememberState
;
1532 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1536 gTeamStat
[TEAM_RED
].Goals
:= 0;
1537 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1539 if gPlayers
<> nil then
1540 for i
:= 0 to High(gPlayers
) do
1541 if gPlayers
[i
] <> nil then
1543 gPlayers
[i
].Reset(Force
);
1545 if gPlayers
[i
] is TPlayer
then
1547 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1548 gPlayers
[i
].Respawn(Silent
)
1550 gPlayers
[i
].Spectate();
1553 TBot(gPlayers
[i
]).Respawn(Silent
);
1557 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1563 if Player
.alive
then
1566 // Ðàçðûâàåì ñâÿçü ñ ïðåæíèì òðóïîì:
1567 if gCorpses
<> nil then
1568 for i
:= 0 to High(gCorpses
) do
1569 if gCorpses
[i
] <> nil then
1570 if gCorpses
[i
].FPlayerUID
= Player
.FUID
then
1571 gCorpses
[i
].FPlayerUID
:= 0;
1573 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1578 if (FHealth
>= -50) or (gGibsCount
= 0) then
1580 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1584 for find_id
:= 0 to High(gCorpses
) do
1585 if gCorpses
[find_id
] = nil then
1592 find_id
:= Random(Length(gCorpses
));
1594 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1595 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1596 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1597 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1598 gCorpses
[find_id
].FPlayerUID
:= FUID
;
1601 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1602 FObj
.Y
+ PLAYER_RECT_CY
,
1603 FModel
.Name
, FModel
.Color
);
1607 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1611 if (gShells
= nil) or (Length(gShells
) = 0) then
1614 with gShells
[CurrentShell
] do
1620 if T
= SHELL_BULLET
then
1622 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1626 Obj
.Rect
.Width
:= 4;
1627 Obj
.Rect
.Height
:= 2;
1631 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1635 Obj
.Rect
.Width
:= 7;
1636 Obj
.Rect
.Height
:= 3;
1642 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1643 positionChanged(); // this updates spatial accelerators
1644 RAngle
:= Random(360);
1645 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1647 if CurrentShell
>= High(gShells
) then
1654 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1657 GibsArray
: TGibsArray
;
1660 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1662 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1664 Blood
:= g_PlayerModel_GetBlood(ModelName
);
1666 for a
:= 0 to High(GibsArray
) do
1667 with gGibs
[CurrentGib
] do
1670 ID
:= GibsArray
[a
].ID
;
1671 MaskID
:= GibsArray
[a
].MaskID
;
1674 Obj
.Rect
:= GibsArray
[a
].Rect
;
1675 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1676 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1677 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1678 positionChanged(); // this updates spatial accelerators
1679 RAngle
:= Random(360);
1681 if gBloodCount
> 0 then
1682 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1683 Random(48), Random(48), Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
1685 if CurrentGib
>= High(gGibs
) then
1692 procedure g_Player_UpdatePhysicalObjects();
1698 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1703 if T
= SHELL_BULLET
then
1704 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1706 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1711 if gGibs
<> nil then
1712 for i
:= 0 to High(gGibs
) do
1713 if gGibs
[i
].alive
then
1717 mr
:= g_Obj_Move(@Obj
, True, False, True);
1718 positionChanged(); // this updates spatial accelerators
1720 if WordBool(mr
and MOVE_FALLOUT
) then
1726 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1727 if WordBool(mr
and MOVE_HITWALL
) then
1728 Obj
.Vel
.X
:= -(vel
.X
div 2);
1729 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1730 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1732 if (Obj
.Vel
.X
>= 0) then
1734 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1735 if RAngle
>= 360 then
1736 RAngle
:= RAngle
mod 360;
1737 end else begin // Counter-clockwise
1738 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1740 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1743 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1744 if gTime
mod (GAME_TICK
*3) = 0 then
1745 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1749 if gCorpses
<> nil then
1750 for i
:= 0 to High(gCorpses
) do
1751 if gCorpses
[i
] <> nil then
1752 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1758 gCorpses
[i
].Update();
1761 if gShells
<> nil then
1762 for i
:= 0 to High(gShells
) do
1763 if gShells
[i
].alive
then
1767 mr
:= g_Obj_Move(@Obj
, True, False, True);
1768 positionChanged(); // this updates spatial accelerators
1770 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1776 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1777 if WordBool(mr
and MOVE_HITWALL
) then
1779 Obj
.Vel
.X
:= -(vel
.X
div 2);
1780 if not WordBool(mr
and MOVE_INWATER
) then
1781 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1783 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1785 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1786 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1787 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1789 if RAngle
mod 90 <> 0 then
1790 RAngle
:= (RAngle
div 90) * 90;
1792 else if not WordBool(mr
and MOVE_INWATER
) then
1793 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1796 if (Obj
.Vel
.X
>= 0) then
1798 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1799 if RAngle
>= 360 then
1800 RAngle
:= RAngle
mod 360;
1801 end else begin // Counter-clockwise
1802 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1804 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1810 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1812 x
:= Obj
.X
+Obj
.Rect
.X
;
1813 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1814 w
:= Obj
.Rect
.Width
;
1815 h
:= Obj
.Rect
.Height
;
1818 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1820 if (dx
<> 0) or (dy
<> 0) then
1829 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1833 w
:= Obj
.Rect
.Width
;
1834 h
:= Obj
.Rect
.Height
;
1837 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1839 if (dx
<> 0) or (dy
<> 0) then
1848 procedure TGib
.positionChanged (); inline; begin end;
1849 procedure TShell
.positionChanged (); inline; begin end;
1852 procedure g_Player_DrawCorpses();
1857 if gGibs
<> nil then
1858 for i
:= 0 to High(gGibs
) do
1859 if gGibs
[i
].alive
then
1862 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1865 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1866 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1868 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1871 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1877 if gCorpses
<> nil then
1878 for i
:= 0 to High(gCorpses
) do
1879 if gCorpses
[i
] <> nil then
1883 procedure g_Player_DrawShells();
1888 if gShells
<> nil then
1889 for i
:= 0 to High(gShells
) do
1890 if gShells
[i
].alive
then
1893 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1899 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1903 procedure g_Player_RemoveAllCorpses();
1909 SetLength(gGibs
, MaxGibs
);
1910 SetLength(gShells
, MaxGibs
);
1914 if gCorpses
<> nil then
1915 for i
:= 0 to High(gCorpses
) do
1919 SetLength(gCorpses
, MaxCorpses
);
1922 procedure g_Player_Corpses_SaveState (st
: TStream
);
1926 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ
1928 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1930 // Êîëè÷åñòâî òðóïîâ
1931 utils
.writeInt(st
, LongInt(count
));
1933 if (count
= 0) then exit
;
1936 for i
:= 0 to High(gCorpses
) do
1938 if gCorpses
[i
] <> nil then
1941 utils
.writeStr(st
, gCorpses
[i
].FModelName
);
1943 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1944 // Ñîõðàíÿåì äàííûå òðóïà:
1945 gCorpses
[i
].SaveState(st
);
1951 procedure g_Player_Corpses_LoadState (st
: TStream
);
1959 g_Player_RemoveAllCorpses();
1961 // Êîëè÷åñòâî òðóïîâ:
1962 count
:= utils
.readLongInt(st
);
1963 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1965 if (count
= 0) then exit
;
1968 for i
:= 0 to count
-1 do
1971 str
:= utils
.readStr(st
);
1973 b
:= utils
.readBool(st
);
1975 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1976 // Çàãðóæàåì äàííûå òðóïà
1977 gCorpses
[i
].LoadState(st
);
1984 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1986 procedure TPlayer
.BFGHit();
1988 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1989 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1990 if g_Game_IsServer
and g_Game_IsNet
then
1991 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1992 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1996 procedure TPlayer
.ChangeModel(ModelName
: string);
1998 locModel
: TPlayerModel
;
2000 locModel
:= g_PlayerModel_Get(ModelName
);
2001 if locModel
= nil then Exit
;
2007 procedure TPlayer
.SetModel(ModelName
: string);
2011 m
:= g_PlayerModel_Get(ModelName
);
2014 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
2015 m
:= g_PlayerModel_Get('doomer');
2018 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
2023 if FModel
<> nil then
2028 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2029 FModel
.Color
:= FColor
2031 FModel
.Color
:= TEAMCOLOR
[FTeam
];
2032 FModel
.SetWeapon(FCurrWeap
);
2033 FModel
.SetFlag(FFlag
);
2034 SetDirection(FDirection
);
2037 procedure TPlayer
.SetColor(Color
: TRGB
);
2040 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2041 if FModel
<> nil then FModel
.Color
:= Color
;
2044 function TPlayer
.GetColor(): TRGB
;
2046 result
:= FModel
.Color
;
2049 procedure TPlayer
.SwitchTeam
;
2051 if g_Game_IsClient
then
2053 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
2055 if gGameOn
and FAlive
then
2056 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
2058 if FTeam
= TEAM_RED
then
2060 ChangeTeam(TEAM_BLUE
);
2061 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
2062 if g_Game_IsNet
then
2063 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
2067 ChangeTeam(TEAM_RED
);
2068 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
2069 if g_Game_IsNet
then
2070 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
2072 FPreferredTeam
:= FTeam
;
2075 procedure TPlayer
.ChangeTeam(Team
: Byte);
2082 TEAM_RED
, TEAM_BLUE
:
2083 FModel
.Color
:= TEAMCOLOR
[Team
];
2085 FModel
.Color
:= FColor
;
2087 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2088 MH_SEND_PlayerStats(FUID
);
2092 procedure TPlayer.CollideItem();
2097 if gItems = nil then Exit;
2098 if not FAlive then Exit;
2100 for i := 0 to High(gItems) do
2103 if (ItemType <> ITEM_NONE) and alive then
2104 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2105 PLAYER_RECT.Height, @Obj) then
2107 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2109 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2110 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2111 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2112 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2113 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2115 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2116 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2117 (gGameSettings.GameType = GT_SINGLE) and
2118 (g_Player_GetCount() > 1)) then
2119 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2125 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2127 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2128 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2132 constructor TPlayer
.Create();
2138 mEDamageType
:= HIT_SOME
;
2144 FSawSound
:= TPlayableSound
.Create();
2145 FSawSoundIdle
:= TPlayableSound
.Create();
2146 FSawSoundHit
:= TPlayableSound
.Create();
2147 FSawSoundSelect
:= TPlayableSound
.Create();
2148 FFlameSoundOn
:= TPlayableSound
.Create();
2149 FFlameSoundOff
:= TPlayableSound
.Create();
2150 FFlameSoundWork
:= TPlayableSound
.Create();
2151 FJetSoundFly
:= TPlayableSound
.Create();
2152 FJetSoundOn
:= TPlayableSound
.Create();
2153 FJetSoundOff
:= TPlayableSound
.Create();
2155 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2156 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2157 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2158 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2159 FFlameSoundOn
.SetByName('SOUND_WEAPON_FLAMEON');
2160 FFlameSoundOff
.SetByName('SOUND_WEAPON_FLAMEOFF');
2161 FFlameSoundWork
.SetByName('SOUND_WEAPON_FLAMEWORK');
2162 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2163 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2164 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2166 FSpectatePlayer
:= -1;
2170 FSavedStateNum
:= -1;
2177 FActualModelName
:= 'doomer';
2180 FObj
.Rect
:= PLAYER_RECT
;
2182 FBFGFireCounter
:= -1;
2183 FJustTeleported
:= False;
2186 FWaitForFirstSpawn
:= false;
2191 procedure TPlayer
.positionChanged (); inline;
2195 procedure TPlayer
.doDamage (v
: Integer);
2197 if (v
<= 0) then exit
;
2198 if (v
> 32767) then v
:= 32767;
2199 Damage(v
, 0, 0, 0, mEDamageType
);
2202 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2206 if (not g_Game_IsClient
) and (not FAlive
) then
2211 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2212 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2214 if not g_Game_IsClient
then
2217 if t
= HIT_TRAP
then
2219 // Ëîâóøêà óáèâàåò ñðàçó:
2221 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2223 if t
= HIT_SELF
then
2227 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2230 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2231 FMegaRulez
[MR_SUIT
] := 0;
2232 FMegaRulez
[MR_INVUL
] := 0;
2233 FMegaRulez
[MR_INVIS
] := 0;
2238 // Íî îò îñòàëüíîãî ñïàñàåò:
2239 if FMegaRulez
[MR_INVUL
] >= gTime
then
2246 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2247 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2248 (SpawnerUID
= FUID
) or
2249 (not SameTeam(FUID
, SpawnerUID
)) then
2251 FLastSpawnerUID
:= SpawnerUID
;
2253 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2254 if gBloodCount
> 0 then
2256 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2257 if value
div 4 <= c
then
2258 c
:= c
- (value
div 4)
2262 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2266 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2267 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2270 if t
= HIT_WATER
then
2271 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2272 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2277 Inc(FDamageBuffer
, value
);
2281 FPain
:= FPain
+ value
;
2284 if g_Game_IsServer
and g_Game_IsNet
then
2286 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2287 MH_SEND_PlayerStats(FUID
);
2288 MH_SEND_PlayerPos(False, FUID
);
2292 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2295 if g_Game_IsClient
then
2300 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2302 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2305 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2307 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2311 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2312 MH_SEND_PlayerStats(FUID
);
2315 destructor TPlayer
.Destroy();
2317 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2319 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2323 FSawSoundIdle
.Free();
2324 FSawSoundHit
.Free();
2325 FSawSoundSelect
.Free();
2326 FFlameSoundOn
.Free();
2327 FFlameSoundOff
.Free();
2328 FFlameSoundWork
.Free();
2329 FJetSoundFly
.Free();
2331 FJetSoundOff
.Free();
2333 if FPunchAnim
<> nil then
2339 procedure TPlayer
.DrawIndicator(Color
: TRGB
);
2341 indX
, indY
: Integer;
2350 case gPlayerIndicatorStyle
of
2353 if g_Texture_Get('TEXTURE_PLAYER_INDICATOR', ID
) then
2355 e_GetTextureSize(ID
, @indW
, @indH
);
2359 if (FObj
.X
+ FObj
.Rect
.X
) < 0 then
2362 indX
:= FObj
.X
+ FObj
.Rect
.X
+ FObj
.Rect
.Width
;
2363 indY
:= FObj
.Y
+ FObj
.Rect
.Y
+ (FObj
.Rect
.Height
- indW
) div 2;
2366 else if (FObj
.X
+ FObj
.Rect
.X
+ FObj
.Rect
.Width
) > Max(gMapInfo
.Width
, gPlayerScreenSize
.X
) then
2369 indX
:= FObj
.X
+ FObj
.Rect
.X
- indH
;
2370 indY
:= FObj
.Y
+ FObj
.Rect
.Y
+ (FObj
.Rect
.Height
- indW
) div 2;
2373 else if (fObj
.Y
- indH
) < 0 then
2376 indX
:= FObj
.X
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
- indW
) div 2;
2377 indY
:= FObj
.Y
+ FObj
.Rect
.Y
+ FObj
.Rect
.Height
;
2383 indX
:= FObj
.X
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
- indW
) div 2;
2384 indY
:= FObj
.Y
- indH
;
2387 indX
:= EnsureRange(indX
, 0, Max(gMapInfo
.Width
, gPlayerScreenSize
.X
) - indW
);
2388 indY
:= EnsureRange(indY
, 0, Max(gMapInfo
.Height
, gPlayerScreenSize
.Y
) - indH
);
2392 e_DrawAdv(ID
, indX
, indY
, 0, True, False, indA
, @a
);
2399 e_TextureFontGetSize(gStdFont
, nW
, nH
);
2400 indX
:= FObj
.X
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
- Length(FName
) * nW
) div 2;
2401 indY
:= FObj
.Y
- nH
;
2402 e_TextureFontPrintEx(indX
, indY
, FName
, gStdFont
, Color
.R
, Color
.G
, Color
.B
, 1.0, True);
2407 procedure TPlayer
.DrawBubble();
2409 bubX
, bubY
: Integer;
2412 Rw
, Gw
, Bw
: SmallInt;
2415 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= TDirection
.D_LEFT
, -4, 18);
2416 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2424 1: // simple textual non-bubble
2426 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2427 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2428 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2431 2: // advanced pixel-perfect bubble
2433 if FTeam
= TEAM_RED
then
2436 if FTeam
= TEAM_BLUE
then
2439 3: // colored bubble
2441 Rb
:= FModel
.Color
.R
;
2442 Gb
:= FModel
.Color
.G
;
2443 Bb
:= FModel
.Color
.B
;
2444 Rw
:= Min(Rb
* 2 + 64, 255);
2445 Gw
:= Min(Gb
* 2 + 64, 255);
2446 Bw
:= Min(Bb
* 2 + 64, 255);
2447 if (Abs(Rw
- Rb
) < 32)
2448 or (Abs(Gw
- Gb
) < 32)
2449 or (Abs(Bw
- Bb
) < 32) then
2451 Rb
:= Max(Rw
div 2 - 16, 0);
2452 Gb
:= Max(Gw
div 2 - 16, 0);
2453 Bb
:= Max(Bw
div 2 - 16, 0);
2456 4: // custom textured bubble
2458 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2459 if FDirection
= TDirection
.D_RIGHT
then
2460 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2462 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, TMirrorType
.Horizontal
);
2468 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2469 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2471 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2474 Dot
:= IfThen(FDirection
= TDirection
.D_LEFT
, 14, 5);
2475 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2476 e_DrawLine(1, bubX
+ IfThen(FDirection
= TDirection
.D_LEFT
, Dot
- 1, Dot
+ 1), bubY
+ 13, bubX
+ IfThen(FDirection
= TDirection
.D_LEFT
, Dot
- 1, Dot
+ 1), bubY
+ 15, Rw
, Gw
, Bw
);
2477 e_DrawLine(1, bubX
+ IfThen(FDirection
= TDirection
.D_LEFT
, Dot
- 2, Dot
+ 2), bubY
+ 13, bubX
+ IfThen(FDirection
= TDirection
.D_LEFT
, Dot
- 2, Dot
+ 2), bubY
+ 14, Rw
, Gw
, Bw
);
2478 e_DrawLine(1, bubX
+ IfThen(FDirection
= TDirection
.D_LEFT
, Dot
- 3, Dot
+ 3), bubY
+ 13, bubX
+ IfThen(FDirection
= TDirection
.D_LEFT
, Dot
- 3, Dot
+ 3), bubY
+ 13, Rw
, Gw
, Bw
);
2479 e_DrawLine(1, bubX
+ IfThen(FDirection
= TDirection
.D_LEFT
, Dot
- 3, Dot
+ 3), bubY
+ 14, bubX
+ IfThen(FDirection
= TDirection
.D_LEFT
, Dot
- 1, Dot
+ 1), bubY
+ 16, Rb
, Gb
, Bb
);
2483 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2484 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2485 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2488 procedure TPlayer
.Draw();
2493 Mirror
: TMirrorType
;
2497 if Direction
= TDirection
.D_RIGHT
then
2498 Mirror
:= TMirrorType
.None
2500 Mirror
:= TMirrorType
.Horizontal
;
2502 if FPunchAnim
<> nil then
2504 FPunchAnim
.Draw(FObj
.X
+IfThen(Direction
= TDirection
.D_LEFT
, 15-FObj
.Rect
.X
, FObj
.Rect
.X
-15),
2505 FObj
.Y
+FObj
.Rect
.Y
-11, Mirror
);
2506 if FPunchAnim
.played
then
2513 if (FMegaRulez
[MR_INVUL
] > gTime
) and ((gPlayerDrawn
<> Self
) or (FSpawnInvul
>= gTime
)) then
2514 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2516 e_GetTextureSize(ID
, @w
, @h
);
2517 if FDirection
= TDirection
.D_LEFT
then
2518 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2519 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False)
2521 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2522 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False);
2525 if FMegaRulez
[MR_INVIS
] > gTime
then
2527 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2528 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2530 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2531 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2535 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 200)
2537 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2540 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 254);
2543 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2546 if g_debug_Frames
then
2548 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2550 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2551 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2555 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2556 if (FMegaRulez
[MR_INVIS
] <= gTime
) or ((gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2557 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
)))) then
2559 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2560 if gAimLine
and alive
and
2561 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2566 procedure TPlayer
.DrawAim();
2567 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2572 {$IFDEF ENABLE_HOLMES}
2573 if isValidViewPort
and (self
= gPlayer1
) then
2575 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2579 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2580 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2582 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2586 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2591 wx
, wy
, xx
, yy
: Integer;
2595 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= TDirection
.D_LEFT
, 7, -7);
2596 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2605 1: begin // Chainsaw
2612 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2613 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2614 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2615 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2620 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2621 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2622 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2623 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2625 4: begin // Double Shotgun
2628 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2629 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2630 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2631 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2633 5: begin // Chaingun
2636 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2637 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2638 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2639 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2641 6: begin // Rocket Launcher
2644 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2645 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2646 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2647 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2649 7: begin // Plasmagun
2652 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2653 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2654 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2655 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2660 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2661 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2662 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2663 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2665 9: begin // Super Chaingun
2668 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2669 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2670 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2671 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2674 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2675 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2676 {$IF DEFINED(D2F_DEBUG)}
2677 drawCast(sz
, wx
, wy
, xx
, yy
);
2679 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2683 procedure TPlayer
.DrawGUI();
2686 X
, Y
, SY
, a
, p
, m
: Integer;
2690 stat
: TPlayerStatArray
;
2692 X
:= gPlayerScreenSize
.X
;
2693 SY
:= gPlayerScreenSize
.Y
;
2696 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2698 if gGameSettings
.GameMode
= GM_CTF
then
2702 if gGameSettings
.GameMode
= GM_CTF
then
2704 s
:= 'TEXTURE_PLAYER_REDFLAG';
2705 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2706 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2707 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2708 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2709 if g_Texture_Get(s
, ID
) then
2710 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2713 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2714 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2715 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2717 if gGameSettings
.GameMode
= GM_CTF
then
2719 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2720 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2721 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2722 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2723 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2724 if g_Texture_Get(s
, ID
) then
2725 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2728 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2729 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2730 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2733 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2734 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2737 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2738 e_Draw(ID
, X
+2, Y
, 0, True, False);
2740 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2744 s
:= IntToStr(Frags
);
2745 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2746 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2751 stat
:= g_Player_GetStats();
2756 for a
:= 0 to High(stat
) do
2757 if stat
[a
].Name
<> Name
then
2759 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2760 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2764 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2765 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2766 s
:= s
+IntToStr(Abs(Frags
-m
));
2768 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2769 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2772 if gLMSRespawn
> LMS_RESPAWN_NONE
then
2774 s
:= _lc
[I_GAME_WARMUP
];
2775 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2776 s
:= s
+ ': ' + IntToStr((gLMSRespawnTime
- gTime
) div 1000);
2777 e_CharFont_PrintEx(gMenuFont
, X
-64-tw
, SY
-32, s
, _RGB(0, 255, 0));
2779 else if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2781 s
:= IntToStr(Lives
);
2782 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2783 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2787 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2788 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2790 if R_BERSERK
in FRulez
then
2791 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2793 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2795 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2796 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2798 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2799 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2800 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2802 s
:= IntToStr(FArmor
);
2803 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2804 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2806 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2812 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2817 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2819 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2820 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2821 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2822 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2823 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2824 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2825 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2826 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2827 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2830 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2831 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2832 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2834 if R_KEY_RED
in FRulez
then
2835 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2837 if R_KEY_GREEN
in FRulez
then
2838 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2840 if R_KEY_BLUE
in FRulez
then
2841 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2843 if FJetFuel
> 0 then
2845 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2846 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2847 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2848 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2849 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2850 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2854 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2855 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2856 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2859 if gShowPing
and g_Game_IsClient
then
2861 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2862 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2868 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2869 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2870 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2873 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2874 s
:= _lc
[I_PLAYER_SPECT4
];
2875 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2876 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2877 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2883 procedure TPlayer
.DrawRulez();
2887 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2888 if (FMegaRulez
[MR_INVUL
] >= gTime
) and (FSpawnInvul
< gTime
) then
2890 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2891 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2896 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2897 191, 191, 191, 0, TBlending
.Invert
);
2900 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2901 if FMegaRulez
[MR_SUIT
] >= gTime
then
2903 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2904 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2909 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2910 0, 96, 0, 200, TBlending
.None
);
2913 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2914 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2916 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2917 255, 0, 0, 200, TBlending
.None
);
2921 procedure TPlayer
.DrawPain();
2925 if FPain
= 0 then Exit
;
2929 if a
< 15 then h
:= 0
2930 else if a
< 35 then h
:= 1
2931 else if a
< 55 then h
:= 2
2932 else if a
< 75 then h
:= 3
2933 else if a
< 95 then h
:= 4
2936 //if a > 255 then a := 255;
2938 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2939 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2942 procedure TPlayer
.DrawPickup();
2946 if FPickup
= 0 then Exit
;
2950 if a
< 15 then h
:= 1
2951 else if a
< 35 then h
:= 2
2952 else if a
< 55 then h
:= 3
2953 else if a
< 75 then h
:= 4
2956 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2959 procedure TPlayer
.DoPunch();
2964 if FPunchAnim
<> nil then begin
2969 st
:= 'FRAMES_PUNCH';
2970 if R_BERSERK
in FRulez
then
2971 st
:= st
+ '_BERSERK';
2972 if FKeys
[KEY_UP
].Pressed
then
2974 else if FKeys
[KEY_DOWN
].Pressed
then
2976 g_Frames_Get(id
, st
);
2977 FPunchAnim
:= TAnimation
.Create(id
, False, 1);
2980 procedure TPlayer
.Fire();
2982 f
, DidFire
: Boolean;
2983 wx
, wy
, xd
, yd
: Integer;
2986 if g_Game_IsClient
then Exit
;
2987 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2988 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2996 if FReloading
[FCurrWeap
] <> 0 then Exit
;
3001 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
3002 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
3003 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
3004 yd
:= wy
+firediry();
3010 if R_BERSERK
in FRulez
then
3012 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
3013 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
3014 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
3017 locobj
.rect
.Width
:= 39;
3018 locobj
.rect
.Height
:= 52;
3019 locobj
.Vel
.X
:= (xd
-wx
) div 2;
3020 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
3021 locobj
.Accel
.X
:= xd
-wx
;
3022 locobj
.Accel
.y
:= yd
-wy
;
3024 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
3025 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
3027 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
3029 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
3033 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
3037 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3042 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
3043 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
3045 FSawSoundSelect
.Stop();
3047 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
3049 else if not FSawSoundHit
.IsPlaying() then
3051 FSawSoundSelect
.Stop();
3052 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
3055 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3061 if FAmmo
[A_BULLETS
] > 0 then
3063 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
3064 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3065 Dec(FAmmo
[A_BULLETS
]);
3066 FFireAngle
:= FAngle
;
3069 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3070 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3074 if FAmmo
[A_SHELLS
] > 0 then
3076 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3077 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
3078 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3079 Dec(FAmmo
[A_SHELLS
]);
3080 FFireAngle
:= FAngle
;
3084 FShellType
:= SHELL_SHELL
;
3088 if FAmmo
[A_SHELLS
] >= 2 then
3090 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
3091 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3092 Dec(FAmmo
[A_SHELLS
], 2);
3093 FFireAngle
:= FAngle
;
3097 FShellType
:= SHELL_DBLSHELL
;
3101 if FAmmo
[A_BULLETS
] > 0 then
3103 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
3104 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
3105 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3106 Dec(FAmmo
[A_BULLETS
]);
3107 FFireAngle
:= FAngle
;
3110 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3111 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3114 WEAPON_ROCKETLAUNCHER
:
3115 if FAmmo
[A_ROCKETS
] > 0 then
3117 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
3118 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3119 Dec(FAmmo
[A_ROCKETS
]);
3120 FFireAngle
:= FAngle
;
3126 if FAmmo
[A_CELLS
] > 0 then
3128 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
3129 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3130 Dec(FAmmo
[A_CELLS
]);
3131 FFireAngle
:= FAngle
;
3137 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
3139 FBFGFireCounter
:= 17;
3140 if not FNoReload
then
3141 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
3142 Dec(FAmmo
[A_CELLS
], 40);
3146 WEAPON_SUPERPULEMET
:
3147 if FAmmo
[A_SHELLS
] > 0 then
3149 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3150 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
3151 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3152 Dec(FAmmo
[A_SHELLS
]);
3153 FFireAngle
:= FAngle
;
3156 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3157 GameVelX
, GameVelY
-2, SHELL_SHELL
);
3160 WEAPON_FLAMETHROWER
:
3161 if FAmmo
[A_FUEL
] > 0 then
3163 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
3165 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3167 FFireAngle
:= FAngle
;
3174 if g_Game_IsNet
and g_Game_IsServer
then MH_SEND_PlayerStats(FUID
);
3178 if g_Game_IsNet
then
3182 if FCurrWeap
<> WEAPON_BFG
then
3183 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
3185 if not FNoReload
then
3186 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
3189 MH_SEND_PlayerStats(FUID
);
3194 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
3195 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
3196 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
3199 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
3202 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
3203 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
3204 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
3205 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
3206 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
3211 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
3213 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
3214 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
3215 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
3218 procedure TPlayer
.FlamerOn
;
3220 FFlameSoundOff
.Stop();
3221 FFlameSoundOff
.SetPosition(0);
3224 if (not FFlameSoundOn
.IsPlaying()) and (not FFlameSoundWork
.IsPlaying()) then
3225 FFlameSoundWork
.PlayAt(FObj
.X
, FObj
.Y
);
3229 FFlameSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3234 procedure TPlayer
.FlamerOff
;
3238 FFlameSoundOn
.Stop();
3239 FFlameSoundOn
.SetPosition(0);
3240 FFlameSoundWork
.Stop();
3241 FFlameSoundWork
.SetPosition(0);
3242 FFlameSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3247 procedure TPlayer
.JetpackOn
;
3251 FJetSoundOn
.SetPosition(0);
3252 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3256 procedure TPlayer
.JetpackOff
;
3260 FJetSoundOff
.SetPosition(0);
3261 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3264 procedure TPlayer
.CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
3266 if Timeout
<= 0 then
3268 if (FMegaRulez
[MR_SUIT
] > gTime
) or (FMegaRulez
[MR_INVUL
] > gTime
) then
3269 exit
; // Íå çàãîðàåìñÿ êîãäà åñòü çàùèòà
3270 if g_Obj_CollidePanel(@FObj
, 0, 0, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
) then
3271 exit
; // Íå ïîäãîðàåì â âîäå íà âñÿêèé ñëó÷àé
3272 if FFireTime
<= 0 then
3273 g_Sound_PlayExAt('SOUND_IGNITE', FObj
.X
, FObj
.Y
);
3274 FFireTime
:= Timeout
;
3275 FFireAttacker
:= Attacker
;
3276 if g_Game_IsNet
and g_Game_IsServer
then
3277 MH_SEND_PlayerStats(FUID
);
3280 procedure TPlayer
.Jump();
3282 if gFly
or FJetpack
then
3284 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3285 if FObj
.Vel
.Y
> -VEL_FLY
then
3286 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3289 if FJetFuel
> 0 then
3291 if (FJetFuel
< 1) and g_Game_IsServer
then
3295 if g_Game_IsNet
then
3296 MH_SEND_PlayerStats(FUID
);
3302 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3304 FCanJetpack
:= False;
3306 // Ïðûãàåì èëè âñïëûâàåì:
3307 if (CollideLevel(0, 1) or
3308 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3309 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3310 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3312 FObj
.Vel
.Y
:= -VEL_JUMP
;
3313 FCanJetpack
:= False;
3317 if BodyInLiquid(0, 0) then
3318 FObj
.Vel
.Y
:= -VEL_SW
3319 else if (FJetFuel
> 0) and FCanJetpack
and
3320 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3324 if g_Game_IsNet
then
3325 MH_SEND_PlayerStats(FUID
);
3330 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3332 a
, i
, k
, ab
, ar
: Byte;
3336 srv
, netsrv
: Boolean;
3342 procedure PushItem(t
: Byte);
3346 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3347 it
:= g_Items_ByIdx(id
);
3348 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3350 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3351 (FObj
.Vel
.Y
div 2)-Random(9));
3352 it
.positionChanged(); // this updates spatial accelerators
3356 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3358 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3359 (FObj
.Vel
.Y
div 2)-Random(6));
3361 else // -3..+3; -3..0
3363 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3364 (FObj
.Vel
.Y
div 2)-Random(4));
3366 it
.positionChanged(); // this updates spatial accelerators
3369 if g_Game_IsNet
and g_Game_IsServer
then
3370 MH_SEND_ItemSpawn(True, id
);
3374 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3375 Srv
:= g_Game_IsServer
;
3376 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3377 if Srv
then FDeath
:= FDeath
+ 1;
3382 if not FPhysics
then
3388 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3390 if FLives
> 0 then FLives
:= FLives
- 1;
3391 if FLives
= 0 then FNoRespawn
:= True;
3394 // Íîìåð òèïà ñìåðòè:
3397 K_SIMPLEKILL
: a
:= 1;
3399 K_EXTRAHARDKILL
: a
:= 3;
3404 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3406 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3413 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3415 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3416 K_EXTRAHARDKILL
, K_FALLKILL
:
3417 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3420 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3424 K_HARDKILL
, K_EXTRAHARDKILL
:
3428 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3429 if (KillType
<> K_FALLKILL
) and (Srv
) then
3430 g_Monsters_killedp();
3432 if SpawnerUID
= FUID
then
3434 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3439 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3442 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3443 begin // Óáèò äðóãèì èãðîêîì
3444 KP
:= g_Player_Get(SpawnerUID
);
3445 if (KP
<> nil) and Srv
then
3447 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3448 if SameTeam(FUID
, SpawnerUID
) then
3458 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3459 Inc(gTeamStat
[KP
.Team
].Goals
,
3460 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3462 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3465 plr
:= g_Player_Get(SpawnerUID
);
3473 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3477 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3481 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3486 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3487 begin // Óáèò ìîíñòðîì
3488 mon
:= g_Monsters_ByUID(SpawnerUID
);
3492 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
3496 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3500 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3504 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3509 else // Îñîáûå òèïû ñìåðòè
3512 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3513 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3514 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3515 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3516 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3517 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3523 for a
:= WP_FIRST
to WP_LAST
do
3527 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3528 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3529 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3530 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3531 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3532 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3533 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3534 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3535 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3544 if R_ITEM_BACKPACK
in FRulez
then
3545 PushItem(ITEM_AMMO_BACKPACK
);
3547 // Âûáðîñ ðàêåòíîãî ðàíöà:
3548 if FJetFuel
> 0 then
3549 PushItem(ITEM_JETPACK
);
3552 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) or
3553 (not LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
)) then
3555 if R_KEY_RED
in FRulez
then
3556 PushItem(ITEM_KEY_RED
);
3558 if R_KEY_GREEN
in FRulez
then
3559 PushItem(ITEM_KEY_GREEN
);
3561 if R_KEY_BLUE
in FRulez
then
3562 PushItem(ITEM_KEY_BLUE
);
3566 DropFlag(KillType
= K_FALLKILL
);
3569 g_Player_CreateCorpse(Self
);
3571 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3572 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3578 for i
:= Low(gPlayers
) to High(gPlayers
) do
3580 if gPlayers
[i
] = nil then continue
;
3581 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3584 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3585 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3590 OldLR
:= gLMSRespawn
;
3591 if (gGameSettings
.GameMode
= GM_COOP
) then
3595 // everyone is dead, restart the map
3596 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3598 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3599 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3600 gLMSRespawnTime
:= gTime
+ 5000;
3602 else if (a
= 1) then
3604 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3605 if (gPlayers
[k
] = gPlayer1
) or
3606 (gPlayers
[k
] = gPlayer2
) then
3607 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3608 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3609 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3612 else if (gGameSettings
.GameMode
= GM_TDM
) then
3614 if (ab
= 0) and (ar
<> 0) then
3617 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3619 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3620 Inc(gTeamStat
[TEAM_RED
].Goals
);
3621 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3622 gLMSRespawnTime
:= gTime
+ 5000;
3624 else if (ar
= 0) and (ab
<> 0) then
3627 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3629 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3630 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3631 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3632 gLMSRespawnTime
:= gTime
+ 5000;
3634 else if (ar
= 0) and (ab
= 0) then
3637 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3639 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3640 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3641 gLMSRespawnTime
:= gTime
+ 5000;
3644 else if (gGameSettings
.GameMode
= GM_DM
) then
3648 if gPlayers
[k
] <> nil then
3651 // survivor is the winner
3652 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3654 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3657 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3658 gLMSRespawnTime
:= gTime
+ 5000;
3660 else if (a
= 0) then
3662 // everyone is dead, restart the map
3663 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3665 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3666 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3667 gLMSRespawnTime
:= gTime
+ 5000;
3670 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3672 if NetMode
= NET_SERVER
then
3673 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
)
3675 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3681 MH_SEND_PlayerStats(FUID
);
3682 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3683 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3686 if srv
and FNoRespawn
then Spectate(True);
3687 FWantsInGame
:= True;
3690 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3692 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3693 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3696 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3698 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3699 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3702 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3704 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3705 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3706 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3707 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3708 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3709 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3710 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3711 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3714 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3716 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3717 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3718 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3719 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3722 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3724 if g_Game_IsClient
then Exit
;
3725 if Weapon
> High(FWeapon
) then Exit
;
3726 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3729 procedure TPlayer
.resetWeaponQueue ();
3732 FNextWeapDelay
:= 0;
3735 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3739 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3740 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
3741 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
3742 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3743 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3744 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3745 else result
:= (weapon
< length(FWeapon
));
3749 // return 255 for "no switch"
3750 function TPlayer
.getNextWeaponIndex (): Byte;
3753 wantThisWeapon
: array[0..64] of Boolean;
3754 wwc
: Integer = 0; //HACK!
3757 result
:= 255; // default result: "no switch"
3758 // had weapon cycling on previous frame? remove that flag
3759 if (FNextWeap
and $2000) <> 0 then
3761 FNextWeap
:= FNextWeap
and $1FFF;
3762 FNextWeapDelay
:= 0;
3764 // cycling has priority
3765 if (FNextWeap
and $C000) <> 0 then
3767 if (FNextWeap
and $8000) <> 0 then
3771 FNextWeap
:= FNextWeap
or $2000; // we need this
3772 if FNextWeapDelay
> 0 then
3773 exit
; // cooldown time
3775 for i
:= 0 to High(FWeapon
) do
3777 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3778 if FWeapon
[cwi
] then
3780 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d', [FCurrWeap, cwi]), MSG_WARNING);
3781 result
:= Byte(cwi
);
3782 FNextWeapDelay
:= WEAPON_DELAY
;
3790 for i
:= 0 to High(wantThisWeapon
) do
3791 wantThisWeapon
[i
] := false;
3792 for i
:= 0 to High(FWeapon
) do
3793 if (FNextWeap
and (1 shl i
)) <> 0 then
3795 wantThisWeapon
[i
] := true;
3798 // exclude currently selected weapon from the set
3799 wantThisWeapon
[FCurrWeap
] := false;
3800 // slow down alterations a little
3803 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3804 // more than one weapon requested, assume "alteration" and check alteration delay
3805 if FNextWeapDelay
> 0 then
3811 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3812 // but clear all counters if no weapon should be switched
3818 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3819 // try weapons in descending order
3820 for i
:= High(FWeapon
) downto 0 do
3822 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3827 FNextWeapDelay
:= WEAPON_DELAY
* 2; // anyway, 'cause why not
3831 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3835 procedure TPlayer
.RealizeCurrentWeapon();
3836 function switchAllowed (): Boolean;
3841 if FBFGFireCounter
<> -1 then
3843 if FTime
[T_SWITCH
] > gTime
then
3845 for i
:= WP_FIRST
to WP_LAST
do
3846 if FReloading
[i
] > 0 then
3854 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3855 //FNextWeap := FNextWeap and $1FFF;
3856 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3858 if not switchAllowed
then
3860 //HACK for weapon cycling
3861 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3865 nw
:= getNextWeaponIndex();
3866 if nw
= 255 then exit
; // don't reset anything here
3867 if nw
> High(FWeapon
) then
3869 // don't forget to reset queue here!
3870 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3878 FTime
[T_SWITCH
] := gTime
+156;
3879 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3880 FModel
.SetWeapon(FCurrWeap
);
3881 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3885 procedure TPlayer
.NextWeapon();
3887 if g_Game_IsClient
then Exit
;
3891 procedure TPlayer
.PrevWeapon();
3893 if g_Game_IsClient
then Exit
;
3897 procedure TPlayer
.SetWeapon(W
: Byte);
3899 if FCurrWeap
<> W
then
3900 if W
= WEAPON_SAW
then
3901 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3904 FModel
.SetWeapon(CurrWeap
);
3908 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3910 function allowBerserkSwitching (): Boolean;
3912 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3914 if gBerserkAutoswitch
then exit
;
3915 if not conIsCheatsEnabled
then exit
;
3923 if g_Game_IsClient
then Exit
;
3925 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3926 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3931 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3933 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3937 if gFlash
= 2 then Inc(FPickup
, 5);
3941 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3943 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3947 if gFlash
= 2 then Inc(FPickup
, 5);
3951 if FArmor
< PLAYER_AP_SOFT
then
3953 FArmor
:= PLAYER_AP_SOFT
;
3956 if gFlash
= 2 then Inc(FPickup
, 5);
3960 if FArmor
< PLAYER_AP_LIMIT
then
3962 FArmor
:= PLAYER_AP_LIMIT
;
3965 if gFlash
= 2 then Inc(FPickup
, 5);
3969 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
3971 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3975 if gFlash
= 2 then Inc(FPickup
, 5);
3979 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) or (FFireTime
> 0) then
3981 if FHealth
< PLAYER_HP_LIMIT
then
3982 FHealth
:= PLAYER_HP_LIMIT
;
3983 if FArmor
< PLAYER_AP_LIMIT
then
3984 FArmor
:= PLAYER_AP_LIMIT
;
3988 if gFlash
= 2 then Inc(FPickup
, 5);
3992 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3994 FWeapon
[WEAPON_SAW
] := True;
3996 if gFlash
= 2 then Inc(FPickup
, 5);
3997 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4000 ITEM_WEAPON_SHOTGUN1
:
4001 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
4003 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
4004 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
4006 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4007 FWeapon
[WEAPON_SHOTGUN1
] := True;
4009 if gFlash
= 2 then Inc(FPickup
, 5);
4010 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4013 ITEM_WEAPON_SHOTGUN2
:
4014 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
4016 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
4018 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4019 FWeapon
[WEAPON_SHOTGUN2
] := True;
4021 if gFlash
= 2 then Inc(FPickup
, 5);
4022 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4025 ITEM_WEAPON_CHAINGUN
:
4026 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
4028 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
4030 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4031 FWeapon
[WEAPON_CHAINGUN
] := True;
4033 if gFlash
= 2 then Inc(FPickup
, 5);
4034 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4037 ITEM_WEAPON_ROCKETLAUNCHER
:
4038 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
4040 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
4042 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
4043 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
4045 if gFlash
= 2 then Inc(FPickup
, 5);
4046 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4050 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
4052 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
4054 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4055 FWeapon
[WEAPON_PLASMA
] := True;
4057 if gFlash
= 2 then Inc(FPickup
, 5);
4058 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4062 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
4064 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
4066 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4067 FWeapon
[WEAPON_BFG
] := True;
4069 if gFlash
= 2 then Inc(FPickup
, 5);
4070 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4073 ITEM_WEAPON_SUPERPULEMET
:
4074 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
4076 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
4078 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4079 FWeapon
[WEAPON_SUPERPULEMET
] := True;
4081 if gFlash
= 2 then Inc(FPickup
, 5);
4082 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4085 ITEM_WEAPON_FLAMETHROWER
:
4086 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
4088 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
4090 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4091 FWeapon
[WEAPON_FLAMETHROWER
] := True;
4093 if gFlash
= 2 then Inc(FPickup
, 5);
4094 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4098 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4100 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4103 if gFlash
= 2 then Inc(FPickup
, 5);
4106 ITEM_AMMO_BULLETS_BOX
:
4107 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4109 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4112 if gFlash
= 2 then Inc(FPickup
, 5);
4116 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4118 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4121 if gFlash
= 2 then Inc(FPickup
, 5);
4124 ITEM_AMMO_SHELLS_BOX
:
4125 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4127 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
4130 if gFlash
= 2 then Inc(FPickup
, 5);
4134 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4136 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4139 if gFlash
= 2 then Inc(FPickup
, 5);
4142 ITEM_AMMO_ROCKET_BOX
:
4143 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4145 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
4148 if gFlash
= 2 then Inc(FPickup
, 5);
4152 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4154 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4157 if gFlash
= 2 then Inc(FPickup
, 5);
4161 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4163 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4166 if gFlash
= 2 then Inc(FPickup
, 5);
4170 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4172 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4175 if gFlash
= 2 then Inc(FPickup
, 5);
4179 if not(R_ITEM_BACKPACK
in FRulez
) or
4180 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4181 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4182 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4183 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4184 (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) then
4186 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4187 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4188 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4189 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4190 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4192 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4193 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4194 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4195 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4196 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4197 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4198 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4199 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4200 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4201 IncMax(FAmmo
[A_FUEL
], 50, FMaxAmmo
[A_FUEL
]);
4203 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
4206 if gFlash
= 2 then Inc(FPickup
, 5);
4210 if not(R_KEY_RED
in FRulez
) then
4212 Include(FRulez
, R_KEY_RED
);
4214 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4215 if gFlash
= 2 then Inc(FPickup
, 5);
4216 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4220 if not(R_KEY_GREEN
in FRulez
) then
4222 Include(FRulez
, R_KEY_GREEN
);
4224 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4225 if gFlash
= 2 then Inc(FPickup
, 5);
4226 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4230 if not(R_KEY_BLUE
in FRulez
) then
4232 Include(FRulez
, R_KEY_BLUE
);
4234 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4235 if gFlash
= 2 then Inc(FPickup
, 5);
4236 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4240 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4242 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4246 if gFlash
= 2 then Inc(FPickup
, 5);
4250 if FAir
< AIR_MAX
then
4255 if gFlash
= 2 then Inc(FPickup
, 5);
4260 if not (R_BERSERK
in FRulez
) then
4262 Include(FRulez
, R_BERSERK
);
4263 if allowBerserkSwitching
then
4265 FCurrWeap
:= WEAPON_KASTET
;
4267 FModel
.SetWeapon(WEAPON_KASTET
);
4272 if gFlash
= 2 then Inc(FPickup
, 5);
4274 FBerserk
:= gTime
+30000;
4279 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
4281 if FHealth
< PLAYER_HP_SOFT
then FHealth
:= PLAYER_HP_SOFT
;
4282 FBerserk
:= gTime
+30000;
4290 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4292 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4296 if gFlash
= 2 then Inc(FPickup
, 5);
4300 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
4302 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4306 if gFlash
= 2 then Inc(FPickup
, 5);
4310 if FArmor
< PLAYER_AP_LIMIT
then
4312 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4315 if gFlash
= 2 then Inc(FPickup
, 5);
4319 if FJetFuel
< JET_MAX
then
4321 FJetFuel
:= JET_MAX
;
4324 if gFlash
= 2 then Inc(FPickup
, 5);
4328 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4330 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4333 if gFlash
= 2 then Inc(FPickup
, 5);
4338 procedure TPlayer
.Touch();
4342 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4345 // Áðîñèòü ôëàã òîâàðèùó:
4346 if gGameSettings
.GameMode
= GM_CTF
then
4351 procedure TPlayer
.Push(vx
, vy
: Integer);
4353 if (not FPhysics
) and FGhost
then
4355 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4356 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4357 if g_Game_IsNet
and g_Game_IsServer
then
4358 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4361 procedure TPlayer
.Reset(Force
: Boolean);
4367 FTime
[T_RESPAWN
] := 0;
4368 FTime
[T_FLAGCAP
] := 0;
4383 FSpectator
:= False;
4386 FSpectatePlayer
:= -1;
4387 FNoRespawn
:= False;
4389 FLives
:= gGameSettings
.MaxLives
;
4394 procedure TPlayer
.SoftReset();
4400 FBFGFireCounter
:= -1;
4408 SetAction(A_STAND
, True);
4411 function TPlayer
.GetRespawnPoint(): Byte;
4416 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4418 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4419 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4421 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4423 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4424 if Self
= gPlayer1
then
4425 c
:= RESPAWNPOINT_PLAYER1
4427 c
:= RESPAWNPOINT_PLAYER2
;
4428 if g_Map_GetPointCount(c
) > 0 then
4434 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4435 if Self
= gPlayer1
then
4436 c
:= RESPAWNPOINT_PLAYER2
4438 c
:= RESPAWNPOINT_PLAYER1
;
4439 if g_Map_GetPointCount(c
) > 0 then
4446 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4447 if Random(2) = 0 then
4448 c
:= RESPAWNPOINT_PLAYER1
4450 c
:= RESPAWNPOINT_PLAYER2
;
4451 if g_Map_GetPointCount(c
) > 0 then
4458 // Òî÷êà ëþáîé èç êîìàíä
4459 if Random(2) = 0 then
4460 c
:= RESPAWNPOINT_RED
4462 c
:= RESPAWNPOINT_BLUE
;
4463 if g_Map_GetPointCount(c
) > 0 then
4470 c
:= RESPAWNPOINT_DM
;
4471 if g_Map_GetPointCount(c
) > 0 then
4479 if gGameSettings
.GameMode
= GM_DM
then
4482 c
:= RESPAWNPOINT_DM
;
4483 if g_Map_GetPointCount(c
) > 0 then
4489 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4490 if Random(2) = 0 then
4491 c
:= RESPAWNPOINT_PLAYER1
4493 c
:= RESPAWNPOINT_PLAYER2
;
4494 if g_Map_GetPointCount(c
) > 0 then
4500 // Òî÷êà ëþáîé èç êîìàíä
4501 if Random(2) = 0 then
4502 c
:= RESPAWNPOINT_RED
4504 c
:= RESPAWNPOINT_BLUE
;
4505 if g_Map_GetPointCount(c
) > 0 then
4513 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4515 // Òî÷êà ñâîåé êîìàíäû
4516 c
:= RESPAWNPOINT_DM
;
4517 if FTeam
= TEAM_RED
then
4518 c
:= RESPAWNPOINT_RED
;
4519 if FTeam
= TEAM_BLUE
then
4520 c
:= RESPAWNPOINT_BLUE
;
4521 if g_Map_GetPointCount(c
) > 0 then
4528 c
:= RESPAWNPOINT_DM
;
4529 if g_Map_GetPointCount(c
) > 0 then
4535 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4536 if Random(2) = 0 then
4537 c
:= RESPAWNPOINT_PLAYER1
4539 c
:= RESPAWNPOINT_PLAYER2
;
4540 if g_Map_GetPointCount(c
) > 0 then
4546 // Òî÷êà äðóãîé êîìàíäû
4547 c
:= RESPAWNPOINT_DM
;
4548 if FTeam
= TEAM_RED
then
4549 c
:= RESPAWNPOINT_BLUE
;
4550 if FTeam
= TEAM_BLUE
then
4551 c
:= RESPAWNPOINT_RED
;
4552 if g_Map_GetPointCount(c
) > 0 then
4560 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4562 RespawnPoint
: TRespawnPoint
;
4568 FBFGFireCounter
:= -1;
4574 if not g_Game_IsServer
then
4578 FWantsInGame
:= True;
4579 FJustTeleported
:= True;
4582 FTime
[T_RESPAWN
] := 0;
4586 // if server changes MaxLives we gotta be ready
4587 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4589 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4590 if FTime
[T_RESPAWN
] > gTime
then
4593 // Ïðîñðàë âñå æèçíè:
4596 if not FSpectator
then Spectate(True);
4597 FWantsInGame
:= True;
4601 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4602 begin // "Ñâîÿ èãðà"
4603 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4604 FRulez
:= FRulez
-[R_BERSERK
];
4606 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4608 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4609 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4612 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4613 c
:= GetRespawnPoint();
4618 // Âîñêðåøåíèå áåç îðóæèÿ:
4621 FHealth
:= Round(PLAYER_HP_SOFT
* (FHandicap
/ 100));
4627 for a
:= WP_FIRST
to WP_LAST
do
4629 FWeapon
[a
] := False;
4633 FWeapon
[WEAPON_PISTOL
] := True;
4634 FWeapon
[WEAPON_KASTET
] := True;
4635 FCurrWeap
:= WEAPON_PISTOL
;
4638 FModel
.SetWeapon(FCurrWeap
);
4640 for b
:= A_BULLETS
to A_HIGH
do
4643 FAmmo
[A_BULLETS
] := 50;
4645 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4646 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4647 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4648 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4649 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4651 if (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) and
4652 LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
) then
4653 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4658 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4659 if not g_Map_GetPoint(c
, RespawnPoint
) then
4661 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4665 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4666 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4667 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4673 FDirection
:= RespawnPoint
.Direction
;
4674 if FDirection
= TDirection
.D_LEFT
then
4679 SetAction(A_STAND
, True);
4680 FModel
.Direction
:= FDirection
;
4682 for a
:= Low(FTime
) to High(FTime
) do
4685 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4688 // Respawn invulnerability
4689 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.SpawnInvul
> 0) then
4691 FMegaRulez
[MR_INVUL
] := gTime
+ gGameSettings
.SpawnInvul
* 1000;
4692 FSpawnInvul
:= FMegaRulez
[MR_INVUL
];
4697 FCanJetpack
:= False;
4703 // Àíèìàöèÿ âîçðîæäåíèÿ:
4704 if (not gLoadGameMode
) and (not Silent
) then
4705 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4707 Anim
:= TAnimation
.Create(ID
, False, 3);
4708 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4709 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4713 FSpectator
:= False;
4716 FSpectatePlayer
:= -1;
4719 if (gPlayer1
= nil) and (gSpectLatchPID1
= FUID
) then
4721 if (gPlayer2
= nil) and (gSpectLatchPID2
= FUID
) then
4724 if g_Game_IsNet
then
4726 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4727 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4729 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4730 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4735 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4738 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4739 else if (not NoMove
) then
4741 GameX
:= gMapInfo
.Width
div 2;
4742 GameY
:= gMapInfo
.Height
div 2;
4751 FWantsInGame
:= False;
4756 if Self
= gPlayer1
then
4758 gSpectLatchPID1
:= FUID
;
4761 else if Self
= gPlayer2
then
4763 gSpectLatchPID2
:= FUID
;
4768 if g_Game_IsNet
then
4769 MH_SEND_PlayerStats(FUID
);
4772 procedure TPlayer
.SwitchNoClip
;
4776 FGhost
:= not FGhost
;
4777 FPhysics
:= not FGhost
;
4789 procedure TPlayer
.Run(Direction
: TDirection
);
4793 if MAX_RUNVEL
> 8 then
4797 if Direction
= TDirection
.D_LEFT
then
4799 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4800 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4803 if FObj
.Vel
.X
< MAX_RUNVEL
then
4804 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4806 // Âîçìîæíî, ïèíàåì êóñêè:
4807 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4809 b
:= Abs(FObj
.Vel
.X
);
4810 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4811 for a
:= 0 to High(gGibs
) do
4813 if gGibs
[a
].alive
and
4814 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4815 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4818 if FObj
.Vel
.X
< 0 then
4820 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4824 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4826 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4834 procedure TPlayer
.SeeDown();
4836 SetAction(A_SEEDOWN
);
4838 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4840 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4843 procedure TPlayer
.SeeUp();
4847 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4849 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4852 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4860 A_ATTACK
: Prior
:= 2;
4861 A_SEEUP
: Prior
:= 1;
4862 A_SEEDOWN
: Prior
:= 1;
4863 A_ATTACKUP
: Prior
:= 2;
4864 A_ATTACKDOWN
: Prior
:= 2;
4869 if (Prior
> FActionPrior
) or Force
then
4870 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4872 FActionPrior
:= Prior
;
4873 FActionAnim
:= Action
;
4874 FActionForce
:= Force
;
4875 FActionChanged
:= True;
4878 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4881 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4883 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4884 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4885 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4886 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4889 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4896 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4898 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4899 if g_Game_IsServer
and g_Game_IsNet
then
4900 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4904 FJustTeleported
:= True;
4909 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4911 Anim
:= TAnimation
.Create(ID
, False, 3);
4914 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4915 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4916 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4917 if g_Game_IsServer
and g_Game_IsNet
then
4918 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4919 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4923 FObj
.X
:= X
-PLAYER_RECT
.X
;
4924 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4925 if FAlive
and FGhost
then
4931 if not g_Game_IsNet
then
4935 SetDirection(TDirection
.D_LEFT
);
4941 SetDirection(TDirection
.D_RIGHT
);
4947 if FDirection
= TDirection
.D_RIGHT
then
4949 SetDirection(TDirection
.D_LEFT
);
4954 SetDirection(TDirection
.D_RIGHT
);
4960 if not silent
and (Anim
<> nil) then
4962 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4963 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4966 if g_Game_IsServer
and g_Game_IsNet
then
4967 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4968 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4975 function nonz(a
: Single): Single;
4983 function TPlayer
.followCorpse(): Boolean;
4988 if FAlive
or FSpectator
then
4990 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
4992 for i
:= 0 to High(gCorpses
) do
4993 if gCorpses
[i
] <> nil then
4994 if gCorpses
[i
].FPlayerUID
= FUID
then
4997 FObj
.X
:= gCorpses
[i
].FObj
.X
;
4998 FObj
.Y
:= gCorpses
[i
].FObj
.Y
;
4999 FObj
.Vel
.X
:= gCorpses
[i
].FObj
.Vel
.X
;
5000 FObj
.Vel
.Y
:= gCorpses
[i
].FObj
.Vel
.Y
;
5001 FObj
.Accel
.X
:= gCorpses
[i
].FObj
.Accel
.X
;
5002 FObj
.Accel
.Y
:= gCorpses
[i
].FObj
.Accel
.Y
;
5007 procedure TPlayer
.Update();
5010 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
5011 blockmon
, headwater
, dospawn
: Boolean;
5016 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
5017 AnyServer
:= g_Game_IsServer
;
5019 if g_Game_IsClient
and (NetInterpLevel
> 0) then
5020 DoLerp(NetInterpLevel
+ 1)
5026 if FClientID
>= 0 then
5028 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
5029 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
5030 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
5039 if FAlive
and (FPunchAnim
<> nil) then
5040 FPunchAnim
.Update();
5042 if FAlive
and (gFly
or FJetpack
) then
5045 if FDirection
= TDirection
.D_LEFT
then
5050 if FAlive
and (not FGhost
) then
5052 if FKeys
[KEY_UP
].Pressed
then
5054 if FKeys
[KEY_DOWN
].Pressed
then
5058 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
5061 i
:= g_basic
.Sign(FIncCam
);
5062 FIncCam
:= Abs(FIncCam
);
5063 DecMin(FIncCam
, 5, 0);
5064 FIncCam
:= FIncCam
*i
;
5067 // no need to do that each second frame, weapon queue will take care of it
5068 if FAlive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
5069 if FAlive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
5071 if gTime
mod (GAME_TICK
*2) <> 0 then
5073 if (FObj
.Vel
.X
= 0) and FAlive
then
5075 if FKeys
[KEY_LEFT
].Pressed
then
5076 Run(TDirection
.D_LEFT
);
5077 if FKeys
[KEY_RIGHT
].Pressed
then
5078 Run(TDirection
.D_RIGHT
);
5083 if not followCorpse() then
5084 g_Obj_Move(@FObj
, True, True, True);
5085 positionChanged(); // this updates spatial accelerators
5091 FActionChanged
:= False;
5095 // Let alive player do some actions
5096 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
5097 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
5098 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
5099 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
5100 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire()
5106 if NetServer
then MH_SEND_PlayerStats(FUID
);
5109 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
5110 if FKeys
[KEY_JUMP
].Pressed
then Jump()
5113 if AnyServer
and FJetpack
then
5117 if NetServer
then MH_SEND_PlayerStats(FUID
);
5119 FCanJetpack
:= True;
5126 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
5128 if FKeys
[k
].Pressed
then
5136 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5139 if (FTime
[T_RESPAWN
] <= gTime
) and
5140 gGameOn
and (not FAlive
) then
5142 if (g_Player_GetCount() > 1) then
5146 gExit
:= EXIT_RESTART
;
5151 // Dead spectator actions
5154 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
5155 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
5159 if (FSpectatePlayer
>= High(gPlayers
)) then
5160 FSpectatePlayer
:= -1
5164 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
5165 if gPlayers
[I
] <> nil then
5166 if gPlayers
[I
].alive
then
5167 if gPlayers
[I
].UID
<> FUID
then
5169 FSpectatePlayer
:= I
;
5174 if not SetSpect
then FSpectatePlayer
:= -1;
5185 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5187 FYTo
:= FObj
.Y
- 32;
5188 FSpectatePlayer
:= -1;
5190 if FKeys
[KEY_DOWN
].Pressed
then
5192 FYTo
:= FObj
.Y
+ 32;
5193 FSpectatePlayer
:= -1;
5195 if FKeys
[KEY_LEFT
].Pressed
then
5197 FXTo
:= FObj
.X
- 32;
5198 FSpectatePlayer
:= -1;
5200 if FKeys
[KEY_RIGHT
].Pressed
then
5202 FXTo
:= FObj
.X
+ 32;
5203 FSpectatePlayer
:= -1;
5206 if (FXTo
< -64) then
5208 else if (FXTo
> gMapInfo
.Width
+ 32) then
5209 FXTo
:= gMapInfo
.Width
+ 32;
5210 if (FYTo
< -72) then
5212 else if (FYTo
> gMapInfo
.Height
+ 32) then
5213 FYTo
:= gMapInfo
.Height
+ 32;
5218 if not followCorpse() then
5219 g_Obj_Move(@FObj
, True, True, True);
5220 positionChanged(); // this updates spatial accelerators
5227 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5228 if gPlayers
[FSpectatePlayer
] <> nil then
5229 if gPlayers
[FSpectatePlayer
].alive
then
5231 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
5232 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
5236 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5237 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5238 PANEL_BLOCKMON
, True);
5239 headwater
:= HeadInLiquid(0, 0);
5241 // Ñîïðîòèâëåíèå âîçäóõà:
5242 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5243 if FObj
.Vel
.X
<> 0 then
5244 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5246 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5247 DecMin(FPain
, 5, 0);
5248 DecMin(FPickup
, 1, 0);
5250 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5252 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5253 FMegaRulez
[MR_SUIT
] := 0;
5254 FMegaRulez
[MR_INVUL
] := 0;
5255 FMegaRulez
[MR_INVIS
] := 0;
5256 Kill(K_FALLKILL
, 0, HIT_FALL
);
5263 if FCurrWeap
= WEAPON_SAW
then
5264 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5265 FSawSoundSelect
.IsPlaying()) then
5266 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5269 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5270 (not FJetSoundOff
.IsPlaying()) then
5272 FJetSoundFly
.SetPosition(0);
5273 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5276 for b
:= WP_FIRST
to WP_LAST
do
5277 if FReloading
[b
] > 0 then
5283 if FShellTimer
> -1 then
5284 if FShellTimer
= 0 then
5286 if FShellType
= SHELL_SHELL
then
5287 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5288 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5289 else if FShellType
= SHELL_DBLSHELL
then
5291 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5292 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5293 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5294 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5297 end else Dec(FShellTimer
);
5299 if (FBFGFireCounter
> -1) then
5300 if FBFGFireCounter
= 0 then
5304 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5305 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5306 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5307 yd
:= wy
+firediry();
5308 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5309 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5310 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5311 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5312 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5315 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5316 FBFGFireCounter
:= -1;
5319 FBFGFireCounter
:= 0
5321 Dec(FBFGFireCounter
);
5323 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5325 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5327 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5330 if (headwater
or blockmon
) then
5336 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5339 else if (FAir
mod 31 = 0) and not blockmon
then
5341 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5342 if Random(2) = 0 then
5343 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5345 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5347 end else if FAir
< AIR_DEF
then
5350 if FFireTime
> 0 then
5352 if BodyInLiquid(0, 0) then
5357 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5359 if FMegaRulez
[MR_SUIT
] = gTime
then
5366 if FFirePainTime
<= 0 then
5368 if g_Game_IsServer
then
5369 Damage(2, FFireAttacker
, 0, 0, HIT_FLAME
);
5370 FFirePainTime
:= 12 - FFireTime
div 12;
5372 FFirePainTime
:= FFirePainTime
- 1;
5373 FFireTime
:= FFireTime
- 1;
5374 if ((FFireTime
mod 33) = 0) and (FMegaRulez
[MR_INVUL
] < gTime
) then
5375 FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
);
5376 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5377 MH_SEND_PlayerStats(FUID
);
5381 if FDamageBuffer
> 0 then
5383 if FDamageBuffer
>= 9 then
5387 if FDamageBuffer
< 30 then i
:= 9
5388 else if FDamageBuffer
< 100 then i
:= 18
5392 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5393 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5394 FHealth
:= FHealth
-ii
;
5397 FHealth
:= FHealth
+FArmor
;
5402 if FHealth
<= 0 then
5403 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5404 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5405 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5407 if FAlive
and ((FLastHit
<> HIT_FLAME
) or (FFireTime
<= 0)) then
5409 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5410 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5411 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5412 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5419 end; // if FAlive then ...
5421 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5423 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5424 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5425 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5426 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5428 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5429 then SetAction(A_STAND
, True);
5431 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5433 for b
:= Low(FKeys
) to High(FKeys
) do
5434 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5438 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5440 x
:= FObj
.X
+PLAYER_RECT
.X
;
5441 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5442 w
:= PLAYER_RECT
.Width
;
5443 h
:= PLAYER_RECT
.Height
;
5447 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5449 if (dx
<> 0) or (dy
<> 0) then
5458 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5460 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5461 FObj
.Y
+PLAYER_RECT
.Y
,
5468 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5470 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5471 FObj
.Y
+PLAYER_RECT
.Y
,
5475 Panel
.Width
, Panel
.Height
);
5478 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5480 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5481 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5482 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5483 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5486 function g_Player_ValidName(Name
: string): Boolean;
5492 if gPlayers
= nil then Exit
;
5494 for a
:= 0 to High(gPlayers
) do
5495 if gPlayers
[a
] <> nil then
5496 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5503 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5507 d
:= FModel
.Direction
;
5509 FModel
.Direction
:= Direction
;
5510 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5512 FDirection
:= Direction
;
5515 function TPlayer
.GetKeys(): Byte;
5519 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5520 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5521 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5523 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5524 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5527 procedure TPlayer
.Use();
5531 if FTime
[T_USE
] > gTime
then Exit
;
5533 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5534 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5536 for a
:= 0 to High(gPlayers
) do
5537 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5538 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5539 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5540 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5542 gPlayers
[a
].Touch();
5543 if g_Game_IsNet
and g_Game_IsServer
then
5544 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5547 FTime
[T_USE
] := gTime
+120;
5550 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5554 WX
, WY
, XD
, YD
: Integer;
5566 if R_BERSERK
in FRulez
then
5568 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5569 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5570 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5573 locobj
.rect
.Width
:= 39;
5574 locobj
.rect
.Height
:= 52;
5575 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5576 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5577 locobj
.Accel
.X
:= xd
-wx
;
5578 locobj
.Accel
.y
:= yd
-wy
;
5580 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5581 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5583 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5587 FPain
:= min(FPain
+ 25, 50);
5589 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5594 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5595 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5597 FSawSoundSelect
.Stop();
5599 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5601 else if not FSawSoundHit
.IsPlaying() then
5603 FSawSoundSelect
.Stop();
5604 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5611 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5612 FFireAngle
:= FAngle
;
5614 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5615 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5620 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5621 FFireAngle
:= FAngle
;
5624 FShellType
:= SHELL_SHELL
;
5629 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5630 FFireAngle
:= FAngle
;
5633 FShellType
:= SHELL_DBLSHELL
;
5638 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5639 FFireAngle
:= FAngle
;
5641 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5642 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5645 WEAPON_ROCKETLAUNCHER
:
5647 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5648 FFireAngle
:= FAngle
;
5654 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5655 FFireAngle
:= FAngle
;
5661 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5662 FFireAngle
:= FAngle
;
5666 WEAPON_SUPERPULEMET
:
5668 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5669 FFireAngle
:= FAngle
;
5671 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5672 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5675 WEAPON_FLAMETHROWER
:
5677 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5679 FFireAngle
:= FAngle
;
5686 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5687 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5688 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5691 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5693 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5694 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5697 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5701 if NetInterpLevel
< 1 then
5711 AX
:= Abs(FXTo
- FObj
.X
);
5712 AY
:= Abs(FYTo
- FObj
.Y
);
5713 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5715 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5720 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5722 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5723 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5724 PANEL_LIFTUP
, False) then Result
:= -1
5726 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5727 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5728 PANEL_LIFTDOWN
, False) then Result
:= 1
5732 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5739 if Flag
= FLAG_NONE
then
5742 if not g_Game_IsServer
then Exit
;
5744 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5745 if (Flag
= FTeam
) and
5746 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5747 (FFlag
<> FLAG_NONE
) then
5749 if FFlag
= FLAG_RED
then
5750 s
:= _lc
[I_PLAYER_FLAG_RED
]
5752 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5754 evtype
:= FLAG_STATE_SCORED
;
5756 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5757 Insert('.', ts
, Length(ts
) + 1 - 3);
5758 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5760 g_Map_ResetFlag(FFlag
);
5761 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5763 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5764 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5765 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5770 if not sound_cap_flag
[a
].IsPlaying() then
5771 sound_cap_flag
[a
].Play();
5773 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5776 if g_Game_IsNet
then
5778 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5782 gFlags
[FFlag
].CaptureTime
:= 0;
5787 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5788 if (Flag
= FTeam
) and
5789 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5791 if Flag
= FLAG_RED
then
5792 s
:= _lc
[I_PLAYER_FLAG_RED
]
5794 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5796 evtype
:= FLAG_STATE_RETURNED
;
5797 gFlags
[Flag
].CaptureTime
:= 0;
5799 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5801 g_Map_ResetFlag(Flag
);
5802 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5804 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5805 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5806 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5811 if not sound_ret_flag
[a
].IsPlaying() then
5812 sound_ret_flag
[a
].Play();
5815 if g_Game_IsNet
then
5817 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5823 // Ïîäîáðàë ÷óæîé ôëàã:
5824 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5828 if Flag
= FLAG_RED
then
5829 s
:= _lc
[I_PLAYER_FLAG_RED
]
5831 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5833 evtype
:= FLAG_STATE_CAPTURED
;
5835 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5837 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5839 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5841 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5842 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5843 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5848 if not sound_get_flag
[a
].IsPlaying() then
5849 sound_get_flag
[a
].Play();
5852 if g_Game_IsNet
then
5854 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5860 procedure TPlayer
.SetFlag(Flag
: Byte);
5863 if FModel
<> nil then
5864 FModel
.SetFlag(FFlag
);
5867 function TPlayer
.DropFlag(Silent
: Boolean = True): Boolean;
5873 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5875 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5876 with gFlags
[FFlag
] do
5880 Direction
:= FDirection
;
5881 State
:= FLAG_STATE_DROPPED
;
5883 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5884 (FObj
.Vel
.Y
div 2)-2+Random(5));
5885 positionChanged(); // this updates spatial accelerators
5887 if FFlag
= FLAG_RED
then
5888 s
:= _lc
[I_PLAYER_FLAG_RED
]
5890 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5892 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5893 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5895 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5896 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5897 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5902 if (not Silent
) and (not sound_lost_flag
[a
].IsPlaying()) then
5903 sound_lost_flag
[a
].Play();
5905 if g_Game_IsNet
then
5906 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5912 procedure TPlayer
.GetSecret();
5914 if (self
= gPlayer1
) or (self
= gPlayer2
) then
5916 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [FName
]), True);
5917 g_Sound_PlayEx('SOUND_GAME_SECRET');
5922 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5924 Assert(Key
<= High(FKeys
));
5926 FKeys
[Key
].Pressed
:= True;
5927 FKeys
[Key
].Time
:= Time
;
5930 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5932 Result
:= FKeys
[K
].Pressed
;
5935 procedure TPlayer
.ReleaseKeys();
5939 for a
:= Low(FKeys
) to High(FKeys
) do
5941 FKeys
[a
].Pressed
:= False;
5946 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5950 function TPlayer
.firediry(): Integer;
5952 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5953 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5957 procedure TPlayer
.RememberState();
5960 SavedState
: TPlayerSavedState
;
5962 SavedState
.Health
:= FHealth
;
5963 SavedState
.Armor
:= FArmor
;
5964 SavedState
.Air
:= FAir
;
5965 SavedState
.JetFuel
:= FJetFuel
;
5966 SavedState
.CurrWeap
:= FCurrWeap
;
5967 SavedState
.NextWeap
:= FNextWeap
;
5968 SavedState
.NextWeapDelay
:= FNextWeapDelay
;
5969 for i
:= Low(FWeapon
) to High(FWeapon
) do
5970 SavedState
.Weapon
[i
] := FWeapon
[i
];
5971 for i
:= Low(FAmmo
) to High(FAmmo
) do
5972 SavedState
.Ammo
[i
] := FAmmo
[i
];
5973 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
5974 SavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5975 SavedState
.Rulez
:= FRulez
- [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5977 FSavedStateNum
:= -1;
5978 for i
:= Low(SavedStates
) to High(SavedStates
) do
5979 if not SavedStates
[i
].Used
then
5981 FSavedStateNum
:= i
;
5984 if FSavedStateNum
< 0 then
5986 SetLength(SavedStates
, Length(SavedStates
) + 1);
5987 FSavedStateNum
:= High(SavedStates
);
5990 SavedState
.Used
:= True;
5991 SavedStates
[FSavedStateNum
] := SavedState
;
5994 procedure TPlayer
.RecallState();
5997 SavedState
: TPlayerSavedState
;
5999 if(FSavedStateNum
< 0) or (FSavedStateNum
> High(SavedStates
)) then
6002 SavedState
:= SavedStates
[FSavedStateNum
];
6003 SavedStates
[FSavedStateNum
].Used
:= False;
6004 FSavedStateNum
:= -1;
6006 FHealth
:= SavedState
.Health
;
6007 FArmor
:= SavedState
.Armor
;
6008 FAir
:= SavedState
.Air
;
6009 FJetFuel
:= SavedState
.JetFuel
;
6010 FCurrWeap
:= SavedState
.CurrWeap
;
6011 FNextWeap
:= SavedState
.NextWeap
;
6012 FNextWeapDelay
:= SavedState
.NextWeapDelay
;
6013 for i
:= Low(FWeapon
) to High(FWeapon
) do
6014 FWeapon
[i
] := SavedState
.Weapon
[i
];
6015 for i
:= Low(FAmmo
) to High(FAmmo
) do
6016 FAmmo
[i
] := SavedState
.Ammo
[i
];
6017 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
6018 FMaxAmmo
[i
] := SavedState
.MaxAmmo
[i
];
6019 FRulez
:= SavedState
.Rulez
;
6021 if gGameSettings
.GameType
= GT_SERVER
then
6022 MH_SEND_PlayerStats(FUID
);
6025 procedure TPlayer
.SaveState (st
: TStream
);
6031 utils
.writeSign(st
, 'PLYR');
6032 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
6034 utils
.writeBool(st
, FIamBot
);
6036 utils
.writeInt(st
, Word(FUID
));
6038 utils
.writeStr(st
, FName
);
6040 utils
.writeInt(st
, Byte(FTeam
));
6042 utils
.writeBool(st
, FAlive
);
6043 // Èçðàñõîäîâàë ëè âñå æèçíè
6044 utils
.writeBool(st
, FNoRespawn
);
6046 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
6047 utils
.writeInt(st
, Byte(b
));
6049 utils
.writeInt(st
, LongInt(FHealth
));
6050 // Êîýôôèöèåíò èíâàëèäíîñòè
6051 utils
.writeInt(st
, LongInt(FHandicap
));
6053 utils
.writeInt(st
, Byte(FLives
));
6055 utils
.writeInt(st
, LongInt(FArmor
));
6057 utils
.writeInt(st
, LongInt(FAir
));
6059 utils
.writeInt(st
, LongInt(FJetFuel
));
6061 utils
.writeInt(st
, LongInt(FPain
));
6063 utils
.writeInt(st
, LongInt(FKills
));
6065 utils
.writeInt(st
, LongInt(FMonsterKills
));
6067 utils
.writeInt(st
, LongInt(FFrags
));
6069 utils
.writeInt(st
, Byte(FFragCombo
));
6070 // Âðåìÿ ïîñëåäíåãî ôðàãà
6071 utils
.writeInt(st
, LongWord(FLastFrag
));
6073 utils
.writeInt(st
, LongInt(FDeath
));
6075 utils
.writeInt(st
, Byte(FFlag
));
6077 utils
.writeInt(st
, LongInt(FSecrets
));
6079 utils
.writeInt(st
, Byte(FCurrWeap
));
6081 utils
.writeInt(st
, Word(FNextWeap
));
6083 utils
.writeInt(st
, Byte(FNextWeapDelay
));
6084 // Âðåìÿ çàðÿäêè BFG
6085 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
6087 utils
.writeInt(st
, LongInt(FDamageBuffer
));
6088 // Ïîñëåäíèé óäàðèâøèé
6089 utils
.writeInt(st
, Word(FLastSpawnerUID
));
6090 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6091 utils
.writeInt(st
, Byte(FLastHit
));
6093 Obj_SaveState(st
, @FObj
);
6094 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6095 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
6096 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6097 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
6099 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
6100 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6101 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
6103 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
6104 // Íàëè÷èå êðàñíîãî êëþ÷à
6105 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
6106 // Íàëè÷èå çåëåíîãî êëþ÷à
6107 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
6108 // Íàëè÷èå ñèíåãî êëþ÷à
6109 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
6111 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
6112 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6113 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
6114 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6115 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
6117 utils
.writeStr(st
, FModel
.Name
);
6119 utils
.writeInt(st
, Byte(FColor
.R
));
6120 utils
.writeInt(st
, Byte(FColor
.G
));
6121 utils
.writeInt(st
, Byte(FColor
.B
));
6125 procedure TPlayer
.LoadState (st
: TStream
);
6134 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
6135 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
6137 FIamBot
:= utils
.readBool(st
);
6139 FUID
:= utils
.readWord(st
);
6141 str
:= utils
.readStr(st
);
6142 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
6144 FTeam
:= utils
.readByte(st
);
6146 FAlive
:= utils
.readBool(st
);
6147 // Èçðàñõîäîâàë ëè âñå æèçíè
6148 FNoRespawn
:= utils
.readBool(st
);
6150 b
:= utils
.readByte(st
);
6151 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
6153 FHealth
:= utils
.readLongInt(st
);
6154 // Êîýôôèöèåíò èíâàëèäíîñòè
6155 FHandicap
:= utils
.readLongInt(st
);
6157 FLives
:= utils
.readByte(st
);
6159 FArmor
:= utils
.readLongInt(st
);
6161 FAir
:= utils
.readLongInt(st
);
6163 FJetFuel
:= utils
.readLongInt(st
);
6165 FPain
:= utils
.readLongInt(st
);
6167 FKills
:= utils
.readLongInt(st
);
6169 FMonsterKills
:= utils
.readLongInt(st
);
6171 FFrags
:= utils
.readLongInt(st
);
6173 FFragCombo
:= utils
.readByte(st
);
6174 // Âðåìÿ ïîñëåäíåãî ôðàãà
6175 FLastFrag
:= utils
.readLongWord(st
);
6177 FDeath
:= utils
.readLongInt(st
);
6179 FFlag
:= utils
.readByte(st
);
6181 FSecrets
:= utils
.readLongInt(st
);
6183 FCurrWeap
:= utils
.readByte(st
);
6185 FNextWeap
:= utils
.readWord(st
);
6187 FNextWeapDelay
:= utils
.readByte(st
);
6188 // Âðåìÿ çàðÿäêè BFG
6189 FBFGFireCounter
:= utils
.readSmallInt(st
);
6191 FDamageBuffer
:= utils
.readLongInt(st
);
6192 // Ïîñëåäíèé óäàðèâøèé
6193 FLastSpawnerUID
:= utils
.readWord(st
);
6194 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6195 FLastHit
:= utils
.readByte(st
);
6197 Obj_LoadState(@FObj
, st
);
6198 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6199 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
6200 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6201 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
6203 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
6204 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6205 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
6207 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
6208 // Íàëè÷èå êðàñíîãî êëþ÷à
6209 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
6210 // Íàëè÷èå çåëåíîãî êëþ÷à
6211 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
6212 // Íàëè÷èå ñèíåãî êëþ÷à
6213 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
6215 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
6216 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6217 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
6218 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6219 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
6221 str
:= utils
.readStr(st
);
6223 FColor
.R
:= utils
.readByte(st
);
6224 FColor
.G
:= utils
.readByte(st
);
6225 FColor
.B
:= utils
.readByte(st
);
6226 if (self
= gPlayer1
) then
6228 str
:= gPlayer1Settings
.Model
;
6229 FColor
:= gPlayer1Settings
.Color
;
6231 else if (self
= gPlayer2
) then
6233 str
:= gPlayer2Settings
.Model
;
6234 FColor
:= gPlayer2Settings
.Color
;
6236 // Îáíîâëÿåì ìîäåëü èãðîêà
6238 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
6239 FModel
.Color
:= TEAMCOLOR
[FTeam
]
6241 FModel
.Color
:= FColor
;
6245 procedure TPlayer
.AllRulez(Health
: Boolean);
6251 FHealth
:= PLAYER_HP_LIMIT
;
6252 FArmor
:= PLAYER_AP_LIMIT
;
6256 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
6257 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
6258 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6261 procedure TPlayer
.RestoreHealthArmor();
6263 FHealth
:= PLAYER_HP_LIMIT
;
6264 FArmor
:= PLAYER_AP_LIMIT
;
6267 procedure TPlayer
.FragCombo();
6271 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6273 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6275 if FFragCombo
< 5 then
6277 Param
:= FUID
or (FFragCombo
shl 16);
6278 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6279 (FComboEvnt
<= High(gDelayedEvents
)) and
6280 gDelayedEvents
[FComboEvnt
].Pending
and
6281 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6282 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6284 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6285 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6288 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6296 procedure TPlayer
.GiveItem(ItemType
: Byte);
6300 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6302 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6306 if FAir
< AIR_MAX
then
6313 if not (R_BERSERK
in FRulez
) then
6315 Include(FRulez
, R_BERSERK
);
6316 if FBFGFireCounter
< 1 then
6318 FCurrWeap
:= WEAPON_KASTET
;
6320 FModel
.SetWeapon(WEAPON_KASTET
);
6324 FBerserk
:= gTime
+30000;
6326 if FHealth
< PLAYER_HP_SOFT
then
6328 FHealth
:= PLAYER_HP_SOFT
;
6329 FBerserk
:= gTime
+30000;
6334 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6336 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6341 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6343 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6347 if FJetFuel
< JET_MAX
then
6349 FJetFuel
:= JET_MAX
;
6352 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6353 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6355 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6356 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6358 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6360 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6362 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6363 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6366 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6367 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6368 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6369 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6370 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6371 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6372 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6373 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6374 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6376 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6377 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6378 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6379 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6380 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6381 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6382 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6383 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6384 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6387 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6388 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6389 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6390 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6391 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6393 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6394 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6395 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6396 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6397 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6399 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6400 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6401 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6402 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6404 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6407 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6408 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6409 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6411 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6412 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6417 if g_Game_IsNet
and g_Game_IsServer
then
6418 MH_SEND_PlayerStats(FUID
);
6421 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6426 if (Random(5) = 1) and (Times
= 1) then
6429 if BodyInLiquid(0, 0) then
6431 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6432 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6433 if Random(2) = 0 then
6434 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6436 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6440 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6442 for i
:= 1 to Times
do
6444 Anim
:= TAnimation
.Create(id
, False, 3);
6446 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6447 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6453 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6458 if (Random(10) = 1) and (Times
= 1) then
6461 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6463 for i
:= 1 to Times
do
6465 Anim
:= TAnimation
.Create(id
, False, 3);
6467 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6468 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6474 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6476 FSawSound
.Pause(Enable
);
6477 FSawSoundIdle
.Pause(Enable
);
6478 FSawSoundHit
.Pause(Enable
);
6479 FSawSoundSelect
.Pause(Enable
);
6480 FFlameSoundOn
.Pause(Enable
);
6481 FFlameSoundOff
.Pause(Enable
);
6482 FFlameSoundWork
.Pause(Enable
);
6483 FJetSoundFly
.Pause(Enable
);
6484 FJetSoundOn
.Pause(Enable
);
6485 FJetSoundOff
.Pause(Enable
);
6490 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6495 FObj
.Rect
:= PLAYER_CORPSERECT
;
6496 FModelName
:= ModelName
;
6501 FState
:= CORPSE_STATE_MESS
;
6502 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6506 FState
:= CORPSE_STATE_NORMAL
;
6507 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6511 destructor TCorpse
.Destroy();
6518 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6520 procedure TCorpse
.positionChanged (); inline; begin end;
6522 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6524 if (dx
<> 0) or (dy
<> 0) then
6533 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6535 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6536 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6537 w
:= PLAYER_CORPSERECT
.Width
;
6538 h
:= PLAYER_CORPSERECT
.Height
;
6542 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6547 if FState
= CORPSE_STATE_REMOVEME
then
6550 FDamage
:= FDamage
+ Value
;
6552 if FDamage
> 150 then
6554 if FAnimation
<> nil then
6559 FState
:= CORPSE_STATE_REMOVEME
;
6561 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6562 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6563 FModelName
, FColor
);
6564 // Çâóê ìÿñà îò òðóïà:
6565 pm
:= g_PlayerModel_Get(FModelName
);
6566 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6570 if (gBodyKillEvent
<> -1)
6571 and gDelayedEvents
[gBodyKillEvent
].Pending
then
6572 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
6573 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, 0);
6578 Blood
:= g_PlayerModel_GetBlood(FModelName
);
6579 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6580 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6581 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6582 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6583 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6584 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
6588 procedure TCorpse
.Draw();
6590 if FState
= CORPSE_STATE_REMOVEME
then
6593 if FAnimation
<> nil then
6594 FAnimation
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6596 if FAnimationMask
<> nil then
6599 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6606 procedure TCorpse
.Update();
6610 if FState
= CORPSE_STATE_REMOVEME
then
6613 if gTime
mod (GAME_TICK
*2) <> 0 then
6615 g_Obj_Move(@FObj
, True, True, True);
6616 positionChanged(); // this updates spatial accelerators
6620 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6621 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6623 st
:= g_Obj_Move(@FObj
, True, True, True);
6624 positionChanged(); // this updates spatial accelerators
6626 if WordBool(st
and MOVE_FALLOUT
) then
6628 FState
:= CORPSE_STATE_REMOVEME
;
6632 if FAnimation
<> nil then
6633 FAnimation
.Update();
6634 if FAnimationMask
<> nil then
6635 FAnimationMask
.Update();
6639 procedure TCorpse
.SaveState (st
: TStream
);
6646 utils
.writeSign(st
, 'CORP');
6647 utils
.writeInt(st
, Byte(0));
6649 utils
.writeInt(st
, Byte(FState
));
6651 utils
.writeInt(st
, Byte(FDamage
));
6653 utils
.writeInt(st
, Byte(FColor
.R
));
6654 utils
.writeInt(st
, Byte(FColor
.G
));
6655 utils
.writeInt(st
, Byte(FColor
.B
));
6657 Obj_SaveState(st
, @FObj
);
6658 utils
.writeInt(st
, Word(FPlayerUID
));
6660 anim
:= (FAnimation
<> nil);
6661 utils
.writeBool(st
, anim
);
6662 // Åñëè åñòü - ñîõðàíÿåì
6663 if anim
then FAnimation
.SaveState(st
);
6664 // Åñòü ëè ìàñêà àíèìàöèè
6665 anim
:= (FAnimationMask
<> nil);
6666 utils
.writeBool(st
, anim
);
6667 // Åñëè åñòü - ñîõðàíÿåì
6668 if anim
then FAnimationMask
.SaveState(st
);
6672 procedure TCorpse
.LoadState (st
: TStream
);
6679 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6680 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6682 FState
:= utils
.readByte(st
);
6684 FDamage
:= utils
.readByte(st
);
6686 FColor
.R
:= utils
.readByte(st
);
6687 FColor
.G
:= utils
.readByte(st
);
6688 FColor
.B
:= utils
.readByte(st
);
6690 Obj_LoadState(@FObj
, st
);
6691 FPlayerUID
:= utils
.readWord(st
);
6693 anim
:= utils
.readBool(st
);
6694 // Åñëè åñòü - çàãðóæàåì
6697 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6698 FAnimation
.LoadState(st
);
6700 // Åñòü ëè ìàñêà àíèìàöèè
6701 anim
:= utils
.readBool(st
);
6702 // Åñëè åñòü - çàãðóæàåì
6705 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6706 FAnimationMask
.LoadState(st
);
6712 constructor TBot
.Create();
6719 FSpectator
:= False;
6726 for a
:= WP_FIRST
to WP_LAST
do
6728 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6729 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6730 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6734 destructor TBot
.Destroy();
6737 inherited Destroy();
6740 procedure TBot
.Draw();
6744 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6745 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6748 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6750 inherited Respawn(Silent
, Force
);
6753 FSelectedWeapon
:= FCurrWeap
;
6758 procedure TBot
.UpdateCombat();
6771 TTargetRecord
= array of TTarget
;
6773 function Compare(a
, b
: TTarget
): Integer;
6775 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6778 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6780 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6781 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6783 if a
.Dist
> b
.Dist
then // B áëèæå
6785 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6788 else // Ñòðàííî -> A
6793 a
, x1
, y1
, x2
, y2
: Integer;
6794 targets
: TTargetRecord
;
6796 Target
, BestTarget
: TTarget
;
6797 firew
, fireh
: Integer;
6801 vsPlayer
, vsMonster
, ok
: Boolean;
6804 function monsUpdate (mon
: TMonster
): Boolean;
6806 result
:= false; // don't stop
6807 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6809 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6811 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6812 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6814 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6815 if g_TraceVector(x1
, y1
, x2
, y2
) then
6817 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6818 SetLength(targets
, Length(targets
)+1);
6819 with targets
[High(targets
)] do
6826 Rect
:= mon
.Obj
.Rect
;
6827 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6828 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6829 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6838 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6839 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6841 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6842 if FCurrWeap
<> FSelectedWeapon
then
6845 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6846 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6848 RemoveAIFlag('NEEDFIRE');
6851 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6852 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6853 else PressKey(KEY_FIRE
);
6857 // Êîîðäèíàòû ñòâîëà:
6858 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6859 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6861 Target
.UID
:= FTargetUID
;
6864 if Target
.UID
<> 0 then
6865 begin // Öåëü åñòü - íàñòðàèâàåì
6866 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6869 tpla
:= g_Player_Get(Target
.UID
);
6873 if (@FObj
) <> nil then
6880 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6881 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6882 Target
.Rect
:= PLAYER_RECT
;
6883 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6884 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6885 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6886 Target
.IsPlayer
:= True;
6890 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6893 mon
:= g_Monsters_ByUID(Target
.UID
);
6896 Target
.X
:= mon
.Obj
.X
;
6897 Target
.Y
:= mon
.Obj
.Y
;
6899 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6900 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6901 Target
.Rect
:= mon
.Obj
.Rect
;
6902 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6903 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6904 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6905 Target
.IsPlayer
:= False;
6912 begin // Öåëè íåò - îáíóëÿåì
6917 Target
.Visible
:= False;
6918 Target
.Line
:= False;
6919 Target
.IsPlayer
:= False;
6924 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6925 if (not Target
.Line
) or (not Target
.Visible
) then
6929 for a
:= 0 to High(gPlayers
) do
6930 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6931 (gPlayers
[a
].FUID
<> FUID
) and
6932 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6933 (not gPlayers
[a
].NoTarget
) and
6934 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6936 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6937 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6940 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6941 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6943 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6944 if g_TraceVector(x1
, y1
, x2
, y2
) then
6946 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6947 SetLength(targets
, Length(targets
)+1);
6948 with targets
[High(targets
)] do
6950 UID
:= gPlayers
[a
].FUID
;
6951 X
:= gPlayers
[a
].FObj
.X
;
6952 Y
:= gPlayers
[a
].FObj
.Y
;
6955 Rect
:= PLAYER_RECT
;
6956 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6957 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6958 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6966 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6969 // Åñëè åñòü âîçìîæíûå öåëè:
6970 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6971 if targets
<> nil then
6973 // Âûáèðàåì íàèëó÷øóþ öåëü:
6974 BestTarget
:= targets
[0];
6975 if Length(targets
) > 1 then
6976 for a
:= 1 to High(targets
) do
6977 if Compare(BestTarget
, targets
[a
]) = 1 then
6978 BestTarget
:= targets
[a
];
6980 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6981 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6982 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6984 Target
:= BestTarget
;
6986 if (Healthy() = 3) or ((Healthy() = 2)) then
6987 begin // Åñëè çäîðîâû - äîãîíÿåì
6988 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6989 SetAIFlag('GORIGHT', '1');
6990 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6991 SetAIFlag('GOLEFT', '1');
6994 begin // Åñëè ïîáèòû - óáåãàåì
6995 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6996 SetAIFlag('GORIGHT', '1');
6997 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6998 SetAIFlag('GOLEFT', '1');
7001 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
7002 SelectWeapon(Abs(x1
-Target
.cX
));
7007 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
7008 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
7009 if Target
.UID
<> 0 then
7011 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
7012 Target
.Y
+ Target
.Rect
.Y
) then
7013 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
7014 if (Healthy() = 3) or ((Healthy() = 2)) then
7015 begin // Åñëè çäîðîâû - äîãîíÿåì
7016 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
7017 SetAIFlag('GORIGHT', '1');
7018 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
7019 SetAIFlag('GOLEFT', '1');
7022 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
7024 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
7025 SetAIFlag('GORIGHT', '1');
7026 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
7027 SetAIFlag('GOLEFT', '1');
7031 begin // Öåëü ïîêà íà "ýêðàíå"
7032 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
7033 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7034 FLastVisible
:= gTime
;
7035 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
7036 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
7038 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
7039 SetAIFlag('GORIGHT', '1');
7040 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
7041 SetAIFlag('GOLEFT', '1');
7045 // Âûáèðàåì óãîë ââåðõ:
7046 if FDirection
= TDirection
.D_LEFT
then
7047 angle
:= ANGLE_LEFTUP
7049 angle
:= ANGLE_RIGHTUP
;
7051 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7052 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7054 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7055 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7056 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
7057 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7058 Target
.Rect
.Width
, Target
.Rect
.Height
) and
7059 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7060 begin // òî íóæíî ñòðåëÿòü ââåðõ
7061 SetAIFlag('NEEDFIRE', '1');
7062 SetAIFlag('NEEDSEEUP', '1');
7065 // Âûáèðàåì óãîë âíèç:
7066 if FDirection
= TDirection
.D_LEFT
then
7067 angle
:= ANGLE_LEFTDOWN
7069 angle
:= ANGLE_RIGHTDOWN
;
7071 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7072 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7074 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7075 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7076 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7077 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7078 Target
.Rect
.Width
, Target
.Rect
.Height
) and
7079 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7080 begin // òî íóæíî ñòðåëÿòü âíèç
7081 SetAIFlag('NEEDFIRE', '1');
7082 SetAIFlag('NEEDSEEDOWN', '1');
7085 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
7086 if Target
.Visible
and
7087 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
7088 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
7090 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
7091 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
7092 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
7093 begin // òî íóæíî ñòðåëÿòü âïåðåä
7094 SetAIFlag('NEEDFIRE', '1');
7095 SetAIFlag('NEEDSEEDOWN', '');
7096 SetAIFlag('NEEDSEEUP', '');
7098 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
7099 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
7100 if GetRnd(FDifficult
.CloseJump
) then
7101 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
7102 if Abs(FObj
.X
-Target
.X
) < 128 then
7106 if Random(a
) = 0 then
7107 SetAIFlag('NEEDJUMP', '1');
7111 // Åñëè öåëü âñå åùå åñòü:
7112 if Target
.UID
<> 0 then
7113 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
7114 Target
.UID
:= 0 // òî çàáûòü öåëü
7115 else // Åñëè âèäåëè íåäàâíî
7116 begin // íî öåëü óáèëè
7117 if Target
.IsPlayer
then
7118 begin // Öåëü - èãðîê
7119 pla
:= g_Player_Get(Target
.UID
);
7120 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
7121 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
7122 Target
.UID
:= 0; // òî çàáûòü öåëü
7125 begin // Öåëü - ìîíñòð
7126 mon
:= g_Monsters_ByUID(Target
.UID
);
7127 if (mon
= nil) or (not mon
.alive
) then
7128 Target
.UID
:= 0; // òî çàáûòü öåëü
7131 end; // if Target.UID <> 0
7133 FTargetUID
:= Target
.UID
;
7135 // Åñëè âîçìîæíûõ öåëåé íåò:
7136 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
7137 if targets
= nil then
7138 if GetAIFlag('ATTACKLEFT') <> '' then
7139 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
7140 RemoveAIFlag('ATTACKLEFT');
7142 SetAIFlag('NEEDJUMP', '1');
7144 if RunDirection() = TDirection
.D_RIGHT
then
7145 begin // Èäåì íå â òó ñòîðîíó
7146 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7147 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
7148 SetAIFlag('NEEDFIRE', '1');
7149 SetAIFlag('GOLEFT', '1');
7153 begin // Èäåì â íóæíóþ ñòîðîíó
7154 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7155 SetAIFlag('NEEDFIRE', '1');
7156 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7157 SetAIFlag('GORIGHT', '1');
7161 if GetAIFlag('ATTACKRIGHT') <> '' then
7162 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
7163 RemoveAIFlag('ATTACKRIGHT');
7165 SetAIFlag('NEEDJUMP', '1');
7167 if RunDirection() = TDirection
.D_LEFT
then
7168 begin // Èäåì íå â òó ñòîðîíó
7169 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7170 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
7171 SetAIFlag('NEEDFIRE', '1');
7172 SetAIFlag('GORIGHT', '1');
7177 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7178 SetAIFlag('NEEDFIRE', '1');
7179 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7180 SetAIFlag('GOLEFT', '1');
7184 //HACK! (does it belongs there?)
7185 RealizeCurrentWeapon();
7187 // Åñëè åñòü âîçìîæíûå öåëè:
7188 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7189 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7190 for a
:= 0 to High(targets
) do
7192 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7193 if GetRnd(FDifficult
.DiagFire
) then
7195 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7196 if FDirection
= TDirection
.D_LEFT
then
7197 angle
:= ANGLE_LEFTUP
7199 angle
:= ANGLE_RIGHTUP
;
7201 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7202 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7204 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7205 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7206 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7207 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7208 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7210 SetAIFlag('NEEDFIRE', '1');
7211 SetAIFlag('NEEDSEEUP', '1');
7214 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7215 if FDirection
= TDirection
.D_LEFT
then
7216 angle
:= ANGLE_LEFTDOWN
7218 angle
:= ANGLE_RIGHTDOWN
;
7220 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7221 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7223 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7224 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7225 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7226 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7227 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7229 SetAIFlag('NEEDFIRE', '1');
7230 SetAIFlag('NEEDSEEDOWN', '1');
7234 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7235 if targets
[a
].Line
and targets
[a
].Visible
and
7236 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
7237 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
7239 SetAIFlag('NEEDFIRE', '1');
7244 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7245 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
7246 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
7247 40+GetInterval(FDifficult
.Cover
, 40)) then
7248 SetAIFlag('NEEDJUMP', '1');
7250 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7251 ammo
:= GetAmmoByWeapon(FCurrWeap
);
7252 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
7253 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
7255 SetAIFlag('SELECTWEAPON', '1');
7257 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7258 if GetAIFlag('SELECTWEAPON') = '1' then
7261 RemoveAIFlag('SELECTWEAPON');
7265 procedure TBot
.Update();
7278 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7279 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7281 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7283 if g_debug_BotAIOff
= 3 then
7293 RealizeCurrentWeapon();
7300 procedure TBot
.ReleaseKey(Key
: Byte);
7309 function TBot
.KeyPressed(Key
: Word): Boolean;
7311 Result
:= FKeys
[Key
].Pressed
;
7314 function TBot
.GetAIFlag(aName
: String20
): String20
;
7320 aName
:= LowerCase(aName
);
7322 if FAIFlags
<> nil then
7323 for a
:= 0 to High(FAIFlags
) do
7324 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7326 Result
:= FAIFlags
[a
].Value
;
7331 procedure TBot
.RemoveAIFlag(aName
: String20
);
7335 if FAIFlags
= nil then Exit
;
7337 aName
:= LowerCase(aName
);
7339 for a
:= 0 to High(FAIFlags
) do
7340 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7342 if a
<> High(FAIFlags
) then
7343 for b
:= a
to High(FAIFlags
)-1 do
7344 FAIFlags
[b
] := FAIFlags
[b
+1];
7346 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7351 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7359 aName
:= LowerCase(aName
);
7361 if FAIFlags
<> nil then
7362 for a
:= 0 to High(FAIFlags
) do
7363 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7369 if ok
then FAIFlags
[a
].Value
:= fValue
7372 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7373 with FAIFlags
[High(FAIFlags
)] do
7381 procedure TBot
.UpdateMove
;
7383 procedure GoLeft(Time
: Word = 1);
7385 ReleaseKey(KEY_LEFT
);
7386 ReleaseKey(KEY_RIGHT
);
7387 PressKey(KEY_LEFT
, Time
);
7388 SetDirection(TDirection
.D_LEFT
);
7391 procedure GoRight(Time
: Word = 1);
7393 ReleaseKey(KEY_LEFT
);
7394 ReleaseKey(KEY_RIGHT
);
7395 PressKey(KEY_RIGHT
, Time
);
7396 SetDirection(TDirection
.D_RIGHT
);
7399 function Rnd(a
: Word): Boolean;
7401 Result
:= Random(a
) = 0;
7404 procedure Turn(Time
: Word = 1200);
7406 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7411 ReleaseKey(KEY_LEFT
);
7412 ReleaseKey(KEY_RIGHT
);
7415 function CanRunLeft(): Boolean;
7417 Result
:= not CollideLevel(-1, 0);
7420 function CanRunRight(): Boolean;
7422 Result
:= not CollideLevel(1, 0);
7425 function CanRun(): Boolean;
7427 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7430 procedure Jump(Time
: Word = 30);
7432 PressKey(KEY_JUMP
, Time
);
7435 function NearHole(): Boolean;
7439 { TODO 5 : Ëåñòíèöû }
7440 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7441 for x
:= 1 to PLAYER_RECT
.Width
do
7442 if (not StayOnStep(x
*sx
, 0)) and
7443 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7444 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7453 function BorderHole(): Boolean;
7457 { TODO 5 : Ëåñòíèöû }
7458 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7459 for x
:= 1 to PLAYER_RECT
.Width
do
7460 if (not StayOnStep(x
*sx
, 0)) and
7461 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7462 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7464 for xx
:= x
to x
+32 do
7465 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7475 function NearDeepHole(): Boolean;
7481 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7484 for x
:= 1 to PLAYER_RECT
.Width
do
7485 if (not StayOnStep(x
*sx
, 0)) and
7486 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7487 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7489 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7491 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7496 end else Result
:= False;
7499 function OverDeepHole(): Boolean;
7506 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7508 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7515 function OnGround(): Boolean;
7517 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7520 function OnLadder(): Boolean;
7522 Result
:= FullInStep(0, 0);
7525 function BelowLadder(): Boolean;
7527 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7528 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7529 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7530 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7533 function BelowLiftUp(): Boolean;
7535 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7536 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7537 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7538 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7541 function OnTopLift(): Boolean;
7543 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7546 function CanJumpOver(): Boolean;
7550 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7554 if not CollideLevel(sx
, 0) then Exit
;
7556 for y
:= 1 to BOT_MAXJUMP
do
7557 if CollideLevel(0, -y
) then Exit
else
7558 if not CollideLevel(sx
, -y
) then
7565 function CanJumpUp(Dist
: ShortInt): Boolean;
7572 if CollideLevel(Dist
, 0) then Exit
;
7575 for y
:= 0 to BOT_MAXJUMP
do
7576 if CollideLevel(Dist
, -y
) then
7585 for yy
:= y
+1 to BOT_MAXJUMP
do
7586 if not CollideLevel(Dist
, -yy
) then
7595 for y
:= 0 to BOT_MAXJUMP
do
7596 if CollideLevel(0, -y
) then
7604 if y
< yy
then Exit
;
7609 function IsSafeTrigger(): Boolean;
7614 if gTriggers
= nil then
7616 for a
:= 0 to High(gTriggers
) do
7617 if Collide(gTriggers
[a
].X
,
7620 gTriggers
[a
].Height
) and
7621 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7622 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7623 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7624 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7625 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7630 // Âîçìîæíî, íàæèìàåì êíîïêó:
7631 if Rnd(16) and IsSafeTrigger() then
7634 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7635 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7637 ReleaseKey(KEY_LEFT
);
7638 ReleaseKey(KEY_RIGHT
);
7642 // Èäåì âëåâî, åñëè íàäî áûëî:
7643 if GetAIFlag('GOLEFT') <> '' then
7645 RemoveAIFlag('GOLEFT');
7646 if CanRunLeft() then
7650 // Èäåì âïðàâî, åñëè íàäî áûëî:
7651 if GetAIFlag('GORIGHT') <> '' then
7653 RemoveAIFlag('GORIGHT');
7654 if CanRunRight() then
7658 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7659 if FObj
.X
< -32 then
7662 if FObj
.X
+32 > gMapInfo
.Width
then
7665 // Ïðûãàåì, åñëè íàäî áûëî:
7666 if GetAIFlag('NEEDJUMP') <> '' then
7669 RemoveAIFlag('NEEDJUMP');
7672 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7673 if GetAIFlag('NEEDSEEUP') <> '' then
7676 ReleaseKey(KEY_DOWN
);
7677 PressKey(KEY_UP
, 20);
7678 RemoveAIFlag('NEEDSEEUP');
7681 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7682 if GetAIFlag('NEEDSEEDOWN') <> '' then
7685 ReleaseKey(KEY_DOWN
);
7686 PressKey(KEY_DOWN
, 20);
7687 RemoveAIFlag('NEEDSEEDOWN');
7690 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7691 if GetAIFlag('GOINHOLE') <> '' then
7692 if not OnGround() then
7694 ReleaseKey(KEY_LEFT
);
7695 ReleaseKey(KEY_RIGHT
);
7696 RemoveAIFlag('GOINHOLE');
7697 SetAIFlag('FALLINHOLE', '1');
7700 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7701 if GetAIFlag('FALLINHOLE') <> '' then
7703 RemoveAIFlag('FALLINHOLE');
7705 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7706 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7707 if GetAIFlag('FALLINHOLE') = '' then
7708 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7714 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7716 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7720 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7721 if OnGround() and NearHole() then
7722 if NearDeepHole() then // Åñëè ýòî áåçäíà
7724 0..3: Turn(); // Áåæèì îáðàòíî
7725 4: Jump(); // Ïðûãàåì
7726 5: begin // Ïðûãàåì îáðàòíî
7731 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7732 if GetAIFlag('GOINHOLE') = '' then
7734 0: Turn(); // Íå íóæíî òóäà
7735 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7736 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7737 if BorderHole() then
7738 SetAIFlag('GOINHOLE', '1');
7741 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7742 if (not CanRun()) and OnGround() then
7744 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7745 if CanJumpOver() or OnLadder() then
7747 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7748 if Random(2) = 0 then
7750 if IsSafeTrigger() then
7756 // Îñòàëîñü ìàëî âîçäóõà:
7757 if FAir
< 36 * 2 then
7760 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7761 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7762 if BodyInAcid(0, 0) then
7766 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7768 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7769 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7772 {function TBot.NeedItem(Item: Byte): Byte;
7777 procedure TBot
.SelectWeapon(Dist
: Integer);
7781 function HaveAmmo(weapon
: Byte): Boolean;
7784 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7785 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7786 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7787 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7788 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7789 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7790 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7791 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7792 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7793 else Result
:= True;
7798 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7800 if Dist
> BOT_LONGDIST
then
7801 begin // Äàëüíèé áîé
7803 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7805 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7809 else //if Dist > BOT_UNSAFEDIST then
7810 begin // Áëèæíèé áîé
7812 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7814 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7821 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7823 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7829 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7831 Result
:= inherited PickItem(ItemType
, force
, remove
);
7833 if Result
then SetAIFlag('SELECTWEAPON', '1');
7836 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7838 Result
:= inherited Heal(value
, Soft
);
7841 function TBot
.Healthy(): Byte;
7843 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7844 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7845 else if (FHealth
> 50) then Result
:= 2
7846 else if (FHealth
> 20) then Result
:= 1
7850 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7852 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7853 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7856 procedure TBot
.OnDamage(Angle
: SmallInt);
7864 if (Angle
= 0) or (Angle
= 180) then
7867 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7868 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7870 pla
:= g_Player_Get(FLastSpawnerUID
);
7871 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7872 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7875 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7876 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7878 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7879 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7880 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7885 SetAIFlag('ATTACKLEFT', '1')
7887 SetAIFlag('ATTACKRIGHT', '1');
7891 function TBot
.RunDirection(): TDirection
;
7893 if Abs(Vel
.X
) >= 1 then
7895 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7897 Result
:= FDirection
;
7900 function TBot
.GetRnd(a
: Byte): Boolean;
7902 if a
= 0 then Result
:= False
7903 else if a
= 255 then Result
:= True
7904 else Result
:= Random(256) > 255-a
;
7907 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7909 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7913 procedure TDifficult
.save (st
: TStream
);
7915 utils
.writeInt(st
, Byte(DiagFire
));
7916 utils
.writeInt(st
, Byte(InvisFire
));
7917 utils
.writeInt(st
, Byte(DiagPrecision
));
7918 utils
.writeInt(st
, Byte(FlyPrecision
));
7919 utils
.writeInt(st
, Byte(Cover
));
7920 utils
.writeInt(st
, Byte(CloseJump
));
7921 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7922 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7925 procedure TDifficult
.load (st
: TStream
);
7927 DiagFire
:= utils
.readByte(st
);
7928 InvisFire
:= utils
.readByte(st
);
7929 DiagPrecision
:= utils
.readByte(st
);
7930 FlyPrecision
:= utils
.readByte(st
);
7931 Cover
:= utils
.readByte(st
);
7932 CloseJump
:= utils
.readByte(st
);
7933 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7934 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7938 procedure TBot
.SaveState (st
: TStream
);
7943 inherited SaveState(st
);
7944 utils
.writeSign(st
, 'BOT0');
7946 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7948 utils
.writeInt(st
, Word(FTargetUID
));
7949 // Âðåìÿ ïîòåðè öåëè
7950 utils
.writeInt(st
, LongWord(FLastVisible
));
7951 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7952 dw
:= Length(FAIFlags
);
7953 utils
.writeInt(st
, LongInt(dw
));
7955 for i
:= 0 to dw
-1 do
7957 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7958 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7960 // Íàñòðîéêè ñëîæíîñòè
7961 FDifficult
.save(st
);
7965 procedure TBot
.LoadState (st
: TStream
);
7970 inherited LoadState(st
);
7971 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7973 FSelectedWeapon
:= utils
.readByte(st
);
7975 FTargetUID
:= utils
.readWord(st
);
7976 // Âðåìÿ ïîòåðè öåëè
7977 FLastVisible
:= utils
.readLongWord(st
);
7978 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7979 dw
:= utils
.readLongInt(st
);
7980 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7981 SetLength(FAIFlags
, dw
);
7983 for i
:= 0 to dw
-1 do
7985 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7986 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7988 // Íàñòðîéêè ñëîæíîñòè
7989 FDifficult
.load(st
);
7994 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);
7995 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');
7996 conRegVar('player_indicator_style', @gPlayerIndicatorStyle
, 'Visual appearance of indicator', 'Visual appearance of indicator');