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;
174 FSpectatePlayer
: Integer;
175 FFirePainTime
: Integer;
178 FSavedStateNum
: Integer;
180 FModel
: TPlayerModel
;
181 FPunchAnim
: TAnimation
;
184 FActionForce
: Boolean;
185 FActionChanged
: Boolean;
187 FFireAngle
: SmallInt;
191 FShellTimer
: Integer;
193 FSawSound
: TPlayableSound
;
194 FSawSoundIdle
: TPlayableSound
;
195 FSawSoundHit
: TPlayableSound
;
196 FSawSoundSelect
: TPlayableSound
;
197 FFlameSoundOn
: TPlayableSound
;
198 FFlameSoundOff
: TPlayableSound
;
199 FFlameSoundWork
: TPlayableSound
;
200 FJetSoundOn
: TPlayableSound
;
201 FJetSoundOff
: TPlayableSound
;
202 FJetSoundFly
: TPlayableSound
;
206 FJustTeleported
: Boolean;
208 mEDamageType
: Integer;
211 function CollideLevel(XInc
, YInc
: Integer): Boolean;
212 function StayOnStep(XInc
, YInc
: Integer): Boolean;
213 function HeadInLiquid(XInc
, YInc
: Integer): Boolean;
214 function BodyInLiquid(XInc
, YInc
: Integer): Boolean;
215 function BodyInAcid(XInc
, YInc
: Integer): Boolean;
216 function FullInLift(XInc
, YInc
: Integer): Integer;
217 {procedure CollideItem();}
218 procedure FlySmoke(Times
: DWORD
= 1);
219 procedure OnFireFlame(Times
: DWORD
= 1);
220 function GetAmmoByWeapon(Weapon
: Byte): Word;
221 procedure SetAction(Action
: Byte; Force
: Boolean = False);
222 procedure OnDamage(Angle
: SmallInt); virtual;
223 function firediry(): Integer;
226 procedure Run(Direction
: TDirection
);
227 procedure NextWeapon();
228 procedure PrevWeapon();
235 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
236 procedure resetWeaponQueue ();
237 function hasAmmoForWeapon (weapon
: Byte): Boolean;
239 procedure doDamage (v
: Integer);
241 function followCorpse(): Boolean;
244 FDamageBuffer
: Integer;
246 FAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
247 FMaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
248 FWeapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
249 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
251 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
252 FReloading
: Array [WP_FIRST
..WP_LAST
] of Word;
253 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
254 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
256 FPreferredTeam
: Byte;
259 FWantsInGame
: Boolean;
264 FActualModelName
: string;
271 FSpawnInvul
: Integer;
273 FWaitForFirstSpawn
: Boolean; // set to `true` in server, used to spawn a player on first full state request
275 // debug: viewport offset
276 viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer;
278 function isValidViewPort (): Boolean; inline;
280 constructor Create(); virtual;
281 destructor Destroy(); override;
282 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
283 function GetRespawnPoint(): Byte;
284 procedure PressKey(Key
: Byte; Time
: Word = 1);
285 procedure ReleaseKeys();
286 procedure SetModel(ModelName
: String);
287 procedure SetColor(Color
: TRGB
);
288 function GetColor(): TRGB
;
289 procedure SetWeapon(W
: Byte);
290 function IsKeyPressed(K
: Byte): Boolean;
291 function GetKeys(): Byte;
292 function PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean; virtual;
293 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
294 function Collide(Panel
: TPanel
): Boolean; overload
;
295 function Collide(X
, Y
: Integer): Boolean; overload
;
296 procedure SetDirection(Direction
: TDirection
);
297 procedure GetSecret();
298 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
300 procedure Push(vx
, vy
: Integer);
301 procedure ChangeModel(ModelName
: String);
302 procedure SwitchTeam
;
303 procedure ChangeTeam(Team
: Byte);
305 function GetFlag(Flag
: Byte): Boolean;
306 procedure SetFlag(Flag
: Byte);
307 function DropFlag(Silent
: Boolean = True): Boolean;
308 procedure AllRulez(Health
: Boolean);
309 procedure RestoreHealthArmor();
310 procedure FragCombo();
311 procedure GiveItem(ItemType
: Byte);
312 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
313 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
314 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
315 procedure MakeBloodSimple(Count
: Word);
316 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
317 procedure Reset(Force
: Boolean);
318 procedure Spectate(NoMove
: Boolean = False);
319 procedure SwitchNoClip
;
320 procedure SoftReset();
321 procedure Draw(); virtual;
322 procedure DrawPain();
323 procedure DrawPickup();
324 procedure DrawRulez();
326 procedure DrawIndicator(Color
: TRGB
);
327 procedure DrawBubble();
329 procedure PreUpdate();
330 procedure Update(); virtual;
331 procedure RememberState();
332 procedure RecallState();
333 procedure SaveState (st
: TStream
); virtual;
334 procedure LoadState (st
: TStream
); virtual;
335 procedure PauseSounds(Enable
: Boolean);
336 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
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 IncCamOld
: Integer read FIncCamOld write FIncCamOld
;
383 property SlopeOld
: Integer read FSlopeOld write FSlopeOld
;
384 property UID
: Word read FUID write FUID
;
385 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
386 property NetTime
: LongWord read FNetTime write FNetTime
;
389 property eName
: String read FName write FName
;
390 property eHealth
: Integer read FHealth write FHealth
;
391 property eLives
: Byte read FLives write FLives
;
392 property eArmor
: Integer read FArmor write FArmor
;
393 property eAir
: Integer read FAir write FAir
;
394 property eJetFuel
: Integer read FJetFuel write FJetFuel
;
395 property eFrags
: Integer read FFrags write FFrags
;
396 property eDeath
: Integer read FDeath write FDeath
;
397 property eKills
: Integer read FKills write FKills
;
398 property eCurrWeap
: Byte read FCurrWeap write FCurrWeap
;
399 property eMonsterKills
: Integer read FMonsterKills write FMonsterKills
;
400 property eSecrets
: Integer read FSecrets write FSecrets
;
401 property eGodMode
: Boolean read FGodMode write FGodMode
;
402 property eNoTarget
: Boolean read FNoTarget write FNoTarget
;
403 property eNoReload
: Boolean read FNoReload write FNoReload
;
404 property eAlive
: Boolean read FAlive write FAlive
;
405 property eFlag
: Byte read FFlag
;
406 property eTeam
: Byte read FTeam write FTeam
;
407 property eDirection
: TDirection read FDirection
;
408 property eGameX
: Integer read FObj
.X write FObj
.X
;
409 property eGameY
: Integer read FObj
.Y write FObj
.Y
;
410 property eGameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
411 property eGameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
412 property eGameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
413 property eGameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
414 property eIncCam
: Integer read FIncCam write FIncCam
;
415 property eUID
: Word read FUID
;
416 property eJustTeleported
: Boolean read FJustTeleported
;
417 property eNetTime
: LongWord read FNetTime
;
419 // set this before assigning something to `eDamage`
420 property eDamageType
: Integer read mEDamageType write mEDamageType
;
421 property eDamage
: Integer write doDamage
;
432 WeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
433 CloseWeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
434 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
437 procedure save (st
: TStream
);
438 procedure load (st
: TStream
);
446 TBot
= class(TPlayer
)
448 FSelectedWeapon
: Byte;
451 FAIFlags
: Array of TAIFlag
;
452 FDifficult
: TDifficult
;
454 function GetRnd(a
: Byte): Boolean;
455 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
456 function RunDirection(): TDirection
;
457 function FullInStep(XInc
, YInc
: Integer): Boolean;
458 //function NeedItem(Item: Byte): Byte;
459 procedure SelectWeapon(Dist
: Integer);
460 procedure SetAIFlag(aName
, fValue
: String20
);
461 function GetAIFlag(aName
: String20
): String20
;
462 procedure RemoveAIFlag(aName
: String20
);
463 function Healthy(): Byte;
464 procedure UpdateMove();
465 procedure UpdateCombat();
466 function KeyPressed(Key
: Word): Boolean;
467 procedure ReleaseKey(Key
: Byte);
468 function TargetOnScreen(TX
, TY
: Integer): Boolean;
469 procedure OnDamage(Angle
: SmallInt); override;
472 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
473 constructor Create(); override;
474 destructor Destroy(); override;
475 procedure Draw(); override;
476 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
477 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
478 procedure Update(); override;
479 procedure SaveState (st
: TStream
); override;
480 procedure LoadState (st
: TStream
); override;
492 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
493 procedure moveBy (dx
, dy
: Integer); inline;
495 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
509 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
510 procedure moveBy (dx
, dy
: Integer); inline;
512 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
515 TCorpse
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
524 FAnimation
: TAnimation
;
525 FAnimationMask
: TAnimation
;
528 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
529 destructor Destroy(); override;
530 procedure Damage(Value
: Word; vx
, vy
: Integer);
533 procedure SaveState (st
: TStream
);
534 procedure LoadState (st
: TStream
);
536 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
537 procedure moveBy (dx
, dy
: Integer); inline;
539 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
541 function ObjPtr (): PObj
; inline;
543 property Obj
: TObj read FObj
; // copies object
544 property State
: Byte read FState
;
545 property Mess
: Boolean read FMess
;
548 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
554 gPlayers
: Array of TPlayer
;
555 gCorpses
: Array of TCorpse
;
556 gGibs
: Array of TGib
;
557 gShells
: Array of TShell
;
558 gTeamStat
: TTeamStat
;
559 gFly
: Boolean = False;
560 gAimLine
: Boolean = False;
561 gChatBubble
: Integer = 0;
562 gPlayerIndicator
: Integer = 1;
563 gPlayerIndicatorStyle
: Integer = 0;
565 gSpectLatchPID1
: Word = 0;
566 gSpectLatchPID2
: Word = 0;
567 MAX_RUNVEL
: Integer = 8;
568 VEL_JUMP
: Integer = 10;
569 SHELL_TIMEOUT
: Cardinal = 60000;
571 function Lerp(X
, Y
, Factor
: Integer): Integer;
573 procedure g_Gibs_SetMax(Count
: Word);
574 function g_Gibs_GetMax(): Word;
575 procedure g_Corpses_SetMax(Count
: Word);
576 function g_Corpses_GetMax(): Word;
577 procedure g_Shells_SetMax(Count
: Word);
578 function g_Shells_GetMax(): Word;
580 procedure g_Player_Init();
581 procedure g_Player_Free();
582 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
583 function g_Player_CreateFromState (st
: TStream
): Word;
584 procedure g_Player_Remove(UID
: Word);
585 procedure g_Player_ResetTeams();
586 procedure g_Player_PreUpdate();
587 procedure g_Player_UpdateAll();
588 procedure g_Player_DrawAll();
589 procedure g_Player_DrawDebug(p
: TPlayer
);
590 procedure g_Player_DrawHealth();
591 procedure g_Player_RememberAll();
592 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
593 function g_Player_Get(UID
: Word): TPlayer
;
594 function g_Player_GetCount(): Byte;
595 function g_Player_GetStats(): TPlayerStatArray
;
596 function g_Player_ValidName(Name
: String): Boolean;
597 procedure g_Player_CreateCorpse(Player
: TPlayer
);
598 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
599 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
600 procedure g_Player_UpdatePhysicalObjects();
601 procedure g_Player_DrawCorpses();
602 procedure g_Player_DrawShells();
603 procedure g_Player_RemoveAllCorpses();
604 procedure g_Player_Corpses_SaveState (st
: TStream
);
605 procedure g_Player_Corpses_LoadState (st
: TStream
);
606 procedure g_Player_ResetReady();
607 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
608 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
609 procedure g_Bot_MixNames();
610 procedure g_Bot_RemoveAll();
615 {$INCLUDE ../nogl/noGLuses.inc}
616 {$IFDEF ENABLE_HOLMES}
619 e_log
, g_map
, g_items
, g_console
, g_gfx
, Math
,
620 g_options
, g_triggers
, g_menu
, g_game
, g_grid
, e_res
,
621 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
,
622 g_net
, g_netmsg
, g_window
,
625 const PLR_SAVE_VERSION
= 0;
635 diag_precision
: Byte;
639 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
640 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
641 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
645 TIME_RESPAWN1
= 1500;
646 TIME_RESPAWN2
= 2000;
647 TIME_RESPAWN3
= 3000;
650 JET_MAX
= 540; // ~30 sec
651 PLAYER_SUIT_TIME
= 30000;
652 PLAYER_INVUL_TIME
= 30000;
653 PLAYER_INVIS_TIME
= 35000;
654 FRAG_COMBO_TIME
= 3000;
658 ANGLE_RIGHTDOWN
= -35;
660 ANGLE_LEFTDOWN
= -145;
661 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
662 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
665 BOT_UNSAFEDIST
= 128;
666 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
668 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
669 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
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_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
672 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
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 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
675 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
676 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
677 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
678 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
679 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
680 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
681 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
682 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
683 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
684 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
685 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
686 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
687 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
688 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
689 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
690 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
691 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
692 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
693 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
695 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
696 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
698 BOTNAMES_FILENAME
= 'botnames.txt';
699 BOTLIST_FILENAME
= 'botlist.txt';
703 MaxCorpses
: Word = 20;
704 MaxShells
: Word = 300;
705 CurrentGib
: Integer = 0;
706 CurrentShell
: Integer = 0;
707 BotNames
: Array of String;
708 BotList
: Array of TBotProfile
;
709 SavedStates
: Array of TPlayerSavedState
;
712 function Lerp(X
, Y
, Factor
: Integer): Integer;
714 Result
:= X
+ ((Y
- X
) div Factor
);
717 function SameTeam(UID1
, UID2
: Word): Boolean;
721 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
722 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
724 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
726 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
727 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
729 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
732 procedure g_Gibs_SetMax(Count
: Word);
735 SetLength(gGibs
, Count
);
737 if CurrentGib
>= Count
then
741 function g_Gibs_GetMax(): Word;
746 procedure g_Shells_SetMax(Count
: Word);
749 SetLength(gShells
, Count
);
751 if CurrentShell
>= Count
then
755 function g_Shells_GetMax(): Word;
761 procedure g_Corpses_SetMax(Count
: Word);
764 SetLength(gCorpses
, Count
);
767 function g_Corpses_GetMax(): Word;
769 Result
:= MaxCorpses
;
772 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
782 // Åñòü ëè ìåñòî â gPlayers:
783 if gPlayers
<> nil then
784 for a
:= 0 to High(gPlayers
) do
785 if gPlayers
[a
] = nil then
791 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
794 SetLength(gPlayers
, Length(gPlayers
)+1);
798 // Ñîçäàåì îáúåêò èãðîêà:
800 gPlayers
[a
] := TBot
.Create()
802 gPlayers
[a
] := TPlayer
.Create();
805 gPlayers
[a
].FActualModelName
:= ModelName
;
806 gPlayers
[a
].SetModel(ModelName
);
808 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
809 if gPlayers
[a
].FModel
= nil then
813 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
817 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
818 if Random(2) = 0 then
822 gPlayers
[a
].FPreferredTeam
:= Team
;
824 case gGameSettings
.GameMode
of
825 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
827 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
829 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
832 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
833 gPlayers
[a
].FColor
:= Color
;
834 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
835 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
837 gPlayers
[a
].FModel
.Color
:= Color
;
839 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
840 gPlayers
[a
].FAlive
:= False;
842 Result
:= gPlayers
[a
].FUID
;
845 function g_Player_CreateFromState (st
: TStream
): Word;
852 if (st
= nil) then exit
; //???
855 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
856 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
859 Bot
:= utils
.readBool(st
);
864 // Åñòü ëè ìåñòî â gPlayers:
865 for a
:= 0 to High(gPlayers
) do if (gPlayers
[a
] = nil) then begin ok
:= true; break
; end;
867 // Íåò ìåñòà - ðàñøèðÿåì gPlayers
870 SetLength(gPlayers
, Length(gPlayers
)+1);
874 // Ñîçäàåì îáúåêò èãðîêà
876 gPlayers
[a
] := TBot
.Create()
878 gPlayers
[a
] := TPlayer
.Create();
879 gPlayers
[a
].FIamBot
:= Bot
;
880 gPlayers
[a
].FPhysics
:= True;
883 gPlayers
[a
].FUID
:= utils
.readWord(st
);
885 gPlayers
[a
].FName
:= utils
.readStr(st
);
887 gPlayers
[a
].FTeam
:= utils
.readByte(st
);
888 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
890 gPlayers
[a
].FAlive
:= utils
.readBool(st
);
891 // Èçðàñõîäîâàë ëè âñå æèçíè
892 gPlayers
[a
].FNoRespawn
:= utils
.readBool(st
);
894 b
:= utils
.readByte(st
);
895 if b
= 1 then gPlayers
[a
].FDirection
:= TDirection
.D_LEFT
else gPlayers
[a
].FDirection
:= TDirection
.D_RIGHT
; // b = 2
897 gPlayers
[a
].FHealth
:= utils
.readLongInt(st
);
899 gPlayers
[a
].FHandicap
:= utils
.readLongInt(st
);
901 gPlayers
[a
].FLives
:= utils
.readByte(st
);
903 gPlayers
[a
].FArmor
:= utils
.readLongInt(st
);
905 gPlayers
[a
].FAir
:= utils
.readLongInt(st
);
907 gPlayers
[a
].FJetFuel
:= utils
.readLongInt(st
);
909 gPlayers
[a
].FPain
:= utils
.readLongInt(st
);
911 gPlayers
[a
].FKills
:= utils
.readLongInt(st
);
913 gPlayers
[a
].FMonsterKills
:= utils
.readLongInt(st
);
915 gPlayers
[a
].FFrags
:= utils
.readLongInt(st
);
917 gPlayers
[a
].FFragCombo
:= utils
.readByte(st
);
918 // Âðåìÿ ïîñëåäíåãî ôðàãà
919 gPlayers
[a
].FLastFrag
:= utils
.readLongWord(st
);
921 gPlayers
[a
].FDeath
:= utils
.readLongInt(st
);
923 gPlayers
[a
].FFlag
:= utils
.readByte(st
);
925 gPlayers
[a
].FSecrets
:= utils
.readLongInt(st
);
927 gPlayers
[a
].FCurrWeap
:= utils
.readByte(st
);
928 // Ñëåäóþùåå æåëàåìîå îðóæèå
929 gPlayers
[a
].FNextWeap
:= utils
.readWord(st
);
931 gPlayers
[a
].FNextWeapDelay
:= utils
.readByte(st
);
933 gPlayers
[a
].FBFGFireCounter
:= utils
.readSmallInt(st
);
935 gPlayers
[a
].FDamageBuffer
:= utils
.readLongInt(st
);
936 // Ïîñëåäíèé óäàðèâøèé
937 gPlayers
[a
].FLastSpawnerUID
:= utils
.readWord(st
);
938 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
939 gPlayers
[a
].FLastHit
:= utils
.readByte(st
);
941 Obj_LoadState(@gPlayers
[a
].FObj
, st
);
942 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
943 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FAmmo
[i
] := utils
.readWord(st
);
944 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
945 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FMaxAmmo
[i
] := utils
.readWord(st
);
947 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FWeapon
[i
] := utils
.readBool(st
);
948 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
949 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FReloading
[i
] := utils
.readWord(st
);
951 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
952 // Íàëè÷èå êðàñíîãî êëþ÷à
953 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
954 // Íàëè÷èå çåëåíîãî êëþ÷à
955 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
956 // Íàëè÷èå ñèíåãî êëþ÷à
957 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
959 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_BERSERK
);
960 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
961 for i
:= MR_SUIT
to MR_MAX
do gPlayers
[a
].FMegaRulez
[i
] := utils
.readLongWord(st
);
962 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
963 for i
:= T_RESPAWN
to T_FLAGCAP
do gPlayers
[a
].FTime
[i
] := utils
.readLongWord(st
);
966 gPlayers
[a
].FActualModelName
:= utils
.readStr(st
);
968 gPlayers
[a
].FColor
.R
:= utils
.readByte(st
);
969 gPlayers
[a
].FColor
.G
:= utils
.readByte(st
);
970 gPlayers
[a
].FColor
.B
:= utils
.readByte(st
);
971 // Îáíîâëÿåì ìîäåëü èãðîêà
972 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
974 // Íåò ìîäåëè - ñîçäàíèå íåâîçìîæíî
975 if (gPlayers
[a
].FModel
= nil) then
979 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
983 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû
984 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
985 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
987 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
989 result
:= gPlayers
[a
].FUID
;
993 procedure g_Player_ResetTeams();
997 if g_Game_IsClient
then
999 if gPlayers
= nil then
1001 for a
:= Low(gPlayers
) to High(gPlayers
) do
1002 if gPlayers
[a
] <> nil then
1003 case gGameSettings
.GameMode
of
1005 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
1007 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
1008 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
1009 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
1012 gPlayers
[a
].ChangeTeam(TEAM_RED
)
1014 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
1017 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
1021 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
1024 _name
, _model
: String;
1027 if not g_Game_IsServer
then Exit
;
1029 // Ñïèñîê íàçâàíèé ìîäåëåé:
1030 m
:= g_PlayerModel_GetNames();
1035 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1036 Team
:= TEAM_COOP
// COOP
1038 if gGameSettings
.GameMode
= GM_DM
then
1039 Team
:= TEAM_NONE
// DM
1041 if Team
= TEAM_NONE
then // CTF / TDM
1043 // Àâòîáàëàíñ êîìàíä:
1047 for a
:= 0 to High(gPlayers
) do
1048 if gPlayers
[a
] <> nil then
1050 if gPlayers
[a
].Team
= TEAM_RED
then
1053 if gPlayers
[a
].Team
= TEAM_BLUE
then
1063 if Random(2) = 0 then
1069 // Âûáèðàåì áîòó èìÿ:
1071 if BotNames
<> nil then
1072 for a
:= 0 to High(BotNames
) do
1073 if g_Player_ValidName(BotNames
[a
]) then
1075 _name
:= BotNames
[a
];
1079 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1080 _model
:= m
[Random(Length(m
))];
1083 with g_Player_Get(g_Player_Create(_model
,
1084 _RGB(Min(Random(9)*32, 255),
1085 Min(Random(9)*32, 255),
1086 Min(Random(9)*32, 255)),
1087 Team
, True)) as TBot
do
1089 // Åñëè èìåíè íåò, äåëàåì åãî èç UID áîòà
1091 Name
:= Format('DFBOT%.5d', [UID
])
1096 1: FDifficult
:= DIFFICULT_EASY
;
1097 2: FDifficult
:= DIFFICULT_MEDIUM
;
1098 else FDifficult
:= DIFFICULT_HARD
;
1101 for a
:= WP_FIRST
to WP_LAST
do
1103 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1104 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1105 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1108 FHandicap
:= Handicap
;
1110 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1112 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1113 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1118 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
1121 _name
, _model
: String;
1124 if not g_Game_IsServer
then Exit
;
1126 // Ñïèñîê íàçâàíèé ìîäåëåé:
1127 m
:= g_PlayerModel_GetNames();
1132 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1133 Team
:= TEAM_COOP
// COOP
1135 if gGameSettings
.GameMode
= GM_DM
then
1136 Team
:= TEAM_NONE
// DM
1138 if Team
= TEAM_NONE
then
1139 Team
:= BotList
[num
].team
; // CTF / TDM
1141 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1142 lName
:= AnsiLowerCase(lName
);
1143 if (num
< 0) or (num
> Length(BotList
)-1) then
1145 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1146 for a
:= 0 to High(BotList
) do
1147 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1156 _name
:= BotList
[num
].name
;
1157 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1158 if not g_Player_ValidName(_name
) then
1160 _name
:= Format('DFBOT%.2d', [Random(100)]);
1161 until g_Player_ValidName(_name
);
1164 _model
:= BotList
[num
].model
;
1165 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1166 if not InSArray(_model
, m
) then
1167 _model
:= m
[Random(Length(m
))];
1170 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1174 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1175 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1176 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1177 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1178 FDifficult
.Cover
:= BotList
[num
].cover
;
1179 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1181 FHandicap
:= Handicap
;
1183 for a
:= WP_FIRST
to WP_LAST
do
1185 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1186 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1187 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1190 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1192 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1196 procedure g_Bot_RemoveAll();
1200 if not g_Game_IsServer
then Exit
;
1201 if gPlayers
= nil then Exit
;
1203 for a
:= 0 to High(gPlayers
) do
1204 if gPlayers
[a
] <> nil then
1205 if gPlayers
[a
] is TBot
then
1207 gPlayers
[a
].Lives
:= 0;
1208 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1209 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1210 g_Player_Remove(gPlayers
[a
].FUID
);
1216 procedure g_Bot_MixNames();
1221 if BotNames
<> nil then
1222 for a
:= 0 to High(BotNames
) do
1224 b
:= Random(Length(BotNames
));
1226 Botnames
[a
] := BotNames
[b
];
1231 procedure g_Player_Remove(UID
: Word);
1235 if gPlayers
= nil then Exit
;
1237 if g_Game_IsServer
and g_Game_IsNet
then
1238 MH_SEND_PlayerDelete(UID
);
1240 for i
:= 0 to High(gPlayers
) do
1241 if gPlayers
[i
] <> nil then
1242 if gPlayers
[i
].FUID
= UID
then
1244 if gPlayers
[i
] is TPlayer
then
1245 TPlayer(gPlayers
[i
]).Free()
1247 TBot(gPlayers
[i
]).Free();
1253 procedure g_Player_Init();
1264 path
:= BOTNAMES_FILENAME
;
1265 if e_FindResource(DataDirs
, path
) = false then
1268 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1269 AssignFile(F
, path
);
1280 SetLength(BotNames
, Length(BotNames
)+1);
1281 BotNames
[High(BotNames
)] := s
;
1289 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1290 config
:= TConfig
.CreateFile(path
);
1294 while config
.SectionExists(IntToStr(a
)) do
1296 SetLength(BotList
, Length(BotList
)+1);
1298 with BotList
[High(BotList
)] do
1301 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1303 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1305 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1310 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1311 color
.R
:= StrToIntDef(sa
[0], 0);
1312 color
.G
:= StrToIntDef(sa
[1], 0);
1313 color
.B
:= StrToIntDef(sa
[2], 0);
1314 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1315 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1316 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1317 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1318 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1319 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1320 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1321 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1322 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1323 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1324 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1325 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1326 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1327 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1328 if Length(sa
) = 10 then
1330 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1331 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1332 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1333 if Length(sa
) = 10 then
1335 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1337 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1338 if Length(sa) = 10 then
1340 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1347 SetLength(SavedStates
, 0);
1350 procedure g_Player_Free();
1354 if gPlayers
<> nil then
1356 for i
:= 0 to High(gPlayers
) do
1357 if gPlayers
[i
] <> nil then
1359 if gPlayers
[i
] is TPlayer
then
1360 TPlayer(gPlayers
[i
]).Free()
1362 TBot(gPlayers
[i
]).Free();
1371 SetLength(SavedStates
, 0);
1374 procedure g_Player_PreUpdate();
1378 if gPlayers
= nil then Exit
;
1379 for i
:= 0 to High(gPlayers
) do
1380 if gPlayers
[i
] <> nil then
1381 gPlayers
[i
].PreUpdate();
1384 procedure g_Player_UpdateAll();
1388 if gPlayers
= nil then Exit
;
1390 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1391 for i
:= 0 to High(gPlayers
) do
1393 if gPlayers
[i
] <> nil then
1395 if gPlayers
[i
] is TPlayer
then
1397 gPlayers
[i
].Update();
1398 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1402 // bot updates weapons in `UpdateCombat()`
1403 TBot(gPlayers
[i
]).Update();
1407 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1410 procedure g_Player_DrawAll();
1414 if gPlayers
= nil then Exit
;
1416 for i
:= 0 to High(gPlayers
) do
1417 if gPlayers
[i
] <> nil then
1418 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1419 else TBot(gPlayers
[i
]).Draw();
1422 procedure g_Player_DrawDebug(p
: TPlayer
);
1426 if p
= nil then Exit
;
1427 if (@p
.FObj
) = nil then Exit
;
1429 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1431 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1432 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1433 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1434 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1435 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1436 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1439 procedure g_Player_DrawHealth();
1444 if gPlayers
= nil then Exit
;
1445 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1447 for i
:= 0 to High(gPlayers
) do
1448 if gPlayers
[i
] <> nil then
1450 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1451 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1452 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1453 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1454 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1455 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1459 function g_Player_Get(UID
: Word): TPlayer
;
1465 if gPlayers
= nil then
1468 for a
:= 0 to High(gPlayers
) do
1469 if gPlayers
[a
] <> nil then
1470 if gPlayers
[a
].FUID
= UID
then
1472 Result
:= gPlayers
[a
];
1477 function g_Player_GetCount(): Byte;
1483 if gPlayers
= nil then
1486 for a
:= 0 to High(gPlayers
) do
1487 if gPlayers
[a
] <> nil then
1488 Result
:= Result
+ 1;
1491 function g_Player_GetStats(): TPlayerStatArray
;
1497 if gPlayers
= nil then Exit
;
1499 for a
:= 0 to High(gPlayers
) do
1500 if gPlayers
[a
] <> nil then
1502 SetLength(Result
, Length(Result
)+1);
1503 with Result
[High(Result
)] do
1506 Ping
:= gPlayers
[a
].FPing
;
1507 Loss
:= gPlayers
[a
].FLoss
;
1508 Name
:= gPlayers
[a
].FName
;
1509 Team
:= gPlayers
[a
].FTeam
;
1510 Frags
:= gPlayers
[a
].FFrags
;
1511 Deaths
:= gPlayers
[a
].FDeath
;
1512 Kills
:= gPlayers
[a
].FKills
;
1513 Color
:= gPlayers
[a
].FModel
.Color
;
1514 Lives
:= gPlayers
[a
].FLives
;
1515 Spectator
:= gPlayers
[a
].FSpectator
;
1520 procedure g_Player_ResetReady();
1524 if not g_Game_IsServer
then Exit
;
1525 if gPlayers
= nil then Exit
;
1527 for a
:= 0 to High(gPlayers
) do
1528 if gPlayers
[a
] <> nil then
1530 gPlayers
[a
].FReady
:= False;
1531 if g_Game_IsNet
then
1532 MH_SEND_GameEvent(NET_EV_INTER_READY
, gPlayers
[a
].UID
, 'N');
1536 procedure g_Player_RememberAll
;
1540 for i
:= Low(gPlayers
) to High(gPlayers
) do
1541 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1542 gPlayers
[i
].RememberState
;
1545 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1549 gTeamStat
[TEAM_RED
].Goals
:= 0;
1550 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1552 if gPlayers
<> nil then
1553 for i
:= 0 to High(gPlayers
) do
1554 if gPlayers
[i
] <> nil then
1556 gPlayers
[i
].Reset(Force
);
1558 if gPlayers
[i
] is TPlayer
then
1560 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1561 gPlayers
[i
].Respawn(Silent
)
1563 gPlayers
[i
].Spectate();
1566 TBot(gPlayers
[i
]).Respawn(Silent
);
1570 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1576 if Player
.alive
then
1579 // Ðàçðûâàåì ñâÿçü ñ ïðåæíèì òðóïîì:
1580 if gCorpses
<> nil then
1581 for i
:= 0 to High(gCorpses
) do
1582 if gCorpses
[i
] <> nil then
1583 if gCorpses
[i
].FPlayerUID
= Player
.FUID
then
1584 gCorpses
[i
].FPlayerUID
:= 0;
1586 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1591 if (FHealth
>= -50) or (gGibsCount
= 0) then
1593 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1597 for find_id
:= 0 to High(gCorpses
) do
1598 if gCorpses
[find_id
] = nil then
1605 find_id
:= Random(Length(gCorpses
));
1607 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1608 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1609 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1610 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1611 gCorpses
[find_id
].FPlayerUID
:= FUID
;
1614 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1615 FObj
.Y
+ PLAYER_RECT_CY
,
1616 FModel
.Name
, FModel
.Color
);
1620 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1624 if (gShells
= nil) or (Length(gShells
) = 0) then
1627 with gShells
[CurrentShell
] do
1633 if T
= SHELL_BULLET
then
1635 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1639 Obj
.Rect
.Width
:= 4;
1640 Obj
.Rect
.Height
:= 2;
1644 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1648 Obj
.Rect
.Width
:= 7;
1649 Obj
.Rect
.Height
:= 3;
1655 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1656 positionChanged(); // this updates spatial accelerators
1657 RAngle
:= Random(360);
1658 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1660 if CurrentShell
>= High(gShells
) then
1667 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1670 GibsArray
: TGibsArray
;
1673 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1675 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1677 Blood
:= g_PlayerModel_GetBlood(ModelName
);
1679 for a
:= 0 to High(GibsArray
) do
1680 with gGibs
[CurrentGib
] do
1683 ID
:= GibsArray
[a
].ID
;
1684 MaskID
:= GibsArray
[a
].MaskID
;
1687 Obj
.Rect
:= GibsArray
[a
].Rect
;
1688 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1689 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1690 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1691 positionChanged(); // this updates spatial accelerators
1692 RAngle
:= Random(360);
1694 if gBloodCount
> 0 then
1695 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1696 Random(48), Random(48), Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
1698 if CurrentGib
>= High(gGibs
) then
1705 procedure g_Player_UpdatePhysicalObjects();
1711 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1716 if T
= SHELL_BULLET
then
1717 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1719 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1724 if gGibs
<> nil then
1725 for i
:= 0 to High(gGibs
) do
1726 if gGibs
[i
].alive
then
1733 mr
:= g_Obj_Move(@Obj
, True, False, True);
1734 positionChanged(); // this updates spatial accelerators
1736 if WordBool(mr
and MOVE_FALLOUT
) then
1742 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1743 if WordBool(mr
and MOVE_HITWALL
) then
1744 Obj
.Vel
.X
:= -(vel
.X
div 2);
1745 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1746 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1748 if (Obj
.Vel
.X
>= 0) then
1750 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1751 if RAngle
>= 360 then
1752 RAngle
:= RAngle
mod 360;
1753 end else begin // Counter-clockwise
1754 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1756 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1759 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1760 if gTime
mod (GAME_TICK
*3) = 0 then
1761 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1765 if gCorpses
<> nil then
1766 for i
:= 0 to High(gCorpses
) do
1767 if gCorpses
[i
] <> nil then
1768 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1774 gCorpses
[i
].Update();
1777 if gShells
<> nil then
1778 for i
:= 0 to High(gShells
) do
1779 if gShells
[i
].alive
then
1786 mr
:= g_Obj_Move(@Obj
, True, False, True);
1787 positionChanged(); // this updates spatial accelerators
1789 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1795 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1796 if WordBool(mr
and MOVE_HITWALL
) then
1798 Obj
.Vel
.X
:= -(vel
.X
div 2);
1799 if not WordBool(mr
and MOVE_INWATER
) then
1800 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1802 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1804 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1805 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1806 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1808 if RAngle
mod 90 <> 0 then
1809 RAngle
:= (RAngle
div 90) * 90;
1811 else if not WordBool(mr
and MOVE_INWATER
) then
1812 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1815 if (Obj
.Vel
.X
>= 0) then
1817 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1818 if RAngle
>= 360 then
1819 RAngle
:= RAngle
mod 360;
1820 end else begin // Counter-clockwise
1821 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1823 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1829 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1831 x
:= Obj
.X
+Obj
.Rect
.X
;
1832 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1833 w
:= Obj
.Rect
.Width
;
1834 h
:= Obj
.Rect
.Height
;
1837 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1839 if (dx
<> 0) or (dy
<> 0) then
1848 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1852 w
:= Obj
.Rect
.Width
;
1853 h
:= Obj
.Rect
.Height
;
1856 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1858 if (dx
<> 0) or (dy
<> 0) then
1867 procedure TGib
.positionChanged (); inline; begin end;
1868 procedure TShell
.positionChanged (); inline; begin end;
1871 procedure g_Player_DrawCorpses();
1876 if gGibs
<> nil then
1877 for i
:= 0 to High(gGibs
) do
1878 if gGibs
[i
].alive
then
1881 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1884 Obj
.lerp(gLerpFactor
, fX
, fY
);
1886 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1887 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1889 e_DrawAdv(ID
, fX
, fY
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1892 e_DrawAdv(MaskID
, fX
, fY
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1898 if gCorpses
<> nil then
1899 for i
:= 0 to High(gCorpses
) do
1900 if gCorpses
[i
] <> nil then
1904 procedure g_Player_DrawShells();
1909 if gShells
<> nil then
1910 for i
:= 0 to High(gShells
) do
1911 if gShells
[i
].alive
then
1914 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1917 Obj
.lerp(gLerpFactor
, fX
, fY
);
1922 e_DrawAdv(SpriteID
, fX
, fY
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1926 procedure g_Player_RemoveAllCorpses();
1932 SetLength(gGibs
, MaxGibs
);
1933 SetLength(gShells
, MaxGibs
);
1937 if gCorpses
<> nil then
1938 for i
:= 0 to High(gCorpses
) do
1942 SetLength(gCorpses
, MaxCorpses
);
1945 procedure g_Player_Corpses_SaveState (st
: TStream
);
1949 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ
1951 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1953 // Êîëè÷åñòâî òðóïîâ
1954 utils
.writeInt(st
, LongInt(count
));
1956 if (count
= 0) then exit
;
1959 for i
:= 0 to High(gCorpses
) do
1961 if gCorpses
[i
] <> nil then
1964 utils
.writeStr(st
, gCorpses
[i
].FModelName
);
1966 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1967 // Ñîõðàíÿåì äàííûå òðóïà:
1968 gCorpses
[i
].SaveState(st
);
1974 procedure g_Player_Corpses_LoadState (st
: TStream
);
1982 g_Player_RemoveAllCorpses();
1984 // Êîëè÷åñòâî òðóïîâ:
1985 count
:= utils
.readLongInt(st
);
1986 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1988 if (count
= 0) then exit
;
1991 for i
:= 0 to count
-1 do
1994 str
:= utils
.readStr(st
);
1996 b
:= utils
.readBool(st
);
1998 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1999 // Çàãðóæàåì äàííûå òðóïà
2000 gCorpses
[i
].LoadState(st
);
2007 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
2009 procedure TPlayer
.BFGHit();
2011 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
2012 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
2013 if g_Game_IsServer
and g_Game_IsNet
then
2014 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
2015 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
2019 procedure TPlayer
.ChangeModel(ModelName
: string);
2021 locModel
: TPlayerModel
;
2023 locModel
:= g_PlayerModel_Get(ModelName
);
2024 if locModel
= nil then Exit
;
2030 procedure TPlayer
.SetModel(ModelName
: string);
2034 m
:= g_PlayerModel_Get(ModelName
);
2037 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
2038 m
:= g_PlayerModel_Get('doomer');
2041 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
2046 if FModel
<> nil then
2051 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2052 FModel
.Color
:= FColor
2054 FModel
.Color
:= TEAMCOLOR
[FTeam
];
2055 FModel
.SetWeapon(FCurrWeap
);
2056 FModel
.SetFlag(FFlag
);
2057 SetDirection(FDirection
);
2060 procedure TPlayer
.SetColor(Color
: TRGB
);
2063 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2064 if FModel
<> nil then FModel
.Color
:= Color
;
2067 function TPlayer
.GetColor(): TRGB
;
2069 result
:= FModel
.Color
;
2072 procedure TPlayer
.SwitchTeam
;
2074 if g_Game_IsClient
then
2076 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
2078 if gGameOn
and FAlive
then
2079 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
2081 if FTeam
= TEAM_RED
then
2083 ChangeTeam(TEAM_BLUE
);
2084 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
2085 if g_Game_IsNet
then
2086 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
2090 ChangeTeam(TEAM_RED
);
2091 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
2092 if g_Game_IsNet
then
2093 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
2095 FPreferredTeam
:= FTeam
;
2098 procedure TPlayer
.ChangeTeam(Team
: Byte);
2105 TEAM_RED
, TEAM_BLUE
:
2106 FModel
.Color
:= TEAMCOLOR
[Team
];
2108 FModel
.Color
:= FColor
;
2110 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2111 MH_SEND_PlayerStats(FUID
);
2115 procedure TPlayer.CollideItem();
2120 if gItems = nil then Exit;
2121 if not FAlive then Exit;
2123 for i := 0 to High(gItems) do
2126 if (ItemType <> ITEM_NONE) and alive then
2127 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2128 PLAYER_RECT.Height, @Obj) then
2130 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2132 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2133 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2134 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2135 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2136 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2138 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2139 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2140 (gGameSettings.GameType = GT_SINGLE) and
2141 (g_Player_GetCount() > 1)) then
2142 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2148 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2150 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2151 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2155 constructor TPlayer
.Create();
2161 mEDamageType
:= HIT_SOME
;
2167 FSawSound
:= TPlayableSound
.Create();
2168 FSawSoundIdle
:= TPlayableSound
.Create();
2169 FSawSoundHit
:= TPlayableSound
.Create();
2170 FSawSoundSelect
:= TPlayableSound
.Create();
2171 FFlameSoundOn
:= TPlayableSound
.Create();
2172 FFlameSoundOff
:= TPlayableSound
.Create();
2173 FFlameSoundWork
:= TPlayableSound
.Create();
2174 FJetSoundFly
:= TPlayableSound
.Create();
2175 FJetSoundOn
:= TPlayableSound
.Create();
2176 FJetSoundOff
:= TPlayableSound
.Create();
2178 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2179 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2180 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2181 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2182 FFlameSoundOn
.SetByName('SOUND_WEAPON_FLAMEON');
2183 FFlameSoundOff
.SetByName('SOUND_WEAPON_FLAMEOFF');
2184 FFlameSoundWork
.SetByName('SOUND_WEAPON_FLAMEWORK');
2185 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2186 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2187 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2189 FSpectatePlayer
:= -1;
2193 FSavedStateNum
:= -1;
2200 FActualModelName
:= 'doomer';
2203 FObj
.Rect
:= PLAYER_RECT
;
2205 FBFGFireCounter
:= -1;
2206 FJustTeleported
:= False;
2209 FWaitForFirstSpawn
:= false;
2214 procedure TPlayer
.positionChanged (); inline;
2218 procedure TPlayer
.doDamage (v
: Integer);
2220 if (v
<= 0) then exit
;
2221 if (v
> 32767) then v
:= 32767;
2222 Damage(v
, 0, 0, 0, mEDamageType
);
2225 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2229 if (not g_Game_IsClient
) and (not FAlive
) then
2234 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2235 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2237 if not g_Game_IsClient
then
2240 if t
= HIT_TRAP
then
2242 // Ëîâóøêà óáèâàåò ñðàçó:
2244 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2246 if t
= HIT_SELF
then
2250 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2253 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2254 FMegaRulez
[MR_SUIT
] := 0;
2255 FMegaRulez
[MR_INVUL
] := 0;
2256 FMegaRulez
[MR_INVIS
] := 0;
2261 // Íî îò îñòàëüíîãî ñïàñàåò:
2262 if FMegaRulez
[MR_INVUL
] >= gTime
then
2269 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2270 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2271 (SpawnerUID
= FUID
) or
2272 (not SameTeam(FUID
, SpawnerUID
)) then
2274 FLastSpawnerUID
:= SpawnerUID
;
2276 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2277 if gBloodCount
> 0 then
2279 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2280 if value
div 4 <= c
then
2281 c
:= c
- (value
div 4)
2285 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2289 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2290 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2293 if t
= HIT_WATER
then
2294 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2295 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2300 Inc(FDamageBuffer
, value
);
2304 FPain
:= FPain
+ value
;
2307 if g_Game_IsServer
and g_Game_IsNet
then
2309 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2310 MH_SEND_PlayerStats(FUID
);
2311 MH_SEND_PlayerPos(False, FUID
);
2315 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2318 if g_Game_IsClient
then
2323 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2325 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2328 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2330 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2334 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2335 MH_SEND_PlayerStats(FUID
);
2338 destructor TPlayer
.Destroy();
2340 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2342 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2346 FSawSoundIdle
.Free();
2347 FSawSoundHit
.Free();
2348 FSawSoundSelect
.Free();
2349 FFlameSoundOn
.Free();
2350 FFlameSoundOff
.Free();
2351 FFlameSoundWork
.Free();
2352 FJetSoundFly
.Free();
2354 FJetSoundOff
.Free();
2356 if FPunchAnim
<> nil then
2362 procedure TPlayer
.DrawIndicator(Color
: TRGB
);
2364 indX
, indY
, fX
, fY
, fSlope
: Integer;
2374 FObj
.lerp(gLerpFactor
, fX
, fY
);
2375 fSlope
:= nlerp(FSlopeOld
, FObj
.slopeUpLeft
, gLerpFactor
);
2377 case gPlayerIndicatorStyle
of
2380 if g_Texture_Get('TEXTURE_PLAYER_INDICATOR', ID
) then
2382 e_GetTextureSize(ID
, @indW
, @indH
);
2386 if (FObj
.X
+ FObj
.Rect
.X
) < 0 then
2389 indX
:= fX
+ FObj
.Rect
.X
+ FObj
.Rect
.Width
;
2390 indY
:= fY
+ FObj
.Rect
.Y
+ (FObj
.Rect
.Height
- indW
) div 2;
2393 else if (FObj
.X
+ FObj
.Rect
.X
+ FObj
.Rect
.Width
) > Max(gMapInfo
.Width
, gPlayerScreenSize
.X
) then
2396 indX
:= fX
+ FObj
.Rect
.X
- indH
;
2397 indY
:= fY
+ FObj
.Rect
.Y
+ (FObj
.Rect
.Height
- indW
) div 2;
2400 else if (FObj
.Y
- indH
) < 0 then
2403 indX
:= fX
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
- indW
) div 2;
2404 indY
:= fY
+ FObj
.Rect
.Y
+ FObj
.Rect
.Height
;
2410 indX
:= fX
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
- indW
) div 2;
2414 indY
:= indY
+ fSlope
;
2415 indX
:= EnsureRange(indX
, 0, Max(gMapInfo
.Width
, gPlayerScreenSize
.X
) - indW
);
2416 indY
:= EnsureRange(indY
, 0, Max(gMapInfo
.Height
, gPlayerScreenSize
.Y
) - indH
);
2420 e_DrawAdv(ID
, indX
, indY
, 0, True, False, indA
, @a
);
2427 e_TextureFontGetSize(gStdFont
, nW
, nH
);
2428 indX
:= fX
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
- Length(FName
) * nW
) div 2;
2429 indY
:= fY
- nH
+ fSlope
;
2430 e_TextureFontPrintEx(indX
, indY
, FName
, gStdFont
, Color
.R
, Color
.G
, Color
.B
, 1.0, True);
2436 procedure TPlayer
.DrawBubble();
2438 bubX
, bubY
, fX
, fY
: Integer;
2441 Rw
, Gw
, Bw
: SmallInt;
2444 FObj
.lerp(gLerpFactor
, fX
, fY
);
2445 bubX
:= fX
+FObj
.Rect
.X
+ IfThen(FDirection
= TDirection
.D_LEFT
, -4, 18);
2446 bubY
:= fY
+FObj
.Rect
.Y
- 18;
2454 1: // simple textual non-bubble
2456 bubX
:= fX
+FObj
.Rect
.X
- 11;
2457 bubY
:= fY
+FObj
.Rect
.Y
- 17;
2458 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2461 2: // advanced pixel-perfect bubble
2463 if FTeam
= TEAM_RED
then
2466 if FTeam
= TEAM_BLUE
then
2469 3: // colored bubble
2471 Rb
:= FModel
.Color
.R
;
2472 Gb
:= FModel
.Color
.G
;
2473 Bb
:= FModel
.Color
.B
;
2474 Rw
:= Min(Rb
* 2 + 64, 255);
2475 Gw
:= Min(Gb
* 2 + 64, 255);
2476 Bw
:= Min(Bb
* 2 + 64, 255);
2477 if (Abs(Rw
- Rb
) < 32)
2478 or (Abs(Gw
- Gb
) < 32)
2479 or (Abs(Bw
- Bb
) < 32) then
2481 Rb
:= Max(Rw
div 2 - 16, 0);
2482 Gb
:= Max(Gw
div 2 - 16, 0);
2483 Bb
:= Max(Bw
div 2 - 16, 0);
2486 4: // custom textured bubble
2488 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2489 if FDirection
= TDirection
.D_RIGHT
then
2490 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2492 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, TMirrorType
.Horizontal
);
2498 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2499 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2501 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2504 Dot
:= IfThen(FDirection
= TDirection
.D_LEFT
, 14, 5);
2505 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2506 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
);
2507 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
);
2508 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
);
2509 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
);
2513 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2514 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2515 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2518 procedure TPlayer
.Draw();
2523 Mirror
: TMirrorType
;
2524 fX
, fY
, fSlope
: Integer;
2526 FObj
.lerp(gLerpFactor
, fX
, fY
);
2527 fSlope
:= nlerp(FSlopeOld
, FObj
.slopeUpLeft
, gLerpFactor
);
2531 if Direction
= TDirection
.D_RIGHT
then
2532 Mirror
:= TMirrorType
.None
2534 Mirror
:= TMirrorType
.Horizontal
;
2536 if FPunchAnim
<> nil then
2538 FPunchAnim
.Draw(fX
+IfThen(Direction
= TDirection
.D_LEFT
, 15-FObj
.Rect
.X
, FObj
.Rect
.X
-15),
2539 fY
+fSlope
+FObj
.Rect
.Y
-11, Mirror
);
2540 if FPunchAnim
.played
then
2547 if (FMegaRulez
[MR_INVUL
] > gTime
) and ((gPlayerDrawn
<> Self
) or (FSpawnInvul
>= gTime
)) then
2548 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2550 e_GetTextureSize(ID
, @w
, @h
);
2551 if FDirection
= TDirection
.D_LEFT
then
2552 e_Draw(ID
, fX
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2553 fY
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+fSlope
, 0, True, False)
2555 e_Draw(ID
, fX
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2556 fY
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+fSlope
, 0, True, False);
2559 if FMegaRulez
[MR_INVIS
] > gTime
then
2561 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2562 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2564 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2565 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2569 FModel
.Draw(fX
, fY
+fSlope
, 200)
2571 FModel
.Draw(fX
, fY
+fSlope
);
2574 FModel
.Draw(fX
, fY
+fSlope
, 254);
2577 FModel
.Draw(fX
, fY
+fSlope
);
2580 if g_debug_Frames
then
2582 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2584 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2585 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2589 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2590 if (FMegaRulez
[MR_INVIS
] <= gTime
) or ((gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2591 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
)))) then
2593 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2594 if gAimLine
and alive
and
2595 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2600 procedure TPlayer
.DrawAim();
2601 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2606 {$IFDEF ENABLE_HOLMES}
2607 if isValidViewPort
and (self
= gPlayer1
) then
2609 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2613 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2614 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2616 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2620 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2625 wx
, wy
, xx
, yy
: Integer;
2629 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= TDirection
.D_LEFT
, 7, -7);
2630 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2639 1: begin // Chainsaw
2646 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2647 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2648 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2649 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2654 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2655 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2656 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2657 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2659 4: begin // Double Shotgun
2662 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2663 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2664 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2665 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2667 5: begin // Chaingun
2670 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2671 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2672 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2673 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2675 6: begin // Rocket Launcher
2678 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2679 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2680 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2681 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2683 7: begin // Plasmagun
2686 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2687 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2688 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2689 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2694 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2695 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2696 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2697 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2699 9: begin // Super Chaingun
2702 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2703 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2704 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2705 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2708 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2709 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2710 {$IF DEFINED(D2F_DEBUG)}
2711 drawCast(sz
, wx
, wy
, xx
, yy
);
2713 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2717 procedure TPlayer
.DrawGUI();
2720 X
, Y
, SY
, a
, p
, m
: Integer;
2724 stat
: TPlayerStatArray
;
2726 X
:= gPlayerScreenSize
.X
;
2727 SY
:= gPlayerScreenSize
.Y
;
2730 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2732 if gGameSettings
.GameMode
= GM_CTF
then
2736 if gGameSettings
.GameMode
= GM_CTF
then
2738 s
:= 'TEXTURE_PLAYER_REDFLAG';
2739 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2740 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2741 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2742 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2743 if g_Texture_Get(s
, ID
) then
2744 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2747 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2748 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2749 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2751 if gGameSettings
.GameMode
= GM_CTF
then
2753 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2754 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2755 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2756 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2757 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2758 if g_Texture_Get(s
, ID
) then
2759 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2762 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2763 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2764 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2767 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2768 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2771 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2772 e_Draw(ID
, X
+2, Y
, 0, True, False);
2774 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2778 s
:= IntToStr(Frags
);
2779 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2780 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2785 stat
:= g_Player_GetStats();
2790 for a
:= 0 to High(stat
) do
2791 if stat
[a
].Name
<> Name
then
2793 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2794 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2798 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2799 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2800 s
:= s
+IntToStr(Abs(Frags
-m
));
2802 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2803 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2806 if gLMSRespawn
> LMS_RESPAWN_NONE
then
2808 s
:= _lc
[I_GAME_WARMUP
];
2809 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2810 s
:= s
+ ': ' + IntToStr((gLMSRespawnTime
- gTime
) div 1000);
2811 e_CharFont_PrintEx(gMenuFont
, X
-64-tw
, SY
-32, s
, _RGB(0, 255, 0));
2813 else if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2815 s
:= IntToStr(Lives
);
2816 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2817 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2821 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2822 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2824 if R_BERSERK
in FRulez
then
2825 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2827 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2829 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2830 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2832 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2833 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2834 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2836 s
:= IntToStr(FArmor
);
2837 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2838 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2840 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2846 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2851 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2853 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2854 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2855 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2856 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2857 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2858 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2859 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2860 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2861 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2864 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2865 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2866 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2868 if R_KEY_RED
in FRulez
then
2869 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2871 if R_KEY_GREEN
in FRulez
then
2872 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2874 if R_KEY_BLUE
in FRulez
then
2875 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2877 if FJetFuel
> 0 then
2879 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2880 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2881 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2882 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2883 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2884 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2888 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2889 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2890 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2893 if gShowPing
and g_Game_IsClient
then
2895 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2896 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2902 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2903 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2904 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2907 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2908 s
:= _lc
[I_PLAYER_SPECT4
];
2909 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2910 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2911 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2917 procedure TPlayer
.DrawRulez();
2921 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2922 if (FMegaRulez
[MR_INVUL
] >= gTime
) and (FSpawnInvul
< gTime
) then
2924 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2925 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2930 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2931 191, 191, 191, 0, TBlending
.Invert
);
2934 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2935 if FMegaRulez
[MR_SUIT
] >= gTime
then
2937 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2938 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2943 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2944 0, 96, 0, 200, TBlending
.None
);
2947 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2948 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2950 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2951 255, 0, 0, 200, TBlending
.None
);
2955 procedure TPlayer
.DrawPain();
2959 if FPain
= 0 then Exit
;
2963 if a
< 15 then h
:= 0
2964 else if a
< 35 then h
:= 1
2965 else if a
< 55 then h
:= 2
2966 else if a
< 75 then h
:= 3
2967 else if a
< 95 then h
:= 4
2970 //if a > 255 then a := 255;
2972 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2973 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2976 procedure TPlayer
.DrawPickup();
2980 if FPickup
= 0 then Exit
;
2984 if a
< 15 then h
:= 1
2985 else if a
< 35 then h
:= 2
2986 else if a
< 55 then h
:= 3
2987 else if a
< 75 then h
:= 4
2990 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2993 procedure TPlayer
.DoPunch();
2998 if FPunchAnim
<> nil then begin
3003 st
:= 'FRAMES_PUNCH';
3004 if R_BERSERK
in FRulez
then
3005 st
:= st
+ '_BERSERK';
3006 if FKeys
[KEY_UP
].Pressed
then
3008 else if FKeys
[KEY_DOWN
].Pressed
then
3010 g_Frames_Get(id
, st
);
3011 FPunchAnim
:= TAnimation
.Create(id
, False, 1);
3014 procedure TPlayer
.Fire();
3016 f
, DidFire
: Boolean;
3017 wx
, wy
, xd
, yd
: Integer;
3020 if g_Game_IsClient
then Exit
;
3021 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
3022 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
3030 if FReloading
[FCurrWeap
] <> 0 then Exit
;
3035 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
3036 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
3037 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
3038 yd
:= wy
+firediry();
3044 if R_BERSERK
in FRulez
then
3046 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
3047 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
3048 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
3051 locobj
.rect
.Width
:= 39;
3052 locobj
.rect
.Height
:= 52;
3053 locobj
.Vel
.X
:= (xd
-wx
) div 2;
3054 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
3055 locobj
.Accel
.X
:= xd
-wx
;
3056 locobj
.Accel
.y
:= yd
-wy
;
3058 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
3059 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
3061 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
3063 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
3067 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
3071 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3076 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
3077 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
3079 FSawSoundSelect
.Stop();
3081 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
3083 else if not FSawSoundHit
.IsPlaying() then
3085 FSawSoundSelect
.Stop();
3086 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
3089 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3095 if FAmmo
[A_BULLETS
] > 0 then
3097 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
3098 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3099 Dec(FAmmo
[A_BULLETS
]);
3100 FFireAngle
:= FAngle
;
3103 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3104 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3108 if FAmmo
[A_SHELLS
] > 0 then
3110 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3111 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
3112 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3113 Dec(FAmmo
[A_SHELLS
]);
3114 FFireAngle
:= FAngle
;
3118 FShellType
:= SHELL_SHELL
;
3122 if FAmmo
[A_SHELLS
] >= 2 then
3124 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
3125 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3126 Dec(FAmmo
[A_SHELLS
], 2);
3127 FFireAngle
:= FAngle
;
3131 FShellType
:= SHELL_DBLSHELL
;
3135 if FAmmo
[A_BULLETS
] > 0 then
3137 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
3138 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
3139 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3140 Dec(FAmmo
[A_BULLETS
]);
3141 FFireAngle
:= FAngle
;
3144 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3145 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3148 WEAPON_ROCKETLAUNCHER
:
3149 if FAmmo
[A_ROCKETS
] > 0 then
3151 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
3152 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3153 Dec(FAmmo
[A_ROCKETS
]);
3154 FFireAngle
:= FAngle
;
3160 if FAmmo
[A_CELLS
] > 0 then
3162 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
3163 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3164 Dec(FAmmo
[A_CELLS
]);
3165 FFireAngle
:= FAngle
;
3171 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
3173 FBFGFireCounter
:= 17;
3174 if not FNoReload
then
3175 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
3176 Dec(FAmmo
[A_CELLS
], 40);
3180 WEAPON_SUPERPULEMET
:
3181 if FAmmo
[A_SHELLS
] > 0 then
3183 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3184 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
3185 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3186 Dec(FAmmo
[A_SHELLS
]);
3187 FFireAngle
:= FAngle
;
3190 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3191 GameVelX
, GameVelY
-2, SHELL_SHELL
);
3194 WEAPON_FLAMETHROWER
:
3195 if FAmmo
[A_FUEL
] > 0 then
3197 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
3199 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3201 FFireAngle
:= FAngle
;
3208 if g_Game_IsNet
and g_Game_IsServer
then MH_SEND_PlayerStats(FUID
);
3212 if g_Game_IsNet
then
3216 if FCurrWeap
<> WEAPON_BFG
then
3217 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
3219 if not FNoReload
then
3220 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
3223 MH_SEND_PlayerStats(FUID
);
3228 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
3229 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
3230 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
3233 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
3236 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
3237 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
3238 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
3239 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
3240 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
3245 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
3247 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
3248 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
3249 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
3252 procedure TPlayer
.FlamerOn
;
3254 FFlameSoundOff
.Stop();
3255 FFlameSoundOff
.SetPosition(0);
3258 if (not FFlameSoundOn
.IsPlaying()) and (not FFlameSoundWork
.IsPlaying()) then
3259 FFlameSoundWork
.PlayAt(FObj
.X
, FObj
.Y
);
3263 FFlameSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3268 procedure TPlayer
.FlamerOff
;
3272 FFlameSoundOn
.Stop();
3273 FFlameSoundOn
.SetPosition(0);
3274 FFlameSoundWork
.Stop();
3275 FFlameSoundWork
.SetPosition(0);
3276 FFlameSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3281 procedure TPlayer
.JetpackOn
;
3285 FJetSoundOn
.SetPosition(0);
3286 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3290 procedure TPlayer
.JetpackOff
;
3294 FJetSoundOff
.SetPosition(0);
3295 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3298 procedure TPlayer
.CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
3300 if Timeout
<= 0 then
3302 if (FMegaRulez
[MR_SUIT
] > gTime
) or (FMegaRulez
[MR_INVUL
] > gTime
) then
3303 exit
; // Íå çàãîðàåìñÿ êîãäà åñòü çàùèòà
3304 if g_Obj_CollidePanel(@FObj
, 0, 0, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
) then
3305 exit
; // Íå ïîäãîðàåì â âîäå íà âñÿêèé ñëó÷àé
3306 if FFireTime
<= 0 then
3307 g_Sound_PlayExAt('SOUND_IGNITE', FObj
.X
, FObj
.Y
);
3308 FFireTime
:= Timeout
;
3309 FFireAttacker
:= Attacker
;
3310 if g_Game_IsNet
and g_Game_IsServer
then
3311 MH_SEND_PlayerStats(FUID
);
3314 procedure TPlayer
.Jump();
3316 if gFly
or FJetpack
then
3318 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3319 if FObj
.Vel
.Y
> -VEL_FLY
then
3320 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3323 if FJetFuel
> 0 then
3325 if (FJetFuel
< 1) and g_Game_IsServer
then
3329 if g_Game_IsNet
then
3330 MH_SEND_PlayerStats(FUID
);
3336 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3338 FCanJetpack
:= False;
3340 // Ïðûãàåì èëè âñïëûâàåì:
3341 if (CollideLevel(0, 1) or
3342 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3343 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3344 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3346 FObj
.Vel
.Y
:= -VEL_JUMP
;
3347 FCanJetpack
:= False;
3351 if BodyInLiquid(0, 0) then
3352 FObj
.Vel
.Y
:= -VEL_SW
3353 else if (FJetFuel
> 0) and FCanJetpack
and
3354 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3358 if g_Game_IsNet
then
3359 MH_SEND_PlayerStats(FUID
);
3364 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3366 a
, i
, k
, ab
, ar
: Byte;
3370 srv
, netsrv
: Boolean;
3376 procedure PushItem(t
: Byte);
3380 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3381 it
:= g_Items_ByIdx(id
);
3382 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3384 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3385 (FObj
.Vel
.Y
div 2)-Random(9));
3386 it
.positionChanged(); // this updates spatial accelerators
3390 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3392 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3393 (FObj
.Vel
.Y
div 2)-Random(6));
3395 else // -3..+3; -3..0
3397 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3398 (FObj
.Vel
.Y
div 2)-Random(4));
3400 it
.positionChanged(); // this updates spatial accelerators
3403 if g_Game_IsNet
and g_Game_IsServer
then
3404 MH_SEND_ItemSpawn(True, id
);
3408 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3409 Srv
:= g_Game_IsServer
;
3410 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3411 if Srv
then FDeath
:= FDeath
+ 1;
3416 if not FPhysics
then
3422 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3424 if FLives
> 0 then FLives
:= FLives
- 1;
3425 if FLives
= 0 then FNoRespawn
:= True;
3428 // Íîìåð òèïà ñìåðòè:
3431 K_SIMPLEKILL
: a
:= 1;
3433 K_EXTRAHARDKILL
: a
:= 3;
3438 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3440 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3447 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3449 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3450 K_EXTRAHARDKILL
, K_FALLKILL
:
3451 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3454 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3458 K_HARDKILL
, K_EXTRAHARDKILL
:
3462 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3463 if (KillType
<> K_FALLKILL
) and (Srv
) then
3464 g_Monsters_killedp();
3466 if SpawnerUID
= FUID
then
3468 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3473 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3476 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3477 begin // Óáèò äðóãèì èãðîêîì
3478 KP
:= g_Player_Get(SpawnerUID
);
3479 if (KP
<> nil) and Srv
then
3481 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3482 if SameTeam(FUID
, SpawnerUID
) then
3492 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3493 Inc(gTeamStat
[KP
.Team
].Goals
,
3494 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3496 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3499 plr
:= g_Player_Get(SpawnerUID
);
3507 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3511 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3515 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3520 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3521 begin // Óáèò ìîíñòðîì
3522 mon
:= g_Monsters_ByUID(SpawnerUID
);
3526 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
3530 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3534 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3538 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3543 else // Îñîáûå òèïû ñìåðòè
3546 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3547 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3548 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3549 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3550 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3551 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3557 for a
:= WP_FIRST
to WP_LAST
do
3561 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3562 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3563 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3564 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3565 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3566 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3567 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3568 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3569 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3578 if R_ITEM_BACKPACK
in FRulez
then
3579 PushItem(ITEM_AMMO_BACKPACK
);
3581 // Âûáðîñ ðàêåòíîãî ðàíöà:
3582 if FJetFuel
> 0 then
3583 PushItem(ITEM_JETPACK
);
3586 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) or
3587 (not LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
)) then
3589 if R_KEY_RED
in FRulez
then
3590 PushItem(ITEM_KEY_RED
);
3592 if R_KEY_GREEN
in FRulez
then
3593 PushItem(ITEM_KEY_GREEN
);
3595 if R_KEY_BLUE
in FRulez
then
3596 PushItem(ITEM_KEY_BLUE
);
3600 DropFlag(KillType
= K_FALLKILL
);
3603 g_Player_CreateCorpse(Self
);
3605 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3606 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3612 for i
:= Low(gPlayers
) to High(gPlayers
) do
3614 if gPlayers
[i
] = nil then continue
;
3615 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3618 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3619 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3624 OldLR
:= gLMSRespawn
;
3625 if (gGameSettings
.GameMode
= GM_COOP
) then
3629 // everyone is dead, restart the map
3630 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3632 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3633 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3634 gLMSRespawnTime
:= gTime
+ 5000;
3636 else if (a
= 1) then
3638 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3639 if (gPlayers
[k
] = gPlayer1
) or
3640 (gPlayers
[k
] = gPlayer2
) then
3641 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3642 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3643 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3646 else if (gGameSettings
.GameMode
= GM_TDM
) then
3648 if (ab
= 0) and (ar
<> 0) then
3651 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3653 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3654 Inc(gTeamStat
[TEAM_RED
].Goals
);
3655 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3656 gLMSRespawnTime
:= gTime
+ 5000;
3658 else if (ar
= 0) and (ab
<> 0) then
3661 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3663 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3664 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3665 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3666 gLMSRespawnTime
:= gTime
+ 5000;
3668 else if (ar
= 0) and (ab
= 0) then
3671 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3673 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3674 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3675 gLMSRespawnTime
:= gTime
+ 5000;
3678 else if (gGameSettings
.GameMode
= GM_DM
) then
3682 if gPlayers
[k
] <> nil then
3685 // survivor is the winner
3686 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3688 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3691 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3692 gLMSRespawnTime
:= gTime
+ 5000;
3694 else if (a
= 0) then
3696 // everyone is dead, restart the map
3697 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3699 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3700 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3701 gLMSRespawnTime
:= gTime
+ 5000;
3704 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3706 if NetMode
= NET_SERVER
then
3707 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
)
3709 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3715 MH_SEND_PlayerStats(FUID
);
3716 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3717 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3720 if srv
and FNoRespawn
then Spectate(True);
3721 FWantsInGame
:= True;
3724 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3726 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3727 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3730 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3732 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3733 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3736 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3738 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3739 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3740 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3741 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3742 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3743 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3744 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3745 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3748 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3750 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3751 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3752 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3753 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3756 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3758 if g_Game_IsClient
then Exit
;
3759 if Weapon
> High(FWeapon
) then Exit
;
3760 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3763 procedure TPlayer
.resetWeaponQueue ();
3766 FNextWeapDelay
:= 0;
3769 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3773 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3774 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
3775 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
3776 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3777 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3778 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3779 else result
:= (weapon
< length(FWeapon
));
3783 // return 255 for "no switch"
3784 function TPlayer
.getNextWeaponIndex (): Byte;
3787 wantThisWeapon
: array[0..64] of Boolean;
3788 wwc
: Integer = 0; //HACK!
3791 result
:= 255; // default result: "no switch"
3792 // had weapon cycling on previous frame? remove that flag
3793 if (FNextWeap
and $2000) <> 0 then
3795 FNextWeap
:= FNextWeap
and $1FFF;
3796 FNextWeapDelay
:= 0;
3798 // cycling has priority
3799 if (FNextWeap
and $C000) <> 0 then
3801 if (FNextWeap
and $8000) <> 0 then
3805 FNextWeap
:= FNextWeap
or $2000; // we need this
3806 if FNextWeapDelay
> 0 then
3807 exit
; // cooldown time
3809 for i
:= 0 to High(FWeapon
) do
3811 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3812 if FWeapon
[cwi
] then
3814 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d', [FCurrWeap, cwi]), MSG_WARNING);
3815 result
:= Byte(cwi
);
3816 FNextWeapDelay
:= WEAPON_DELAY
;
3824 for i
:= 0 to High(wantThisWeapon
) do
3825 wantThisWeapon
[i
] := false;
3826 for i
:= 0 to High(FWeapon
) do
3827 if (FNextWeap
and (1 shl i
)) <> 0 then
3829 wantThisWeapon
[i
] := true;
3832 // exclude currently selected weapon from the set
3833 wantThisWeapon
[FCurrWeap
] := false;
3834 // slow down alterations a little
3837 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3838 // more than one weapon requested, assume "alteration" and check alteration delay
3839 if FNextWeapDelay
> 0 then
3845 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3846 // but clear all counters if no weapon should be switched
3852 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3853 // try weapons in descending order
3854 for i
:= High(FWeapon
) downto 0 do
3856 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3861 FNextWeapDelay
:= WEAPON_DELAY
* 2; // anyway, 'cause why not
3865 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3869 procedure TPlayer
.RealizeCurrentWeapon();
3870 function switchAllowed (): Boolean;
3875 if FBFGFireCounter
<> -1 then
3877 if FTime
[T_SWITCH
] > gTime
then
3879 for i
:= WP_FIRST
to WP_LAST
do
3880 if FReloading
[i
] > 0 then
3888 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3889 //FNextWeap := FNextWeap and $1FFF;
3890 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3892 if not switchAllowed
then
3894 //HACK for weapon cycling
3895 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3899 nw
:= getNextWeaponIndex();
3900 if nw
= 255 then exit
; // don't reset anything here
3901 if nw
> High(FWeapon
) then
3903 // don't forget to reset queue here!
3904 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3912 FTime
[T_SWITCH
] := gTime
+156;
3913 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3914 FModel
.SetWeapon(FCurrWeap
);
3915 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3919 procedure TPlayer
.NextWeapon();
3921 if g_Game_IsClient
then Exit
;
3925 procedure TPlayer
.PrevWeapon();
3927 if g_Game_IsClient
then Exit
;
3931 procedure TPlayer
.SetWeapon(W
: Byte);
3933 if FCurrWeap
<> W
then
3934 if W
= WEAPON_SAW
then
3935 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3938 FModel
.SetWeapon(CurrWeap
);
3942 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3944 function allowBerserkSwitching (): Boolean;
3946 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3948 if gBerserkAutoswitch
then exit
;
3949 if not conIsCheatsEnabled
then exit
;
3957 if g_Game_IsClient
then Exit
;
3959 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3960 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3965 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3967 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3971 if gFlash
= 2 then Inc(FPickup
, 5);
3975 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3977 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3981 if gFlash
= 2 then Inc(FPickup
, 5);
3985 if FArmor
< PLAYER_AP_SOFT
then
3987 FArmor
:= PLAYER_AP_SOFT
;
3990 if gFlash
= 2 then Inc(FPickup
, 5);
3994 if FArmor
< PLAYER_AP_LIMIT
then
3996 FArmor
:= PLAYER_AP_LIMIT
;
3999 if gFlash
= 2 then Inc(FPickup
, 5);
4003 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
4005 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
4009 if gFlash
= 2 then Inc(FPickup
, 5);
4013 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) or (FFireTime
> 0) then
4015 if FHealth
< PLAYER_HP_LIMIT
then
4016 FHealth
:= PLAYER_HP_LIMIT
;
4017 if FArmor
< PLAYER_AP_LIMIT
then
4018 FArmor
:= PLAYER_AP_LIMIT
;
4022 if gFlash
= 2 then Inc(FPickup
, 5);
4026 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
4028 FWeapon
[WEAPON_SAW
] := True;
4030 if gFlash
= 2 then Inc(FPickup
, 5);
4031 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4034 ITEM_WEAPON_SHOTGUN1
:
4035 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
4037 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
4038 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
4040 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4041 FWeapon
[WEAPON_SHOTGUN1
] := True;
4043 if gFlash
= 2 then Inc(FPickup
, 5);
4044 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4047 ITEM_WEAPON_SHOTGUN2
:
4048 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
4050 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
4052 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4053 FWeapon
[WEAPON_SHOTGUN2
] := True;
4055 if gFlash
= 2 then Inc(FPickup
, 5);
4056 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4059 ITEM_WEAPON_CHAINGUN
:
4060 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
4062 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
4064 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4065 FWeapon
[WEAPON_CHAINGUN
] := True;
4067 if gFlash
= 2 then Inc(FPickup
, 5);
4068 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4071 ITEM_WEAPON_ROCKETLAUNCHER
:
4072 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
4074 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
4076 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
4077 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
4079 if gFlash
= 2 then Inc(FPickup
, 5);
4080 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4084 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
4086 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
4088 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4089 FWeapon
[WEAPON_PLASMA
] := True;
4091 if gFlash
= 2 then Inc(FPickup
, 5);
4092 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4096 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
4098 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
4100 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4101 FWeapon
[WEAPON_BFG
] := True;
4103 if gFlash
= 2 then Inc(FPickup
, 5);
4104 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4107 ITEM_WEAPON_SUPERPULEMET
:
4108 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
4110 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
4112 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4113 FWeapon
[WEAPON_SUPERPULEMET
] := True;
4115 if gFlash
= 2 then Inc(FPickup
, 5);
4116 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4119 ITEM_WEAPON_FLAMETHROWER
:
4120 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
4122 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
4124 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4125 FWeapon
[WEAPON_FLAMETHROWER
] := True;
4127 if gFlash
= 2 then Inc(FPickup
, 5);
4128 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4132 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4134 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4137 if gFlash
= 2 then Inc(FPickup
, 5);
4140 ITEM_AMMO_BULLETS_BOX
:
4141 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4143 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4146 if gFlash
= 2 then Inc(FPickup
, 5);
4150 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4152 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4155 if gFlash
= 2 then Inc(FPickup
, 5);
4158 ITEM_AMMO_SHELLS_BOX
:
4159 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4161 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
4164 if gFlash
= 2 then Inc(FPickup
, 5);
4168 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4170 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4173 if gFlash
= 2 then Inc(FPickup
, 5);
4176 ITEM_AMMO_ROCKET_BOX
:
4177 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4179 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
4182 if gFlash
= 2 then Inc(FPickup
, 5);
4186 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4188 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4191 if gFlash
= 2 then Inc(FPickup
, 5);
4195 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4197 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4200 if gFlash
= 2 then Inc(FPickup
, 5);
4204 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4206 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4209 if gFlash
= 2 then Inc(FPickup
, 5);
4213 if not(R_ITEM_BACKPACK
in FRulez
) or
4214 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4215 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4216 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4217 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4218 (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) then
4220 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4221 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4222 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4223 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4224 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4226 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4227 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4228 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4229 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4230 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4231 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4232 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4233 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4234 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4235 IncMax(FAmmo
[A_FUEL
], 50, FMaxAmmo
[A_FUEL
]);
4237 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
4240 if gFlash
= 2 then Inc(FPickup
, 5);
4244 if not(R_KEY_RED
in FRulez
) then
4246 Include(FRulez
, R_KEY_RED
);
4248 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4249 if gFlash
= 2 then Inc(FPickup
, 5);
4250 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4254 if not(R_KEY_GREEN
in FRulez
) then
4256 Include(FRulez
, R_KEY_GREEN
);
4258 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4259 if gFlash
= 2 then Inc(FPickup
, 5);
4260 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4264 if not(R_KEY_BLUE
in FRulez
) then
4266 Include(FRulez
, R_KEY_BLUE
);
4268 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4269 if gFlash
= 2 then Inc(FPickup
, 5);
4270 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4274 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4276 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4280 if gFlash
= 2 then Inc(FPickup
, 5);
4284 if FAir
< AIR_MAX
then
4289 if gFlash
= 2 then Inc(FPickup
, 5);
4294 if not (R_BERSERK
in FRulez
) then
4296 Include(FRulez
, R_BERSERK
);
4297 if allowBerserkSwitching
then
4299 FCurrWeap
:= WEAPON_KASTET
;
4301 FModel
.SetWeapon(WEAPON_KASTET
);
4306 if gFlash
= 2 then Inc(FPickup
, 5);
4308 FBerserk
:= gTime
+30000;
4313 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
4315 if FHealth
< PLAYER_HP_SOFT
then FHealth
:= PLAYER_HP_SOFT
;
4316 FBerserk
:= gTime
+30000;
4324 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4326 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4330 if gFlash
= 2 then Inc(FPickup
, 5);
4334 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
4336 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4340 if gFlash
= 2 then Inc(FPickup
, 5);
4344 if FArmor
< PLAYER_AP_LIMIT
then
4346 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4349 if gFlash
= 2 then Inc(FPickup
, 5);
4353 if FJetFuel
< JET_MAX
then
4355 FJetFuel
:= JET_MAX
;
4358 if gFlash
= 2 then Inc(FPickup
, 5);
4362 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4364 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4367 if gFlash
= 2 then Inc(FPickup
, 5);
4372 procedure TPlayer
.Touch();
4376 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4379 // Áðîñèòü ôëàã òîâàðèùó:
4380 if gGameSettings
.GameMode
= GM_CTF
then
4385 procedure TPlayer
.Push(vx
, vy
: Integer);
4387 if (not FPhysics
) and FGhost
then
4389 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4390 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4391 if g_Game_IsNet
and g_Game_IsServer
then
4392 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4395 procedure TPlayer
.Reset(Force
: Boolean);
4401 FTime
[T_RESPAWN
] := 0;
4402 FTime
[T_FLAGCAP
] := 0;
4417 FSpectator
:= False;
4420 FSpectatePlayer
:= -1;
4421 FNoRespawn
:= False;
4423 FLives
:= gGameSettings
.MaxLives
;
4428 procedure TPlayer
.SoftReset();
4436 FBFGFireCounter
:= -1;
4444 SetAction(A_STAND
, True);
4447 function TPlayer
.GetRespawnPoint(): Byte;
4452 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4454 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4455 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4457 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4459 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4460 if Self
= gPlayer1
then
4461 c
:= RESPAWNPOINT_PLAYER1
4463 c
:= RESPAWNPOINT_PLAYER2
;
4464 if g_Map_GetPointCount(c
) > 0 then
4470 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4471 if Self
= gPlayer1
then
4472 c
:= RESPAWNPOINT_PLAYER2
4474 c
:= RESPAWNPOINT_PLAYER1
;
4475 if g_Map_GetPointCount(c
) > 0 then
4482 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4483 if Random(2) = 0 then
4484 c
:= RESPAWNPOINT_PLAYER1
4486 c
:= RESPAWNPOINT_PLAYER2
;
4487 if g_Map_GetPointCount(c
) > 0 then
4494 // Òî÷êà ëþáîé èç êîìàíä
4495 if Random(2) = 0 then
4496 c
:= RESPAWNPOINT_RED
4498 c
:= RESPAWNPOINT_BLUE
;
4499 if g_Map_GetPointCount(c
) > 0 then
4506 c
:= RESPAWNPOINT_DM
;
4507 if g_Map_GetPointCount(c
) > 0 then
4515 if gGameSettings
.GameMode
= GM_DM
then
4518 c
:= RESPAWNPOINT_DM
;
4519 if g_Map_GetPointCount(c
) > 0 then
4525 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4526 if Random(2) = 0 then
4527 c
:= RESPAWNPOINT_PLAYER1
4529 c
:= RESPAWNPOINT_PLAYER2
;
4530 if g_Map_GetPointCount(c
) > 0 then
4536 // Òî÷êà ëþáîé èç êîìàíä
4537 if Random(2) = 0 then
4538 c
:= RESPAWNPOINT_RED
4540 c
:= RESPAWNPOINT_BLUE
;
4541 if g_Map_GetPointCount(c
) > 0 then
4549 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4551 // Òî÷êà ñâîåé êîìàíäû
4552 c
:= RESPAWNPOINT_DM
;
4553 if FTeam
= TEAM_RED
then
4554 c
:= RESPAWNPOINT_RED
;
4555 if FTeam
= TEAM_BLUE
then
4556 c
:= RESPAWNPOINT_BLUE
;
4557 if g_Map_GetPointCount(c
) > 0 then
4564 c
:= RESPAWNPOINT_DM
;
4565 if g_Map_GetPointCount(c
) > 0 then
4571 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4572 if Random(2) = 0 then
4573 c
:= RESPAWNPOINT_PLAYER1
4575 c
:= RESPAWNPOINT_PLAYER2
;
4576 if g_Map_GetPointCount(c
) > 0 then
4582 // Òî÷êà äðóãîé êîìàíäû
4583 c
:= RESPAWNPOINT_DM
;
4584 if FTeam
= TEAM_RED
then
4585 c
:= RESPAWNPOINT_BLUE
;
4586 if FTeam
= TEAM_BLUE
then
4587 c
:= RESPAWNPOINT_RED
;
4588 if g_Map_GetPointCount(c
) > 0 then
4596 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4598 RespawnPoint
: TRespawnPoint
;
4606 FBFGFireCounter
:= -1;
4612 if not g_Game_IsServer
then
4616 FWantsInGame
:= True;
4617 FJustTeleported
:= True;
4620 FTime
[T_RESPAWN
] := 0;
4624 // if server changes MaxLives we gotta be ready
4625 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4627 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4628 if FTime
[T_RESPAWN
] > gTime
then
4631 // Ïðîñðàë âñå æèçíè:
4634 if not FSpectator
then Spectate(True);
4635 FWantsInGame
:= True;
4639 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4640 begin // "Ñâîÿ èãðà"
4641 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4642 FRulez
:= FRulez
-[R_BERSERK
];
4644 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4646 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4647 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4650 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4651 c
:= GetRespawnPoint();
4656 // Âîñêðåøåíèå áåç îðóæèÿ:
4659 FHealth
:= Round(PLAYER_HP_SOFT
* (FHandicap
/ 100));
4665 for a
:= WP_FIRST
to WP_LAST
do
4667 FWeapon
[a
] := False;
4671 FWeapon
[WEAPON_PISTOL
] := True;
4672 FWeapon
[WEAPON_KASTET
] := True;
4673 FCurrWeap
:= WEAPON_PISTOL
;
4676 FModel
.SetWeapon(FCurrWeap
);
4678 for b
:= A_BULLETS
to A_HIGH
do
4681 FAmmo
[A_BULLETS
] := 50;
4683 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4684 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4685 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4686 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4687 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4689 if (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) and
4690 LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
) then
4691 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4696 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4697 if not g_Map_GetPoint(c
, RespawnPoint
) then
4699 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4703 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4704 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4705 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4706 FObj
.oldX
:= FObj
.X
; // don't interpolate after respawn
4707 FObj
.oldY
:= FObj
.Y
;
4713 FDirection
:= RespawnPoint
.Direction
;
4714 if FDirection
= TDirection
.D_LEFT
then
4719 SetAction(A_STAND
, True);
4720 FModel
.Direction
:= FDirection
;
4722 for a
:= Low(FTime
) to High(FTime
) do
4725 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4728 // Respawn invulnerability
4729 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.SpawnInvul
> 0) then
4731 FMegaRulez
[MR_INVUL
] := gTime
+ gGameSettings
.SpawnInvul
* 1000;
4732 FSpawnInvul
:= FMegaRulez
[MR_INVUL
];
4737 FCanJetpack
:= False;
4743 // Àíèìàöèÿ âîçðîæäåíèÿ:
4744 if (not gLoadGameMode
) and (not Silent
) then
4745 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4747 Anim
:= TAnimation
.Create(ID
, False, 3);
4748 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4749 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4753 FSpectator
:= False;
4756 FSpectatePlayer
:= -1;
4759 if (gPlayer1
= nil) and (gSpectLatchPID1
= FUID
) then
4761 if (gPlayer2
= nil) and (gSpectLatchPID2
= FUID
) then
4764 if g_Game_IsNet
then
4766 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4767 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4769 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4770 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4775 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4778 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4779 else if (not NoMove
) then
4781 GameX
:= gMapInfo
.Width
div 2;
4782 GameY
:= gMapInfo
.Height
div 2;
4789 FWantsInGame
:= False;
4794 if Self
= gPlayer1
then
4796 gSpectLatchPID1
:= FUID
;
4799 else if Self
= gPlayer2
then
4801 gSpectLatchPID2
:= FUID
;
4806 if g_Game_IsNet
then
4807 MH_SEND_PlayerStats(FUID
);
4810 procedure TPlayer
.SwitchNoClip
;
4814 FGhost
:= not FGhost
;
4815 FPhysics
:= not FGhost
;
4823 procedure TPlayer
.Run(Direction
: TDirection
);
4827 if MAX_RUNVEL
> 8 then
4831 if Direction
= TDirection
.D_LEFT
then
4833 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4834 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4837 if FObj
.Vel
.X
< MAX_RUNVEL
then
4838 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4840 // Âîçìîæíî, ïèíàåì êóñêè:
4841 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4843 b
:= Abs(FObj
.Vel
.X
);
4844 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4845 for a
:= 0 to High(gGibs
) do
4847 if gGibs
[a
].alive
and
4848 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4849 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4852 if FObj
.Vel
.X
< 0 then
4854 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4858 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4860 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4868 procedure TPlayer
.SeeDown();
4870 SetAction(A_SEEDOWN
);
4872 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4874 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4877 procedure TPlayer
.SeeUp();
4881 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4883 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4886 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4894 A_ATTACK
: Prior
:= 2;
4895 A_SEEUP
: Prior
:= 1;
4896 A_SEEDOWN
: Prior
:= 1;
4897 A_ATTACKUP
: Prior
:= 2;
4898 A_ATTACKDOWN
: Prior
:= 2;
4903 if (Prior
> FActionPrior
) or Force
then
4904 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4906 FActionPrior
:= Prior
;
4907 FActionAnim
:= Action
;
4908 FActionForce
:= Force
;
4909 FActionChanged
:= True;
4912 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4915 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4917 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4918 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4919 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4920 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4923 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4930 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4932 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4933 if g_Game_IsServer
and g_Game_IsNet
then
4934 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4938 FJustTeleported
:= True;
4943 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4945 Anim
:= TAnimation
.Create(ID
, False, 3);
4948 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4949 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4950 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4951 if g_Game_IsServer
and g_Game_IsNet
then
4952 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4953 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4957 FObj
.X
:= X
-PLAYER_RECT
.X
;
4958 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4959 FObj
.oldX
:= FObj
.X
; // don't interpolate after respawn
4960 FObj
.oldY
:= FObj
.Y
;
4962 if not g_Game_IsNet
then
4966 SetDirection(TDirection
.D_LEFT
);
4972 SetDirection(TDirection
.D_RIGHT
);
4978 if FDirection
= TDirection
.D_RIGHT
then
4980 SetDirection(TDirection
.D_LEFT
);
4985 SetDirection(TDirection
.D_RIGHT
);
4991 if not silent
and (Anim
<> nil) then
4993 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4994 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4997 if g_Game_IsServer
and g_Game_IsNet
then
4998 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4999 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
5006 function nonz(a
: Single): Single;
5014 function TPlayer
.followCorpse(): Boolean;
5019 if FAlive
or FSpectator
then
5021 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
5023 for i
:= 0 to High(gCorpses
) do
5024 if gCorpses
[i
] <> nil then
5025 if gCorpses
[i
].FPlayerUID
= FUID
then
5028 FObj
.X
:= gCorpses
[i
].FObj
.X
;
5029 FObj
.Y
:= gCorpses
[i
].FObj
.Y
;
5030 FObj
.Vel
.X
:= gCorpses
[i
].FObj
.Vel
.X
;
5031 FObj
.Vel
.Y
:= gCorpses
[i
].FObj
.Vel
.Y
;
5032 FObj
.Accel
.X
:= gCorpses
[i
].FObj
.Accel
.X
;
5033 FObj
.Accel
.Y
:= gCorpses
[i
].FObj
.Accel
.Y
;
5038 procedure TPlayer
.PreUpdate();
5040 FSlopeOld
:= FObj
.slopeUpLeft
;
5041 FIncCamOld
:= FIncCam
;
5042 FObj
.oldX
:= FObj
.X
;
5043 FObj
.oldY
:= FObj
.Y
;
5046 procedure TPlayer
.Update();
5049 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
5050 blockmon
, headwater
, dospawn
: Boolean;
5055 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
5056 AnyServer
:= g_Game_IsServer
;
5059 if FClientID
>= 0 then
5061 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
5062 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
5063 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
5072 if FAlive
and (FPunchAnim
<> nil) then
5073 FPunchAnim
.Update();
5075 if FAlive
and (gFly
or FJetpack
) then
5078 if FDirection
= TDirection
.D_LEFT
then
5083 if FAlive
and (not FGhost
) then
5085 if FKeys
[KEY_UP
].Pressed
then
5087 if FKeys
[KEY_DOWN
].Pressed
then
5091 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
5094 i
:= g_basic
.Sign(FIncCam
);
5095 FIncCam
:= Abs(FIncCam
);
5096 DecMin(FIncCam
, 5, 0);
5097 FIncCam
:= FIncCam
*i
;
5100 // no need to do that each second frame, weapon queue will take care of it
5101 if FAlive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
5102 if FAlive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
5104 if gTime
mod (GAME_TICK
*2) <> 0 then
5106 if (FObj
.Vel
.X
= 0) and FAlive
then
5108 if FKeys
[KEY_LEFT
].Pressed
then
5109 Run(TDirection
.D_LEFT
);
5110 if FKeys
[KEY_RIGHT
].Pressed
then
5111 Run(TDirection
.D_RIGHT
);
5116 if not followCorpse() then
5117 g_Obj_Move(@FObj
, True, True, True);
5118 positionChanged(); // this updates spatial accelerators
5124 FActionChanged
:= False;
5128 // Let alive player do some actions
5129 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
5130 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
5131 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
5132 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
5133 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire()
5139 if NetServer
then MH_SEND_PlayerStats(FUID
);
5142 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
5143 if FKeys
[KEY_JUMP
].Pressed
then Jump()
5146 if AnyServer
and FJetpack
then
5150 if NetServer
then MH_SEND_PlayerStats(FUID
);
5152 FCanJetpack
:= True;
5159 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
5161 if FKeys
[k
].Pressed
then
5169 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5172 if (FTime
[T_RESPAWN
] <= gTime
) and
5173 gGameOn
and (not FAlive
) then
5175 if (g_Player_GetCount() > 1) then
5179 gExit
:= EXIT_RESTART
;
5184 // Dead spectator actions
5187 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
5188 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
5192 if (FSpectatePlayer
>= High(gPlayers
)) then
5193 FSpectatePlayer
:= -1
5197 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
5198 if gPlayers
[I
] <> nil then
5199 if gPlayers
[I
].alive
then
5200 if gPlayers
[I
].UID
<> FUID
then
5202 FSpectatePlayer
:= I
;
5207 if not SetSpect
then FSpectatePlayer
:= -1;
5218 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5220 FObj
.Y
:= FObj
.Y
- 32;
5221 FSpectatePlayer
:= -1;
5223 if FKeys
[KEY_DOWN
].Pressed
then
5225 FObj
.Y
:= FObj
.Y
+ 32;
5226 FSpectatePlayer
:= -1;
5228 if FKeys
[KEY_LEFT
].Pressed
then
5230 FObj
.X
:= FObj
.X
- 32;
5231 FSpectatePlayer
:= -1;
5233 if FKeys
[KEY_RIGHT
].Pressed
then
5235 FObj
.X
:= FObj
.X
+ 32;
5236 FSpectatePlayer
:= -1;
5239 if (FObj
.X
< -64) then
5241 else if (FObj
.X
> gMapInfo
.Width
+ 32) then
5242 FObj
.X
:= gMapInfo
.Width
+ 32;
5243 if (FObj
.Y
< -72) then
5245 else if (FObj
.Y
> gMapInfo
.Height
+ 32) then
5246 FObj
.Y
:= gMapInfo
.Height
+ 32;
5251 if not followCorpse() then
5252 g_Obj_Move(@FObj
, True, True, True);
5253 positionChanged(); // this updates spatial accelerators
5260 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5261 if gPlayers
[FSpectatePlayer
] <> nil then
5262 if gPlayers
[FSpectatePlayer
].alive
then
5264 FObj
.X
:= gPlayers
[FSpectatePlayer
].GameX
;
5265 FObj
.Y
:= gPlayers
[FSpectatePlayer
].GameY
;
5269 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5270 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5271 PANEL_BLOCKMON
, True);
5272 headwater
:= HeadInLiquid(0, 0);
5274 // Ñîïðîòèâëåíèå âîçäóõà:
5275 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5276 if FObj
.Vel
.X
<> 0 then
5277 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5279 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5280 DecMin(FPain
, 5, 0);
5281 DecMin(FPickup
, 1, 0);
5283 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5285 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5286 FMegaRulez
[MR_SUIT
] := 0;
5287 FMegaRulez
[MR_INVUL
] := 0;
5288 FMegaRulez
[MR_INVIS
] := 0;
5289 Kill(K_FALLKILL
, 0, HIT_FALL
);
5296 if FCurrWeap
= WEAPON_SAW
then
5297 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5298 FSawSoundSelect
.IsPlaying()) then
5299 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5302 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5303 (not FJetSoundOff
.IsPlaying()) then
5305 FJetSoundFly
.SetPosition(0);
5306 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5309 for b
:= WP_FIRST
to WP_LAST
do
5310 if FReloading
[b
] > 0 then
5316 if FShellTimer
> -1 then
5317 if FShellTimer
= 0 then
5319 if FShellType
= SHELL_SHELL
then
5320 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5321 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5322 else if FShellType
= SHELL_DBLSHELL
then
5324 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5325 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5326 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5327 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5330 end else Dec(FShellTimer
);
5332 if (FBFGFireCounter
> -1) then
5333 if FBFGFireCounter
= 0 then
5337 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5338 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5339 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5340 yd
:= wy
+firediry();
5341 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5342 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5343 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5344 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5345 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5348 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5349 FBFGFireCounter
:= -1;
5352 FBFGFireCounter
:= 0
5354 Dec(FBFGFireCounter
);
5356 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5358 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5360 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5363 if (headwater
or blockmon
) then
5369 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5372 else if (FAir
mod 31 = 0) and not blockmon
then
5374 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5375 if Random(2) = 0 then
5376 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5378 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5380 end else if FAir
< AIR_DEF
then
5383 if FFireTime
> 0 then
5385 if BodyInLiquid(0, 0) then
5390 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5392 if FMegaRulez
[MR_SUIT
] = gTime
then
5399 if FFirePainTime
<= 0 then
5401 if g_Game_IsServer
then
5402 Damage(2, FFireAttacker
, 0, 0, HIT_FLAME
);
5403 FFirePainTime
:= 12 - FFireTime
div 12;
5405 FFirePainTime
:= FFirePainTime
- 1;
5406 FFireTime
:= FFireTime
- 1;
5407 if ((FFireTime
mod 33) = 0) and (FMegaRulez
[MR_INVUL
] < gTime
) then
5408 FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
);
5409 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5410 MH_SEND_PlayerStats(FUID
);
5414 if FDamageBuffer
> 0 then
5416 if FDamageBuffer
>= 9 then
5420 if FDamageBuffer
< 30 then i
:= 9
5421 else if FDamageBuffer
< 100 then i
:= 18
5425 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5426 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5427 FHealth
:= FHealth
-ii
;
5430 FHealth
:= FHealth
+FArmor
;
5435 if FHealth
<= 0 then
5436 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5437 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5438 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5440 if FAlive
and ((FLastHit
<> HIT_FLAME
) or (FFireTime
<= 0)) then
5442 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5443 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5444 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5445 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5452 end; // if FAlive then ...
5454 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5456 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5457 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5458 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5459 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5461 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5462 then SetAction(A_STAND
, True);
5464 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5466 for b
:= Low(FKeys
) to High(FKeys
) do
5467 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5471 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5473 x
:= FObj
.X
+PLAYER_RECT
.X
;
5474 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5475 w
:= PLAYER_RECT
.Width
;
5476 h
:= PLAYER_RECT
.Height
;
5480 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5482 if (dx
<> 0) or (dy
<> 0) then
5491 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5493 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5494 FObj
.Y
+PLAYER_RECT
.Y
,
5501 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5503 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5504 FObj
.Y
+PLAYER_RECT
.Y
,
5508 Panel
.Width
, Panel
.Height
);
5511 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5513 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5514 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5515 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5516 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5519 function g_Player_ValidName(Name
: string): Boolean;
5525 if gPlayers
= nil then Exit
;
5527 for a
:= 0 to High(gPlayers
) do
5528 if gPlayers
[a
] <> nil then
5529 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5536 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5540 d
:= FModel
.Direction
;
5542 FModel
.Direction
:= Direction
;
5543 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5545 FDirection
:= Direction
;
5548 function TPlayer
.GetKeys(): Byte;
5552 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5553 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5554 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5556 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5557 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5560 procedure TPlayer
.Use();
5564 if FTime
[T_USE
] > gTime
then Exit
;
5566 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5567 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5569 for a
:= 0 to High(gPlayers
) do
5570 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5571 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5572 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5573 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5575 gPlayers
[a
].Touch();
5576 if g_Game_IsNet
and g_Game_IsServer
then
5577 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5580 FTime
[T_USE
] := gTime
+120;
5583 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5587 WX
, WY
, XD
, YD
: Integer;
5599 if R_BERSERK
in FRulez
then
5601 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5602 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5603 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5606 locobj
.rect
.Width
:= 39;
5607 locobj
.rect
.Height
:= 52;
5608 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5609 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5610 locobj
.Accel
.X
:= xd
-wx
;
5611 locobj
.Accel
.y
:= yd
-wy
;
5613 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5614 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5616 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5620 FPain
:= min(FPain
+ 25, 50);
5622 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5627 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5628 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5630 FSawSoundSelect
.Stop();
5632 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5634 else if not FSawSoundHit
.IsPlaying() then
5636 FSawSoundSelect
.Stop();
5637 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5644 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5645 FFireAngle
:= FAngle
;
5647 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5648 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5653 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5654 FFireAngle
:= FAngle
;
5657 FShellType
:= SHELL_SHELL
;
5662 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5663 FFireAngle
:= FAngle
;
5666 FShellType
:= SHELL_DBLSHELL
;
5671 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5672 FFireAngle
:= FAngle
;
5674 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5675 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5678 WEAPON_ROCKETLAUNCHER
:
5680 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5681 FFireAngle
:= FAngle
;
5687 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5688 FFireAngle
:= FAngle
;
5694 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5695 FFireAngle
:= FAngle
;
5699 WEAPON_SUPERPULEMET
:
5701 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5702 FFireAngle
:= FAngle
;
5704 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5705 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5708 WEAPON_FLAMETHROWER
:
5710 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5712 FFireAngle
:= FAngle
;
5719 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5720 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5721 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5724 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
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_LIFTUP
, False) then Result
:= -1
5730 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5731 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5732 PANEL_LIFTDOWN
, False) then Result
:= 1
5736 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5743 if Flag
= FLAG_NONE
then
5746 if not g_Game_IsServer
then Exit
;
5748 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5749 if (Flag
= FTeam
) and
5750 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5751 (FFlag
<> FLAG_NONE
) then
5753 if FFlag
= FLAG_RED
then
5754 s
:= _lc
[I_PLAYER_FLAG_RED
]
5756 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5758 evtype
:= FLAG_STATE_SCORED
;
5760 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5761 Insert('.', ts
, Length(ts
) + 1 - 3);
5762 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5764 g_Map_ResetFlag(FFlag
);
5765 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5767 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5768 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5769 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5774 if not sound_cap_flag
[a
].IsPlaying() then
5775 sound_cap_flag
[a
].Play();
5777 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5780 if g_Game_IsNet
then
5782 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5786 gFlags
[FFlag
].CaptureTime
:= 0;
5791 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5792 if (Flag
= FTeam
) and
5793 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5795 if Flag
= FLAG_RED
then
5796 s
:= _lc
[I_PLAYER_FLAG_RED
]
5798 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5800 evtype
:= FLAG_STATE_RETURNED
;
5801 gFlags
[Flag
].CaptureTime
:= 0;
5803 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5805 g_Map_ResetFlag(Flag
);
5806 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5808 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5809 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5810 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5815 if not sound_ret_flag
[a
].IsPlaying() then
5816 sound_ret_flag
[a
].Play();
5819 if g_Game_IsNet
then
5821 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5827 // Ïîäîáðàë ÷óæîé ôëàã:
5828 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5832 if Flag
= FLAG_RED
then
5833 s
:= _lc
[I_PLAYER_FLAG_RED
]
5835 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5837 evtype
:= FLAG_STATE_CAPTURED
;
5839 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5841 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5843 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5845 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5846 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5847 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5852 if not sound_get_flag
[a
].IsPlaying() then
5853 sound_get_flag
[a
].Play();
5856 if g_Game_IsNet
then
5858 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5864 procedure TPlayer
.SetFlag(Flag
: Byte);
5867 if FModel
<> nil then
5868 FModel
.SetFlag(FFlag
);
5871 function TPlayer
.DropFlag(Silent
: Boolean = True): Boolean;
5877 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5879 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5880 with gFlags
[FFlag
] do
5884 Direction
:= FDirection
;
5885 State
:= FLAG_STATE_DROPPED
;
5887 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5888 (FObj
.Vel
.Y
div 2)-2+Random(5));
5889 positionChanged(); // this updates spatial accelerators
5891 if FFlag
= FLAG_RED
then
5892 s
:= _lc
[I_PLAYER_FLAG_RED
]
5894 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5896 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5897 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5899 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5900 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5901 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5906 if (not Silent
) and (not sound_lost_flag
[a
].IsPlaying()) then
5907 sound_lost_flag
[a
].Play();
5909 if g_Game_IsNet
then
5910 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5916 procedure TPlayer
.GetSecret();
5918 if (self
= gPlayer1
) or (self
= gPlayer2
) then
5920 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [FName
]), True);
5921 g_Sound_PlayEx('SOUND_GAME_SECRET');
5926 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5928 Assert(Key
<= High(FKeys
));
5930 FKeys
[Key
].Pressed
:= True;
5931 FKeys
[Key
].Time
:= Time
;
5934 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5936 Result
:= FKeys
[K
].Pressed
;
5939 procedure TPlayer
.ReleaseKeys();
5943 for a
:= Low(FKeys
) to High(FKeys
) do
5945 FKeys
[a
].Pressed
:= False;
5950 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5954 function TPlayer
.firediry(): Integer;
5956 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5957 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5961 procedure TPlayer
.RememberState();
5964 SavedState
: TPlayerSavedState
;
5966 SavedState
.Health
:= FHealth
;
5967 SavedState
.Armor
:= FArmor
;
5968 SavedState
.Air
:= FAir
;
5969 SavedState
.JetFuel
:= FJetFuel
;
5970 SavedState
.CurrWeap
:= FCurrWeap
;
5971 SavedState
.NextWeap
:= FNextWeap
;
5972 SavedState
.NextWeapDelay
:= FNextWeapDelay
;
5973 for i
:= Low(FWeapon
) to High(FWeapon
) do
5974 SavedState
.Weapon
[i
] := FWeapon
[i
];
5975 for i
:= Low(FAmmo
) to High(FAmmo
) do
5976 SavedState
.Ammo
[i
] := FAmmo
[i
];
5977 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
5978 SavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5979 SavedState
.Rulez
:= FRulez
- [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5981 FSavedStateNum
:= -1;
5982 for i
:= Low(SavedStates
) to High(SavedStates
) do
5983 if not SavedStates
[i
].Used
then
5985 FSavedStateNum
:= i
;
5988 if FSavedStateNum
< 0 then
5990 SetLength(SavedStates
, Length(SavedStates
) + 1);
5991 FSavedStateNum
:= High(SavedStates
);
5994 SavedState
.Used
:= True;
5995 SavedStates
[FSavedStateNum
] := SavedState
;
5998 procedure TPlayer
.RecallState();
6001 SavedState
: TPlayerSavedState
;
6003 if(FSavedStateNum
< 0) or (FSavedStateNum
> High(SavedStates
)) then
6006 SavedState
:= SavedStates
[FSavedStateNum
];
6007 SavedStates
[FSavedStateNum
].Used
:= False;
6008 FSavedStateNum
:= -1;
6010 FHealth
:= SavedState
.Health
;
6011 FArmor
:= SavedState
.Armor
;
6012 FAir
:= SavedState
.Air
;
6013 FJetFuel
:= SavedState
.JetFuel
;
6014 FCurrWeap
:= SavedState
.CurrWeap
;
6015 FNextWeap
:= SavedState
.NextWeap
;
6016 FNextWeapDelay
:= SavedState
.NextWeapDelay
;
6017 for i
:= Low(FWeapon
) to High(FWeapon
) do
6018 FWeapon
[i
] := SavedState
.Weapon
[i
];
6019 for i
:= Low(FAmmo
) to High(FAmmo
) do
6020 FAmmo
[i
] := SavedState
.Ammo
[i
];
6021 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
6022 FMaxAmmo
[i
] := SavedState
.MaxAmmo
[i
];
6023 FRulez
:= SavedState
.Rulez
;
6025 if gGameSettings
.GameType
= GT_SERVER
then
6026 MH_SEND_PlayerStats(FUID
);
6029 procedure TPlayer
.SaveState (st
: TStream
);
6035 utils
.writeSign(st
, 'PLYR');
6036 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
6038 utils
.writeBool(st
, FIamBot
);
6040 utils
.writeInt(st
, Word(FUID
));
6042 utils
.writeStr(st
, FName
);
6044 utils
.writeInt(st
, Byte(FTeam
));
6046 utils
.writeBool(st
, FAlive
);
6047 // Èçðàñõîäîâàë ëè âñå æèçíè
6048 utils
.writeBool(st
, FNoRespawn
);
6050 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
6051 utils
.writeInt(st
, Byte(b
));
6053 utils
.writeInt(st
, LongInt(FHealth
));
6054 // Êîýôôèöèåíò èíâàëèäíîñòè
6055 utils
.writeInt(st
, LongInt(FHandicap
));
6057 utils
.writeInt(st
, Byte(FLives
));
6059 utils
.writeInt(st
, LongInt(FArmor
));
6061 utils
.writeInt(st
, LongInt(FAir
));
6063 utils
.writeInt(st
, LongInt(FJetFuel
));
6065 utils
.writeInt(st
, LongInt(FPain
));
6067 utils
.writeInt(st
, LongInt(FKills
));
6069 utils
.writeInt(st
, LongInt(FMonsterKills
));
6071 utils
.writeInt(st
, LongInt(FFrags
));
6073 utils
.writeInt(st
, Byte(FFragCombo
));
6074 // Âðåìÿ ïîñëåäíåãî ôðàãà
6075 utils
.writeInt(st
, LongWord(FLastFrag
));
6077 utils
.writeInt(st
, LongInt(FDeath
));
6079 utils
.writeInt(st
, Byte(FFlag
));
6081 utils
.writeInt(st
, LongInt(FSecrets
));
6083 utils
.writeInt(st
, Byte(FCurrWeap
));
6085 utils
.writeInt(st
, Word(FNextWeap
));
6087 utils
.writeInt(st
, Byte(FNextWeapDelay
));
6088 // Âðåìÿ çàðÿäêè BFG
6089 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
6091 utils
.writeInt(st
, LongInt(FDamageBuffer
));
6092 // Ïîñëåäíèé óäàðèâøèé
6093 utils
.writeInt(st
, Word(FLastSpawnerUID
));
6094 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6095 utils
.writeInt(st
, Byte(FLastHit
));
6097 Obj_SaveState(st
, @FObj
);
6098 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6099 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
6100 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6101 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
6103 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
6104 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6105 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
6107 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
6108 // Íàëè÷èå êðàñíîãî êëþ÷à
6109 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
6110 // Íàëè÷èå çåëåíîãî êëþ÷à
6111 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
6112 // Íàëè÷èå ñèíåãî êëþ÷à
6113 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
6115 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
6116 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6117 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
6118 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6119 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
6121 utils
.writeStr(st
, FModel
.Name
);
6123 utils
.writeInt(st
, Byte(FColor
.R
));
6124 utils
.writeInt(st
, Byte(FColor
.G
));
6125 utils
.writeInt(st
, Byte(FColor
.B
));
6129 procedure TPlayer
.LoadState (st
: TStream
);
6138 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
6139 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
6141 FIamBot
:= utils
.readBool(st
);
6143 FUID
:= utils
.readWord(st
);
6145 str
:= utils
.readStr(st
);
6146 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
6148 FTeam
:= utils
.readByte(st
);
6150 FAlive
:= utils
.readBool(st
);
6151 // Èçðàñõîäîâàë ëè âñå æèçíè
6152 FNoRespawn
:= utils
.readBool(st
);
6154 b
:= utils
.readByte(st
);
6155 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
6157 FHealth
:= utils
.readLongInt(st
);
6158 // Êîýôôèöèåíò èíâàëèäíîñòè
6159 FHandicap
:= utils
.readLongInt(st
);
6161 FLives
:= utils
.readByte(st
);
6163 FArmor
:= utils
.readLongInt(st
);
6165 FAir
:= utils
.readLongInt(st
);
6167 FJetFuel
:= utils
.readLongInt(st
);
6169 FPain
:= utils
.readLongInt(st
);
6171 FKills
:= utils
.readLongInt(st
);
6173 FMonsterKills
:= utils
.readLongInt(st
);
6175 FFrags
:= utils
.readLongInt(st
);
6177 FFragCombo
:= utils
.readByte(st
);
6178 // Âðåìÿ ïîñëåäíåãî ôðàãà
6179 FLastFrag
:= utils
.readLongWord(st
);
6181 FDeath
:= utils
.readLongInt(st
);
6183 FFlag
:= utils
.readByte(st
);
6185 FSecrets
:= utils
.readLongInt(st
);
6187 FCurrWeap
:= utils
.readByte(st
);
6189 FNextWeap
:= utils
.readWord(st
);
6191 FNextWeapDelay
:= utils
.readByte(st
);
6192 // Âðåìÿ çàðÿäêè BFG
6193 FBFGFireCounter
:= utils
.readSmallInt(st
);
6195 FDamageBuffer
:= utils
.readLongInt(st
);
6196 // Ïîñëåäíèé óäàðèâøèé
6197 FLastSpawnerUID
:= utils
.readWord(st
);
6198 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6199 FLastHit
:= utils
.readByte(st
);
6201 Obj_LoadState(@FObj
, st
);
6202 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6203 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
6204 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6205 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
6207 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
6208 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6209 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
6211 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
6212 // Íàëè÷èå êðàñíîãî êëþ÷à
6213 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
6214 // Íàëè÷èå çåëåíîãî êëþ÷à
6215 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
6216 // Íàëè÷èå ñèíåãî êëþ÷à
6217 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
6219 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
6220 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6221 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
6222 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6223 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
6225 str
:= utils
.readStr(st
);
6227 FColor
.R
:= utils
.readByte(st
);
6228 FColor
.G
:= utils
.readByte(st
);
6229 FColor
.B
:= utils
.readByte(st
);
6230 if (self
= gPlayer1
) then
6232 str
:= gPlayer1Settings
.Model
;
6233 FColor
:= gPlayer1Settings
.Color
;
6235 else if (self
= gPlayer2
) then
6237 str
:= gPlayer2Settings
.Model
;
6238 FColor
:= gPlayer2Settings
.Color
;
6240 // Îáíîâëÿåì ìîäåëü èãðîêà
6242 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
6243 FModel
.Color
:= TEAMCOLOR
[FTeam
]
6245 FModel
.Color
:= FColor
;
6249 procedure TPlayer
.AllRulez(Health
: Boolean);
6255 FHealth
:= PLAYER_HP_LIMIT
;
6256 FArmor
:= PLAYER_AP_LIMIT
;
6260 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
6261 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
6262 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6265 procedure TPlayer
.RestoreHealthArmor();
6267 FHealth
:= PLAYER_HP_LIMIT
;
6268 FArmor
:= PLAYER_AP_LIMIT
;
6271 procedure TPlayer
.FragCombo();
6275 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6277 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6279 if FFragCombo
< 5 then
6281 Param
:= FUID
or (FFragCombo
shl 16);
6282 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6283 (FComboEvnt
<= High(gDelayedEvents
)) and
6284 gDelayedEvents
[FComboEvnt
].Pending
and
6285 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6286 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6288 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6289 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6292 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6300 procedure TPlayer
.GiveItem(ItemType
: Byte);
6304 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6306 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6310 if FAir
< AIR_MAX
then
6317 if not (R_BERSERK
in FRulez
) then
6319 Include(FRulez
, R_BERSERK
);
6320 if FBFGFireCounter
< 1 then
6322 FCurrWeap
:= WEAPON_KASTET
;
6324 FModel
.SetWeapon(WEAPON_KASTET
);
6328 FBerserk
:= gTime
+30000;
6330 if FHealth
< PLAYER_HP_SOFT
then
6332 FHealth
:= PLAYER_HP_SOFT
;
6333 FBerserk
:= gTime
+30000;
6338 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6340 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6345 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6347 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6351 if FJetFuel
< JET_MAX
then
6353 FJetFuel
:= JET_MAX
;
6356 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6357 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6359 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6360 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6362 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6364 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6366 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6367 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6370 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6371 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6372 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6373 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6374 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6375 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6376 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6377 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6378 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6380 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6381 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6382 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6383 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6384 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6385 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6386 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6387 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6388 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6391 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6392 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6393 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6394 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6395 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6397 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6398 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6399 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6400 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6401 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6403 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6404 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6405 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6406 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6408 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6411 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6412 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6413 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6415 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6416 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6421 if g_Game_IsNet
and g_Game_IsServer
then
6422 MH_SEND_PlayerStats(FUID
);
6425 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6430 if (Random(5) = 1) and (Times
= 1) then
6433 if BodyInLiquid(0, 0) then
6435 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6436 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6437 if Random(2) = 0 then
6438 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6440 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6444 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6446 for i
:= 1 to Times
do
6448 Anim
:= TAnimation
.Create(id
, False, 3);
6450 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6451 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6457 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6462 if (Random(10) = 1) and (Times
= 1) then
6465 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6467 for i
:= 1 to Times
do
6469 Anim
:= TAnimation
.Create(id
, False, 3);
6471 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6472 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6478 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6480 FSawSound
.Pause(Enable
);
6481 FSawSoundIdle
.Pause(Enable
);
6482 FSawSoundHit
.Pause(Enable
);
6483 FSawSoundSelect
.Pause(Enable
);
6484 FFlameSoundOn
.Pause(Enable
);
6485 FFlameSoundOff
.Pause(Enable
);
6486 FFlameSoundWork
.Pause(Enable
);
6487 FJetSoundFly
.Pause(Enable
);
6488 FJetSoundOn
.Pause(Enable
);
6489 FJetSoundOff
.Pause(Enable
);
6494 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6499 FObj
.Rect
:= PLAYER_CORPSERECT
;
6500 FModelName
:= ModelName
;
6505 FState
:= CORPSE_STATE_MESS
;
6506 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6510 FState
:= CORPSE_STATE_NORMAL
;
6511 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6515 destructor TCorpse
.Destroy();
6522 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6524 procedure TCorpse
.positionChanged (); inline; begin end;
6526 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6528 if (dx
<> 0) or (dy
<> 0) then
6537 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6539 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6540 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6541 w
:= PLAYER_CORPSERECT
.Width
;
6542 h
:= PLAYER_CORPSERECT
.Height
;
6546 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6551 if FState
= CORPSE_STATE_REMOVEME
then
6554 FDamage
:= FDamage
+ Value
;
6556 if FDamage
> 150 then
6558 if FAnimation
<> nil then
6563 FState
:= CORPSE_STATE_REMOVEME
;
6565 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6566 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6567 FModelName
, FColor
);
6568 // Çâóê ìÿñà îò òðóïà:
6569 pm
:= g_PlayerModel_Get(FModelName
);
6570 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6574 if (gBodyKillEvent
<> -1)
6575 and gDelayedEvents
[gBodyKillEvent
].Pending
then
6576 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
6577 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, 0);
6582 Blood
:= g_PlayerModel_GetBlood(FModelName
);
6583 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6584 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6585 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6586 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6587 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6588 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
6592 procedure TCorpse
.Draw();
6596 if FState
= CORPSE_STATE_REMOVEME
then
6599 FObj
.lerp(gLerpFactor
, fX
, fY
);
6601 if FAnimation
<> nil then
6602 FAnimation
.Draw(fX
, fY
, TMirrorType
.None
);
6604 if FAnimationMask
<> nil then
6607 FAnimationMask
.Draw(fX
, fY
, TMirrorType
.None
);
6614 procedure TCorpse
.Update();
6618 if FState
= CORPSE_STATE_REMOVEME
then
6621 FObj
.oldX
:= FObj
.X
;
6622 FObj
.oldY
:= FObj
.Y
;
6624 if gTime
mod (GAME_TICK
*2) <> 0 then
6626 g_Obj_Move(@FObj
, True, True, True);
6627 positionChanged(); // this updates spatial accelerators
6631 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6632 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6634 st
:= g_Obj_Move(@FObj
, True, True, True);
6635 positionChanged(); // this updates spatial accelerators
6637 if WordBool(st
and MOVE_FALLOUT
) then
6639 FState
:= CORPSE_STATE_REMOVEME
;
6643 if FAnimation
<> nil then
6644 FAnimation
.Update();
6645 if FAnimationMask
<> nil then
6646 FAnimationMask
.Update();
6650 procedure TCorpse
.SaveState (st
: TStream
);
6657 utils
.writeSign(st
, 'CORP');
6658 utils
.writeInt(st
, Byte(0));
6660 utils
.writeInt(st
, Byte(FState
));
6662 utils
.writeInt(st
, Byte(FDamage
));
6664 utils
.writeInt(st
, Byte(FColor
.R
));
6665 utils
.writeInt(st
, Byte(FColor
.G
));
6666 utils
.writeInt(st
, Byte(FColor
.B
));
6668 Obj_SaveState(st
, @FObj
);
6669 utils
.writeInt(st
, Word(FPlayerUID
));
6671 anim
:= (FAnimation
<> nil);
6672 utils
.writeBool(st
, anim
);
6673 // Åñëè åñòü - ñîõðàíÿåì
6674 if anim
then FAnimation
.SaveState(st
);
6675 // Åñòü ëè ìàñêà àíèìàöèè
6676 anim
:= (FAnimationMask
<> nil);
6677 utils
.writeBool(st
, anim
);
6678 // Åñëè åñòü - ñîõðàíÿåì
6679 if anim
then FAnimationMask
.SaveState(st
);
6683 procedure TCorpse
.LoadState (st
: TStream
);
6690 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6691 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6693 FState
:= utils
.readByte(st
);
6695 FDamage
:= utils
.readByte(st
);
6697 FColor
.R
:= utils
.readByte(st
);
6698 FColor
.G
:= utils
.readByte(st
);
6699 FColor
.B
:= utils
.readByte(st
);
6701 Obj_LoadState(@FObj
, st
);
6702 FPlayerUID
:= utils
.readWord(st
);
6704 anim
:= utils
.readBool(st
);
6705 // Åñëè åñòü - çàãðóæàåì
6708 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6709 FAnimation
.LoadState(st
);
6711 // Åñòü ëè ìàñêà àíèìàöèè
6712 anim
:= utils
.readBool(st
);
6713 // Åñëè åñòü - çàãðóæàåì
6716 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6717 FAnimationMask
.LoadState(st
);
6723 constructor TBot
.Create();
6730 FSpectator
:= False;
6737 for a
:= WP_FIRST
to WP_LAST
do
6739 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6740 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6741 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6745 destructor TBot
.Destroy();
6748 inherited Destroy();
6751 procedure TBot
.Draw();
6755 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6756 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6759 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6761 inherited Respawn(Silent
, Force
);
6764 FSelectedWeapon
:= FCurrWeap
;
6769 procedure TBot
.UpdateCombat();
6782 TTargetRecord
= array of TTarget
;
6784 function Compare(a
, b
: TTarget
): Integer;
6786 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6789 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6791 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6792 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6794 if a
.Dist
> b
.Dist
then // B áëèæå
6796 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6799 else // Ñòðàííî -> A
6804 a
, x1
, y1
, x2
, y2
: Integer;
6805 targets
: TTargetRecord
;
6807 Target
, BestTarget
: TTarget
;
6808 firew
, fireh
: Integer;
6812 vsPlayer
, vsMonster
, ok
: Boolean;
6815 function monsUpdate (mon
: TMonster
): Boolean;
6817 result
:= false; // don't stop
6818 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6820 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6822 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6823 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6825 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6826 if g_TraceVector(x1
, y1
, x2
, y2
) then
6828 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6829 SetLength(targets
, Length(targets
)+1);
6830 with targets
[High(targets
)] do
6837 Rect
:= mon
.Obj
.Rect
;
6838 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6839 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6840 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6849 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6850 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6852 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6853 if FCurrWeap
<> FSelectedWeapon
then
6856 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6857 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6859 RemoveAIFlag('NEEDFIRE');
6862 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6863 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6864 else PressKey(KEY_FIRE
);
6868 // Êîîðäèíàòû ñòâîëà:
6869 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6870 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6872 Target
.UID
:= FTargetUID
;
6875 if Target
.UID
<> 0 then
6876 begin // Öåëü åñòü - íàñòðàèâàåì
6877 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6880 tpla
:= g_Player_Get(Target
.UID
);
6884 if (@FObj
) <> nil then
6891 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6892 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6893 Target
.Rect
:= PLAYER_RECT
;
6894 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6895 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6896 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6897 Target
.IsPlayer
:= True;
6901 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6904 mon
:= g_Monsters_ByUID(Target
.UID
);
6907 Target
.X
:= mon
.Obj
.X
;
6908 Target
.Y
:= mon
.Obj
.Y
;
6910 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6911 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6912 Target
.Rect
:= mon
.Obj
.Rect
;
6913 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6914 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6915 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6916 Target
.IsPlayer
:= False;
6923 begin // Öåëè íåò - îáíóëÿåì
6928 Target
.Visible
:= False;
6929 Target
.Line
:= False;
6930 Target
.IsPlayer
:= False;
6935 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6936 if (not Target
.Line
) or (not Target
.Visible
) then
6940 for a
:= 0 to High(gPlayers
) do
6941 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6942 (gPlayers
[a
].FUID
<> FUID
) and
6943 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6944 (not gPlayers
[a
].NoTarget
) and
6945 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6947 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6948 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6951 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6952 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6954 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6955 if g_TraceVector(x1
, y1
, x2
, y2
) then
6957 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6958 SetLength(targets
, Length(targets
)+1);
6959 with targets
[High(targets
)] do
6961 UID
:= gPlayers
[a
].FUID
;
6962 X
:= gPlayers
[a
].FObj
.X
;
6963 Y
:= gPlayers
[a
].FObj
.Y
;
6966 Rect
:= PLAYER_RECT
;
6967 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6968 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6969 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6977 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6980 // Åñëè åñòü âîçìîæíûå öåëè:
6981 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6982 if targets
<> nil then
6984 // Âûáèðàåì íàèëó÷øóþ öåëü:
6985 BestTarget
:= targets
[0];
6986 if Length(targets
) > 1 then
6987 for a
:= 1 to High(targets
) do
6988 if Compare(BestTarget
, targets
[a
]) = 1 then
6989 BestTarget
:= targets
[a
];
6991 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6992 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6993 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6995 Target
:= BestTarget
;
6997 if (Healthy() = 3) or ((Healthy() = 2)) then
6998 begin // Åñëè çäîðîâû - äîãîíÿåì
6999 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
7000 SetAIFlag('GORIGHT', '1');
7001 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
7002 SetAIFlag('GOLEFT', '1');
7005 begin // Åñëè ïîáèòû - óáåãàåì
7006 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
7007 SetAIFlag('GORIGHT', '1');
7008 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
7009 SetAIFlag('GOLEFT', '1');
7012 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
7013 SelectWeapon(Abs(x1
-Target
.cX
));
7018 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
7019 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
7020 if Target
.UID
<> 0 then
7022 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
7023 Target
.Y
+ Target
.Rect
.Y
) then
7024 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
7025 if (Healthy() = 3) or ((Healthy() = 2)) then
7026 begin // Åñëè çäîðîâû - äîãîíÿåì
7027 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
7028 SetAIFlag('GORIGHT', '1');
7029 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
7030 SetAIFlag('GOLEFT', '1');
7033 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
7035 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
7036 SetAIFlag('GORIGHT', '1');
7037 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
7038 SetAIFlag('GOLEFT', '1');
7042 begin // Öåëü ïîêà íà "ýêðàíå"
7043 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
7044 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7045 FLastVisible
:= gTime
;
7046 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
7047 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
7049 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
7050 SetAIFlag('GORIGHT', '1');
7051 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
7052 SetAIFlag('GOLEFT', '1');
7056 // Âûáèðàåì óãîë ââåðõ:
7057 if FDirection
= TDirection
.D_LEFT
then
7058 angle
:= ANGLE_LEFTUP
7060 angle
:= ANGLE_RIGHTUP
;
7062 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7063 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7065 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7066 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7067 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
7068 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7069 Target
.Rect
.Width
, Target
.Rect
.Height
) and
7070 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7071 begin // òî íóæíî ñòðåëÿòü ââåðõ
7072 SetAIFlag('NEEDFIRE', '1');
7073 SetAIFlag('NEEDSEEUP', '1');
7076 // Âûáèðàåì óãîë âíèç:
7077 if FDirection
= TDirection
.D_LEFT
then
7078 angle
:= ANGLE_LEFTDOWN
7080 angle
:= ANGLE_RIGHTDOWN
;
7082 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7083 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7085 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7086 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7087 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7088 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7089 Target
.Rect
.Width
, Target
.Rect
.Height
) and
7090 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7091 begin // òî íóæíî ñòðåëÿòü âíèç
7092 SetAIFlag('NEEDFIRE', '1');
7093 SetAIFlag('NEEDSEEDOWN', '1');
7096 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
7097 if Target
.Visible
and
7098 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
7099 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
7101 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
7102 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
7103 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
7104 begin // òî íóæíî ñòðåëÿòü âïåðåä
7105 SetAIFlag('NEEDFIRE', '1');
7106 SetAIFlag('NEEDSEEDOWN', '');
7107 SetAIFlag('NEEDSEEUP', '');
7109 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
7110 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
7111 if GetRnd(FDifficult
.CloseJump
) then
7112 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
7113 if Abs(FObj
.X
-Target
.X
) < 128 then
7117 if Random(a
) = 0 then
7118 SetAIFlag('NEEDJUMP', '1');
7122 // Åñëè öåëü âñå åùå åñòü:
7123 if Target
.UID
<> 0 then
7124 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
7125 Target
.UID
:= 0 // òî çàáûòü öåëü
7126 else // Åñëè âèäåëè íåäàâíî
7127 begin // íî öåëü óáèëè
7128 if Target
.IsPlayer
then
7129 begin // Öåëü - èãðîê
7130 pla
:= g_Player_Get(Target
.UID
);
7131 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
7132 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
7133 Target
.UID
:= 0; // òî çàáûòü öåëü
7136 begin // Öåëü - ìîíñòð
7137 mon
:= g_Monsters_ByUID(Target
.UID
);
7138 if (mon
= nil) or (not mon
.alive
) then
7139 Target
.UID
:= 0; // òî çàáûòü öåëü
7142 end; // if Target.UID <> 0
7144 FTargetUID
:= Target
.UID
;
7146 // Åñëè âîçìîæíûõ öåëåé íåò:
7147 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
7148 if targets
= nil then
7149 if GetAIFlag('ATTACKLEFT') <> '' then
7150 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
7151 RemoveAIFlag('ATTACKLEFT');
7153 SetAIFlag('NEEDJUMP', '1');
7155 if RunDirection() = TDirection
.D_RIGHT
then
7156 begin // Èäåì íå â òó ñòîðîíó
7157 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7158 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
7159 SetAIFlag('NEEDFIRE', '1');
7160 SetAIFlag('GOLEFT', '1');
7164 begin // Èäåì â íóæíóþ ñòîðîíó
7165 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7166 SetAIFlag('NEEDFIRE', '1');
7167 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7168 SetAIFlag('GORIGHT', '1');
7172 if GetAIFlag('ATTACKRIGHT') <> '' then
7173 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
7174 RemoveAIFlag('ATTACKRIGHT');
7176 SetAIFlag('NEEDJUMP', '1');
7178 if RunDirection() = TDirection
.D_LEFT
then
7179 begin // Èäåì íå â òó ñòîðîíó
7180 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7181 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
7182 SetAIFlag('NEEDFIRE', '1');
7183 SetAIFlag('GORIGHT', '1');
7188 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7189 SetAIFlag('NEEDFIRE', '1');
7190 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7191 SetAIFlag('GOLEFT', '1');
7195 //HACK! (does it belongs there?)
7196 RealizeCurrentWeapon();
7198 // Åñëè åñòü âîçìîæíûå öåëè:
7199 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7200 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7201 for a
:= 0 to High(targets
) do
7203 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7204 if GetRnd(FDifficult
.DiagFire
) then
7206 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7207 if FDirection
= TDirection
.D_LEFT
then
7208 angle
:= ANGLE_LEFTUP
7210 angle
:= ANGLE_RIGHTUP
;
7212 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7213 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7215 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7216 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7217 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7218 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7219 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7221 SetAIFlag('NEEDFIRE', '1');
7222 SetAIFlag('NEEDSEEUP', '1');
7225 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7226 if FDirection
= TDirection
.D_LEFT
then
7227 angle
:= ANGLE_LEFTDOWN
7229 angle
:= ANGLE_RIGHTDOWN
;
7231 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7232 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7234 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7235 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7236 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7237 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7238 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7240 SetAIFlag('NEEDFIRE', '1');
7241 SetAIFlag('NEEDSEEDOWN', '1');
7245 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7246 if targets
[a
].Line
and targets
[a
].Visible
and
7247 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
7248 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
7250 SetAIFlag('NEEDFIRE', '1');
7255 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7256 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
7257 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
7258 40+GetInterval(FDifficult
.Cover
, 40)) then
7259 SetAIFlag('NEEDJUMP', '1');
7261 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7262 ammo
:= GetAmmoByWeapon(FCurrWeap
);
7263 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
7264 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
7266 SetAIFlag('SELECTWEAPON', '1');
7268 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7269 if GetAIFlag('SELECTWEAPON') = '1' then
7272 RemoveAIFlag('SELECTWEAPON');
7276 procedure TBot
.Update();
7289 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7290 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7292 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7294 if g_debug_BotAIOff
= 3 then
7304 RealizeCurrentWeapon();
7311 procedure TBot
.ReleaseKey(Key
: Byte);
7320 function TBot
.KeyPressed(Key
: Word): Boolean;
7322 Result
:= FKeys
[Key
].Pressed
;
7325 function TBot
.GetAIFlag(aName
: String20
): String20
;
7331 aName
:= LowerCase(aName
);
7333 if FAIFlags
<> nil then
7334 for a
:= 0 to High(FAIFlags
) do
7335 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7337 Result
:= FAIFlags
[a
].Value
;
7342 procedure TBot
.RemoveAIFlag(aName
: String20
);
7346 if FAIFlags
= nil then Exit
;
7348 aName
:= LowerCase(aName
);
7350 for a
:= 0 to High(FAIFlags
) do
7351 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7353 if a
<> High(FAIFlags
) then
7354 for b
:= a
to High(FAIFlags
)-1 do
7355 FAIFlags
[b
] := FAIFlags
[b
+1];
7357 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7362 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7370 aName
:= LowerCase(aName
);
7372 if FAIFlags
<> nil then
7373 for a
:= 0 to High(FAIFlags
) do
7374 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7380 if ok
then FAIFlags
[a
].Value
:= fValue
7383 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7384 with FAIFlags
[High(FAIFlags
)] do
7392 procedure TBot
.UpdateMove
;
7394 procedure GoLeft(Time
: Word = 1);
7396 ReleaseKey(KEY_LEFT
);
7397 ReleaseKey(KEY_RIGHT
);
7398 PressKey(KEY_LEFT
, Time
);
7399 SetDirection(TDirection
.D_LEFT
);
7402 procedure GoRight(Time
: Word = 1);
7404 ReleaseKey(KEY_LEFT
);
7405 ReleaseKey(KEY_RIGHT
);
7406 PressKey(KEY_RIGHT
, Time
);
7407 SetDirection(TDirection
.D_RIGHT
);
7410 function Rnd(a
: Word): Boolean;
7412 Result
:= Random(a
) = 0;
7415 procedure Turn(Time
: Word = 1200);
7417 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7422 ReleaseKey(KEY_LEFT
);
7423 ReleaseKey(KEY_RIGHT
);
7426 function CanRunLeft(): Boolean;
7428 Result
:= not CollideLevel(-1, 0);
7431 function CanRunRight(): Boolean;
7433 Result
:= not CollideLevel(1, 0);
7436 function CanRun(): Boolean;
7438 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7441 procedure Jump(Time
: Word = 30);
7443 PressKey(KEY_JUMP
, Time
);
7446 function NearHole(): Boolean;
7450 { TODO 5 : Ëåñòíèöû }
7451 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7452 for x
:= 1 to PLAYER_RECT
.Width
do
7453 if (not StayOnStep(x
*sx
, 0)) and
7454 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7455 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7464 function BorderHole(): Boolean;
7468 { TODO 5 : Ëåñòíèöû }
7469 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7470 for x
:= 1 to PLAYER_RECT
.Width
do
7471 if (not StayOnStep(x
*sx
, 0)) and
7472 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7473 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7475 for xx
:= x
to x
+32 do
7476 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7486 function NearDeepHole(): Boolean;
7492 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7495 for x
:= 1 to PLAYER_RECT
.Width
do
7496 if (not StayOnStep(x
*sx
, 0)) and
7497 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7498 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7500 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7502 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7507 end else Result
:= False;
7510 function OverDeepHole(): Boolean;
7517 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7519 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7526 function OnGround(): Boolean;
7528 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7531 function OnLadder(): Boolean;
7533 Result
:= FullInStep(0, 0);
7536 function BelowLadder(): Boolean;
7538 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7539 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7540 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7541 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7544 function BelowLiftUp(): Boolean;
7546 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7547 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7548 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7549 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7552 function OnTopLift(): Boolean;
7554 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7557 function CanJumpOver(): Boolean;
7561 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7565 if not CollideLevel(sx
, 0) then Exit
;
7567 for y
:= 1 to BOT_MAXJUMP
do
7568 if CollideLevel(0, -y
) then Exit
else
7569 if not CollideLevel(sx
, -y
) then
7576 function CanJumpUp(Dist
: ShortInt): Boolean;
7583 if CollideLevel(Dist
, 0) then Exit
;
7586 for y
:= 0 to BOT_MAXJUMP
do
7587 if CollideLevel(Dist
, -y
) then
7596 for yy
:= y
+1 to BOT_MAXJUMP
do
7597 if not CollideLevel(Dist
, -yy
) then
7606 for y
:= 0 to BOT_MAXJUMP
do
7607 if CollideLevel(0, -y
) then
7615 if y
< yy
then Exit
;
7620 function IsSafeTrigger(): Boolean;
7625 if gTriggers
= nil then
7627 for a
:= 0 to High(gTriggers
) do
7628 if Collide(gTriggers
[a
].X
,
7631 gTriggers
[a
].Height
) and
7632 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7633 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7634 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7635 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7636 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7641 // Âîçìîæíî, íàæèìàåì êíîïêó:
7642 if Rnd(16) and IsSafeTrigger() then
7645 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7646 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7648 ReleaseKey(KEY_LEFT
);
7649 ReleaseKey(KEY_RIGHT
);
7653 // Èäåì âëåâî, åñëè íàäî áûëî:
7654 if GetAIFlag('GOLEFT') <> '' then
7656 RemoveAIFlag('GOLEFT');
7657 if CanRunLeft() then
7661 // Èäåì âïðàâî, åñëè íàäî áûëî:
7662 if GetAIFlag('GORIGHT') <> '' then
7664 RemoveAIFlag('GORIGHT');
7665 if CanRunRight() then
7669 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7670 if FObj
.X
< -32 then
7673 if FObj
.X
+32 > gMapInfo
.Width
then
7676 // Ïðûãàåì, åñëè íàäî áûëî:
7677 if GetAIFlag('NEEDJUMP') <> '' then
7680 RemoveAIFlag('NEEDJUMP');
7683 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7684 if GetAIFlag('NEEDSEEUP') <> '' then
7687 ReleaseKey(KEY_DOWN
);
7688 PressKey(KEY_UP
, 20);
7689 RemoveAIFlag('NEEDSEEUP');
7692 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7693 if GetAIFlag('NEEDSEEDOWN') <> '' then
7696 ReleaseKey(KEY_DOWN
);
7697 PressKey(KEY_DOWN
, 20);
7698 RemoveAIFlag('NEEDSEEDOWN');
7701 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7702 if GetAIFlag('GOINHOLE') <> '' then
7703 if not OnGround() then
7705 ReleaseKey(KEY_LEFT
);
7706 ReleaseKey(KEY_RIGHT
);
7707 RemoveAIFlag('GOINHOLE');
7708 SetAIFlag('FALLINHOLE', '1');
7711 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7712 if GetAIFlag('FALLINHOLE') <> '' then
7714 RemoveAIFlag('FALLINHOLE');
7716 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7717 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7718 if GetAIFlag('FALLINHOLE') = '' then
7719 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7725 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7727 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7731 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7732 if OnGround() and NearHole() then
7733 if NearDeepHole() then // Åñëè ýòî áåçäíà
7735 0..3: Turn(); // Áåæèì îáðàòíî
7736 4: Jump(); // Ïðûãàåì
7737 5: begin // Ïðûãàåì îáðàòíî
7742 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7743 if GetAIFlag('GOINHOLE') = '' then
7745 0: Turn(); // Íå íóæíî òóäà
7746 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7747 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7748 if BorderHole() then
7749 SetAIFlag('GOINHOLE', '1');
7752 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7753 if (not CanRun()) and OnGround() then
7755 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7756 if CanJumpOver() or OnLadder() then
7758 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7759 if Random(2) = 0 then
7761 if IsSafeTrigger() then
7767 // Îñòàëîñü ìàëî âîçäóõà:
7768 if FAir
< 36 * 2 then
7771 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7772 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7773 if BodyInAcid(0, 0) then
7777 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7779 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7780 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7783 {function TBot.NeedItem(Item: Byte): Byte;
7788 procedure TBot
.SelectWeapon(Dist
: Integer);
7792 function HaveAmmo(weapon
: Byte): Boolean;
7795 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7796 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7797 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7798 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7799 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7800 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7801 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7802 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7803 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7804 else Result
:= True;
7809 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7811 if Dist
> BOT_LONGDIST
then
7812 begin // Äàëüíèé áîé
7814 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7816 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7820 else //if Dist > BOT_UNSAFEDIST then
7821 begin // Áëèæíèé áîé
7823 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7825 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7832 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7834 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7840 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7842 Result
:= inherited PickItem(ItemType
, force
, remove
);
7844 if Result
then SetAIFlag('SELECTWEAPON', '1');
7847 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7849 Result
:= inherited Heal(value
, Soft
);
7852 function TBot
.Healthy(): Byte;
7854 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7855 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7856 else if (FHealth
> 50) then Result
:= 2
7857 else if (FHealth
> 20) then Result
:= 1
7861 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7863 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7864 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7867 procedure TBot
.OnDamage(Angle
: SmallInt);
7875 if (Angle
= 0) or (Angle
= 180) then
7878 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7879 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7881 pla
:= g_Player_Get(FLastSpawnerUID
);
7882 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7883 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7886 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7887 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7889 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7890 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7891 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7896 SetAIFlag('ATTACKLEFT', '1')
7898 SetAIFlag('ATTACKRIGHT', '1');
7902 function TBot
.RunDirection(): TDirection
;
7904 if Abs(Vel
.X
) >= 1 then
7906 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7908 Result
:= FDirection
;
7911 function TBot
.GetRnd(a
: Byte): Boolean;
7913 if a
= 0 then Result
:= False
7914 else if a
= 255 then Result
:= True
7915 else Result
:= Random(256) > 255-a
;
7918 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7920 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7924 procedure TDifficult
.save (st
: TStream
);
7926 utils
.writeInt(st
, Byte(DiagFire
));
7927 utils
.writeInt(st
, Byte(InvisFire
));
7928 utils
.writeInt(st
, Byte(DiagPrecision
));
7929 utils
.writeInt(st
, Byte(FlyPrecision
));
7930 utils
.writeInt(st
, Byte(Cover
));
7931 utils
.writeInt(st
, Byte(CloseJump
));
7932 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7933 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7936 procedure TDifficult
.load (st
: TStream
);
7938 DiagFire
:= utils
.readByte(st
);
7939 InvisFire
:= utils
.readByte(st
);
7940 DiagPrecision
:= utils
.readByte(st
);
7941 FlyPrecision
:= utils
.readByte(st
);
7942 Cover
:= utils
.readByte(st
);
7943 CloseJump
:= utils
.readByte(st
);
7944 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7945 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7949 procedure TBot
.SaveState (st
: TStream
);
7954 inherited SaveState(st
);
7955 utils
.writeSign(st
, 'BOT0');
7957 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7959 utils
.writeInt(st
, Word(FTargetUID
));
7960 // Âðåìÿ ïîòåðè öåëè
7961 utils
.writeInt(st
, LongWord(FLastVisible
));
7962 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7963 dw
:= Length(FAIFlags
);
7964 utils
.writeInt(st
, LongInt(dw
));
7966 for i
:= 0 to dw
-1 do
7968 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7969 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7971 // Íàñòðîéêè ñëîæíîñòè
7972 FDifficult
.save(st
);
7976 procedure TBot
.LoadState (st
: TStream
);
7981 inherited LoadState(st
);
7982 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7984 FSelectedWeapon
:= utils
.readByte(st
);
7986 FTargetUID
:= utils
.readWord(st
);
7987 // Âðåìÿ ïîòåðè öåëè
7988 FLastVisible
:= utils
.readLongWord(st
);
7989 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7990 dw
:= utils
.readLongInt(st
);
7991 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7992 SetLength(FAIFlags
, dw
);
7994 for i
:= 0 to dw
-1 do
7996 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7997 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7999 // Íàñòðîéêè ñëîæíîñòè
8000 FDifficult
.load(st
);
8005 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);
8006 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');
8007 conRegVar('player_indicator_style', @gPlayerIndicatorStyle
, 'Visual appearance of indicator', 'Visual appearance of indicator');