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;
3711 curlidx
:= -1; // start from a weapon with a highest priority (-1, 'cause loop will immediately increment this index)
3713 for i
:= 0 to High(FWeapon
) do
3715 if (FNextWeap
and (1 shl i
)) <> 0 then
3720 wantThisWeapon
[cwi
] := true;
3722 // if we hit currently selected weapon, start seachring from it, so we'll get "next weaker" weapon
3723 if (i
= FCurrWeap
) then curlidx
:= cwi
; // compare real, start from logical
3728 // slow down alterations a little
3731 // more than one weapon requested, assume "alteration", and check alteration delay
3732 if FNextWeapDelay
> 0 then
3734 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), TMsgType.Warning);
3740 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3741 // but clear all counters if no weapon should be switched
3748 //e_WriteLog(Format('*** wwc=%d; currweap=%d; logweap=%d', [wwc, FCurrWeap, curlidx]), TMsgType.Warning);
3750 // find next weapon to switch onto
3752 for i
:= 0 to High(weaponOrder
) do
3754 cwi
:= (cwi
+length(weaponOrder
)+1) mod length(weaponOrder
);
3755 if (cwi
= curlidx
) then continue
; // skip current weapon
3756 if not wantThisWeapon
[cwi
] then continue
;
3757 rwidx
:= weaponOrder
[cwi
];
3758 if (rwidx
< 0) then continue
;
3759 //e_WriteLog(Format(' trying logical %d (real %d); has=%d, hasammo=%d', [cwi, rwidx, Integer(FWeapon[rwidx]), Integer(hasAmmoForWeapon(rwidx))]), TMsgType.Warning);
3760 if FWeapon
[rwidx
] and ((wwc
= 1) or hasAmmoForWeapon(rwidx
)) then
3762 //e_WriteLog(' I FOUND HER!', TMsgType.Warning);
3764 result
:= Byte(rwidx
);
3766 //FNextWeapDelay := 10; // anyway, 'cause why not; k8: not needed anymore
3771 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3775 procedure TPlayer
.RealizeCurrentWeapon();
3776 function switchAllowed (): Boolean;
3781 if FBFGFireCounter
<> -1 then
3783 if FTime
[T_SWITCH
] > gTime
then
3785 for i
:= WP_FIRST
to WP_LAST
do
3786 if FReloading
[i
] > 0 then
3794 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3795 //FNextWeap := FNextWeap and $1FFF;
3796 //HACK: alteration delay will be reset when player released any weapon switch key
3797 FNextWeapDelay
:= 0; //k8: just in case
3798 //if FNextWeapDelay > 0 then Dec(FNextWeapDelay); // "alteration delay"
3800 if not switchAllowed
then
3802 //HACK for weapon cycling
3803 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3807 nw
:= getNextWeaponIndex();
3808 if nw
= 255 then exit
; // don't reset anything here
3809 if nw
> High(FWeapon
) then
3811 // don't forget to reset queue here!
3812 //e_WriteLog(Format(' RealizeCurrentWeapon: WUTAFUUUU?! (%d)', [nw]), TMsgType.Warning);
3820 FTime
[T_SWITCH
] := gTime
+156;
3821 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3822 FModel
.SetWeapon(FCurrWeap
);
3823 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3827 procedure TPlayer
.NextWeapon();
3829 if g_Game_IsClient
then Exit
;
3833 procedure TPlayer
.PrevWeapon();
3835 if g_Game_IsClient
then Exit
;
3839 procedure TPlayer
.SetWeapon(W
: Byte);
3841 if FCurrWeap
<> W
then
3842 if W
= WEAPON_SAW
then
3843 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3846 FModel
.SetWeapon(CurrWeap
);
3850 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3852 function allowBerserkSwitching (): Boolean;
3854 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3856 if gBerserkAutoswitch
then exit
;
3857 if not conIsCheatsEnabled
then exit
;
3865 if g_Game_IsClient
then Exit
;
3867 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3868 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3873 if FHealth
< PLAYER_HP_SOFT
then
3875 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3879 if gFlash
= 2 then Inc(FPickup
, 5);
3883 if FHealth
< PLAYER_HP_SOFT
then
3885 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3889 if gFlash
= 2 then Inc(FPickup
, 5);
3893 if FArmor
< PLAYER_AP_SOFT
then
3895 FArmor
:= PLAYER_AP_SOFT
;
3898 if gFlash
= 2 then Inc(FPickup
, 5);
3902 if FArmor
< PLAYER_AP_LIMIT
then
3904 FArmor
:= PLAYER_AP_LIMIT
;
3907 if gFlash
= 2 then Inc(FPickup
, 5);
3911 if FHealth
< PLAYER_HP_LIMIT
then
3913 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3917 if gFlash
= 2 then Inc(FPickup
, 5);
3921 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3923 if FHealth
< PLAYER_HP_LIMIT
then
3924 FHealth
:= PLAYER_HP_LIMIT
;
3925 if FArmor
< PLAYER_AP_LIMIT
then
3926 FArmor
:= PLAYER_AP_LIMIT
;
3930 if gFlash
= 2 then Inc(FPickup
, 5);
3934 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3936 FWeapon
[WEAPON_SAW
] := True;
3938 if gFlash
= 2 then Inc(FPickup
, 5);
3939 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3942 ITEM_WEAPON_SHOTGUN1
:
3943 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3945 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3946 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3948 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3949 FWeapon
[WEAPON_SHOTGUN1
] := True;
3951 if gFlash
= 2 then Inc(FPickup
, 5);
3952 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3955 ITEM_WEAPON_SHOTGUN2
:
3956 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3958 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3960 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3961 FWeapon
[WEAPON_SHOTGUN2
] := True;
3963 if gFlash
= 2 then Inc(FPickup
, 5);
3964 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3967 ITEM_WEAPON_CHAINGUN
:
3968 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3970 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3972 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3973 FWeapon
[WEAPON_CHAINGUN
] := True;
3975 if gFlash
= 2 then Inc(FPickup
, 5);
3976 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3979 ITEM_WEAPON_ROCKETLAUNCHER
:
3980 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3982 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3984 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3985 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3987 if gFlash
= 2 then Inc(FPickup
, 5);
3988 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3992 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3994 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3996 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3997 FWeapon
[WEAPON_PLASMA
] := True;
3999 if gFlash
= 2 then Inc(FPickup
, 5);
4000 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4004 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
4006 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
4008 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4009 FWeapon
[WEAPON_BFG
] := True;
4011 if gFlash
= 2 then Inc(FPickup
, 5);
4012 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4015 ITEM_WEAPON_SUPERPULEMET
:
4016 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
4018 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
4020 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4021 FWeapon
[WEAPON_SUPERPULEMET
] := True;
4023 if gFlash
= 2 then Inc(FPickup
, 5);
4024 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4027 ITEM_WEAPON_FLAMETHROWER
:
4028 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
4030 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
4032 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4033 FWeapon
[WEAPON_FLAMETHROWER
] := True;
4035 if gFlash
= 2 then Inc(FPickup
, 5);
4036 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4040 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4042 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4045 if gFlash
= 2 then Inc(FPickup
, 5);
4048 ITEM_AMMO_BULLETS_BOX
:
4049 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4051 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4054 if gFlash
= 2 then Inc(FPickup
, 5);
4058 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4060 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4063 if gFlash
= 2 then Inc(FPickup
, 5);
4066 ITEM_AMMO_SHELLS_BOX
:
4067 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4069 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
4072 if gFlash
= 2 then Inc(FPickup
, 5);
4076 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4078 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4081 if gFlash
= 2 then Inc(FPickup
, 5);
4084 ITEM_AMMO_ROCKET_BOX
:
4085 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4087 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
4090 if gFlash
= 2 then Inc(FPickup
, 5);
4094 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4096 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4099 if gFlash
= 2 then Inc(FPickup
, 5);
4103 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4105 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4108 if gFlash
= 2 then Inc(FPickup
, 5);
4112 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4114 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4117 if gFlash
= 2 then Inc(FPickup
, 5);
4121 if not(R_ITEM_BACKPACK
in FRulez
) or
4122 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4123 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4124 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4125 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4126 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
4128 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4129 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4130 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4131 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4132 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4134 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4135 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4136 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4137 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4138 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4139 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4140 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4141 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4143 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
4146 if gFlash
= 2 then Inc(FPickup
, 5);
4150 if not(R_KEY_RED
in FRulez
) then
4152 Include(FRulez
, R_KEY_RED
);
4154 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4155 if gFlash
= 2 then Inc(FPickup
, 5);
4156 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4160 if not(R_KEY_GREEN
in FRulez
) then
4162 Include(FRulez
, R_KEY_GREEN
);
4164 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4165 if gFlash
= 2 then Inc(FPickup
, 5);
4166 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4170 if not(R_KEY_BLUE
in FRulez
) then
4172 Include(FRulez
, R_KEY_BLUE
);
4174 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4175 if gFlash
= 2 then Inc(FPickup
, 5);
4176 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4180 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4182 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4186 if gFlash
= 2 then Inc(FPickup
, 5);
4190 if FAir
< AIR_MAX
then
4195 if gFlash
= 2 then Inc(FPickup
, 5);
4200 if not (R_BERSERK
in FRulez
) then
4202 Include(FRulez
, R_BERSERK
);
4203 if allowBerserkSwitching
then
4205 FCurrWeap
:= WEAPON_KASTET
;
4207 FModel
.SetWeapon(WEAPON_KASTET
);
4212 if gFlash
= 2 then Inc(FPickup
, 5);
4214 FBerserk
:= gTime
+30000;
4218 //k8:do we need it? if g_Game_IsNet and g_Game_IsServer then MH_SEND_PlayerStats(FUID);
4220 if FHealth
< PLAYER_HP_SOFT
then
4222 FHealth
:= PLAYER_HP_SOFT
;
4223 FBerserk
:= gTime
+30000;
4231 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4233 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4236 if gFlash
= 2 then Inc(FPickup
, 5);
4240 if FHealth
< PLAYER_HP_LIMIT
then
4242 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4246 if gFlash
= 2 then Inc(FPickup
, 5);
4250 if FArmor
< PLAYER_AP_LIMIT
then
4252 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4255 if gFlash
= 2 then Inc(FPickup
, 5);
4259 if FJetFuel
< JET_MAX
then
4261 FJetFuel
:= JET_MAX
;
4264 if gFlash
= 2 then Inc(FPickup
, 5);
4268 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4270 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4273 if gFlash
= 2 then Inc(FPickup
, 5);
4278 procedure TPlayer
.Touch();
4282 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4285 // Áðîñèòü ôëàã òîâàðèùó:
4286 if gGameSettings
.GameMode
= GM_CTF
then
4291 procedure TPlayer
.Push(vx
, vy
: Integer);
4293 if (not FPhysics
) and FGhost
then
4295 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4296 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4297 if g_Game_IsNet
and g_Game_IsServer
then
4298 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4301 procedure TPlayer
.Reset(Force
: Boolean);
4307 FTime
[T_RESPAWN
] := 0;
4308 FTime
[T_FLAGCAP
] := 0;
4321 FSpectator
:= False;
4324 FSpectatePlayer
:= -1;
4325 FNoRespawn
:= False;
4327 FLives
:= gGameSettings
.MaxLives
;
4332 procedure TPlayer
.SoftReset();
4338 FBFGFireCounter
:= -1;
4346 SetAction(A_STAND
, True);
4349 function TPlayer
.GetRespawnPoint(): Byte;
4354 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4356 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4357 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4359 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4361 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4362 if Self
= gPlayer1
then
4363 c
:= RESPAWNPOINT_PLAYER1
4365 c
:= RESPAWNPOINT_PLAYER2
;
4366 if g_Map_GetPointCount(c
) > 0 then
4372 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4373 if Self
= gPlayer1
then
4374 c
:= RESPAWNPOINT_PLAYER2
4376 c
:= RESPAWNPOINT_PLAYER1
;
4377 if g_Map_GetPointCount(c
) > 0 then
4384 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4385 if Random(2) = 0 then
4386 c
:= RESPAWNPOINT_PLAYER1
4388 c
:= RESPAWNPOINT_PLAYER2
;
4389 if g_Map_GetPointCount(c
) > 0 then
4396 // Òî÷êà ëþáîé èç êîìàíä
4397 if Random(2) = 0 then
4398 c
:= RESPAWNPOINT_RED
4400 c
:= RESPAWNPOINT_BLUE
;
4401 if g_Map_GetPointCount(c
) > 0 then
4408 c
:= RESPAWNPOINT_DM
;
4409 if g_Map_GetPointCount(c
) > 0 then
4417 if gGameSettings
.GameMode
= GM_DM
then
4420 c
:= RESPAWNPOINT_DM
;
4421 if g_Map_GetPointCount(c
) > 0 then
4427 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4428 if Random(2) = 0 then
4429 c
:= RESPAWNPOINT_PLAYER1
4431 c
:= RESPAWNPOINT_PLAYER2
;
4432 if g_Map_GetPointCount(c
) > 0 then
4438 // Òî÷êà ëþáîé èç êîìàíä
4439 if Random(2) = 0 then
4440 c
:= RESPAWNPOINT_RED
4442 c
:= RESPAWNPOINT_BLUE
;
4443 if g_Map_GetPointCount(c
) > 0 then
4451 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4453 // Òî÷êà ñâîåé êîìàíäû
4454 c
:= RESPAWNPOINT_DM
;
4455 if FTeam
= TEAM_RED
then
4456 c
:= RESPAWNPOINT_RED
;
4457 if FTeam
= TEAM_BLUE
then
4458 c
:= RESPAWNPOINT_BLUE
;
4459 if g_Map_GetPointCount(c
) > 0 then
4466 c
:= RESPAWNPOINT_DM
;
4467 if g_Map_GetPointCount(c
) > 0 then
4473 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4474 if Random(2) = 0 then
4475 c
:= RESPAWNPOINT_PLAYER1
4477 c
:= RESPAWNPOINT_PLAYER2
;
4478 if g_Map_GetPointCount(c
) > 0 then
4484 // Òî÷êà äðóãîé êîìàíäû
4485 c
:= RESPAWNPOINT_DM
;
4486 if FTeam
= TEAM_RED
then
4487 c
:= RESPAWNPOINT_BLUE
;
4488 if FTeam
= TEAM_BLUE
then
4489 c
:= RESPAWNPOINT_RED
;
4490 if g_Map_GetPointCount(c
) > 0 then
4498 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4500 RespawnPoint
: TRespawnPoint
;
4506 FBFGFireCounter
:= -1;
4511 if not g_Game_IsServer
then
4515 FWantsInGame
:= True;
4516 FJustTeleported
:= True;
4519 FTime
[T_RESPAWN
] := 0;
4523 // if server changes MaxLives we gotta be ready
4524 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4526 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4527 if FTime
[T_RESPAWN
] > gTime
then
4530 // Ïðîñðàë âñå æèçíè:
4533 if not FSpectator
then Spectate(True);
4534 FWantsInGame
:= True;
4538 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4539 begin // "Ñâîÿ èãðà"
4540 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4541 FRulez
:= FRulez
-[R_BERSERK
];
4543 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4545 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4546 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4549 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4550 c
:= GetRespawnPoint();
4555 // Âîñêðåøåíèå áåç îðóæèÿ:
4558 FHealth
:= PLAYER_HP_SOFT
;
4564 for a
:= WP_FIRST
to WP_LAST
do
4566 FWeapon
[a
] := False;
4570 FWeapon
[WEAPON_PISTOL
] := True;
4571 FWeapon
[WEAPON_KASTET
] := True;
4572 FCurrWeap
:= WEAPON_PISTOL
;
4575 FModel
.SetWeapon(FCurrWeap
);
4577 for b
:= A_BULLETS
to A_HIGH
do
4580 FAmmo
[A_BULLETS
] := 50;
4582 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4583 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4584 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4585 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4586 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4588 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4589 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4594 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4595 if not g_Map_GetPoint(c
, RespawnPoint
) then
4597 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4601 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4602 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4603 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4609 FDirection
:= RespawnPoint
.Direction
;
4610 if FDirection
= TDirection
.D_LEFT
then
4615 SetAction(A_STAND
, True);
4616 FModel
.Direction
:= FDirection
;
4618 for a
:= Low(FTime
) to High(FTime
) do
4621 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4626 FCanJetpack
:= False;
4631 // Àíèìàöèÿ âîçðîæäåíèÿ:
4632 if (not gLoadGameMode
) and (not Silent
) then
4633 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4635 Anim
:= TAnimation
.Create(ID
, False, 3);
4636 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4637 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4641 FSpectator
:= False;
4644 FSpectatePlayer
:= -1;
4647 if (gPlayer1
= nil) and (gLMSPID1
= FUID
) then
4649 if (gPlayer2
= nil) and (gLMSPID2
= FUID
) then
4652 if g_Game_IsNet
then
4654 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4655 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4657 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4658 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4663 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4666 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4667 else if (not NoMove
) then
4669 GameX
:= gMapInfo
.Width
div 2;
4670 GameY
:= gMapInfo
.Height
div 2;
4679 FWantsInGame
:= False;
4684 if Self
= gPlayer1
then
4689 if Self
= gPlayer2
then
4696 if g_Game_IsNet
then
4697 MH_SEND_PlayerStats(FUID
);
4700 procedure TPlayer
.SwitchNoClip
;
4704 FGhost
:= not FGhost
;
4705 FPhysics
:= not FGhost
;
4717 procedure TPlayer
.Run(Direction
: TDirection
);
4721 if MAX_RUNVEL
> 8 then
4725 if Direction
= TDirection
.D_LEFT
then
4727 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4728 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4731 if FObj
.Vel
.X
< MAX_RUNVEL
then
4732 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4734 // Âîçìîæíî, ïèíàåì êóñêè:
4735 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4737 b
:= Abs(FObj
.Vel
.X
);
4738 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4739 for a
:= 0 to High(gGibs
) do
4741 if gGibs
[a
].alive
and
4742 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4743 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4746 if FObj
.Vel
.X
< 0 then
4748 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4752 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4754 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4762 procedure TPlayer
.SeeDown();
4764 SetAction(A_SEEDOWN
);
4766 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4768 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4771 procedure TPlayer
.SeeUp();
4775 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4777 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4780 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4788 A_ATTACK
: Prior
:= 2;
4789 A_SEEUP
: Prior
:= 1;
4790 A_SEEDOWN
: Prior
:= 1;
4791 A_ATTACKUP
: Prior
:= 2;
4792 A_ATTACKDOWN
: Prior
:= 2;
4797 if (Prior
> FActionPrior
) or Force
then
4798 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4800 FActionPrior
:= Prior
;
4801 FActionAnim
:= Action
;
4802 FActionForce
:= Force
;
4803 FActionChanged
:= True;
4806 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4809 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4811 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4812 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4813 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4814 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4817 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4824 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4826 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4827 if g_Game_IsServer
and g_Game_IsNet
then
4828 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4832 FJustTeleported
:= True;
4837 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4839 Anim
:= TAnimation
.Create(ID
, False, 3);
4842 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4843 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4844 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4845 if g_Game_IsServer
and g_Game_IsNet
then
4846 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4847 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4851 FObj
.X
:= X
-PLAYER_RECT
.X
;
4852 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4853 if FAlive
and FGhost
then
4859 if not g_Game_IsNet
then
4863 SetDirection(TDirection
.D_LEFT
);
4869 SetDirection(TDirection
.D_RIGHT
);
4875 if FDirection
= TDirection
.D_RIGHT
then
4877 SetDirection(TDirection
.D_LEFT
);
4882 SetDirection(TDirection
.D_RIGHT
);
4888 if not silent
and (Anim
<> nil) then
4890 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4891 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4894 if g_Game_IsServer
and g_Game_IsNet
then
4895 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4896 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4903 function nonz(a
: Single): Single;
4911 function TPlayer
.followCorpse(): Boolean;
4916 if FAlive
or FSpectator
then
4918 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
4920 for i
:= 0 to High(gCorpses
) do
4921 if gCorpses
[i
] <> nil then
4922 if gCorpses
[i
].FPlayerUID
= FUID
then
4925 FObj
.X
:= gCorpses
[i
].FObj
.X
;
4926 FObj
.Y
:= gCorpses
[i
].FObj
.Y
;
4927 FObj
.Vel
.X
:= gCorpses
[i
].FObj
.Vel
.X
;
4928 FObj
.Vel
.Y
:= gCorpses
[i
].FObj
.Vel
.Y
;
4929 FObj
.Accel
.X
:= gCorpses
[i
].FObj
.Accel
.X
;
4930 FObj
.Accel
.Y
:= gCorpses
[i
].FObj
.Accel
.Y
;
4935 procedure TPlayer
.Update();
4938 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4939 blockmon
, headwater
, dospawn
: Boolean;
4944 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4945 AnyServer
:= g_Game_IsServer
;
4947 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4948 DoLerp(NetInterpLevel
+ 1)
4954 if FClientID
>= 0 then
4956 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4957 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4958 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4967 if FAlive
and (FPunchAnim
<> nil) then
4968 FPunchAnim
.Update();
4970 if FAlive
and (gFly
or FJetpack
) then
4973 if FDirection
= TDirection
.D_LEFT
then
4978 if FAlive
and (not FGhost
) then
4980 if FKeys
[KEY_UP
].Pressed
then
4982 if FKeys
[KEY_DOWN
].Pressed
then
4986 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4989 i
:= g_basic
.Sign(FIncCam
);
4990 FIncCam
:= Abs(FIncCam
);
4991 DecMin(FIncCam
, 5, 0);
4992 FIncCam
:= FIncCam
*i
;
4995 // no need to do that each second frame, weapon queue will take care of it
4996 if FAlive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4997 if FAlive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4999 if gTime
mod (GAME_TICK
*2) <> 0 then
5001 if (FObj
.Vel
.X
= 0) and FAlive
then
5003 if FKeys
[KEY_LEFT
].Pressed
then
5004 Run(TDirection
.D_LEFT
);
5005 if FKeys
[KEY_RIGHT
].Pressed
then
5006 Run(TDirection
.D_RIGHT
);
5011 if not followCorpse() then
5012 g_Obj_Move(@FObj
, True, True, True);
5013 positionChanged(); // this updates spatial accelerators
5019 FActionChanged
:= False;
5023 // Let alive player do some actions
5024 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
5025 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
5026 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
5027 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
5028 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
5029 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
5030 if FKeys
[KEY_JUMP
].Pressed
then Jump()
5033 if AnyServer
and FJetpack
then
5037 if NetServer
then MH_SEND_PlayerStats(FUID
);
5039 FCanJetpack
:= True;
5046 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
5048 if FKeys
[k
].Pressed
then
5056 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5059 if (FTime
[T_RESPAWN
] <= gTime
) and
5060 gGameOn
and (not FAlive
) then
5062 if (g_Player_GetCount() > 1) then
5066 gExit
:= EXIT_RESTART
;
5071 // Dead spectator actions
5074 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
5075 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
5079 if (FSpectatePlayer
>= High(gPlayers
)) then
5080 FSpectatePlayer
:= -1
5084 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
5085 if gPlayers
[I
] <> nil then
5086 if gPlayers
[I
].alive
then
5087 if gPlayers
[I
].UID
<> FUID
then
5089 FSpectatePlayer
:= I
;
5094 if not SetSpect
then FSpectatePlayer
:= -1;
5105 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5107 FYTo
:= FObj
.Y
- 32;
5108 FSpectatePlayer
:= -1;
5110 if FKeys
[KEY_DOWN
].Pressed
then
5112 FYTo
:= FObj
.Y
+ 32;
5113 FSpectatePlayer
:= -1;
5115 if FKeys
[KEY_LEFT
].Pressed
then
5117 FXTo
:= FObj
.X
- 32;
5118 FSpectatePlayer
:= -1;
5120 if FKeys
[KEY_RIGHT
].Pressed
then
5122 FXTo
:= FObj
.X
+ 32;
5123 FSpectatePlayer
:= -1;
5126 if (FXTo
< -64) then
5128 else if (FXTo
> gMapInfo
.Width
+ 32) then
5129 FXTo
:= gMapInfo
.Width
+ 32;
5130 if (FYTo
< -72) then
5132 else if (FYTo
> gMapInfo
.Height
+ 32) then
5133 FYTo
:= gMapInfo
.Height
+ 32;
5138 if not followCorpse() then
5139 g_Obj_Move(@FObj
, True, True, True);
5140 positionChanged(); // this updates spatial accelerators
5147 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5148 if gPlayers
[FSpectatePlayer
] <> nil then
5149 if gPlayers
[FSpectatePlayer
].alive
then
5151 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
5152 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
5156 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5157 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5158 PANEL_BLOCKMON
, True);
5159 headwater
:= HeadInLiquid(0, 0);
5161 // Ñîïðîòèâëåíèå âîçäóõà:
5162 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5163 if FObj
.Vel
.X
<> 0 then
5164 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5166 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5167 DecMin(FPain
, 5, 0);
5168 DecMin(FPickup
, 1, 0);
5170 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5172 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5173 FMegaRulez
[MR_SUIT
] := 0;
5174 FMegaRulez
[MR_INVUL
] := 0;
5175 FMegaRulez
[MR_INVIS
] := 0;
5176 Kill(K_FALLKILL
, 0, HIT_FALL
);
5183 if FCurrWeap
= WEAPON_SAW
then
5184 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5185 FSawSoundSelect
.IsPlaying()) then
5186 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5189 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5190 (not FJetSoundOff
.IsPlaying()) then
5192 FJetSoundFly
.SetPosition(0);
5193 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5196 for b
:= WP_FIRST
to WP_LAST
do
5197 if FReloading
[b
] > 0 then
5203 if FShellTimer
> -1 then
5204 if FShellTimer
= 0 then
5206 if FShellType
= SHELL_SHELL
then
5207 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5208 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5209 else if FShellType
= SHELL_DBLSHELL
then
5211 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5212 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5213 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5214 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5217 end else Dec(FShellTimer
);
5219 if (FBFGFireCounter
> -1) then
5220 if FBFGFireCounter
= 0 then
5224 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5225 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5226 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5227 yd
:= wy
+firediry();
5228 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5229 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5230 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5231 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5232 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5235 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5236 FBFGFireCounter
:= -1;
5239 FBFGFireCounter
:= 0
5241 Dec(FBFGFireCounter
);
5243 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5245 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5247 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5250 if (headwater
or blockmon
) then
5256 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5259 else if (FAir
mod 31 = 0) and not blockmon
then
5261 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5262 if Random(2) = 0 then
5263 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5265 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5267 end else if FAir
< AIR_DEF
then
5270 if FFireTime
> 0 then
5272 if BodyInLiquid(0, 0) then
5277 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5279 if FMegaRulez
[MR_SUIT
] = gTime
then
5286 if FFirePainTime
<= 0 then
5288 if g_Game_IsServer
then
5289 Damage(5, FFireAttacker
, 0, 0, HIT_FLAME
);
5290 FFirePainTime
:= 18;
5292 FFirePainTime
:= FFirePainTime
- 1;
5293 FFireTime
:= FFireTime
- 1;
5294 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5295 MH_SEND_PlayerStats(FUID
);
5299 if FDamageBuffer
> 0 then
5301 if FDamageBuffer
>= 9 then
5305 if FDamageBuffer
< 30 then i
:= 9
5306 else if FDamageBuffer
< 100 then i
:= 18
5310 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5311 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5312 FHealth
:= FHealth
-ii
;
5315 FHealth
:= FHealth
+FArmor
;
5320 if FHealth
<= 0 then
5321 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5322 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5323 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5327 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5328 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5329 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5330 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5337 end; // if FAlive then ...
5339 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5341 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5342 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5343 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5344 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5346 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5347 then SetAction(A_STAND
, True);
5349 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5351 for b
:= Low(FKeys
) to High(FKeys
) do
5352 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5356 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5358 x
:= FObj
.X
+PLAYER_RECT
.X
;
5359 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5360 w
:= PLAYER_RECT
.Width
;
5361 h
:= PLAYER_RECT
.Height
;
5365 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5367 if (dx
<> 0) or (dy
<> 0) then
5376 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5378 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5379 FObj
.Y
+PLAYER_RECT
.Y
,
5386 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5388 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5389 FObj
.Y
+PLAYER_RECT
.Y
,
5393 Panel
.Width
, Panel
.Height
);
5396 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5398 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5399 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5400 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5401 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5404 function g_Player_ValidName(Name
: string): Boolean;
5410 if gPlayers
= nil then Exit
;
5412 for a
:= 0 to High(gPlayers
) do
5413 if gPlayers
[a
] <> nil then
5414 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5421 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5425 d
:= FModel
.Direction
;
5427 FModel
.Direction
:= Direction
;
5428 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5430 FDirection
:= Direction
;
5433 function TPlayer
.GetKeys(): Byte;
5437 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5438 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5439 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5441 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5442 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5445 procedure TPlayer
.Use();
5449 if FTime
[T_USE
] > gTime
then Exit
;
5451 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5452 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5454 for a
:= 0 to High(gPlayers
) do
5455 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5456 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5457 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5458 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5460 gPlayers
[a
].Touch();
5461 if g_Game_IsNet
and g_Game_IsServer
then
5462 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5465 FTime
[T_USE
] := gTime
+120;
5468 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5472 WX
, WY
, XD
, YD
: Integer;
5484 if R_BERSERK
in FRulez
then
5486 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5487 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5488 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5491 locobj
.rect
.Width
:= 39;
5492 locobj
.rect
.Height
:= 52;
5493 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5494 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5495 locobj
.Accel
.X
:= xd
-wx
;
5496 locobj
.Accel
.y
:= yd
-wy
;
5498 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5499 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5501 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5505 FPain
:= min(FPain
+ 25, 50);
5507 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5512 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5513 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5515 FSawSoundSelect
.Stop();
5517 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5519 else if not FSawSoundHit
.IsPlaying() then
5521 FSawSoundSelect
.Stop();
5522 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5529 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5530 FFireAngle
:= FAngle
;
5532 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5533 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5538 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5539 FFireAngle
:= FAngle
;
5542 FShellType
:= SHELL_SHELL
;
5547 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5548 FFireAngle
:= FAngle
;
5551 FShellType
:= SHELL_DBLSHELL
;
5556 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5557 FFireAngle
:= FAngle
;
5559 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5560 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5563 WEAPON_ROCKETLAUNCHER
:
5565 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5566 FFireAngle
:= FAngle
;
5572 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5573 FFireAngle
:= FAngle
;
5579 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5580 FFireAngle
:= FAngle
;
5584 WEAPON_SUPERPULEMET
:
5586 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5587 FFireAngle
:= FAngle
;
5589 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5590 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5593 WEAPON_FLAMETHROWER
:
5595 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5596 FFireAngle
:= FAngle
;
5603 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5604 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5605 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5608 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5610 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5611 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5614 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5618 if NetInterpLevel
< 1 then
5628 AX
:= Abs(FXTo
- FObj
.X
);
5629 AY
:= Abs(FYTo
- FObj
.Y
);
5630 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5632 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5637 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
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_LIFTUP
, False) then Result
:= -1
5643 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5644 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5645 PANEL_LIFTDOWN
, False) then Result
:= 1
5649 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5656 if Flag
= FLAG_NONE
then
5659 if not g_Game_IsServer
then Exit
;
5661 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5662 if (Flag
= FTeam
) and
5663 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5664 (FFlag
<> FLAG_NONE
) then
5666 if FFlag
= FLAG_RED
then
5667 s
:= _lc
[I_PLAYER_FLAG_RED
]
5669 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5671 evtype
:= FLAG_STATE_SCORED
;
5673 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5674 Insert('.', ts
, Length(ts
) + 1 - 3);
5675 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5677 g_Map_ResetFlag(FFlag
);
5678 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5680 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5683 if g_Game_IsNet
then
5685 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5689 gFlags
[FFlag
].CaptureTime
:= 0;
5694 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5695 if (Flag
= FTeam
) and
5696 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5698 if Flag
= FLAG_RED
then
5699 s
:= _lc
[I_PLAYER_FLAG_RED
]
5701 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5703 evtype
:= FLAG_STATE_RETURNED
;
5704 gFlags
[Flag
].CaptureTime
:= 0;
5706 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5708 g_Map_ResetFlag(Flag
);
5709 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5712 if g_Game_IsNet
then
5714 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5720 // Ïîäîáðàë ÷óæîé ôëàã:
5721 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5725 if Flag
= FLAG_RED
then
5726 s
:= _lc
[I_PLAYER_FLAG_RED
]
5728 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5730 evtype
:= FLAG_STATE_CAPTURED
;
5732 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5734 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5736 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5739 if g_Game_IsNet
then
5741 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5747 procedure TPlayer
.SetFlag(Flag
: Byte);
5750 if FModel
<> nil then
5751 FModel
.SetFlag(FFlag
);
5754 function TPlayer
.DropFlag(): Boolean;
5759 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5761 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5762 with gFlags
[FFlag
] do
5766 Direction
:= FDirection
;
5767 State
:= FLAG_STATE_DROPPED
;
5769 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5770 (FObj
.Vel
.Y
div 2)-2+Random(5));
5771 positionChanged(); // this updates spatial accelerators
5773 if FFlag
= FLAG_RED
then
5774 s
:= _lc
[I_PLAYER_FLAG_RED
]
5776 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5778 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5779 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5781 if g_Game_IsNet
then
5782 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5788 procedure TPlayer
.GetSecret();
5793 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5795 Assert(Key
<= High(FKeys
));
5797 FKeys
[Key
].Pressed
:= True;
5798 FKeys
[Key
].Time
:= Time
;
5801 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5803 Result
:= FKeys
[K
].Pressed
;
5806 procedure TPlayer
.ReleaseKeys();
5810 for a
:= Low(FKeys
) to High(FKeys
) do
5812 FKeys
[a
].Pressed
:= False;
5817 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5821 function TPlayer
.firediry(): Integer;
5823 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5824 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5828 procedure TPlayer
.RememberState();
5832 FSavedState
.Health
:= FHealth
;
5833 FSavedState
.Armor
:= FArmor
;
5834 FSavedState
.Air
:= FAir
;
5835 FSavedState
.JetFuel
:= FJetFuel
;
5836 FSavedState
.CurrWeap
:= FCurrWeap
;
5837 FSavedState
.NextWeap
:= FNextWeap
;
5838 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5841 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5843 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5845 FSavedState
.Rulez
:= FRulez
;
5846 FSavedState
.WaitRecall
:= True;
5849 procedure TPlayer
.RecallState();
5853 if not FSavedState
.WaitRecall
then Exit
;
5855 FHealth
:= FSavedState
.Health
;
5856 FArmor
:= FSavedState
.Armor
;
5857 FAir
:= FSavedState
.Air
;
5858 FJetFuel
:= FSavedState
.JetFuel
;
5859 FCurrWeap
:= FSavedState
.CurrWeap
;
5860 FNextWeap
:= FSavedState
.NextWeap
;
5861 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5864 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5866 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5868 FRulez
:= FSavedState
.Rulez
;
5869 FSavedState
.WaitRecall
:= False;
5871 if gGameSettings
.GameType
= GT_SERVER
then
5872 MH_SEND_PlayerStats(FUID
);
5875 procedure TPlayer
.SaveState (st
: TStream
);
5881 utils
.writeSign(st
, 'PLYR');
5882 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
5884 utils
.writeBool(st
, FIamBot
);
5886 utils
.writeInt(st
, Word(FUID
));
5888 utils
.writeStr(st
, FName
);
5890 utils
.writeInt(st
, Byte(FTeam
));
5892 utils
.writeBool(st
, FAlive
);
5893 // Èçðàñõîäîâàë ëè âñå æèçíè
5894 utils
.writeBool(st
, FNoRespawn
);
5896 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
5897 utils
.writeInt(st
, Byte(b
));
5899 utils
.writeInt(st
, LongInt(FHealth
));
5901 utils
.writeInt(st
, Byte(FLives
));
5903 utils
.writeInt(st
, LongInt(FArmor
));
5905 utils
.writeInt(st
, LongInt(FAir
));
5907 utils
.writeInt(st
, LongInt(FJetFuel
));
5909 utils
.writeInt(st
, LongInt(FPain
));
5911 utils
.writeInt(st
, LongInt(FKills
));
5913 utils
.writeInt(st
, LongInt(FMonsterKills
));
5915 utils
.writeInt(st
, LongInt(FFrags
));
5917 utils
.writeInt(st
, Byte(FFragCombo
));
5918 // Âðåìÿ ïîñëåäíåãî ôðàãà
5919 utils
.writeInt(st
, LongWord(FLastFrag
));
5921 utils
.writeInt(st
, LongInt(FDeath
));
5923 utils
.writeInt(st
, Byte(FFlag
));
5925 utils
.writeInt(st
, LongInt(FSecrets
));
5927 utils
.writeInt(st
, Byte(FCurrWeap
));
5929 utils
.writeInt(st
, Word(FNextWeap
));
5931 utils
.writeInt(st
, Byte(FNextWeapDelay
));
5932 // Âðåìÿ çàðÿäêè BFG
5933 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
5935 utils
.writeInt(st
, LongInt(FDamageBuffer
));
5936 // Ïîñëåäíèé óäàðèâøèé
5937 utils
.writeInt(st
, Word(FLastSpawnerUID
));
5938 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
5939 utils
.writeInt(st
, Byte(FLastHit
));
5941 Obj_SaveState(st
, @FObj
);
5942 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
5943 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
5944 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
5945 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
5947 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
5948 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
5949 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
5951 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
5952 // Íàëè÷èå êðàñíîãî êëþ÷à
5953 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
5954 // Íàëè÷èå çåëåíîãî êëþ÷à
5955 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
5956 // Íàëè÷èå ñèíåãî êëþ÷à
5957 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
5959 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
5960 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
5961 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
5962 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
5963 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
5965 utils
.writeStr(st
, FModel
.Name
);
5967 utils
.writeInt(st
, Byte(FColor
.R
));
5968 utils
.writeInt(st
, Byte(FColor
.G
));
5969 utils
.writeInt(st
, Byte(FColor
.B
));
5973 procedure TPlayer
.LoadState (st
: TStream
);
5982 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
5983 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
5985 FIamBot
:= utils
.readBool(st
);
5987 FUID
:= utils
.readWord(st
);
5989 str
:= utils
.readStr(st
);
5990 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
5992 FTeam
:= utils
.readByte(st
);
5994 FAlive
:= utils
.readBool(st
);
5995 // Èçðàñõîäîâàë ëè âñå æèçíè
5996 FNoRespawn
:= utils
.readBool(st
);
5998 b
:= utils
.readByte(st
);
5999 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
6001 FHealth
:= utils
.readLongInt(st
);
6003 FLives
:= utils
.readByte(st
);
6005 FArmor
:= utils
.readLongInt(st
);
6007 FAir
:= utils
.readLongInt(st
);
6009 FJetFuel
:= utils
.readLongInt(st
);
6011 FPain
:= utils
.readLongInt(st
);
6013 FKills
:= utils
.readLongInt(st
);
6015 FMonsterKills
:= utils
.readLongInt(st
);
6017 FFrags
:= utils
.readLongInt(st
);
6019 FFragCombo
:= utils
.readByte(st
);
6020 // Âðåìÿ ïîñëåäíåãî ôðàãà
6021 FLastFrag
:= utils
.readLongWord(st
);
6023 FDeath
:= utils
.readLongInt(st
);
6025 FFlag
:= utils
.readByte(st
);
6027 FSecrets
:= utils
.readLongInt(st
);
6029 FCurrWeap
:= utils
.readByte(st
);
6031 FNextWeap
:= utils
.readWord(st
);
6033 FNextWeapDelay
:= utils
.readByte(st
);
6034 // Âðåìÿ çàðÿäêè BFG
6035 FBFGFireCounter
:= utils
.readSmallInt(st
);
6037 FDamageBuffer
:= utils
.readLongInt(st
);
6038 // Ïîñëåäíèé óäàðèâøèé
6039 FLastSpawnerUID
:= utils
.readWord(st
);
6040 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6041 FLastHit
:= utils
.readByte(st
);
6043 Obj_LoadState(@FObj
, st
);
6044 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6045 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
6046 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6047 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
6049 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
6050 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6051 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
6053 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
6054 // Íàëè÷èå êðàñíîãî êëþ÷à
6055 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
6056 // Íàëè÷èå çåëåíîãî êëþ÷à
6057 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
6058 // Íàëè÷èå ñèíåãî êëþ÷à
6059 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
6061 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
6062 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6063 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
6064 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6065 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
6067 str
:= utils
.readStr(st
);
6069 FColor
.R
:= utils
.readByte(st
);
6070 FColor
.G
:= utils
.readByte(st
);
6071 FColor
.B
:= utils
.readByte(st
);
6072 if (self
= gPlayer1
) then
6074 str
:= gPlayer1Settings
.Model
;
6075 FColor
:= gPlayer1Settings
.Color
;
6077 else if (self
= gPlayer2
) then
6079 str
:= gPlayer2Settings
.Model
;
6080 FColor
:= gPlayer2Settings
.Color
;
6082 // Îáíîâëÿåì ìîäåëü èãðîêà
6084 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
6085 FModel
.Color
:= TEAMCOLOR
[FTeam
]
6087 FModel
.Color
:= FColor
;
6091 procedure TPlayer
.AllRulez(Health
: Boolean);
6097 FHealth
:= PLAYER_HP_LIMIT
;
6098 FArmor
:= PLAYER_AP_LIMIT
;
6102 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
6103 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
6104 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6107 procedure TPlayer
.RestoreHealthArmor();
6109 FHealth
:= PLAYER_HP_LIMIT
;
6110 FArmor
:= PLAYER_AP_LIMIT
;
6113 procedure TPlayer
.FragCombo();
6117 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6119 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6121 if FFragCombo
< 5 then
6123 Param
:= FUID
or (FFragCombo
shl 16);
6124 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6125 (FComboEvnt
<= High(gDelayedEvents
)) and
6126 gDelayedEvents
[FComboEvnt
].Pending
and
6127 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6128 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6130 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6131 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6134 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6142 procedure TPlayer
.GiveItem(ItemType
: Byte);
6146 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6148 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6152 if FAir
< AIR_MAX
then
6159 if not (R_BERSERK
in FRulez
) then
6161 Include(FRulez
, R_BERSERK
);
6162 if FBFGFireCounter
< 1 then
6164 FCurrWeap
:= WEAPON_KASTET
;
6166 FModel
.SetWeapon(WEAPON_KASTET
);
6170 FBerserk
:= gTime
+30000;
6172 if FHealth
< PLAYER_HP_SOFT
then
6174 FHealth
:= PLAYER_HP_SOFT
;
6175 FBerserk
:= gTime
+30000;
6180 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6182 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6186 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6188 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6192 if FJetFuel
< JET_MAX
then
6194 FJetFuel
:= JET_MAX
;
6197 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6198 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6200 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6201 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6203 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6205 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6207 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6208 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6211 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6212 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6213 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6214 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6215 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6216 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6217 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6218 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6219 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6221 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6222 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6223 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6224 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6225 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6226 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6227 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6228 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6229 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6232 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6233 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6234 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6235 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6236 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6238 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6239 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6240 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6241 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6242 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6244 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6245 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6246 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6247 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6249 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6252 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6253 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6254 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6256 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6257 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6262 if g_Game_IsNet
and g_Game_IsServer
then
6263 MH_SEND_PlayerStats(FUID
);
6266 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6271 if (Random(5) = 1) and (Times
= 1) then
6274 if BodyInLiquid(0, 0) then
6276 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6277 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6278 if Random(2) = 0 then
6279 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6281 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6285 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6287 for i
:= 1 to Times
do
6289 Anim
:= TAnimation
.Create(id
, False, 3);
6291 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6292 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6298 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6303 if (Random(10) = 1) and (Times
= 1) then
6306 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6308 for i
:= 1 to Times
do
6310 Anim
:= TAnimation
.Create(id
, False, 3);
6312 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6313 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6319 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6321 FSawSound
.Pause(Enable
);
6322 FSawSoundIdle
.Pause(Enable
);
6323 FSawSoundHit
.Pause(Enable
);
6324 FSawSoundSelect
.Pause(Enable
);
6329 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6334 FObj
.Rect
:= PLAYER_CORPSERECT
;
6335 FModelName
:= ModelName
;
6340 FState
:= CORPSE_STATE_MESS
;
6341 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6345 FState
:= CORPSE_STATE_NORMAL
;
6346 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6350 destructor TCorpse
.Destroy();
6357 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6359 procedure TCorpse
.positionChanged (); inline; begin end;
6361 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6363 if (dx
<> 0) or (dy
<> 0) then
6372 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6374 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6375 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6376 w
:= PLAYER_CORPSERECT
.Width
;
6377 h
:= PLAYER_CORPSERECT
.Height
;
6381 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6386 if FState
= CORPSE_STATE_REMOVEME
then
6389 FDamage
:= FDamage
+ Value
;
6391 if FDamage
> 150 then
6393 if FAnimation
<> nil then
6398 FState
:= CORPSE_STATE_REMOVEME
;
6400 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6401 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6402 FModelName
, FColor
);
6403 // Çâóê ìÿñà îò òðóïà:
6404 pm
:= g_PlayerModel_Get(FModelName
);
6405 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6409 if (gBodyKillEvent
<> -1)
6410 and gDelayedEvents
[gBodyKillEvent
].Pending
then
6411 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
6412 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, 0);
6417 Blood
:= g_PlayerModel_GetBlood(FModelName
);
6418 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6419 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6420 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6421 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6422 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6423 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
6427 procedure TCorpse
.Draw();
6429 if FState
= CORPSE_STATE_REMOVEME
then
6432 if FAnimation
<> nil then
6433 FAnimation
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6435 if FAnimationMask
<> nil then
6438 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6445 procedure TCorpse
.Update();
6449 if FState
= CORPSE_STATE_REMOVEME
then
6452 if gTime
mod (GAME_TICK
*2) <> 0 then
6454 g_Obj_Move(@FObj
, True, True, True);
6455 positionChanged(); // this updates spatial accelerators
6459 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6460 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6462 st
:= g_Obj_Move(@FObj
, True, True, True);
6463 positionChanged(); // this updates spatial accelerators
6465 if WordBool(st
and MOVE_FALLOUT
) then
6467 FState
:= CORPSE_STATE_REMOVEME
;
6471 if FAnimation
<> nil then
6472 FAnimation
.Update();
6473 if FAnimationMask
<> nil then
6474 FAnimationMask
.Update();
6478 procedure TCorpse
.SaveState (st
: TStream
);
6485 utils
.writeSign(st
, 'CORP');
6486 utils
.writeInt(st
, Byte(0));
6488 utils
.writeInt(st
, Byte(FState
));
6490 utils
.writeInt(st
, Byte(FDamage
));
6492 utils
.writeInt(st
, Byte(FColor
.R
));
6493 utils
.writeInt(st
, Byte(FColor
.G
));
6494 utils
.writeInt(st
, Byte(FColor
.B
));
6496 Obj_SaveState(st
, @FObj
);
6497 utils
.writeInt(st
, Word(FPlayerUID
));
6499 anim
:= (FAnimation
<> nil);
6500 utils
.writeBool(st
, anim
);
6501 // Åñëè åñòü - ñîõðàíÿåì
6502 if anim
then FAnimation
.SaveState(st
);
6503 // Åñòü ëè ìàñêà àíèìàöèè
6504 anim
:= (FAnimationMask
<> nil);
6505 utils
.writeBool(st
, anim
);
6506 // Åñëè åñòü - ñîõðàíÿåì
6507 if anim
then FAnimationMask
.SaveState(st
);
6511 procedure TCorpse
.LoadState (st
: TStream
);
6518 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6519 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6521 FState
:= utils
.readByte(st
);
6523 FDamage
:= utils
.readByte(st
);
6525 FColor
.R
:= utils
.readByte(st
);
6526 FColor
.G
:= utils
.readByte(st
);
6527 FColor
.B
:= utils
.readByte(st
);
6529 Obj_LoadState(@FObj
, st
);
6530 FPlayerUID
:= utils
.readWord(st
);
6532 anim
:= utils
.readBool(st
);
6533 // Åñëè åñòü - çàãðóæàåì
6536 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6537 FAnimation
.LoadState(st
);
6539 // Åñòü ëè ìàñêà àíèìàöèè
6540 anim
:= utils
.readBool(st
);
6541 // Åñëè åñòü - çàãðóæàåì
6544 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6545 FAnimationMask
.LoadState(st
);
6551 constructor TBot
.Create();
6558 FSpectator
:= False;
6565 for a
:= WP_FIRST
to WP_LAST
do
6567 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6568 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6569 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6573 destructor TBot
.Destroy();
6576 inherited Destroy();
6579 procedure TBot
.Draw();
6583 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6584 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6587 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6589 inherited Respawn(Silent
, Force
);
6592 FSelectedWeapon
:= FCurrWeap
;
6597 procedure TBot
.UpdateCombat();
6610 TTargetRecord
= array of TTarget
;
6612 function Compare(a
, b
: TTarget
): Integer;
6614 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6617 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6619 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6620 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6622 if a
.Dist
> b
.Dist
then // B áëèæå
6624 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6627 else // Ñòðàííî -> A
6632 a
, x1
, y1
, x2
, y2
: Integer;
6633 targets
: TTargetRecord
;
6635 Target
, BestTarget
: TTarget
;
6636 firew
, fireh
: Integer;
6640 vsPlayer
, vsMonster
, ok
: Boolean;
6643 function monsUpdate (mon
: TMonster
): Boolean;
6645 result
:= false; // don't stop
6646 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6648 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6650 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6651 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6653 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6654 if g_TraceVector(x1
, y1
, x2
, y2
) then
6656 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6657 SetLength(targets
, Length(targets
)+1);
6658 with targets
[High(targets
)] do
6665 Rect
:= mon
.Obj
.Rect
;
6666 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6667 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6668 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6677 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6678 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6680 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6681 if FCurrWeap
<> FSelectedWeapon
then
6684 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6685 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6687 RemoveAIFlag('NEEDFIRE');
6690 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6691 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6692 else PressKey(KEY_FIRE
);
6696 // Êîîðäèíàòû ñòâîëà:
6697 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6698 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6700 Target
.UID
:= FTargetUID
;
6703 if Target
.UID
<> 0 then
6704 begin // Öåëü åñòü - íàñòðàèâàåì
6705 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6708 tpla
:= g_Player_Get(Target
.UID
);
6712 if (@FObj
) <> nil then
6719 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6720 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6721 Target
.Rect
:= PLAYER_RECT
;
6722 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6723 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6724 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6725 Target
.IsPlayer
:= True;
6729 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6732 mon
:= g_Monsters_ByUID(Target
.UID
);
6735 Target
.X
:= mon
.Obj
.X
;
6736 Target
.Y
:= mon
.Obj
.Y
;
6738 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6739 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6740 Target
.Rect
:= mon
.Obj
.Rect
;
6741 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6742 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6743 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6744 Target
.IsPlayer
:= False;
6751 begin // Öåëè íåò - îáíóëÿåì
6756 Target
.Visible
:= False;
6757 Target
.Line
:= False;
6758 Target
.IsPlayer
:= False;
6763 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6764 if (not Target
.Line
) or (not Target
.Visible
) then
6768 for a
:= 0 to High(gPlayers
) do
6769 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6770 (gPlayers
[a
].FUID
<> FUID
) and
6771 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6772 (not gPlayers
[a
].NoTarget
) and
6773 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6775 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6776 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6779 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6780 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6782 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6783 if g_TraceVector(x1
, y1
, x2
, y2
) then
6785 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6786 SetLength(targets
, Length(targets
)+1);
6787 with targets
[High(targets
)] do
6789 UID
:= gPlayers
[a
].FUID
;
6790 X
:= gPlayers
[a
].FObj
.X
;
6791 Y
:= gPlayers
[a
].FObj
.Y
;
6794 Rect
:= PLAYER_RECT
;
6795 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6796 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6797 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6805 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6808 // Åñëè åñòü âîçìîæíûå öåëè:
6809 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6810 if targets
<> nil then
6812 // Âûáèðàåì íàèëó÷øóþ öåëü:
6813 BestTarget
:= targets
[0];
6814 if Length(targets
) > 1 then
6815 for a
:= 1 to High(targets
) do
6816 if Compare(BestTarget
, targets
[a
]) = 1 then
6817 BestTarget
:= targets
[a
];
6819 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6820 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6821 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6823 Target
:= BestTarget
;
6825 if (Healthy() = 3) or ((Healthy() = 2)) then
6826 begin // Åñëè çäîðîâû - äîãîíÿåì
6827 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6828 SetAIFlag('GORIGHT', '1');
6829 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6830 SetAIFlag('GOLEFT', '1');
6833 begin // Åñëè ïîáèòû - óáåãàåì
6834 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6835 SetAIFlag('GORIGHT', '1');
6836 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6837 SetAIFlag('GOLEFT', '1');
6840 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6841 SelectWeapon(Abs(x1
-Target
.cX
));
6846 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6847 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6848 if Target
.UID
<> 0 then
6850 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6851 Target
.Y
+ Target
.Rect
.Y
) then
6852 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6853 if (Healthy() = 3) or ((Healthy() = 2)) then
6854 begin // Åñëè çäîðîâû - äîãîíÿåì
6855 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6856 SetAIFlag('GORIGHT', '1');
6857 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6858 SetAIFlag('GOLEFT', '1');
6861 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6863 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6864 SetAIFlag('GORIGHT', '1');
6865 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6866 SetAIFlag('GOLEFT', '1');
6870 begin // Öåëü ïîêà íà "ýêðàíå"
6871 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6872 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6873 FLastVisible
:= gTime
;
6874 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6875 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6877 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6878 SetAIFlag('GORIGHT', '1');
6879 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6880 SetAIFlag('GOLEFT', '1');
6884 // Âûáèðàåì óãîë ââåðõ:
6885 if FDirection
= TDirection
.D_LEFT
then
6886 angle
:= ANGLE_LEFTUP
6888 angle
:= ANGLE_RIGHTUP
;
6890 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6891 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6893 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6894 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6895 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6896 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6897 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6898 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6899 begin // òî íóæíî ñòðåëÿòü ââåðõ
6900 SetAIFlag('NEEDFIRE', '1');
6901 SetAIFlag('NEEDSEEUP', '1');
6904 // Âûáèðàåì óãîë âíèç:
6905 if FDirection
= TDirection
.D_LEFT
then
6906 angle
:= ANGLE_LEFTDOWN
6908 angle
:= ANGLE_RIGHTDOWN
;
6910 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6911 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6913 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6914 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6915 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6916 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6917 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6918 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6919 begin // òî íóæíî ñòðåëÿòü âíèç
6920 SetAIFlag('NEEDFIRE', '1');
6921 SetAIFlag('NEEDSEEDOWN', '1');
6924 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6925 if Target
.Visible
and
6926 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6927 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6929 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6930 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
6931 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6932 begin // òî íóæíî ñòðåëÿòü âïåðåä
6933 SetAIFlag('NEEDFIRE', '1');
6934 SetAIFlag('NEEDSEEDOWN', '');
6935 SetAIFlag('NEEDSEEUP', '');
6937 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6938 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6939 if GetRnd(FDifficult
.CloseJump
) then
6940 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6941 if Abs(FObj
.X
-Target
.X
) < 128 then
6945 if Random(a
) = 0 then
6946 SetAIFlag('NEEDJUMP', '1');
6950 // Åñëè öåëü âñå åùå åñòü:
6951 if Target
.UID
<> 0 then
6952 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
6953 Target
.UID
:= 0 // òî çàáûòü öåëü
6954 else // Åñëè âèäåëè íåäàâíî
6955 begin // íî öåëü óáèëè
6956 if Target
.IsPlayer
then
6957 begin // Öåëü - èãðîê
6958 pla
:= g_Player_Get(Target
.UID
);
6959 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
6960 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6961 Target
.UID
:= 0; // òî çàáûòü öåëü
6964 begin // Öåëü - ìîíñòð
6965 mon
:= g_Monsters_ByUID(Target
.UID
);
6966 if (mon
= nil) or (not mon
.alive
) then
6967 Target
.UID
:= 0; // òî çàáûòü öåëü
6970 end; // if Target.UID <> 0
6972 FTargetUID
:= Target
.UID
;
6974 // Åñëè âîçìîæíûõ öåëåé íåò:
6975 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
6976 if targets
= nil then
6977 if GetAIFlag('ATTACKLEFT') <> '' then
6978 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
6979 RemoveAIFlag('ATTACKLEFT');
6981 SetAIFlag('NEEDJUMP', '1');
6983 if RunDirection() = TDirection
.D_RIGHT
then
6984 begin // Èäåì íå â òó ñòîðîíó
6985 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6986 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
6987 SetAIFlag('NEEDFIRE', '1');
6988 SetAIFlag('GOLEFT', '1');
6992 begin // Èäåì â íóæíóþ ñòîðîíó
6993 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6994 SetAIFlag('NEEDFIRE', '1');
6995 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6996 SetAIFlag('GORIGHT', '1');
7000 if GetAIFlag('ATTACKRIGHT') <> '' then
7001 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
7002 RemoveAIFlag('ATTACKRIGHT');
7004 SetAIFlag('NEEDJUMP', '1');
7006 if RunDirection() = TDirection
.D_LEFT
then
7007 begin // Èäåì íå â òó ñòîðîíó
7008 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7009 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
7010 SetAIFlag('NEEDFIRE', '1');
7011 SetAIFlag('GORIGHT', '1');
7016 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7017 SetAIFlag('NEEDFIRE', '1');
7018 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7019 SetAIFlag('GOLEFT', '1');
7023 //HACK! (does it belongs there?)
7024 RealizeCurrentWeapon();
7026 // Åñëè åñòü âîçìîæíûå öåëè:
7027 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7028 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7029 for a
:= 0 to High(targets
) do
7031 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7032 if GetRnd(FDifficult
.DiagFire
) then
7034 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7035 if FDirection
= TDirection
.D_LEFT
then
7036 angle
:= ANGLE_LEFTUP
7038 angle
:= ANGLE_RIGHTUP
;
7040 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7041 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7043 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7044 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7045 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7046 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7047 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7049 SetAIFlag('NEEDFIRE', '1');
7050 SetAIFlag('NEEDSEEUP', '1');
7053 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7054 if FDirection
= TDirection
.D_LEFT
then
7055 angle
:= ANGLE_LEFTDOWN
7057 angle
:= ANGLE_RIGHTDOWN
;
7059 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7060 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7062 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7063 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7064 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7065 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7066 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7068 SetAIFlag('NEEDFIRE', '1');
7069 SetAIFlag('NEEDSEEDOWN', '1');
7073 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7074 if targets
[a
].Line
and targets
[a
].Visible
and
7075 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
7076 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
7078 SetAIFlag('NEEDFIRE', '1');
7083 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7084 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
7085 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
7086 40+GetInterval(FDifficult
.Cover
, 40)) then
7087 SetAIFlag('NEEDJUMP', '1');
7089 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7090 ammo
:= GetAmmoByWeapon(FCurrWeap
);
7091 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
7092 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
7094 SetAIFlag('SELECTWEAPON', '1');
7096 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7097 if GetAIFlag('SELECTWEAPON') = '1' then
7100 RemoveAIFlag('SELECTWEAPON');
7104 procedure TBot
.Update();
7117 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7118 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7120 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7122 if g_debug_BotAIOff
= 3 then
7132 RealizeCurrentWeapon();
7139 procedure TBot
.ReleaseKey(Key
: Byte);
7148 function TBot
.KeyPressed(Key
: Word): Boolean;
7150 Result
:= FKeys
[Key
].Pressed
;
7153 function TBot
.GetAIFlag(aName
: String20
): String20
;
7159 aName
:= LowerCase(aName
);
7161 if FAIFlags
<> nil then
7162 for a
:= 0 to High(FAIFlags
) do
7163 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7165 Result
:= FAIFlags
[a
].Value
;
7170 procedure TBot
.RemoveAIFlag(aName
: String20
);
7174 if FAIFlags
= nil then Exit
;
7176 aName
:= LowerCase(aName
);
7178 for a
:= 0 to High(FAIFlags
) do
7179 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7181 if a
<> High(FAIFlags
) then
7182 for b
:= a
to High(FAIFlags
)-1 do
7183 FAIFlags
[b
] := FAIFlags
[b
+1];
7185 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7190 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7198 aName
:= LowerCase(aName
);
7200 if FAIFlags
<> nil then
7201 for a
:= 0 to High(FAIFlags
) do
7202 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7208 if ok
then FAIFlags
[a
].Value
:= fValue
7211 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7212 with FAIFlags
[High(FAIFlags
)] do
7220 procedure TBot
.UpdateMove
;
7222 procedure GoLeft(Time
: Word = 1);
7224 ReleaseKey(KEY_LEFT
);
7225 ReleaseKey(KEY_RIGHT
);
7226 PressKey(KEY_LEFT
, Time
);
7227 SetDirection(TDirection
.D_LEFT
);
7230 procedure GoRight(Time
: Word = 1);
7232 ReleaseKey(KEY_LEFT
);
7233 ReleaseKey(KEY_RIGHT
);
7234 PressKey(KEY_RIGHT
, Time
);
7235 SetDirection(TDirection
.D_RIGHT
);
7238 function Rnd(a
: Word): Boolean;
7240 Result
:= Random(a
) = 0;
7243 procedure Turn(Time
: Word = 1200);
7245 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7250 ReleaseKey(KEY_LEFT
);
7251 ReleaseKey(KEY_RIGHT
);
7254 function CanRunLeft(): Boolean;
7256 Result
:= not CollideLevel(-1, 0);
7259 function CanRunRight(): Boolean;
7261 Result
:= not CollideLevel(1, 0);
7264 function CanRun(): Boolean;
7266 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7269 procedure Jump(Time
: Word = 30);
7271 PressKey(KEY_JUMP
, Time
);
7274 function NearHole(): Boolean;
7278 { TODO 5 : Ëåñòíèöû }
7279 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7280 for x
:= 1 to PLAYER_RECT
.Width
do
7281 if (not StayOnStep(x
*sx
, 0)) and
7282 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7283 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7292 function BorderHole(): Boolean;
7296 { TODO 5 : Ëåñòíèöû }
7297 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7298 for x
:= 1 to PLAYER_RECT
.Width
do
7299 if (not StayOnStep(x
*sx
, 0)) and
7300 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7301 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7303 for xx
:= x
to x
+32 do
7304 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7314 function NearDeepHole(): Boolean;
7320 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7323 for x
:= 1 to PLAYER_RECT
.Width
do
7324 if (not StayOnStep(x
*sx
, 0)) and
7325 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7326 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7328 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7330 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7335 end else Result
:= False;
7338 function OverDeepHole(): Boolean;
7345 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7347 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7354 function OnGround(): Boolean;
7356 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7359 function OnLadder(): Boolean;
7361 Result
:= FullInStep(0, 0);
7364 function BelowLadder(): Boolean;
7366 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7367 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7368 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7369 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7372 function BelowLiftUp(): Boolean;
7374 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7375 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7376 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7377 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7380 function OnTopLift(): Boolean;
7382 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7385 function CanJumpOver(): Boolean;
7389 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7393 if not CollideLevel(sx
, 0) then Exit
;
7395 for y
:= 1 to BOT_MAXJUMP
do
7396 if CollideLevel(0, -y
) then Exit
else
7397 if not CollideLevel(sx
, -y
) then
7404 function CanJumpUp(Dist
: ShortInt): Boolean;
7411 if CollideLevel(Dist
, 0) then Exit
;
7414 for y
:= 0 to BOT_MAXJUMP
do
7415 if CollideLevel(Dist
, -y
) then
7424 for yy
:= y
+1 to BOT_MAXJUMP
do
7425 if not CollideLevel(Dist
, -yy
) then
7434 for y
:= 0 to BOT_MAXJUMP
do
7435 if CollideLevel(0, -y
) then
7443 if y
< yy
then Exit
;
7448 function IsSafeTrigger(): Boolean;
7453 if gTriggers
= nil then
7455 for a
:= 0 to High(gTriggers
) do
7456 if Collide(gTriggers
[a
].X
,
7459 gTriggers
[a
].Height
) and
7460 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7461 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7462 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7463 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7464 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7469 // Âîçìîæíî, íàæèìàåì êíîïêó:
7470 if Rnd(16) and IsSafeTrigger() then
7473 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7474 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7476 ReleaseKey(KEY_LEFT
);
7477 ReleaseKey(KEY_RIGHT
);
7481 // Èäåì âëåâî, åñëè íàäî áûëî:
7482 if GetAIFlag('GOLEFT') <> '' then
7484 RemoveAIFlag('GOLEFT');
7485 if CanRunLeft() then
7489 // Èäåì âïðàâî, åñëè íàäî áûëî:
7490 if GetAIFlag('GORIGHT') <> '' then
7492 RemoveAIFlag('GORIGHT');
7493 if CanRunRight() then
7497 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7498 if FObj
.X
< -32 then
7501 if FObj
.X
+32 > gMapInfo
.Width
then
7504 // Ïðûãàåì, åñëè íàäî áûëî:
7505 if GetAIFlag('NEEDJUMP') <> '' then
7508 RemoveAIFlag('NEEDJUMP');
7511 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7512 if GetAIFlag('NEEDSEEUP') <> '' then
7515 ReleaseKey(KEY_DOWN
);
7516 PressKey(KEY_UP
, 20);
7517 RemoveAIFlag('NEEDSEEUP');
7520 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7521 if GetAIFlag('NEEDSEEDOWN') <> '' then
7524 ReleaseKey(KEY_DOWN
);
7525 PressKey(KEY_DOWN
, 20);
7526 RemoveAIFlag('NEEDSEEDOWN');
7529 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7530 if GetAIFlag('GOINHOLE') <> '' then
7531 if not OnGround() then
7533 ReleaseKey(KEY_LEFT
);
7534 ReleaseKey(KEY_RIGHT
);
7535 RemoveAIFlag('GOINHOLE');
7536 SetAIFlag('FALLINHOLE', '1');
7539 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7540 if GetAIFlag('FALLINHOLE') <> '' then
7542 RemoveAIFlag('FALLINHOLE');
7544 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7545 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7546 if GetAIFlag('FALLINHOLE') = '' then
7547 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7553 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7555 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7559 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7560 if OnGround() and NearHole() then
7561 if NearDeepHole() then // Åñëè ýòî áåçäíà
7563 0..3: Turn(); // Áåæèì îáðàòíî
7564 4: Jump(); // Ïðûãàåì
7565 5: begin // Ïðûãàåì îáðàòíî
7570 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7571 if GetAIFlag('GOINHOLE') = '' then
7573 0: Turn(); // Íå íóæíî òóäà
7574 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7575 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7576 if BorderHole() then
7577 SetAIFlag('GOINHOLE', '1');
7580 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7581 if (not CanRun()) and OnGround() then
7583 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7584 if CanJumpOver() or OnLadder() then
7586 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7587 if Random(2) = 0 then
7589 if IsSafeTrigger() then
7595 // Îñòàëîñü ìàëî âîçäóõà:
7596 if FAir
< 36 * 2 then
7599 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7600 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7601 if BodyInAcid(0, 0) then
7605 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7607 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7608 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7611 {function TBot.NeedItem(Item: Byte): Byte;
7616 procedure TBot
.SelectWeapon(Dist
: Integer);
7620 function HaveAmmo(weapon
: Byte): Boolean;
7623 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7624 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7625 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7626 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7627 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7628 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7629 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7630 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7631 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7632 else Result
:= True;
7637 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7639 if Dist
> BOT_LONGDIST
then
7640 begin // Äàëüíèé áîé
7642 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7644 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7648 else //if Dist > BOT_UNSAFEDIST then
7649 begin // Áëèæíèé áîé
7651 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7653 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7660 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7662 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7668 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7670 Result
:= inherited PickItem(ItemType
, force
, remove
);
7672 if Result
then SetAIFlag('SELECTWEAPON', '1');
7675 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7677 Result
:= inherited Heal(value
, Soft
);
7680 function TBot
.Healthy(): Byte;
7682 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7683 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7684 else if (FHealth
> 50) then Result
:= 2
7685 else if (FHealth
> 20) then Result
:= 1
7689 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7691 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7692 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7695 procedure TBot
.OnDamage(Angle
: SmallInt);
7703 if (Angle
= 0) or (Angle
= 180) then
7706 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7707 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7709 pla
:= g_Player_Get(FLastSpawnerUID
);
7710 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7711 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7714 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7715 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7717 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7718 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7719 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7724 SetAIFlag('ATTACKLEFT', '1')
7726 SetAIFlag('ATTACKRIGHT', '1');
7730 function TBot
.RunDirection(): TDirection
;
7732 if Abs(Vel
.X
) >= 1 then
7734 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7736 Result
:= FDirection
;
7739 function TBot
.GetRnd(a
: Byte): Boolean;
7741 if a
= 0 then Result
:= False
7742 else if a
= 255 then Result
:= True
7743 else Result
:= Random(256) > 255-a
;
7746 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7748 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7752 procedure TDifficult
.save (st
: TStream
);
7754 utils
.writeInt(st
, Byte(DiagFire
));
7755 utils
.writeInt(st
, Byte(InvisFire
));
7756 utils
.writeInt(st
, Byte(DiagPrecision
));
7757 utils
.writeInt(st
, Byte(FlyPrecision
));
7758 utils
.writeInt(st
, Byte(Cover
));
7759 utils
.writeInt(st
, Byte(CloseJump
));
7760 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7761 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7764 procedure TDifficult
.load (st
: TStream
);
7766 DiagFire
:= utils
.readByte(st
);
7767 InvisFire
:= utils
.readByte(st
);
7768 DiagPrecision
:= utils
.readByte(st
);
7769 FlyPrecision
:= utils
.readByte(st
);
7770 Cover
:= utils
.readByte(st
);
7771 CloseJump
:= utils
.readByte(st
);
7772 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7773 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7777 procedure TBot
.SaveState (st
: TStream
);
7782 inherited SaveState(st
);
7783 utils
.writeSign(st
, 'BOT0');
7785 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7787 utils
.writeInt(st
, Word(FTargetUID
));
7788 // Âðåìÿ ïîòåðè öåëè
7789 utils
.writeInt(st
, LongWord(FLastVisible
));
7790 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7791 dw
:= Length(FAIFlags
);
7792 utils
.writeInt(st
, LongInt(dw
));
7794 for i
:= 0 to dw
-1 do
7796 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7797 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7799 // Íàñòðîéêè ñëîæíîñòè
7800 FDifficult
.save(st
);
7804 procedure TBot
.LoadState (st
: TStream
);
7809 inherited LoadState(st
);
7810 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7812 FSelectedWeapon
:= utils
.readByte(st
);
7814 FTargetUID
:= utils
.readWord(st
);
7815 // Âðåìÿ ïîòåðè öåëè
7816 FLastVisible
:= utils
.readLongWord(st
);
7817 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7818 dw
:= utils
.readLongInt(st
);
7819 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7820 SetLength(FAIFlags
, dw
);
7822 for i
:= 0 to dw
-1 do
7824 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7825 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7827 // Íàñòðîéêè ñëîæíîñòè
7828 FDifficult
.load(st
);
7833 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);