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(): 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 FJetSoundFly
.Free();
2271 FJetSoundOff
.Free();
2273 if FPunchAnim
<> nil then
2279 procedure TPlayer
.DrawIndicator();
2281 indX
, indY
: Integer;
2287 indX
:= FObj
.X
+FObj
.Rect
.X
;
2289 if g_Texture_Get('TEXTURE_PLAYER_INDICATOR', ID
) then
2291 e_GetTextureSize(ID
, @indW
, @indH
);
2292 e_Draw(ID
, indX
+ indW
div 2, indY
- indH
, 0, True, False);
2295 //e_TextureFontPrint(indX, indY, FName, gStdFont); // Shows player name overhead
2298 procedure TPlayer
.DrawBubble();
2300 bubX
, bubY
: Integer;
2303 Rw
, Gw
, Bw
: SmallInt;
2306 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= TDirection
.D_LEFT
, -4, 18);
2307 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2315 1: // simple textual non-bubble
2317 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2318 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2319 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2322 2: // advanced pixel-perfect bubble
2324 if FTeam
= TEAM_RED
then
2327 if FTeam
= TEAM_BLUE
then
2330 3: // colored bubble
2332 Rb
:= FModel
.Color
.R
;
2333 Gb
:= FModel
.Color
.G
;
2334 Bb
:= FModel
.Color
.B
;
2335 Rw
:= Min(Rb
* 2 + 64, 255);
2336 Gw
:= Min(Gb
* 2 + 64, 255);
2337 Bw
:= Min(Bb
* 2 + 64, 255);
2338 if (Abs(Rw
- Rb
) < 32)
2339 or (Abs(Gw
- Gb
) < 32)
2340 or (Abs(Bw
- Bb
) < 32) then
2342 Rb
:= Max(Rw
div 2 - 16, 0);
2343 Gb
:= Max(Gw
div 2 - 16, 0);
2344 Bb
:= Max(Bw
div 2 - 16, 0);
2347 4: // custom textured bubble
2349 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2350 if FDirection
= TDirection
.D_RIGHT
then
2351 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2353 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, TMirrorType
.Horizontal
);
2359 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2360 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2362 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2365 Dot
:= IfThen(FDirection
= TDirection
.D_LEFT
, 14, 5);
2366 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2367 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
);
2368 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
);
2369 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
);
2370 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
);
2374 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2375 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2376 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2379 procedure TPlayer
.Draw();
2384 Mirror
: TMirrorType
;
2388 if Direction
= TDirection
.D_RIGHT
then
2389 Mirror
:= TMirrorType
.None
2391 Mirror
:= TMirrorType
.Horizontal
;
2393 if FPunchAnim
<> nil then
2395 FPunchAnim
.Draw(FObj
.X
+IfThen(Direction
= TDirection
.D_LEFT
, 15-FObj
.Rect
.X
, FObj
.Rect
.X
-15),
2396 FObj
.Y
+FObj
.Rect
.Y
-11, Mirror
);
2397 if FPunchAnim
.played
then
2404 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2405 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2407 e_GetTextureSize(ID
, @w
, @h
);
2408 if FDirection
= TDirection
.D_LEFT
then
2409 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2410 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False)
2412 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2413 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False);
2416 if FMegaRulez
[MR_INVIS
] > gTime
then
2418 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2419 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2421 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2422 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2426 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 200)
2428 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2431 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 254);
2434 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2437 if g_debug_Frames
then
2439 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2441 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2442 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2446 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2448 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2449 if gAimLine
and alive
and
2450 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2455 procedure TPlayer
.DrawAim();
2456 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2461 {$IFDEF ENABLE_HOLMES}
2462 if isValidViewPort
and (self
= gPlayer1
) then
2464 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2468 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2469 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2471 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2475 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2480 wx
, wy
, xx
, yy
: Integer;
2484 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= TDirection
.D_LEFT
, 7, -7);
2485 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2494 1: begin // Chainsaw
2501 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2502 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2503 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2504 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2509 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2510 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2511 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2512 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2514 4: begin // Double Shotgun
2517 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2518 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2519 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2520 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2522 5: begin // Chaingun
2525 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2526 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2527 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2528 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2530 6: begin // Rocket Launcher
2533 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2534 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2535 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2536 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2538 7: begin // Plasmagun
2541 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2542 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2543 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2544 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2549 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2550 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2551 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2552 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2554 9: begin // Super Chaingun
2557 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2558 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2559 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2560 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2563 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2564 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2565 {$IF DEFINED(D2F_DEBUG)}
2566 drawCast(sz
, wx
, wy
, xx
, yy
);
2568 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2572 procedure TPlayer
.DrawGUI();
2575 X
, Y
, SY
, a
, p
, m
: Integer;
2579 stat
: TPlayerStatArray
;
2581 X
:= gPlayerScreenSize
.X
;
2582 SY
:= gPlayerScreenSize
.Y
;
2585 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2587 if gGameSettings
.GameMode
= GM_CTF
then
2591 if gGameSettings
.GameMode
= GM_CTF
then
2593 s
:= 'TEXTURE_PLAYER_REDFLAG';
2594 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2595 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2596 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2597 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2598 if g_Texture_Get(s
, ID
) then
2599 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2602 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2603 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2604 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2606 if gGameSettings
.GameMode
= GM_CTF
then
2608 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2609 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2610 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2611 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2612 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2613 if g_Texture_Get(s
, ID
) then
2614 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2617 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2618 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2619 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2622 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2623 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2626 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2627 e_Draw(ID
, X
+2, Y
, 0, True, False);
2629 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2633 s
:= IntToStr(Frags
);
2634 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2635 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2640 stat
:= g_Player_GetStats();
2645 for a
:= 0 to High(stat
) do
2646 if stat
[a
].Name
<> Name
then
2648 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2649 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2653 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2654 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2655 s
:= s
+IntToStr(Abs(Frags
-m
));
2657 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2658 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2661 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2663 s
:= IntToStr(Lives
);
2664 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2665 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2669 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2670 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2672 if R_BERSERK
in FRulez
then
2673 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2675 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2677 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2678 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2680 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2681 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2682 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2684 s
:= IntToStr(FArmor
);
2685 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2686 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2688 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2694 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2699 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2701 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2702 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2703 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2704 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2705 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2706 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2707 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2708 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2709 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2712 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2713 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2714 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2716 if R_KEY_RED
in FRulez
then
2717 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2719 if R_KEY_GREEN
in FRulez
then
2720 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2722 if R_KEY_BLUE
in FRulez
then
2723 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2725 if FJetFuel
> 0 then
2727 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2728 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2729 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2730 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2731 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2732 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2736 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2737 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2738 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2741 if gShowPing
and g_Game_IsClient
then
2743 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2744 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2750 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2751 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2752 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2755 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2756 s
:= _lc
[I_PLAYER_SPECT4
];
2757 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2758 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2759 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2765 procedure TPlayer
.DrawRulez();
2769 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2770 if FMegaRulez
[MR_INVUL
] >= gTime
then
2772 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2773 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2778 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2779 191, 191, 191, 0, TBlending
.Invert
);
2782 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2783 if FMegaRulez
[MR_SUIT
] >= gTime
then
2785 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2786 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2791 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2792 0, 96, 0, 200, TBlending
.None
);
2795 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2796 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2798 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2799 255, 0, 0, 200, TBlending
.None
);
2803 procedure TPlayer
.DrawPain();
2807 if FPain
= 0 then Exit
;
2811 if a
< 15 then h
:= 0
2812 else if a
< 35 then h
:= 1
2813 else if a
< 55 then h
:= 2
2814 else if a
< 75 then h
:= 3
2815 else if a
< 95 then h
:= 4
2818 //if a > 255 then a := 255;
2820 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2821 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2824 procedure TPlayer
.DrawPickup();
2828 if FPickup
= 0 then Exit
;
2832 if a
< 15 then h
:= 1
2833 else if a
< 35 then h
:= 2
2834 else if a
< 55 then h
:= 3
2835 else if a
< 75 then h
:= 4
2838 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2841 procedure TPlayer
.DoPunch();
2846 if FPunchAnim
<> nil then begin
2851 st
:= 'FRAMES_PUNCH';
2852 if R_BERSERK
in FRulez
then
2853 st
:= st
+ '_BERSERK';
2854 if FKeys
[KEY_UP
].Pressed
then
2856 else if FKeys
[KEY_DOWN
].Pressed
then
2858 g_Frames_Get(id
, st
);
2859 FPunchAnim
:= TAnimation
.Create(id
, False, 1);
2862 procedure TPlayer
.Fire();
2864 f
, DidFire
: Boolean;
2865 wx
, wy
, xd
, yd
: Integer;
2868 if g_Game_IsClient
then Exit
;
2869 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2870 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2878 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2883 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2884 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2885 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
2886 yd
:= wy
+firediry();
2892 if R_BERSERK
in FRulez
then
2894 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2895 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2896 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2899 locobj
.rect
.Width
:= 39;
2900 locobj
.rect
.Height
:= 52;
2901 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2902 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2903 locobj
.Accel
.X
:= xd
-wx
;
2904 locobj
.Accel
.y
:= yd
-wy
;
2906 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2907 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2909 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2911 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
2915 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2919 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2924 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2925 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2927 FSawSoundSelect
.Stop();
2929 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2931 else if not FSawSoundHit
.IsPlaying() then
2933 FSawSoundSelect
.Stop();
2934 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2937 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2943 if FAmmo
[A_BULLETS
] > 0 then
2945 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2946 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2947 Dec(FAmmo
[A_BULLETS
]);
2948 FFireAngle
:= FAngle
;
2951 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2952 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2956 if FAmmo
[A_SHELLS
] > 0 then
2958 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2959 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
2960 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2961 Dec(FAmmo
[A_SHELLS
]);
2962 FFireAngle
:= FAngle
;
2966 FShellType
:= SHELL_SHELL
;
2970 if FAmmo
[A_SHELLS
] >= 2 then
2972 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
2973 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2974 Dec(FAmmo
[A_SHELLS
], 2);
2975 FFireAngle
:= FAngle
;
2979 FShellType
:= SHELL_DBLSHELL
;
2983 if FAmmo
[A_BULLETS
] > 0 then
2985 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
2986 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
2987 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2988 Dec(FAmmo
[A_BULLETS
]);
2989 FFireAngle
:= FAngle
;
2992 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2993 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2996 WEAPON_ROCKETLAUNCHER
:
2997 if FAmmo
[A_ROCKETS
] > 0 then
2999 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
3000 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3001 Dec(FAmmo
[A_ROCKETS
]);
3002 FFireAngle
:= FAngle
;
3008 if FAmmo
[A_CELLS
] > 0 then
3010 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
3011 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3012 Dec(FAmmo
[A_CELLS
]);
3013 FFireAngle
:= FAngle
;
3019 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
3021 FBFGFireCounter
:= 17;
3022 if not FNoReload
then
3023 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
3024 Dec(FAmmo
[A_CELLS
], 40);
3028 WEAPON_SUPERPULEMET
:
3029 if FAmmo
[A_SHELLS
] > 0 then
3031 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3032 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
3033 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3034 Dec(FAmmo
[A_SHELLS
]);
3035 FFireAngle
:= FAngle
;
3038 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3039 GameVelX
, GameVelY
-2, SHELL_SHELL
);
3042 WEAPON_FLAMETHROWER
:
3043 if FAmmo
[A_FUEL
] > 0 then
3045 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
3046 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3048 FFireAngle
:= FAngle
;
3054 if g_Game_IsNet
then
3058 if FCurrWeap
<> WEAPON_BFG
then
3059 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
3061 if not FNoReload
then
3062 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
3065 MH_SEND_PlayerStats(FUID
);
3070 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
3071 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
3072 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
3075 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
3078 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
3079 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
3080 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
3081 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
3082 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
3087 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
3089 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
3090 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
3091 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
3094 procedure TPlayer
.JetpackOn
;
3098 FJetSoundOn
.SetPosition(0);
3099 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3103 procedure TPlayer
.JetpackOff
;
3107 FJetSoundOff
.SetPosition(0);
3108 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3111 procedure TPlayer
.CatchFire(Attacker
: Word);
3114 FFireAttacker
:= Attacker
;
3115 if g_Game_IsNet
and g_Game_IsServer
then
3116 MH_SEND_PlayerStats(FUID
);
3119 procedure TPlayer
.Jump();
3121 if gFly
or FJetpack
then
3123 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3124 if FObj
.Vel
.Y
> -VEL_FLY
then
3125 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3128 if FJetFuel
> 0 then
3130 if (FJetFuel
< 1) and g_Game_IsServer
then
3134 if g_Game_IsNet
then
3135 MH_SEND_PlayerStats(FUID
);
3141 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3143 FCanJetpack
:= False;
3145 // Ïðûãàåì èëè âñïëûâàåì:
3146 if (CollideLevel(0, 1) or
3147 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3148 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3149 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3151 FObj
.Vel
.Y
:= -VEL_JUMP
;
3152 FCanJetpack
:= False;
3156 if BodyInLiquid(0, 0) then
3157 FObj
.Vel
.Y
:= -VEL_SW
3158 else if (FJetFuel
> 0) and FCanJetpack
and
3159 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3163 if g_Game_IsNet
then
3164 MH_SEND_PlayerStats(FUID
);
3169 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3171 a
, i
, k
, ab
, ar
: Byte;
3175 srv
, netsrv
: Boolean;
3181 procedure PushItem(t
: Byte);
3185 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3186 it
:= g_Items_ByIdx(id
);
3187 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3189 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3190 (FObj
.Vel
.Y
div 2)-Random(9));
3191 it
.positionChanged(); // this updates spatial accelerators
3195 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3197 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3198 (FObj
.Vel
.Y
div 2)-Random(6));
3200 else // -3..+3; -3..0
3202 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3203 (FObj
.Vel
.Y
div 2)-Random(4));
3205 it
.positionChanged(); // this updates spatial accelerators
3208 if g_Game_IsNet
and g_Game_IsServer
then
3209 MH_SEND_ItemSpawn(True, id
);
3213 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3214 Srv
:= g_Game_IsServer
;
3215 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3216 if Srv
then FDeath
:= FDeath
+ 1;
3221 if not FPhysics
then
3227 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3229 if FLives
> 0 then FLives
:= FLives
- 1;
3230 if FLives
= 0 then FNoRespawn
:= True;
3233 // Íîìåð òèïà ñìåðòè:
3236 K_SIMPLEKILL
: a
:= 1;
3238 K_EXTRAHARDKILL
: a
:= 3;
3243 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3245 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3252 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3254 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3255 K_EXTRAHARDKILL
, K_FALLKILL
:
3256 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3259 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3263 K_HARDKILL
, K_EXTRAHARDKILL
:
3267 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3268 if (KillType
<> K_FALLKILL
) and (Srv
) then
3269 g_Monsters_killedp();
3271 if SpawnerUID
= FUID
then
3273 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3278 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3281 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3282 begin // Óáèò äðóãèì èãðîêîì
3283 KP
:= g_Player_Get(SpawnerUID
);
3284 if (KP
<> nil) and Srv
then
3286 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3287 if SameTeam(FUID
, SpawnerUID
) then
3297 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3298 Inc(gTeamStat
[KP
.Team
].Goals
,
3299 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3301 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3304 plr
:= g_Player_Get(SpawnerUID
);
3312 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3316 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3320 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3325 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3326 begin // Óáèò ìîíñòðîì
3327 mon
:= g_Monsters_ByUID(SpawnerUID
);
3331 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
3335 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3339 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3343 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3348 else // Îñîáûå òèïû ñìåðòè
3351 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3352 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3353 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3354 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3355 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3356 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3362 for a
:= WP_FIRST
to WP_LAST
do
3366 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3367 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3368 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3369 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3370 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3371 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3372 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3373 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3374 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3383 if R_ITEM_BACKPACK
in FRulez
then
3384 PushItem(ITEM_AMMO_BACKPACK
);
3386 // Âûáðîñ ðàêåòíîãî ðàíöà:
3387 if FJetFuel
> 0 then
3388 PushItem(ITEM_JETPACK
);
3391 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3393 if R_KEY_RED
in FRulez
then
3394 PushItem(ITEM_KEY_RED
);
3396 if R_KEY_GREEN
in FRulez
then
3397 PushItem(ITEM_KEY_GREEN
);
3399 if R_KEY_BLUE
in FRulez
then
3400 PushItem(ITEM_KEY_BLUE
);
3407 g_Player_CreateCorpse(Self
);
3409 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3410 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3416 for i
:= Low(gPlayers
) to High(gPlayers
) do
3418 if gPlayers
[i
] = nil then continue
;
3419 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3422 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3423 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3428 OldLR
:= gLMSRespawn
;
3429 if (gGameSettings
.GameMode
= GM_COOP
) then
3433 // everyone is dead, restart the map
3434 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3436 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3437 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3438 gLMSRespawnTime
:= gTime
+ 5000;
3440 else if (a
= 1) then
3442 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3443 if (gPlayers
[k
] = gPlayer1
) or
3444 (gPlayers
[k
] = gPlayer2
) then
3445 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3446 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3447 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3450 else if (gGameSettings
.GameMode
= GM_TDM
) then
3452 if (ab
= 0) and (ar
<> 0) then
3455 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3457 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3458 Inc(gTeamStat
[TEAM_RED
].Goals
);
3459 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3460 gLMSRespawnTime
:= gTime
+ 5000;
3462 else if (ar
= 0) and (ab
<> 0) then
3465 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3467 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3468 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3469 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3470 gLMSRespawnTime
:= gTime
+ 5000;
3472 else if (ar
= 0) and (ab
= 0) then
3475 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3477 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3478 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3479 gLMSRespawnTime
:= gTime
+ 5000;
3482 else if (gGameSettings
.GameMode
= GM_DM
) then
3486 if gPlayers
[k
] <> nil then
3489 // survivor is the winner
3490 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3492 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3495 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3496 gLMSRespawnTime
:= gTime
+ 5000;
3498 else if (a
= 0) then
3500 // everyone is dead, restart the map
3501 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3503 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3504 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3505 gLMSRespawnTime
:= gTime
+ 5000;
3508 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3510 if NetMode
= NET_SERVER
then
3511 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3513 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3519 MH_SEND_PlayerStats(FUID
);
3520 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3521 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3524 if srv
and FNoRespawn
then Spectate(True);
3525 FWantsInGame
:= True;
3528 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3530 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3531 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3534 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3536 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3537 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3540 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3542 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3543 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3544 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3545 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3546 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3547 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3548 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3549 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3552 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3554 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3555 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3556 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3557 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3560 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3562 if g_Game_IsClient
then Exit
;
3563 if Weapon
> High(FWeapon
) then Exit
;
3564 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3567 procedure TPlayer
.resetWeaponQueue ();
3570 FNextWeapDelay
:= 0;
3573 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3577 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3578 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 0);
3579 WEAPON_PISTOL
, WEAPON_CHAINGUN
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_BULLETS
] > 0);
3580 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3581 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3582 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3583 else result
:= (weapon
< length(FWeapon
));
3587 // return 255 for "no switch"
3588 function TPlayer
.getNextWeaponIndex (): Byte;
3591 wantThisWeapon
: array[0..64] of Boolean;
3592 wwc
: Integer = 0; //HACK!
3595 result
:= 255; // default result: "no switch"
3596 // had weapon cycling on previous frame? remove that flag
3597 if (FNextWeap
and $2000) <> 0 then
3599 FNextWeap
:= FNextWeap
and $1FFF;
3600 FNextWeapDelay
:= 0;
3602 // cycling has priority
3603 if (FNextWeap
and $C000) <> 0 then
3605 if (FNextWeap
and $8000) <> 0 then
3609 FNextWeap
:= FNextWeap
or $2000; // we need this
3610 if FNextWeapDelay
> 0 then
3611 exit
; // cooldown time
3613 for i
:= 0 to High(FWeapon
) do
3615 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3616 if FWeapon
[cwi
] then
3618 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d', [FCurrWeap, cwi]), MSG_WARNING);
3619 result
:= Byte(cwi
);
3620 FNextWeapDelay
:= WEAPON_DELAY
;
3628 for i
:= 0 to High(wantThisWeapon
) do
3629 wantThisWeapon
[i
] := false;
3630 for i
:= 0 to High(FWeapon
) do
3631 if (FNextWeap
and (1 shl i
)) <> 0 then
3633 wantThisWeapon
[i
] := true;
3636 // exclude currently selected weapon from the set
3637 wantThisWeapon
[FCurrWeap
] := false;
3638 // slow down alterations a little
3641 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3642 // more than one weapon requested, assume "alteration" and check alteration delay
3643 if FNextWeapDelay
> 0 then
3649 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3650 // but clear all counters if no weapon should be switched
3656 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3657 // try weapons in descending order
3658 for i
:= High(FWeapon
) downto 0 do
3660 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3665 FNextWeapDelay
:= WEAPON_DELAY
; // anyway, 'cause why not
3669 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3673 procedure TPlayer
.RealizeCurrentWeapon();
3674 function switchAllowed (): Boolean;
3679 if FBFGFireCounter
<> -1 then
3681 if FTime
[T_SWITCH
] > gTime
then
3683 for i
:= WP_FIRST
to WP_LAST
do
3684 if FReloading
[i
] > 0 then
3692 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3693 //FNextWeap := FNextWeap and $1FFF;
3694 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3696 if not switchAllowed
then
3698 //HACK for weapon cycling
3699 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3703 nw
:= getNextWeaponIndex();
3704 if nw
= 255 then exit
; // don't reset anything here
3705 if nw
> High(FWeapon
) then
3707 // don't forget to reset queue here!
3708 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3716 FTime
[T_SWITCH
] := gTime
+156;
3717 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3718 FModel
.SetWeapon(FCurrWeap
);
3719 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3723 procedure TPlayer
.NextWeapon();
3725 if g_Game_IsClient
then Exit
;
3729 procedure TPlayer
.PrevWeapon();
3731 if g_Game_IsClient
then Exit
;
3735 procedure TPlayer
.SetWeapon(W
: Byte);
3737 if FCurrWeap
<> W
then
3738 if W
= WEAPON_SAW
then
3739 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3742 FModel
.SetWeapon(CurrWeap
);
3746 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3748 function allowBerserkSwitching (): Boolean;
3750 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3752 if gBerserkAutoswitch
then exit
;
3753 if not conIsCheatsEnabled
then exit
;
3761 if g_Game_IsClient
then Exit
;
3763 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3764 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3769 if FHealth
< PLAYER_HP_SOFT
then
3771 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3775 if gFlash
= 2 then Inc(FPickup
, 5);
3779 if FHealth
< PLAYER_HP_SOFT
then
3781 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3785 if gFlash
= 2 then Inc(FPickup
, 5);
3789 if FArmor
< PLAYER_AP_SOFT
then
3791 FArmor
:= PLAYER_AP_SOFT
;
3794 if gFlash
= 2 then Inc(FPickup
, 5);
3798 if FArmor
< PLAYER_AP_LIMIT
then
3800 FArmor
:= PLAYER_AP_LIMIT
;
3803 if gFlash
= 2 then Inc(FPickup
, 5);
3807 if FHealth
< PLAYER_HP_LIMIT
then
3809 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3813 if gFlash
= 2 then Inc(FPickup
, 5);
3817 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3819 if FHealth
< PLAYER_HP_LIMIT
then
3820 FHealth
:= PLAYER_HP_LIMIT
;
3821 if FArmor
< PLAYER_AP_LIMIT
then
3822 FArmor
:= PLAYER_AP_LIMIT
;
3826 if gFlash
= 2 then Inc(FPickup
, 5);
3830 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3832 FWeapon
[WEAPON_SAW
] := True;
3834 if gFlash
= 2 then Inc(FPickup
, 5);
3835 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3838 ITEM_WEAPON_SHOTGUN1
:
3839 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3841 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3842 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3844 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3845 FWeapon
[WEAPON_SHOTGUN1
] := True;
3847 if gFlash
= 2 then Inc(FPickup
, 5);
3848 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3851 ITEM_WEAPON_SHOTGUN2
:
3852 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3854 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3856 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3857 FWeapon
[WEAPON_SHOTGUN2
] := True;
3859 if gFlash
= 2 then Inc(FPickup
, 5);
3860 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3863 ITEM_WEAPON_CHAINGUN
:
3864 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3866 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3868 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3869 FWeapon
[WEAPON_CHAINGUN
] := True;
3871 if gFlash
= 2 then Inc(FPickup
, 5);
3872 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3875 ITEM_WEAPON_ROCKETLAUNCHER
:
3876 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3878 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3880 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3881 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3883 if gFlash
= 2 then Inc(FPickup
, 5);
3884 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3888 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3890 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3892 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3893 FWeapon
[WEAPON_PLASMA
] := True;
3895 if gFlash
= 2 then Inc(FPickup
, 5);
3896 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3900 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3902 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3904 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3905 FWeapon
[WEAPON_BFG
] := True;
3907 if gFlash
= 2 then Inc(FPickup
, 5);
3908 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3911 ITEM_WEAPON_SUPERPULEMET
:
3912 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3914 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3916 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3917 FWeapon
[WEAPON_SUPERPULEMET
] := True;
3919 if gFlash
= 2 then Inc(FPickup
, 5);
3920 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3923 ITEM_WEAPON_FLAMETHROWER
:
3924 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
3926 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
3928 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3929 FWeapon
[WEAPON_FLAMETHROWER
] := True;
3931 if gFlash
= 2 then Inc(FPickup
, 5);
3932 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3936 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3938 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3941 if gFlash
= 2 then Inc(FPickup
, 5);
3944 ITEM_AMMO_BULLETS_BOX
:
3945 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3947 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3950 if gFlash
= 2 then Inc(FPickup
, 5);
3954 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3956 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3959 if gFlash
= 2 then Inc(FPickup
, 5);
3962 ITEM_AMMO_SHELLS_BOX
:
3963 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3965 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
3968 if gFlash
= 2 then Inc(FPickup
, 5);
3972 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3974 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3977 if gFlash
= 2 then Inc(FPickup
, 5);
3980 ITEM_AMMO_ROCKET_BOX
:
3981 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3983 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
3986 if gFlash
= 2 then Inc(FPickup
, 5);
3990 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3992 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3995 if gFlash
= 2 then Inc(FPickup
, 5);
3999 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4001 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4004 if gFlash
= 2 then Inc(FPickup
, 5);
4008 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4010 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4013 if gFlash
= 2 then Inc(FPickup
, 5);
4017 if not(R_ITEM_BACKPACK
in FRulez
) or
4018 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4019 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4020 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4021 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4022 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
4024 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4025 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4026 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4027 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4028 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4030 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4031 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4032 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4033 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4034 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4035 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4036 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4037 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4039 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
4042 if gFlash
= 2 then Inc(FPickup
, 5);
4046 if not(R_KEY_RED
in FRulez
) then
4048 Include(FRulez
, R_KEY_RED
);
4050 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4051 if gFlash
= 2 then Inc(FPickup
, 5);
4052 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4056 if not(R_KEY_GREEN
in FRulez
) then
4058 Include(FRulez
, R_KEY_GREEN
);
4060 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4061 if gFlash
= 2 then Inc(FPickup
, 5);
4062 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4066 if not(R_KEY_BLUE
in FRulez
) then
4068 Include(FRulez
, R_KEY_BLUE
);
4070 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4071 if gFlash
= 2 then Inc(FPickup
, 5);
4072 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4076 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4078 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4082 if gFlash
= 2 then Inc(FPickup
, 5);
4086 if FAir
< AIR_MAX
then
4091 if gFlash
= 2 then Inc(FPickup
, 5);
4096 if not (R_BERSERK
in FRulez
) then
4098 Include(FRulez
, R_BERSERK
);
4099 if allowBerserkSwitching
then
4101 FCurrWeap
:= WEAPON_KASTET
;
4103 FModel
.SetWeapon(WEAPON_KASTET
);
4108 if gFlash
= 2 then Inc(FPickup
, 5);
4110 FBerserk
:= gTime
+30000;
4115 if FHealth
< PLAYER_HP_SOFT
then
4117 FHealth
:= PLAYER_HP_SOFT
;
4118 FBerserk
:= gTime
+30000;
4126 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4128 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4131 if gFlash
= 2 then Inc(FPickup
, 5);
4135 if FHealth
< PLAYER_HP_LIMIT
then
4137 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4141 if gFlash
= 2 then Inc(FPickup
, 5);
4145 if FArmor
< PLAYER_AP_LIMIT
then
4147 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4150 if gFlash
= 2 then Inc(FPickup
, 5);
4154 if FJetFuel
< JET_MAX
then
4156 FJetFuel
:= JET_MAX
;
4159 if gFlash
= 2 then Inc(FPickup
, 5);
4163 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4165 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4168 if gFlash
= 2 then Inc(FPickup
, 5);
4173 procedure TPlayer
.Touch();
4177 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4180 // Áðîñèòü ôëàã òîâàðèùó:
4181 if gGameSettings
.GameMode
= GM_CTF
then
4186 procedure TPlayer
.Push(vx
, vy
: Integer);
4188 if (not FPhysics
) and FGhost
then
4190 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4191 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4192 if g_Game_IsNet
and g_Game_IsServer
then
4193 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4196 procedure TPlayer
.Reset(Force
: Boolean);
4202 FTime
[T_RESPAWN
] := 0;
4203 FTime
[T_FLAGCAP
] := 0;
4216 FSpectator
:= False;
4219 FSpectatePlayer
:= -1;
4220 FNoRespawn
:= False;
4222 FLives
:= gGameSettings
.MaxLives
;
4227 procedure TPlayer
.SoftReset();
4233 FBFGFireCounter
:= -1;
4241 SetAction(A_STAND
, True);
4244 function TPlayer
.GetRespawnPoint(): Byte;
4249 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4251 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4252 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4254 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4256 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4257 if Self
= gPlayer1
then
4258 c
:= RESPAWNPOINT_PLAYER1
4260 c
:= RESPAWNPOINT_PLAYER2
;
4261 if g_Map_GetPointCount(c
) > 0 then
4267 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4268 if Self
= gPlayer1
then
4269 c
:= RESPAWNPOINT_PLAYER2
4271 c
:= RESPAWNPOINT_PLAYER1
;
4272 if g_Map_GetPointCount(c
) > 0 then
4279 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4280 if Random(2) = 0 then
4281 c
:= RESPAWNPOINT_PLAYER1
4283 c
:= RESPAWNPOINT_PLAYER2
;
4284 if g_Map_GetPointCount(c
) > 0 then
4291 // Òî÷êà ëþáîé èç êîìàíä
4292 if Random(2) = 0 then
4293 c
:= RESPAWNPOINT_RED
4295 c
:= RESPAWNPOINT_BLUE
;
4296 if g_Map_GetPointCount(c
) > 0 then
4303 c
:= RESPAWNPOINT_DM
;
4304 if g_Map_GetPointCount(c
) > 0 then
4312 if gGameSettings
.GameMode
= GM_DM
then
4315 c
:= RESPAWNPOINT_DM
;
4316 if g_Map_GetPointCount(c
) > 0 then
4322 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4323 if Random(2) = 0 then
4324 c
:= RESPAWNPOINT_PLAYER1
4326 c
:= RESPAWNPOINT_PLAYER2
;
4327 if g_Map_GetPointCount(c
) > 0 then
4333 // Òî÷êà ëþáîé èç êîìàíä
4334 if Random(2) = 0 then
4335 c
:= RESPAWNPOINT_RED
4337 c
:= RESPAWNPOINT_BLUE
;
4338 if g_Map_GetPointCount(c
) > 0 then
4346 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4348 // Òî÷êà ñâîåé êîìàíäû
4349 c
:= RESPAWNPOINT_DM
;
4350 if FTeam
= TEAM_RED
then
4351 c
:= RESPAWNPOINT_RED
;
4352 if FTeam
= TEAM_BLUE
then
4353 c
:= RESPAWNPOINT_BLUE
;
4354 if g_Map_GetPointCount(c
) > 0 then
4361 c
:= RESPAWNPOINT_DM
;
4362 if g_Map_GetPointCount(c
) > 0 then
4368 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4369 if Random(2) = 0 then
4370 c
:= RESPAWNPOINT_PLAYER1
4372 c
:= RESPAWNPOINT_PLAYER2
;
4373 if g_Map_GetPointCount(c
) > 0 then
4379 // Òî÷êà äðóãîé êîìàíäû
4380 c
:= RESPAWNPOINT_DM
;
4381 if FTeam
= TEAM_RED
then
4382 c
:= RESPAWNPOINT_BLUE
;
4383 if FTeam
= TEAM_BLUE
then
4384 c
:= RESPAWNPOINT_RED
;
4385 if g_Map_GetPointCount(c
) > 0 then
4393 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4395 RespawnPoint
: TRespawnPoint
;
4401 FBFGFireCounter
:= -1;
4406 if not g_Game_IsServer
then
4410 FWantsInGame
:= True;
4411 FJustTeleported
:= True;
4414 FTime
[T_RESPAWN
] := 0;
4418 // if server changes MaxLives we gotta be ready
4419 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4421 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4422 if FTime
[T_RESPAWN
] > gTime
then
4425 // Ïðîñðàë âñå æèçíè:
4428 if not FSpectator
then Spectate(True);
4429 FWantsInGame
:= True;
4433 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4434 begin // "Ñâîÿ èãðà"
4435 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4436 FRulez
:= FRulez
-[R_BERSERK
];
4438 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4440 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4441 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4444 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4445 c
:= GetRespawnPoint();
4450 // Âîñêðåøåíèå áåç îðóæèÿ:
4453 FHealth
:= PLAYER_HP_SOFT
;
4459 for a
:= WP_FIRST
to WP_LAST
do
4461 FWeapon
[a
] := False;
4465 FWeapon
[WEAPON_PISTOL
] := True;
4466 FWeapon
[WEAPON_KASTET
] := True;
4467 FCurrWeap
:= WEAPON_PISTOL
;
4470 FModel
.SetWeapon(FCurrWeap
);
4472 for b
:= A_BULLETS
to A_HIGH
do
4475 FAmmo
[A_BULLETS
] := 50;
4477 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4478 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4479 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4480 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4481 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4483 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4484 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4489 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4490 if not g_Map_GetPoint(c
, RespawnPoint
) then
4492 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4496 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4497 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4498 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4504 FDirection
:= RespawnPoint
.Direction
;
4505 if FDirection
= TDirection
.D_LEFT
then
4510 SetAction(A_STAND
, True);
4511 FModel
.Direction
:= FDirection
;
4513 for a
:= Low(FTime
) to High(FTime
) do
4516 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4521 FCanJetpack
:= False;
4526 // Àíèìàöèÿ âîçðîæäåíèÿ:
4527 if (not gLoadGameMode
) and (not Silent
) then
4528 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4530 Anim
:= TAnimation
.Create(ID
, False, 3);
4531 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4532 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4536 FSpectator
:= False;
4539 FSpectatePlayer
:= -1;
4542 if (gPlayer1
= nil) and (gLMSPID1
= FUID
) then
4544 if (gPlayer2
= nil) and (gLMSPID2
= FUID
) then
4547 if g_Game_IsNet
then
4549 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4550 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4552 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4553 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4558 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4561 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4562 else if (not NoMove
) then
4564 GameX
:= gMapInfo
.Width
div 2;
4565 GameY
:= gMapInfo
.Height
div 2;
4574 FWantsInGame
:= False;
4579 if Self
= gPlayer1
then
4584 if Self
= gPlayer2
then
4591 if g_Game_IsNet
then
4592 MH_SEND_PlayerStats(FUID
);
4595 procedure TPlayer
.SwitchNoClip
;
4599 FGhost
:= not FGhost
;
4600 FPhysics
:= not FGhost
;
4612 procedure TPlayer
.Run(Direction
: TDirection
);
4616 if MAX_RUNVEL
> 8 then
4620 if Direction
= TDirection
.D_LEFT
then
4622 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4623 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4626 if FObj
.Vel
.X
< MAX_RUNVEL
then
4627 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4629 // Âîçìîæíî, ïèíàåì êóñêè:
4630 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4632 b
:= Abs(FObj
.Vel
.X
);
4633 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4634 for a
:= 0 to High(gGibs
) do
4636 if gGibs
[a
].alive
and
4637 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4638 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4641 if FObj
.Vel
.X
< 0 then
4643 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4647 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4649 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4657 procedure TPlayer
.SeeDown();
4659 SetAction(A_SEEDOWN
);
4661 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4663 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4666 procedure TPlayer
.SeeUp();
4670 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4672 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4675 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4683 A_ATTACK
: Prior
:= 2;
4684 A_SEEUP
: Prior
:= 1;
4685 A_SEEDOWN
: Prior
:= 1;
4686 A_ATTACKUP
: Prior
:= 2;
4687 A_ATTACKDOWN
: Prior
:= 2;
4692 if (Prior
> FActionPrior
) or Force
then
4693 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4695 FActionPrior
:= Prior
;
4696 FActionAnim
:= Action
;
4697 FActionForce
:= Force
;
4698 FActionChanged
:= True;
4701 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4704 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4706 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4707 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4708 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4709 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4712 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4719 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4721 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4722 if g_Game_IsServer
and g_Game_IsNet
then
4723 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4727 FJustTeleported
:= True;
4732 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4734 Anim
:= TAnimation
.Create(ID
, False, 3);
4737 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4738 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4739 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4740 if g_Game_IsServer
and g_Game_IsNet
then
4741 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4742 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4746 FObj
.X
:= X
-PLAYER_RECT
.X
;
4747 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4748 if FAlive
and FGhost
then
4754 if not g_Game_IsNet
then
4758 SetDirection(TDirection
.D_LEFT
);
4764 SetDirection(TDirection
.D_RIGHT
);
4770 if FDirection
= TDirection
.D_RIGHT
then
4772 SetDirection(TDirection
.D_LEFT
);
4777 SetDirection(TDirection
.D_RIGHT
);
4783 if not silent
and (Anim
<> nil) then
4785 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4786 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4789 if g_Game_IsServer
and g_Game_IsNet
then
4790 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4791 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4798 function nonz(a
: Single): Single;
4806 function TPlayer
.followCorpse(): Boolean;
4811 if FAlive
or FSpectator
then
4813 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
4815 for i
:= 0 to High(gCorpses
) do
4816 if gCorpses
[i
] <> nil then
4817 if gCorpses
[i
].FPlayerUID
= FUID
then
4820 FObj
.X
:= gCorpses
[i
].FObj
.X
;
4821 FObj
.Y
:= gCorpses
[i
].FObj
.Y
;
4822 FObj
.Vel
.X
:= gCorpses
[i
].FObj
.Vel
.X
;
4823 FObj
.Vel
.Y
:= gCorpses
[i
].FObj
.Vel
.Y
;
4824 FObj
.Accel
.X
:= gCorpses
[i
].FObj
.Accel
.X
;
4825 FObj
.Accel
.Y
:= gCorpses
[i
].FObj
.Accel
.Y
;
4830 procedure TPlayer
.Update();
4833 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4834 blockmon
, headwater
, dospawn
: Boolean;
4839 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4840 AnyServer
:= g_Game_IsServer
;
4842 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4843 DoLerp(NetInterpLevel
+ 1)
4849 if FClientID
>= 0 then
4851 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4852 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4853 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4862 if FAlive
and (FPunchAnim
<> nil) then
4863 FPunchAnim
.Update();
4865 if FAlive
and (gFly
or FJetpack
) then
4868 if FDirection
= TDirection
.D_LEFT
then
4873 if FAlive
and (not FGhost
) then
4875 if FKeys
[KEY_UP
].Pressed
then
4877 if FKeys
[KEY_DOWN
].Pressed
then
4881 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4884 i
:= g_basic
.Sign(FIncCam
);
4885 FIncCam
:= Abs(FIncCam
);
4886 DecMin(FIncCam
, 5, 0);
4887 FIncCam
:= FIncCam
*i
;
4890 // no need to do that each second frame, weapon queue will take care of it
4891 if FAlive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4892 if FAlive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4894 if gTime
mod (GAME_TICK
*2) <> 0 then
4896 if (FObj
.Vel
.X
= 0) and FAlive
then
4898 if FKeys
[KEY_LEFT
].Pressed
then
4899 Run(TDirection
.D_LEFT
);
4900 if FKeys
[KEY_RIGHT
].Pressed
then
4901 Run(TDirection
.D_RIGHT
);
4906 if not followCorpse() then
4907 g_Obj_Move(@FObj
, True, True, True);
4908 positionChanged(); // this updates spatial accelerators
4914 FActionChanged
:= False;
4918 // Let alive player do some actions
4919 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
4920 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
4921 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
4922 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
4923 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
4924 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
4925 if FKeys
[KEY_JUMP
].Pressed
then Jump()
4928 if AnyServer
and FJetpack
then
4932 if NetServer
then MH_SEND_PlayerStats(FUID
);
4934 FCanJetpack
:= True;
4941 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
4943 if FKeys
[k
].Pressed
then
4951 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4954 if (FTime
[T_RESPAWN
] <= gTime
) and
4955 gGameOn
and (not FAlive
) then
4957 if (g_Player_GetCount() > 1) then
4961 gExit
:= EXIT_RESTART
;
4966 // Dead spectator actions
4969 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
4970 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
4974 if (FSpectatePlayer
>= High(gPlayers
)) then
4975 FSpectatePlayer
:= -1
4979 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
4980 if gPlayers
[I
] <> nil then
4981 if gPlayers
[I
].alive
then
4982 if gPlayers
[I
].UID
<> FUID
then
4984 FSpectatePlayer
:= I
;
4989 if not SetSpect
then FSpectatePlayer
:= -1;
5000 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5002 FYTo
:= FObj
.Y
- 32;
5003 FSpectatePlayer
:= -1;
5005 if FKeys
[KEY_DOWN
].Pressed
then
5007 FYTo
:= FObj
.Y
+ 32;
5008 FSpectatePlayer
:= -1;
5010 if FKeys
[KEY_LEFT
].Pressed
then
5012 FXTo
:= FObj
.X
- 32;
5013 FSpectatePlayer
:= -1;
5015 if FKeys
[KEY_RIGHT
].Pressed
then
5017 FXTo
:= FObj
.X
+ 32;
5018 FSpectatePlayer
:= -1;
5021 if (FXTo
< -64) then
5023 else if (FXTo
> gMapInfo
.Width
+ 32) then
5024 FXTo
:= gMapInfo
.Width
+ 32;
5025 if (FYTo
< -72) then
5027 else if (FYTo
> gMapInfo
.Height
+ 32) then
5028 FYTo
:= gMapInfo
.Height
+ 32;
5033 if not followCorpse() then
5034 g_Obj_Move(@FObj
, True, True, True);
5035 positionChanged(); // this updates spatial accelerators
5042 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5043 if gPlayers
[FSpectatePlayer
] <> nil then
5044 if gPlayers
[FSpectatePlayer
].alive
then
5046 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
5047 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
5051 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5052 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5053 PANEL_BLOCKMON
, True);
5054 headwater
:= HeadInLiquid(0, 0);
5056 // Ñîïðîòèâëåíèå âîçäóõà:
5057 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5058 if FObj
.Vel
.X
<> 0 then
5059 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5061 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5062 DecMin(FPain
, 5, 0);
5063 DecMin(FPickup
, 1, 0);
5065 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5067 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5068 FMegaRulez
[MR_SUIT
] := 0;
5069 FMegaRulez
[MR_INVUL
] := 0;
5070 FMegaRulez
[MR_INVIS
] := 0;
5071 Kill(K_FALLKILL
, 0, HIT_FALL
);
5078 if FCurrWeap
= WEAPON_SAW
then
5079 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5080 FSawSoundSelect
.IsPlaying()) then
5081 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5084 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5085 (not FJetSoundOff
.IsPlaying()) then
5087 FJetSoundFly
.SetPosition(0);
5088 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5091 for b
:= WP_FIRST
to WP_LAST
do
5092 if FReloading
[b
] > 0 then
5098 if FShellTimer
> -1 then
5099 if FShellTimer
= 0 then
5101 if FShellType
= SHELL_SHELL
then
5102 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5103 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5104 else if FShellType
= SHELL_DBLSHELL
then
5106 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5107 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5108 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5109 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5112 end else Dec(FShellTimer
);
5114 if (FBFGFireCounter
> -1) then
5115 if FBFGFireCounter
= 0 then
5119 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5120 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5121 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5122 yd
:= wy
+firediry();
5123 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5124 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5125 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5126 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5127 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5130 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5131 FBFGFireCounter
:= -1;
5134 FBFGFireCounter
:= 0
5136 Dec(FBFGFireCounter
);
5138 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5140 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5142 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5145 if (headwater
or blockmon
) then
5151 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5154 else if (FAir
mod 31 = 0) and not blockmon
then
5156 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5157 if Random(2) = 0 then
5158 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5160 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5162 end else if FAir
< AIR_DEF
then
5165 if FFireTime
> 0 then
5167 if BodyInLiquid(0, 0) then
5172 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5174 if FMegaRulez
[MR_SUIT
] = gTime
then
5181 if FFirePainTime
<= 0 then
5183 if g_Game_IsServer
then
5184 Damage(5, FFireAttacker
, 0, 0, HIT_FLAME
);
5185 FFirePainTime
:= 18;
5187 FFirePainTime
:= FFirePainTime
- 1;
5188 FFireTime
:= FFireTime
- 1;
5189 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5190 MH_SEND_PlayerStats(FUID
);
5194 if FDamageBuffer
> 0 then
5196 if FDamageBuffer
>= 9 then
5200 if FDamageBuffer
< 30 then i
:= 9
5201 else if FDamageBuffer
< 100 then i
:= 18
5205 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5206 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5207 FHealth
:= FHealth
-ii
;
5210 FHealth
:= FHealth
+FArmor
;
5215 if FHealth
<= 0 then
5216 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5217 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5218 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5222 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5223 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5224 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5225 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5232 end; // if FAlive then ...
5234 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5236 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5237 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5238 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5239 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5241 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5242 then SetAction(A_STAND
, True);
5244 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5246 for b
:= Low(FKeys
) to High(FKeys
) do
5247 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5251 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5253 x
:= FObj
.X
+PLAYER_RECT
.X
;
5254 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5255 w
:= PLAYER_RECT
.Width
;
5256 h
:= PLAYER_RECT
.Height
;
5260 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5262 if (dx
<> 0) or (dy
<> 0) then
5271 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5273 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5274 FObj
.Y
+PLAYER_RECT
.Y
,
5281 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5283 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5284 FObj
.Y
+PLAYER_RECT
.Y
,
5288 Panel
.Width
, Panel
.Height
);
5291 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5293 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5294 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5295 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5296 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5299 function g_Player_ValidName(Name
: string): Boolean;
5305 if gPlayers
= nil then Exit
;
5307 for a
:= 0 to High(gPlayers
) do
5308 if gPlayers
[a
] <> nil then
5309 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5316 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5320 d
:= FModel
.Direction
;
5322 FModel
.Direction
:= Direction
;
5323 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5325 FDirection
:= Direction
;
5328 function TPlayer
.GetKeys(): Byte;
5332 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5333 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5334 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5336 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5337 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5340 procedure TPlayer
.Use();
5344 if FTime
[T_USE
] > gTime
then Exit
;
5346 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5347 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5349 for a
:= 0 to High(gPlayers
) do
5350 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5351 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5352 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5353 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5355 gPlayers
[a
].Touch();
5356 if g_Game_IsNet
and g_Game_IsServer
then
5357 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5360 FTime
[T_USE
] := gTime
+120;
5363 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5367 WX
, WY
, XD
, YD
: Integer;
5379 if R_BERSERK
in FRulez
then
5381 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5382 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5383 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5386 locobj
.rect
.Width
:= 39;
5387 locobj
.rect
.Height
:= 52;
5388 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5389 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5390 locobj
.Accel
.X
:= xd
-wx
;
5391 locobj
.Accel
.y
:= yd
-wy
;
5393 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5394 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5396 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5400 FPain
:= min(FPain
+ 25, 50);
5402 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5407 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5408 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5410 FSawSoundSelect
.Stop();
5412 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5414 else if not FSawSoundHit
.IsPlaying() then
5416 FSawSoundSelect
.Stop();
5417 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5424 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5425 FFireAngle
:= FAngle
;
5427 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5428 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5433 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5434 FFireAngle
:= FAngle
;
5437 FShellType
:= SHELL_SHELL
;
5442 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5443 FFireAngle
:= FAngle
;
5446 FShellType
:= SHELL_DBLSHELL
;
5451 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5452 FFireAngle
:= FAngle
;
5454 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5455 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5458 WEAPON_ROCKETLAUNCHER
:
5460 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5461 FFireAngle
:= FAngle
;
5467 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5468 FFireAngle
:= FAngle
;
5474 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5475 FFireAngle
:= FAngle
;
5479 WEAPON_SUPERPULEMET
:
5481 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5482 FFireAngle
:= FAngle
;
5484 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5485 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5488 WEAPON_FLAMETHROWER
:
5490 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5491 FFireAngle
:= FAngle
;
5498 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5499 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5500 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5503 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5505 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5506 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5509 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5513 if NetInterpLevel
< 1 then
5523 AX
:= Abs(FXTo
- FObj
.X
);
5524 AY
:= Abs(FYTo
- FObj
.Y
);
5525 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5527 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5532 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5534 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5535 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5536 PANEL_LIFTUP
, False) then Result
:= -1
5538 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5539 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5540 PANEL_LIFTDOWN
, False) then Result
:= 1
5544 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5551 if Flag
= FLAG_NONE
then
5554 if not g_Game_IsServer
then Exit
;
5556 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5557 if (Flag
= FTeam
) and
5558 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5559 (FFlag
<> FLAG_NONE
) then
5561 if FFlag
= FLAG_RED
then
5562 s
:= _lc
[I_PLAYER_FLAG_RED
]
5564 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5566 evtype
:= FLAG_STATE_SCORED
;
5568 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5569 Insert('.', ts
, Length(ts
) + 1 - 3);
5570 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5572 g_Map_ResetFlag(FFlag
);
5573 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5575 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5578 if g_Game_IsNet
then
5580 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5584 gFlags
[FFlag
].CaptureTime
:= 0;
5589 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5590 if (Flag
= FTeam
) and
5591 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5593 if Flag
= FLAG_RED
then
5594 s
:= _lc
[I_PLAYER_FLAG_RED
]
5596 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5598 evtype
:= FLAG_STATE_RETURNED
;
5599 gFlags
[Flag
].CaptureTime
:= 0;
5601 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5603 g_Map_ResetFlag(Flag
);
5604 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5607 if g_Game_IsNet
then
5609 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5615 // Ïîäîáðàë ÷óæîé ôëàã:
5616 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5620 if Flag
= FLAG_RED
then
5621 s
:= _lc
[I_PLAYER_FLAG_RED
]
5623 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5625 evtype
:= FLAG_STATE_CAPTURED
;
5627 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5629 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5631 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5634 if g_Game_IsNet
then
5636 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5642 procedure TPlayer
.SetFlag(Flag
: Byte);
5645 if FModel
<> nil then
5646 FModel
.SetFlag(FFlag
);
5649 function TPlayer
.DropFlag(): Boolean;
5654 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5656 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5657 with gFlags
[FFlag
] do
5661 Direction
:= FDirection
;
5662 State
:= FLAG_STATE_DROPPED
;
5664 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5665 (FObj
.Vel
.Y
div 2)-2+Random(5));
5666 positionChanged(); // this updates spatial accelerators
5668 if FFlag
= FLAG_RED
then
5669 s
:= _lc
[I_PLAYER_FLAG_RED
]
5671 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5673 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5674 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5676 if g_Game_IsNet
then
5677 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5683 procedure TPlayer
.GetSecret();
5688 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5690 Assert(Key
<= High(FKeys
));
5692 FKeys
[Key
].Pressed
:= True;
5693 FKeys
[Key
].Time
:= Time
;
5696 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5698 Result
:= FKeys
[K
].Pressed
;
5701 procedure TPlayer
.ReleaseKeys();
5705 for a
:= Low(FKeys
) to High(FKeys
) do
5707 FKeys
[a
].Pressed
:= False;
5712 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5716 function TPlayer
.firediry(): Integer;
5718 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5719 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5723 procedure TPlayer
.RememberState();
5727 FSavedState
.Health
:= FHealth
;
5728 FSavedState
.Armor
:= FArmor
;
5729 FSavedState
.Air
:= FAir
;
5730 FSavedState
.JetFuel
:= FJetFuel
;
5731 FSavedState
.CurrWeap
:= FCurrWeap
;
5732 FSavedState
.NextWeap
:= FNextWeap
;
5733 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5736 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5738 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5740 FSavedState
.Rulez
:= FRulez
;
5741 FSavedState
.WaitRecall
:= True;
5744 procedure TPlayer
.RecallState();
5748 if not FSavedState
.WaitRecall
then Exit
;
5750 FHealth
:= FSavedState
.Health
;
5751 FArmor
:= FSavedState
.Armor
;
5752 FAir
:= FSavedState
.Air
;
5753 FJetFuel
:= FSavedState
.JetFuel
;
5754 FCurrWeap
:= FSavedState
.CurrWeap
;
5755 FNextWeap
:= FSavedState
.NextWeap
;
5756 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5759 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5761 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5763 FRulez
:= FSavedState
.Rulez
;
5764 FSavedState
.WaitRecall
:= False;
5766 if gGameSettings
.GameType
= GT_SERVER
then
5767 MH_SEND_PlayerStats(FUID
);
5770 procedure TPlayer
.SaveState (st
: TStream
);
5776 utils
.writeSign(st
, 'PLYR');
5777 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
5779 utils
.writeBool(st
, FIamBot
);
5781 utils
.writeInt(st
, Word(FUID
));
5783 utils
.writeStr(st
, FName
);
5785 utils
.writeInt(st
, Byte(FTeam
));
5787 utils
.writeBool(st
, FAlive
);
5788 // Èçðàñõîäîâàë ëè âñå æèçíè
5789 utils
.writeBool(st
, FNoRespawn
);
5791 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
5792 utils
.writeInt(st
, Byte(b
));
5794 utils
.writeInt(st
, LongInt(FHealth
));
5796 utils
.writeInt(st
, Byte(FLives
));
5798 utils
.writeInt(st
, LongInt(FArmor
));
5800 utils
.writeInt(st
, LongInt(FAir
));
5802 utils
.writeInt(st
, LongInt(FJetFuel
));
5804 utils
.writeInt(st
, LongInt(FPain
));
5806 utils
.writeInt(st
, LongInt(FKills
));
5808 utils
.writeInt(st
, LongInt(FMonsterKills
));
5810 utils
.writeInt(st
, LongInt(FFrags
));
5812 utils
.writeInt(st
, Byte(FFragCombo
));
5813 // Âðåìÿ ïîñëåäíåãî ôðàãà
5814 utils
.writeInt(st
, LongWord(FLastFrag
));
5816 utils
.writeInt(st
, LongInt(FDeath
));
5818 utils
.writeInt(st
, Byte(FFlag
));
5820 utils
.writeInt(st
, LongInt(FSecrets
));
5822 utils
.writeInt(st
, Byte(FCurrWeap
));
5824 utils
.writeInt(st
, Word(FNextWeap
));
5826 utils
.writeInt(st
, Byte(FNextWeapDelay
));
5827 // Âðåìÿ çàðÿäêè BFG
5828 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
5830 utils
.writeInt(st
, LongInt(FDamageBuffer
));
5831 // Ïîñëåäíèé óäàðèâøèé
5832 utils
.writeInt(st
, Word(FLastSpawnerUID
));
5833 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
5834 utils
.writeInt(st
, Byte(FLastHit
));
5836 Obj_SaveState(st
, @FObj
);
5837 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
5838 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
5839 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
5840 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
5842 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
5843 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
5844 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
5846 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
5847 // Íàëè÷èå êðàñíîãî êëþ÷à
5848 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
5849 // Íàëè÷èå çåëåíîãî êëþ÷à
5850 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
5851 // Íàëè÷èå ñèíåãî êëþ÷à
5852 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
5854 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
5855 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
5856 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
5857 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
5858 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
5860 utils
.writeStr(st
, FModel
.Name
);
5862 utils
.writeInt(st
, Byte(FColor
.R
));
5863 utils
.writeInt(st
, Byte(FColor
.G
));
5864 utils
.writeInt(st
, Byte(FColor
.B
));
5868 procedure TPlayer
.LoadState (st
: TStream
);
5877 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
5878 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
5880 FIamBot
:= utils
.readBool(st
);
5882 FUID
:= utils
.readWord(st
);
5884 str
:= utils
.readStr(st
);
5885 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
5887 FTeam
:= utils
.readByte(st
);
5889 FAlive
:= utils
.readBool(st
);
5890 // Èçðàñõîäîâàë ëè âñå æèçíè
5891 FNoRespawn
:= utils
.readBool(st
);
5893 b
:= utils
.readByte(st
);
5894 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
5896 FHealth
:= utils
.readLongInt(st
);
5898 FLives
:= utils
.readByte(st
);
5900 FArmor
:= utils
.readLongInt(st
);
5902 FAir
:= utils
.readLongInt(st
);
5904 FJetFuel
:= utils
.readLongInt(st
);
5906 FPain
:= utils
.readLongInt(st
);
5908 FKills
:= utils
.readLongInt(st
);
5910 FMonsterKills
:= utils
.readLongInt(st
);
5912 FFrags
:= utils
.readLongInt(st
);
5914 FFragCombo
:= utils
.readByte(st
);
5915 // Âðåìÿ ïîñëåäíåãî ôðàãà
5916 FLastFrag
:= utils
.readLongWord(st
);
5918 FDeath
:= utils
.readLongInt(st
);
5920 FFlag
:= utils
.readByte(st
);
5922 FSecrets
:= utils
.readLongInt(st
);
5924 FCurrWeap
:= utils
.readByte(st
);
5926 FNextWeap
:= utils
.readWord(st
);
5928 FNextWeapDelay
:= utils
.readByte(st
);
5929 // Âðåìÿ çàðÿäêè BFG
5930 FBFGFireCounter
:= utils
.readSmallInt(st
);
5932 FDamageBuffer
:= utils
.readLongInt(st
);
5933 // Ïîñëåäíèé óäàðèâøèé
5934 FLastSpawnerUID
:= utils
.readWord(st
);
5935 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
5936 FLastHit
:= utils
.readByte(st
);
5938 Obj_LoadState(@FObj
, st
);
5939 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
5940 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
5941 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
5942 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
5944 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
5945 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
5946 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
5948 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
5949 // Íàëè÷èå êðàñíîãî êëþ÷à
5950 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
5951 // Íàëè÷èå çåëåíîãî êëþ÷à
5952 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
5953 // Íàëè÷èå ñèíåãî êëþ÷à
5954 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
5956 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
5957 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
5958 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
5959 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
5960 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
5962 str
:= utils
.readStr(st
);
5964 FColor
.R
:= utils
.readByte(st
);
5965 FColor
.G
:= utils
.readByte(st
);
5966 FColor
.B
:= utils
.readByte(st
);
5967 if (self
= gPlayer1
) then
5969 str
:= gPlayer1Settings
.Model
;
5970 FColor
:= gPlayer1Settings
.Color
;
5972 else if (self
= gPlayer2
) then
5974 str
:= gPlayer2Settings
.Model
;
5975 FColor
:= gPlayer2Settings
.Color
;
5977 // Îáíîâëÿåì ìîäåëü èãðîêà
5979 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
5980 FModel
.Color
:= TEAMCOLOR
[FTeam
]
5982 FModel
.Color
:= FColor
;
5986 procedure TPlayer
.AllRulez(Health
: Boolean);
5992 FHealth
:= PLAYER_HP_LIMIT
;
5993 FArmor
:= PLAYER_AP_LIMIT
;
5997 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
5998 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
5999 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6002 procedure TPlayer
.RestoreHealthArmor();
6004 FHealth
:= PLAYER_HP_LIMIT
;
6005 FArmor
:= PLAYER_AP_LIMIT
;
6008 procedure TPlayer
.FragCombo();
6012 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6014 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6016 if FFragCombo
< 5 then
6018 Param
:= FUID
or (FFragCombo
shl 16);
6019 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6020 (FComboEvnt
<= High(gDelayedEvents
)) and
6021 gDelayedEvents
[FComboEvnt
].Pending
and
6022 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6023 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6025 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6026 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6029 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6037 procedure TPlayer
.GiveItem(ItemType
: Byte);
6041 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6043 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6047 if FAir
< AIR_MAX
then
6054 if not (R_BERSERK
in FRulez
) then
6056 Include(FRulez
, R_BERSERK
);
6057 if FBFGFireCounter
< 1 then
6059 FCurrWeap
:= WEAPON_KASTET
;
6061 FModel
.SetWeapon(WEAPON_KASTET
);
6065 FBerserk
:= gTime
+30000;
6067 if FHealth
< PLAYER_HP_SOFT
then
6069 FHealth
:= PLAYER_HP_SOFT
;
6070 FBerserk
:= gTime
+30000;
6075 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6077 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6081 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6083 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6087 if FJetFuel
< JET_MAX
then
6089 FJetFuel
:= JET_MAX
;
6092 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6093 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6095 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6096 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6098 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6100 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6102 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6103 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6106 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6107 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6108 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6109 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6110 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6111 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6112 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6113 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6114 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6116 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6117 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6118 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6119 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6120 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6121 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6122 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6123 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6124 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6127 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6128 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6129 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6130 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6131 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6133 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6134 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6135 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6136 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6137 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6139 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6140 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6141 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6142 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6144 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6147 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6148 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6149 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6151 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6152 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6157 if g_Game_IsNet
and g_Game_IsServer
then
6158 MH_SEND_PlayerStats(FUID
);
6161 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6166 if (Random(5) = 1) and (Times
= 1) then
6169 if BodyInLiquid(0, 0) then
6171 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6172 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6173 if Random(2) = 0 then
6174 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6176 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6180 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6182 for i
:= 1 to Times
do
6184 Anim
:= TAnimation
.Create(id
, False, 3);
6186 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6187 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6193 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6198 if (Random(10) = 1) and (Times
= 1) then
6201 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6203 for i
:= 1 to Times
do
6205 Anim
:= TAnimation
.Create(id
, False, 3);
6207 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6208 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6214 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6216 FSawSound
.Pause(Enable
);
6217 FSawSoundIdle
.Pause(Enable
);
6218 FSawSoundHit
.Pause(Enable
);
6219 FSawSoundSelect
.Pause(Enable
);
6224 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6229 FObj
.Rect
:= PLAYER_CORPSERECT
;
6230 FModelName
:= ModelName
;
6235 FState
:= CORPSE_STATE_MESS
;
6236 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6240 FState
:= CORPSE_STATE_NORMAL
;
6241 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6245 destructor TCorpse
.Destroy();
6252 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6254 procedure TCorpse
.positionChanged (); inline; begin end;
6256 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6258 if (dx
<> 0) or (dy
<> 0) then
6267 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6269 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6270 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6271 w
:= PLAYER_CORPSERECT
.Width
;
6272 h
:= PLAYER_CORPSERECT
.Height
;
6276 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6281 if FState
= CORPSE_STATE_REMOVEME
then
6284 FDamage
:= FDamage
+ Value
;
6286 if FDamage
> 150 then
6288 if FAnimation
<> nil then
6293 FState
:= CORPSE_STATE_REMOVEME
;
6295 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6296 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6297 FModelName
, FColor
);
6298 // Çâóê ìÿñà îò òðóïà:
6299 pm
:= g_PlayerModel_Get(FModelName
);
6300 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6304 if (gBodyKillEvent
<> -1)
6305 and gDelayedEvents
[gBodyKillEvent
].Pending
then
6306 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
6307 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, 0);
6312 Blood
:= g_PlayerModel_GetBlood(FModelName
);
6313 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6314 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6315 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6316 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6317 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6318 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
6322 procedure TCorpse
.Draw();
6324 if FState
= CORPSE_STATE_REMOVEME
then
6327 if FAnimation
<> nil then
6328 FAnimation
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6330 if FAnimationMask
<> nil then
6333 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6340 procedure TCorpse
.Update();
6344 if FState
= CORPSE_STATE_REMOVEME
then
6347 if gTime
mod (GAME_TICK
*2) <> 0 then
6349 g_Obj_Move(@FObj
, True, True, True);
6350 positionChanged(); // this updates spatial accelerators
6354 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6355 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6357 st
:= g_Obj_Move(@FObj
, True, True, True);
6358 positionChanged(); // this updates spatial accelerators
6360 if WordBool(st
and MOVE_FALLOUT
) then
6362 FState
:= CORPSE_STATE_REMOVEME
;
6366 if FAnimation
<> nil then
6367 FAnimation
.Update();
6368 if FAnimationMask
<> nil then
6369 FAnimationMask
.Update();
6373 procedure TCorpse
.SaveState (st
: TStream
);
6380 utils
.writeSign(st
, 'CORP');
6381 utils
.writeInt(st
, Byte(0));
6383 utils
.writeInt(st
, Byte(FState
));
6385 utils
.writeInt(st
, Byte(FDamage
));
6387 utils
.writeInt(st
, Byte(FColor
.R
));
6388 utils
.writeInt(st
, Byte(FColor
.G
));
6389 utils
.writeInt(st
, Byte(FColor
.B
));
6391 Obj_SaveState(st
, @FObj
);
6392 utils
.writeInt(st
, Word(FPlayerUID
));
6394 anim
:= (FAnimation
<> nil);
6395 utils
.writeBool(st
, anim
);
6396 // Åñëè åñòü - ñîõðàíÿåì
6397 if anim
then FAnimation
.SaveState(st
);
6398 // Åñòü ëè ìàñêà àíèìàöèè
6399 anim
:= (FAnimationMask
<> nil);
6400 utils
.writeBool(st
, anim
);
6401 // Åñëè åñòü - ñîõðàíÿåì
6402 if anim
then FAnimationMask
.SaveState(st
);
6406 procedure TCorpse
.LoadState (st
: TStream
);
6413 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6414 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6416 FState
:= utils
.readByte(st
);
6418 FDamage
:= utils
.readByte(st
);
6420 FColor
.R
:= utils
.readByte(st
);
6421 FColor
.G
:= utils
.readByte(st
);
6422 FColor
.B
:= utils
.readByte(st
);
6424 Obj_LoadState(@FObj
, st
);
6425 FPlayerUID
:= utils
.readWord(st
);
6427 anim
:= utils
.readBool(st
);
6428 // Åñëè åñòü - çàãðóæàåì
6431 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6432 FAnimation
.LoadState(st
);
6434 // Åñòü ëè ìàñêà àíèìàöèè
6435 anim
:= utils
.readBool(st
);
6436 // Åñëè åñòü - çàãðóæàåì
6439 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6440 FAnimationMask
.LoadState(st
);
6446 constructor TBot
.Create();
6453 FSpectator
:= False;
6460 for a
:= WP_FIRST
to WP_LAST
do
6462 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6463 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6464 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6468 destructor TBot
.Destroy();
6471 inherited Destroy();
6474 procedure TBot
.Draw();
6478 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6479 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6482 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6484 inherited Respawn(Silent
, Force
);
6487 FSelectedWeapon
:= FCurrWeap
;
6492 procedure TBot
.UpdateCombat();
6505 TTargetRecord
= array of TTarget
;
6507 function Compare(a
, b
: TTarget
): Integer;
6509 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6512 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6514 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6515 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6517 if a
.Dist
> b
.Dist
then // B áëèæå
6519 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6522 else // Ñòðàííî -> A
6527 a
, x1
, y1
, x2
, y2
: Integer;
6528 targets
: TTargetRecord
;
6530 Target
, BestTarget
: TTarget
;
6531 firew
, fireh
: Integer;
6535 vsPlayer
, vsMonster
, ok
: Boolean;
6538 function monsUpdate (mon
: TMonster
): Boolean;
6540 result
:= false; // don't stop
6541 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6543 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6545 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6546 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6548 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6549 if g_TraceVector(x1
, y1
, x2
, y2
) then
6551 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6552 SetLength(targets
, Length(targets
)+1);
6553 with targets
[High(targets
)] do
6560 Rect
:= mon
.Obj
.Rect
;
6561 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6562 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6563 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6572 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6573 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6575 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6576 if FCurrWeap
<> FSelectedWeapon
then
6579 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6580 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6582 RemoveAIFlag('NEEDFIRE');
6585 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6586 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6587 else PressKey(KEY_FIRE
);
6591 // Êîîðäèíàòû ñòâîëà:
6592 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6593 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6595 Target
.UID
:= FTargetUID
;
6598 if Target
.UID
<> 0 then
6599 begin // Öåëü åñòü - íàñòðàèâàåì
6600 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6603 tpla
:= g_Player_Get(Target
.UID
);
6607 if (@FObj
) <> nil then
6614 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6615 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6616 Target
.Rect
:= PLAYER_RECT
;
6617 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6618 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6619 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6620 Target
.IsPlayer
:= True;
6624 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6627 mon
:= g_Monsters_ByUID(Target
.UID
);
6630 Target
.X
:= mon
.Obj
.X
;
6631 Target
.Y
:= mon
.Obj
.Y
;
6633 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6634 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6635 Target
.Rect
:= mon
.Obj
.Rect
;
6636 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6637 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6638 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6639 Target
.IsPlayer
:= False;
6646 begin // Öåëè íåò - îáíóëÿåì
6651 Target
.Visible
:= False;
6652 Target
.Line
:= False;
6653 Target
.IsPlayer
:= False;
6658 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6659 if (not Target
.Line
) or (not Target
.Visible
) then
6663 for a
:= 0 to High(gPlayers
) do
6664 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6665 (gPlayers
[a
].FUID
<> FUID
) and
6666 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6667 (not gPlayers
[a
].NoTarget
) and
6668 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6670 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6671 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6674 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6675 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6677 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6678 if g_TraceVector(x1
, y1
, x2
, y2
) then
6680 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6681 SetLength(targets
, Length(targets
)+1);
6682 with targets
[High(targets
)] do
6684 UID
:= gPlayers
[a
].FUID
;
6685 X
:= gPlayers
[a
].FObj
.X
;
6686 Y
:= gPlayers
[a
].FObj
.Y
;
6689 Rect
:= PLAYER_RECT
;
6690 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6691 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6692 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6700 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6703 // Åñëè åñòü âîçìîæíûå öåëè:
6704 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6705 if targets
<> nil then
6707 // Âûáèðàåì íàèëó÷øóþ öåëü:
6708 BestTarget
:= targets
[0];
6709 if Length(targets
) > 1 then
6710 for a
:= 1 to High(targets
) do
6711 if Compare(BestTarget
, targets
[a
]) = 1 then
6712 BestTarget
:= targets
[a
];
6714 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6715 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6716 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6718 Target
:= BestTarget
;
6720 if (Healthy() = 3) or ((Healthy() = 2)) then
6721 begin // Åñëè çäîðîâû - äîãîíÿåì
6722 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6723 SetAIFlag('GORIGHT', '1');
6724 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6725 SetAIFlag('GOLEFT', '1');
6728 begin // Åñëè ïîáèòû - óáåãàåì
6729 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6730 SetAIFlag('GORIGHT', '1');
6731 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6732 SetAIFlag('GOLEFT', '1');
6735 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6736 SelectWeapon(Abs(x1
-Target
.cX
));
6741 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6742 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6743 if Target
.UID
<> 0 then
6745 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6746 Target
.Y
+ Target
.Rect
.Y
) then
6747 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6748 if (Healthy() = 3) or ((Healthy() = 2)) then
6749 begin // Åñëè çäîðîâû - äîãîíÿåì
6750 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6751 SetAIFlag('GORIGHT', '1');
6752 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6753 SetAIFlag('GOLEFT', '1');
6756 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6758 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6759 SetAIFlag('GORIGHT', '1');
6760 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6761 SetAIFlag('GOLEFT', '1');
6765 begin // Öåëü ïîêà íà "ýêðàíå"
6766 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6767 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6768 FLastVisible
:= gTime
;
6769 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6770 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6772 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6773 SetAIFlag('GORIGHT', '1');
6774 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6775 SetAIFlag('GOLEFT', '1');
6779 // Âûáèðàåì óãîë ââåðõ:
6780 if FDirection
= TDirection
.D_LEFT
then
6781 angle
:= ANGLE_LEFTUP
6783 angle
:= ANGLE_RIGHTUP
;
6785 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6786 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6788 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6789 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6790 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6791 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6792 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6793 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6794 begin // òî íóæíî ñòðåëÿòü ââåðõ
6795 SetAIFlag('NEEDFIRE', '1');
6796 SetAIFlag('NEEDSEEUP', '1');
6799 // Âûáèðàåì óãîë âíèç:
6800 if FDirection
= TDirection
.D_LEFT
then
6801 angle
:= ANGLE_LEFTDOWN
6803 angle
:= ANGLE_RIGHTDOWN
;
6805 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6806 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6808 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6809 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6810 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6811 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6812 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6813 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6814 begin // òî íóæíî ñòðåëÿòü âíèç
6815 SetAIFlag('NEEDFIRE', '1');
6816 SetAIFlag('NEEDSEEDOWN', '1');
6819 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6820 if Target
.Visible
and
6821 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6822 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6824 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6825 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
6826 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6827 begin // òî íóæíî ñòðåëÿòü âïåðåä
6828 SetAIFlag('NEEDFIRE', '1');
6829 SetAIFlag('NEEDSEEDOWN', '');
6830 SetAIFlag('NEEDSEEUP', '');
6832 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6833 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6834 if GetRnd(FDifficult
.CloseJump
) then
6835 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6836 if Abs(FObj
.X
-Target
.X
) < 128 then
6840 if Random(a
) = 0 then
6841 SetAIFlag('NEEDJUMP', '1');
6845 // Åñëè öåëü âñå åùå åñòü:
6846 if Target
.UID
<> 0 then
6847 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
6848 Target
.UID
:= 0 // òî çàáûòü öåëü
6849 else // Åñëè âèäåëè íåäàâíî
6850 begin // íî öåëü óáèëè
6851 if Target
.IsPlayer
then
6852 begin // Öåëü - èãðîê
6853 pla
:= g_Player_Get(Target
.UID
);
6854 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
6855 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6856 Target
.UID
:= 0; // òî çàáûòü öåëü
6859 begin // Öåëü - ìîíñòð
6860 mon
:= g_Monsters_ByUID(Target
.UID
);
6861 if (mon
= nil) or (not mon
.alive
) then
6862 Target
.UID
:= 0; // òî çàáûòü öåëü
6865 end; // if Target.UID <> 0
6867 FTargetUID
:= Target
.UID
;
6869 // Åñëè âîçìîæíûõ öåëåé íåò:
6870 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
6871 if targets
= nil then
6872 if GetAIFlag('ATTACKLEFT') <> '' then
6873 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
6874 RemoveAIFlag('ATTACKLEFT');
6876 SetAIFlag('NEEDJUMP', '1');
6878 if RunDirection() = TDirection
.D_RIGHT
then
6879 begin // Èäåì íå â òó ñòîðîíó
6880 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6881 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
6882 SetAIFlag('NEEDFIRE', '1');
6883 SetAIFlag('GOLEFT', '1');
6887 begin // Èäåì â íóæíóþ ñòîðîíó
6888 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6889 SetAIFlag('NEEDFIRE', '1');
6890 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6891 SetAIFlag('GORIGHT', '1');
6895 if GetAIFlag('ATTACKRIGHT') <> '' then
6896 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
6897 RemoveAIFlag('ATTACKRIGHT');
6899 SetAIFlag('NEEDJUMP', '1');
6901 if RunDirection() = TDirection
.D_LEFT
then
6902 begin // Èäåì íå â òó ñòîðîíó
6903 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6904 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
6905 SetAIFlag('NEEDFIRE', '1');
6906 SetAIFlag('GORIGHT', '1');
6911 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6912 SetAIFlag('NEEDFIRE', '1');
6913 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6914 SetAIFlag('GOLEFT', '1');
6918 //HACK! (does it belongs there?)
6919 RealizeCurrentWeapon();
6921 // Åñëè åñòü âîçìîæíûå öåëè:
6922 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
6923 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6924 for a
:= 0 to High(targets
) do
6926 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
6927 if GetRnd(FDifficult
.DiagFire
) then
6929 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
6930 if FDirection
= TDirection
.D_LEFT
then
6931 angle
:= ANGLE_LEFTUP
6933 angle
:= ANGLE_RIGHTUP
;
6935 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6936 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6938 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6939 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6940 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6941 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6942 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6944 SetAIFlag('NEEDFIRE', '1');
6945 SetAIFlag('NEEDSEEUP', '1');
6948 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
6949 if FDirection
= TDirection
.D_LEFT
then
6950 angle
:= ANGLE_LEFTDOWN
6952 angle
:= ANGLE_RIGHTDOWN
;
6954 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6955 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6957 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6958 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6959 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6960 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6961 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6963 SetAIFlag('NEEDFIRE', '1');
6964 SetAIFlag('NEEDSEEDOWN', '1');
6968 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
6969 if targets
[a
].Line
and targets
[a
].Visible
and
6970 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
6971 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
6973 SetAIFlag('NEEDFIRE', '1');
6978 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
6979 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
6980 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
6981 40+GetInterval(FDifficult
.Cover
, 40)) then
6982 SetAIFlag('NEEDJUMP', '1');
6984 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
6985 ammo
:= GetAmmoByWeapon(FCurrWeap
);
6986 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
6987 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
6989 SetAIFlag('SELECTWEAPON', '1');
6991 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
6992 if GetAIFlag('SELECTWEAPON') = '1' then
6995 RemoveAIFlag('SELECTWEAPON');
6999 procedure TBot
.Update();
7012 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7013 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7015 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7017 if g_debug_BotAIOff
= 3 then
7027 RealizeCurrentWeapon();
7034 procedure TBot
.ReleaseKey(Key
: Byte);
7043 function TBot
.KeyPressed(Key
: Word): Boolean;
7045 Result
:= FKeys
[Key
].Pressed
;
7048 function TBot
.GetAIFlag(aName
: String20
): String20
;
7054 aName
:= LowerCase(aName
);
7056 if FAIFlags
<> nil then
7057 for a
:= 0 to High(FAIFlags
) do
7058 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7060 Result
:= FAIFlags
[a
].Value
;
7065 procedure TBot
.RemoveAIFlag(aName
: String20
);
7069 if FAIFlags
= nil then Exit
;
7071 aName
:= LowerCase(aName
);
7073 for a
:= 0 to High(FAIFlags
) do
7074 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7076 if a
<> High(FAIFlags
) then
7077 for b
:= a
to High(FAIFlags
)-1 do
7078 FAIFlags
[b
] := FAIFlags
[b
+1];
7080 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7085 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7093 aName
:= LowerCase(aName
);
7095 if FAIFlags
<> nil then
7096 for a
:= 0 to High(FAIFlags
) do
7097 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7103 if ok
then FAIFlags
[a
].Value
:= fValue
7106 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7107 with FAIFlags
[High(FAIFlags
)] do
7115 procedure TBot
.UpdateMove
;
7117 procedure GoLeft(Time
: Word = 1);
7119 ReleaseKey(KEY_LEFT
);
7120 ReleaseKey(KEY_RIGHT
);
7121 PressKey(KEY_LEFT
, Time
);
7122 SetDirection(TDirection
.D_LEFT
);
7125 procedure GoRight(Time
: Word = 1);
7127 ReleaseKey(KEY_LEFT
);
7128 ReleaseKey(KEY_RIGHT
);
7129 PressKey(KEY_RIGHT
, Time
);
7130 SetDirection(TDirection
.D_RIGHT
);
7133 function Rnd(a
: Word): Boolean;
7135 Result
:= Random(a
) = 0;
7138 procedure Turn(Time
: Word = 1200);
7140 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7145 ReleaseKey(KEY_LEFT
);
7146 ReleaseKey(KEY_RIGHT
);
7149 function CanRunLeft(): Boolean;
7151 Result
:= not CollideLevel(-1, 0);
7154 function CanRunRight(): Boolean;
7156 Result
:= not CollideLevel(1, 0);
7159 function CanRun(): Boolean;
7161 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7164 procedure Jump(Time
: Word = 30);
7166 PressKey(KEY_JUMP
, Time
);
7169 function NearHole(): Boolean;
7173 { TODO 5 : Ëåñòíèöû }
7174 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7175 for x
:= 1 to PLAYER_RECT
.Width
do
7176 if (not StayOnStep(x
*sx
, 0)) and
7177 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7178 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7187 function BorderHole(): Boolean;
7191 { TODO 5 : Ëåñòíèöû }
7192 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7193 for x
:= 1 to PLAYER_RECT
.Width
do
7194 if (not StayOnStep(x
*sx
, 0)) and
7195 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7196 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7198 for xx
:= x
to x
+32 do
7199 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7209 function NearDeepHole(): Boolean;
7215 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7218 for x
:= 1 to PLAYER_RECT
.Width
do
7219 if (not StayOnStep(x
*sx
, 0)) and
7220 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7221 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7223 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7225 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7230 end else Result
:= False;
7233 function OverDeepHole(): Boolean;
7240 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7242 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7249 function OnGround(): Boolean;
7251 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7254 function OnLadder(): Boolean;
7256 Result
:= FullInStep(0, 0);
7259 function BelowLadder(): Boolean;
7261 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7262 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7263 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7264 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7267 function BelowLiftUp(): Boolean;
7269 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7270 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7271 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7272 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7275 function OnTopLift(): Boolean;
7277 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7280 function CanJumpOver(): Boolean;
7284 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7288 if not CollideLevel(sx
, 0) then Exit
;
7290 for y
:= 1 to BOT_MAXJUMP
do
7291 if CollideLevel(0, -y
) then Exit
else
7292 if not CollideLevel(sx
, -y
) then
7299 function CanJumpUp(Dist
: ShortInt): Boolean;
7306 if CollideLevel(Dist
, 0) then Exit
;
7309 for y
:= 0 to BOT_MAXJUMP
do
7310 if CollideLevel(Dist
, -y
) then
7319 for yy
:= y
+1 to BOT_MAXJUMP
do
7320 if not CollideLevel(Dist
, -yy
) then
7329 for y
:= 0 to BOT_MAXJUMP
do
7330 if CollideLevel(0, -y
) then
7338 if y
< yy
then Exit
;
7343 function IsSafeTrigger(): Boolean;
7348 if gTriggers
= nil then
7350 for a
:= 0 to High(gTriggers
) do
7351 if Collide(gTriggers
[a
].X
,
7354 gTriggers
[a
].Height
) and
7355 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7356 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7357 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7358 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7359 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7364 // Âîçìîæíî, íàæèìàåì êíîïêó:
7365 if Rnd(16) and IsSafeTrigger() then
7368 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7369 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7371 ReleaseKey(KEY_LEFT
);
7372 ReleaseKey(KEY_RIGHT
);
7376 // Èäåì âëåâî, åñëè íàäî áûëî:
7377 if GetAIFlag('GOLEFT') <> '' then
7379 RemoveAIFlag('GOLEFT');
7380 if CanRunLeft() then
7384 // Èäåì âïðàâî, åñëè íàäî áûëî:
7385 if GetAIFlag('GORIGHT') <> '' then
7387 RemoveAIFlag('GORIGHT');
7388 if CanRunRight() then
7392 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7393 if FObj
.X
< -32 then
7396 if FObj
.X
+32 > gMapInfo
.Width
then
7399 // Ïðûãàåì, åñëè íàäî áûëî:
7400 if GetAIFlag('NEEDJUMP') <> '' then
7403 RemoveAIFlag('NEEDJUMP');
7406 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7407 if GetAIFlag('NEEDSEEUP') <> '' then
7410 ReleaseKey(KEY_DOWN
);
7411 PressKey(KEY_UP
, 20);
7412 RemoveAIFlag('NEEDSEEUP');
7415 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7416 if GetAIFlag('NEEDSEEDOWN') <> '' then
7419 ReleaseKey(KEY_DOWN
);
7420 PressKey(KEY_DOWN
, 20);
7421 RemoveAIFlag('NEEDSEEDOWN');
7424 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7425 if GetAIFlag('GOINHOLE') <> '' then
7426 if not OnGround() then
7428 ReleaseKey(KEY_LEFT
);
7429 ReleaseKey(KEY_RIGHT
);
7430 RemoveAIFlag('GOINHOLE');
7431 SetAIFlag('FALLINHOLE', '1');
7434 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7435 if GetAIFlag('FALLINHOLE') <> '' then
7437 RemoveAIFlag('FALLINHOLE');
7439 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7440 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7441 if GetAIFlag('FALLINHOLE') = '' then
7442 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7448 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7450 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7454 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7455 if OnGround() and NearHole() then
7456 if NearDeepHole() then // Åñëè ýòî áåçäíà
7458 0..3: Turn(); // Áåæèì îáðàòíî
7459 4: Jump(); // Ïðûãàåì
7460 5: begin // Ïðûãàåì îáðàòíî
7465 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7466 if GetAIFlag('GOINHOLE') = '' then
7468 0: Turn(); // Íå íóæíî òóäà
7469 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7470 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7471 if BorderHole() then
7472 SetAIFlag('GOINHOLE', '1');
7475 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7476 if (not CanRun()) and OnGround() then
7478 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7479 if CanJumpOver() or OnLadder() then
7481 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7482 if Random(2) = 0 then
7484 if IsSafeTrigger() then
7490 // Îñòàëîñü ìàëî âîçäóõà:
7491 if FAir
< 36 * 2 then
7494 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7495 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7496 if BodyInAcid(0, 0) then
7500 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7502 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7503 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7506 {function TBot.NeedItem(Item: Byte): Byte;
7511 procedure TBot
.SelectWeapon(Dist
: Integer);
7515 function HaveAmmo(weapon
: Byte): Boolean;
7518 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7519 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7520 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7521 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7522 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7523 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7524 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7525 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7526 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7527 else Result
:= True;
7532 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7534 if Dist
> BOT_LONGDIST
then
7535 begin // Äàëüíèé áîé
7537 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7539 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7543 else //if Dist > BOT_UNSAFEDIST then
7544 begin // Áëèæíèé áîé
7546 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7548 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7555 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7557 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7563 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7565 Result
:= inherited PickItem(ItemType
, force
, remove
);
7567 if Result
then SetAIFlag('SELECTWEAPON', '1');
7570 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7572 Result
:= inherited Heal(value
, Soft
);
7575 function TBot
.Healthy(): Byte;
7577 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7578 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7579 else if (FHealth
> 50) then Result
:= 2
7580 else if (FHealth
> 20) then Result
:= 1
7584 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7586 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7587 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7590 procedure TBot
.OnDamage(Angle
: SmallInt);
7598 if (Angle
= 0) or (Angle
= 180) then
7601 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7602 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7604 pla
:= g_Player_Get(FLastSpawnerUID
);
7605 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7606 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7609 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7610 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7612 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7613 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7614 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7619 SetAIFlag('ATTACKLEFT', '1')
7621 SetAIFlag('ATTACKRIGHT', '1');
7625 function TBot
.RunDirection(): TDirection
;
7627 if Abs(Vel
.X
) >= 1 then
7629 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7631 Result
:= FDirection
;
7634 function TBot
.GetRnd(a
: Byte): Boolean;
7636 if a
= 0 then Result
:= False
7637 else if a
= 255 then Result
:= True
7638 else Result
:= Random(256) > 255-a
;
7641 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7643 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7647 procedure TDifficult
.save (st
: TStream
);
7649 utils
.writeInt(st
, Byte(DiagFire
));
7650 utils
.writeInt(st
, Byte(InvisFire
));
7651 utils
.writeInt(st
, Byte(DiagPrecision
));
7652 utils
.writeInt(st
, Byte(FlyPrecision
));
7653 utils
.writeInt(st
, Byte(Cover
));
7654 utils
.writeInt(st
, Byte(CloseJump
));
7655 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7656 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7659 procedure TDifficult
.load (st
: TStream
);
7661 DiagFire
:= utils
.readByte(st
);
7662 InvisFire
:= utils
.readByte(st
);
7663 DiagPrecision
:= utils
.readByte(st
);
7664 FlyPrecision
:= utils
.readByte(st
);
7665 Cover
:= utils
.readByte(st
);
7666 CloseJump
:= utils
.readByte(st
);
7667 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7668 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7672 procedure TBot
.SaveState (st
: TStream
);
7677 inherited SaveState(st
);
7678 utils
.writeSign(st
, 'BOT0');
7680 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7682 utils
.writeInt(st
, Word(FTargetUID
));
7683 // Âðåìÿ ïîòåðè öåëè
7684 utils
.writeInt(st
, LongWord(FLastVisible
));
7685 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7686 dw
:= Length(FAIFlags
);
7687 utils
.writeInt(st
, LongInt(dw
));
7689 for i
:= 0 to dw
-1 do
7691 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7692 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7694 // Íàñòðîéêè ñëîæíîñòè
7695 FDifficult
.save(st
);
7699 procedure TBot
.LoadState (st
: TStream
);
7704 inherited LoadState(st
);
7705 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7707 FSelectedWeapon
:= utils
.readByte(st
);
7709 FTargetUID
:= utils
.readWord(st
);
7710 // Âðåìÿ ïîòåðè öåëè
7711 FLastVisible
:= utils
.readLongWord(st
);
7712 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7713 dw
:= utils
.readLongInt(st
);
7714 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7715 SetLength(FAIFlags
, dw
);
7717 for i
:= 0 to dw
-1 do
7719 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7720 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7722 // Íàñòðîéêè ñëîæíîñòè
7723 FDifficult
.load(st
);
7728 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);