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);
117 TPlayerStatArray
= Array of TPlayerStat
;
119 TPlayerSavedState
= record
127 Ammo
: Array [A_BULLETS
..A_HIGH
] of Word;
128 MaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
129 Weapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
130 Rulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
139 TPlayer
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
147 FDirection
: TDirection
;
155 FMonsterKills
: Integer;
161 FCanJetpack
: Boolean;
167 FNextWeapDelay
: Byte; // frames
168 FBFGFireCounter
: SmallInt;
169 FLastSpawnerUID
: Word;
173 FSpectatePlayer
: Integer;
174 FFirePainTime
: Integer;
177 FSavedState
: TPlayerSavedState
;
179 FModel
: TPlayerModel
;
180 FPunchAnim
: TAnimation
;
183 FActionForce
: Boolean;
184 FActionChanged
: Boolean;
186 FFireAngle
: SmallInt;
188 FShellTimer
: Integer;
190 FSawSound
: TPlayableSound
;
191 FSawSoundIdle
: TPlayableSound
;
192 FSawSoundHit
: TPlayableSound
;
193 FSawSoundSelect
: TPlayableSound
;
194 FJetSoundOn
: TPlayableSound
;
195 FJetSoundOff
: TPlayableSound
;
196 FJetSoundFly
: TPlayableSound
;
200 FJustTeleported
: Boolean;
202 mEDamageType
: Integer;
205 function CollideLevel(XInc
, YInc
: Integer): Boolean;
206 function StayOnStep(XInc
, YInc
: Integer): Boolean;
207 function HeadInLiquid(XInc
, YInc
: Integer): Boolean;
208 function BodyInLiquid(XInc
, YInc
: Integer): Boolean;
209 function BodyInAcid(XInc
, YInc
: Integer): Boolean;
210 function FullInLift(XInc
, YInc
: Integer): Integer;
211 {procedure CollideItem();}
212 procedure FlySmoke(Times
: DWORD
= 1);
213 procedure OnFireFlame(Times
: DWORD
= 1);
214 function GetAmmoByWeapon(Weapon
: Byte): Word;
215 procedure SetAction(Action
: Byte; Force
: Boolean = False);
216 procedure OnDamage(Angle
: SmallInt); virtual;
217 function firediry(): Integer;
220 procedure Run(Direction
: TDirection
);
221 procedure NextWeapon();
222 procedure PrevWeapon();
229 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
230 procedure resetWeaponQueue ();
231 function hasAmmoForWeapon (weapon
: Byte): Boolean;
233 procedure doDamage (v
: Integer);
235 function followCorpse(): Boolean;
238 FDamageBuffer
: Integer;
240 FAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
241 FMaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
242 FWeapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
243 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
245 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
246 FReloading
: Array [WP_FIRST
..WP_LAST
] of Word;
247 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
248 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
250 FPreferredTeam
: Byte;
253 FWantsInGame
: Boolean;
257 FActualModelName
: string;
264 // debug: viewport offset
265 viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer;
267 function isValidViewPort (): Boolean; inline;
269 constructor Create(); virtual;
270 destructor Destroy(); override;
271 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
272 function GetRespawnPoint(): Byte;
273 procedure PressKey(Key
: Byte; Time
: Word = 1);
274 procedure ReleaseKeys();
275 procedure SetModel(ModelName
: String);
276 procedure SetColor(Color
: TRGB
);
277 procedure SetWeapon(W
: Byte);
278 function IsKeyPressed(K
: Byte): Boolean;
279 function GetKeys(): Byte;
280 function PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean; virtual;
281 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
282 function Collide(Panel
: TPanel
): Boolean; overload
;
283 function Collide(X
, Y
: Integer): Boolean; overload
;
284 procedure SetDirection(Direction
: TDirection
);
285 procedure GetSecret();
286 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
288 procedure Push(vx
, vy
: Integer);
289 procedure ChangeModel(ModelName
: String);
290 procedure SwitchTeam
;
291 procedure ChangeTeam(Team
: Byte);
293 function GetFlag(Flag
: Byte): Boolean;
294 procedure SetFlag(Flag
: Byte);
295 function DropFlag(Silent
: Boolean = True): Boolean;
296 procedure AllRulez(Health
: Boolean);
297 procedure RestoreHealthArmor();
298 procedure FragCombo();
299 procedure GiveItem(ItemType
: Byte);
300 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
301 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
302 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
303 procedure MakeBloodSimple(Count
: Word);
304 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
305 procedure Reset(Force
: Boolean);
306 procedure Spectate(NoMove
: Boolean = False);
307 procedure SwitchNoClip
;
308 procedure SoftReset();
309 procedure Draw(); virtual;
310 procedure DrawPain();
311 procedure DrawPickup();
312 procedure DrawRulez();
314 procedure DrawIndicator();
315 procedure DrawBubble();
317 procedure Update(); virtual;
318 procedure RememberState();
319 procedure RecallState();
320 procedure SaveState (st
: TStream
); virtual;
321 procedure LoadState (st
: TStream
); virtual;
322 procedure PauseSounds(Enable
: Boolean);
323 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
324 procedure DoLerp(Level
: Integer = 2);
325 procedure SetLerp(XTo
, YTo
: Integer);
326 procedure QueueWeaponSwitch(Weapon
: Byte);
327 procedure RealizeCurrentWeapon();
329 procedure JetpackOff
;
330 procedure CatchFire(Attacker
: Word);
332 //WARNING! this does nothing for now, but still call it!
333 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
335 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
336 procedure moveBy (dx
, dy
: Integer); inline;
339 property Vel
: TPoint2i read FObj
.Vel
;
340 property Obj
: TObj read FObj
;
342 property Name
: String read FName write FName
;
343 property Model
: TPlayerModel read FModel
;
344 property Health
: Integer read FHealth write FHealth
;
345 property Lives
: Byte read FLives write FLives
;
346 property Armor
: Integer read FArmor write FArmor
;
347 property Air
: Integer read FAir write FAir
;
348 property JetFuel
: Integer read FJetFuel write FJetFuel
;
349 property Frags
: Integer read FFrags write FFrags
;
350 property Death
: Integer read FDeath write FDeath
;
351 property Kills
: Integer read FKills write FKills
;
352 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
353 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
354 property Secrets
: Integer read FSecrets
;
355 property GodMode
: Boolean read FGodMode write FGodMode
;
356 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
357 property NoReload
: Boolean read FNoReload write FNoReload
;
358 property alive
: Boolean read FAlive write FAlive
;
359 property Flag
: Byte read FFlag
;
360 property Team
: Byte read FTeam write FTeam
;
361 property Direction
: TDirection read FDirection
;
362 property GameX
: Integer read FObj
.X write FObj
.X
;
363 property GameY
: Integer read FObj
.Y write FObj
.Y
;
364 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
365 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
366 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
367 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
368 property IncCam
: Integer read FIncCam write FIncCam
;
369 property UID
: Word read FUID write FUID
;
370 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
371 property NetTime
: LongWord read FNetTime write FNetTime
;
374 property eName
: String read FName write FName
;
375 property eHealth
: Integer read FHealth write FHealth
;
376 property eLives
: Byte read FLives write FLives
;
377 property eArmor
: Integer read FArmor write FArmor
;
378 property eAir
: Integer read FAir write FAir
;
379 property eJetFuel
: Integer read FJetFuel write FJetFuel
;
380 property eFrags
: Integer read FFrags write FFrags
;
381 property eDeath
: Integer read FDeath write FDeath
;
382 property eKills
: Integer read FKills write FKills
;
383 property eCurrWeap
: Byte read FCurrWeap write FCurrWeap
;
384 property eMonsterKills
: Integer read FMonsterKills write FMonsterKills
;
385 property eSecrets
: Integer read FSecrets write FSecrets
;
386 property eGodMode
: Boolean read FGodMode write FGodMode
;
387 property eNoTarget
: Boolean read FNoTarget write FNoTarget
;
388 property eNoReload
: Boolean read FNoReload write FNoReload
;
389 property eAlive
: Boolean read FAlive write FAlive
;
390 property eFlag
: Byte read FFlag
;
391 property eTeam
: Byte read FTeam write FTeam
;
392 property eDirection
: TDirection read FDirection
;
393 property eGameX
: Integer read FObj
.X write FObj
.X
;
394 property eGameY
: Integer read FObj
.Y write FObj
.Y
;
395 property eGameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
396 property eGameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
397 property eGameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
398 property eGameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
399 property eIncCam
: Integer read FIncCam write FIncCam
;
400 property eUID
: Word read FUID
;
401 property eJustTeleported
: Boolean read FJustTeleported
;
402 property eNetTime
: LongWord read FNetTime
;
404 // set this before assigning something to `eDamage`
405 property eDamageType
: Integer read mEDamageType write mEDamageType
;
406 property eDamage
: Integer write doDamage
;
417 WeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
418 CloseWeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
419 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
422 procedure save (st
: TStream
);
423 procedure load (st
: TStream
);
431 TBot
= class(TPlayer
)
433 FSelectedWeapon
: Byte;
436 FAIFlags
: Array of TAIFlag
;
437 FDifficult
: TDifficult
;
439 function GetRnd(a
: Byte): Boolean;
440 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
441 function RunDirection(): TDirection
;
442 function FullInStep(XInc
, YInc
: Integer): Boolean;
443 //function NeedItem(Item: Byte): Byte;
444 procedure SelectWeapon(Dist
: Integer);
445 procedure SetAIFlag(aName
, fValue
: String20
);
446 function GetAIFlag(aName
: String20
): String20
;
447 procedure RemoveAIFlag(aName
: String20
);
448 function Healthy(): Byte;
449 procedure UpdateMove();
450 procedure UpdateCombat();
451 function KeyPressed(Key
: Word): Boolean;
452 procedure ReleaseKey(Key
: Byte);
453 function TargetOnScreen(TX
, TY
: Integer): Boolean;
454 procedure OnDamage(Angle
: SmallInt); override;
457 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
458 constructor Create(); override;
459 destructor Destroy(); override;
460 procedure Draw(); override;
461 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
462 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
463 procedure Update(); override;
464 procedure SaveState (st
: TStream
); override;
465 procedure LoadState (st
: TStream
); override;
477 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
478 procedure moveBy (dx
, dy
: Integer); inline;
480 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
494 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
495 procedure moveBy (dx
, dy
: Integer); inline;
497 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
500 TCorpse
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
509 FAnimation
: TAnimation
;
510 FAnimationMask
: TAnimation
;
513 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
514 destructor Destroy(); override;
515 procedure Damage(Value
: Word; vx
, vy
: Integer);
518 procedure SaveState (st
: TStream
);
519 procedure LoadState (st
: TStream
);
521 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
522 procedure moveBy (dx
, dy
: Integer); inline;
524 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
526 function ObjPtr (): PObj
; inline;
528 property Obj
: TObj read FObj
; // copies object
529 property State
: Byte read FState
;
530 property Mess
: Boolean read FMess
;
533 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
539 gPlayers
: Array of TPlayer
;
540 gCorpses
: Array of TCorpse
;
541 gGibs
: Array of TGib
;
542 gShells
: Array of TShell
;
543 gTeamStat
: TTeamStat
;
544 gFly
: Boolean = False;
545 gAimLine
: Boolean = False;
546 gChatBubble
: Byte = 0;
547 gPlayerIndicator
: Boolean = True;
551 MAX_RUNVEL
: Integer = 8;
552 VEL_JUMP
: Integer = 10;
553 SHELL_TIMEOUT
: Cardinal = 60000;
555 function Lerp(X
, Y
, Factor
: Integer): Integer;
557 procedure g_Gibs_SetMax(Count
: Word);
558 function g_Gibs_GetMax(): Word;
559 procedure g_Corpses_SetMax(Count
: Word);
560 function g_Corpses_GetMax(): Word;
561 procedure g_Shells_SetMax(Count
: Word);
562 function g_Shells_GetMax(): Word;
564 procedure g_Player_Init();
565 procedure g_Player_Free();
566 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
567 function g_Player_CreateFromState (st
: TStream
): Word;
568 procedure g_Player_Remove(UID
: Word);
569 procedure g_Player_ResetTeams();
570 procedure g_Player_UpdateAll();
571 procedure g_Player_DrawAll();
572 procedure g_Player_DrawDebug(p
: TPlayer
);
573 procedure g_Player_DrawHealth();
574 procedure g_Player_RememberAll();
575 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
576 function g_Player_Get(UID
: Word): TPlayer
;
577 function g_Player_GetCount(): Byte;
578 function g_Player_GetStats(): TPlayerStatArray
;
579 function g_Player_ValidName(Name
: String): Boolean;
580 procedure g_Player_CreateCorpse(Player
: TPlayer
);
581 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
582 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
583 procedure g_Player_UpdatePhysicalObjects();
584 procedure g_Player_DrawCorpses();
585 procedure g_Player_DrawShells();
586 procedure g_Player_RemoveAllCorpses();
587 procedure g_Player_Corpses_SaveState (st
: TStream
);
588 procedure g_Player_Corpses_LoadState (st
: TStream
);
589 procedure g_Bot_Add(Team
, Difficult
: Byte);
590 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1);
591 procedure g_Bot_MixNames();
592 procedure g_Bot_RemoveAll();
597 {$INCLUDE ../nogl/noGLuses.inc}
598 {$IFDEF ENABLE_HOLMES}
601 e_log
, g_map
, g_items
, g_console
, g_gfx
, Math
,
602 g_options
, g_triggers
, g_menu
, g_game
, g_grid
,
603 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
,
604 g_net
, g_netmsg
, g_window
,
607 const PLR_SAVE_VERSION
= 0;
617 diag_precision
: Byte;
621 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
622 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
623 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
627 TIME_RESPAWN1
= 1500;
628 TIME_RESPAWN2
= 2000;
629 TIME_RESPAWN3
= 3000;
632 JET_MAX
= 540; // ~30 sec
633 PLAYER_SUIT_TIME
= 30000;
634 PLAYER_INVUL_TIME
= 30000;
635 PLAYER_INVIS_TIME
= 35000;
636 FRAG_COMBO_TIME
= 3000;
640 ANGLE_RIGHTDOWN
= -35;
642 ANGLE_LEFTDOWN
= -145;
643 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
644 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
647 BOT_UNSAFEDIST
= 128;
648 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
650 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
651 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
652 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
653 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
654 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
655 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
656 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
657 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
658 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
659 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
660 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
661 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
662 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
663 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
664 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
665 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
666 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
667 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
668 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
669 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
670 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
671 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
672 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
673 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
674 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
675 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
677 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
678 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
680 BOTNAMES_FILENAME
= 'botnames.txt';
681 BOTLIST_FILENAME
= 'botlist.txt';
685 MaxCorpses
: Word = 20;
686 MaxShells
: Word = 300;
687 CurrentGib
: Integer = 0;
688 CurrentShell
: Integer = 0;
689 BotNames
: Array of String;
690 BotList
: Array of TBotProfile
;
693 function Lerp(X
, Y
, Factor
: Integer): Integer;
695 Result
:= X
+ ((Y
- X
) div Factor
);
698 function SameTeam(UID1
, UID2
: Word): Boolean;
702 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
703 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
705 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
707 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
708 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
710 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
713 procedure g_Gibs_SetMax(Count
: Word);
716 SetLength(gGibs
, Count
);
718 if CurrentGib
>= Count
then
722 function g_Gibs_GetMax(): Word;
727 procedure g_Shells_SetMax(Count
: Word);
730 SetLength(gShells
, Count
);
732 if CurrentShell
>= Count
then
736 function g_Shells_GetMax(): Word;
742 procedure g_Corpses_SetMax(Count
: Word);
745 SetLength(gCorpses
, Count
);
748 function g_Corpses_GetMax(): Word;
750 Result
:= MaxCorpses
;
753 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
763 // Åñòü ëè ìåñòî â gPlayers:
764 if gPlayers
<> nil then
765 for a
:= 0 to High(gPlayers
) do
766 if gPlayers
[a
] = nil then
772 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
775 SetLength(gPlayers
, Length(gPlayers
)+1);
779 // Ñîçäàåì îáúåêò èãðîêà:
781 gPlayers
[a
] := TBot
.Create()
783 gPlayers
[a
] := TPlayer
.Create();
786 gPlayers
[a
].FActualModelName
:= ModelName
;
787 gPlayers
[a
].SetModel(ModelName
);
789 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
790 if gPlayers
[a
].FModel
= nil then
794 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
798 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
799 if Random(2) = 0 then
803 gPlayers
[a
].FPreferredTeam
:= Team
;
805 case gGameSettings
.GameMode
of
806 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
808 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
810 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
813 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
814 gPlayers
[a
].FColor
:= Color
;
815 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
816 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
818 gPlayers
[a
].FModel
.Color
:= Color
;
820 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
821 gPlayers
[a
].FAlive
:= False;
823 Result
:= gPlayers
[a
].FUID
;
826 function g_Player_CreateFromState (st
: TStream
): Word;
833 if (st
= nil) then exit
; //???
836 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
837 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
840 Bot
:= utils
.readBool(st
);
845 // Åñòü ëè ìåñòî â gPlayers:
846 for a
:= 0 to High(gPlayers
) do if (gPlayers
[a
] = nil) then begin ok
:= true; break
; end;
848 // Íåò ìåñòà - ðàñøèðÿåì gPlayers
851 SetLength(gPlayers
, Length(gPlayers
)+1);
855 // Ñîçäàåì îáúåêò èãðîêà
857 gPlayers
[a
] := TBot
.Create()
859 gPlayers
[a
] := TPlayer
.Create();
860 gPlayers
[a
].FIamBot
:= Bot
;
861 gPlayers
[a
].FPhysics
:= True;
864 gPlayers
[a
].FUID
:= utils
.readWord(st
);
866 gPlayers
[a
].FName
:= utils
.readStr(st
);
868 gPlayers
[a
].FTeam
:= utils
.readByte(st
);
869 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
871 gPlayers
[a
].FAlive
:= utils
.readBool(st
);
872 // Èçðàñõîäîâàë ëè âñå æèçíè
873 gPlayers
[a
].FNoRespawn
:= utils
.readBool(st
);
875 b
:= utils
.readByte(st
);
876 if b
= 1 then gPlayers
[a
].FDirection
:= TDirection
.D_LEFT
else gPlayers
[a
].FDirection
:= TDirection
.D_RIGHT
; // b = 2
878 gPlayers
[a
].FHealth
:= utils
.readLongInt(st
);
880 gPlayers
[a
].FLives
:= utils
.readByte(st
);
882 gPlayers
[a
].FArmor
:= utils
.readLongInt(st
);
884 gPlayers
[a
].FAir
:= utils
.readLongInt(st
);
886 gPlayers
[a
].FJetFuel
:= utils
.readLongInt(st
);
888 gPlayers
[a
].FPain
:= utils
.readLongInt(st
);
890 gPlayers
[a
].FKills
:= utils
.readLongInt(st
);
892 gPlayers
[a
].FMonsterKills
:= utils
.readLongInt(st
);
894 gPlayers
[a
].FFrags
:= utils
.readLongInt(st
);
896 gPlayers
[a
].FFragCombo
:= utils
.readByte(st
);
897 // Âðåìÿ ïîñëåäíåãî ôðàãà
898 gPlayers
[a
].FLastFrag
:= utils
.readLongWord(st
);
900 gPlayers
[a
].FDeath
:= utils
.readLongInt(st
);
902 gPlayers
[a
].FFlag
:= utils
.readByte(st
);
904 gPlayers
[a
].FSecrets
:= utils
.readLongInt(st
);
906 gPlayers
[a
].FCurrWeap
:= utils
.readByte(st
);
907 // Ñëåäóþùåå æåëàåìîå îðóæèå
908 gPlayers
[a
].FNextWeap
:= utils
.readWord(st
);
910 gPlayers
[a
].FNextWeapDelay
:= utils
.readByte(st
);
912 gPlayers
[a
].FBFGFireCounter
:= utils
.readSmallInt(st
);
914 gPlayers
[a
].FDamageBuffer
:= utils
.readLongInt(st
);
915 // Ïîñëåäíèé óäàðèâøèé
916 gPlayers
[a
].FLastSpawnerUID
:= utils
.readWord(st
);
917 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
918 gPlayers
[a
].FLastHit
:= utils
.readByte(st
);
920 Obj_LoadState(@gPlayers
[a
].FObj
, st
);
921 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
922 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FAmmo
[i
] := utils
.readWord(st
);
923 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
924 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FMaxAmmo
[i
] := utils
.readWord(st
);
926 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FWeapon
[i
] := utils
.readBool(st
);
927 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
928 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FReloading
[i
] := utils
.readWord(st
);
930 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
931 // Íàëè÷èå êðàñíîãî êëþ÷à
932 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
933 // Íàëè÷èå çåëåíîãî êëþ÷à
934 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
935 // Íàëè÷èå ñèíåãî êëþ÷à
936 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
938 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_BERSERK
);
939 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
940 for i
:= MR_SUIT
to MR_MAX
do gPlayers
[a
].FMegaRulez
[i
] := utils
.readLongWord(st
);
941 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
942 for i
:= T_RESPAWN
to T_FLAGCAP
do gPlayers
[a
].FTime
[i
] := utils
.readLongWord(st
);
945 gPlayers
[a
].FActualModelName
:= utils
.readStr(st
);
947 gPlayers
[a
].FColor
.R
:= utils
.readByte(st
);
948 gPlayers
[a
].FColor
.G
:= utils
.readByte(st
);
949 gPlayers
[a
].FColor
.B
:= utils
.readByte(st
);
950 // Îáíîâëÿåì ìîäåëü èãðîêà
951 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
953 // Íåò ìîäåëè - ñîçäàíèå íåâîçìîæíî
954 if (gPlayers
[a
].FModel
= nil) then
958 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
962 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû
963 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
964 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
966 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
968 result
:= gPlayers
[a
].FUID
;
972 procedure g_Player_ResetTeams();
976 if g_Game_IsClient
then
978 if gPlayers
= nil then
980 for a
:= Low(gPlayers
) to High(gPlayers
) do
981 if gPlayers
[a
] <> nil then
982 case gGameSettings
.GameMode
of
984 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
986 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
987 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
988 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
991 gPlayers
[a
].ChangeTeam(TEAM_RED
)
993 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
996 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
1000 procedure g_Bot_Add(Team
, Difficult
: Byte);
1003 _name
, _model
: String;
1006 if not g_Game_IsServer
then Exit
;
1008 // Ñïèñîê íàçâàíèé ìîäåëåé:
1009 m
:= g_PlayerModel_GetNames();
1014 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1015 Team
:= TEAM_COOP
// COOP
1017 if gGameSettings
.GameMode
= GM_DM
then
1018 Team
:= TEAM_NONE
// DM
1020 if Team
= TEAM_NONE
then // CTF / TDM
1022 // Àâòîáàëàíñ êîìàíä:
1026 for a
:= 0 to High(gPlayers
) do
1027 if gPlayers
[a
] <> nil then
1029 if gPlayers
[a
].Team
= TEAM_RED
then
1032 if gPlayers
[a
].Team
= TEAM_BLUE
then
1042 if Random(2) = 0 then
1048 // Âûáèðàåì áîòó èìÿ:
1050 if BotNames
<> nil then
1051 for a
:= 0 to High(BotNames
) do
1052 if g_Player_ValidName(BotNames
[a
]) then
1054 _name
:= BotNames
[a
];
1058 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
1061 _name
:= Format('DFBOT%.2d', [Random(100)]);
1062 until g_Player_ValidName(_name
);
1064 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1065 _model
:= m
[Random(Length(m
))];
1068 with g_Player_Get(g_Player_Create(_model
,
1069 _RGB(Min(Random(9)*32, 255),
1070 Min(Random(9)*32, 255),
1071 Min(Random(9)*32, 255)),
1072 Team
, True)) as TBot
do
1077 1: FDifficult
:= DIFFICULT_EASY
;
1078 2: FDifficult
:= DIFFICULT_MEDIUM
;
1079 else FDifficult
:= DIFFICULT_HARD
;
1082 for a
:= WP_FIRST
to WP_LAST
do
1084 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1085 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1086 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1089 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1091 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1092 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1097 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1);
1100 _name
, _model
: String;
1103 if not g_Game_IsServer
then Exit
;
1105 // Ñïèñîê íàçâàíèé ìîäåëåé:
1106 m
:= g_PlayerModel_GetNames();
1111 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1112 Team
:= TEAM_COOP
// COOP
1114 if gGameSettings
.GameMode
= GM_DM
then
1115 Team
:= TEAM_NONE
// DM
1117 if Team
= TEAM_NONE
then
1118 Team
:= BotList
[num
].team
; // CTF / TDM
1120 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1121 lName
:= AnsiLowerCase(lName
);
1122 if (num
< 0) or (num
> Length(BotList
)-1) then
1124 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1125 for a
:= 0 to High(BotList
) do
1126 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1135 _name
:= BotList
[num
].name
;
1136 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1137 if not g_Player_ValidName(_name
) then
1139 _name
:= Format('DFBOT%.2d', [Random(100)]);
1140 until g_Player_ValidName(_name
);
1143 _model
:= BotList
[num
].model
;
1144 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1145 if not InSArray(_model
, m
) then
1146 _model
:= m
[Random(Length(m
))];
1149 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1153 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1154 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1155 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1156 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1157 FDifficult
.Cover
:= BotList
[num
].cover
;
1158 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1160 for a
:= WP_FIRST
to WP_LAST
do
1162 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1163 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1164 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1167 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1169 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1173 procedure g_Bot_RemoveAll();
1177 if not g_Game_IsServer
then Exit
;
1178 if gPlayers
= nil then Exit
;
1180 for a
:= 0 to High(gPlayers
) do
1181 if gPlayers
[a
] <> nil then
1182 if gPlayers
[a
] is TBot
then
1184 gPlayers
[a
].Lives
:= 0;
1185 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1186 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1187 g_Player_Remove(gPlayers
[a
].FUID
);
1193 procedure g_Bot_MixNames();
1198 if BotNames
<> nil then
1199 for a
:= 0 to High(BotNames
) do
1201 b
:= Random(Length(BotNames
));
1203 Botnames
[a
] := BotNames
[b
];
1208 procedure g_Player_Remove(UID
: Word);
1212 if gPlayers
= nil then Exit
;
1214 if g_Game_IsServer
and g_Game_IsNet
then
1215 MH_SEND_PlayerDelete(UID
);
1217 for i
:= 0 to High(gPlayers
) do
1218 if gPlayers
[i
] <> nil then
1219 if gPlayers
[i
].FUID
= UID
then
1221 if gPlayers
[i
] is TPlayer
then
1222 TPlayer(gPlayers
[i
]).Free()
1224 TBot(gPlayers
[i
]).Free();
1230 procedure g_Player_Init();
1240 if not FileExists(DataDir
+ BOTNAMES_FILENAME
) then
1243 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1244 AssignFile(F
, DataDir
+ BOTNAMES_FILENAME
);
1255 SetLength(BotNames
, Length(BotNames
)+1);
1256 BotNames
[High(BotNames
)] := s
;
1264 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1265 config
:= TConfig
.CreateFile(DataDir
+ BOTLIST_FILENAME
);
1269 while config
.SectionExists(IntToStr(a
)) do
1271 SetLength(BotList
, Length(BotList
)+1);
1273 with BotList
[High(BotList
)] do
1276 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1278 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1280 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1285 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1286 color
.R
:= StrToIntDef(sa
[0], 0);
1287 color
.G
:= StrToIntDef(sa
[1], 0);
1288 color
.B
:= StrToIntDef(sa
[2], 0);
1289 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1290 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1291 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1292 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1293 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1294 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1295 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1296 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1297 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1298 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1299 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1300 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1301 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1302 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1303 if Length(sa
) = 10 then
1305 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1306 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1307 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1308 if Length(sa
) = 10 then
1310 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1312 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1313 if Length(sa) = 10 then
1315 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1324 procedure g_Player_Free();
1328 if gPlayers
<> nil then
1330 for i
:= 0 to High(gPlayers
) do
1331 if gPlayers
[i
] <> nil then
1333 if gPlayers
[i
] is TPlayer
then
1334 TPlayer(gPlayers
[i
]).Free()
1336 TBot(gPlayers
[i
]).Free();
1347 procedure g_Player_UpdateAll();
1351 if gPlayers
= nil then Exit
;
1353 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1354 for i
:= 0 to High(gPlayers
) do
1356 if gPlayers
[i
] <> nil then
1358 if gPlayers
[i
] is TPlayer
then
1360 gPlayers
[i
].Update();
1361 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1365 // bot updates weapons in `UpdateCombat()`
1366 TBot(gPlayers
[i
]).Update();
1370 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1373 procedure g_Player_DrawAll();
1377 if gPlayers
= nil then Exit
;
1379 for i
:= 0 to High(gPlayers
) do
1380 if gPlayers
[i
] <> nil then
1381 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1382 else TBot(gPlayers
[i
]).Draw();
1385 procedure g_Player_DrawDebug(p
: TPlayer
);
1389 if p
= nil then Exit
;
1390 if (@p
.FObj
) = nil then Exit
;
1392 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1394 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1395 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1396 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1397 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1398 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1399 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1402 procedure g_Player_DrawHealth();
1407 if gPlayers
= nil then Exit
;
1408 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1410 for i
:= 0 to High(gPlayers
) do
1411 if gPlayers
[i
] <> nil then
1413 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1414 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1415 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1416 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1417 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1418 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1422 function g_Player_Get(UID
: Word): TPlayer
;
1428 if gPlayers
= nil then
1431 for a
:= 0 to High(gPlayers
) do
1432 if gPlayers
[a
] <> nil then
1433 if gPlayers
[a
].FUID
= UID
then
1435 Result
:= gPlayers
[a
];
1440 function g_Player_GetCount(): Byte;
1446 if gPlayers
= nil then
1449 for a
:= 0 to High(gPlayers
) do
1450 if gPlayers
[a
] <> nil then
1451 Result
:= Result
+ 1;
1454 function g_Player_GetStats(): TPlayerStatArray
;
1460 if gPlayers
= nil then Exit
;
1462 for a
:= 0 to High(gPlayers
) do
1463 if gPlayers
[a
] <> nil then
1465 SetLength(Result
, Length(Result
)+1);
1466 with Result
[High(Result
)] do
1468 Ping
:= gPlayers
[a
].FPing
;
1469 Loss
:= gPlayers
[a
].FLoss
;
1470 Name
:= gPlayers
[a
].FName
;
1471 Team
:= gPlayers
[a
].FTeam
;
1472 Frags
:= gPlayers
[a
].FFrags
;
1473 Deaths
:= gPlayers
[a
].FDeath
;
1474 Kills
:= gPlayers
[a
].FKills
;
1475 Color
:= gPlayers
[a
].FModel
.Color
;
1476 Lives
:= gPlayers
[a
].FLives
;
1477 Spectator
:= gPlayers
[a
].FSpectator
;
1482 procedure g_Player_RememberAll
;
1486 for i
:= Low(gPlayers
) to High(gPlayers
) do
1487 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1488 gPlayers
[i
].RememberState
;
1491 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1495 gTeamStat
[TEAM_RED
].Goals
:= 0;
1496 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1498 if gPlayers
<> nil then
1499 for i
:= 0 to High(gPlayers
) do
1500 if gPlayers
[i
] <> nil then
1502 gPlayers
[i
].Reset(Force
);
1504 if gPlayers
[i
] is TPlayer
then
1506 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1507 gPlayers
[i
].Respawn(Silent
)
1509 gPlayers
[i
].Spectate();
1512 TBot(gPlayers
[i
]).Respawn(Silent
);
1516 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1522 if Player
.alive
then
1525 // Ðàçðûâàåì ñâÿçü ñ ïðåæíèì òðóïîì:
1526 if gCorpses
<> nil then
1527 for i
:= 0 to High(gCorpses
) do
1528 if gCorpses
[i
] <> nil then
1529 if gCorpses
[i
].FPlayerUID
= Player
.FUID
then
1530 gCorpses
[i
].FPlayerUID
:= 0;
1532 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1537 if (FHealth
>= -50) or (gGibsCount
= 0) then
1539 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1543 for find_id
:= 0 to High(gCorpses
) do
1544 if gCorpses
[find_id
] = nil then
1551 find_id
:= Random(Length(gCorpses
));
1553 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1554 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1555 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1556 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1557 gCorpses
[find_id
].FPlayerUID
:= FUID
;
1560 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1561 FObj
.Y
+ PLAYER_RECT_CY
,
1562 FModel
.Name
, FModel
.Color
);
1566 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1570 if (gShells
= nil) or (Length(gShells
) = 0) then
1573 with gShells
[CurrentShell
] do
1579 if T
= SHELL_BULLET
then
1581 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1585 Obj
.Rect
.Width
:= 4;
1586 Obj
.Rect
.Height
:= 2;
1590 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1594 Obj
.Rect
.Width
:= 7;
1595 Obj
.Rect
.Height
:= 3;
1601 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1602 positionChanged(); // this updates spatial accelerators
1603 RAngle
:= Random(360);
1604 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1606 if CurrentShell
>= High(gShells
) then
1613 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1616 GibsArray
: TGibsArray
;
1619 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1621 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1623 Blood
:= g_PlayerModel_GetBlood(ModelName
);
1625 for a
:= 0 to High(GibsArray
) do
1626 with gGibs
[CurrentGib
] do
1629 ID
:= GibsArray
[a
].ID
;
1630 MaskID
:= GibsArray
[a
].MaskID
;
1633 Obj
.Rect
:= GibsArray
[a
].Rect
;
1634 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1635 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1636 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1637 positionChanged(); // this updates spatial accelerators
1638 RAngle
:= Random(360);
1640 if gBloodCount
> 0 then
1641 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1642 Random(48), Random(48), Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
1644 if CurrentGib
>= High(gGibs
) then
1651 procedure g_Player_UpdatePhysicalObjects();
1657 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1662 if T
= SHELL_BULLET
then
1663 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1665 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1670 if gGibs
<> nil then
1671 for i
:= 0 to High(gGibs
) do
1672 if gGibs
[i
].alive
then
1676 mr
:= g_Obj_Move(@Obj
, True, False, True);
1677 positionChanged(); // this updates spatial accelerators
1679 if WordBool(mr
and MOVE_FALLOUT
) then
1685 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1686 if WordBool(mr
and MOVE_HITWALL
) then
1687 Obj
.Vel
.X
:= -(vel
.X
div 2);
1688 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1689 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1691 if (Obj
.Vel
.X
>= 0) then
1693 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1694 if RAngle
>= 360 then
1695 RAngle
:= RAngle
mod 360;
1696 end else begin // Counter-clockwise
1697 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1699 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1702 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1703 if gTime
mod (GAME_TICK
*3) = 0 then
1704 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1708 if gCorpses
<> nil then
1709 for i
:= 0 to High(gCorpses
) do
1710 if gCorpses
[i
] <> nil then
1711 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1717 gCorpses
[i
].Update();
1720 if gShells
<> nil then
1721 for i
:= 0 to High(gShells
) do
1722 if gShells
[i
].alive
then
1726 mr
:= g_Obj_Move(@Obj
, True, False, True);
1727 positionChanged(); // this updates spatial accelerators
1729 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1735 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1736 if WordBool(mr
and MOVE_HITWALL
) then
1738 Obj
.Vel
.X
:= -(vel
.X
div 2);
1739 if not WordBool(mr
and MOVE_INWATER
) then
1740 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1742 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1744 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1745 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1746 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1748 if RAngle
mod 90 <> 0 then
1749 RAngle
:= (RAngle
div 90) * 90;
1751 else if not WordBool(mr
and MOVE_INWATER
) then
1752 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1755 if (Obj
.Vel
.X
>= 0) then
1757 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1758 if RAngle
>= 360 then
1759 RAngle
:= RAngle
mod 360;
1760 end else begin // Counter-clockwise
1761 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1763 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1769 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1771 x
:= Obj
.X
+Obj
.Rect
.X
;
1772 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1773 w
:= Obj
.Rect
.Width
;
1774 h
:= Obj
.Rect
.Height
;
1777 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1779 if (dx
<> 0) or (dy
<> 0) then
1788 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1792 w
:= Obj
.Rect
.Width
;
1793 h
:= Obj
.Rect
.Height
;
1796 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1798 if (dx
<> 0) or (dy
<> 0) then
1807 procedure TGib
.positionChanged (); inline; begin end;
1808 procedure TShell
.positionChanged (); inline; begin end;
1811 procedure g_Player_DrawCorpses();
1816 if gGibs
<> nil then
1817 for i
:= 0 to High(gGibs
) do
1818 if gGibs
[i
].alive
then
1821 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1824 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1825 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1827 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1830 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1836 if gCorpses
<> nil then
1837 for i
:= 0 to High(gCorpses
) do
1838 if gCorpses
[i
] <> nil then
1842 procedure g_Player_DrawShells();
1847 if gShells
<> nil then
1848 for i
:= 0 to High(gShells
) do
1849 if gShells
[i
].alive
then
1852 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1858 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1862 procedure g_Player_RemoveAllCorpses();
1868 SetLength(gGibs
, MaxGibs
);
1869 SetLength(gShells
, MaxGibs
);
1873 if gCorpses
<> nil then
1874 for i
:= 0 to High(gCorpses
) do
1878 SetLength(gCorpses
, MaxCorpses
);
1881 procedure g_Player_Corpses_SaveState (st
: TStream
);
1885 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ
1887 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1889 // Êîëè÷åñòâî òðóïîâ
1890 utils
.writeInt(st
, LongInt(count
));
1892 if (count
= 0) then exit
;
1895 for i
:= 0 to High(gCorpses
) do
1897 if gCorpses
[i
] <> nil then
1900 utils
.writeStr(st
, gCorpses
[i
].FModelName
);
1902 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1903 // Ñîõðàíÿåì äàííûå òðóïà:
1904 gCorpses
[i
].SaveState(st
);
1910 procedure g_Player_Corpses_LoadState (st
: TStream
);
1918 g_Player_RemoveAllCorpses();
1920 // Êîëè÷åñòâî òðóïîâ:
1921 count
:= utils
.readLongInt(st
);
1922 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1924 if (count
= 0) then exit
;
1927 for i
:= 0 to count
-1 do
1930 str
:= utils
.readStr(st
);
1932 b
:= utils
.readBool(st
);
1934 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1935 // Çàãðóæàåì äàííûå òðóïà
1936 gCorpses
[i
].LoadState(st
);
1943 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1945 procedure TPlayer
.BFGHit();
1947 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1948 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1949 if g_Game_IsServer
and g_Game_IsNet
then
1950 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1951 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1955 procedure TPlayer
.ChangeModel(ModelName
: string);
1957 locModel
: TPlayerModel
;
1959 locModel
:= g_PlayerModel_Get(ModelName
);
1960 if locModel
= nil then Exit
;
1966 procedure TPlayer
.SetModel(ModelName
: string);
1970 m
:= g_PlayerModel_Get(ModelName
);
1973 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1974 m
:= g_PlayerModel_Get('doomer');
1977 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1982 if FModel
<> nil then
1987 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1988 FModel
.Color
:= FColor
1990 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1991 FModel
.SetWeapon(FCurrWeap
);
1992 FModel
.SetFlag(FFlag
);
1993 SetDirection(FDirection
);
1996 procedure TPlayer
.SetColor(Color
: TRGB
);
1999 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2000 if FModel
<> nil then FModel
.Color
:= Color
;
2003 procedure TPlayer
.SwitchTeam
;
2005 if g_Game_IsClient
then
2007 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
2009 if gGameOn
and FAlive
then
2010 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
2012 if FTeam
= TEAM_RED
then
2014 ChangeTeam(TEAM_BLUE
);
2015 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
2016 if g_Game_IsNet
then
2017 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
2021 ChangeTeam(TEAM_RED
);
2022 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
2023 if g_Game_IsNet
then
2024 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
2026 FPreferredTeam
:= FTeam
;
2029 procedure TPlayer
.ChangeTeam(Team
: Byte);
2036 TEAM_RED
, TEAM_BLUE
:
2037 FModel
.Color
:= TEAMCOLOR
[Team
];
2039 FModel
.Color
:= FColor
;
2041 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2042 MH_SEND_PlayerStats(FUID
);
2046 procedure TPlayer.CollideItem();
2051 if gItems = nil then Exit;
2052 if not FAlive then Exit;
2054 for i := 0 to High(gItems) do
2057 if (ItemType <> ITEM_NONE) and alive then
2058 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2059 PLAYER_RECT.Height, @Obj) then
2061 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2063 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2064 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2065 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2066 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2067 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2069 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2070 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2071 (gGameSettings.GameType = GT_SINGLE) and
2072 (g_Player_GetCount() > 1)) then
2073 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2079 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2081 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2082 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2086 constructor TPlayer
.Create();
2092 mEDamageType
:= HIT_SOME
;
2098 FSawSound
:= TPlayableSound
.Create();
2099 FSawSoundIdle
:= TPlayableSound
.Create();
2100 FSawSoundHit
:= TPlayableSound
.Create();
2101 FSawSoundSelect
:= TPlayableSound
.Create();
2102 FJetSoundFly
:= TPlayableSound
.Create();
2103 FJetSoundOn
:= TPlayableSound
.Create();
2104 FJetSoundOff
:= TPlayableSound
.Create();
2106 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2107 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2108 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2109 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2110 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2111 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2112 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2114 FSpectatePlayer
:= -1;
2118 FSavedState
.WaitRecall
:= False;
2124 FActualModelName
:= 'doomer';
2127 FObj
.Rect
:= PLAYER_RECT
;
2129 FBFGFireCounter
:= -1;
2130 FJustTeleported
:= False;
2136 procedure TPlayer
.positionChanged (); inline;
2140 procedure TPlayer
.doDamage (v
: Integer);
2142 if (v
<= 0) then exit
;
2143 if (v
> 32767) then v
:= 32767;
2144 Damage(v
, 0, 0, 0, mEDamageType
);
2147 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2151 if (not g_Game_IsClient
) and (not FAlive
) then
2156 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2157 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2159 if not g_Game_IsClient
then
2162 if t
= HIT_TRAP
then
2164 // Ëîâóøêà óáèâàåò ñðàçó:
2166 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2168 if t
= HIT_SELF
then
2172 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2175 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2176 FMegaRulez
[MR_SUIT
] := 0;
2177 FMegaRulez
[MR_INVUL
] := 0;
2178 FMegaRulez
[MR_INVIS
] := 0;
2182 // Íî îò îñòàëüíîãî ñïàñàåò:
2183 if FMegaRulez
[MR_INVUL
] >= gTime
then
2190 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2191 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2192 (SpawnerUID
= FUID
) or
2193 (not SameTeam(FUID
, SpawnerUID
)) then
2195 FLastSpawnerUID
:= SpawnerUID
;
2197 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2198 if gBloodCount
> 0 then
2200 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2201 if value
div 4 <= c
then
2202 c
:= c
- (value
div 4)
2206 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2210 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2211 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2214 if t
= HIT_WATER
then
2215 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2216 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2221 Inc(FDamageBuffer
, value
);
2225 FPain
:= FPain
+ value
;
2228 if g_Game_IsServer
and g_Game_IsNet
then
2230 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2231 MH_SEND_PlayerStats(FUID
);
2232 MH_SEND_PlayerPos(False, FUID
);
2236 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2239 if g_Game_IsClient
then
2244 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2246 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2249 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2251 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2255 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2256 MH_SEND_PlayerStats(FUID
);
2259 destructor TPlayer
.Destroy();
2261 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2263 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2267 FSawSoundIdle
.Free();
2268 FSawSoundHit
.Free();
2269 FSawSoundSelect
.Free();
2270 FJetSoundFly
.Free();
2272 FJetSoundOff
.Free();
2274 if FPunchAnim
<> nil then
2280 procedure TPlayer
.DrawIndicator();
2282 indX
, indY
: Integer;
2288 indX
:= FObj
.X
+FObj
.Rect
.X
;
2290 if g_Texture_Get('TEXTURE_PLAYER_INDICATOR', ID
) then
2292 e_GetTextureSize(ID
, @indW
, @indH
);
2293 e_Draw(ID
, indX
+ indW
div 2, indY
- indH
, 0, True, False);
2296 //e_TextureFontPrint(indX, indY, FName, gStdFont); // Shows player name overhead
2299 procedure TPlayer
.DrawBubble();
2301 bubX
, bubY
: Integer;
2304 Rw
, Gw
, Bw
: SmallInt;
2307 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= TDirection
.D_LEFT
, -4, 18);
2308 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2316 1: // simple textual non-bubble
2318 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2319 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2320 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2323 2: // advanced pixel-perfect bubble
2325 if FTeam
= TEAM_RED
then
2328 if FTeam
= TEAM_BLUE
then
2331 3: // colored bubble
2333 Rb
:= FModel
.Color
.R
;
2334 Gb
:= FModel
.Color
.G
;
2335 Bb
:= FModel
.Color
.B
;
2336 Rw
:= Min(Rb
* 2 + 64, 255);
2337 Gw
:= Min(Gb
* 2 + 64, 255);
2338 Bw
:= Min(Bb
* 2 + 64, 255);
2339 if (Abs(Rw
- Rb
) < 32)
2340 or (Abs(Gw
- Gb
) < 32)
2341 or (Abs(Bw
- Bb
) < 32) then
2343 Rb
:= Max(Rw
div 2 - 16, 0);
2344 Gb
:= Max(Gw
div 2 - 16, 0);
2345 Bb
:= Max(Bw
div 2 - 16, 0);
2348 4: // custom textured bubble
2350 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2351 if FDirection
= TDirection
.D_RIGHT
then
2352 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2354 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, TMirrorType
.Horizontal
);
2360 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2361 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2363 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2366 Dot
:= IfThen(FDirection
= TDirection
.D_LEFT
, 14, 5);
2367 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2368 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
);
2369 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
);
2370 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
);
2371 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
);
2375 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2376 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2377 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2380 procedure TPlayer
.Draw();
2385 Mirror
: TMirrorType
;
2389 if Direction
= TDirection
.D_RIGHT
then
2390 Mirror
:= TMirrorType
.None
2392 Mirror
:= TMirrorType
.Horizontal
;
2394 if FPunchAnim
<> nil then
2396 FPunchAnim
.Draw(FObj
.X
+IfThen(Direction
= TDirection
.D_LEFT
, 15-FObj
.Rect
.X
, FObj
.Rect
.X
-15),
2397 FObj
.Y
+FObj
.Rect
.Y
-11, Mirror
);
2398 if FPunchAnim
.played
then
2405 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2406 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2408 e_GetTextureSize(ID
, @w
, @h
);
2409 if FDirection
= TDirection
.D_LEFT
then
2410 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2411 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False)
2413 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2414 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False);
2417 if FMegaRulez
[MR_INVIS
] > gTime
then
2419 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2420 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2422 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2423 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2427 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 200)
2429 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2432 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 254);
2435 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2438 if g_debug_Frames
then
2440 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2442 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2443 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2447 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2448 if (FMegaRulez
[MR_INVIS
] <= gTime
) or ((gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2449 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
)))) then
2451 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2452 if gAimLine
and alive
and
2453 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2458 procedure TPlayer
.DrawAim();
2459 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2464 {$IFDEF ENABLE_HOLMES}
2465 if isValidViewPort
and (self
= gPlayer1
) then
2467 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2471 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2472 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2474 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2478 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2483 wx
, wy
, xx
, yy
: Integer;
2487 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= TDirection
.D_LEFT
, 7, -7);
2488 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2497 1: begin // Chainsaw
2504 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2505 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2506 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2507 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2512 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2513 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2514 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2515 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2517 4: begin // Double Shotgun
2520 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2521 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2522 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2523 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2525 5: begin // Chaingun
2528 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2529 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2530 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2531 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2533 6: begin // Rocket Launcher
2536 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2537 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2538 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2539 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2541 7: begin // Plasmagun
2544 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2545 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2546 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2547 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2552 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2553 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2554 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2555 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2557 9: begin // Super Chaingun
2560 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2561 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2562 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2563 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2566 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2567 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2568 {$IF DEFINED(D2F_DEBUG)}
2569 drawCast(sz
, wx
, wy
, xx
, yy
);
2571 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2575 procedure TPlayer
.DrawGUI();
2578 X
, Y
, SY
, a
, p
, m
: Integer;
2582 stat
: TPlayerStatArray
;
2584 X
:= gPlayerScreenSize
.X
;
2585 SY
:= gPlayerScreenSize
.Y
;
2588 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2590 if gGameSettings
.GameMode
= GM_CTF
then
2594 if gGameSettings
.GameMode
= GM_CTF
then
2596 s
:= 'TEXTURE_PLAYER_REDFLAG';
2597 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2598 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2599 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2600 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2601 if g_Texture_Get(s
, ID
) then
2602 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2605 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2606 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2607 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2609 if gGameSettings
.GameMode
= GM_CTF
then
2611 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2612 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2613 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2614 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2615 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2616 if g_Texture_Get(s
, ID
) then
2617 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2620 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2621 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2622 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2625 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2626 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2629 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2630 e_Draw(ID
, X
+2, Y
, 0, True, False);
2632 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2636 s
:= IntToStr(Frags
);
2637 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2638 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2643 stat
:= g_Player_GetStats();
2648 for a
:= 0 to High(stat
) do
2649 if stat
[a
].Name
<> Name
then
2651 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2652 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2656 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2657 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2658 s
:= s
+IntToStr(Abs(Frags
-m
));
2660 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2661 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2664 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2666 s
:= IntToStr(Lives
);
2667 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2668 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2672 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2673 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2675 if R_BERSERK
in FRulez
then
2676 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2678 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2680 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2681 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2683 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2684 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2685 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2687 s
:= IntToStr(FArmor
);
2688 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2689 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2691 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2697 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2702 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2704 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2705 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2706 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2707 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2708 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2709 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2710 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2711 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2712 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2715 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2716 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2717 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2719 if R_KEY_RED
in FRulez
then
2720 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2722 if R_KEY_GREEN
in FRulez
then
2723 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2725 if R_KEY_BLUE
in FRulez
then
2726 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2728 if FJetFuel
> 0 then
2730 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2731 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2732 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2733 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2734 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2735 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2739 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2740 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2741 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2744 if gShowPing
and g_Game_IsClient
then
2746 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2747 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2753 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2754 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2755 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2758 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2759 s
:= _lc
[I_PLAYER_SPECT4
];
2760 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2761 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2762 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2768 procedure TPlayer
.DrawRulez();
2772 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2773 if FMegaRulez
[MR_INVUL
] >= gTime
then
2775 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2776 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2781 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2782 191, 191, 191, 0, TBlending
.Invert
);
2785 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2786 if FMegaRulez
[MR_SUIT
] >= gTime
then
2788 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2789 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2794 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2795 0, 96, 0, 200, TBlending
.None
);
2798 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2799 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2801 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2802 255, 0, 0, 200, TBlending
.None
);
2806 procedure TPlayer
.DrawPain();
2810 if FPain
= 0 then Exit
;
2814 if a
< 15 then h
:= 0
2815 else if a
< 35 then h
:= 1
2816 else if a
< 55 then h
:= 2
2817 else if a
< 75 then h
:= 3
2818 else if a
< 95 then h
:= 4
2821 //if a > 255 then a := 255;
2823 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2824 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2827 procedure TPlayer
.DrawPickup();
2831 if FPickup
= 0 then Exit
;
2835 if a
< 15 then h
:= 1
2836 else if a
< 35 then h
:= 2
2837 else if a
< 55 then h
:= 3
2838 else if a
< 75 then h
:= 4
2841 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2844 procedure TPlayer
.DoPunch();
2849 if FPunchAnim
<> nil then begin
2854 st
:= 'FRAMES_PUNCH';
2855 if R_BERSERK
in FRulez
then
2856 st
:= st
+ '_BERSERK';
2857 if FKeys
[KEY_UP
].Pressed
then
2859 else if FKeys
[KEY_DOWN
].Pressed
then
2861 g_Frames_Get(id
, st
);
2862 FPunchAnim
:= TAnimation
.Create(id
, False, 1);
2865 procedure TPlayer
.Fire();
2867 f
, DidFire
: Boolean;
2868 wx
, wy
, xd
, yd
: Integer;
2871 if g_Game_IsClient
then Exit
;
2872 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2873 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2881 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2886 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2887 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2888 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
2889 yd
:= wy
+firediry();
2895 if R_BERSERK
in FRulez
then
2897 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2898 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2899 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2902 locobj
.rect
.Width
:= 39;
2903 locobj
.rect
.Height
:= 52;
2904 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2905 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2906 locobj
.Accel
.X
:= xd
-wx
;
2907 locobj
.Accel
.y
:= yd
-wy
;
2909 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2910 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2912 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2914 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
2918 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2922 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2927 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2928 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2930 FSawSoundSelect
.Stop();
2932 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2934 else if not FSawSoundHit
.IsPlaying() then
2936 FSawSoundSelect
.Stop();
2937 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2940 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2946 if FAmmo
[A_BULLETS
] > 0 then
2948 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2949 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2950 Dec(FAmmo
[A_BULLETS
]);
2951 FFireAngle
:= FAngle
;
2954 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2955 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2959 if FAmmo
[A_SHELLS
] > 0 then
2961 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2962 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
2963 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2964 Dec(FAmmo
[A_SHELLS
]);
2965 FFireAngle
:= FAngle
;
2969 FShellType
:= SHELL_SHELL
;
2973 if FAmmo
[A_SHELLS
] >= 2 then
2975 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
2976 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2977 Dec(FAmmo
[A_SHELLS
], 2);
2978 FFireAngle
:= FAngle
;
2982 FShellType
:= SHELL_DBLSHELL
;
2986 if FAmmo
[A_BULLETS
] > 0 then
2988 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
2989 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
2990 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2991 Dec(FAmmo
[A_BULLETS
]);
2992 FFireAngle
:= FAngle
;
2995 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2996 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2999 WEAPON_ROCKETLAUNCHER
:
3000 if FAmmo
[A_ROCKETS
] > 0 then
3002 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
3003 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3004 Dec(FAmmo
[A_ROCKETS
]);
3005 FFireAngle
:= FAngle
;
3011 if FAmmo
[A_CELLS
] > 0 then
3013 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
3014 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3015 Dec(FAmmo
[A_CELLS
]);
3016 FFireAngle
:= FAngle
;
3022 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
3024 FBFGFireCounter
:= 17;
3025 if not FNoReload
then
3026 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
3027 Dec(FAmmo
[A_CELLS
], 40);
3031 WEAPON_SUPERPULEMET
:
3032 if FAmmo
[A_SHELLS
] > 0 then
3034 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3035 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
3036 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3037 Dec(FAmmo
[A_SHELLS
]);
3038 FFireAngle
:= FAngle
;
3041 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3042 GameVelX
, GameVelY
-2, SHELL_SHELL
);
3045 WEAPON_FLAMETHROWER
:
3046 if FAmmo
[A_FUEL
] > 0 then
3048 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
3049 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3051 FFireAngle
:= FAngle
;
3057 if g_Game_IsNet
then
3061 if FCurrWeap
<> WEAPON_BFG
then
3062 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
3064 if not FNoReload
then
3065 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
3068 MH_SEND_PlayerStats(FUID
);
3073 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
3074 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
3075 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
3078 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
3081 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
3082 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
3083 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
3084 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
3085 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
3090 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
3092 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
3093 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
3094 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
3097 procedure TPlayer
.JetpackOn
;
3101 FJetSoundOn
.SetPosition(0);
3102 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3106 procedure TPlayer
.JetpackOff
;
3110 FJetSoundOff
.SetPosition(0);
3111 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3114 procedure TPlayer
.CatchFire(Attacker
: Word);
3117 FFireAttacker
:= Attacker
;
3118 if g_Game_IsNet
and g_Game_IsServer
then
3119 MH_SEND_PlayerStats(FUID
);
3122 procedure TPlayer
.Jump();
3124 if gFly
or FJetpack
then
3126 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3127 if FObj
.Vel
.Y
> -VEL_FLY
then
3128 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3131 if FJetFuel
> 0 then
3133 if (FJetFuel
< 1) and g_Game_IsServer
then
3137 if g_Game_IsNet
then
3138 MH_SEND_PlayerStats(FUID
);
3144 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3146 FCanJetpack
:= False;
3148 // Ïðûãàåì èëè âñïëûâàåì:
3149 if (CollideLevel(0, 1) or
3150 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3151 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3152 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3154 FObj
.Vel
.Y
:= -VEL_JUMP
;
3155 FCanJetpack
:= False;
3159 if BodyInLiquid(0, 0) then
3160 FObj
.Vel
.Y
:= -VEL_SW
3161 else if (FJetFuel
> 0) and FCanJetpack
and
3162 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3166 if g_Game_IsNet
then
3167 MH_SEND_PlayerStats(FUID
);
3172 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3174 a
, i
, k
, ab
, ar
: Byte;
3178 srv
, netsrv
: Boolean;
3184 procedure PushItem(t
: Byte);
3188 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3189 it
:= g_Items_ByIdx(id
);
3190 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3192 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3193 (FObj
.Vel
.Y
div 2)-Random(9));
3194 it
.positionChanged(); // this updates spatial accelerators
3198 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3200 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3201 (FObj
.Vel
.Y
div 2)-Random(6));
3203 else // -3..+3; -3..0
3205 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3206 (FObj
.Vel
.Y
div 2)-Random(4));
3208 it
.positionChanged(); // this updates spatial accelerators
3211 if g_Game_IsNet
and g_Game_IsServer
then
3212 MH_SEND_ItemSpawn(True, id
);
3216 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3217 Srv
:= g_Game_IsServer
;
3218 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3219 if Srv
then FDeath
:= FDeath
+ 1;
3224 if not FPhysics
then
3230 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3232 if FLives
> 0 then FLives
:= FLives
- 1;
3233 if FLives
= 0 then FNoRespawn
:= True;
3236 // Íîìåð òèïà ñìåðòè:
3239 K_SIMPLEKILL
: a
:= 1;
3241 K_EXTRAHARDKILL
: a
:= 3;
3246 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3248 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3255 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3257 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3258 K_EXTRAHARDKILL
, K_FALLKILL
:
3259 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3262 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3266 K_HARDKILL
, K_EXTRAHARDKILL
:
3270 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3271 if (KillType
<> K_FALLKILL
) and (Srv
) then
3272 g_Monsters_killedp();
3274 if SpawnerUID
= FUID
then
3276 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3281 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3284 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3285 begin // Óáèò äðóãèì èãðîêîì
3286 KP
:= g_Player_Get(SpawnerUID
);
3287 if (KP
<> nil) and Srv
then
3289 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3290 if SameTeam(FUID
, SpawnerUID
) then
3300 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3301 Inc(gTeamStat
[KP
.Team
].Goals
,
3302 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3304 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3307 plr
:= g_Player_Get(SpawnerUID
);
3315 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3319 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3323 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3328 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3329 begin // Óáèò ìîíñòðîì
3330 mon
:= g_Monsters_ByUID(SpawnerUID
);
3334 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
3338 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3342 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3346 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3351 else // Îñîáûå òèïû ñìåðòè
3354 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3355 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3356 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3357 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3358 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3359 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3365 for a
:= WP_FIRST
to WP_LAST
do
3369 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3370 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3371 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3372 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3373 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3374 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3375 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3376 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3377 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3386 if R_ITEM_BACKPACK
in FRulez
then
3387 PushItem(ITEM_AMMO_BACKPACK
);
3389 // Âûáðîñ ðàêåòíîãî ðàíöà:
3390 if FJetFuel
> 0 then
3391 PushItem(ITEM_JETPACK
);
3394 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3396 if R_KEY_RED
in FRulez
then
3397 PushItem(ITEM_KEY_RED
);
3399 if R_KEY_GREEN
in FRulez
then
3400 PushItem(ITEM_KEY_GREEN
);
3402 if R_KEY_BLUE
in FRulez
then
3403 PushItem(ITEM_KEY_BLUE
);
3407 DropFlag(KillType
= K_FALLKILL
);
3410 g_Player_CreateCorpse(Self
);
3412 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3413 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3419 for i
:= Low(gPlayers
) to High(gPlayers
) do
3421 if gPlayers
[i
] = nil then continue
;
3422 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3425 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3426 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3431 OldLR
:= gLMSRespawn
;
3432 if (gGameSettings
.GameMode
= GM_COOP
) then
3436 // everyone is dead, restart the map
3437 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3439 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3440 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3441 gLMSRespawnTime
:= gTime
+ 5000;
3443 else if (a
= 1) then
3445 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3446 if (gPlayers
[k
] = gPlayer1
) or
3447 (gPlayers
[k
] = gPlayer2
) then
3448 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3449 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3450 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3453 else if (gGameSettings
.GameMode
= GM_TDM
) then
3455 if (ab
= 0) and (ar
<> 0) then
3458 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3460 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3461 Inc(gTeamStat
[TEAM_RED
].Goals
);
3462 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3463 gLMSRespawnTime
:= gTime
+ 5000;
3465 else if (ar
= 0) and (ab
<> 0) then
3468 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3470 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3471 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3472 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3473 gLMSRespawnTime
:= gTime
+ 5000;
3475 else if (ar
= 0) and (ab
= 0) then
3478 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3480 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3481 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3482 gLMSRespawnTime
:= gTime
+ 5000;
3485 else if (gGameSettings
.GameMode
= GM_DM
) then
3489 if gPlayers
[k
] <> nil then
3492 // survivor is the winner
3493 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3495 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3498 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3499 gLMSRespawnTime
:= gTime
+ 5000;
3501 else if (a
= 0) then
3503 // everyone is dead, restart the map
3504 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3506 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3507 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3508 gLMSRespawnTime
:= gTime
+ 5000;
3511 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3513 if NetMode
= NET_SERVER
then
3514 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3516 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3522 MH_SEND_PlayerStats(FUID
);
3523 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3524 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3527 if srv
and FNoRespawn
then Spectate(True);
3528 FWantsInGame
:= True;
3531 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3533 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3534 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3537 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3539 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3540 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3543 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3545 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3546 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3547 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3548 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3549 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3550 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3551 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3552 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3555 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3557 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3558 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3559 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3560 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3563 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3565 if g_Game_IsClient
then Exit
;
3566 if Weapon
> High(FWeapon
) then Exit
;
3567 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3570 procedure TPlayer
.resetWeaponQueue ();
3573 FNextWeapDelay
:= 0;
3576 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3580 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3581 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 0);
3582 WEAPON_PISTOL
, WEAPON_CHAINGUN
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_BULLETS
] > 0);
3583 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3584 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3585 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3586 else result
:= (weapon
< length(FWeapon
));
3590 // return 255 for "no switch"
3591 function TPlayer
.getNextWeaponIndex (): Byte;
3594 wantThisWeapon
: array[0..64] of Boolean;
3595 wwc
: Integer = 0; //HACK!
3598 result
:= 255; // default result: "no switch"
3599 // had weapon cycling on previous frame? remove that flag
3600 if (FNextWeap
and $2000) <> 0 then
3602 FNextWeap
:= FNextWeap
and $1FFF;
3603 FNextWeapDelay
:= 0;
3605 // cycling has priority
3606 if (FNextWeap
and $C000) <> 0 then
3608 if (FNextWeap
and $8000) <> 0 then
3612 FNextWeap
:= FNextWeap
or $2000; // we need this
3613 if FNextWeapDelay
> 0 then
3614 exit
; // cooldown time
3616 for i
:= 0 to High(FWeapon
) do
3618 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3619 if FWeapon
[cwi
] then
3621 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d', [FCurrWeap, cwi]), MSG_WARNING);
3622 result
:= Byte(cwi
);
3623 FNextWeapDelay
:= WEAPON_DELAY
;
3631 for i
:= 0 to High(wantThisWeapon
) do
3632 wantThisWeapon
[i
] := false;
3633 for i
:= 0 to High(FWeapon
) do
3634 if (FNextWeap
and (1 shl i
)) <> 0 then
3636 wantThisWeapon
[i
] := true;
3639 // exclude currently selected weapon from the set
3640 wantThisWeapon
[FCurrWeap
] := false;
3641 // slow down alterations a little
3644 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3645 // more than one weapon requested, assume "alteration" and check alteration delay
3646 if FNextWeapDelay
> 0 then
3652 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3653 // but clear all counters if no weapon should be switched
3659 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3660 // try weapons in descending order
3661 for i
:= High(FWeapon
) downto 0 do
3663 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3668 FNextWeapDelay
:= WEAPON_DELAY
; // anyway, 'cause why not
3672 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3676 procedure TPlayer
.RealizeCurrentWeapon();
3677 function switchAllowed (): Boolean;
3682 if FBFGFireCounter
<> -1 then
3684 if FTime
[T_SWITCH
] > gTime
then
3686 for i
:= WP_FIRST
to WP_LAST
do
3687 if FReloading
[i
] > 0 then
3695 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3696 //FNextWeap := FNextWeap and $1FFF;
3697 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3699 if not switchAllowed
then
3701 //HACK for weapon cycling
3702 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3706 nw
:= getNextWeaponIndex();
3707 if nw
= 255 then exit
; // don't reset anything here
3708 if nw
> High(FWeapon
) then
3710 // don't forget to reset queue here!
3711 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3719 FTime
[T_SWITCH
] := gTime
+156;
3720 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3721 FModel
.SetWeapon(FCurrWeap
);
3722 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3726 procedure TPlayer
.NextWeapon();
3728 if g_Game_IsClient
then Exit
;
3732 procedure TPlayer
.PrevWeapon();
3734 if g_Game_IsClient
then Exit
;
3738 procedure TPlayer
.SetWeapon(W
: Byte);
3740 if FCurrWeap
<> W
then
3741 if W
= WEAPON_SAW
then
3742 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3745 FModel
.SetWeapon(CurrWeap
);
3749 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3751 function allowBerserkSwitching (): Boolean;
3753 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3755 if gBerserkAutoswitch
then exit
;
3756 if not conIsCheatsEnabled
then exit
;
3764 if g_Game_IsClient
then Exit
;
3766 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3767 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3772 if FHealth
< PLAYER_HP_SOFT
then
3774 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3778 if gFlash
= 2 then Inc(FPickup
, 5);
3782 if FHealth
< PLAYER_HP_SOFT
then
3784 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3788 if gFlash
= 2 then Inc(FPickup
, 5);
3792 if FArmor
< PLAYER_AP_SOFT
then
3794 FArmor
:= PLAYER_AP_SOFT
;
3797 if gFlash
= 2 then Inc(FPickup
, 5);
3801 if FArmor
< PLAYER_AP_LIMIT
then
3803 FArmor
:= PLAYER_AP_LIMIT
;
3806 if gFlash
= 2 then Inc(FPickup
, 5);
3810 if FHealth
< PLAYER_HP_LIMIT
then
3812 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3816 if gFlash
= 2 then Inc(FPickup
, 5);
3820 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3822 if FHealth
< PLAYER_HP_LIMIT
then
3823 FHealth
:= PLAYER_HP_LIMIT
;
3824 if FArmor
< PLAYER_AP_LIMIT
then
3825 FArmor
:= PLAYER_AP_LIMIT
;
3829 if gFlash
= 2 then Inc(FPickup
, 5);
3833 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3835 FWeapon
[WEAPON_SAW
] := True;
3837 if gFlash
= 2 then Inc(FPickup
, 5);
3838 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3841 ITEM_WEAPON_SHOTGUN1
:
3842 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3844 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3845 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3847 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3848 FWeapon
[WEAPON_SHOTGUN1
] := True;
3850 if gFlash
= 2 then Inc(FPickup
, 5);
3851 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3854 ITEM_WEAPON_SHOTGUN2
:
3855 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3857 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3859 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3860 FWeapon
[WEAPON_SHOTGUN2
] := True;
3862 if gFlash
= 2 then Inc(FPickup
, 5);
3863 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3866 ITEM_WEAPON_CHAINGUN
:
3867 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3869 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3871 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3872 FWeapon
[WEAPON_CHAINGUN
] := True;
3874 if gFlash
= 2 then Inc(FPickup
, 5);
3875 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3878 ITEM_WEAPON_ROCKETLAUNCHER
:
3879 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3881 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3883 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3884 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3886 if gFlash
= 2 then Inc(FPickup
, 5);
3887 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3891 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3893 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3895 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3896 FWeapon
[WEAPON_PLASMA
] := True;
3898 if gFlash
= 2 then Inc(FPickup
, 5);
3899 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3903 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3905 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3907 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3908 FWeapon
[WEAPON_BFG
] := True;
3910 if gFlash
= 2 then Inc(FPickup
, 5);
3911 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3914 ITEM_WEAPON_SUPERPULEMET
:
3915 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3917 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3919 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3920 FWeapon
[WEAPON_SUPERPULEMET
] := 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_FLAMETHROWER
:
3927 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
3929 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
3931 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3932 FWeapon
[WEAPON_FLAMETHROWER
] := 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');
3939 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3941 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3944 if gFlash
= 2 then Inc(FPickup
, 5);
3947 ITEM_AMMO_BULLETS_BOX
:
3948 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3950 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3953 if gFlash
= 2 then Inc(FPickup
, 5);
3957 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3959 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3962 if gFlash
= 2 then Inc(FPickup
, 5);
3965 ITEM_AMMO_SHELLS_BOX
:
3966 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3968 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
3971 if gFlash
= 2 then Inc(FPickup
, 5);
3975 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3977 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3980 if gFlash
= 2 then Inc(FPickup
, 5);
3983 ITEM_AMMO_ROCKET_BOX
:
3984 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3986 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
3989 if gFlash
= 2 then Inc(FPickup
, 5);
3993 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3995 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3998 if gFlash
= 2 then Inc(FPickup
, 5);
4002 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4004 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4007 if gFlash
= 2 then Inc(FPickup
, 5);
4011 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4013 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4016 if gFlash
= 2 then Inc(FPickup
, 5);
4020 if not(R_ITEM_BACKPACK
in FRulez
) or
4021 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4022 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4023 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4024 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4025 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
4027 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4028 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4029 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4030 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4031 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4033 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4034 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4035 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4036 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4037 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4038 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4039 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4040 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4042 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
4045 if gFlash
= 2 then Inc(FPickup
, 5);
4049 if not(R_KEY_RED
in FRulez
) then
4051 Include(FRulez
, R_KEY_RED
);
4053 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4054 if gFlash
= 2 then Inc(FPickup
, 5);
4055 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4059 if not(R_KEY_GREEN
in FRulez
) then
4061 Include(FRulez
, R_KEY_GREEN
);
4063 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4064 if gFlash
= 2 then Inc(FPickup
, 5);
4065 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4069 if not(R_KEY_BLUE
in FRulez
) then
4071 Include(FRulez
, R_KEY_BLUE
);
4073 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4074 if gFlash
= 2 then Inc(FPickup
, 5);
4075 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4079 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4081 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4085 if gFlash
= 2 then Inc(FPickup
, 5);
4089 if FAir
< AIR_MAX
then
4094 if gFlash
= 2 then Inc(FPickup
, 5);
4099 if not (R_BERSERK
in FRulez
) then
4101 Include(FRulez
, R_BERSERK
);
4102 if allowBerserkSwitching
then
4104 FCurrWeap
:= WEAPON_KASTET
;
4106 FModel
.SetWeapon(WEAPON_KASTET
);
4111 if gFlash
= 2 then Inc(FPickup
, 5);
4113 FBerserk
:= gTime
+30000;
4118 if FHealth
< PLAYER_HP_SOFT
then
4120 FHealth
:= PLAYER_HP_SOFT
;
4121 FBerserk
:= gTime
+30000;
4129 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4131 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4134 if gFlash
= 2 then Inc(FPickup
, 5);
4138 if FHealth
< PLAYER_HP_LIMIT
then
4140 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4144 if gFlash
= 2 then Inc(FPickup
, 5);
4148 if FArmor
< PLAYER_AP_LIMIT
then
4150 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4153 if gFlash
= 2 then Inc(FPickup
, 5);
4157 if FJetFuel
< JET_MAX
then
4159 FJetFuel
:= JET_MAX
;
4162 if gFlash
= 2 then Inc(FPickup
, 5);
4166 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4168 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4171 if gFlash
= 2 then Inc(FPickup
, 5);
4176 procedure TPlayer
.Touch();
4180 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4183 // Áðîñèòü ôëàã òîâàðèùó:
4184 if gGameSettings
.GameMode
= GM_CTF
then
4189 procedure TPlayer
.Push(vx
, vy
: Integer);
4191 if (not FPhysics
) and FGhost
then
4193 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4194 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4195 if g_Game_IsNet
and g_Game_IsServer
then
4196 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4199 procedure TPlayer
.Reset(Force
: Boolean);
4205 FTime
[T_RESPAWN
] := 0;
4206 FTime
[T_FLAGCAP
] := 0;
4219 FSpectator
:= False;
4222 FSpectatePlayer
:= -1;
4223 FNoRespawn
:= False;
4225 FLives
:= gGameSettings
.MaxLives
;
4230 procedure TPlayer
.SoftReset();
4236 FBFGFireCounter
:= -1;
4244 SetAction(A_STAND
, True);
4247 function TPlayer
.GetRespawnPoint(): Byte;
4252 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4254 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4255 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4257 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4259 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4260 if Self
= gPlayer1
then
4261 c
:= RESPAWNPOINT_PLAYER1
4263 c
:= RESPAWNPOINT_PLAYER2
;
4264 if g_Map_GetPointCount(c
) > 0 then
4270 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4271 if Self
= gPlayer1
then
4272 c
:= RESPAWNPOINT_PLAYER2
4274 c
:= RESPAWNPOINT_PLAYER1
;
4275 if g_Map_GetPointCount(c
) > 0 then
4282 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4283 if Random(2) = 0 then
4284 c
:= RESPAWNPOINT_PLAYER1
4286 c
:= RESPAWNPOINT_PLAYER2
;
4287 if g_Map_GetPointCount(c
) > 0 then
4294 // Òî÷êà ëþáîé èç êîìàíä
4295 if Random(2) = 0 then
4296 c
:= RESPAWNPOINT_RED
4298 c
:= RESPAWNPOINT_BLUE
;
4299 if g_Map_GetPointCount(c
) > 0 then
4306 c
:= RESPAWNPOINT_DM
;
4307 if g_Map_GetPointCount(c
) > 0 then
4315 if gGameSettings
.GameMode
= GM_DM
then
4318 c
:= RESPAWNPOINT_DM
;
4319 if g_Map_GetPointCount(c
) > 0 then
4325 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4326 if Random(2) = 0 then
4327 c
:= RESPAWNPOINT_PLAYER1
4329 c
:= RESPAWNPOINT_PLAYER2
;
4330 if g_Map_GetPointCount(c
) > 0 then
4336 // Òî÷êà ëþáîé èç êîìàíä
4337 if Random(2) = 0 then
4338 c
:= RESPAWNPOINT_RED
4340 c
:= RESPAWNPOINT_BLUE
;
4341 if g_Map_GetPointCount(c
) > 0 then
4349 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4351 // Òî÷êà ñâîåé êîìàíäû
4352 c
:= RESPAWNPOINT_DM
;
4353 if FTeam
= TEAM_RED
then
4354 c
:= RESPAWNPOINT_RED
;
4355 if FTeam
= TEAM_BLUE
then
4356 c
:= RESPAWNPOINT_BLUE
;
4357 if g_Map_GetPointCount(c
) > 0 then
4364 c
:= RESPAWNPOINT_DM
;
4365 if g_Map_GetPointCount(c
) > 0 then
4371 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4372 if Random(2) = 0 then
4373 c
:= RESPAWNPOINT_PLAYER1
4375 c
:= RESPAWNPOINT_PLAYER2
;
4376 if g_Map_GetPointCount(c
) > 0 then
4382 // Òî÷êà äðóãîé êîìàíäû
4383 c
:= RESPAWNPOINT_DM
;
4384 if FTeam
= TEAM_RED
then
4385 c
:= RESPAWNPOINT_BLUE
;
4386 if FTeam
= TEAM_BLUE
then
4387 c
:= RESPAWNPOINT_RED
;
4388 if g_Map_GetPointCount(c
) > 0 then
4396 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4398 RespawnPoint
: TRespawnPoint
;
4404 FBFGFireCounter
:= -1;
4409 if not g_Game_IsServer
then
4413 FWantsInGame
:= True;
4414 FJustTeleported
:= True;
4417 FTime
[T_RESPAWN
] := 0;
4421 // if server changes MaxLives we gotta be ready
4422 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4424 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4425 if FTime
[T_RESPAWN
] > gTime
then
4428 // Ïðîñðàë âñå æèçíè:
4431 if not FSpectator
then Spectate(True);
4432 FWantsInGame
:= True;
4436 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4437 begin // "Ñâîÿ èãðà"
4438 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4439 FRulez
:= FRulez
-[R_BERSERK
];
4441 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4443 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4444 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4447 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4448 c
:= GetRespawnPoint();
4453 // Âîñêðåøåíèå áåç îðóæèÿ:
4456 FHealth
:= PLAYER_HP_SOFT
;
4462 for a
:= WP_FIRST
to WP_LAST
do
4464 FWeapon
[a
] := False;
4468 FWeapon
[WEAPON_PISTOL
] := True;
4469 FWeapon
[WEAPON_KASTET
] := True;
4470 FCurrWeap
:= WEAPON_PISTOL
;
4473 FModel
.SetWeapon(FCurrWeap
);
4475 for b
:= A_BULLETS
to A_HIGH
do
4478 FAmmo
[A_BULLETS
] := 50;
4480 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4481 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4482 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4483 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4484 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4486 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4487 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4492 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4493 if not g_Map_GetPoint(c
, RespawnPoint
) then
4495 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4499 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4500 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4501 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4507 FDirection
:= RespawnPoint
.Direction
;
4508 if FDirection
= TDirection
.D_LEFT
then
4513 SetAction(A_STAND
, True);
4514 FModel
.Direction
:= FDirection
;
4516 for a
:= Low(FTime
) to High(FTime
) do
4519 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4524 FCanJetpack
:= False;
4529 // Àíèìàöèÿ âîçðîæäåíèÿ:
4530 if (not gLoadGameMode
) and (not Silent
) then
4531 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4533 Anim
:= TAnimation
.Create(ID
, False, 3);
4534 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4535 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4539 FSpectator
:= False;
4542 FSpectatePlayer
:= -1;
4545 if (gPlayer1
= nil) and (gLMSPID1
= FUID
) then
4547 if (gPlayer2
= nil) and (gLMSPID2
= FUID
) then
4550 if g_Game_IsNet
then
4552 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4553 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4555 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4556 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4561 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4564 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4565 else if (not NoMove
) then
4567 GameX
:= gMapInfo
.Width
div 2;
4568 GameY
:= gMapInfo
.Height
div 2;
4577 FWantsInGame
:= False;
4582 if Self
= gPlayer1
then
4587 if Self
= gPlayer2
then
4594 if g_Game_IsNet
then
4595 MH_SEND_PlayerStats(FUID
);
4598 procedure TPlayer
.SwitchNoClip
;
4602 FGhost
:= not FGhost
;
4603 FPhysics
:= not FGhost
;
4615 procedure TPlayer
.Run(Direction
: TDirection
);
4619 if MAX_RUNVEL
> 8 then
4623 if Direction
= TDirection
.D_LEFT
then
4625 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4626 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4629 if FObj
.Vel
.X
< MAX_RUNVEL
then
4630 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4632 // Âîçìîæíî, ïèíàåì êóñêè:
4633 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4635 b
:= Abs(FObj
.Vel
.X
);
4636 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4637 for a
:= 0 to High(gGibs
) do
4639 if gGibs
[a
].alive
and
4640 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4641 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4644 if FObj
.Vel
.X
< 0 then
4646 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4650 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4652 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4660 procedure TPlayer
.SeeDown();
4662 SetAction(A_SEEDOWN
);
4664 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4666 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4669 procedure TPlayer
.SeeUp();
4673 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4675 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4678 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4686 A_ATTACK
: Prior
:= 2;
4687 A_SEEUP
: Prior
:= 1;
4688 A_SEEDOWN
: Prior
:= 1;
4689 A_ATTACKUP
: Prior
:= 2;
4690 A_ATTACKDOWN
: Prior
:= 2;
4695 if (Prior
> FActionPrior
) or Force
then
4696 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4698 FActionPrior
:= Prior
;
4699 FActionAnim
:= Action
;
4700 FActionForce
:= Force
;
4701 FActionChanged
:= True;
4704 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4707 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4709 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4710 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4711 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4712 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4715 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4722 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4724 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4725 if g_Game_IsServer
and g_Game_IsNet
then
4726 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4730 FJustTeleported
:= True;
4735 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4737 Anim
:= TAnimation
.Create(ID
, False, 3);
4740 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4741 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4742 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4743 if g_Game_IsServer
and g_Game_IsNet
then
4744 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4745 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4749 FObj
.X
:= X
-PLAYER_RECT
.X
;
4750 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4751 if FAlive
and FGhost
then
4757 if not g_Game_IsNet
then
4761 SetDirection(TDirection
.D_LEFT
);
4767 SetDirection(TDirection
.D_RIGHT
);
4773 if FDirection
= TDirection
.D_RIGHT
then
4775 SetDirection(TDirection
.D_LEFT
);
4780 SetDirection(TDirection
.D_RIGHT
);
4786 if not silent
and (Anim
<> nil) then
4788 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4789 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4792 if g_Game_IsServer
and g_Game_IsNet
then
4793 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4794 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4801 function nonz(a
: Single): Single;
4809 function TPlayer
.followCorpse(): Boolean;
4814 if FAlive
or FSpectator
then
4816 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
4818 for i
:= 0 to High(gCorpses
) do
4819 if gCorpses
[i
] <> nil then
4820 if gCorpses
[i
].FPlayerUID
= FUID
then
4823 FObj
.X
:= gCorpses
[i
].FObj
.X
;
4824 FObj
.Y
:= gCorpses
[i
].FObj
.Y
;
4825 FObj
.Vel
.X
:= gCorpses
[i
].FObj
.Vel
.X
;
4826 FObj
.Vel
.Y
:= gCorpses
[i
].FObj
.Vel
.Y
;
4827 FObj
.Accel
.X
:= gCorpses
[i
].FObj
.Accel
.X
;
4828 FObj
.Accel
.Y
:= gCorpses
[i
].FObj
.Accel
.Y
;
4833 procedure TPlayer
.Update();
4836 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4837 blockmon
, headwater
, dospawn
: Boolean;
4842 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4843 AnyServer
:= g_Game_IsServer
;
4845 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4846 DoLerp(NetInterpLevel
+ 1)
4852 if FClientID
>= 0 then
4854 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4855 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4856 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4865 if FAlive
and (FPunchAnim
<> nil) then
4866 FPunchAnim
.Update();
4868 if FAlive
and (gFly
or FJetpack
) then
4871 if FDirection
= TDirection
.D_LEFT
then
4876 if FAlive
and (not FGhost
) then
4878 if FKeys
[KEY_UP
].Pressed
then
4880 if FKeys
[KEY_DOWN
].Pressed
then
4884 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4887 i
:= g_basic
.Sign(FIncCam
);
4888 FIncCam
:= Abs(FIncCam
);
4889 DecMin(FIncCam
, 5, 0);
4890 FIncCam
:= FIncCam
*i
;
4893 // no need to do that each second frame, weapon queue will take care of it
4894 if FAlive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4895 if FAlive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4897 if gTime
mod (GAME_TICK
*2) <> 0 then
4899 if (FObj
.Vel
.X
= 0) and FAlive
then
4901 if FKeys
[KEY_LEFT
].Pressed
then
4902 Run(TDirection
.D_LEFT
);
4903 if FKeys
[KEY_RIGHT
].Pressed
then
4904 Run(TDirection
.D_RIGHT
);
4909 if not followCorpse() then
4910 g_Obj_Move(@FObj
, True, True, True);
4911 positionChanged(); // this updates spatial accelerators
4917 FActionChanged
:= False;
4921 // Let alive player do some actions
4922 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
4923 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
4924 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
4925 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
4926 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
4927 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
4928 if FKeys
[KEY_JUMP
].Pressed
then Jump()
4931 if AnyServer
and FJetpack
then
4935 if NetServer
then MH_SEND_PlayerStats(FUID
);
4937 FCanJetpack
:= True;
4944 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
4946 if FKeys
[k
].Pressed
then
4954 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4957 if (FTime
[T_RESPAWN
] <= gTime
) and
4958 gGameOn
and (not FAlive
) then
4960 if (g_Player_GetCount() > 1) then
4964 gExit
:= EXIT_RESTART
;
4969 // Dead spectator actions
4972 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
4973 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
4977 if (FSpectatePlayer
>= High(gPlayers
)) then
4978 FSpectatePlayer
:= -1
4982 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
4983 if gPlayers
[I
] <> nil then
4984 if gPlayers
[I
].alive
then
4985 if gPlayers
[I
].UID
<> FUID
then
4987 FSpectatePlayer
:= I
;
4992 if not SetSpect
then FSpectatePlayer
:= -1;
5003 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5005 FYTo
:= FObj
.Y
- 32;
5006 FSpectatePlayer
:= -1;
5008 if FKeys
[KEY_DOWN
].Pressed
then
5010 FYTo
:= FObj
.Y
+ 32;
5011 FSpectatePlayer
:= -1;
5013 if FKeys
[KEY_LEFT
].Pressed
then
5015 FXTo
:= FObj
.X
- 32;
5016 FSpectatePlayer
:= -1;
5018 if FKeys
[KEY_RIGHT
].Pressed
then
5020 FXTo
:= FObj
.X
+ 32;
5021 FSpectatePlayer
:= -1;
5024 if (FXTo
< -64) then
5026 else if (FXTo
> gMapInfo
.Width
+ 32) then
5027 FXTo
:= gMapInfo
.Width
+ 32;
5028 if (FYTo
< -72) then
5030 else if (FYTo
> gMapInfo
.Height
+ 32) then
5031 FYTo
:= gMapInfo
.Height
+ 32;
5036 if not followCorpse() then
5037 g_Obj_Move(@FObj
, True, True, True);
5038 positionChanged(); // this updates spatial accelerators
5045 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5046 if gPlayers
[FSpectatePlayer
] <> nil then
5047 if gPlayers
[FSpectatePlayer
].alive
then
5049 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
5050 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
5054 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5055 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5056 PANEL_BLOCKMON
, True);
5057 headwater
:= HeadInLiquid(0, 0);
5059 // Ñîïðîòèâëåíèå âîçäóõà:
5060 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5061 if FObj
.Vel
.X
<> 0 then
5062 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5064 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5065 DecMin(FPain
, 5, 0);
5066 DecMin(FPickup
, 1, 0);
5068 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5070 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5071 FMegaRulez
[MR_SUIT
] := 0;
5072 FMegaRulez
[MR_INVUL
] := 0;
5073 FMegaRulez
[MR_INVIS
] := 0;
5074 Kill(K_FALLKILL
, 0, HIT_FALL
);
5081 if FCurrWeap
= WEAPON_SAW
then
5082 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5083 FSawSoundSelect
.IsPlaying()) then
5084 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5087 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5088 (not FJetSoundOff
.IsPlaying()) then
5090 FJetSoundFly
.SetPosition(0);
5091 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5094 for b
:= WP_FIRST
to WP_LAST
do
5095 if FReloading
[b
] > 0 then
5101 if FShellTimer
> -1 then
5102 if FShellTimer
= 0 then
5104 if FShellType
= SHELL_SHELL
then
5105 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5106 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5107 else if FShellType
= SHELL_DBLSHELL
then
5109 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5110 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5111 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5112 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5115 end else Dec(FShellTimer
);
5117 if (FBFGFireCounter
> -1) then
5118 if FBFGFireCounter
= 0 then
5122 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5123 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5124 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5125 yd
:= wy
+firediry();
5126 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5127 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5128 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5129 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5130 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5133 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5134 FBFGFireCounter
:= -1;
5137 FBFGFireCounter
:= 0
5139 Dec(FBFGFireCounter
);
5141 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5143 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5145 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5148 if (headwater
or blockmon
) then
5154 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5157 else if (FAir
mod 31 = 0) and not blockmon
then
5159 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5160 if Random(2) = 0 then
5161 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5163 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5165 end else if FAir
< AIR_DEF
then
5168 if FFireTime
> 0 then
5170 if BodyInLiquid(0, 0) then
5175 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5177 if FMegaRulez
[MR_SUIT
] = gTime
then
5184 if FFirePainTime
<= 0 then
5186 if g_Game_IsServer
then
5187 Damage(5, FFireAttacker
, 0, 0, HIT_FLAME
);
5188 FFirePainTime
:= 18;
5190 FFirePainTime
:= FFirePainTime
- 1;
5191 FFireTime
:= FFireTime
- 1;
5192 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5193 MH_SEND_PlayerStats(FUID
);
5197 if FDamageBuffer
> 0 then
5199 if FDamageBuffer
>= 9 then
5203 if FDamageBuffer
< 30 then i
:= 9
5204 else if FDamageBuffer
< 100 then i
:= 18
5208 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5209 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5210 FHealth
:= FHealth
-ii
;
5213 FHealth
:= FHealth
+FArmor
;
5218 if FHealth
<= 0 then
5219 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5220 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5221 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5225 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5226 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5227 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5228 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5235 end; // if FAlive then ...
5237 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5239 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5240 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5241 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5242 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5244 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5245 then SetAction(A_STAND
, True);
5247 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5249 for b
:= Low(FKeys
) to High(FKeys
) do
5250 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5254 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5256 x
:= FObj
.X
+PLAYER_RECT
.X
;
5257 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5258 w
:= PLAYER_RECT
.Width
;
5259 h
:= PLAYER_RECT
.Height
;
5263 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5265 if (dx
<> 0) or (dy
<> 0) then
5274 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5276 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5277 FObj
.Y
+PLAYER_RECT
.Y
,
5284 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5286 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5287 FObj
.Y
+PLAYER_RECT
.Y
,
5291 Panel
.Width
, Panel
.Height
);
5294 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5296 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5297 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5298 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5299 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5302 function g_Player_ValidName(Name
: string): Boolean;
5308 if gPlayers
= nil then Exit
;
5310 for a
:= 0 to High(gPlayers
) do
5311 if gPlayers
[a
] <> nil then
5312 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5319 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5323 d
:= FModel
.Direction
;
5325 FModel
.Direction
:= Direction
;
5326 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5328 FDirection
:= Direction
;
5331 function TPlayer
.GetKeys(): Byte;
5335 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5336 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5337 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5339 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5340 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5343 procedure TPlayer
.Use();
5347 if FTime
[T_USE
] > gTime
then Exit
;
5349 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5350 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5352 for a
:= 0 to High(gPlayers
) do
5353 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5354 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5355 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5356 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5358 gPlayers
[a
].Touch();
5359 if g_Game_IsNet
and g_Game_IsServer
then
5360 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5363 FTime
[T_USE
] := gTime
+120;
5366 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5370 WX
, WY
, XD
, YD
: Integer;
5382 if R_BERSERK
in FRulez
then
5384 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5385 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5386 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5389 locobj
.rect
.Width
:= 39;
5390 locobj
.rect
.Height
:= 52;
5391 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5392 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5393 locobj
.Accel
.X
:= xd
-wx
;
5394 locobj
.Accel
.y
:= yd
-wy
;
5396 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5397 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5399 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5403 FPain
:= min(FPain
+ 25, 50);
5405 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5410 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5411 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5413 FSawSoundSelect
.Stop();
5415 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5417 else if not FSawSoundHit
.IsPlaying() then
5419 FSawSoundSelect
.Stop();
5420 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5427 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5428 FFireAngle
:= FAngle
;
5430 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5431 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5436 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5437 FFireAngle
:= FAngle
;
5440 FShellType
:= SHELL_SHELL
;
5445 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5446 FFireAngle
:= FAngle
;
5449 FShellType
:= SHELL_DBLSHELL
;
5454 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5455 FFireAngle
:= FAngle
;
5457 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5458 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5461 WEAPON_ROCKETLAUNCHER
:
5463 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5464 FFireAngle
:= FAngle
;
5470 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5471 FFireAngle
:= FAngle
;
5477 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5478 FFireAngle
:= FAngle
;
5482 WEAPON_SUPERPULEMET
:
5484 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5485 FFireAngle
:= FAngle
;
5487 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5488 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5491 WEAPON_FLAMETHROWER
:
5493 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5494 FFireAngle
:= FAngle
;
5501 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5502 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5503 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5506 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5508 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5509 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5512 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5516 if NetInterpLevel
< 1 then
5526 AX
:= Abs(FXTo
- FObj
.X
);
5527 AY
:= Abs(FYTo
- FObj
.Y
);
5528 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5530 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5535 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5537 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5538 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5539 PANEL_LIFTUP
, False) then Result
:= -1
5541 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5542 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5543 PANEL_LIFTDOWN
, False) then Result
:= 1
5547 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5554 if Flag
= FLAG_NONE
then
5557 if not g_Game_IsServer
then Exit
;
5559 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5560 if (Flag
= FTeam
) and
5561 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5562 (FFlag
<> FLAG_NONE
) then
5564 if FFlag
= FLAG_RED
then
5565 s
:= _lc
[I_PLAYER_FLAG_RED
]
5567 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5569 evtype
:= FLAG_STATE_SCORED
;
5571 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5572 Insert('.', ts
, Length(ts
) + 1 - 3);
5573 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5575 g_Map_ResetFlag(FFlag
);
5576 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5578 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5579 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5580 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5585 if not sound_cap_flag
[a
].IsPlaying() then
5586 sound_cap_flag
[a
].Play();
5588 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5591 if g_Game_IsNet
then
5593 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5597 gFlags
[FFlag
].CaptureTime
:= 0;
5602 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5603 if (Flag
= FTeam
) and
5604 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5606 if Flag
= FLAG_RED
then
5607 s
:= _lc
[I_PLAYER_FLAG_RED
]
5609 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5611 evtype
:= FLAG_STATE_RETURNED
;
5612 gFlags
[Flag
].CaptureTime
:= 0;
5614 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5616 g_Map_ResetFlag(Flag
);
5617 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5619 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5620 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5621 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5626 if not sound_ret_flag
[a
].IsPlaying() then
5627 sound_ret_flag
[a
].Play();
5630 if g_Game_IsNet
then
5632 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5638 // Ïîäîáðàë ÷óæîé ôëàã:
5639 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5643 if Flag
= FLAG_RED
then
5644 s
:= _lc
[I_PLAYER_FLAG_RED
]
5646 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5648 evtype
:= FLAG_STATE_CAPTURED
;
5650 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5652 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5654 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5656 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5657 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5658 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5663 if not sound_get_flag
[a
].IsPlaying() then
5664 sound_get_flag
[a
].Play();
5667 if g_Game_IsNet
then
5669 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5675 procedure TPlayer
.SetFlag(Flag
: Byte);
5678 if FModel
<> nil then
5679 FModel
.SetFlag(FFlag
);
5682 function TPlayer
.DropFlag(Silent
: Boolean = True): Boolean;
5688 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5690 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5691 with gFlags
[FFlag
] do
5695 Direction
:= FDirection
;
5696 State
:= FLAG_STATE_DROPPED
;
5698 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5699 (FObj
.Vel
.Y
div 2)-2+Random(5));
5700 positionChanged(); // this updates spatial accelerators
5702 if FFlag
= FLAG_RED
then
5703 s
:= _lc
[I_PLAYER_FLAG_RED
]
5705 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5707 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5708 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5710 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5711 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5712 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5717 if (not Silent
) and (not sound_lost_flag
[a
].IsPlaying()) then
5718 sound_lost_flag
[a
].Play();
5720 if g_Game_IsNet
then
5721 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5727 procedure TPlayer
.GetSecret();
5732 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5734 Assert(Key
<= High(FKeys
));
5736 FKeys
[Key
].Pressed
:= True;
5737 FKeys
[Key
].Time
:= Time
;
5740 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5742 Result
:= FKeys
[K
].Pressed
;
5745 procedure TPlayer
.ReleaseKeys();
5749 for a
:= Low(FKeys
) to High(FKeys
) do
5751 FKeys
[a
].Pressed
:= False;
5756 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5760 function TPlayer
.firediry(): Integer;
5762 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5763 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5767 procedure TPlayer
.RememberState();
5771 FSavedState
.Health
:= FHealth
;
5772 FSavedState
.Armor
:= FArmor
;
5773 FSavedState
.Air
:= FAir
;
5774 FSavedState
.JetFuel
:= FJetFuel
;
5775 FSavedState
.CurrWeap
:= FCurrWeap
;
5776 FSavedState
.NextWeap
:= FNextWeap
;
5777 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5780 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5782 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5784 FSavedState
.Rulez
:= FRulez
;
5785 FSavedState
.WaitRecall
:= True;
5788 procedure TPlayer
.RecallState();
5792 if not FSavedState
.WaitRecall
then Exit
;
5794 FHealth
:= FSavedState
.Health
;
5795 FArmor
:= FSavedState
.Armor
;
5796 FAir
:= FSavedState
.Air
;
5797 FJetFuel
:= FSavedState
.JetFuel
;
5798 FCurrWeap
:= FSavedState
.CurrWeap
;
5799 FNextWeap
:= FSavedState
.NextWeap
;
5800 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5803 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5805 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5807 FRulez
:= FSavedState
.Rulez
;
5808 FSavedState
.WaitRecall
:= False;
5810 if gGameSettings
.GameType
= GT_SERVER
then
5811 MH_SEND_PlayerStats(FUID
);
5814 procedure TPlayer
.SaveState (st
: TStream
);
5820 utils
.writeSign(st
, 'PLYR');
5821 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
5823 utils
.writeBool(st
, FIamBot
);
5825 utils
.writeInt(st
, Word(FUID
));
5827 utils
.writeStr(st
, FName
);
5829 utils
.writeInt(st
, Byte(FTeam
));
5831 utils
.writeBool(st
, FAlive
);
5832 // Èçðàñõîäîâàë ëè âñå æèçíè
5833 utils
.writeBool(st
, FNoRespawn
);
5835 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
5836 utils
.writeInt(st
, Byte(b
));
5838 utils
.writeInt(st
, LongInt(FHealth
));
5840 utils
.writeInt(st
, Byte(FLives
));
5842 utils
.writeInt(st
, LongInt(FArmor
));
5844 utils
.writeInt(st
, LongInt(FAir
));
5846 utils
.writeInt(st
, LongInt(FJetFuel
));
5848 utils
.writeInt(st
, LongInt(FPain
));
5850 utils
.writeInt(st
, LongInt(FKills
));
5852 utils
.writeInt(st
, LongInt(FMonsterKills
));
5854 utils
.writeInt(st
, LongInt(FFrags
));
5856 utils
.writeInt(st
, Byte(FFragCombo
));
5857 // Âðåìÿ ïîñëåäíåãî ôðàãà
5858 utils
.writeInt(st
, LongWord(FLastFrag
));
5860 utils
.writeInt(st
, LongInt(FDeath
));
5862 utils
.writeInt(st
, Byte(FFlag
));
5864 utils
.writeInt(st
, LongInt(FSecrets
));
5866 utils
.writeInt(st
, Byte(FCurrWeap
));
5868 utils
.writeInt(st
, Word(FNextWeap
));
5870 utils
.writeInt(st
, Byte(FNextWeapDelay
));
5871 // Âðåìÿ çàðÿäêè BFG
5872 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
5874 utils
.writeInt(st
, LongInt(FDamageBuffer
));
5875 // Ïîñëåäíèé óäàðèâøèé
5876 utils
.writeInt(st
, Word(FLastSpawnerUID
));
5877 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
5878 utils
.writeInt(st
, Byte(FLastHit
));
5880 Obj_SaveState(st
, @FObj
);
5881 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
5882 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
5883 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
5884 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
5886 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
5887 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
5888 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
5890 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
5891 // Íàëè÷èå êðàñíîãî êëþ÷à
5892 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
5893 // Íàëè÷èå çåëåíîãî êëþ÷à
5894 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
5895 // Íàëè÷èå ñèíåãî êëþ÷à
5896 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
5898 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
5899 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
5900 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
5901 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
5902 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
5904 utils
.writeStr(st
, FModel
.Name
);
5906 utils
.writeInt(st
, Byte(FColor
.R
));
5907 utils
.writeInt(st
, Byte(FColor
.G
));
5908 utils
.writeInt(st
, Byte(FColor
.B
));
5912 procedure TPlayer
.LoadState (st
: TStream
);
5921 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
5922 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
5924 FIamBot
:= utils
.readBool(st
);
5926 FUID
:= utils
.readWord(st
);
5928 str
:= utils
.readStr(st
);
5929 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
5931 FTeam
:= utils
.readByte(st
);
5933 FAlive
:= utils
.readBool(st
);
5934 // Èçðàñõîäîâàë ëè âñå æèçíè
5935 FNoRespawn
:= utils
.readBool(st
);
5937 b
:= utils
.readByte(st
);
5938 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
5940 FHealth
:= utils
.readLongInt(st
);
5942 FLives
:= utils
.readByte(st
);
5944 FArmor
:= utils
.readLongInt(st
);
5946 FAir
:= utils
.readLongInt(st
);
5948 FJetFuel
:= utils
.readLongInt(st
);
5950 FPain
:= utils
.readLongInt(st
);
5952 FKills
:= utils
.readLongInt(st
);
5954 FMonsterKills
:= utils
.readLongInt(st
);
5956 FFrags
:= utils
.readLongInt(st
);
5958 FFragCombo
:= utils
.readByte(st
);
5959 // Âðåìÿ ïîñëåäíåãî ôðàãà
5960 FLastFrag
:= utils
.readLongWord(st
);
5962 FDeath
:= utils
.readLongInt(st
);
5964 FFlag
:= utils
.readByte(st
);
5966 FSecrets
:= utils
.readLongInt(st
);
5968 FCurrWeap
:= utils
.readByte(st
);
5970 FNextWeap
:= utils
.readWord(st
);
5972 FNextWeapDelay
:= utils
.readByte(st
);
5973 // Âðåìÿ çàðÿäêè BFG
5974 FBFGFireCounter
:= utils
.readSmallInt(st
);
5976 FDamageBuffer
:= utils
.readLongInt(st
);
5977 // Ïîñëåäíèé óäàðèâøèé
5978 FLastSpawnerUID
:= utils
.readWord(st
);
5979 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
5980 FLastHit
:= utils
.readByte(st
);
5982 Obj_LoadState(@FObj
, st
);
5983 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
5984 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
5985 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
5986 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
5988 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
5989 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
5990 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
5992 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
5993 // Íàëè÷èå êðàñíîãî êëþ÷à
5994 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
5995 // Íàëè÷èå çåëåíîãî êëþ÷à
5996 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
5997 // Íàëè÷èå ñèíåãî êëþ÷à
5998 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
6000 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
6001 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6002 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
6003 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6004 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
6006 str
:= utils
.readStr(st
);
6008 FColor
.R
:= utils
.readByte(st
);
6009 FColor
.G
:= utils
.readByte(st
);
6010 FColor
.B
:= utils
.readByte(st
);
6011 if (self
= gPlayer1
) then
6013 str
:= gPlayer1Settings
.Model
;
6014 FColor
:= gPlayer1Settings
.Color
;
6016 else if (self
= gPlayer2
) then
6018 str
:= gPlayer2Settings
.Model
;
6019 FColor
:= gPlayer2Settings
.Color
;
6021 // Îáíîâëÿåì ìîäåëü èãðîêà
6023 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
6024 FModel
.Color
:= TEAMCOLOR
[FTeam
]
6026 FModel
.Color
:= FColor
;
6030 procedure TPlayer
.AllRulez(Health
: Boolean);
6036 FHealth
:= PLAYER_HP_LIMIT
;
6037 FArmor
:= PLAYER_AP_LIMIT
;
6041 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
6042 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
6043 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6046 procedure TPlayer
.RestoreHealthArmor();
6048 FHealth
:= PLAYER_HP_LIMIT
;
6049 FArmor
:= PLAYER_AP_LIMIT
;
6052 procedure TPlayer
.FragCombo();
6056 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6058 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6060 if FFragCombo
< 5 then
6062 Param
:= FUID
or (FFragCombo
shl 16);
6063 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6064 (FComboEvnt
<= High(gDelayedEvents
)) and
6065 gDelayedEvents
[FComboEvnt
].Pending
and
6066 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6067 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6069 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6070 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6073 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6081 procedure TPlayer
.GiveItem(ItemType
: Byte);
6085 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6087 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6091 if FAir
< AIR_MAX
then
6098 if not (R_BERSERK
in FRulez
) then
6100 Include(FRulez
, R_BERSERK
);
6101 if FBFGFireCounter
< 1 then
6103 FCurrWeap
:= WEAPON_KASTET
;
6105 FModel
.SetWeapon(WEAPON_KASTET
);
6109 FBerserk
:= gTime
+30000;
6111 if FHealth
< PLAYER_HP_SOFT
then
6113 FHealth
:= PLAYER_HP_SOFT
;
6114 FBerserk
:= gTime
+30000;
6119 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6121 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6125 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6127 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6131 if FJetFuel
< JET_MAX
then
6133 FJetFuel
:= JET_MAX
;
6136 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6137 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6139 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6140 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6142 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6144 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6146 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6147 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6150 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6151 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6152 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6153 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6154 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6155 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6156 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6157 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6158 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6160 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6161 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6162 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6163 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6164 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6165 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6166 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6167 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6168 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6171 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6172 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6173 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6174 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6175 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6177 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6178 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6179 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6180 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6181 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6183 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6184 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6185 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6186 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6188 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6191 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6192 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6193 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6195 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6196 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6201 if g_Game_IsNet
and g_Game_IsServer
then
6202 MH_SEND_PlayerStats(FUID
);
6205 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6210 if (Random(5) = 1) and (Times
= 1) then
6213 if BodyInLiquid(0, 0) then
6215 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6216 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6217 if Random(2) = 0 then
6218 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6220 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6224 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6226 for i
:= 1 to Times
do
6228 Anim
:= TAnimation
.Create(id
, False, 3);
6230 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6231 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6237 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6242 if (Random(10) = 1) and (Times
= 1) then
6245 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6247 for i
:= 1 to Times
do
6249 Anim
:= TAnimation
.Create(id
, False, 3);
6251 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6252 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6258 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6260 FSawSound
.Pause(Enable
);
6261 FSawSoundIdle
.Pause(Enable
);
6262 FSawSoundHit
.Pause(Enable
);
6263 FSawSoundSelect
.Pause(Enable
);
6264 FJetSoundFly
.Pause(Enable
);
6265 FJetSoundOn
.Pause(Enable
);
6266 FJetSoundOff
.Pause(Enable
);
6271 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6276 FObj
.Rect
:= PLAYER_CORPSERECT
;
6277 FModelName
:= ModelName
;
6282 FState
:= CORPSE_STATE_MESS
;
6283 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6287 FState
:= CORPSE_STATE_NORMAL
;
6288 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6292 destructor TCorpse
.Destroy();
6299 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6301 procedure TCorpse
.positionChanged (); inline; begin end;
6303 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6305 if (dx
<> 0) or (dy
<> 0) then
6314 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6316 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6317 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6318 w
:= PLAYER_CORPSERECT
.Width
;
6319 h
:= PLAYER_CORPSERECT
.Height
;
6323 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6328 if FState
= CORPSE_STATE_REMOVEME
then
6331 FDamage
:= FDamage
+ Value
;
6333 if FDamage
> 150 then
6335 if FAnimation
<> nil then
6340 FState
:= CORPSE_STATE_REMOVEME
;
6342 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6343 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6344 FModelName
, FColor
);
6345 // Çâóê ìÿñà îò òðóïà:
6346 pm
:= g_PlayerModel_Get(FModelName
);
6347 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6351 if (gBodyKillEvent
<> -1)
6352 and gDelayedEvents
[gBodyKillEvent
].Pending
then
6353 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
6354 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, 0);
6359 Blood
:= g_PlayerModel_GetBlood(FModelName
);
6360 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6361 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6362 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6363 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6364 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6365 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
6369 procedure TCorpse
.Draw();
6371 if FState
= CORPSE_STATE_REMOVEME
then
6374 if FAnimation
<> nil then
6375 FAnimation
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6377 if FAnimationMask
<> nil then
6380 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6387 procedure TCorpse
.Update();
6391 if FState
= CORPSE_STATE_REMOVEME
then
6394 if gTime
mod (GAME_TICK
*2) <> 0 then
6396 g_Obj_Move(@FObj
, True, True, True);
6397 positionChanged(); // this updates spatial accelerators
6401 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6402 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6404 st
:= g_Obj_Move(@FObj
, True, True, True);
6405 positionChanged(); // this updates spatial accelerators
6407 if WordBool(st
and MOVE_FALLOUT
) then
6409 FState
:= CORPSE_STATE_REMOVEME
;
6413 if FAnimation
<> nil then
6414 FAnimation
.Update();
6415 if FAnimationMask
<> nil then
6416 FAnimationMask
.Update();
6420 procedure TCorpse
.SaveState (st
: TStream
);
6427 utils
.writeSign(st
, 'CORP');
6428 utils
.writeInt(st
, Byte(0));
6430 utils
.writeInt(st
, Byte(FState
));
6432 utils
.writeInt(st
, Byte(FDamage
));
6434 utils
.writeInt(st
, Byte(FColor
.R
));
6435 utils
.writeInt(st
, Byte(FColor
.G
));
6436 utils
.writeInt(st
, Byte(FColor
.B
));
6438 Obj_SaveState(st
, @FObj
);
6439 utils
.writeInt(st
, Word(FPlayerUID
));
6441 anim
:= (FAnimation
<> nil);
6442 utils
.writeBool(st
, anim
);
6443 // Åñëè åñòü - ñîõðàíÿåì
6444 if anim
then FAnimation
.SaveState(st
);
6445 // Åñòü ëè ìàñêà àíèìàöèè
6446 anim
:= (FAnimationMask
<> nil);
6447 utils
.writeBool(st
, anim
);
6448 // Åñëè åñòü - ñîõðàíÿåì
6449 if anim
then FAnimationMask
.SaveState(st
);
6453 procedure TCorpse
.LoadState (st
: TStream
);
6460 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6461 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6463 FState
:= utils
.readByte(st
);
6465 FDamage
:= utils
.readByte(st
);
6467 FColor
.R
:= utils
.readByte(st
);
6468 FColor
.G
:= utils
.readByte(st
);
6469 FColor
.B
:= utils
.readByte(st
);
6471 Obj_LoadState(@FObj
, st
);
6472 FPlayerUID
:= utils
.readWord(st
);
6474 anim
:= utils
.readBool(st
);
6475 // Åñëè åñòü - çàãðóæàåì
6478 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6479 FAnimation
.LoadState(st
);
6481 // Åñòü ëè ìàñêà àíèìàöèè
6482 anim
:= utils
.readBool(st
);
6483 // Åñëè åñòü - çàãðóæàåì
6486 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6487 FAnimationMask
.LoadState(st
);
6493 constructor TBot
.Create();
6500 FSpectator
:= False;
6507 for a
:= WP_FIRST
to WP_LAST
do
6509 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6510 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6511 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6515 destructor TBot
.Destroy();
6518 inherited Destroy();
6521 procedure TBot
.Draw();
6525 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6526 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6529 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6531 inherited Respawn(Silent
, Force
);
6534 FSelectedWeapon
:= FCurrWeap
;
6539 procedure TBot
.UpdateCombat();
6552 TTargetRecord
= array of TTarget
;
6554 function Compare(a
, b
: TTarget
): Integer;
6556 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6559 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6561 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6562 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6564 if a
.Dist
> b
.Dist
then // B áëèæå
6566 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6569 else // Ñòðàííî -> A
6574 a
, x1
, y1
, x2
, y2
: Integer;
6575 targets
: TTargetRecord
;
6577 Target
, BestTarget
: TTarget
;
6578 firew
, fireh
: Integer;
6582 vsPlayer
, vsMonster
, ok
: Boolean;
6585 function monsUpdate (mon
: TMonster
): Boolean;
6587 result
:= false; // don't stop
6588 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6590 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6592 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6593 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6595 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6596 if g_TraceVector(x1
, y1
, x2
, y2
) then
6598 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6599 SetLength(targets
, Length(targets
)+1);
6600 with targets
[High(targets
)] do
6607 Rect
:= mon
.Obj
.Rect
;
6608 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6609 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6610 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6619 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6620 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6622 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6623 if FCurrWeap
<> FSelectedWeapon
then
6626 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6627 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6629 RemoveAIFlag('NEEDFIRE');
6632 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6633 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6634 else PressKey(KEY_FIRE
);
6638 // Êîîðäèíàòû ñòâîëà:
6639 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6640 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6642 Target
.UID
:= FTargetUID
;
6645 if Target
.UID
<> 0 then
6646 begin // Öåëü åñòü - íàñòðàèâàåì
6647 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6650 tpla
:= g_Player_Get(Target
.UID
);
6654 if (@FObj
) <> nil then
6661 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6662 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6663 Target
.Rect
:= PLAYER_RECT
;
6664 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6665 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6666 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6667 Target
.IsPlayer
:= True;
6671 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6674 mon
:= g_Monsters_ByUID(Target
.UID
);
6677 Target
.X
:= mon
.Obj
.X
;
6678 Target
.Y
:= mon
.Obj
.Y
;
6680 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6681 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6682 Target
.Rect
:= mon
.Obj
.Rect
;
6683 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6684 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6685 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6686 Target
.IsPlayer
:= False;
6693 begin // Öåëè íåò - îáíóëÿåì
6698 Target
.Visible
:= False;
6699 Target
.Line
:= False;
6700 Target
.IsPlayer
:= False;
6705 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6706 if (not Target
.Line
) or (not Target
.Visible
) then
6710 for a
:= 0 to High(gPlayers
) do
6711 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6712 (gPlayers
[a
].FUID
<> FUID
) and
6713 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6714 (not gPlayers
[a
].NoTarget
) and
6715 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6717 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6718 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6721 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6722 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6724 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6725 if g_TraceVector(x1
, y1
, x2
, y2
) then
6727 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6728 SetLength(targets
, Length(targets
)+1);
6729 with targets
[High(targets
)] do
6731 UID
:= gPlayers
[a
].FUID
;
6732 X
:= gPlayers
[a
].FObj
.X
;
6733 Y
:= gPlayers
[a
].FObj
.Y
;
6736 Rect
:= PLAYER_RECT
;
6737 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6738 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6739 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6747 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6750 // Åñëè åñòü âîçìîæíûå öåëè:
6751 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6752 if targets
<> nil then
6754 // Âûáèðàåì íàèëó÷øóþ öåëü:
6755 BestTarget
:= targets
[0];
6756 if Length(targets
) > 1 then
6757 for a
:= 1 to High(targets
) do
6758 if Compare(BestTarget
, targets
[a
]) = 1 then
6759 BestTarget
:= targets
[a
];
6761 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6762 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6763 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6765 Target
:= BestTarget
;
6767 if (Healthy() = 3) or ((Healthy() = 2)) then
6768 begin // Åñëè çäîðîâû - äîãîíÿåì
6769 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6770 SetAIFlag('GORIGHT', '1');
6771 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6772 SetAIFlag('GOLEFT', '1');
6775 begin // Åñëè ïîáèòû - óáåãàåì
6776 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6777 SetAIFlag('GORIGHT', '1');
6778 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6779 SetAIFlag('GOLEFT', '1');
6782 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6783 SelectWeapon(Abs(x1
-Target
.cX
));
6788 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6789 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6790 if Target
.UID
<> 0 then
6792 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6793 Target
.Y
+ Target
.Rect
.Y
) then
6794 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6795 if (Healthy() = 3) or ((Healthy() = 2)) then
6796 begin // Åñëè çäîðîâû - äîãîíÿåì
6797 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6798 SetAIFlag('GORIGHT', '1');
6799 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6800 SetAIFlag('GOLEFT', '1');
6803 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6805 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6806 SetAIFlag('GORIGHT', '1');
6807 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6808 SetAIFlag('GOLEFT', '1');
6812 begin // Öåëü ïîêà íà "ýêðàíå"
6813 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6814 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6815 FLastVisible
:= gTime
;
6816 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6817 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6819 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6820 SetAIFlag('GORIGHT', '1');
6821 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6822 SetAIFlag('GOLEFT', '1');
6826 // Âûáèðàåì óãîë ââåðõ:
6827 if FDirection
= TDirection
.D_LEFT
then
6828 angle
:= ANGLE_LEFTUP
6830 angle
:= ANGLE_RIGHTUP
;
6832 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6833 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6835 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6836 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6837 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6838 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6839 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6840 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6841 begin // òî íóæíî ñòðåëÿòü ââåðõ
6842 SetAIFlag('NEEDFIRE', '1');
6843 SetAIFlag('NEEDSEEUP', '1');
6846 // Âûáèðàåì óãîë âíèç:
6847 if FDirection
= TDirection
.D_LEFT
then
6848 angle
:= ANGLE_LEFTDOWN
6850 angle
:= ANGLE_RIGHTDOWN
;
6852 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6853 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6855 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6856 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6857 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6858 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6859 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6860 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6861 begin // òî íóæíî ñòðåëÿòü âíèç
6862 SetAIFlag('NEEDFIRE', '1');
6863 SetAIFlag('NEEDSEEDOWN', '1');
6866 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6867 if Target
.Visible
and
6868 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6869 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6871 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6872 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
6873 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6874 begin // òî íóæíî ñòðåëÿòü âïåðåä
6875 SetAIFlag('NEEDFIRE', '1');
6876 SetAIFlag('NEEDSEEDOWN', '');
6877 SetAIFlag('NEEDSEEUP', '');
6879 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6880 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6881 if GetRnd(FDifficult
.CloseJump
) then
6882 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6883 if Abs(FObj
.X
-Target
.X
) < 128 then
6887 if Random(a
) = 0 then
6888 SetAIFlag('NEEDJUMP', '1');
6892 // Åñëè öåëü âñå åùå åñòü:
6893 if Target
.UID
<> 0 then
6894 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
6895 Target
.UID
:= 0 // òî çàáûòü öåëü
6896 else // Åñëè âèäåëè íåäàâíî
6897 begin // íî öåëü óáèëè
6898 if Target
.IsPlayer
then
6899 begin // Öåëü - èãðîê
6900 pla
:= g_Player_Get(Target
.UID
);
6901 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
6902 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6903 Target
.UID
:= 0; // òî çàáûòü öåëü
6906 begin // Öåëü - ìîíñòð
6907 mon
:= g_Monsters_ByUID(Target
.UID
);
6908 if (mon
= nil) or (not mon
.alive
) then
6909 Target
.UID
:= 0; // òî çàáûòü öåëü
6912 end; // if Target.UID <> 0
6914 FTargetUID
:= Target
.UID
;
6916 // Åñëè âîçìîæíûõ öåëåé íåò:
6917 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
6918 if targets
= nil then
6919 if GetAIFlag('ATTACKLEFT') <> '' then
6920 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
6921 RemoveAIFlag('ATTACKLEFT');
6923 SetAIFlag('NEEDJUMP', '1');
6925 if RunDirection() = TDirection
.D_RIGHT
then
6926 begin // Èäåì íå â òó ñòîðîíó
6927 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6928 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
6929 SetAIFlag('NEEDFIRE', '1');
6930 SetAIFlag('GOLEFT', '1');
6934 begin // Èäåì â íóæíóþ ñòîðîíó
6935 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6936 SetAIFlag('NEEDFIRE', '1');
6937 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6938 SetAIFlag('GORIGHT', '1');
6942 if GetAIFlag('ATTACKRIGHT') <> '' then
6943 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
6944 RemoveAIFlag('ATTACKRIGHT');
6946 SetAIFlag('NEEDJUMP', '1');
6948 if RunDirection() = TDirection
.D_LEFT
then
6949 begin // Èäåì íå â òó ñòîðîíó
6950 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6951 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
6952 SetAIFlag('NEEDFIRE', '1');
6953 SetAIFlag('GORIGHT', '1');
6958 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6959 SetAIFlag('NEEDFIRE', '1');
6960 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6961 SetAIFlag('GOLEFT', '1');
6965 //HACK! (does it belongs there?)
6966 RealizeCurrentWeapon();
6968 // Åñëè åñòü âîçìîæíûå öåëè:
6969 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
6970 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6971 for a
:= 0 to High(targets
) do
6973 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
6974 if GetRnd(FDifficult
.DiagFire
) then
6976 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
6977 if FDirection
= TDirection
.D_LEFT
then
6978 angle
:= ANGLE_LEFTUP
6980 angle
:= ANGLE_RIGHTUP
;
6982 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6983 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6985 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6986 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6987 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6988 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6989 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6991 SetAIFlag('NEEDFIRE', '1');
6992 SetAIFlag('NEEDSEEUP', '1');
6995 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
6996 if FDirection
= TDirection
.D_LEFT
then
6997 angle
:= ANGLE_LEFTDOWN
6999 angle
:= ANGLE_RIGHTDOWN
;
7001 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7002 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7004 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7005 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7006 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7007 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7008 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7010 SetAIFlag('NEEDFIRE', '1');
7011 SetAIFlag('NEEDSEEDOWN', '1');
7015 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7016 if targets
[a
].Line
and targets
[a
].Visible
and
7017 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
7018 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
7020 SetAIFlag('NEEDFIRE', '1');
7025 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7026 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
7027 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
7028 40+GetInterval(FDifficult
.Cover
, 40)) then
7029 SetAIFlag('NEEDJUMP', '1');
7031 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7032 ammo
:= GetAmmoByWeapon(FCurrWeap
);
7033 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
7034 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
7036 SetAIFlag('SELECTWEAPON', '1');
7038 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7039 if GetAIFlag('SELECTWEAPON') = '1' then
7042 RemoveAIFlag('SELECTWEAPON');
7046 procedure TBot
.Update();
7059 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7060 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7062 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7064 if g_debug_BotAIOff
= 3 then
7074 RealizeCurrentWeapon();
7081 procedure TBot
.ReleaseKey(Key
: Byte);
7090 function TBot
.KeyPressed(Key
: Word): Boolean;
7092 Result
:= FKeys
[Key
].Pressed
;
7095 function TBot
.GetAIFlag(aName
: String20
): String20
;
7101 aName
:= LowerCase(aName
);
7103 if FAIFlags
<> nil then
7104 for a
:= 0 to High(FAIFlags
) do
7105 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7107 Result
:= FAIFlags
[a
].Value
;
7112 procedure TBot
.RemoveAIFlag(aName
: String20
);
7116 if FAIFlags
= nil then Exit
;
7118 aName
:= LowerCase(aName
);
7120 for a
:= 0 to High(FAIFlags
) do
7121 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7123 if a
<> High(FAIFlags
) then
7124 for b
:= a
to High(FAIFlags
)-1 do
7125 FAIFlags
[b
] := FAIFlags
[b
+1];
7127 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7132 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7140 aName
:= LowerCase(aName
);
7142 if FAIFlags
<> nil then
7143 for a
:= 0 to High(FAIFlags
) do
7144 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7150 if ok
then FAIFlags
[a
].Value
:= fValue
7153 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7154 with FAIFlags
[High(FAIFlags
)] do
7162 procedure TBot
.UpdateMove
;
7164 procedure GoLeft(Time
: Word = 1);
7166 ReleaseKey(KEY_LEFT
);
7167 ReleaseKey(KEY_RIGHT
);
7168 PressKey(KEY_LEFT
, Time
);
7169 SetDirection(TDirection
.D_LEFT
);
7172 procedure GoRight(Time
: Word = 1);
7174 ReleaseKey(KEY_LEFT
);
7175 ReleaseKey(KEY_RIGHT
);
7176 PressKey(KEY_RIGHT
, Time
);
7177 SetDirection(TDirection
.D_RIGHT
);
7180 function Rnd(a
: Word): Boolean;
7182 Result
:= Random(a
) = 0;
7185 procedure Turn(Time
: Word = 1200);
7187 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7192 ReleaseKey(KEY_LEFT
);
7193 ReleaseKey(KEY_RIGHT
);
7196 function CanRunLeft(): Boolean;
7198 Result
:= not CollideLevel(-1, 0);
7201 function CanRunRight(): Boolean;
7203 Result
:= not CollideLevel(1, 0);
7206 function CanRun(): Boolean;
7208 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7211 procedure Jump(Time
: Word = 30);
7213 PressKey(KEY_JUMP
, Time
);
7216 function NearHole(): Boolean;
7220 { TODO 5 : Ëåñòíèöû }
7221 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7222 for x
:= 1 to PLAYER_RECT
.Width
do
7223 if (not StayOnStep(x
*sx
, 0)) and
7224 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7225 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7234 function BorderHole(): Boolean;
7238 { TODO 5 : Ëåñòíèöû }
7239 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7240 for x
:= 1 to PLAYER_RECT
.Width
do
7241 if (not StayOnStep(x
*sx
, 0)) and
7242 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7243 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7245 for xx
:= x
to x
+32 do
7246 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7256 function NearDeepHole(): Boolean;
7262 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7265 for x
:= 1 to PLAYER_RECT
.Width
do
7266 if (not StayOnStep(x
*sx
, 0)) and
7267 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7268 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7270 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7272 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7277 end else Result
:= False;
7280 function OverDeepHole(): Boolean;
7287 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7289 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7296 function OnGround(): Boolean;
7298 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7301 function OnLadder(): Boolean;
7303 Result
:= FullInStep(0, 0);
7306 function BelowLadder(): Boolean;
7308 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7309 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7310 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7311 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7314 function BelowLiftUp(): Boolean;
7316 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7317 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7318 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7319 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7322 function OnTopLift(): Boolean;
7324 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7327 function CanJumpOver(): Boolean;
7331 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7335 if not CollideLevel(sx
, 0) then Exit
;
7337 for y
:= 1 to BOT_MAXJUMP
do
7338 if CollideLevel(0, -y
) then Exit
else
7339 if not CollideLevel(sx
, -y
) then
7346 function CanJumpUp(Dist
: ShortInt): Boolean;
7353 if CollideLevel(Dist
, 0) then Exit
;
7356 for y
:= 0 to BOT_MAXJUMP
do
7357 if CollideLevel(Dist
, -y
) then
7366 for yy
:= y
+1 to BOT_MAXJUMP
do
7367 if not CollideLevel(Dist
, -yy
) then
7376 for y
:= 0 to BOT_MAXJUMP
do
7377 if CollideLevel(0, -y
) then
7385 if y
< yy
then Exit
;
7390 function IsSafeTrigger(): Boolean;
7395 if gTriggers
= nil then
7397 for a
:= 0 to High(gTriggers
) do
7398 if Collide(gTriggers
[a
].X
,
7401 gTriggers
[a
].Height
) and
7402 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7403 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7404 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7405 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7406 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7411 // Âîçìîæíî, íàæèìàåì êíîïêó:
7412 if Rnd(16) and IsSafeTrigger() then
7415 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7416 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7418 ReleaseKey(KEY_LEFT
);
7419 ReleaseKey(KEY_RIGHT
);
7423 // Èäåì âëåâî, åñëè íàäî áûëî:
7424 if GetAIFlag('GOLEFT') <> '' then
7426 RemoveAIFlag('GOLEFT');
7427 if CanRunLeft() then
7431 // Èäåì âïðàâî, åñëè íàäî áûëî:
7432 if GetAIFlag('GORIGHT') <> '' then
7434 RemoveAIFlag('GORIGHT');
7435 if CanRunRight() then
7439 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7440 if FObj
.X
< -32 then
7443 if FObj
.X
+32 > gMapInfo
.Width
then
7446 // Ïðûãàåì, åñëè íàäî áûëî:
7447 if GetAIFlag('NEEDJUMP') <> '' then
7450 RemoveAIFlag('NEEDJUMP');
7453 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7454 if GetAIFlag('NEEDSEEUP') <> '' then
7457 ReleaseKey(KEY_DOWN
);
7458 PressKey(KEY_UP
, 20);
7459 RemoveAIFlag('NEEDSEEUP');
7462 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7463 if GetAIFlag('NEEDSEEDOWN') <> '' then
7466 ReleaseKey(KEY_DOWN
);
7467 PressKey(KEY_DOWN
, 20);
7468 RemoveAIFlag('NEEDSEEDOWN');
7471 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7472 if GetAIFlag('GOINHOLE') <> '' then
7473 if not OnGround() then
7475 ReleaseKey(KEY_LEFT
);
7476 ReleaseKey(KEY_RIGHT
);
7477 RemoveAIFlag('GOINHOLE');
7478 SetAIFlag('FALLINHOLE', '1');
7481 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7482 if GetAIFlag('FALLINHOLE') <> '' then
7484 RemoveAIFlag('FALLINHOLE');
7486 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7487 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7488 if GetAIFlag('FALLINHOLE') = '' then
7489 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7495 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7497 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7501 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7502 if OnGround() and NearHole() then
7503 if NearDeepHole() then // Åñëè ýòî áåçäíà
7505 0..3: Turn(); // Áåæèì îáðàòíî
7506 4: Jump(); // Ïðûãàåì
7507 5: begin // Ïðûãàåì îáðàòíî
7512 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7513 if GetAIFlag('GOINHOLE') = '' then
7515 0: Turn(); // Íå íóæíî òóäà
7516 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7517 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7518 if BorderHole() then
7519 SetAIFlag('GOINHOLE', '1');
7522 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7523 if (not CanRun()) and OnGround() then
7525 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7526 if CanJumpOver() or OnLadder() then
7528 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7529 if Random(2) = 0 then
7531 if IsSafeTrigger() then
7537 // Îñòàëîñü ìàëî âîçäóõà:
7538 if FAir
< 36 * 2 then
7541 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7542 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7543 if BodyInAcid(0, 0) then
7547 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7549 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7550 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7553 {function TBot.NeedItem(Item: Byte): Byte;
7558 procedure TBot
.SelectWeapon(Dist
: Integer);
7562 function HaveAmmo(weapon
: Byte): Boolean;
7565 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7566 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7567 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7568 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7569 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7570 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7571 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7572 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7573 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7574 else Result
:= True;
7579 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7581 if Dist
> BOT_LONGDIST
then
7582 begin // Äàëüíèé áîé
7584 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7586 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7590 else //if Dist > BOT_UNSAFEDIST then
7591 begin // Áëèæíèé áîé
7593 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7595 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7602 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7604 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7610 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7612 Result
:= inherited PickItem(ItemType
, force
, remove
);
7614 if Result
then SetAIFlag('SELECTWEAPON', '1');
7617 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7619 Result
:= inherited Heal(value
, Soft
);
7622 function TBot
.Healthy(): Byte;
7624 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7625 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7626 else if (FHealth
> 50) then Result
:= 2
7627 else if (FHealth
> 20) then Result
:= 1
7631 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7633 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7634 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7637 procedure TBot
.OnDamage(Angle
: SmallInt);
7645 if (Angle
= 0) or (Angle
= 180) then
7648 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7649 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7651 pla
:= g_Player_Get(FLastSpawnerUID
);
7652 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7653 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7656 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7657 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7659 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7660 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7661 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7666 SetAIFlag('ATTACKLEFT', '1')
7668 SetAIFlag('ATTACKRIGHT', '1');
7672 function TBot
.RunDirection(): TDirection
;
7674 if Abs(Vel
.X
) >= 1 then
7676 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7678 Result
:= FDirection
;
7681 function TBot
.GetRnd(a
: Byte): Boolean;
7683 if a
= 0 then Result
:= False
7684 else if a
= 255 then Result
:= True
7685 else Result
:= Random(256) > 255-a
;
7688 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7690 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7694 procedure TDifficult
.save (st
: TStream
);
7696 utils
.writeInt(st
, Byte(DiagFire
));
7697 utils
.writeInt(st
, Byte(InvisFire
));
7698 utils
.writeInt(st
, Byte(DiagPrecision
));
7699 utils
.writeInt(st
, Byte(FlyPrecision
));
7700 utils
.writeInt(st
, Byte(Cover
));
7701 utils
.writeInt(st
, Byte(CloseJump
));
7702 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7703 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7706 procedure TDifficult
.load (st
: TStream
);
7708 DiagFire
:= utils
.readByte(st
);
7709 InvisFire
:= utils
.readByte(st
);
7710 DiagPrecision
:= utils
.readByte(st
);
7711 FlyPrecision
:= utils
.readByte(st
);
7712 Cover
:= utils
.readByte(st
);
7713 CloseJump
:= utils
.readByte(st
);
7714 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7715 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7719 procedure TBot
.SaveState (st
: TStream
);
7724 inherited SaveState(st
);
7725 utils
.writeSign(st
, 'BOT0');
7727 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7729 utils
.writeInt(st
, Word(FTargetUID
));
7730 // Âðåìÿ ïîòåðè öåëè
7731 utils
.writeInt(st
, LongWord(FLastVisible
));
7732 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7733 dw
:= Length(FAIFlags
);
7734 utils
.writeInt(st
, LongInt(dw
));
7736 for i
:= 0 to dw
-1 do
7738 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7739 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7741 // Íàñòðîéêè ñëîæíîñòè
7742 FDifficult
.save(st
);
7746 procedure TBot
.LoadState (st
: TStream
);
7751 inherited LoadState(st
);
7752 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7754 FSelectedWeapon
:= utils
.readByte(st
);
7756 FTargetUID
:= utils
.readWord(st
);
7757 // Âðåìÿ ïîòåðè öåëè
7758 FLastVisible
:= utils
.readLongWord(st
);
7759 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7760 dw
:= utils
.readLongInt(st
);
7761 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7762 SetLength(FAIFlags
, dw
);
7764 for i
:= 0 to dw
-1 do
7766 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7767 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7769 // Íàñòðîéêè ñëîæíîñòè
7770 FDifficult
.load(st
);
7775 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);