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;
99 PLAYER1_DEF_COLOR
: TRGB
= (R
:64; G
:175; B
:48);
100 PLAYER2_DEF_COLOR
: TRGB
= (R
:96; G
:96; B
:96);
116 TPlayerStatArray
= Array of TPlayerStat
;
118 TPlayerSavedState
= record
126 Ammo
: Array [A_BULLETS
..A_HIGH
] of Word;
127 MaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
128 Weapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
129 Rulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
138 TPlayer
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
146 FDirection
: TDirection
;
154 FMonsterKills
: Integer;
160 FCanJetpack
: Boolean;
166 FNextWeapDelay
: Byte; // frames (unused)
167 FBFGFireCounter
: SmallInt;
168 FLastSpawnerUID
: Word;
172 FSpectatePlayer
: Integer;
173 FFirePainTime
: Integer;
176 FSavedState
: TPlayerSavedState
;
178 FModel
: TPlayerModel
;
179 FPunchAnim
: TAnimation
;
182 FActionForce
: Boolean;
183 FActionChanged
: Boolean;
185 FFireAngle
: SmallInt;
187 FShellTimer
: Integer;
189 FSawSound
: TPlayableSound
;
190 FSawSoundIdle
: TPlayableSound
;
191 FSawSoundHit
: TPlayableSound
;
192 FSawSoundSelect
: TPlayableSound
;
193 FJetSoundOn
: TPlayableSound
;
194 FJetSoundOff
: TPlayableSound
;
195 FJetSoundFly
: TPlayableSound
;
199 FJustTeleported
: Boolean;
201 mEDamageType
: Integer;
204 weaponSwitchKeyReleased
: array[0..16] of Boolean; // true: was release
207 function CollideLevel(XInc
, YInc
: Integer): Boolean;
208 function StayOnStep(XInc
, YInc
: Integer): Boolean;
209 function HeadInLiquid(XInc
, YInc
: Integer): Boolean;
210 function BodyInLiquid(XInc
, YInc
: Integer): Boolean;
211 function BodyInAcid(XInc
, YInc
: Integer): Boolean;
212 function FullInLift(XInc
, YInc
: Integer): Integer;
213 {procedure CollideItem();}
214 procedure FlySmoke(Times
: DWORD
= 1);
215 procedure OnFireFlame(Times
: DWORD
= 1);
216 function GetAmmoByWeapon(Weapon
: Byte): Word;
217 procedure SetAction(Action
: Byte; Force
: Boolean = False);
218 procedure OnDamage(Angle
: SmallInt); virtual;
219 function firediry(): Integer;
222 procedure Run(Direction
: TDirection
);
223 procedure NextWeapon();
224 procedure PrevWeapon();
231 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
232 procedure resetWeaponQueue ();
233 function hasAmmoForWeapon (weapon
: Byte): Boolean;
235 procedure doDamage (v
: Integer);
237 function followCorpse(): Boolean;
240 FDamageBuffer
: Integer;
242 FAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
243 FMaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
244 FWeapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
245 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
247 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
248 FReloading
: Array [WP_FIRST
..WP_LAST
] of Word;
249 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
250 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
252 FPreferredTeam
: Byte;
255 FWantsInGame
: Boolean;
259 FActualModelName
: string;
266 // debug: viewport offset
267 viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer;
269 function isValidViewPort (): Boolean; inline;
271 constructor Create(); virtual;
272 destructor Destroy(); override;
273 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
274 function GetRespawnPoint(): Byte;
275 procedure PressKey(Key
: Byte; Time
: Word = 1);
276 procedure ReleaseKeys();
277 procedure SetModel(ModelName
: String);
278 procedure SetColor(Color
: TRGB
);
279 procedure SetWeapon(W
: Byte);
280 function IsKeyPressed(K
: Byte): Boolean;
281 function GetKeys(): Byte;
282 function PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean; virtual;
283 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
284 function Collide(Panel
: TPanel
): Boolean; overload
;
285 function Collide(X
, Y
: Integer): Boolean; overload
;
286 procedure SetDirection(Direction
: TDirection
);
287 procedure GetSecret();
288 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
290 procedure Push(vx
, vy
: Integer);
291 procedure ChangeModel(ModelName
: String);
292 procedure SwitchTeam
;
293 procedure ChangeTeam(Team
: Byte);
295 function GetFlag(Flag
: Byte): Boolean;
296 procedure SetFlag(Flag
: Byte);
297 function DropFlag(): Boolean;
298 procedure AllRulez(Health
: Boolean);
299 procedure RestoreHealthArmor();
300 procedure FragCombo();
301 procedure GiveItem(ItemType
: Byte);
302 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
303 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
304 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
305 procedure MakeBloodSimple(Count
: Word);
306 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
307 procedure Reset(Force
: Boolean);
308 procedure Spectate(NoMove
: Boolean = False);
309 procedure SwitchNoClip
;
310 procedure SoftReset();
311 procedure Draw(); virtual;
312 procedure DrawPain();
313 procedure DrawPickup();
314 procedure DrawRulez();
316 procedure DrawBubble();
318 procedure Update(); virtual;
319 procedure RememberState();
320 procedure RecallState();
321 procedure SaveState (st
: TStream
); virtual;
322 procedure LoadState (st
: TStream
); virtual;
323 procedure PauseSounds(Enable
: Boolean);
324 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
325 procedure DoLerp(Level
: Integer = 2);
326 procedure SetLerp(XTo
, YTo
: Integer);
327 procedure QueueWeaponSwitch(Weapon
: Byte);
328 procedure RealizeCurrentWeapon();
330 procedure JetpackOff
;
331 procedure CatchFire(Attacker
: Word);
333 //WARNING! this does nothing for now, but still call it!
334 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
336 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
337 procedure moveBy (dx
, dy
: Integer); inline;
339 procedure releaseAllWeaponSwitchKeys ();
340 procedure weaponSwitchKeysStateChange (index
: Integer; pressed
: Boolean);
341 function isWeaponSwitchKeyReleased (index
: Integer): Boolean;
344 property Vel
: TPoint2i read FObj
.Vel
;
345 property Obj
: TObj read FObj
;
347 property Name
: String read FName write FName
;
348 property Model
: TPlayerModel read FModel
;
349 property Health
: Integer read FHealth write FHealth
;
350 property Lives
: Byte read FLives write FLives
;
351 property Armor
: Integer read FArmor write FArmor
;
352 property Air
: Integer read FAir write FAir
;
353 property JetFuel
: Integer read FJetFuel write FJetFuel
;
354 property Frags
: Integer read FFrags write FFrags
;
355 property Death
: Integer read FDeath write FDeath
;
356 property Kills
: Integer read FKills write FKills
;
357 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
358 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
359 property Secrets
: Integer read FSecrets
;
360 property GodMode
: Boolean read FGodMode write FGodMode
;
361 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
362 property NoReload
: Boolean read FNoReload write FNoReload
;
363 property alive
: Boolean read FAlive write FAlive
;
364 property Flag
: Byte read FFlag
;
365 property Team
: Byte read FTeam write FTeam
;
366 property Direction
: TDirection read FDirection
;
367 property GameX
: Integer read FObj
.X write FObj
.X
;
368 property GameY
: Integer read FObj
.Y write FObj
.Y
;
369 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
370 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
371 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
372 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
373 property IncCam
: Integer read FIncCam write FIncCam
;
374 property UID
: Word read FUID write FUID
;
375 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
376 property NetTime
: LongWord read FNetTime write FNetTime
;
379 property eName
: String read FName write FName
;
380 property eHealth
: Integer read FHealth write FHealth
;
381 property eLives
: Byte read FLives write FLives
;
382 property eArmor
: Integer read FArmor write FArmor
;
383 property eAir
: Integer read FAir write FAir
;
384 property eJetFuel
: Integer read FJetFuel write FJetFuel
;
385 property eFrags
: Integer read FFrags write FFrags
;
386 property eDeath
: Integer read FDeath write FDeath
;
387 property eKills
: Integer read FKills write FKills
;
388 property eCurrWeap
: Byte read FCurrWeap write FCurrWeap
;
389 property eMonsterKills
: Integer read FMonsterKills write FMonsterKills
;
390 property eSecrets
: Integer read FSecrets write FSecrets
;
391 property eGodMode
: Boolean read FGodMode write FGodMode
;
392 property eNoTarget
: Boolean read FNoTarget write FNoTarget
;
393 property eNoReload
: Boolean read FNoReload write FNoReload
;
394 property eAlive
: Boolean read FAlive write FAlive
;
395 property eFlag
: Byte read FFlag
;
396 property eTeam
: Byte read FTeam write FTeam
;
397 property eDirection
: TDirection read FDirection
;
398 property eGameX
: Integer read FObj
.X write FObj
.X
;
399 property eGameY
: Integer read FObj
.Y write FObj
.Y
;
400 property eGameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
401 property eGameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
402 property eGameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
403 property eGameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
404 property eIncCam
: Integer read FIncCam write FIncCam
;
405 property eUID
: Word read FUID
;
406 property eJustTeleported
: Boolean read FJustTeleported
;
407 property eNetTime
: LongWord read FNetTime
;
409 // set this before assigning something to `eDamage`
410 property eDamageType
: Integer read mEDamageType write mEDamageType
;
411 property eDamage
: Integer write doDamage
;
422 WeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
423 CloseWeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
424 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
427 procedure save (st
: TStream
);
428 procedure load (st
: TStream
);
436 TBot
= class(TPlayer
)
438 FSelectedWeapon
: Byte;
441 FAIFlags
: Array of TAIFlag
;
442 FDifficult
: TDifficult
;
444 function GetRnd(a
: Byte): Boolean;
445 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
446 function RunDirection(): TDirection
;
447 function FullInStep(XInc
, YInc
: Integer): Boolean;
448 //function NeedItem(Item: Byte): Byte;
449 procedure SelectWeapon(Dist
: Integer);
450 procedure SetAIFlag(aName
, fValue
: String20
);
451 function GetAIFlag(aName
: String20
): String20
;
452 procedure RemoveAIFlag(aName
: String20
);
453 function Healthy(): Byte;
454 procedure UpdateMove();
455 procedure UpdateCombat();
456 function KeyPressed(Key
: Word): Boolean;
457 procedure ReleaseKey(Key
: Byte);
458 function TargetOnScreen(TX
, TY
: Integer): Boolean;
459 procedure OnDamage(Angle
: SmallInt); override;
462 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
463 constructor Create(); override;
464 destructor Destroy(); override;
465 procedure Draw(); override;
466 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
467 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
468 procedure Update(); override;
469 procedure SaveState (st
: TStream
); override;
470 procedure LoadState (st
: TStream
); override;
482 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
483 procedure moveBy (dx
, dy
: Integer); inline;
485 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
499 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
500 procedure moveBy (dx
, dy
: Integer); inline;
502 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
505 TCorpse
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
514 FAnimation
: TAnimation
;
515 FAnimationMask
: TAnimation
;
518 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
519 destructor Destroy(); override;
520 procedure Damage(Value
: Word; vx
, vy
: Integer);
523 procedure SaveState (st
: TStream
);
524 procedure LoadState (st
: TStream
);
526 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
527 procedure moveBy (dx
, dy
: Integer); inline;
529 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
531 function ObjPtr (): PObj
; inline;
533 property Obj
: TObj read FObj
; // copies object
534 property State
: Byte read FState
;
535 property Mess
: Boolean read FMess
;
538 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
544 gPlayers
: Array of TPlayer
;
545 gCorpses
: Array of TCorpse
;
546 gGibs
: Array of TGib
;
547 gShells
: Array of TShell
;
548 gTeamStat
: TTeamStat
;
549 gFly
: Boolean = False;
550 gAimLine
: Boolean = False;
551 gChatBubble
: Byte = 0;
555 MAX_RUNVEL
: Integer = 8;
556 VEL_JUMP
: Integer = 10;
557 SHELL_TIMEOUT
: Cardinal = 60000;
559 function Lerp(X
, Y
, Factor
: Integer): Integer;
561 procedure g_Gibs_SetMax(Count
: Word);
562 function g_Gibs_GetMax(): Word;
563 procedure g_Corpses_SetMax(Count
: Word);
564 function g_Corpses_GetMax(): Word;
565 procedure g_Shells_SetMax(Count
: Word);
566 function g_Shells_GetMax(): Word;
568 procedure g_Player_Init();
569 procedure g_Player_Free();
570 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
571 function g_Player_CreateFromState (st
: TStream
): Word;
572 procedure g_Player_Remove(UID
: Word);
573 procedure g_Player_ResetTeams();
574 procedure g_Player_UpdateAll();
575 procedure g_Player_DrawAll();
576 procedure g_Player_DrawDebug(p
: TPlayer
);
577 procedure g_Player_DrawHealth();
578 procedure g_Player_RememberAll();
579 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
580 function g_Player_Get(UID
: Word): TPlayer
;
581 function g_Player_GetCount(): Byte;
582 function g_Player_GetStats(): TPlayerStatArray
;
583 function g_Player_ValidName(Name
: String): Boolean;
584 procedure g_Player_CreateCorpse(Player
: TPlayer
);
585 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
586 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
587 procedure g_Player_UpdatePhysicalObjects();
588 procedure g_Player_DrawCorpses();
589 procedure g_Player_DrawShells();
590 procedure g_Player_RemoveAllCorpses();
591 procedure g_Player_Corpses_SaveState (st
: TStream
);
592 procedure g_Player_Corpses_LoadState (st
: TStream
);
593 procedure g_Bot_Add(Team
, Difficult
: Byte);
594 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1);
595 procedure g_Bot_MixNames();
596 procedure g_Bot_RemoveAll();
601 {$INCLUDE ../nogl/noGLuses.inc}
602 {$IFDEF ENABLE_HOLMES}
605 e_log
, g_map
, g_items
, g_console
, g_gfx
, Math
,
606 g_options
, g_triggers
, g_menu
, g_game
, g_grid
,
607 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
,
608 g_net
, g_netmsg
, g_window
,
611 const PLR_SAVE_VERSION
= 0;
621 diag_precision
: Byte;
625 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
626 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
627 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
631 TIME_RESPAWN1
= 1500;
632 TIME_RESPAWN2
= 2000;
633 TIME_RESPAWN3
= 3000;
636 JET_MAX
= 540; // ~30 sec
637 PLAYER_SUIT_TIME
= 30000;
638 PLAYER_INVUL_TIME
= 30000;
639 PLAYER_INVIS_TIME
= 35000;
640 FRAG_COMBO_TIME
= 3000;
644 ANGLE_RIGHTDOWN
= -35;
646 ANGLE_LEFTDOWN
= -145;
647 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
648 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
651 BOT_UNSAFEDIST
= 128;
652 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
654 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
655 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
656 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
657 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
658 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
659 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
660 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
661 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
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 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
664 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
665 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
666 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
667 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
668 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
669 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
670 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
671 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
672 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
673 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
674 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
675 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
676 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
677 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
678 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
679 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
681 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
682 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
684 BOTNAMES_FILENAME
= 'botnames.txt';
685 BOTLIST_FILENAME
= 'botlist.txt';
689 MaxCorpses
: Word = 20;
690 MaxShells
: Word = 300;
691 CurrentGib
: Integer = 0;
692 CurrentShell
: Integer = 0;
693 BotNames
: Array of String;
694 BotList
: Array of TBotProfile
;
697 function Lerp(X
, Y
, Factor
: Integer): Integer;
699 Result
:= X
+ ((Y
- X
) div Factor
);
702 function SameTeam(UID1
, UID2
: Word): Boolean;
706 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
707 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
709 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
711 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
712 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
714 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
717 procedure g_Gibs_SetMax(Count
: Word);
720 SetLength(gGibs
, Count
);
722 if CurrentGib
>= Count
then
726 function g_Gibs_GetMax(): Word;
731 procedure g_Shells_SetMax(Count
: Word);
734 SetLength(gShells
, Count
);
736 if CurrentShell
>= Count
then
740 function g_Shells_GetMax(): Word;
746 procedure g_Corpses_SetMax(Count
: Word);
749 SetLength(gCorpses
, Count
);
752 function g_Corpses_GetMax(): Word;
754 Result
:= MaxCorpses
;
757 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
767 // Åñòü ëè ìåñòî â gPlayers:
768 if gPlayers
<> nil then
769 for a
:= 0 to High(gPlayers
) do
770 if gPlayers
[a
] = nil then
776 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
779 SetLength(gPlayers
, Length(gPlayers
)+1);
783 // Ñîçäàåì îáúåêò èãðîêà:
785 gPlayers
[a
] := TBot
.Create()
787 gPlayers
[a
] := TPlayer
.Create();
790 gPlayers
[a
].FActualModelName
:= ModelName
;
791 gPlayers
[a
].SetModel(ModelName
);
793 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
794 if gPlayers
[a
].FModel
= nil then
798 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
802 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
803 if Random(2) = 0 then
807 gPlayers
[a
].FPreferredTeam
:= Team
;
809 case gGameSettings
.GameMode
of
810 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
812 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
814 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
817 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
818 gPlayers
[a
].FColor
:= Color
;
819 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
820 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
822 gPlayers
[a
].FModel
.Color
:= Color
;
824 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
825 gPlayers
[a
].FAlive
:= False;
827 Result
:= gPlayers
[a
].FUID
;
830 function g_Player_CreateFromState (st
: TStream
): Word;
837 if (st
= nil) then exit
; //???
840 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
841 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
844 Bot
:= utils
.readBool(st
);
849 // Åñòü ëè ìåñòî â gPlayers:
850 for a
:= 0 to High(gPlayers
) do if (gPlayers
[a
] = nil) then begin ok
:= true; break
; end;
852 // Íåò ìåñòà - ðàñøèðÿåì gPlayers
855 SetLength(gPlayers
, Length(gPlayers
)+1);
859 // Ñîçäàåì îáúåêò èãðîêà
861 gPlayers
[a
] := TBot
.Create()
863 gPlayers
[a
] := TPlayer
.Create();
864 gPlayers
[a
].FIamBot
:= Bot
;
865 gPlayers
[a
].FPhysics
:= True;
868 gPlayers
[a
].FUID
:= utils
.readWord(st
);
870 gPlayers
[a
].FName
:= utils
.readStr(st
);
872 gPlayers
[a
].FTeam
:= utils
.readByte(st
);
873 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
875 gPlayers
[a
].FAlive
:= utils
.readBool(st
);
876 // Èçðàñõîäîâàë ëè âñå æèçíè
877 gPlayers
[a
].FNoRespawn
:= utils
.readBool(st
);
879 b
:= utils
.readByte(st
);
880 if b
= 1 then gPlayers
[a
].FDirection
:= TDirection
.D_LEFT
else gPlayers
[a
].FDirection
:= TDirection
.D_RIGHT
; // b = 2
882 gPlayers
[a
].FHealth
:= utils
.readLongInt(st
);
884 gPlayers
[a
].FLives
:= utils
.readByte(st
);
886 gPlayers
[a
].FArmor
:= utils
.readLongInt(st
);
888 gPlayers
[a
].FAir
:= utils
.readLongInt(st
);
890 gPlayers
[a
].FJetFuel
:= utils
.readLongInt(st
);
892 gPlayers
[a
].FPain
:= utils
.readLongInt(st
);
894 gPlayers
[a
].FKills
:= utils
.readLongInt(st
);
896 gPlayers
[a
].FMonsterKills
:= utils
.readLongInt(st
);
898 gPlayers
[a
].FFrags
:= utils
.readLongInt(st
);
900 gPlayers
[a
].FFragCombo
:= utils
.readByte(st
);
901 // Âðåìÿ ïîñëåäíåãî ôðàãà
902 gPlayers
[a
].FLastFrag
:= utils
.readLongWord(st
);
904 gPlayers
[a
].FDeath
:= utils
.readLongInt(st
);
906 gPlayers
[a
].FFlag
:= utils
.readByte(st
);
908 gPlayers
[a
].FSecrets
:= utils
.readLongInt(st
);
910 gPlayers
[a
].FCurrWeap
:= utils
.readByte(st
);
911 // Ñëåäóþùåå æåëàåìîå îðóæèå
912 gPlayers
[a
].FNextWeap
:= utils
.readWord(st
);
914 gPlayers
[a
].FNextWeapDelay
:= utils
.readByte(st
);
916 gPlayers
[a
].FBFGFireCounter
:= utils
.readSmallInt(st
);
918 gPlayers
[a
].FDamageBuffer
:= utils
.readLongInt(st
);
919 // Ïîñëåäíèé óäàðèâøèé
920 gPlayers
[a
].FLastSpawnerUID
:= utils
.readWord(st
);
921 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
922 gPlayers
[a
].FLastHit
:= utils
.readByte(st
);
924 Obj_LoadState(@gPlayers
[a
].FObj
, st
);
925 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
926 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FAmmo
[i
] := utils
.readWord(st
);
927 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
928 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FMaxAmmo
[i
] := utils
.readWord(st
);
930 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FWeapon
[i
] := utils
.readBool(st
);
931 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
932 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FReloading
[i
] := utils
.readWord(st
);
934 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
935 // Íàëè÷èå êðàñíîãî êëþ÷à
936 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
937 // Íàëè÷èå çåëåíîãî êëþ÷à
938 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
939 // Íàëè÷èå ñèíåãî êëþ÷à
940 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
942 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_BERSERK
);
943 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
944 for i
:= MR_SUIT
to MR_MAX
do gPlayers
[a
].FMegaRulez
[i
] := utils
.readLongWord(st
);
945 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
946 for i
:= T_RESPAWN
to T_FLAGCAP
do gPlayers
[a
].FTime
[i
] := utils
.readLongWord(st
);
949 gPlayers
[a
].FActualModelName
:= utils
.readStr(st
);
951 gPlayers
[a
].FColor
.R
:= utils
.readByte(st
);
952 gPlayers
[a
].FColor
.G
:= utils
.readByte(st
);
953 gPlayers
[a
].FColor
.B
:= utils
.readByte(st
);
954 // Îáíîâëÿåì ìîäåëü èãðîêà
955 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
957 // Íåò ìîäåëè - ñîçäàíèå íåâîçìîæíî
958 if (gPlayers
[a
].FModel
= nil) then
962 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
966 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû
967 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
968 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
970 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
972 result
:= gPlayers
[a
].FUID
;
976 procedure g_Player_ResetTeams();
980 if g_Game_IsClient
then
982 if gPlayers
= nil then
984 for a
:= Low(gPlayers
) to High(gPlayers
) do
985 if gPlayers
[a
] <> nil then
986 case gGameSettings
.GameMode
of
988 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
990 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
991 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
992 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
995 gPlayers
[a
].ChangeTeam(TEAM_RED
)
997 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
1000 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
1004 procedure g_Bot_Add(Team
, Difficult
: Byte);
1007 _name
, _model
: String;
1010 if not g_Game_IsServer
then Exit
;
1012 // Ñïèñîê íàçâàíèé ìîäåëåé:
1013 m
:= g_PlayerModel_GetNames();
1018 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1019 Team
:= TEAM_COOP
// COOP
1021 if gGameSettings
.GameMode
= GM_DM
then
1022 Team
:= TEAM_NONE
// DM
1024 if Team
= TEAM_NONE
then // CTF / TDM
1026 // Àâòîáàëàíñ êîìàíä:
1030 for a
:= 0 to High(gPlayers
) do
1031 if gPlayers
[a
] <> nil then
1033 if gPlayers
[a
].Team
= TEAM_RED
then
1036 if gPlayers
[a
].Team
= TEAM_BLUE
then
1046 if Random(2) = 0 then
1052 // Âûáèðàåì áîòó èìÿ:
1054 if BotNames
<> nil then
1055 for a
:= 0 to High(BotNames
) do
1056 if g_Player_ValidName(BotNames
[a
]) then
1058 _name
:= BotNames
[a
];
1062 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
1065 _name
:= Format('DFBOT%.2d', [Random(100)]);
1066 until g_Player_ValidName(_name
);
1068 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1069 _model
:= m
[Random(Length(m
))];
1072 with g_Player_Get(g_Player_Create(_model
,
1073 _RGB(Min(Random(9)*32, 255),
1074 Min(Random(9)*32, 255),
1075 Min(Random(9)*32, 255)),
1076 Team
, True)) as TBot
do
1081 1: FDifficult
:= DIFFICULT_EASY
;
1082 2: FDifficult
:= DIFFICULT_MEDIUM
;
1083 else FDifficult
:= DIFFICULT_HARD
;
1086 for a
:= WP_FIRST
to WP_LAST
do
1088 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1089 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1090 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1093 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1095 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1096 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1101 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1);
1104 _name
, _model
: String;
1107 if not g_Game_IsServer
then Exit
;
1109 // Ñïèñîê íàçâàíèé ìîäåëåé:
1110 m
:= g_PlayerModel_GetNames();
1115 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1116 Team
:= TEAM_COOP
// COOP
1118 if gGameSettings
.GameMode
= GM_DM
then
1119 Team
:= TEAM_NONE
// DM
1121 if Team
= TEAM_NONE
then
1122 Team
:= BotList
[num
].team
; // CTF / TDM
1124 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1125 lName
:= AnsiLowerCase(lName
);
1126 if (num
< 0) or (num
> Length(BotList
)-1) then
1128 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1129 for a
:= 0 to High(BotList
) do
1130 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1139 _name
:= BotList
[num
].name
;
1140 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1141 if not g_Player_ValidName(_name
) then
1143 _name
:= Format('DFBOT%.2d', [Random(100)]);
1144 until g_Player_ValidName(_name
);
1147 _model
:= BotList
[num
].model
;
1148 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1149 if not InSArray(_model
, m
) then
1150 _model
:= m
[Random(Length(m
))];
1153 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1157 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1158 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1159 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1160 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1161 FDifficult
.Cover
:= BotList
[num
].cover
;
1162 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1164 for a
:= WP_FIRST
to WP_LAST
do
1166 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1167 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1168 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1171 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1173 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1177 procedure g_Bot_RemoveAll();
1181 if not g_Game_IsServer
then Exit
;
1182 if gPlayers
= nil then Exit
;
1184 for a
:= 0 to High(gPlayers
) do
1185 if gPlayers
[a
] <> nil then
1186 if gPlayers
[a
] is TBot
then
1188 gPlayers
[a
].Lives
:= 0;
1189 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1190 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1191 g_Player_Remove(gPlayers
[a
].FUID
);
1197 procedure g_Bot_MixNames();
1202 if BotNames
<> nil then
1203 for a
:= 0 to High(BotNames
) do
1205 b
:= Random(Length(BotNames
));
1207 Botnames
[a
] := BotNames
[b
];
1212 procedure g_Player_Remove(UID
: Word);
1216 if gPlayers
= nil then Exit
;
1218 if g_Game_IsServer
and g_Game_IsNet
then
1219 MH_SEND_PlayerDelete(UID
);
1221 for i
:= 0 to High(gPlayers
) do
1222 if gPlayers
[i
] <> nil then
1223 if gPlayers
[i
].FUID
= UID
then
1225 if gPlayers
[i
] is TPlayer
then
1226 TPlayer(gPlayers
[i
]).Free()
1228 TBot(gPlayers
[i
]).Free();
1234 procedure g_Player_Init();
1244 if not FileExists(DataDir
+ BOTNAMES_FILENAME
) then
1247 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1248 AssignFile(F
, DataDir
+ BOTNAMES_FILENAME
);
1259 SetLength(BotNames
, Length(BotNames
)+1);
1260 BotNames
[High(BotNames
)] := s
;
1268 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1269 config
:= TConfig
.CreateFile(DataDir
+ BOTLIST_FILENAME
);
1273 while config
.SectionExists(IntToStr(a
)) do
1275 SetLength(BotList
, Length(BotList
)+1);
1277 with BotList
[High(BotList
)] do
1280 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1282 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1284 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1289 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1290 color
.R
:= StrToIntDef(sa
[0], 0);
1291 color
.G
:= StrToIntDef(sa
[1], 0);
1292 color
.B
:= StrToIntDef(sa
[2], 0);
1293 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1294 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1295 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1296 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1297 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1298 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1299 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1300 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1301 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1302 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1303 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1304 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1305 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1306 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1307 if Length(sa
) = 10 then
1309 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1310 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1311 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1312 if Length(sa
) = 10 then
1314 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1316 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1317 if Length(sa) = 10 then
1319 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1328 procedure g_Player_Free();
1332 if gPlayers
<> nil then
1334 for i
:= 0 to High(gPlayers
) do
1335 if gPlayers
[i
] <> nil then
1337 if gPlayers
[i
] is TPlayer
then
1338 TPlayer(gPlayers
[i
]).Free()
1340 TBot(gPlayers
[i
]).Free();
1351 procedure g_Player_UpdateAll();
1355 if gPlayers
= nil then Exit
;
1357 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1358 for i
:= 0 to High(gPlayers
) do
1360 if gPlayers
[i
] <> nil then
1362 if gPlayers
[i
] is TPlayer
then
1364 gPlayers
[i
].Update();
1365 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1369 // bot updates weapons in `UpdateCombat()`
1370 TBot(gPlayers
[i
]).Update();
1374 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1377 procedure g_Player_DrawAll();
1381 if gPlayers
= nil then Exit
;
1383 for i
:= 0 to High(gPlayers
) do
1384 if gPlayers
[i
] <> nil then
1385 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1386 else TBot(gPlayers
[i
]).Draw();
1389 procedure g_Player_DrawDebug(p
: TPlayer
);
1393 if p
= nil then Exit
;
1394 if (@p
.FObj
) = nil then Exit
;
1396 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1398 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1399 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1400 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1401 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1402 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1403 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1406 procedure g_Player_DrawHealth();
1411 if gPlayers
= nil then Exit
;
1412 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1414 for i
:= 0 to High(gPlayers
) do
1415 if gPlayers
[i
] <> nil then
1417 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1418 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1419 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1420 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1421 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1422 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1426 function g_Player_Get(UID
: Word): TPlayer
;
1432 if gPlayers
= nil then
1435 for a
:= 0 to High(gPlayers
) do
1436 if gPlayers
[a
] <> nil then
1437 if gPlayers
[a
].FUID
= UID
then
1439 Result
:= gPlayers
[a
];
1444 function g_Player_GetCount(): Byte;
1450 if gPlayers
= nil then
1453 for a
:= 0 to High(gPlayers
) do
1454 if gPlayers
[a
] <> nil then
1455 Result
:= Result
+ 1;
1458 function g_Player_GetStats(): TPlayerStatArray
;
1464 if gPlayers
= nil then Exit
;
1466 for a
:= 0 to High(gPlayers
) do
1467 if gPlayers
[a
] <> nil then
1469 SetLength(Result
, Length(Result
)+1);
1470 with Result
[High(Result
)] do
1472 Ping
:= gPlayers
[a
].FPing
;
1473 Loss
:= gPlayers
[a
].FLoss
;
1474 Name
:= gPlayers
[a
].FName
;
1475 Team
:= gPlayers
[a
].FTeam
;
1476 Frags
:= gPlayers
[a
].FFrags
;
1477 Deaths
:= gPlayers
[a
].FDeath
;
1478 Kills
:= gPlayers
[a
].FKills
;
1479 Color
:= gPlayers
[a
].FModel
.Color
;
1480 Lives
:= gPlayers
[a
].FLives
;
1481 Spectator
:= gPlayers
[a
].FSpectator
;
1486 procedure g_Player_RememberAll
;
1490 for i
:= Low(gPlayers
) to High(gPlayers
) do
1491 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1492 gPlayers
[i
].RememberState
;
1495 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1499 gTeamStat
[TEAM_RED
].Goals
:= 0;
1500 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1502 if gPlayers
<> nil then
1503 for i
:= 0 to High(gPlayers
) do
1504 if gPlayers
[i
] <> nil then
1506 gPlayers
[i
].Reset(Force
);
1508 if gPlayers
[i
] is TPlayer
then
1510 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1511 gPlayers
[i
].Respawn(Silent
)
1513 gPlayers
[i
].Spectate();
1516 TBot(gPlayers
[i
]).Respawn(Silent
);
1520 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1526 if Player
.alive
then
1529 // Ðàçðûâàåì ñâÿçü ñ ïðåæíèì òðóïîì:
1530 if gCorpses
<> nil then
1531 for i
:= 0 to High(gCorpses
) do
1532 if gCorpses
[i
] <> nil then
1533 if gCorpses
[i
].FPlayerUID
= Player
.FUID
then
1534 gCorpses
[i
].FPlayerUID
:= 0;
1536 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1541 if (FHealth
>= -50) or (gGibsCount
= 0) then
1543 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1547 for find_id
:= 0 to High(gCorpses
) do
1548 if gCorpses
[find_id
] = nil then
1555 find_id
:= Random(Length(gCorpses
));
1557 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1558 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1559 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1560 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1561 gCorpses
[find_id
].FPlayerUID
:= FUID
;
1564 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1565 FObj
.Y
+ PLAYER_RECT_CY
,
1566 FModel
.Name
, FModel
.Color
);
1570 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1574 if (gShells
= nil) or (Length(gShells
) = 0) then
1577 with gShells
[CurrentShell
] do
1583 if T
= SHELL_BULLET
then
1585 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1589 Obj
.Rect
.Width
:= 4;
1590 Obj
.Rect
.Height
:= 2;
1594 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1598 Obj
.Rect
.Width
:= 7;
1599 Obj
.Rect
.Height
:= 3;
1605 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1606 positionChanged(); // this updates spatial accelerators
1607 RAngle
:= Random(360);
1608 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1610 if CurrentShell
>= High(gShells
) then
1617 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1620 GibsArray
: TGibsArray
;
1623 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1625 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1627 Blood
:= g_PlayerModel_GetBlood(ModelName
);
1629 for a
:= 0 to High(GibsArray
) do
1630 with gGibs
[CurrentGib
] do
1633 ID
:= GibsArray
[a
].ID
;
1634 MaskID
:= GibsArray
[a
].MaskID
;
1637 Obj
.Rect
:= GibsArray
[a
].Rect
;
1638 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1639 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1640 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1641 positionChanged(); // this updates spatial accelerators
1642 RAngle
:= Random(360);
1644 if gBloodCount
> 0 then
1645 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1646 Random(48), Random(48), Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
1648 if CurrentGib
>= High(gGibs
) then
1655 procedure g_Player_UpdatePhysicalObjects();
1661 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1666 if T
= SHELL_BULLET
then
1667 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1669 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1674 if gGibs
<> nil then
1675 for i
:= 0 to High(gGibs
) do
1676 if gGibs
[i
].alive
then
1680 mr
:= g_Obj_Move(@Obj
, True, False, True);
1681 positionChanged(); // this updates spatial accelerators
1683 if WordBool(mr
and MOVE_FALLOUT
) then
1689 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1690 if WordBool(mr
and MOVE_HITWALL
) then
1691 Obj
.Vel
.X
:= -(vel
.X
div 2);
1692 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1693 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1695 if (Obj
.Vel
.X
>= 0) then
1697 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1698 if RAngle
>= 360 then
1699 RAngle
:= RAngle
mod 360;
1700 end else begin // Counter-clockwise
1701 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1703 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1706 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1707 if gTime
mod (GAME_TICK
*3) = 0 then
1708 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1712 if gCorpses
<> nil then
1713 for i
:= 0 to High(gCorpses
) do
1714 if gCorpses
[i
] <> nil then
1715 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1721 gCorpses
[i
].Update();
1724 if gShells
<> nil then
1725 for i
:= 0 to High(gShells
) do
1726 if gShells
[i
].alive
then
1730 mr
:= g_Obj_Move(@Obj
, True, False, True);
1731 positionChanged(); // this updates spatial accelerators
1733 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1739 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1740 if WordBool(mr
and MOVE_HITWALL
) then
1742 Obj
.Vel
.X
:= -(vel
.X
div 2);
1743 if not WordBool(mr
and MOVE_INWATER
) then
1744 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1746 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1748 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1749 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1750 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1752 if RAngle
mod 90 <> 0 then
1753 RAngle
:= (RAngle
div 90) * 90;
1755 else if not WordBool(mr
and MOVE_INWATER
) then
1756 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1759 if (Obj
.Vel
.X
>= 0) then
1761 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1762 if RAngle
>= 360 then
1763 RAngle
:= RAngle
mod 360;
1764 end else begin // Counter-clockwise
1765 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1767 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1773 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1775 x
:= Obj
.X
+Obj
.Rect
.X
;
1776 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1777 w
:= Obj
.Rect
.Width
;
1778 h
:= Obj
.Rect
.Height
;
1781 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1783 if (dx
<> 0) or (dy
<> 0) then
1792 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1796 w
:= Obj
.Rect
.Width
;
1797 h
:= Obj
.Rect
.Height
;
1800 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1802 if (dx
<> 0) or (dy
<> 0) then
1811 procedure TGib
.positionChanged (); inline; begin end;
1812 procedure TShell
.positionChanged (); inline; begin end;
1815 procedure g_Player_DrawCorpses();
1820 if gGibs
<> nil then
1821 for i
:= 0 to High(gGibs
) do
1822 if gGibs
[i
].alive
then
1825 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1828 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1829 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1831 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1834 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1840 if gCorpses
<> nil then
1841 for i
:= 0 to High(gCorpses
) do
1842 if gCorpses
[i
] <> nil then
1846 procedure g_Player_DrawShells();
1851 if gShells
<> nil then
1852 for i
:= 0 to High(gShells
) do
1853 if gShells
[i
].alive
then
1856 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1862 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1866 procedure g_Player_RemoveAllCorpses();
1872 SetLength(gGibs
, MaxGibs
);
1873 SetLength(gShells
, MaxGibs
);
1877 if gCorpses
<> nil then
1878 for i
:= 0 to High(gCorpses
) do
1882 SetLength(gCorpses
, MaxCorpses
);
1885 procedure g_Player_Corpses_SaveState (st
: TStream
);
1889 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ
1891 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1893 // Êîëè÷åñòâî òðóïîâ
1894 utils
.writeInt(st
, LongInt(count
));
1896 if (count
= 0) then exit
;
1899 for i
:= 0 to High(gCorpses
) do
1901 if gCorpses
[i
] <> nil then
1904 utils
.writeStr(st
, gCorpses
[i
].FModelName
);
1906 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1907 // Ñîõðàíÿåì äàííûå òðóïà:
1908 gCorpses
[i
].SaveState(st
);
1914 procedure g_Player_Corpses_LoadState (st
: TStream
);
1922 g_Player_RemoveAllCorpses();
1924 // Êîëè÷åñòâî òðóïîâ:
1925 count
:= utils
.readLongInt(st
);
1926 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1928 if (count
= 0) then exit
;
1931 for i
:= 0 to count
-1 do
1934 str
:= utils
.readStr(st
);
1936 b
:= utils
.readBool(st
);
1938 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1939 // Çàãðóæàåì äàííûå òðóïà
1940 gCorpses
[i
].LoadState(st
);
1947 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1949 procedure TPlayer
.BFGHit();
1951 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1952 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1953 if g_Game_IsServer
and g_Game_IsNet
then
1954 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1955 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1959 procedure TPlayer
.ChangeModel(ModelName
: string);
1961 locModel
: TPlayerModel
;
1963 locModel
:= g_PlayerModel_Get(ModelName
);
1964 if locModel
= nil then Exit
;
1970 procedure TPlayer
.SetModel(ModelName
: string);
1974 m
:= g_PlayerModel_Get(ModelName
);
1977 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1978 m
:= g_PlayerModel_Get('doomer');
1981 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1986 if FModel
<> nil then
1991 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1992 FModel
.Color
:= FColor
1994 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1995 FModel
.SetWeapon(FCurrWeap
);
1996 FModel
.SetFlag(FFlag
);
1997 SetDirection(FDirection
);
2000 procedure TPlayer
.SetColor(Color
: TRGB
);
2003 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2004 if FModel
<> nil then FModel
.Color
:= Color
;
2007 procedure TPlayer
.SwitchTeam
;
2009 if g_Game_IsClient
then
2011 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
2013 if gGameOn
and FAlive
then
2014 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
2016 if FTeam
= TEAM_RED
then
2018 ChangeTeam(TEAM_BLUE
);
2019 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
2020 if g_Game_IsNet
then
2021 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
2025 ChangeTeam(TEAM_RED
);
2026 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
2027 if g_Game_IsNet
then
2028 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
2030 FPreferredTeam
:= FTeam
;
2033 procedure TPlayer
.ChangeTeam(Team
: Byte);
2040 TEAM_RED
, TEAM_BLUE
:
2041 FModel
.Color
:= TEAMCOLOR
[Team
];
2043 FModel
.Color
:= FColor
;
2045 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2046 MH_SEND_PlayerStats(FUID
);
2050 procedure TPlayer.CollideItem();
2055 if gItems = nil then Exit;
2056 if not FAlive then Exit;
2058 for i := 0 to High(gItems) do
2061 if (ItemType <> ITEM_NONE) and alive then
2062 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2063 PLAYER_RECT.Height, @Obj) then
2065 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2067 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2068 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2069 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2070 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2071 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2073 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2074 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2075 (gGameSettings.GameType = GT_SINGLE) and
2076 (g_Player_GetCount() > 1)) then
2077 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2083 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2085 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2086 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2090 constructor TPlayer
.Create();
2096 mEDamageType
:= HIT_SOME
;
2102 FSawSound
:= TPlayableSound
.Create();
2103 FSawSoundIdle
:= TPlayableSound
.Create();
2104 FSawSoundHit
:= TPlayableSound
.Create();
2105 FSawSoundSelect
:= TPlayableSound
.Create();
2106 FJetSoundFly
:= TPlayableSound
.Create();
2107 FJetSoundOn
:= TPlayableSound
.Create();
2108 FJetSoundOff
:= TPlayableSound
.Create();
2110 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2111 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2112 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2113 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2114 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2115 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2116 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2118 FSpectatePlayer
:= -1;
2122 FSavedState
.WaitRecall
:= False;
2128 FActualModelName
:= 'doomer';
2131 FObj
.Rect
:= PLAYER_RECT
;
2133 FBFGFireCounter
:= -1;
2134 FJustTeleported
:= False;
2138 releaseAllWeaponSwitchKeys();
2142 procedure TPlayer
.releaseAllWeaponSwitchKeys ();
2146 for f
:= 0 to High(weaponSwitchKeyReleased
) do weaponSwitchKeyReleased
[f
] := true;
2149 procedure TPlayer
.weaponSwitchKeysStateChange (index
: Integer; pressed
: Boolean);
2151 Inc(index
, 2); // -2: prev; -1: next
2152 if (index
< 0) or (index
> High(weaponSwitchKeyReleased
)) then exit
;
2153 weaponSwitchKeyReleased
[index
] := not pressed
;
2156 function TPlayer
.isWeaponSwitchKeyReleased (index
: Integer): Boolean;
2158 Inc(index
, 2); // -2: prev; -1: next
2159 if (index
< 0) or (index
> High(weaponSwitchKeyReleased
)) then
2165 result
:= weaponSwitchKeyReleased
[index
];
2170 procedure TPlayer
.positionChanged (); inline;
2174 procedure TPlayer
.doDamage (v
: Integer);
2176 if (v
<= 0) then exit
;
2177 if (v
> 32767) then v
:= 32767;
2178 Damage(v
, 0, 0, 0, mEDamageType
);
2181 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2185 if (not g_Game_IsClient
) and (not FAlive
) then
2190 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2191 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2193 if not g_Game_IsClient
then
2196 if t
= HIT_TRAP
then
2198 // Ëîâóøêà óáèâàåò ñðàçó:
2200 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2202 if t
= HIT_SELF
then
2206 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2209 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2210 FMegaRulez
[MR_SUIT
] := 0;
2211 FMegaRulez
[MR_INVUL
] := 0;
2212 FMegaRulez
[MR_INVIS
] := 0;
2216 // Íî îò îñòàëüíîãî ñïàñàåò:
2217 if FMegaRulez
[MR_INVUL
] >= gTime
then
2224 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2225 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2226 (SpawnerUID
= FUID
) or
2227 (not SameTeam(FUID
, SpawnerUID
)) then
2229 FLastSpawnerUID
:= SpawnerUID
;
2231 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2232 if gBloodCount
> 0 then
2234 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2235 if value
div 4 <= c
then
2236 c
:= c
- (value
div 4)
2240 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2244 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2245 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2248 if t
= HIT_WATER
then
2249 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2250 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2255 Inc(FDamageBuffer
, value
);
2259 FPain
:= FPain
+ value
;
2262 if g_Game_IsServer
and g_Game_IsNet
then
2264 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2265 MH_SEND_PlayerStats(FUID
);
2266 MH_SEND_PlayerPos(False, FUID
);
2270 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2273 if g_Game_IsClient
then
2278 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2280 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2283 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2285 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2289 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2290 MH_SEND_PlayerStats(FUID
);
2293 destructor TPlayer
.Destroy();
2295 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2297 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2301 FSawSoundIdle
.Free();
2302 FSawSoundHit
.Free();
2303 FJetSoundFly
.Free();
2305 FJetSoundOff
.Free();
2307 if FPunchAnim
<> nil then
2313 procedure TPlayer
.DrawBubble();
2315 bubX
, bubY
: Integer;
2318 Rw
, Gw
, Bw
: SmallInt;
2321 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= TDirection
.D_LEFT
, -4, 18);
2322 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2330 1: // simple textual non-bubble
2332 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2333 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2334 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2337 2: // advanced pixel-perfect bubble
2339 if FTeam
= TEAM_RED
then
2342 if FTeam
= TEAM_BLUE
then
2345 3: // colored bubble
2347 Rb
:= FModel
.Color
.R
;
2348 Gb
:= FModel
.Color
.G
;
2349 Bb
:= FModel
.Color
.B
;
2350 Rw
:= Min(Rb
* 2 + 64, 255);
2351 Gw
:= Min(Gb
* 2 + 64, 255);
2352 Bw
:= Min(Bb
* 2 + 64, 255);
2353 if (Abs(Rw
- Rb
) < 32)
2354 or (Abs(Gw
- Gb
) < 32)
2355 or (Abs(Bw
- Bb
) < 32) then
2357 Rb
:= Max(Rw
div 2 - 16, 0);
2358 Gb
:= Max(Gw
div 2 - 16, 0);
2359 Bb
:= Max(Bw
div 2 - 16, 0);
2362 4: // custom textured bubble
2364 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2365 if FDirection
= TDirection
.D_RIGHT
then
2366 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2368 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, TMirrorType
.Horizontal
);
2374 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2375 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2377 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2380 Dot
:= IfThen(FDirection
= TDirection
.D_LEFT
, 14, 5);
2381 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2382 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
);
2383 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
);
2384 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
);
2385 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
);
2389 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2390 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2391 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2394 procedure TPlayer
.Draw();
2399 Mirror
: TMirrorType
;
2403 if Direction
= TDirection
.D_RIGHT
then
2404 Mirror
:= TMirrorType
.None
2406 Mirror
:= TMirrorType
.Horizontal
;
2408 if FPunchAnim
<> nil then
2410 FPunchAnim
.Draw(FObj
.X
+IfThen(Direction
= TDirection
.D_LEFT
, 15-FObj
.Rect
.X
, FObj
.Rect
.X
-15),
2411 FObj
.Y
+FObj
.Rect
.Y
-11, Mirror
);
2412 if FPunchAnim
.played
then
2419 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2420 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2422 e_GetTextureSize(ID
, @w
, @h
);
2423 if FDirection
= TDirection
.D_LEFT
then
2424 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2425 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False)
2427 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2428 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False);
2431 if FMegaRulez
[MR_INVIS
] > gTime
then
2433 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2434 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2436 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2437 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2441 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 200)
2443 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2446 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 254);
2449 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2452 if g_debug_Frames
then
2454 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2456 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2457 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2461 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2463 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2464 if gAimLine
and alive
and
2465 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2470 procedure TPlayer
.DrawAim();
2471 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2476 {$IFDEF ENABLE_HOLMES}
2477 if isValidViewPort
and (self
= gPlayer1
) then
2479 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2483 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2484 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2486 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2490 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2495 wx
, wy
, xx
, yy
: Integer;
2499 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= TDirection
.D_LEFT
, 7, -7);
2500 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2509 1: begin // Chainsaw
2516 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2517 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2518 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2519 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2524 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2525 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2526 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2527 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2529 4: begin // Double Shotgun
2532 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2533 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2534 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2535 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2537 5: begin // Chaingun
2540 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2541 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2542 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2543 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2545 6: begin // Rocket Launcher
2548 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2549 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2550 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2551 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2553 7: begin // Plasmagun
2556 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2557 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2558 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2559 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2564 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2565 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2566 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2567 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2569 9: begin // Super Chaingun
2572 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2573 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2574 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2575 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2578 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2579 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2580 {$IF DEFINED(D2F_DEBUG)}
2581 drawCast(sz
, wx
, wy
, xx
, yy
);
2583 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2587 procedure TPlayer
.DrawGUI();
2590 X
, Y
, SY
, a
, p
, m
: Integer;
2594 stat
: TPlayerStatArray
;
2596 X
:= gPlayerScreenSize
.X
;
2597 SY
:= gPlayerScreenSize
.Y
;
2600 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2602 if gGameSettings
.GameMode
= GM_CTF
then
2606 if gGameSettings
.GameMode
= GM_CTF
then
2608 s
:= 'TEXTURE_PLAYER_REDFLAG';
2609 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2610 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2611 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2612 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2613 if g_Texture_Get(s
, ID
) then
2614 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2617 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2618 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2619 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2621 if gGameSettings
.GameMode
= GM_CTF
then
2623 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2624 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2625 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2626 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2627 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2628 if g_Texture_Get(s
, ID
) then
2629 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2632 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2633 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2634 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2637 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2638 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2641 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2642 e_Draw(ID
, X
+2, Y
, 0, True, False);
2644 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2648 s
:= IntToStr(Frags
);
2649 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2650 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2655 stat
:= g_Player_GetStats();
2660 for a
:= 0 to High(stat
) do
2661 if stat
[a
].Name
<> Name
then
2663 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2664 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2668 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2669 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2670 s
:= s
+IntToStr(Abs(Frags
-m
));
2672 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2673 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2676 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2678 s
:= IntToStr(Lives
);
2679 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2680 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2684 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2685 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2687 if R_BERSERK
in FRulez
then
2688 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2690 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2692 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2693 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2695 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2696 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2697 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2699 s
:= IntToStr(FArmor
);
2700 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2701 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2703 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2709 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2714 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2716 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2717 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2718 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2719 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2720 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2721 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2722 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2723 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2724 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2727 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2728 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2729 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2731 if R_KEY_RED
in FRulez
then
2732 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2734 if R_KEY_GREEN
in FRulez
then
2735 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2737 if R_KEY_BLUE
in FRulez
then
2738 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2740 if FJetFuel
> 0 then
2742 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2743 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2744 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2745 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2746 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2747 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2751 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2752 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2753 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2756 if gShowPing
and g_Game_IsClient
then
2758 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2759 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2765 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2766 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2767 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2770 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2771 s
:= _lc
[I_PLAYER_SPECT4
];
2772 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2773 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2774 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2780 procedure TPlayer
.DrawRulez();
2784 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2785 if FMegaRulez
[MR_INVUL
] >= gTime
then
2787 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2788 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2793 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2794 191, 191, 191, 0, TBlending
.Invert
);
2797 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2798 if FMegaRulez
[MR_SUIT
] >= gTime
then
2800 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2801 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2806 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2807 0, 96, 0, 200, TBlending
.None
);
2810 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2811 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2813 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2814 255, 0, 0, 200, TBlending
.None
);
2818 procedure TPlayer
.DrawPain();
2822 if FPain
= 0 then Exit
;
2826 if a
< 15 then h
:= 0
2827 else if a
< 35 then h
:= 1
2828 else if a
< 55 then h
:= 2
2829 else if a
< 75 then h
:= 3
2830 else if a
< 95 then h
:= 4
2833 //if a > 255 then a := 255;
2835 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2836 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2839 procedure TPlayer
.DrawPickup();
2843 if FPickup
= 0 then Exit
;
2847 if a
< 15 then h
:= 1
2848 else if a
< 35 then h
:= 2
2849 else if a
< 55 then h
:= 3
2850 else if a
< 75 then h
:= 4
2853 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2856 procedure TPlayer
.DoPunch();
2861 if FPunchAnim
<> nil then begin
2866 st
:= 'FRAMES_PUNCH';
2867 if R_BERSERK
in FRulez
then
2868 st
:= st
+ '_BERSERK';
2869 if FKeys
[KEY_UP
].Pressed
then
2871 else if FKeys
[KEY_DOWN
].Pressed
then
2873 g_Frames_Get(id
, st
);
2874 FPunchAnim
:= TAnimation
.Create(id
, False, 1);
2877 procedure TPlayer
.Fire();
2879 f
, DidFire
: Boolean;
2880 wx
, wy
, xd
, yd
: Integer;
2883 if g_Game_IsClient
then Exit
;
2884 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2885 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2893 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2898 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2899 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2900 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
2901 yd
:= wy
+firediry();
2907 if R_BERSERK
in FRulez
then
2909 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2910 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2911 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2914 locobj
.rect
.Width
:= 39;
2915 locobj
.rect
.Height
:= 52;
2916 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2917 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2918 locobj
.Accel
.X
:= xd
-wx
;
2919 locobj
.Accel
.y
:= yd
-wy
;
2921 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2922 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2924 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2926 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
2930 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2934 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2939 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2940 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2942 FSawSoundSelect
.Stop();
2944 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2946 else if not FSawSoundHit
.IsPlaying() then
2948 FSawSoundSelect
.Stop();
2949 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2952 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2958 if FAmmo
[A_BULLETS
] > 0 then
2960 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2961 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2962 Dec(FAmmo
[A_BULLETS
]);
2963 FFireAngle
:= FAngle
;
2966 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2967 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2971 if FAmmo
[A_SHELLS
] > 0 then
2973 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2974 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
2975 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2976 Dec(FAmmo
[A_SHELLS
]);
2977 FFireAngle
:= FAngle
;
2981 FShellType
:= SHELL_SHELL
;
2985 if FAmmo
[A_SHELLS
] >= 2 then
2987 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
2988 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2989 Dec(FAmmo
[A_SHELLS
], 2);
2990 FFireAngle
:= FAngle
;
2994 FShellType
:= SHELL_DBLSHELL
;
2998 if FAmmo
[A_BULLETS
] > 0 then
3000 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
3001 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
3002 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3003 Dec(FAmmo
[A_BULLETS
]);
3004 FFireAngle
:= FAngle
;
3007 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3008 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3011 WEAPON_ROCKETLAUNCHER
:
3012 if FAmmo
[A_ROCKETS
] > 0 then
3014 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
3015 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3016 Dec(FAmmo
[A_ROCKETS
]);
3017 FFireAngle
:= FAngle
;
3023 if FAmmo
[A_CELLS
] > 0 then
3025 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
3026 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3027 Dec(FAmmo
[A_CELLS
]);
3028 FFireAngle
:= FAngle
;
3034 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
3036 FBFGFireCounter
:= 17;
3037 if not FNoReload
then
3038 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
3039 Dec(FAmmo
[A_CELLS
], 40);
3043 WEAPON_SUPERPULEMET
:
3044 if FAmmo
[A_SHELLS
] > 0 then
3046 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3047 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
3048 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3049 Dec(FAmmo
[A_SHELLS
]);
3050 FFireAngle
:= FAngle
;
3053 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3054 GameVelX
, GameVelY
-2, SHELL_SHELL
);
3057 WEAPON_FLAMETHROWER
:
3058 if FAmmo
[A_FUEL
] > 0 then
3060 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
3061 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3063 FFireAngle
:= FAngle
;
3069 if g_Game_IsNet
then
3073 if FCurrWeap
<> WEAPON_BFG
then
3074 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
3076 if not FNoReload
then
3077 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
3080 MH_SEND_PlayerStats(FUID
);
3085 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
3086 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
3087 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
3090 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
3093 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
3094 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
3095 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
3096 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
3097 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
3102 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
3104 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
3105 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
3106 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
3109 procedure TPlayer
.JetpackOn
;
3113 FJetSoundOn
.SetPosition(0);
3114 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3118 procedure TPlayer
.JetpackOff
;
3122 FJetSoundOff
.SetPosition(0);
3123 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3126 procedure TPlayer
.CatchFire(Attacker
: Word);
3129 FFireAttacker
:= Attacker
;
3130 if g_Game_IsNet
and g_Game_IsServer
then
3131 MH_SEND_PlayerStats(FUID
);
3134 procedure TPlayer
.Jump();
3136 if gFly
or FJetpack
then
3138 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3139 if FObj
.Vel
.Y
> -VEL_FLY
then
3140 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3143 if FJetFuel
> 0 then
3145 if (FJetFuel
< 1) and g_Game_IsServer
then
3149 if g_Game_IsNet
then
3150 MH_SEND_PlayerStats(FUID
);
3156 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3158 FCanJetpack
:= False;
3160 // Ïðûãàåì èëè âñïëûâàåì:
3161 if (CollideLevel(0, 1) or
3162 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3163 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3164 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3166 FObj
.Vel
.Y
:= -VEL_JUMP
;
3167 FCanJetpack
:= False;
3171 if BodyInLiquid(0, 0) then
3172 FObj
.Vel
.Y
:= -VEL_SW
3173 else if (FJetFuel
> 0) and FCanJetpack
and
3174 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3178 if g_Game_IsNet
then
3179 MH_SEND_PlayerStats(FUID
);
3184 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3186 a
, i
, k
, ab
, ar
: Byte;
3190 srv
, netsrv
: Boolean;
3196 procedure PushItem(t
: Byte);
3200 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3201 it
:= g_Items_ByIdx(id
);
3202 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3204 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3205 (FObj
.Vel
.Y
div 2)-Random(9));
3206 it
.positionChanged(); // this updates spatial accelerators
3210 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3212 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3213 (FObj
.Vel
.Y
div 2)-Random(6));
3215 else // -3..+3; -3..0
3217 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3218 (FObj
.Vel
.Y
div 2)-Random(4));
3220 it
.positionChanged(); // this updates spatial accelerators
3223 if g_Game_IsNet
and g_Game_IsServer
then
3224 MH_SEND_ItemSpawn(True, id
);
3228 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3229 Srv
:= g_Game_IsServer
;
3230 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3231 if Srv
then FDeath
:= FDeath
+ 1;
3236 if not FPhysics
then
3242 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3244 if FLives
> 0 then FLives
:= FLives
- 1;
3245 if FLives
= 0 then FNoRespawn
:= True;
3248 // Íîìåð òèïà ñìåðòè:
3251 K_SIMPLEKILL
: a
:= 1;
3253 K_EXTRAHARDKILL
: a
:= 3;
3258 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3260 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3267 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3269 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3270 K_EXTRAHARDKILL
, K_FALLKILL
:
3271 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3274 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3278 K_HARDKILL
, K_EXTRAHARDKILL
:
3282 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3283 if (KillType
<> K_FALLKILL
) and (Srv
) then
3284 g_Monsters_killedp();
3286 if SpawnerUID
= FUID
then
3288 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3293 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3296 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3297 begin // Óáèò äðóãèì èãðîêîì
3298 KP
:= g_Player_Get(SpawnerUID
);
3299 if (KP
<> nil) and Srv
then
3301 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3302 if SameTeam(FUID
, SpawnerUID
) then
3312 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3313 Inc(gTeamStat
[KP
.Team
].Goals
,
3314 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3316 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3319 plr
:= g_Player_Get(SpawnerUID
);
3327 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3331 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3335 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3340 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3341 begin // Óáèò ìîíñòðîì
3342 mon
:= g_Monsters_ByUID(SpawnerUID
);
3346 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
3350 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3354 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3358 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3363 else // Îñîáûå òèïû ñìåðòè
3366 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3367 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3368 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3369 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3370 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3371 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3377 for a
:= WP_FIRST
to WP_LAST
do
3381 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3382 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3383 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3384 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3385 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3386 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3387 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3388 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3389 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3398 if R_ITEM_BACKPACK
in FRulez
then
3399 PushItem(ITEM_AMMO_BACKPACK
);
3401 // Âûáðîñ ðàêåòíîãî ðàíöà:
3402 if FJetFuel
> 0 then
3403 PushItem(ITEM_JETPACK
);
3406 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3408 if R_KEY_RED
in FRulez
then
3409 PushItem(ITEM_KEY_RED
);
3411 if R_KEY_GREEN
in FRulez
then
3412 PushItem(ITEM_KEY_GREEN
);
3414 if R_KEY_BLUE
in FRulez
then
3415 PushItem(ITEM_KEY_BLUE
);
3422 g_Player_CreateCorpse(Self
);
3424 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3425 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3431 for i
:= Low(gPlayers
) to High(gPlayers
) do
3433 if gPlayers
[i
] = nil then continue
;
3434 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3437 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3438 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3443 OldLR
:= gLMSRespawn
;
3444 if (gGameSettings
.GameMode
= GM_COOP
) then
3448 // everyone is dead, restart the map
3449 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3451 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3452 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3453 gLMSRespawnTime
:= gTime
+ 5000;
3455 else if (a
= 1) then
3457 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3458 if (gPlayers
[k
] = gPlayer1
) or
3459 (gPlayers
[k
] = gPlayer2
) then
3460 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3461 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3462 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3465 else if (gGameSettings
.GameMode
= GM_TDM
) then
3467 if (ab
= 0) and (ar
<> 0) then
3470 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3472 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3473 Inc(gTeamStat
[TEAM_RED
].Goals
);
3474 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3475 gLMSRespawnTime
:= gTime
+ 5000;
3477 else if (ar
= 0) and (ab
<> 0) then
3480 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3482 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3483 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3484 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3485 gLMSRespawnTime
:= gTime
+ 5000;
3487 else if (ar
= 0) and (ab
= 0) then
3490 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3492 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3493 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3494 gLMSRespawnTime
:= gTime
+ 5000;
3497 else if (gGameSettings
.GameMode
= GM_DM
) then
3501 if gPlayers
[k
] <> nil then
3504 // survivor is the winner
3505 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3507 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3510 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3511 gLMSRespawnTime
:= gTime
+ 5000;
3513 else if (a
= 0) then
3515 // everyone is dead, restart the map
3516 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3518 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3519 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3520 gLMSRespawnTime
:= gTime
+ 5000;
3523 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3525 if NetMode
= NET_SERVER
then
3526 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3528 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3534 MH_SEND_PlayerStats(FUID
);
3535 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3536 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3539 if srv
and FNoRespawn
then Spectate(True);
3540 FWantsInGame
:= True;
3543 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3545 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3546 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3549 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3551 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3552 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3555 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3557 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3558 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3559 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3560 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3561 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3562 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3563 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3564 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3567 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3569 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3570 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3571 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3572 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3575 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3577 if g_Game_IsClient
then Exit
;
3578 if Weapon
> High(FWeapon
) then Exit
;
3579 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3582 procedure TPlayer
.resetWeaponQueue ();
3585 FNextWeapDelay
:= 0;
3588 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3592 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3593 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
3594 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
3595 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3596 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3597 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3598 else result
:= (weapon
< length(FWeapon
));
3602 // return 255 for "no switch"
3603 function TPlayer
.getNextWeaponIndex (): Byte;
3606 wantThisWeapon
: array[0..64] of Boolean;
3607 weaponOrder
: array[0..16] of Integer; // value: index in `FWeapon`
3609 f
, dir
, cwi
, rwidx
, curlidx
: Integer;
3611 function real2log (ridx
: Integer): Integer;
3617 for f
:= 0 to High(weaponOrder
) do if (weaponOrder
[f
] = ridx
) then begin result
:= f
; exit
; end;
3623 result
:= 255; // default result: "no switch"
3625 // had weapon cycling on previous frame? remove that flag
3626 if (FNextWeap
and $2000) <> 0 then
3628 FNextWeap
:= FNextWeap
and $1FFF;
3629 FNextWeapDelay
:= 0;
3632 for f
:= 0 to High(weaponOrder
) do weaponOrder
[f
] := -1;
3634 // build weapon order (k8: i know, i know, learn how to do constants and such... gtfo, please!)
3635 // two knuckles are for "normal" and "berserk" (see `if` below -- it removes the one that is not needed)
3637 // bfg, launcher, plasma, flamethrower, ssg, minigun, sg, pistol, berserk, chainsaw, fist
3638 weaponOrder
[0] := WEAPON_SUPERPULEMET
;
3639 weaponOrder
[1] := WEAPON_BFG
;
3640 weaponOrder
[2] := WEAPON_ROCKETLAUNCHER
;
3641 weaponOrder
[3] := WEAPON_PLASMA
;
3642 weaponOrder
[4] := WEAPON_FLAMETHROWER
;
3643 weaponOrder
[5] := WEAPON_SHOTGUN2
;
3644 weaponOrder
[6] := WEAPON_CHAINGUN
;
3645 weaponOrder
[7] := WEAPON_SHOTGUN1
;
3646 weaponOrder
[8] := WEAPON_PISTOL
;
3647 weaponOrder
[9] := WEAPON_KASTET
+666; // berserk fist
3648 weaponOrder
[10] := WEAPON_SAW
;
3649 weaponOrder
[11] := WEAPON_KASTET
; // normal fist
3651 for f
:= 0 to High(weaponOrder
) do
3653 if (weaponOrder
[f
] = WEAPON_KASTET
) then
3655 // normal fist: remove if we have a berserk pack
3656 if (R_BERSERK
in FRulez
) then weaponOrder
[f
] := -1;
3659 if (weaponOrder
[f
] = WEAPON_KASTET
+666) then
3661 // berserk fist: remove if we don't have a berserk pack
3662 if (R_BERSERK
in FRulez
) then weaponOrder
[f
] := WEAPON_KASTET
else weaponOrder
[f
] := -1;
3670 WEAPON_SHOTGUN1 = 3;
3671 WEAPON_SHOTGUN2 = 4;
3672 WEAPON_CHAINGUN = 5;
3673 WEAPON_ROCKETLAUNCHER = 6;
3676 WEAPON_SUPERPULEMET = 9;
3677 WEAPON_FLAMETHROWER = 10;
3680 // cycling has priority
3681 if (FNextWeap
and $C000) <> 0 then
3683 if (FNextWeap
and $8000) <> 0 then dir
:= 1 else dir
:= -1; // should be reversed if we want "priority-driven cycling"
3684 FNextWeap
:= FNextWeap
or $2000; // we need this
3685 if FNextWeapDelay
> 0 then exit
; // cooldown time
3686 //cwi := real2log(FCurrWeap);
3687 //if (cwi < 0) then cwi := 0;
3689 for i
:= 0 to High(FWeapon
) do
3691 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3692 //rwidx := weaponOrder[cwi];
3693 rwidx
:= cwi
; // sorry
3694 if (rwidx
< 0) then continue
;
3695 if FWeapon
[rwidx
] then
3697 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d (dir=%d; log=%d)', [FCurrWeap, rwidx, dir, cwi]), TMsgType.Warning);
3698 result
:= Byte(rwidx
);
3699 //FNextWeapDelay := 10; //k8: not needed anymore
3708 for i
:= 0 to High(wantThisWeapon
) do wantThisWeapon
[i
] := false;
3710 for i
:= 0 to High(FWeapon
) do
3712 if (FNextWeap
and (1 shl i
)) <> 0 then
3715 if (cwi
>= 0) then wantThisWeapon
[cwi
] := true;
3720 // slow down alterations a little
3723 // more than one weapon requested, assume "alteration", and check alteration delay
3724 if FNextWeapDelay
> 0 then
3726 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), TMsgType.Warning);
3732 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3733 // but clear all counters if no weapon should be switched
3740 // exclude currently selected weapon from the set
3741 curlidx
:= real2log(FCurrWeap
);
3742 //e_WriteLog(Format('*** wwc=%d; currweap=%d; logweap=%d', [wwc, FCurrWeap, curlidx]), TMsgType.Warning);
3743 //e_WriteLog(Format('FCurrWeap=%d; curlidx=%d', [FCurrWeap, curlidx]), TMsgType.Warning);
3744 //if (curlidx >= 0) then wantThisWeapon[curlidx] := false;
3745 //if (wwc = 2) then begin Dec(wwc); end; // easy case: switch between two weapons
3747 // find next weapon to switch onto
3749 for i
:= 0 to High(weaponOrder
) do
3751 cwi
:= (cwi
+length(weaponOrder
)+1) mod length(weaponOrder
);
3752 if (cwi
= curlidx
) then continue
; // skip current weapon
3753 if not wantThisWeapon
[cwi
] then continue
;
3754 rwidx
:= weaponOrder
[cwi
];
3755 if (rwidx
< 0) then continue
;
3756 //e_WriteLog(Format(' trying logical %d (real %d); has=%d, hasammo=%d', [cwi, rwidx, Integer(FWeapon[rwidx]), Integer(hasAmmoForWeapon(rwidx))]), TMsgType.Warning);
3757 if FWeapon
[rwidx
] and ((wwc
= 1) or hasAmmoForWeapon(rwidx
)) then
3759 //e_WriteLog(' I FOUND HER!', TMsgType.Warning);
3761 result
:= Byte(rwidx
);
3763 //FNextWeapDelay := 10; // anyway, 'cause why not; k8: not needed anymore
3768 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3772 procedure TPlayer
.RealizeCurrentWeapon();
3773 function switchAllowed (): Boolean;
3778 if FBFGFireCounter
<> -1 then
3780 if FTime
[T_SWITCH
] > gTime
then
3782 for i
:= WP_FIRST
to WP_LAST
do
3783 if FReloading
[i
] > 0 then
3791 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3792 //FNextWeap := FNextWeap and $1FFF;
3793 //HACK: alteration delay will be reset when player released any weapon switch key
3794 FNextWeapDelay
:= 0; //k8: just in case
3795 //if FNextWeapDelay > 0 then Dec(FNextWeapDelay); // "alteration delay"
3797 if not switchAllowed
then
3799 //HACK for weapon cycling
3800 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3804 nw
:= getNextWeaponIndex();
3805 if nw
= 255 then exit
; // don't reset anything here
3806 if nw
> High(FWeapon
) then
3808 // don't forget to reset queue here!
3809 //e_WriteLog(Format(' RealizeCurrentWeapon: WUTAFUUUU?! (%d)', [nw]), TMsgType.Warning);
3817 FTime
[T_SWITCH
] := gTime
+156;
3818 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3819 FModel
.SetWeapon(FCurrWeap
);
3820 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3824 procedure TPlayer
.NextWeapon();
3826 if g_Game_IsClient
then Exit
;
3830 procedure TPlayer
.PrevWeapon();
3832 if g_Game_IsClient
then Exit
;
3836 procedure TPlayer
.SetWeapon(W
: Byte);
3838 if FCurrWeap
<> W
then
3839 if W
= WEAPON_SAW
then
3840 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3843 FModel
.SetWeapon(CurrWeap
);
3847 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3849 function allowBerserkSwitching (): Boolean;
3851 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3853 if gBerserkAutoswitch
then exit
;
3854 if not conIsCheatsEnabled
then exit
;
3862 if g_Game_IsClient
then Exit
;
3864 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3865 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3870 if FHealth
< PLAYER_HP_SOFT
then
3872 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3876 if gFlash
= 2 then Inc(FPickup
, 5);
3880 if FHealth
< PLAYER_HP_SOFT
then
3882 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3886 if gFlash
= 2 then Inc(FPickup
, 5);
3890 if FArmor
< PLAYER_AP_SOFT
then
3892 FArmor
:= PLAYER_AP_SOFT
;
3895 if gFlash
= 2 then Inc(FPickup
, 5);
3899 if FArmor
< PLAYER_AP_LIMIT
then
3901 FArmor
:= PLAYER_AP_LIMIT
;
3904 if gFlash
= 2 then Inc(FPickup
, 5);
3908 if FHealth
< PLAYER_HP_LIMIT
then
3910 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3914 if gFlash
= 2 then Inc(FPickup
, 5);
3918 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3920 if FHealth
< PLAYER_HP_LIMIT
then
3921 FHealth
:= PLAYER_HP_LIMIT
;
3922 if FArmor
< PLAYER_AP_LIMIT
then
3923 FArmor
:= PLAYER_AP_LIMIT
;
3927 if gFlash
= 2 then Inc(FPickup
, 5);
3931 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3933 FWeapon
[WEAPON_SAW
] := True;
3935 if gFlash
= 2 then Inc(FPickup
, 5);
3936 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3939 ITEM_WEAPON_SHOTGUN1
:
3940 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3942 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3943 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3945 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3946 FWeapon
[WEAPON_SHOTGUN1
] := True;
3948 if gFlash
= 2 then Inc(FPickup
, 5);
3949 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3952 ITEM_WEAPON_SHOTGUN2
:
3953 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3955 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3957 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3958 FWeapon
[WEAPON_SHOTGUN2
] := True;
3960 if gFlash
= 2 then Inc(FPickup
, 5);
3961 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3964 ITEM_WEAPON_CHAINGUN
:
3965 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3967 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3969 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3970 FWeapon
[WEAPON_CHAINGUN
] := True;
3972 if gFlash
= 2 then Inc(FPickup
, 5);
3973 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3976 ITEM_WEAPON_ROCKETLAUNCHER
:
3977 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3979 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3981 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3982 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3984 if gFlash
= 2 then Inc(FPickup
, 5);
3985 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3989 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3991 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3993 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3994 FWeapon
[WEAPON_PLASMA
] := True;
3996 if gFlash
= 2 then Inc(FPickup
, 5);
3997 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4001 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
4003 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
4005 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4006 FWeapon
[WEAPON_BFG
] := True;
4008 if gFlash
= 2 then Inc(FPickup
, 5);
4009 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4012 ITEM_WEAPON_SUPERPULEMET
:
4013 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
4015 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
4017 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4018 FWeapon
[WEAPON_SUPERPULEMET
] := True;
4020 if gFlash
= 2 then Inc(FPickup
, 5);
4021 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4024 ITEM_WEAPON_FLAMETHROWER
:
4025 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
4027 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
4029 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4030 FWeapon
[WEAPON_FLAMETHROWER
] := True;
4032 if gFlash
= 2 then Inc(FPickup
, 5);
4033 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4037 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4039 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4042 if gFlash
= 2 then Inc(FPickup
, 5);
4045 ITEM_AMMO_BULLETS_BOX
:
4046 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4048 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4051 if gFlash
= 2 then Inc(FPickup
, 5);
4055 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4057 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4060 if gFlash
= 2 then Inc(FPickup
, 5);
4063 ITEM_AMMO_SHELLS_BOX
:
4064 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4066 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
4069 if gFlash
= 2 then Inc(FPickup
, 5);
4073 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4075 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4078 if gFlash
= 2 then Inc(FPickup
, 5);
4081 ITEM_AMMO_ROCKET_BOX
:
4082 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4084 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
4087 if gFlash
= 2 then Inc(FPickup
, 5);
4091 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4093 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4096 if gFlash
= 2 then Inc(FPickup
, 5);
4100 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4102 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4105 if gFlash
= 2 then Inc(FPickup
, 5);
4109 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4111 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4114 if gFlash
= 2 then Inc(FPickup
, 5);
4118 if not(R_ITEM_BACKPACK
in FRulez
) or
4119 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4120 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4121 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4122 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4123 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
4125 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4126 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4127 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4128 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4129 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4131 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4132 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4133 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4134 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4135 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4136 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4137 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4138 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4140 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
4143 if gFlash
= 2 then Inc(FPickup
, 5);
4147 if not(R_KEY_RED
in FRulez
) then
4149 Include(FRulez
, R_KEY_RED
);
4151 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4152 if gFlash
= 2 then Inc(FPickup
, 5);
4153 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4157 if not(R_KEY_GREEN
in FRulez
) then
4159 Include(FRulez
, R_KEY_GREEN
);
4161 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4162 if gFlash
= 2 then Inc(FPickup
, 5);
4163 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4167 if not(R_KEY_BLUE
in FRulez
) then
4169 Include(FRulez
, R_KEY_BLUE
);
4171 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4172 if gFlash
= 2 then Inc(FPickup
, 5);
4173 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4177 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4179 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4183 if gFlash
= 2 then Inc(FPickup
, 5);
4187 if FAir
< AIR_MAX
then
4192 if gFlash
= 2 then Inc(FPickup
, 5);
4197 if not (R_BERSERK
in FRulez
) then
4199 Include(FRulez
, R_BERSERK
);
4200 if allowBerserkSwitching
then
4202 FCurrWeap
:= WEAPON_KASTET
;
4204 FModel
.SetWeapon(WEAPON_KASTET
);
4209 if gFlash
= 2 then Inc(FPickup
, 5);
4211 FBerserk
:= gTime
+30000;
4216 if FHealth
< PLAYER_HP_SOFT
then
4218 FHealth
:= PLAYER_HP_SOFT
;
4219 FBerserk
:= gTime
+30000;
4227 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4229 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4232 if gFlash
= 2 then Inc(FPickup
, 5);
4236 if FHealth
< PLAYER_HP_LIMIT
then
4238 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4242 if gFlash
= 2 then Inc(FPickup
, 5);
4246 if FArmor
< PLAYER_AP_LIMIT
then
4248 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4251 if gFlash
= 2 then Inc(FPickup
, 5);
4255 if FJetFuel
< JET_MAX
then
4257 FJetFuel
:= JET_MAX
;
4260 if gFlash
= 2 then Inc(FPickup
, 5);
4264 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4266 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4269 if gFlash
= 2 then Inc(FPickup
, 5);
4274 procedure TPlayer
.Touch();
4278 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4281 // Áðîñèòü ôëàã òîâàðèùó:
4282 if gGameSettings
.GameMode
= GM_CTF
then
4287 procedure TPlayer
.Push(vx
, vy
: Integer);
4289 if (not FPhysics
) and FGhost
then
4291 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4292 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4293 if g_Game_IsNet
and g_Game_IsServer
then
4294 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4297 procedure TPlayer
.Reset(Force
: Boolean);
4303 FTime
[T_RESPAWN
] := 0;
4304 FTime
[T_FLAGCAP
] := 0;
4317 FSpectator
:= False;
4320 FSpectatePlayer
:= -1;
4321 FNoRespawn
:= False;
4323 FLives
:= gGameSettings
.MaxLives
;
4328 procedure TPlayer
.SoftReset();
4334 FBFGFireCounter
:= -1;
4342 SetAction(A_STAND
, True);
4345 function TPlayer
.GetRespawnPoint(): Byte;
4350 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4352 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4353 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4355 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4357 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4358 if Self
= gPlayer1
then
4359 c
:= RESPAWNPOINT_PLAYER1
4361 c
:= RESPAWNPOINT_PLAYER2
;
4362 if g_Map_GetPointCount(c
) > 0 then
4368 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4369 if Self
= gPlayer1
then
4370 c
:= RESPAWNPOINT_PLAYER2
4372 c
:= RESPAWNPOINT_PLAYER1
;
4373 if g_Map_GetPointCount(c
) > 0 then
4380 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4381 if Random(2) = 0 then
4382 c
:= RESPAWNPOINT_PLAYER1
4384 c
:= RESPAWNPOINT_PLAYER2
;
4385 if g_Map_GetPointCount(c
) > 0 then
4392 // Òî÷êà ëþáîé èç êîìàíä
4393 if Random(2) = 0 then
4394 c
:= RESPAWNPOINT_RED
4396 c
:= RESPAWNPOINT_BLUE
;
4397 if g_Map_GetPointCount(c
) > 0 then
4404 c
:= RESPAWNPOINT_DM
;
4405 if g_Map_GetPointCount(c
) > 0 then
4413 if gGameSettings
.GameMode
= GM_DM
then
4416 c
:= RESPAWNPOINT_DM
;
4417 if g_Map_GetPointCount(c
) > 0 then
4423 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4424 if Random(2) = 0 then
4425 c
:= RESPAWNPOINT_PLAYER1
4427 c
:= RESPAWNPOINT_PLAYER2
;
4428 if g_Map_GetPointCount(c
) > 0 then
4434 // Òî÷êà ëþáîé èç êîìàíä
4435 if Random(2) = 0 then
4436 c
:= RESPAWNPOINT_RED
4438 c
:= RESPAWNPOINT_BLUE
;
4439 if g_Map_GetPointCount(c
) > 0 then
4447 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4449 // Òî÷êà ñâîåé êîìàíäû
4450 c
:= RESPAWNPOINT_DM
;
4451 if FTeam
= TEAM_RED
then
4452 c
:= RESPAWNPOINT_RED
;
4453 if FTeam
= TEAM_BLUE
then
4454 c
:= RESPAWNPOINT_BLUE
;
4455 if g_Map_GetPointCount(c
) > 0 then
4462 c
:= RESPAWNPOINT_DM
;
4463 if g_Map_GetPointCount(c
) > 0 then
4469 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4470 if Random(2) = 0 then
4471 c
:= RESPAWNPOINT_PLAYER1
4473 c
:= RESPAWNPOINT_PLAYER2
;
4474 if g_Map_GetPointCount(c
) > 0 then
4480 // Òî÷êà äðóãîé êîìàíäû
4481 c
:= RESPAWNPOINT_DM
;
4482 if FTeam
= TEAM_RED
then
4483 c
:= RESPAWNPOINT_BLUE
;
4484 if FTeam
= TEAM_BLUE
then
4485 c
:= RESPAWNPOINT_RED
;
4486 if g_Map_GetPointCount(c
) > 0 then
4494 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4496 RespawnPoint
: TRespawnPoint
;
4502 FBFGFireCounter
:= -1;
4507 if not g_Game_IsServer
then
4511 FWantsInGame
:= True;
4512 FJustTeleported
:= True;
4515 FTime
[T_RESPAWN
] := 0;
4519 // if server changes MaxLives we gotta be ready
4520 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4522 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4523 if FTime
[T_RESPAWN
] > gTime
then
4526 // Ïðîñðàë âñå æèçíè:
4529 if not FSpectator
then Spectate(True);
4530 FWantsInGame
:= True;
4534 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4535 begin // "Ñâîÿ èãðà"
4536 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4537 FRulez
:= FRulez
-[R_BERSERK
];
4539 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4541 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4542 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4545 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4546 c
:= GetRespawnPoint();
4551 // Âîñêðåøåíèå áåç îðóæèÿ:
4554 FHealth
:= PLAYER_HP_SOFT
;
4560 for a
:= WP_FIRST
to WP_LAST
do
4562 FWeapon
[a
] := False;
4566 FWeapon
[WEAPON_PISTOL
] := True;
4567 FWeapon
[WEAPON_KASTET
] := True;
4568 FCurrWeap
:= WEAPON_PISTOL
;
4571 FModel
.SetWeapon(FCurrWeap
);
4573 for b
:= A_BULLETS
to A_HIGH
do
4576 FAmmo
[A_BULLETS
] := 50;
4578 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4579 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4580 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4581 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4582 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4584 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4585 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4590 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4591 if not g_Map_GetPoint(c
, RespawnPoint
) then
4593 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4597 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4598 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4599 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4605 FDirection
:= RespawnPoint
.Direction
;
4606 if FDirection
= TDirection
.D_LEFT
then
4611 SetAction(A_STAND
, True);
4612 FModel
.Direction
:= FDirection
;
4614 for a
:= Low(FTime
) to High(FTime
) do
4617 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4622 FCanJetpack
:= False;
4627 // Àíèìàöèÿ âîçðîæäåíèÿ:
4628 if (not gLoadGameMode
) and (not Silent
) then
4629 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4631 Anim
:= TAnimation
.Create(ID
, False, 3);
4632 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4633 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4637 FSpectator
:= False;
4640 FSpectatePlayer
:= -1;
4643 if (gPlayer1
= nil) and (gLMSPID1
= FUID
) then
4645 if (gPlayer2
= nil) and (gLMSPID2
= FUID
) then
4648 if g_Game_IsNet
then
4650 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4651 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4653 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4654 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4659 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4662 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4663 else if (not NoMove
) then
4665 GameX
:= gMapInfo
.Width
div 2;
4666 GameY
:= gMapInfo
.Height
div 2;
4675 FWantsInGame
:= False;
4680 if Self
= gPlayer1
then
4685 if Self
= gPlayer2
then
4692 if g_Game_IsNet
then
4693 MH_SEND_PlayerStats(FUID
);
4696 procedure TPlayer
.SwitchNoClip
;
4700 FGhost
:= not FGhost
;
4701 FPhysics
:= not FGhost
;
4713 procedure TPlayer
.Run(Direction
: TDirection
);
4717 if MAX_RUNVEL
> 8 then
4721 if Direction
= TDirection
.D_LEFT
then
4723 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4724 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4727 if FObj
.Vel
.X
< MAX_RUNVEL
then
4728 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4730 // Âîçìîæíî, ïèíàåì êóñêè:
4731 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4733 b
:= Abs(FObj
.Vel
.X
);
4734 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4735 for a
:= 0 to High(gGibs
) do
4737 if gGibs
[a
].alive
and
4738 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4739 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4742 if FObj
.Vel
.X
< 0 then
4744 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4748 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4750 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4758 procedure TPlayer
.SeeDown();
4760 SetAction(A_SEEDOWN
);
4762 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4764 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4767 procedure TPlayer
.SeeUp();
4771 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4773 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4776 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4784 A_ATTACK
: Prior
:= 2;
4785 A_SEEUP
: Prior
:= 1;
4786 A_SEEDOWN
: Prior
:= 1;
4787 A_ATTACKUP
: Prior
:= 2;
4788 A_ATTACKDOWN
: Prior
:= 2;
4793 if (Prior
> FActionPrior
) or Force
then
4794 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4796 FActionPrior
:= Prior
;
4797 FActionAnim
:= Action
;
4798 FActionForce
:= Force
;
4799 FActionChanged
:= True;
4802 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4805 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4807 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4808 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4809 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4810 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4813 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4820 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4822 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4823 if g_Game_IsServer
and g_Game_IsNet
then
4824 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4828 FJustTeleported
:= True;
4833 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4835 Anim
:= TAnimation
.Create(ID
, False, 3);
4838 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4839 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4840 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4841 if g_Game_IsServer
and g_Game_IsNet
then
4842 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4843 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4847 FObj
.X
:= X
-PLAYER_RECT
.X
;
4848 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4849 if FAlive
and FGhost
then
4855 if not g_Game_IsNet
then
4859 SetDirection(TDirection
.D_LEFT
);
4865 SetDirection(TDirection
.D_RIGHT
);
4871 if FDirection
= TDirection
.D_RIGHT
then
4873 SetDirection(TDirection
.D_LEFT
);
4878 SetDirection(TDirection
.D_RIGHT
);
4884 if not silent
and (Anim
<> nil) then
4886 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4887 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4890 if g_Game_IsServer
and g_Game_IsNet
then
4891 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4892 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4899 function nonz(a
: Single): Single;
4907 function TPlayer
.followCorpse(): Boolean;
4912 if FAlive
or FSpectator
then
4914 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
4916 for i
:= 0 to High(gCorpses
) do
4917 if gCorpses
[i
] <> nil then
4918 if gCorpses
[i
].FPlayerUID
= FUID
then
4921 FObj
.X
:= gCorpses
[i
].FObj
.X
;
4922 FObj
.Y
:= gCorpses
[i
].FObj
.Y
;
4923 FObj
.Vel
.X
:= gCorpses
[i
].FObj
.Vel
.X
;
4924 FObj
.Vel
.Y
:= gCorpses
[i
].FObj
.Vel
.Y
;
4925 FObj
.Accel
.X
:= gCorpses
[i
].FObj
.Accel
.X
;
4926 FObj
.Accel
.Y
:= gCorpses
[i
].FObj
.Accel
.Y
;
4931 procedure TPlayer
.Update();
4934 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4935 blockmon
, headwater
, dospawn
: Boolean;
4940 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4941 AnyServer
:= g_Game_IsServer
;
4943 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4944 DoLerp(NetInterpLevel
+ 1)
4950 if FClientID
>= 0 then
4952 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4953 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4954 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4963 if FAlive
and (FPunchAnim
<> nil) then
4964 FPunchAnim
.Update();
4966 if FAlive
and (gFly
or FJetpack
) then
4969 if FDirection
= TDirection
.D_LEFT
then
4974 if FAlive
and (not FGhost
) then
4976 if FKeys
[KEY_UP
].Pressed
then
4978 if FKeys
[KEY_DOWN
].Pressed
then
4982 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4985 i
:= g_basic
.Sign(FIncCam
);
4986 FIncCam
:= Abs(FIncCam
);
4987 DecMin(FIncCam
, 5, 0);
4988 FIncCam
:= FIncCam
*i
;
4991 // no need to do that each second frame, weapon queue will take care of it
4992 if FAlive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4993 if FAlive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4995 if gTime
mod (GAME_TICK
*2) <> 0 then
4997 if (FObj
.Vel
.X
= 0) and FAlive
then
4999 if FKeys
[KEY_LEFT
].Pressed
then
5000 Run(TDirection
.D_LEFT
);
5001 if FKeys
[KEY_RIGHT
].Pressed
then
5002 Run(TDirection
.D_RIGHT
);
5007 if not followCorpse() then
5008 g_Obj_Move(@FObj
, True, True, True);
5009 positionChanged(); // this updates spatial accelerators
5015 FActionChanged
:= False;
5019 // Let alive player do some actions
5020 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
5021 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
5022 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
5023 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
5024 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
5025 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
5026 if FKeys
[KEY_JUMP
].Pressed
then Jump()
5029 if AnyServer
and FJetpack
then
5033 if NetServer
then MH_SEND_PlayerStats(FUID
);
5035 FCanJetpack
:= True;
5042 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
5044 if FKeys
[k
].Pressed
then
5052 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5055 if (FTime
[T_RESPAWN
] <= gTime
) and
5056 gGameOn
and (not FAlive
) then
5058 if (g_Player_GetCount() > 1) then
5062 gExit
:= EXIT_RESTART
;
5067 // Dead spectator actions
5070 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
5071 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
5075 if (FSpectatePlayer
>= High(gPlayers
)) then
5076 FSpectatePlayer
:= -1
5080 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
5081 if gPlayers
[I
] <> nil then
5082 if gPlayers
[I
].alive
then
5083 if gPlayers
[I
].UID
<> FUID
then
5085 FSpectatePlayer
:= I
;
5090 if not SetSpect
then FSpectatePlayer
:= -1;
5101 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5103 FYTo
:= FObj
.Y
- 32;
5104 FSpectatePlayer
:= -1;
5106 if FKeys
[KEY_DOWN
].Pressed
then
5108 FYTo
:= FObj
.Y
+ 32;
5109 FSpectatePlayer
:= -1;
5111 if FKeys
[KEY_LEFT
].Pressed
then
5113 FXTo
:= FObj
.X
- 32;
5114 FSpectatePlayer
:= -1;
5116 if FKeys
[KEY_RIGHT
].Pressed
then
5118 FXTo
:= FObj
.X
+ 32;
5119 FSpectatePlayer
:= -1;
5122 if (FXTo
< -64) then
5124 else if (FXTo
> gMapInfo
.Width
+ 32) then
5125 FXTo
:= gMapInfo
.Width
+ 32;
5126 if (FYTo
< -72) then
5128 else if (FYTo
> gMapInfo
.Height
+ 32) then
5129 FYTo
:= gMapInfo
.Height
+ 32;
5134 if not followCorpse() then
5135 g_Obj_Move(@FObj
, True, True, True);
5136 positionChanged(); // this updates spatial accelerators
5143 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5144 if gPlayers
[FSpectatePlayer
] <> nil then
5145 if gPlayers
[FSpectatePlayer
].alive
then
5147 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
5148 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
5152 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5153 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5154 PANEL_BLOCKMON
, True);
5155 headwater
:= HeadInLiquid(0, 0);
5157 // Ñîïðîòèâëåíèå âîçäóõà:
5158 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5159 if FObj
.Vel
.X
<> 0 then
5160 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5162 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5163 DecMin(FPain
, 5, 0);
5164 DecMin(FPickup
, 1, 0);
5166 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5168 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5169 FMegaRulez
[MR_SUIT
] := 0;
5170 FMegaRulez
[MR_INVUL
] := 0;
5171 FMegaRulez
[MR_INVIS
] := 0;
5172 Kill(K_FALLKILL
, 0, HIT_FALL
);
5179 if FCurrWeap
= WEAPON_SAW
then
5180 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5181 FSawSoundSelect
.IsPlaying()) then
5182 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5185 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5186 (not FJetSoundOff
.IsPlaying()) then
5188 FJetSoundFly
.SetPosition(0);
5189 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5192 for b
:= WP_FIRST
to WP_LAST
do
5193 if FReloading
[b
] > 0 then
5199 if FShellTimer
> -1 then
5200 if FShellTimer
= 0 then
5202 if FShellType
= SHELL_SHELL
then
5203 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5204 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5205 else if FShellType
= SHELL_DBLSHELL
then
5207 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5208 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5209 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5210 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5213 end else Dec(FShellTimer
);
5215 if (FBFGFireCounter
> -1) then
5216 if FBFGFireCounter
= 0 then
5220 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5221 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5222 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5223 yd
:= wy
+firediry();
5224 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5225 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5226 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5227 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5228 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5231 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5232 FBFGFireCounter
:= -1;
5235 FBFGFireCounter
:= 0
5237 Dec(FBFGFireCounter
);
5239 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5241 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5243 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5246 if (headwater
or blockmon
) then
5252 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5255 else if (FAir
mod 31 = 0) and not blockmon
then
5257 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5258 if Random(2) = 0 then
5259 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5261 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5263 end else if FAir
< AIR_DEF
then
5266 if FFireTime
> 0 then
5268 if BodyInLiquid(0, 0) then
5273 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5275 if FMegaRulez
[MR_SUIT
] = gTime
then
5282 if FFirePainTime
<= 0 then
5284 if g_Game_IsServer
then
5285 Damage(5, FFireAttacker
, 0, 0, HIT_FLAME
);
5286 FFirePainTime
:= 18;
5288 FFirePainTime
:= FFirePainTime
- 1;
5289 FFireTime
:= FFireTime
- 1;
5290 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5291 MH_SEND_PlayerStats(FUID
);
5295 if FDamageBuffer
> 0 then
5297 if FDamageBuffer
>= 9 then
5301 if FDamageBuffer
< 30 then i
:= 9
5302 else if FDamageBuffer
< 100 then i
:= 18
5306 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5307 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5308 FHealth
:= FHealth
-ii
;
5311 FHealth
:= FHealth
+FArmor
;
5316 if FHealth
<= 0 then
5317 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5318 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5319 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5323 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5324 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5325 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5326 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5333 end; // if FAlive then ...
5335 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5337 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5338 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5339 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5340 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5342 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5343 then SetAction(A_STAND
, True);
5345 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5347 for b
:= Low(FKeys
) to High(FKeys
) do
5348 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5352 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5354 x
:= FObj
.X
+PLAYER_RECT
.X
;
5355 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5356 w
:= PLAYER_RECT
.Width
;
5357 h
:= PLAYER_RECT
.Height
;
5361 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5363 if (dx
<> 0) or (dy
<> 0) then
5372 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5374 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5375 FObj
.Y
+PLAYER_RECT
.Y
,
5382 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5384 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5385 FObj
.Y
+PLAYER_RECT
.Y
,
5389 Panel
.Width
, Panel
.Height
);
5392 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5394 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5395 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5396 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5397 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5400 function g_Player_ValidName(Name
: string): Boolean;
5406 if gPlayers
= nil then Exit
;
5408 for a
:= 0 to High(gPlayers
) do
5409 if gPlayers
[a
] <> nil then
5410 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5417 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5421 d
:= FModel
.Direction
;
5423 FModel
.Direction
:= Direction
;
5424 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5426 FDirection
:= Direction
;
5429 function TPlayer
.GetKeys(): Byte;
5433 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5434 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5435 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5437 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5438 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5441 procedure TPlayer
.Use();
5445 if FTime
[T_USE
] > gTime
then Exit
;
5447 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5448 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5450 for a
:= 0 to High(gPlayers
) do
5451 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5452 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5453 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5454 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5456 gPlayers
[a
].Touch();
5457 if g_Game_IsNet
and g_Game_IsServer
then
5458 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5461 FTime
[T_USE
] := gTime
+120;
5464 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5468 WX
, WY
, XD
, YD
: Integer;
5480 if R_BERSERK
in FRulez
then
5482 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5483 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5484 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5487 locobj
.rect
.Width
:= 39;
5488 locobj
.rect
.Height
:= 52;
5489 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5490 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5491 locobj
.Accel
.X
:= xd
-wx
;
5492 locobj
.Accel
.y
:= yd
-wy
;
5494 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5495 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5497 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5501 FPain
:= min(FPain
+ 25, 50);
5503 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5508 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5509 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5511 FSawSoundSelect
.Stop();
5513 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5515 else if not FSawSoundHit
.IsPlaying() then
5517 FSawSoundSelect
.Stop();
5518 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5525 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5526 FFireAngle
:= FAngle
;
5528 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5529 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5534 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5535 FFireAngle
:= FAngle
;
5538 FShellType
:= SHELL_SHELL
;
5543 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5544 FFireAngle
:= FAngle
;
5547 FShellType
:= SHELL_DBLSHELL
;
5552 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5553 FFireAngle
:= FAngle
;
5555 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5556 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5559 WEAPON_ROCKETLAUNCHER
:
5561 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5562 FFireAngle
:= FAngle
;
5568 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5569 FFireAngle
:= FAngle
;
5575 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5576 FFireAngle
:= FAngle
;
5580 WEAPON_SUPERPULEMET
:
5582 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5583 FFireAngle
:= FAngle
;
5585 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5586 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5589 WEAPON_FLAMETHROWER
:
5591 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5592 FFireAngle
:= FAngle
;
5599 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5600 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5601 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5604 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5606 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5607 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5610 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5614 if NetInterpLevel
< 1 then
5624 AX
:= Abs(FXTo
- FObj
.X
);
5625 AY
:= Abs(FYTo
- FObj
.Y
);
5626 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5628 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5633 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5635 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5636 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5637 PANEL_LIFTUP
, False) then Result
:= -1
5639 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5640 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5641 PANEL_LIFTDOWN
, False) then Result
:= 1
5645 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5652 if Flag
= FLAG_NONE
then
5655 if not g_Game_IsServer
then Exit
;
5657 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5658 if (Flag
= FTeam
) and
5659 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5660 (FFlag
<> FLAG_NONE
) then
5662 if FFlag
= FLAG_RED
then
5663 s
:= _lc
[I_PLAYER_FLAG_RED
]
5665 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5667 evtype
:= FLAG_STATE_SCORED
;
5669 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5670 Insert('.', ts
, Length(ts
) + 1 - 3);
5671 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5673 g_Map_ResetFlag(FFlag
);
5674 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5676 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5679 if g_Game_IsNet
then
5681 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5685 gFlags
[FFlag
].CaptureTime
:= 0;
5690 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5691 if (Flag
= FTeam
) and
5692 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5694 if Flag
= FLAG_RED
then
5695 s
:= _lc
[I_PLAYER_FLAG_RED
]
5697 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5699 evtype
:= FLAG_STATE_RETURNED
;
5700 gFlags
[Flag
].CaptureTime
:= 0;
5702 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5704 g_Map_ResetFlag(Flag
);
5705 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5708 if g_Game_IsNet
then
5710 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5716 // Ïîäîáðàë ÷óæîé ôëàã:
5717 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5721 if Flag
= FLAG_RED
then
5722 s
:= _lc
[I_PLAYER_FLAG_RED
]
5724 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5726 evtype
:= FLAG_STATE_CAPTURED
;
5728 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5730 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5732 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5735 if g_Game_IsNet
then
5737 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5743 procedure TPlayer
.SetFlag(Flag
: Byte);
5746 if FModel
<> nil then
5747 FModel
.SetFlag(FFlag
);
5750 function TPlayer
.DropFlag(): Boolean;
5755 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5757 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5758 with gFlags
[FFlag
] do
5762 Direction
:= FDirection
;
5763 State
:= FLAG_STATE_DROPPED
;
5765 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5766 (FObj
.Vel
.Y
div 2)-2+Random(5));
5767 positionChanged(); // this updates spatial accelerators
5769 if FFlag
= FLAG_RED
then
5770 s
:= _lc
[I_PLAYER_FLAG_RED
]
5772 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5774 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5775 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5777 if g_Game_IsNet
then
5778 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5784 procedure TPlayer
.GetSecret();
5789 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5791 Assert(Key
<= High(FKeys
));
5793 FKeys
[Key
].Pressed
:= True;
5794 FKeys
[Key
].Time
:= Time
;
5797 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5799 Result
:= FKeys
[K
].Pressed
;
5802 procedure TPlayer
.ReleaseKeys();
5806 for a
:= Low(FKeys
) to High(FKeys
) do
5808 FKeys
[a
].Pressed
:= False;
5813 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5817 function TPlayer
.firediry(): Integer;
5819 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5820 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5824 procedure TPlayer
.RememberState();
5828 FSavedState
.Health
:= FHealth
;
5829 FSavedState
.Armor
:= FArmor
;
5830 FSavedState
.Air
:= FAir
;
5831 FSavedState
.JetFuel
:= FJetFuel
;
5832 FSavedState
.CurrWeap
:= FCurrWeap
;
5833 FSavedState
.NextWeap
:= FNextWeap
;
5834 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5837 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5839 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5841 FSavedState
.Rulez
:= FRulez
;
5842 FSavedState
.WaitRecall
:= True;
5845 procedure TPlayer
.RecallState();
5849 if not FSavedState
.WaitRecall
then Exit
;
5851 FHealth
:= FSavedState
.Health
;
5852 FArmor
:= FSavedState
.Armor
;
5853 FAir
:= FSavedState
.Air
;
5854 FJetFuel
:= FSavedState
.JetFuel
;
5855 FCurrWeap
:= FSavedState
.CurrWeap
;
5856 FNextWeap
:= FSavedState
.NextWeap
;
5857 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5860 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5862 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5864 FRulez
:= FSavedState
.Rulez
;
5865 FSavedState
.WaitRecall
:= False;
5867 if gGameSettings
.GameType
= GT_SERVER
then
5868 MH_SEND_PlayerStats(FUID
);
5871 procedure TPlayer
.SaveState (st
: TStream
);
5877 utils
.writeSign(st
, 'PLYR');
5878 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
5880 utils
.writeBool(st
, FIamBot
);
5882 utils
.writeInt(st
, Word(FUID
));
5884 utils
.writeStr(st
, FName
);
5886 utils
.writeInt(st
, Byte(FTeam
));
5888 utils
.writeBool(st
, FAlive
);
5889 // Èçðàñõîäîâàë ëè âñå æèçíè
5890 utils
.writeBool(st
, FNoRespawn
);
5892 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
5893 utils
.writeInt(st
, Byte(b
));
5895 utils
.writeInt(st
, LongInt(FHealth
));
5897 utils
.writeInt(st
, Byte(FLives
));
5899 utils
.writeInt(st
, LongInt(FArmor
));
5901 utils
.writeInt(st
, LongInt(FAir
));
5903 utils
.writeInt(st
, LongInt(FJetFuel
));
5905 utils
.writeInt(st
, LongInt(FPain
));
5907 utils
.writeInt(st
, LongInt(FKills
));
5909 utils
.writeInt(st
, LongInt(FMonsterKills
));
5911 utils
.writeInt(st
, LongInt(FFrags
));
5913 utils
.writeInt(st
, Byte(FFragCombo
));
5914 // Âðåìÿ ïîñëåäíåãî ôðàãà
5915 utils
.writeInt(st
, LongWord(FLastFrag
));
5917 utils
.writeInt(st
, LongInt(FDeath
));
5919 utils
.writeInt(st
, Byte(FFlag
));
5921 utils
.writeInt(st
, LongInt(FSecrets
));
5923 utils
.writeInt(st
, Byte(FCurrWeap
));
5925 utils
.writeInt(st
, Word(FNextWeap
));
5927 utils
.writeInt(st
, Byte(FNextWeapDelay
));
5928 // Âðåìÿ çàðÿäêè BFG
5929 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
5931 utils
.writeInt(st
, LongInt(FDamageBuffer
));
5932 // Ïîñëåäíèé óäàðèâøèé
5933 utils
.writeInt(st
, Word(FLastSpawnerUID
));
5934 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
5935 utils
.writeInt(st
, Byte(FLastHit
));
5937 Obj_SaveState(st
, @FObj
);
5938 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
5939 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
5940 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
5941 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
5943 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
5944 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
5945 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
5947 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
5948 // Íàëè÷èå êðàñíîãî êëþ÷à
5949 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
5950 // Íàëè÷èå çåëåíîãî êëþ÷à
5951 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
5952 // Íàëè÷èå ñèíåãî êëþ÷à
5953 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
5955 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
5956 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
5957 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
5958 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
5959 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
5961 utils
.writeStr(st
, FModel
.Name
);
5963 utils
.writeInt(st
, Byte(FColor
.R
));
5964 utils
.writeInt(st
, Byte(FColor
.G
));
5965 utils
.writeInt(st
, Byte(FColor
.B
));
5969 procedure TPlayer
.LoadState (st
: TStream
);
5978 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
5979 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
5981 FIamBot
:= utils
.readBool(st
);
5983 FUID
:= utils
.readWord(st
);
5985 str
:= utils
.readStr(st
);
5986 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
5988 FTeam
:= utils
.readByte(st
);
5990 FAlive
:= utils
.readBool(st
);
5991 // Èçðàñõîäîâàë ëè âñå æèçíè
5992 FNoRespawn
:= utils
.readBool(st
);
5994 b
:= utils
.readByte(st
);
5995 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
5997 FHealth
:= utils
.readLongInt(st
);
5999 FLives
:= utils
.readByte(st
);
6001 FArmor
:= utils
.readLongInt(st
);
6003 FAir
:= utils
.readLongInt(st
);
6005 FJetFuel
:= utils
.readLongInt(st
);
6007 FPain
:= utils
.readLongInt(st
);
6009 FKills
:= utils
.readLongInt(st
);
6011 FMonsterKills
:= utils
.readLongInt(st
);
6013 FFrags
:= utils
.readLongInt(st
);
6015 FFragCombo
:= utils
.readByte(st
);
6016 // Âðåìÿ ïîñëåäíåãî ôðàãà
6017 FLastFrag
:= utils
.readLongWord(st
);
6019 FDeath
:= utils
.readLongInt(st
);
6021 FFlag
:= utils
.readByte(st
);
6023 FSecrets
:= utils
.readLongInt(st
);
6025 FCurrWeap
:= utils
.readByte(st
);
6027 FNextWeap
:= utils
.readWord(st
);
6029 FNextWeapDelay
:= utils
.readByte(st
);
6030 // Âðåìÿ çàðÿäêè BFG
6031 FBFGFireCounter
:= utils
.readSmallInt(st
);
6033 FDamageBuffer
:= utils
.readLongInt(st
);
6034 // Ïîñëåäíèé óäàðèâøèé
6035 FLastSpawnerUID
:= utils
.readWord(st
);
6036 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6037 FLastHit
:= utils
.readByte(st
);
6039 Obj_LoadState(@FObj
, st
);
6040 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6041 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
6042 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6043 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
6045 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
6046 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6047 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
6049 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
6050 // Íàëè÷èå êðàñíîãî êëþ÷à
6051 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
6052 // Íàëè÷èå çåëåíîãî êëþ÷à
6053 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
6054 // Íàëè÷èå ñèíåãî êëþ÷à
6055 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
6057 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
6058 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6059 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
6060 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6061 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
6063 str
:= utils
.readStr(st
);
6065 FColor
.R
:= utils
.readByte(st
);
6066 FColor
.G
:= utils
.readByte(st
);
6067 FColor
.B
:= utils
.readByte(st
);
6068 if (self
= gPlayer1
) then
6070 str
:= gPlayer1Settings
.Model
;
6071 FColor
:= gPlayer1Settings
.Color
;
6073 else if (self
= gPlayer2
) then
6075 str
:= gPlayer2Settings
.Model
;
6076 FColor
:= gPlayer2Settings
.Color
;
6078 // Îáíîâëÿåì ìîäåëü èãðîêà
6080 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
6081 FModel
.Color
:= TEAMCOLOR
[FTeam
]
6083 FModel
.Color
:= FColor
;
6087 procedure TPlayer
.AllRulez(Health
: Boolean);
6093 FHealth
:= PLAYER_HP_LIMIT
;
6094 FArmor
:= PLAYER_AP_LIMIT
;
6098 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
6099 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
6100 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6103 procedure TPlayer
.RestoreHealthArmor();
6105 FHealth
:= PLAYER_HP_LIMIT
;
6106 FArmor
:= PLAYER_AP_LIMIT
;
6109 procedure TPlayer
.FragCombo();
6113 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6115 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6117 if FFragCombo
< 5 then
6119 Param
:= FUID
or (FFragCombo
shl 16);
6120 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6121 (FComboEvnt
<= High(gDelayedEvents
)) and
6122 gDelayedEvents
[FComboEvnt
].Pending
and
6123 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6124 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6126 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6127 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6130 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6138 procedure TPlayer
.GiveItem(ItemType
: Byte);
6142 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6144 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6148 if FAir
< AIR_MAX
then
6155 if not (R_BERSERK
in FRulez
) then
6157 Include(FRulez
, R_BERSERK
);
6158 if FBFGFireCounter
< 1 then
6160 FCurrWeap
:= WEAPON_KASTET
;
6162 FModel
.SetWeapon(WEAPON_KASTET
);
6166 FBerserk
:= gTime
+30000;
6168 if FHealth
< PLAYER_HP_SOFT
then
6170 FHealth
:= PLAYER_HP_SOFT
;
6171 FBerserk
:= gTime
+30000;
6176 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6178 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6182 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6184 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6188 if FJetFuel
< JET_MAX
then
6190 FJetFuel
:= JET_MAX
;
6193 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6194 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6196 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6197 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6199 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6201 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6203 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6204 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6207 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6208 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6209 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6210 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6211 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6212 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6213 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6214 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6215 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6217 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6218 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6219 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6220 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6221 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6222 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6223 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6224 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6225 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6228 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6229 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6230 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6231 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6232 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6234 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6235 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6236 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6237 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6238 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6240 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6241 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6242 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6243 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6245 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6248 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6249 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6250 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6252 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6253 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6258 if g_Game_IsNet
and g_Game_IsServer
then
6259 MH_SEND_PlayerStats(FUID
);
6262 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6267 if (Random(5) = 1) and (Times
= 1) then
6270 if BodyInLiquid(0, 0) then
6272 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6273 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6274 if Random(2) = 0 then
6275 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6277 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6281 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6283 for i
:= 1 to Times
do
6285 Anim
:= TAnimation
.Create(id
, False, 3);
6287 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6288 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6294 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6299 if (Random(10) = 1) and (Times
= 1) then
6302 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6304 for i
:= 1 to Times
do
6306 Anim
:= TAnimation
.Create(id
, False, 3);
6308 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6309 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6315 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6317 FSawSound
.Pause(Enable
);
6318 FSawSoundIdle
.Pause(Enable
);
6319 FSawSoundHit
.Pause(Enable
);
6320 FSawSoundSelect
.Pause(Enable
);
6325 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6330 FObj
.Rect
:= PLAYER_CORPSERECT
;
6331 FModelName
:= ModelName
;
6336 FState
:= CORPSE_STATE_MESS
;
6337 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6341 FState
:= CORPSE_STATE_NORMAL
;
6342 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6346 destructor TCorpse
.Destroy();
6353 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6355 procedure TCorpse
.positionChanged (); inline; begin end;
6357 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6359 if (dx
<> 0) or (dy
<> 0) then
6368 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6370 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6371 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6372 w
:= PLAYER_CORPSERECT
.Width
;
6373 h
:= PLAYER_CORPSERECT
.Height
;
6377 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6382 if FState
= CORPSE_STATE_REMOVEME
then
6385 FDamage
:= FDamage
+ Value
;
6387 if FDamage
> 150 then
6389 if FAnimation
<> nil then
6394 FState
:= CORPSE_STATE_REMOVEME
;
6396 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6397 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6398 FModelName
, FColor
);
6399 // Çâóê ìÿñà îò òðóïà:
6400 pm
:= g_PlayerModel_Get(FModelName
);
6401 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6405 if (gBodyKillEvent
<> -1)
6406 and gDelayedEvents
[gBodyKillEvent
].Pending
then
6407 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
6408 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, 0);
6413 Blood
:= g_PlayerModel_GetBlood(FModelName
);
6414 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6415 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6416 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6417 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6418 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6419 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
6423 procedure TCorpse
.Draw();
6425 if FState
= CORPSE_STATE_REMOVEME
then
6428 if FAnimation
<> nil then
6429 FAnimation
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6431 if FAnimationMask
<> nil then
6434 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6441 procedure TCorpse
.Update();
6445 if FState
= CORPSE_STATE_REMOVEME
then
6448 if gTime
mod (GAME_TICK
*2) <> 0 then
6450 g_Obj_Move(@FObj
, True, True, True);
6451 positionChanged(); // this updates spatial accelerators
6455 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6456 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6458 st
:= g_Obj_Move(@FObj
, True, True, True);
6459 positionChanged(); // this updates spatial accelerators
6461 if WordBool(st
and MOVE_FALLOUT
) then
6463 FState
:= CORPSE_STATE_REMOVEME
;
6467 if FAnimation
<> nil then
6468 FAnimation
.Update();
6469 if FAnimationMask
<> nil then
6470 FAnimationMask
.Update();
6474 procedure TCorpse
.SaveState (st
: TStream
);
6481 utils
.writeSign(st
, 'CORP');
6482 utils
.writeInt(st
, Byte(0));
6484 utils
.writeInt(st
, Byte(FState
));
6486 utils
.writeInt(st
, Byte(FDamage
));
6488 utils
.writeInt(st
, Byte(FColor
.R
));
6489 utils
.writeInt(st
, Byte(FColor
.G
));
6490 utils
.writeInt(st
, Byte(FColor
.B
));
6492 Obj_SaveState(st
, @FObj
);
6493 utils
.writeInt(st
, Word(FPlayerUID
));
6495 anim
:= (FAnimation
<> nil);
6496 utils
.writeBool(st
, anim
);
6497 // Åñëè åñòü - ñîõðàíÿåì
6498 if anim
then FAnimation
.SaveState(st
);
6499 // Åñòü ëè ìàñêà àíèìàöèè
6500 anim
:= (FAnimationMask
<> nil);
6501 utils
.writeBool(st
, anim
);
6502 // Åñëè åñòü - ñîõðàíÿåì
6503 if anim
then FAnimationMask
.SaveState(st
);
6507 procedure TCorpse
.LoadState (st
: TStream
);
6514 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6515 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6517 FState
:= utils
.readByte(st
);
6519 FDamage
:= utils
.readByte(st
);
6521 FColor
.R
:= utils
.readByte(st
);
6522 FColor
.G
:= utils
.readByte(st
);
6523 FColor
.B
:= utils
.readByte(st
);
6525 Obj_LoadState(@FObj
, st
);
6526 FPlayerUID
:= utils
.readWord(st
);
6528 anim
:= utils
.readBool(st
);
6529 // Åñëè åñòü - çàãðóæàåì
6532 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6533 FAnimation
.LoadState(st
);
6535 // Åñòü ëè ìàñêà àíèìàöèè
6536 anim
:= utils
.readBool(st
);
6537 // Åñëè åñòü - çàãðóæàåì
6540 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6541 FAnimationMask
.LoadState(st
);
6547 constructor TBot
.Create();
6554 FSpectator
:= False;
6561 for a
:= WP_FIRST
to WP_LAST
do
6563 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6564 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6565 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6569 destructor TBot
.Destroy();
6572 inherited Destroy();
6575 procedure TBot
.Draw();
6579 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6580 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6583 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6585 inherited Respawn(Silent
, Force
);
6588 FSelectedWeapon
:= FCurrWeap
;
6593 procedure TBot
.UpdateCombat();
6606 TTargetRecord
= array of TTarget
;
6608 function Compare(a
, b
: TTarget
): Integer;
6610 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6613 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6615 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6616 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6618 if a
.Dist
> b
.Dist
then // B áëèæå
6620 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6623 else // Ñòðàííî -> A
6628 a
, x1
, y1
, x2
, y2
: Integer;
6629 targets
: TTargetRecord
;
6631 Target
, BestTarget
: TTarget
;
6632 firew
, fireh
: Integer;
6636 vsPlayer
, vsMonster
, ok
: Boolean;
6639 function monsUpdate (mon
: TMonster
): Boolean;
6641 result
:= false; // don't stop
6642 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6644 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6646 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6647 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6649 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6650 if g_TraceVector(x1
, y1
, x2
, y2
) then
6652 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6653 SetLength(targets
, Length(targets
)+1);
6654 with targets
[High(targets
)] do
6661 Rect
:= mon
.Obj
.Rect
;
6662 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6663 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6664 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6673 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6674 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6676 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6677 if FCurrWeap
<> FSelectedWeapon
then
6680 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6681 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6683 RemoveAIFlag('NEEDFIRE');
6686 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6687 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6688 else PressKey(KEY_FIRE
);
6692 // Êîîðäèíàòû ñòâîëà:
6693 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6694 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6696 Target
.UID
:= FTargetUID
;
6699 if Target
.UID
<> 0 then
6700 begin // Öåëü åñòü - íàñòðàèâàåì
6701 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6704 tpla
:= g_Player_Get(Target
.UID
);
6708 if (@FObj
) <> nil then
6715 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6716 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6717 Target
.Rect
:= PLAYER_RECT
;
6718 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6719 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6720 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6721 Target
.IsPlayer
:= True;
6725 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6728 mon
:= g_Monsters_ByUID(Target
.UID
);
6731 Target
.X
:= mon
.Obj
.X
;
6732 Target
.Y
:= mon
.Obj
.Y
;
6734 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6735 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6736 Target
.Rect
:= mon
.Obj
.Rect
;
6737 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6738 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6739 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6740 Target
.IsPlayer
:= False;
6747 begin // Öåëè íåò - îáíóëÿåì
6752 Target
.Visible
:= False;
6753 Target
.Line
:= False;
6754 Target
.IsPlayer
:= False;
6759 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6760 if (not Target
.Line
) or (not Target
.Visible
) then
6764 for a
:= 0 to High(gPlayers
) do
6765 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6766 (gPlayers
[a
].FUID
<> FUID
) and
6767 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6768 (not gPlayers
[a
].NoTarget
) and
6769 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6771 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6772 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6775 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6776 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6778 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6779 if g_TraceVector(x1
, y1
, x2
, y2
) then
6781 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6782 SetLength(targets
, Length(targets
)+1);
6783 with targets
[High(targets
)] do
6785 UID
:= gPlayers
[a
].FUID
;
6786 X
:= gPlayers
[a
].FObj
.X
;
6787 Y
:= gPlayers
[a
].FObj
.Y
;
6790 Rect
:= PLAYER_RECT
;
6791 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6792 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6793 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6801 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6804 // Åñëè åñòü âîçìîæíûå öåëè:
6805 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6806 if targets
<> nil then
6808 // Âûáèðàåì íàèëó÷øóþ öåëü:
6809 BestTarget
:= targets
[0];
6810 if Length(targets
) > 1 then
6811 for a
:= 1 to High(targets
) do
6812 if Compare(BestTarget
, targets
[a
]) = 1 then
6813 BestTarget
:= targets
[a
];
6815 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6816 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6817 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6819 Target
:= BestTarget
;
6821 if (Healthy() = 3) or ((Healthy() = 2)) then
6822 begin // Åñëè çäîðîâû - äîãîíÿåì
6823 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6824 SetAIFlag('GORIGHT', '1');
6825 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6826 SetAIFlag('GOLEFT', '1');
6829 begin // Åñëè ïîáèòû - óáåãàåì
6830 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6831 SetAIFlag('GORIGHT', '1');
6832 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6833 SetAIFlag('GOLEFT', '1');
6836 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6837 SelectWeapon(Abs(x1
-Target
.cX
));
6842 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6843 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6844 if Target
.UID
<> 0 then
6846 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6847 Target
.Y
+ Target
.Rect
.Y
) then
6848 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6849 if (Healthy() = 3) or ((Healthy() = 2)) then
6850 begin // Åñëè çäîðîâû - äîãîíÿåì
6851 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6852 SetAIFlag('GORIGHT', '1');
6853 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6854 SetAIFlag('GOLEFT', '1');
6857 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6859 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6860 SetAIFlag('GORIGHT', '1');
6861 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6862 SetAIFlag('GOLEFT', '1');
6866 begin // Öåëü ïîêà íà "ýêðàíå"
6867 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6868 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6869 FLastVisible
:= gTime
;
6870 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6871 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6873 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6874 SetAIFlag('GORIGHT', '1');
6875 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6876 SetAIFlag('GOLEFT', '1');
6880 // Âûáèðàåì óãîë ââåðõ:
6881 if FDirection
= TDirection
.D_LEFT
then
6882 angle
:= ANGLE_LEFTUP
6884 angle
:= ANGLE_RIGHTUP
;
6886 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6887 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6889 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6890 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6891 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6892 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6893 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6894 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6895 begin // òî íóæíî ñòðåëÿòü ââåðõ
6896 SetAIFlag('NEEDFIRE', '1');
6897 SetAIFlag('NEEDSEEUP', '1');
6900 // Âûáèðàåì óãîë âíèç:
6901 if FDirection
= TDirection
.D_LEFT
then
6902 angle
:= ANGLE_LEFTDOWN
6904 angle
:= ANGLE_RIGHTDOWN
;
6906 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6907 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6909 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6910 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6911 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6912 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6913 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6914 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6915 begin // òî íóæíî ñòðåëÿòü âíèç
6916 SetAIFlag('NEEDFIRE', '1');
6917 SetAIFlag('NEEDSEEDOWN', '1');
6920 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6921 if Target
.Visible
and
6922 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6923 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6925 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6926 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
6927 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6928 begin // òî íóæíî ñòðåëÿòü âïåðåä
6929 SetAIFlag('NEEDFIRE', '1');
6930 SetAIFlag('NEEDSEEDOWN', '');
6931 SetAIFlag('NEEDSEEUP', '');
6933 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6934 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6935 if GetRnd(FDifficult
.CloseJump
) then
6936 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6937 if Abs(FObj
.X
-Target
.X
) < 128 then
6941 if Random(a
) = 0 then
6942 SetAIFlag('NEEDJUMP', '1');
6946 // Åñëè öåëü âñå åùå åñòü:
6947 if Target
.UID
<> 0 then
6948 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
6949 Target
.UID
:= 0 // òî çàáûòü öåëü
6950 else // Åñëè âèäåëè íåäàâíî
6951 begin // íî öåëü óáèëè
6952 if Target
.IsPlayer
then
6953 begin // Öåëü - èãðîê
6954 pla
:= g_Player_Get(Target
.UID
);
6955 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
6956 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6957 Target
.UID
:= 0; // òî çàáûòü öåëü
6960 begin // Öåëü - ìîíñòð
6961 mon
:= g_Monsters_ByUID(Target
.UID
);
6962 if (mon
= nil) or (not mon
.alive
) then
6963 Target
.UID
:= 0; // òî çàáûòü öåëü
6966 end; // if Target.UID <> 0
6968 FTargetUID
:= Target
.UID
;
6970 // Åñëè âîçìîæíûõ öåëåé íåò:
6971 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
6972 if targets
= nil then
6973 if GetAIFlag('ATTACKLEFT') <> '' then
6974 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
6975 RemoveAIFlag('ATTACKLEFT');
6977 SetAIFlag('NEEDJUMP', '1');
6979 if RunDirection() = TDirection
.D_RIGHT
then
6980 begin // Èäåì íå â òó ñòîðîíó
6981 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6982 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
6983 SetAIFlag('NEEDFIRE', '1');
6984 SetAIFlag('GOLEFT', '1');
6988 begin // Èäåì â íóæíóþ ñòîðîíó
6989 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6990 SetAIFlag('NEEDFIRE', '1');
6991 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6992 SetAIFlag('GORIGHT', '1');
6996 if GetAIFlag('ATTACKRIGHT') <> '' then
6997 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
6998 RemoveAIFlag('ATTACKRIGHT');
7000 SetAIFlag('NEEDJUMP', '1');
7002 if RunDirection() = TDirection
.D_LEFT
then
7003 begin // Èäåì íå â òó ñòîðîíó
7004 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7005 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
7006 SetAIFlag('NEEDFIRE', '1');
7007 SetAIFlag('GORIGHT', '1');
7012 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7013 SetAIFlag('NEEDFIRE', '1');
7014 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7015 SetAIFlag('GOLEFT', '1');
7019 //HACK! (does it belongs there?)
7020 RealizeCurrentWeapon();
7022 // Åñëè åñòü âîçìîæíûå öåëè:
7023 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7024 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7025 for a
:= 0 to High(targets
) do
7027 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7028 if GetRnd(FDifficult
.DiagFire
) then
7030 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7031 if FDirection
= TDirection
.D_LEFT
then
7032 angle
:= ANGLE_LEFTUP
7034 angle
:= ANGLE_RIGHTUP
;
7036 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7037 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7039 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7040 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7041 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7042 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7043 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7045 SetAIFlag('NEEDFIRE', '1');
7046 SetAIFlag('NEEDSEEUP', '1');
7049 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7050 if FDirection
= TDirection
.D_LEFT
then
7051 angle
:= ANGLE_LEFTDOWN
7053 angle
:= ANGLE_RIGHTDOWN
;
7055 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7056 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7058 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7059 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7060 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7061 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7062 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7064 SetAIFlag('NEEDFIRE', '1');
7065 SetAIFlag('NEEDSEEDOWN', '1');
7069 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7070 if targets
[a
].Line
and targets
[a
].Visible
and
7071 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
7072 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
7074 SetAIFlag('NEEDFIRE', '1');
7079 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7080 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
7081 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
7082 40+GetInterval(FDifficult
.Cover
, 40)) then
7083 SetAIFlag('NEEDJUMP', '1');
7085 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7086 ammo
:= GetAmmoByWeapon(FCurrWeap
);
7087 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
7088 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
7090 SetAIFlag('SELECTWEAPON', '1');
7092 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7093 if GetAIFlag('SELECTWEAPON') = '1' then
7096 RemoveAIFlag('SELECTWEAPON');
7100 procedure TBot
.Update();
7113 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7114 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7116 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7118 if g_debug_BotAIOff
= 3 then
7128 RealizeCurrentWeapon();
7135 procedure TBot
.ReleaseKey(Key
: Byte);
7144 function TBot
.KeyPressed(Key
: Word): Boolean;
7146 Result
:= FKeys
[Key
].Pressed
;
7149 function TBot
.GetAIFlag(aName
: String20
): String20
;
7155 aName
:= LowerCase(aName
);
7157 if FAIFlags
<> nil then
7158 for a
:= 0 to High(FAIFlags
) do
7159 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7161 Result
:= FAIFlags
[a
].Value
;
7166 procedure TBot
.RemoveAIFlag(aName
: String20
);
7170 if FAIFlags
= nil then Exit
;
7172 aName
:= LowerCase(aName
);
7174 for a
:= 0 to High(FAIFlags
) do
7175 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7177 if a
<> High(FAIFlags
) then
7178 for b
:= a
to High(FAIFlags
)-1 do
7179 FAIFlags
[b
] := FAIFlags
[b
+1];
7181 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7186 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7194 aName
:= LowerCase(aName
);
7196 if FAIFlags
<> nil then
7197 for a
:= 0 to High(FAIFlags
) do
7198 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7204 if ok
then FAIFlags
[a
].Value
:= fValue
7207 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7208 with FAIFlags
[High(FAIFlags
)] do
7216 procedure TBot
.UpdateMove
;
7218 procedure GoLeft(Time
: Word = 1);
7220 ReleaseKey(KEY_LEFT
);
7221 ReleaseKey(KEY_RIGHT
);
7222 PressKey(KEY_LEFT
, Time
);
7223 SetDirection(TDirection
.D_LEFT
);
7226 procedure GoRight(Time
: Word = 1);
7228 ReleaseKey(KEY_LEFT
);
7229 ReleaseKey(KEY_RIGHT
);
7230 PressKey(KEY_RIGHT
, Time
);
7231 SetDirection(TDirection
.D_RIGHT
);
7234 function Rnd(a
: Word): Boolean;
7236 Result
:= Random(a
) = 0;
7239 procedure Turn(Time
: Word = 1200);
7241 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7246 ReleaseKey(KEY_LEFT
);
7247 ReleaseKey(KEY_RIGHT
);
7250 function CanRunLeft(): Boolean;
7252 Result
:= not CollideLevel(-1, 0);
7255 function CanRunRight(): Boolean;
7257 Result
:= not CollideLevel(1, 0);
7260 function CanRun(): Boolean;
7262 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7265 procedure Jump(Time
: Word = 30);
7267 PressKey(KEY_JUMP
, Time
);
7270 function NearHole(): Boolean;
7274 { TODO 5 : Ëåñòíèöû }
7275 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7276 for x
:= 1 to PLAYER_RECT
.Width
do
7277 if (not StayOnStep(x
*sx
, 0)) and
7278 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7279 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7288 function BorderHole(): Boolean;
7292 { TODO 5 : Ëåñòíèöû }
7293 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7294 for x
:= 1 to PLAYER_RECT
.Width
do
7295 if (not StayOnStep(x
*sx
, 0)) and
7296 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7297 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7299 for xx
:= x
to x
+32 do
7300 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7310 function NearDeepHole(): Boolean;
7316 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7319 for x
:= 1 to PLAYER_RECT
.Width
do
7320 if (not StayOnStep(x
*sx
, 0)) and
7321 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7322 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7324 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7326 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7331 end else Result
:= False;
7334 function OverDeepHole(): Boolean;
7341 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7343 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7350 function OnGround(): Boolean;
7352 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7355 function OnLadder(): Boolean;
7357 Result
:= FullInStep(0, 0);
7360 function BelowLadder(): Boolean;
7362 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7363 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7364 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7365 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7368 function BelowLiftUp(): Boolean;
7370 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7371 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7372 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7373 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7376 function OnTopLift(): Boolean;
7378 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7381 function CanJumpOver(): Boolean;
7385 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7389 if not CollideLevel(sx
, 0) then Exit
;
7391 for y
:= 1 to BOT_MAXJUMP
do
7392 if CollideLevel(0, -y
) then Exit
else
7393 if not CollideLevel(sx
, -y
) then
7400 function CanJumpUp(Dist
: ShortInt): Boolean;
7407 if CollideLevel(Dist
, 0) then Exit
;
7410 for y
:= 0 to BOT_MAXJUMP
do
7411 if CollideLevel(Dist
, -y
) then
7420 for yy
:= y
+1 to BOT_MAXJUMP
do
7421 if not CollideLevel(Dist
, -yy
) then
7430 for y
:= 0 to BOT_MAXJUMP
do
7431 if CollideLevel(0, -y
) then
7439 if y
< yy
then Exit
;
7444 function IsSafeTrigger(): Boolean;
7449 if gTriggers
= nil then
7451 for a
:= 0 to High(gTriggers
) do
7452 if Collide(gTriggers
[a
].X
,
7455 gTriggers
[a
].Height
) and
7456 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7457 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7458 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7459 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7460 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7465 // Âîçìîæíî, íàæèìàåì êíîïêó:
7466 if Rnd(16) and IsSafeTrigger() then
7469 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7470 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7472 ReleaseKey(KEY_LEFT
);
7473 ReleaseKey(KEY_RIGHT
);
7477 // Èäåì âëåâî, åñëè íàäî áûëî:
7478 if GetAIFlag('GOLEFT') <> '' then
7480 RemoveAIFlag('GOLEFT');
7481 if CanRunLeft() then
7485 // Èäåì âïðàâî, åñëè íàäî áûëî:
7486 if GetAIFlag('GORIGHT') <> '' then
7488 RemoveAIFlag('GORIGHT');
7489 if CanRunRight() then
7493 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7494 if FObj
.X
< -32 then
7497 if FObj
.X
+32 > gMapInfo
.Width
then
7500 // Ïðûãàåì, åñëè íàäî áûëî:
7501 if GetAIFlag('NEEDJUMP') <> '' then
7504 RemoveAIFlag('NEEDJUMP');
7507 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7508 if GetAIFlag('NEEDSEEUP') <> '' then
7511 ReleaseKey(KEY_DOWN
);
7512 PressKey(KEY_UP
, 20);
7513 RemoveAIFlag('NEEDSEEUP');
7516 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7517 if GetAIFlag('NEEDSEEDOWN') <> '' then
7520 ReleaseKey(KEY_DOWN
);
7521 PressKey(KEY_DOWN
, 20);
7522 RemoveAIFlag('NEEDSEEDOWN');
7525 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7526 if GetAIFlag('GOINHOLE') <> '' then
7527 if not OnGround() then
7529 ReleaseKey(KEY_LEFT
);
7530 ReleaseKey(KEY_RIGHT
);
7531 RemoveAIFlag('GOINHOLE');
7532 SetAIFlag('FALLINHOLE', '1');
7535 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7536 if GetAIFlag('FALLINHOLE') <> '' then
7538 RemoveAIFlag('FALLINHOLE');
7540 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7541 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7542 if GetAIFlag('FALLINHOLE') = '' then
7543 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7549 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7551 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7555 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7556 if OnGround() and NearHole() then
7557 if NearDeepHole() then // Åñëè ýòî áåçäíà
7559 0..3: Turn(); // Áåæèì îáðàòíî
7560 4: Jump(); // Ïðûãàåì
7561 5: begin // Ïðûãàåì îáðàòíî
7566 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7567 if GetAIFlag('GOINHOLE') = '' then
7569 0: Turn(); // Íå íóæíî òóäà
7570 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7571 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7572 if BorderHole() then
7573 SetAIFlag('GOINHOLE', '1');
7576 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7577 if (not CanRun()) and OnGround() then
7579 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7580 if CanJumpOver() or OnLadder() then
7582 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7583 if Random(2) = 0 then
7585 if IsSafeTrigger() then
7591 // Îñòàëîñü ìàëî âîçäóõà:
7592 if FAir
< 36 * 2 then
7595 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7596 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7597 if BodyInAcid(0, 0) then
7601 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7603 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7604 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7607 {function TBot.NeedItem(Item: Byte): Byte;
7612 procedure TBot
.SelectWeapon(Dist
: Integer);
7616 function HaveAmmo(weapon
: Byte): Boolean;
7619 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7620 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7621 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7622 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7623 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7624 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7625 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7626 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7627 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7628 else Result
:= True;
7633 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7635 if Dist
> BOT_LONGDIST
then
7636 begin // Äàëüíèé áîé
7638 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7640 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7644 else //if Dist > BOT_UNSAFEDIST then
7645 begin // Áëèæíèé áîé
7647 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7649 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7656 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7658 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7664 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7666 Result
:= inherited PickItem(ItemType
, force
, remove
);
7668 if Result
then SetAIFlag('SELECTWEAPON', '1');
7671 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7673 Result
:= inherited Heal(value
, Soft
);
7676 function TBot
.Healthy(): Byte;
7678 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7679 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7680 else if (FHealth
> 50) then Result
:= 2
7681 else if (FHealth
> 20) then Result
:= 1
7685 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7687 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7688 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7691 procedure TBot
.OnDamage(Angle
: SmallInt);
7699 if (Angle
= 0) or (Angle
= 180) then
7702 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7703 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7705 pla
:= g_Player_Get(FLastSpawnerUID
);
7706 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7707 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7710 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7711 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7713 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7714 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7715 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7720 SetAIFlag('ATTACKLEFT', '1')
7722 SetAIFlag('ATTACKRIGHT', '1');
7726 function TBot
.RunDirection(): TDirection
;
7728 if Abs(Vel
.X
) >= 1 then
7730 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7732 Result
:= FDirection
;
7735 function TBot
.GetRnd(a
: Byte): Boolean;
7737 if a
= 0 then Result
:= False
7738 else if a
= 255 then Result
:= True
7739 else Result
:= Random(256) > 255-a
;
7742 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7744 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7748 procedure TDifficult
.save (st
: TStream
);
7750 utils
.writeInt(st
, Byte(DiagFire
));
7751 utils
.writeInt(st
, Byte(InvisFire
));
7752 utils
.writeInt(st
, Byte(DiagPrecision
));
7753 utils
.writeInt(st
, Byte(FlyPrecision
));
7754 utils
.writeInt(st
, Byte(Cover
));
7755 utils
.writeInt(st
, Byte(CloseJump
));
7756 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7757 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7760 procedure TDifficult
.load (st
: TStream
);
7762 DiagFire
:= utils
.readByte(st
);
7763 InvisFire
:= utils
.readByte(st
);
7764 DiagPrecision
:= utils
.readByte(st
);
7765 FlyPrecision
:= utils
.readByte(st
);
7766 Cover
:= utils
.readByte(st
);
7767 CloseJump
:= utils
.readByte(st
);
7768 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7769 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7773 procedure TBot
.SaveState (st
: TStream
);
7778 inherited SaveState(st
);
7779 utils
.writeSign(st
, 'BOT0');
7781 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7783 utils
.writeInt(st
, Word(FTargetUID
));
7784 // Âðåìÿ ïîòåðè öåëè
7785 utils
.writeInt(st
, LongWord(FLastVisible
));
7786 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7787 dw
:= Length(FAIFlags
);
7788 utils
.writeInt(st
, LongInt(dw
));
7790 for i
:= 0 to dw
-1 do
7792 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7793 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7795 // Íàñòðîéêè ñëîæíîñòè
7796 FDifficult
.save(st
);
7800 procedure TBot
.LoadState (st
: TStream
);
7805 inherited LoadState(st
);
7806 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7808 FSelectedWeapon
:= utils
.readByte(st
);
7810 FTargetUID
:= utils
.readWord(st
);
7811 // Âðåìÿ ïîòåðè öåëè
7812 FLastVisible
:= utils
.readLongWord(st
);
7813 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7814 dw
:= utils
.readLongInt(st
);
7815 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7816 SetLength(FAIFlags
, dw
);
7818 for i
:= 0 to dw
-1 do
7820 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7821 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7823 // Íàñòðîéêè ñëîæíîñòè
7824 FDifficult
.load(st
);
7829 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);