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 Byte; // bit 0: was released on prev frame; bit 1: new status
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;
342 procedure weaponSwitchKeysShiftNewStates ();
345 property Vel
: TPoint2i read FObj
.Vel
;
346 property Obj
: TObj read FObj
;
348 property Name
: String read FName write FName
;
349 property Model
: TPlayerModel read FModel
;
350 property Health
: Integer read FHealth write FHealth
;
351 property Lives
: Byte read FLives write FLives
;
352 property Armor
: Integer read FArmor write FArmor
;
353 property Air
: Integer read FAir write FAir
;
354 property JetFuel
: Integer read FJetFuel write FJetFuel
;
355 property Frags
: Integer read FFrags write FFrags
;
356 property Death
: Integer read FDeath write FDeath
;
357 property Kills
: Integer read FKills write FKills
;
358 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
359 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
360 property Secrets
: Integer read FSecrets
;
361 property GodMode
: Boolean read FGodMode write FGodMode
;
362 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
363 property NoReload
: Boolean read FNoReload write FNoReload
;
364 property alive
: Boolean read FAlive write FAlive
;
365 property Flag
: Byte read FFlag
;
366 property Team
: Byte read FTeam write FTeam
;
367 property Direction
: TDirection read FDirection
;
368 property GameX
: Integer read FObj
.X write FObj
.X
;
369 property GameY
: Integer read FObj
.Y write FObj
.Y
;
370 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
371 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
372 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
373 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
374 property IncCam
: Integer read FIncCam write FIncCam
;
375 property UID
: Word read FUID write FUID
;
376 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
377 property NetTime
: LongWord read FNetTime write FNetTime
;
380 property eName
: String read FName write FName
;
381 property eHealth
: Integer read FHealth write FHealth
;
382 property eLives
: Byte read FLives write FLives
;
383 property eArmor
: Integer read FArmor write FArmor
;
384 property eAir
: Integer read FAir write FAir
;
385 property eJetFuel
: Integer read FJetFuel write FJetFuel
;
386 property eFrags
: Integer read FFrags write FFrags
;
387 property eDeath
: Integer read FDeath write FDeath
;
388 property eKills
: Integer read FKills write FKills
;
389 property eCurrWeap
: Byte read FCurrWeap write FCurrWeap
;
390 property eMonsterKills
: Integer read FMonsterKills write FMonsterKills
;
391 property eSecrets
: Integer read FSecrets write FSecrets
;
392 property eGodMode
: Boolean read FGodMode write FGodMode
;
393 property eNoTarget
: Boolean read FNoTarget write FNoTarget
;
394 property eNoReload
: Boolean read FNoReload write FNoReload
;
395 property eAlive
: Boolean read FAlive write FAlive
;
396 property eFlag
: Byte read FFlag
;
397 property eTeam
: Byte read FTeam write FTeam
;
398 property eDirection
: TDirection read FDirection
;
399 property eGameX
: Integer read FObj
.X write FObj
.X
;
400 property eGameY
: Integer read FObj
.Y write FObj
.Y
;
401 property eGameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
402 property eGameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
403 property eGameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
404 property eGameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
405 property eIncCam
: Integer read FIncCam write FIncCam
;
406 property eUID
: Word read FUID
;
407 property eJustTeleported
: Boolean read FJustTeleported
;
408 property eNetTime
: LongWord read FNetTime
;
410 // set this before assigning something to `eDamage`
411 property eDamageType
: Integer read mEDamageType write mEDamageType
;
412 property eDamage
: Integer write doDamage
;
423 WeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
424 CloseWeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
425 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
428 procedure save (st
: TStream
);
429 procedure load (st
: TStream
);
437 TBot
= class(TPlayer
)
439 FSelectedWeapon
: Byte;
442 FAIFlags
: Array of TAIFlag
;
443 FDifficult
: TDifficult
;
445 function GetRnd(a
: Byte): Boolean;
446 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
447 function RunDirection(): TDirection
;
448 function FullInStep(XInc
, YInc
: Integer): Boolean;
449 //function NeedItem(Item: Byte): Byte;
450 procedure SelectWeapon(Dist
: Integer);
451 procedure SetAIFlag(aName
, fValue
: String20
);
452 function GetAIFlag(aName
: String20
): String20
;
453 procedure RemoveAIFlag(aName
: String20
);
454 function Healthy(): Byte;
455 procedure UpdateMove();
456 procedure UpdateCombat();
457 function KeyPressed(Key
: Word): Boolean;
458 procedure ReleaseKey(Key
: Byte);
459 function TargetOnScreen(TX
, TY
: Integer): Boolean;
460 procedure OnDamage(Angle
: SmallInt); override;
463 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
464 constructor Create(); override;
465 destructor Destroy(); override;
466 procedure Draw(); override;
467 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
468 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
469 procedure Update(); override;
470 procedure SaveState (st
: TStream
); override;
471 procedure LoadState (st
: TStream
); override;
483 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
484 procedure moveBy (dx
, dy
: Integer); inline;
486 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
500 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
501 procedure moveBy (dx
, dy
: Integer); inline;
503 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
506 TCorpse
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
515 FAnimation
: TAnimation
;
516 FAnimationMask
: TAnimation
;
519 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
520 destructor Destroy(); override;
521 procedure Damage(Value
: Word; vx
, vy
: Integer);
524 procedure SaveState (st
: TStream
);
525 procedure LoadState (st
: TStream
);
527 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
528 procedure moveBy (dx
, dy
: Integer); inline;
530 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
532 function ObjPtr (): PObj
; inline;
534 property Obj
: TObj read FObj
; // copies object
535 property State
: Byte read FState
;
536 property Mess
: Boolean read FMess
;
539 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
545 gPlayers
: Array of TPlayer
;
546 gCorpses
: Array of TCorpse
;
547 gGibs
: Array of TGib
;
548 gShells
: Array of TShell
;
549 gTeamStat
: TTeamStat
;
550 gFly
: Boolean = False;
551 gAimLine
: Boolean = False;
552 gChatBubble
: Byte = 0;
556 MAX_RUNVEL
: Integer = 8;
557 VEL_JUMP
: Integer = 10;
558 SHELL_TIMEOUT
: Cardinal = 60000;
560 function Lerp(X
, Y
, Factor
: Integer): Integer;
562 procedure g_Gibs_SetMax(Count
: Word);
563 function g_Gibs_GetMax(): Word;
564 procedure g_Corpses_SetMax(Count
: Word);
565 function g_Corpses_GetMax(): Word;
566 procedure g_Shells_SetMax(Count
: Word);
567 function g_Shells_GetMax(): Word;
569 procedure g_Player_Init();
570 procedure g_Player_Free();
571 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
572 function g_Player_CreateFromState (st
: TStream
): Word;
573 procedure g_Player_Remove(UID
: Word);
574 procedure g_Player_ResetTeams();
575 procedure g_Player_UpdateAll();
576 procedure g_Player_DrawAll();
577 procedure g_Player_DrawDebug(p
: TPlayer
);
578 procedure g_Player_DrawHealth();
579 procedure g_Player_RememberAll();
580 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
581 function g_Player_Get(UID
: Word): TPlayer
;
582 function g_Player_GetCount(): Byte;
583 function g_Player_GetStats(): TPlayerStatArray
;
584 function g_Player_ValidName(Name
: String): Boolean;
585 procedure g_Player_CreateCorpse(Player
: TPlayer
);
586 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
587 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
588 procedure g_Player_UpdatePhysicalObjects();
589 procedure g_Player_DrawCorpses();
590 procedure g_Player_DrawShells();
591 procedure g_Player_RemoveAllCorpses();
592 procedure g_Player_Corpses_SaveState (st
: TStream
);
593 procedure g_Player_Corpses_LoadState (st
: TStream
);
594 procedure g_Bot_Add(Team
, Difficult
: Byte);
595 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1);
596 procedure g_Bot_MixNames();
597 procedure g_Bot_RemoveAll();
602 {$INCLUDE ../nogl/noGLuses.inc}
603 {$IFDEF ENABLE_HOLMES}
606 e_log
, g_map
, g_items
, g_console
, g_gfx
, Math
,
607 g_options
, g_triggers
, g_menu
, g_game
, g_grid
,
608 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
,
609 g_net
, g_netmsg
, g_window
,
612 const PLR_SAVE_VERSION
= 0;
622 diag_precision
: Byte;
626 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
627 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
628 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
632 TIME_RESPAWN1
= 1500;
633 TIME_RESPAWN2
= 2000;
634 TIME_RESPAWN3
= 3000;
637 JET_MAX
= 540; // ~30 sec
638 PLAYER_SUIT_TIME
= 30000;
639 PLAYER_INVUL_TIME
= 30000;
640 PLAYER_INVIS_TIME
= 35000;
641 FRAG_COMBO_TIME
= 3000;
645 ANGLE_RIGHTDOWN
= -35;
647 ANGLE_LEFTDOWN
= -145;
648 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
649 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
652 BOT_UNSAFEDIST
= 128;
653 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
655 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
656 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
657 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
658 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
659 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
660 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
661 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
662 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
663 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
664 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
665 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
666 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
667 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
668 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
669 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
670 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
671 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
672 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
673 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
674 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
675 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
676 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
677 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
678 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
679 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
680 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
682 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
683 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
685 BOTNAMES_FILENAME
= 'botnames.txt';
686 BOTLIST_FILENAME
= 'botlist.txt';
690 MaxCorpses
: Word = 20;
691 MaxShells
: Word = 300;
692 CurrentGib
: Integer = 0;
693 CurrentShell
: Integer = 0;
694 BotNames
: Array of String;
695 BotList
: Array of TBotProfile
;
698 function Lerp(X
, Y
, Factor
: Integer): Integer;
700 Result
:= X
+ ((Y
- X
) div Factor
);
703 function SameTeam(UID1
, UID2
: Word): Boolean;
707 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
708 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
710 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
712 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
713 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
715 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
718 procedure g_Gibs_SetMax(Count
: Word);
721 SetLength(gGibs
, Count
);
723 if CurrentGib
>= Count
then
727 function g_Gibs_GetMax(): Word;
732 procedure g_Shells_SetMax(Count
: Word);
735 SetLength(gShells
, Count
);
737 if CurrentShell
>= Count
then
741 function g_Shells_GetMax(): Word;
747 procedure g_Corpses_SetMax(Count
: Word);
750 SetLength(gCorpses
, Count
);
753 function g_Corpses_GetMax(): Word;
755 Result
:= MaxCorpses
;
758 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
768 // Åñòü ëè ìåñòî â gPlayers:
769 if gPlayers
<> nil then
770 for a
:= 0 to High(gPlayers
) do
771 if gPlayers
[a
] = nil then
777 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
780 SetLength(gPlayers
, Length(gPlayers
)+1);
784 // Ñîçäàåì îáúåêò èãðîêà:
786 gPlayers
[a
] := TBot
.Create()
788 gPlayers
[a
] := TPlayer
.Create();
791 gPlayers
[a
].FActualModelName
:= ModelName
;
792 gPlayers
[a
].SetModel(ModelName
);
794 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
795 if gPlayers
[a
].FModel
= nil then
799 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
803 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
804 if Random(2) = 0 then
808 gPlayers
[a
].FPreferredTeam
:= Team
;
810 case gGameSettings
.GameMode
of
811 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
813 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
815 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
818 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
819 gPlayers
[a
].FColor
:= Color
;
820 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
821 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
823 gPlayers
[a
].FModel
.Color
:= Color
;
825 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
826 gPlayers
[a
].FAlive
:= False;
828 Result
:= gPlayers
[a
].FUID
;
831 function g_Player_CreateFromState (st
: TStream
): Word;
838 if (st
= nil) then exit
; //???
841 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
842 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
845 Bot
:= utils
.readBool(st
);
850 // Åñòü ëè ìåñòî â gPlayers:
851 for a
:= 0 to High(gPlayers
) do if (gPlayers
[a
] = nil) then begin ok
:= true; break
; end;
853 // Íåò ìåñòà - ðàñøèðÿåì gPlayers
856 SetLength(gPlayers
, Length(gPlayers
)+1);
860 // Ñîçäàåì îáúåêò èãðîêà
862 gPlayers
[a
] := TBot
.Create()
864 gPlayers
[a
] := TPlayer
.Create();
865 gPlayers
[a
].FIamBot
:= Bot
;
866 gPlayers
[a
].FPhysics
:= True;
869 gPlayers
[a
].FUID
:= utils
.readWord(st
);
871 gPlayers
[a
].FName
:= utils
.readStr(st
);
873 gPlayers
[a
].FTeam
:= utils
.readByte(st
);
874 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
876 gPlayers
[a
].FAlive
:= utils
.readBool(st
);
877 // Èçðàñõîäîâàë ëè âñå æèçíè
878 gPlayers
[a
].FNoRespawn
:= utils
.readBool(st
);
880 b
:= utils
.readByte(st
);
881 if b
= 1 then gPlayers
[a
].FDirection
:= TDirection
.D_LEFT
else gPlayers
[a
].FDirection
:= TDirection
.D_RIGHT
; // b = 2
883 gPlayers
[a
].FHealth
:= utils
.readLongInt(st
);
885 gPlayers
[a
].FLives
:= utils
.readByte(st
);
887 gPlayers
[a
].FArmor
:= utils
.readLongInt(st
);
889 gPlayers
[a
].FAir
:= utils
.readLongInt(st
);
891 gPlayers
[a
].FJetFuel
:= utils
.readLongInt(st
);
893 gPlayers
[a
].FPain
:= utils
.readLongInt(st
);
895 gPlayers
[a
].FKills
:= utils
.readLongInt(st
);
897 gPlayers
[a
].FMonsterKills
:= utils
.readLongInt(st
);
899 gPlayers
[a
].FFrags
:= utils
.readLongInt(st
);
901 gPlayers
[a
].FFragCombo
:= utils
.readByte(st
);
902 // Âðåìÿ ïîñëåäíåãî ôðàãà
903 gPlayers
[a
].FLastFrag
:= utils
.readLongWord(st
);
905 gPlayers
[a
].FDeath
:= utils
.readLongInt(st
);
907 gPlayers
[a
].FFlag
:= utils
.readByte(st
);
909 gPlayers
[a
].FSecrets
:= utils
.readLongInt(st
);
911 gPlayers
[a
].FCurrWeap
:= utils
.readByte(st
);
912 // Ñëåäóþùåå æåëàåìîå îðóæèå
913 gPlayers
[a
].FNextWeap
:= utils
.readWord(st
);
915 gPlayers
[a
].FNextWeapDelay
:= utils
.readByte(st
);
917 gPlayers
[a
].FBFGFireCounter
:= utils
.readSmallInt(st
);
919 gPlayers
[a
].FDamageBuffer
:= utils
.readLongInt(st
);
920 // Ïîñëåäíèé óäàðèâøèé
921 gPlayers
[a
].FLastSpawnerUID
:= utils
.readWord(st
);
922 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
923 gPlayers
[a
].FLastHit
:= utils
.readByte(st
);
925 Obj_LoadState(@gPlayers
[a
].FObj
, st
);
926 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
927 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FAmmo
[i
] := utils
.readWord(st
);
928 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
929 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FMaxAmmo
[i
] := utils
.readWord(st
);
931 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FWeapon
[i
] := utils
.readBool(st
);
932 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
933 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FReloading
[i
] := utils
.readWord(st
);
935 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
936 // Íàëè÷èå êðàñíîãî êëþ÷à
937 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
938 // Íàëè÷èå çåëåíîãî êëþ÷à
939 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
940 // Íàëè÷èå ñèíåãî êëþ÷à
941 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
943 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_BERSERK
);
944 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
945 for i
:= MR_SUIT
to MR_MAX
do gPlayers
[a
].FMegaRulez
[i
] := utils
.readLongWord(st
);
946 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
947 for i
:= T_RESPAWN
to T_FLAGCAP
do gPlayers
[a
].FTime
[i
] := utils
.readLongWord(st
);
950 gPlayers
[a
].FActualModelName
:= utils
.readStr(st
);
952 gPlayers
[a
].FColor
.R
:= utils
.readByte(st
);
953 gPlayers
[a
].FColor
.G
:= utils
.readByte(st
);
954 gPlayers
[a
].FColor
.B
:= utils
.readByte(st
);
955 // Îáíîâëÿåì ìîäåëü èãðîêà
956 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
958 // Íåò ìîäåëè - ñîçäàíèå íåâîçìîæíî
959 if (gPlayers
[a
].FModel
= nil) then
963 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
967 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû
968 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
969 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
971 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
973 result
:= gPlayers
[a
].FUID
;
977 procedure g_Player_ResetTeams();
981 if g_Game_IsClient
then
983 if gPlayers
= nil then
985 for a
:= Low(gPlayers
) to High(gPlayers
) do
986 if gPlayers
[a
] <> nil then
987 case gGameSettings
.GameMode
of
989 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
991 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
992 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
993 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
996 gPlayers
[a
].ChangeTeam(TEAM_RED
)
998 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
1001 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
1005 procedure g_Bot_Add(Team
, Difficult
: Byte);
1008 _name
, _model
: String;
1011 if not g_Game_IsServer
then Exit
;
1013 // Ñïèñîê íàçâàíèé ìîäåëåé:
1014 m
:= g_PlayerModel_GetNames();
1019 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1020 Team
:= TEAM_COOP
// COOP
1022 if gGameSettings
.GameMode
= GM_DM
then
1023 Team
:= TEAM_NONE
// DM
1025 if Team
= TEAM_NONE
then // CTF / TDM
1027 // Àâòîáàëàíñ êîìàíä:
1031 for a
:= 0 to High(gPlayers
) do
1032 if gPlayers
[a
] <> nil then
1034 if gPlayers
[a
].Team
= TEAM_RED
then
1037 if gPlayers
[a
].Team
= TEAM_BLUE
then
1047 if Random(2) = 0 then
1053 // Âûáèðàåì áîòó èìÿ:
1055 if BotNames
<> nil then
1056 for a
:= 0 to High(BotNames
) do
1057 if g_Player_ValidName(BotNames
[a
]) then
1059 _name
:= BotNames
[a
];
1063 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
1066 _name
:= Format('DFBOT%.2d', [Random(100)]);
1067 until g_Player_ValidName(_name
);
1069 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1070 _model
:= m
[Random(Length(m
))];
1073 with g_Player_Get(g_Player_Create(_model
,
1074 _RGB(Min(Random(9)*32, 255),
1075 Min(Random(9)*32, 255),
1076 Min(Random(9)*32, 255)),
1077 Team
, True)) as TBot
do
1082 1: FDifficult
:= DIFFICULT_EASY
;
1083 2: FDifficult
:= DIFFICULT_MEDIUM
;
1084 else FDifficult
:= DIFFICULT_HARD
;
1087 for a
:= WP_FIRST
to WP_LAST
do
1089 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1090 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1091 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1094 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1096 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1097 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1102 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1);
1105 _name
, _model
: String;
1108 if not g_Game_IsServer
then Exit
;
1110 // Ñïèñîê íàçâàíèé ìîäåëåé:
1111 m
:= g_PlayerModel_GetNames();
1116 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1117 Team
:= TEAM_COOP
// COOP
1119 if gGameSettings
.GameMode
= GM_DM
then
1120 Team
:= TEAM_NONE
// DM
1122 if Team
= TEAM_NONE
then
1123 Team
:= BotList
[num
].team
; // CTF / TDM
1125 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1126 lName
:= AnsiLowerCase(lName
);
1127 if (num
< 0) or (num
> Length(BotList
)-1) then
1129 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1130 for a
:= 0 to High(BotList
) do
1131 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1140 _name
:= BotList
[num
].name
;
1141 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1142 if not g_Player_ValidName(_name
) then
1144 _name
:= Format('DFBOT%.2d', [Random(100)]);
1145 until g_Player_ValidName(_name
);
1148 _model
:= BotList
[num
].model
;
1149 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1150 if not InSArray(_model
, m
) then
1151 _model
:= m
[Random(Length(m
))];
1154 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1158 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1159 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1160 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1161 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1162 FDifficult
.Cover
:= BotList
[num
].cover
;
1163 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1165 for a
:= WP_FIRST
to WP_LAST
do
1167 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1168 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1169 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1172 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1174 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1178 procedure g_Bot_RemoveAll();
1182 if not g_Game_IsServer
then Exit
;
1183 if gPlayers
= nil then Exit
;
1185 for a
:= 0 to High(gPlayers
) do
1186 if gPlayers
[a
] <> nil then
1187 if gPlayers
[a
] is TBot
then
1189 gPlayers
[a
].Lives
:= 0;
1190 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1191 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1192 g_Player_Remove(gPlayers
[a
].FUID
);
1198 procedure g_Bot_MixNames();
1203 if BotNames
<> nil then
1204 for a
:= 0 to High(BotNames
) do
1206 b
:= Random(Length(BotNames
));
1208 Botnames
[a
] := BotNames
[b
];
1213 procedure g_Player_Remove(UID
: Word);
1217 if gPlayers
= nil then Exit
;
1219 if g_Game_IsServer
and g_Game_IsNet
then
1220 MH_SEND_PlayerDelete(UID
);
1222 for i
:= 0 to High(gPlayers
) do
1223 if gPlayers
[i
] <> nil then
1224 if gPlayers
[i
].FUID
= UID
then
1226 if gPlayers
[i
] is TPlayer
then
1227 TPlayer(gPlayers
[i
]).Free()
1229 TBot(gPlayers
[i
]).Free();
1235 procedure g_Player_Init();
1245 if not FileExists(DataDir
+ BOTNAMES_FILENAME
) then
1248 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1249 AssignFile(F
, DataDir
+ BOTNAMES_FILENAME
);
1260 SetLength(BotNames
, Length(BotNames
)+1);
1261 BotNames
[High(BotNames
)] := s
;
1269 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1270 config
:= TConfig
.CreateFile(DataDir
+ BOTLIST_FILENAME
);
1274 while config
.SectionExists(IntToStr(a
)) do
1276 SetLength(BotList
, Length(BotList
)+1);
1278 with BotList
[High(BotList
)] do
1281 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1283 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1285 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1290 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1291 color
.R
:= StrToIntDef(sa
[0], 0);
1292 color
.G
:= StrToIntDef(sa
[1], 0);
1293 color
.B
:= StrToIntDef(sa
[2], 0);
1294 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1295 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1296 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1297 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1298 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1299 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1300 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1301 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1302 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1303 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1304 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1305 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1306 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1307 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1308 if Length(sa
) = 10 then
1310 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1311 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1312 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1313 if Length(sa
) = 10 then
1315 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1317 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1318 if Length(sa) = 10 then
1320 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1329 procedure g_Player_Free();
1333 if gPlayers
<> nil then
1335 for i
:= 0 to High(gPlayers
) do
1336 if gPlayers
[i
] <> nil then
1338 if gPlayers
[i
] is TPlayer
then
1339 TPlayer(gPlayers
[i
]).Free()
1341 TBot(gPlayers
[i
]).Free();
1352 procedure g_Player_UpdateAll();
1356 if gPlayers
= nil then Exit
;
1358 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1359 for i
:= 0 to High(gPlayers
) do
1361 if gPlayers
[i
] <> nil then
1363 if gPlayers
[i
] is TPlayer
then
1365 gPlayers
[i
].Update();
1366 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1370 // bot updates weapons in `UpdateCombat()`
1371 TBot(gPlayers
[i
]).Update();
1375 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1378 procedure g_Player_DrawAll();
1382 if gPlayers
= nil then Exit
;
1384 for i
:= 0 to High(gPlayers
) do
1385 if gPlayers
[i
] <> nil then
1386 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1387 else TBot(gPlayers
[i
]).Draw();
1390 procedure g_Player_DrawDebug(p
: TPlayer
);
1394 if p
= nil then Exit
;
1395 if (@p
.FObj
) = nil then Exit
;
1397 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1399 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1400 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1401 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1402 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1403 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1404 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1407 procedure g_Player_DrawHealth();
1412 if gPlayers
= nil then Exit
;
1413 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1415 for i
:= 0 to High(gPlayers
) do
1416 if gPlayers
[i
] <> nil then
1418 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1419 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1420 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1421 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1422 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1423 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1427 function g_Player_Get(UID
: Word): TPlayer
;
1433 if gPlayers
= nil then
1436 for a
:= 0 to High(gPlayers
) do
1437 if gPlayers
[a
] <> nil then
1438 if gPlayers
[a
].FUID
= UID
then
1440 Result
:= gPlayers
[a
];
1445 function g_Player_GetCount(): Byte;
1451 if gPlayers
= nil then
1454 for a
:= 0 to High(gPlayers
) do
1455 if gPlayers
[a
] <> nil then
1456 Result
:= Result
+ 1;
1459 function g_Player_GetStats(): TPlayerStatArray
;
1465 if gPlayers
= nil then Exit
;
1467 for a
:= 0 to High(gPlayers
) do
1468 if gPlayers
[a
] <> nil then
1470 SetLength(Result
, Length(Result
)+1);
1471 with Result
[High(Result
)] do
1473 Ping
:= gPlayers
[a
].FPing
;
1474 Loss
:= gPlayers
[a
].FLoss
;
1475 Name
:= gPlayers
[a
].FName
;
1476 Team
:= gPlayers
[a
].FTeam
;
1477 Frags
:= gPlayers
[a
].FFrags
;
1478 Deaths
:= gPlayers
[a
].FDeath
;
1479 Kills
:= gPlayers
[a
].FKills
;
1480 Color
:= gPlayers
[a
].FModel
.Color
;
1481 Lives
:= gPlayers
[a
].FLives
;
1482 Spectator
:= gPlayers
[a
].FSpectator
;
1487 procedure g_Player_RememberAll
;
1491 for i
:= Low(gPlayers
) to High(gPlayers
) do
1492 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1493 gPlayers
[i
].RememberState
;
1496 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1500 gTeamStat
[TEAM_RED
].Goals
:= 0;
1501 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1503 if gPlayers
<> nil then
1504 for i
:= 0 to High(gPlayers
) do
1505 if gPlayers
[i
] <> nil then
1507 gPlayers
[i
].Reset(Force
);
1509 if gPlayers
[i
] is TPlayer
then
1511 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1512 gPlayers
[i
].Respawn(Silent
)
1514 gPlayers
[i
].Spectate();
1517 TBot(gPlayers
[i
]).Respawn(Silent
);
1521 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1527 if Player
.alive
then
1530 // Ðàçðûâàåì ñâÿçü ñ ïðåæíèì òðóïîì:
1531 if gCorpses
<> nil then
1532 for i
:= 0 to High(gCorpses
) do
1533 if gCorpses
[i
] <> nil then
1534 if gCorpses
[i
].FPlayerUID
= Player
.FUID
then
1535 gCorpses
[i
].FPlayerUID
:= 0;
1537 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1542 if (FHealth
>= -50) or (gGibsCount
= 0) then
1544 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1548 for find_id
:= 0 to High(gCorpses
) do
1549 if gCorpses
[find_id
] = nil then
1556 find_id
:= Random(Length(gCorpses
));
1558 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1559 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1560 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1561 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1562 gCorpses
[find_id
].FPlayerUID
:= FUID
;
1565 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1566 FObj
.Y
+ PLAYER_RECT_CY
,
1567 FModel
.Name
, FModel
.Color
);
1571 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1575 if (gShells
= nil) or (Length(gShells
) = 0) then
1578 with gShells
[CurrentShell
] do
1584 if T
= SHELL_BULLET
then
1586 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1590 Obj
.Rect
.Width
:= 4;
1591 Obj
.Rect
.Height
:= 2;
1595 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1599 Obj
.Rect
.Width
:= 7;
1600 Obj
.Rect
.Height
:= 3;
1606 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1607 positionChanged(); // this updates spatial accelerators
1608 RAngle
:= Random(360);
1609 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1611 if CurrentShell
>= High(gShells
) then
1618 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1621 GibsArray
: TGibsArray
;
1624 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1626 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1628 Blood
:= g_PlayerModel_GetBlood(ModelName
);
1630 for a
:= 0 to High(GibsArray
) do
1631 with gGibs
[CurrentGib
] do
1634 ID
:= GibsArray
[a
].ID
;
1635 MaskID
:= GibsArray
[a
].MaskID
;
1638 Obj
.Rect
:= GibsArray
[a
].Rect
;
1639 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1640 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1641 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1642 positionChanged(); // this updates spatial accelerators
1643 RAngle
:= Random(360);
1645 if gBloodCount
> 0 then
1646 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1647 Random(48), Random(48), Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
1649 if CurrentGib
>= High(gGibs
) then
1656 procedure g_Player_UpdatePhysicalObjects();
1662 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1667 if T
= SHELL_BULLET
then
1668 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1670 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1675 if gGibs
<> nil then
1676 for i
:= 0 to High(gGibs
) do
1677 if gGibs
[i
].alive
then
1681 mr
:= g_Obj_Move(@Obj
, True, False, True);
1682 positionChanged(); // this updates spatial accelerators
1684 if WordBool(mr
and MOVE_FALLOUT
) then
1690 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1691 if WordBool(mr
and MOVE_HITWALL
) then
1692 Obj
.Vel
.X
:= -(vel
.X
div 2);
1693 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1694 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1696 if (Obj
.Vel
.X
>= 0) then
1698 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1699 if RAngle
>= 360 then
1700 RAngle
:= RAngle
mod 360;
1701 end else begin // Counter-clockwise
1702 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1704 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1707 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1708 if gTime
mod (GAME_TICK
*3) = 0 then
1709 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1713 if gCorpses
<> nil then
1714 for i
:= 0 to High(gCorpses
) do
1715 if gCorpses
[i
] <> nil then
1716 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1722 gCorpses
[i
].Update();
1725 if gShells
<> nil then
1726 for i
:= 0 to High(gShells
) do
1727 if gShells
[i
].alive
then
1731 mr
:= g_Obj_Move(@Obj
, True, False, True);
1732 positionChanged(); // this updates spatial accelerators
1734 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1740 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1741 if WordBool(mr
and MOVE_HITWALL
) then
1743 Obj
.Vel
.X
:= -(vel
.X
div 2);
1744 if not WordBool(mr
and MOVE_INWATER
) then
1745 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1747 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1749 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1750 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1751 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1753 if RAngle
mod 90 <> 0 then
1754 RAngle
:= (RAngle
div 90) * 90;
1756 else if not WordBool(mr
and MOVE_INWATER
) then
1757 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1760 if (Obj
.Vel
.X
>= 0) then
1762 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1763 if RAngle
>= 360 then
1764 RAngle
:= RAngle
mod 360;
1765 end else begin // Counter-clockwise
1766 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1768 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1774 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1776 x
:= Obj
.X
+Obj
.Rect
.X
;
1777 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1778 w
:= Obj
.Rect
.Width
;
1779 h
:= Obj
.Rect
.Height
;
1782 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1784 if (dx
<> 0) or (dy
<> 0) then
1793 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1797 w
:= Obj
.Rect
.Width
;
1798 h
:= Obj
.Rect
.Height
;
1801 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1803 if (dx
<> 0) or (dy
<> 0) then
1812 procedure TGib
.positionChanged (); inline; begin end;
1813 procedure TShell
.positionChanged (); inline; begin end;
1816 procedure g_Player_DrawCorpses();
1821 if gGibs
<> nil then
1822 for i
:= 0 to High(gGibs
) do
1823 if gGibs
[i
].alive
then
1826 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1829 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1830 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1832 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1835 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1841 if gCorpses
<> nil then
1842 for i
:= 0 to High(gCorpses
) do
1843 if gCorpses
[i
] <> nil then
1847 procedure g_Player_DrawShells();
1852 if gShells
<> nil then
1853 for i
:= 0 to High(gShells
) do
1854 if gShells
[i
].alive
then
1857 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1863 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1867 procedure g_Player_RemoveAllCorpses();
1873 SetLength(gGibs
, MaxGibs
);
1874 SetLength(gShells
, MaxGibs
);
1878 if gCorpses
<> nil then
1879 for i
:= 0 to High(gCorpses
) do
1883 SetLength(gCorpses
, MaxCorpses
);
1886 procedure g_Player_Corpses_SaveState (st
: TStream
);
1890 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ
1892 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1894 // Êîëè÷åñòâî òðóïîâ
1895 utils
.writeInt(st
, LongInt(count
));
1897 if (count
= 0) then exit
;
1900 for i
:= 0 to High(gCorpses
) do
1902 if gCorpses
[i
] <> nil then
1905 utils
.writeStr(st
, gCorpses
[i
].FModelName
);
1907 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1908 // Ñîõðàíÿåì äàííûå òðóïà:
1909 gCorpses
[i
].SaveState(st
);
1915 procedure g_Player_Corpses_LoadState (st
: TStream
);
1923 g_Player_RemoveAllCorpses();
1925 // Êîëè÷åñòâî òðóïîâ:
1926 count
:= utils
.readLongInt(st
);
1927 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1929 if (count
= 0) then exit
;
1932 for i
:= 0 to count
-1 do
1935 str
:= utils
.readStr(st
);
1937 b
:= utils
.readBool(st
);
1939 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1940 // Çàãðóæàåì äàííûå òðóïà
1941 gCorpses
[i
].LoadState(st
);
1948 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1950 procedure TPlayer
.BFGHit();
1952 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1953 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1954 if g_Game_IsServer
and g_Game_IsNet
then
1955 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1956 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1960 procedure TPlayer
.ChangeModel(ModelName
: string);
1962 locModel
: TPlayerModel
;
1964 locModel
:= g_PlayerModel_Get(ModelName
);
1965 if locModel
= nil then Exit
;
1971 procedure TPlayer
.SetModel(ModelName
: string);
1975 m
:= g_PlayerModel_Get(ModelName
);
1978 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1979 m
:= g_PlayerModel_Get('doomer');
1982 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1987 if FModel
<> nil then
1992 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1993 FModel
.Color
:= FColor
1995 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1996 FModel
.SetWeapon(FCurrWeap
);
1997 FModel
.SetFlag(FFlag
);
1998 SetDirection(FDirection
);
2001 procedure TPlayer
.SetColor(Color
: TRGB
);
2004 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2005 if FModel
<> nil then FModel
.Color
:= Color
;
2008 procedure TPlayer
.SwitchTeam
;
2010 if g_Game_IsClient
then
2012 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
2014 if gGameOn
and FAlive
then
2015 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
2017 if FTeam
= TEAM_RED
then
2019 ChangeTeam(TEAM_BLUE
);
2020 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
2021 if g_Game_IsNet
then
2022 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
2026 ChangeTeam(TEAM_RED
);
2027 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
2028 if g_Game_IsNet
then
2029 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
2031 FPreferredTeam
:= FTeam
;
2034 procedure TPlayer
.ChangeTeam(Team
: Byte);
2041 TEAM_RED
, TEAM_BLUE
:
2042 FModel
.Color
:= TEAMCOLOR
[Team
];
2044 FModel
.Color
:= FColor
;
2046 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2047 MH_SEND_PlayerStats(FUID
);
2051 procedure TPlayer.CollideItem();
2056 if gItems = nil then Exit;
2057 if not FAlive then Exit;
2059 for i := 0 to High(gItems) do
2062 if (ItemType <> ITEM_NONE) and alive then
2063 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2064 PLAYER_RECT.Height, @Obj) then
2066 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2068 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2069 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2070 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2071 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2072 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2074 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2075 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2076 (gGameSettings.GameType = GT_SINGLE) and
2077 (g_Player_GetCount() > 1)) then
2078 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2084 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2086 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2087 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2091 constructor TPlayer
.Create();
2097 mEDamageType
:= HIT_SOME
;
2103 FSawSound
:= TPlayableSound
.Create();
2104 FSawSoundIdle
:= TPlayableSound
.Create();
2105 FSawSoundHit
:= TPlayableSound
.Create();
2106 FSawSoundSelect
:= TPlayableSound
.Create();
2107 FJetSoundFly
:= TPlayableSound
.Create();
2108 FJetSoundOn
:= TPlayableSound
.Create();
2109 FJetSoundOff
:= TPlayableSound
.Create();
2111 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2112 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2113 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2114 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2115 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2116 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2117 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2119 FSpectatePlayer
:= -1;
2123 FSavedState
.WaitRecall
:= False;
2129 FActualModelName
:= 'doomer';
2132 FObj
.Rect
:= PLAYER_RECT
;
2134 FBFGFireCounter
:= -1;
2135 FJustTeleported
:= False;
2139 releaseAllWeaponSwitchKeys();
2143 procedure TPlayer
.releaseAllWeaponSwitchKeys ();
2147 for f
:= 0 to High(weaponSwitchKeyReleased
) do weaponSwitchKeyReleased
[f
] := $03;
2150 procedure TPlayer
.weaponSwitchKeysStateChange (index
: Integer; pressed
: Boolean);
2152 Inc(index
, 2); // -2: prev; -1: next
2153 if (index
< 0) or (index
> High(weaponSwitchKeyReleased
)) then exit
;
2154 weaponSwitchKeyReleased
[index
] := weaponSwitchKeyReleased
[index
] or $02;
2155 if (pressed
) then weaponSwitchKeyReleased
[index
] := weaponSwitchKeyReleased
[index
] xor $02;
2158 function TPlayer
.isWeaponSwitchKeyReleased (index
: Integer): Boolean;
2160 Inc(index
, 2); // -2: prev; -1: next
2161 if (index
< 0) or (index
> High(weaponSwitchKeyReleased
)) then
2167 result
:= (weaponSwitchKeyReleased
[index
] and $01) <> 0;
2171 procedure TPlayer
.weaponSwitchKeysShiftNewStates ();
2175 // copy bit 1 to bit 0
2176 for f
:= 0 to High(weaponSwitchKeyReleased
) do
2178 weaponSwitchKeyReleased
[f
] :=
2179 (weaponSwitchKeyReleased
[f
] and $02) or
2180 ((weaponSwitchKeyReleased
[f
] shr 1) and $01);
2185 procedure TPlayer
.positionChanged (); inline;
2189 procedure TPlayer
.doDamage (v
: Integer);
2191 if (v
<= 0) then exit
;
2192 if (v
> 32767) then v
:= 32767;
2193 Damage(v
, 0, 0, 0, mEDamageType
);
2196 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2200 if (not g_Game_IsClient
) and (not FAlive
) then
2205 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2206 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2208 if not g_Game_IsClient
then
2211 if t
= HIT_TRAP
then
2213 // Ëîâóøêà óáèâàåò ñðàçó:
2215 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2217 if t
= HIT_SELF
then
2221 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2224 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2225 FMegaRulez
[MR_SUIT
] := 0;
2226 FMegaRulez
[MR_INVUL
] := 0;
2227 FMegaRulez
[MR_INVIS
] := 0;
2231 // Íî îò îñòàëüíîãî ñïàñàåò:
2232 if FMegaRulez
[MR_INVUL
] >= gTime
then
2239 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2240 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2241 (SpawnerUID
= FUID
) or
2242 (not SameTeam(FUID
, SpawnerUID
)) then
2244 FLastSpawnerUID
:= SpawnerUID
;
2246 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2247 if gBloodCount
> 0 then
2249 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2250 if value
div 4 <= c
then
2251 c
:= c
- (value
div 4)
2255 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2259 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2260 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2263 if t
= HIT_WATER
then
2264 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2265 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2270 Inc(FDamageBuffer
, value
);
2274 FPain
:= FPain
+ value
;
2277 if g_Game_IsServer
and g_Game_IsNet
then
2279 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2280 MH_SEND_PlayerStats(FUID
);
2281 MH_SEND_PlayerPos(False, FUID
);
2285 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2288 if g_Game_IsClient
then
2293 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2295 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2298 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2300 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2304 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2305 MH_SEND_PlayerStats(FUID
);
2308 destructor TPlayer
.Destroy();
2310 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2312 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2316 FSawSoundIdle
.Free();
2317 FSawSoundHit
.Free();
2318 FJetSoundFly
.Free();
2320 FJetSoundOff
.Free();
2322 if FPunchAnim
<> nil then
2328 procedure TPlayer
.DrawBubble();
2330 bubX
, bubY
: Integer;
2333 Rw
, Gw
, Bw
: SmallInt;
2336 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= TDirection
.D_LEFT
, -4, 18);
2337 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2345 1: // simple textual non-bubble
2347 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2348 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2349 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2352 2: // advanced pixel-perfect bubble
2354 if FTeam
= TEAM_RED
then
2357 if FTeam
= TEAM_BLUE
then
2360 3: // colored bubble
2362 Rb
:= FModel
.Color
.R
;
2363 Gb
:= FModel
.Color
.G
;
2364 Bb
:= FModel
.Color
.B
;
2365 Rw
:= Min(Rb
* 2 + 64, 255);
2366 Gw
:= Min(Gb
* 2 + 64, 255);
2367 Bw
:= Min(Bb
* 2 + 64, 255);
2368 if (Abs(Rw
- Rb
) < 32)
2369 or (Abs(Gw
- Gb
) < 32)
2370 or (Abs(Bw
- Bb
) < 32) then
2372 Rb
:= Max(Rw
div 2 - 16, 0);
2373 Gb
:= Max(Gw
div 2 - 16, 0);
2374 Bb
:= Max(Bw
div 2 - 16, 0);
2377 4: // custom textured bubble
2379 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2380 if FDirection
= TDirection
.D_RIGHT
then
2381 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2383 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, TMirrorType
.Horizontal
);
2389 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2390 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2392 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2395 Dot
:= IfThen(FDirection
= TDirection
.D_LEFT
, 14, 5);
2396 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2397 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
);
2398 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
);
2399 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
);
2400 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
);
2404 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2405 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2406 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2409 procedure TPlayer
.Draw();
2414 Mirror
: TMirrorType
;
2418 if Direction
= TDirection
.D_RIGHT
then
2419 Mirror
:= TMirrorType
.None
2421 Mirror
:= TMirrorType
.Horizontal
;
2423 if FPunchAnim
<> nil then
2425 FPunchAnim
.Draw(FObj
.X
+IfThen(Direction
= TDirection
.D_LEFT
, 15-FObj
.Rect
.X
, FObj
.Rect
.X
-15),
2426 FObj
.Y
+FObj
.Rect
.Y
-11, Mirror
);
2427 if FPunchAnim
.played
then
2434 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2435 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2437 e_GetTextureSize(ID
, @w
, @h
);
2438 if FDirection
= TDirection
.D_LEFT
then
2439 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2440 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False)
2442 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2443 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False);
2446 if FMegaRulez
[MR_INVIS
] > gTime
then
2448 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2449 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2451 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2452 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2456 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 200)
2458 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2461 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 254);
2464 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2467 if g_debug_Frames
then
2469 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2471 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2472 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2476 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2478 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2479 if gAimLine
and alive
and
2480 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2485 procedure TPlayer
.DrawAim();
2486 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2491 {$IFDEF ENABLE_HOLMES}
2492 if isValidViewPort
and (self
= gPlayer1
) then
2494 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2498 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2499 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2501 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2505 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2510 wx
, wy
, xx
, yy
: Integer;
2514 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= TDirection
.D_LEFT
, 7, -7);
2515 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2524 1: begin // Chainsaw
2531 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2532 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2533 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2534 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2539 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2540 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2541 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2542 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2544 4: begin // Double Shotgun
2547 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2548 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2549 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2550 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2552 5: begin // Chaingun
2555 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2556 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2557 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2558 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2560 6: begin // Rocket Launcher
2563 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2564 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2565 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2566 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2568 7: begin // Plasmagun
2571 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2572 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2573 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2574 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2579 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2580 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2581 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2582 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2584 9: begin // Super Chaingun
2587 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2588 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2589 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2590 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2593 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2594 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2595 {$IF DEFINED(D2F_DEBUG)}
2596 drawCast(sz
, wx
, wy
, xx
, yy
);
2598 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2602 procedure TPlayer
.DrawGUI();
2605 X
, Y
, SY
, a
, p
, m
: Integer;
2609 stat
: TPlayerStatArray
;
2611 X
:= gPlayerScreenSize
.X
;
2612 SY
:= gPlayerScreenSize
.Y
;
2615 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2617 if gGameSettings
.GameMode
= GM_CTF
then
2621 if gGameSettings
.GameMode
= GM_CTF
then
2623 s
:= 'TEXTURE_PLAYER_REDFLAG';
2624 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2625 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2626 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2627 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2628 if g_Texture_Get(s
, ID
) then
2629 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2632 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2633 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2634 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2636 if gGameSettings
.GameMode
= GM_CTF
then
2638 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2639 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2640 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2641 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2642 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2643 if g_Texture_Get(s
, ID
) then
2644 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2647 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2648 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2649 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2652 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2653 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2656 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2657 e_Draw(ID
, X
+2, Y
, 0, True, False);
2659 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2663 s
:= IntToStr(Frags
);
2664 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2665 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2670 stat
:= g_Player_GetStats();
2675 for a
:= 0 to High(stat
) do
2676 if stat
[a
].Name
<> Name
then
2678 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2679 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2683 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2684 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2685 s
:= s
+IntToStr(Abs(Frags
-m
));
2687 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2688 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2691 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2693 s
:= IntToStr(Lives
);
2694 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2695 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2699 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2700 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2702 if R_BERSERK
in FRulez
then
2703 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2705 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2707 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2708 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2710 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2711 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2712 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2714 s
:= IntToStr(FArmor
);
2715 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2716 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2718 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2724 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2729 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2731 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2732 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2733 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2734 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2735 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2736 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2737 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2738 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2739 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2742 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2743 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2744 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2746 if R_KEY_RED
in FRulez
then
2747 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2749 if R_KEY_GREEN
in FRulez
then
2750 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2752 if R_KEY_BLUE
in FRulez
then
2753 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2755 if FJetFuel
> 0 then
2757 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2758 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2759 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2760 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2761 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2762 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2766 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2767 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2768 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2771 if gShowPing
and g_Game_IsClient
then
2773 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2774 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2780 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2781 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2782 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2785 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2786 s
:= _lc
[I_PLAYER_SPECT4
];
2787 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2788 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2789 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2795 procedure TPlayer
.DrawRulez();
2799 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2800 if FMegaRulez
[MR_INVUL
] >= gTime
then
2802 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2803 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2808 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2809 191, 191, 191, 0, TBlending
.Invert
);
2812 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2813 if FMegaRulez
[MR_SUIT
] >= gTime
then
2815 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2816 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2821 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2822 0, 96, 0, 200, TBlending
.None
);
2825 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2826 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2828 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2829 255, 0, 0, 200, TBlending
.None
);
2833 procedure TPlayer
.DrawPain();
2837 if FPain
= 0 then Exit
;
2841 if a
< 15 then h
:= 0
2842 else if a
< 35 then h
:= 1
2843 else if a
< 55 then h
:= 2
2844 else if a
< 75 then h
:= 3
2845 else if a
< 95 then h
:= 4
2848 //if a > 255 then a := 255;
2850 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2851 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2854 procedure TPlayer
.DrawPickup();
2858 if FPickup
= 0 then Exit
;
2862 if a
< 15 then h
:= 1
2863 else if a
< 35 then h
:= 2
2864 else if a
< 55 then h
:= 3
2865 else if a
< 75 then h
:= 4
2868 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2871 procedure TPlayer
.DoPunch();
2876 if FPunchAnim
<> nil then begin
2881 st
:= 'FRAMES_PUNCH';
2882 if R_BERSERK
in FRulez
then
2883 st
:= st
+ '_BERSERK';
2884 if FKeys
[KEY_UP
].Pressed
then
2886 else if FKeys
[KEY_DOWN
].Pressed
then
2888 g_Frames_Get(id
, st
);
2889 FPunchAnim
:= TAnimation
.Create(id
, False, 1);
2892 procedure TPlayer
.Fire();
2894 f
, DidFire
: Boolean;
2895 wx
, wy
, xd
, yd
: Integer;
2898 if g_Game_IsClient
then Exit
;
2899 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2900 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2908 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2913 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2914 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2915 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
2916 yd
:= wy
+firediry();
2922 if R_BERSERK
in FRulez
then
2924 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2925 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2926 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2929 locobj
.rect
.Width
:= 39;
2930 locobj
.rect
.Height
:= 52;
2931 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2932 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2933 locobj
.Accel
.X
:= xd
-wx
;
2934 locobj
.Accel
.y
:= yd
-wy
;
2936 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2937 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2939 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2941 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
2945 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2949 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2954 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2955 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2957 FSawSoundSelect
.Stop();
2959 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2961 else if not FSawSoundHit
.IsPlaying() then
2963 FSawSoundSelect
.Stop();
2964 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2967 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2973 if FAmmo
[A_BULLETS
] > 0 then
2975 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2976 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2977 Dec(FAmmo
[A_BULLETS
]);
2978 FFireAngle
:= FAngle
;
2981 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2982 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2986 if FAmmo
[A_SHELLS
] > 0 then
2988 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2989 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
2990 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2991 Dec(FAmmo
[A_SHELLS
]);
2992 FFireAngle
:= FAngle
;
2996 FShellType
:= SHELL_SHELL
;
3000 if FAmmo
[A_SHELLS
] >= 2 then
3002 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
3003 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3004 Dec(FAmmo
[A_SHELLS
], 2);
3005 FFireAngle
:= FAngle
;
3009 FShellType
:= SHELL_DBLSHELL
;
3013 if FAmmo
[A_BULLETS
] > 0 then
3015 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
3016 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
3017 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3018 Dec(FAmmo
[A_BULLETS
]);
3019 FFireAngle
:= FAngle
;
3022 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3023 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3026 WEAPON_ROCKETLAUNCHER
:
3027 if FAmmo
[A_ROCKETS
] > 0 then
3029 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
3030 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3031 Dec(FAmmo
[A_ROCKETS
]);
3032 FFireAngle
:= FAngle
;
3038 if FAmmo
[A_CELLS
] > 0 then
3040 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
3041 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3042 Dec(FAmmo
[A_CELLS
]);
3043 FFireAngle
:= FAngle
;
3049 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
3051 FBFGFireCounter
:= 17;
3052 if not FNoReload
then
3053 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
3054 Dec(FAmmo
[A_CELLS
], 40);
3058 WEAPON_SUPERPULEMET
:
3059 if FAmmo
[A_SHELLS
] > 0 then
3061 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3062 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
3063 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3064 Dec(FAmmo
[A_SHELLS
]);
3065 FFireAngle
:= FAngle
;
3068 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3069 GameVelX
, GameVelY
-2, SHELL_SHELL
);
3072 WEAPON_FLAMETHROWER
:
3073 if FAmmo
[A_FUEL
] > 0 then
3075 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
3076 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3078 FFireAngle
:= FAngle
;
3084 if g_Game_IsNet
then
3088 if FCurrWeap
<> WEAPON_BFG
then
3089 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
3091 if not FNoReload
then
3092 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
3095 MH_SEND_PlayerStats(FUID
);
3100 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
3101 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
3102 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
3105 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
3108 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
3109 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
3110 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
3111 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
3112 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
3117 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
3119 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
3120 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
3121 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
3124 procedure TPlayer
.JetpackOn
;
3128 FJetSoundOn
.SetPosition(0);
3129 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3133 procedure TPlayer
.JetpackOff
;
3137 FJetSoundOff
.SetPosition(0);
3138 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3141 procedure TPlayer
.CatchFire(Attacker
: Word);
3144 FFireAttacker
:= Attacker
;
3145 if g_Game_IsNet
and g_Game_IsServer
then
3146 MH_SEND_PlayerStats(FUID
);
3149 procedure TPlayer
.Jump();
3151 if gFly
or FJetpack
then
3153 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3154 if FObj
.Vel
.Y
> -VEL_FLY
then
3155 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3158 if FJetFuel
> 0 then
3160 if (FJetFuel
< 1) and g_Game_IsServer
then
3164 if g_Game_IsNet
then
3165 MH_SEND_PlayerStats(FUID
);
3171 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3173 FCanJetpack
:= False;
3175 // Ïðûãàåì èëè âñïëûâàåì:
3176 if (CollideLevel(0, 1) or
3177 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3178 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3179 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3181 FObj
.Vel
.Y
:= -VEL_JUMP
;
3182 FCanJetpack
:= False;
3186 if BodyInLiquid(0, 0) then
3187 FObj
.Vel
.Y
:= -VEL_SW
3188 else if (FJetFuel
> 0) and FCanJetpack
and
3189 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3193 if g_Game_IsNet
then
3194 MH_SEND_PlayerStats(FUID
);
3199 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3201 a
, i
, k
, ab
, ar
: Byte;
3205 srv
, netsrv
: Boolean;
3211 procedure PushItem(t
: Byte);
3215 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3216 it
:= g_Items_ByIdx(id
);
3217 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3219 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3220 (FObj
.Vel
.Y
div 2)-Random(9));
3221 it
.positionChanged(); // this updates spatial accelerators
3225 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3227 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3228 (FObj
.Vel
.Y
div 2)-Random(6));
3230 else // -3..+3; -3..0
3232 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3233 (FObj
.Vel
.Y
div 2)-Random(4));
3235 it
.positionChanged(); // this updates spatial accelerators
3238 if g_Game_IsNet
and g_Game_IsServer
then
3239 MH_SEND_ItemSpawn(True, id
);
3243 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3244 Srv
:= g_Game_IsServer
;
3245 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3246 if Srv
then FDeath
:= FDeath
+ 1;
3251 if not FPhysics
then
3257 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3259 if FLives
> 0 then FLives
:= FLives
- 1;
3260 if FLives
= 0 then FNoRespawn
:= True;
3263 // Íîìåð òèïà ñìåðòè:
3266 K_SIMPLEKILL
: a
:= 1;
3268 K_EXTRAHARDKILL
: a
:= 3;
3273 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3275 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3282 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3284 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3285 K_EXTRAHARDKILL
, K_FALLKILL
:
3286 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3289 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3293 K_HARDKILL
, K_EXTRAHARDKILL
:
3297 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3298 if (KillType
<> K_FALLKILL
) and (Srv
) then
3299 g_Monsters_killedp();
3301 if SpawnerUID
= FUID
then
3303 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3308 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3311 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3312 begin // Óáèò äðóãèì èãðîêîì
3313 KP
:= g_Player_Get(SpawnerUID
);
3314 if (KP
<> nil) and Srv
then
3316 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3317 if SameTeam(FUID
, SpawnerUID
) then
3327 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3328 Inc(gTeamStat
[KP
.Team
].Goals
,
3329 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3331 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3334 plr
:= g_Player_Get(SpawnerUID
);
3342 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3346 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3350 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3355 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3356 begin // Óáèò ìîíñòðîì
3357 mon
:= g_Monsters_ByUID(SpawnerUID
);
3361 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
3365 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3369 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3373 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3378 else // Îñîáûå òèïû ñìåðòè
3381 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3382 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3383 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3384 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3385 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3386 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3392 for a
:= WP_FIRST
to WP_LAST
do
3396 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3397 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3398 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3399 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3400 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3401 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3402 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3403 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3404 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3413 if R_ITEM_BACKPACK
in FRulez
then
3414 PushItem(ITEM_AMMO_BACKPACK
);
3416 // Âûáðîñ ðàêåòíîãî ðàíöà:
3417 if FJetFuel
> 0 then
3418 PushItem(ITEM_JETPACK
);
3421 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3423 if R_KEY_RED
in FRulez
then
3424 PushItem(ITEM_KEY_RED
);
3426 if R_KEY_GREEN
in FRulez
then
3427 PushItem(ITEM_KEY_GREEN
);
3429 if R_KEY_BLUE
in FRulez
then
3430 PushItem(ITEM_KEY_BLUE
);
3437 g_Player_CreateCorpse(Self
);
3439 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3440 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3446 for i
:= Low(gPlayers
) to High(gPlayers
) do
3448 if gPlayers
[i
] = nil then continue
;
3449 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3452 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3453 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3458 OldLR
:= gLMSRespawn
;
3459 if (gGameSettings
.GameMode
= GM_COOP
) then
3463 // everyone is dead, restart the map
3464 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3466 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3467 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3468 gLMSRespawnTime
:= gTime
+ 5000;
3470 else if (a
= 1) then
3472 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3473 if (gPlayers
[k
] = gPlayer1
) or
3474 (gPlayers
[k
] = gPlayer2
) then
3475 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3476 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3477 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3480 else if (gGameSettings
.GameMode
= GM_TDM
) then
3482 if (ab
= 0) and (ar
<> 0) then
3485 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3487 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3488 Inc(gTeamStat
[TEAM_RED
].Goals
);
3489 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3490 gLMSRespawnTime
:= gTime
+ 5000;
3492 else if (ar
= 0) and (ab
<> 0) then
3495 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3497 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3498 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3499 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3500 gLMSRespawnTime
:= gTime
+ 5000;
3502 else if (ar
= 0) and (ab
= 0) then
3505 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3507 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3508 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3509 gLMSRespawnTime
:= gTime
+ 5000;
3512 else if (gGameSettings
.GameMode
= GM_DM
) then
3516 if gPlayers
[k
] <> nil then
3519 // survivor is the winner
3520 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3522 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3525 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3526 gLMSRespawnTime
:= gTime
+ 5000;
3528 else if (a
= 0) then
3530 // everyone is dead, restart the map
3531 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3533 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3534 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3535 gLMSRespawnTime
:= gTime
+ 5000;
3538 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3540 if NetMode
= NET_SERVER
then
3541 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3543 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3549 MH_SEND_PlayerStats(FUID
);
3550 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3551 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3554 if srv
and FNoRespawn
then Spectate(True);
3555 FWantsInGame
:= True;
3558 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3560 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3561 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3564 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3566 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3567 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3570 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3572 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3573 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3574 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3575 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3576 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3577 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3578 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3579 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3582 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3584 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3585 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3586 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3587 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3590 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3592 if g_Game_IsClient
then Exit
;
3593 if Weapon
> High(FWeapon
) then Exit
;
3594 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3597 procedure TPlayer
.resetWeaponQueue ();
3600 FNextWeapDelay
:= 0;
3603 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3607 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3608 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
3609 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
3610 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3611 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3612 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3613 else result
:= (weapon
< length(FWeapon
));
3617 // return 255 for "no switch"
3618 function TPlayer
.getNextWeaponIndex (): Byte;
3621 wantThisWeapon
: array[0..64] of Boolean;
3622 weaponOrder
: array[0..16] of Integer; // value: index in `FWeapon`
3624 f
, dir
, cwi
, rwidx
, curlidx
: Integer;
3626 function real2log (ridx
: Integer): Integer;
3632 for f
:= 0 to High(weaponOrder
) do if (weaponOrder
[f
] = ridx
) then begin result
:= f
; exit
; end;
3638 result
:= 255; // default result: "no switch"
3640 // had weapon cycling on previous frame? remove that flag
3641 if (FNextWeap
and $2000) <> 0 then
3643 FNextWeap
:= FNextWeap
and $1FFF;
3644 FNextWeapDelay
:= 0;
3647 for f
:= 0 to High(weaponOrder
) do weaponOrder
[f
] := -1;
3649 // build weapon order (k8: i know, i know, learn how to do constants and such... gtfo, please!)
3650 // two knuckles are for "normal" and "berserk" (see `if` below -- it removes the one that is not needed)
3652 // bfg, launcher, plasma, flamethrower, ssg, minigun, sg, pistol, berserk, chainsaw, fist
3653 weaponOrder
[0] := WEAPON_SUPERPULEMET
;
3654 weaponOrder
[1] := WEAPON_BFG
;
3655 weaponOrder
[2] := WEAPON_ROCKETLAUNCHER
;
3656 weaponOrder
[3] := WEAPON_PLASMA
;
3657 weaponOrder
[4] := WEAPON_FLAMETHROWER
;
3658 weaponOrder
[5] := WEAPON_SHOTGUN2
;
3659 weaponOrder
[6] := WEAPON_CHAINGUN
;
3660 weaponOrder
[7] := WEAPON_SHOTGUN1
;
3661 weaponOrder
[8] := WEAPON_PISTOL
;
3662 weaponOrder
[9] := WEAPON_KASTET
+666; // berserk fist
3663 weaponOrder
[10] := WEAPON_SAW
;
3664 weaponOrder
[11] := WEAPON_KASTET
; // normal fist
3666 for f
:= 0 to High(weaponOrder
) do
3668 if (weaponOrder
[f
] = WEAPON_KASTET
) then
3670 // normal fist: remove if we have a berserk pack
3671 if (R_BERSERK
in FRulez
) then weaponOrder
[f
] := -1;
3674 if (weaponOrder
[f
] = WEAPON_KASTET
+666) then
3676 // berserk fist: remove if we don't have a berserk pack
3677 if (R_BERSERK
in FRulez
) then weaponOrder
[f
] := WEAPON_KASTET
else weaponOrder
[f
] := -1;
3685 WEAPON_SHOTGUN1 = 3;
3686 WEAPON_SHOTGUN2 = 4;
3687 WEAPON_CHAINGUN = 5;
3688 WEAPON_ROCKETLAUNCHER = 6;
3691 WEAPON_SUPERPULEMET = 9;
3692 WEAPON_FLAMETHROWER = 10;
3695 // cycling has priority
3696 if (FNextWeap
and $C000) <> 0 then
3698 if (FNextWeap
and $8000) <> 0 then dir
:= 1 else dir
:= -1; // should be reversed if we want "priority-driven cycling"
3699 FNextWeap
:= FNextWeap
or $2000; // we need this
3700 if FNextWeapDelay
> 0 then exit
; // cooldown time
3701 //cwi := real2log(FCurrWeap);
3702 //if (cwi < 0) then cwi := 0;
3704 for i
:= 0 to High(FWeapon
) do
3706 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3707 //rwidx := weaponOrder[cwi];
3708 rwidx
:= cwi
; // sorry
3709 if (rwidx
< 0) then continue
;
3710 if FWeapon
[rwidx
] then
3712 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d (dir=%d; log=%d)', [FCurrWeap, rwidx, dir, cwi]), TMsgType.Warning);
3713 result
:= Byte(rwidx
);
3714 //FNextWeapDelay := 10; //k8: not needed anymore
3723 for i
:= 0 to High(wantThisWeapon
) do wantThisWeapon
[i
] := false;
3726 curlidx
:= -1; // start from a weapon with a highest priority (-1, 'cause loop will immediately increment this index)
3728 for i
:= 0 to High(FWeapon
) do
3730 if (FNextWeap
and (1 shl i
)) <> 0 then
3735 wantThisWeapon
[cwi
] := true;
3737 // if we hit currently selected weapon, start seachring from it, so we'll get "next weaker" weapon
3738 if (i
= FCurrWeap
) then curlidx
:= cwi
; // compare real, start from logical
3743 // slow down alterations a little
3746 // more than one weapon requested, assume "alteration", and check alteration delay
3747 if FNextWeapDelay
> 0 then
3749 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), TMsgType.Warning);
3755 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3756 // but clear all counters if no weapon should be switched
3763 //e_WriteLog(Format('*** wwc=%d; currweap=%d; logweap=%d', [wwc, FCurrWeap, curlidx]), TMsgType.Warning);
3765 // find next weapon to switch onto
3767 for i
:= 0 to High(weaponOrder
) do
3769 cwi
:= (cwi
+length(weaponOrder
)+1) mod length(weaponOrder
);
3770 if (cwi
= curlidx
) then continue
; // skip current weapon
3771 if not wantThisWeapon
[cwi
] then continue
;
3772 rwidx
:= weaponOrder
[cwi
];
3773 if (rwidx
< 0) then continue
;
3774 //e_WriteLog(Format(' trying logical %d (real %d); has=%d, hasammo=%d', [cwi, rwidx, Integer(FWeapon[rwidx]), Integer(hasAmmoForWeapon(rwidx))]), TMsgType.Warning);
3775 if FWeapon
[rwidx
] and ((wwc
= 1) or hasAmmoForWeapon(rwidx
)) then
3777 //e_WriteLog(' I FOUND HER!', TMsgType.Warning);
3779 result
:= Byte(rwidx
);
3781 //FNextWeapDelay := 10; // anyway, 'cause why not; k8: not needed anymore
3786 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3790 procedure TPlayer
.RealizeCurrentWeapon();
3791 function switchAllowed (): Boolean;
3796 if FBFGFireCounter
<> -1 then
3798 if FTime
[T_SWITCH
] > gTime
then
3800 for i
:= WP_FIRST
to WP_LAST
do
3801 if FReloading
[i
] > 0 then
3809 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3810 //FNextWeap := FNextWeap and $1FFF;
3811 //HACK: alteration delay will be reset when player released any weapon switch key
3812 FNextWeapDelay
:= 0; //k8: just in case
3813 //if FNextWeapDelay > 0 then Dec(FNextWeapDelay); // "alteration delay"
3815 if not switchAllowed
then
3817 //HACK for weapon cycling
3818 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3822 nw
:= getNextWeaponIndex();
3823 if nw
= 255 then exit
; // don't reset anything here
3824 if nw
> High(FWeapon
) then
3826 // don't forget to reset queue here!
3827 //e_WriteLog(Format(' RealizeCurrentWeapon: WUTAFUUUU?! (%d)', [nw]), TMsgType.Warning);
3835 FTime
[T_SWITCH
] := gTime
+156;
3836 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3837 FModel
.SetWeapon(FCurrWeap
);
3838 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3842 procedure TPlayer
.NextWeapon();
3844 if g_Game_IsClient
then Exit
;
3848 procedure TPlayer
.PrevWeapon();
3850 if g_Game_IsClient
then Exit
;
3854 procedure TPlayer
.SetWeapon(W
: Byte);
3856 if FCurrWeap
<> W
then
3857 if W
= WEAPON_SAW
then
3858 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3861 FModel
.SetWeapon(CurrWeap
);
3865 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3867 function allowBerserkSwitching (): Boolean;
3869 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3871 if gBerserkAutoswitch
then exit
;
3872 if not conIsCheatsEnabled
then exit
;
3880 if g_Game_IsClient
then Exit
;
3882 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3883 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3888 if FHealth
< PLAYER_HP_SOFT
then
3890 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3894 if gFlash
= 2 then Inc(FPickup
, 5);
3898 if FHealth
< PLAYER_HP_SOFT
then
3900 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3904 if gFlash
= 2 then Inc(FPickup
, 5);
3908 if FArmor
< PLAYER_AP_SOFT
then
3910 FArmor
:= PLAYER_AP_SOFT
;
3913 if gFlash
= 2 then Inc(FPickup
, 5);
3917 if FArmor
< PLAYER_AP_LIMIT
then
3919 FArmor
:= PLAYER_AP_LIMIT
;
3922 if gFlash
= 2 then Inc(FPickup
, 5);
3926 if FHealth
< PLAYER_HP_LIMIT
then
3928 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3932 if gFlash
= 2 then Inc(FPickup
, 5);
3936 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3938 if FHealth
< PLAYER_HP_LIMIT
then
3939 FHealth
:= PLAYER_HP_LIMIT
;
3940 if FArmor
< PLAYER_AP_LIMIT
then
3941 FArmor
:= PLAYER_AP_LIMIT
;
3945 if gFlash
= 2 then Inc(FPickup
, 5);
3949 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3951 FWeapon
[WEAPON_SAW
] := True;
3953 if gFlash
= 2 then Inc(FPickup
, 5);
3954 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3957 ITEM_WEAPON_SHOTGUN1
:
3958 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3960 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3961 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3963 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3964 FWeapon
[WEAPON_SHOTGUN1
] := True;
3966 if gFlash
= 2 then Inc(FPickup
, 5);
3967 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3970 ITEM_WEAPON_SHOTGUN2
:
3971 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3973 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3975 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3976 FWeapon
[WEAPON_SHOTGUN2
] := True;
3978 if gFlash
= 2 then Inc(FPickup
, 5);
3979 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3982 ITEM_WEAPON_CHAINGUN
:
3983 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3985 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3987 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3988 FWeapon
[WEAPON_CHAINGUN
] := True;
3990 if gFlash
= 2 then Inc(FPickup
, 5);
3991 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3994 ITEM_WEAPON_ROCKETLAUNCHER
:
3995 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3997 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3999 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
4000 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
4002 if gFlash
= 2 then Inc(FPickup
, 5);
4003 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4007 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
4009 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
4011 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4012 FWeapon
[WEAPON_PLASMA
] := True;
4014 if gFlash
= 2 then Inc(FPickup
, 5);
4015 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4019 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
4021 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
4023 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4024 FWeapon
[WEAPON_BFG
] := True;
4026 if gFlash
= 2 then Inc(FPickup
, 5);
4027 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4030 ITEM_WEAPON_SUPERPULEMET
:
4031 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
4033 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
4035 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4036 FWeapon
[WEAPON_SUPERPULEMET
] := True;
4038 if gFlash
= 2 then Inc(FPickup
, 5);
4039 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4042 ITEM_WEAPON_FLAMETHROWER
:
4043 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
4045 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
4047 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4048 FWeapon
[WEAPON_FLAMETHROWER
] := True;
4050 if gFlash
= 2 then Inc(FPickup
, 5);
4051 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4055 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4057 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4060 if gFlash
= 2 then Inc(FPickup
, 5);
4063 ITEM_AMMO_BULLETS_BOX
:
4064 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4066 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4069 if gFlash
= 2 then Inc(FPickup
, 5);
4073 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4075 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4078 if gFlash
= 2 then Inc(FPickup
, 5);
4081 ITEM_AMMO_SHELLS_BOX
:
4082 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4084 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
4087 if gFlash
= 2 then Inc(FPickup
, 5);
4091 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4093 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4096 if gFlash
= 2 then Inc(FPickup
, 5);
4099 ITEM_AMMO_ROCKET_BOX
:
4100 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4102 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
4105 if gFlash
= 2 then Inc(FPickup
, 5);
4109 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4111 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4114 if gFlash
= 2 then Inc(FPickup
, 5);
4118 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4120 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4123 if gFlash
= 2 then Inc(FPickup
, 5);
4127 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4129 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4132 if gFlash
= 2 then Inc(FPickup
, 5);
4136 if not(R_ITEM_BACKPACK
in FRulez
) or
4137 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4138 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4139 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4140 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4141 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
4143 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4144 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4145 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4146 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4147 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4149 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4150 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4151 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4152 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4153 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4154 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4155 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4156 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4158 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
4161 if gFlash
= 2 then Inc(FPickup
, 5);
4165 if not(R_KEY_RED
in FRulez
) then
4167 Include(FRulez
, R_KEY_RED
);
4169 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4170 if gFlash
= 2 then Inc(FPickup
, 5);
4171 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4175 if not(R_KEY_GREEN
in FRulez
) then
4177 Include(FRulez
, R_KEY_GREEN
);
4179 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4180 if gFlash
= 2 then Inc(FPickup
, 5);
4181 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4185 if not(R_KEY_BLUE
in FRulez
) then
4187 Include(FRulez
, R_KEY_BLUE
);
4189 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4190 if gFlash
= 2 then Inc(FPickup
, 5);
4191 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4195 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4197 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4201 if gFlash
= 2 then Inc(FPickup
, 5);
4205 if FAir
< AIR_MAX
then
4210 if gFlash
= 2 then Inc(FPickup
, 5);
4215 if not (R_BERSERK
in FRulez
) then
4217 Include(FRulez
, R_BERSERK
);
4218 if allowBerserkSwitching
then
4220 FCurrWeap
:= WEAPON_KASTET
;
4222 FModel
.SetWeapon(WEAPON_KASTET
);
4227 if gFlash
= 2 then Inc(FPickup
, 5);
4229 FBerserk
:= gTime
+30000;
4233 //k8:do we need it? if g_Game_IsNet and g_Game_IsServer then MH_SEND_PlayerStats(FUID);
4235 if FHealth
< PLAYER_HP_SOFT
then
4237 FHealth
:= PLAYER_HP_SOFT
;
4238 FBerserk
:= gTime
+30000;
4246 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4248 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4251 if gFlash
= 2 then Inc(FPickup
, 5);
4255 if FHealth
< PLAYER_HP_LIMIT
then
4257 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4261 if gFlash
= 2 then Inc(FPickup
, 5);
4265 if FArmor
< PLAYER_AP_LIMIT
then
4267 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4270 if gFlash
= 2 then Inc(FPickup
, 5);
4274 if FJetFuel
< JET_MAX
then
4276 FJetFuel
:= JET_MAX
;
4279 if gFlash
= 2 then Inc(FPickup
, 5);
4283 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4285 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4288 if gFlash
= 2 then Inc(FPickup
, 5);
4293 procedure TPlayer
.Touch();
4297 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4300 // Áðîñèòü ôëàã òîâàðèùó:
4301 if gGameSettings
.GameMode
= GM_CTF
then
4306 procedure TPlayer
.Push(vx
, vy
: Integer);
4308 if (not FPhysics
) and FGhost
then
4310 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4311 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4312 if g_Game_IsNet
and g_Game_IsServer
then
4313 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4316 procedure TPlayer
.Reset(Force
: Boolean);
4322 FTime
[T_RESPAWN
] := 0;
4323 FTime
[T_FLAGCAP
] := 0;
4336 FSpectator
:= False;
4339 FSpectatePlayer
:= -1;
4340 FNoRespawn
:= False;
4342 FLives
:= gGameSettings
.MaxLives
;
4347 procedure TPlayer
.SoftReset();
4353 FBFGFireCounter
:= -1;
4361 SetAction(A_STAND
, True);
4364 function TPlayer
.GetRespawnPoint(): Byte;
4369 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4371 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4372 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4374 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4376 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4377 if Self
= gPlayer1
then
4378 c
:= RESPAWNPOINT_PLAYER1
4380 c
:= RESPAWNPOINT_PLAYER2
;
4381 if g_Map_GetPointCount(c
) > 0 then
4387 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4388 if Self
= gPlayer1
then
4389 c
:= RESPAWNPOINT_PLAYER2
4391 c
:= RESPAWNPOINT_PLAYER1
;
4392 if g_Map_GetPointCount(c
) > 0 then
4399 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4400 if Random(2) = 0 then
4401 c
:= RESPAWNPOINT_PLAYER1
4403 c
:= RESPAWNPOINT_PLAYER2
;
4404 if g_Map_GetPointCount(c
) > 0 then
4411 // Òî÷êà ëþáîé èç êîìàíä
4412 if Random(2) = 0 then
4413 c
:= RESPAWNPOINT_RED
4415 c
:= RESPAWNPOINT_BLUE
;
4416 if g_Map_GetPointCount(c
) > 0 then
4423 c
:= RESPAWNPOINT_DM
;
4424 if g_Map_GetPointCount(c
) > 0 then
4432 if gGameSettings
.GameMode
= GM_DM
then
4435 c
:= RESPAWNPOINT_DM
;
4436 if g_Map_GetPointCount(c
) > 0 then
4442 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4443 if Random(2) = 0 then
4444 c
:= RESPAWNPOINT_PLAYER1
4446 c
:= RESPAWNPOINT_PLAYER2
;
4447 if g_Map_GetPointCount(c
) > 0 then
4453 // Òî÷êà ëþáîé èç êîìàíä
4454 if Random(2) = 0 then
4455 c
:= RESPAWNPOINT_RED
4457 c
:= RESPAWNPOINT_BLUE
;
4458 if g_Map_GetPointCount(c
) > 0 then
4466 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4468 // Òî÷êà ñâîåé êîìàíäû
4469 c
:= RESPAWNPOINT_DM
;
4470 if FTeam
= TEAM_RED
then
4471 c
:= RESPAWNPOINT_RED
;
4472 if FTeam
= TEAM_BLUE
then
4473 c
:= RESPAWNPOINT_BLUE
;
4474 if g_Map_GetPointCount(c
) > 0 then
4481 c
:= RESPAWNPOINT_DM
;
4482 if g_Map_GetPointCount(c
) > 0 then
4488 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4489 if Random(2) = 0 then
4490 c
:= RESPAWNPOINT_PLAYER1
4492 c
:= RESPAWNPOINT_PLAYER2
;
4493 if g_Map_GetPointCount(c
) > 0 then
4499 // Òî÷êà äðóãîé êîìàíäû
4500 c
:= RESPAWNPOINT_DM
;
4501 if FTeam
= TEAM_RED
then
4502 c
:= RESPAWNPOINT_BLUE
;
4503 if FTeam
= TEAM_BLUE
then
4504 c
:= RESPAWNPOINT_RED
;
4505 if g_Map_GetPointCount(c
) > 0 then
4513 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4515 RespawnPoint
: TRespawnPoint
;
4521 FBFGFireCounter
:= -1;
4526 if not g_Game_IsServer
then
4530 FWantsInGame
:= True;
4531 FJustTeleported
:= True;
4534 FTime
[T_RESPAWN
] := 0;
4538 // if server changes MaxLives we gotta be ready
4539 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4541 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4542 if FTime
[T_RESPAWN
] > gTime
then
4545 // Ïðîñðàë âñå æèçíè:
4548 if not FSpectator
then Spectate(True);
4549 FWantsInGame
:= True;
4553 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4554 begin // "Ñâîÿ èãðà"
4555 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4556 FRulez
:= FRulez
-[R_BERSERK
];
4558 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4560 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4561 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4564 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4565 c
:= GetRespawnPoint();
4570 // Âîñêðåøåíèå áåç îðóæèÿ:
4573 FHealth
:= PLAYER_HP_SOFT
;
4579 for a
:= WP_FIRST
to WP_LAST
do
4581 FWeapon
[a
] := False;
4585 FWeapon
[WEAPON_PISTOL
] := True;
4586 FWeapon
[WEAPON_KASTET
] := True;
4587 FCurrWeap
:= WEAPON_PISTOL
;
4590 FModel
.SetWeapon(FCurrWeap
);
4592 for b
:= A_BULLETS
to A_HIGH
do
4595 FAmmo
[A_BULLETS
] := 50;
4597 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4598 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4599 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4600 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4601 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4603 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4604 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4609 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4610 if not g_Map_GetPoint(c
, RespawnPoint
) then
4612 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4616 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4617 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4618 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4624 FDirection
:= RespawnPoint
.Direction
;
4625 if FDirection
= TDirection
.D_LEFT
then
4630 SetAction(A_STAND
, True);
4631 FModel
.Direction
:= FDirection
;
4633 for a
:= Low(FTime
) to High(FTime
) do
4636 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4641 FCanJetpack
:= False;
4646 // Àíèìàöèÿ âîçðîæäåíèÿ:
4647 if (not gLoadGameMode
) and (not Silent
) then
4648 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4650 Anim
:= TAnimation
.Create(ID
, False, 3);
4651 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4652 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4656 FSpectator
:= False;
4659 FSpectatePlayer
:= -1;
4662 if (gPlayer1
= nil) and (gLMSPID1
= FUID
) then
4664 if (gPlayer2
= nil) and (gLMSPID2
= FUID
) then
4667 if g_Game_IsNet
then
4669 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4670 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4672 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4673 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4678 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4681 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4682 else if (not NoMove
) then
4684 GameX
:= gMapInfo
.Width
div 2;
4685 GameY
:= gMapInfo
.Height
div 2;
4694 FWantsInGame
:= False;
4699 if Self
= gPlayer1
then
4704 if Self
= gPlayer2
then
4711 if g_Game_IsNet
then
4712 MH_SEND_PlayerStats(FUID
);
4715 procedure TPlayer
.SwitchNoClip
;
4719 FGhost
:= not FGhost
;
4720 FPhysics
:= not FGhost
;
4732 procedure TPlayer
.Run(Direction
: TDirection
);
4736 if MAX_RUNVEL
> 8 then
4740 if Direction
= TDirection
.D_LEFT
then
4742 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4743 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4746 if FObj
.Vel
.X
< MAX_RUNVEL
then
4747 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4749 // Âîçìîæíî, ïèíàåì êóñêè:
4750 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4752 b
:= Abs(FObj
.Vel
.X
);
4753 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4754 for a
:= 0 to High(gGibs
) do
4756 if gGibs
[a
].alive
and
4757 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4758 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4761 if FObj
.Vel
.X
< 0 then
4763 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4767 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4769 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4777 procedure TPlayer
.SeeDown();
4779 SetAction(A_SEEDOWN
);
4781 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4783 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4786 procedure TPlayer
.SeeUp();
4790 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4792 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4795 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4803 A_ATTACK
: Prior
:= 2;
4804 A_SEEUP
: Prior
:= 1;
4805 A_SEEDOWN
: Prior
:= 1;
4806 A_ATTACKUP
: Prior
:= 2;
4807 A_ATTACKDOWN
: Prior
:= 2;
4812 if (Prior
> FActionPrior
) or Force
then
4813 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4815 FActionPrior
:= Prior
;
4816 FActionAnim
:= Action
;
4817 FActionForce
:= Force
;
4818 FActionChanged
:= True;
4821 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4824 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4826 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4827 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4828 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4829 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4832 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4839 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4841 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4842 if g_Game_IsServer
and g_Game_IsNet
then
4843 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4847 FJustTeleported
:= True;
4852 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4854 Anim
:= TAnimation
.Create(ID
, False, 3);
4857 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4858 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4859 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4860 if g_Game_IsServer
and g_Game_IsNet
then
4861 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4862 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4866 FObj
.X
:= X
-PLAYER_RECT
.X
;
4867 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4868 if FAlive
and FGhost
then
4874 if not g_Game_IsNet
then
4878 SetDirection(TDirection
.D_LEFT
);
4884 SetDirection(TDirection
.D_RIGHT
);
4890 if FDirection
= TDirection
.D_RIGHT
then
4892 SetDirection(TDirection
.D_LEFT
);
4897 SetDirection(TDirection
.D_RIGHT
);
4903 if not silent
and (Anim
<> nil) then
4905 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4906 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4909 if g_Game_IsServer
and g_Game_IsNet
then
4910 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4911 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4918 function nonz(a
: Single): Single;
4926 function TPlayer
.followCorpse(): Boolean;
4931 if FAlive
or FSpectator
then
4933 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
4935 for i
:= 0 to High(gCorpses
) do
4936 if gCorpses
[i
] <> nil then
4937 if gCorpses
[i
].FPlayerUID
= FUID
then
4940 FObj
.X
:= gCorpses
[i
].FObj
.X
;
4941 FObj
.Y
:= gCorpses
[i
].FObj
.Y
;
4942 FObj
.Vel
.X
:= gCorpses
[i
].FObj
.Vel
.X
;
4943 FObj
.Vel
.Y
:= gCorpses
[i
].FObj
.Vel
.Y
;
4944 FObj
.Accel
.X
:= gCorpses
[i
].FObj
.Accel
.X
;
4945 FObj
.Accel
.Y
:= gCorpses
[i
].FObj
.Accel
.Y
;
4950 procedure TPlayer
.Update();
4953 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4954 blockmon
, headwater
, dospawn
: Boolean;
4959 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4960 AnyServer
:= g_Game_IsServer
;
4962 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4963 DoLerp(NetInterpLevel
+ 1)
4969 if FClientID
>= 0 then
4971 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4972 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4973 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4982 if FAlive
and (FPunchAnim
<> nil) then
4983 FPunchAnim
.Update();
4985 if FAlive
and (gFly
or FJetpack
) then
4988 if FDirection
= TDirection
.D_LEFT
then
4993 if FAlive
and (not FGhost
) then
4995 if FKeys
[KEY_UP
].Pressed
then
4997 if FKeys
[KEY_DOWN
].Pressed
then
5001 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
5004 i
:= g_basic
.Sign(FIncCam
);
5005 FIncCam
:= Abs(FIncCam
);
5006 DecMin(FIncCam
, 5, 0);
5007 FIncCam
:= FIncCam
*i
;
5010 // no need to do that each second frame, weapon queue will take care of it
5011 if FAlive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
5012 if FAlive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
5014 if gTime
mod (GAME_TICK
*2) <> 0 then
5016 if (FObj
.Vel
.X
= 0) and FAlive
then
5018 if FKeys
[KEY_LEFT
].Pressed
then
5019 Run(TDirection
.D_LEFT
);
5020 if FKeys
[KEY_RIGHT
].Pressed
then
5021 Run(TDirection
.D_RIGHT
);
5026 if not followCorpse() then
5027 g_Obj_Move(@FObj
, True, True, True);
5028 positionChanged(); // this updates spatial accelerators
5034 FActionChanged
:= False;
5038 // Let alive player do some actions
5039 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
5040 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
5041 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
5042 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
5043 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
5044 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
5045 if FKeys
[KEY_JUMP
].Pressed
then Jump()
5048 if AnyServer
and FJetpack
then
5052 if NetServer
then MH_SEND_PlayerStats(FUID
);
5054 FCanJetpack
:= True;
5061 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
5063 if FKeys
[k
].Pressed
then
5071 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5074 if (FTime
[T_RESPAWN
] <= gTime
) and
5075 gGameOn
and (not FAlive
) then
5077 if (g_Player_GetCount() > 1) then
5081 gExit
:= EXIT_RESTART
;
5086 // Dead spectator actions
5089 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
5090 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
5094 if (FSpectatePlayer
>= High(gPlayers
)) then
5095 FSpectatePlayer
:= -1
5099 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
5100 if gPlayers
[I
] <> nil then
5101 if gPlayers
[I
].alive
then
5102 if gPlayers
[I
].UID
<> FUID
then
5104 FSpectatePlayer
:= I
;
5109 if not SetSpect
then FSpectatePlayer
:= -1;
5120 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5122 FYTo
:= FObj
.Y
- 32;
5123 FSpectatePlayer
:= -1;
5125 if FKeys
[KEY_DOWN
].Pressed
then
5127 FYTo
:= FObj
.Y
+ 32;
5128 FSpectatePlayer
:= -1;
5130 if FKeys
[KEY_LEFT
].Pressed
then
5132 FXTo
:= FObj
.X
- 32;
5133 FSpectatePlayer
:= -1;
5135 if FKeys
[KEY_RIGHT
].Pressed
then
5137 FXTo
:= FObj
.X
+ 32;
5138 FSpectatePlayer
:= -1;
5141 if (FXTo
< -64) then
5143 else if (FXTo
> gMapInfo
.Width
+ 32) then
5144 FXTo
:= gMapInfo
.Width
+ 32;
5145 if (FYTo
< -72) then
5147 else if (FYTo
> gMapInfo
.Height
+ 32) then
5148 FYTo
:= gMapInfo
.Height
+ 32;
5153 if not followCorpse() then
5154 g_Obj_Move(@FObj
, True, True, True);
5155 positionChanged(); // this updates spatial accelerators
5162 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5163 if gPlayers
[FSpectatePlayer
] <> nil then
5164 if gPlayers
[FSpectatePlayer
].alive
then
5166 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
5167 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
5171 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5172 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5173 PANEL_BLOCKMON
, True);
5174 headwater
:= HeadInLiquid(0, 0);
5176 // Ñîïðîòèâëåíèå âîçäóõà:
5177 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5178 if FObj
.Vel
.X
<> 0 then
5179 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5181 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5182 DecMin(FPain
, 5, 0);
5183 DecMin(FPickup
, 1, 0);
5185 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5187 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5188 FMegaRulez
[MR_SUIT
] := 0;
5189 FMegaRulez
[MR_INVUL
] := 0;
5190 FMegaRulez
[MR_INVIS
] := 0;
5191 Kill(K_FALLKILL
, 0, HIT_FALL
);
5198 if FCurrWeap
= WEAPON_SAW
then
5199 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5200 FSawSoundSelect
.IsPlaying()) then
5201 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5204 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5205 (not FJetSoundOff
.IsPlaying()) then
5207 FJetSoundFly
.SetPosition(0);
5208 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5211 for b
:= WP_FIRST
to WP_LAST
do
5212 if FReloading
[b
] > 0 then
5218 if FShellTimer
> -1 then
5219 if FShellTimer
= 0 then
5221 if FShellType
= SHELL_SHELL
then
5222 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5223 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5224 else if FShellType
= SHELL_DBLSHELL
then
5226 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5227 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5228 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5229 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5232 end else Dec(FShellTimer
);
5234 if (FBFGFireCounter
> -1) then
5235 if FBFGFireCounter
= 0 then
5239 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5240 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5241 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5242 yd
:= wy
+firediry();
5243 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5244 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5245 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5246 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5247 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5250 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5251 FBFGFireCounter
:= -1;
5254 FBFGFireCounter
:= 0
5256 Dec(FBFGFireCounter
);
5258 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5260 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5262 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5265 if (headwater
or blockmon
) then
5271 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5274 else if (FAir
mod 31 = 0) and not blockmon
then
5276 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5277 if Random(2) = 0 then
5278 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5280 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5282 end else if FAir
< AIR_DEF
then
5285 if FFireTime
> 0 then
5287 if BodyInLiquid(0, 0) then
5292 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5294 if FMegaRulez
[MR_SUIT
] = gTime
then
5301 if FFirePainTime
<= 0 then
5303 if g_Game_IsServer
then
5304 Damage(5, FFireAttacker
, 0, 0, HIT_FLAME
);
5305 FFirePainTime
:= 18;
5307 FFirePainTime
:= FFirePainTime
- 1;
5308 FFireTime
:= FFireTime
- 1;
5309 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5310 MH_SEND_PlayerStats(FUID
);
5314 if FDamageBuffer
> 0 then
5316 if FDamageBuffer
>= 9 then
5320 if FDamageBuffer
< 30 then i
:= 9
5321 else if FDamageBuffer
< 100 then i
:= 18
5325 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5326 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5327 FHealth
:= FHealth
-ii
;
5330 FHealth
:= FHealth
+FArmor
;
5335 if FHealth
<= 0 then
5336 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5337 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5338 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5342 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5343 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5344 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5345 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5352 end; // if FAlive then ...
5354 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5356 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5357 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5358 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5359 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5361 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5362 then SetAction(A_STAND
, True);
5364 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5366 for b
:= Low(FKeys
) to High(FKeys
) do
5367 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5371 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5373 x
:= FObj
.X
+PLAYER_RECT
.X
;
5374 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5375 w
:= PLAYER_RECT
.Width
;
5376 h
:= PLAYER_RECT
.Height
;
5380 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5382 if (dx
<> 0) or (dy
<> 0) then
5391 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5393 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5394 FObj
.Y
+PLAYER_RECT
.Y
,
5401 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5403 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5404 FObj
.Y
+PLAYER_RECT
.Y
,
5408 Panel
.Width
, Panel
.Height
);
5411 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5413 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5414 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5415 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5416 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5419 function g_Player_ValidName(Name
: string): Boolean;
5425 if gPlayers
= nil then Exit
;
5427 for a
:= 0 to High(gPlayers
) do
5428 if gPlayers
[a
] <> nil then
5429 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5436 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5440 d
:= FModel
.Direction
;
5442 FModel
.Direction
:= Direction
;
5443 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5445 FDirection
:= Direction
;
5448 function TPlayer
.GetKeys(): Byte;
5452 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5453 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5454 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5456 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5457 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5460 procedure TPlayer
.Use();
5464 if FTime
[T_USE
] > gTime
then Exit
;
5466 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5467 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5469 for a
:= 0 to High(gPlayers
) do
5470 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5471 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5472 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5473 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5475 gPlayers
[a
].Touch();
5476 if g_Game_IsNet
and g_Game_IsServer
then
5477 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5480 FTime
[T_USE
] := gTime
+120;
5483 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5487 WX
, WY
, XD
, YD
: Integer;
5499 if R_BERSERK
in FRulez
then
5501 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5502 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5503 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5506 locobj
.rect
.Width
:= 39;
5507 locobj
.rect
.Height
:= 52;
5508 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5509 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5510 locobj
.Accel
.X
:= xd
-wx
;
5511 locobj
.Accel
.y
:= yd
-wy
;
5513 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5514 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5516 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5520 FPain
:= min(FPain
+ 25, 50);
5522 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5527 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5528 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5530 FSawSoundSelect
.Stop();
5532 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5534 else if not FSawSoundHit
.IsPlaying() then
5536 FSawSoundSelect
.Stop();
5537 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5544 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5545 FFireAngle
:= FAngle
;
5547 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5548 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5553 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5554 FFireAngle
:= FAngle
;
5557 FShellType
:= SHELL_SHELL
;
5562 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5563 FFireAngle
:= FAngle
;
5566 FShellType
:= SHELL_DBLSHELL
;
5571 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5572 FFireAngle
:= FAngle
;
5574 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5575 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5578 WEAPON_ROCKETLAUNCHER
:
5580 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5581 FFireAngle
:= FAngle
;
5587 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5588 FFireAngle
:= FAngle
;
5594 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5595 FFireAngle
:= FAngle
;
5599 WEAPON_SUPERPULEMET
:
5601 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5602 FFireAngle
:= FAngle
;
5604 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5605 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5608 WEAPON_FLAMETHROWER
:
5610 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5611 FFireAngle
:= FAngle
;
5618 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5619 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5620 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5623 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5625 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5626 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5629 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5633 if NetInterpLevel
< 1 then
5643 AX
:= Abs(FXTo
- FObj
.X
);
5644 AY
:= Abs(FYTo
- FObj
.Y
);
5645 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5647 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5652 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5654 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5655 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5656 PANEL_LIFTUP
, False) then Result
:= -1
5658 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5659 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5660 PANEL_LIFTDOWN
, False) then Result
:= 1
5664 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5671 if Flag
= FLAG_NONE
then
5674 if not g_Game_IsServer
then Exit
;
5676 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5677 if (Flag
= FTeam
) and
5678 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5679 (FFlag
<> FLAG_NONE
) then
5681 if FFlag
= FLAG_RED
then
5682 s
:= _lc
[I_PLAYER_FLAG_RED
]
5684 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5686 evtype
:= FLAG_STATE_SCORED
;
5688 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5689 Insert('.', ts
, Length(ts
) + 1 - 3);
5690 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5692 g_Map_ResetFlag(FFlag
);
5693 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5695 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5698 if g_Game_IsNet
then
5700 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5704 gFlags
[FFlag
].CaptureTime
:= 0;
5709 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5710 if (Flag
= FTeam
) and
5711 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5713 if Flag
= FLAG_RED
then
5714 s
:= _lc
[I_PLAYER_FLAG_RED
]
5716 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5718 evtype
:= FLAG_STATE_RETURNED
;
5719 gFlags
[Flag
].CaptureTime
:= 0;
5721 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5723 g_Map_ResetFlag(Flag
);
5724 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5727 if g_Game_IsNet
then
5729 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5735 // Ïîäîáðàë ÷óæîé ôëàã:
5736 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5740 if Flag
= FLAG_RED
then
5741 s
:= _lc
[I_PLAYER_FLAG_RED
]
5743 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5745 evtype
:= FLAG_STATE_CAPTURED
;
5747 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5749 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5751 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5754 if g_Game_IsNet
then
5756 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5762 procedure TPlayer
.SetFlag(Flag
: Byte);
5765 if FModel
<> nil then
5766 FModel
.SetFlag(FFlag
);
5769 function TPlayer
.DropFlag(): Boolean;
5774 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5776 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5777 with gFlags
[FFlag
] do
5781 Direction
:= FDirection
;
5782 State
:= FLAG_STATE_DROPPED
;
5784 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5785 (FObj
.Vel
.Y
div 2)-2+Random(5));
5786 positionChanged(); // this updates spatial accelerators
5788 if FFlag
= FLAG_RED
then
5789 s
:= _lc
[I_PLAYER_FLAG_RED
]
5791 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5793 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5794 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5796 if g_Game_IsNet
then
5797 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5803 procedure TPlayer
.GetSecret();
5808 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5810 Assert(Key
<= High(FKeys
));
5812 FKeys
[Key
].Pressed
:= True;
5813 FKeys
[Key
].Time
:= Time
;
5816 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5818 Result
:= FKeys
[K
].Pressed
;
5821 procedure TPlayer
.ReleaseKeys();
5825 for a
:= Low(FKeys
) to High(FKeys
) do
5827 FKeys
[a
].Pressed
:= False;
5832 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5836 function TPlayer
.firediry(): Integer;
5838 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5839 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5843 procedure TPlayer
.RememberState();
5847 FSavedState
.Health
:= FHealth
;
5848 FSavedState
.Armor
:= FArmor
;
5849 FSavedState
.Air
:= FAir
;
5850 FSavedState
.JetFuel
:= FJetFuel
;
5851 FSavedState
.CurrWeap
:= FCurrWeap
;
5852 FSavedState
.NextWeap
:= FNextWeap
;
5853 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5856 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5858 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5860 FSavedState
.Rulez
:= FRulez
;
5861 FSavedState
.WaitRecall
:= True;
5864 procedure TPlayer
.RecallState();
5868 if not FSavedState
.WaitRecall
then Exit
;
5870 FHealth
:= FSavedState
.Health
;
5871 FArmor
:= FSavedState
.Armor
;
5872 FAir
:= FSavedState
.Air
;
5873 FJetFuel
:= FSavedState
.JetFuel
;
5874 FCurrWeap
:= FSavedState
.CurrWeap
;
5875 FNextWeap
:= FSavedState
.NextWeap
;
5876 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5879 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5881 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5883 FRulez
:= FSavedState
.Rulez
;
5884 FSavedState
.WaitRecall
:= False;
5886 if gGameSettings
.GameType
= GT_SERVER
then
5887 MH_SEND_PlayerStats(FUID
);
5890 procedure TPlayer
.SaveState (st
: TStream
);
5896 utils
.writeSign(st
, 'PLYR');
5897 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
5899 utils
.writeBool(st
, FIamBot
);
5901 utils
.writeInt(st
, Word(FUID
));
5903 utils
.writeStr(st
, FName
);
5905 utils
.writeInt(st
, Byte(FTeam
));
5907 utils
.writeBool(st
, FAlive
);
5908 // Èçðàñõîäîâàë ëè âñå æèçíè
5909 utils
.writeBool(st
, FNoRespawn
);
5911 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
5912 utils
.writeInt(st
, Byte(b
));
5914 utils
.writeInt(st
, LongInt(FHealth
));
5916 utils
.writeInt(st
, Byte(FLives
));
5918 utils
.writeInt(st
, LongInt(FArmor
));
5920 utils
.writeInt(st
, LongInt(FAir
));
5922 utils
.writeInt(st
, LongInt(FJetFuel
));
5924 utils
.writeInt(st
, LongInt(FPain
));
5926 utils
.writeInt(st
, LongInt(FKills
));
5928 utils
.writeInt(st
, LongInt(FMonsterKills
));
5930 utils
.writeInt(st
, LongInt(FFrags
));
5932 utils
.writeInt(st
, Byte(FFragCombo
));
5933 // Âðåìÿ ïîñëåäíåãî ôðàãà
5934 utils
.writeInt(st
, LongWord(FLastFrag
));
5936 utils
.writeInt(st
, LongInt(FDeath
));
5938 utils
.writeInt(st
, Byte(FFlag
));
5940 utils
.writeInt(st
, LongInt(FSecrets
));
5942 utils
.writeInt(st
, Byte(FCurrWeap
));
5944 utils
.writeInt(st
, Word(FNextWeap
));
5946 utils
.writeInt(st
, Byte(FNextWeapDelay
));
5947 // Âðåìÿ çàðÿäêè BFG
5948 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
5950 utils
.writeInt(st
, LongInt(FDamageBuffer
));
5951 // Ïîñëåäíèé óäàðèâøèé
5952 utils
.writeInt(st
, Word(FLastSpawnerUID
));
5953 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
5954 utils
.writeInt(st
, Byte(FLastHit
));
5956 Obj_SaveState(st
, @FObj
);
5957 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
5958 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
5959 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
5960 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
5962 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
5963 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
5964 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
5966 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
5967 // Íàëè÷èå êðàñíîãî êëþ÷à
5968 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
5969 // Íàëè÷èå çåëåíîãî êëþ÷à
5970 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
5971 // Íàëè÷èå ñèíåãî êëþ÷à
5972 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
5974 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
5975 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
5976 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
5977 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
5978 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
5980 utils
.writeStr(st
, FModel
.Name
);
5982 utils
.writeInt(st
, Byte(FColor
.R
));
5983 utils
.writeInt(st
, Byte(FColor
.G
));
5984 utils
.writeInt(st
, Byte(FColor
.B
));
5988 procedure TPlayer
.LoadState (st
: TStream
);
5997 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
5998 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
6000 FIamBot
:= utils
.readBool(st
);
6002 FUID
:= utils
.readWord(st
);
6004 str
:= utils
.readStr(st
);
6005 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
6007 FTeam
:= utils
.readByte(st
);
6009 FAlive
:= utils
.readBool(st
);
6010 // Èçðàñõîäîâàë ëè âñå æèçíè
6011 FNoRespawn
:= utils
.readBool(st
);
6013 b
:= utils
.readByte(st
);
6014 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
6016 FHealth
:= utils
.readLongInt(st
);
6018 FLives
:= utils
.readByte(st
);
6020 FArmor
:= utils
.readLongInt(st
);
6022 FAir
:= utils
.readLongInt(st
);
6024 FJetFuel
:= utils
.readLongInt(st
);
6026 FPain
:= utils
.readLongInt(st
);
6028 FKills
:= utils
.readLongInt(st
);
6030 FMonsterKills
:= utils
.readLongInt(st
);
6032 FFrags
:= utils
.readLongInt(st
);
6034 FFragCombo
:= utils
.readByte(st
);
6035 // Âðåìÿ ïîñëåäíåãî ôðàãà
6036 FLastFrag
:= utils
.readLongWord(st
);
6038 FDeath
:= utils
.readLongInt(st
);
6040 FFlag
:= utils
.readByte(st
);
6042 FSecrets
:= utils
.readLongInt(st
);
6044 FCurrWeap
:= utils
.readByte(st
);
6046 FNextWeap
:= utils
.readWord(st
);
6048 FNextWeapDelay
:= utils
.readByte(st
);
6049 // Âðåìÿ çàðÿäêè BFG
6050 FBFGFireCounter
:= utils
.readSmallInt(st
);
6052 FDamageBuffer
:= utils
.readLongInt(st
);
6053 // Ïîñëåäíèé óäàðèâøèé
6054 FLastSpawnerUID
:= utils
.readWord(st
);
6055 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6056 FLastHit
:= utils
.readByte(st
);
6058 Obj_LoadState(@FObj
, st
);
6059 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6060 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
6061 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6062 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
6064 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
6065 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6066 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
6068 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
6069 // Íàëè÷èå êðàñíîãî êëþ÷à
6070 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
6071 // Íàëè÷èå çåëåíîãî êëþ÷à
6072 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
6073 // Íàëè÷èå ñèíåãî êëþ÷à
6074 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
6076 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
6077 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6078 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
6079 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6080 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
6082 str
:= utils
.readStr(st
);
6084 FColor
.R
:= utils
.readByte(st
);
6085 FColor
.G
:= utils
.readByte(st
);
6086 FColor
.B
:= utils
.readByte(st
);
6087 if (self
= gPlayer1
) then
6089 str
:= gPlayer1Settings
.Model
;
6090 FColor
:= gPlayer1Settings
.Color
;
6092 else if (self
= gPlayer2
) then
6094 str
:= gPlayer2Settings
.Model
;
6095 FColor
:= gPlayer2Settings
.Color
;
6097 // Îáíîâëÿåì ìîäåëü èãðîêà
6099 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
6100 FModel
.Color
:= TEAMCOLOR
[FTeam
]
6102 FModel
.Color
:= FColor
;
6106 procedure TPlayer
.AllRulez(Health
: Boolean);
6112 FHealth
:= PLAYER_HP_LIMIT
;
6113 FArmor
:= PLAYER_AP_LIMIT
;
6117 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
6118 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
6119 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6122 procedure TPlayer
.RestoreHealthArmor();
6124 FHealth
:= PLAYER_HP_LIMIT
;
6125 FArmor
:= PLAYER_AP_LIMIT
;
6128 procedure TPlayer
.FragCombo();
6132 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6134 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6136 if FFragCombo
< 5 then
6138 Param
:= FUID
or (FFragCombo
shl 16);
6139 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6140 (FComboEvnt
<= High(gDelayedEvents
)) and
6141 gDelayedEvents
[FComboEvnt
].Pending
and
6142 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6143 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6145 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6146 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6149 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6157 procedure TPlayer
.GiveItem(ItemType
: Byte);
6161 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6163 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6167 if FAir
< AIR_MAX
then
6174 if not (R_BERSERK
in FRulez
) then
6176 Include(FRulez
, R_BERSERK
);
6177 if FBFGFireCounter
< 1 then
6179 FCurrWeap
:= WEAPON_KASTET
;
6181 FModel
.SetWeapon(WEAPON_KASTET
);
6185 FBerserk
:= gTime
+30000;
6187 if FHealth
< PLAYER_HP_SOFT
then
6189 FHealth
:= PLAYER_HP_SOFT
;
6190 FBerserk
:= gTime
+30000;
6195 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6197 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6201 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6203 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6207 if FJetFuel
< JET_MAX
then
6209 FJetFuel
:= JET_MAX
;
6212 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6213 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6215 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6216 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6218 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6220 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6222 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6223 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6226 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6227 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6228 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6229 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6230 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6231 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6232 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6233 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6234 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6236 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6237 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6238 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6239 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6240 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6241 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6242 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6243 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6244 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6247 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6248 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6249 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6250 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6251 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6253 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6254 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6255 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6256 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6257 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6259 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6260 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6261 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6262 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6264 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6267 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6268 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6269 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6271 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6272 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6277 if g_Game_IsNet
and g_Game_IsServer
then
6278 MH_SEND_PlayerStats(FUID
);
6281 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6286 if (Random(5) = 1) and (Times
= 1) then
6289 if BodyInLiquid(0, 0) then
6291 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6292 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6293 if Random(2) = 0 then
6294 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6296 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6300 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6302 for i
:= 1 to Times
do
6304 Anim
:= TAnimation
.Create(id
, False, 3);
6306 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6307 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6313 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6318 if (Random(10) = 1) and (Times
= 1) then
6321 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6323 for i
:= 1 to Times
do
6325 Anim
:= TAnimation
.Create(id
, False, 3);
6327 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6328 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6334 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6336 FSawSound
.Pause(Enable
);
6337 FSawSoundIdle
.Pause(Enable
);
6338 FSawSoundHit
.Pause(Enable
);
6339 FSawSoundSelect
.Pause(Enable
);
6344 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6349 FObj
.Rect
:= PLAYER_CORPSERECT
;
6350 FModelName
:= ModelName
;
6355 FState
:= CORPSE_STATE_MESS
;
6356 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6360 FState
:= CORPSE_STATE_NORMAL
;
6361 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6365 destructor TCorpse
.Destroy();
6372 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6374 procedure TCorpse
.positionChanged (); inline; begin end;
6376 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6378 if (dx
<> 0) or (dy
<> 0) then
6387 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6389 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6390 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6391 w
:= PLAYER_CORPSERECT
.Width
;
6392 h
:= PLAYER_CORPSERECT
.Height
;
6396 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6401 if FState
= CORPSE_STATE_REMOVEME
then
6404 FDamage
:= FDamage
+ Value
;
6406 if FDamage
> 150 then
6408 if FAnimation
<> nil then
6413 FState
:= CORPSE_STATE_REMOVEME
;
6415 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6416 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6417 FModelName
, FColor
);
6418 // Çâóê ìÿñà îò òðóïà:
6419 pm
:= g_PlayerModel_Get(FModelName
);
6420 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6424 if (gBodyKillEvent
<> -1)
6425 and gDelayedEvents
[gBodyKillEvent
].Pending
then
6426 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
6427 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, 0);
6432 Blood
:= g_PlayerModel_GetBlood(FModelName
);
6433 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6434 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6435 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6436 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6437 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6438 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
6442 procedure TCorpse
.Draw();
6444 if FState
= CORPSE_STATE_REMOVEME
then
6447 if FAnimation
<> nil then
6448 FAnimation
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6450 if FAnimationMask
<> nil then
6453 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6460 procedure TCorpse
.Update();
6464 if FState
= CORPSE_STATE_REMOVEME
then
6467 if gTime
mod (GAME_TICK
*2) <> 0 then
6469 g_Obj_Move(@FObj
, True, True, True);
6470 positionChanged(); // this updates spatial accelerators
6474 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6475 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6477 st
:= g_Obj_Move(@FObj
, True, True, True);
6478 positionChanged(); // this updates spatial accelerators
6480 if WordBool(st
and MOVE_FALLOUT
) then
6482 FState
:= CORPSE_STATE_REMOVEME
;
6486 if FAnimation
<> nil then
6487 FAnimation
.Update();
6488 if FAnimationMask
<> nil then
6489 FAnimationMask
.Update();
6493 procedure TCorpse
.SaveState (st
: TStream
);
6500 utils
.writeSign(st
, 'CORP');
6501 utils
.writeInt(st
, Byte(0));
6503 utils
.writeInt(st
, Byte(FState
));
6505 utils
.writeInt(st
, Byte(FDamage
));
6507 utils
.writeInt(st
, Byte(FColor
.R
));
6508 utils
.writeInt(st
, Byte(FColor
.G
));
6509 utils
.writeInt(st
, Byte(FColor
.B
));
6511 Obj_SaveState(st
, @FObj
);
6512 utils
.writeInt(st
, Word(FPlayerUID
));
6514 anim
:= (FAnimation
<> nil);
6515 utils
.writeBool(st
, anim
);
6516 // Åñëè åñòü - ñîõðàíÿåì
6517 if anim
then FAnimation
.SaveState(st
);
6518 // Åñòü ëè ìàñêà àíèìàöèè
6519 anim
:= (FAnimationMask
<> nil);
6520 utils
.writeBool(st
, anim
);
6521 // Åñëè åñòü - ñîõðàíÿåì
6522 if anim
then FAnimationMask
.SaveState(st
);
6526 procedure TCorpse
.LoadState (st
: TStream
);
6533 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6534 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6536 FState
:= utils
.readByte(st
);
6538 FDamage
:= utils
.readByte(st
);
6540 FColor
.R
:= utils
.readByte(st
);
6541 FColor
.G
:= utils
.readByte(st
);
6542 FColor
.B
:= utils
.readByte(st
);
6544 Obj_LoadState(@FObj
, st
);
6545 FPlayerUID
:= utils
.readWord(st
);
6547 anim
:= utils
.readBool(st
);
6548 // Åñëè åñòü - çàãðóæàåì
6551 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6552 FAnimation
.LoadState(st
);
6554 // Åñòü ëè ìàñêà àíèìàöèè
6555 anim
:= utils
.readBool(st
);
6556 // Åñëè åñòü - çàãðóæàåì
6559 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6560 FAnimationMask
.LoadState(st
);
6566 constructor TBot
.Create();
6573 FSpectator
:= False;
6580 for a
:= WP_FIRST
to WP_LAST
do
6582 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6583 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6584 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6588 destructor TBot
.Destroy();
6591 inherited Destroy();
6594 procedure TBot
.Draw();
6598 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6599 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6602 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6604 inherited Respawn(Silent
, Force
);
6607 FSelectedWeapon
:= FCurrWeap
;
6612 procedure TBot
.UpdateCombat();
6625 TTargetRecord
= array of TTarget
;
6627 function Compare(a
, b
: TTarget
): Integer;
6629 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6632 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6634 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6635 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6637 if a
.Dist
> b
.Dist
then // B áëèæå
6639 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6642 else // Ñòðàííî -> A
6647 a
, x1
, y1
, x2
, y2
: Integer;
6648 targets
: TTargetRecord
;
6650 Target
, BestTarget
: TTarget
;
6651 firew
, fireh
: Integer;
6655 vsPlayer
, vsMonster
, ok
: Boolean;
6658 function monsUpdate (mon
: TMonster
): Boolean;
6660 result
:= false; // don't stop
6661 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6663 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6665 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6666 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6668 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6669 if g_TraceVector(x1
, y1
, x2
, y2
) then
6671 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6672 SetLength(targets
, Length(targets
)+1);
6673 with targets
[High(targets
)] do
6680 Rect
:= mon
.Obj
.Rect
;
6681 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6682 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6683 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6692 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6693 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6695 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6696 if FCurrWeap
<> FSelectedWeapon
then
6699 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6700 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6702 RemoveAIFlag('NEEDFIRE');
6705 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6706 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6707 else PressKey(KEY_FIRE
);
6711 // Êîîðäèíàòû ñòâîëà:
6712 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6713 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6715 Target
.UID
:= FTargetUID
;
6718 if Target
.UID
<> 0 then
6719 begin // Öåëü åñòü - íàñòðàèâàåì
6720 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6723 tpla
:= g_Player_Get(Target
.UID
);
6727 if (@FObj
) <> nil then
6734 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6735 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6736 Target
.Rect
:= PLAYER_RECT
;
6737 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6738 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6739 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6740 Target
.IsPlayer
:= True;
6744 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6747 mon
:= g_Monsters_ByUID(Target
.UID
);
6750 Target
.X
:= mon
.Obj
.X
;
6751 Target
.Y
:= mon
.Obj
.Y
;
6753 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6754 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6755 Target
.Rect
:= mon
.Obj
.Rect
;
6756 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6757 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6758 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6759 Target
.IsPlayer
:= False;
6766 begin // Öåëè íåò - îáíóëÿåì
6771 Target
.Visible
:= False;
6772 Target
.Line
:= False;
6773 Target
.IsPlayer
:= False;
6778 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6779 if (not Target
.Line
) or (not Target
.Visible
) then
6783 for a
:= 0 to High(gPlayers
) do
6784 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6785 (gPlayers
[a
].FUID
<> FUID
) and
6786 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6787 (not gPlayers
[a
].NoTarget
) and
6788 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6790 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6791 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6794 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6795 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6797 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6798 if g_TraceVector(x1
, y1
, x2
, y2
) then
6800 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6801 SetLength(targets
, Length(targets
)+1);
6802 with targets
[High(targets
)] do
6804 UID
:= gPlayers
[a
].FUID
;
6805 X
:= gPlayers
[a
].FObj
.X
;
6806 Y
:= gPlayers
[a
].FObj
.Y
;
6809 Rect
:= PLAYER_RECT
;
6810 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6811 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6812 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6820 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6823 // Åñëè åñòü âîçìîæíûå öåëè:
6824 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6825 if targets
<> nil then
6827 // Âûáèðàåì íàèëó÷øóþ öåëü:
6828 BestTarget
:= targets
[0];
6829 if Length(targets
) > 1 then
6830 for a
:= 1 to High(targets
) do
6831 if Compare(BestTarget
, targets
[a
]) = 1 then
6832 BestTarget
:= targets
[a
];
6834 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6835 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6836 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6838 Target
:= BestTarget
;
6840 if (Healthy() = 3) or ((Healthy() = 2)) then
6841 begin // Åñëè çäîðîâû - äîãîíÿåì
6842 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6843 SetAIFlag('GORIGHT', '1');
6844 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6845 SetAIFlag('GOLEFT', '1');
6848 begin // Åñëè ïîáèòû - óáåãàåì
6849 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6850 SetAIFlag('GORIGHT', '1');
6851 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6852 SetAIFlag('GOLEFT', '1');
6855 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6856 SelectWeapon(Abs(x1
-Target
.cX
));
6861 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6862 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6863 if Target
.UID
<> 0 then
6865 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6866 Target
.Y
+ Target
.Rect
.Y
) then
6867 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6868 if (Healthy() = 3) or ((Healthy() = 2)) then
6869 begin // Åñëè çäîðîâû - äîãîíÿåì
6870 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6871 SetAIFlag('GORIGHT', '1');
6872 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6873 SetAIFlag('GOLEFT', '1');
6876 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6878 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6879 SetAIFlag('GORIGHT', '1');
6880 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6881 SetAIFlag('GOLEFT', '1');
6885 begin // Öåëü ïîêà íà "ýêðàíå"
6886 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6887 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6888 FLastVisible
:= gTime
;
6889 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6890 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6892 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6893 SetAIFlag('GORIGHT', '1');
6894 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6895 SetAIFlag('GOLEFT', '1');
6899 // Âûáèðàåì óãîë ââåðõ:
6900 if FDirection
= TDirection
.D_LEFT
then
6901 angle
:= ANGLE_LEFTUP
6903 angle
:= ANGLE_RIGHTUP
;
6905 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6906 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6908 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6909 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6910 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6911 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6912 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6913 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6914 begin // òî íóæíî ñòðåëÿòü ââåðõ
6915 SetAIFlag('NEEDFIRE', '1');
6916 SetAIFlag('NEEDSEEUP', '1');
6919 // Âûáèðàåì óãîë âíèç:
6920 if FDirection
= TDirection
.D_LEFT
then
6921 angle
:= ANGLE_LEFTDOWN
6923 angle
:= ANGLE_RIGHTDOWN
;
6925 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6926 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6928 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6929 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6930 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6931 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6932 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6933 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6934 begin // òî íóæíî ñòðåëÿòü âíèç
6935 SetAIFlag('NEEDFIRE', '1');
6936 SetAIFlag('NEEDSEEDOWN', '1');
6939 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6940 if Target
.Visible
and
6941 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6942 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6944 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6945 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
6946 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6947 begin // òî íóæíî ñòðåëÿòü âïåðåä
6948 SetAIFlag('NEEDFIRE', '1');
6949 SetAIFlag('NEEDSEEDOWN', '');
6950 SetAIFlag('NEEDSEEUP', '');
6952 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6953 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6954 if GetRnd(FDifficult
.CloseJump
) then
6955 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6956 if Abs(FObj
.X
-Target
.X
) < 128 then
6960 if Random(a
) = 0 then
6961 SetAIFlag('NEEDJUMP', '1');
6965 // Åñëè öåëü âñå åùå åñòü:
6966 if Target
.UID
<> 0 then
6967 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
6968 Target
.UID
:= 0 // òî çàáûòü öåëü
6969 else // Åñëè âèäåëè íåäàâíî
6970 begin // íî öåëü óáèëè
6971 if Target
.IsPlayer
then
6972 begin // Öåëü - èãðîê
6973 pla
:= g_Player_Get(Target
.UID
);
6974 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
6975 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6976 Target
.UID
:= 0; // òî çàáûòü öåëü
6979 begin // Öåëü - ìîíñòð
6980 mon
:= g_Monsters_ByUID(Target
.UID
);
6981 if (mon
= nil) or (not mon
.alive
) then
6982 Target
.UID
:= 0; // òî çàáûòü öåëü
6985 end; // if Target.UID <> 0
6987 FTargetUID
:= Target
.UID
;
6989 // Åñëè âîçìîæíûõ öåëåé íåò:
6990 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
6991 if targets
= nil then
6992 if GetAIFlag('ATTACKLEFT') <> '' then
6993 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
6994 RemoveAIFlag('ATTACKLEFT');
6996 SetAIFlag('NEEDJUMP', '1');
6998 if RunDirection() = TDirection
.D_RIGHT
then
6999 begin // Èäåì íå â òó ñòîðîíó
7000 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7001 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
7002 SetAIFlag('NEEDFIRE', '1');
7003 SetAIFlag('GOLEFT', '1');
7007 begin // Èäåì â íóæíóþ ñòîðîíó
7008 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7009 SetAIFlag('NEEDFIRE', '1');
7010 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7011 SetAIFlag('GORIGHT', '1');
7015 if GetAIFlag('ATTACKRIGHT') <> '' then
7016 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
7017 RemoveAIFlag('ATTACKRIGHT');
7019 SetAIFlag('NEEDJUMP', '1');
7021 if RunDirection() = TDirection
.D_LEFT
then
7022 begin // Èäåì íå â òó ñòîðîíó
7023 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7024 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
7025 SetAIFlag('NEEDFIRE', '1');
7026 SetAIFlag('GORIGHT', '1');
7031 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7032 SetAIFlag('NEEDFIRE', '1');
7033 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7034 SetAIFlag('GOLEFT', '1');
7038 //HACK! (does it belongs there?)
7039 RealizeCurrentWeapon();
7041 // Åñëè åñòü âîçìîæíûå öåëè:
7042 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7043 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7044 for a
:= 0 to High(targets
) do
7046 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7047 if GetRnd(FDifficult
.DiagFire
) then
7049 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7050 if FDirection
= TDirection
.D_LEFT
then
7051 angle
:= ANGLE_LEFTUP
7053 angle
:= ANGLE_RIGHTUP
;
7055 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7056 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7058 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7059 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7060 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7061 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7062 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7064 SetAIFlag('NEEDFIRE', '1');
7065 SetAIFlag('NEEDSEEUP', '1');
7068 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7069 if FDirection
= TDirection
.D_LEFT
then
7070 angle
:= ANGLE_LEFTDOWN
7072 angle
:= ANGLE_RIGHTDOWN
;
7074 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7075 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7077 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7078 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7079 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7080 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7081 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7083 SetAIFlag('NEEDFIRE', '1');
7084 SetAIFlag('NEEDSEEDOWN', '1');
7088 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7089 if targets
[a
].Line
and targets
[a
].Visible
and
7090 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
7091 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
7093 SetAIFlag('NEEDFIRE', '1');
7098 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7099 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
7100 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
7101 40+GetInterval(FDifficult
.Cover
, 40)) then
7102 SetAIFlag('NEEDJUMP', '1');
7104 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7105 ammo
:= GetAmmoByWeapon(FCurrWeap
);
7106 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
7107 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
7109 SetAIFlag('SELECTWEAPON', '1');
7111 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7112 if GetAIFlag('SELECTWEAPON') = '1' then
7115 RemoveAIFlag('SELECTWEAPON');
7119 procedure TBot
.Update();
7132 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7133 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7135 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7137 if g_debug_BotAIOff
= 3 then
7147 RealizeCurrentWeapon();
7154 procedure TBot
.ReleaseKey(Key
: Byte);
7163 function TBot
.KeyPressed(Key
: Word): Boolean;
7165 Result
:= FKeys
[Key
].Pressed
;
7168 function TBot
.GetAIFlag(aName
: String20
): String20
;
7174 aName
:= LowerCase(aName
);
7176 if FAIFlags
<> nil then
7177 for a
:= 0 to High(FAIFlags
) do
7178 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7180 Result
:= FAIFlags
[a
].Value
;
7185 procedure TBot
.RemoveAIFlag(aName
: String20
);
7189 if FAIFlags
= nil then Exit
;
7191 aName
:= LowerCase(aName
);
7193 for a
:= 0 to High(FAIFlags
) do
7194 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7196 if a
<> High(FAIFlags
) then
7197 for b
:= a
to High(FAIFlags
)-1 do
7198 FAIFlags
[b
] := FAIFlags
[b
+1];
7200 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7205 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7213 aName
:= LowerCase(aName
);
7215 if FAIFlags
<> nil then
7216 for a
:= 0 to High(FAIFlags
) do
7217 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7223 if ok
then FAIFlags
[a
].Value
:= fValue
7226 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7227 with FAIFlags
[High(FAIFlags
)] do
7235 procedure TBot
.UpdateMove
;
7237 procedure GoLeft(Time
: Word = 1);
7239 ReleaseKey(KEY_LEFT
);
7240 ReleaseKey(KEY_RIGHT
);
7241 PressKey(KEY_LEFT
, Time
);
7242 SetDirection(TDirection
.D_LEFT
);
7245 procedure GoRight(Time
: Word = 1);
7247 ReleaseKey(KEY_LEFT
);
7248 ReleaseKey(KEY_RIGHT
);
7249 PressKey(KEY_RIGHT
, Time
);
7250 SetDirection(TDirection
.D_RIGHT
);
7253 function Rnd(a
: Word): Boolean;
7255 Result
:= Random(a
) = 0;
7258 procedure Turn(Time
: Word = 1200);
7260 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7265 ReleaseKey(KEY_LEFT
);
7266 ReleaseKey(KEY_RIGHT
);
7269 function CanRunLeft(): Boolean;
7271 Result
:= not CollideLevel(-1, 0);
7274 function CanRunRight(): Boolean;
7276 Result
:= not CollideLevel(1, 0);
7279 function CanRun(): Boolean;
7281 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7284 procedure Jump(Time
: Word = 30);
7286 PressKey(KEY_JUMP
, Time
);
7289 function NearHole(): Boolean;
7293 { TODO 5 : Ëåñòíèöû }
7294 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7295 for x
:= 1 to PLAYER_RECT
.Width
do
7296 if (not StayOnStep(x
*sx
, 0)) and
7297 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7298 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7307 function BorderHole(): Boolean;
7311 { TODO 5 : Ëåñòíèöû }
7312 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7313 for x
:= 1 to PLAYER_RECT
.Width
do
7314 if (not StayOnStep(x
*sx
, 0)) and
7315 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7316 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7318 for xx
:= x
to x
+32 do
7319 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7329 function NearDeepHole(): Boolean;
7335 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7338 for x
:= 1 to PLAYER_RECT
.Width
do
7339 if (not StayOnStep(x
*sx
, 0)) and
7340 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7341 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7343 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7345 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7350 end else Result
:= False;
7353 function OverDeepHole(): Boolean;
7360 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7362 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7369 function OnGround(): Boolean;
7371 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7374 function OnLadder(): Boolean;
7376 Result
:= FullInStep(0, 0);
7379 function BelowLadder(): Boolean;
7381 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7382 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7383 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7384 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7387 function BelowLiftUp(): Boolean;
7389 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7390 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7391 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7392 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7395 function OnTopLift(): Boolean;
7397 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7400 function CanJumpOver(): Boolean;
7404 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7408 if not CollideLevel(sx
, 0) then Exit
;
7410 for y
:= 1 to BOT_MAXJUMP
do
7411 if CollideLevel(0, -y
) then Exit
else
7412 if not CollideLevel(sx
, -y
) then
7419 function CanJumpUp(Dist
: ShortInt): Boolean;
7426 if CollideLevel(Dist
, 0) then Exit
;
7429 for y
:= 0 to BOT_MAXJUMP
do
7430 if CollideLevel(Dist
, -y
) then
7439 for yy
:= y
+1 to BOT_MAXJUMP
do
7440 if not CollideLevel(Dist
, -yy
) then
7449 for y
:= 0 to BOT_MAXJUMP
do
7450 if CollideLevel(0, -y
) then
7458 if y
< yy
then Exit
;
7463 function IsSafeTrigger(): Boolean;
7468 if gTriggers
= nil then
7470 for a
:= 0 to High(gTriggers
) do
7471 if Collide(gTriggers
[a
].X
,
7474 gTriggers
[a
].Height
) and
7475 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7476 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7477 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7478 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7479 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7484 // Âîçìîæíî, íàæèìàåì êíîïêó:
7485 if Rnd(16) and IsSafeTrigger() then
7488 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7489 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7491 ReleaseKey(KEY_LEFT
);
7492 ReleaseKey(KEY_RIGHT
);
7496 // Èäåì âëåâî, åñëè íàäî áûëî:
7497 if GetAIFlag('GOLEFT') <> '' then
7499 RemoveAIFlag('GOLEFT');
7500 if CanRunLeft() then
7504 // Èäåì âïðàâî, åñëè íàäî áûëî:
7505 if GetAIFlag('GORIGHT') <> '' then
7507 RemoveAIFlag('GORIGHT');
7508 if CanRunRight() then
7512 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7513 if FObj
.X
< -32 then
7516 if FObj
.X
+32 > gMapInfo
.Width
then
7519 // Ïðûãàåì, åñëè íàäî áûëî:
7520 if GetAIFlag('NEEDJUMP') <> '' then
7523 RemoveAIFlag('NEEDJUMP');
7526 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7527 if GetAIFlag('NEEDSEEUP') <> '' then
7530 ReleaseKey(KEY_DOWN
);
7531 PressKey(KEY_UP
, 20);
7532 RemoveAIFlag('NEEDSEEUP');
7535 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7536 if GetAIFlag('NEEDSEEDOWN') <> '' then
7539 ReleaseKey(KEY_DOWN
);
7540 PressKey(KEY_DOWN
, 20);
7541 RemoveAIFlag('NEEDSEEDOWN');
7544 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7545 if GetAIFlag('GOINHOLE') <> '' then
7546 if not OnGround() then
7548 ReleaseKey(KEY_LEFT
);
7549 ReleaseKey(KEY_RIGHT
);
7550 RemoveAIFlag('GOINHOLE');
7551 SetAIFlag('FALLINHOLE', '1');
7554 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7555 if GetAIFlag('FALLINHOLE') <> '' then
7557 RemoveAIFlag('FALLINHOLE');
7559 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7560 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7561 if GetAIFlag('FALLINHOLE') = '' then
7562 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7568 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7570 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7574 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7575 if OnGround() and NearHole() then
7576 if NearDeepHole() then // Åñëè ýòî áåçäíà
7578 0..3: Turn(); // Áåæèì îáðàòíî
7579 4: Jump(); // Ïðûãàåì
7580 5: begin // Ïðûãàåì îáðàòíî
7585 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7586 if GetAIFlag('GOINHOLE') = '' then
7588 0: Turn(); // Íå íóæíî òóäà
7589 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7590 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7591 if BorderHole() then
7592 SetAIFlag('GOINHOLE', '1');
7595 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7596 if (not CanRun()) and OnGround() then
7598 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7599 if CanJumpOver() or OnLadder() then
7601 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7602 if Random(2) = 0 then
7604 if IsSafeTrigger() then
7610 // Îñòàëîñü ìàëî âîçäóõà:
7611 if FAir
< 36 * 2 then
7614 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7615 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7616 if BodyInAcid(0, 0) then
7620 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7622 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7623 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7626 {function TBot.NeedItem(Item: Byte): Byte;
7631 procedure TBot
.SelectWeapon(Dist
: Integer);
7635 function HaveAmmo(weapon
: Byte): Boolean;
7638 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7639 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7640 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7641 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7642 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7643 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7644 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7645 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7646 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7647 else Result
:= True;
7652 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7654 if Dist
> BOT_LONGDIST
then
7655 begin // Äàëüíèé áîé
7657 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7659 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7663 else //if Dist > BOT_UNSAFEDIST then
7664 begin // Áëèæíèé áîé
7666 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7668 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7675 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7677 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7683 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7685 Result
:= inherited PickItem(ItemType
, force
, remove
);
7687 if Result
then SetAIFlag('SELECTWEAPON', '1');
7690 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7692 Result
:= inherited Heal(value
, Soft
);
7695 function TBot
.Healthy(): Byte;
7697 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7698 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7699 else if (FHealth
> 50) then Result
:= 2
7700 else if (FHealth
> 20) then Result
:= 1
7704 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7706 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7707 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7710 procedure TBot
.OnDamage(Angle
: SmallInt);
7718 if (Angle
= 0) or (Angle
= 180) then
7721 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7722 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7724 pla
:= g_Player_Get(FLastSpawnerUID
);
7725 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7726 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7729 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7730 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7732 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7733 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7734 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7739 SetAIFlag('ATTACKLEFT', '1')
7741 SetAIFlag('ATTACKRIGHT', '1');
7745 function TBot
.RunDirection(): TDirection
;
7747 if Abs(Vel
.X
) >= 1 then
7749 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7751 Result
:= FDirection
;
7754 function TBot
.GetRnd(a
: Byte): Boolean;
7756 if a
= 0 then Result
:= False
7757 else if a
= 255 then Result
:= True
7758 else Result
:= Random(256) > 255-a
;
7761 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7763 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7767 procedure TDifficult
.save (st
: TStream
);
7769 utils
.writeInt(st
, Byte(DiagFire
));
7770 utils
.writeInt(st
, Byte(InvisFire
));
7771 utils
.writeInt(st
, Byte(DiagPrecision
));
7772 utils
.writeInt(st
, Byte(FlyPrecision
));
7773 utils
.writeInt(st
, Byte(Cover
));
7774 utils
.writeInt(st
, Byte(CloseJump
));
7775 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7776 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7779 procedure TDifficult
.load (st
: TStream
);
7781 DiagFire
:= utils
.readByte(st
);
7782 InvisFire
:= utils
.readByte(st
);
7783 DiagPrecision
:= utils
.readByte(st
);
7784 FlyPrecision
:= utils
.readByte(st
);
7785 Cover
:= utils
.readByte(st
);
7786 CloseJump
:= utils
.readByte(st
);
7787 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7788 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7792 procedure TBot
.SaveState (st
: TStream
);
7797 inherited SaveState(st
);
7798 utils
.writeSign(st
, 'BOT0');
7800 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7802 utils
.writeInt(st
, Word(FTargetUID
));
7803 // Âðåìÿ ïîòåðè öåëè
7804 utils
.writeInt(st
, LongWord(FLastVisible
));
7805 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7806 dw
:= Length(FAIFlags
);
7807 utils
.writeInt(st
, LongInt(dw
));
7809 for i
:= 0 to dw
-1 do
7811 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7812 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7814 // Íàñòðîéêè ñëîæíîñòè
7815 FDifficult
.save(st
);
7819 procedure TBot
.LoadState (st
: TStream
);
7824 inherited LoadState(st
);
7825 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7827 FSelectedWeapon
:= utils
.readByte(st
);
7829 FTargetUID
:= utils
.readWord(st
);
7830 // Âðåìÿ ïîòåðè öåëè
7831 FLastVisible
:= utils
.readLongWord(st
);
7832 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7833 dw
:= utils
.readLongInt(st
);
7834 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7835 SetLength(FAIFlags
, dw
);
7837 for i
:= 0 to dw
-1 do
7839 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7840 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7842 // Íàñòðîéêè ñëîæíîñòè
7843 FDifficult
.load(st
);
7848 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);