1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
24 {$IFDEF USE_MEMPOOL}mempool
,{$ENDIF}
25 e_graphics
, g_playermodel
, g_basic
, g_textures
,
26 g_weapons
, g_phys
, g_sound
, g_saveload
, MAPDEF
,
59 AmmoLimits
: Array [0..1] of Array [A_BULLETS
..A_HIGH
] of Word =
60 ((200, 50, 50, 300, 100),
61 (400, 100, 100, 600, 200));
82 ANGLE_NONE
= Low(SmallInt);
84 CORPSE_STATE_REMOVEME
= 0;
85 CORPSE_STATE_NORMAL
= 1;
86 CORPSE_STATE_MESS
= 2;
88 PLAYER_RECT
: TRectWH
= (X
:15; Y
:12; Width
:34; Height
:52);
89 PLAYER_RECT_CX
= 15+(34 div 2);
90 PLAYER_RECT_CY
= 12+(52 div 2);
91 PLAYER_CORPSERECT
: TRectWH
= (X
:15; Y
:48; Width
:34; Height
:16);
94 PLAYER_HP_LIMIT
= 200;
96 PLAYER_AP_LIMIT
= 200;
100 PLAYER1_DEF_COLOR
: TRGB
= (R
:64; G
:175; B
:48);
101 PLAYER2_DEF_COLOR
: TRGB
= (R
:96; G
:96; B
:96);
118 TPlayerStatArray
= Array of TPlayerStat
;
120 TPlayerSavedState
= record
128 Ammo
: Array [A_BULLETS
..A_HIGH
] of Word;
129 MaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
130 Weapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
131 Rulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
140 TPlayer
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
148 FDirection
: TDirection
;
156 FMonsterKills
: Integer;
162 FCanJetpack
: Boolean;
168 FNextWeapDelay
: Byte; // frames
169 FBFGFireCounter
: SmallInt;
170 FLastSpawnerUID
: Word;
174 FSpectatePlayer
: Integer;
175 FFirePainTime
: Integer;
178 FSavedState
: TPlayerSavedState
;
180 FModel
: TPlayerModel
;
181 FPunchAnim
: TAnimation
;
184 FActionForce
: Boolean;
185 FActionChanged
: Boolean;
187 FFireAngle
: SmallInt;
189 FShellTimer
: Integer;
191 FSawSound
: TPlayableSound
;
192 FSawSoundIdle
: TPlayableSound
;
193 FSawSoundHit
: TPlayableSound
;
194 FSawSoundSelect
: TPlayableSound
;
195 FFlameSoundOn
: TPlayableSound
;
196 FFlameSoundOff
: TPlayableSound
;
197 FFlameSoundWork
: TPlayableSound
;
198 FJetSoundOn
: TPlayableSound
;
199 FJetSoundOff
: TPlayableSound
;
200 FJetSoundFly
: TPlayableSound
;
204 FJustTeleported
: Boolean;
206 mEDamageType
: Integer;
209 function CollideLevel(XInc
, YInc
: Integer): Boolean;
210 function StayOnStep(XInc
, YInc
: Integer): Boolean;
211 function HeadInLiquid(XInc
, YInc
: Integer): Boolean;
212 function BodyInLiquid(XInc
, YInc
: Integer): Boolean;
213 function BodyInAcid(XInc
, YInc
: Integer): Boolean;
214 function FullInLift(XInc
, YInc
: Integer): Integer;
215 {procedure CollideItem();}
216 procedure FlySmoke(Times
: DWORD
= 1);
217 procedure OnFireFlame(Times
: DWORD
= 1);
218 function GetAmmoByWeapon(Weapon
: Byte): Word;
219 procedure SetAction(Action
: Byte; Force
: Boolean = False);
220 procedure OnDamage(Angle
: SmallInt); virtual;
221 function firediry(): Integer;
224 procedure Run(Direction
: TDirection
);
225 procedure NextWeapon();
226 procedure PrevWeapon();
233 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
234 procedure resetWeaponQueue ();
235 function hasAmmoForWeapon (weapon
: Byte): Boolean;
237 procedure doDamage (v
: Integer);
239 function followCorpse(): Boolean;
242 FDamageBuffer
: Integer;
244 FAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
245 FMaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
246 FWeapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
247 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
249 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
250 FReloading
: Array [WP_FIRST
..WP_LAST
] of Word;
251 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
252 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
254 FPreferredTeam
: Byte;
257 FWantsInGame
: Boolean;
262 FActualModelName
: string;
270 // debug: viewport offset
271 viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer;
273 function isValidViewPort (): Boolean; inline;
275 constructor Create(); virtual;
276 destructor Destroy(); override;
277 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
278 function GetRespawnPoint(): Byte;
279 procedure PressKey(Key
: Byte; Time
: Word = 1);
280 procedure ReleaseKeys();
281 procedure SetModel(ModelName
: String);
282 procedure SetColor(Color
: TRGB
);
283 procedure SetWeapon(W
: Byte);
284 function IsKeyPressed(K
: Byte): Boolean;
285 function GetKeys(): Byte;
286 function PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean; virtual;
287 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
288 function Collide(Panel
: TPanel
): Boolean; overload
;
289 function Collide(X
, Y
: Integer): Boolean; overload
;
290 procedure SetDirection(Direction
: TDirection
);
291 procedure GetSecret();
292 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
294 procedure Push(vx
, vy
: Integer);
295 procedure ChangeModel(ModelName
: String);
296 procedure SwitchTeam
;
297 procedure ChangeTeam(Team
: Byte);
299 function GetFlag(Flag
: Byte): Boolean;
300 procedure SetFlag(Flag
: Byte);
301 function DropFlag(Silent
: Boolean = True): Boolean;
302 procedure AllRulez(Health
: Boolean);
303 procedure RestoreHealthArmor();
304 procedure FragCombo();
305 procedure GiveItem(ItemType
: Byte);
306 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
307 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
308 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
309 procedure MakeBloodSimple(Count
: Word);
310 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
311 procedure Reset(Force
: Boolean);
312 procedure Spectate(NoMove
: Boolean = False);
313 procedure SwitchNoClip
;
314 procedure SoftReset();
315 procedure Draw(); virtual;
316 procedure DrawPain();
317 procedure DrawPickup();
318 procedure DrawRulez();
320 procedure DrawIndicator();
321 procedure DrawBubble();
323 procedure Update(); virtual;
324 procedure RememberState();
325 procedure RecallState();
326 procedure SaveState (st
: TStream
); virtual;
327 procedure LoadState (st
: TStream
); virtual;
328 procedure PauseSounds(Enable
: Boolean);
329 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
330 procedure DoLerp(Level
: Integer = 2);
331 procedure SetLerp(XTo
, YTo
: Integer);
332 procedure QueueWeaponSwitch(Weapon
: Byte);
333 procedure RealizeCurrentWeapon();
337 procedure JetpackOff
;
338 procedure CatchFire(Attacker
: Word);
340 //WARNING! this does nothing for now, but still call it!
341 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
343 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
344 procedure moveBy (dx
, dy
: Integer); inline;
347 property Vel
: TPoint2i read FObj
.Vel
;
348 property Obj
: TObj read FObj
;
350 property Name
: String read FName write FName
;
351 property Model
: TPlayerModel read FModel
;
352 property Health
: Integer read FHealth write FHealth
;
353 property Lives
: Byte read FLives write FLives
;
354 property Armor
: Integer read FArmor write FArmor
;
355 property Air
: Integer read FAir write FAir
;
356 property JetFuel
: Integer read FJetFuel write FJetFuel
;
357 property Frags
: Integer read FFrags write FFrags
;
358 property Death
: Integer read FDeath write FDeath
;
359 property Kills
: Integer read FKills write FKills
;
360 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
361 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
362 property Secrets
: Integer read FSecrets
;
363 property GodMode
: Boolean read FGodMode write FGodMode
;
364 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
365 property NoReload
: Boolean read FNoReload write FNoReload
;
366 property alive
: Boolean read FAlive write FAlive
;
367 property Flag
: Byte read FFlag
;
368 property Team
: Byte read FTeam write FTeam
;
369 property Direction
: TDirection read FDirection
;
370 property GameX
: Integer read FObj
.X write FObj
.X
;
371 property GameY
: Integer read FObj
.Y write FObj
.Y
;
372 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
373 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
374 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
375 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
376 property IncCam
: Integer read FIncCam write FIncCam
;
377 property UID
: Word read FUID write FUID
;
378 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
379 property NetTime
: LongWord read FNetTime write FNetTime
;
382 property eName
: String read FName write FName
;
383 property eHealth
: Integer read FHealth write FHealth
;
384 property eLives
: Byte read FLives write FLives
;
385 property eArmor
: Integer read FArmor write FArmor
;
386 property eAir
: Integer read FAir write FAir
;
387 property eJetFuel
: Integer read FJetFuel write FJetFuel
;
388 property eFrags
: Integer read FFrags write FFrags
;
389 property eDeath
: Integer read FDeath write FDeath
;
390 property eKills
: Integer read FKills write FKills
;
391 property eCurrWeap
: Byte read FCurrWeap write FCurrWeap
;
392 property eMonsterKills
: Integer read FMonsterKills write FMonsterKills
;
393 property eSecrets
: Integer read FSecrets write FSecrets
;
394 property eGodMode
: Boolean read FGodMode write FGodMode
;
395 property eNoTarget
: Boolean read FNoTarget write FNoTarget
;
396 property eNoReload
: Boolean read FNoReload write FNoReload
;
397 property eAlive
: Boolean read FAlive write FAlive
;
398 property eFlag
: Byte read FFlag
;
399 property eTeam
: Byte read FTeam write FTeam
;
400 property eDirection
: TDirection read FDirection
;
401 property eGameX
: Integer read FObj
.X write FObj
.X
;
402 property eGameY
: Integer read FObj
.Y write FObj
.Y
;
403 property eGameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
404 property eGameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
405 property eGameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
406 property eGameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
407 property eIncCam
: Integer read FIncCam write FIncCam
;
408 property eUID
: Word read FUID
;
409 property eJustTeleported
: Boolean read FJustTeleported
;
410 property eNetTime
: LongWord read FNetTime
;
412 // set this before assigning something to `eDamage`
413 property eDamageType
: Integer read mEDamageType write mEDamageType
;
414 property eDamage
: Integer write doDamage
;
425 WeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
426 CloseWeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
427 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
430 procedure save (st
: TStream
);
431 procedure load (st
: TStream
);
439 TBot
= class(TPlayer
)
441 FSelectedWeapon
: Byte;
444 FAIFlags
: Array of TAIFlag
;
445 FDifficult
: TDifficult
;
447 function GetRnd(a
: Byte): Boolean;
448 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
449 function RunDirection(): TDirection
;
450 function FullInStep(XInc
, YInc
: Integer): Boolean;
451 //function NeedItem(Item: Byte): Byte;
452 procedure SelectWeapon(Dist
: Integer);
453 procedure SetAIFlag(aName
, fValue
: String20
);
454 function GetAIFlag(aName
: String20
): String20
;
455 procedure RemoveAIFlag(aName
: String20
);
456 function Healthy(): Byte;
457 procedure UpdateMove();
458 procedure UpdateCombat();
459 function KeyPressed(Key
: Word): Boolean;
460 procedure ReleaseKey(Key
: Byte);
461 function TargetOnScreen(TX
, TY
: Integer): Boolean;
462 procedure OnDamage(Angle
: SmallInt); override;
465 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
466 constructor Create(); override;
467 destructor Destroy(); override;
468 procedure Draw(); override;
469 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
470 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
471 procedure Update(); override;
472 procedure SaveState (st
: TStream
); override;
473 procedure LoadState (st
: TStream
); override;
485 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
486 procedure moveBy (dx
, dy
: Integer); inline;
488 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
502 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
503 procedure moveBy (dx
, dy
: Integer); inline;
505 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
508 TCorpse
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
517 FAnimation
: TAnimation
;
518 FAnimationMask
: TAnimation
;
521 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
522 destructor Destroy(); override;
523 procedure Damage(Value
: Word; vx
, vy
: Integer);
526 procedure SaveState (st
: TStream
);
527 procedure LoadState (st
: TStream
);
529 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
530 procedure moveBy (dx
, dy
: Integer); inline;
532 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
534 function ObjPtr (): PObj
; inline;
536 property Obj
: TObj read FObj
; // copies object
537 property State
: Byte read FState
;
538 property Mess
: Boolean read FMess
;
541 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
547 gPlayers
: Array of TPlayer
;
548 gCorpses
: Array of TCorpse
;
549 gGibs
: Array of TGib
;
550 gShells
: Array of TShell
;
551 gTeamStat
: TTeamStat
;
552 gFly
: Boolean = False;
553 gAimLine
: Boolean = False;
554 gChatBubble
: Byte = 0;
555 gPlayerIndicator
: Boolean = True;
559 MAX_RUNVEL
: Integer = 8;
560 VEL_JUMP
: Integer = 10;
561 SHELL_TIMEOUT
: Cardinal = 60000;
563 function Lerp(X
, Y
, Factor
: Integer): Integer;
565 procedure g_Gibs_SetMax(Count
: Word);
566 function g_Gibs_GetMax(): Word;
567 procedure g_Corpses_SetMax(Count
: Word);
568 function g_Corpses_GetMax(): Word;
569 procedure g_Shells_SetMax(Count
: Word);
570 function g_Shells_GetMax(): Word;
572 procedure g_Player_Init();
573 procedure g_Player_Free();
574 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
575 function g_Player_CreateFromState (st
: TStream
): Word;
576 procedure g_Player_Remove(UID
: Word);
577 procedure g_Player_ResetTeams();
578 procedure g_Player_UpdateAll();
579 procedure g_Player_DrawAll();
580 procedure g_Player_DrawDebug(p
: TPlayer
);
581 procedure g_Player_DrawHealth();
582 procedure g_Player_RememberAll();
583 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
584 function g_Player_Get(UID
: Word): TPlayer
;
585 function g_Player_GetCount(): Byte;
586 function g_Player_GetStats(): TPlayerStatArray
;
587 function g_Player_ValidName(Name
: String): Boolean;
588 procedure g_Player_CreateCorpse(Player
: TPlayer
);
589 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
590 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
591 procedure g_Player_UpdatePhysicalObjects();
592 procedure g_Player_DrawCorpses();
593 procedure g_Player_DrawShells();
594 procedure g_Player_RemoveAllCorpses();
595 procedure g_Player_Corpses_SaveState (st
: TStream
);
596 procedure g_Player_Corpses_LoadState (st
: TStream
);
597 procedure g_Player_ResetReady();
598 procedure g_Bot_Add(Team
, Difficult
: Byte);
599 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1);
600 procedure g_Bot_MixNames();
601 procedure g_Bot_RemoveAll();
606 {$INCLUDE ../nogl/noGLuses.inc}
607 {$IFDEF ENABLE_HOLMES}
610 e_log
, g_map
, g_items
, g_console
, g_gfx
, Math
,
611 g_options
, g_triggers
, g_menu
, g_game
, g_grid
,
612 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
,
613 g_net
, g_netmsg
, g_window
,
616 const PLR_SAVE_VERSION
= 0;
626 diag_precision
: Byte;
630 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
631 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
632 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
636 TIME_RESPAWN1
= 1500;
637 TIME_RESPAWN2
= 2000;
638 TIME_RESPAWN3
= 3000;
641 JET_MAX
= 540; // ~30 sec
642 PLAYER_SUIT_TIME
= 30000;
643 PLAYER_INVUL_TIME
= 30000;
644 PLAYER_INVIS_TIME
= 35000;
645 FRAG_COMBO_TIME
= 3000;
649 ANGLE_RIGHTDOWN
= -35;
651 ANGLE_LEFTDOWN
= -145;
652 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
653 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
656 BOT_UNSAFEDIST
= 128;
657 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
659 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
660 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
661 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
662 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
663 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
664 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
665 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
666 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
667 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
668 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
669 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
670 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
671 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
672 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
673 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
674 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
675 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
676 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
677 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
678 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
679 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
680 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
681 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
682 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
683 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
684 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
686 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
687 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
689 BOTNAMES_FILENAME
= 'botnames.txt';
690 BOTLIST_FILENAME
= 'botlist.txt';
694 MaxCorpses
: Word = 20;
695 MaxShells
: Word = 300;
696 CurrentGib
: Integer = 0;
697 CurrentShell
: Integer = 0;
698 BotNames
: Array of String;
699 BotList
: Array of TBotProfile
;
702 function Lerp(X
, Y
, Factor
: Integer): Integer;
704 Result
:= X
+ ((Y
- X
) div Factor
);
707 function SameTeam(UID1
, UID2
: Word): Boolean;
711 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
712 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
714 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
716 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
717 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
719 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
722 procedure g_Gibs_SetMax(Count
: Word);
725 SetLength(gGibs
, Count
);
727 if CurrentGib
>= Count
then
731 function g_Gibs_GetMax(): Word;
736 procedure g_Shells_SetMax(Count
: Word);
739 SetLength(gShells
, Count
);
741 if CurrentShell
>= Count
then
745 function g_Shells_GetMax(): Word;
751 procedure g_Corpses_SetMax(Count
: Word);
754 SetLength(gCorpses
, Count
);
757 function g_Corpses_GetMax(): Word;
759 Result
:= MaxCorpses
;
762 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
772 // Åñòü ëè ìåñòî â gPlayers:
773 if gPlayers
<> nil then
774 for a
:= 0 to High(gPlayers
) do
775 if gPlayers
[a
] = nil then
781 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
784 SetLength(gPlayers
, Length(gPlayers
)+1);
788 // Ñîçäàåì îáúåêò èãðîêà:
790 gPlayers
[a
] := TBot
.Create()
792 gPlayers
[a
] := TPlayer
.Create();
795 gPlayers
[a
].FActualModelName
:= ModelName
;
796 gPlayers
[a
].SetModel(ModelName
);
798 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
799 if gPlayers
[a
].FModel
= nil then
803 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
807 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
808 if Random(2) = 0 then
812 gPlayers
[a
].FPreferredTeam
:= Team
;
814 case gGameSettings
.GameMode
of
815 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
817 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
819 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
822 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
823 gPlayers
[a
].FColor
:= Color
;
824 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
825 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
827 gPlayers
[a
].FModel
.Color
:= Color
;
829 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
830 gPlayers
[a
].FAlive
:= False;
832 Result
:= gPlayers
[a
].FUID
;
835 function g_Player_CreateFromState (st
: TStream
): Word;
842 if (st
= nil) then exit
; //???
845 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
846 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
849 Bot
:= utils
.readBool(st
);
854 // Åñòü ëè ìåñòî â gPlayers:
855 for a
:= 0 to High(gPlayers
) do if (gPlayers
[a
] = nil) then begin ok
:= true; break
; end;
857 // Íåò ìåñòà - ðàñøèðÿåì gPlayers
860 SetLength(gPlayers
, Length(gPlayers
)+1);
864 // Ñîçäàåì îáúåêò èãðîêà
866 gPlayers
[a
] := TBot
.Create()
868 gPlayers
[a
] := TPlayer
.Create();
869 gPlayers
[a
].FIamBot
:= Bot
;
870 gPlayers
[a
].FPhysics
:= True;
873 gPlayers
[a
].FUID
:= utils
.readWord(st
);
875 gPlayers
[a
].FName
:= utils
.readStr(st
);
877 gPlayers
[a
].FTeam
:= utils
.readByte(st
);
878 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
880 gPlayers
[a
].FAlive
:= utils
.readBool(st
);
881 // Èçðàñõîäîâàë ëè âñå æèçíè
882 gPlayers
[a
].FNoRespawn
:= utils
.readBool(st
);
884 b
:= utils
.readByte(st
);
885 if b
= 1 then gPlayers
[a
].FDirection
:= TDirection
.D_LEFT
else gPlayers
[a
].FDirection
:= TDirection
.D_RIGHT
; // b = 2
887 gPlayers
[a
].FHealth
:= utils
.readLongInt(st
);
889 gPlayers
[a
].FLives
:= utils
.readByte(st
);
891 gPlayers
[a
].FArmor
:= utils
.readLongInt(st
);
893 gPlayers
[a
].FAir
:= utils
.readLongInt(st
);
895 gPlayers
[a
].FJetFuel
:= utils
.readLongInt(st
);
897 gPlayers
[a
].FPain
:= utils
.readLongInt(st
);
899 gPlayers
[a
].FKills
:= utils
.readLongInt(st
);
901 gPlayers
[a
].FMonsterKills
:= utils
.readLongInt(st
);
903 gPlayers
[a
].FFrags
:= utils
.readLongInt(st
);
905 gPlayers
[a
].FFragCombo
:= utils
.readByte(st
);
906 // Âðåìÿ ïîñëåäíåãî ôðàãà
907 gPlayers
[a
].FLastFrag
:= utils
.readLongWord(st
);
909 gPlayers
[a
].FDeath
:= utils
.readLongInt(st
);
911 gPlayers
[a
].FFlag
:= utils
.readByte(st
);
913 gPlayers
[a
].FSecrets
:= utils
.readLongInt(st
);
915 gPlayers
[a
].FCurrWeap
:= utils
.readByte(st
);
916 // Ñëåäóþùåå æåëàåìîå îðóæèå
917 gPlayers
[a
].FNextWeap
:= utils
.readWord(st
);
919 gPlayers
[a
].FNextWeapDelay
:= utils
.readByte(st
);
921 gPlayers
[a
].FBFGFireCounter
:= utils
.readSmallInt(st
);
923 gPlayers
[a
].FDamageBuffer
:= utils
.readLongInt(st
);
924 // Ïîñëåäíèé óäàðèâøèé
925 gPlayers
[a
].FLastSpawnerUID
:= utils
.readWord(st
);
926 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
927 gPlayers
[a
].FLastHit
:= utils
.readByte(st
);
929 Obj_LoadState(@gPlayers
[a
].FObj
, st
);
930 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
931 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FAmmo
[i
] := utils
.readWord(st
);
932 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
933 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FMaxAmmo
[i
] := utils
.readWord(st
);
935 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FWeapon
[i
] := utils
.readBool(st
);
936 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
937 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FReloading
[i
] := utils
.readWord(st
);
939 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
940 // Íàëè÷èå êðàñíîãî êëþ÷à
941 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
942 // Íàëè÷èå çåëåíîãî êëþ÷à
943 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
944 // Íàëè÷èå ñèíåãî êëþ÷à
945 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
947 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_BERSERK
);
948 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
949 for i
:= MR_SUIT
to MR_MAX
do gPlayers
[a
].FMegaRulez
[i
] := utils
.readLongWord(st
);
950 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
951 for i
:= T_RESPAWN
to T_FLAGCAP
do gPlayers
[a
].FTime
[i
] := utils
.readLongWord(st
);
954 gPlayers
[a
].FActualModelName
:= utils
.readStr(st
);
956 gPlayers
[a
].FColor
.R
:= utils
.readByte(st
);
957 gPlayers
[a
].FColor
.G
:= utils
.readByte(st
);
958 gPlayers
[a
].FColor
.B
:= utils
.readByte(st
);
959 // Îáíîâëÿåì ìîäåëü èãðîêà
960 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
962 // Íåò ìîäåëè - ñîçäàíèå íåâîçìîæíî
963 if (gPlayers
[a
].FModel
= nil) then
967 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
971 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû
972 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
973 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
975 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
977 result
:= gPlayers
[a
].FUID
;
981 procedure g_Player_ResetTeams();
985 if g_Game_IsClient
then
987 if gPlayers
= nil then
989 for a
:= Low(gPlayers
) to High(gPlayers
) do
990 if gPlayers
[a
] <> nil then
991 case gGameSettings
.GameMode
of
993 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
995 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
996 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
997 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
1000 gPlayers
[a
].ChangeTeam(TEAM_RED
)
1002 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
1005 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
1009 procedure g_Bot_Add(Team
, Difficult
: Byte);
1012 _name
, _model
: String;
1015 if not g_Game_IsServer
then Exit
;
1017 // Ñïèñîê íàçâàíèé ìîäåëåé:
1018 m
:= g_PlayerModel_GetNames();
1023 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1024 Team
:= TEAM_COOP
// COOP
1026 if gGameSettings
.GameMode
= GM_DM
then
1027 Team
:= TEAM_NONE
// DM
1029 if Team
= TEAM_NONE
then // CTF / TDM
1031 // Àâòîáàëàíñ êîìàíä:
1035 for a
:= 0 to High(gPlayers
) do
1036 if gPlayers
[a
] <> nil then
1038 if gPlayers
[a
].Team
= TEAM_RED
then
1041 if gPlayers
[a
].Team
= TEAM_BLUE
then
1051 if Random(2) = 0 then
1057 // Âûáèðàåì áîòó èìÿ:
1059 if BotNames
<> nil then
1060 for a
:= 0 to High(BotNames
) do
1061 if g_Player_ValidName(BotNames
[a
]) then
1063 _name
:= BotNames
[a
];
1067 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
1070 _name
:= Format('DFBOT%.2d', [Random(100)]);
1071 until g_Player_ValidName(_name
);
1073 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1074 _model
:= m
[Random(Length(m
))];
1077 with g_Player_Get(g_Player_Create(_model
,
1078 _RGB(Min(Random(9)*32, 255),
1079 Min(Random(9)*32, 255),
1080 Min(Random(9)*32, 255)),
1081 Team
, True)) as TBot
do
1086 1: FDifficult
:= DIFFICULT_EASY
;
1087 2: FDifficult
:= DIFFICULT_MEDIUM
;
1088 else FDifficult
:= DIFFICULT_HARD
;
1091 for a
:= WP_FIRST
to WP_LAST
do
1093 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1094 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1095 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1098 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1100 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1101 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1106 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1);
1109 _name
, _model
: String;
1112 if not g_Game_IsServer
then Exit
;
1114 // Ñïèñîê íàçâàíèé ìîäåëåé:
1115 m
:= g_PlayerModel_GetNames();
1120 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1121 Team
:= TEAM_COOP
// COOP
1123 if gGameSettings
.GameMode
= GM_DM
then
1124 Team
:= TEAM_NONE
// DM
1126 if Team
= TEAM_NONE
then
1127 Team
:= BotList
[num
].team
; // CTF / TDM
1129 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1130 lName
:= AnsiLowerCase(lName
);
1131 if (num
< 0) or (num
> Length(BotList
)-1) then
1133 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1134 for a
:= 0 to High(BotList
) do
1135 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1144 _name
:= BotList
[num
].name
;
1145 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1146 if not g_Player_ValidName(_name
) then
1148 _name
:= Format('DFBOT%.2d', [Random(100)]);
1149 until g_Player_ValidName(_name
);
1152 _model
:= BotList
[num
].model
;
1153 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1154 if not InSArray(_model
, m
) then
1155 _model
:= m
[Random(Length(m
))];
1158 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1162 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1163 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1164 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1165 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1166 FDifficult
.Cover
:= BotList
[num
].cover
;
1167 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1169 for a
:= WP_FIRST
to WP_LAST
do
1171 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1172 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1173 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1176 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1178 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1182 procedure g_Bot_RemoveAll();
1186 if not g_Game_IsServer
then Exit
;
1187 if gPlayers
= nil then Exit
;
1189 for a
:= 0 to High(gPlayers
) do
1190 if gPlayers
[a
] <> nil then
1191 if gPlayers
[a
] is TBot
then
1193 gPlayers
[a
].Lives
:= 0;
1194 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1195 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1196 g_Player_Remove(gPlayers
[a
].FUID
);
1202 procedure g_Bot_MixNames();
1207 if BotNames
<> nil then
1208 for a
:= 0 to High(BotNames
) do
1210 b
:= Random(Length(BotNames
));
1212 Botnames
[a
] := BotNames
[b
];
1217 procedure g_Player_Remove(UID
: Word);
1221 if gPlayers
= nil then Exit
;
1223 if g_Game_IsServer
and g_Game_IsNet
then
1224 MH_SEND_PlayerDelete(UID
);
1226 for i
:= 0 to High(gPlayers
) do
1227 if gPlayers
[i
] <> nil then
1228 if gPlayers
[i
].FUID
= UID
then
1230 if gPlayers
[i
] is TPlayer
then
1231 TPlayer(gPlayers
[i
]).Free()
1233 TBot(gPlayers
[i
]).Free();
1239 procedure g_Player_Init();
1249 if not FileExists(DataDir
+ BOTNAMES_FILENAME
) then
1252 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1253 AssignFile(F
, DataDir
+ BOTNAMES_FILENAME
);
1264 SetLength(BotNames
, Length(BotNames
)+1);
1265 BotNames
[High(BotNames
)] := s
;
1273 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1274 config
:= TConfig
.CreateFile(DataDir
+ BOTLIST_FILENAME
);
1278 while config
.SectionExists(IntToStr(a
)) do
1280 SetLength(BotList
, Length(BotList
)+1);
1282 with BotList
[High(BotList
)] do
1285 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1287 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1289 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1294 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1295 color
.R
:= StrToIntDef(sa
[0], 0);
1296 color
.G
:= StrToIntDef(sa
[1], 0);
1297 color
.B
:= StrToIntDef(sa
[2], 0);
1298 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1299 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1300 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1301 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1302 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1303 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1304 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1305 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1306 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1307 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1308 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1309 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1310 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1311 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1312 if Length(sa
) = 10 then
1314 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1315 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1316 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1317 if Length(sa
) = 10 then
1319 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1321 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1322 if Length(sa) = 10 then
1324 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1333 procedure g_Player_Free();
1337 if gPlayers
<> nil then
1339 for i
:= 0 to High(gPlayers
) do
1340 if gPlayers
[i
] <> nil then
1342 if gPlayers
[i
] is TPlayer
then
1343 TPlayer(gPlayers
[i
]).Free()
1345 TBot(gPlayers
[i
]).Free();
1356 procedure g_Player_UpdateAll();
1360 if gPlayers
= nil then Exit
;
1362 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1363 for i
:= 0 to High(gPlayers
) do
1365 if gPlayers
[i
] <> nil then
1367 if gPlayers
[i
] is TPlayer
then
1369 gPlayers
[i
].Update();
1370 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1374 // bot updates weapons in `UpdateCombat()`
1375 TBot(gPlayers
[i
]).Update();
1379 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1382 procedure g_Player_DrawAll();
1386 if gPlayers
= nil then Exit
;
1388 for i
:= 0 to High(gPlayers
) do
1389 if gPlayers
[i
] <> nil then
1390 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1391 else TBot(gPlayers
[i
]).Draw();
1394 procedure g_Player_DrawDebug(p
: TPlayer
);
1398 if p
= nil then Exit
;
1399 if (@p
.FObj
) = nil then Exit
;
1401 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1403 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1404 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1405 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1406 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1407 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1408 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1411 procedure g_Player_DrawHealth();
1416 if gPlayers
= nil then Exit
;
1417 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1419 for i
:= 0 to High(gPlayers
) do
1420 if gPlayers
[i
] <> nil then
1422 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1423 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1424 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1425 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1426 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1427 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1431 function g_Player_Get(UID
: Word): TPlayer
;
1437 if gPlayers
= nil then
1440 for a
:= 0 to High(gPlayers
) do
1441 if gPlayers
[a
] <> nil then
1442 if gPlayers
[a
].FUID
= UID
then
1444 Result
:= gPlayers
[a
];
1449 function g_Player_GetCount(): Byte;
1455 if gPlayers
= nil then
1458 for a
:= 0 to High(gPlayers
) do
1459 if gPlayers
[a
] <> nil then
1460 Result
:= Result
+ 1;
1463 function g_Player_GetStats(): TPlayerStatArray
;
1469 if gPlayers
= nil then Exit
;
1471 for a
:= 0 to High(gPlayers
) do
1472 if gPlayers
[a
] <> nil then
1474 SetLength(Result
, Length(Result
)+1);
1475 with Result
[High(Result
)] do
1478 Ping
:= gPlayers
[a
].FPing
;
1479 Loss
:= gPlayers
[a
].FLoss
;
1480 Name
:= gPlayers
[a
].FName
;
1481 Team
:= gPlayers
[a
].FTeam
;
1482 Frags
:= gPlayers
[a
].FFrags
;
1483 Deaths
:= gPlayers
[a
].FDeath
;
1484 Kills
:= gPlayers
[a
].FKills
;
1485 Color
:= gPlayers
[a
].FModel
.Color
;
1486 Lives
:= gPlayers
[a
].FLives
;
1487 Spectator
:= gPlayers
[a
].FSpectator
;
1492 procedure g_Player_ResetReady();
1496 if not g_Game_IsServer
then Exit
;
1497 if gPlayers
= nil then Exit
;
1499 for a
:= 0 to High(gPlayers
) do
1500 if gPlayers
[a
] <> nil then
1502 gPlayers
[a
].FReady
:= False;
1503 if g_Game_IsNet
then
1504 MH_SEND_GameEvent(NET_EV_INTER_READY
, gPlayers
[a
].UID
, 'N');
1508 procedure g_Player_RememberAll
;
1512 for i
:= Low(gPlayers
) to High(gPlayers
) do
1513 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1514 gPlayers
[i
].RememberState
;
1517 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1521 gTeamStat
[TEAM_RED
].Goals
:= 0;
1522 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1524 if gPlayers
<> nil then
1525 for i
:= 0 to High(gPlayers
) do
1526 if gPlayers
[i
] <> nil then
1528 gPlayers
[i
].Reset(Force
);
1530 if gPlayers
[i
] is TPlayer
then
1532 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1533 gPlayers
[i
].Respawn(Silent
)
1535 gPlayers
[i
].Spectate();
1538 TBot(gPlayers
[i
]).Respawn(Silent
);
1542 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1548 if Player
.alive
then
1551 // Ðàçðûâàåì ñâÿçü ñ ïðåæíèì òðóïîì:
1552 if gCorpses
<> nil then
1553 for i
:= 0 to High(gCorpses
) do
1554 if gCorpses
[i
] <> nil then
1555 if gCorpses
[i
].FPlayerUID
= Player
.FUID
then
1556 gCorpses
[i
].FPlayerUID
:= 0;
1558 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1563 if (FHealth
>= -50) or (gGibsCount
= 0) then
1565 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1569 for find_id
:= 0 to High(gCorpses
) do
1570 if gCorpses
[find_id
] = nil then
1577 find_id
:= Random(Length(gCorpses
));
1579 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1580 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1581 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1582 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1583 gCorpses
[find_id
].FPlayerUID
:= FUID
;
1586 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1587 FObj
.Y
+ PLAYER_RECT_CY
,
1588 FModel
.Name
, FModel
.Color
);
1592 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1596 if (gShells
= nil) or (Length(gShells
) = 0) then
1599 with gShells
[CurrentShell
] do
1605 if T
= SHELL_BULLET
then
1607 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1611 Obj
.Rect
.Width
:= 4;
1612 Obj
.Rect
.Height
:= 2;
1616 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1620 Obj
.Rect
.Width
:= 7;
1621 Obj
.Rect
.Height
:= 3;
1627 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1628 positionChanged(); // this updates spatial accelerators
1629 RAngle
:= Random(360);
1630 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1632 if CurrentShell
>= High(gShells
) then
1639 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1642 GibsArray
: TGibsArray
;
1645 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1647 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1649 Blood
:= g_PlayerModel_GetBlood(ModelName
);
1651 for a
:= 0 to High(GibsArray
) do
1652 with gGibs
[CurrentGib
] do
1655 ID
:= GibsArray
[a
].ID
;
1656 MaskID
:= GibsArray
[a
].MaskID
;
1659 Obj
.Rect
:= GibsArray
[a
].Rect
;
1660 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1661 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1662 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1663 positionChanged(); // this updates spatial accelerators
1664 RAngle
:= Random(360);
1666 if gBloodCount
> 0 then
1667 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1668 Random(48), Random(48), Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
1670 if CurrentGib
>= High(gGibs
) then
1677 procedure g_Player_UpdatePhysicalObjects();
1683 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1688 if T
= SHELL_BULLET
then
1689 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1691 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1696 if gGibs
<> nil then
1697 for i
:= 0 to High(gGibs
) do
1698 if gGibs
[i
].alive
then
1702 mr
:= g_Obj_Move(@Obj
, True, False, True);
1703 positionChanged(); // this updates spatial accelerators
1705 if WordBool(mr
and MOVE_FALLOUT
) then
1711 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1712 if WordBool(mr
and MOVE_HITWALL
) then
1713 Obj
.Vel
.X
:= -(vel
.X
div 2);
1714 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1715 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1717 if (Obj
.Vel
.X
>= 0) then
1719 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1720 if RAngle
>= 360 then
1721 RAngle
:= RAngle
mod 360;
1722 end else begin // Counter-clockwise
1723 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1725 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1728 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1729 if gTime
mod (GAME_TICK
*3) = 0 then
1730 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1734 if gCorpses
<> nil then
1735 for i
:= 0 to High(gCorpses
) do
1736 if gCorpses
[i
] <> nil then
1737 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1743 gCorpses
[i
].Update();
1746 if gShells
<> nil then
1747 for i
:= 0 to High(gShells
) do
1748 if gShells
[i
].alive
then
1752 mr
:= g_Obj_Move(@Obj
, True, False, True);
1753 positionChanged(); // this updates spatial accelerators
1755 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1761 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1762 if WordBool(mr
and MOVE_HITWALL
) then
1764 Obj
.Vel
.X
:= -(vel
.X
div 2);
1765 if not WordBool(mr
and MOVE_INWATER
) then
1766 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1768 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1770 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1771 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1772 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1774 if RAngle
mod 90 <> 0 then
1775 RAngle
:= (RAngle
div 90) * 90;
1777 else if not WordBool(mr
and MOVE_INWATER
) then
1778 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1781 if (Obj
.Vel
.X
>= 0) then
1783 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1784 if RAngle
>= 360 then
1785 RAngle
:= RAngle
mod 360;
1786 end else begin // Counter-clockwise
1787 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1789 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1795 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1797 x
:= Obj
.X
+Obj
.Rect
.X
;
1798 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1799 w
:= Obj
.Rect
.Width
;
1800 h
:= Obj
.Rect
.Height
;
1803 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1805 if (dx
<> 0) or (dy
<> 0) then
1814 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1818 w
:= Obj
.Rect
.Width
;
1819 h
:= Obj
.Rect
.Height
;
1822 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1824 if (dx
<> 0) or (dy
<> 0) then
1833 procedure TGib
.positionChanged (); inline; begin end;
1834 procedure TShell
.positionChanged (); inline; begin end;
1837 procedure g_Player_DrawCorpses();
1842 if gGibs
<> nil then
1843 for i
:= 0 to High(gGibs
) do
1844 if gGibs
[i
].alive
then
1847 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1850 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1851 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1853 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1856 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1862 if gCorpses
<> nil then
1863 for i
:= 0 to High(gCorpses
) do
1864 if gCorpses
[i
] <> nil then
1868 procedure g_Player_DrawShells();
1873 if gShells
<> nil then
1874 for i
:= 0 to High(gShells
) do
1875 if gShells
[i
].alive
then
1878 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1884 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1888 procedure g_Player_RemoveAllCorpses();
1894 SetLength(gGibs
, MaxGibs
);
1895 SetLength(gShells
, MaxGibs
);
1899 if gCorpses
<> nil then
1900 for i
:= 0 to High(gCorpses
) do
1904 SetLength(gCorpses
, MaxCorpses
);
1907 procedure g_Player_Corpses_SaveState (st
: TStream
);
1911 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ
1913 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1915 // Êîëè÷åñòâî òðóïîâ
1916 utils
.writeInt(st
, LongInt(count
));
1918 if (count
= 0) then exit
;
1921 for i
:= 0 to High(gCorpses
) do
1923 if gCorpses
[i
] <> nil then
1926 utils
.writeStr(st
, gCorpses
[i
].FModelName
);
1928 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1929 // Ñîõðàíÿåì äàííûå òðóïà:
1930 gCorpses
[i
].SaveState(st
);
1936 procedure g_Player_Corpses_LoadState (st
: TStream
);
1944 g_Player_RemoveAllCorpses();
1946 // Êîëè÷åñòâî òðóïîâ:
1947 count
:= utils
.readLongInt(st
);
1948 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1950 if (count
= 0) then exit
;
1953 for i
:= 0 to count
-1 do
1956 str
:= utils
.readStr(st
);
1958 b
:= utils
.readBool(st
);
1960 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1961 // Çàãðóæàåì äàííûå òðóïà
1962 gCorpses
[i
].LoadState(st
);
1969 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1971 procedure TPlayer
.BFGHit();
1973 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1974 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1975 if g_Game_IsServer
and g_Game_IsNet
then
1976 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1977 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1981 procedure TPlayer
.ChangeModel(ModelName
: string);
1983 locModel
: TPlayerModel
;
1985 locModel
:= g_PlayerModel_Get(ModelName
);
1986 if locModel
= nil then Exit
;
1992 procedure TPlayer
.SetModel(ModelName
: string);
1996 m
:= g_PlayerModel_Get(ModelName
);
1999 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
2000 m
:= g_PlayerModel_Get('doomer');
2003 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
2008 if FModel
<> nil then
2013 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2014 FModel
.Color
:= FColor
2016 FModel
.Color
:= TEAMCOLOR
[FTeam
];
2017 FModel
.SetWeapon(FCurrWeap
);
2018 FModel
.SetFlag(FFlag
);
2019 SetDirection(FDirection
);
2022 procedure TPlayer
.SetColor(Color
: TRGB
);
2025 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2026 if FModel
<> nil then FModel
.Color
:= Color
;
2029 procedure TPlayer
.SwitchTeam
;
2031 if g_Game_IsClient
then
2033 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
2035 if gGameOn
and FAlive
then
2036 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
2038 if FTeam
= TEAM_RED
then
2040 ChangeTeam(TEAM_BLUE
);
2041 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
2042 if g_Game_IsNet
then
2043 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
2047 ChangeTeam(TEAM_RED
);
2048 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
2049 if g_Game_IsNet
then
2050 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
2052 FPreferredTeam
:= FTeam
;
2055 procedure TPlayer
.ChangeTeam(Team
: Byte);
2062 TEAM_RED
, TEAM_BLUE
:
2063 FModel
.Color
:= TEAMCOLOR
[Team
];
2065 FModel
.Color
:= FColor
;
2067 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2068 MH_SEND_PlayerStats(FUID
);
2072 procedure TPlayer.CollideItem();
2077 if gItems = nil then Exit;
2078 if not FAlive then Exit;
2080 for i := 0 to High(gItems) do
2083 if (ItemType <> ITEM_NONE) and alive then
2084 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2085 PLAYER_RECT.Height, @Obj) then
2087 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2089 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2090 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2091 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2092 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2093 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2095 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2096 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2097 (gGameSettings.GameType = GT_SINGLE) and
2098 (g_Player_GetCount() > 1)) then
2099 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2105 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2107 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2108 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2112 constructor TPlayer
.Create();
2118 mEDamageType
:= HIT_SOME
;
2124 FSawSound
:= TPlayableSound
.Create();
2125 FSawSoundIdle
:= TPlayableSound
.Create();
2126 FSawSoundHit
:= TPlayableSound
.Create();
2127 FSawSoundSelect
:= TPlayableSound
.Create();
2128 FFlameSoundOn
:= TPlayableSound
.Create();
2129 FFlameSoundOff
:= TPlayableSound
.Create();
2130 FFlameSoundWork
:= TPlayableSound
.Create();
2131 FJetSoundFly
:= TPlayableSound
.Create();
2132 FJetSoundOn
:= TPlayableSound
.Create();
2133 FJetSoundOff
:= TPlayableSound
.Create();
2135 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2136 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2137 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2138 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2139 FFlameSoundOn
.SetByName('SOUND_WEAPON_FLAMEON');
2140 FFlameSoundOff
.SetByName('SOUND_WEAPON_FLAMEOFF');
2141 FFlameSoundWork
.SetByName('SOUND_WEAPON_FLAMEWORK');
2142 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2143 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2144 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2146 FSpectatePlayer
:= -1;
2150 FSavedState
.WaitRecall
:= False;
2156 FActualModelName
:= 'doomer';
2159 FObj
.Rect
:= PLAYER_RECT
;
2161 FBFGFireCounter
:= -1;
2162 FJustTeleported
:= False;
2168 procedure TPlayer
.positionChanged (); inline;
2172 procedure TPlayer
.doDamage (v
: Integer);
2174 if (v
<= 0) then exit
;
2175 if (v
> 32767) then v
:= 32767;
2176 Damage(v
, 0, 0, 0, mEDamageType
);
2179 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2183 if (not g_Game_IsClient
) and (not FAlive
) then
2188 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2189 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2191 if not g_Game_IsClient
then
2194 if t
= HIT_TRAP
then
2196 // Ëîâóøêà óáèâàåò ñðàçó:
2198 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2200 if t
= HIT_SELF
then
2204 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2207 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2208 FMegaRulez
[MR_SUIT
] := 0;
2209 FMegaRulez
[MR_INVUL
] := 0;
2210 FMegaRulez
[MR_INVIS
] := 0;
2214 // Íî îò îñòàëüíîãî ñïàñàåò:
2215 if FMegaRulez
[MR_INVUL
] >= gTime
then
2222 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2223 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2224 (SpawnerUID
= FUID
) or
2225 (not SameTeam(FUID
, SpawnerUID
)) then
2227 FLastSpawnerUID
:= SpawnerUID
;
2229 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2230 if gBloodCount
> 0 then
2232 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2233 if value
div 4 <= c
then
2234 c
:= c
- (value
div 4)
2238 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2242 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2243 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2246 if t
= HIT_WATER
then
2247 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2248 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2253 Inc(FDamageBuffer
, value
);
2257 FPain
:= FPain
+ value
;
2260 if g_Game_IsServer
and g_Game_IsNet
then
2262 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2263 MH_SEND_PlayerStats(FUID
);
2264 MH_SEND_PlayerPos(False, FUID
);
2268 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2271 if g_Game_IsClient
then
2276 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2278 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2281 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2283 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2287 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2288 MH_SEND_PlayerStats(FUID
);
2291 destructor TPlayer
.Destroy();
2293 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2295 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2299 FSawSoundIdle
.Free();
2300 FSawSoundHit
.Free();
2301 FSawSoundSelect
.Free();
2302 FFlameSoundOn
.Free();
2303 FFlameSoundOff
.Free();
2304 FFlameSoundWork
.Free();
2305 FJetSoundFly
.Free();
2307 FJetSoundOff
.Free();
2309 if FPunchAnim
<> nil then
2315 procedure TPlayer
.DrawIndicator();
2317 indX
, indY
: Integer;
2323 indX
:= FObj
.X
+FObj
.Rect
.X
;
2325 if g_Texture_Get('TEXTURE_PLAYER_INDICATOR', ID
) then
2327 e_GetTextureSize(ID
, @indW
, @indH
);
2328 e_Draw(ID
, indX
+ indW
div 2, indY
- indH
, 0, True, False);
2331 //e_TextureFontPrint(indX, indY, FName, gStdFont); // Shows player name overhead
2334 procedure TPlayer
.DrawBubble();
2336 bubX
, bubY
: Integer;
2339 Rw
, Gw
, Bw
: SmallInt;
2342 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= TDirection
.D_LEFT
, -4, 18);
2343 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2351 1: // simple textual non-bubble
2353 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2354 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2355 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2358 2: // advanced pixel-perfect bubble
2360 if FTeam
= TEAM_RED
then
2363 if FTeam
= TEAM_BLUE
then
2366 3: // colored bubble
2368 Rb
:= FModel
.Color
.R
;
2369 Gb
:= FModel
.Color
.G
;
2370 Bb
:= FModel
.Color
.B
;
2371 Rw
:= Min(Rb
* 2 + 64, 255);
2372 Gw
:= Min(Gb
* 2 + 64, 255);
2373 Bw
:= Min(Bb
* 2 + 64, 255);
2374 if (Abs(Rw
- Rb
) < 32)
2375 or (Abs(Gw
- Gb
) < 32)
2376 or (Abs(Bw
- Bb
) < 32) then
2378 Rb
:= Max(Rw
div 2 - 16, 0);
2379 Gb
:= Max(Gw
div 2 - 16, 0);
2380 Bb
:= Max(Bw
div 2 - 16, 0);
2383 4: // custom textured bubble
2385 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2386 if FDirection
= TDirection
.D_RIGHT
then
2387 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2389 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, TMirrorType
.Horizontal
);
2395 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2396 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2398 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2401 Dot
:= IfThen(FDirection
= TDirection
.D_LEFT
, 14, 5);
2402 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2403 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
);
2404 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
);
2405 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
);
2406 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
);
2410 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2411 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2412 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2415 procedure TPlayer
.Draw();
2420 Mirror
: TMirrorType
;
2424 if Direction
= TDirection
.D_RIGHT
then
2425 Mirror
:= TMirrorType
.None
2427 Mirror
:= TMirrorType
.Horizontal
;
2429 if FPunchAnim
<> nil then
2431 FPunchAnim
.Draw(FObj
.X
+IfThen(Direction
= TDirection
.D_LEFT
, 15-FObj
.Rect
.X
, FObj
.Rect
.X
-15),
2432 FObj
.Y
+FObj
.Rect
.Y
-11, Mirror
);
2433 if FPunchAnim
.played
then
2440 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2441 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2443 e_GetTextureSize(ID
, @w
, @h
);
2444 if FDirection
= TDirection
.D_LEFT
then
2445 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2446 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False)
2448 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2449 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False);
2452 if FMegaRulez
[MR_INVIS
] > gTime
then
2454 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2455 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2457 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2458 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2462 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 200)
2464 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2467 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 254);
2470 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2473 if g_debug_Frames
then
2475 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2477 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2478 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2482 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2483 if (FMegaRulez
[MR_INVIS
] <= gTime
) or ((gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2484 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
)))) then
2486 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2487 if gAimLine
and alive
and
2488 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2493 procedure TPlayer
.DrawAim();
2494 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2499 {$IFDEF ENABLE_HOLMES}
2500 if isValidViewPort
and (self
= gPlayer1
) then
2502 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2506 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2507 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2509 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2513 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2518 wx
, wy
, xx
, yy
: Integer;
2522 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= TDirection
.D_LEFT
, 7, -7);
2523 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2532 1: begin // Chainsaw
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);
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 4: begin // Double Shotgun
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 5: begin // Chaingun
2563 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2564 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2565 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2566 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2568 6: begin // Rocket Launcher
2571 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2572 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2573 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2574 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2576 7: begin // Plasmagun
2579 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2580 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2581 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2582 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2587 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2588 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2589 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2590 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2592 9: begin // Super Chaingun
2595 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2596 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2597 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2598 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2601 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2602 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2603 {$IF DEFINED(D2F_DEBUG)}
2604 drawCast(sz
, wx
, wy
, xx
, yy
);
2606 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2610 procedure TPlayer
.DrawGUI();
2613 X
, Y
, SY
, a
, p
, m
: Integer;
2617 stat
: TPlayerStatArray
;
2619 X
:= gPlayerScreenSize
.X
;
2620 SY
:= gPlayerScreenSize
.Y
;
2623 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2625 if gGameSettings
.GameMode
= GM_CTF
then
2629 if gGameSettings
.GameMode
= GM_CTF
then
2631 s
:= 'TEXTURE_PLAYER_REDFLAG';
2632 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2633 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2634 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2635 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2636 if g_Texture_Get(s
, ID
) then
2637 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2640 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2641 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2642 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2644 if gGameSettings
.GameMode
= GM_CTF
then
2646 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2647 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2648 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2649 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2650 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2651 if g_Texture_Get(s
, ID
) then
2652 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2655 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2656 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2657 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2660 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2661 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2664 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2665 e_Draw(ID
, X
+2, Y
, 0, True, False);
2667 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2671 s
:= IntToStr(Frags
);
2672 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2673 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2678 stat
:= g_Player_GetStats();
2683 for a
:= 0 to High(stat
) do
2684 if stat
[a
].Name
<> Name
then
2686 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2687 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2691 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2692 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2693 s
:= s
+IntToStr(Abs(Frags
-m
));
2695 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2696 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2699 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2701 s
:= IntToStr(Lives
);
2702 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2703 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2707 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2708 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2710 if R_BERSERK
in FRulez
then
2711 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2713 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2715 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2716 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2718 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2719 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2720 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2722 s
:= IntToStr(FArmor
);
2723 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2724 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2726 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2732 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2737 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2739 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2740 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2741 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2742 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2743 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2744 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2745 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2746 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2747 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2750 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2751 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2752 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2754 if R_KEY_RED
in FRulez
then
2755 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2757 if R_KEY_GREEN
in FRulez
then
2758 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2760 if R_KEY_BLUE
in FRulez
then
2761 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2763 if FJetFuel
> 0 then
2765 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2766 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2767 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2768 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2769 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2770 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2774 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2775 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2776 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2779 if gShowPing
and g_Game_IsClient
then
2781 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2782 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2788 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2789 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2790 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2793 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2794 s
:= _lc
[I_PLAYER_SPECT4
];
2795 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2796 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2797 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2803 procedure TPlayer
.DrawRulez();
2807 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2808 if FMegaRulez
[MR_INVUL
] >= gTime
then
2810 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2811 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2816 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2817 191, 191, 191, 0, TBlending
.Invert
);
2820 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2821 if FMegaRulez
[MR_SUIT
] >= gTime
then
2823 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2824 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2829 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2830 0, 96, 0, 200, TBlending
.None
);
2833 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2834 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2836 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2837 255, 0, 0, 200, TBlending
.None
);
2841 procedure TPlayer
.DrawPain();
2845 if FPain
= 0 then Exit
;
2849 if a
< 15 then h
:= 0
2850 else if a
< 35 then h
:= 1
2851 else if a
< 55 then h
:= 2
2852 else if a
< 75 then h
:= 3
2853 else if a
< 95 then h
:= 4
2856 //if a > 255 then a := 255;
2858 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2859 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2862 procedure TPlayer
.DrawPickup();
2866 if FPickup
= 0 then Exit
;
2870 if a
< 15 then h
:= 1
2871 else if a
< 35 then h
:= 2
2872 else if a
< 55 then h
:= 3
2873 else if a
< 75 then h
:= 4
2876 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2879 procedure TPlayer
.DoPunch();
2884 if FPunchAnim
<> nil then begin
2889 st
:= 'FRAMES_PUNCH';
2890 if R_BERSERK
in FRulez
then
2891 st
:= st
+ '_BERSERK';
2892 if FKeys
[KEY_UP
].Pressed
then
2894 else if FKeys
[KEY_DOWN
].Pressed
then
2896 g_Frames_Get(id
, st
);
2897 FPunchAnim
:= TAnimation
.Create(id
, False, 1);
2900 procedure TPlayer
.Fire();
2902 f
, DidFire
: Boolean;
2903 wx
, wy
, xd
, yd
: Integer;
2906 if g_Game_IsClient
then Exit
;
2907 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2908 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2916 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2921 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2922 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2923 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
2924 yd
:= wy
+firediry();
2930 if R_BERSERK
in FRulez
then
2932 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2933 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2934 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2937 locobj
.rect
.Width
:= 39;
2938 locobj
.rect
.Height
:= 52;
2939 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2940 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2941 locobj
.Accel
.X
:= xd
-wx
;
2942 locobj
.Accel
.y
:= yd
-wy
;
2944 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2945 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2947 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2949 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
2953 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2957 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2962 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2963 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2965 FSawSoundSelect
.Stop();
2967 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2969 else if not FSawSoundHit
.IsPlaying() then
2971 FSawSoundSelect
.Stop();
2972 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2975 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2981 if FAmmo
[A_BULLETS
] > 0 then
2983 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2984 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2985 Dec(FAmmo
[A_BULLETS
]);
2986 FFireAngle
:= FAngle
;
2989 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2990 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2994 if FAmmo
[A_SHELLS
] > 0 then
2996 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2997 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
2998 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2999 Dec(FAmmo
[A_SHELLS
]);
3000 FFireAngle
:= FAngle
;
3004 FShellType
:= SHELL_SHELL
;
3008 if FAmmo
[A_SHELLS
] >= 2 then
3010 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
3011 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3012 Dec(FAmmo
[A_SHELLS
], 2);
3013 FFireAngle
:= FAngle
;
3017 FShellType
:= SHELL_DBLSHELL
;
3021 if FAmmo
[A_BULLETS
] > 0 then
3023 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
3024 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
3025 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3026 Dec(FAmmo
[A_BULLETS
]);
3027 FFireAngle
:= FAngle
;
3030 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3031 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3034 WEAPON_ROCKETLAUNCHER
:
3035 if FAmmo
[A_ROCKETS
] > 0 then
3037 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
3038 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3039 Dec(FAmmo
[A_ROCKETS
]);
3040 FFireAngle
:= FAngle
;
3046 if FAmmo
[A_CELLS
] > 0 then
3048 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
3049 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3050 Dec(FAmmo
[A_CELLS
]);
3051 FFireAngle
:= FAngle
;
3057 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
3059 FBFGFireCounter
:= 17;
3060 if not FNoReload
then
3061 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
3062 Dec(FAmmo
[A_CELLS
], 40);
3066 WEAPON_SUPERPULEMET
:
3067 if FAmmo
[A_SHELLS
] > 0 then
3069 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3070 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
3071 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3072 Dec(FAmmo
[A_SHELLS
]);
3073 FFireAngle
:= FAngle
;
3076 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3077 GameVelX
, GameVelY
-2, SHELL_SHELL
);
3080 WEAPON_FLAMETHROWER
:
3081 if FAmmo
[A_FUEL
] > 0 then
3083 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
3085 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3087 FFireAngle
:= FAngle
;
3094 if g_Game_IsNet
and g_Game_IsServer
then MH_SEND_PlayerStats(FUID
);
3098 if g_Game_IsNet
then
3102 if FCurrWeap
<> WEAPON_BFG
then
3103 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
3105 if not FNoReload
then
3106 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
3109 MH_SEND_PlayerStats(FUID
);
3114 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
3115 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
3116 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
3119 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
3122 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
3123 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
3124 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
3125 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
3126 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
3131 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
3133 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
3134 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
3135 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
3138 procedure TPlayer
.FlamerOn
;
3140 FFlameSoundOff
.Stop();
3141 FFlameSoundOff
.SetPosition(0);
3144 if (not FFlameSoundOn
.IsPlaying()) and (not FFlameSoundWork
.IsPlaying()) then
3145 FFlameSoundWork
.PlayAt(FObj
.X
, FObj
.Y
);
3149 FFlameSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3154 procedure TPlayer
.FlamerOff
;
3158 FFlameSoundOn
.Stop();
3159 FFlameSoundOn
.SetPosition(0);
3160 FFlameSoundWork
.Stop();
3161 FFlameSoundWork
.SetPosition(0);
3162 FFlameSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3167 procedure TPlayer
.JetpackOn
;
3171 FJetSoundOn
.SetPosition(0);
3172 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3176 procedure TPlayer
.JetpackOff
;
3180 FJetSoundOff
.SetPosition(0);
3181 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3184 procedure TPlayer
.CatchFire(Attacker
: Word);
3186 if FFireTime
<= 0 then
3187 g_Sound_PlayExAt('SOUND_IGNITE', FObj
.X
, FObj
.Y
);
3189 FFireAttacker
:= Attacker
;
3190 if g_Game_IsNet
and g_Game_IsServer
then
3191 MH_SEND_PlayerStats(FUID
);
3194 procedure TPlayer
.Jump();
3196 if gFly
or FJetpack
then
3198 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3199 if FObj
.Vel
.Y
> -VEL_FLY
then
3200 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3203 if FJetFuel
> 0 then
3205 if (FJetFuel
< 1) and g_Game_IsServer
then
3209 if g_Game_IsNet
then
3210 MH_SEND_PlayerStats(FUID
);
3216 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3218 FCanJetpack
:= False;
3220 // Ïðûãàåì èëè âñïëûâàåì:
3221 if (CollideLevel(0, 1) or
3222 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3223 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3224 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3226 FObj
.Vel
.Y
:= -VEL_JUMP
;
3227 FCanJetpack
:= False;
3231 if BodyInLiquid(0, 0) then
3232 FObj
.Vel
.Y
:= -VEL_SW
3233 else if (FJetFuel
> 0) and FCanJetpack
and
3234 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3238 if g_Game_IsNet
then
3239 MH_SEND_PlayerStats(FUID
);
3244 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3246 a
, i
, k
, ab
, ar
: Byte;
3250 srv
, netsrv
: Boolean;
3256 procedure PushItem(t
: Byte);
3260 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3261 it
:= g_Items_ByIdx(id
);
3262 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3264 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3265 (FObj
.Vel
.Y
div 2)-Random(9));
3266 it
.positionChanged(); // this updates spatial accelerators
3270 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3272 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3273 (FObj
.Vel
.Y
div 2)-Random(6));
3275 else // -3..+3; -3..0
3277 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3278 (FObj
.Vel
.Y
div 2)-Random(4));
3280 it
.positionChanged(); // this updates spatial accelerators
3283 if g_Game_IsNet
and g_Game_IsServer
then
3284 MH_SEND_ItemSpawn(True, id
);
3288 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3289 Srv
:= g_Game_IsServer
;
3290 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3291 if Srv
then FDeath
:= FDeath
+ 1;
3296 if not FPhysics
then
3302 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3304 if FLives
> 0 then FLives
:= FLives
- 1;
3305 if FLives
= 0 then FNoRespawn
:= True;
3308 // Íîìåð òèïà ñìåðòè:
3311 K_SIMPLEKILL
: a
:= 1;
3313 K_EXTRAHARDKILL
: a
:= 3;
3318 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3320 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3327 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3329 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3330 K_EXTRAHARDKILL
, K_FALLKILL
:
3331 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3334 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3338 K_HARDKILL
, K_EXTRAHARDKILL
:
3342 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3343 if (KillType
<> K_FALLKILL
) and (Srv
) then
3344 g_Monsters_killedp();
3346 if SpawnerUID
= FUID
then
3348 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3353 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3356 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3357 begin // Óáèò äðóãèì èãðîêîì
3358 KP
:= g_Player_Get(SpawnerUID
);
3359 if (KP
<> nil) and Srv
then
3361 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3362 if SameTeam(FUID
, SpawnerUID
) then
3372 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3373 Inc(gTeamStat
[KP
.Team
].Goals
,
3374 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3376 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3379 plr
:= g_Player_Get(SpawnerUID
);
3387 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3391 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3395 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3400 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3401 begin // Óáèò ìîíñòðîì
3402 mon
:= g_Monsters_ByUID(SpawnerUID
);
3406 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
3410 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3414 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3418 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3423 else // Îñîáûå òèïû ñìåðòè
3426 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3427 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3428 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3429 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3430 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3431 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3437 for a
:= WP_FIRST
to WP_LAST
do
3441 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3442 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3443 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3444 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3445 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3446 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3447 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3448 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3449 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3458 if R_ITEM_BACKPACK
in FRulez
then
3459 PushItem(ITEM_AMMO_BACKPACK
);
3461 // Âûáðîñ ðàêåòíîãî ðàíöà:
3462 if FJetFuel
> 0 then
3463 PushItem(ITEM_JETPACK
);
3466 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3468 if R_KEY_RED
in FRulez
then
3469 PushItem(ITEM_KEY_RED
);
3471 if R_KEY_GREEN
in FRulez
then
3472 PushItem(ITEM_KEY_GREEN
);
3474 if R_KEY_BLUE
in FRulez
then
3475 PushItem(ITEM_KEY_BLUE
);
3479 DropFlag(KillType
= K_FALLKILL
);
3482 g_Player_CreateCorpse(Self
);
3484 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3485 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3491 for i
:= Low(gPlayers
) to High(gPlayers
) do
3493 if gPlayers
[i
] = nil then continue
;
3494 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3497 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3498 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3503 OldLR
:= gLMSRespawn
;
3504 if (gGameSettings
.GameMode
= GM_COOP
) then
3508 // everyone is dead, restart the map
3509 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3511 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3512 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3513 gLMSRespawnTime
:= gTime
+ 5000;
3515 else if (a
= 1) then
3517 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3518 if (gPlayers
[k
] = gPlayer1
) or
3519 (gPlayers
[k
] = gPlayer2
) then
3520 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3521 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3522 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3525 else if (gGameSettings
.GameMode
= GM_TDM
) then
3527 if (ab
= 0) and (ar
<> 0) then
3530 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3532 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3533 Inc(gTeamStat
[TEAM_RED
].Goals
);
3534 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3535 gLMSRespawnTime
:= gTime
+ 5000;
3537 else if (ar
= 0) and (ab
<> 0) then
3540 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3542 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3543 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3544 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3545 gLMSRespawnTime
:= gTime
+ 5000;
3547 else if (ar
= 0) and (ab
= 0) then
3550 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3552 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3553 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3554 gLMSRespawnTime
:= gTime
+ 5000;
3557 else if (gGameSettings
.GameMode
= GM_DM
) then
3561 if gPlayers
[k
] <> nil then
3564 // survivor is the winner
3565 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3567 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3570 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3571 gLMSRespawnTime
:= gTime
+ 5000;
3573 else if (a
= 0) then
3575 // everyone is dead, restart the map
3576 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3578 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3579 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3580 gLMSRespawnTime
:= gTime
+ 5000;
3583 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3585 if NetMode
= NET_SERVER
then
3586 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3588 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3594 MH_SEND_PlayerStats(FUID
);
3595 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3596 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3599 if srv
and FNoRespawn
then Spectate(True);
3600 FWantsInGame
:= True;
3603 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3605 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3606 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3609 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3611 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3612 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3615 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3617 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3618 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3619 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3620 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3621 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3622 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3623 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3624 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3627 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3629 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3630 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3631 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3632 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3635 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3637 if g_Game_IsClient
then Exit
;
3638 if Weapon
> High(FWeapon
) then Exit
;
3639 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3642 procedure TPlayer
.resetWeaponQueue ();
3645 FNextWeapDelay
:= 0;
3648 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3652 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3653 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 0);
3654 WEAPON_PISTOL
, WEAPON_CHAINGUN
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_BULLETS
] > 0);
3655 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3656 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3657 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3658 else result
:= (weapon
< length(FWeapon
));
3662 // return 255 for "no switch"
3663 function TPlayer
.getNextWeaponIndex (): Byte;
3666 wantThisWeapon
: array[0..64] of Boolean;
3667 wwc
: Integer = 0; //HACK!
3670 result
:= 255; // default result: "no switch"
3671 // had weapon cycling on previous frame? remove that flag
3672 if (FNextWeap
and $2000) <> 0 then
3674 FNextWeap
:= FNextWeap
and $1FFF;
3675 FNextWeapDelay
:= 0;
3677 // cycling has priority
3678 if (FNextWeap
and $C000) <> 0 then
3680 if (FNextWeap
and $8000) <> 0 then
3684 FNextWeap
:= FNextWeap
or $2000; // we need this
3685 if FNextWeapDelay
> 0 then
3686 exit
; // cooldown time
3688 for i
:= 0 to High(FWeapon
) do
3690 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3691 if FWeapon
[cwi
] then
3693 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d', [FCurrWeap, cwi]), MSG_WARNING);
3694 result
:= Byte(cwi
);
3695 FNextWeapDelay
:= WEAPON_DELAY
;
3703 for i
:= 0 to High(wantThisWeapon
) do
3704 wantThisWeapon
[i
] := false;
3705 for i
:= 0 to High(FWeapon
) do
3706 if (FNextWeap
and (1 shl i
)) <> 0 then
3708 wantThisWeapon
[i
] := true;
3711 // exclude currently selected weapon from the set
3712 wantThisWeapon
[FCurrWeap
] := false;
3713 // slow down alterations a little
3716 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3717 // more than one weapon requested, assume "alteration" and check alteration delay
3718 if FNextWeapDelay
> 0 then
3724 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3725 // but clear all counters if no weapon should be switched
3731 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3732 // try weapons in descending order
3733 for i
:= High(FWeapon
) downto 0 do
3735 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3740 FNextWeapDelay
:= WEAPON_DELAY
* 2; // anyway, 'cause why not
3744 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3748 procedure TPlayer
.RealizeCurrentWeapon();
3749 function switchAllowed (): Boolean;
3754 if FBFGFireCounter
<> -1 then
3756 if FTime
[T_SWITCH
] > gTime
then
3758 for i
:= WP_FIRST
to WP_LAST
do
3759 if FReloading
[i
] > 0 then
3767 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3768 //FNextWeap := FNextWeap and $1FFF;
3769 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3771 if not switchAllowed
then
3773 //HACK for weapon cycling
3774 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3778 nw
:= getNextWeaponIndex();
3779 if nw
= 255 then exit
; // don't reset anything here
3780 if nw
> High(FWeapon
) then
3782 // don't forget to reset queue here!
3783 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3791 FTime
[T_SWITCH
] := gTime
+156;
3792 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3793 FModel
.SetWeapon(FCurrWeap
);
3794 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3798 procedure TPlayer
.NextWeapon();
3800 if g_Game_IsClient
then Exit
;
3804 procedure TPlayer
.PrevWeapon();
3806 if g_Game_IsClient
then Exit
;
3810 procedure TPlayer
.SetWeapon(W
: Byte);
3812 if FCurrWeap
<> W
then
3813 if W
= WEAPON_SAW
then
3814 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3817 FModel
.SetWeapon(CurrWeap
);
3821 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3823 function allowBerserkSwitching (): Boolean;
3825 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3827 if gBerserkAutoswitch
then exit
;
3828 if not conIsCheatsEnabled
then exit
;
3836 if g_Game_IsClient
then Exit
;
3838 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3839 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3844 if FHealth
< PLAYER_HP_SOFT
then
3846 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3850 if gFlash
= 2 then Inc(FPickup
, 5);
3854 if FHealth
< PLAYER_HP_SOFT
then
3856 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3860 if gFlash
= 2 then Inc(FPickup
, 5);
3864 if FArmor
< PLAYER_AP_SOFT
then
3866 FArmor
:= PLAYER_AP_SOFT
;
3869 if gFlash
= 2 then Inc(FPickup
, 5);
3873 if FArmor
< PLAYER_AP_LIMIT
then
3875 FArmor
:= PLAYER_AP_LIMIT
;
3878 if gFlash
= 2 then Inc(FPickup
, 5);
3882 if FHealth
< PLAYER_HP_LIMIT
then
3884 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3888 if gFlash
= 2 then Inc(FPickup
, 5);
3892 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3894 if FHealth
< PLAYER_HP_LIMIT
then
3895 FHealth
:= PLAYER_HP_LIMIT
;
3896 if FArmor
< PLAYER_AP_LIMIT
then
3897 FArmor
:= PLAYER_AP_LIMIT
;
3901 if gFlash
= 2 then Inc(FPickup
, 5);
3905 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3907 FWeapon
[WEAPON_SAW
] := True;
3909 if gFlash
= 2 then Inc(FPickup
, 5);
3910 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3913 ITEM_WEAPON_SHOTGUN1
:
3914 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3916 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3917 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3919 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3920 FWeapon
[WEAPON_SHOTGUN1
] := True;
3922 if gFlash
= 2 then Inc(FPickup
, 5);
3923 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3926 ITEM_WEAPON_SHOTGUN2
:
3927 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3929 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3931 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3932 FWeapon
[WEAPON_SHOTGUN2
] := True;
3934 if gFlash
= 2 then Inc(FPickup
, 5);
3935 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3938 ITEM_WEAPON_CHAINGUN
:
3939 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3941 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3943 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3944 FWeapon
[WEAPON_CHAINGUN
] := True;
3946 if gFlash
= 2 then Inc(FPickup
, 5);
3947 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3950 ITEM_WEAPON_ROCKETLAUNCHER
:
3951 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3953 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3955 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3956 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3958 if gFlash
= 2 then Inc(FPickup
, 5);
3959 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3963 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3965 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3967 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3968 FWeapon
[WEAPON_PLASMA
] := True;
3970 if gFlash
= 2 then Inc(FPickup
, 5);
3971 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3975 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3977 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3979 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3980 FWeapon
[WEAPON_BFG
] := True;
3982 if gFlash
= 2 then Inc(FPickup
, 5);
3983 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3986 ITEM_WEAPON_SUPERPULEMET
:
3987 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3989 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3991 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3992 FWeapon
[WEAPON_SUPERPULEMET
] := True;
3994 if gFlash
= 2 then Inc(FPickup
, 5);
3995 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3998 ITEM_WEAPON_FLAMETHROWER
:
3999 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
4001 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
4003 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4004 FWeapon
[WEAPON_FLAMETHROWER
] := True;
4006 if gFlash
= 2 then Inc(FPickup
, 5);
4007 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4011 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4013 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4016 if gFlash
= 2 then Inc(FPickup
, 5);
4019 ITEM_AMMO_BULLETS_BOX
:
4020 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4022 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4025 if gFlash
= 2 then Inc(FPickup
, 5);
4029 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4031 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4034 if gFlash
= 2 then Inc(FPickup
, 5);
4037 ITEM_AMMO_SHELLS_BOX
:
4038 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4040 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
4043 if gFlash
= 2 then Inc(FPickup
, 5);
4047 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4049 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4052 if gFlash
= 2 then Inc(FPickup
, 5);
4055 ITEM_AMMO_ROCKET_BOX
:
4056 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4058 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
4061 if gFlash
= 2 then Inc(FPickup
, 5);
4065 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4067 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4070 if gFlash
= 2 then Inc(FPickup
, 5);
4074 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4076 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4079 if gFlash
= 2 then Inc(FPickup
, 5);
4083 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4085 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4088 if gFlash
= 2 then Inc(FPickup
, 5);
4092 if not(R_ITEM_BACKPACK
in FRulez
) or
4093 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4094 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4095 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4096 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4097 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
4099 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4100 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4101 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4102 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4103 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4105 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4106 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4107 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4108 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4109 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4110 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4111 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4112 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4114 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
4117 if gFlash
= 2 then Inc(FPickup
, 5);
4121 if not(R_KEY_RED
in FRulez
) then
4123 Include(FRulez
, R_KEY_RED
);
4125 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4126 if gFlash
= 2 then Inc(FPickup
, 5);
4127 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4131 if not(R_KEY_GREEN
in FRulez
) then
4133 Include(FRulez
, R_KEY_GREEN
);
4135 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4136 if gFlash
= 2 then Inc(FPickup
, 5);
4137 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4141 if not(R_KEY_BLUE
in FRulez
) then
4143 Include(FRulez
, R_KEY_BLUE
);
4145 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4146 if gFlash
= 2 then Inc(FPickup
, 5);
4147 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4151 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4153 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4157 if gFlash
= 2 then Inc(FPickup
, 5);
4161 if FAir
< AIR_MAX
then
4166 if gFlash
= 2 then Inc(FPickup
, 5);
4171 if not (R_BERSERK
in FRulez
) then
4173 Include(FRulez
, R_BERSERK
);
4174 if allowBerserkSwitching
then
4176 FCurrWeap
:= WEAPON_KASTET
;
4178 FModel
.SetWeapon(WEAPON_KASTET
);
4183 if gFlash
= 2 then Inc(FPickup
, 5);
4185 FBerserk
:= gTime
+30000;
4190 if FHealth
< PLAYER_HP_SOFT
then
4192 FHealth
:= PLAYER_HP_SOFT
;
4193 FBerserk
:= gTime
+30000;
4201 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4203 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4206 if gFlash
= 2 then Inc(FPickup
, 5);
4210 if FHealth
< PLAYER_HP_LIMIT
then
4212 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4216 if gFlash
= 2 then Inc(FPickup
, 5);
4220 if FArmor
< PLAYER_AP_LIMIT
then
4222 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4225 if gFlash
= 2 then Inc(FPickup
, 5);
4229 if FJetFuel
< JET_MAX
then
4231 FJetFuel
:= JET_MAX
;
4234 if gFlash
= 2 then Inc(FPickup
, 5);
4238 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4240 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4243 if gFlash
= 2 then Inc(FPickup
, 5);
4248 procedure TPlayer
.Touch();
4252 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4255 // Áðîñèòü ôëàã òîâàðèùó:
4256 if gGameSettings
.GameMode
= GM_CTF
then
4261 procedure TPlayer
.Push(vx
, vy
: Integer);
4263 if (not FPhysics
) and FGhost
then
4265 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4266 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4267 if g_Game_IsNet
and g_Game_IsServer
then
4268 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4271 procedure TPlayer
.Reset(Force
: Boolean);
4277 FTime
[T_RESPAWN
] := 0;
4278 FTime
[T_FLAGCAP
] := 0;
4292 FSpectator
:= False;
4295 FSpectatePlayer
:= -1;
4296 FNoRespawn
:= False;
4298 FLives
:= gGameSettings
.MaxLives
;
4303 procedure TPlayer
.SoftReset();
4309 FBFGFireCounter
:= -1;
4317 SetAction(A_STAND
, True);
4320 function TPlayer
.GetRespawnPoint(): Byte;
4325 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4327 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4328 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4330 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4332 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4333 if Self
= gPlayer1
then
4334 c
:= RESPAWNPOINT_PLAYER1
4336 c
:= RESPAWNPOINT_PLAYER2
;
4337 if g_Map_GetPointCount(c
) > 0 then
4343 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4344 if Self
= gPlayer1
then
4345 c
:= RESPAWNPOINT_PLAYER2
4347 c
:= RESPAWNPOINT_PLAYER1
;
4348 if g_Map_GetPointCount(c
) > 0 then
4355 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4356 if Random(2) = 0 then
4357 c
:= RESPAWNPOINT_PLAYER1
4359 c
:= RESPAWNPOINT_PLAYER2
;
4360 if g_Map_GetPointCount(c
) > 0 then
4367 // Òî÷êà ëþáîé èç êîìàíä
4368 if Random(2) = 0 then
4369 c
:= RESPAWNPOINT_RED
4371 c
:= RESPAWNPOINT_BLUE
;
4372 if g_Map_GetPointCount(c
) > 0 then
4379 c
:= RESPAWNPOINT_DM
;
4380 if g_Map_GetPointCount(c
) > 0 then
4388 if gGameSettings
.GameMode
= GM_DM
then
4391 c
:= RESPAWNPOINT_DM
;
4392 if g_Map_GetPointCount(c
) > 0 then
4398 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4399 if Random(2) = 0 then
4400 c
:= RESPAWNPOINT_PLAYER1
4402 c
:= RESPAWNPOINT_PLAYER2
;
4403 if g_Map_GetPointCount(c
) > 0 then
4409 // Òî÷êà ëþáîé èç êîìàíä
4410 if Random(2) = 0 then
4411 c
:= RESPAWNPOINT_RED
4413 c
:= RESPAWNPOINT_BLUE
;
4414 if g_Map_GetPointCount(c
) > 0 then
4422 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4424 // Òî÷êà ñâîåé êîìàíäû
4425 c
:= RESPAWNPOINT_DM
;
4426 if FTeam
= TEAM_RED
then
4427 c
:= RESPAWNPOINT_RED
;
4428 if FTeam
= TEAM_BLUE
then
4429 c
:= RESPAWNPOINT_BLUE
;
4430 if g_Map_GetPointCount(c
) > 0 then
4437 c
:= RESPAWNPOINT_DM
;
4438 if g_Map_GetPointCount(c
) > 0 then
4444 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4445 if Random(2) = 0 then
4446 c
:= RESPAWNPOINT_PLAYER1
4448 c
:= RESPAWNPOINT_PLAYER2
;
4449 if g_Map_GetPointCount(c
) > 0 then
4455 // Òî÷êà äðóãîé êîìàíäû
4456 c
:= RESPAWNPOINT_DM
;
4457 if FTeam
= TEAM_RED
then
4458 c
:= RESPAWNPOINT_BLUE
;
4459 if FTeam
= TEAM_BLUE
then
4460 c
:= RESPAWNPOINT_RED
;
4461 if g_Map_GetPointCount(c
) > 0 then
4469 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4471 RespawnPoint
: TRespawnPoint
;
4477 FBFGFireCounter
:= -1;
4482 if not g_Game_IsServer
then
4486 FWantsInGame
:= True;
4487 FJustTeleported
:= True;
4490 FTime
[T_RESPAWN
] := 0;
4494 // if server changes MaxLives we gotta be ready
4495 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4497 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4498 if FTime
[T_RESPAWN
] > gTime
then
4501 // Ïðîñðàë âñå æèçíè:
4504 if not FSpectator
then Spectate(True);
4505 FWantsInGame
:= True;
4509 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4510 begin // "Ñâîÿ èãðà"
4511 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4512 FRulez
:= FRulez
-[R_BERSERK
];
4514 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4516 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4517 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4520 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4521 c
:= GetRespawnPoint();
4526 // Âîñêðåøåíèå áåç îðóæèÿ:
4529 FHealth
:= PLAYER_HP_SOFT
;
4535 for a
:= WP_FIRST
to WP_LAST
do
4537 FWeapon
[a
] := False;
4541 FWeapon
[WEAPON_PISTOL
] := True;
4542 FWeapon
[WEAPON_KASTET
] := True;
4543 FCurrWeap
:= WEAPON_PISTOL
;
4546 FModel
.SetWeapon(FCurrWeap
);
4548 for b
:= A_BULLETS
to A_HIGH
do
4551 FAmmo
[A_BULLETS
] := 50;
4553 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4554 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4555 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4556 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4557 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4559 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4560 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4565 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4566 if not g_Map_GetPoint(c
, RespawnPoint
) then
4568 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4572 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4573 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4574 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4580 FDirection
:= RespawnPoint
.Direction
;
4581 if FDirection
= TDirection
.D_LEFT
then
4586 SetAction(A_STAND
, True);
4587 FModel
.Direction
:= FDirection
;
4589 for a
:= Low(FTime
) to High(FTime
) do
4592 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4597 FCanJetpack
:= False;
4603 // Àíèìàöèÿ âîçðîæäåíèÿ:
4604 if (not gLoadGameMode
) and (not Silent
) then
4605 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4607 Anim
:= TAnimation
.Create(ID
, False, 3);
4608 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4609 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4613 FSpectator
:= False;
4616 FSpectatePlayer
:= -1;
4619 if (gPlayer1
= nil) and (gLMSPID1
= FUID
) then
4621 if (gPlayer2
= nil) and (gLMSPID2
= FUID
) then
4624 if g_Game_IsNet
then
4626 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4627 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4629 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4630 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4635 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4638 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4639 else if (not NoMove
) then
4641 GameX
:= gMapInfo
.Width
div 2;
4642 GameY
:= gMapInfo
.Height
div 2;
4651 FWantsInGame
:= False;
4656 if Self
= gPlayer1
then
4661 if Self
= gPlayer2
then
4668 if g_Game_IsNet
then
4669 MH_SEND_PlayerStats(FUID
);
4672 procedure TPlayer
.SwitchNoClip
;
4676 FGhost
:= not FGhost
;
4677 FPhysics
:= not FGhost
;
4689 procedure TPlayer
.Run(Direction
: TDirection
);
4693 if MAX_RUNVEL
> 8 then
4697 if Direction
= TDirection
.D_LEFT
then
4699 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4700 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4703 if FObj
.Vel
.X
< MAX_RUNVEL
then
4704 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4706 // Âîçìîæíî, ïèíàåì êóñêè:
4707 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4709 b
:= Abs(FObj
.Vel
.X
);
4710 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4711 for a
:= 0 to High(gGibs
) do
4713 if gGibs
[a
].alive
and
4714 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4715 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4718 if FObj
.Vel
.X
< 0 then
4720 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4724 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4726 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4734 procedure TPlayer
.SeeDown();
4736 SetAction(A_SEEDOWN
);
4738 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4740 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4743 procedure TPlayer
.SeeUp();
4747 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4749 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4752 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4760 A_ATTACK
: Prior
:= 2;
4761 A_SEEUP
: Prior
:= 1;
4762 A_SEEDOWN
: Prior
:= 1;
4763 A_ATTACKUP
: Prior
:= 2;
4764 A_ATTACKDOWN
: Prior
:= 2;
4769 if (Prior
> FActionPrior
) or Force
then
4770 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4772 FActionPrior
:= Prior
;
4773 FActionAnim
:= Action
;
4774 FActionForce
:= Force
;
4775 FActionChanged
:= True;
4778 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4781 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4783 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4784 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4785 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4786 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4789 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4796 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4798 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4799 if g_Game_IsServer
and g_Game_IsNet
then
4800 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4804 FJustTeleported
:= True;
4809 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4811 Anim
:= TAnimation
.Create(ID
, False, 3);
4814 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4815 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4816 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4817 if g_Game_IsServer
and g_Game_IsNet
then
4818 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4819 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4823 FObj
.X
:= X
-PLAYER_RECT
.X
;
4824 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4825 if FAlive
and FGhost
then
4831 if not g_Game_IsNet
then
4835 SetDirection(TDirection
.D_LEFT
);
4841 SetDirection(TDirection
.D_RIGHT
);
4847 if FDirection
= TDirection
.D_RIGHT
then
4849 SetDirection(TDirection
.D_LEFT
);
4854 SetDirection(TDirection
.D_RIGHT
);
4860 if not silent
and (Anim
<> nil) then
4862 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4863 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4866 if g_Game_IsServer
and g_Game_IsNet
then
4867 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4868 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4875 function nonz(a
: Single): Single;
4883 function TPlayer
.followCorpse(): Boolean;
4888 if FAlive
or FSpectator
then
4890 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
4892 for i
:= 0 to High(gCorpses
) do
4893 if gCorpses
[i
] <> nil then
4894 if gCorpses
[i
].FPlayerUID
= FUID
then
4897 FObj
.X
:= gCorpses
[i
].FObj
.X
;
4898 FObj
.Y
:= gCorpses
[i
].FObj
.Y
;
4899 FObj
.Vel
.X
:= gCorpses
[i
].FObj
.Vel
.X
;
4900 FObj
.Vel
.Y
:= gCorpses
[i
].FObj
.Vel
.Y
;
4901 FObj
.Accel
.X
:= gCorpses
[i
].FObj
.Accel
.X
;
4902 FObj
.Accel
.Y
:= gCorpses
[i
].FObj
.Accel
.Y
;
4907 procedure TPlayer
.Update();
4910 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4911 blockmon
, headwater
, dospawn
: Boolean;
4916 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4917 AnyServer
:= g_Game_IsServer
;
4919 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4920 DoLerp(NetInterpLevel
+ 1)
4926 if FClientID
>= 0 then
4928 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4929 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4930 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4939 if FAlive
and (FPunchAnim
<> nil) then
4940 FPunchAnim
.Update();
4942 if FAlive
and (gFly
or FJetpack
) then
4945 if FDirection
= TDirection
.D_LEFT
then
4950 if FAlive
and (not FGhost
) then
4952 if FKeys
[KEY_UP
].Pressed
then
4954 if FKeys
[KEY_DOWN
].Pressed
then
4958 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4961 i
:= g_basic
.Sign(FIncCam
);
4962 FIncCam
:= Abs(FIncCam
);
4963 DecMin(FIncCam
, 5, 0);
4964 FIncCam
:= FIncCam
*i
;
4967 // no need to do that each second frame, weapon queue will take care of it
4968 if FAlive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4969 if FAlive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4971 if gTime
mod (GAME_TICK
*2) <> 0 then
4973 if (FObj
.Vel
.X
= 0) and FAlive
then
4975 if FKeys
[KEY_LEFT
].Pressed
then
4976 Run(TDirection
.D_LEFT
);
4977 if FKeys
[KEY_RIGHT
].Pressed
then
4978 Run(TDirection
.D_RIGHT
);
4983 if not followCorpse() then
4984 g_Obj_Move(@FObj
, True, True, True);
4985 positionChanged(); // this updates spatial accelerators
4991 FActionChanged
:= False;
4995 // Let alive player do some actions
4996 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
4997 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
4998 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
4999 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
5000 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire()
5006 if NetServer
then MH_SEND_PlayerStats(FUID
);
5009 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
5010 if FKeys
[KEY_JUMP
].Pressed
then Jump()
5013 if AnyServer
and FJetpack
then
5017 if NetServer
then MH_SEND_PlayerStats(FUID
);
5019 FCanJetpack
:= True;
5026 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
5028 if FKeys
[k
].Pressed
then
5036 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5039 if (FTime
[T_RESPAWN
] <= gTime
) and
5040 gGameOn
and (not FAlive
) then
5042 if (g_Player_GetCount() > 1) then
5046 gExit
:= EXIT_RESTART
;
5051 // Dead spectator actions
5054 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
5055 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
5059 if (FSpectatePlayer
>= High(gPlayers
)) then
5060 FSpectatePlayer
:= -1
5064 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
5065 if gPlayers
[I
] <> nil then
5066 if gPlayers
[I
].alive
then
5067 if gPlayers
[I
].UID
<> FUID
then
5069 FSpectatePlayer
:= I
;
5074 if not SetSpect
then FSpectatePlayer
:= -1;
5085 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5087 FYTo
:= FObj
.Y
- 32;
5088 FSpectatePlayer
:= -1;
5090 if FKeys
[KEY_DOWN
].Pressed
then
5092 FYTo
:= FObj
.Y
+ 32;
5093 FSpectatePlayer
:= -1;
5095 if FKeys
[KEY_LEFT
].Pressed
then
5097 FXTo
:= FObj
.X
- 32;
5098 FSpectatePlayer
:= -1;
5100 if FKeys
[KEY_RIGHT
].Pressed
then
5102 FXTo
:= FObj
.X
+ 32;
5103 FSpectatePlayer
:= -1;
5106 if (FXTo
< -64) then
5108 else if (FXTo
> gMapInfo
.Width
+ 32) then
5109 FXTo
:= gMapInfo
.Width
+ 32;
5110 if (FYTo
< -72) then
5112 else if (FYTo
> gMapInfo
.Height
+ 32) then
5113 FYTo
:= gMapInfo
.Height
+ 32;
5118 if not followCorpse() then
5119 g_Obj_Move(@FObj
, True, True, True);
5120 positionChanged(); // this updates spatial accelerators
5127 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5128 if gPlayers
[FSpectatePlayer
] <> nil then
5129 if gPlayers
[FSpectatePlayer
].alive
then
5131 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
5132 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
5136 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5137 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5138 PANEL_BLOCKMON
, True);
5139 headwater
:= HeadInLiquid(0, 0);
5141 // Ñîïðîòèâëåíèå âîçäóõà:
5142 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5143 if FObj
.Vel
.X
<> 0 then
5144 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5146 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5147 DecMin(FPain
, 5, 0);
5148 DecMin(FPickup
, 1, 0);
5150 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5152 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5153 FMegaRulez
[MR_SUIT
] := 0;
5154 FMegaRulez
[MR_INVUL
] := 0;
5155 FMegaRulez
[MR_INVIS
] := 0;
5156 Kill(K_FALLKILL
, 0, HIT_FALL
);
5163 if FCurrWeap
= WEAPON_SAW
then
5164 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5165 FSawSoundSelect
.IsPlaying()) then
5166 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5169 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5170 (not FJetSoundOff
.IsPlaying()) then
5172 FJetSoundFly
.SetPosition(0);
5173 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5176 for b
:= WP_FIRST
to WP_LAST
do
5177 if FReloading
[b
] > 0 then
5183 if FShellTimer
> -1 then
5184 if FShellTimer
= 0 then
5186 if FShellType
= SHELL_SHELL
then
5187 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5188 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5189 else if FShellType
= SHELL_DBLSHELL
then
5191 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5192 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5193 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5194 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5197 end else Dec(FShellTimer
);
5199 if (FBFGFireCounter
> -1) then
5200 if FBFGFireCounter
= 0 then
5204 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5205 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5206 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5207 yd
:= wy
+firediry();
5208 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5209 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5210 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5211 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5212 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5215 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5216 FBFGFireCounter
:= -1;
5219 FBFGFireCounter
:= 0
5221 Dec(FBFGFireCounter
);
5223 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5225 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5227 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5230 if (headwater
or blockmon
) then
5236 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5239 else if (FAir
mod 31 = 0) and not blockmon
then
5241 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5242 if Random(2) = 0 then
5243 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5245 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5247 end else if FAir
< AIR_DEF
then
5250 if FFireTime
> 0 then
5252 if BodyInLiquid(0, 0) then
5257 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5259 if FMegaRulez
[MR_SUIT
] = gTime
then
5266 if FFirePainTime
<= 0 then
5268 if g_Game_IsServer
then
5269 Damage(5, FFireAttacker
, 0, 0, HIT_FLAME
);
5270 FFirePainTime
:= 18;
5272 FFirePainTime
:= FFirePainTime
- 1;
5273 FFireTime
:= FFireTime
- 1;
5274 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5275 MH_SEND_PlayerStats(FUID
);
5279 if FDamageBuffer
> 0 then
5281 if FDamageBuffer
>= 9 then
5285 if FDamageBuffer
< 30 then i
:= 9
5286 else if FDamageBuffer
< 100 then i
:= 18
5290 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5291 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5292 FHealth
:= FHealth
-ii
;
5295 FHealth
:= FHealth
+FArmor
;
5300 if FHealth
<= 0 then
5301 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5302 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5303 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5307 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5308 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5309 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5310 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5317 end; // if FAlive then ...
5319 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5321 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5322 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5323 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5324 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5326 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5327 then SetAction(A_STAND
, True);
5329 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5331 for b
:= Low(FKeys
) to High(FKeys
) do
5332 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5336 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5338 x
:= FObj
.X
+PLAYER_RECT
.X
;
5339 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5340 w
:= PLAYER_RECT
.Width
;
5341 h
:= PLAYER_RECT
.Height
;
5345 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5347 if (dx
<> 0) or (dy
<> 0) then
5356 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5358 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5359 FObj
.Y
+PLAYER_RECT
.Y
,
5366 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5368 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5369 FObj
.Y
+PLAYER_RECT
.Y
,
5373 Panel
.Width
, Panel
.Height
);
5376 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5378 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5379 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5380 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5381 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5384 function g_Player_ValidName(Name
: string): Boolean;
5390 if gPlayers
= nil then Exit
;
5392 for a
:= 0 to High(gPlayers
) do
5393 if gPlayers
[a
] <> nil then
5394 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5401 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5405 d
:= FModel
.Direction
;
5407 FModel
.Direction
:= Direction
;
5408 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5410 FDirection
:= Direction
;
5413 function TPlayer
.GetKeys(): Byte;
5417 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5418 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5419 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5421 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5422 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5425 procedure TPlayer
.Use();
5429 if FTime
[T_USE
] > gTime
then Exit
;
5431 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5432 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5434 for a
:= 0 to High(gPlayers
) do
5435 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5436 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5437 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5438 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5440 gPlayers
[a
].Touch();
5441 if g_Game_IsNet
and g_Game_IsServer
then
5442 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5445 FTime
[T_USE
] := gTime
+120;
5448 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5452 WX
, WY
, XD
, YD
: Integer;
5464 if R_BERSERK
in FRulez
then
5466 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5467 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5468 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5471 locobj
.rect
.Width
:= 39;
5472 locobj
.rect
.Height
:= 52;
5473 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5474 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5475 locobj
.Accel
.X
:= xd
-wx
;
5476 locobj
.Accel
.y
:= yd
-wy
;
5478 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5479 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5481 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5485 FPain
:= min(FPain
+ 25, 50);
5487 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5492 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5493 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5495 FSawSoundSelect
.Stop();
5497 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5499 else if not FSawSoundHit
.IsPlaying() then
5501 FSawSoundSelect
.Stop();
5502 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5509 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5510 FFireAngle
:= FAngle
;
5512 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5513 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5518 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5519 FFireAngle
:= FAngle
;
5522 FShellType
:= SHELL_SHELL
;
5527 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5528 FFireAngle
:= FAngle
;
5531 FShellType
:= SHELL_DBLSHELL
;
5536 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5537 FFireAngle
:= FAngle
;
5539 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5540 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5543 WEAPON_ROCKETLAUNCHER
:
5545 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5546 FFireAngle
:= FAngle
;
5552 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5553 FFireAngle
:= FAngle
;
5559 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5560 FFireAngle
:= FAngle
;
5564 WEAPON_SUPERPULEMET
:
5566 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5567 FFireAngle
:= FAngle
;
5569 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5570 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5573 WEAPON_FLAMETHROWER
:
5575 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5577 FFireAngle
:= FAngle
;
5584 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5585 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5586 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5589 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5591 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5592 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5595 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5599 if NetInterpLevel
< 1 then
5609 AX
:= Abs(FXTo
- FObj
.X
);
5610 AY
:= Abs(FYTo
- FObj
.Y
);
5611 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5613 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5618 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5620 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5621 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5622 PANEL_LIFTUP
, False) then Result
:= -1
5624 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5625 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5626 PANEL_LIFTDOWN
, False) then Result
:= 1
5630 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5637 if Flag
= FLAG_NONE
then
5640 if not g_Game_IsServer
then Exit
;
5642 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5643 if (Flag
= FTeam
) and
5644 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5645 (FFlag
<> FLAG_NONE
) then
5647 if FFlag
= FLAG_RED
then
5648 s
:= _lc
[I_PLAYER_FLAG_RED
]
5650 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5652 evtype
:= FLAG_STATE_SCORED
;
5654 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5655 Insert('.', ts
, Length(ts
) + 1 - 3);
5656 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5658 g_Map_ResetFlag(FFlag
);
5659 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5661 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5662 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5663 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5668 if not sound_cap_flag
[a
].IsPlaying() then
5669 sound_cap_flag
[a
].Play();
5671 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5674 if g_Game_IsNet
then
5676 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5680 gFlags
[FFlag
].CaptureTime
:= 0;
5685 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5686 if (Flag
= FTeam
) and
5687 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5689 if Flag
= FLAG_RED
then
5690 s
:= _lc
[I_PLAYER_FLAG_RED
]
5692 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5694 evtype
:= FLAG_STATE_RETURNED
;
5695 gFlags
[Flag
].CaptureTime
:= 0;
5697 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5699 g_Map_ResetFlag(Flag
);
5700 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5702 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5703 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5704 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5709 if not sound_ret_flag
[a
].IsPlaying() then
5710 sound_ret_flag
[a
].Play();
5713 if g_Game_IsNet
then
5715 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5721 // Ïîäîáðàë ÷óæîé ôëàã:
5722 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5726 if Flag
= FLAG_RED
then
5727 s
:= _lc
[I_PLAYER_FLAG_RED
]
5729 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5731 evtype
:= FLAG_STATE_CAPTURED
;
5733 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5735 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5737 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5739 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5740 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5741 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5746 if not sound_get_flag
[a
].IsPlaying() then
5747 sound_get_flag
[a
].Play();
5750 if g_Game_IsNet
then
5752 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5758 procedure TPlayer
.SetFlag(Flag
: Byte);
5761 if FModel
<> nil then
5762 FModel
.SetFlag(FFlag
);
5765 function TPlayer
.DropFlag(Silent
: Boolean = True): Boolean;
5771 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5773 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5774 with gFlags
[FFlag
] do
5778 Direction
:= FDirection
;
5779 State
:= FLAG_STATE_DROPPED
;
5781 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5782 (FObj
.Vel
.Y
div 2)-2+Random(5));
5783 positionChanged(); // this updates spatial accelerators
5785 if FFlag
= FLAG_RED
then
5786 s
:= _lc
[I_PLAYER_FLAG_RED
]
5788 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5790 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5791 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5793 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5794 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5795 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5800 if (not Silent
) and (not sound_lost_flag
[a
].IsPlaying()) then
5801 sound_lost_flag
[a
].Play();
5803 if g_Game_IsNet
then
5804 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5810 procedure TPlayer
.GetSecret();
5812 if (self
= gPlayer1
) or (self
= gPlayer2
) then
5814 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [FName
]), True);
5815 g_Sound_PlayEx('SOUND_GAME_SECRET');
5820 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5822 Assert(Key
<= High(FKeys
));
5824 FKeys
[Key
].Pressed
:= True;
5825 FKeys
[Key
].Time
:= Time
;
5828 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5830 Result
:= FKeys
[K
].Pressed
;
5833 procedure TPlayer
.ReleaseKeys();
5837 for a
:= Low(FKeys
) to High(FKeys
) do
5839 FKeys
[a
].Pressed
:= False;
5844 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5848 function TPlayer
.firediry(): Integer;
5850 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5851 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5855 procedure TPlayer
.RememberState();
5859 FSavedState
.Health
:= FHealth
;
5860 FSavedState
.Armor
:= FArmor
;
5861 FSavedState
.Air
:= FAir
;
5862 FSavedState
.JetFuel
:= FJetFuel
;
5863 FSavedState
.CurrWeap
:= FCurrWeap
;
5864 FSavedState
.NextWeap
:= FNextWeap
;
5865 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5868 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5870 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5872 FSavedState
.Rulez
:= FRulez
;
5873 FSavedState
.WaitRecall
:= True;
5876 procedure TPlayer
.RecallState();
5880 if not FSavedState
.WaitRecall
then Exit
;
5882 FHealth
:= FSavedState
.Health
;
5883 FArmor
:= FSavedState
.Armor
;
5884 FAir
:= FSavedState
.Air
;
5885 FJetFuel
:= FSavedState
.JetFuel
;
5886 FCurrWeap
:= FSavedState
.CurrWeap
;
5887 FNextWeap
:= FSavedState
.NextWeap
;
5888 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5891 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5893 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5895 FRulez
:= FSavedState
.Rulez
;
5896 FSavedState
.WaitRecall
:= False;
5898 if gGameSettings
.GameType
= GT_SERVER
then
5899 MH_SEND_PlayerStats(FUID
);
5902 procedure TPlayer
.SaveState (st
: TStream
);
5908 utils
.writeSign(st
, 'PLYR');
5909 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
5911 utils
.writeBool(st
, FIamBot
);
5913 utils
.writeInt(st
, Word(FUID
));
5915 utils
.writeStr(st
, FName
);
5917 utils
.writeInt(st
, Byte(FTeam
));
5919 utils
.writeBool(st
, FAlive
);
5920 // Èçðàñõîäîâàë ëè âñå æèçíè
5921 utils
.writeBool(st
, FNoRespawn
);
5923 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
5924 utils
.writeInt(st
, Byte(b
));
5926 utils
.writeInt(st
, LongInt(FHealth
));
5928 utils
.writeInt(st
, Byte(FLives
));
5930 utils
.writeInt(st
, LongInt(FArmor
));
5932 utils
.writeInt(st
, LongInt(FAir
));
5934 utils
.writeInt(st
, LongInt(FJetFuel
));
5936 utils
.writeInt(st
, LongInt(FPain
));
5938 utils
.writeInt(st
, LongInt(FKills
));
5940 utils
.writeInt(st
, LongInt(FMonsterKills
));
5942 utils
.writeInt(st
, LongInt(FFrags
));
5944 utils
.writeInt(st
, Byte(FFragCombo
));
5945 // Âðåìÿ ïîñëåäíåãî ôðàãà
5946 utils
.writeInt(st
, LongWord(FLastFrag
));
5948 utils
.writeInt(st
, LongInt(FDeath
));
5950 utils
.writeInt(st
, Byte(FFlag
));
5952 utils
.writeInt(st
, LongInt(FSecrets
));
5954 utils
.writeInt(st
, Byte(FCurrWeap
));
5956 utils
.writeInt(st
, Word(FNextWeap
));
5958 utils
.writeInt(st
, Byte(FNextWeapDelay
));
5959 // Âðåìÿ çàðÿäêè BFG
5960 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
5962 utils
.writeInt(st
, LongInt(FDamageBuffer
));
5963 // Ïîñëåäíèé óäàðèâøèé
5964 utils
.writeInt(st
, Word(FLastSpawnerUID
));
5965 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
5966 utils
.writeInt(st
, Byte(FLastHit
));
5968 Obj_SaveState(st
, @FObj
);
5969 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
5970 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
5971 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
5972 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
5974 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
5975 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
5976 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
5978 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
5979 // Íàëè÷èå êðàñíîãî êëþ÷à
5980 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
5981 // Íàëè÷èå çåëåíîãî êëþ÷à
5982 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
5983 // Íàëè÷èå ñèíåãî êëþ÷à
5984 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
5986 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
5987 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
5988 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
5989 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
5990 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
5992 utils
.writeStr(st
, FModel
.Name
);
5994 utils
.writeInt(st
, Byte(FColor
.R
));
5995 utils
.writeInt(st
, Byte(FColor
.G
));
5996 utils
.writeInt(st
, Byte(FColor
.B
));
6000 procedure TPlayer
.LoadState (st
: TStream
);
6009 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
6010 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
6012 FIamBot
:= utils
.readBool(st
);
6014 FUID
:= utils
.readWord(st
);
6016 str
:= utils
.readStr(st
);
6017 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
6019 FTeam
:= utils
.readByte(st
);
6021 FAlive
:= utils
.readBool(st
);
6022 // Èçðàñõîäîâàë ëè âñå æèçíè
6023 FNoRespawn
:= utils
.readBool(st
);
6025 b
:= utils
.readByte(st
);
6026 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
6028 FHealth
:= utils
.readLongInt(st
);
6030 FLives
:= utils
.readByte(st
);
6032 FArmor
:= utils
.readLongInt(st
);
6034 FAir
:= utils
.readLongInt(st
);
6036 FJetFuel
:= utils
.readLongInt(st
);
6038 FPain
:= utils
.readLongInt(st
);
6040 FKills
:= utils
.readLongInt(st
);
6042 FMonsterKills
:= utils
.readLongInt(st
);
6044 FFrags
:= utils
.readLongInt(st
);
6046 FFragCombo
:= utils
.readByte(st
);
6047 // Âðåìÿ ïîñëåäíåãî ôðàãà
6048 FLastFrag
:= utils
.readLongWord(st
);
6050 FDeath
:= utils
.readLongInt(st
);
6052 FFlag
:= utils
.readByte(st
);
6054 FSecrets
:= utils
.readLongInt(st
);
6056 FCurrWeap
:= utils
.readByte(st
);
6058 FNextWeap
:= utils
.readWord(st
);
6060 FNextWeapDelay
:= utils
.readByte(st
);
6061 // Âðåìÿ çàðÿäêè BFG
6062 FBFGFireCounter
:= utils
.readSmallInt(st
);
6064 FDamageBuffer
:= utils
.readLongInt(st
);
6065 // Ïîñëåäíèé óäàðèâøèé
6066 FLastSpawnerUID
:= utils
.readWord(st
);
6067 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6068 FLastHit
:= utils
.readByte(st
);
6070 Obj_LoadState(@FObj
, st
);
6071 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6072 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
6073 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6074 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
6076 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
6077 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6078 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
6080 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
6081 // Íàëè÷èå êðàñíîãî êëþ÷à
6082 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
6083 // Íàëè÷èå çåëåíîãî êëþ÷à
6084 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
6085 // Íàëè÷èå ñèíåãî êëþ÷à
6086 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
6088 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
6089 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6090 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
6091 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6092 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
6094 str
:= utils
.readStr(st
);
6096 FColor
.R
:= utils
.readByte(st
);
6097 FColor
.G
:= utils
.readByte(st
);
6098 FColor
.B
:= utils
.readByte(st
);
6099 if (self
= gPlayer1
) then
6101 str
:= gPlayer1Settings
.Model
;
6102 FColor
:= gPlayer1Settings
.Color
;
6104 else if (self
= gPlayer2
) then
6106 str
:= gPlayer2Settings
.Model
;
6107 FColor
:= gPlayer2Settings
.Color
;
6109 // Îáíîâëÿåì ìîäåëü èãðîêà
6111 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
6112 FModel
.Color
:= TEAMCOLOR
[FTeam
]
6114 FModel
.Color
:= FColor
;
6118 procedure TPlayer
.AllRulez(Health
: Boolean);
6124 FHealth
:= PLAYER_HP_LIMIT
;
6125 FArmor
:= PLAYER_AP_LIMIT
;
6129 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
6130 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
6131 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6134 procedure TPlayer
.RestoreHealthArmor();
6136 FHealth
:= PLAYER_HP_LIMIT
;
6137 FArmor
:= PLAYER_AP_LIMIT
;
6140 procedure TPlayer
.FragCombo();
6144 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6146 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6148 if FFragCombo
< 5 then
6150 Param
:= FUID
or (FFragCombo
shl 16);
6151 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6152 (FComboEvnt
<= High(gDelayedEvents
)) and
6153 gDelayedEvents
[FComboEvnt
].Pending
and
6154 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6155 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6157 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6158 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6161 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6169 procedure TPlayer
.GiveItem(ItemType
: Byte);
6173 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6175 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6179 if FAir
< AIR_MAX
then
6186 if not (R_BERSERK
in FRulez
) then
6188 Include(FRulez
, R_BERSERK
);
6189 if FBFGFireCounter
< 1 then
6191 FCurrWeap
:= WEAPON_KASTET
;
6193 FModel
.SetWeapon(WEAPON_KASTET
);
6197 FBerserk
:= gTime
+30000;
6199 if FHealth
< PLAYER_HP_SOFT
then
6201 FHealth
:= PLAYER_HP_SOFT
;
6202 FBerserk
:= gTime
+30000;
6207 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6209 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6213 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6215 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6219 if FJetFuel
< JET_MAX
then
6221 FJetFuel
:= JET_MAX
;
6224 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6225 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6227 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6228 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6230 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6232 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6234 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6235 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6238 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6239 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6240 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6241 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6242 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6243 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6244 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6245 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6246 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6248 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6249 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6250 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6251 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6252 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6253 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6254 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6255 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6256 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6259 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6260 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6261 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6262 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6263 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6265 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6266 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6267 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6268 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6269 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6271 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6272 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6273 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6274 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6276 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6279 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6280 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6281 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6283 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6284 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6289 if g_Game_IsNet
and g_Game_IsServer
then
6290 MH_SEND_PlayerStats(FUID
);
6293 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6298 if (Random(5) = 1) and (Times
= 1) then
6301 if BodyInLiquid(0, 0) then
6303 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6304 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6305 if Random(2) = 0 then
6306 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6308 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6312 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6314 for i
:= 1 to Times
do
6316 Anim
:= TAnimation
.Create(id
, False, 3);
6318 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6319 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6325 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6330 if (Random(10) = 1) and (Times
= 1) then
6333 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6335 for i
:= 1 to Times
do
6337 Anim
:= TAnimation
.Create(id
, False, 3);
6339 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6340 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6346 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6348 FSawSound
.Pause(Enable
);
6349 FSawSoundIdle
.Pause(Enable
);
6350 FSawSoundHit
.Pause(Enable
);
6351 FSawSoundSelect
.Pause(Enable
);
6352 FFlameSoundOn
.Pause(Enable
);
6353 FFlameSoundOff
.Pause(Enable
);
6354 FFlameSoundWork
.Pause(Enable
);
6355 FJetSoundFly
.Pause(Enable
);
6356 FJetSoundOn
.Pause(Enable
);
6357 FJetSoundOff
.Pause(Enable
);
6362 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6367 FObj
.Rect
:= PLAYER_CORPSERECT
;
6368 FModelName
:= ModelName
;
6373 FState
:= CORPSE_STATE_MESS
;
6374 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6378 FState
:= CORPSE_STATE_NORMAL
;
6379 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6383 destructor TCorpse
.Destroy();
6390 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6392 procedure TCorpse
.positionChanged (); inline; begin end;
6394 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6396 if (dx
<> 0) or (dy
<> 0) then
6405 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6407 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6408 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6409 w
:= PLAYER_CORPSERECT
.Width
;
6410 h
:= PLAYER_CORPSERECT
.Height
;
6414 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6419 if FState
= CORPSE_STATE_REMOVEME
then
6422 FDamage
:= FDamage
+ Value
;
6424 if FDamage
> 150 then
6426 if FAnimation
<> nil then
6431 FState
:= CORPSE_STATE_REMOVEME
;
6433 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6434 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6435 FModelName
, FColor
);
6436 // Çâóê ìÿñà îò òðóïà:
6437 pm
:= g_PlayerModel_Get(FModelName
);
6438 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6442 if (gBodyKillEvent
<> -1)
6443 and gDelayedEvents
[gBodyKillEvent
].Pending
then
6444 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
6445 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, 0);
6450 Blood
:= g_PlayerModel_GetBlood(FModelName
);
6451 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6452 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6453 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6454 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6455 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6456 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
6460 procedure TCorpse
.Draw();
6462 if FState
= CORPSE_STATE_REMOVEME
then
6465 if FAnimation
<> nil then
6466 FAnimation
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6468 if FAnimationMask
<> nil then
6471 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6478 procedure TCorpse
.Update();
6482 if FState
= CORPSE_STATE_REMOVEME
then
6485 if gTime
mod (GAME_TICK
*2) <> 0 then
6487 g_Obj_Move(@FObj
, True, True, True);
6488 positionChanged(); // this updates spatial accelerators
6492 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6493 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6495 st
:= g_Obj_Move(@FObj
, True, True, True);
6496 positionChanged(); // this updates spatial accelerators
6498 if WordBool(st
and MOVE_FALLOUT
) then
6500 FState
:= CORPSE_STATE_REMOVEME
;
6504 if FAnimation
<> nil then
6505 FAnimation
.Update();
6506 if FAnimationMask
<> nil then
6507 FAnimationMask
.Update();
6511 procedure TCorpse
.SaveState (st
: TStream
);
6518 utils
.writeSign(st
, 'CORP');
6519 utils
.writeInt(st
, Byte(0));
6521 utils
.writeInt(st
, Byte(FState
));
6523 utils
.writeInt(st
, Byte(FDamage
));
6525 utils
.writeInt(st
, Byte(FColor
.R
));
6526 utils
.writeInt(st
, Byte(FColor
.G
));
6527 utils
.writeInt(st
, Byte(FColor
.B
));
6529 Obj_SaveState(st
, @FObj
);
6530 utils
.writeInt(st
, Word(FPlayerUID
));
6532 anim
:= (FAnimation
<> nil);
6533 utils
.writeBool(st
, anim
);
6534 // Åñëè åñòü - ñîõðàíÿåì
6535 if anim
then FAnimation
.SaveState(st
);
6536 // Åñòü ëè ìàñêà àíèìàöèè
6537 anim
:= (FAnimationMask
<> nil);
6538 utils
.writeBool(st
, anim
);
6539 // Åñëè åñòü - ñîõðàíÿåì
6540 if anim
then FAnimationMask
.SaveState(st
);
6544 procedure TCorpse
.LoadState (st
: TStream
);
6551 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6552 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6554 FState
:= utils
.readByte(st
);
6556 FDamage
:= utils
.readByte(st
);
6558 FColor
.R
:= utils
.readByte(st
);
6559 FColor
.G
:= utils
.readByte(st
);
6560 FColor
.B
:= utils
.readByte(st
);
6562 Obj_LoadState(@FObj
, st
);
6563 FPlayerUID
:= utils
.readWord(st
);
6565 anim
:= utils
.readBool(st
);
6566 // Åñëè åñòü - çàãðóæàåì
6569 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6570 FAnimation
.LoadState(st
);
6572 // Åñòü ëè ìàñêà àíèìàöèè
6573 anim
:= utils
.readBool(st
);
6574 // Åñëè åñòü - çàãðóæàåì
6577 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6578 FAnimationMask
.LoadState(st
);
6584 constructor TBot
.Create();
6591 FSpectator
:= False;
6598 for a
:= WP_FIRST
to WP_LAST
do
6600 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6601 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6602 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6606 destructor TBot
.Destroy();
6609 inherited Destroy();
6612 procedure TBot
.Draw();
6616 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6617 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6620 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6622 inherited Respawn(Silent
, Force
);
6625 FSelectedWeapon
:= FCurrWeap
;
6630 procedure TBot
.UpdateCombat();
6643 TTargetRecord
= array of TTarget
;
6645 function Compare(a
, b
: TTarget
): Integer;
6647 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6650 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6652 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6653 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6655 if a
.Dist
> b
.Dist
then // B áëèæå
6657 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6660 else // Ñòðàííî -> A
6665 a
, x1
, y1
, x2
, y2
: Integer;
6666 targets
: TTargetRecord
;
6668 Target
, BestTarget
: TTarget
;
6669 firew
, fireh
: Integer;
6673 vsPlayer
, vsMonster
, ok
: Boolean;
6676 function monsUpdate (mon
: TMonster
): Boolean;
6678 result
:= false; // don't stop
6679 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6681 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6683 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6684 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6686 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6687 if g_TraceVector(x1
, y1
, x2
, y2
) then
6689 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6690 SetLength(targets
, Length(targets
)+1);
6691 with targets
[High(targets
)] do
6698 Rect
:= mon
.Obj
.Rect
;
6699 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6700 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6701 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6710 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6711 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6713 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6714 if FCurrWeap
<> FSelectedWeapon
then
6717 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6718 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6720 RemoveAIFlag('NEEDFIRE');
6723 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6724 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6725 else PressKey(KEY_FIRE
);
6729 // Êîîðäèíàòû ñòâîëà:
6730 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6731 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6733 Target
.UID
:= FTargetUID
;
6736 if Target
.UID
<> 0 then
6737 begin // Öåëü åñòü - íàñòðàèâàåì
6738 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6741 tpla
:= g_Player_Get(Target
.UID
);
6745 if (@FObj
) <> nil then
6752 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6753 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6754 Target
.Rect
:= PLAYER_RECT
;
6755 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6756 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6757 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6758 Target
.IsPlayer
:= True;
6762 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6765 mon
:= g_Monsters_ByUID(Target
.UID
);
6768 Target
.X
:= mon
.Obj
.X
;
6769 Target
.Y
:= mon
.Obj
.Y
;
6771 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6772 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6773 Target
.Rect
:= mon
.Obj
.Rect
;
6774 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6775 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6776 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6777 Target
.IsPlayer
:= False;
6784 begin // Öåëè íåò - îáíóëÿåì
6789 Target
.Visible
:= False;
6790 Target
.Line
:= False;
6791 Target
.IsPlayer
:= False;
6796 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6797 if (not Target
.Line
) or (not Target
.Visible
) then
6801 for a
:= 0 to High(gPlayers
) do
6802 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6803 (gPlayers
[a
].FUID
<> FUID
) and
6804 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6805 (not gPlayers
[a
].NoTarget
) and
6806 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6808 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6809 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6812 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6813 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6815 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6816 if g_TraceVector(x1
, y1
, x2
, y2
) then
6818 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6819 SetLength(targets
, Length(targets
)+1);
6820 with targets
[High(targets
)] do
6822 UID
:= gPlayers
[a
].FUID
;
6823 X
:= gPlayers
[a
].FObj
.X
;
6824 Y
:= gPlayers
[a
].FObj
.Y
;
6827 Rect
:= PLAYER_RECT
;
6828 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6829 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6830 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6838 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6841 // Åñëè åñòü âîçìîæíûå öåëè:
6842 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6843 if targets
<> nil then
6845 // Âûáèðàåì íàèëó÷øóþ öåëü:
6846 BestTarget
:= targets
[0];
6847 if Length(targets
) > 1 then
6848 for a
:= 1 to High(targets
) do
6849 if Compare(BestTarget
, targets
[a
]) = 1 then
6850 BestTarget
:= targets
[a
];
6852 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6853 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6854 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6856 Target
:= BestTarget
;
6858 if (Healthy() = 3) or ((Healthy() = 2)) then
6859 begin // Åñëè çäîðîâû - äîãîíÿåì
6860 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6861 SetAIFlag('GORIGHT', '1');
6862 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6863 SetAIFlag('GOLEFT', '1');
6866 begin // Åñëè ïîáèòû - óáåãàåì
6867 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6868 SetAIFlag('GORIGHT', '1');
6869 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6870 SetAIFlag('GOLEFT', '1');
6873 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6874 SelectWeapon(Abs(x1
-Target
.cX
));
6879 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6880 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6881 if Target
.UID
<> 0 then
6883 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6884 Target
.Y
+ Target
.Rect
.Y
) then
6885 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6886 if (Healthy() = 3) or ((Healthy() = 2)) then
6887 begin // Åñëè çäîðîâû - äîãîíÿåì
6888 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6889 SetAIFlag('GORIGHT', '1');
6890 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6891 SetAIFlag('GOLEFT', '1');
6894 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6896 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6897 SetAIFlag('GORIGHT', '1');
6898 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6899 SetAIFlag('GOLEFT', '1');
6903 begin // Öåëü ïîêà íà "ýêðàíå"
6904 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6905 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6906 FLastVisible
:= gTime
;
6907 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6908 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6910 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6911 SetAIFlag('GORIGHT', '1');
6912 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6913 SetAIFlag('GOLEFT', '1');
6917 // Âûáèðàåì óãîë ââåðõ:
6918 if FDirection
= TDirection
.D_LEFT
then
6919 angle
:= ANGLE_LEFTUP
6921 angle
:= ANGLE_RIGHTUP
;
6923 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6924 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6926 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6927 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6928 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6929 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6930 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6931 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6932 begin // òî íóæíî ñòðåëÿòü ââåðõ
6933 SetAIFlag('NEEDFIRE', '1');
6934 SetAIFlag('NEEDSEEUP', '1');
6937 // Âûáèðàåì óãîë âíèç:
6938 if FDirection
= TDirection
.D_LEFT
then
6939 angle
:= ANGLE_LEFTDOWN
6941 angle
:= ANGLE_RIGHTDOWN
;
6943 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6944 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6946 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6947 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6948 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6949 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6950 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6951 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6952 begin // òî íóæíî ñòðåëÿòü âíèç
6953 SetAIFlag('NEEDFIRE', '1');
6954 SetAIFlag('NEEDSEEDOWN', '1');
6957 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6958 if Target
.Visible
and
6959 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6960 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6962 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6963 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
6964 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6965 begin // òî íóæíî ñòðåëÿòü âïåðåä
6966 SetAIFlag('NEEDFIRE', '1');
6967 SetAIFlag('NEEDSEEDOWN', '');
6968 SetAIFlag('NEEDSEEUP', '');
6970 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6971 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6972 if GetRnd(FDifficult
.CloseJump
) then
6973 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6974 if Abs(FObj
.X
-Target
.X
) < 128 then
6978 if Random(a
) = 0 then
6979 SetAIFlag('NEEDJUMP', '1');
6983 // Åñëè öåëü âñå åùå åñòü:
6984 if Target
.UID
<> 0 then
6985 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
6986 Target
.UID
:= 0 // òî çàáûòü öåëü
6987 else // Åñëè âèäåëè íåäàâíî
6988 begin // íî öåëü óáèëè
6989 if Target
.IsPlayer
then
6990 begin // Öåëü - èãðîê
6991 pla
:= g_Player_Get(Target
.UID
);
6992 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
6993 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6994 Target
.UID
:= 0; // òî çàáûòü öåëü
6997 begin // Öåëü - ìîíñòð
6998 mon
:= g_Monsters_ByUID(Target
.UID
);
6999 if (mon
= nil) or (not mon
.alive
) then
7000 Target
.UID
:= 0; // òî çàáûòü öåëü
7003 end; // if Target.UID <> 0
7005 FTargetUID
:= Target
.UID
;
7007 // Åñëè âîçìîæíûõ öåëåé íåò:
7008 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
7009 if targets
= nil then
7010 if GetAIFlag('ATTACKLEFT') <> '' then
7011 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
7012 RemoveAIFlag('ATTACKLEFT');
7014 SetAIFlag('NEEDJUMP', '1');
7016 if RunDirection() = TDirection
.D_RIGHT
then
7017 begin // Èäåì íå â òó ñòîðîíó
7018 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7019 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
7020 SetAIFlag('NEEDFIRE', '1');
7021 SetAIFlag('GOLEFT', '1');
7025 begin // Èäåì â íóæíóþ ñòîðîíó
7026 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7027 SetAIFlag('NEEDFIRE', '1');
7028 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7029 SetAIFlag('GORIGHT', '1');
7033 if GetAIFlag('ATTACKRIGHT') <> '' then
7034 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
7035 RemoveAIFlag('ATTACKRIGHT');
7037 SetAIFlag('NEEDJUMP', '1');
7039 if RunDirection() = TDirection
.D_LEFT
then
7040 begin // Èäåì íå â òó ñòîðîíó
7041 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7042 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
7043 SetAIFlag('NEEDFIRE', '1');
7044 SetAIFlag('GORIGHT', '1');
7049 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7050 SetAIFlag('NEEDFIRE', '1');
7051 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7052 SetAIFlag('GOLEFT', '1');
7056 //HACK! (does it belongs there?)
7057 RealizeCurrentWeapon();
7059 // Åñëè åñòü âîçìîæíûå öåëè:
7060 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7061 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7062 for a
:= 0 to High(targets
) do
7064 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7065 if GetRnd(FDifficult
.DiagFire
) then
7067 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7068 if FDirection
= TDirection
.D_LEFT
then
7069 angle
:= ANGLE_LEFTUP
7071 angle
:= ANGLE_RIGHTUP
;
7073 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7074 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7076 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7077 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7078 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7079 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7080 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7082 SetAIFlag('NEEDFIRE', '1');
7083 SetAIFlag('NEEDSEEUP', '1');
7086 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7087 if FDirection
= TDirection
.D_LEFT
then
7088 angle
:= ANGLE_LEFTDOWN
7090 angle
:= ANGLE_RIGHTDOWN
;
7092 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7093 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7095 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7096 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7097 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7098 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7099 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7101 SetAIFlag('NEEDFIRE', '1');
7102 SetAIFlag('NEEDSEEDOWN', '1');
7106 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7107 if targets
[a
].Line
and targets
[a
].Visible
and
7108 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
7109 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
7111 SetAIFlag('NEEDFIRE', '1');
7116 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7117 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
7118 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
7119 40+GetInterval(FDifficult
.Cover
, 40)) then
7120 SetAIFlag('NEEDJUMP', '1');
7122 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7123 ammo
:= GetAmmoByWeapon(FCurrWeap
);
7124 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
7125 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
7127 SetAIFlag('SELECTWEAPON', '1');
7129 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7130 if GetAIFlag('SELECTWEAPON') = '1' then
7133 RemoveAIFlag('SELECTWEAPON');
7137 procedure TBot
.Update();
7150 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7151 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7153 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7155 if g_debug_BotAIOff
= 3 then
7165 RealizeCurrentWeapon();
7172 procedure TBot
.ReleaseKey(Key
: Byte);
7181 function TBot
.KeyPressed(Key
: Word): Boolean;
7183 Result
:= FKeys
[Key
].Pressed
;
7186 function TBot
.GetAIFlag(aName
: String20
): String20
;
7192 aName
:= LowerCase(aName
);
7194 if FAIFlags
<> nil then
7195 for a
:= 0 to High(FAIFlags
) do
7196 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7198 Result
:= FAIFlags
[a
].Value
;
7203 procedure TBot
.RemoveAIFlag(aName
: String20
);
7207 if FAIFlags
= nil then Exit
;
7209 aName
:= LowerCase(aName
);
7211 for a
:= 0 to High(FAIFlags
) do
7212 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7214 if a
<> High(FAIFlags
) then
7215 for b
:= a
to High(FAIFlags
)-1 do
7216 FAIFlags
[b
] := FAIFlags
[b
+1];
7218 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7223 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7231 aName
:= LowerCase(aName
);
7233 if FAIFlags
<> nil then
7234 for a
:= 0 to High(FAIFlags
) do
7235 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7241 if ok
then FAIFlags
[a
].Value
:= fValue
7244 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7245 with FAIFlags
[High(FAIFlags
)] do
7253 procedure TBot
.UpdateMove
;
7255 procedure GoLeft(Time
: Word = 1);
7257 ReleaseKey(KEY_LEFT
);
7258 ReleaseKey(KEY_RIGHT
);
7259 PressKey(KEY_LEFT
, Time
);
7260 SetDirection(TDirection
.D_LEFT
);
7263 procedure GoRight(Time
: Word = 1);
7265 ReleaseKey(KEY_LEFT
);
7266 ReleaseKey(KEY_RIGHT
);
7267 PressKey(KEY_RIGHT
, Time
);
7268 SetDirection(TDirection
.D_RIGHT
);
7271 function Rnd(a
: Word): Boolean;
7273 Result
:= Random(a
) = 0;
7276 procedure Turn(Time
: Word = 1200);
7278 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7283 ReleaseKey(KEY_LEFT
);
7284 ReleaseKey(KEY_RIGHT
);
7287 function CanRunLeft(): Boolean;
7289 Result
:= not CollideLevel(-1, 0);
7292 function CanRunRight(): Boolean;
7294 Result
:= not CollideLevel(1, 0);
7297 function CanRun(): Boolean;
7299 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7302 procedure Jump(Time
: Word = 30);
7304 PressKey(KEY_JUMP
, Time
);
7307 function NearHole(): 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
7325 function BorderHole(): Boolean;
7329 { TODO 5 : Ëåñòíèöû }
7330 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7331 for x
:= 1 to PLAYER_RECT
.Width
do
7332 if (not StayOnStep(x
*sx
, 0)) and
7333 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7334 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7336 for xx
:= x
to x
+32 do
7337 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7347 function NearDeepHole(): Boolean;
7353 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7356 for x
:= 1 to PLAYER_RECT
.Width
do
7357 if (not StayOnStep(x
*sx
, 0)) and
7358 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7359 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7361 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7363 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7368 end else Result
:= False;
7371 function OverDeepHole(): Boolean;
7378 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7380 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7387 function OnGround(): Boolean;
7389 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7392 function OnLadder(): Boolean;
7394 Result
:= FullInStep(0, 0);
7397 function BelowLadder(): Boolean;
7399 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7400 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7401 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7402 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7405 function BelowLiftUp(): Boolean;
7407 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7408 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7409 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7410 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7413 function OnTopLift(): Boolean;
7415 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7418 function CanJumpOver(): Boolean;
7422 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7426 if not CollideLevel(sx
, 0) then Exit
;
7428 for y
:= 1 to BOT_MAXJUMP
do
7429 if CollideLevel(0, -y
) then Exit
else
7430 if not CollideLevel(sx
, -y
) then
7437 function CanJumpUp(Dist
: ShortInt): Boolean;
7444 if CollideLevel(Dist
, 0) then Exit
;
7447 for y
:= 0 to BOT_MAXJUMP
do
7448 if CollideLevel(Dist
, -y
) then
7457 for yy
:= y
+1 to BOT_MAXJUMP
do
7458 if not CollideLevel(Dist
, -yy
) then
7467 for y
:= 0 to BOT_MAXJUMP
do
7468 if CollideLevel(0, -y
) then
7476 if y
< yy
then Exit
;
7481 function IsSafeTrigger(): Boolean;
7486 if gTriggers
= nil then
7488 for a
:= 0 to High(gTriggers
) do
7489 if Collide(gTriggers
[a
].X
,
7492 gTriggers
[a
].Height
) and
7493 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7494 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7495 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7496 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7497 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7502 // Âîçìîæíî, íàæèìàåì êíîïêó:
7503 if Rnd(16) and IsSafeTrigger() then
7506 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7507 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7509 ReleaseKey(KEY_LEFT
);
7510 ReleaseKey(KEY_RIGHT
);
7514 // Èäåì âëåâî, åñëè íàäî áûëî:
7515 if GetAIFlag('GOLEFT') <> '' then
7517 RemoveAIFlag('GOLEFT');
7518 if CanRunLeft() then
7522 // Èäåì âïðàâî, åñëè íàäî áûëî:
7523 if GetAIFlag('GORIGHT') <> '' then
7525 RemoveAIFlag('GORIGHT');
7526 if CanRunRight() then
7530 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7531 if FObj
.X
< -32 then
7534 if FObj
.X
+32 > gMapInfo
.Width
then
7537 // Ïðûãàåì, åñëè íàäî áûëî:
7538 if GetAIFlag('NEEDJUMP') <> '' then
7541 RemoveAIFlag('NEEDJUMP');
7544 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7545 if GetAIFlag('NEEDSEEUP') <> '' then
7548 ReleaseKey(KEY_DOWN
);
7549 PressKey(KEY_UP
, 20);
7550 RemoveAIFlag('NEEDSEEUP');
7553 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7554 if GetAIFlag('NEEDSEEDOWN') <> '' then
7557 ReleaseKey(KEY_DOWN
);
7558 PressKey(KEY_DOWN
, 20);
7559 RemoveAIFlag('NEEDSEEDOWN');
7562 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7563 if GetAIFlag('GOINHOLE') <> '' then
7564 if not OnGround() then
7566 ReleaseKey(KEY_LEFT
);
7567 ReleaseKey(KEY_RIGHT
);
7568 RemoveAIFlag('GOINHOLE');
7569 SetAIFlag('FALLINHOLE', '1');
7572 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7573 if GetAIFlag('FALLINHOLE') <> '' then
7575 RemoveAIFlag('FALLINHOLE');
7577 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7578 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7579 if GetAIFlag('FALLINHOLE') = '' then
7580 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7586 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7588 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7592 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7593 if OnGround() and NearHole() then
7594 if NearDeepHole() then // Åñëè ýòî áåçäíà
7596 0..3: Turn(); // Áåæèì îáðàòíî
7597 4: Jump(); // Ïðûãàåì
7598 5: begin // Ïðûãàåì îáðàòíî
7603 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7604 if GetAIFlag('GOINHOLE') = '' then
7606 0: Turn(); // Íå íóæíî òóäà
7607 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7608 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7609 if BorderHole() then
7610 SetAIFlag('GOINHOLE', '1');
7613 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7614 if (not CanRun()) and OnGround() then
7616 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7617 if CanJumpOver() or OnLadder() then
7619 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7620 if Random(2) = 0 then
7622 if IsSafeTrigger() then
7628 // Îñòàëîñü ìàëî âîçäóõà:
7629 if FAir
< 36 * 2 then
7632 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7633 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7634 if BodyInAcid(0, 0) then
7638 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7640 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7641 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7644 {function TBot.NeedItem(Item: Byte): Byte;
7649 procedure TBot
.SelectWeapon(Dist
: Integer);
7653 function HaveAmmo(weapon
: Byte): Boolean;
7656 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7657 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7658 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7659 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7660 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7661 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7662 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7663 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7664 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7665 else Result
:= True;
7670 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7672 if Dist
> BOT_LONGDIST
then
7673 begin // Äàëüíèé áîé
7675 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7677 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7681 else //if Dist > BOT_UNSAFEDIST then
7682 begin // Áëèæíèé áîé
7684 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7686 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7693 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7695 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7701 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7703 Result
:= inherited PickItem(ItemType
, force
, remove
);
7705 if Result
then SetAIFlag('SELECTWEAPON', '1');
7708 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7710 Result
:= inherited Heal(value
, Soft
);
7713 function TBot
.Healthy(): Byte;
7715 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7716 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7717 else if (FHealth
> 50) then Result
:= 2
7718 else if (FHealth
> 20) then Result
:= 1
7722 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7724 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7725 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7728 procedure TBot
.OnDamage(Angle
: SmallInt);
7736 if (Angle
= 0) or (Angle
= 180) then
7739 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7740 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7742 pla
:= g_Player_Get(FLastSpawnerUID
);
7743 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7744 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7747 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7748 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7750 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7751 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7752 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7757 SetAIFlag('ATTACKLEFT', '1')
7759 SetAIFlag('ATTACKRIGHT', '1');
7763 function TBot
.RunDirection(): TDirection
;
7765 if Abs(Vel
.X
) >= 1 then
7767 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7769 Result
:= FDirection
;
7772 function TBot
.GetRnd(a
: Byte): Boolean;
7774 if a
= 0 then Result
:= False
7775 else if a
= 255 then Result
:= True
7776 else Result
:= Random(256) > 255-a
;
7779 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7781 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7785 procedure TDifficult
.save (st
: TStream
);
7787 utils
.writeInt(st
, Byte(DiagFire
));
7788 utils
.writeInt(st
, Byte(InvisFire
));
7789 utils
.writeInt(st
, Byte(DiagPrecision
));
7790 utils
.writeInt(st
, Byte(FlyPrecision
));
7791 utils
.writeInt(st
, Byte(Cover
));
7792 utils
.writeInt(st
, Byte(CloseJump
));
7793 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7794 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7797 procedure TDifficult
.load (st
: TStream
);
7799 DiagFire
:= utils
.readByte(st
);
7800 InvisFire
:= utils
.readByte(st
);
7801 DiagPrecision
:= utils
.readByte(st
);
7802 FlyPrecision
:= utils
.readByte(st
);
7803 Cover
:= utils
.readByte(st
);
7804 CloseJump
:= utils
.readByte(st
);
7805 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7806 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7810 procedure TBot
.SaveState (st
: TStream
);
7815 inherited SaveState(st
);
7816 utils
.writeSign(st
, 'BOT0');
7818 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7820 utils
.writeInt(st
, Word(FTargetUID
));
7821 // Âðåìÿ ïîòåðè öåëè
7822 utils
.writeInt(st
, LongWord(FLastVisible
));
7823 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7824 dw
:= Length(FAIFlags
);
7825 utils
.writeInt(st
, LongInt(dw
));
7827 for i
:= 0 to dw
-1 do
7829 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7830 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7832 // Íàñòðîéêè ñëîæíîñòè
7833 FDifficult
.save(st
);
7837 procedure TBot
.LoadState (st
: TStream
);
7842 inherited LoadState(st
);
7843 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7845 FSelectedWeapon
:= utils
.readByte(st
);
7847 FTargetUID
:= utils
.readWord(st
);
7848 // Âðåìÿ ïîòåðè öåëè
7849 FLastVisible
:= utils
.readLongWord(st
);
7850 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7851 dw
:= utils
.readLongInt(st
);
7852 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7853 SetLength(FAIFlags
, dw
);
7855 for i
:= 0 to dw
-1 do
7857 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7858 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7860 // Íàñòðîéêè ñëîæíîñòè
7861 FDifficult
.load(st
);
7866 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);