1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
23 {$IFDEF USE_MEMPOOL}mempool
,{$ENDIF}
24 e_graphics
, g_playermodel
, g_basic
, g_textures
,
25 g_weapons
, g_phys
, g_sound
, g_saveload
, MAPDEF
,
58 AmmoLimits
: Array [0..1] of Array [A_BULLETS
..A_HIGH
] of Word =
59 ((200, 50, 50, 300, 100),
60 (400, 100, 100, 600, 200));
81 ANGLE_NONE
= Low(SmallInt);
83 CORPSE_STATE_REMOVEME
= 0;
84 CORPSE_STATE_NORMAL
= 1;
85 CORPSE_STATE_MESS
= 2;
87 PLAYER_RECT
: TRectWH
= (X
:15; Y
:12; Width
:34; Height
:52);
88 PLAYER_RECT_CX
= 15+(34 div 2);
89 PLAYER_RECT_CY
= 12+(52 div 2);
90 PLAYER_CORPSERECT
: TRectWH
= (X
:15; Y
:48; Width
:34; Height
:16);
93 PLAYER_HP_LIMIT
= 200;
95 PLAYER_AP_LIMIT
= 200;
99 PLAYER_BURN_TIME
= 110;
101 PLAYER1_DEF_COLOR
: TRGB
= (R
:64; G
:175; B
:48);
102 PLAYER2_DEF_COLOR
: TRGB
= (R
:96; G
:96; B
:96);
119 TPlayerStatArray
= Array of TPlayerStat
;
121 TPlayerSavedState
= record
129 Ammo
: Array [A_BULLETS
..A_HIGH
] of Word;
130 MaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
131 Weapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
132 Rulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
141 TPlayer
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
149 FDirection
: TDirection
;
157 FMonsterKills
: Integer;
163 FCanJetpack
: Boolean;
169 FNextWeapDelay
: Byte; // frames
170 FBFGFireCounter
: SmallInt;
171 FLastSpawnerUID
: Word;
175 FSpectatePlayer
: Integer;
176 FFirePainTime
: Integer;
179 FSavedState
: TPlayerSavedState
;
181 FModel
: TPlayerModel
;
182 FPunchAnim
: TAnimation
;
185 FActionForce
: Boolean;
186 FActionChanged
: Boolean;
188 FFireAngle
: SmallInt;
190 FShellTimer
: Integer;
192 FSawSound
: TPlayableSound
;
193 FSawSoundIdle
: TPlayableSound
;
194 FSawSoundHit
: TPlayableSound
;
195 FSawSoundSelect
: TPlayableSound
;
196 FFlameSoundOn
: TPlayableSound
;
197 FFlameSoundOff
: TPlayableSound
;
198 FFlameSoundWork
: TPlayableSound
;
199 FJetSoundOn
: TPlayableSound
;
200 FJetSoundOff
: TPlayableSound
;
201 FJetSoundFly
: TPlayableSound
;
205 FJustTeleported
: Boolean;
207 mEDamageType
: Integer;
210 function CollideLevel(XInc
, YInc
: Integer): Boolean;
211 function StayOnStep(XInc
, YInc
: Integer): Boolean;
212 function HeadInLiquid(XInc
, YInc
: Integer): Boolean;
213 function BodyInLiquid(XInc
, YInc
: Integer): Boolean;
214 function BodyInAcid(XInc
, YInc
: Integer): Boolean;
215 function FullInLift(XInc
, YInc
: Integer): Integer;
216 {procedure CollideItem();}
217 procedure FlySmoke(Times
: DWORD
= 1);
218 procedure OnFireFlame(Times
: DWORD
= 1);
219 function GetAmmoByWeapon(Weapon
: Byte): Word;
220 procedure SetAction(Action
: Byte; Force
: Boolean = False);
221 procedure OnDamage(Angle
: SmallInt); virtual;
222 function firediry(): Integer;
225 procedure Run(Direction
: TDirection
);
226 procedure NextWeapon();
227 procedure PrevWeapon();
234 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
235 procedure resetWeaponQueue ();
236 function hasAmmoForWeapon (weapon
: Byte): Boolean;
238 procedure doDamage (v
: Integer);
240 function followCorpse(): Boolean;
243 FDamageBuffer
: Integer;
245 FAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
246 FMaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
247 FWeapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
248 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
250 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
251 FReloading
: Array [WP_FIRST
..WP_LAST
] of Word;
252 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
253 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
255 FPreferredTeam
: Byte;
258 FWantsInGame
: Boolean;
263 FActualModelName
: string;
272 // debug: viewport offset
273 viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer;
275 function isValidViewPort (): Boolean; inline;
277 constructor Create(); virtual;
278 destructor Destroy(); override;
279 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
280 function GetRespawnPoint(): Byte;
281 procedure PressKey(Key
: Byte; Time
: Word = 1);
282 procedure ReleaseKeys();
283 procedure SetModel(ModelName
: String);
284 procedure SetColor(Color
: TRGB
);
285 function GetColor(): TRGB
;
286 procedure SetWeapon(W
: Byte);
287 function IsKeyPressed(K
: Byte): Boolean;
288 function GetKeys(): Byte;
289 function PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean; virtual;
290 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
291 function Collide(Panel
: TPanel
): Boolean; overload
;
292 function Collide(X
, Y
: Integer): Boolean; overload
;
293 procedure SetDirection(Direction
: TDirection
);
294 procedure GetSecret();
295 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
297 procedure Push(vx
, vy
: Integer);
298 procedure ChangeModel(ModelName
: String);
299 procedure SwitchTeam
;
300 procedure ChangeTeam(Team
: Byte);
302 function GetFlag(Flag
: Byte): Boolean;
303 procedure SetFlag(Flag
: Byte);
304 function DropFlag(Silent
: Boolean = True): Boolean;
305 procedure AllRulez(Health
: Boolean);
306 procedure RestoreHealthArmor();
307 procedure FragCombo();
308 procedure GiveItem(ItemType
: Byte);
309 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
310 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
311 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
312 procedure MakeBloodSimple(Count
: Word);
313 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
314 procedure Reset(Force
: Boolean);
315 procedure Spectate(NoMove
: Boolean = False);
316 procedure SwitchNoClip
;
317 procedure SoftReset();
318 procedure Draw(); virtual;
319 procedure DrawPain();
320 procedure DrawPickup();
321 procedure DrawRulez();
323 procedure DrawIndicator(Color
: TRGB
);
324 procedure DrawBubble();
326 procedure Update(); virtual;
327 procedure RememberState();
328 procedure RecallState();
329 procedure SaveState (st
: TStream
); virtual;
330 procedure LoadState (st
: TStream
); virtual;
331 procedure PauseSounds(Enable
: Boolean);
332 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
333 procedure DoLerp(Level
: Integer = 2);
334 procedure SetLerp(XTo
, YTo
: Integer);
335 procedure QueueWeaponSwitch(Weapon
: Byte);
336 procedure RealizeCurrentWeapon();
340 procedure JetpackOff
;
341 procedure CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
343 //WARNING! this does nothing for now, but still call it!
344 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
346 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
347 procedure moveBy (dx
, dy
: Integer); inline;
350 property Vel
: TPoint2i read FObj
.Vel
;
351 property Obj
: TObj read FObj
;
353 property Name
: String read FName write FName
;
354 property Model
: TPlayerModel read FModel
;
355 property Health
: Integer read FHealth write FHealth
;
356 property Lives
: Byte read FLives write FLives
;
357 property Armor
: Integer read FArmor write FArmor
;
358 property Air
: Integer read FAir write FAir
;
359 property JetFuel
: Integer read FJetFuel write FJetFuel
;
360 property Frags
: Integer read FFrags write FFrags
;
361 property Death
: Integer read FDeath write FDeath
;
362 property Kills
: Integer read FKills write FKills
;
363 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
364 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
365 property Secrets
: Integer read FSecrets
;
366 property GodMode
: Boolean read FGodMode write FGodMode
;
367 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
368 property NoReload
: Boolean read FNoReload write FNoReload
;
369 property alive
: Boolean read FAlive write FAlive
;
370 property Flag
: Byte read FFlag
;
371 property Team
: Byte read FTeam write FTeam
;
372 property Direction
: TDirection read FDirection
;
373 property GameX
: Integer read FObj
.X write FObj
.X
;
374 property GameY
: Integer read FObj
.Y write FObj
.Y
;
375 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
376 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
377 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
378 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
379 property IncCam
: Integer read FIncCam write FIncCam
;
380 property UID
: Word read FUID write FUID
;
381 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
382 property NetTime
: LongWord read FNetTime write FNetTime
;
385 property eName
: String read FName write FName
;
386 property eHealth
: Integer read FHealth write FHealth
;
387 property eLives
: Byte read FLives write FLives
;
388 property eArmor
: Integer read FArmor write FArmor
;
389 property eAir
: Integer read FAir write FAir
;
390 property eJetFuel
: Integer read FJetFuel write FJetFuel
;
391 property eFrags
: Integer read FFrags write FFrags
;
392 property eDeath
: Integer read FDeath write FDeath
;
393 property eKills
: Integer read FKills write FKills
;
394 property eCurrWeap
: Byte read FCurrWeap write FCurrWeap
;
395 property eMonsterKills
: Integer read FMonsterKills write FMonsterKills
;
396 property eSecrets
: Integer read FSecrets write FSecrets
;
397 property eGodMode
: Boolean read FGodMode write FGodMode
;
398 property eNoTarget
: Boolean read FNoTarget write FNoTarget
;
399 property eNoReload
: Boolean read FNoReload write FNoReload
;
400 property eAlive
: Boolean read FAlive write FAlive
;
401 property eFlag
: Byte read FFlag
;
402 property eTeam
: Byte read FTeam write FTeam
;
403 property eDirection
: TDirection read FDirection
;
404 property eGameX
: Integer read FObj
.X write FObj
.X
;
405 property eGameY
: Integer read FObj
.Y write FObj
.Y
;
406 property eGameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
407 property eGameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
408 property eGameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
409 property eGameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
410 property eIncCam
: Integer read FIncCam write FIncCam
;
411 property eUID
: Word read FUID
;
412 property eJustTeleported
: Boolean read FJustTeleported
;
413 property eNetTime
: LongWord read FNetTime
;
415 // set this before assigning something to `eDamage`
416 property eDamageType
: Integer read mEDamageType write mEDamageType
;
417 property eDamage
: Integer write doDamage
;
428 WeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
429 CloseWeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
430 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
433 procedure save (st
: TStream
);
434 procedure load (st
: TStream
);
442 TBot
= class(TPlayer
)
444 FSelectedWeapon
: Byte;
447 FAIFlags
: Array of TAIFlag
;
448 FDifficult
: TDifficult
;
450 function GetRnd(a
: Byte): Boolean;
451 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
452 function RunDirection(): TDirection
;
453 function FullInStep(XInc
, YInc
: Integer): Boolean;
454 //function NeedItem(Item: Byte): Byte;
455 procedure SelectWeapon(Dist
: Integer);
456 procedure SetAIFlag(aName
, fValue
: String20
);
457 function GetAIFlag(aName
: String20
): String20
;
458 procedure RemoveAIFlag(aName
: String20
);
459 function Healthy(): Byte;
460 procedure UpdateMove();
461 procedure UpdateCombat();
462 function KeyPressed(Key
: Word): Boolean;
463 procedure ReleaseKey(Key
: Byte);
464 function TargetOnScreen(TX
, TY
: Integer): Boolean;
465 procedure OnDamage(Angle
: SmallInt); override;
468 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
469 constructor Create(); override;
470 destructor Destroy(); override;
471 procedure Draw(); override;
472 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
473 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
474 procedure Update(); override;
475 procedure SaveState (st
: TStream
); override;
476 procedure LoadState (st
: TStream
); override;
488 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
489 procedure moveBy (dx
, dy
: Integer); inline;
491 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
505 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
506 procedure moveBy (dx
, dy
: Integer); inline;
508 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
511 TCorpse
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
520 FAnimation
: TAnimation
;
521 FAnimationMask
: TAnimation
;
524 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
525 destructor Destroy(); override;
526 procedure Damage(Value
: Word; vx
, vy
: Integer);
529 procedure SaveState (st
: TStream
);
530 procedure LoadState (st
: TStream
);
532 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
533 procedure moveBy (dx
, dy
: Integer); inline;
535 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
537 function ObjPtr (): PObj
; inline;
539 property Obj
: TObj read FObj
; // copies object
540 property State
: Byte read FState
;
541 property Mess
: Boolean read FMess
;
544 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
550 gPlayers
: Array of TPlayer
;
551 gCorpses
: Array of TCorpse
;
552 gGibs
: Array of TGib
;
553 gShells
: Array of TShell
;
554 gTeamStat
: TTeamStat
;
555 gFly
: Boolean = False;
556 gAimLine
: Boolean = False;
557 gChatBubble
: Byte = 0;
558 gPlayerIndicator
: Integer = 1;
559 gPlayerIndicatorStyle
: Integer = 0;
563 MAX_RUNVEL
: Integer = 8;
564 VEL_JUMP
: Integer = 10;
565 SHELL_TIMEOUT
: Cardinal = 60000;
567 function Lerp(X
, Y
, Factor
: Integer): Integer;
569 procedure g_Gibs_SetMax(Count
: Word);
570 function g_Gibs_GetMax(): Word;
571 procedure g_Corpses_SetMax(Count
: Word);
572 function g_Corpses_GetMax(): Word;
573 procedure g_Shells_SetMax(Count
: Word);
574 function g_Shells_GetMax(): Word;
576 procedure g_Player_Init();
577 procedure g_Player_Free();
578 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
579 function g_Player_CreateFromState (st
: TStream
): Word;
580 procedure g_Player_Remove(UID
: Word);
581 procedure g_Player_ResetTeams();
582 procedure g_Player_UpdateAll();
583 procedure g_Player_DrawAll();
584 procedure g_Player_DrawDebug(p
: TPlayer
);
585 procedure g_Player_DrawHealth();
586 procedure g_Player_RememberAll();
587 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
588 function g_Player_Get(UID
: Word): TPlayer
;
589 function g_Player_GetCount(): Byte;
590 function g_Player_GetStats(): TPlayerStatArray
;
591 function g_Player_ValidName(Name
: String): Boolean;
592 procedure g_Player_CreateCorpse(Player
: TPlayer
);
593 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
594 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
595 procedure g_Player_UpdatePhysicalObjects();
596 procedure g_Player_DrawCorpses();
597 procedure g_Player_DrawShells();
598 procedure g_Player_RemoveAllCorpses();
599 procedure g_Player_Corpses_SaveState (st
: TStream
);
600 procedure g_Player_Corpses_LoadState (st
: TStream
);
601 procedure g_Player_ResetReady();
602 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
603 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
604 procedure g_Bot_MixNames();
605 procedure g_Bot_RemoveAll();
610 {$INCLUDE ../nogl/noGLuses.inc}
611 {$IFDEF ENABLE_HOLMES}
614 e_log
, g_map
, g_items
, g_console
, g_gfx
, Math
,
615 g_options
, g_triggers
, g_menu
, g_game
, g_grid
,
616 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
,
617 g_net
, g_netmsg
, g_window
,
620 const PLR_SAVE_VERSION
= 0;
630 diag_precision
: Byte;
634 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
635 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
636 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
640 TIME_RESPAWN1
= 1500;
641 TIME_RESPAWN2
= 2000;
642 TIME_RESPAWN3
= 3000;
645 JET_MAX
= 540; // ~30 sec
646 PLAYER_SUIT_TIME
= 30000;
647 PLAYER_INVUL_TIME
= 30000;
648 PLAYER_INVIS_TIME
= 35000;
649 FRAG_COMBO_TIME
= 3000;
653 ANGLE_RIGHTDOWN
= -35;
655 ANGLE_LEFTDOWN
= -145;
656 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
657 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
660 BOT_UNSAFEDIST
= 128;
661 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
663 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
664 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
665 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
666 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
667 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
668 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
669 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
670 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
671 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
672 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
673 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
674 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
675 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
676 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
677 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
678 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
679 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
680 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
681 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
682 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
683 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
684 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
685 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
686 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
687 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
688 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
690 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
691 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
693 BOTNAMES_FILENAME
= 'botnames.txt';
694 BOTLIST_FILENAME
= 'botlist.txt';
698 MaxCorpses
: Word = 20;
699 MaxShells
: Word = 300;
700 CurrentGib
: Integer = 0;
701 CurrentShell
: Integer = 0;
702 BotNames
: Array of String;
703 BotList
: Array of TBotProfile
;
706 function Lerp(X
, Y
, Factor
: Integer): Integer;
708 Result
:= X
+ ((Y
- X
) div Factor
);
711 function SameTeam(UID1
, UID2
: Word): Boolean;
715 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
716 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
718 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
720 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
721 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
723 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
726 procedure g_Gibs_SetMax(Count
: Word);
729 SetLength(gGibs
, Count
);
731 if CurrentGib
>= Count
then
735 function g_Gibs_GetMax(): Word;
740 procedure g_Shells_SetMax(Count
: Word);
743 SetLength(gShells
, Count
);
745 if CurrentShell
>= Count
then
749 function g_Shells_GetMax(): Word;
755 procedure g_Corpses_SetMax(Count
: Word);
758 SetLength(gCorpses
, Count
);
761 function g_Corpses_GetMax(): Word;
763 Result
:= MaxCorpses
;
766 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
776 // Åñòü ëè ìåñòî â gPlayers:
777 if gPlayers
<> nil then
778 for a
:= 0 to High(gPlayers
) do
779 if gPlayers
[a
] = nil then
785 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
788 SetLength(gPlayers
, Length(gPlayers
)+1);
792 // Ñîçäàåì îáúåêò èãðîêà:
794 gPlayers
[a
] := TBot
.Create()
796 gPlayers
[a
] := TPlayer
.Create();
799 gPlayers
[a
].FActualModelName
:= ModelName
;
800 gPlayers
[a
].SetModel(ModelName
);
802 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
803 if gPlayers
[a
].FModel
= nil then
807 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
811 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
812 if Random(2) = 0 then
816 gPlayers
[a
].FPreferredTeam
:= Team
;
818 case gGameSettings
.GameMode
of
819 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
821 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
823 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
826 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
827 gPlayers
[a
].FColor
:= Color
;
828 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
829 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
831 gPlayers
[a
].FModel
.Color
:= Color
;
833 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
834 gPlayers
[a
].FAlive
:= False;
836 Result
:= gPlayers
[a
].FUID
;
839 function g_Player_CreateFromState (st
: TStream
): Word;
846 if (st
= nil) then exit
; //???
849 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
850 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
853 Bot
:= utils
.readBool(st
);
858 // Åñòü ëè ìåñòî â gPlayers:
859 for a
:= 0 to High(gPlayers
) do if (gPlayers
[a
] = nil) then begin ok
:= true; break
; end;
861 // Íåò ìåñòà - ðàñøèðÿåì gPlayers
864 SetLength(gPlayers
, Length(gPlayers
)+1);
868 // Ñîçäàåì îáúåêò èãðîêà
870 gPlayers
[a
] := TBot
.Create()
872 gPlayers
[a
] := TPlayer
.Create();
873 gPlayers
[a
].FIamBot
:= Bot
;
874 gPlayers
[a
].FPhysics
:= True;
877 gPlayers
[a
].FUID
:= utils
.readWord(st
);
879 gPlayers
[a
].FName
:= utils
.readStr(st
);
881 gPlayers
[a
].FTeam
:= utils
.readByte(st
);
882 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
884 gPlayers
[a
].FAlive
:= utils
.readBool(st
);
885 // Èçðàñõîäîâàë ëè âñå æèçíè
886 gPlayers
[a
].FNoRespawn
:= utils
.readBool(st
);
888 b
:= utils
.readByte(st
);
889 if b
= 1 then gPlayers
[a
].FDirection
:= TDirection
.D_LEFT
else gPlayers
[a
].FDirection
:= TDirection
.D_RIGHT
; // b = 2
891 gPlayers
[a
].FHealth
:= utils
.readLongInt(st
);
893 gPlayers
[a
].FHandicap
:= utils
.readLongInt(st
);
895 gPlayers
[a
].FLives
:= utils
.readByte(st
);
897 gPlayers
[a
].FArmor
:= utils
.readLongInt(st
);
899 gPlayers
[a
].FAir
:= utils
.readLongInt(st
);
901 gPlayers
[a
].FJetFuel
:= utils
.readLongInt(st
);
903 gPlayers
[a
].FPain
:= utils
.readLongInt(st
);
905 gPlayers
[a
].FKills
:= utils
.readLongInt(st
);
907 gPlayers
[a
].FMonsterKills
:= utils
.readLongInt(st
);
909 gPlayers
[a
].FFrags
:= utils
.readLongInt(st
);
911 gPlayers
[a
].FFragCombo
:= utils
.readByte(st
);
912 // Âðåìÿ ïîñëåäíåãî ôðàãà
913 gPlayers
[a
].FLastFrag
:= utils
.readLongWord(st
);
915 gPlayers
[a
].FDeath
:= utils
.readLongInt(st
);
917 gPlayers
[a
].FFlag
:= utils
.readByte(st
);
919 gPlayers
[a
].FSecrets
:= utils
.readLongInt(st
);
921 gPlayers
[a
].FCurrWeap
:= utils
.readByte(st
);
922 // Ñëåäóþùåå æåëàåìîå îðóæèå
923 gPlayers
[a
].FNextWeap
:= utils
.readWord(st
);
925 gPlayers
[a
].FNextWeapDelay
:= utils
.readByte(st
);
927 gPlayers
[a
].FBFGFireCounter
:= utils
.readSmallInt(st
);
929 gPlayers
[a
].FDamageBuffer
:= utils
.readLongInt(st
);
930 // Ïîñëåäíèé óäàðèâøèé
931 gPlayers
[a
].FLastSpawnerUID
:= utils
.readWord(st
);
932 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
933 gPlayers
[a
].FLastHit
:= utils
.readByte(st
);
935 Obj_LoadState(@gPlayers
[a
].FObj
, st
);
936 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
937 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FAmmo
[i
] := utils
.readWord(st
);
938 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
939 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FMaxAmmo
[i
] := utils
.readWord(st
);
941 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FWeapon
[i
] := utils
.readBool(st
);
942 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
943 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FReloading
[i
] := utils
.readWord(st
);
945 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
946 // Íàëè÷èå êðàñíîãî êëþ÷à
947 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
948 // Íàëè÷èå çåëåíîãî êëþ÷à
949 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
950 // Íàëè÷èå ñèíåãî êëþ÷à
951 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
953 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_BERSERK
);
954 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
955 for i
:= MR_SUIT
to MR_MAX
do gPlayers
[a
].FMegaRulez
[i
] := utils
.readLongWord(st
);
956 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
957 for i
:= T_RESPAWN
to T_FLAGCAP
do gPlayers
[a
].FTime
[i
] := utils
.readLongWord(st
);
960 gPlayers
[a
].FActualModelName
:= utils
.readStr(st
);
962 gPlayers
[a
].FColor
.R
:= utils
.readByte(st
);
963 gPlayers
[a
].FColor
.G
:= utils
.readByte(st
);
964 gPlayers
[a
].FColor
.B
:= utils
.readByte(st
);
965 // Îáíîâëÿåì ìîäåëü èãðîêà
966 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
968 // Íåò ìîäåëè - ñîçäàíèå íåâîçìîæíî
969 if (gPlayers
[a
].FModel
= nil) then
973 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
977 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû
978 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
979 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
981 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
983 result
:= gPlayers
[a
].FUID
;
987 procedure g_Player_ResetTeams();
991 if g_Game_IsClient
then
993 if gPlayers
= nil then
995 for a
:= Low(gPlayers
) to High(gPlayers
) do
996 if gPlayers
[a
] <> nil then
997 case gGameSettings
.GameMode
of
999 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
1001 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
1002 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
1003 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
1006 gPlayers
[a
].ChangeTeam(TEAM_RED
)
1008 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
1011 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
1015 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
1018 _name
, _model
: String;
1021 if not g_Game_IsServer
then Exit
;
1023 // Ñïèñîê íàçâàíèé ìîäåëåé:
1024 m
:= g_PlayerModel_GetNames();
1029 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1030 Team
:= TEAM_COOP
// COOP
1032 if gGameSettings
.GameMode
= GM_DM
then
1033 Team
:= TEAM_NONE
// DM
1035 if Team
= TEAM_NONE
then // CTF / TDM
1037 // Àâòîáàëàíñ êîìàíä:
1041 for a
:= 0 to High(gPlayers
) do
1042 if gPlayers
[a
] <> nil then
1044 if gPlayers
[a
].Team
= TEAM_RED
then
1047 if gPlayers
[a
].Team
= TEAM_BLUE
then
1057 if Random(2) = 0 then
1063 // Âûáèðàåì áîòó èìÿ:
1065 if BotNames
<> nil then
1066 for a
:= 0 to High(BotNames
) do
1067 if g_Player_ValidName(BotNames
[a
]) then
1069 _name
:= BotNames
[a
];
1073 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
1076 _name
:= Format('DFBOT%.2d', [Random(100)]);
1077 until g_Player_ValidName(_name
);
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
1092 1: FDifficult
:= DIFFICULT_EASY
;
1093 2: FDifficult
:= DIFFICULT_MEDIUM
;
1094 else FDifficult
:= DIFFICULT_HARD
;
1097 for a
:= WP_FIRST
to WP_LAST
do
1099 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1100 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1101 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1104 FHandicap
:= Handicap
;
1106 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1108 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1109 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1114 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
1117 _name
, _model
: String;
1120 if not g_Game_IsServer
then Exit
;
1122 // Ñïèñîê íàçâàíèé ìîäåëåé:
1123 m
:= g_PlayerModel_GetNames();
1128 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1129 Team
:= TEAM_COOP
// COOP
1131 if gGameSettings
.GameMode
= GM_DM
then
1132 Team
:= TEAM_NONE
// DM
1134 if Team
= TEAM_NONE
then
1135 Team
:= BotList
[num
].team
; // CTF / TDM
1137 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1138 lName
:= AnsiLowerCase(lName
);
1139 if (num
< 0) or (num
> Length(BotList
)-1) then
1141 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1142 for a
:= 0 to High(BotList
) do
1143 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1152 _name
:= BotList
[num
].name
;
1153 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1154 if not g_Player_ValidName(_name
) then
1156 _name
:= Format('DFBOT%.2d', [Random(100)]);
1157 until g_Player_ValidName(_name
);
1160 _model
:= BotList
[num
].model
;
1161 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1162 if not InSArray(_model
, m
) then
1163 _model
:= m
[Random(Length(m
))];
1166 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1170 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1171 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1172 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1173 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1174 FDifficult
.Cover
:= BotList
[num
].cover
;
1175 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1177 FHandicap
:= Handicap
;
1179 for a
:= WP_FIRST
to WP_LAST
do
1181 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1182 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1183 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1186 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1188 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1192 procedure g_Bot_RemoveAll();
1196 if not g_Game_IsServer
then Exit
;
1197 if gPlayers
= nil then Exit
;
1199 for a
:= 0 to High(gPlayers
) do
1200 if gPlayers
[a
] <> nil then
1201 if gPlayers
[a
] is TBot
then
1203 gPlayers
[a
].Lives
:= 0;
1204 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1205 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1206 g_Player_Remove(gPlayers
[a
].FUID
);
1212 procedure g_Bot_MixNames();
1217 if BotNames
<> nil then
1218 for a
:= 0 to High(BotNames
) do
1220 b
:= Random(Length(BotNames
));
1222 Botnames
[a
] := BotNames
[b
];
1227 procedure g_Player_Remove(UID
: Word);
1231 if gPlayers
= nil then Exit
;
1233 if g_Game_IsServer
and g_Game_IsNet
then
1234 MH_SEND_PlayerDelete(UID
);
1236 for i
:= 0 to High(gPlayers
) do
1237 if gPlayers
[i
] <> nil then
1238 if gPlayers
[i
].FUID
= UID
then
1240 if gPlayers
[i
] is TPlayer
then
1241 TPlayer(gPlayers
[i
]).Free()
1243 TBot(gPlayers
[i
]).Free();
1249 procedure g_Player_Init();
1259 if not FileExists(DataDir
+ BOTNAMES_FILENAME
) then
1262 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1263 AssignFile(F
, DataDir
+ BOTNAMES_FILENAME
);
1274 SetLength(BotNames
, Length(BotNames
)+1);
1275 BotNames
[High(BotNames
)] := s
;
1283 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1284 config
:= TConfig
.CreateFile(DataDir
+ BOTLIST_FILENAME
);
1288 while config
.SectionExists(IntToStr(a
)) do
1290 SetLength(BotList
, Length(BotList
)+1);
1292 with BotList
[High(BotList
)] do
1295 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1297 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1299 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1304 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1305 color
.R
:= StrToIntDef(sa
[0], 0);
1306 color
.G
:= StrToIntDef(sa
[1], 0);
1307 color
.B
:= StrToIntDef(sa
[2], 0);
1308 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1309 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1310 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1311 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1312 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1313 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1314 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1315 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1316 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1317 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1318 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1319 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1320 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1321 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1322 if Length(sa
) = 10 then
1324 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1325 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1326 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1327 if Length(sa
) = 10 then
1329 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1331 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1332 if Length(sa) = 10 then
1334 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1343 procedure g_Player_Free();
1347 if gPlayers
<> nil then
1349 for i
:= 0 to High(gPlayers
) do
1350 if gPlayers
[i
] <> nil then
1352 if gPlayers
[i
] is TPlayer
then
1353 TPlayer(gPlayers
[i
]).Free()
1355 TBot(gPlayers
[i
]).Free();
1366 procedure g_Player_UpdateAll();
1370 if gPlayers
= nil then Exit
;
1372 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1373 for i
:= 0 to High(gPlayers
) do
1375 if gPlayers
[i
] <> nil then
1377 if gPlayers
[i
] is TPlayer
then
1379 gPlayers
[i
].Update();
1380 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1384 // bot updates weapons in `UpdateCombat()`
1385 TBot(gPlayers
[i
]).Update();
1389 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1392 procedure g_Player_DrawAll();
1396 if gPlayers
= nil then Exit
;
1398 for i
:= 0 to High(gPlayers
) do
1399 if gPlayers
[i
] <> nil then
1400 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1401 else TBot(gPlayers
[i
]).Draw();
1404 procedure g_Player_DrawDebug(p
: TPlayer
);
1408 if p
= nil then Exit
;
1409 if (@p
.FObj
) = nil then Exit
;
1411 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1413 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1414 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1415 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1416 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1417 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1418 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1421 procedure g_Player_DrawHealth();
1426 if gPlayers
= nil then Exit
;
1427 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1429 for i
:= 0 to High(gPlayers
) do
1430 if gPlayers
[i
] <> nil then
1432 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1433 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1434 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1435 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1436 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1437 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1441 function g_Player_Get(UID
: Word): TPlayer
;
1447 if gPlayers
= nil then
1450 for a
:= 0 to High(gPlayers
) do
1451 if gPlayers
[a
] <> nil then
1452 if gPlayers
[a
].FUID
= UID
then
1454 Result
:= gPlayers
[a
];
1459 function g_Player_GetCount(): Byte;
1465 if gPlayers
= nil then
1468 for a
:= 0 to High(gPlayers
) do
1469 if gPlayers
[a
] <> nil then
1470 Result
:= Result
+ 1;
1473 function g_Player_GetStats(): TPlayerStatArray
;
1479 if gPlayers
= nil then Exit
;
1481 for a
:= 0 to High(gPlayers
) do
1482 if gPlayers
[a
] <> nil then
1484 SetLength(Result
, Length(Result
)+1);
1485 with Result
[High(Result
)] do
1488 Ping
:= gPlayers
[a
].FPing
;
1489 Loss
:= gPlayers
[a
].FLoss
;
1490 Name
:= gPlayers
[a
].FName
;
1491 Team
:= gPlayers
[a
].FTeam
;
1492 Frags
:= gPlayers
[a
].FFrags
;
1493 Deaths
:= gPlayers
[a
].FDeath
;
1494 Kills
:= gPlayers
[a
].FKills
;
1495 Color
:= gPlayers
[a
].FModel
.Color
;
1496 Lives
:= gPlayers
[a
].FLives
;
1497 Spectator
:= gPlayers
[a
].FSpectator
;
1502 procedure g_Player_ResetReady();
1506 if not g_Game_IsServer
then Exit
;
1507 if gPlayers
= nil then Exit
;
1509 for a
:= 0 to High(gPlayers
) do
1510 if gPlayers
[a
] <> nil then
1512 gPlayers
[a
].FReady
:= False;
1513 if g_Game_IsNet
then
1514 MH_SEND_GameEvent(NET_EV_INTER_READY
, gPlayers
[a
].UID
, 'N');
1518 procedure g_Player_RememberAll
;
1522 for i
:= Low(gPlayers
) to High(gPlayers
) do
1523 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1524 gPlayers
[i
].RememberState
;
1527 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1531 gTeamStat
[TEAM_RED
].Goals
:= 0;
1532 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1534 if gPlayers
<> nil then
1535 for i
:= 0 to High(gPlayers
) do
1536 if gPlayers
[i
] <> nil then
1538 gPlayers
[i
].Reset(Force
);
1540 if gPlayers
[i
] is TPlayer
then
1542 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1543 gPlayers
[i
].Respawn(Silent
)
1545 gPlayers
[i
].Spectate();
1548 TBot(gPlayers
[i
]).Respawn(Silent
);
1552 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1558 if Player
.alive
then
1561 // Ðàçðûâàåì ñâÿçü ñ ïðåæíèì òðóïîì:
1562 if gCorpses
<> nil then
1563 for i
:= 0 to High(gCorpses
) do
1564 if gCorpses
[i
] <> nil then
1565 if gCorpses
[i
].FPlayerUID
= Player
.FUID
then
1566 gCorpses
[i
].FPlayerUID
:= 0;
1568 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1573 if (FHealth
>= -50) or (gGibsCount
= 0) then
1575 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1579 for find_id
:= 0 to High(gCorpses
) do
1580 if gCorpses
[find_id
] = nil then
1587 find_id
:= Random(Length(gCorpses
));
1589 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1590 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1591 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1592 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1593 gCorpses
[find_id
].FPlayerUID
:= FUID
;
1596 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1597 FObj
.Y
+ PLAYER_RECT_CY
,
1598 FModel
.Name
, FModel
.Color
);
1602 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1606 if (gShells
= nil) or (Length(gShells
) = 0) then
1609 with gShells
[CurrentShell
] do
1615 if T
= SHELL_BULLET
then
1617 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1621 Obj
.Rect
.Width
:= 4;
1622 Obj
.Rect
.Height
:= 2;
1626 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1630 Obj
.Rect
.Width
:= 7;
1631 Obj
.Rect
.Height
:= 3;
1637 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1638 positionChanged(); // this updates spatial accelerators
1639 RAngle
:= Random(360);
1640 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1642 if CurrentShell
>= High(gShells
) then
1649 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1652 GibsArray
: TGibsArray
;
1655 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1657 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1659 Blood
:= g_PlayerModel_GetBlood(ModelName
);
1661 for a
:= 0 to High(GibsArray
) do
1662 with gGibs
[CurrentGib
] do
1665 ID
:= GibsArray
[a
].ID
;
1666 MaskID
:= GibsArray
[a
].MaskID
;
1669 Obj
.Rect
:= GibsArray
[a
].Rect
;
1670 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1671 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1672 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1673 positionChanged(); // this updates spatial accelerators
1674 RAngle
:= Random(360);
1676 if gBloodCount
> 0 then
1677 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1678 Random(48), Random(48), Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
1680 if CurrentGib
>= High(gGibs
) then
1687 procedure g_Player_UpdatePhysicalObjects();
1693 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1698 if T
= SHELL_BULLET
then
1699 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1701 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1706 if gGibs
<> nil then
1707 for i
:= 0 to High(gGibs
) do
1708 if gGibs
[i
].alive
then
1712 mr
:= g_Obj_Move(@Obj
, True, False, True);
1713 positionChanged(); // this updates spatial accelerators
1715 if WordBool(mr
and MOVE_FALLOUT
) then
1721 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1722 if WordBool(mr
and MOVE_HITWALL
) then
1723 Obj
.Vel
.X
:= -(vel
.X
div 2);
1724 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1725 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1727 if (Obj
.Vel
.X
>= 0) then
1729 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1730 if RAngle
>= 360 then
1731 RAngle
:= RAngle
mod 360;
1732 end else begin // Counter-clockwise
1733 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1735 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1738 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1739 if gTime
mod (GAME_TICK
*3) = 0 then
1740 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1744 if gCorpses
<> nil then
1745 for i
:= 0 to High(gCorpses
) do
1746 if gCorpses
[i
] <> nil then
1747 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1753 gCorpses
[i
].Update();
1756 if gShells
<> nil then
1757 for i
:= 0 to High(gShells
) do
1758 if gShells
[i
].alive
then
1762 mr
:= g_Obj_Move(@Obj
, True, False, True);
1763 positionChanged(); // this updates spatial accelerators
1765 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1771 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1772 if WordBool(mr
and MOVE_HITWALL
) then
1774 Obj
.Vel
.X
:= -(vel
.X
div 2);
1775 if not WordBool(mr
and MOVE_INWATER
) then
1776 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1778 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1780 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1781 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1782 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1784 if RAngle
mod 90 <> 0 then
1785 RAngle
:= (RAngle
div 90) * 90;
1787 else if not WordBool(mr
and MOVE_INWATER
) then
1788 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1791 if (Obj
.Vel
.X
>= 0) then
1793 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1794 if RAngle
>= 360 then
1795 RAngle
:= RAngle
mod 360;
1796 end else begin // Counter-clockwise
1797 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1799 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1805 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1807 x
:= Obj
.X
+Obj
.Rect
.X
;
1808 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1809 w
:= Obj
.Rect
.Width
;
1810 h
:= Obj
.Rect
.Height
;
1813 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1815 if (dx
<> 0) or (dy
<> 0) then
1824 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1828 w
:= Obj
.Rect
.Width
;
1829 h
:= Obj
.Rect
.Height
;
1832 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1834 if (dx
<> 0) or (dy
<> 0) then
1843 procedure TGib
.positionChanged (); inline; begin end;
1844 procedure TShell
.positionChanged (); inline; begin end;
1847 procedure g_Player_DrawCorpses();
1852 if gGibs
<> nil then
1853 for i
:= 0 to High(gGibs
) do
1854 if gGibs
[i
].alive
then
1857 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1860 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1861 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1863 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1866 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1872 if gCorpses
<> nil then
1873 for i
:= 0 to High(gCorpses
) do
1874 if gCorpses
[i
] <> nil then
1878 procedure g_Player_DrawShells();
1883 if gShells
<> nil then
1884 for i
:= 0 to High(gShells
) do
1885 if gShells
[i
].alive
then
1888 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1894 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1898 procedure g_Player_RemoveAllCorpses();
1904 SetLength(gGibs
, MaxGibs
);
1905 SetLength(gShells
, MaxGibs
);
1909 if gCorpses
<> nil then
1910 for i
:= 0 to High(gCorpses
) do
1914 SetLength(gCorpses
, MaxCorpses
);
1917 procedure g_Player_Corpses_SaveState (st
: TStream
);
1921 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ
1923 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1925 // Êîëè÷åñòâî òðóïîâ
1926 utils
.writeInt(st
, LongInt(count
));
1928 if (count
= 0) then exit
;
1931 for i
:= 0 to High(gCorpses
) do
1933 if gCorpses
[i
] <> nil then
1936 utils
.writeStr(st
, gCorpses
[i
].FModelName
);
1938 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1939 // Ñîõðàíÿåì äàííûå òðóïà:
1940 gCorpses
[i
].SaveState(st
);
1946 procedure g_Player_Corpses_LoadState (st
: TStream
);
1954 g_Player_RemoveAllCorpses();
1956 // Êîëè÷åñòâî òðóïîâ:
1957 count
:= utils
.readLongInt(st
);
1958 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1960 if (count
= 0) then exit
;
1963 for i
:= 0 to count
-1 do
1966 str
:= utils
.readStr(st
);
1968 b
:= utils
.readBool(st
);
1970 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1971 // Çàãðóæàåì äàííûå òðóïà
1972 gCorpses
[i
].LoadState(st
);
1979 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1981 procedure TPlayer
.BFGHit();
1983 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1984 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1985 if g_Game_IsServer
and g_Game_IsNet
then
1986 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1987 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1991 procedure TPlayer
.ChangeModel(ModelName
: string);
1993 locModel
: TPlayerModel
;
1995 locModel
:= g_PlayerModel_Get(ModelName
);
1996 if locModel
= nil then Exit
;
2002 procedure TPlayer
.SetModel(ModelName
: string);
2006 m
:= g_PlayerModel_Get(ModelName
);
2009 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
2010 m
:= g_PlayerModel_Get('doomer');
2013 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
2018 if FModel
<> nil then
2023 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2024 FModel
.Color
:= FColor
2026 FModel
.Color
:= TEAMCOLOR
[FTeam
];
2027 FModel
.SetWeapon(FCurrWeap
);
2028 FModel
.SetFlag(FFlag
);
2029 SetDirection(FDirection
);
2032 procedure TPlayer
.SetColor(Color
: TRGB
);
2035 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2036 if FModel
<> nil then FModel
.Color
:= Color
;
2039 function TPlayer
.GetColor(): TRGB
;
2041 result
:= FModel
.Color
;
2044 procedure TPlayer
.SwitchTeam
;
2046 if g_Game_IsClient
then
2048 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
2050 if gGameOn
and FAlive
then
2051 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
2053 if FTeam
= TEAM_RED
then
2055 ChangeTeam(TEAM_BLUE
);
2056 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
2057 if g_Game_IsNet
then
2058 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
2062 ChangeTeam(TEAM_RED
);
2063 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
2064 if g_Game_IsNet
then
2065 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
2067 FPreferredTeam
:= FTeam
;
2070 procedure TPlayer
.ChangeTeam(Team
: Byte);
2077 TEAM_RED
, TEAM_BLUE
:
2078 FModel
.Color
:= TEAMCOLOR
[Team
];
2080 FModel
.Color
:= FColor
;
2082 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2083 MH_SEND_PlayerStats(FUID
);
2087 procedure TPlayer.CollideItem();
2092 if gItems = nil then Exit;
2093 if not FAlive then Exit;
2095 for i := 0 to High(gItems) do
2098 if (ItemType <> ITEM_NONE) and alive then
2099 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2100 PLAYER_RECT.Height, @Obj) then
2102 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2104 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2105 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2106 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2107 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2108 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2110 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2111 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2112 (gGameSettings.GameType = GT_SINGLE) and
2113 (g_Player_GetCount() > 1)) then
2114 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2120 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2122 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2123 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2127 constructor TPlayer
.Create();
2133 mEDamageType
:= HIT_SOME
;
2139 FSawSound
:= TPlayableSound
.Create();
2140 FSawSoundIdle
:= TPlayableSound
.Create();
2141 FSawSoundHit
:= TPlayableSound
.Create();
2142 FSawSoundSelect
:= TPlayableSound
.Create();
2143 FFlameSoundOn
:= TPlayableSound
.Create();
2144 FFlameSoundOff
:= TPlayableSound
.Create();
2145 FFlameSoundWork
:= TPlayableSound
.Create();
2146 FJetSoundFly
:= TPlayableSound
.Create();
2147 FJetSoundOn
:= TPlayableSound
.Create();
2148 FJetSoundOff
:= TPlayableSound
.Create();
2150 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2151 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2152 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2153 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2154 FFlameSoundOn
.SetByName('SOUND_WEAPON_FLAMEON');
2155 FFlameSoundOff
.SetByName('SOUND_WEAPON_FLAMEOFF');
2156 FFlameSoundWork
.SetByName('SOUND_WEAPON_FLAMEWORK');
2157 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2158 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2159 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2161 FSpectatePlayer
:= -1;
2165 FSavedState
.WaitRecall
:= False;
2172 FActualModelName
:= 'doomer';
2175 FObj
.Rect
:= PLAYER_RECT
;
2177 FBFGFireCounter
:= -1;
2178 FJustTeleported
:= False;
2184 procedure TPlayer
.positionChanged (); inline;
2188 procedure TPlayer
.doDamage (v
: Integer);
2190 if (v
<= 0) then exit
;
2191 if (v
> 32767) then v
:= 32767;
2192 Damage(v
, 0, 0, 0, mEDamageType
);
2195 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2199 if (not g_Game_IsClient
) and (not FAlive
) then
2204 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2205 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2207 if not g_Game_IsClient
then
2210 if t
= HIT_TRAP
then
2212 // Ëîâóøêà óáèâàåò ñðàçó:
2214 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2216 if t
= HIT_SELF
then
2220 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2223 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2224 FMegaRulez
[MR_SUIT
] := 0;
2225 FMegaRulez
[MR_INVUL
] := 0;
2226 FMegaRulez
[MR_INVIS
] := 0;
2230 // Íî îò îñòàëüíîãî ñïàñàåò:
2231 if FMegaRulez
[MR_INVUL
] >= gTime
then
2238 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2239 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2240 (SpawnerUID
= FUID
) or
2241 (not SameTeam(FUID
, SpawnerUID
)) then
2243 FLastSpawnerUID
:= SpawnerUID
;
2245 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2246 if gBloodCount
> 0 then
2248 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2249 if value
div 4 <= c
then
2250 c
:= c
- (value
div 4)
2254 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2258 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2259 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2262 if t
= HIT_WATER
then
2263 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2264 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2269 Inc(FDamageBuffer
, value
);
2273 FPain
:= FPain
+ value
;
2276 if g_Game_IsServer
and g_Game_IsNet
then
2278 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2279 MH_SEND_PlayerStats(FUID
);
2280 MH_SEND_PlayerPos(False, FUID
);
2284 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2287 if g_Game_IsClient
then
2292 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2294 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2297 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2299 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2303 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2304 MH_SEND_PlayerStats(FUID
);
2307 destructor TPlayer
.Destroy();
2309 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2311 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2315 FSawSoundIdle
.Free();
2316 FSawSoundHit
.Free();
2317 FSawSoundSelect
.Free();
2318 FFlameSoundOn
.Free();
2319 FFlameSoundOff
.Free();
2320 FFlameSoundWork
.Free();
2321 FJetSoundFly
.Free();
2323 FJetSoundOff
.Free();
2325 if FPunchAnim
<> nil then
2331 procedure TPlayer
.DrawIndicator(Color
: TRGB
);
2333 indX
, indY
: Integer;
2340 case gPlayerIndicatorStyle
of
2343 if g_Texture_Get('TEXTURE_PLAYER_INDICATOR', ID
) then
2345 e_GetTextureSize(ID
, @indW
, @indH
);
2346 indX
:= FObj
.X
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
- indW
) div 2;
2347 indY
:= FObj
.Y
- indH
;
2351 e_Draw(ID
, indX
, indY
, 0, True, False);
2358 e_TextureFontGetSize(gStdFont
, nW
, nH
);
2359 indX
:= FObj
.X
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
- Length(FName
) * nW
) div 2;
2360 indY
:= FObj
.Y
- nH
;
2361 e_TextureFontPrintEx(indX
, indY
, FName
, gStdFont
, Color
.R
, Color
.G
, Color
.B
, 1.0, True);
2366 procedure TPlayer
.DrawBubble();
2368 bubX
, bubY
: Integer;
2371 Rw
, Gw
, Bw
: SmallInt;
2374 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= TDirection
.D_LEFT
, -4, 18);
2375 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2383 1: // simple textual non-bubble
2385 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2386 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2387 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2390 2: // advanced pixel-perfect bubble
2392 if FTeam
= TEAM_RED
then
2395 if FTeam
= TEAM_BLUE
then
2398 3: // colored bubble
2400 Rb
:= FModel
.Color
.R
;
2401 Gb
:= FModel
.Color
.G
;
2402 Bb
:= FModel
.Color
.B
;
2403 Rw
:= Min(Rb
* 2 + 64, 255);
2404 Gw
:= Min(Gb
* 2 + 64, 255);
2405 Bw
:= Min(Bb
* 2 + 64, 255);
2406 if (Abs(Rw
- Rb
) < 32)
2407 or (Abs(Gw
- Gb
) < 32)
2408 or (Abs(Bw
- Bb
) < 32) then
2410 Rb
:= Max(Rw
div 2 - 16, 0);
2411 Gb
:= Max(Gw
div 2 - 16, 0);
2412 Bb
:= Max(Bw
div 2 - 16, 0);
2415 4: // custom textured bubble
2417 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2418 if FDirection
= TDirection
.D_RIGHT
then
2419 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2421 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, TMirrorType
.Horizontal
);
2427 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2428 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2430 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2433 Dot
:= IfThen(FDirection
= TDirection
.D_LEFT
, 14, 5);
2434 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2435 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
);
2436 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
);
2437 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
);
2438 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
);
2442 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2443 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2444 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2447 procedure TPlayer
.Draw();
2452 Mirror
: TMirrorType
;
2456 if Direction
= TDirection
.D_RIGHT
then
2457 Mirror
:= TMirrorType
.None
2459 Mirror
:= TMirrorType
.Horizontal
;
2461 if FPunchAnim
<> nil then
2463 FPunchAnim
.Draw(FObj
.X
+IfThen(Direction
= TDirection
.D_LEFT
, 15-FObj
.Rect
.X
, FObj
.Rect
.X
-15),
2464 FObj
.Y
+FObj
.Rect
.Y
-11, Mirror
);
2465 if FPunchAnim
.played
then
2472 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2473 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2475 e_GetTextureSize(ID
, @w
, @h
);
2476 if FDirection
= TDirection
.D_LEFT
then
2477 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2478 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False)
2480 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2481 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False);
2484 if FMegaRulez
[MR_INVIS
] > gTime
then
2486 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2487 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2489 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2490 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2494 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 200)
2496 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2499 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 254);
2502 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2505 if g_debug_Frames
then
2507 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2509 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2510 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2514 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2515 if (FMegaRulez
[MR_INVIS
] <= gTime
) or ((gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2516 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
)))) then
2518 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2519 if gAimLine
and alive
and
2520 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2525 procedure TPlayer
.DrawAim();
2526 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2531 {$IFDEF ENABLE_HOLMES}
2532 if isValidViewPort
and (self
= gPlayer1
) then
2534 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2538 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2539 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2541 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2545 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2550 wx
, wy
, xx
, yy
: Integer;
2554 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= TDirection
.D_LEFT
, 7, -7);
2555 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2564 1: begin // Chainsaw
2571 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2572 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2573 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2574 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2579 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2580 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2581 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2582 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2584 4: begin // Double Shotgun
2587 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2588 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2589 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2590 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2592 5: begin // Chaingun
2595 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2596 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2597 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2598 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2600 6: begin // Rocket Launcher
2603 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2604 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2605 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2606 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2608 7: begin // Plasmagun
2611 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2612 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2613 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2614 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2619 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2620 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2621 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2622 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2624 9: begin // Super Chaingun
2627 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2628 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2629 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2630 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2633 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2634 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2635 {$IF DEFINED(D2F_DEBUG)}
2636 drawCast(sz
, wx
, wy
, xx
, yy
);
2638 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2642 procedure TPlayer
.DrawGUI();
2645 X
, Y
, SY
, a
, p
, m
: Integer;
2649 stat
: TPlayerStatArray
;
2651 X
:= gPlayerScreenSize
.X
;
2652 SY
:= gPlayerScreenSize
.Y
;
2655 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2657 if gGameSettings
.GameMode
= GM_CTF
then
2661 if gGameSettings
.GameMode
= GM_CTF
then
2663 s
:= 'TEXTURE_PLAYER_REDFLAG';
2664 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2665 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2666 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2667 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2668 if g_Texture_Get(s
, ID
) then
2669 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2672 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2673 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2674 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2676 if gGameSettings
.GameMode
= GM_CTF
then
2678 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2679 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2680 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2681 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2682 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2683 if g_Texture_Get(s
, ID
) then
2684 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2687 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2688 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2689 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2692 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2693 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2696 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2697 e_Draw(ID
, X
+2, Y
, 0, True, False);
2699 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2703 s
:= IntToStr(Frags
);
2704 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2705 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2710 stat
:= g_Player_GetStats();
2715 for a
:= 0 to High(stat
) do
2716 if stat
[a
].Name
<> Name
then
2718 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2719 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2723 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2724 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2725 s
:= s
+IntToStr(Abs(Frags
-m
));
2727 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2728 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2731 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2733 s
:= IntToStr(Lives
);
2734 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2735 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2739 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2740 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2742 if R_BERSERK
in FRulez
then
2743 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2745 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2747 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2748 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2750 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2751 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2752 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2754 s
:= IntToStr(FArmor
);
2755 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2756 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2758 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2764 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2769 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2771 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2772 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2773 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2774 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2775 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2776 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2777 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2778 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2779 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2782 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2783 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2784 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2786 if R_KEY_RED
in FRulez
then
2787 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2789 if R_KEY_GREEN
in FRulez
then
2790 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2792 if R_KEY_BLUE
in FRulez
then
2793 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2795 if FJetFuel
> 0 then
2797 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2798 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2799 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2800 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2801 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2802 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2806 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2807 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2808 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2811 if gShowPing
and g_Game_IsClient
then
2813 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2814 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2820 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2821 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2822 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2825 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2826 s
:= _lc
[I_PLAYER_SPECT4
];
2827 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2828 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2829 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2835 procedure TPlayer
.DrawRulez();
2839 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2840 if FMegaRulez
[MR_INVUL
] >= gTime
then
2842 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2843 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2848 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2849 191, 191, 191, 0, TBlending
.Invert
);
2852 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2853 if FMegaRulez
[MR_SUIT
] >= gTime
then
2855 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2856 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2861 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2862 0, 96, 0, 200, TBlending
.None
);
2865 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2866 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2868 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2869 255, 0, 0, 200, TBlending
.None
);
2873 procedure TPlayer
.DrawPain();
2877 if FPain
= 0 then Exit
;
2881 if a
< 15 then h
:= 0
2882 else if a
< 35 then h
:= 1
2883 else if a
< 55 then h
:= 2
2884 else if a
< 75 then h
:= 3
2885 else if a
< 95 then h
:= 4
2888 //if a > 255 then a := 255;
2890 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2891 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2894 procedure TPlayer
.DrawPickup();
2898 if FPickup
= 0 then Exit
;
2902 if a
< 15 then h
:= 1
2903 else if a
< 35 then h
:= 2
2904 else if a
< 55 then h
:= 3
2905 else if a
< 75 then h
:= 4
2908 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2911 procedure TPlayer
.DoPunch();
2916 if FPunchAnim
<> nil then begin
2921 st
:= 'FRAMES_PUNCH';
2922 if R_BERSERK
in FRulez
then
2923 st
:= st
+ '_BERSERK';
2924 if FKeys
[KEY_UP
].Pressed
then
2926 else if FKeys
[KEY_DOWN
].Pressed
then
2928 g_Frames_Get(id
, st
);
2929 FPunchAnim
:= TAnimation
.Create(id
, False, 1);
2932 procedure TPlayer
.Fire();
2934 f
, DidFire
: Boolean;
2935 wx
, wy
, xd
, yd
: Integer;
2938 if g_Game_IsClient
then Exit
;
2939 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2940 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2948 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2953 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2954 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2955 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
2956 yd
:= wy
+firediry();
2962 if R_BERSERK
in FRulez
then
2964 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2965 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2966 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2969 locobj
.rect
.Width
:= 39;
2970 locobj
.rect
.Height
:= 52;
2971 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2972 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2973 locobj
.Accel
.X
:= xd
-wx
;
2974 locobj
.Accel
.y
:= yd
-wy
;
2976 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2977 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2979 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2981 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
2985 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2989 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2994 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2995 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2997 FSawSoundSelect
.Stop();
2999 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
3001 else if not FSawSoundHit
.IsPlaying() then
3003 FSawSoundSelect
.Stop();
3004 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
3007 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3013 if FAmmo
[A_BULLETS
] > 0 then
3015 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
3016 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3017 Dec(FAmmo
[A_BULLETS
]);
3018 FFireAngle
:= FAngle
;
3021 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3022 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3026 if FAmmo
[A_SHELLS
] > 0 then
3028 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3029 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
3030 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3031 Dec(FAmmo
[A_SHELLS
]);
3032 FFireAngle
:= FAngle
;
3036 FShellType
:= SHELL_SHELL
;
3040 if FAmmo
[A_SHELLS
] >= 2 then
3042 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
3043 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3044 Dec(FAmmo
[A_SHELLS
], 2);
3045 FFireAngle
:= FAngle
;
3049 FShellType
:= SHELL_DBLSHELL
;
3053 if FAmmo
[A_BULLETS
] > 0 then
3055 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
3056 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
3057 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3058 Dec(FAmmo
[A_BULLETS
]);
3059 FFireAngle
:= FAngle
;
3062 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3063 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3066 WEAPON_ROCKETLAUNCHER
:
3067 if FAmmo
[A_ROCKETS
] > 0 then
3069 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
3070 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3071 Dec(FAmmo
[A_ROCKETS
]);
3072 FFireAngle
:= FAngle
;
3078 if FAmmo
[A_CELLS
] > 0 then
3080 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
3081 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3082 Dec(FAmmo
[A_CELLS
]);
3083 FFireAngle
:= FAngle
;
3089 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
3091 FBFGFireCounter
:= 17;
3092 if not FNoReload
then
3093 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
3094 Dec(FAmmo
[A_CELLS
], 40);
3098 WEAPON_SUPERPULEMET
:
3099 if FAmmo
[A_SHELLS
] > 0 then
3101 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3102 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
3103 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3104 Dec(FAmmo
[A_SHELLS
]);
3105 FFireAngle
:= FAngle
;
3108 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3109 GameVelX
, GameVelY
-2, SHELL_SHELL
);
3112 WEAPON_FLAMETHROWER
:
3113 if FAmmo
[A_FUEL
] > 0 then
3115 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
3117 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3119 FFireAngle
:= FAngle
;
3126 if g_Game_IsNet
and g_Game_IsServer
then MH_SEND_PlayerStats(FUID
);
3130 if g_Game_IsNet
then
3134 if FCurrWeap
<> WEAPON_BFG
then
3135 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
3137 if not FNoReload
then
3138 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
3141 MH_SEND_PlayerStats(FUID
);
3146 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
3147 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
3148 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
3151 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
3154 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
3155 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
3156 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
3157 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
3158 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
3163 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
3165 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
3166 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
3167 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
3170 procedure TPlayer
.FlamerOn
;
3172 FFlameSoundOff
.Stop();
3173 FFlameSoundOff
.SetPosition(0);
3176 if (not FFlameSoundOn
.IsPlaying()) and (not FFlameSoundWork
.IsPlaying()) then
3177 FFlameSoundWork
.PlayAt(FObj
.X
, FObj
.Y
);
3181 FFlameSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3186 procedure TPlayer
.FlamerOff
;
3190 FFlameSoundOn
.Stop();
3191 FFlameSoundOn
.SetPosition(0);
3192 FFlameSoundWork
.Stop();
3193 FFlameSoundWork
.SetPosition(0);
3194 FFlameSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3199 procedure TPlayer
.JetpackOn
;
3203 FJetSoundOn
.SetPosition(0);
3204 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3208 procedure TPlayer
.JetpackOff
;
3212 FJetSoundOff
.SetPosition(0);
3213 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3216 procedure TPlayer
.CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
3218 if Timeout
<= 0 then
3220 if (FMegaRulez
[MR_SUIT
] > gTime
) or (FMegaRulez
[MR_INVUL
] > gTime
) then
3221 exit
; // Íå çàãîðàåìñÿ êîãäà åñòü çàùèòà
3222 if g_Obj_CollidePanel(@FObj
, 0, 0, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
) then
3223 exit
; // Íå ïîäãîðàåì â âîäå íà âñÿêèé ñëó÷àé
3224 if FFireTime
<= 0 then
3225 g_Sound_PlayExAt('SOUND_IGNITE', FObj
.X
, FObj
.Y
);
3226 FFireTime
:= Timeout
;
3227 FFireAttacker
:= Attacker
;
3228 if g_Game_IsNet
and g_Game_IsServer
then
3229 MH_SEND_PlayerStats(FUID
);
3232 procedure TPlayer
.Jump();
3234 if gFly
or FJetpack
then
3236 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3237 if FObj
.Vel
.Y
> -VEL_FLY
then
3238 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3241 if FJetFuel
> 0 then
3243 if (FJetFuel
< 1) and g_Game_IsServer
then
3247 if g_Game_IsNet
then
3248 MH_SEND_PlayerStats(FUID
);
3254 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3256 FCanJetpack
:= False;
3258 // Ïðûãàåì èëè âñïëûâàåì:
3259 if (CollideLevel(0, 1) or
3260 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3261 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3262 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3264 FObj
.Vel
.Y
:= -VEL_JUMP
;
3265 FCanJetpack
:= False;
3269 if BodyInLiquid(0, 0) then
3270 FObj
.Vel
.Y
:= -VEL_SW
3271 else if (FJetFuel
> 0) and FCanJetpack
and
3272 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3276 if g_Game_IsNet
then
3277 MH_SEND_PlayerStats(FUID
);
3282 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3284 a
, i
, k
, ab
, ar
: Byte;
3288 srv
, netsrv
: Boolean;
3294 procedure PushItem(t
: Byte);
3298 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3299 it
:= g_Items_ByIdx(id
);
3300 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3302 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3303 (FObj
.Vel
.Y
div 2)-Random(9));
3304 it
.positionChanged(); // this updates spatial accelerators
3308 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3310 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3311 (FObj
.Vel
.Y
div 2)-Random(6));
3313 else // -3..+3; -3..0
3315 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3316 (FObj
.Vel
.Y
div 2)-Random(4));
3318 it
.positionChanged(); // this updates spatial accelerators
3321 if g_Game_IsNet
and g_Game_IsServer
then
3322 MH_SEND_ItemSpawn(True, id
);
3326 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3327 Srv
:= g_Game_IsServer
;
3328 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3329 if Srv
then FDeath
:= FDeath
+ 1;
3334 if not FPhysics
then
3340 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3342 if FLives
> 0 then FLives
:= FLives
- 1;
3343 if FLives
= 0 then FNoRespawn
:= True;
3346 // Íîìåð òèïà ñìåðòè:
3349 K_SIMPLEKILL
: a
:= 1;
3351 K_EXTRAHARDKILL
: a
:= 3;
3356 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3358 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3365 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3367 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3368 K_EXTRAHARDKILL
, K_FALLKILL
:
3369 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3372 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3376 K_HARDKILL
, K_EXTRAHARDKILL
:
3380 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3381 if (KillType
<> K_FALLKILL
) and (Srv
) then
3382 g_Monsters_killedp();
3384 if SpawnerUID
= FUID
then
3386 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3391 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3394 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3395 begin // Óáèò äðóãèì èãðîêîì
3396 KP
:= g_Player_Get(SpawnerUID
);
3397 if (KP
<> nil) and Srv
then
3399 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3400 if SameTeam(FUID
, SpawnerUID
) then
3410 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3411 Inc(gTeamStat
[KP
.Team
].Goals
,
3412 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3414 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3417 plr
:= g_Player_Get(SpawnerUID
);
3425 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3429 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3433 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3438 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3439 begin // Óáèò ìîíñòðîì
3440 mon
:= g_Monsters_ByUID(SpawnerUID
);
3444 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
3448 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3452 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3456 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3461 else // Îñîáûå òèïû ñìåðòè
3464 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3465 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3466 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3467 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3468 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3469 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3475 for a
:= WP_FIRST
to WP_LAST
do
3479 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3480 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3481 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3482 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3483 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3484 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3485 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3486 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3487 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3496 if R_ITEM_BACKPACK
in FRulez
then
3497 PushItem(ITEM_AMMO_BACKPACK
);
3499 // Âûáðîñ ðàêåòíîãî ðàíöà:
3500 if FJetFuel
> 0 then
3501 PushItem(ITEM_JETPACK
);
3504 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3506 if R_KEY_RED
in FRulez
then
3507 PushItem(ITEM_KEY_RED
);
3509 if R_KEY_GREEN
in FRulez
then
3510 PushItem(ITEM_KEY_GREEN
);
3512 if R_KEY_BLUE
in FRulez
then
3513 PushItem(ITEM_KEY_BLUE
);
3517 DropFlag(KillType
= K_FALLKILL
);
3520 g_Player_CreateCorpse(Self
);
3522 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3523 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3529 for i
:= Low(gPlayers
) to High(gPlayers
) do
3531 if gPlayers
[i
] = nil then continue
;
3532 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3535 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3536 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3541 OldLR
:= gLMSRespawn
;
3542 if (gGameSettings
.GameMode
= GM_COOP
) then
3546 // everyone is dead, restart the map
3547 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3549 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3550 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3551 gLMSRespawnTime
:= gTime
+ 5000;
3553 else if (a
= 1) then
3555 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3556 if (gPlayers
[k
] = gPlayer1
) or
3557 (gPlayers
[k
] = gPlayer2
) then
3558 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3559 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3560 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3563 else if (gGameSettings
.GameMode
= GM_TDM
) then
3565 if (ab
= 0) and (ar
<> 0) then
3568 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3570 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3571 Inc(gTeamStat
[TEAM_RED
].Goals
);
3572 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3573 gLMSRespawnTime
:= gTime
+ 5000;
3575 else if (ar
= 0) and (ab
<> 0) then
3578 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3580 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3581 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3582 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3583 gLMSRespawnTime
:= gTime
+ 5000;
3585 else if (ar
= 0) and (ab
= 0) then
3588 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3590 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3591 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3592 gLMSRespawnTime
:= gTime
+ 5000;
3595 else if (gGameSettings
.GameMode
= GM_DM
) then
3599 if gPlayers
[k
] <> nil then
3602 // survivor is the winner
3603 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3605 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3608 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3609 gLMSRespawnTime
:= gTime
+ 5000;
3611 else if (a
= 0) then
3613 // everyone is dead, restart the map
3614 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3616 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3617 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3618 gLMSRespawnTime
:= gTime
+ 5000;
3621 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3623 if NetMode
= NET_SERVER
then
3624 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3626 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3632 MH_SEND_PlayerStats(FUID
);
3633 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3634 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3637 if srv
and FNoRespawn
then Spectate(True);
3638 FWantsInGame
:= True;
3641 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3643 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3644 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3647 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3649 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3650 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3653 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3655 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3656 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3657 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3658 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3659 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3660 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3661 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3662 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3665 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3667 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3668 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3669 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3670 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3673 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3675 if g_Game_IsClient
then Exit
;
3676 if Weapon
> High(FWeapon
) then Exit
;
3677 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3680 procedure TPlayer
.resetWeaponQueue ();
3683 FNextWeapDelay
:= 0;
3686 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3690 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3691 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 0);
3692 WEAPON_PISTOL
, WEAPON_CHAINGUN
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_BULLETS
] > 0);
3693 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3694 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3695 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3696 else result
:= (weapon
< length(FWeapon
));
3700 // return 255 for "no switch"
3701 function TPlayer
.getNextWeaponIndex (): Byte;
3704 wantThisWeapon
: array[0..64] of Boolean;
3705 wwc
: Integer = 0; //HACK!
3708 result
:= 255; // default result: "no switch"
3709 // had weapon cycling on previous frame? remove that flag
3710 if (FNextWeap
and $2000) <> 0 then
3712 FNextWeap
:= FNextWeap
and $1FFF;
3713 FNextWeapDelay
:= 0;
3715 // cycling has priority
3716 if (FNextWeap
and $C000) <> 0 then
3718 if (FNextWeap
and $8000) <> 0 then
3722 FNextWeap
:= FNextWeap
or $2000; // we need this
3723 if FNextWeapDelay
> 0 then
3724 exit
; // cooldown time
3726 for i
:= 0 to High(FWeapon
) do
3728 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3729 if FWeapon
[cwi
] then
3731 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d', [FCurrWeap, cwi]), MSG_WARNING);
3732 result
:= Byte(cwi
);
3733 FNextWeapDelay
:= WEAPON_DELAY
;
3741 for i
:= 0 to High(wantThisWeapon
) do
3742 wantThisWeapon
[i
] := false;
3743 for i
:= 0 to High(FWeapon
) do
3744 if (FNextWeap
and (1 shl i
)) <> 0 then
3746 wantThisWeapon
[i
] := true;
3749 // exclude currently selected weapon from the set
3750 wantThisWeapon
[FCurrWeap
] := false;
3751 // slow down alterations a little
3754 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3755 // more than one weapon requested, assume "alteration" and check alteration delay
3756 if FNextWeapDelay
> 0 then
3762 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3763 // but clear all counters if no weapon should be switched
3769 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3770 // try weapons in descending order
3771 for i
:= High(FWeapon
) downto 0 do
3773 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3778 FNextWeapDelay
:= WEAPON_DELAY
* 2; // anyway, 'cause why not
3782 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3786 procedure TPlayer
.RealizeCurrentWeapon();
3787 function switchAllowed (): Boolean;
3792 if FBFGFireCounter
<> -1 then
3794 if FTime
[T_SWITCH
] > gTime
then
3796 for i
:= WP_FIRST
to WP_LAST
do
3797 if FReloading
[i
] > 0 then
3805 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3806 //FNextWeap := FNextWeap and $1FFF;
3807 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3809 if not switchAllowed
then
3811 //HACK for weapon cycling
3812 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3816 nw
:= getNextWeaponIndex();
3817 if nw
= 255 then exit
; // don't reset anything here
3818 if nw
> High(FWeapon
) then
3820 // don't forget to reset queue here!
3821 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3829 FTime
[T_SWITCH
] := gTime
+156;
3830 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3831 FModel
.SetWeapon(FCurrWeap
);
3832 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3836 procedure TPlayer
.NextWeapon();
3838 if g_Game_IsClient
then Exit
;
3842 procedure TPlayer
.PrevWeapon();
3844 if g_Game_IsClient
then Exit
;
3848 procedure TPlayer
.SetWeapon(W
: Byte);
3850 if FCurrWeap
<> W
then
3851 if W
= WEAPON_SAW
then
3852 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3855 FModel
.SetWeapon(CurrWeap
);
3859 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3861 function allowBerserkSwitching (): Boolean;
3863 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3865 if gBerserkAutoswitch
then exit
;
3866 if not conIsCheatsEnabled
then exit
;
3874 if g_Game_IsClient
then Exit
;
3876 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3877 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3882 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3884 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3888 if gFlash
= 2 then Inc(FPickup
, 5);
3892 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3894 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3898 if gFlash
= 2 then Inc(FPickup
, 5);
3902 if FArmor
< PLAYER_AP_SOFT
then
3904 FArmor
:= PLAYER_AP_SOFT
;
3907 if gFlash
= 2 then Inc(FPickup
, 5);
3911 if FArmor
< PLAYER_AP_LIMIT
then
3913 FArmor
:= PLAYER_AP_LIMIT
;
3916 if gFlash
= 2 then Inc(FPickup
, 5);
3920 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
3922 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3926 if gFlash
= 2 then Inc(FPickup
, 5);
3930 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) or (FFireTime
> 0) then
3932 if FHealth
< PLAYER_HP_LIMIT
then
3933 FHealth
:= PLAYER_HP_LIMIT
;
3934 if FArmor
< PLAYER_AP_LIMIT
then
3935 FArmor
:= PLAYER_AP_LIMIT
;
3939 if gFlash
= 2 then Inc(FPickup
, 5);
3943 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3945 FWeapon
[WEAPON_SAW
] := True;
3947 if gFlash
= 2 then Inc(FPickup
, 5);
3948 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3951 ITEM_WEAPON_SHOTGUN1
:
3952 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3954 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3955 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3957 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3958 FWeapon
[WEAPON_SHOTGUN1
] := True;
3960 if gFlash
= 2 then Inc(FPickup
, 5);
3961 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3964 ITEM_WEAPON_SHOTGUN2
:
3965 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3967 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3969 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3970 FWeapon
[WEAPON_SHOTGUN2
] := True;
3972 if gFlash
= 2 then Inc(FPickup
, 5);
3973 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3976 ITEM_WEAPON_CHAINGUN
:
3977 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3979 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3981 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3982 FWeapon
[WEAPON_CHAINGUN
] := True;
3984 if gFlash
= 2 then Inc(FPickup
, 5);
3985 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3988 ITEM_WEAPON_ROCKETLAUNCHER
:
3989 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3991 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3993 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3994 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3996 if gFlash
= 2 then Inc(FPickup
, 5);
3997 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4001 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
4003 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
4005 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4006 FWeapon
[WEAPON_PLASMA
] := True;
4008 if gFlash
= 2 then Inc(FPickup
, 5);
4009 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4013 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
4015 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
4017 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4018 FWeapon
[WEAPON_BFG
] := True;
4020 if gFlash
= 2 then Inc(FPickup
, 5);
4021 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4024 ITEM_WEAPON_SUPERPULEMET
:
4025 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
4027 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
4029 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4030 FWeapon
[WEAPON_SUPERPULEMET
] := True;
4032 if gFlash
= 2 then Inc(FPickup
, 5);
4033 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4036 ITEM_WEAPON_FLAMETHROWER
:
4037 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
4039 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
4041 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4042 FWeapon
[WEAPON_FLAMETHROWER
] := True;
4044 if gFlash
= 2 then Inc(FPickup
, 5);
4045 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4049 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4051 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4054 if gFlash
= 2 then Inc(FPickup
, 5);
4057 ITEM_AMMO_BULLETS_BOX
:
4058 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4060 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4063 if gFlash
= 2 then Inc(FPickup
, 5);
4067 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4069 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4072 if gFlash
= 2 then Inc(FPickup
, 5);
4075 ITEM_AMMO_SHELLS_BOX
:
4076 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4078 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
4081 if gFlash
= 2 then Inc(FPickup
, 5);
4085 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4087 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4090 if gFlash
= 2 then Inc(FPickup
, 5);
4093 ITEM_AMMO_ROCKET_BOX
:
4094 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4096 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
4099 if gFlash
= 2 then Inc(FPickup
, 5);
4103 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4105 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4108 if gFlash
= 2 then Inc(FPickup
, 5);
4112 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4114 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4117 if gFlash
= 2 then Inc(FPickup
, 5);
4121 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4123 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4126 if gFlash
= 2 then Inc(FPickup
, 5);
4130 if not(R_ITEM_BACKPACK
in FRulez
) or
4131 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4132 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4133 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4134 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4135 (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) then
4137 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4138 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4139 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4140 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4141 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4143 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4144 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4145 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4146 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4147 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4148 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4149 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4150 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4151 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4152 IncMax(FAmmo
[A_FUEL
], 50, FMaxAmmo
[A_FUEL
]);
4154 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
4157 if gFlash
= 2 then Inc(FPickup
, 5);
4161 if not(R_KEY_RED
in FRulez
) then
4163 Include(FRulez
, R_KEY_RED
);
4165 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4166 if gFlash
= 2 then Inc(FPickup
, 5);
4167 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4171 if not(R_KEY_GREEN
in FRulez
) then
4173 Include(FRulez
, R_KEY_GREEN
);
4175 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4176 if gFlash
= 2 then Inc(FPickup
, 5);
4177 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4181 if not(R_KEY_BLUE
in FRulez
) then
4183 Include(FRulez
, R_KEY_BLUE
);
4185 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4186 if gFlash
= 2 then Inc(FPickup
, 5);
4187 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4191 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4193 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4197 if gFlash
= 2 then Inc(FPickup
, 5);
4201 if FAir
< AIR_MAX
then
4206 if gFlash
= 2 then Inc(FPickup
, 5);
4211 if not (R_BERSERK
in FRulez
) then
4213 Include(FRulez
, R_BERSERK
);
4214 if allowBerserkSwitching
then
4216 FCurrWeap
:= WEAPON_KASTET
;
4218 FModel
.SetWeapon(WEAPON_KASTET
);
4223 if gFlash
= 2 then Inc(FPickup
, 5);
4225 FBerserk
:= gTime
+30000;
4230 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
4232 if FHealth
< PLAYER_HP_SOFT
then FHealth
:= PLAYER_HP_SOFT
;
4233 FBerserk
:= gTime
+30000;
4241 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4243 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4246 if gFlash
= 2 then Inc(FPickup
, 5);
4250 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
4252 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4256 if gFlash
= 2 then Inc(FPickup
, 5);
4260 if FArmor
< PLAYER_AP_LIMIT
then
4262 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4265 if gFlash
= 2 then Inc(FPickup
, 5);
4269 if FJetFuel
< JET_MAX
then
4271 FJetFuel
:= JET_MAX
;
4274 if gFlash
= 2 then Inc(FPickup
, 5);
4278 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4280 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4283 if gFlash
= 2 then Inc(FPickup
, 5);
4288 procedure TPlayer
.Touch();
4292 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4295 // Áðîñèòü ôëàã òîâàðèùó:
4296 if gGameSettings
.GameMode
= GM_CTF
then
4301 procedure TPlayer
.Push(vx
, vy
: Integer);
4303 if (not FPhysics
) and FGhost
then
4305 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4306 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4307 if g_Game_IsNet
and g_Game_IsServer
then
4308 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4311 procedure TPlayer
.Reset(Force
: Boolean);
4317 FTime
[T_RESPAWN
] := 0;
4318 FTime
[T_FLAGCAP
] := 0;
4332 FSpectator
:= False;
4335 FSpectatePlayer
:= -1;
4336 FNoRespawn
:= False;
4338 FLives
:= gGameSettings
.MaxLives
;
4343 procedure TPlayer
.SoftReset();
4349 FBFGFireCounter
:= -1;
4357 SetAction(A_STAND
, True);
4360 function TPlayer
.GetRespawnPoint(): Byte;
4365 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4367 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4368 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4370 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4372 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4373 if Self
= gPlayer1
then
4374 c
:= RESPAWNPOINT_PLAYER1
4376 c
:= RESPAWNPOINT_PLAYER2
;
4377 if g_Map_GetPointCount(c
) > 0 then
4383 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4384 if Self
= gPlayer1
then
4385 c
:= RESPAWNPOINT_PLAYER2
4387 c
:= RESPAWNPOINT_PLAYER1
;
4388 if g_Map_GetPointCount(c
) > 0 then
4395 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4396 if Random(2) = 0 then
4397 c
:= RESPAWNPOINT_PLAYER1
4399 c
:= RESPAWNPOINT_PLAYER2
;
4400 if g_Map_GetPointCount(c
) > 0 then
4407 // Òî÷êà ëþáîé èç êîìàíä
4408 if Random(2) = 0 then
4409 c
:= RESPAWNPOINT_RED
4411 c
:= RESPAWNPOINT_BLUE
;
4412 if g_Map_GetPointCount(c
) > 0 then
4419 c
:= RESPAWNPOINT_DM
;
4420 if g_Map_GetPointCount(c
) > 0 then
4428 if gGameSettings
.GameMode
= GM_DM
then
4431 c
:= RESPAWNPOINT_DM
;
4432 if g_Map_GetPointCount(c
) > 0 then
4438 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4439 if Random(2) = 0 then
4440 c
:= RESPAWNPOINT_PLAYER1
4442 c
:= RESPAWNPOINT_PLAYER2
;
4443 if g_Map_GetPointCount(c
) > 0 then
4449 // Òî÷êà ëþáîé èç êîìàíä
4450 if Random(2) = 0 then
4451 c
:= RESPAWNPOINT_RED
4453 c
:= RESPAWNPOINT_BLUE
;
4454 if g_Map_GetPointCount(c
) > 0 then
4462 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4464 // Òî÷êà ñâîåé êîìàíäû
4465 c
:= RESPAWNPOINT_DM
;
4466 if FTeam
= TEAM_RED
then
4467 c
:= RESPAWNPOINT_RED
;
4468 if FTeam
= TEAM_BLUE
then
4469 c
:= RESPAWNPOINT_BLUE
;
4470 if g_Map_GetPointCount(c
) > 0 then
4477 c
:= RESPAWNPOINT_DM
;
4478 if g_Map_GetPointCount(c
) > 0 then
4484 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4485 if Random(2) = 0 then
4486 c
:= RESPAWNPOINT_PLAYER1
4488 c
:= RESPAWNPOINT_PLAYER2
;
4489 if g_Map_GetPointCount(c
) > 0 then
4495 // Òî÷êà äðóãîé êîìàíäû
4496 c
:= RESPAWNPOINT_DM
;
4497 if FTeam
= TEAM_RED
then
4498 c
:= RESPAWNPOINT_BLUE
;
4499 if FTeam
= TEAM_BLUE
then
4500 c
:= RESPAWNPOINT_RED
;
4501 if g_Map_GetPointCount(c
) > 0 then
4509 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4511 RespawnPoint
: TRespawnPoint
;
4517 FBFGFireCounter
:= -1;
4522 if not g_Game_IsServer
then
4526 FWantsInGame
:= True;
4527 FJustTeleported
:= True;
4530 FTime
[T_RESPAWN
] := 0;
4534 // if server changes MaxLives we gotta be ready
4535 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4537 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4538 if FTime
[T_RESPAWN
] > gTime
then
4541 // Ïðîñðàë âñå æèçíè:
4544 if not FSpectator
then Spectate(True);
4545 FWantsInGame
:= True;
4549 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4550 begin // "Ñâîÿ èãðà"
4551 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4552 FRulez
:= FRulez
-[R_BERSERK
];
4554 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4556 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4557 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4560 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4561 c
:= GetRespawnPoint();
4566 // Âîñêðåøåíèå áåç îðóæèÿ:
4569 FHealth
:= Round(PLAYER_HP_SOFT
* (FHandicap
/ 100));
4575 for a
:= WP_FIRST
to WP_LAST
do
4577 FWeapon
[a
] := False;
4581 FWeapon
[WEAPON_PISTOL
] := True;
4582 FWeapon
[WEAPON_KASTET
] := True;
4583 FCurrWeap
:= WEAPON_PISTOL
;
4586 FModel
.SetWeapon(FCurrWeap
);
4588 for b
:= A_BULLETS
to A_HIGH
do
4591 FAmmo
[A_BULLETS
] := 50;
4593 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4594 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4595 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4596 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4597 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4599 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4600 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4605 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4606 if not g_Map_GetPoint(c
, RespawnPoint
) then
4608 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4612 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4613 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4614 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4620 FDirection
:= RespawnPoint
.Direction
;
4621 if FDirection
= TDirection
.D_LEFT
then
4626 SetAction(A_STAND
, True);
4627 FModel
.Direction
:= FDirection
;
4629 for a
:= Low(FTime
) to High(FTime
) do
4632 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4637 FCanJetpack
:= False;
4643 // Àíèìàöèÿ âîçðîæäåíèÿ:
4644 if (not gLoadGameMode
) and (not Silent
) then
4645 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4647 Anim
:= TAnimation
.Create(ID
, False, 3);
4648 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4649 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4653 FSpectator
:= False;
4656 FSpectatePlayer
:= -1;
4659 if (gPlayer1
= nil) and (gLMSPID1
= FUID
) then
4661 if (gPlayer2
= nil) and (gLMSPID2
= FUID
) then
4664 if g_Game_IsNet
then
4666 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4667 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4669 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4670 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4675 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4678 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4679 else if (not NoMove
) then
4681 GameX
:= gMapInfo
.Width
div 2;
4682 GameY
:= gMapInfo
.Height
div 2;
4691 FWantsInGame
:= False;
4696 if Self
= gPlayer1
then
4701 if Self
= gPlayer2
then
4708 if g_Game_IsNet
then
4709 MH_SEND_PlayerStats(FUID
);
4712 procedure TPlayer
.SwitchNoClip
;
4716 FGhost
:= not FGhost
;
4717 FPhysics
:= not FGhost
;
4729 procedure TPlayer
.Run(Direction
: TDirection
);
4733 if MAX_RUNVEL
> 8 then
4737 if Direction
= TDirection
.D_LEFT
then
4739 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4740 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4743 if FObj
.Vel
.X
< MAX_RUNVEL
then
4744 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4746 // Âîçìîæíî, ïèíàåì êóñêè:
4747 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4749 b
:= Abs(FObj
.Vel
.X
);
4750 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4751 for a
:= 0 to High(gGibs
) do
4753 if gGibs
[a
].alive
and
4754 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4755 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4758 if FObj
.Vel
.X
< 0 then
4760 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4764 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4766 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4774 procedure TPlayer
.SeeDown();
4776 SetAction(A_SEEDOWN
);
4778 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4780 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4783 procedure TPlayer
.SeeUp();
4787 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4789 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4792 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4800 A_ATTACK
: Prior
:= 2;
4801 A_SEEUP
: Prior
:= 1;
4802 A_SEEDOWN
: Prior
:= 1;
4803 A_ATTACKUP
: Prior
:= 2;
4804 A_ATTACKDOWN
: Prior
:= 2;
4809 if (Prior
> FActionPrior
) or Force
then
4810 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4812 FActionPrior
:= Prior
;
4813 FActionAnim
:= Action
;
4814 FActionForce
:= Force
;
4815 FActionChanged
:= True;
4818 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4821 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4823 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4824 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4825 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4826 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4829 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4836 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4838 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4839 if g_Game_IsServer
and g_Game_IsNet
then
4840 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4844 FJustTeleported
:= True;
4849 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4851 Anim
:= TAnimation
.Create(ID
, False, 3);
4854 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4855 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4856 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4857 if g_Game_IsServer
and g_Game_IsNet
then
4858 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4859 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4863 FObj
.X
:= X
-PLAYER_RECT
.X
;
4864 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4865 if FAlive
and FGhost
then
4871 if not g_Game_IsNet
then
4875 SetDirection(TDirection
.D_LEFT
);
4881 SetDirection(TDirection
.D_RIGHT
);
4887 if FDirection
= TDirection
.D_RIGHT
then
4889 SetDirection(TDirection
.D_LEFT
);
4894 SetDirection(TDirection
.D_RIGHT
);
4900 if not silent
and (Anim
<> nil) then
4902 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4903 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4906 if g_Game_IsServer
and g_Game_IsNet
then
4907 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4908 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4915 function nonz(a
: Single): Single;
4923 function TPlayer
.followCorpse(): Boolean;
4928 if FAlive
or FSpectator
then
4930 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
4932 for i
:= 0 to High(gCorpses
) do
4933 if gCorpses
[i
] <> nil then
4934 if gCorpses
[i
].FPlayerUID
= FUID
then
4937 FObj
.X
:= gCorpses
[i
].FObj
.X
;
4938 FObj
.Y
:= gCorpses
[i
].FObj
.Y
;
4939 FObj
.Vel
.X
:= gCorpses
[i
].FObj
.Vel
.X
;
4940 FObj
.Vel
.Y
:= gCorpses
[i
].FObj
.Vel
.Y
;
4941 FObj
.Accel
.X
:= gCorpses
[i
].FObj
.Accel
.X
;
4942 FObj
.Accel
.Y
:= gCorpses
[i
].FObj
.Accel
.Y
;
4947 procedure TPlayer
.Update();
4950 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4951 blockmon
, headwater
, dospawn
: Boolean;
4956 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4957 AnyServer
:= g_Game_IsServer
;
4959 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4960 DoLerp(NetInterpLevel
+ 1)
4966 if FClientID
>= 0 then
4968 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4969 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4970 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4979 if FAlive
and (FPunchAnim
<> nil) then
4980 FPunchAnim
.Update();
4982 if FAlive
and (gFly
or FJetpack
) then
4985 if FDirection
= TDirection
.D_LEFT
then
4990 if FAlive
and (not FGhost
) then
4992 if FKeys
[KEY_UP
].Pressed
then
4994 if FKeys
[KEY_DOWN
].Pressed
then
4998 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
5001 i
:= g_basic
.Sign(FIncCam
);
5002 FIncCam
:= Abs(FIncCam
);
5003 DecMin(FIncCam
, 5, 0);
5004 FIncCam
:= FIncCam
*i
;
5007 // no need to do that each second frame, weapon queue will take care of it
5008 if FAlive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
5009 if FAlive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
5011 if gTime
mod (GAME_TICK
*2) <> 0 then
5013 if (FObj
.Vel
.X
= 0) and FAlive
then
5015 if FKeys
[KEY_LEFT
].Pressed
then
5016 Run(TDirection
.D_LEFT
);
5017 if FKeys
[KEY_RIGHT
].Pressed
then
5018 Run(TDirection
.D_RIGHT
);
5023 if not followCorpse() then
5024 g_Obj_Move(@FObj
, True, True, True);
5025 positionChanged(); // this updates spatial accelerators
5031 FActionChanged
:= False;
5035 // Let alive player do some actions
5036 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
5037 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
5038 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
5039 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
5040 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire()
5046 if NetServer
then MH_SEND_PlayerStats(FUID
);
5049 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
5050 if FKeys
[KEY_JUMP
].Pressed
then Jump()
5053 if AnyServer
and FJetpack
then
5057 if NetServer
then MH_SEND_PlayerStats(FUID
);
5059 FCanJetpack
:= True;
5066 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
5068 if FKeys
[k
].Pressed
then
5076 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5079 if (FTime
[T_RESPAWN
] <= gTime
) and
5080 gGameOn
and (not FAlive
) then
5082 if (g_Player_GetCount() > 1) then
5086 gExit
:= EXIT_RESTART
;
5091 // Dead spectator actions
5094 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
5095 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
5099 if (FSpectatePlayer
>= High(gPlayers
)) then
5100 FSpectatePlayer
:= -1
5104 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
5105 if gPlayers
[I
] <> nil then
5106 if gPlayers
[I
].alive
then
5107 if gPlayers
[I
].UID
<> FUID
then
5109 FSpectatePlayer
:= I
;
5114 if not SetSpect
then FSpectatePlayer
:= -1;
5125 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5127 FYTo
:= FObj
.Y
- 32;
5128 FSpectatePlayer
:= -1;
5130 if FKeys
[KEY_DOWN
].Pressed
then
5132 FYTo
:= FObj
.Y
+ 32;
5133 FSpectatePlayer
:= -1;
5135 if FKeys
[KEY_LEFT
].Pressed
then
5137 FXTo
:= FObj
.X
- 32;
5138 FSpectatePlayer
:= -1;
5140 if FKeys
[KEY_RIGHT
].Pressed
then
5142 FXTo
:= FObj
.X
+ 32;
5143 FSpectatePlayer
:= -1;
5146 if (FXTo
< -64) then
5148 else if (FXTo
> gMapInfo
.Width
+ 32) then
5149 FXTo
:= gMapInfo
.Width
+ 32;
5150 if (FYTo
< -72) then
5152 else if (FYTo
> gMapInfo
.Height
+ 32) then
5153 FYTo
:= gMapInfo
.Height
+ 32;
5158 if not followCorpse() then
5159 g_Obj_Move(@FObj
, True, True, True);
5160 positionChanged(); // this updates spatial accelerators
5167 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5168 if gPlayers
[FSpectatePlayer
] <> nil then
5169 if gPlayers
[FSpectatePlayer
].alive
then
5171 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
5172 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
5176 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5177 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5178 PANEL_BLOCKMON
, True);
5179 headwater
:= HeadInLiquid(0, 0);
5181 // Ñîïðîòèâëåíèå âîçäóõà:
5182 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5183 if FObj
.Vel
.X
<> 0 then
5184 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5186 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5187 DecMin(FPain
, 5, 0);
5188 DecMin(FPickup
, 1, 0);
5190 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5192 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5193 FMegaRulez
[MR_SUIT
] := 0;
5194 FMegaRulez
[MR_INVUL
] := 0;
5195 FMegaRulez
[MR_INVIS
] := 0;
5196 Kill(K_FALLKILL
, 0, HIT_FALL
);
5203 if FCurrWeap
= WEAPON_SAW
then
5204 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5205 FSawSoundSelect
.IsPlaying()) then
5206 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5209 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5210 (not FJetSoundOff
.IsPlaying()) then
5212 FJetSoundFly
.SetPosition(0);
5213 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5216 for b
:= WP_FIRST
to WP_LAST
do
5217 if FReloading
[b
] > 0 then
5223 if FShellTimer
> -1 then
5224 if FShellTimer
= 0 then
5226 if FShellType
= SHELL_SHELL
then
5227 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5228 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5229 else if FShellType
= SHELL_DBLSHELL
then
5231 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5232 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5233 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5234 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5237 end else Dec(FShellTimer
);
5239 if (FBFGFireCounter
> -1) then
5240 if FBFGFireCounter
= 0 then
5244 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5245 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5246 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5247 yd
:= wy
+firediry();
5248 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5249 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5250 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5251 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5252 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5255 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5256 FBFGFireCounter
:= -1;
5259 FBFGFireCounter
:= 0
5261 Dec(FBFGFireCounter
);
5263 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5265 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5267 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5270 if (headwater
or blockmon
) then
5276 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5279 else if (FAir
mod 31 = 0) and not blockmon
then
5281 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5282 if Random(2) = 0 then
5283 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5285 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5287 end else if FAir
< AIR_DEF
then
5290 if FFireTime
> 0 then
5292 if BodyInLiquid(0, 0) then
5297 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5299 if FMegaRulez
[MR_SUIT
] = gTime
then
5306 if FFirePainTime
<= 0 then
5308 if g_Game_IsServer
then
5309 Damage(2, FFireAttacker
, 0, 0, HIT_FLAME
);
5310 FFirePainTime
:= 12 - FFireTime
div 12;
5312 FFirePainTime
:= FFirePainTime
- 1;
5313 FFireTime
:= FFireTime
- 1;
5314 if ((FFireTime
mod 33) = 0) and (FMegaRulez
[MR_INVUL
] < gTime
) then
5315 FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
);
5316 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5317 MH_SEND_PlayerStats(FUID
);
5321 if FDamageBuffer
> 0 then
5323 if FDamageBuffer
>= 9 then
5327 if FDamageBuffer
< 30 then i
:= 9
5328 else if FDamageBuffer
< 100 then i
:= 18
5332 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5333 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5334 FHealth
:= FHealth
-ii
;
5337 FHealth
:= FHealth
+FArmor
;
5342 if FHealth
<= 0 then
5343 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5344 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5345 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5347 if FAlive
and ((FLastHit
<> HIT_FLAME
) or (FFireTime
<= 0)) then
5349 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5350 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5351 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5352 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5359 end; // if FAlive then ...
5361 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5363 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5364 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5365 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5366 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5368 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5369 then SetAction(A_STAND
, True);
5371 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5373 for b
:= Low(FKeys
) to High(FKeys
) do
5374 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5378 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5380 x
:= FObj
.X
+PLAYER_RECT
.X
;
5381 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5382 w
:= PLAYER_RECT
.Width
;
5383 h
:= PLAYER_RECT
.Height
;
5387 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5389 if (dx
<> 0) or (dy
<> 0) then
5398 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5400 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5401 FObj
.Y
+PLAYER_RECT
.Y
,
5408 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5410 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5411 FObj
.Y
+PLAYER_RECT
.Y
,
5415 Panel
.Width
, Panel
.Height
);
5418 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5420 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5421 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5422 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5423 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5426 function g_Player_ValidName(Name
: string): Boolean;
5432 if gPlayers
= nil then Exit
;
5434 for a
:= 0 to High(gPlayers
) do
5435 if gPlayers
[a
] <> nil then
5436 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5443 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5447 d
:= FModel
.Direction
;
5449 FModel
.Direction
:= Direction
;
5450 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5452 FDirection
:= Direction
;
5455 function TPlayer
.GetKeys(): Byte;
5459 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5460 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5461 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5463 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5464 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5467 procedure TPlayer
.Use();
5471 if FTime
[T_USE
] > gTime
then Exit
;
5473 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5474 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5476 for a
:= 0 to High(gPlayers
) do
5477 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5478 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5479 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5480 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5482 gPlayers
[a
].Touch();
5483 if g_Game_IsNet
and g_Game_IsServer
then
5484 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5487 FTime
[T_USE
] := gTime
+120;
5490 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5494 WX
, WY
, XD
, YD
: Integer;
5506 if R_BERSERK
in FRulez
then
5508 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5509 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5510 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5513 locobj
.rect
.Width
:= 39;
5514 locobj
.rect
.Height
:= 52;
5515 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5516 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5517 locobj
.Accel
.X
:= xd
-wx
;
5518 locobj
.Accel
.y
:= yd
-wy
;
5520 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5521 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5523 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5527 FPain
:= min(FPain
+ 25, 50);
5529 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5534 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5535 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5537 FSawSoundSelect
.Stop();
5539 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5541 else if not FSawSoundHit
.IsPlaying() then
5543 FSawSoundSelect
.Stop();
5544 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5551 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5552 FFireAngle
:= FAngle
;
5554 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5555 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5560 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5561 FFireAngle
:= FAngle
;
5564 FShellType
:= SHELL_SHELL
;
5569 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5570 FFireAngle
:= FAngle
;
5573 FShellType
:= SHELL_DBLSHELL
;
5578 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5579 FFireAngle
:= FAngle
;
5581 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5582 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5585 WEAPON_ROCKETLAUNCHER
:
5587 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5588 FFireAngle
:= FAngle
;
5594 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5595 FFireAngle
:= FAngle
;
5601 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5602 FFireAngle
:= FAngle
;
5606 WEAPON_SUPERPULEMET
:
5608 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5609 FFireAngle
:= FAngle
;
5611 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5612 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5615 WEAPON_FLAMETHROWER
:
5617 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5619 FFireAngle
:= FAngle
;
5626 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5627 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5628 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5631 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5633 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5634 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5637 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5641 if NetInterpLevel
< 1 then
5651 AX
:= Abs(FXTo
- FObj
.X
);
5652 AY
:= Abs(FYTo
- FObj
.Y
);
5653 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5655 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5660 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5662 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5663 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5664 PANEL_LIFTUP
, False) then Result
:= -1
5666 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5667 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5668 PANEL_LIFTDOWN
, False) then Result
:= 1
5672 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5679 if Flag
= FLAG_NONE
then
5682 if not g_Game_IsServer
then Exit
;
5684 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5685 if (Flag
= FTeam
) and
5686 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5687 (FFlag
<> FLAG_NONE
) then
5689 if FFlag
= FLAG_RED
then
5690 s
:= _lc
[I_PLAYER_FLAG_RED
]
5692 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5694 evtype
:= FLAG_STATE_SCORED
;
5696 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5697 Insert('.', ts
, Length(ts
) + 1 - 3);
5698 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5700 g_Map_ResetFlag(FFlag
);
5701 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5703 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5704 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5705 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5710 if not sound_cap_flag
[a
].IsPlaying() then
5711 sound_cap_flag
[a
].Play();
5713 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5716 if g_Game_IsNet
then
5718 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5722 gFlags
[FFlag
].CaptureTime
:= 0;
5727 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5728 if (Flag
= FTeam
) and
5729 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5731 if Flag
= FLAG_RED
then
5732 s
:= _lc
[I_PLAYER_FLAG_RED
]
5734 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5736 evtype
:= FLAG_STATE_RETURNED
;
5737 gFlags
[Flag
].CaptureTime
:= 0;
5739 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5741 g_Map_ResetFlag(Flag
);
5742 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5744 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5745 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5746 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5751 if not sound_ret_flag
[a
].IsPlaying() then
5752 sound_ret_flag
[a
].Play();
5755 if g_Game_IsNet
then
5757 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5763 // Ïîäîáðàë ÷óæîé ôëàã:
5764 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5768 if Flag
= FLAG_RED
then
5769 s
:= _lc
[I_PLAYER_FLAG_RED
]
5771 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5773 evtype
:= FLAG_STATE_CAPTURED
;
5775 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5777 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5779 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5781 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5782 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5783 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5788 if not sound_get_flag
[a
].IsPlaying() then
5789 sound_get_flag
[a
].Play();
5792 if g_Game_IsNet
then
5794 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5800 procedure TPlayer
.SetFlag(Flag
: Byte);
5803 if FModel
<> nil then
5804 FModel
.SetFlag(FFlag
);
5807 function TPlayer
.DropFlag(Silent
: Boolean = True): Boolean;
5813 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5815 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5816 with gFlags
[FFlag
] do
5820 Direction
:= FDirection
;
5821 State
:= FLAG_STATE_DROPPED
;
5823 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5824 (FObj
.Vel
.Y
div 2)-2+Random(5));
5825 positionChanged(); // this updates spatial accelerators
5827 if FFlag
= FLAG_RED
then
5828 s
:= _lc
[I_PLAYER_FLAG_RED
]
5830 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5832 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5833 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5835 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5836 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5837 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5842 if (not Silent
) and (not sound_lost_flag
[a
].IsPlaying()) then
5843 sound_lost_flag
[a
].Play();
5845 if g_Game_IsNet
then
5846 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5852 procedure TPlayer
.GetSecret();
5854 if (self
= gPlayer1
) or (self
= gPlayer2
) then
5856 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [FName
]), True);
5857 g_Sound_PlayEx('SOUND_GAME_SECRET');
5862 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5864 Assert(Key
<= High(FKeys
));
5866 FKeys
[Key
].Pressed
:= True;
5867 FKeys
[Key
].Time
:= Time
;
5870 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5872 Result
:= FKeys
[K
].Pressed
;
5875 procedure TPlayer
.ReleaseKeys();
5879 for a
:= Low(FKeys
) to High(FKeys
) do
5881 FKeys
[a
].Pressed
:= False;
5886 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5890 function TPlayer
.firediry(): Integer;
5892 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5893 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5897 procedure TPlayer
.RememberState();
5901 FSavedState
.Health
:= FHealth
;
5902 FSavedState
.Armor
:= FArmor
;
5903 FSavedState
.Air
:= FAir
;
5904 FSavedState
.JetFuel
:= FJetFuel
;
5905 FSavedState
.CurrWeap
:= FCurrWeap
;
5906 FSavedState
.NextWeap
:= FNextWeap
;
5907 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5910 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5912 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5914 FSavedState
.Rulez
:= FRulez
;
5915 FSavedState
.WaitRecall
:= True;
5918 procedure TPlayer
.RecallState();
5922 if not FSavedState
.WaitRecall
then Exit
;
5924 FHealth
:= FSavedState
.Health
;
5925 FArmor
:= FSavedState
.Armor
;
5926 FAir
:= FSavedState
.Air
;
5927 FJetFuel
:= FSavedState
.JetFuel
;
5928 FCurrWeap
:= FSavedState
.CurrWeap
;
5929 FNextWeap
:= FSavedState
.NextWeap
;
5930 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5933 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5935 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5937 FRulez
:= FSavedState
.Rulez
;
5938 FSavedState
.WaitRecall
:= False;
5940 if gGameSettings
.GameType
= GT_SERVER
then
5941 MH_SEND_PlayerStats(FUID
);
5944 procedure TPlayer
.SaveState (st
: TStream
);
5950 utils
.writeSign(st
, 'PLYR');
5951 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
5953 utils
.writeBool(st
, FIamBot
);
5955 utils
.writeInt(st
, Word(FUID
));
5957 utils
.writeStr(st
, FName
);
5959 utils
.writeInt(st
, Byte(FTeam
));
5961 utils
.writeBool(st
, FAlive
);
5962 // Èçðàñõîäîâàë ëè âñå æèçíè
5963 utils
.writeBool(st
, FNoRespawn
);
5965 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
5966 utils
.writeInt(st
, Byte(b
));
5968 utils
.writeInt(st
, LongInt(FHealth
));
5969 // Êîýôôèöèåíò èíâàëèäíîñòè
5970 utils
.writeInt(st
, LongInt(FHandicap
));
5972 utils
.writeInt(st
, Byte(FLives
));
5974 utils
.writeInt(st
, LongInt(FArmor
));
5976 utils
.writeInt(st
, LongInt(FAir
));
5978 utils
.writeInt(st
, LongInt(FJetFuel
));
5980 utils
.writeInt(st
, LongInt(FPain
));
5982 utils
.writeInt(st
, LongInt(FKills
));
5984 utils
.writeInt(st
, LongInt(FMonsterKills
));
5986 utils
.writeInt(st
, LongInt(FFrags
));
5988 utils
.writeInt(st
, Byte(FFragCombo
));
5989 // Âðåìÿ ïîñëåäíåãî ôðàãà
5990 utils
.writeInt(st
, LongWord(FLastFrag
));
5992 utils
.writeInt(st
, LongInt(FDeath
));
5994 utils
.writeInt(st
, Byte(FFlag
));
5996 utils
.writeInt(st
, LongInt(FSecrets
));
5998 utils
.writeInt(st
, Byte(FCurrWeap
));
6000 utils
.writeInt(st
, Word(FNextWeap
));
6002 utils
.writeInt(st
, Byte(FNextWeapDelay
));
6003 // Âðåìÿ çàðÿäêè BFG
6004 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
6006 utils
.writeInt(st
, LongInt(FDamageBuffer
));
6007 // Ïîñëåäíèé óäàðèâøèé
6008 utils
.writeInt(st
, Word(FLastSpawnerUID
));
6009 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6010 utils
.writeInt(st
, Byte(FLastHit
));
6012 Obj_SaveState(st
, @FObj
);
6013 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6014 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
6015 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6016 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
6018 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
6019 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6020 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
6022 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
6023 // Íàëè÷èå êðàñíîãî êëþ÷à
6024 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
6025 // Íàëè÷èå çåëåíîãî êëþ÷à
6026 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
6027 // Íàëè÷èå ñèíåãî êëþ÷à
6028 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
6030 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
6031 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6032 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
6033 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6034 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
6036 utils
.writeStr(st
, FModel
.Name
);
6038 utils
.writeInt(st
, Byte(FColor
.R
));
6039 utils
.writeInt(st
, Byte(FColor
.G
));
6040 utils
.writeInt(st
, Byte(FColor
.B
));
6044 procedure TPlayer
.LoadState (st
: TStream
);
6053 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
6054 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
6056 FIamBot
:= utils
.readBool(st
);
6058 FUID
:= utils
.readWord(st
);
6060 str
:= utils
.readStr(st
);
6061 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
6063 FTeam
:= utils
.readByte(st
);
6065 FAlive
:= utils
.readBool(st
);
6066 // Èçðàñõîäîâàë ëè âñå æèçíè
6067 FNoRespawn
:= utils
.readBool(st
);
6069 b
:= utils
.readByte(st
);
6070 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
6072 FHealth
:= utils
.readLongInt(st
);
6073 // Êîýôôèöèåíò èíâàëèäíîñòè
6074 FHandicap
:= utils
.readLongInt(st
);
6076 FLives
:= utils
.readByte(st
);
6078 FArmor
:= utils
.readLongInt(st
);
6080 FAir
:= utils
.readLongInt(st
);
6082 FJetFuel
:= utils
.readLongInt(st
);
6084 FPain
:= utils
.readLongInt(st
);
6086 FKills
:= utils
.readLongInt(st
);
6088 FMonsterKills
:= utils
.readLongInt(st
);
6090 FFrags
:= utils
.readLongInt(st
);
6092 FFragCombo
:= utils
.readByte(st
);
6093 // Âðåìÿ ïîñëåäíåãî ôðàãà
6094 FLastFrag
:= utils
.readLongWord(st
);
6096 FDeath
:= utils
.readLongInt(st
);
6098 FFlag
:= utils
.readByte(st
);
6100 FSecrets
:= utils
.readLongInt(st
);
6102 FCurrWeap
:= utils
.readByte(st
);
6104 FNextWeap
:= utils
.readWord(st
);
6106 FNextWeapDelay
:= utils
.readByte(st
);
6107 // Âðåìÿ çàðÿäêè BFG
6108 FBFGFireCounter
:= utils
.readSmallInt(st
);
6110 FDamageBuffer
:= utils
.readLongInt(st
);
6111 // Ïîñëåäíèé óäàðèâøèé
6112 FLastSpawnerUID
:= utils
.readWord(st
);
6113 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6114 FLastHit
:= utils
.readByte(st
);
6116 Obj_LoadState(@FObj
, st
);
6117 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6118 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
6119 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6120 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
6122 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
6123 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6124 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
6126 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
6127 // Íàëè÷èå êðàñíîãî êëþ÷à
6128 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
6129 // Íàëè÷èå çåëåíîãî êëþ÷à
6130 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
6131 // Íàëè÷èå ñèíåãî êëþ÷à
6132 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
6134 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
6135 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6136 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
6137 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6138 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
6140 str
:= utils
.readStr(st
);
6142 FColor
.R
:= utils
.readByte(st
);
6143 FColor
.G
:= utils
.readByte(st
);
6144 FColor
.B
:= utils
.readByte(st
);
6145 if (self
= gPlayer1
) then
6147 str
:= gPlayer1Settings
.Model
;
6148 FColor
:= gPlayer1Settings
.Color
;
6150 else if (self
= gPlayer2
) then
6152 str
:= gPlayer2Settings
.Model
;
6153 FColor
:= gPlayer2Settings
.Color
;
6155 // Îáíîâëÿåì ìîäåëü èãðîêà
6157 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
6158 FModel
.Color
:= TEAMCOLOR
[FTeam
]
6160 FModel
.Color
:= FColor
;
6164 procedure TPlayer
.AllRulez(Health
: Boolean);
6170 FHealth
:= PLAYER_HP_LIMIT
;
6171 FArmor
:= PLAYER_AP_LIMIT
;
6175 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
6176 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
6177 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6180 procedure TPlayer
.RestoreHealthArmor();
6182 FHealth
:= PLAYER_HP_LIMIT
;
6183 FArmor
:= PLAYER_AP_LIMIT
;
6186 procedure TPlayer
.FragCombo();
6190 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6192 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6194 if FFragCombo
< 5 then
6196 Param
:= FUID
or (FFragCombo
shl 16);
6197 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6198 (FComboEvnt
<= High(gDelayedEvents
)) and
6199 gDelayedEvents
[FComboEvnt
].Pending
and
6200 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6201 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6203 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6204 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6207 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6215 procedure TPlayer
.GiveItem(ItemType
: Byte);
6219 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6221 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6225 if FAir
< AIR_MAX
then
6232 if not (R_BERSERK
in FRulez
) then
6234 Include(FRulez
, R_BERSERK
);
6235 if FBFGFireCounter
< 1 then
6237 FCurrWeap
:= WEAPON_KASTET
;
6239 FModel
.SetWeapon(WEAPON_KASTET
);
6243 FBerserk
:= gTime
+30000;
6245 if FHealth
< PLAYER_HP_SOFT
then
6247 FHealth
:= PLAYER_HP_SOFT
;
6248 FBerserk
:= gTime
+30000;
6253 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6255 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6259 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6261 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6265 if FJetFuel
< JET_MAX
then
6267 FJetFuel
:= JET_MAX
;
6270 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6271 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6273 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6274 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6276 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6278 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6280 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6281 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6284 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6285 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6286 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6287 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6288 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6289 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6290 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6291 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6292 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6294 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6295 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6296 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6297 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6298 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6299 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6300 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6301 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6302 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6305 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6306 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6307 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6308 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6309 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6311 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6312 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6313 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6314 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6315 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6317 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6318 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6319 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6320 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6322 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6325 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6326 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6327 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6329 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6330 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6335 if g_Game_IsNet
and g_Game_IsServer
then
6336 MH_SEND_PlayerStats(FUID
);
6339 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6344 if (Random(5) = 1) and (Times
= 1) then
6347 if BodyInLiquid(0, 0) then
6349 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6350 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6351 if Random(2) = 0 then
6352 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6354 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6358 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6360 for i
:= 1 to Times
do
6362 Anim
:= TAnimation
.Create(id
, False, 3);
6364 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6365 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6371 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6376 if (Random(10) = 1) and (Times
= 1) then
6379 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6381 for i
:= 1 to Times
do
6383 Anim
:= TAnimation
.Create(id
, False, 3);
6385 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6386 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6392 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6394 FSawSound
.Pause(Enable
);
6395 FSawSoundIdle
.Pause(Enable
);
6396 FSawSoundHit
.Pause(Enable
);
6397 FSawSoundSelect
.Pause(Enable
);
6398 FFlameSoundOn
.Pause(Enable
);
6399 FFlameSoundOff
.Pause(Enable
);
6400 FFlameSoundWork
.Pause(Enable
);
6401 FJetSoundFly
.Pause(Enable
);
6402 FJetSoundOn
.Pause(Enable
);
6403 FJetSoundOff
.Pause(Enable
);
6408 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6413 FObj
.Rect
:= PLAYER_CORPSERECT
;
6414 FModelName
:= ModelName
;
6419 FState
:= CORPSE_STATE_MESS
;
6420 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6424 FState
:= CORPSE_STATE_NORMAL
;
6425 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6429 destructor TCorpse
.Destroy();
6436 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6438 procedure TCorpse
.positionChanged (); inline; begin end;
6440 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6442 if (dx
<> 0) or (dy
<> 0) then
6451 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6453 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6454 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6455 w
:= PLAYER_CORPSERECT
.Width
;
6456 h
:= PLAYER_CORPSERECT
.Height
;
6460 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6465 if FState
= CORPSE_STATE_REMOVEME
then
6468 FDamage
:= FDamage
+ Value
;
6470 if FDamage
> 150 then
6472 if FAnimation
<> nil then
6477 FState
:= CORPSE_STATE_REMOVEME
;
6479 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6480 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6481 FModelName
, FColor
);
6482 // Çâóê ìÿñà îò òðóïà:
6483 pm
:= g_PlayerModel_Get(FModelName
);
6484 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6488 if (gBodyKillEvent
<> -1)
6489 and gDelayedEvents
[gBodyKillEvent
].Pending
then
6490 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
6491 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, 0);
6496 Blood
:= g_PlayerModel_GetBlood(FModelName
);
6497 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6498 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6499 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6500 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6501 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6502 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
6506 procedure TCorpse
.Draw();
6508 if FState
= CORPSE_STATE_REMOVEME
then
6511 if FAnimation
<> nil then
6512 FAnimation
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6514 if FAnimationMask
<> nil then
6517 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6524 procedure TCorpse
.Update();
6528 if FState
= CORPSE_STATE_REMOVEME
then
6531 if gTime
mod (GAME_TICK
*2) <> 0 then
6533 g_Obj_Move(@FObj
, True, True, True);
6534 positionChanged(); // this updates spatial accelerators
6538 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6539 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6541 st
:= g_Obj_Move(@FObj
, True, True, True);
6542 positionChanged(); // this updates spatial accelerators
6544 if WordBool(st
and MOVE_FALLOUT
) then
6546 FState
:= CORPSE_STATE_REMOVEME
;
6550 if FAnimation
<> nil then
6551 FAnimation
.Update();
6552 if FAnimationMask
<> nil then
6553 FAnimationMask
.Update();
6557 procedure TCorpse
.SaveState (st
: TStream
);
6564 utils
.writeSign(st
, 'CORP');
6565 utils
.writeInt(st
, Byte(0));
6567 utils
.writeInt(st
, Byte(FState
));
6569 utils
.writeInt(st
, Byte(FDamage
));
6571 utils
.writeInt(st
, Byte(FColor
.R
));
6572 utils
.writeInt(st
, Byte(FColor
.G
));
6573 utils
.writeInt(st
, Byte(FColor
.B
));
6575 Obj_SaveState(st
, @FObj
);
6576 utils
.writeInt(st
, Word(FPlayerUID
));
6578 anim
:= (FAnimation
<> nil);
6579 utils
.writeBool(st
, anim
);
6580 // Åñëè åñòü - ñîõðàíÿåì
6581 if anim
then FAnimation
.SaveState(st
);
6582 // Åñòü ëè ìàñêà àíèìàöèè
6583 anim
:= (FAnimationMask
<> nil);
6584 utils
.writeBool(st
, anim
);
6585 // Åñëè åñòü - ñîõðàíÿåì
6586 if anim
then FAnimationMask
.SaveState(st
);
6590 procedure TCorpse
.LoadState (st
: TStream
);
6597 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6598 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6600 FState
:= utils
.readByte(st
);
6602 FDamage
:= utils
.readByte(st
);
6604 FColor
.R
:= utils
.readByte(st
);
6605 FColor
.G
:= utils
.readByte(st
);
6606 FColor
.B
:= utils
.readByte(st
);
6608 Obj_LoadState(@FObj
, st
);
6609 FPlayerUID
:= utils
.readWord(st
);
6611 anim
:= utils
.readBool(st
);
6612 // Åñëè åñòü - çàãðóæàåì
6615 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6616 FAnimation
.LoadState(st
);
6618 // Åñòü ëè ìàñêà àíèìàöèè
6619 anim
:= utils
.readBool(st
);
6620 // Åñëè åñòü - çàãðóæàåì
6623 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6624 FAnimationMask
.LoadState(st
);
6630 constructor TBot
.Create();
6637 FSpectator
:= False;
6644 for a
:= WP_FIRST
to WP_LAST
do
6646 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6647 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6648 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6652 destructor TBot
.Destroy();
6655 inherited Destroy();
6658 procedure TBot
.Draw();
6662 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6663 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6666 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6668 inherited Respawn(Silent
, Force
);
6671 FSelectedWeapon
:= FCurrWeap
;
6676 procedure TBot
.UpdateCombat();
6689 TTargetRecord
= array of TTarget
;
6691 function Compare(a
, b
: TTarget
): Integer;
6693 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6696 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6698 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6699 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6701 if a
.Dist
> b
.Dist
then // B áëèæå
6703 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6706 else // Ñòðàííî -> A
6711 a
, x1
, y1
, x2
, y2
: Integer;
6712 targets
: TTargetRecord
;
6714 Target
, BestTarget
: TTarget
;
6715 firew
, fireh
: Integer;
6719 vsPlayer
, vsMonster
, ok
: Boolean;
6722 function monsUpdate (mon
: TMonster
): Boolean;
6724 result
:= false; // don't stop
6725 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6727 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6729 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6730 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6732 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6733 if g_TraceVector(x1
, y1
, x2
, y2
) then
6735 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6736 SetLength(targets
, Length(targets
)+1);
6737 with targets
[High(targets
)] do
6744 Rect
:= mon
.Obj
.Rect
;
6745 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6746 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6747 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6756 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6757 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6759 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6760 if FCurrWeap
<> FSelectedWeapon
then
6763 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6764 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6766 RemoveAIFlag('NEEDFIRE');
6769 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6770 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6771 else PressKey(KEY_FIRE
);
6775 // Êîîðäèíàòû ñòâîëà:
6776 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6777 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6779 Target
.UID
:= FTargetUID
;
6782 if Target
.UID
<> 0 then
6783 begin // Öåëü åñòü - íàñòðàèâàåì
6784 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6787 tpla
:= g_Player_Get(Target
.UID
);
6791 if (@FObj
) <> nil then
6798 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6799 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6800 Target
.Rect
:= PLAYER_RECT
;
6801 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6802 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6803 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6804 Target
.IsPlayer
:= True;
6808 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6811 mon
:= g_Monsters_ByUID(Target
.UID
);
6814 Target
.X
:= mon
.Obj
.X
;
6815 Target
.Y
:= mon
.Obj
.Y
;
6817 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6818 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6819 Target
.Rect
:= mon
.Obj
.Rect
;
6820 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6821 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6822 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6823 Target
.IsPlayer
:= False;
6830 begin // Öåëè íåò - îáíóëÿåì
6835 Target
.Visible
:= False;
6836 Target
.Line
:= False;
6837 Target
.IsPlayer
:= False;
6842 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6843 if (not Target
.Line
) or (not Target
.Visible
) then
6847 for a
:= 0 to High(gPlayers
) do
6848 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6849 (gPlayers
[a
].FUID
<> FUID
) and
6850 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6851 (not gPlayers
[a
].NoTarget
) and
6852 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6854 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6855 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6858 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6859 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6861 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6862 if g_TraceVector(x1
, y1
, x2
, y2
) then
6864 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6865 SetLength(targets
, Length(targets
)+1);
6866 with targets
[High(targets
)] do
6868 UID
:= gPlayers
[a
].FUID
;
6869 X
:= gPlayers
[a
].FObj
.X
;
6870 Y
:= gPlayers
[a
].FObj
.Y
;
6873 Rect
:= PLAYER_RECT
;
6874 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6875 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6876 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6884 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6887 // Åñëè åñòü âîçìîæíûå öåëè:
6888 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6889 if targets
<> nil then
6891 // Âûáèðàåì íàèëó÷øóþ öåëü:
6892 BestTarget
:= targets
[0];
6893 if Length(targets
) > 1 then
6894 for a
:= 1 to High(targets
) do
6895 if Compare(BestTarget
, targets
[a
]) = 1 then
6896 BestTarget
:= targets
[a
];
6898 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6899 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6900 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6902 Target
:= BestTarget
;
6904 if (Healthy() = 3) or ((Healthy() = 2)) then
6905 begin // Åñëè çäîðîâû - äîãîíÿåì
6906 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6907 SetAIFlag('GORIGHT', '1');
6908 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6909 SetAIFlag('GOLEFT', '1');
6912 begin // Åñëè ïîáèòû - óáåãàåì
6913 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6914 SetAIFlag('GORIGHT', '1');
6915 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6916 SetAIFlag('GOLEFT', '1');
6919 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6920 SelectWeapon(Abs(x1
-Target
.cX
));
6925 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6926 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6927 if Target
.UID
<> 0 then
6929 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6930 Target
.Y
+ Target
.Rect
.Y
) then
6931 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6932 if (Healthy() = 3) or ((Healthy() = 2)) then
6933 begin // Åñëè çäîðîâû - äîãîíÿåì
6934 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6935 SetAIFlag('GORIGHT', '1');
6936 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6937 SetAIFlag('GOLEFT', '1');
6940 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6942 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6943 SetAIFlag('GORIGHT', '1');
6944 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6945 SetAIFlag('GOLEFT', '1');
6949 begin // Öåëü ïîêà íà "ýêðàíå"
6950 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6951 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6952 FLastVisible
:= gTime
;
6953 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6954 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6956 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6957 SetAIFlag('GORIGHT', '1');
6958 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6959 SetAIFlag('GOLEFT', '1');
6963 // Âûáèðàåì óãîë ââåðõ:
6964 if FDirection
= TDirection
.D_LEFT
then
6965 angle
:= ANGLE_LEFTUP
6967 angle
:= ANGLE_RIGHTUP
;
6969 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6970 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6972 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6973 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6974 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6975 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6976 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6977 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6978 begin // òî íóæíî ñòðåëÿòü ââåðõ
6979 SetAIFlag('NEEDFIRE', '1');
6980 SetAIFlag('NEEDSEEUP', '1');
6983 // Âûáèðàåì óãîë âíèç:
6984 if FDirection
= TDirection
.D_LEFT
then
6985 angle
:= ANGLE_LEFTDOWN
6987 angle
:= ANGLE_RIGHTDOWN
;
6989 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6990 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6992 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6993 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6994 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6995 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6996 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6997 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6998 begin // òî íóæíî ñòðåëÿòü âíèç
6999 SetAIFlag('NEEDFIRE', '1');
7000 SetAIFlag('NEEDSEEDOWN', '1');
7003 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
7004 if Target
.Visible
and
7005 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
7006 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
7008 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
7009 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
7010 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
7011 begin // òî íóæíî ñòðåëÿòü âïåðåä
7012 SetAIFlag('NEEDFIRE', '1');
7013 SetAIFlag('NEEDSEEDOWN', '');
7014 SetAIFlag('NEEDSEEUP', '');
7016 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
7017 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
7018 if GetRnd(FDifficult
.CloseJump
) then
7019 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
7020 if Abs(FObj
.X
-Target
.X
) < 128 then
7024 if Random(a
) = 0 then
7025 SetAIFlag('NEEDJUMP', '1');
7029 // Åñëè öåëü âñå åùå åñòü:
7030 if Target
.UID
<> 0 then
7031 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
7032 Target
.UID
:= 0 // òî çàáûòü öåëü
7033 else // Åñëè âèäåëè íåäàâíî
7034 begin // íî öåëü óáèëè
7035 if Target
.IsPlayer
then
7036 begin // Öåëü - èãðîê
7037 pla
:= g_Player_Get(Target
.UID
);
7038 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
7039 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
7040 Target
.UID
:= 0; // òî çàáûòü öåëü
7043 begin // Öåëü - ìîíñòð
7044 mon
:= g_Monsters_ByUID(Target
.UID
);
7045 if (mon
= nil) or (not mon
.alive
) then
7046 Target
.UID
:= 0; // òî çàáûòü öåëü
7049 end; // if Target.UID <> 0
7051 FTargetUID
:= Target
.UID
;
7053 // Åñëè âîçìîæíûõ öåëåé íåò:
7054 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
7055 if targets
= nil then
7056 if GetAIFlag('ATTACKLEFT') <> '' then
7057 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
7058 RemoveAIFlag('ATTACKLEFT');
7060 SetAIFlag('NEEDJUMP', '1');
7062 if RunDirection() = TDirection
.D_RIGHT
then
7063 begin // Èäåì íå â òó ñòîðîíó
7064 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7065 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
7066 SetAIFlag('NEEDFIRE', '1');
7067 SetAIFlag('GOLEFT', '1');
7071 begin // Èäåì â íóæíóþ ñòîðîíó
7072 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7073 SetAIFlag('NEEDFIRE', '1');
7074 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7075 SetAIFlag('GORIGHT', '1');
7079 if GetAIFlag('ATTACKRIGHT') <> '' then
7080 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
7081 RemoveAIFlag('ATTACKRIGHT');
7083 SetAIFlag('NEEDJUMP', '1');
7085 if RunDirection() = TDirection
.D_LEFT
then
7086 begin // Èäåì íå â òó ñòîðîíó
7087 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7088 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
7089 SetAIFlag('NEEDFIRE', '1');
7090 SetAIFlag('GORIGHT', '1');
7095 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7096 SetAIFlag('NEEDFIRE', '1');
7097 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7098 SetAIFlag('GOLEFT', '1');
7102 //HACK! (does it belongs there?)
7103 RealizeCurrentWeapon();
7105 // Åñëè åñòü âîçìîæíûå öåëè:
7106 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7107 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7108 for a
:= 0 to High(targets
) do
7110 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7111 if GetRnd(FDifficult
.DiagFire
) then
7113 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7114 if FDirection
= TDirection
.D_LEFT
then
7115 angle
:= ANGLE_LEFTUP
7117 angle
:= ANGLE_RIGHTUP
;
7119 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7120 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7122 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7123 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7124 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7125 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7126 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7128 SetAIFlag('NEEDFIRE', '1');
7129 SetAIFlag('NEEDSEEUP', '1');
7132 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7133 if FDirection
= TDirection
.D_LEFT
then
7134 angle
:= ANGLE_LEFTDOWN
7136 angle
:= ANGLE_RIGHTDOWN
;
7138 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7139 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7141 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7142 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7143 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7144 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7145 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7147 SetAIFlag('NEEDFIRE', '1');
7148 SetAIFlag('NEEDSEEDOWN', '1');
7152 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7153 if targets
[a
].Line
and targets
[a
].Visible
and
7154 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
7155 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
7157 SetAIFlag('NEEDFIRE', '1');
7162 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7163 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
7164 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
7165 40+GetInterval(FDifficult
.Cover
, 40)) then
7166 SetAIFlag('NEEDJUMP', '1');
7168 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7169 ammo
:= GetAmmoByWeapon(FCurrWeap
);
7170 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
7171 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
7173 SetAIFlag('SELECTWEAPON', '1');
7175 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7176 if GetAIFlag('SELECTWEAPON') = '1' then
7179 RemoveAIFlag('SELECTWEAPON');
7183 procedure TBot
.Update();
7196 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7197 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7199 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7201 if g_debug_BotAIOff
= 3 then
7211 RealizeCurrentWeapon();
7218 procedure TBot
.ReleaseKey(Key
: Byte);
7227 function TBot
.KeyPressed(Key
: Word): Boolean;
7229 Result
:= FKeys
[Key
].Pressed
;
7232 function TBot
.GetAIFlag(aName
: String20
): String20
;
7238 aName
:= LowerCase(aName
);
7240 if FAIFlags
<> nil then
7241 for a
:= 0 to High(FAIFlags
) do
7242 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7244 Result
:= FAIFlags
[a
].Value
;
7249 procedure TBot
.RemoveAIFlag(aName
: String20
);
7253 if FAIFlags
= nil then Exit
;
7255 aName
:= LowerCase(aName
);
7257 for a
:= 0 to High(FAIFlags
) do
7258 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7260 if a
<> High(FAIFlags
) then
7261 for b
:= a
to High(FAIFlags
)-1 do
7262 FAIFlags
[b
] := FAIFlags
[b
+1];
7264 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7269 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7277 aName
:= LowerCase(aName
);
7279 if FAIFlags
<> nil then
7280 for a
:= 0 to High(FAIFlags
) do
7281 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7287 if ok
then FAIFlags
[a
].Value
:= fValue
7290 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7291 with FAIFlags
[High(FAIFlags
)] do
7299 procedure TBot
.UpdateMove
;
7301 procedure GoLeft(Time
: Word = 1);
7303 ReleaseKey(KEY_LEFT
);
7304 ReleaseKey(KEY_RIGHT
);
7305 PressKey(KEY_LEFT
, Time
);
7306 SetDirection(TDirection
.D_LEFT
);
7309 procedure GoRight(Time
: Word = 1);
7311 ReleaseKey(KEY_LEFT
);
7312 ReleaseKey(KEY_RIGHT
);
7313 PressKey(KEY_RIGHT
, Time
);
7314 SetDirection(TDirection
.D_RIGHT
);
7317 function Rnd(a
: Word): Boolean;
7319 Result
:= Random(a
) = 0;
7322 procedure Turn(Time
: Word = 1200);
7324 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7329 ReleaseKey(KEY_LEFT
);
7330 ReleaseKey(KEY_RIGHT
);
7333 function CanRunLeft(): Boolean;
7335 Result
:= not CollideLevel(-1, 0);
7338 function CanRunRight(): Boolean;
7340 Result
:= not CollideLevel(1, 0);
7343 function CanRun(): Boolean;
7345 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7348 procedure Jump(Time
: Word = 30);
7350 PressKey(KEY_JUMP
, Time
);
7353 function NearHole(): Boolean;
7357 { TODO 5 : Ëåñòíèöû }
7358 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7359 for x
:= 1 to PLAYER_RECT
.Width
do
7360 if (not StayOnStep(x
*sx
, 0)) and
7361 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7362 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7371 function BorderHole(): Boolean;
7375 { TODO 5 : Ëåñòíèöû }
7376 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7377 for x
:= 1 to PLAYER_RECT
.Width
do
7378 if (not StayOnStep(x
*sx
, 0)) and
7379 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7380 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7382 for xx
:= x
to x
+32 do
7383 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7393 function NearDeepHole(): Boolean;
7399 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7402 for x
:= 1 to PLAYER_RECT
.Width
do
7403 if (not StayOnStep(x
*sx
, 0)) and
7404 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7405 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7407 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7409 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7414 end else Result
:= False;
7417 function OverDeepHole(): Boolean;
7424 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7426 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7433 function OnGround(): Boolean;
7435 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7438 function OnLadder(): Boolean;
7440 Result
:= FullInStep(0, 0);
7443 function BelowLadder(): Boolean;
7445 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7446 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7447 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7448 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7451 function BelowLiftUp(): Boolean;
7453 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7454 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7455 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7456 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7459 function OnTopLift(): Boolean;
7461 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7464 function CanJumpOver(): Boolean;
7468 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7472 if not CollideLevel(sx
, 0) then Exit
;
7474 for y
:= 1 to BOT_MAXJUMP
do
7475 if CollideLevel(0, -y
) then Exit
else
7476 if not CollideLevel(sx
, -y
) then
7483 function CanJumpUp(Dist
: ShortInt): Boolean;
7490 if CollideLevel(Dist
, 0) then Exit
;
7493 for y
:= 0 to BOT_MAXJUMP
do
7494 if CollideLevel(Dist
, -y
) then
7503 for yy
:= y
+1 to BOT_MAXJUMP
do
7504 if not CollideLevel(Dist
, -yy
) then
7513 for y
:= 0 to BOT_MAXJUMP
do
7514 if CollideLevel(0, -y
) then
7522 if y
< yy
then Exit
;
7527 function IsSafeTrigger(): Boolean;
7532 if gTriggers
= nil then
7534 for a
:= 0 to High(gTriggers
) do
7535 if Collide(gTriggers
[a
].X
,
7538 gTriggers
[a
].Height
) and
7539 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7540 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7541 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7542 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7543 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7548 // Âîçìîæíî, íàæèìàåì êíîïêó:
7549 if Rnd(16) and IsSafeTrigger() then
7552 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7553 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7555 ReleaseKey(KEY_LEFT
);
7556 ReleaseKey(KEY_RIGHT
);
7560 // Èäåì âëåâî, åñëè íàäî áûëî:
7561 if GetAIFlag('GOLEFT') <> '' then
7563 RemoveAIFlag('GOLEFT');
7564 if CanRunLeft() then
7568 // Èäåì âïðàâî, åñëè íàäî áûëî:
7569 if GetAIFlag('GORIGHT') <> '' then
7571 RemoveAIFlag('GORIGHT');
7572 if CanRunRight() then
7576 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7577 if FObj
.X
< -32 then
7580 if FObj
.X
+32 > gMapInfo
.Width
then
7583 // Ïðûãàåì, åñëè íàäî áûëî:
7584 if GetAIFlag('NEEDJUMP') <> '' then
7587 RemoveAIFlag('NEEDJUMP');
7590 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7591 if GetAIFlag('NEEDSEEUP') <> '' then
7594 ReleaseKey(KEY_DOWN
);
7595 PressKey(KEY_UP
, 20);
7596 RemoveAIFlag('NEEDSEEUP');
7599 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7600 if GetAIFlag('NEEDSEEDOWN') <> '' then
7603 ReleaseKey(KEY_DOWN
);
7604 PressKey(KEY_DOWN
, 20);
7605 RemoveAIFlag('NEEDSEEDOWN');
7608 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7609 if GetAIFlag('GOINHOLE') <> '' then
7610 if not OnGround() then
7612 ReleaseKey(KEY_LEFT
);
7613 ReleaseKey(KEY_RIGHT
);
7614 RemoveAIFlag('GOINHOLE');
7615 SetAIFlag('FALLINHOLE', '1');
7618 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7619 if GetAIFlag('FALLINHOLE') <> '' then
7621 RemoveAIFlag('FALLINHOLE');
7623 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7624 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7625 if GetAIFlag('FALLINHOLE') = '' then
7626 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7632 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7634 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7638 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7639 if OnGround() and NearHole() then
7640 if NearDeepHole() then // Åñëè ýòî áåçäíà
7642 0..3: Turn(); // Áåæèì îáðàòíî
7643 4: Jump(); // Ïðûãàåì
7644 5: begin // Ïðûãàåì îáðàòíî
7649 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7650 if GetAIFlag('GOINHOLE') = '' then
7652 0: Turn(); // Íå íóæíî òóäà
7653 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7654 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7655 if BorderHole() then
7656 SetAIFlag('GOINHOLE', '1');
7659 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7660 if (not CanRun()) and OnGround() then
7662 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7663 if CanJumpOver() or OnLadder() then
7665 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7666 if Random(2) = 0 then
7668 if IsSafeTrigger() then
7674 // Îñòàëîñü ìàëî âîçäóõà:
7675 if FAir
< 36 * 2 then
7678 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7679 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7680 if BodyInAcid(0, 0) then
7684 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7686 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7687 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7690 {function TBot.NeedItem(Item: Byte): Byte;
7695 procedure TBot
.SelectWeapon(Dist
: Integer);
7699 function HaveAmmo(weapon
: Byte): Boolean;
7702 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7703 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7704 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7705 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7706 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7707 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7708 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7709 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7710 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7711 else Result
:= True;
7716 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7718 if Dist
> BOT_LONGDIST
then
7719 begin // Äàëüíèé áîé
7721 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7723 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7727 else //if Dist > BOT_UNSAFEDIST then
7728 begin // Áëèæíèé áîé
7730 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7732 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7739 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7741 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7747 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7749 Result
:= inherited PickItem(ItemType
, force
, remove
);
7751 if Result
then SetAIFlag('SELECTWEAPON', '1');
7754 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7756 Result
:= inherited Heal(value
, Soft
);
7759 function TBot
.Healthy(): Byte;
7761 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7762 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7763 else if (FHealth
> 50) then Result
:= 2
7764 else if (FHealth
> 20) then Result
:= 1
7768 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7770 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7771 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7774 procedure TBot
.OnDamage(Angle
: SmallInt);
7782 if (Angle
= 0) or (Angle
= 180) then
7785 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7786 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7788 pla
:= g_Player_Get(FLastSpawnerUID
);
7789 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7790 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7793 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7794 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7796 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7797 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7798 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7803 SetAIFlag('ATTACKLEFT', '1')
7805 SetAIFlag('ATTACKRIGHT', '1');
7809 function TBot
.RunDirection(): TDirection
;
7811 if Abs(Vel
.X
) >= 1 then
7813 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7815 Result
:= FDirection
;
7818 function TBot
.GetRnd(a
: Byte): Boolean;
7820 if a
= 0 then Result
:= False
7821 else if a
= 255 then Result
:= True
7822 else Result
:= Random(256) > 255-a
;
7825 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7827 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7831 procedure TDifficult
.save (st
: TStream
);
7833 utils
.writeInt(st
, Byte(DiagFire
));
7834 utils
.writeInt(st
, Byte(InvisFire
));
7835 utils
.writeInt(st
, Byte(DiagPrecision
));
7836 utils
.writeInt(st
, Byte(FlyPrecision
));
7837 utils
.writeInt(st
, Byte(Cover
));
7838 utils
.writeInt(st
, Byte(CloseJump
));
7839 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7840 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7843 procedure TDifficult
.load (st
: TStream
);
7845 DiagFire
:= utils
.readByte(st
);
7846 InvisFire
:= utils
.readByte(st
);
7847 DiagPrecision
:= utils
.readByte(st
);
7848 FlyPrecision
:= utils
.readByte(st
);
7849 Cover
:= utils
.readByte(st
);
7850 CloseJump
:= utils
.readByte(st
);
7851 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7852 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7856 procedure TBot
.SaveState (st
: TStream
);
7861 inherited SaveState(st
);
7862 utils
.writeSign(st
, 'BOT0');
7864 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7866 utils
.writeInt(st
, Word(FTargetUID
));
7867 // Âðåìÿ ïîòåðè öåëè
7868 utils
.writeInt(st
, LongWord(FLastVisible
));
7869 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7870 dw
:= Length(FAIFlags
);
7871 utils
.writeInt(st
, LongInt(dw
));
7873 for i
:= 0 to dw
-1 do
7875 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7876 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7878 // Íàñòðîéêè ñëîæíîñòè
7879 FDifficult
.save(st
);
7883 procedure TBot
.LoadState (st
: TStream
);
7888 inherited LoadState(st
);
7889 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7891 FSelectedWeapon
:= utils
.readByte(st
);
7893 FTargetUID
:= utils
.readWord(st
);
7894 // Âðåìÿ ïîòåðè öåëè
7895 FLastVisible
:= utils
.readLongWord(st
);
7896 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7897 dw
:= utils
.readLongInt(st
);
7898 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7899 SetLength(FAIFlags
, dw
);
7901 for i
:= 0 to dw
-1 do
7903 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7904 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7906 // Íàñòðîéêè ñëîæíîñòè
7907 FDifficult
.load(st
);
7912 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);
7913 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');
7914 conRegVar('player_indicator_style', @gPlayerIndicatorStyle
, 'Visual appearance of indicator', 'Visual appearance of indicator');