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, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
24 {$IFDEF USE_MEMPOOL}mempool
,{$ENDIF}
25 e_graphics
, g_playermodel
, g_basic
, g_textures
,
26 g_weapons
, g_phys
, g_sound
, g_saveload
, MAPDEF
,
59 AmmoLimits
: Array [0..1] of Array [A_BULLETS
..A_HIGH
] of Word =
60 ((200, 50, 50, 300, 100),
61 (400, 100, 100, 600, 200));
82 ANGLE_NONE
= Low(SmallInt);
84 CORPSE_STATE_REMOVEME
= 0;
85 CORPSE_STATE_NORMAL
= 1;
86 CORPSE_STATE_MESS
= 2;
88 PLAYER_RECT
: TRectWH
= (X
:15; Y
:12; Width
:34; Height
:52);
89 PLAYER_RECT_CX
= 15+(34 div 2);
90 PLAYER_RECT_CY
= 12+(52 div 2);
91 PLAYER_CORPSERECT
: TRectWH
= (X
:15; Y
:48; Width
:34; Height
:16);
94 PLAYER_HP_LIMIT
= 200;
96 PLAYER_AP_LIMIT
= 200;
100 PLAYER1_DEF_COLOR
: TRGB
= (R
:64; G
:175; B
:48);
101 PLAYER2_DEF_COLOR
: TRGB
= (R
:96; G
:96; B
:96);
118 TPlayerStatArray
= Array of TPlayerStat
;
120 TPlayerSavedState
= record
128 Ammo
: Array [A_BULLETS
..A_HIGH
] of Word;
129 MaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
130 Weapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
131 Rulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
140 TPlayer
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
148 FDirection
: TDirection
;
156 FMonsterKills
: Integer;
162 FCanJetpack
: Boolean;
168 FNextWeapDelay
: Byte; // frames
169 FBFGFireCounter
: SmallInt;
170 FLastSpawnerUID
: Word;
174 FSpectatePlayer
: Integer;
175 FFirePainTime
: Integer;
178 FSavedState
: TPlayerSavedState
;
180 FModel
: TPlayerModel
;
181 FPunchAnim
: TAnimation
;
184 FActionForce
: Boolean;
185 FActionChanged
: Boolean;
187 FFireAngle
: SmallInt;
189 FShellTimer
: Integer;
191 FSawSound
: TPlayableSound
;
192 FSawSoundIdle
: TPlayableSound
;
193 FSawSoundHit
: TPlayableSound
;
194 FSawSoundSelect
: TPlayableSound
;
195 FFlameSoundOn
: TPlayableSound
;
196 FFlameSoundOff
: TPlayableSound
;
197 FFlameSoundWork
: TPlayableSound
;
198 FJetSoundOn
: TPlayableSound
;
199 FJetSoundOff
: TPlayableSound
;
200 FJetSoundFly
: TPlayableSound
;
204 FJustTeleported
: Boolean;
206 mEDamageType
: Integer;
209 function CollideLevel(XInc
, YInc
: Integer): Boolean;
210 function StayOnStep(XInc
, YInc
: Integer): Boolean;
211 function HeadInLiquid(XInc
, YInc
: Integer): Boolean;
212 function BodyInLiquid(XInc
, YInc
: Integer): Boolean;
213 function BodyInAcid(XInc
, YInc
: Integer): Boolean;
214 function FullInLift(XInc
, YInc
: Integer): Integer;
215 {procedure CollideItem();}
216 procedure FlySmoke(Times
: DWORD
= 1);
217 procedure OnFireFlame(Times
: DWORD
= 1);
218 function GetAmmoByWeapon(Weapon
: Byte): Word;
219 procedure SetAction(Action
: Byte; Force
: Boolean = False);
220 procedure OnDamage(Angle
: SmallInt); virtual;
221 function firediry(): Integer;
224 procedure Run(Direction
: TDirection
);
225 procedure NextWeapon();
226 procedure PrevWeapon();
233 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
234 procedure resetWeaponQueue ();
235 function hasAmmoForWeapon (weapon
: Byte): Boolean;
237 procedure doDamage (v
: Integer);
239 function followCorpse(): Boolean;
242 FDamageBuffer
: Integer;
244 FAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
245 FMaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
246 FWeapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
247 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
249 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
250 FReloading
: Array [WP_FIRST
..WP_LAST
] of Word;
251 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
252 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
254 FPreferredTeam
: Byte;
257 FWantsInGame
: Boolean;
262 FActualModelName
: string;
271 // debug: viewport offset
272 viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer;
274 function isValidViewPort (): Boolean; inline;
276 constructor Create(); virtual;
277 destructor Destroy(); override;
278 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
279 function GetRespawnPoint(): Byte;
280 procedure PressKey(Key
: Byte; Time
: Word = 1);
281 procedure ReleaseKeys();
282 procedure SetModel(ModelName
: String);
283 procedure SetColor(Color
: TRGB
);
284 procedure SetWeapon(W
: Byte);
285 function IsKeyPressed(K
: Byte): Boolean;
286 function GetKeys(): Byte;
287 function PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean; virtual;
288 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
289 function Collide(Panel
: TPanel
): Boolean; overload
;
290 function Collide(X
, Y
: Integer): Boolean; overload
;
291 procedure SetDirection(Direction
: TDirection
);
292 procedure GetSecret();
293 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
295 procedure Push(vx
, vy
: Integer);
296 procedure ChangeModel(ModelName
: String);
297 procedure SwitchTeam
;
298 procedure ChangeTeam(Team
: Byte);
300 function GetFlag(Flag
: Byte): Boolean;
301 procedure SetFlag(Flag
: Byte);
302 function DropFlag(Silent
: Boolean = True): Boolean;
303 procedure AllRulez(Health
: Boolean);
304 procedure RestoreHealthArmor();
305 procedure FragCombo();
306 procedure GiveItem(ItemType
: Byte);
307 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
308 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
309 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
310 procedure MakeBloodSimple(Count
: Word);
311 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
312 procedure Reset(Force
: Boolean);
313 procedure Spectate(NoMove
: Boolean = False);
314 procedure SwitchNoClip
;
315 procedure SoftReset();
316 procedure Draw(); virtual;
317 procedure DrawPain();
318 procedure DrawPickup();
319 procedure DrawRulez();
321 procedure DrawIndicator();
322 procedure DrawBubble();
324 procedure Update(); virtual;
325 procedure RememberState();
326 procedure RecallState();
327 procedure SaveState (st
: TStream
); virtual;
328 procedure LoadState (st
: TStream
); virtual;
329 procedure PauseSounds(Enable
: Boolean);
330 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
331 procedure DoLerp(Level
: Integer = 2);
332 procedure SetLerp(XTo
, YTo
: Integer);
333 procedure QueueWeaponSwitch(Weapon
: Byte);
334 procedure RealizeCurrentWeapon();
338 procedure JetpackOff
;
339 procedure CatchFire(Attacker
: Word);
341 //WARNING! this does nothing for now, but still call it!
342 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
344 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
345 procedure moveBy (dx
, dy
: Integer); inline;
348 property Vel
: TPoint2i read FObj
.Vel
;
349 property Obj
: TObj read FObj
;
351 property Name
: String read FName write FName
;
352 property Model
: TPlayerModel read FModel
;
353 property Health
: Integer read FHealth write FHealth
;
354 property Lives
: Byte read FLives write FLives
;
355 property Armor
: Integer read FArmor write FArmor
;
356 property Air
: Integer read FAir write FAir
;
357 property JetFuel
: Integer read FJetFuel write FJetFuel
;
358 property Frags
: Integer read FFrags write FFrags
;
359 property Death
: Integer read FDeath write FDeath
;
360 property Kills
: Integer read FKills write FKills
;
361 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
362 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
363 property Secrets
: Integer read FSecrets
;
364 property GodMode
: Boolean read FGodMode write FGodMode
;
365 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
366 property NoReload
: Boolean read FNoReload write FNoReload
;
367 property alive
: Boolean read FAlive write FAlive
;
368 property Flag
: Byte read FFlag
;
369 property Team
: Byte read FTeam write FTeam
;
370 property Direction
: TDirection read FDirection
;
371 property GameX
: Integer read FObj
.X write FObj
.X
;
372 property GameY
: Integer read FObj
.Y write FObj
.Y
;
373 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
374 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
375 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
376 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
377 property IncCam
: Integer read FIncCam write FIncCam
;
378 property UID
: Word read FUID write FUID
;
379 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
380 property NetTime
: LongWord read FNetTime write FNetTime
;
383 property eName
: String read FName write FName
;
384 property eHealth
: Integer read FHealth write FHealth
;
385 property eLives
: Byte read FLives write FLives
;
386 property eArmor
: Integer read FArmor write FArmor
;
387 property eAir
: Integer read FAir write FAir
;
388 property eJetFuel
: Integer read FJetFuel write FJetFuel
;
389 property eFrags
: Integer read FFrags write FFrags
;
390 property eDeath
: Integer read FDeath write FDeath
;
391 property eKills
: Integer read FKills write FKills
;
392 property eCurrWeap
: Byte read FCurrWeap write FCurrWeap
;
393 property eMonsterKills
: Integer read FMonsterKills write FMonsterKills
;
394 property eSecrets
: Integer read FSecrets write FSecrets
;
395 property eGodMode
: Boolean read FGodMode write FGodMode
;
396 property eNoTarget
: Boolean read FNoTarget write FNoTarget
;
397 property eNoReload
: Boolean read FNoReload write FNoReload
;
398 property eAlive
: Boolean read FAlive write FAlive
;
399 property eFlag
: Byte read FFlag
;
400 property eTeam
: Byte read FTeam write FTeam
;
401 property eDirection
: TDirection read FDirection
;
402 property eGameX
: Integer read FObj
.X write FObj
.X
;
403 property eGameY
: Integer read FObj
.Y write FObj
.Y
;
404 property eGameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
405 property eGameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
406 property eGameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
407 property eGameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
408 property eIncCam
: Integer read FIncCam write FIncCam
;
409 property eUID
: Word read FUID
;
410 property eJustTeleported
: Boolean read FJustTeleported
;
411 property eNetTime
: LongWord read FNetTime
;
413 // set this before assigning something to `eDamage`
414 property eDamageType
: Integer read mEDamageType write mEDamageType
;
415 property eDamage
: Integer write doDamage
;
426 WeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
427 CloseWeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
428 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
431 procedure save (st
: TStream
);
432 procedure load (st
: TStream
);
440 TBot
= class(TPlayer
)
442 FSelectedWeapon
: Byte;
445 FAIFlags
: Array of TAIFlag
;
446 FDifficult
: TDifficult
;
448 function GetRnd(a
: Byte): Boolean;
449 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
450 function RunDirection(): TDirection
;
451 function FullInStep(XInc
, YInc
: Integer): Boolean;
452 //function NeedItem(Item: Byte): Byte;
453 procedure SelectWeapon(Dist
: Integer);
454 procedure SetAIFlag(aName
, fValue
: String20
);
455 function GetAIFlag(aName
: String20
): String20
;
456 procedure RemoveAIFlag(aName
: String20
);
457 function Healthy(): Byte;
458 procedure UpdateMove();
459 procedure UpdateCombat();
460 function KeyPressed(Key
: Word): Boolean;
461 procedure ReleaseKey(Key
: Byte);
462 function TargetOnScreen(TX
, TY
: Integer): Boolean;
463 procedure OnDamage(Angle
: SmallInt); override;
466 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
467 constructor Create(); override;
468 destructor Destroy(); override;
469 procedure Draw(); override;
470 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
471 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
472 procedure Update(); override;
473 procedure SaveState (st
: TStream
); override;
474 procedure LoadState (st
: TStream
); override;
486 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
487 procedure moveBy (dx
, dy
: Integer); inline;
489 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
503 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
504 procedure moveBy (dx
, dy
: Integer); inline;
506 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
509 TCorpse
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
518 FAnimation
: TAnimation
;
519 FAnimationMask
: TAnimation
;
522 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
523 destructor Destroy(); override;
524 procedure Damage(Value
: Word; vx
, vy
: Integer);
527 procedure SaveState (st
: TStream
);
528 procedure LoadState (st
: TStream
);
530 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
531 procedure moveBy (dx
, dy
: Integer); inline;
533 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
535 function ObjPtr (): PObj
; inline;
537 property Obj
: TObj read FObj
; // copies object
538 property State
: Byte read FState
;
539 property Mess
: Boolean read FMess
;
542 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
548 gPlayers
: Array of TPlayer
;
549 gCorpses
: Array of TCorpse
;
550 gGibs
: Array of TGib
;
551 gShells
: Array of TShell
;
552 gTeamStat
: TTeamStat
;
553 gFly
: Boolean = False;
554 gAimLine
: Boolean = False;
555 gChatBubble
: Byte = 0;
556 gPlayerIndicator
: Boolean = True;
560 MAX_RUNVEL
: Integer = 8;
561 VEL_JUMP
: Integer = 10;
562 SHELL_TIMEOUT
: Cardinal = 60000;
564 function Lerp(X
, Y
, Factor
: Integer): Integer;
566 procedure g_Gibs_SetMax(Count
: Word);
567 function g_Gibs_GetMax(): Word;
568 procedure g_Corpses_SetMax(Count
: Word);
569 function g_Corpses_GetMax(): Word;
570 procedure g_Shells_SetMax(Count
: Word);
571 function g_Shells_GetMax(): Word;
573 procedure g_Player_Init();
574 procedure g_Player_Free();
575 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
576 function g_Player_CreateFromState (st
: TStream
): Word;
577 procedure g_Player_Remove(UID
: Word);
578 procedure g_Player_ResetTeams();
579 procedure g_Player_UpdateAll();
580 procedure g_Player_DrawAll();
581 procedure g_Player_DrawDebug(p
: TPlayer
);
582 procedure g_Player_DrawHealth();
583 procedure g_Player_RememberAll();
584 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
585 function g_Player_Get(UID
: Word): TPlayer
;
586 function g_Player_GetCount(): Byte;
587 function g_Player_GetStats(): TPlayerStatArray
;
588 function g_Player_ValidName(Name
: String): Boolean;
589 procedure g_Player_CreateCorpse(Player
: TPlayer
);
590 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
591 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
592 procedure g_Player_UpdatePhysicalObjects();
593 procedure g_Player_DrawCorpses();
594 procedure g_Player_DrawShells();
595 procedure g_Player_RemoveAllCorpses();
596 procedure g_Player_Corpses_SaveState (st
: TStream
);
597 procedure g_Player_Corpses_LoadState (st
: TStream
);
598 procedure g_Player_ResetReady();
599 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
600 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
601 procedure g_Bot_MixNames();
602 procedure g_Bot_RemoveAll();
607 {$INCLUDE ../nogl/noGLuses.inc}
608 {$IFDEF ENABLE_HOLMES}
611 e_log
, g_map
, g_items
, g_console
, g_gfx
, Math
,
612 g_options
, g_triggers
, g_menu
, g_game
, g_grid
,
613 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
,
614 g_net
, g_netmsg
, g_window
,
617 const PLR_SAVE_VERSION
= 0;
627 diag_precision
: Byte;
631 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
632 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
633 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
637 TIME_RESPAWN1
= 1500;
638 TIME_RESPAWN2
= 2000;
639 TIME_RESPAWN3
= 3000;
642 JET_MAX
= 540; // ~30 sec
643 PLAYER_SUIT_TIME
= 30000;
644 PLAYER_INVUL_TIME
= 30000;
645 PLAYER_INVIS_TIME
= 35000;
646 FRAG_COMBO_TIME
= 3000;
650 ANGLE_RIGHTDOWN
= -35;
652 ANGLE_LEFTDOWN
= -145;
653 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
654 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
657 BOT_UNSAFEDIST
= 128;
658 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
660 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
661 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
662 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
663 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
664 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
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_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
667 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
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 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
670 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
671 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
672 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
673 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
674 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
675 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
676 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
677 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
678 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
679 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
680 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
681 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
682 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
683 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
684 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
685 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
687 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
688 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
690 BOTNAMES_FILENAME
= 'botnames.txt';
691 BOTLIST_FILENAME
= 'botlist.txt';
695 MaxCorpses
: Word = 20;
696 MaxShells
: Word = 300;
697 CurrentGib
: Integer = 0;
698 CurrentShell
: Integer = 0;
699 BotNames
: Array of String;
700 BotList
: Array of TBotProfile
;
703 function Lerp(X
, Y
, Factor
: Integer): Integer;
705 Result
:= X
+ ((Y
- X
) div Factor
);
708 function SameTeam(UID1
, UID2
: Word): Boolean;
712 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
713 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
715 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
717 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
718 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
720 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
723 procedure g_Gibs_SetMax(Count
: Word);
726 SetLength(gGibs
, Count
);
728 if CurrentGib
>= Count
then
732 function g_Gibs_GetMax(): Word;
737 procedure g_Shells_SetMax(Count
: Word);
740 SetLength(gShells
, Count
);
742 if CurrentShell
>= Count
then
746 function g_Shells_GetMax(): Word;
752 procedure g_Corpses_SetMax(Count
: Word);
755 SetLength(gCorpses
, Count
);
758 function g_Corpses_GetMax(): Word;
760 Result
:= MaxCorpses
;
763 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
773 // Åñòü ëè ìåñòî â gPlayers:
774 if gPlayers
<> nil then
775 for a
:= 0 to High(gPlayers
) do
776 if gPlayers
[a
] = nil then
782 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
785 SetLength(gPlayers
, Length(gPlayers
)+1);
789 // Ñîçäàåì îáúåêò èãðîêà:
791 gPlayers
[a
] := TBot
.Create()
793 gPlayers
[a
] := TPlayer
.Create();
796 gPlayers
[a
].FActualModelName
:= ModelName
;
797 gPlayers
[a
].SetModel(ModelName
);
799 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
800 if gPlayers
[a
].FModel
= nil then
804 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
808 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
809 if Random(2) = 0 then
813 gPlayers
[a
].FPreferredTeam
:= Team
;
815 case gGameSettings
.GameMode
of
816 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
818 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
820 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
823 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
824 gPlayers
[a
].FColor
:= Color
;
825 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
826 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
828 gPlayers
[a
].FModel
.Color
:= Color
;
830 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
831 gPlayers
[a
].FAlive
:= False;
833 Result
:= gPlayers
[a
].FUID
;
836 function g_Player_CreateFromState (st
: TStream
): Word;
843 if (st
= nil) then exit
; //???
846 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
847 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
850 Bot
:= utils
.readBool(st
);
855 // Åñòü ëè ìåñòî â gPlayers:
856 for a
:= 0 to High(gPlayers
) do if (gPlayers
[a
] = nil) then begin ok
:= true; break
; end;
858 // Íåò ìåñòà - ðàñøèðÿåì gPlayers
861 SetLength(gPlayers
, Length(gPlayers
)+1);
865 // Ñîçäàåì îáúåêò èãðîêà
867 gPlayers
[a
] := TBot
.Create()
869 gPlayers
[a
] := TPlayer
.Create();
870 gPlayers
[a
].FIamBot
:= Bot
;
871 gPlayers
[a
].FPhysics
:= True;
874 gPlayers
[a
].FUID
:= utils
.readWord(st
);
876 gPlayers
[a
].FName
:= utils
.readStr(st
);
878 gPlayers
[a
].FTeam
:= utils
.readByte(st
);
879 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
881 gPlayers
[a
].FAlive
:= utils
.readBool(st
);
882 // Èçðàñõîäîâàë ëè âñå æèçíè
883 gPlayers
[a
].FNoRespawn
:= utils
.readBool(st
);
885 b
:= utils
.readByte(st
);
886 if b
= 1 then gPlayers
[a
].FDirection
:= TDirection
.D_LEFT
else gPlayers
[a
].FDirection
:= TDirection
.D_RIGHT
; // b = 2
888 gPlayers
[a
].FHealth
:= utils
.readLongInt(st
);
890 gPlayers
[a
].FHandicap
:= utils
.readLongInt(st
);
892 gPlayers
[a
].FLives
:= utils
.readByte(st
);
894 gPlayers
[a
].FArmor
:= utils
.readLongInt(st
);
896 gPlayers
[a
].FAir
:= utils
.readLongInt(st
);
898 gPlayers
[a
].FJetFuel
:= utils
.readLongInt(st
);
900 gPlayers
[a
].FPain
:= utils
.readLongInt(st
);
902 gPlayers
[a
].FKills
:= utils
.readLongInt(st
);
904 gPlayers
[a
].FMonsterKills
:= utils
.readLongInt(st
);
906 gPlayers
[a
].FFrags
:= utils
.readLongInt(st
);
908 gPlayers
[a
].FFragCombo
:= utils
.readByte(st
);
909 // Âðåìÿ ïîñëåäíåãî ôðàãà
910 gPlayers
[a
].FLastFrag
:= utils
.readLongWord(st
);
912 gPlayers
[a
].FDeath
:= utils
.readLongInt(st
);
914 gPlayers
[a
].FFlag
:= utils
.readByte(st
);
916 gPlayers
[a
].FSecrets
:= utils
.readLongInt(st
);
918 gPlayers
[a
].FCurrWeap
:= utils
.readByte(st
);
919 // Ñëåäóþùåå æåëàåìîå îðóæèå
920 gPlayers
[a
].FNextWeap
:= utils
.readWord(st
);
922 gPlayers
[a
].FNextWeapDelay
:= utils
.readByte(st
);
924 gPlayers
[a
].FBFGFireCounter
:= utils
.readSmallInt(st
);
926 gPlayers
[a
].FDamageBuffer
:= utils
.readLongInt(st
);
927 // Ïîñëåäíèé óäàðèâøèé
928 gPlayers
[a
].FLastSpawnerUID
:= utils
.readWord(st
);
929 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
930 gPlayers
[a
].FLastHit
:= utils
.readByte(st
);
932 Obj_LoadState(@gPlayers
[a
].FObj
, st
);
933 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
934 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FAmmo
[i
] := utils
.readWord(st
);
935 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
936 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FMaxAmmo
[i
] := utils
.readWord(st
);
938 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FWeapon
[i
] := utils
.readBool(st
);
939 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
940 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FReloading
[i
] := utils
.readWord(st
);
942 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
943 // Íàëè÷èå êðàñíîãî êëþ÷à
944 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
945 // Íàëè÷èå çåëåíîãî êëþ÷à
946 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
947 // Íàëè÷èå ñèíåãî êëþ÷à
948 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
950 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_BERSERK
);
951 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
952 for i
:= MR_SUIT
to MR_MAX
do gPlayers
[a
].FMegaRulez
[i
] := utils
.readLongWord(st
);
953 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
954 for i
:= T_RESPAWN
to T_FLAGCAP
do gPlayers
[a
].FTime
[i
] := utils
.readLongWord(st
);
957 gPlayers
[a
].FActualModelName
:= utils
.readStr(st
);
959 gPlayers
[a
].FColor
.R
:= utils
.readByte(st
);
960 gPlayers
[a
].FColor
.G
:= utils
.readByte(st
);
961 gPlayers
[a
].FColor
.B
:= utils
.readByte(st
);
962 // Îáíîâëÿåì ìîäåëü èãðîêà
963 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
965 // Íåò ìîäåëè - ñîçäàíèå íåâîçìîæíî
966 if (gPlayers
[a
].FModel
= nil) then
970 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
974 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû
975 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
976 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
978 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
980 result
:= gPlayers
[a
].FUID
;
984 procedure g_Player_ResetTeams();
988 if g_Game_IsClient
then
990 if gPlayers
= nil then
992 for a
:= Low(gPlayers
) to High(gPlayers
) do
993 if gPlayers
[a
] <> nil then
994 case gGameSettings
.GameMode
of
996 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
998 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
999 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
1000 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
1003 gPlayers
[a
].ChangeTeam(TEAM_RED
)
1005 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
1008 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
1012 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
1015 _name
, _model
: String;
1018 if not g_Game_IsServer
then Exit
;
1020 // Ñïèñîê íàçâàíèé ìîäåëåé:
1021 m
:= g_PlayerModel_GetNames();
1026 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1027 Team
:= TEAM_COOP
// COOP
1029 if gGameSettings
.GameMode
= GM_DM
then
1030 Team
:= TEAM_NONE
// DM
1032 if Team
= TEAM_NONE
then // CTF / TDM
1034 // Àâòîáàëàíñ êîìàíä:
1038 for a
:= 0 to High(gPlayers
) do
1039 if gPlayers
[a
] <> nil then
1041 if gPlayers
[a
].Team
= TEAM_RED
then
1044 if gPlayers
[a
].Team
= TEAM_BLUE
then
1054 if Random(2) = 0 then
1060 // Âûáèðàåì áîòó èìÿ:
1062 if BotNames
<> nil then
1063 for a
:= 0 to High(BotNames
) do
1064 if g_Player_ValidName(BotNames
[a
]) then
1066 _name
:= BotNames
[a
];
1070 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
1073 _name
:= Format('DFBOT%.2d', [Random(100)]);
1074 until g_Player_ValidName(_name
);
1076 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1077 _model
:= m
[Random(Length(m
))];
1080 with g_Player_Get(g_Player_Create(_model
,
1081 _RGB(Min(Random(9)*32, 255),
1082 Min(Random(9)*32, 255),
1083 Min(Random(9)*32, 255)),
1084 Team
, True)) as TBot
do
1089 1: FDifficult
:= DIFFICULT_EASY
;
1090 2: FDifficult
:= DIFFICULT_MEDIUM
;
1091 else FDifficult
:= DIFFICULT_HARD
;
1094 for a
:= WP_FIRST
to WP_LAST
do
1096 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1097 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1098 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1101 FHandicap
:= Handicap
;
1103 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1105 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1106 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1111 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
1114 _name
, _model
: String;
1117 if not g_Game_IsServer
then Exit
;
1119 // Ñïèñîê íàçâàíèé ìîäåëåé:
1120 m
:= g_PlayerModel_GetNames();
1125 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1126 Team
:= TEAM_COOP
// COOP
1128 if gGameSettings
.GameMode
= GM_DM
then
1129 Team
:= TEAM_NONE
// DM
1131 if Team
= TEAM_NONE
then
1132 Team
:= BotList
[num
].team
; // CTF / TDM
1134 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1135 lName
:= AnsiLowerCase(lName
);
1136 if (num
< 0) or (num
> Length(BotList
)-1) then
1138 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1139 for a
:= 0 to High(BotList
) do
1140 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1149 _name
:= BotList
[num
].name
;
1150 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1151 if not g_Player_ValidName(_name
) then
1153 _name
:= Format('DFBOT%.2d', [Random(100)]);
1154 until g_Player_ValidName(_name
);
1157 _model
:= BotList
[num
].model
;
1158 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1159 if not InSArray(_model
, m
) then
1160 _model
:= m
[Random(Length(m
))];
1163 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1167 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1168 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1169 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1170 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1171 FDifficult
.Cover
:= BotList
[num
].cover
;
1172 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1174 FHandicap
:= Handicap
;
1176 for a
:= WP_FIRST
to WP_LAST
do
1178 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1179 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1180 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1183 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1185 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1189 procedure g_Bot_RemoveAll();
1193 if not g_Game_IsServer
then Exit
;
1194 if gPlayers
= nil then Exit
;
1196 for a
:= 0 to High(gPlayers
) do
1197 if gPlayers
[a
] <> nil then
1198 if gPlayers
[a
] is TBot
then
1200 gPlayers
[a
].Lives
:= 0;
1201 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1202 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1203 g_Player_Remove(gPlayers
[a
].FUID
);
1209 procedure g_Bot_MixNames();
1214 if BotNames
<> nil then
1215 for a
:= 0 to High(BotNames
) do
1217 b
:= Random(Length(BotNames
));
1219 Botnames
[a
] := BotNames
[b
];
1224 procedure g_Player_Remove(UID
: Word);
1228 if gPlayers
= nil then Exit
;
1230 if g_Game_IsServer
and g_Game_IsNet
then
1231 MH_SEND_PlayerDelete(UID
);
1233 for i
:= 0 to High(gPlayers
) do
1234 if gPlayers
[i
] <> nil then
1235 if gPlayers
[i
].FUID
= UID
then
1237 if gPlayers
[i
] is TPlayer
then
1238 TPlayer(gPlayers
[i
]).Free()
1240 TBot(gPlayers
[i
]).Free();
1246 procedure g_Player_Init();
1256 if not FileExists(DataDir
+ BOTNAMES_FILENAME
) then
1259 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1260 AssignFile(F
, DataDir
+ BOTNAMES_FILENAME
);
1271 SetLength(BotNames
, Length(BotNames
)+1);
1272 BotNames
[High(BotNames
)] := s
;
1280 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1281 config
:= TConfig
.CreateFile(DataDir
+ BOTLIST_FILENAME
);
1285 while config
.SectionExists(IntToStr(a
)) do
1287 SetLength(BotList
, Length(BotList
)+1);
1289 with BotList
[High(BotList
)] do
1292 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1294 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1296 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1301 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1302 color
.R
:= StrToIntDef(sa
[0], 0);
1303 color
.G
:= StrToIntDef(sa
[1], 0);
1304 color
.B
:= StrToIntDef(sa
[2], 0);
1305 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1306 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1307 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1308 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1309 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1310 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1311 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1312 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1313 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1314 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1315 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1316 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1317 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1318 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1319 if Length(sa
) = 10 then
1321 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1322 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1323 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1324 if Length(sa
) = 10 then
1326 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1328 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1329 if Length(sa) = 10 then
1331 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1340 procedure g_Player_Free();
1344 if gPlayers
<> nil then
1346 for i
:= 0 to High(gPlayers
) do
1347 if gPlayers
[i
] <> nil then
1349 if gPlayers
[i
] is TPlayer
then
1350 TPlayer(gPlayers
[i
]).Free()
1352 TBot(gPlayers
[i
]).Free();
1363 procedure g_Player_UpdateAll();
1367 if gPlayers
= nil then Exit
;
1369 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1370 for i
:= 0 to High(gPlayers
) do
1372 if gPlayers
[i
] <> nil then
1374 if gPlayers
[i
] is TPlayer
then
1376 gPlayers
[i
].Update();
1377 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1381 // bot updates weapons in `UpdateCombat()`
1382 TBot(gPlayers
[i
]).Update();
1386 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1389 procedure g_Player_DrawAll();
1393 if gPlayers
= nil then Exit
;
1395 for i
:= 0 to High(gPlayers
) do
1396 if gPlayers
[i
] <> nil then
1397 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1398 else TBot(gPlayers
[i
]).Draw();
1401 procedure g_Player_DrawDebug(p
: TPlayer
);
1405 if p
= nil then Exit
;
1406 if (@p
.FObj
) = nil then Exit
;
1408 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1410 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1411 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1412 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1413 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1414 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1415 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1418 procedure g_Player_DrawHealth();
1423 if gPlayers
= nil then Exit
;
1424 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1426 for i
:= 0 to High(gPlayers
) do
1427 if gPlayers
[i
] <> nil then
1429 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1430 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1431 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
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
,
1434 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1438 function g_Player_Get(UID
: Word): TPlayer
;
1444 if gPlayers
= nil then
1447 for a
:= 0 to High(gPlayers
) do
1448 if gPlayers
[a
] <> nil then
1449 if gPlayers
[a
].FUID
= UID
then
1451 Result
:= gPlayers
[a
];
1456 function g_Player_GetCount(): Byte;
1462 if gPlayers
= nil then
1465 for a
:= 0 to High(gPlayers
) do
1466 if gPlayers
[a
] <> nil then
1467 Result
:= Result
+ 1;
1470 function g_Player_GetStats(): TPlayerStatArray
;
1476 if gPlayers
= nil then Exit
;
1478 for a
:= 0 to High(gPlayers
) do
1479 if gPlayers
[a
] <> nil then
1481 SetLength(Result
, Length(Result
)+1);
1482 with Result
[High(Result
)] do
1485 Ping
:= gPlayers
[a
].FPing
;
1486 Loss
:= gPlayers
[a
].FLoss
;
1487 Name
:= gPlayers
[a
].FName
;
1488 Team
:= gPlayers
[a
].FTeam
;
1489 Frags
:= gPlayers
[a
].FFrags
;
1490 Deaths
:= gPlayers
[a
].FDeath
;
1491 Kills
:= gPlayers
[a
].FKills
;
1492 Color
:= gPlayers
[a
].FModel
.Color
;
1493 Lives
:= gPlayers
[a
].FLives
;
1494 Spectator
:= gPlayers
[a
].FSpectator
;
1499 procedure g_Player_ResetReady();
1503 if not g_Game_IsServer
then Exit
;
1504 if gPlayers
= nil then Exit
;
1506 for a
:= 0 to High(gPlayers
) do
1507 if gPlayers
[a
] <> nil then
1509 gPlayers
[a
].FReady
:= False;
1510 if g_Game_IsNet
then
1511 MH_SEND_GameEvent(NET_EV_INTER_READY
, gPlayers
[a
].UID
, 'N');
1515 procedure g_Player_RememberAll
;
1519 for i
:= Low(gPlayers
) to High(gPlayers
) do
1520 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1521 gPlayers
[i
].RememberState
;
1524 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1528 gTeamStat
[TEAM_RED
].Goals
:= 0;
1529 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1531 if gPlayers
<> nil then
1532 for i
:= 0 to High(gPlayers
) do
1533 if gPlayers
[i
] <> nil then
1535 gPlayers
[i
].Reset(Force
);
1537 if gPlayers
[i
] is TPlayer
then
1539 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1540 gPlayers
[i
].Respawn(Silent
)
1542 gPlayers
[i
].Spectate();
1545 TBot(gPlayers
[i
]).Respawn(Silent
);
1549 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1555 if Player
.alive
then
1558 // Ðàçðûâàåì ñâÿçü ñ ïðåæíèì òðóïîì:
1559 if gCorpses
<> nil then
1560 for i
:= 0 to High(gCorpses
) do
1561 if gCorpses
[i
] <> nil then
1562 if gCorpses
[i
].FPlayerUID
= Player
.FUID
then
1563 gCorpses
[i
].FPlayerUID
:= 0;
1565 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1570 if (FHealth
>= -50) or (gGibsCount
= 0) then
1572 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1576 for find_id
:= 0 to High(gCorpses
) do
1577 if gCorpses
[find_id
] = nil then
1584 find_id
:= Random(Length(gCorpses
));
1586 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1587 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1588 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1589 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1590 gCorpses
[find_id
].FPlayerUID
:= FUID
;
1593 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1594 FObj
.Y
+ PLAYER_RECT_CY
,
1595 FModel
.Name
, FModel
.Color
);
1599 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1603 if (gShells
= nil) or (Length(gShells
) = 0) then
1606 with gShells
[CurrentShell
] do
1612 if T
= SHELL_BULLET
then
1614 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1618 Obj
.Rect
.Width
:= 4;
1619 Obj
.Rect
.Height
:= 2;
1623 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1627 Obj
.Rect
.Width
:= 7;
1628 Obj
.Rect
.Height
:= 3;
1634 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1635 positionChanged(); // this updates spatial accelerators
1636 RAngle
:= Random(360);
1637 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1639 if CurrentShell
>= High(gShells
) then
1646 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1649 GibsArray
: TGibsArray
;
1652 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1654 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1656 Blood
:= g_PlayerModel_GetBlood(ModelName
);
1658 for a
:= 0 to High(GibsArray
) do
1659 with gGibs
[CurrentGib
] do
1662 ID
:= GibsArray
[a
].ID
;
1663 MaskID
:= GibsArray
[a
].MaskID
;
1666 Obj
.Rect
:= GibsArray
[a
].Rect
;
1667 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1668 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1669 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1670 positionChanged(); // this updates spatial accelerators
1671 RAngle
:= Random(360);
1673 if gBloodCount
> 0 then
1674 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1675 Random(48), Random(48), Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
1677 if CurrentGib
>= High(gGibs
) then
1684 procedure g_Player_UpdatePhysicalObjects();
1690 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1695 if T
= SHELL_BULLET
then
1696 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1698 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1703 if gGibs
<> nil then
1704 for i
:= 0 to High(gGibs
) do
1705 if gGibs
[i
].alive
then
1709 mr
:= g_Obj_Move(@Obj
, True, False, True);
1710 positionChanged(); // this updates spatial accelerators
1712 if WordBool(mr
and MOVE_FALLOUT
) then
1718 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1719 if WordBool(mr
and MOVE_HITWALL
) then
1720 Obj
.Vel
.X
:= -(vel
.X
div 2);
1721 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1722 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1724 if (Obj
.Vel
.X
>= 0) then
1726 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1727 if RAngle
>= 360 then
1728 RAngle
:= RAngle
mod 360;
1729 end else begin // Counter-clockwise
1730 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1732 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1735 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1736 if gTime
mod (GAME_TICK
*3) = 0 then
1737 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1741 if gCorpses
<> nil then
1742 for i
:= 0 to High(gCorpses
) do
1743 if gCorpses
[i
] <> nil then
1744 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1750 gCorpses
[i
].Update();
1753 if gShells
<> nil then
1754 for i
:= 0 to High(gShells
) do
1755 if gShells
[i
].alive
then
1759 mr
:= g_Obj_Move(@Obj
, True, False, True);
1760 positionChanged(); // this updates spatial accelerators
1762 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1768 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1769 if WordBool(mr
and MOVE_HITWALL
) then
1771 Obj
.Vel
.X
:= -(vel
.X
div 2);
1772 if not WordBool(mr
and MOVE_INWATER
) then
1773 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1775 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1777 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1778 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1779 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1781 if RAngle
mod 90 <> 0 then
1782 RAngle
:= (RAngle
div 90) * 90;
1784 else if not WordBool(mr
and MOVE_INWATER
) then
1785 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1788 if (Obj
.Vel
.X
>= 0) then
1790 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1791 if RAngle
>= 360 then
1792 RAngle
:= RAngle
mod 360;
1793 end else begin // Counter-clockwise
1794 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1796 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1802 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1804 x
:= Obj
.X
+Obj
.Rect
.X
;
1805 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1806 w
:= Obj
.Rect
.Width
;
1807 h
:= Obj
.Rect
.Height
;
1810 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1812 if (dx
<> 0) or (dy
<> 0) then
1821 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1825 w
:= Obj
.Rect
.Width
;
1826 h
:= Obj
.Rect
.Height
;
1829 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1831 if (dx
<> 0) or (dy
<> 0) then
1840 procedure TGib
.positionChanged (); inline; begin end;
1841 procedure TShell
.positionChanged (); inline; begin end;
1844 procedure g_Player_DrawCorpses();
1849 if gGibs
<> nil then
1850 for i
:= 0 to High(gGibs
) do
1851 if gGibs
[i
].alive
then
1854 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1857 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1858 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1860 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1863 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1869 if gCorpses
<> nil then
1870 for i
:= 0 to High(gCorpses
) do
1871 if gCorpses
[i
] <> nil then
1875 procedure g_Player_DrawShells();
1880 if gShells
<> nil then
1881 for i
:= 0 to High(gShells
) do
1882 if gShells
[i
].alive
then
1885 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1891 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1895 procedure g_Player_RemoveAllCorpses();
1901 SetLength(gGibs
, MaxGibs
);
1902 SetLength(gShells
, MaxGibs
);
1906 if gCorpses
<> nil then
1907 for i
:= 0 to High(gCorpses
) do
1911 SetLength(gCorpses
, MaxCorpses
);
1914 procedure g_Player_Corpses_SaveState (st
: TStream
);
1918 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ
1920 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1922 // Êîëè÷åñòâî òðóïîâ
1923 utils
.writeInt(st
, LongInt(count
));
1925 if (count
= 0) then exit
;
1928 for i
:= 0 to High(gCorpses
) do
1930 if gCorpses
[i
] <> nil then
1933 utils
.writeStr(st
, gCorpses
[i
].FModelName
);
1935 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1936 // Ñîõðàíÿåì äàííûå òðóïà:
1937 gCorpses
[i
].SaveState(st
);
1943 procedure g_Player_Corpses_LoadState (st
: TStream
);
1951 g_Player_RemoveAllCorpses();
1953 // Êîëè÷åñòâî òðóïîâ:
1954 count
:= utils
.readLongInt(st
);
1955 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1957 if (count
= 0) then exit
;
1960 for i
:= 0 to count
-1 do
1963 str
:= utils
.readStr(st
);
1965 b
:= utils
.readBool(st
);
1967 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1968 // Çàãðóæàåì äàííûå òðóïà
1969 gCorpses
[i
].LoadState(st
);
1976 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1978 procedure TPlayer
.BFGHit();
1980 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1981 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1982 if g_Game_IsServer
and g_Game_IsNet
then
1983 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1984 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1988 procedure TPlayer
.ChangeModel(ModelName
: string);
1990 locModel
: TPlayerModel
;
1992 locModel
:= g_PlayerModel_Get(ModelName
);
1993 if locModel
= nil then Exit
;
1999 procedure TPlayer
.SetModel(ModelName
: string);
2003 m
:= g_PlayerModel_Get(ModelName
);
2006 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
2007 m
:= g_PlayerModel_Get('doomer');
2010 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
2015 if FModel
<> nil then
2020 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2021 FModel
.Color
:= FColor
2023 FModel
.Color
:= TEAMCOLOR
[FTeam
];
2024 FModel
.SetWeapon(FCurrWeap
);
2025 FModel
.SetFlag(FFlag
);
2026 SetDirection(FDirection
);
2029 procedure TPlayer
.SetColor(Color
: TRGB
);
2032 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2033 if FModel
<> nil then FModel
.Color
:= Color
;
2036 procedure TPlayer
.SwitchTeam
;
2038 if g_Game_IsClient
then
2040 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
2042 if gGameOn
and FAlive
then
2043 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
2045 if FTeam
= TEAM_RED
then
2047 ChangeTeam(TEAM_BLUE
);
2048 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
2049 if g_Game_IsNet
then
2050 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
2054 ChangeTeam(TEAM_RED
);
2055 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
2056 if g_Game_IsNet
then
2057 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
2059 FPreferredTeam
:= FTeam
;
2062 procedure TPlayer
.ChangeTeam(Team
: Byte);
2069 TEAM_RED
, TEAM_BLUE
:
2070 FModel
.Color
:= TEAMCOLOR
[Team
];
2072 FModel
.Color
:= FColor
;
2074 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2075 MH_SEND_PlayerStats(FUID
);
2079 procedure TPlayer.CollideItem();
2084 if gItems = nil then Exit;
2085 if not FAlive then Exit;
2087 for i := 0 to High(gItems) do
2090 if (ItemType <> ITEM_NONE) and alive then
2091 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2092 PLAYER_RECT.Height, @Obj) then
2094 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2096 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2097 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2098 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2099 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2100 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2102 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2103 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2104 (gGameSettings.GameType = GT_SINGLE) and
2105 (g_Player_GetCount() > 1)) then
2106 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2112 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2114 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2115 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2119 constructor TPlayer
.Create();
2125 mEDamageType
:= HIT_SOME
;
2131 FSawSound
:= TPlayableSound
.Create();
2132 FSawSoundIdle
:= TPlayableSound
.Create();
2133 FSawSoundHit
:= TPlayableSound
.Create();
2134 FSawSoundSelect
:= TPlayableSound
.Create();
2135 FFlameSoundOn
:= TPlayableSound
.Create();
2136 FFlameSoundOff
:= TPlayableSound
.Create();
2137 FFlameSoundWork
:= TPlayableSound
.Create();
2138 FJetSoundFly
:= TPlayableSound
.Create();
2139 FJetSoundOn
:= TPlayableSound
.Create();
2140 FJetSoundOff
:= TPlayableSound
.Create();
2142 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2143 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2144 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2145 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2146 FFlameSoundOn
.SetByName('SOUND_WEAPON_FLAMEON');
2147 FFlameSoundOff
.SetByName('SOUND_WEAPON_FLAMEOFF');
2148 FFlameSoundWork
.SetByName('SOUND_WEAPON_FLAMEWORK');
2149 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2150 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2151 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2153 FSpectatePlayer
:= -1;
2157 FSavedState
.WaitRecall
:= False;
2164 FActualModelName
:= 'doomer';
2167 FObj
.Rect
:= PLAYER_RECT
;
2169 FBFGFireCounter
:= -1;
2170 FJustTeleported
:= False;
2176 procedure TPlayer
.positionChanged (); inline;
2180 procedure TPlayer
.doDamage (v
: Integer);
2182 if (v
<= 0) then exit
;
2183 if (v
> 32767) then v
:= 32767;
2184 Damage(v
, 0, 0, 0, mEDamageType
);
2187 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2191 if (not g_Game_IsClient
) and (not FAlive
) then
2196 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2197 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2199 if not g_Game_IsClient
then
2202 if t
= HIT_TRAP
then
2204 // Ëîâóøêà óáèâàåò ñðàçó:
2206 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2208 if t
= HIT_SELF
then
2212 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2215 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2216 FMegaRulez
[MR_SUIT
] := 0;
2217 FMegaRulez
[MR_INVUL
] := 0;
2218 FMegaRulez
[MR_INVIS
] := 0;
2222 // Íî îò îñòàëüíîãî ñïàñàåò:
2223 if FMegaRulez
[MR_INVUL
] >= gTime
then
2230 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2231 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2232 (SpawnerUID
= FUID
) or
2233 (not SameTeam(FUID
, SpawnerUID
)) then
2235 FLastSpawnerUID
:= SpawnerUID
;
2237 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2238 if gBloodCount
> 0 then
2240 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2241 if value
div 4 <= c
then
2242 c
:= c
- (value
div 4)
2246 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2250 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2251 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2254 if t
= HIT_WATER
then
2255 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2256 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2261 Inc(FDamageBuffer
, value
);
2265 FPain
:= FPain
+ value
;
2268 if g_Game_IsServer
and g_Game_IsNet
then
2270 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2271 MH_SEND_PlayerStats(FUID
);
2272 MH_SEND_PlayerPos(False, FUID
);
2276 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2279 if g_Game_IsClient
then
2284 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2286 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2289 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2291 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2295 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2296 MH_SEND_PlayerStats(FUID
);
2299 destructor TPlayer
.Destroy();
2301 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2303 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2307 FSawSoundIdle
.Free();
2308 FSawSoundHit
.Free();
2309 FSawSoundSelect
.Free();
2310 FFlameSoundOn
.Free();
2311 FFlameSoundOff
.Free();
2312 FFlameSoundWork
.Free();
2313 FJetSoundFly
.Free();
2315 FJetSoundOff
.Free();
2317 if FPunchAnim
<> nil then
2323 procedure TPlayer
.DrawIndicator();
2325 indX
, indY
: Integer;
2331 indX
:= FObj
.X
+FObj
.Rect
.X
;
2333 if g_Texture_Get('TEXTURE_PLAYER_INDICATOR', ID
) then
2335 e_GetTextureSize(ID
, @indW
, @indH
);
2336 e_Draw(ID
, indX
+ indW
div 2, indY
- indH
, 0, True, False);
2339 //e_TextureFontPrint(indX, indY, FName, gStdFont); // Shows player name overhead
2342 procedure TPlayer
.DrawBubble();
2344 bubX
, bubY
: Integer;
2347 Rw
, Gw
, Bw
: SmallInt;
2350 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= TDirection
.D_LEFT
, -4, 18);
2351 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2359 1: // simple textual non-bubble
2361 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2362 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2363 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2366 2: // advanced pixel-perfect bubble
2368 if FTeam
= TEAM_RED
then
2371 if FTeam
= TEAM_BLUE
then
2374 3: // colored bubble
2376 Rb
:= FModel
.Color
.R
;
2377 Gb
:= FModel
.Color
.G
;
2378 Bb
:= FModel
.Color
.B
;
2379 Rw
:= Min(Rb
* 2 + 64, 255);
2380 Gw
:= Min(Gb
* 2 + 64, 255);
2381 Bw
:= Min(Bb
* 2 + 64, 255);
2382 if (Abs(Rw
- Rb
) < 32)
2383 or (Abs(Gw
- Gb
) < 32)
2384 or (Abs(Bw
- Bb
) < 32) then
2386 Rb
:= Max(Rw
div 2 - 16, 0);
2387 Gb
:= Max(Gw
div 2 - 16, 0);
2388 Bb
:= Max(Bw
div 2 - 16, 0);
2391 4: // custom textured bubble
2393 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2394 if FDirection
= TDirection
.D_RIGHT
then
2395 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2397 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, TMirrorType
.Horizontal
);
2403 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2404 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2406 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2409 Dot
:= IfThen(FDirection
= TDirection
.D_LEFT
, 14, 5);
2410 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2411 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
);
2412 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
);
2413 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
);
2414 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
);
2418 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2419 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2420 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2423 procedure TPlayer
.Draw();
2428 Mirror
: TMirrorType
;
2432 if Direction
= TDirection
.D_RIGHT
then
2433 Mirror
:= TMirrorType
.None
2435 Mirror
:= TMirrorType
.Horizontal
;
2437 if FPunchAnim
<> nil then
2439 FPunchAnim
.Draw(FObj
.X
+IfThen(Direction
= TDirection
.D_LEFT
, 15-FObj
.Rect
.X
, FObj
.Rect
.X
-15),
2440 FObj
.Y
+FObj
.Rect
.Y
-11, Mirror
);
2441 if FPunchAnim
.played
then
2448 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2449 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2451 e_GetTextureSize(ID
, @w
, @h
);
2452 if FDirection
= TDirection
.D_LEFT
then
2453 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2454 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False)
2456 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2457 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False);
2460 if FMegaRulez
[MR_INVIS
] > gTime
then
2462 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2463 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2465 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2466 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2470 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 200)
2472 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2475 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 254);
2478 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2481 if g_debug_Frames
then
2483 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2485 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2486 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2490 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2491 if (FMegaRulez
[MR_INVIS
] <= gTime
) or ((gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2492 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
)))) then
2494 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2495 if gAimLine
and alive
and
2496 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2501 procedure TPlayer
.DrawAim();
2502 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2507 {$IFDEF ENABLE_HOLMES}
2508 if isValidViewPort
and (self
= gPlayer1
) then
2510 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2514 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2515 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2517 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2521 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2526 wx
, wy
, xx
, yy
: Integer;
2530 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= TDirection
.D_LEFT
, 7, -7);
2531 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2540 1: begin // Chainsaw
2547 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2548 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2549 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2550 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2555 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2556 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2557 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2558 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2560 4: begin // Double Shotgun
2563 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2564 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2565 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2566 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2568 5: begin // Chaingun
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);
2576 6: begin // Rocket Launcher
2579 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2580 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2581 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2582 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2584 7: begin // Plasmagun
2587 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2588 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2589 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2590 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2595 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2596 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2597 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2598 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2600 9: begin // Super Chaingun
2603 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2604 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2605 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2606 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2609 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2610 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2611 {$IF DEFINED(D2F_DEBUG)}
2612 drawCast(sz
, wx
, wy
, xx
, yy
);
2614 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2618 procedure TPlayer
.DrawGUI();
2621 X
, Y
, SY
, a
, p
, m
: Integer;
2625 stat
: TPlayerStatArray
;
2627 X
:= gPlayerScreenSize
.X
;
2628 SY
:= gPlayerScreenSize
.Y
;
2631 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2633 if gGameSettings
.GameMode
= GM_CTF
then
2637 if gGameSettings
.GameMode
= GM_CTF
then
2639 s
:= 'TEXTURE_PLAYER_REDFLAG';
2640 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2641 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2642 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2643 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2644 if g_Texture_Get(s
, ID
) then
2645 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2648 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2649 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2650 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2652 if gGameSettings
.GameMode
= GM_CTF
then
2654 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2655 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2656 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2657 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2658 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2659 if g_Texture_Get(s
, ID
) then
2660 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2663 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2664 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2665 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2668 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2669 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2672 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2673 e_Draw(ID
, X
+2, Y
, 0, True, False);
2675 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2679 s
:= IntToStr(Frags
);
2680 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2681 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2686 stat
:= g_Player_GetStats();
2691 for a
:= 0 to High(stat
) do
2692 if stat
[a
].Name
<> Name
then
2694 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2695 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2699 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2700 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2701 s
:= s
+IntToStr(Abs(Frags
-m
));
2703 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2704 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2707 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2709 s
:= IntToStr(Lives
);
2710 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2711 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2715 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2716 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2718 if R_BERSERK
in FRulez
then
2719 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2721 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2723 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2724 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2726 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2727 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2728 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2730 s
:= IntToStr(FArmor
);
2731 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2732 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2734 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2740 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2745 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2747 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2748 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2749 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2750 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2751 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2752 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2753 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2754 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2755 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2758 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2759 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2760 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2762 if R_KEY_RED
in FRulez
then
2763 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2765 if R_KEY_GREEN
in FRulez
then
2766 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2768 if R_KEY_BLUE
in FRulez
then
2769 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2771 if FJetFuel
> 0 then
2773 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2774 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2775 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2776 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2777 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2778 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2782 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2783 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2784 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2787 if gShowPing
and g_Game_IsClient
then
2789 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2790 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2796 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2797 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2798 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2801 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2802 s
:= _lc
[I_PLAYER_SPECT4
];
2803 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2804 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2805 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2811 procedure TPlayer
.DrawRulez();
2815 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2816 if FMegaRulez
[MR_INVUL
] >= gTime
then
2818 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2819 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2824 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2825 191, 191, 191, 0, TBlending
.Invert
);
2828 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2829 if FMegaRulez
[MR_SUIT
] >= gTime
then
2831 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2832 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2837 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2838 0, 96, 0, 200, TBlending
.None
);
2841 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2842 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2844 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2845 255, 0, 0, 200, TBlending
.None
);
2849 procedure TPlayer
.DrawPain();
2853 if FPain
= 0 then Exit
;
2857 if a
< 15 then h
:= 0
2858 else if a
< 35 then h
:= 1
2859 else if a
< 55 then h
:= 2
2860 else if a
< 75 then h
:= 3
2861 else if a
< 95 then h
:= 4
2864 //if a > 255 then a := 255;
2866 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2867 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2870 procedure TPlayer
.DrawPickup();
2874 if FPickup
= 0 then Exit
;
2878 if a
< 15 then h
:= 1
2879 else if a
< 35 then h
:= 2
2880 else if a
< 55 then h
:= 3
2881 else if a
< 75 then h
:= 4
2884 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2887 procedure TPlayer
.DoPunch();
2892 if FPunchAnim
<> nil then begin
2897 st
:= 'FRAMES_PUNCH';
2898 if R_BERSERK
in FRulez
then
2899 st
:= st
+ '_BERSERK';
2900 if FKeys
[KEY_UP
].Pressed
then
2902 else if FKeys
[KEY_DOWN
].Pressed
then
2904 g_Frames_Get(id
, st
);
2905 FPunchAnim
:= TAnimation
.Create(id
, False, 1);
2908 procedure TPlayer
.Fire();
2910 f
, DidFire
: Boolean;
2911 wx
, wy
, xd
, yd
: Integer;
2914 if g_Game_IsClient
then Exit
;
2915 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2916 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2924 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2929 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2930 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2931 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
2932 yd
:= wy
+firediry();
2938 if R_BERSERK
in FRulez
then
2940 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2941 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2942 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2945 locobj
.rect
.Width
:= 39;
2946 locobj
.rect
.Height
:= 52;
2947 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2948 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2949 locobj
.Accel
.X
:= xd
-wx
;
2950 locobj
.Accel
.y
:= yd
-wy
;
2952 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2953 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2955 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2957 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
2961 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2965 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2970 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2971 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2973 FSawSoundSelect
.Stop();
2975 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2977 else if not FSawSoundHit
.IsPlaying() then
2979 FSawSoundSelect
.Stop();
2980 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2983 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2989 if FAmmo
[A_BULLETS
] > 0 then
2991 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2992 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2993 Dec(FAmmo
[A_BULLETS
]);
2994 FFireAngle
:= FAngle
;
2997 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2998 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3002 if FAmmo
[A_SHELLS
] > 0 then
3004 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3005 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
3006 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3007 Dec(FAmmo
[A_SHELLS
]);
3008 FFireAngle
:= FAngle
;
3012 FShellType
:= SHELL_SHELL
;
3016 if FAmmo
[A_SHELLS
] >= 2 then
3018 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
3019 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3020 Dec(FAmmo
[A_SHELLS
], 2);
3021 FFireAngle
:= FAngle
;
3025 FShellType
:= SHELL_DBLSHELL
;
3029 if FAmmo
[A_BULLETS
] > 0 then
3031 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
3032 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
3033 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3034 Dec(FAmmo
[A_BULLETS
]);
3035 FFireAngle
:= FAngle
;
3038 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3039 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3042 WEAPON_ROCKETLAUNCHER
:
3043 if FAmmo
[A_ROCKETS
] > 0 then
3045 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
3046 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3047 Dec(FAmmo
[A_ROCKETS
]);
3048 FFireAngle
:= FAngle
;
3054 if FAmmo
[A_CELLS
] > 0 then
3056 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
3057 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3058 Dec(FAmmo
[A_CELLS
]);
3059 FFireAngle
:= FAngle
;
3065 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
3067 FBFGFireCounter
:= 17;
3068 if not FNoReload
then
3069 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
3070 Dec(FAmmo
[A_CELLS
], 40);
3074 WEAPON_SUPERPULEMET
:
3075 if FAmmo
[A_SHELLS
] > 0 then
3077 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3078 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
3079 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3080 Dec(FAmmo
[A_SHELLS
]);
3081 FFireAngle
:= FAngle
;
3084 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3085 GameVelX
, GameVelY
-2, SHELL_SHELL
);
3088 WEAPON_FLAMETHROWER
:
3089 if FAmmo
[A_FUEL
] > 0 then
3091 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
3093 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3095 FFireAngle
:= FAngle
;
3102 if g_Game_IsNet
and g_Game_IsServer
then MH_SEND_PlayerStats(FUID
);
3106 if g_Game_IsNet
then
3110 if FCurrWeap
<> WEAPON_BFG
then
3111 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
3113 if not FNoReload
then
3114 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
3117 MH_SEND_PlayerStats(FUID
);
3122 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
3123 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
3124 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
3127 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
3130 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
3131 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
3132 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
3133 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
3134 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
3139 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
3141 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
3142 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
3143 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
3146 procedure TPlayer
.FlamerOn
;
3148 FFlameSoundOff
.Stop();
3149 FFlameSoundOff
.SetPosition(0);
3152 if (not FFlameSoundOn
.IsPlaying()) and (not FFlameSoundWork
.IsPlaying()) then
3153 FFlameSoundWork
.PlayAt(FObj
.X
, FObj
.Y
);
3157 FFlameSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3162 procedure TPlayer
.FlamerOff
;
3166 FFlameSoundOn
.Stop();
3167 FFlameSoundOn
.SetPosition(0);
3168 FFlameSoundWork
.Stop();
3169 FFlameSoundWork
.SetPosition(0);
3170 FFlameSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3175 procedure TPlayer
.JetpackOn
;
3179 FJetSoundOn
.SetPosition(0);
3180 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3184 procedure TPlayer
.JetpackOff
;
3188 FJetSoundOff
.SetPosition(0);
3189 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3192 procedure TPlayer
.CatchFire(Attacker
: Word);
3194 if (FMegaRulez
[MR_SUIT
] > gTime
) or (FMegaRulez
[MR_INVUL
] > gTime
) then
3195 exit
; // Íå çàãîðàåìñÿ êîãäà åñòü çàùèòà
3196 if FFireTime
<= 0 then
3197 g_Sound_PlayExAt('SOUND_IGNITE', FObj
.X
, FObj
.Y
);
3199 FFireAttacker
:= Attacker
;
3200 if g_Game_IsNet
and g_Game_IsServer
then
3201 MH_SEND_PlayerStats(FUID
);
3204 procedure TPlayer
.Jump();
3206 if gFly
or FJetpack
then
3208 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3209 if FObj
.Vel
.Y
> -VEL_FLY
then
3210 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3213 if FJetFuel
> 0 then
3215 if (FJetFuel
< 1) and g_Game_IsServer
then
3219 if g_Game_IsNet
then
3220 MH_SEND_PlayerStats(FUID
);
3226 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3228 FCanJetpack
:= False;
3230 // Ïðûãàåì èëè âñïëûâàåì:
3231 if (CollideLevel(0, 1) or
3232 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3233 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3234 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3236 FObj
.Vel
.Y
:= -VEL_JUMP
;
3237 FCanJetpack
:= False;
3241 if BodyInLiquid(0, 0) then
3242 FObj
.Vel
.Y
:= -VEL_SW
3243 else if (FJetFuel
> 0) and FCanJetpack
and
3244 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3248 if g_Game_IsNet
then
3249 MH_SEND_PlayerStats(FUID
);
3254 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3256 a
, i
, k
, ab
, ar
: Byte;
3260 srv
, netsrv
: Boolean;
3266 procedure PushItem(t
: Byte);
3270 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3271 it
:= g_Items_ByIdx(id
);
3272 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3274 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3275 (FObj
.Vel
.Y
div 2)-Random(9));
3276 it
.positionChanged(); // this updates spatial accelerators
3280 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3282 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3283 (FObj
.Vel
.Y
div 2)-Random(6));
3285 else // -3..+3; -3..0
3287 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3288 (FObj
.Vel
.Y
div 2)-Random(4));
3290 it
.positionChanged(); // this updates spatial accelerators
3293 if g_Game_IsNet
and g_Game_IsServer
then
3294 MH_SEND_ItemSpawn(True, id
);
3298 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3299 Srv
:= g_Game_IsServer
;
3300 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3301 if Srv
then FDeath
:= FDeath
+ 1;
3306 if not FPhysics
then
3312 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3314 if FLives
> 0 then FLives
:= FLives
- 1;
3315 if FLives
= 0 then FNoRespawn
:= True;
3318 // Íîìåð òèïà ñìåðòè:
3321 K_SIMPLEKILL
: a
:= 1;
3323 K_EXTRAHARDKILL
: a
:= 3;
3328 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3330 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3337 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3339 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3340 K_EXTRAHARDKILL
, K_FALLKILL
:
3341 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3344 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3348 K_HARDKILL
, K_EXTRAHARDKILL
:
3352 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3353 if (KillType
<> K_FALLKILL
) and (Srv
) then
3354 g_Monsters_killedp();
3356 if SpawnerUID
= FUID
then
3358 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3363 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3366 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3367 begin // Óáèò äðóãèì èãðîêîì
3368 KP
:= g_Player_Get(SpawnerUID
);
3369 if (KP
<> nil) and Srv
then
3371 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3372 if SameTeam(FUID
, SpawnerUID
) then
3382 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3383 Inc(gTeamStat
[KP
.Team
].Goals
,
3384 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3386 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3389 plr
:= g_Player_Get(SpawnerUID
);
3397 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3401 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3405 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3410 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3411 begin // Óáèò ìîíñòðîì
3412 mon
:= g_Monsters_ByUID(SpawnerUID
);
3416 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
3420 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3424 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3428 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3433 else // Îñîáûå òèïû ñìåðòè
3436 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3437 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3438 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3439 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3440 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3441 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3447 for a
:= WP_FIRST
to WP_LAST
do
3451 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3452 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3453 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3454 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3455 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3456 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3457 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3458 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3459 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3468 if R_ITEM_BACKPACK
in FRulez
then
3469 PushItem(ITEM_AMMO_BACKPACK
);
3471 // Âûáðîñ ðàêåòíîãî ðàíöà:
3472 if FJetFuel
> 0 then
3473 PushItem(ITEM_JETPACK
);
3476 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3478 if R_KEY_RED
in FRulez
then
3479 PushItem(ITEM_KEY_RED
);
3481 if R_KEY_GREEN
in FRulez
then
3482 PushItem(ITEM_KEY_GREEN
);
3484 if R_KEY_BLUE
in FRulez
then
3485 PushItem(ITEM_KEY_BLUE
);
3489 DropFlag(KillType
= K_FALLKILL
);
3492 g_Player_CreateCorpse(Self
);
3494 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3495 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3501 for i
:= Low(gPlayers
) to High(gPlayers
) do
3503 if gPlayers
[i
] = nil then continue
;
3504 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3507 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3508 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3513 OldLR
:= gLMSRespawn
;
3514 if (gGameSettings
.GameMode
= GM_COOP
) then
3518 // everyone is dead, restart the map
3519 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3521 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3522 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3523 gLMSRespawnTime
:= gTime
+ 5000;
3525 else if (a
= 1) then
3527 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3528 if (gPlayers
[k
] = gPlayer1
) or
3529 (gPlayers
[k
] = gPlayer2
) then
3530 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3531 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3532 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3535 else if (gGameSettings
.GameMode
= GM_TDM
) then
3537 if (ab
= 0) and (ar
<> 0) then
3540 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3542 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3543 Inc(gTeamStat
[TEAM_RED
].Goals
);
3544 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3545 gLMSRespawnTime
:= gTime
+ 5000;
3547 else if (ar
= 0) and (ab
<> 0) then
3550 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3552 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3553 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3554 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3555 gLMSRespawnTime
:= gTime
+ 5000;
3557 else if (ar
= 0) and (ab
= 0) then
3560 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3562 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3563 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3564 gLMSRespawnTime
:= gTime
+ 5000;
3567 else if (gGameSettings
.GameMode
= GM_DM
) then
3571 if gPlayers
[k
] <> nil then
3574 // survivor is the winner
3575 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3577 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3580 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3581 gLMSRespawnTime
:= gTime
+ 5000;
3583 else if (a
= 0) then
3585 // everyone is dead, restart the map
3586 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3588 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3589 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3590 gLMSRespawnTime
:= gTime
+ 5000;
3593 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3595 if NetMode
= NET_SERVER
then
3596 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3598 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3604 MH_SEND_PlayerStats(FUID
);
3605 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3606 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3609 if srv
and FNoRespawn
then Spectate(True);
3610 FWantsInGame
:= True;
3613 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3615 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3616 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3619 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3621 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3622 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3625 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3627 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3628 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3629 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3630 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3631 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3632 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3633 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3634 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3637 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3639 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3640 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3641 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3642 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3645 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3647 if g_Game_IsClient
then Exit
;
3648 if Weapon
> High(FWeapon
) then Exit
;
3649 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3652 procedure TPlayer
.resetWeaponQueue ();
3655 FNextWeapDelay
:= 0;
3658 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3662 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3663 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 0);
3664 WEAPON_PISTOL
, WEAPON_CHAINGUN
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_BULLETS
] > 0);
3665 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3666 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3667 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3668 else result
:= (weapon
< length(FWeapon
));
3672 // return 255 for "no switch"
3673 function TPlayer
.getNextWeaponIndex (): Byte;
3676 wantThisWeapon
: array[0..64] of Boolean;
3677 wwc
: Integer = 0; //HACK!
3680 result
:= 255; // default result: "no switch"
3681 // had weapon cycling on previous frame? remove that flag
3682 if (FNextWeap
and $2000) <> 0 then
3684 FNextWeap
:= FNextWeap
and $1FFF;
3685 FNextWeapDelay
:= 0;
3687 // cycling has priority
3688 if (FNextWeap
and $C000) <> 0 then
3690 if (FNextWeap
and $8000) <> 0 then
3694 FNextWeap
:= FNextWeap
or $2000; // we need this
3695 if FNextWeapDelay
> 0 then
3696 exit
; // cooldown time
3698 for i
:= 0 to High(FWeapon
) do
3700 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3701 if FWeapon
[cwi
] then
3703 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d', [FCurrWeap, cwi]), MSG_WARNING);
3704 result
:= Byte(cwi
);
3705 FNextWeapDelay
:= WEAPON_DELAY
;
3713 for i
:= 0 to High(wantThisWeapon
) do
3714 wantThisWeapon
[i
] := false;
3715 for i
:= 0 to High(FWeapon
) do
3716 if (FNextWeap
and (1 shl i
)) <> 0 then
3718 wantThisWeapon
[i
] := true;
3721 // exclude currently selected weapon from the set
3722 wantThisWeapon
[FCurrWeap
] := false;
3723 // slow down alterations a little
3726 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3727 // more than one weapon requested, assume "alteration" and check alteration delay
3728 if FNextWeapDelay
> 0 then
3734 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3735 // but clear all counters if no weapon should be switched
3741 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3742 // try weapons in descending order
3743 for i
:= High(FWeapon
) downto 0 do
3745 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3750 FNextWeapDelay
:= WEAPON_DELAY
* 2; // anyway, 'cause why not
3754 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3758 procedure TPlayer
.RealizeCurrentWeapon();
3759 function switchAllowed (): Boolean;
3764 if FBFGFireCounter
<> -1 then
3766 if FTime
[T_SWITCH
] > gTime
then
3768 for i
:= WP_FIRST
to WP_LAST
do
3769 if FReloading
[i
] > 0 then
3777 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3778 //FNextWeap := FNextWeap and $1FFF;
3779 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3781 if not switchAllowed
then
3783 //HACK for weapon cycling
3784 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3788 nw
:= getNextWeaponIndex();
3789 if nw
= 255 then exit
; // don't reset anything here
3790 if nw
> High(FWeapon
) then
3792 // don't forget to reset queue here!
3793 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3801 FTime
[T_SWITCH
] := gTime
+156;
3802 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3803 FModel
.SetWeapon(FCurrWeap
);
3804 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3808 procedure TPlayer
.NextWeapon();
3810 if g_Game_IsClient
then Exit
;
3814 procedure TPlayer
.PrevWeapon();
3816 if g_Game_IsClient
then Exit
;
3820 procedure TPlayer
.SetWeapon(W
: Byte);
3822 if FCurrWeap
<> W
then
3823 if W
= WEAPON_SAW
then
3824 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3827 FModel
.SetWeapon(CurrWeap
);
3831 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3833 function allowBerserkSwitching (): Boolean;
3835 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3837 if gBerserkAutoswitch
then exit
;
3838 if not conIsCheatsEnabled
then exit
;
3846 if g_Game_IsClient
then Exit
;
3848 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3849 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3854 if FHealth
< PLAYER_HP_SOFT
then
3856 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3860 if gFlash
= 2 then Inc(FPickup
, 5);
3864 if FHealth
< PLAYER_HP_SOFT
then
3866 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3870 if gFlash
= 2 then Inc(FPickup
, 5);
3874 if FArmor
< PLAYER_AP_SOFT
then
3876 FArmor
:= PLAYER_AP_SOFT
;
3879 if gFlash
= 2 then Inc(FPickup
, 5);
3883 if FArmor
< PLAYER_AP_LIMIT
then
3885 FArmor
:= PLAYER_AP_LIMIT
;
3888 if gFlash
= 2 then Inc(FPickup
, 5);
3892 if FHealth
< PLAYER_HP_LIMIT
then
3894 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3898 if gFlash
= 2 then Inc(FPickup
, 5);
3902 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3904 if FHealth
< PLAYER_HP_LIMIT
then
3905 FHealth
:= PLAYER_HP_LIMIT
;
3906 if FArmor
< PLAYER_AP_LIMIT
then
3907 FArmor
:= PLAYER_AP_LIMIT
;
3911 if gFlash
= 2 then Inc(FPickup
, 5);
3915 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3917 FWeapon
[WEAPON_SAW
] := True;
3919 if gFlash
= 2 then Inc(FPickup
, 5);
3920 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3923 ITEM_WEAPON_SHOTGUN1
:
3924 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3926 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3927 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3929 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3930 FWeapon
[WEAPON_SHOTGUN1
] := True;
3932 if gFlash
= 2 then Inc(FPickup
, 5);
3933 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3936 ITEM_WEAPON_SHOTGUN2
:
3937 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3939 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3941 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3942 FWeapon
[WEAPON_SHOTGUN2
] := True;
3944 if gFlash
= 2 then Inc(FPickup
, 5);
3945 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3948 ITEM_WEAPON_CHAINGUN
:
3949 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3951 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3953 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3954 FWeapon
[WEAPON_CHAINGUN
] := True;
3956 if gFlash
= 2 then Inc(FPickup
, 5);
3957 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3960 ITEM_WEAPON_ROCKETLAUNCHER
:
3961 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3963 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3965 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3966 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3968 if gFlash
= 2 then Inc(FPickup
, 5);
3969 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3973 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3975 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3977 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3978 FWeapon
[WEAPON_PLASMA
] := True;
3980 if gFlash
= 2 then Inc(FPickup
, 5);
3981 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3985 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3987 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3989 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3990 FWeapon
[WEAPON_BFG
] := True;
3992 if gFlash
= 2 then Inc(FPickup
, 5);
3993 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3996 ITEM_WEAPON_SUPERPULEMET
:
3997 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3999 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
4001 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4002 FWeapon
[WEAPON_SUPERPULEMET
] := True;
4004 if gFlash
= 2 then Inc(FPickup
, 5);
4005 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4008 ITEM_WEAPON_FLAMETHROWER
:
4009 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
4011 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
4013 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4014 FWeapon
[WEAPON_FLAMETHROWER
] := True;
4016 if gFlash
= 2 then Inc(FPickup
, 5);
4017 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4021 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4023 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4026 if gFlash
= 2 then Inc(FPickup
, 5);
4029 ITEM_AMMO_BULLETS_BOX
:
4030 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4032 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4035 if gFlash
= 2 then Inc(FPickup
, 5);
4039 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4041 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4044 if gFlash
= 2 then Inc(FPickup
, 5);
4047 ITEM_AMMO_SHELLS_BOX
:
4048 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4050 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
4053 if gFlash
= 2 then Inc(FPickup
, 5);
4057 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4059 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4062 if gFlash
= 2 then Inc(FPickup
, 5);
4065 ITEM_AMMO_ROCKET_BOX
:
4066 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4068 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
4071 if gFlash
= 2 then Inc(FPickup
, 5);
4075 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4077 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4080 if gFlash
= 2 then Inc(FPickup
, 5);
4084 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4086 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4089 if gFlash
= 2 then Inc(FPickup
, 5);
4093 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4095 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4098 if gFlash
= 2 then Inc(FPickup
, 5);
4102 if not(R_ITEM_BACKPACK
in FRulez
) or
4103 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4104 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4105 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4106 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4107 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
4109 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4110 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4111 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4112 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4113 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4115 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4116 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4117 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4118 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4119 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4120 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4121 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4122 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4124 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
4127 if gFlash
= 2 then Inc(FPickup
, 5);
4131 if not(R_KEY_RED
in FRulez
) then
4133 Include(FRulez
, R_KEY_RED
);
4135 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4136 if gFlash
= 2 then Inc(FPickup
, 5);
4137 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4141 if not(R_KEY_GREEN
in FRulez
) then
4143 Include(FRulez
, R_KEY_GREEN
);
4145 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4146 if gFlash
= 2 then Inc(FPickup
, 5);
4147 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4151 if not(R_KEY_BLUE
in FRulez
) then
4153 Include(FRulez
, R_KEY_BLUE
);
4155 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4156 if gFlash
= 2 then Inc(FPickup
, 5);
4157 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4161 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4163 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4167 if gFlash
= 2 then Inc(FPickup
, 5);
4171 if FAir
< AIR_MAX
then
4176 if gFlash
= 2 then Inc(FPickup
, 5);
4181 if not (R_BERSERK
in FRulez
) then
4183 Include(FRulez
, R_BERSERK
);
4184 if allowBerserkSwitching
then
4186 FCurrWeap
:= WEAPON_KASTET
;
4188 FModel
.SetWeapon(WEAPON_KASTET
);
4193 if gFlash
= 2 then Inc(FPickup
, 5);
4195 FBerserk
:= gTime
+30000;
4200 if FHealth
< PLAYER_HP_SOFT
then
4202 FHealth
:= PLAYER_HP_SOFT
;
4203 FBerserk
:= gTime
+30000;
4211 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4213 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4216 if gFlash
= 2 then Inc(FPickup
, 5);
4220 if FHealth
< PLAYER_HP_LIMIT
then
4222 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4226 if gFlash
= 2 then Inc(FPickup
, 5);
4230 if FArmor
< PLAYER_AP_LIMIT
then
4232 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4235 if gFlash
= 2 then Inc(FPickup
, 5);
4239 if FJetFuel
< JET_MAX
then
4241 FJetFuel
:= JET_MAX
;
4244 if gFlash
= 2 then Inc(FPickup
, 5);
4248 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4250 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4253 if gFlash
= 2 then Inc(FPickup
, 5);
4258 procedure TPlayer
.Touch();
4262 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4265 // Áðîñèòü ôëàã òîâàðèùó:
4266 if gGameSettings
.GameMode
= GM_CTF
then
4271 procedure TPlayer
.Push(vx
, vy
: Integer);
4273 if (not FPhysics
) and FGhost
then
4275 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4276 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4277 if g_Game_IsNet
and g_Game_IsServer
then
4278 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4281 procedure TPlayer
.Reset(Force
: Boolean);
4287 FTime
[T_RESPAWN
] := 0;
4288 FTime
[T_FLAGCAP
] := 0;
4302 FSpectator
:= False;
4305 FSpectatePlayer
:= -1;
4306 FNoRespawn
:= False;
4308 FLives
:= gGameSettings
.MaxLives
;
4313 procedure TPlayer
.SoftReset();
4319 FBFGFireCounter
:= -1;
4327 SetAction(A_STAND
, True);
4330 function TPlayer
.GetRespawnPoint(): Byte;
4335 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4337 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4338 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4340 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4342 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4343 if Self
= gPlayer1
then
4344 c
:= RESPAWNPOINT_PLAYER1
4346 c
:= RESPAWNPOINT_PLAYER2
;
4347 if g_Map_GetPointCount(c
) > 0 then
4353 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4354 if Self
= gPlayer1
then
4355 c
:= RESPAWNPOINT_PLAYER2
4357 c
:= RESPAWNPOINT_PLAYER1
;
4358 if g_Map_GetPointCount(c
) > 0 then
4365 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4366 if Random(2) = 0 then
4367 c
:= RESPAWNPOINT_PLAYER1
4369 c
:= RESPAWNPOINT_PLAYER2
;
4370 if g_Map_GetPointCount(c
) > 0 then
4377 // Òî÷êà ëþáîé èç êîìàíä
4378 if Random(2) = 0 then
4379 c
:= RESPAWNPOINT_RED
4381 c
:= RESPAWNPOINT_BLUE
;
4382 if g_Map_GetPointCount(c
) > 0 then
4389 c
:= RESPAWNPOINT_DM
;
4390 if g_Map_GetPointCount(c
) > 0 then
4398 if gGameSettings
.GameMode
= GM_DM
then
4401 c
:= RESPAWNPOINT_DM
;
4402 if g_Map_GetPointCount(c
) > 0 then
4408 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4409 if Random(2) = 0 then
4410 c
:= RESPAWNPOINT_PLAYER1
4412 c
:= RESPAWNPOINT_PLAYER2
;
4413 if g_Map_GetPointCount(c
) > 0 then
4419 // Òî÷êà ëþáîé èç êîìàíä
4420 if Random(2) = 0 then
4421 c
:= RESPAWNPOINT_RED
4423 c
:= RESPAWNPOINT_BLUE
;
4424 if g_Map_GetPointCount(c
) > 0 then
4432 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4434 // Òî÷êà ñâîåé êîìàíäû
4435 c
:= RESPAWNPOINT_DM
;
4436 if FTeam
= TEAM_RED
then
4437 c
:= RESPAWNPOINT_RED
;
4438 if FTeam
= TEAM_BLUE
then
4439 c
:= RESPAWNPOINT_BLUE
;
4440 if g_Map_GetPointCount(c
) > 0 then
4447 c
:= RESPAWNPOINT_DM
;
4448 if g_Map_GetPointCount(c
) > 0 then
4454 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4455 if Random(2) = 0 then
4456 c
:= RESPAWNPOINT_PLAYER1
4458 c
:= RESPAWNPOINT_PLAYER2
;
4459 if g_Map_GetPointCount(c
) > 0 then
4465 // Òî÷êà äðóãîé êîìàíäû
4466 c
:= RESPAWNPOINT_DM
;
4467 if FTeam
= TEAM_RED
then
4468 c
:= RESPAWNPOINT_BLUE
;
4469 if FTeam
= TEAM_BLUE
then
4470 c
:= RESPAWNPOINT_RED
;
4471 if g_Map_GetPointCount(c
) > 0 then
4479 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4481 RespawnPoint
: TRespawnPoint
;
4487 FBFGFireCounter
:= -1;
4492 if not g_Game_IsServer
then
4496 FWantsInGame
:= True;
4497 FJustTeleported
:= True;
4500 FTime
[T_RESPAWN
] := 0;
4504 // if server changes MaxLives we gotta be ready
4505 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4507 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4508 if FTime
[T_RESPAWN
] > gTime
then
4511 // Ïðîñðàë âñå æèçíè:
4514 if not FSpectator
then Spectate(True);
4515 FWantsInGame
:= True;
4519 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4520 begin // "Ñâîÿ èãðà"
4521 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4522 FRulez
:= FRulez
-[R_BERSERK
];
4524 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4526 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4527 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4530 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4531 c
:= GetRespawnPoint();
4536 // Âîñêðåøåíèå áåç îðóæèÿ:
4539 FHealth
:= Round(PLAYER_HP_SOFT
* (FHandicap
/ 100));
4545 for a
:= WP_FIRST
to WP_LAST
do
4547 FWeapon
[a
] := False;
4551 FWeapon
[WEAPON_PISTOL
] := True;
4552 FWeapon
[WEAPON_KASTET
] := True;
4553 FCurrWeap
:= WEAPON_PISTOL
;
4556 FModel
.SetWeapon(FCurrWeap
);
4558 for b
:= A_BULLETS
to A_HIGH
do
4561 FAmmo
[A_BULLETS
] := 50;
4563 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4564 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4565 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4566 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4567 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4569 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4570 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4575 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4576 if not g_Map_GetPoint(c
, RespawnPoint
) then
4578 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4582 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4583 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4584 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4590 FDirection
:= RespawnPoint
.Direction
;
4591 if FDirection
= TDirection
.D_LEFT
then
4596 SetAction(A_STAND
, True);
4597 FModel
.Direction
:= FDirection
;
4599 for a
:= Low(FTime
) to High(FTime
) do
4602 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4607 FCanJetpack
:= False;
4613 // Àíèìàöèÿ âîçðîæäåíèÿ:
4614 if (not gLoadGameMode
) and (not Silent
) then
4615 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4617 Anim
:= TAnimation
.Create(ID
, False, 3);
4618 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4619 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4623 FSpectator
:= False;
4626 FSpectatePlayer
:= -1;
4629 if (gPlayer1
= nil) and (gLMSPID1
= FUID
) then
4631 if (gPlayer2
= nil) and (gLMSPID2
= FUID
) then
4634 if g_Game_IsNet
then
4636 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4637 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4639 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4640 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4645 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4648 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4649 else if (not NoMove
) then
4651 GameX
:= gMapInfo
.Width
div 2;
4652 GameY
:= gMapInfo
.Height
div 2;
4661 FWantsInGame
:= False;
4666 if Self
= gPlayer1
then
4671 if Self
= gPlayer2
then
4678 if g_Game_IsNet
then
4679 MH_SEND_PlayerStats(FUID
);
4682 procedure TPlayer
.SwitchNoClip
;
4686 FGhost
:= not FGhost
;
4687 FPhysics
:= not FGhost
;
4699 procedure TPlayer
.Run(Direction
: TDirection
);
4703 if MAX_RUNVEL
> 8 then
4707 if Direction
= TDirection
.D_LEFT
then
4709 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4710 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4713 if FObj
.Vel
.X
< MAX_RUNVEL
then
4714 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4716 // Âîçìîæíî, ïèíàåì êóñêè:
4717 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4719 b
:= Abs(FObj
.Vel
.X
);
4720 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4721 for a
:= 0 to High(gGibs
) do
4723 if gGibs
[a
].alive
and
4724 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4725 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4728 if FObj
.Vel
.X
< 0 then
4730 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4734 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4736 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4744 procedure TPlayer
.SeeDown();
4746 SetAction(A_SEEDOWN
);
4748 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4750 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4753 procedure TPlayer
.SeeUp();
4757 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4759 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4762 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4770 A_ATTACK
: Prior
:= 2;
4771 A_SEEUP
: Prior
:= 1;
4772 A_SEEDOWN
: Prior
:= 1;
4773 A_ATTACKUP
: Prior
:= 2;
4774 A_ATTACKDOWN
: Prior
:= 2;
4779 if (Prior
> FActionPrior
) or Force
then
4780 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4782 FActionPrior
:= Prior
;
4783 FActionAnim
:= Action
;
4784 FActionForce
:= Force
;
4785 FActionChanged
:= True;
4788 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4791 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4793 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4794 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4795 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4796 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4799 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4806 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4808 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4809 if g_Game_IsServer
and g_Game_IsNet
then
4810 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4814 FJustTeleported
:= True;
4819 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4821 Anim
:= TAnimation
.Create(ID
, False, 3);
4824 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4825 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4826 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4827 if g_Game_IsServer
and g_Game_IsNet
then
4828 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4829 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4833 FObj
.X
:= X
-PLAYER_RECT
.X
;
4834 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4835 if FAlive
and FGhost
then
4841 if not g_Game_IsNet
then
4845 SetDirection(TDirection
.D_LEFT
);
4851 SetDirection(TDirection
.D_RIGHT
);
4857 if FDirection
= TDirection
.D_RIGHT
then
4859 SetDirection(TDirection
.D_LEFT
);
4864 SetDirection(TDirection
.D_RIGHT
);
4870 if not silent
and (Anim
<> nil) then
4872 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4873 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4876 if g_Game_IsServer
and g_Game_IsNet
then
4877 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4878 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4885 function nonz(a
: Single): Single;
4893 function TPlayer
.followCorpse(): Boolean;
4898 if FAlive
or FSpectator
then
4900 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
4902 for i
:= 0 to High(gCorpses
) do
4903 if gCorpses
[i
] <> nil then
4904 if gCorpses
[i
].FPlayerUID
= FUID
then
4907 FObj
.X
:= gCorpses
[i
].FObj
.X
;
4908 FObj
.Y
:= gCorpses
[i
].FObj
.Y
;
4909 FObj
.Vel
.X
:= gCorpses
[i
].FObj
.Vel
.X
;
4910 FObj
.Vel
.Y
:= gCorpses
[i
].FObj
.Vel
.Y
;
4911 FObj
.Accel
.X
:= gCorpses
[i
].FObj
.Accel
.X
;
4912 FObj
.Accel
.Y
:= gCorpses
[i
].FObj
.Accel
.Y
;
4917 procedure TPlayer
.Update();
4920 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4921 blockmon
, headwater
, dospawn
: Boolean;
4926 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4927 AnyServer
:= g_Game_IsServer
;
4929 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4930 DoLerp(NetInterpLevel
+ 1)
4936 if FClientID
>= 0 then
4938 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4939 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4940 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4949 if FAlive
and (FPunchAnim
<> nil) then
4950 FPunchAnim
.Update();
4952 if FAlive
and (gFly
or FJetpack
) then
4955 if FDirection
= TDirection
.D_LEFT
then
4960 if FAlive
and (not FGhost
) then
4962 if FKeys
[KEY_UP
].Pressed
then
4964 if FKeys
[KEY_DOWN
].Pressed
then
4968 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4971 i
:= g_basic
.Sign(FIncCam
);
4972 FIncCam
:= Abs(FIncCam
);
4973 DecMin(FIncCam
, 5, 0);
4974 FIncCam
:= FIncCam
*i
;
4977 // no need to do that each second frame, weapon queue will take care of it
4978 if FAlive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4979 if FAlive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4981 if gTime
mod (GAME_TICK
*2) <> 0 then
4983 if (FObj
.Vel
.X
= 0) and FAlive
then
4985 if FKeys
[KEY_LEFT
].Pressed
then
4986 Run(TDirection
.D_LEFT
);
4987 if FKeys
[KEY_RIGHT
].Pressed
then
4988 Run(TDirection
.D_RIGHT
);
4993 if not followCorpse() then
4994 g_Obj_Move(@FObj
, True, True, True);
4995 positionChanged(); // this updates spatial accelerators
5001 FActionChanged
:= False;
5005 // Let alive player do some actions
5006 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
5007 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
5008 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
5009 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
5010 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire()
5016 if NetServer
then MH_SEND_PlayerStats(FUID
);
5019 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
5020 if FKeys
[KEY_JUMP
].Pressed
then Jump()
5023 if AnyServer
and FJetpack
then
5027 if NetServer
then MH_SEND_PlayerStats(FUID
);
5029 FCanJetpack
:= True;
5036 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
5038 if FKeys
[k
].Pressed
then
5046 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5049 if (FTime
[T_RESPAWN
] <= gTime
) and
5050 gGameOn
and (not FAlive
) then
5052 if (g_Player_GetCount() > 1) then
5056 gExit
:= EXIT_RESTART
;
5061 // Dead spectator actions
5064 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
5065 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
5069 if (FSpectatePlayer
>= High(gPlayers
)) then
5070 FSpectatePlayer
:= -1
5074 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
5075 if gPlayers
[I
] <> nil then
5076 if gPlayers
[I
].alive
then
5077 if gPlayers
[I
].UID
<> FUID
then
5079 FSpectatePlayer
:= I
;
5084 if not SetSpect
then FSpectatePlayer
:= -1;
5095 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5097 FYTo
:= FObj
.Y
- 32;
5098 FSpectatePlayer
:= -1;
5100 if FKeys
[KEY_DOWN
].Pressed
then
5102 FYTo
:= FObj
.Y
+ 32;
5103 FSpectatePlayer
:= -1;
5105 if FKeys
[KEY_LEFT
].Pressed
then
5107 FXTo
:= FObj
.X
- 32;
5108 FSpectatePlayer
:= -1;
5110 if FKeys
[KEY_RIGHT
].Pressed
then
5112 FXTo
:= FObj
.X
+ 32;
5113 FSpectatePlayer
:= -1;
5116 if (FXTo
< -64) then
5118 else if (FXTo
> gMapInfo
.Width
+ 32) then
5119 FXTo
:= gMapInfo
.Width
+ 32;
5120 if (FYTo
< -72) then
5122 else if (FYTo
> gMapInfo
.Height
+ 32) then
5123 FYTo
:= gMapInfo
.Height
+ 32;
5128 if not followCorpse() then
5129 g_Obj_Move(@FObj
, True, True, True);
5130 positionChanged(); // this updates spatial accelerators
5137 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5138 if gPlayers
[FSpectatePlayer
] <> nil then
5139 if gPlayers
[FSpectatePlayer
].alive
then
5141 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
5142 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
5146 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5147 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5148 PANEL_BLOCKMON
, True);
5149 headwater
:= HeadInLiquid(0, 0);
5151 // Ñîïðîòèâëåíèå âîçäóõà:
5152 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5153 if FObj
.Vel
.X
<> 0 then
5154 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5156 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5157 DecMin(FPain
, 5, 0);
5158 DecMin(FPickup
, 1, 0);
5160 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5162 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5163 FMegaRulez
[MR_SUIT
] := 0;
5164 FMegaRulez
[MR_INVUL
] := 0;
5165 FMegaRulez
[MR_INVIS
] := 0;
5166 Kill(K_FALLKILL
, 0, HIT_FALL
);
5173 if FCurrWeap
= WEAPON_SAW
then
5174 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5175 FSawSoundSelect
.IsPlaying()) then
5176 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5179 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5180 (not FJetSoundOff
.IsPlaying()) then
5182 FJetSoundFly
.SetPosition(0);
5183 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5186 for b
:= WP_FIRST
to WP_LAST
do
5187 if FReloading
[b
] > 0 then
5193 if FShellTimer
> -1 then
5194 if FShellTimer
= 0 then
5196 if FShellType
= SHELL_SHELL
then
5197 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5198 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5199 else if FShellType
= SHELL_DBLSHELL
then
5201 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5202 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5203 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5204 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5207 end else Dec(FShellTimer
);
5209 if (FBFGFireCounter
> -1) then
5210 if FBFGFireCounter
= 0 then
5214 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5215 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5216 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5217 yd
:= wy
+firediry();
5218 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5219 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5220 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5221 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5222 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5225 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5226 FBFGFireCounter
:= -1;
5229 FBFGFireCounter
:= 0
5231 Dec(FBFGFireCounter
);
5233 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5235 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5237 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5240 if (headwater
or blockmon
) then
5246 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5249 else if (FAir
mod 31 = 0) and not blockmon
then
5251 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5252 if Random(2) = 0 then
5253 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5255 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5257 end else if FAir
< AIR_DEF
then
5260 if FFireTime
> 0 then
5262 if BodyInLiquid(0, 0) then
5267 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5269 if FMegaRulez
[MR_SUIT
] = gTime
then
5276 if FFirePainTime
<= 0 then
5278 if g_Game_IsServer
then
5279 Damage(6, FFireAttacker
, 0, 0, HIT_FLAME
);
5280 FFirePainTime
:= 18;
5282 FFirePainTime
:= FFirePainTime
- 1;
5283 FFireTime
:= FFireTime
- 1;
5284 if ((FFireTime
mod 36) = 0) and (FMegaRulez
[MR_INVUL
] < gTime
) then
5285 FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
);
5286 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5287 MH_SEND_PlayerStats(FUID
);
5291 if FDamageBuffer
> 0 then
5293 if FDamageBuffer
>= 9 then
5297 if FDamageBuffer
< 30 then i
:= 9
5298 else if FDamageBuffer
< 100 then i
:= 18
5302 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5303 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5304 FHealth
:= FHealth
-ii
;
5307 FHealth
:= FHealth
+FArmor
;
5312 if FHealth
<= 0 then
5313 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5314 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5315 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5317 if FAlive
and (FFireTime
<= 0) then
5319 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5320 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5321 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5322 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5329 end; // if FAlive then ...
5331 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5333 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5334 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5335 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5336 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5338 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5339 then SetAction(A_STAND
, True);
5341 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5343 for b
:= Low(FKeys
) to High(FKeys
) do
5344 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5348 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5350 x
:= FObj
.X
+PLAYER_RECT
.X
;
5351 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5352 w
:= PLAYER_RECT
.Width
;
5353 h
:= PLAYER_RECT
.Height
;
5357 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5359 if (dx
<> 0) or (dy
<> 0) then
5368 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5370 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5371 FObj
.Y
+PLAYER_RECT
.Y
,
5378 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5380 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5381 FObj
.Y
+PLAYER_RECT
.Y
,
5385 Panel
.Width
, Panel
.Height
);
5388 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5390 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5391 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5392 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5393 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5396 function g_Player_ValidName(Name
: string): Boolean;
5402 if gPlayers
= nil then Exit
;
5404 for a
:= 0 to High(gPlayers
) do
5405 if gPlayers
[a
] <> nil then
5406 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5413 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5417 d
:= FModel
.Direction
;
5419 FModel
.Direction
:= Direction
;
5420 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5422 FDirection
:= Direction
;
5425 function TPlayer
.GetKeys(): Byte;
5429 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5430 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5431 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5433 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5434 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5437 procedure TPlayer
.Use();
5441 if FTime
[T_USE
] > gTime
then Exit
;
5443 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5444 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5446 for a
:= 0 to High(gPlayers
) do
5447 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5448 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5449 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5450 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5452 gPlayers
[a
].Touch();
5453 if g_Game_IsNet
and g_Game_IsServer
then
5454 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5457 FTime
[T_USE
] := gTime
+120;
5460 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5464 WX
, WY
, XD
, YD
: Integer;
5476 if R_BERSERK
in FRulez
then
5478 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5479 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5480 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5483 locobj
.rect
.Width
:= 39;
5484 locobj
.rect
.Height
:= 52;
5485 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5486 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5487 locobj
.Accel
.X
:= xd
-wx
;
5488 locobj
.Accel
.y
:= yd
-wy
;
5490 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5491 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5493 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5497 FPain
:= min(FPain
+ 25, 50);
5499 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5504 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5505 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5507 FSawSoundSelect
.Stop();
5509 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5511 else if not FSawSoundHit
.IsPlaying() then
5513 FSawSoundSelect
.Stop();
5514 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5521 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5522 FFireAngle
:= FAngle
;
5524 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5525 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5530 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5531 FFireAngle
:= FAngle
;
5534 FShellType
:= SHELL_SHELL
;
5539 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5540 FFireAngle
:= FAngle
;
5543 FShellType
:= SHELL_DBLSHELL
;
5548 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5549 FFireAngle
:= FAngle
;
5551 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5552 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5555 WEAPON_ROCKETLAUNCHER
:
5557 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5558 FFireAngle
:= FAngle
;
5564 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5565 FFireAngle
:= FAngle
;
5571 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5572 FFireAngle
:= FAngle
;
5576 WEAPON_SUPERPULEMET
:
5578 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5579 FFireAngle
:= FAngle
;
5581 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5582 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5585 WEAPON_FLAMETHROWER
:
5587 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5589 FFireAngle
:= FAngle
;
5596 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5597 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5598 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5601 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5603 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5604 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5607 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5611 if NetInterpLevel
< 1 then
5621 AX
:= Abs(FXTo
- FObj
.X
);
5622 AY
:= Abs(FYTo
- FObj
.Y
);
5623 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5625 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5630 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5632 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5633 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5634 PANEL_LIFTUP
, False) then Result
:= -1
5636 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5637 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5638 PANEL_LIFTDOWN
, False) then Result
:= 1
5642 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5649 if Flag
= FLAG_NONE
then
5652 if not g_Game_IsServer
then Exit
;
5654 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5655 if (Flag
= FTeam
) and
5656 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5657 (FFlag
<> FLAG_NONE
) then
5659 if FFlag
= FLAG_RED
then
5660 s
:= _lc
[I_PLAYER_FLAG_RED
]
5662 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5664 evtype
:= FLAG_STATE_SCORED
;
5666 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5667 Insert('.', ts
, Length(ts
) + 1 - 3);
5668 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5670 g_Map_ResetFlag(FFlag
);
5671 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5673 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5674 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5675 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5680 if not sound_cap_flag
[a
].IsPlaying() then
5681 sound_cap_flag
[a
].Play();
5683 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5686 if g_Game_IsNet
then
5688 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5692 gFlags
[FFlag
].CaptureTime
:= 0;
5697 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5698 if (Flag
= FTeam
) and
5699 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5701 if Flag
= FLAG_RED
then
5702 s
:= _lc
[I_PLAYER_FLAG_RED
]
5704 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5706 evtype
:= FLAG_STATE_RETURNED
;
5707 gFlags
[Flag
].CaptureTime
:= 0;
5709 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5711 g_Map_ResetFlag(Flag
);
5712 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5714 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5715 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5716 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5721 if not sound_ret_flag
[a
].IsPlaying() then
5722 sound_ret_flag
[a
].Play();
5725 if g_Game_IsNet
then
5727 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5733 // Ïîäîáðàë ÷óæîé ôëàã:
5734 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5738 if Flag
= FLAG_RED
then
5739 s
:= _lc
[I_PLAYER_FLAG_RED
]
5741 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5743 evtype
:= FLAG_STATE_CAPTURED
;
5745 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5747 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5749 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5751 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5752 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5753 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5758 if not sound_get_flag
[a
].IsPlaying() then
5759 sound_get_flag
[a
].Play();
5762 if g_Game_IsNet
then
5764 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5770 procedure TPlayer
.SetFlag(Flag
: Byte);
5773 if FModel
<> nil then
5774 FModel
.SetFlag(FFlag
);
5777 function TPlayer
.DropFlag(Silent
: Boolean = True): Boolean;
5783 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5785 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5786 with gFlags
[FFlag
] do
5790 Direction
:= FDirection
;
5791 State
:= FLAG_STATE_DROPPED
;
5793 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5794 (FObj
.Vel
.Y
div 2)-2+Random(5));
5795 positionChanged(); // this updates spatial accelerators
5797 if FFlag
= FLAG_RED
then
5798 s
:= _lc
[I_PLAYER_FLAG_RED
]
5800 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5802 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5803 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5805 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5806 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5807 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5812 if (not Silent
) and (not sound_lost_flag
[a
].IsPlaying()) then
5813 sound_lost_flag
[a
].Play();
5815 if g_Game_IsNet
then
5816 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5822 procedure TPlayer
.GetSecret();
5824 if (self
= gPlayer1
) or (self
= gPlayer2
) then
5826 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [FName
]), True);
5827 g_Sound_PlayEx('SOUND_GAME_SECRET');
5832 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5834 Assert(Key
<= High(FKeys
));
5836 FKeys
[Key
].Pressed
:= True;
5837 FKeys
[Key
].Time
:= Time
;
5840 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5842 Result
:= FKeys
[K
].Pressed
;
5845 procedure TPlayer
.ReleaseKeys();
5849 for a
:= Low(FKeys
) to High(FKeys
) do
5851 FKeys
[a
].Pressed
:= False;
5856 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5860 function TPlayer
.firediry(): Integer;
5862 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5863 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5867 procedure TPlayer
.RememberState();
5871 FSavedState
.Health
:= FHealth
;
5872 FSavedState
.Armor
:= FArmor
;
5873 FSavedState
.Air
:= FAir
;
5874 FSavedState
.JetFuel
:= FJetFuel
;
5875 FSavedState
.CurrWeap
:= FCurrWeap
;
5876 FSavedState
.NextWeap
:= FNextWeap
;
5877 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5880 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5882 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5884 FSavedState
.Rulez
:= FRulez
;
5885 FSavedState
.WaitRecall
:= True;
5888 procedure TPlayer
.RecallState();
5892 if not FSavedState
.WaitRecall
then Exit
;
5894 FHealth
:= FSavedState
.Health
;
5895 FArmor
:= FSavedState
.Armor
;
5896 FAir
:= FSavedState
.Air
;
5897 FJetFuel
:= FSavedState
.JetFuel
;
5898 FCurrWeap
:= FSavedState
.CurrWeap
;
5899 FNextWeap
:= FSavedState
.NextWeap
;
5900 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5903 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5905 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5907 FRulez
:= FSavedState
.Rulez
;
5908 FSavedState
.WaitRecall
:= False;
5910 if gGameSettings
.GameType
= GT_SERVER
then
5911 MH_SEND_PlayerStats(FUID
);
5914 procedure TPlayer
.SaveState (st
: TStream
);
5920 utils
.writeSign(st
, 'PLYR');
5921 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
5923 utils
.writeBool(st
, FIamBot
);
5925 utils
.writeInt(st
, Word(FUID
));
5927 utils
.writeStr(st
, FName
);
5929 utils
.writeInt(st
, Byte(FTeam
));
5931 utils
.writeBool(st
, FAlive
);
5932 // Èçðàñõîäîâàë ëè âñå æèçíè
5933 utils
.writeBool(st
, FNoRespawn
);
5935 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
5936 utils
.writeInt(st
, Byte(b
));
5938 utils
.writeInt(st
, LongInt(FHealth
));
5939 // Êîýôôèöèåíò èíâàëèäíîñòè
5940 utils
.writeInt(st
, LongInt(FHandicap
));
5942 utils
.writeInt(st
, Byte(FLives
));
5944 utils
.writeInt(st
, LongInt(FArmor
));
5946 utils
.writeInt(st
, LongInt(FAir
));
5948 utils
.writeInt(st
, LongInt(FJetFuel
));
5950 utils
.writeInt(st
, LongInt(FPain
));
5952 utils
.writeInt(st
, LongInt(FKills
));
5954 utils
.writeInt(st
, LongInt(FMonsterKills
));
5956 utils
.writeInt(st
, LongInt(FFrags
));
5958 utils
.writeInt(st
, Byte(FFragCombo
));
5959 // Âðåìÿ ïîñëåäíåãî ôðàãà
5960 utils
.writeInt(st
, LongWord(FLastFrag
));
5962 utils
.writeInt(st
, LongInt(FDeath
));
5964 utils
.writeInt(st
, Byte(FFlag
));
5966 utils
.writeInt(st
, LongInt(FSecrets
));
5968 utils
.writeInt(st
, Byte(FCurrWeap
));
5970 utils
.writeInt(st
, Word(FNextWeap
));
5972 utils
.writeInt(st
, Byte(FNextWeapDelay
));
5973 // Âðåìÿ çàðÿäêè BFG
5974 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
5976 utils
.writeInt(st
, LongInt(FDamageBuffer
));
5977 // Ïîñëåäíèé óäàðèâøèé
5978 utils
.writeInt(st
, Word(FLastSpawnerUID
));
5979 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
5980 utils
.writeInt(st
, Byte(FLastHit
));
5982 Obj_SaveState(st
, @FObj
);
5983 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
5984 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
5985 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
5986 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
5988 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
5989 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
5990 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
5992 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
5993 // Íàëè÷èå êðàñíîãî êëþ÷à
5994 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
5995 // Íàëè÷èå çåëåíîãî êëþ÷à
5996 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
5997 // Íàëè÷èå ñèíåãî êëþ÷à
5998 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
6000 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
6001 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6002 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
6003 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6004 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
6006 utils
.writeStr(st
, FModel
.Name
);
6008 utils
.writeInt(st
, Byte(FColor
.R
));
6009 utils
.writeInt(st
, Byte(FColor
.G
));
6010 utils
.writeInt(st
, Byte(FColor
.B
));
6014 procedure TPlayer
.LoadState (st
: TStream
);
6023 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
6024 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
6026 FIamBot
:= utils
.readBool(st
);
6028 FUID
:= utils
.readWord(st
);
6030 str
:= utils
.readStr(st
);
6031 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
6033 FTeam
:= utils
.readByte(st
);
6035 FAlive
:= utils
.readBool(st
);
6036 // Èçðàñõîäîâàë ëè âñå æèçíè
6037 FNoRespawn
:= utils
.readBool(st
);
6039 b
:= utils
.readByte(st
);
6040 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
6042 FHealth
:= utils
.readLongInt(st
);
6043 // Êîýôôèöèåíò èíâàëèäíîñòè
6044 FHandicap
:= utils
.readLongInt(st
);
6046 FLives
:= utils
.readByte(st
);
6048 FArmor
:= utils
.readLongInt(st
);
6050 FAir
:= utils
.readLongInt(st
);
6052 FJetFuel
:= utils
.readLongInt(st
);
6054 FPain
:= utils
.readLongInt(st
);
6056 FKills
:= utils
.readLongInt(st
);
6058 FMonsterKills
:= utils
.readLongInt(st
);
6060 FFrags
:= utils
.readLongInt(st
);
6062 FFragCombo
:= utils
.readByte(st
);
6063 // Âðåìÿ ïîñëåäíåãî ôðàãà
6064 FLastFrag
:= utils
.readLongWord(st
);
6066 FDeath
:= utils
.readLongInt(st
);
6068 FFlag
:= utils
.readByte(st
);
6070 FSecrets
:= utils
.readLongInt(st
);
6072 FCurrWeap
:= utils
.readByte(st
);
6074 FNextWeap
:= utils
.readWord(st
);
6076 FNextWeapDelay
:= utils
.readByte(st
);
6077 // Âðåìÿ çàðÿäêè BFG
6078 FBFGFireCounter
:= utils
.readSmallInt(st
);
6080 FDamageBuffer
:= utils
.readLongInt(st
);
6081 // Ïîñëåäíèé óäàðèâøèé
6082 FLastSpawnerUID
:= utils
.readWord(st
);
6083 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6084 FLastHit
:= utils
.readByte(st
);
6086 Obj_LoadState(@FObj
, st
);
6087 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6088 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
6089 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6090 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
6092 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
6093 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6094 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
6096 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
6097 // Íàëè÷èå êðàñíîãî êëþ÷à
6098 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
6099 // Íàëè÷èå çåëåíîãî êëþ÷à
6100 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
6101 // Íàëè÷èå ñèíåãî êëþ÷à
6102 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
6104 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
6105 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6106 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
6107 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6108 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
6110 str
:= utils
.readStr(st
);
6112 FColor
.R
:= utils
.readByte(st
);
6113 FColor
.G
:= utils
.readByte(st
);
6114 FColor
.B
:= utils
.readByte(st
);
6115 if (self
= gPlayer1
) then
6117 str
:= gPlayer1Settings
.Model
;
6118 FColor
:= gPlayer1Settings
.Color
;
6120 else if (self
= gPlayer2
) then
6122 str
:= gPlayer2Settings
.Model
;
6123 FColor
:= gPlayer2Settings
.Color
;
6125 // Îáíîâëÿåì ìîäåëü èãðîêà
6127 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
6128 FModel
.Color
:= TEAMCOLOR
[FTeam
]
6130 FModel
.Color
:= FColor
;
6134 procedure TPlayer
.AllRulez(Health
: Boolean);
6140 FHealth
:= PLAYER_HP_LIMIT
;
6141 FArmor
:= PLAYER_AP_LIMIT
;
6145 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
6146 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
6147 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6150 procedure TPlayer
.RestoreHealthArmor();
6152 FHealth
:= PLAYER_HP_LIMIT
;
6153 FArmor
:= PLAYER_AP_LIMIT
;
6156 procedure TPlayer
.FragCombo();
6160 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6162 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6164 if FFragCombo
< 5 then
6166 Param
:= FUID
or (FFragCombo
shl 16);
6167 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6168 (FComboEvnt
<= High(gDelayedEvents
)) and
6169 gDelayedEvents
[FComboEvnt
].Pending
and
6170 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6171 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6173 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6174 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6177 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6185 procedure TPlayer
.GiveItem(ItemType
: Byte);
6189 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6191 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6195 if FAir
< AIR_MAX
then
6202 if not (R_BERSERK
in FRulez
) then
6204 Include(FRulez
, R_BERSERK
);
6205 if FBFGFireCounter
< 1 then
6207 FCurrWeap
:= WEAPON_KASTET
;
6209 FModel
.SetWeapon(WEAPON_KASTET
);
6213 FBerserk
:= gTime
+30000;
6215 if FHealth
< PLAYER_HP_SOFT
then
6217 FHealth
:= PLAYER_HP_SOFT
;
6218 FBerserk
:= gTime
+30000;
6223 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6225 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6229 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6231 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6235 if FJetFuel
< JET_MAX
then
6237 FJetFuel
:= JET_MAX
;
6240 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6241 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6243 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6244 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6246 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6248 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6250 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6251 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6254 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6255 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6256 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6257 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6258 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6259 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6260 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6261 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6262 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6264 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6265 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6266 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6267 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6268 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6269 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6270 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6271 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6272 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6275 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6276 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6277 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6278 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6279 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6281 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6282 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6283 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6284 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6285 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6287 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6288 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6289 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6290 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6292 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6295 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6296 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6297 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6299 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6300 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6305 if g_Game_IsNet
and g_Game_IsServer
then
6306 MH_SEND_PlayerStats(FUID
);
6309 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6314 if (Random(5) = 1) and (Times
= 1) then
6317 if BodyInLiquid(0, 0) then
6319 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6320 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6321 if Random(2) = 0 then
6322 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6324 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6328 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6330 for i
:= 1 to Times
do
6332 Anim
:= TAnimation
.Create(id
, False, 3);
6334 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6335 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6341 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6346 if (Random(10) = 1) and (Times
= 1) then
6349 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6351 for i
:= 1 to Times
do
6353 Anim
:= TAnimation
.Create(id
, False, 3);
6355 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6356 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6362 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6364 FSawSound
.Pause(Enable
);
6365 FSawSoundIdle
.Pause(Enable
);
6366 FSawSoundHit
.Pause(Enable
);
6367 FSawSoundSelect
.Pause(Enable
);
6368 FFlameSoundOn
.Pause(Enable
);
6369 FFlameSoundOff
.Pause(Enable
);
6370 FFlameSoundWork
.Pause(Enable
);
6371 FJetSoundFly
.Pause(Enable
);
6372 FJetSoundOn
.Pause(Enable
);
6373 FJetSoundOff
.Pause(Enable
);
6378 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6383 FObj
.Rect
:= PLAYER_CORPSERECT
;
6384 FModelName
:= ModelName
;
6389 FState
:= CORPSE_STATE_MESS
;
6390 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6394 FState
:= CORPSE_STATE_NORMAL
;
6395 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6399 destructor TCorpse
.Destroy();
6406 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6408 procedure TCorpse
.positionChanged (); inline; begin end;
6410 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6412 if (dx
<> 0) or (dy
<> 0) then
6421 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6423 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6424 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6425 w
:= PLAYER_CORPSERECT
.Width
;
6426 h
:= PLAYER_CORPSERECT
.Height
;
6430 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6435 if FState
= CORPSE_STATE_REMOVEME
then
6438 FDamage
:= FDamage
+ Value
;
6440 if FDamage
> 150 then
6442 if FAnimation
<> nil then
6447 FState
:= CORPSE_STATE_REMOVEME
;
6449 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6450 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6451 FModelName
, FColor
);
6452 // Çâóê ìÿñà îò òðóïà:
6453 pm
:= g_PlayerModel_Get(FModelName
);
6454 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6458 if (gBodyKillEvent
<> -1)
6459 and gDelayedEvents
[gBodyKillEvent
].Pending
then
6460 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
6461 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, 0);
6466 Blood
:= g_PlayerModel_GetBlood(FModelName
);
6467 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6468 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6469 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6470 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6471 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6472 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
6476 procedure TCorpse
.Draw();
6478 if FState
= CORPSE_STATE_REMOVEME
then
6481 if FAnimation
<> nil then
6482 FAnimation
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6484 if FAnimationMask
<> nil then
6487 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6494 procedure TCorpse
.Update();
6498 if FState
= CORPSE_STATE_REMOVEME
then
6501 if gTime
mod (GAME_TICK
*2) <> 0 then
6503 g_Obj_Move(@FObj
, True, True, True);
6504 positionChanged(); // this updates spatial accelerators
6508 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6509 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6511 st
:= g_Obj_Move(@FObj
, True, True, True);
6512 positionChanged(); // this updates spatial accelerators
6514 if WordBool(st
and MOVE_FALLOUT
) then
6516 FState
:= CORPSE_STATE_REMOVEME
;
6520 if FAnimation
<> nil then
6521 FAnimation
.Update();
6522 if FAnimationMask
<> nil then
6523 FAnimationMask
.Update();
6527 procedure TCorpse
.SaveState (st
: TStream
);
6534 utils
.writeSign(st
, 'CORP');
6535 utils
.writeInt(st
, Byte(0));
6537 utils
.writeInt(st
, Byte(FState
));
6539 utils
.writeInt(st
, Byte(FDamage
));
6541 utils
.writeInt(st
, Byte(FColor
.R
));
6542 utils
.writeInt(st
, Byte(FColor
.G
));
6543 utils
.writeInt(st
, Byte(FColor
.B
));
6545 Obj_SaveState(st
, @FObj
);
6546 utils
.writeInt(st
, Word(FPlayerUID
));
6548 anim
:= (FAnimation
<> nil);
6549 utils
.writeBool(st
, anim
);
6550 // Åñëè åñòü - ñîõðàíÿåì
6551 if anim
then FAnimation
.SaveState(st
);
6552 // Åñòü ëè ìàñêà àíèìàöèè
6553 anim
:= (FAnimationMask
<> nil);
6554 utils
.writeBool(st
, anim
);
6555 // Åñëè åñòü - ñîõðàíÿåì
6556 if anim
then FAnimationMask
.SaveState(st
);
6560 procedure TCorpse
.LoadState (st
: TStream
);
6567 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6568 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6570 FState
:= utils
.readByte(st
);
6572 FDamage
:= utils
.readByte(st
);
6574 FColor
.R
:= utils
.readByte(st
);
6575 FColor
.G
:= utils
.readByte(st
);
6576 FColor
.B
:= utils
.readByte(st
);
6578 Obj_LoadState(@FObj
, st
);
6579 FPlayerUID
:= utils
.readWord(st
);
6581 anim
:= utils
.readBool(st
);
6582 // Åñëè åñòü - çàãðóæàåì
6585 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6586 FAnimation
.LoadState(st
);
6588 // Åñòü ëè ìàñêà àíèìàöèè
6589 anim
:= utils
.readBool(st
);
6590 // Åñëè åñòü - çàãðóæàåì
6593 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6594 FAnimationMask
.LoadState(st
);
6600 constructor TBot
.Create();
6607 FSpectator
:= False;
6614 for a
:= WP_FIRST
to WP_LAST
do
6616 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6617 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6618 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6622 destructor TBot
.Destroy();
6625 inherited Destroy();
6628 procedure TBot
.Draw();
6632 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6633 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6636 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6638 inherited Respawn(Silent
, Force
);
6641 FSelectedWeapon
:= FCurrWeap
;
6646 procedure TBot
.UpdateCombat();
6659 TTargetRecord
= array of TTarget
;
6661 function Compare(a
, b
: TTarget
): Integer;
6663 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6666 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6668 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6669 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6671 if a
.Dist
> b
.Dist
then // B áëèæå
6673 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6676 else // Ñòðàííî -> A
6681 a
, x1
, y1
, x2
, y2
: Integer;
6682 targets
: TTargetRecord
;
6684 Target
, BestTarget
: TTarget
;
6685 firew
, fireh
: Integer;
6689 vsPlayer
, vsMonster
, ok
: Boolean;
6692 function monsUpdate (mon
: TMonster
): Boolean;
6694 result
:= false; // don't stop
6695 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6697 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6699 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6700 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6702 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6703 if g_TraceVector(x1
, y1
, x2
, y2
) then
6705 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6706 SetLength(targets
, Length(targets
)+1);
6707 with targets
[High(targets
)] do
6714 Rect
:= mon
.Obj
.Rect
;
6715 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6716 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6717 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6726 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6727 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6729 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6730 if FCurrWeap
<> FSelectedWeapon
then
6733 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6734 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6736 RemoveAIFlag('NEEDFIRE');
6739 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6740 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6741 else PressKey(KEY_FIRE
);
6745 // Êîîðäèíàòû ñòâîëà:
6746 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6747 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6749 Target
.UID
:= FTargetUID
;
6752 if Target
.UID
<> 0 then
6753 begin // Öåëü åñòü - íàñòðàèâàåì
6754 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6757 tpla
:= g_Player_Get(Target
.UID
);
6761 if (@FObj
) <> nil then
6768 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6769 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6770 Target
.Rect
:= PLAYER_RECT
;
6771 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6772 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6773 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6774 Target
.IsPlayer
:= True;
6778 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6781 mon
:= g_Monsters_ByUID(Target
.UID
);
6784 Target
.X
:= mon
.Obj
.X
;
6785 Target
.Y
:= mon
.Obj
.Y
;
6787 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6788 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6789 Target
.Rect
:= mon
.Obj
.Rect
;
6790 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6791 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6792 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6793 Target
.IsPlayer
:= False;
6800 begin // Öåëè íåò - îáíóëÿåì
6805 Target
.Visible
:= False;
6806 Target
.Line
:= False;
6807 Target
.IsPlayer
:= False;
6812 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6813 if (not Target
.Line
) or (not Target
.Visible
) then
6817 for a
:= 0 to High(gPlayers
) do
6818 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6819 (gPlayers
[a
].FUID
<> FUID
) and
6820 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6821 (not gPlayers
[a
].NoTarget
) and
6822 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6824 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6825 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6828 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6829 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6831 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6832 if g_TraceVector(x1
, y1
, x2
, y2
) then
6834 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6835 SetLength(targets
, Length(targets
)+1);
6836 with targets
[High(targets
)] do
6838 UID
:= gPlayers
[a
].FUID
;
6839 X
:= gPlayers
[a
].FObj
.X
;
6840 Y
:= gPlayers
[a
].FObj
.Y
;
6843 Rect
:= PLAYER_RECT
;
6844 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6845 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6846 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6854 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6857 // Åñëè åñòü âîçìîæíûå öåëè:
6858 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6859 if targets
<> nil then
6861 // Âûáèðàåì íàèëó÷øóþ öåëü:
6862 BestTarget
:= targets
[0];
6863 if Length(targets
) > 1 then
6864 for a
:= 1 to High(targets
) do
6865 if Compare(BestTarget
, targets
[a
]) = 1 then
6866 BestTarget
:= targets
[a
];
6868 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6869 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6870 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6872 Target
:= BestTarget
;
6874 if (Healthy() = 3) or ((Healthy() = 2)) then
6875 begin // Åñëè çäîðîâû - äîãîíÿåì
6876 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6877 SetAIFlag('GORIGHT', '1');
6878 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6879 SetAIFlag('GOLEFT', '1');
6882 begin // Åñëè ïîáèòû - óáåãàåì
6883 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6884 SetAIFlag('GORIGHT', '1');
6885 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6886 SetAIFlag('GOLEFT', '1');
6889 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6890 SelectWeapon(Abs(x1
-Target
.cX
));
6895 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6896 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6897 if Target
.UID
<> 0 then
6899 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6900 Target
.Y
+ Target
.Rect
.Y
) then
6901 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6902 if (Healthy() = 3) or ((Healthy() = 2)) then
6903 begin // Åñëè çäîðîâû - äîãîíÿåì
6904 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6905 SetAIFlag('GORIGHT', '1');
6906 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6907 SetAIFlag('GOLEFT', '1');
6910 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6912 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6913 SetAIFlag('GORIGHT', '1');
6914 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6915 SetAIFlag('GOLEFT', '1');
6919 begin // Öåëü ïîêà íà "ýêðàíå"
6920 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6921 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6922 FLastVisible
:= gTime
;
6923 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6924 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6926 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6927 SetAIFlag('GORIGHT', '1');
6928 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6929 SetAIFlag('GOLEFT', '1');
6933 // Âûáèðàåì óãîë ââåðõ:
6934 if FDirection
= TDirection
.D_LEFT
then
6935 angle
:= ANGLE_LEFTUP
6937 angle
:= ANGLE_RIGHTUP
;
6939 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6940 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6942 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6943 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6944 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6945 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6946 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6947 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6948 begin // òî íóæíî ñòðåëÿòü ââåðõ
6949 SetAIFlag('NEEDFIRE', '1');
6950 SetAIFlag('NEEDSEEUP', '1');
6953 // Âûáèðàåì óãîë âíèç:
6954 if FDirection
= TDirection
.D_LEFT
then
6955 angle
:= ANGLE_LEFTDOWN
6957 angle
:= ANGLE_RIGHTDOWN
;
6959 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6960 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6962 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6963 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6964 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6965 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6966 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6967 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6968 begin // òî íóæíî ñòðåëÿòü âíèç
6969 SetAIFlag('NEEDFIRE', '1');
6970 SetAIFlag('NEEDSEEDOWN', '1');
6973 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6974 if Target
.Visible
and
6975 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6976 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6978 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6979 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
6980 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6981 begin // òî íóæíî ñòðåëÿòü âïåðåä
6982 SetAIFlag('NEEDFIRE', '1');
6983 SetAIFlag('NEEDSEEDOWN', '');
6984 SetAIFlag('NEEDSEEUP', '');
6986 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6987 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6988 if GetRnd(FDifficult
.CloseJump
) then
6989 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6990 if Abs(FObj
.X
-Target
.X
) < 128 then
6994 if Random(a
) = 0 then
6995 SetAIFlag('NEEDJUMP', '1');
6999 // Åñëè öåëü âñå åùå åñòü:
7000 if Target
.UID
<> 0 then
7001 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
7002 Target
.UID
:= 0 // òî çàáûòü öåëü
7003 else // Åñëè âèäåëè íåäàâíî
7004 begin // íî öåëü óáèëè
7005 if Target
.IsPlayer
then
7006 begin // Öåëü - èãðîê
7007 pla
:= g_Player_Get(Target
.UID
);
7008 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
7009 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
7010 Target
.UID
:= 0; // òî çàáûòü öåëü
7013 begin // Öåëü - ìîíñòð
7014 mon
:= g_Monsters_ByUID(Target
.UID
);
7015 if (mon
= nil) or (not mon
.alive
) then
7016 Target
.UID
:= 0; // òî çàáûòü öåëü
7019 end; // if Target.UID <> 0
7021 FTargetUID
:= Target
.UID
;
7023 // Åñëè âîçìîæíûõ öåëåé íåò:
7024 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
7025 if targets
= nil then
7026 if GetAIFlag('ATTACKLEFT') <> '' then
7027 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
7028 RemoveAIFlag('ATTACKLEFT');
7030 SetAIFlag('NEEDJUMP', '1');
7032 if RunDirection() = TDirection
.D_RIGHT
then
7033 begin // Èäåì íå â òó ñòîðîíó
7034 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7035 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
7036 SetAIFlag('NEEDFIRE', '1');
7037 SetAIFlag('GOLEFT', '1');
7041 begin // Èäåì â íóæíóþ ñòîðîíó
7042 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7043 SetAIFlag('NEEDFIRE', '1');
7044 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7045 SetAIFlag('GORIGHT', '1');
7049 if GetAIFlag('ATTACKRIGHT') <> '' then
7050 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
7051 RemoveAIFlag('ATTACKRIGHT');
7053 SetAIFlag('NEEDJUMP', '1');
7055 if RunDirection() = TDirection
.D_LEFT
then
7056 begin // Èäåì íå â òó ñòîðîíó
7057 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7058 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
7059 SetAIFlag('NEEDFIRE', '1');
7060 SetAIFlag('GORIGHT', '1');
7065 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7066 SetAIFlag('NEEDFIRE', '1');
7067 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7068 SetAIFlag('GOLEFT', '1');
7072 //HACK! (does it belongs there?)
7073 RealizeCurrentWeapon();
7075 // Åñëè åñòü âîçìîæíûå öåëè:
7076 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7077 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7078 for a
:= 0 to High(targets
) do
7080 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7081 if GetRnd(FDifficult
.DiagFire
) then
7083 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7084 if FDirection
= TDirection
.D_LEFT
then
7085 angle
:= ANGLE_LEFTUP
7087 angle
:= ANGLE_RIGHTUP
;
7089 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7090 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7092 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7093 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7094 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7095 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7096 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7098 SetAIFlag('NEEDFIRE', '1');
7099 SetAIFlag('NEEDSEEUP', '1');
7102 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7103 if FDirection
= TDirection
.D_LEFT
then
7104 angle
:= ANGLE_LEFTDOWN
7106 angle
:= ANGLE_RIGHTDOWN
;
7108 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7109 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7111 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7112 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7113 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7114 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7115 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7117 SetAIFlag('NEEDFIRE', '1');
7118 SetAIFlag('NEEDSEEDOWN', '1');
7122 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7123 if targets
[a
].Line
and targets
[a
].Visible
and
7124 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
7125 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
7127 SetAIFlag('NEEDFIRE', '1');
7132 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7133 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
7134 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
7135 40+GetInterval(FDifficult
.Cover
, 40)) then
7136 SetAIFlag('NEEDJUMP', '1');
7138 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7139 ammo
:= GetAmmoByWeapon(FCurrWeap
);
7140 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
7141 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
7143 SetAIFlag('SELECTWEAPON', '1');
7145 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7146 if GetAIFlag('SELECTWEAPON') = '1' then
7149 RemoveAIFlag('SELECTWEAPON');
7153 procedure TBot
.Update();
7166 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7167 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7169 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7171 if g_debug_BotAIOff
= 3 then
7181 RealizeCurrentWeapon();
7188 procedure TBot
.ReleaseKey(Key
: Byte);
7197 function TBot
.KeyPressed(Key
: Word): Boolean;
7199 Result
:= FKeys
[Key
].Pressed
;
7202 function TBot
.GetAIFlag(aName
: String20
): String20
;
7208 aName
:= LowerCase(aName
);
7210 if FAIFlags
<> nil then
7211 for a
:= 0 to High(FAIFlags
) do
7212 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7214 Result
:= FAIFlags
[a
].Value
;
7219 procedure TBot
.RemoveAIFlag(aName
: String20
);
7223 if FAIFlags
= nil then Exit
;
7225 aName
:= LowerCase(aName
);
7227 for a
:= 0 to High(FAIFlags
) do
7228 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7230 if a
<> High(FAIFlags
) then
7231 for b
:= a
to High(FAIFlags
)-1 do
7232 FAIFlags
[b
] := FAIFlags
[b
+1];
7234 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7239 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7247 aName
:= LowerCase(aName
);
7249 if FAIFlags
<> nil then
7250 for a
:= 0 to High(FAIFlags
) do
7251 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7257 if ok
then FAIFlags
[a
].Value
:= fValue
7260 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7261 with FAIFlags
[High(FAIFlags
)] do
7269 procedure TBot
.UpdateMove
;
7271 procedure GoLeft(Time
: Word = 1);
7273 ReleaseKey(KEY_LEFT
);
7274 ReleaseKey(KEY_RIGHT
);
7275 PressKey(KEY_LEFT
, Time
);
7276 SetDirection(TDirection
.D_LEFT
);
7279 procedure GoRight(Time
: Word = 1);
7281 ReleaseKey(KEY_LEFT
);
7282 ReleaseKey(KEY_RIGHT
);
7283 PressKey(KEY_RIGHT
, Time
);
7284 SetDirection(TDirection
.D_RIGHT
);
7287 function Rnd(a
: Word): Boolean;
7289 Result
:= Random(a
) = 0;
7292 procedure Turn(Time
: Word = 1200);
7294 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7299 ReleaseKey(KEY_LEFT
);
7300 ReleaseKey(KEY_RIGHT
);
7303 function CanRunLeft(): Boolean;
7305 Result
:= not CollideLevel(-1, 0);
7308 function CanRunRight(): Boolean;
7310 Result
:= not CollideLevel(1, 0);
7313 function CanRun(): Boolean;
7315 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7318 procedure Jump(Time
: Word = 30);
7320 PressKey(KEY_JUMP
, Time
);
7323 function NearHole(): Boolean;
7327 { TODO 5 : Ëåñòíèöû }
7328 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7329 for x
:= 1 to PLAYER_RECT
.Width
do
7330 if (not StayOnStep(x
*sx
, 0)) and
7331 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7332 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7341 function BorderHole(): Boolean;
7345 { TODO 5 : Ëåñòíèöû }
7346 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7347 for x
:= 1 to PLAYER_RECT
.Width
do
7348 if (not StayOnStep(x
*sx
, 0)) and
7349 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7350 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7352 for xx
:= x
to x
+32 do
7353 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7363 function NearDeepHole(): Boolean;
7369 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7372 for x
:= 1 to PLAYER_RECT
.Width
do
7373 if (not StayOnStep(x
*sx
, 0)) and
7374 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7375 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7377 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7379 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7384 end else Result
:= False;
7387 function OverDeepHole(): Boolean;
7394 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7396 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7403 function OnGround(): Boolean;
7405 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7408 function OnLadder(): Boolean;
7410 Result
:= FullInStep(0, 0);
7413 function BelowLadder(): Boolean;
7415 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7416 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7417 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7418 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7421 function BelowLiftUp(): Boolean;
7423 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7424 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7425 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7426 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7429 function OnTopLift(): Boolean;
7431 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7434 function CanJumpOver(): Boolean;
7438 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7442 if not CollideLevel(sx
, 0) then Exit
;
7444 for y
:= 1 to BOT_MAXJUMP
do
7445 if CollideLevel(0, -y
) then Exit
else
7446 if not CollideLevel(sx
, -y
) then
7453 function CanJumpUp(Dist
: ShortInt): Boolean;
7460 if CollideLevel(Dist
, 0) then Exit
;
7463 for y
:= 0 to BOT_MAXJUMP
do
7464 if CollideLevel(Dist
, -y
) then
7473 for yy
:= y
+1 to BOT_MAXJUMP
do
7474 if not CollideLevel(Dist
, -yy
) then
7483 for y
:= 0 to BOT_MAXJUMP
do
7484 if CollideLevel(0, -y
) then
7492 if y
< yy
then Exit
;
7497 function IsSafeTrigger(): Boolean;
7502 if gTriggers
= nil then
7504 for a
:= 0 to High(gTriggers
) do
7505 if Collide(gTriggers
[a
].X
,
7508 gTriggers
[a
].Height
) and
7509 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7510 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7511 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7512 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7513 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7518 // Âîçìîæíî, íàæèìàåì êíîïêó:
7519 if Rnd(16) and IsSafeTrigger() then
7522 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7523 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7525 ReleaseKey(KEY_LEFT
);
7526 ReleaseKey(KEY_RIGHT
);
7530 // Èäåì âëåâî, åñëè íàäî áûëî:
7531 if GetAIFlag('GOLEFT') <> '' then
7533 RemoveAIFlag('GOLEFT');
7534 if CanRunLeft() then
7538 // Èäåì âïðàâî, åñëè íàäî áûëî:
7539 if GetAIFlag('GORIGHT') <> '' then
7541 RemoveAIFlag('GORIGHT');
7542 if CanRunRight() then
7546 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7547 if FObj
.X
< -32 then
7550 if FObj
.X
+32 > gMapInfo
.Width
then
7553 // Ïðûãàåì, åñëè íàäî áûëî:
7554 if GetAIFlag('NEEDJUMP') <> '' then
7557 RemoveAIFlag('NEEDJUMP');
7560 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7561 if GetAIFlag('NEEDSEEUP') <> '' then
7564 ReleaseKey(KEY_DOWN
);
7565 PressKey(KEY_UP
, 20);
7566 RemoveAIFlag('NEEDSEEUP');
7569 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7570 if GetAIFlag('NEEDSEEDOWN') <> '' then
7573 ReleaseKey(KEY_DOWN
);
7574 PressKey(KEY_DOWN
, 20);
7575 RemoveAIFlag('NEEDSEEDOWN');
7578 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7579 if GetAIFlag('GOINHOLE') <> '' then
7580 if not OnGround() then
7582 ReleaseKey(KEY_LEFT
);
7583 ReleaseKey(KEY_RIGHT
);
7584 RemoveAIFlag('GOINHOLE');
7585 SetAIFlag('FALLINHOLE', '1');
7588 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7589 if GetAIFlag('FALLINHOLE') <> '' then
7591 RemoveAIFlag('FALLINHOLE');
7593 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7594 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7595 if GetAIFlag('FALLINHOLE') = '' then
7596 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7602 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7604 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7608 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7609 if OnGround() and NearHole() then
7610 if NearDeepHole() then // Åñëè ýòî áåçäíà
7612 0..3: Turn(); // Áåæèì îáðàòíî
7613 4: Jump(); // Ïðûãàåì
7614 5: begin // Ïðûãàåì îáðàòíî
7619 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7620 if GetAIFlag('GOINHOLE') = '' then
7622 0: Turn(); // Íå íóæíî òóäà
7623 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7624 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7625 if BorderHole() then
7626 SetAIFlag('GOINHOLE', '1');
7629 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7630 if (not CanRun()) and OnGround() then
7632 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7633 if CanJumpOver() or OnLadder() then
7635 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7636 if Random(2) = 0 then
7638 if IsSafeTrigger() then
7644 // Îñòàëîñü ìàëî âîçäóõà:
7645 if FAir
< 36 * 2 then
7648 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7649 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7650 if BodyInAcid(0, 0) then
7654 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7656 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7657 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7660 {function TBot.NeedItem(Item: Byte): Byte;
7665 procedure TBot
.SelectWeapon(Dist
: Integer);
7669 function HaveAmmo(weapon
: Byte): Boolean;
7672 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7673 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7674 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7675 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7676 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7677 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7678 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7679 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7680 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7681 else Result
:= True;
7686 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7688 if Dist
> BOT_LONGDIST
then
7689 begin // Äàëüíèé áîé
7691 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7693 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7697 else //if Dist > BOT_UNSAFEDIST then
7698 begin // Áëèæíèé áîé
7700 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7702 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7709 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7711 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7717 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7719 Result
:= inherited PickItem(ItemType
, force
, remove
);
7721 if Result
then SetAIFlag('SELECTWEAPON', '1');
7724 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7726 Result
:= inherited Heal(value
, Soft
);
7729 function TBot
.Healthy(): Byte;
7731 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7732 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7733 else if (FHealth
> 50) then Result
:= 2
7734 else if (FHealth
> 20) then Result
:= 1
7738 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7740 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7741 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7744 procedure TBot
.OnDamage(Angle
: SmallInt);
7752 if (Angle
= 0) or (Angle
= 180) then
7755 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7756 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7758 pla
:= g_Player_Get(FLastSpawnerUID
);
7759 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7760 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7763 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7764 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7766 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7767 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7768 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7773 SetAIFlag('ATTACKLEFT', '1')
7775 SetAIFlag('ATTACKRIGHT', '1');
7779 function TBot
.RunDirection(): TDirection
;
7781 if Abs(Vel
.X
) >= 1 then
7783 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7785 Result
:= FDirection
;
7788 function TBot
.GetRnd(a
: Byte): Boolean;
7790 if a
= 0 then Result
:= False
7791 else if a
= 255 then Result
:= True
7792 else Result
:= Random(256) > 255-a
;
7795 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7797 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7801 procedure TDifficult
.save (st
: TStream
);
7803 utils
.writeInt(st
, Byte(DiagFire
));
7804 utils
.writeInt(st
, Byte(InvisFire
));
7805 utils
.writeInt(st
, Byte(DiagPrecision
));
7806 utils
.writeInt(st
, Byte(FlyPrecision
));
7807 utils
.writeInt(st
, Byte(Cover
));
7808 utils
.writeInt(st
, Byte(CloseJump
));
7809 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7810 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7813 procedure TDifficult
.load (st
: TStream
);
7815 DiagFire
:= utils
.readByte(st
);
7816 InvisFire
:= utils
.readByte(st
);
7817 DiagPrecision
:= utils
.readByte(st
);
7818 FlyPrecision
:= utils
.readByte(st
);
7819 Cover
:= utils
.readByte(st
);
7820 CloseJump
:= utils
.readByte(st
);
7821 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7822 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7826 procedure TBot
.SaveState (st
: TStream
);
7831 inherited SaveState(st
);
7832 utils
.writeSign(st
, 'BOT0');
7834 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7836 utils
.writeInt(st
, Word(FTargetUID
));
7837 // Âðåìÿ ïîòåðè öåëè
7838 utils
.writeInt(st
, LongWord(FLastVisible
));
7839 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7840 dw
:= Length(FAIFlags
);
7841 utils
.writeInt(st
, LongInt(dw
));
7843 for i
:= 0 to dw
-1 do
7845 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7846 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7848 // Íàñòðîéêè ñëîæíîñòè
7849 FDifficult
.save(st
);
7853 procedure TBot
.LoadState (st
: TStream
);
7858 inherited LoadState(st
);
7859 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7861 FSelectedWeapon
:= utils
.readByte(st
);
7863 FTargetUID
:= utils
.readWord(st
);
7864 // Âðåìÿ ïîòåðè öåëè
7865 FLastVisible
:= utils
.readLongWord(st
);
7866 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7867 dw
:= utils
.readLongInt(st
);
7868 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7869 SetLength(FAIFlags
, dw
);
7871 for i
:= 0 to dw
-1 do
7873 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7874 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7876 // Íàñòðîéêè ñëîæíîñòè
7877 FDifficult
.load(st
);
7882 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);