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
2447 if (FMegaRulez
[MR_INVIS
] <= gTime
) or ((gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2448 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
)))) then
2450 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2451 if gAimLine
and alive
and
2452 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2457 procedure TPlayer
.DrawAim();
2458 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2463 {$IFDEF ENABLE_HOLMES}
2464 if isValidViewPort
and (self
= gPlayer1
) then
2466 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2470 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2471 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2473 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2477 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2482 wx
, wy
, xx
, yy
: Integer;
2486 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= TDirection
.D_LEFT
, 7, -7);
2487 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2496 1: begin // Chainsaw
2503 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2504 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2505 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2506 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2511 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2512 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2513 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2514 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2516 4: begin // Double Shotgun
2519 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2520 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2521 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2522 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2524 5: begin // Chaingun
2527 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2528 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2529 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2530 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2532 6: begin // Rocket Launcher
2535 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2536 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2537 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2538 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2540 7: begin // Plasmagun
2543 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2544 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2545 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2546 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2551 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2552 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2553 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2554 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2556 9: begin // Super Chaingun
2559 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2560 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2561 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2562 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2565 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2566 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2567 {$IF DEFINED(D2F_DEBUG)}
2568 drawCast(sz
, wx
, wy
, xx
, yy
);
2570 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2574 procedure TPlayer
.DrawGUI();
2577 X
, Y
, SY
, a
, p
, m
: Integer;
2581 stat
: TPlayerStatArray
;
2583 X
:= gPlayerScreenSize
.X
;
2584 SY
:= gPlayerScreenSize
.Y
;
2587 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2589 if gGameSettings
.GameMode
= GM_CTF
then
2593 if gGameSettings
.GameMode
= GM_CTF
then
2595 s
:= 'TEXTURE_PLAYER_REDFLAG';
2596 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2597 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2598 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2599 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2600 if g_Texture_Get(s
, ID
) then
2601 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2604 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2605 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2606 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2608 if gGameSettings
.GameMode
= GM_CTF
then
2610 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2611 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2612 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2613 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2614 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2615 if g_Texture_Get(s
, ID
) then
2616 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2619 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2620 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2621 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2624 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2625 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2628 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2629 e_Draw(ID
, X
+2, Y
, 0, True, False);
2631 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2635 s
:= IntToStr(Frags
);
2636 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2637 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2642 stat
:= g_Player_GetStats();
2647 for a
:= 0 to High(stat
) do
2648 if stat
[a
].Name
<> Name
then
2650 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2651 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2655 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2656 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2657 s
:= s
+IntToStr(Abs(Frags
-m
));
2659 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2660 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2663 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2665 s
:= IntToStr(Lives
);
2666 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2667 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2671 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2672 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2674 if R_BERSERK
in FRulez
then
2675 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2677 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2679 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2680 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2682 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2683 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2684 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2686 s
:= IntToStr(FArmor
);
2687 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2688 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2690 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2696 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2701 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2703 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2704 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2705 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2706 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2707 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2708 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2709 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2710 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2711 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2714 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2715 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2716 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2718 if R_KEY_RED
in FRulez
then
2719 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2721 if R_KEY_GREEN
in FRulez
then
2722 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2724 if R_KEY_BLUE
in FRulez
then
2725 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2727 if FJetFuel
> 0 then
2729 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2730 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2731 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2732 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2733 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2734 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2738 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2739 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2740 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2743 if gShowPing
and g_Game_IsClient
then
2745 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2746 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2752 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2753 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2754 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2757 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2758 s
:= _lc
[I_PLAYER_SPECT4
];
2759 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2760 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2761 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2767 procedure TPlayer
.DrawRulez();
2771 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2772 if FMegaRulez
[MR_INVUL
] >= gTime
then
2774 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2775 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2780 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2781 191, 191, 191, 0, TBlending
.Invert
);
2784 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2785 if FMegaRulez
[MR_SUIT
] >= gTime
then
2787 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2788 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2793 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2794 0, 96, 0, 200, TBlending
.None
);
2797 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2798 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2800 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2801 255, 0, 0, 200, TBlending
.None
);
2805 procedure TPlayer
.DrawPain();
2809 if FPain
= 0 then Exit
;
2813 if a
< 15 then h
:= 0
2814 else if a
< 35 then h
:= 1
2815 else if a
< 55 then h
:= 2
2816 else if a
< 75 then h
:= 3
2817 else if a
< 95 then h
:= 4
2820 //if a > 255 then a := 255;
2822 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2823 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2826 procedure TPlayer
.DrawPickup();
2830 if FPickup
= 0 then Exit
;
2834 if a
< 15 then h
:= 1
2835 else if a
< 35 then h
:= 2
2836 else if a
< 55 then h
:= 3
2837 else if a
< 75 then h
:= 4
2840 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2843 procedure TPlayer
.DoPunch();
2848 if FPunchAnim
<> nil then begin
2853 st
:= 'FRAMES_PUNCH';
2854 if R_BERSERK
in FRulez
then
2855 st
:= st
+ '_BERSERK';
2856 if FKeys
[KEY_UP
].Pressed
then
2858 else if FKeys
[KEY_DOWN
].Pressed
then
2860 g_Frames_Get(id
, st
);
2861 FPunchAnim
:= TAnimation
.Create(id
, False, 1);
2864 procedure TPlayer
.Fire();
2866 f
, DidFire
: Boolean;
2867 wx
, wy
, xd
, yd
: Integer;
2870 if g_Game_IsClient
then Exit
;
2871 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2872 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2880 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2885 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2886 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2887 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
2888 yd
:= wy
+firediry();
2894 if R_BERSERK
in FRulez
then
2896 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2897 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2898 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2901 locobj
.rect
.Width
:= 39;
2902 locobj
.rect
.Height
:= 52;
2903 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2904 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2905 locobj
.Accel
.X
:= xd
-wx
;
2906 locobj
.Accel
.y
:= yd
-wy
;
2908 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2909 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2911 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2913 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
2917 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2921 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2926 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2927 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2929 FSawSoundSelect
.Stop();
2931 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2933 else if not FSawSoundHit
.IsPlaying() then
2935 FSawSoundSelect
.Stop();
2936 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2939 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2945 if FAmmo
[A_BULLETS
] > 0 then
2947 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2948 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2949 Dec(FAmmo
[A_BULLETS
]);
2950 FFireAngle
:= FAngle
;
2953 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2954 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2958 if FAmmo
[A_SHELLS
] > 0 then
2960 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2961 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
2962 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2963 Dec(FAmmo
[A_SHELLS
]);
2964 FFireAngle
:= FAngle
;
2968 FShellType
:= SHELL_SHELL
;
2972 if FAmmo
[A_SHELLS
] >= 2 then
2974 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
2975 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2976 Dec(FAmmo
[A_SHELLS
], 2);
2977 FFireAngle
:= FAngle
;
2981 FShellType
:= SHELL_DBLSHELL
;
2985 if FAmmo
[A_BULLETS
] > 0 then
2987 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
2988 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
2989 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2990 Dec(FAmmo
[A_BULLETS
]);
2991 FFireAngle
:= FAngle
;
2994 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2995 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2998 WEAPON_ROCKETLAUNCHER
:
2999 if FAmmo
[A_ROCKETS
] > 0 then
3001 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
3002 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3003 Dec(FAmmo
[A_ROCKETS
]);
3004 FFireAngle
:= FAngle
;
3010 if FAmmo
[A_CELLS
] > 0 then
3012 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
3013 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3014 Dec(FAmmo
[A_CELLS
]);
3015 FFireAngle
:= FAngle
;
3021 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
3023 FBFGFireCounter
:= 17;
3024 if not FNoReload
then
3025 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
3026 Dec(FAmmo
[A_CELLS
], 40);
3030 WEAPON_SUPERPULEMET
:
3031 if FAmmo
[A_SHELLS
] > 0 then
3033 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3034 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
3035 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3036 Dec(FAmmo
[A_SHELLS
]);
3037 FFireAngle
:= FAngle
;
3040 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3041 GameVelX
, GameVelY
-2, SHELL_SHELL
);
3044 WEAPON_FLAMETHROWER
:
3045 if FAmmo
[A_FUEL
] > 0 then
3047 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
3048 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3050 FFireAngle
:= FAngle
;
3056 if g_Game_IsNet
then
3060 if FCurrWeap
<> WEAPON_BFG
then
3061 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
3063 if not FNoReload
then
3064 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
3067 MH_SEND_PlayerStats(FUID
);
3072 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
3073 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
3074 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
3077 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
3080 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
3081 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
3082 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
3083 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
3084 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
3089 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
3091 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
3092 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
3093 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
3096 procedure TPlayer
.JetpackOn
;
3100 FJetSoundOn
.SetPosition(0);
3101 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3105 procedure TPlayer
.JetpackOff
;
3109 FJetSoundOff
.SetPosition(0);
3110 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3113 procedure TPlayer
.CatchFire(Attacker
: Word);
3116 FFireAttacker
:= Attacker
;
3117 if g_Game_IsNet
and g_Game_IsServer
then
3118 MH_SEND_PlayerStats(FUID
);
3121 procedure TPlayer
.Jump();
3123 if gFly
or FJetpack
then
3125 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3126 if FObj
.Vel
.Y
> -VEL_FLY
then
3127 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3130 if FJetFuel
> 0 then
3132 if (FJetFuel
< 1) and g_Game_IsServer
then
3136 if g_Game_IsNet
then
3137 MH_SEND_PlayerStats(FUID
);
3143 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3145 FCanJetpack
:= False;
3147 // Ïðûãàåì èëè âñïëûâàåì:
3148 if (CollideLevel(0, 1) or
3149 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3150 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3151 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3153 FObj
.Vel
.Y
:= -VEL_JUMP
;
3154 FCanJetpack
:= False;
3158 if BodyInLiquid(0, 0) then
3159 FObj
.Vel
.Y
:= -VEL_SW
3160 else if (FJetFuel
> 0) and FCanJetpack
and
3161 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3165 if g_Game_IsNet
then
3166 MH_SEND_PlayerStats(FUID
);
3171 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3173 a
, i
, k
, ab
, ar
: Byte;
3177 srv
, netsrv
: Boolean;
3183 procedure PushItem(t
: Byte);
3187 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3188 it
:= g_Items_ByIdx(id
);
3189 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3191 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3192 (FObj
.Vel
.Y
div 2)-Random(9));
3193 it
.positionChanged(); // this updates spatial accelerators
3197 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3199 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3200 (FObj
.Vel
.Y
div 2)-Random(6));
3202 else // -3..+3; -3..0
3204 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3205 (FObj
.Vel
.Y
div 2)-Random(4));
3207 it
.positionChanged(); // this updates spatial accelerators
3210 if g_Game_IsNet
and g_Game_IsServer
then
3211 MH_SEND_ItemSpawn(True, id
);
3215 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3216 Srv
:= g_Game_IsServer
;
3217 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3218 if Srv
then FDeath
:= FDeath
+ 1;
3223 if not FPhysics
then
3229 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3231 if FLives
> 0 then FLives
:= FLives
- 1;
3232 if FLives
= 0 then FNoRespawn
:= True;
3235 // Íîìåð òèïà ñìåðòè:
3238 K_SIMPLEKILL
: a
:= 1;
3240 K_EXTRAHARDKILL
: a
:= 3;
3245 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3247 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3254 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3256 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3257 K_EXTRAHARDKILL
, K_FALLKILL
:
3258 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3261 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3265 K_HARDKILL
, K_EXTRAHARDKILL
:
3269 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3270 if (KillType
<> K_FALLKILL
) and (Srv
) then
3271 g_Monsters_killedp();
3273 if SpawnerUID
= FUID
then
3275 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3280 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3283 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3284 begin // Óáèò äðóãèì èãðîêîì
3285 KP
:= g_Player_Get(SpawnerUID
);
3286 if (KP
<> nil) and Srv
then
3288 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3289 if SameTeam(FUID
, SpawnerUID
) then
3299 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3300 Inc(gTeamStat
[KP
.Team
].Goals
,
3301 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3303 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3306 plr
:= g_Player_Get(SpawnerUID
);
3314 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3318 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3322 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3327 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3328 begin // Óáèò ìîíñòðîì
3329 mon
:= g_Monsters_ByUID(SpawnerUID
);
3333 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
3337 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3341 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3345 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3350 else // Îñîáûå òèïû ñìåðòè
3353 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3354 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3355 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3356 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3357 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3358 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3364 for a
:= WP_FIRST
to WP_LAST
do
3368 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3369 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3370 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3371 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3372 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3373 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3374 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3375 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3376 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3385 if R_ITEM_BACKPACK
in FRulez
then
3386 PushItem(ITEM_AMMO_BACKPACK
);
3388 // Âûáðîñ ðàêåòíîãî ðàíöà:
3389 if FJetFuel
> 0 then
3390 PushItem(ITEM_JETPACK
);
3393 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3395 if R_KEY_RED
in FRulez
then
3396 PushItem(ITEM_KEY_RED
);
3398 if R_KEY_GREEN
in FRulez
then
3399 PushItem(ITEM_KEY_GREEN
);
3401 if R_KEY_BLUE
in FRulez
then
3402 PushItem(ITEM_KEY_BLUE
);
3409 g_Player_CreateCorpse(Self
);
3411 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3412 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3418 for i
:= Low(gPlayers
) to High(gPlayers
) do
3420 if gPlayers
[i
] = nil then continue
;
3421 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3424 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3425 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3430 OldLR
:= gLMSRespawn
;
3431 if (gGameSettings
.GameMode
= GM_COOP
) then
3435 // everyone is dead, restart the map
3436 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3438 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3439 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3440 gLMSRespawnTime
:= gTime
+ 5000;
3442 else if (a
= 1) then
3444 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3445 if (gPlayers
[k
] = gPlayer1
) or
3446 (gPlayers
[k
] = gPlayer2
) then
3447 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3448 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3449 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3452 else if (gGameSettings
.GameMode
= GM_TDM
) then
3454 if (ab
= 0) and (ar
<> 0) then
3457 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3459 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3460 Inc(gTeamStat
[TEAM_RED
].Goals
);
3461 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3462 gLMSRespawnTime
:= gTime
+ 5000;
3464 else if (ar
= 0) and (ab
<> 0) then
3467 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3469 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3470 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3471 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3472 gLMSRespawnTime
:= gTime
+ 5000;
3474 else if (ar
= 0) and (ab
= 0) then
3477 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3479 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3480 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3481 gLMSRespawnTime
:= gTime
+ 5000;
3484 else if (gGameSettings
.GameMode
= GM_DM
) then
3488 if gPlayers
[k
] <> nil then
3491 // survivor is the winner
3492 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3494 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3497 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3498 gLMSRespawnTime
:= gTime
+ 5000;
3500 else if (a
= 0) then
3502 // everyone is dead, restart the map
3503 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3505 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3506 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3507 gLMSRespawnTime
:= gTime
+ 5000;
3510 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3512 if NetMode
= NET_SERVER
then
3513 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3515 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3521 MH_SEND_PlayerStats(FUID
);
3522 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3523 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3526 if srv
and FNoRespawn
then Spectate(True);
3527 FWantsInGame
:= True;
3530 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3532 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3533 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3536 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3538 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3539 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3542 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3544 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3545 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3546 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3547 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3548 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3549 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3550 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3551 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3554 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3556 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3557 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3558 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3559 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3562 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3564 if g_Game_IsClient
then Exit
;
3565 if Weapon
> High(FWeapon
) then Exit
;
3566 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3569 procedure TPlayer
.resetWeaponQueue ();
3572 FNextWeapDelay
:= 0;
3575 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3579 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3580 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 0);
3581 WEAPON_PISTOL
, WEAPON_CHAINGUN
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_BULLETS
] > 0);
3582 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3583 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3584 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3585 else result
:= (weapon
< length(FWeapon
));
3589 // return 255 for "no switch"
3590 function TPlayer
.getNextWeaponIndex (): Byte;
3593 wantThisWeapon
: array[0..64] of Boolean;
3594 wwc
: Integer = 0; //HACK!
3597 result
:= 255; // default result: "no switch"
3598 // had weapon cycling on previous frame? remove that flag
3599 if (FNextWeap
and $2000) <> 0 then
3601 FNextWeap
:= FNextWeap
and $1FFF;
3602 FNextWeapDelay
:= 0;
3604 // cycling has priority
3605 if (FNextWeap
and $C000) <> 0 then
3607 if (FNextWeap
and $8000) <> 0 then
3611 FNextWeap
:= FNextWeap
or $2000; // we need this
3612 if FNextWeapDelay
> 0 then
3613 exit
; // cooldown time
3615 for i
:= 0 to High(FWeapon
) do
3617 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3618 if FWeapon
[cwi
] then
3620 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d', [FCurrWeap, cwi]), MSG_WARNING);
3621 result
:= Byte(cwi
);
3622 FNextWeapDelay
:= WEAPON_DELAY
;
3630 for i
:= 0 to High(wantThisWeapon
) do
3631 wantThisWeapon
[i
] := false;
3632 for i
:= 0 to High(FWeapon
) do
3633 if (FNextWeap
and (1 shl i
)) <> 0 then
3635 wantThisWeapon
[i
] := true;
3638 // exclude currently selected weapon from the set
3639 wantThisWeapon
[FCurrWeap
] := false;
3640 // slow down alterations a little
3643 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3644 // more than one weapon requested, assume "alteration" and check alteration delay
3645 if FNextWeapDelay
> 0 then
3651 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3652 // but clear all counters if no weapon should be switched
3658 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3659 // try weapons in descending order
3660 for i
:= High(FWeapon
) downto 0 do
3662 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3667 FNextWeapDelay
:= WEAPON_DELAY
; // anyway, 'cause why not
3671 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3675 procedure TPlayer
.RealizeCurrentWeapon();
3676 function switchAllowed (): Boolean;
3681 if FBFGFireCounter
<> -1 then
3683 if FTime
[T_SWITCH
] > gTime
then
3685 for i
:= WP_FIRST
to WP_LAST
do
3686 if FReloading
[i
] > 0 then
3694 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3695 //FNextWeap := FNextWeap and $1FFF;
3696 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3698 if not switchAllowed
then
3700 //HACK for weapon cycling
3701 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3705 nw
:= getNextWeaponIndex();
3706 if nw
= 255 then exit
; // don't reset anything here
3707 if nw
> High(FWeapon
) then
3709 // don't forget to reset queue here!
3710 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3718 FTime
[T_SWITCH
] := gTime
+156;
3719 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3720 FModel
.SetWeapon(FCurrWeap
);
3721 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3725 procedure TPlayer
.NextWeapon();
3727 if g_Game_IsClient
then Exit
;
3731 procedure TPlayer
.PrevWeapon();
3733 if g_Game_IsClient
then Exit
;
3737 procedure TPlayer
.SetWeapon(W
: Byte);
3739 if FCurrWeap
<> W
then
3740 if W
= WEAPON_SAW
then
3741 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3744 FModel
.SetWeapon(CurrWeap
);
3748 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3750 function allowBerserkSwitching (): Boolean;
3752 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3754 if gBerserkAutoswitch
then exit
;
3755 if not conIsCheatsEnabled
then exit
;
3763 if g_Game_IsClient
then Exit
;
3765 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3766 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3771 if FHealth
< PLAYER_HP_SOFT
then
3773 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3777 if gFlash
= 2 then Inc(FPickup
, 5);
3781 if FHealth
< PLAYER_HP_SOFT
then
3783 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3787 if gFlash
= 2 then Inc(FPickup
, 5);
3791 if FArmor
< PLAYER_AP_SOFT
then
3793 FArmor
:= PLAYER_AP_SOFT
;
3796 if gFlash
= 2 then Inc(FPickup
, 5);
3800 if FArmor
< PLAYER_AP_LIMIT
then
3802 FArmor
:= PLAYER_AP_LIMIT
;
3805 if gFlash
= 2 then Inc(FPickup
, 5);
3809 if FHealth
< PLAYER_HP_LIMIT
then
3811 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3815 if gFlash
= 2 then Inc(FPickup
, 5);
3819 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3821 if FHealth
< PLAYER_HP_LIMIT
then
3822 FHealth
:= PLAYER_HP_LIMIT
;
3823 if FArmor
< PLAYER_AP_LIMIT
then
3824 FArmor
:= PLAYER_AP_LIMIT
;
3828 if gFlash
= 2 then Inc(FPickup
, 5);
3832 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3834 FWeapon
[WEAPON_SAW
] := True;
3836 if gFlash
= 2 then Inc(FPickup
, 5);
3837 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3840 ITEM_WEAPON_SHOTGUN1
:
3841 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3843 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3844 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3846 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3847 FWeapon
[WEAPON_SHOTGUN1
] := True;
3849 if gFlash
= 2 then Inc(FPickup
, 5);
3850 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3853 ITEM_WEAPON_SHOTGUN2
:
3854 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3856 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3858 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3859 FWeapon
[WEAPON_SHOTGUN2
] := True;
3861 if gFlash
= 2 then Inc(FPickup
, 5);
3862 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3865 ITEM_WEAPON_CHAINGUN
:
3866 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3868 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3870 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3871 FWeapon
[WEAPON_CHAINGUN
] := True;
3873 if gFlash
= 2 then Inc(FPickup
, 5);
3874 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3877 ITEM_WEAPON_ROCKETLAUNCHER
:
3878 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3880 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3882 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3883 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3885 if gFlash
= 2 then Inc(FPickup
, 5);
3886 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3890 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3892 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3894 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3895 FWeapon
[WEAPON_PLASMA
] := True;
3897 if gFlash
= 2 then Inc(FPickup
, 5);
3898 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3902 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3904 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3906 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3907 FWeapon
[WEAPON_BFG
] := True;
3909 if gFlash
= 2 then Inc(FPickup
, 5);
3910 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3913 ITEM_WEAPON_SUPERPULEMET
:
3914 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3916 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3918 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3919 FWeapon
[WEAPON_SUPERPULEMET
] := True;
3921 if gFlash
= 2 then Inc(FPickup
, 5);
3922 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3925 ITEM_WEAPON_FLAMETHROWER
:
3926 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
3928 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
3930 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3931 FWeapon
[WEAPON_FLAMETHROWER
] := True;
3933 if gFlash
= 2 then Inc(FPickup
, 5);
3934 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3938 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3940 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3943 if gFlash
= 2 then Inc(FPickup
, 5);
3946 ITEM_AMMO_BULLETS_BOX
:
3947 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3949 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3952 if gFlash
= 2 then Inc(FPickup
, 5);
3956 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3958 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3961 if gFlash
= 2 then Inc(FPickup
, 5);
3964 ITEM_AMMO_SHELLS_BOX
:
3965 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3967 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
3970 if gFlash
= 2 then Inc(FPickup
, 5);
3974 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3976 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3979 if gFlash
= 2 then Inc(FPickup
, 5);
3982 ITEM_AMMO_ROCKET_BOX
:
3983 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3985 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
3988 if gFlash
= 2 then Inc(FPickup
, 5);
3992 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3994 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3997 if gFlash
= 2 then Inc(FPickup
, 5);
4001 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4003 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4006 if gFlash
= 2 then Inc(FPickup
, 5);
4010 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4012 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4015 if gFlash
= 2 then Inc(FPickup
, 5);
4019 if not(R_ITEM_BACKPACK
in FRulez
) or
4020 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4021 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4022 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4023 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4024 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
4026 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4027 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4028 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4029 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4030 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4032 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4033 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4034 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4035 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4036 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4037 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4038 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4039 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4041 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
4044 if gFlash
= 2 then Inc(FPickup
, 5);
4048 if not(R_KEY_RED
in FRulez
) then
4050 Include(FRulez
, R_KEY_RED
);
4052 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4053 if gFlash
= 2 then Inc(FPickup
, 5);
4054 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4058 if not(R_KEY_GREEN
in FRulez
) then
4060 Include(FRulez
, R_KEY_GREEN
);
4062 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4063 if gFlash
= 2 then Inc(FPickup
, 5);
4064 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4068 if not(R_KEY_BLUE
in FRulez
) then
4070 Include(FRulez
, R_KEY_BLUE
);
4072 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4073 if gFlash
= 2 then Inc(FPickup
, 5);
4074 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4078 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4080 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4084 if gFlash
= 2 then Inc(FPickup
, 5);
4088 if FAir
< AIR_MAX
then
4093 if gFlash
= 2 then Inc(FPickup
, 5);
4098 if not (R_BERSERK
in FRulez
) then
4100 Include(FRulez
, R_BERSERK
);
4101 if allowBerserkSwitching
then
4103 FCurrWeap
:= WEAPON_KASTET
;
4105 FModel
.SetWeapon(WEAPON_KASTET
);
4110 if gFlash
= 2 then Inc(FPickup
, 5);
4112 FBerserk
:= gTime
+30000;
4117 if FHealth
< PLAYER_HP_SOFT
then
4119 FHealth
:= PLAYER_HP_SOFT
;
4120 FBerserk
:= gTime
+30000;
4128 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4130 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4133 if gFlash
= 2 then Inc(FPickup
, 5);
4137 if FHealth
< PLAYER_HP_LIMIT
then
4139 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4143 if gFlash
= 2 then Inc(FPickup
, 5);
4147 if FArmor
< PLAYER_AP_LIMIT
then
4149 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4152 if gFlash
= 2 then Inc(FPickup
, 5);
4156 if FJetFuel
< JET_MAX
then
4158 FJetFuel
:= JET_MAX
;
4161 if gFlash
= 2 then Inc(FPickup
, 5);
4165 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4167 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4170 if gFlash
= 2 then Inc(FPickup
, 5);
4175 procedure TPlayer
.Touch();
4179 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4182 // Áðîñèòü ôëàã òîâàðèùó:
4183 if gGameSettings
.GameMode
= GM_CTF
then
4188 procedure TPlayer
.Push(vx
, vy
: Integer);
4190 if (not FPhysics
) and FGhost
then
4192 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4193 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4194 if g_Game_IsNet
and g_Game_IsServer
then
4195 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4198 procedure TPlayer
.Reset(Force
: Boolean);
4204 FTime
[T_RESPAWN
] := 0;
4205 FTime
[T_FLAGCAP
] := 0;
4218 FSpectator
:= False;
4221 FSpectatePlayer
:= -1;
4222 FNoRespawn
:= False;
4224 FLives
:= gGameSettings
.MaxLives
;
4229 procedure TPlayer
.SoftReset();
4235 FBFGFireCounter
:= -1;
4243 SetAction(A_STAND
, True);
4246 function TPlayer
.GetRespawnPoint(): Byte;
4251 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4253 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4254 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4256 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4258 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4259 if Self
= gPlayer1
then
4260 c
:= RESPAWNPOINT_PLAYER1
4262 c
:= RESPAWNPOINT_PLAYER2
;
4263 if g_Map_GetPointCount(c
) > 0 then
4269 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4270 if Self
= gPlayer1
then
4271 c
:= RESPAWNPOINT_PLAYER2
4273 c
:= RESPAWNPOINT_PLAYER1
;
4274 if g_Map_GetPointCount(c
) > 0 then
4281 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4282 if Random(2) = 0 then
4283 c
:= RESPAWNPOINT_PLAYER1
4285 c
:= RESPAWNPOINT_PLAYER2
;
4286 if g_Map_GetPointCount(c
) > 0 then
4293 // Òî÷êà ëþáîé èç êîìàíä
4294 if Random(2) = 0 then
4295 c
:= RESPAWNPOINT_RED
4297 c
:= RESPAWNPOINT_BLUE
;
4298 if g_Map_GetPointCount(c
) > 0 then
4305 c
:= RESPAWNPOINT_DM
;
4306 if g_Map_GetPointCount(c
) > 0 then
4314 if gGameSettings
.GameMode
= GM_DM
then
4317 c
:= RESPAWNPOINT_DM
;
4318 if g_Map_GetPointCount(c
) > 0 then
4324 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4325 if Random(2) = 0 then
4326 c
:= RESPAWNPOINT_PLAYER1
4328 c
:= RESPAWNPOINT_PLAYER2
;
4329 if g_Map_GetPointCount(c
) > 0 then
4335 // Òî÷êà ëþáîé èç êîìàíä
4336 if Random(2) = 0 then
4337 c
:= RESPAWNPOINT_RED
4339 c
:= RESPAWNPOINT_BLUE
;
4340 if g_Map_GetPointCount(c
) > 0 then
4348 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4350 // Òî÷êà ñâîåé êîìàíäû
4351 c
:= RESPAWNPOINT_DM
;
4352 if FTeam
= TEAM_RED
then
4353 c
:= RESPAWNPOINT_RED
;
4354 if FTeam
= TEAM_BLUE
then
4355 c
:= RESPAWNPOINT_BLUE
;
4356 if g_Map_GetPointCount(c
) > 0 then
4363 c
:= RESPAWNPOINT_DM
;
4364 if g_Map_GetPointCount(c
) > 0 then
4370 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4371 if Random(2) = 0 then
4372 c
:= RESPAWNPOINT_PLAYER1
4374 c
:= RESPAWNPOINT_PLAYER2
;
4375 if g_Map_GetPointCount(c
) > 0 then
4381 // Òî÷êà äðóãîé êîìàíäû
4382 c
:= RESPAWNPOINT_DM
;
4383 if FTeam
= TEAM_RED
then
4384 c
:= RESPAWNPOINT_BLUE
;
4385 if FTeam
= TEAM_BLUE
then
4386 c
:= RESPAWNPOINT_RED
;
4387 if g_Map_GetPointCount(c
) > 0 then
4395 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4397 RespawnPoint
: TRespawnPoint
;
4403 FBFGFireCounter
:= -1;
4408 if not g_Game_IsServer
then
4412 FWantsInGame
:= True;
4413 FJustTeleported
:= True;
4416 FTime
[T_RESPAWN
] := 0;
4420 // if server changes MaxLives we gotta be ready
4421 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4423 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4424 if FTime
[T_RESPAWN
] > gTime
then
4427 // Ïðîñðàë âñå æèçíè:
4430 if not FSpectator
then Spectate(True);
4431 FWantsInGame
:= True;
4435 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4436 begin // "Ñâîÿ èãðà"
4437 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4438 FRulez
:= FRulez
-[R_BERSERK
];
4440 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4442 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4443 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4446 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4447 c
:= GetRespawnPoint();
4452 // Âîñêðåøåíèå áåç îðóæèÿ:
4455 FHealth
:= PLAYER_HP_SOFT
;
4461 for a
:= WP_FIRST
to WP_LAST
do
4463 FWeapon
[a
] := False;
4467 FWeapon
[WEAPON_PISTOL
] := True;
4468 FWeapon
[WEAPON_KASTET
] := True;
4469 FCurrWeap
:= WEAPON_PISTOL
;
4472 FModel
.SetWeapon(FCurrWeap
);
4474 for b
:= A_BULLETS
to A_HIGH
do
4477 FAmmo
[A_BULLETS
] := 50;
4479 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4480 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4481 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4482 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4483 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4485 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4486 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4491 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4492 if not g_Map_GetPoint(c
, RespawnPoint
) then
4494 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4498 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4499 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4500 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4506 FDirection
:= RespawnPoint
.Direction
;
4507 if FDirection
= TDirection
.D_LEFT
then
4512 SetAction(A_STAND
, True);
4513 FModel
.Direction
:= FDirection
;
4515 for a
:= Low(FTime
) to High(FTime
) do
4518 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4523 FCanJetpack
:= False;
4528 // Àíèìàöèÿ âîçðîæäåíèÿ:
4529 if (not gLoadGameMode
) and (not Silent
) then
4530 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4532 Anim
:= TAnimation
.Create(ID
, False, 3);
4533 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4534 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4538 FSpectator
:= False;
4541 FSpectatePlayer
:= -1;
4544 if (gPlayer1
= nil) and (gLMSPID1
= FUID
) then
4546 if (gPlayer2
= nil) and (gLMSPID2
= FUID
) then
4549 if g_Game_IsNet
then
4551 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4552 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4554 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4555 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4560 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4563 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4564 else if (not NoMove
) then
4566 GameX
:= gMapInfo
.Width
div 2;
4567 GameY
:= gMapInfo
.Height
div 2;
4576 FWantsInGame
:= False;
4581 if Self
= gPlayer1
then
4586 if Self
= gPlayer2
then
4593 if g_Game_IsNet
then
4594 MH_SEND_PlayerStats(FUID
);
4597 procedure TPlayer
.SwitchNoClip
;
4601 FGhost
:= not FGhost
;
4602 FPhysics
:= not FGhost
;
4614 procedure TPlayer
.Run(Direction
: TDirection
);
4618 if MAX_RUNVEL
> 8 then
4622 if Direction
= TDirection
.D_LEFT
then
4624 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4625 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4628 if FObj
.Vel
.X
< MAX_RUNVEL
then
4629 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4631 // Âîçìîæíî, ïèíàåì êóñêè:
4632 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4634 b
:= Abs(FObj
.Vel
.X
);
4635 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4636 for a
:= 0 to High(gGibs
) do
4638 if gGibs
[a
].alive
and
4639 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4640 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4643 if FObj
.Vel
.X
< 0 then
4645 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4649 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4651 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4659 procedure TPlayer
.SeeDown();
4661 SetAction(A_SEEDOWN
);
4663 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4665 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4668 procedure TPlayer
.SeeUp();
4672 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4674 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4677 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4685 A_ATTACK
: Prior
:= 2;
4686 A_SEEUP
: Prior
:= 1;
4687 A_SEEDOWN
: Prior
:= 1;
4688 A_ATTACKUP
: Prior
:= 2;
4689 A_ATTACKDOWN
: Prior
:= 2;
4694 if (Prior
> FActionPrior
) or Force
then
4695 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4697 FActionPrior
:= Prior
;
4698 FActionAnim
:= Action
;
4699 FActionForce
:= Force
;
4700 FActionChanged
:= True;
4703 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4706 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4708 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4709 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4710 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4711 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4714 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4721 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4723 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4724 if g_Game_IsServer
and g_Game_IsNet
then
4725 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4729 FJustTeleported
:= True;
4734 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4736 Anim
:= TAnimation
.Create(ID
, False, 3);
4739 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4740 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4741 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4742 if g_Game_IsServer
and g_Game_IsNet
then
4743 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4744 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4748 FObj
.X
:= X
-PLAYER_RECT
.X
;
4749 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4750 if FAlive
and FGhost
then
4756 if not g_Game_IsNet
then
4760 SetDirection(TDirection
.D_LEFT
);
4766 SetDirection(TDirection
.D_RIGHT
);
4772 if FDirection
= TDirection
.D_RIGHT
then
4774 SetDirection(TDirection
.D_LEFT
);
4779 SetDirection(TDirection
.D_RIGHT
);
4785 if not silent
and (Anim
<> nil) then
4787 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4788 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4791 if g_Game_IsServer
and g_Game_IsNet
then
4792 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4793 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4800 function nonz(a
: Single): Single;
4808 function TPlayer
.followCorpse(): Boolean;
4813 if FAlive
or FSpectator
then
4815 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
4817 for i
:= 0 to High(gCorpses
) do
4818 if gCorpses
[i
] <> nil then
4819 if gCorpses
[i
].FPlayerUID
= FUID
then
4822 FObj
.X
:= gCorpses
[i
].FObj
.X
;
4823 FObj
.Y
:= gCorpses
[i
].FObj
.Y
;
4824 FObj
.Vel
.X
:= gCorpses
[i
].FObj
.Vel
.X
;
4825 FObj
.Vel
.Y
:= gCorpses
[i
].FObj
.Vel
.Y
;
4826 FObj
.Accel
.X
:= gCorpses
[i
].FObj
.Accel
.X
;
4827 FObj
.Accel
.Y
:= gCorpses
[i
].FObj
.Accel
.Y
;
4832 procedure TPlayer
.Update();
4835 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4836 blockmon
, headwater
, dospawn
: Boolean;
4841 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4842 AnyServer
:= g_Game_IsServer
;
4844 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4845 DoLerp(NetInterpLevel
+ 1)
4851 if FClientID
>= 0 then
4853 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4854 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4855 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4864 if FAlive
and (FPunchAnim
<> nil) then
4865 FPunchAnim
.Update();
4867 if FAlive
and (gFly
or FJetpack
) then
4870 if FDirection
= TDirection
.D_LEFT
then
4875 if FAlive
and (not FGhost
) then
4877 if FKeys
[KEY_UP
].Pressed
then
4879 if FKeys
[KEY_DOWN
].Pressed
then
4883 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4886 i
:= g_basic
.Sign(FIncCam
);
4887 FIncCam
:= Abs(FIncCam
);
4888 DecMin(FIncCam
, 5, 0);
4889 FIncCam
:= FIncCam
*i
;
4892 // no need to do that each second frame, weapon queue will take care of it
4893 if FAlive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4894 if FAlive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4896 if gTime
mod (GAME_TICK
*2) <> 0 then
4898 if (FObj
.Vel
.X
= 0) and FAlive
then
4900 if FKeys
[KEY_LEFT
].Pressed
then
4901 Run(TDirection
.D_LEFT
);
4902 if FKeys
[KEY_RIGHT
].Pressed
then
4903 Run(TDirection
.D_RIGHT
);
4908 if not followCorpse() then
4909 g_Obj_Move(@FObj
, True, True, True);
4910 positionChanged(); // this updates spatial accelerators
4916 FActionChanged
:= False;
4920 // Let alive player do some actions
4921 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
4922 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
4923 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
4924 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
4925 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
4926 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
4927 if FKeys
[KEY_JUMP
].Pressed
then Jump()
4930 if AnyServer
and FJetpack
then
4934 if NetServer
then MH_SEND_PlayerStats(FUID
);
4936 FCanJetpack
:= True;
4943 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
4945 if FKeys
[k
].Pressed
then
4953 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4956 if (FTime
[T_RESPAWN
] <= gTime
) and
4957 gGameOn
and (not FAlive
) then
4959 if (g_Player_GetCount() > 1) then
4963 gExit
:= EXIT_RESTART
;
4968 // Dead spectator actions
4971 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
4972 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
4976 if (FSpectatePlayer
>= High(gPlayers
)) then
4977 FSpectatePlayer
:= -1
4981 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
4982 if gPlayers
[I
] <> nil then
4983 if gPlayers
[I
].alive
then
4984 if gPlayers
[I
].UID
<> FUID
then
4986 FSpectatePlayer
:= I
;
4991 if not SetSpect
then FSpectatePlayer
:= -1;
5002 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5004 FYTo
:= FObj
.Y
- 32;
5005 FSpectatePlayer
:= -1;
5007 if FKeys
[KEY_DOWN
].Pressed
then
5009 FYTo
:= FObj
.Y
+ 32;
5010 FSpectatePlayer
:= -1;
5012 if FKeys
[KEY_LEFT
].Pressed
then
5014 FXTo
:= FObj
.X
- 32;
5015 FSpectatePlayer
:= -1;
5017 if FKeys
[KEY_RIGHT
].Pressed
then
5019 FXTo
:= FObj
.X
+ 32;
5020 FSpectatePlayer
:= -1;
5023 if (FXTo
< -64) then
5025 else if (FXTo
> gMapInfo
.Width
+ 32) then
5026 FXTo
:= gMapInfo
.Width
+ 32;
5027 if (FYTo
< -72) then
5029 else if (FYTo
> gMapInfo
.Height
+ 32) then
5030 FYTo
:= gMapInfo
.Height
+ 32;
5035 if not followCorpse() then
5036 g_Obj_Move(@FObj
, True, True, True);
5037 positionChanged(); // this updates spatial accelerators
5044 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5045 if gPlayers
[FSpectatePlayer
] <> nil then
5046 if gPlayers
[FSpectatePlayer
].alive
then
5048 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
5049 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
5053 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5054 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5055 PANEL_BLOCKMON
, True);
5056 headwater
:= HeadInLiquid(0, 0);
5058 // Ñîïðîòèâëåíèå âîçäóõà:
5059 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5060 if FObj
.Vel
.X
<> 0 then
5061 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5063 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5064 DecMin(FPain
, 5, 0);
5065 DecMin(FPickup
, 1, 0);
5067 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5069 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5070 FMegaRulez
[MR_SUIT
] := 0;
5071 FMegaRulez
[MR_INVUL
] := 0;
5072 FMegaRulez
[MR_INVIS
] := 0;
5073 Kill(K_FALLKILL
, 0, HIT_FALL
);
5080 if FCurrWeap
= WEAPON_SAW
then
5081 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5082 FSawSoundSelect
.IsPlaying()) then
5083 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5086 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5087 (not FJetSoundOff
.IsPlaying()) then
5089 FJetSoundFly
.SetPosition(0);
5090 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5093 for b
:= WP_FIRST
to WP_LAST
do
5094 if FReloading
[b
] > 0 then
5100 if FShellTimer
> -1 then
5101 if FShellTimer
= 0 then
5103 if FShellType
= SHELL_SHELL
then
5104 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5105 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5106 else if FShellType
= SHELL_DBLSHELL
then
5108 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5109 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5110 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5111 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5114 end else Dec(FShellTimer
);
5116 if (FBFGFireCounter
> -1) then
5117 if FBFGFireCounter
= 0 then
5121 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5122 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5123 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5124 yd
:= wy
+firediry();
5125 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5126 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5127 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5128 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5129 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5132 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5133 FBFGFireCounter
:= -1;
5136 FBFGFireCounter
:= 0
5138 Dec(FBFGFireCounter
);
5140 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5142 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5144 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5147 if (headwater
or blockmon
) then
5153 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5156 else if (FAir
mod 31 = 0) and not blockmon
then
5158 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5159 if Random(2) = 0 then
5160 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5162 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5164 end else if FAir
< AIR_DEF
then
5167 if FFireTime
> 0 then
5169 if BodyInLiquid(0, 0) then
5174 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5176 if FMegaRulez
[MR_SUIT
] = gTime
then
5183 if FFirePainTime
<= 0 then
5185 if g_Game_IsServer
then
5186 Damage(5, FFireAttacker
, 0, 0, HIT_FLAME
);
5187 FFirePainTime
:= 18;
5189 FFirePainTime
:= FFirePainTime
- 1;
5190 FFireTime
:= FFireTime
- 1;
5191 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5192 MH_SEND_PlayerStats(FUID
);
5196 if FDamageBuffer
> 0 then
5198 if FDamageBuffer
>= 9 then
5202 if FDamageBuffer
< 30 then i
:= 9
5203 else if FDamageBuffer
< 100 then i
:= 18
5207 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5208 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5209 FHealth
:= FHealth
-ii
;
5212 FHealth
:= FHealth
+FArmor
;
5217 if FHealth
<= 0 then
5218 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5219 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5220 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5224 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5225 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5226 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5227 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5234 end; // if FAlive then ...
5236 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5238 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5239 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5240 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5241 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5243 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5244 then SetAction(A_STAND
, True);
5246 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5248 for b
:= Low(FKeys
) to High(FKeys
) do
5249 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5253 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5255 x
:= FObj
.X
+PLAYER_RECT
.X
;
5256 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5257 w
:= PLAYER_RECT
.Width
;
5258 h
:= PLAYER_RECT
.Height
;
5262 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5264 if (dx
<> 0) or (dy
<> 0) then
5273 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5275 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5276 FObj
.Y
+PLAYER_RECT
.Y
,
5283 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5285 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5286 FObj
.Y
+PLAYER_RECT
.Y
,
5290 Panel
.Width
, Panel
.Height
);
5293 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5295 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5296 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5297 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5298 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5301 function g_Player_ValidName(Name
: string): Boolean;
5307 if gPlayers
= nil then Exit
;
5309 for a
:= 0 to High(gPlayers
) do
5310 if gPlayers
[a
] <> nil then
5311 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5318 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5322 d
:= FModel
.Direction
;
5324 FModel
.Direction
:= Direction
;
5325 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5327 FDirection
:= Direction
;
5330 function TPlayer
.GetKeys(): Byte;
5334 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5335 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5336 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5338 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5339 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5342 procedure TPlayer
.Use();
5346 if FTime
[T_USE
] > gTime
then Exit
;
5348 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5349 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5351 for a
:= 0 to High(gPlayers
) do
5352 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5353 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5354 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5355 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5357 gPlayers
[a
].Touch();
5358 if g_Game_IsNet
and g_Game_IsServer
then
5359 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5362 FTime
[T_USE
] := gTime
+120;
5365 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5369 WX
, WY
, XD
, YD
: Integer;
5381 if R_BERSERK
in FRulez
then
5383 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5384 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5385 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5388 locobj
.rect
.Width
:= 39;
5389 locobj
.rect
.Height
:= 52;
5390 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5391 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5392 locobj
.Accel
.X
:= xd
-wx
;
5393 locobj
.Accel
.y
:= yd
-wy
;
5395 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5396 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5398 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5402 FPain
:= min(FPain
+ 25, 50);
5404 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5409 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5410 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5412 FSawSoundSelect
.Stop();
5414 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5416 else if not FSawSoundHit
.IsPlaying() then
5418 FSawSoundSelect
.Stop();
5419 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5426 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5427 FFireAngle
:= FAngle
;
5429 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5430 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5435 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5436 FFireAngle
:= FAngle
;
5439 FShellType
:= SHELL_SHELL
;
5444 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5445 FFireAngle
:= FAngle
;
5448 FShellType
:= SHELL_DBLSHELL
;
5453 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5454 FFireAngle
:= FAngle
;
5456 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5457 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5460 WEAPON_ROCKETLAUNCHER
:
5462 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5463 FFireAngle
:= FAngle
;
5469 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5470 FFireAngle
:= FAngle
;
5476 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5477 FFireAngle
:= FAngle
;
5481 WEAPON_SUPERPULEMET
:
5483 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5484 FFireAngle
:= FAngle
;
5486 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5487 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5490 WEAPON_FLAMETHROWER
:
5492 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5493 FFireAngle
:= FAngle
;
5500 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5501 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5502 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5505 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5507 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5508 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5511 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5515 if NetInterpLevel
< 1 then
5525 AX
:= Abs(FXTo
- FObj
.X
);
5526 AY
:= Abs(FYTo
- FObj
.Y
);
5527 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5529 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5534 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5536 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5537 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5538 PANEL_LIFTUP
, False) then Result
:= -1
5540 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5541 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5542 PANEL_LIFTDOWN
, False) then Result
:= 1
5546 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5553 if Flag
= FLAG_NONE
then
5556 if not g_Game_IsServer
then Exit
;
5558 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5559 if (Flag
= FTeam
) and
5560 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5561 (FFlag
<> FLAG_NONE
) then
5563 if FFlag
= FLAG_RED
then
5564 s
:= _lc
[I_PLAYER_FLAG_RED
]
5566 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5568 evtype
:= FLAG_STATE_SCORED
;
5570 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5571 Insert('.', ts
, Length(ts
) + 1 - 3);
5572 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5574 g_Map_ResetFlag(FFlag
);
5575 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5577 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5580 if g_Game_IsNet
then
5582 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5586 gFlags
[FFlag
].CaptureTime
:= 0;
5591 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5592 if (Flag
= FTeam
) and
5593 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5595 if Flag
= FLAG_RED
then
5596 s
:= _lc
[I_PLAYER_FLAG_RED
]
5598 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5600 evtype
:= FLAG_STATE_RETURNED
;
5601 gFlags
[Flag
].CaptureTime
:= 0;
5603 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5605 g_Map_ResetFlag(Flag
);
5606 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5609 if g_Game_IsNet
then
5611 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5617 // Ïîäîáðàë ÷óæîé ôëàã:
5618 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5622 if Flag
= FLAG_RED
then
5623 s
:= _lc
[I_PLAYER_FLAG_RED
]
5625 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5627 evtype
:= FLAG_STATE_CAPTURED
;
5629 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5631 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5633 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5636 if g_Game_IsNet
then
5638 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5644 procedure TPlayer
.SetFlag(Flag
: Byte);
5647 if FModel
<> nil then
5648 FModel
.SetFlag(FFlag
);
5651 function TPlayer
.DropFlag(): Boolean;
5656 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5658 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5659 with gFlags
[FFlag
] do
5663 Direction
:= FDirection
;
5664 State
:= FLAG_STATE_DROPPED
;
5666 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5667 (FObj
.Vel
.Y
div 2)-2+Random(5));
5668 positionChanged(); // this updates spatial accelerators
5670 if FFlag
= FLAG_RED
then
5671 s
:= _lc
[I_PLAYER_FLAG_RED
]
5673 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5675 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5676 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5678 if g_Game_IsNet
then
5679 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5685 procedure TPlayer
.GetSecret();
5690 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5692 Assert(Key
<= High(FKeys
));
5694 FKeys
[Key
].Pressed
:= True;
5695 FKeys
[Key
].Time
:= Time
;
5698 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5700 Result
:= FKeys
[K
].Pressed
;
5703 procedure TPlayer
.ReleaseKeys();
5707 for a
:= Low(FKeys
) to High(FKeys
) do
5709 FKeys
[a
].Pressed
:= False;
5714 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5718 function TPlayer
.firediry(): Integer;
5720 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5721 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5725 procedure TPlayer
.RememberState();
5729 FSavedState
.Health
:= FHealth
;
5730 FSavedState
.Armor
:= FArmor
;
5731 FSavedState
.Air
:= FAir
;
5732 FSavedState
.JetFuel
:= FJetFuel
;
5733 FSavedState
.CurrWeap
:= FCurrWeap
;
5734 FSavedState
.NextWeap
:= FNextWeap
;
5735 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5738 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5740 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5742 FSavedState
.Rulez
:= FRulez
;
5743 FSavedState
.WaitRecall
:= True;
5746 procedure TPlayer
.RecallState();
5750 if not FSavedState
.WaitRecall
then Exit
;
5752 FHealth
:= FSavedState
.Health
;
5753 FArmor
:= FSavedState
.Armor
;
5754 FAir
:= FSavedState
.Air
;
5755 FJetFuel
:= FSavedState
.JetFuel
;
5756 FCurrWeap
:= FSavedState
.CurrWeap
;
5757 FNextWeap
:= FSavedState
.NextWeap
;
5758 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5761 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5763 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5765 FRulez
:= FSavedState
.Rulez
;
5766 FSavedState
.WaitRecall
:= False;
5768 if gGameSettings
.GameType
= GT_SERVER
then
5769 MH_SEND_PlayerStats(FUID
);
5772 procedure TPlayer
.SaveState (st
: TStream
);
5778 utils
.writeSign(st
, 'PLYR');
5779 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
5781 utils
.writeBool(st
, FIamBot
);
5783 utils
.writeInt(st
, Word(FUID
));
5785 utils
.writeStr(st
, FName
);
5787 utils
.writeInt(st
, Byte(FTeam
));
5789 utils
.writeBool(st
, FAlive
);
5790 // Èçðàñõîäîâàë ëè âñå æèçíè
5791 utils
.writeBool(st
, FNoRespawn
);
5793 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
5794 utils
.writeInt(st
, Byte(b
));
5796 utils
.writeInt(st
, LongInt(FHealth
));
5798 utils
.writeInt(st
, Byte(FLives
));
5800 utils
.writeInt(st
, LongInt(FArmor
));
5802 utils
.writeInt(st
, LongInt(FAir
));
5804 utils
.writeInt(st
, LongInt(FJetFuel
));
5806 utils
.writeInt(st
, LongInt(FPain
));
5808 utils
.writeInt(st
, LongInt(FKills
));
5810 utils
.writeInt(st
, LongInt(FMonsterKills
));
5812 utils
.writeInt(st
, LongInt(FFrags
));
5814 utils
.writeInt(st
, Byte(FFragCombo
));
5815 // Âðåìÿ ïîñëåäíåãî ôðàãà
5816 utils
.writeInt(st
, LongWord(FLastFrag
));
5818 utils
.writeInt(st
, LongInt(FDeath
));
5820 utils
.writeInt(st
, Byte(FFlag
));
5822 utils
.writeInt(st
, LongInt(FSecrets
));
5824 utils
.writeInt(st
, Byte(FCurrWeap
));
5826 utils
.writeInt(st
, Word(FNextWeap
));
5828 utils
.writeInt(st
, Byte(FNextWeapDelay
));
5829 // Âðåìÿ çàðÿäêè BFG
5830 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
5832 utils
.writeInt(st
, LongInt(FDamageBuffer
));
5833 // Ïîñëåäíèé óäàðèâøèé
5834 utils
.writeInt(st
, Word(FLastSpawnerUID
));
5835 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
5836 utils
.writeInt(st
, Byte(FLastHit
));
5838 Obj_SaveState(st
, @FObj
);
5839 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
5840 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
5841 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
5842 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
5844 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
5845 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
5846 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
5848 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
5849 // Íàëè÷èå êðàñíîãî êëþ÷à
5850 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
5851 // Íàëè÷èå çåëåíîãî êëþ÷à
5852 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
5853 // Íàëè÷èå ñèíåãî êëþ÷à
5854 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
5856 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
5857 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
5858 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
5859 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
5860 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
5862 utils
.writeStr(st
, FModel
.Name
);
5864 utils
.writeInt(st
, Byte(FColor
.R
));
5865 utils
.writeInt(st
, Byte(FColor
.G
));
5866 utils
.writeInt(st
, Byte(FColor
.B
));
5870 procedure TPlayer
.LoadState (st
: TStream
);
5879 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
5880 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
5882 FIamBot
:= utils
.readBool(st
);
5884 FUID
:= utils
.readWord(st
);
5886 str
:= utils
.readStr(st
);
5887 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
5889 FTeam
:= utils
.readByte(st
);
5891 FAlive
:= utils
.readBool(st
);
5892 // Èçðàñõîäîâàë ëè âñå æèçíè
5893 FNoRespawn
:= utils
.readBool(st
);
5895 b
:= utils
.readByte(st
);
5896 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
5898 FHealth
:= utils
.readLongInt(st
);
5900 FLives
:= utils
.readByte(st
);
5902 FArmor
:= utils
.readLongInt(st
);
5904 FAir
:= utils
.readLongInt(st
);
5906 FJetFuel
:= utils
.readLongInt(st
);
5908 FPain
:= utils
.readLongInt(st
);
5910 FKills
:= utils
.readLongInt(st
);
5912 FMonsterKills
:= utils
.readLongInt(st
);
5914 FFrags
:= utils
.readLongInt(st
);
5916 FFragCombo
:= utils
.readByte(st
);
5917 // Âðåìÿ ïîñëåäíåãî ôðàãà
5918 FLastFrag
:= utils
.readLongWord(st
);
5920 FDeath
:= utils
.readLongInt(st
);
5922 FFlag
:= utils
.readByte(st
);
5924 FSecrets
:= utils
.readLongInt(st
);
5926 FCurrWeap
:= utils
.readByte(st
);
5928 FNextWeap
:= utils
.readWord(st
);
5930 FNextWeapDelay
:= utils
.readByte(st
);
5931 // Âðåìÿ çàðÿäêè BFG
5932 FBFGFireCounter
:= utils
.readSmallInt(st
);
5934 FDamageBuffer
:= utils
.readLongInt(st
);
5935 // Ïîñëåäíèé óäàðèâøèé
5936 FLastSpawnerUID
:= utils
.readWord(st
);
5937 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
5938 FLastHit
:= utils
.readByte(st
);
5940 Obj_LoadState(@FObj
, st
);
5941 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
5942 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
5943 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
5944 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
5946 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
5947 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
5948 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
5950 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
5951 // Íàëè÷èå êðàñíîãî êëþ÷à
5952 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
5953 // Íàëè÷èå çåëåíîãî êëþ÷à
5954 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
5955 // Íàëè÷èå ñèíåãî êëþ÷à
5956 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
5958 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
5959 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
5960 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
5961 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
5962 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
5964 str
:= utils
.readStr(st
);
5966 FColor
.R
:= utils
.readByte(st
);
5967 FColor
.G
:= utils
.readByte(st
);
5968 FColor
.B
:= utils
.readByte(st
);
5969 if (self
= gPlayer1
) then
5971 str
:= gPlayer1Settings
.Model
;
5972 FColor
:= gPlayer1Settings
.Color
;
5974 else if (self
= gPlayer2
) then
5976 str
:= gPlayer2Settings
.Model
;
5977 FColor
:= gPlayer2Settings
.Color
;
5979 // Îáíîâëÿåì ìîäåëü èãðîêà
5981 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
5982 FModel
.Color
:= TEAMCOLOR
[FTeam
]
5984 FModel
.Color
:= FColor
;
5988 procedure TPlayer
.AllRulez(Health
: Boolean);
5994 FHealth
:= PLAYER_HP_LIMIT
;
5995 FArmor
:= PLAYER_AP_LIMIT
;
5999 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
6000 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
6001 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6004 procedure TPlayer
.RestoreHealthArmor();
6006 FHealth
:= PLAYER_HP_LIMIT
;
6007 FArmor
:= PLAYER_AP_LIMIT
;
6010 procedure TPlayer
.FragCombo();
6014 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6016 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6018 if FFragCombo
< 5 then
6020 Param
:= FUID
or (FFragCombo
shl 16);
6021 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6022 (FComboEvnt
<= High(gDelayedEvents
)) and
6023 gDelayedEvents
[FComboEvnt
].Pending
and
6024 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6025 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6027 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6028 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6031 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6039 procedure TPlayer
.GiveItem(ItemType
: Byte);
6043 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6045 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6049 if FAir
< AIR_MAX
then
6056 if not (R_BERSERK
in FRulez
) then
6058 Include(FRulez
, R_BERSERK
);
6059 if FBFGFireCounter
< 1 then
6061 FCurrWeap
:= WEAPON_KASTET
;
6063 FModel
.SetWeapon(WEAPON_KASTET
);
6067 FBerserk
:= gTime
+30000;
6069 if FHealth
< PLAYER_HP_SOFT
then
6071 FHealth
:= PLAYER_HP_SOFT
;
6072 FBerserk
:= gTime
+30000;
6077 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6079 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6083 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6085 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6089 if FJetFuel
< JET_MAX
then
6091 FJetFuel
:= JET_MAX
;
6094 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6095 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6097 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6098 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6100 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6102 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6104 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6105 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6108 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6109 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6110 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6111 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6112 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6113 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6114 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6115 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6116 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6118 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6119 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6120 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6121 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6122 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6123 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6124 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6125 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6126 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6129 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6130 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6131 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6132 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6133 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6135 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6136 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6137 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6138 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6139 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6141 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6142 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6143 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6144 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6146 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6149 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6150 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6151 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6153 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6154 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6159 if g_Game_IsNet
and g_Game_IsServer
then
6160 MH_SEND_PlayerStats(FUID
);
6163 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6168 if (Random(5) = 1) and (Times
= 1) then
6171 if BodyInLiquid(0, 0) then
6173 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6174 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6175 if Random(2) = 0 then
6176 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6178 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6182 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6184 for i
:= 1 to Times
do
6186 Anim
:= TAnimation
.Create(id
, False, 3);
6188 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6189 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6195 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6200 if (Random(10) = 1) and (Times
= 1) then
6203 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6205 for i
:= 1 to Times
do
6207 Anim
:= TAnimation
.Create(id
, False, 3);
6209 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6210 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6216 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6218 FSawSound
.Pause(Enable
);
6219 FSawSoundIdle
.Pause(Enable
);
6220 FSawSoundHit
.Pause(Enable
);
6221 FSawSoundSelect
.Pause(Enable
);
6226 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6231 FObj
.Rect
:= PLAYER_CORPSERECT
;
6232 FModelName
:= ModelName
;
6237 FState
:= CORPSE_STATE_MESS
;
6238 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6242 FState
:= CORPSE_STATE_NORMAL
;
6243 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6247 destructor TCorpse
.Destroy();
6254 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6256 procedure TCorpse
.positionChanged (); inline; begin end;
6258 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6260 if (dx
<> 0) or (dy
<> 0) then
6269 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6271 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6272 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6273 w
:= PLAYER_CORPSERECT
.Width
;
6274 h
:= PLAYER_CORPSERECT
.Height
;
6278 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6283 if FState
= CORPSE_STATE_REMOVEME
then
6286 FDamage
:= FDamage
+ Value
;
6288 if FDamage
> 150 then
6290 if FAnimation
<> nil then
6295 FState
:= CORPSE_STATE_REMOVEME
;
6297 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6298 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6299 FModelName
, FColor
);
6300 // Çâóê ìÿñà îò òðóïà:
6301 pm
:= g_PlayerModel_Get(FModelName
);
6302 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6306 if (gBodyKillEvent
<> -1)
6307 and gDelayedEvents
[gBodyKillEvent
].Pending
then
6308 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
6309 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, 0);
6314 Blood
:= g_PlayerModel_GetBlood(FModelName
);
6315 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6316 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6317 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6318 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6319 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6320 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
6324 procedure TCorpse
.Draw();
6326 if FState
= CORPSE_STATE_REMOVEME
then
6329 if FAnimation
<> nil then
6330 FAnimation
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6332 if FAnimationMask
<> nil then
6335 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6342 procedure TCorpse
.Update();
6346 if FState
= CORPSE_STATE_REMOVEME
then
6349 if gTime
mod (GAME_TICK
*2) <> 0 then
6351 g_Obj_Move(@FObj
, True, True, True);
6352 positionChanged(); // this updates spatial accelerators
6356 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6357 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6359 st
:= g_Obj_Move(@FObj
, True, True, True);
6360 positionChanged(); // this updates spatial accelerators
6362 if WordBool(st
and MOVE_FALLOUT
) then
6364 FState
:= CORPSE_STATE_REMOVEME
;
6368 if FAnimation
<> nil then
6369 FAnimation
.Update();
6370 if FAnimationMask
<> nil then
6371 FAnimationMask
.Update();
6375 procedure TCorpse
.SaveState (st
: TStream
);
6382 utils
.writeSign(st
, 'CORP');
6383 utils
.writeInt(st
, Byte(0));
6385 utils
.writeInt(st
, Byte(FState
));
6387 utils
.writeInt(st
, Byte(FDamage
));
6389 utils
.writeInt(st
, Byte(FColor
.R
));
6390 utils
.writeInt(st
, Byte(FColor
.G
));
6391 utils
.writeInt(st
, Byte(FColor
.B
));
6393 Obj_SaveState(st
, @FObj
);
6394 utils
.writeInt(st
, Word(FPlayerUID
));
6396 anim
:= (FAnimation
<> nil);
6397 utils
.writeBool(st
, anim
);
6398 // Åñëè åñòü - ñîõðàíÿåì
6399 if anim
then FAnimation
.SaveState(st
);
6400 // Åñòü ëè ìàñêà àíèìàöèè
6401 anim
:= (FAnimationMask
<> nil);
6402 utils
.writeBool(st
, anim
);
6403 // Åñëè åñòü - ñîõðàíÿåì
6404 if anim
then FAnimationMask
.SaveState(st
);
6408 procedure TCorpse
.LoadState (st
: TStream
);
6415 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6416 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6418 FState
:= utils
.readByte(st
);
6420 FDamage
:= utils
.readByte(st
);
6422 FColor
.R
:= utils
.readByte(st
);
6423 FColor
.G
:= utils
.readByte(st
);
6424 FColor
.B
:= utils
.readByte(st
);
6426 Obj_LoadState(@FObj
, st
);
6427 FPlayerUID
:= utils
.readWord(st
);
6429 anim
:= utils
.readBool(st
);
6430 // Åñëè åñòü - çàãðóæàåì
6433 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6434 FAnimation
.LoadState(st
);
6436 // Åñòü ëè ìàñêà àíèìàöèè
6437 anim
:= utils
.readBool(st
);
6438 // Åñëè åñòü - çàãðóæàåì
6441 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6442 FAnimationMask
.LoadState(st
);
6448 constructor TBot
.Create();
6455 FSpectator
:= False;
6462 for a
:= WP_FIRST
to WP_LAST
do
6464 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6465 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6466 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6470 destructor TBot
.Destroy();
6473 inherited Destroy();
6476 procedure TBot
.Draw();
6480 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6481 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6484 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6486 inherited Respawn(Silent
, Force
);
6489 FSelectedWeapon
:= FCurrWeap
;
6494 procedure TBot
.UpdateCombat();
6507 TTargetRecord
= array of TTarget
;
6509 function Compare(a
, b
: TTarget
): Integer;
6511 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6514 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6516 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6517 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6519 if a
.Dist
> b
.Dist
then // B áëèæå
6521 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6524 else // Ñòðàííî -> A
6529 a
, x1
, y1
, x2
, y2
: Integer;
6530 targets
: TTargetRecord
;
6532 Target
, BestTarget
: TTarget
;
6533 firew
, fireh
: Integer;
6537 vsPlayer
, vsMonster
, ok
: Boolean;
6540 function monsUpdate (mon
: TMonster
): Boolean;
6542 result
:= false; // don't stop
6543 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6545 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6547 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6548 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6550 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6551 if g_TraceVector(x1
, y1
, x2
, y2
) then
6553 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6554 SetLength(targets
, Length(targets
)+1);
6555 with targets
[High(targets
)] do
6562 Rect
:= mon
.Obj
.Rect
;
6563 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6564 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6565 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6574 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6575 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6577 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6578 if FCurrWeap
<> FSelectedWeapon
then
6581 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6582 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6584 RemoveAIFlag('NEEDFIRE');
6587 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6588 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6589 else PressKey(KEY_FIRE
);
6593 // Êîîðäèíàòû ñòâîëà:
6594 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6595 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6597 Target
.UID
:= FTargetUID
;
6600 if Target
.UID
<> 0 then
6601 begin // Öåëü åñòü - íàñòðàèâàåì
6602 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6605 tpla
:= g_Player_Get(Target
.UID
);
6609 if (@FObj
) <> nil then
6616 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6617 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6618 Target
.Rect
:= PLAYER_RECT
;
6619 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6620 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6621 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6622 Target
.IsPlayer
:= True;
6626 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6629 mon
:= g_Monsters_ByUID(Target
.UID
);
6632 Target
.X
:= mon
.Obj
.X
;
6633 Target
.Y
:= mon
.Obj
.Y
;
6635 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6636 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6637 Target
.Rect
:= mon
.Obj
.Rect
;
6638 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6639 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6640 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6641 Target
.IsPlayer
:= False;
6648 begin // Öåëè íåò - îáíóëÿåì
6653 Target
.Visible
:= False;
6654 Target
.Line
:= False;
6655 Target
.IsPlayer
:= False;
6660 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6661 if (not Target
.Line
) or (not Target
.Visible
) then
6665 for a
:= 0 to High(gPlayers
) do
6666 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6667 (gPlayers
[a
].FUID
<> FUID
) and
6668 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6669 (not gPlayers
[a
].NoTarget
) and
6670 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6672 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6673 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6676 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6677 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6679 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6680 if g_TraceVector(x1
, y1
, x2
, y2
) then
6682 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6683 SetLength(targets
, Length(targets
)+1);
6684 with targets
[High(targets
)] do
6686 UID
:= gPlayers
[a
].FUID
;
6687 X
:= gPlayers
[a
].FObj
.X
;
6688 Y
:= gPlayers
[a
].FObj
.Y
;
6691 Rect
:= PLAYER_RECT
;
6692 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6693 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6694 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6702 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6705 // Åñëè åñòü âîçìîæíûå öåëè:
6706 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6707 if targets
<> nil then
6709 // Âûáèðàåì íàèëó÷øóþ öåëü:
6710 BestTarget
:= targets
[0];
6711 if Length(targets
) > 1 then
6712 for a
:= 1 to High(targets
) do
6713 if Compare(BestTarget
, targets
[a
]) = 1 then
6714 BestTarget
:= targets
[a
];
6716 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6717 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6718 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6720 Target
:= BestTarget
;
6722 if (Healthy() = 3) or ((Healthy() = 2)) then
6723 begin // Åñëè çäîðîâû - äîãîíÿåì
6724 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6725 SetAIFlag('GORIGHT', '1');
6726 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6727 SetAIFlag('GOLEFT', '1');
6730 begin // Åñëè ïîáèòû - óáåãàåì
6731 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6732 SetAIFlag('GORIGHT', '1');
6733 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6734 SetAIFlag('GOLEFT', '1');
6737 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6738 SelectWeapon(Abs(x1
-Target
.cX
));
6743 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6744 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6745 if Target
.UID
<> 0 then
6747 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6748 Target
.Y
+ Target
.Rect
.Y
) then
6749 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6750 if (Healthy() = 3) or ((Healthy() = 2)) then
6751 begin // Åñëè çäîðîâû - äîãîíÿåì
6752 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6753 SetAIFlag('GORIGHT', '1');
6754 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6755 SetAIFlag('GOLEFT', '1');
6758 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6760 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6761 SetAIFlag('GORIGHT', '1');
6762 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6763 SetAIFlag('GOLEFT', '1');
6767 begin // Öåëü ïîêà íà "ýêðàíå"
6768 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6769 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6770 FLastVisible
:= gTime
;
6771 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6772 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6774 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6775 SetAIFlag('GORIGHT', '1');
6776 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6777 SetAIFlag('GOLEFT', '1');
6781 // Âûáèðàåì óãîë ââåðõ:
6782 if FDirection
= TDirection
.D_LEFT
then
6783 angle
:= ANGLE_LEFTUP
6785 angle
:= ANGLE_RIGHTUP
;
6787 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6788 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6790 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6791 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6792 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6793 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6794 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6795 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6796 begin // òî íóæíî ñòðåëÿòü ââåðõ
6797 SetAIFlag('NEEDFIRE', '1');
6798 SetAIFlag('NEEDSEEUP', '1');
6801 // Âûáèðàåì óãîë âíèç:
6802 if FDirection
= TDirection
.D_LEFT
then
6803 angle
:= ANGLE_LEFTDOWN
6805 angle
:= ANGLE_RIGHTDOWN
;
6807 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6808 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6810 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6811 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6812 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6813 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6814 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6815 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6816 begin // òî íóæíî ñòðåëÿòü âíèç
6817 SetAIFlag('NEEDFIRE', '1');
6818 SetAIFlag('NEEDSEEDOWN', '1');
6821 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6822 if Target
.Visible
and
6823 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6824 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6826 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6827 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
6828 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6829 begin // òî íóæíî ñòðåëÿòü âïåðåä
6830 SetAIFlag('NEEDFIRE', '1');
6831 SetAIFlag('NEEDSEEDOWN', '');
6832 SetAIFlag('NEEDSEEUP', '');
6834 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6835 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6836 if GetRnd(FDifficult
.CloseJump
) then
6837 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6838 if Abs(FObj
.X
-Target
.X
) < 128 then
6842 if Random(a
) = 0 then
6843 SetAIFlag('NEEDJUMP', '1');
6847 // Åñëè öåëü âñå åùå åñòü:
6848 if Target
.UID
<> 0 then
6849 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
6850 Target
.UID
:= 0 // òî çàáûòü öåëü
6851 else // Åñëè âèäåëè íåäàâíî
6852 begin // íî öåëü óáèëè
6853 if Target
.IsPlayer
then
6854 begin // Öåëü - èãðîê
6855 pla
:= g_Player_Get(Target
.UID
);
6856 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
6857 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6858 Target
.UID
:= 0; // òî çàáûòü öåëü
6861 begin // Öåëü - ìîíñòð
6862 mon
:= g_Monsters_ByUID(Target
.UID
);
6863 if (mon
= nil) or (not mon
.alive
) then
6864 Target
.UID
:= 0; // òî çàáûòü öåëü
6867 end; // if Target.UID <> 0
6869 FTargetUID
:= Target
.UID
;
6871 // Åñëè âîçìîæíûõ öåëåé íåò:
6872 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
6873 if targets
= nil then
6874 if GetAIFlag('ATTACKLEFT') <> '' then
6875 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
6876 RemoveAIFlag('ATTACKLEFT');
6878 SetAIFlag('NEEDJUMP', '1');
6880 if RunDirection() = TDirection
.D_RIGHT
then
6881 begin // Èäåì íå â òó ñòîðîíó
6882 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6883 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
6884 SetAIFlag('NEEDFIRE', '1');
6885 SetAIFlag('GOLEFT', '1');
6889 begin // Èäåì â íóæíóþ ñòîðîíó
6890 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6891 SetAIFlag('NEEDFIRE', '1');
6892 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6893 SetAIFlag('GORIGHT', '1');
6897 if GetAIFlag('ATTACKRIGHT') <> '' then
6898 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
6899 RemoveAIFlag('ATTACKRIGHT');
6901 SetAIFlag('NEEDJUMP', '1');
6903 if RunDirection() = TDirection
.D_LEFT
then
6904 begin // Èäåì íå â òó ñòîðîíó
6905 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6906 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
6907 SetAIFlag('NEEDFIRE', '1');
6908 SetAIFlag('GORIGHT', '1');
6913 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6914 SetAIFlag('NEEDFIRE', '1');
6915 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6916 SetAIFlag('GOLEFT', '1');
6920 //HACK! (does it belongs there?)
6921 RealizeCurrentWeapon();
6923 // Åñëè åñòü âîçìîæíûå öåëè:
6924 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
6925 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6926 for a
:= 0 to High(targets
) do
6928 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
6929 if GetRnd(FDifficult
.DiagFire
) then
6931 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
6932 if FDirection
= TDirection
.D_LEFT
then
6933 angle
:= ANGLE_LEFTUP
6935 angle
:= ANGLE_RIGHTUP
;
6937 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6938 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6940 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6941 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6942 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6943 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6944 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6946 SetAIFlag('NEEDFIRE', '1');
6947 SetAIFlag('NEEDSEEUP', '1');
6950 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
6951 if FDirection
= TDirection
.D_LEFT
then
6952 angle
:= ANGLE_LEFTDOWN
6954 angle
:= ANGLE_RIGHTDOWN
;
6956 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6957 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6959 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6960 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6961 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6962 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6963 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6965 SetAIFlag('NEEDFIRE', '1');
6966 SetAIFlag('NEEDSEEDOWN', '1');
6970 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
6971 if targets
[a
].Line
and targets
[a
].Visible
and
6972 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
6973 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
6975 SetAIFlag('NEEDFIRE', '1');
6980 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
6981 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
6982 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
6983 40+GetInterval(FDifficult
.Cover
, 40)) then
6984 SetAIFlag('NEEDJUMP', '1');
6986 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
6987 ammo
:= GetAmmoByWeapon(FCurrWeap
);
6988 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
6989 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
6991 SetAIFlag('SELECTWEAPON', '1');
6993 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
6994 if GetAIFlag('SELECTWEAPON') = '1' then
6997 RemoveAIFlag('SELECTWEAPON');
7001 procedure TBot
.Update();
7014 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7015 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7017 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7019 if g_debug_BotAIOff
= 3 then
7029 RealizeCurrentWeapon();
7036 procedure TBot
.ReleaseKey(Key
: Byte);
7045 function TBot
.KeyPressed(Key
: Word): Boolean;
7047 Result
:= FKeys
[Key
].Pressed
;
7050 function TBot
.GetAIFlag(aName
: String20
): String20
;
7056 aName
:= LowerCase(aName
);
7058 if FAIFlags
<> nil then
7059 for a
:= 0 to High(FAIFlags
) do
7060 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7062 Result
:= FAIFlags
[a
].Value
;
7067 procedure TBot
.RemoveAIFlag(aName
: String20
);
7071 if FAIFlags
= nil then Exit
;
7073 aName
:= LowerCase(aName
);
7075 for a
:= 0 to High(FAIFlags
) do
7076 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7078 if a
<> High(FAIFlags
) then
7079 for b
:= a
to High(FAIFlags
)-1 do
7080 FAIFlags
[b
] := FAIFlags
[b
+1];
7082 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7087 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7095 aName
:= LowerCase(aName
);
7097 if FAIFlags
<> nil then
7098 for a
:= 0 to High(FAIFlags
) do
7099 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7105 if ok
then FAIFlags
[a
].Value
:= fValue
7108 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7109 with FAIFlags
[High(FAIFlags
)] do
7117 procedure TBot
.UpdateMove
;
7119 procedure GoLeft(Time
: Word = 1);
7121 ReleaseKey(KEY_LEFT
);
7122 ReleaseKey(KEY_RIGHT
);
7123 PressKey(KEY_LEFT
, Time
);
7124 SetDirection(TDirection
.D_LEFT
);
7127 procedure GoRight(Time
: Word = 1);
7129 ReleaseKey(KEY_LEFT
);
7130 ReleaseKey(KEY_RIGHT
);
7131 PressKey(KEY_RIGHT
, Time
);
7132 SetDirection(TDirection
.D_RIGHT
);
7135 function Rnd(a
: Word): Boolean;
7137 Result
:= Random(a
) = 0;
7140 procedure Turn(Time
: Word = 1200);
7142 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7147 ReleaseKey(KEY_LEFT
);
7148 ReleaseKey(KEY_RIGHT
);
7151 function CanRunLeft(): Boolean;
7153 Result
:= not CollideLevel(-1, 0);
7156 function CanRunRight(): Boolean;
7158 Result
:= not CollideLevel(1, 0);
7161 function CanRun(): Boolean;
7163 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7166 procedure Jump(Time
: Word = 30);
7168 PressKey(KEY_JUMP
, Time
);
7171 function NearHole(): Boolean;
7175 { TODO 5 : Ëåñòíèöû }
7176 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7177 for x
:= 1 to PLAYER_RECT
.Width
do
7178 if (not StayOnStep(x
*sx
, 0)) and
7179 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7180 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7189 function BorderHole(): Boolean;
7193 { TODO 5 : Ëåñòíèöû }
7194 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7195 for x
:= 1 to PLAYER_RECT
.Width
do
7196 if (not StayOnStep(x
*sx
, 0)) and
7197 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7198 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7200 for xx
:= x
to x
+32 do
7201 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7211 function NearDeepHole(): Boolean;
7217 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7220 for x
:= 1 to PLAYER_RECT
.Width
do
7221 if (not StayOnStep(x
*sx
, 0)) and
7222 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7223 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7225 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7227 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7232 end else Result
:= False;
7235 function OverDeepHole(): Boolean;
7242 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7244 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7251 function OnGround(): Boolean;
7253 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7256 function OnLadder(): Boolean;
7258 Result
:= FullInStep(0, 0);
7261 function BelowLadder(): Boolean;
7263 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7264 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7265 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7266 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7269 function BelowLiftUp(): Boolean;
7271 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7272 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7273 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7274 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7277 function OnTopLift(): Boolean;
7279 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7282 function CanJumpOver(): Boolean;
7286 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7290 if not CollideLevel(sx
, 0) then Exit
;
7292 for y
:= 1 to BOT_MAXJUMP
do
7293 if CollideLevel(0, -y
) then Exit
else
7294 if not CollideLevel(sx
, -y
) then
7301 function CanJumpUp(Dist
: ShortInt): Boolean;
7308 if CollideLevel(Dist
, 0) then Exit
;
7311 for y
:= 0 to BOT_MAXJUMP
do
7312 if CollideLevel(Dist
, -y
) then
7321 for yy
:= y
+1 to BOT_MAXJUMP
do
7322 if not CollideLevel(Dist
, -yy
) then
7331 for y
:= 0 to BOT_MAXJUMP
do
7332 if CollideLevel(0, -y
) then
7340 if y
< yy
then Exit
;
7345 function IsSafeTrigger(): Boolean;
7350 if gTriggers
= nil then
7352 for a
:= 0 to High(gTriggers
) do
7353 if Collide(gTriggers
[a
].X
,
7356 gTriggers
[a
].Height
) and
7357 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7358 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7359 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7360 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7361 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7366 // Âîçìîæíî, íàæèìàåì êíîïêó:
7367 if Rnd(16) and IsSafeTrigger() then
7370 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7371 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7373 ReleaseKey(KEY_LEFT
);
7374 ReleaseKey(KEY_RIGHT
);
7378 // Èäåì âëåâî, åñëè íàäî áûëî:
7379 if GetAIFlag('GOLEFT') <> '' then
7381 RemoveAIFlag('GOLEFT');
7382 if CanRunLeft() then
7386 // Èäåì âïðàâî, åñëè íàäî áûëî:
7387 if GetAIFlag('GORIGHT') <> '' then
7389 RemoveAIFlag('GORIGHT');
7390 if CanRunRight() then
7394 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7395 if FObj
.X
< -32 then
7398 if FObj
.X
+32 > gMapInfo
.Width
then
7401 // Ïðûãàåì, åñëè íàäî áûëî:
7402 if GetAIFlag('NEEDJUMP') <> '' then
7405 RemoveAIFlag('NEEDJUMP');
7408 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7409 if GetAIFlag('NEEDSEEUP') <> '' then
7412 ReleaseKey(KEY_DOWN
);
7413 PressKey(KEY_UP
, 20);
7414 RemoveAIFlag('NEEDSEEUP');
7417 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7418 if GetAIFlag('NEEDSEEDOWN') <> '' then
7421 ReleaseKey(KEY_DOWN
);
7422 PressKey(KEY_DOWN
, 20);
7423 RemoveAIFlag('NEEDSEEDOWN');
7426 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7427 if GetAIFlag('GOINHOLE') <> '' then
7428 if not OnGround() then
7430 ReleaseKey(KEY_LEFT
);
7431 ReleaseKey(KEY_RIGHT
);
7432 RemoveAIFlag('GOINHOLE');
7433 SetAIFlag('FALLINHOLE', '1');
7436 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7437 if GetAIFlag('FALLINHOLE') <> '' then
7439 RemoveAIFlag('FALLINHOLE');
7441 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7442 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7443 if GetAIFlag('FALLINHOLE') = '' then
7444 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7450 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7452 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7456 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7457 if OnGround() and NearHole() then
7458 if NearDeepHole() then // Åñëè ýòî áåçäíà
7460 0..3: Turn(); // Áåæèì îáðàòíî
7461 4: Jump(); // Ïðûãàåì
7462 5: begin // Ïðûãàåì îáðàòíî
7467 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7468 if GetAIFlag('GOINHOLE') = '' then
7470 0: Turn(); // Íå íóæíî òóäà
7471 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7472 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7473 if BorderHole() then
7474 SetAIFlag('GOINHOLE', '1');
7477 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7478 if (not CanRun()) and OnGround() then
7480 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7481 if CanJumpOver() or OnLadder() then
7483 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7484 if Random(2) = 0 then
7486 if IsSafeTrigger() then
7492 // Îñòàëîñü ìàëî âîçäóõà:
7493 if FAir
< 36 * 2 then
7496 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7497 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7498 if BodyInAcid(0, 0) then
7502 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7504 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7505 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7508 {function TBot.NeedItem(Item: Byte): Byte;
7513 procedure TBot
.SelectWeapon(Dist
: Integer);
7517 function HaveAmmo(weapon
: Byte): Boolean;
7520 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7521 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7522 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7523 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7524 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7525 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7526 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7527 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7528 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7529 else Result
:= True;
7534 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7536 if Dist
> BOT_LONGDIST
then
7537 begin // Äàëüíèé áîé
7539 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7541 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7545 else //if Dist > BOT_UNSAFEDIST then
7546 begin // Áëèæíèé áîé
7548 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7550 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7557 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7559 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7565 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7567 Result
:= inherited PickItem(ItemType
, force
, remove
);
7569 if Result
then SetAIFlag('SELECTWEAPON', '1');
7572 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7574 Result
:= inherited Heal(value
, Soft
);
7577 function TBot
.Healthy(): Byte;
7579 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7580 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7581 else if (FHealth
> 50) then Result
:= 2
7582 else if (FHealth
> 20) then Result
:= 1
7586 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7588 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7589 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7592 procedure TBot
.OnDamage(Angle
: SmallInt);
7600 if (Angle
= 0) or (Angle
= 180) then
7603 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7604 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7606 pla
:= g_Player_Get(FLastSpawnerUID
);
7607 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7608 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7611 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7612 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7614 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7615 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7616 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7621 SetAIFlag('ATTACKLEFT', '1')
7623 SetAIFlag('ATTACKRIGHT', '1');
7627 function TBot
.RunDirection(): TDirection
;
7629 if Abs(Vel
.X
) >= 1 then
7631 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7633 Result
:= FDirection
;
7636 function TBot
.GetRnd(a
: Byte): Boolean;
7638 if a
= 0 then Result
:= False
7639 else if a
= 255 then Result
:= True
7640 else Result
:= Random(256) > 255-a
;
7643 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7645 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7649 procedure TDifficult
.save (st
: TStream
);
7651 utils
.writeInt(st
, Byte(DiagFire
));
7652 utils
.writeInt(st
, Byte(InvisFire
));
7653 utils
.writeInt(st
, Byte(DiagPrecision
));
7654 utils
.writeInt(st
, Byte(FlyPrecision
));
7655 utils
.writeInt(st
, Byte(Cover
));
7656 utils
.writeInt(st
, Byte(CloseJump
));
7657 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7658 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7661 procedure TDifficult
.load (st
: TStream
);
7663 DiagFire
:= utils
.readByte(st
);
7664 InvisFire
:= utils
.readByte(st
);
7665 DiagPrecision
:= utils
.readByte(st
);
7666 FlyPrecision
:= utils
.readByte(st
);
7667 Cover
:= utils
.readByte(st
);
7668 CloseJump
:= utils
.readByte(st
);
7669 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7670 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7674 procedure TBot
.SaveState (st
: TStream
);
7679 inherited SaveState(st
);
7680 utils
.writeSign(st
, 'BOT0');
7682 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7684 utils
.writeInt(st
, Word(FTargetUID
));
7685 // Âðåìÿ ïîòåðè öåëè
7686 utils
.writeInt(st
, LongWord(FLastVisible
));
7687 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7688 dw
:= Length(FAIFlags
);
7689 utils
.writeInt(st
, LongInt(dw
));
7691 for i
:= 0 to dw
-1 do
7693 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7694 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7696 // Íàñòðîéêè ñëîæíîñòè
7697 FDifficult
.save(st
);
7701 procedure TBot
.LoadState (st
: TStream
);
7706 inherited LoadState(st
);
7707 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7709 FSelectedWeapon
:= utils
.readByte(st
);
7711 FTargetUID
:= utils
.readWord(st
);
7712 // Âðåìÿ ïîòåðè öåëè
7713 FLastVisible
:= utils
.readLongWord(st
);
7714 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7715 dw
:= utils
.readLongInt(st
);
7716 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7717 SetLength(FAIFlags
, dw
);
7719 for i
:= 0 to dw
-1 do
7721 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7722 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7724 // Íàñòðîéêè ñëîæíîñòè
7725 FDifficult
.load(st
);
7730 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);