1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
24 {$IFDEF USE_MEMPOOL}mempool
,{$ENDIF}
25 e_graphics
, g_playermodel
, g_basic
, g_textures
,
26 g_weapons
, g_phys
, g_sound
, g_saveload
, MAPDEF
,
59 AmmoLimits
: Array [0..1] of Array [A_BULLETS
..A_HIGH
] of Word =
60 ((200, 50, 50, 300, 100),
61 (400, 100, 100, 600, 200));
82 ANGLE_NONE
= Low(SmallInt);
84 CORPSE_STATE_REMOVEME
= 0;
85 CORPSE_STATE_NORMAL
= 1;
86 CORPSE_STATE_MESS
= 2;
88 PLAYER_RECT
: TRectWH
= (X
:15; Y
:12; Width
:34; Height
:52);
89 PLAYER_RECT_CX
= 15+(34 div 2);
90 PLAYER_RECT_CY
= 12+(52 div 2);
91 PLAYER_CORPSERECT
: TRectWH
= (X
:15; Y
:48; Width
:34; Height
:16);
94 PLAYER_HP_LIMIT
= 200;
96 PLAYER_AP_LIMIT
= 200;
99 PLAYER1_DEF_COLOR
: TRGB
= (R
:64; G
:175; B
:48);
100 PLAYER2_DEF_COLOR
: TRGB
= (R
:96; G
:96; B
:96);
116 TPlayerStatArray
= Array of TPlayerStat
;
118 TPlayerSavedState
= record
126 Ammo
: Array [A_BULLETS
..A_HIGH
] of Word;
127 MaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
128 Weapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
129 Rulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
138 TPlayer
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
146 FDirection
: TDirection
;
154 FMonsterKills
: Integer;
160 FCanJetpack
: Boolean;
166 FNextWeapDelay
: Byte; // frames
167 FBFGFireCounter
: SmallInt;
168 FLastSpawnerUID
: Word;
172 FSpectatePlayer
: Integer;
173 FFirePainTime
: Integer;
176 FSavedState
: TPlayerSavedState
;
178 FModel
: TPlayerModel
;
179 FPunchAnim
: TAnimation
;
182 FActionForce
: Boolean;
183 FActionChanged
: Boolean;
185 FFireAngle
: SmallInt;
187 FShellTimer
: Integer;
189 FSawSound
: TPlayableSound
;
190 FSawSoundIdle
: TPlayableSound
;
191 FSawSoundHit
: TPlayableSound
;
192 FSawSoundSelect
: TPlayableSound
;
193 FJetSoundOn
: TPlayableSound
;
194 FJetSoundOff
: TPlayableSound
;
195 FJetSoundFly
: TPlayableSound
;
199 FJustTeleported
: Boolean;
201 mEDamageType
: Integer;
204 function CollideLevel(XInc
, YInc
: Integer): Boolean;
205 function StayOnStep(XInc
, YInc
: Integer): Boolean;
206 function HeadInLiquid(XInc
, YInc
: Integer): Boolean;
207 function BodyInLiquid(XInc
, YInc
: Integer): Boolean;
208 function BodyInAcid(XInc
, YInc
: Integer): Boolean;
209 function FullInLift(XInc
, YInc
: Integer): Integer;
210 {procedure CollideItem();}
211 procedure FlySmoke(Times
: DWORD
= 1);
212 procedure OnFireFlame(Times
: DWORD
= 1);
213 function GetAmmoByWeapon(Weapon
: Byte): Word;
214 procedure SetAction(Action
: Byte; Force
: Boolean = False);
215 procedure OnDamage(Angle
: SmallInt); virtual;
216 function firediry(): Integer;
219 procedure Run(Direction
: TDirection
);
220 procedure NextWeapon();
221 procedure PrevWeapon();
228 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
229 procedure resetWeaponQueue ();
230 function hasAmmoForWeapon (weapon
: Byte): Boolean;
232 procedure doDamage (v
: Integer);
234 function followCorpse(): Boolean;
237 FDamageBuffer
: Integer;
239 FAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
240 FMaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
241 FWeapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
242 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
244 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
245 FReloading
: Array [WP_FIRST
..WP_LAST
] of Word;
246 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
247 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
249 FPreferredTeam
: Byte;
252 FWantsInGame
: Boolean;
256 FActualModelName
: string;
263 // debug: viewport offset
264 viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer;
266 function isValidViewPort (): Boolean; inline;
268 constructor Create(); virtual;
269 destructor Destroy(); override;
270 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
271 function GetRespawnPoint(): Byte;
272 procedure PressKey(Key
: Byte; Time
: Word = 1);
273 procedure ReleaseKeys();
274 procedure SetModel(ModelName
: String);
275 procedure SetColor(Color
: TRGB
);
276 procedure SetWeapon(W
: Byte);
277 function IsKeyPressed(K
: Byte): Boolean;
278 function GetKeys(): Byte;
279 function PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean; virtual;
280 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
281 function Collide(Panel
: TPanel
): Boolean; overload
;
282 function Collide(X
, Y
: Integer): Boolean; overload
;
283 procedure SetDirection(Direction
: TDirection
);
284 procedure GetSecret();
285 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
287 procedure Push(vx
, vy
: Integer);
288 procedure ChangeModel(ModelName
: String);
289 procedure SwitchTeam
;
290 procedure ChangeTeam(Team
: Byte);
292 function GetFlag(Flag
: Byte): Boolean;
293 procedure SetFlag(Flag
: Byte);
294 function DropFlag(): Boolean;
295 procedure AllRulez(Health
: Boolean);
296 procedure RestoreHealthArmor();
297 procedure FragCombo();
298 procedure GiveItem(ItemType
: Byte);
299 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
300 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
301 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
302 procedure MakeBloodSimple(Count
: Word);
303 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
304 procedure Reset(Force
: Boolean);
305 procedure Spectate(NoMove
: Boolean = False);
306 procedure SwitchNoClip
;
307 procedure SoftReset();
308 procedure Draw(); virtual;
309 procedure DrawPain();
310 procedure DrawPickup();
311 procedure DrawRulez();
313 procedure DrawIndicator();
314 procedure DrawBubble();
316 procedure Update(); virtual;
317 procedure RememberState();
318 procedure RecallState();
319 procedure SaveState (st
: TStream
); virtual;
320 procedure LoadState (st
: TStream
); virtual;
321 procedure PauseSounds(Enable
: Boolean);
322 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
323 procedure DoLerp(Level
: Integer = 2);
324 procedure SetLerp(XTo
, YTo
: Integer);
325 procedure QueueWeaponSwitch(Weapon
: Byte);
326 procedure RealizeCurrentWeapon();
328 procedure JetpackOff
;
329 procedure CatchFire(Attacker
: Word);
331 //WARNING! this does nothing for now, but still call it!
332 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
334 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
335 procedure moveBy (dx
, dy
: Integer); inline;
338 property Vel
: TPoint2i read FObj
.Vel
;
339 property Obj
: TObj read FObj
;
341 property Name
: String read FName write FName
;
342 property Model
: TPlayerModel read FModel
;
343 property Health
: Integer read FHealth write FHealth
;
344 property Lives
: Byte read FLives write FLives
;
345 property Armor
: Integer read FArmor write FArmor
;
346 property Air
: Integer read FAir write FAir
;
347 property JetFuel
: Integer read FJetFuel write FJetFuel
;
348 property Frags
: Integer read FFrags write FFrags
;
349 property Death
: Integer read FDeath write FDeath
;
350 property Kills
: Integer read FKills write FKills
;
351 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
352 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
353 property Secrets
: Integer read FSecrets
;
354 property GodMode
: Boolean read FGodMode write FGodMode
;
355 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
356 property NoReload
: Boolean read FNoReload write FNoReload
;
357 property alive
: Boolean read FAlive write FAlive
;
358 property Flag
: Byte read FFlag
;
359 property Team
: Byte read FTeam write FTeam
;
360 property Direction
: TDirection read FDirection
;
361 property GameX
: Integer read FObj
.X write FObj
.X
;
362 property GameY
: Integer read FObj
.Y write FObj
.Y
;
363 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
364 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
365 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
366 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
367 property IncCam
: Integer read FIncCam write FIncCam
;
368 property UID
: Word read FUID write FUID
;
369 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
370 property NetTime
: LongWord read FNetTime write FNetTime
;
373 property eName
: String read FName write FName
;
374 property eHealth
: Integer read FHealth write FHealth
;
375 property eLives
: Byte read FLives write FLives
;
376 property eArmor
: Integer read FArmor write FArmor
;
377 property eAir
: Integer read FAir write FAir
;
378 property eJetFuel
: Integer read FJetFuel write FJetFuel
;
379 property eFrags
: Integer read FFrags write FFrags
;
380 property eDeath
: Integer read FDeath write FDeath
;
381 property eKills
: Integer read FKills write FKills
;
382 property eCurrWeap
: Byte read FCurrWeap write FCurrWeap
;
383 property eMonsterKills
: Integer read FMonsterKills write FMonsterKills
;
384 property eSecrets
: Integer read FSecrets write FSecrets
;
385 property eGodMode
: Boolean read FGodMode write FGodMode
;
386 property eNoTarget
: Boolean read FNoTarget write FNoTarget
;
387 property eNoReload
: Boolean read FNoReload write FNoReload
;
388 property eAlive
: Boolean read FAlive write FAlive
;
389 property eFlag
: Byte read FFlag
;
390 property eTeam
: Byte read FTeam write FTeam
;
391 property eDirection
: TDirection read FDirection
;
392 property eGameX
: Integer read FObj
.X write FObj
.X
;
393 property eGameY
: Integer read FObj
.Y write FObj
.Y
;
394 property eGameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
395 property eGameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
396 property eGameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
397 property eGameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
398 property eIncCam
: Integer read FIncCam write FIncCam
;
399 property eUID
: Word read FUID
;
400 property eJustTeleported
: Boolean read FJustTeleported
;
401 property eNetTime
: LongWord read FNetTime
;
403 // set this before assigning something to `eDamage`
404 property eDamageType
: Integer read mEDamageType write mEDamageType
;
405 property eDamage
: Integer write doDamage
;
416 WeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
417 CloseWeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
418 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
421 procedure save (st
: TStream
);
422 procedure load (st
: TStream
);
430 TBot
= class(TPlayer
)
432 FSelectedWeapon
: Byte;
435 FAIFlags
: Array of TAIFlag
;
436 FDifficult
: TDifficult
;
438 function GetRnd(a
: Byte): Boolean;
439 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
440 function RunDirection(): TDirection
;
441 function FullInStep(XInc
, YInc
: Integer): Boolean;
442 //function NeedItem(Item: Byte): Byte;
443 procedure SelectWeapon(Dist
: Integer);
444 procedure SetAIFlag(aName
, fValue
: String20
);
445 function GetAIFlag(aName
: String20
): String20
;
446 procedure RemoveAIFlag(aName
: String20
);
447 function Healthy(): Byte;
448 procedure UpdateMove();
449 procedure UpdateCombat();
450 function KeyPressed(Key
: Word): Boolean;
451 procedure ReleaseKey(Key
: Byte);
452 function TargetOnScreen(TX
, TY
: Integer): Boolean;
453 procedure OnDamage(Angle
: SmallInt); override;
456 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
457 constructor Create(); override;
458 destructor Destroy(); override;
459 procedure Draw(); override;
460 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
461 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
462 procedure Update(); override;
463 procedure SaveState (st
: TStream
); override;
464 procedure LoadState (st
: TStream
); override;
476 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
477 procedure moveBy (dx
, dy
: Integer); inline;
479 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
493 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
494 procedure moveBy (dx
, dy
: Integer); inline;
496 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
499 TCorpse
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
508 FAnimation
: TAnimation
;
509 FAnimationMask
: TAnimation
;
512 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
513 destructor Destroy(); override;
514 procedure Damage(Value
: Word; vx
, vy
: Integer);
517 procedure SaveState (st
: TStream
);
518 procedure LoadState (st
: TStream
);
520 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
521 procedure moveBy (dx
, dy
: Integer); inline;
523 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
525 function ObjPtr (): PObj
; inline;
527 property Obj
: TObj read FObj
; // copies object
528 property State
: Byte read FState
;
529 property Mess
: Boolean read FMess
;
532 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
538 gPlayers
: Array of TPlayer
;
539 gCorpses
: Array of TCorpse
;
540 gGibs
: Array of TGib
;
541 gShells
: Array of TShell
;
542 gTeamStat
: TTeamStat
;
543 gFly
: Boolean = False;
544 gAimLine
: Boolean = False;
545 gChatBubble
: Byte = 0;
546 gPlayerIndicator
: Boolean = True;
550 MAX_RUNVEL
: Integer = 8;
551 VEL_JUMP
: Integer = 10;
552 SHELL_TIMEOUT
: Cardinal = 60000;
554 function Lerp(X
, Y
, Factor
: Integer): Integer;
556 procedure g_Gibs_SetMax(Count
: Word);
557 function g_Gibs_GetMax(): Word;
558 procedure g_Corpses_SetMax(Count
: Word);
559 function g_Corpses_GetMax(): Word;
560 procedure g_Shells_SetMax(Count
: Word);
561 function g_Shells_GetMax(): Word;
563 procedure g_Player_Init();
564 procedure g_Player_Free();
565 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
566 function g_Player_CreateFromState (st
: TStream
): Word;
567 procedure g_Player_Remove(UID
: Word);
568 procedure g_Player_ResetTeams();
569 procedure g_Player_UpdateAll();
570 procedure g_Player_DrawAll();
571 procedure g_Player_DrawDebug(p
: TPlayer
);
572 procedure g_Player_DrawHealth();
573 procedure g_Player_RememberAll();
574 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
575 function g_Player_Get(UID
: Word): TPlayer
;
576 function g_Player_GetCount(): Byte;
577 function g_Player_GetStats(): TPlayerStatArray
;
578 function g_Player_ValidName(Name
: String): Boolean;
579 procedure g_Player_CreateCorpse(Player
: TPlayer
);
580 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
581 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
582 procedure g_Player_UpdatePhysicalObjects();
583 procedure g_Player_DrawCorpses();
584 procedure g_Player_DrawShells();
585 procedure g_Player_RemoveAllCorpses();
586 procedure g_Player_Corpses_SaveState (st
: TStream
);
587 procedure g_Player_Corpses_LoadState (st
: TStream
);
588 procedure g_Bot_Add(Team
, Difficult
: Byte);
589 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1);
590 procedure g_Bot_MixNames();
591 procedure g_Bot_RemoveAll();
596 {$INCLUDE ../nogl/noGLuses.inc}
597 {$IFDEF ENABLE_HOLMES}
600 e_log
, g_map
, g_items
, g_console
, g_gfx
, Math
,
601 g_options
, g_triggers
, g_menu
, g_game
, g_grid
,
602 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
,
603 g_net
, g_netmsg
, g_window
,
606 const PLR_SAVE_VERSION
= 0;
616 diag_precision
: Byte;
620 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
621 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
622 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
626 TIME_RESPAWN1
= 1500;
627 TIME_RESPAWN2
= 2000;
628 TIME_RESPAWN3
= 3000;
631 JET_MAX
= 540; // ~30 sec
632 PLAYER_SUIT_TIME
= 30000;
633 PLAYER_INVUL_TIME
= 30000;
634 PLAYER_INVIS_TIME
= 35000;
635 FRAG_COMBO_TIME
= 3000;
639 ANGLE_RIGHTDOWN
= -35;
641 ANGLE_LEFTDOWN
= -145;
642 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
643 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
646 BOT_UNSAFEDIST
= 128;
647 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
649 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
650 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
651 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
652 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
653 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
654 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
655 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
656 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
657 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
658 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
659 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
660 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
661 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
662 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
663 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
664 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
665 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
666 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
667 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
668 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
669 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
670 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
671 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
672 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
673 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
674 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
676 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
677 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
679 BOTNAMES_FILENAME
= 'botnames.txt';
680 BOTLIST_FILENAME
= 'botlist.txt';
684 MaxCorpses
: Word = 20;
685 MaxShells
: Word = 300;
686 CurrentGib
: Integer = 0;
687 CurrentShell
: Integer = 0;
688 BotNames
: Array of String;
689 BotList
: Array of TBotProfile
;
692 function Lerp(X
, Y
, Factor
: Integer): Integer;
694 Result
:= X
+ ((Y
- X
) div Factor
);
697 function SameTeam(UID1
, UID2
: Word): Boolean;
701 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
702 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
704 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
706 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
707 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
709 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
712 procedure g_Gibs_SetMax(Count
: Word);
715 SetLength(gGibs
, Count
);
717 if CurrentGib
>= Count
then
721 function g_Gibs_GetMax(): Word;
726 procedure g_Shells_SetMax(Count
: Word);
729 SetLength(gShells
, Count
);
731 if CurrentShell
>= Count
then
735 function g_Shells_GetMax(): Word;
741 procedure g_Corpses_SetMax(Count
: Word);
744 SetLength(gCorpses
, Count
);
747 function g_Corpses_GetMax(): Word;
749 Result
:= MaxCorpses
;
752 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
762 // Åñòü ëè ìåñòî â gPlayers:
763 if gPlayers
<> nil then
764 for a
:= 0 to High(gPlayers
) do
765 if gPlayers
[a
] = nil then
771 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
774 SetLength(gPlayers
, Length(gPlayers
)+1);
778 // Ñîçäàåì îáúåêò èãðîêà:
780 gPlayers
[a
] := TBot
.Create()
782 gPlayers
[a
] := TPlayer
.Create();
785 gPlayers
[a
].FActualModelName
:= ModelName
;
786 gPlayers
[a
].SetModel(ModelName
);
788 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
789 if gPlayers
[a
].FModel
= nil then
793 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
797 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
798 if Random(2) = 0 then
802 gPlayers
[a
].FPreferredTeam
:= Team
;
804 case gGameSettings
.GameMode
of
805 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
807 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
809 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
812 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
813 gPlayers
[a
].FColor
:= Color
;
814 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
815 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
817 gPlayers
[a
].FModel
.Color
:= Color
;
819 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
820 gPlayers
[a
].FAlive
:= False;
822 Result
:= gPlayers
[a
].FUID
;
825 function g_Player_CreateFromState (st
: TStream
): Word;
832 if (st
= nil) then exit
; //???
835 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
836 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
839 Bot
:= utils
.readBool(st
);
844 // Åñòü ëè ìåñòî â gPlayers:
845 for a
:= 0 to High(gPlayers
) do if (gPlayers
[a
] = nil) then begin ok
:= true; break
; end;
847 // Íåò ìåñòà - ðàñøèðÿåì gPlayers
850 SetLength(gPlayers
, Length(gPlayers
)+1);
854 // Ñîçäàåì îáúåêò èãðîêà
856 gPlayers
[a
] := TBot
.Create()
858 gPlayers
[a
] := TPlayer
.Create();
859 gPlayers
[a
].FIamBot
:= Bot
;
860 gPlayers
[a
].FPhysics
:= True;
863 gPlayers
[a
].FUID
:= utils
.readWord(st
);
865 gPlayers
[a
].FName
:= utils
.readStr(st
);
867 gPlayers
[a
].FTeam
:= utils
.readByte(st
);
868 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
870 gPlayers
[a
].FAlive
:= utils
.readBool(st
);
871 // Èçðàñõîäîâàë ëè âñå æèçíè
872 gPlayers
[a
].FNoRespawn
:= utils
.readBool(st
);
874 b
:= utils
.readByte(st
);
875 if b
= 1 then gPlayers
[a
].FDirection
:= TDirection
.D_LEFT
else gPlayers
[a
].FDirection
:= TDirection
.D_RIGHT
; // b = 2
877 gPlayers
[a
].FHealth
:= utils
.readLongInt(st
);
879 gPlayers
[a
].FLives
:= utils
.readByte(st
);
881 gPlayers
[a
].FArmor
:= utils
.readLongInt(st
);
883 gPlayers
[a
].FAir
:= utils
.readLongInt(st
);
885 gPlayers
[a
].FJetFuel
:= utils
.readLongInt(st
);
887 gPlayers
[a
].FPain
:= utils
.readLongInt(st
);
889 gPlayers
[a
].FKills
:= utils
.readLongInt(st
);
891 gPlayers
[a
].FMonsterKills
:= utils
.readLongInt(st
);
893 gPlayers
[a
].FFrags
:= utils
.readLongInt(st
);
895 gPlayers
[a
].FFragCombo
:= utils
.readByte(st
);
896 // Âðåìÿ ïîñëåäíåãî ôðàãà
897 gPlayers
[a
].FLastFrag
:= utils
.readLongWord(st
);
899 gPlayers
[a
].FDeath
:= utils
.readLongInt(st
);
901 gPlayers
[a
].FFlag
:= utils
.readByte(st
);
903 gPlayers
[a
].FSecrets
:= utils
.readLongInt(st
);
905 gPlayers
[a
].FCurrWeap
:= utils
.readByte(st
);
906 // Ñëåäóþùåå æåëàåìîå îðóæèå
907 gPlayers
[a
].FNextWeap
:= utils
.readWord(st
);
909 gPlayers
[a
].FNextWeapDelay
:= utils
.readByte(st
);
911 gPlayers
[a
].FBFGFireCounter
:= utils
.readSmallInt(st
);
913 gPlayers
[a
].FDamageBuffer
:= utils
.readLongInt(st
);
914 // Ïîñëåäíèé óäàðèâøèé
915 gPlayers
[a
].FLastSpawnerUID
:= utils
.readWord(st
);
916 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
917 gPlayers
[a
].FLastHit
:= utils
.readByte(st
);
919 Obj_LoadState(@gPlayers
[a
].FObj
, st
);
920 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
921 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FAmmo
[i
] := utils
.readWord(st
);
922 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
923 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FMaxAmmo
[i
] := utils
.readWord(st
);
925 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FWeapon
[i
] := utils
.readBool(st
);
926 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
927 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FReloading
[i
] := utils
.readWord(st
);
929 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
930 // Íàëè÷èå êðàñíîãî êëþ÷à
931 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
932 // Íàëè÷èå çåëåíîãî êëþ÷à
933 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
934 // Íàëè÷èå ñèíåãî êëþ÷à
935 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
937 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_BERSERK
);
938 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
939 for i
:= MR_SUIT
to MR_MAX
do gPlayers
[a
].FMegaRulez
[i
] := utils
.readLongWord(st
);
940 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
941 for i
:= T_RESPAWN
to T_FLAGCAP
do gPlayers
[a
].FTime
[i
] := utils
.readLongWord(st
);
944 gPlayers
[a
].FActualModelName
:= utils
.readStr(st
);
946 gPlayers
[a
].FColor
.R
:= utils
.readByte(st
);
947 gPlayers
[a
].FColor
.G
:= utils
.readByte(st
);
948 gPlayers
[a
].FColor
.B
:= utils
.readByte(st
);
949 // Îáíîâëÿåì ìîäåëü èãðîêà
950 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
952 // Íåò ìîäåëè - ñîçäàíèå íåâîçìîæíî
953 if (gPlayers
[a
].FModel
= nil) then
957 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
961 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû
962 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
963 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
965 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
967 result
:= gPlayers
[a
].FUID
;
971 procedure g_Player_ResetTeams();
975 if g_Game_IsClient
then
977 if gPlayers
= nil then
979 for a
:= Low(gPlayers
) to High(gPlayers
) do
980 if gPlayers
[a
] <> nil then
981 case gGameSettings
.GameMode
of
983 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
985 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
986 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
987 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
990 gPlayers
[a
].ChangeTeam(TEAM_RED
)
992 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
995 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
999 procedure g_Bot_Add(Team
, Difficult
: Byte);
1002 _name
, _model
: String;
1005 if not g_Game_IsServer
then Exit
;
1007 // Ñïèñîê íàçâàíèé ìîäåëåé:
1008 m
:= g_PlayerModel_GetNames();
1013 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1014 Team
:= TEAM_COOP
// COOP
1016 if gGameSettings
.GameMode
= GM_DM
then
1017 Team
:= TEAM_NONE
// DM
1019 if Team
= TEAM_NONE
then // CTF / TDM
1021 // Àâòîáàëàíñ êîìàíä:
1025 for a
:= 0 to High(gPlayers
) do
1026 if gPlayers
[a
] <> nil then
1028 if gPlayers
[a
].Team
= TEAM_RED
then
1031 if gPlayers
[a
].Team
= TEAM_BLUE
then
1041 if Random(2) = 0 then
1047 // Âûáèðàåì áîòó èìÿ:
1049 if BotNames
<> nil then
1050 for a
:= 0 to High(BotNames
) do
1051 if g_Player_ValidName(BotNames
[a
]) then
1053 _name
:= BotNames
[a
];
1057 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
1060 _name
:= Format('DFBOT%.2d', [Random(100)]);
1061 until g_Player_ValidName(_name
);
1063 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1064 _model
:= m
[Random(Length(m
))];
1067 with g_Player_Get(g_Player_Create(_model
,
1068 _RGB(Min(Random(9)*32, 255),
1069 Min(Random(9)*32, 255),
1070 Min(Random(9)*32, 255)),
1071 Team
, True)) as TBot
do
1076 1: FDifficult
:= DIFFICULT_EASY
;
1077 2: FDifficult
:= DIFFICULT_MEDIUM
;
1078 else FDifficult
:= DIFFICULT_HARD
;
1081 for a
:= WP_FIRST
to WP_LAST
do
1083 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1084 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1085 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1088 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1090 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1091 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1096 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1);
1099 _name
, _model
: String;
1102 if not g_Game_IsServer
then Exit
;
1104 // Ñïèñîê íàçâàíèé ìîäåëåé:
1105 m
:= g_PlayerModel_GetNames();
1110 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1111 Team
:= TEAM_COOP
// COOP
1113 if gGameSettings
.GameMode
= GM_DM
then
1114 Team
:= TEAM_NONE
// DM
1116 if Team
= TEAM_NONE
then
1117 Team
:= BotList
[num
].team
; // CTF / TDM
1119 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1120 lName
:= AnsiLowerCase(lName
);
1121 if (num
< 0) or (num
> Length(BotList
)-1) then
1123 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1124 for a
:= 0 to High(BotList
) do
1125 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1134 _name
:= BotList
[num
].name
;
1135 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1136 if not g_Player_ValidName(_name
) then
1138 _name
:= Format('DFBOT%.2d', [Random(100)]);
1139 until g_Player_ValidName(_name
);
1142 _model
:= BotList
[num
].model
;
1143 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1144 if not InSArray(_model
, m
) then
1145 _model
:= m
[Random(Length(m
))];
1148 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1152 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1153 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1154 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1155 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1156 FDifficult
.Cover
:= BotList
[num
].cover
;
1157 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1159 for a
:= WP_FIRST
to WP_LAST
do
1161 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1162 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1163 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1166 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1168 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1172 procedure g_Bot_RemoveAll();
1176 if not g_Game_IsServer
then Exit
;
1177 if gPlayers
= nil then Exit
;
1179 for a
:= 0 to High(gPlayers
) do
1180 if gPlayers
[a
] <> nil then
1181 if gPlayers
[a
] is TBot
then
1183 gPlayers
[a
].Lives
:= 0;
1184 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1185 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1186 g_Player_Remove(gPlayers
[a
].FUID
);
1192 procedure g_Bot_MixNames();
1197 if BotNames
<> nil then
1198 for a
:= 0 to High(BotNames
) do
1200 b
:= Random(Length(BotNames
));
1202 Botnames
[a
] := BotNames
[b
];
1207 procedure g_Player_Remove(UID
: Word);
1211 if gPlayers
= nil then Exit
;
1213 if g_Game_IsServer
and g_Game_IsNet
then
1214 MH_SEND_PlayerDelete(UID
);
1216 for i
:= 0 to High(gPlayers
) do
1217 if gPlayers
[i
] <> nil then
1218 if gPlayers
[i
].FUID
= UID
then
1220 if gPlayers
[i
] is TPlayer
then
1221 TPlayer(gPlayers
[i
]).Free()
1223 TBot(gPlayers
[i
]).Free();
1229 procedure g_Player_Init();
1239 if not FileExists(DataDir
+ BOTNAMES_FILENAME
) then
1242 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1243 AssignFile(F
, DataDir
+ BOTNAMES_FILENAME
);
1254 SetLength(BotNames
, Length(BotNames
)+1);
1255 BotNames
[High(BotNames
)] := s
;
1263 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1264 config
:= TConfig
.CreateFile(DataDir
+ BOTLIST_FILENAME
);
1268 while config
.SectionExists(IntToStr(a
)) do
1270 SetLength(BotList
, Length(BotList
)+1);
1272 with BotList
[High(BotList
)] do
1275 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1277 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1279 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1284 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1285 color
.R
:= StrToIntDef(sa
[0], 0);
1286 color
.G
:= StrToIntDef(sa
[1], 0);
1287 color
.B
:= StrToIntDef(sa
[2], 0);
1288 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1289 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1290 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1291 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1292 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1293 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1294 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1295 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1296 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1297 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1298 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1299 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1300 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1301 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1302 if Length(sa
) = 10 then
1304 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1305 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1306 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1307 if Length(sa
) = 10 then
1309 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1311 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1312 if Length(sa) = 10 then
1314 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1323 procedure g_Player_Free();
1327 if gPlayers
<> nil then
1329 for i
:= 0 to High(gPlayers
) do
1330 if gPlayers
[i
] <> nil then
1332 if gPlayers
[i
] is TPlayer
then
1333 TPlayer(gPlayers
[i
]).Free()
1335 TBot(gPlayers
[i
]).Free();
1346 procedure g_Player_UpdateAll();
1350 if gPlayers
= nil then Exit
;
1352 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1353 for i
:= 0 to High(gPlayers
) do
1355 if gPlayers
[i
] <> nil then
1357 if gPlayers
[i
] is TPlayer
then
1359 gPlayers
[i
].Update();
1360 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1364 // bot updates weapons in `UpdateCombat()`
1365 TBot(gPlayers
[i
]).Update();
1369 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1372 procedure g_Player_DrawAll();
1376 if gPlayers
= nil then Exit
;
1378 for i
:= 0 to High(gPlayers
) do
1379 if gPlayers
[i
] <> nil then
1380 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1381 else TBot(gPlayers
[i
]).Draw();
1384 procedure g_Player_DrawDebug(p
: TPlayer
);
1388 if p
= nil then Exit
;
1389 if (@p
.FObj
) = nil then Exit
;
1391 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1393 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1394 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1395 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1396 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1397 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1398 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1401 procedure g_Player_DrawHealth();
1406 if gPlayers
= nil then Exit
;
1407 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1409 for i
:= 0 to High(gPlayers
) do
1410 if gPlayers
[i
] <> nil then
1412 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1413 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1414 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1415 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1416 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1417 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1421 function g_Player_Get(UID
: Word): TPlayer
;
1427 if gPlayers
= nil then
1430 for a
:= 0 to High(gPlayers
) do
1431 if gPlayers
[a
] <> nil then
1432 if gPlayers
[a
].FUID
= UID
then
1434 Result
:= gPlayers
[a
];
1439 function g_Player_GetCount(): Byte;
1445 if gPlayers
= nil then
1448 for a
:= 0 to High(gPlayers
) do
1449 if gPlayers
[a
] <> nil then
1450 Result
:= Result
+ 1;
1453 function g_Player_GetStats(): TPlayerStatArray
;
1459 if gPlayers
= nil then Exit
;
1461 for a
:= 0 to High(gPlayers
) do
1462 if gPlayers
[a
] <> nil then
1464 SetLength(Result
, Length(Result
)+1);
1465 with Result
[High(Result
)] do
1467 Ping
:= gPlayers
[a
].FPing
;
1468 Loss
:= gPlayers
[a
].FLoss
;
1469 Name
:= gPlayers
[a
].FName
;
1470 Team
:= gPlayers
[a
].FTeam
;
1471 Frags
:= gPlayers
[a
].FFrags
;
1472 Deaths
:= gPlayers
[a
].FDeath
;
1473 Kills
:= gPlayers
[a
].FKills
;
1474 Color
:= gPlayers
[a
].FModel
.Color
;
1475 Lives
:= gPlayers
[a
].FLives
;
1476 Spectator
:= gPlayers
[a
].FSpectator
;
1481 procedure g_Player_RememberAll
;
1485 for i
:= Low(gPlayers
) to High(gPlayers
) do
1486 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1487 gPlayers
[i
].RememberState
;
1490 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1494 gTeamStat
[TEAM_RED
].Goals
:= 0;
1495 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1497 if gPlayers
<> nil then
1498 for i
:= 0 to High(gPlayers
) do
1499 if gPlayers
[i
] <> nil then
1501 gPlayers
[i
].Reset(Force
);
1503 if gPlayers
[i
] is TPlayer
then
1505 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1506 gPlayers
[i
].Respawn(Silent
)
1508 gPlayers
[i
].Spectate();
1511 TBot(gPlayers
[i
]).Respawn(Silent
);
1515 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1521 if Player
.alive
then
1524 // Ðàçðûâàåì ñâÿçü ñ ïðåæíèì òðóïîì:
1525 if gCorpses
<> nil then
1526 for i
:= 0 to High(gCorpses
) do
1527 if gCorpses
[i
] <> nil then
1528 if gCorpses
[i
].FPlayerUID
= Player
.FUID
then
1529 gCorpses
[i
].FPlayerUID
:= 0;
1531 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1536 if (FHealth
>= -50) or (gGibsCount
= 0) then
1538 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1542 for find_id
:= 0 to High(gCorpses
) do
1543 if gCorpses
[find_id
] = nil then
1550 find_id
:= Random(Length(gCorpses
));
1552 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1553 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1554 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1555 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1556 gCorpses
[find_id
].FPlayerUID
:= FUID
;
1559 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1560 FObj
.Y
+ PLAYER_RECT_CY
,
1561 FModel
.Name
, FModel
.Color
);
1565 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1569 if (gShells
= nil) or (Length(gShells
) = 0) then
1572 with gShells
[CurrentShell
] do
1578 if T
= SHELL_BULLET
then
1580 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1584 Obj
.Rect
.Width
:= 4;
1585 Obj
.Rect
.Height
:= 2;
1589 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1593 Obj
.Rect
.Width
:= 7;
1594 Obj
.Rect
.Height
:= 3;
1600 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1601 positionChanged(); // this updates spatial accelerators
1602 RAngle
:= Random(360);
1603 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1605 if CurrentShell
>= High(gShells
) then
1612 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1615 GibsArray
: TGibsArray
;
1618 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1620 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1622 Blood
:= g_PlayerModel_GetBlood(ModelName
);
1624 for a
:= 0 to High(GibsArray
) do
1625 with gGibs
[CurrentGib
] do
1628 ID
:= GibsArray
[a
].ID
;
1629 MaskID
:= GibsArray
[a
].MaskID
;
1632 Obj
.Rect
:= GibsArray
[a
].Rect
;
1633 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1634 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1635 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1636 positionChanged(); // this updates spatial accelerators
1637 RAngle
:= Random(360);
1639 if gBloodCount
> 0 then
1640 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1641 Random(48), Random(48), Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
1643 if CurrentGib
>= High(gGibs
) then
1650 procedure g_Player_UpdatePhysicalObjects();
1656 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1661 if T
= SHELL_BULLET
then
1662 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1664 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1669 if gGibs
<> nil then
1670 for i
:= 0 to High(gGibs
) do
1671 if gGibs
[i
].alive
then
1675 mr
:= g_Obj_Move(@Obj
, True, False, True);
1676 positionChanged(); // this updates spatial accelerators
1678 if WordBool(mr
and MOVE_FALLOUT
) then
1684 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1685 if WordBool(mr
and MOVE_HITWALL
) then
1686 Obj
.Vel
.X
:= -(vel
.X
div 2);
1687 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1688 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1690 if (Obj
.Vel
.X
>= 0) then
1692 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1693 if RAngle
>= 360 then
1694 RAngle
:= RAngle
mod 360;
1695 end else begin // Counter-clockwise
1696 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1698 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1701 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1702 if gTime
mod (GAME_TICK
*3) = 0 then
1703 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1707 if gCorpses
<> nil then
1708 for i
:= 0 to High(gCorpses
) do
1709 if gCorpses
[i
] <> nil then
1710 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1716 gCorpses
[i
].Update();
1719 if gShells
<> nil then
1720 for i
:= 0 to High(gShells
) do
1721 if gShells
[i
].alive
then
1725 mr
:= g_Obj_Move(@Obj
, True, False, True);
1726 positionChanged(); // this updates spatial accelerators
1728 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1734 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1735 if WordBool(mr
and MOVE_HITWALL
) then
1737 Obj
.Vel
.X
:= -(vel
.X
div 2);
1738 if not WordBool(mr
and MOVE_INWATER
) then
1739 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1741 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1743 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1744 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1745 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1747 if RAngle
mod 90 <> 0 then
1748 RAngle
:= (RAngle
div 90) * 90;
1750 else if not WordBool(mr
and MOVE_INWATER
) then
1751 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1754 if (Obj
.Vel
.X
>= 0) then
1756 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1757 if RAngle
>= 360 then
1758 RAngle
:= RAngle
mod 360;
1759 end else begin // Counter-clockwise
1760 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1762 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1768 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1770 x
:= Obj
.X
+Obj
.Rect
.X
;
1771 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1772 w
:= Obj
.Rect
.Width
;
1773 h
:= Obj
.Rect
.Height
;
1776 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1778 if (dx
<> 0) or (dy
<> 0) then
1787 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1791 w
:= Obj
.Rect
.Width
;
1792 h
:= Obj
.Rect
.Height
;
1795 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1797 if (dx
<> 0) or (dy
<> 0) then
1806 procedure TGib
.positionChanged (); inline; begin end;
1807 procedure TShell
.positionChanged (); inline; begin end;
1810 procedure g_Player_DrawCorpses();
1815 if gGibs
<> nil then
1816 for i
:= 0 to High(gGibs
) do
1817 if gGibs
[i
].alive
then
1820 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1823 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1824 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1826 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1829 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1835 if gCorpses
<> nil then
1836 for i
:= 0 to High(gCorpses
) do
1837 if gCorpses
[i
] <> nil then
1841 procedure g_Player_DrawShells();
1846 if gShells
<> nil then
1847 for i
:= 0 to High(gShells
) do
1848 if gShells
[i
].alive
then
1851 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1857 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1861 procedure g_Player_RemoveAllCorpses();
1867 SetLength(gGibs
, MaxGibs
);
1868 SetLength(gShells
, MaxGibs
);
1872 if gCorpses
<> nil then
1873 for i
:= 0 to High(gCorpses
) do
1877 SetLength(gCorpses
, MaxCorpses
);
1880 procedure g_Player_Corpses_SaveState (st
: TStream
);
1884 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ
1886 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1888 // Êîëè÷åñòâî òðóïîâ
1889 utils
.writeInt(st
, LongInt(count
));
1891 if (count
= 0) then exit
;
1894 for i
:= 0 to High(gCorpses
) do
1896 if gCorpses
[i
] <> nil then
1899 utils
.writeStr(st
, gCorpses
[i
].FModelName
);
1901 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1902 // Ñîõðàíÿåì äàííûå òðóïà:
1903 gCorpses
[i
].SaveState(st
);
1909 procedure g_Player_Corpses_LoadState (st
: TStream
);
1917 g_Player_RemoveAllCorpses();
1919 // Êîëè÷åñòâî òðóïîâ:
1920 count
:= utils
.readLongInt(st
);
1921 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1923 if (count
= 0) then exit
;
1926 for i
:= 0 to count
-1 do
1929 str
:= utils
.readStr(st
);
1931 b
:= utils
.readBool(st
);
1933 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1934 // Çàãðóæàåì äàííûå òðóïà
1935 gCorpses
[i
].LoadState(st
);
1942 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1944 procedure TPlayer
.BFGHit();
1946 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1947 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1948 if g_Game_IsServer
and g_Game_IsNet
then
1949 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1950 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1954 procedure TPlayer
.ChangeModel(ModelName
: string);
1956 locModel
: TPlayerModel
;
1958 locModel
:= g_PlayerModel_Get(ModelName
);
1959 if locModel
= nil then Exit
;
1965 procedure TPlayer
.SetModel(ModelName
: string);
1969 m
:= g_PlayerModel_Get(ModelName
);
1972 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1973 m
:= g_PlayerModel_Get('doomer');
1976 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1981 if FModel
<> nil then
1986 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1987 FModel
.Color
:= FColor
1989 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1990 FModel
.SetWeapon(FCurrWeap
);
1991 FModel
.SetFlag(FFlag
);
1992 SetDirection(FDirection
);
1995 procedure TPlayer
.SetColor(Color
: TRGB
);
1998 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1999 if FModel
<> nil then FModel
.Color
:= Color
;
2002 procedure TPlayer
.SwitchTeam
;
2004 if g_Game_IsClient
then
2006 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
2008 if gGameOn
and FAlive
then
2009 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
2011 if FTeam
= TEAM_RED
then
2013 ChangeTeam(TEAM_BLUE
);
2014 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
2015 if g_Game_IsNet
then
2016 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
2020 ChangeTeam(TEAM_RED
);
2021 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
2022 if g_Game_IsNet
then
2023 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
2025 FPreferredTeam
:= FTeam
;
2028 procedure TPlayer
.ChangeTeam(Team
: Byte);
2035 TEAM_RED
, TEAM_BLUE
:
2036 FModel
.Color
:= TEAMCOLOR
[Team
];
2038 FModel
.Color
:= FColor
;
2040 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2041 MH_SEND_PlayerStats(FUID
);
2045 procedure TPlayer.CollideItem();
2050 if gItems = nil then Exit;
2051 if not FAlive then Exit;
2053 for i := 0 to High(gItems) do
2056 if (ItemType <> ITEM_NONE) and alive then
2057 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2058 PLAYER_RECT.Height, @Obj) then
2060 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2062 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2063 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2064 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2065 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2066 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2068 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2069 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2070 (gGameSettings.GameType = GT_SINGLE) and
2071 (g_Player_GetCount() > 1)) then
2072 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2078 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2080 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2081 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2085 constructor TPlayer
.Create();
2091 mEDamageType
:= HIT_SOME
;
2097 FSawSound
:= TPlayableSound
.Create();
2098 FSawSoundIdle
:= TPlayableSound
.Create();
2099 FSawSoundHit
:= TPlayableSound
.Create();
2100 FSawSoundSelect
:= TPlayableSound
.Create();
2101 FJetSoundFly
:= TPlayableSound
.Create();
2102 FJetSoundOn
:= TPlayableSound
.Create();
2103 FJetSoundOff
:= TPlayableSound
.Create();
2105 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2106 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2107 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2108 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2109 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2110 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2111 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2113 FSpectatePlayer
:= -1;
2117 FSavedState
.WaitRecall
:= False;
2123 FActualModelName
:= 'doomer';
2126 FObj
.Rect
:= PLAYER_RECT
;
2128 FBFGFireCounter
:= -1;
2129 FJustTeleported
:= False;
2135 procedure TPlayer
.positionChanged (); inline;
2139 procedure TPlayer
.doDamage (v
: Integer);
2141 if (v
<= 0) then exit
;
2142 if (v
> 32767) then v
:= 32767;
2143 Damage(v
, 0, 0, 0, mEDamageType
);
2146 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2150 if (not g_Game_IsClient
) and (not FAlive
) then
2155 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2156 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2158 if not g_Game_IsClient
then
2161 if t
= HIT_TRAP
then
2163 // Ëîâóøêà óáèâàåò ñðàçó:
2165 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2167 if t
= HIT_SELF
then
2171 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2174 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2175 FMegaRulez
[MR_SUIT
] := 0;
2176 FMegaRulez
[MR_INVUL
] := 0;
2177 FMegaRulez
[MR_INVIS
] := 0;
2181 // Íî îò îñòàëüíîãî ñïàñàåò:
2182 if FMegaRulez
[MR_INVUL
] >= gTime
then
2189 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2190 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2191 (SpawnerUID
= FUID
) or
2192 (not SameTeam(FUID
, SpawnerUID
)) then
2194 FLastSpawnerUID
:= SpawnerUID
;
2196 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2197 if gBloodCount
> 0 then
2199 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2200 if value
div 4 <= c
then
2201 c
:= c
- (value
div 4)
2205 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2209 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2210 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2213 if t
= HIT_WATER
then
2214 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2215 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2220 Inc(FDamageBuffer
, value
);
2224 FPain
:= FPain
+ value
;
2227 if g_Game_IsServer
and g_Game_IsNet
then
2229 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2230 MH_SEND_PlayerStats(FUID
);
2231 MH_SEND_PlayerPos(False, FUID
);
2235 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2238 if g_Game_IsClient
then
2243 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2245 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2248 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2250 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2254 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2255 MH_SEND_PlayerStats(FUID
);
2258 destructor TPlayer
.Destroy();
2260 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2262 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2266 FSawSoundIdle
.Free();
2267 FSawSoundHit
.Free();
2268 FJetSoundFly
.Free();
2270 FJetSoundOff
.Free();
2272 if FPunchAnim
<> nil then
2278 procedure TPlayer
.DrawIndicator();
2280 indX
, indY
: Integer;
2286 indX
:= FObj
.X
+FObj
.Rect
.X
;
2287 indY
:= FObj
.Y
- 12;
2288 if g_Texture_Get('TEXTURE_PLAYER_INDICATOR', ID
) then
2290 e_GetTextureSize(ID
, @indW
, @indH
);
2291 e_Draw(ID
, indX
+ indW
div 2, indY
, 0, True, False);
2294 //e_TextureFontPrint(indX, indY, FName, gStdFont); // Shows player name overhead
2297 procedure TPlayer
.DrawBubble();
2299 bubX
, bubY
: Integer;
2302 Rw
, Gw
, Bw
: SmallInt;
2305 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= TDirection
.D_LEFT
, -4, 18);
2306 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2314 1: // simple textual non-bubble
2316 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2317 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2318 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2321 2: // advanced pixel-perfect bubble
2323 if FTeam
= TEAM_RED
then
2326 if FTeam
= TEAM_BLUE
then
2329 3: // colored bubble
2331 Rb
:= FModel
.Color
.R
;
2332 Gb
:= FModel
.Color
.G
;
2333 Bb
:= FModel
.Color
.B
;
2334 Rw
:= Min(Rb
* 2 + 64, 255);
2335 Gw
:= Min(Gb
* 2 + 64, 255);
2336 Bw
:= Min(Bb
* 2 + 64, 255);
2337 if (Abs(Rw
- Rb
) < 32)
2338 or (Abs(Gw
- Gb
) < 32)
2339 or (Abs(Bw
- Bb
) < 32) then
2341 Rb
:= Max(Rw
div 2 - 16, 0);
2342 Gb
:= Max(Gw
div 2 - 16, 0);
2343 Bb
:= Max(Bw
div 2 - 16, 0);
2346 4: // custom textured bubble
2348 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2349 if FDirection
= TDirection
.D_RIGHT
then
2350 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2352 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, TMirrorType
.Horizontal
);
2358 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2359 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2361 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2364 Dot
:= IfThen(FDirection
= TDirection
.D_LEFT
, 14, 5);
2365 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2366 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
);
2367 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
);
2368 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
);
2369 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
);
2373 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2374 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2375 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2378 procedure TPlayer
.Draw();
2383 Mirror
: TMirrorType
;
2387 if Direction
= TDirection
.D_RIGHT
then
2388 Mirror
:= TMirrorType
.None
2390 Mirror
:= TMirrorType
.Horizontal
;
2392 if FPunchAnim
<> nil then
2394 FPunchAnim
.Draw(FObj
.X
+IfThen(Direction
= TDirection
.D_LEFT
, 15-FObj
.Rect
.X
, FObj
.Rect
.X
-15),
2395 FObj
.Y
+FObj
.Rect
.Y
-11, Mirror
);
2396 if FPunchAnim
.played
then
2403 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2404 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2406 e_GetTextureSize(ID
, @w
, @h
);
2407 if FDirection
= TDirection
.D_LEFT
then
2408 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2409 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False)
2411 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2412 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False);
2415 if FMegaRulez
[MR_INVIS
] > gTime
then
2417 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2418 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2420 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2421 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2425 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 200)
2427 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2430 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 254);
2433 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2436 if g_debug_Frames
then
2438 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2440 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2441 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2445 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2447 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2448 if gAimLine
and alive
and
2449 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2454 procedure TPlayer
.DrawAim();
2455 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2460 {$IFDEF ENABLE_HOLMES}
2461 if isValidViewPort
and (self
= gPlayer1
) then
2463 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2467 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2468 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2470 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2474 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2479 wx
, wy
, xx
, yy
: Integer;
2483 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= TDirection
.D_LEFT
, 7, -7);
2484 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2493 1: begin // Chainsaw
2500 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2501 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2502 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2503 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2508 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2509 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2510 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2511 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2513 4: begin // Double Shotgun
2516 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2517 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2518 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2519 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2521 5: begin // Chaingun
2524 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2525 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2526 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2527 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2529 6: begin // Rocket Launcher
2532 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2533 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2534 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2535 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2537 7: begin // Plasmagun
2540 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2541 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2542 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2543 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2548 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2549 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2550 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2551 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2553 9: begin // Super Chaingun
2556 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2557 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2558 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2559 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2562 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2563 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2564 {$IF DEFINED(D2F_DEBUG)}
2565 drawCast(sz
, wx
, wy
, xx
, yy
);
2567 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2571 procedure TPlayer
.DrawGUI();
2574 X
, Y
, SY
, a
, p
, m
: Integer;
2578 stat
: TPlayerStatArray
;
2580 X
:= gPlayerScreenSize
.X
;
2581 SY
:= gPlayerScreenSize
.Y
;
2584 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2586 if gGameSettings
.GameMode
= GM_CTF
then
2590 if gGameSettings
.GameMode
= GM_CTF
then
2592 s
:= 'TEXTURE_PLAYER_REDFLAG';
2593 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2594 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2595 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2596 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2597 if g_Texture_Get(s
, ID
) then
2598 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2601 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2602 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2603 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2605 if gGameSettings
.GameMode
= GM_CTF
then
2607 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2608 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2609 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2610 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2611 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2612 if g_Texture_Get(s
, ID
) then
2613 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2616 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2617 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2618 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2621 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2622 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2625 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2626 e_Draw(ID
, X
+2, Y
, 0, True, False);
2628 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2632 s
:= IntToStr(Frags
);
2633 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2634 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2639 stat
:= g_Player_GetStats();
2644 for a
:= 0 to High(stat
) do
2645 if stat
[a
].Name
<> Name
then
2647 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2648 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2652 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2653 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2654 s
:= s
+IntToStr(Abs(Frags
-m
));
2656 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2657 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2660 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2662 s
:= IntToStr(Lives
);
2663 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2664 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2668 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2669 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2671 if R_BERSERK
in FRulez
then
2672 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2674 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2676 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2677 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2679 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2680 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2681 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2683 s
:= IntToStr(FArmor
);
2684 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2685 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2687 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2693 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2698 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2700 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2701 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2702 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2703 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2704 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2705 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2706 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2707 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2708 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2711 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2712 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2713 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2715 if R_KEY_RED
in FRulez
then
2716 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2718 if R_KEY_GREEN
in FRulez
then
2719 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2721 if R_KEY_BLUE
in FRulez
then
2722 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2724 if FJetFuel
> 0 then
2726 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2727 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2728 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2729 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2730 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2731 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2735 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2736 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2737 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2740 if gShowPing
and g_Game_IsClient
then
2742 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2743 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2749 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2750 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2751 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2754 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2755 s
:= _lc
[I_PLAYER_SPECT4
];
2756 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2757 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2758 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2764 procedure TPlayer
.DrawRulez();
2768 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2769 if FMegaRulez
[MR_INVUL
] >= gTime
then
2771 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2772 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2777 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2778 191, 191, 191, 0, TBlending
.Invert
);
2781 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2782 if FMegaRulez
[MR_SUIT
] >= gTime
then
2784 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2785 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2790 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2791 0, 96, 0, 200, TBlending
.None
);
2794 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2795 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2797 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2798 255, 0, 0, 200, TBlending
.None
);
2802 procedure TPlayer
.DrawPain();
2806 if FPain
= 0 then Exit
;
2810 if a
< 15 then h
:= 0
2811 else if a
< 35 then h
:= 1
2812 else if a
< 55 then h
:= 2
2813 else if a
< 75 then h
:= 3
2814 else if a
< 95 then h
:= 4
2817 //if a > 255 then a := 255;
2819 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2820 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2823 procedure TPlayer
.DrawPickup();
2827 if FPickup
= 0 then Exit
;
2831 if a
< 15 then h
:= 1
2832 else if a
< 35 then h
:= 2
2833 else if a
< 55 then h
:= 3
2834 else if a
< 75 then h
:= 4
2837 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2840 procedure TPlayer
.DoPunch();
2845 if FPunchAnim
<> nil then begin
2850 st
:= 'FRAMES_PUNCH';
2851 if R_BERSERK
in FRulez
then
2852 st
:= st
+ '_BERSERK';
2853 if FKeys
[KEY_UP
].Pressed
then
2855 else if FKeys
[KEY_DOWN
].Pressed
then
2857 g_Frames_Get(id
, st
);
2858 FPunchAnim
:= TAnimation
.Create(id
, False, 1);
2861 procedure TPlayer
.Fire();
2863 f
, DidFire
: Boolean;
2864 wx
, wy
, xd
, yd
: Integer;
2867 if g_Game_IsClient
then Exit
;
2868 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2869 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2877 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2882 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2883 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2884 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
2885 yd
:= wy
+firediry();
2891 if R_BERSERK
in FRulez
then
2893 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2894 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2895 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2898 locobj
.rect
.Width
:= 39;
2899 locobj
.rect
.Height
:= 52;
2900 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2901 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2902 locobj
.Accel
.X
:= xd
-wx
;
2903 locobj
.Accel
.y
:= yd
-wy
;
2905 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2906 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2908 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2910 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
2914 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2918 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2923 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2924 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2926 FSawSoundSelect
.Stop();
2928 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2930 else if not FSawSoundHit
.IsPlaying() then
2932 FSawSoundSelect
.Stop();
2933 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2936 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2942 if FAmmo
[A_BULLETS
] > 0 then
2944 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2945 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2946 Dec(FAmmo
[A_BULLETS
]);
2947 FFireAngle
:= FAngle
;
2950 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2951 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2955 if FAmmo
[A_SHELLS
] > 0 then
2957 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2958 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
2959 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2960 Dec(FAmmo
[A_SHELLS
]);
2961 FFireAngle
:= FAngle
;
2965 FShellType
:= SHELL_SHELL
;
2969 if FAmmo
[A_SHELLS
] >= 2 then
2971 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
2972 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2973 Dec(FAmmo
[A_SHELLS
], 2);
2974 FFireAngle
:= FAngle
;
2978 FShellType
:= SHELL_DBLSHELL
;
2982 if FAmmo
[A_BULLETS
] > 0 then
2984 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
2985 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
2986 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2987 Dec(FAmmo
[A_BULLETS
]);
2988 FFireAngle
:= FAngle
;
2991 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2992 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2995 WEAPON_ROCKETLAUNCHER
:
2996 if FAmmo
[A_ROCKETS
] > 0 then
2998 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
2999 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3000 Dec(FAmmo
[A_ROCKETS
]);
3001 FFireAngle
:= FAngle
;
3007 if FAmmo
[A_CELLS
] > 0 then
3009 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
3010 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3011 Dec(FAmmo
[A_CELLS
]);
3012 FFireAngle
:= FAngle
;
3018 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
3020 FBFGFireCounter
:= 17;
3021 if not FNoReload
then
3022 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
3023 Dec(FAmmo
[A_CELLS
], 40);
3027 WEAPON_SUPERPULEMET
:
3028 if FAmmo
[A_SHELLS
] > 0 then
3030 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3031 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
3032 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3033 Dec(FAmmo
[A_SHELLS
]);
3034 FFireAngle
:= FAngle
;
3037 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3038 GameVelX
, GameVelY
-2, SHELL_SHELL
);
3041 WEAPON_FLAMETHROWER
:
3042 if FAmmo
[A_FUEL
] > 0 then
3044 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
3045 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3047 FFireAngle
:= FAngle
;
3053 if g_Game_IsNet
then
3057 if FCurrWeap
<> WEAPON_BFG
then
3058 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
3060 if not FNoReload
then
3061 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
3064 MH_SEND_PlayerStats(FUID
);
3069 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
3070 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
3071 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
3074 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
3077 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
3078 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
3079 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
3080 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
3081 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
3086 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
3088 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
3089 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
3090 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
3093 procedure TPlayer
.JetpackOn
;
3097 FJetSoundOn
.SetPosition(0);
3098 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3102 procedure TPlayer
.JetpackOff
;
3106 FJetSoundOff
.SetPosition(0);
3107 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3110 procedure TPlayer
.CatchFire(Attacker
: Word);
3113 FFireAttacker
:= Attacker
;
3114 if g_Game_IsNet
and g_Game_IsServer
then
3115 MH_SEND_PlayerStats(FUID
);
3118 procedure TPlayer
.Jump();
3120 if gFly
or FJetpack
then
3122 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3123 if FObj
.Vel
.Y
> -VEL_FLY
then
3124 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3127 if FJetFuel
> 0 then
3129 if (FJetFuel
< 1) and g_Game_IsServer
then
3133 if g_Game_IsNet
then
3134 MH_SEND_PlayerStats(FUID
);
3140 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3142 FCanJetpack
:= False;
3144 // Ïðûãàåì èëè âñïëûâàåì:
3145 if (CollideLevel(0, 1) or
3146 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3147 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3148 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3150 FObj
.Vel
.Y
:= -VEL_JUMP
;
3151 FCanJetpack
:= False;
3155 if BodyInLiquid(0, 0) then
3156 FObj
.Vel
.Y
:= -VEL_SW
3157 else if (FJetFuel
> 0) and FCanJetpack
and
3158 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3162 if g_Game_IsNet
then
3163 MH_SEND_PlayerStats(FUID
);
3168 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3170 a
, i
, k
, ab
, ar
: Byte;
3174 srv
, netsrv
: Boolean;
3180 procedure PushItem(t
: Byte);
3184 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3185 it
:= g_Items_ByIdx(id
);
3186 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3188 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3189 (FObj
.Vel
.Y
div 2)-Random(9));
3190 it
.positionChanged(); // this updates spatial accelerators
3194 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3196 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3197 (FObj
.Vel
.Y
div 2)-Random(6));
3199 else // -3..+3; -3..0
3201 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3202 (FObj
.Vel
.Y
div 2)-Random(4));
3204 it
.positionChanged(); // this updates spatial accelerators
3207 if g_Game_IsNet
and g_Game_IsServer
then
3208 MH_SEND_ItemSpawn(True, id
);
3212 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3213 Srv
:= g_Game_IsServer
;
3214 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3215 if Srv
then FDeath
:= FDeath
+ 1;
3220 if not FPhysics
then
3226 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3228 if FLives
> 0 then FLives
:= FLives
- 1;
3229 if FLives
= 0 then FNoRespawn
:= True;
3232 // Íîìåð òèïà ñìåðòè:
3235 K_SIMPLEKILL
: a
:= 1;
3237 K_EXTRAHARDKILL
: a
:= 3;
3242 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3244 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3251 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3253 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3254 K_EXTRAHARDKILL
, K_FALLKILL
:
3255 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3258 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3262 K_HARDKILL
, K_EXTRAHARDKILL
:
3266 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3267 if (KillType
<> K_FALLKILL
) and (Srv
) then
3268 g_Monsters_killedp();
3270 if SpawnerUID
= FUID
then
3272 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3277 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3280 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3281 begin // Óáèò äðóãèì èãðîêîì
3282 KP
:= g_Player_Get(SpawnerUID
);
3283 if (KP
<> nil) and Srv
then
3285 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3286 if SameTeam(FUID
, SpawnerUID
) then
3296 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3297 Inc(gTeamStat
[KP
.Team
].Goals
,
3298 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3300 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3303 plr
:= g_Player_Get(SpawnerUID
);
3311 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3315 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3319 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3324 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3325 begin // Óáèò ìîíñòðîì
3326 mon
:= g_Monsters_ByUID(SpawnerUID
);
3330 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
3334 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3338 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3342 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3347 else // Îñîáûå òèïû ñìåðòè
3350 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3351 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3352 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3353 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3354 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3355 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3361 for a
:= WP_FIRST
to WP_LAST
do
3365 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3366 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3367 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3368 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3369 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3370 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3371 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3372 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3373 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3382 if R_ITEM_BACKPACK
in FRulez
then
3383 PushItem(ITEM_AMMO_BACKPACK
);
3385 // Âûáðîñ ðàêåòíîãî ðàíöà:
3386 if FJetFuel
> 0 then
3387 PushItem(ITEM_JETPACK
);
3390 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3392 if R_KEY_RED
in FRulez
then
3393 PushItem(ITEM_KEY_RED
);
3395 if R_KEY_GREEN
in FRulez
then
3396 PushItem(ITEM_KEY_GREEN
);
3398 if R_KEY_BLUE
in FRulez
then
3399 PushItem(ITEM_KEY_BLUE
);
3406 g_Player_CreateCorpse(Self
);
3408 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3409 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3415 for i
:= Low(gPlayers
) to High(gPlayers
) do
3417 if gPlayers
[i
] = nil then continue
;
3418 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3421 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3422 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3427 OldLR
:= gLMSRespawn
;
3428 if (gGameSettings
.GameMode
= GM_COOP
) then
3432 // everyone is dead, restart the map
3433 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3435 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3436 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3437 gLMSRespawnTime
:= gTime
+ 5000;
3439 else if (a
= 1) then
3441 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3442 if (gPlayers
[k
] = gPlayer1
) or
3443 (gPlayers
[k
] = gPlayer2
) then
3444 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3445 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3446 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3449 else if (gGameSettings
.GameMode
= GM_TDM
) then
3451 if (ab
= 0) and (ar
<> 0) then
3454 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3456 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3457 Inc(gTeamStat
[TEAM_RED
].Goals
);
3458 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3459 gLMSRespawnTime
:= gTime
+ 5000;
3461 else if (ar
= 0) and (ab
<> 0) then
3464 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3466 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3467 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3468 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3469 gLMSRespawnTime
:= gTime
+ 5000;
3471 else if (ar
= 0) and (ab
= 0) then
3474 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3476 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3477 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3478 gLMSRespawnTime
:= gTime
+ 5000;
3481 else if (gGameSettings
.GameMode
= GM_DM
) then
3485 if gPlayers
[k
] <> nil then
3488 // survivor is the winner
3489 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3491 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3494 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3495 gLMSRespawnTime
:= gTime
+ 5000;
3497 else if (a
= 0) then
3499 // everyone is dead, restart the map
3500 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3502 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3503 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3504 gLMSRespawnTime
:= gTime
+ 5000;
3507 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3509 if NetMode
= NET_SERVER
then
3510 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3512 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3518 MH_SEND_PlayerStats(FUID
);
3519 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3520 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3523 if srv
and FNoRespawn
then Spectate(True);
3524 FWantsInGame
:= True;
3527 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3529 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3530 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3533 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3535 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3536 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3539 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3541 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3542 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3543 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3544 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3545 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3546 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3547 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3548 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3551 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3553 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3554 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3555 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3556 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3559 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3561 if g_Game_IsClient
then Exit
;
3562 if Weapon
> High(FWeapon
) then Exit
;
3563 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3566 procedure TPlayer
.resetWeaponQueue ();
3569 FNextWeapDelay
:= 0;
3572 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3576 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3577 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
3578 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
3579 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3580 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3581 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3582 else result
:= (weapon
< length(FWeapon
));
3586 // return 255 for "no switch"
3587 function TPlayer
.getNextWeaponIndex (): Byte;
3590 wantThisWeapon
: array[0..64] of Boolean;
3591 weaponOrder
: array[0..16] of Integer; // value: index in `FWeapon`
3593 f
, dir
, cwi
, rwidx
, curlidx
: Integer;
3595 function real2log (ridx
: Integer): Integer;
3601 for f
:= 0 to High(weaponOrder
) do if (weaponOrder
[f
] = ridx
) then begin result
:= f
; exit
; end;
3607 result
:= 255; // default result: "no switch"
3609 // had weapon cycling on previous frame? remove that flag
3610 if (FNextWeap
and $2000) <> 0 then
3612 FNextWeap
:= FNextWeap
and $1FFF;
3613 FNextWeapDelay
:= 0;
3616 for f
:= 0 to High(weaponOrder
) do weaponOrder
[f
] := -1;
3618 // build weapon order (k8: i know, i know, learn how to do constants and such... gtfo, please!)
3619 // two knuckles are for "normal" and "berserk" (see `if` below -- it removes the one that is not needed)
3621 // bfg, launcher, plasma, flamethrower, ssg, minigun, sg, pistol, berserk, chainsaw, fist
3622 weaponOrder
[0] := WEAPON_SUPERPULEMET
;
3623 weaponOrder
[1] := WEAPON_BFG
;
3624 weaponOrder
[2] := WEAPON_ROCKETLAUNCHER
;
3625 weaponOrder
[3] := WEAPON_PLASMA
;
3626 weaponOrder
[4] := WEAPON_FLAMETHROWER
;
3627 weaponOrder
[5] := WEAPON_SHOTGUN2
;
3628 weaponOrder
[6] := WEAPON_CHAINGUN
;
3629 weaponOrder
[7] := WEAPON_SHOTGUN1
;
3630 weaponOrder
[8] := WEAPON_PISTOL
;
3631 weaponOrder
[9] := WEAPON_KASTET
+666; // berserk fist
3632 weaponOrder
[10] := WEAPON_SAW
;
3633 weaponOrder
[11] := WEAPON_KASTET
; // normal fist
3635 for f
:= 0 to High(weaponOrder
) do
3637 if (weaponOrder
[f
] = WEAPON_KASTET
) then
3639 // normal fist: remove if we have a berserk pack
3640 if (R_BERSERK
in FRulez
) then weaponOrder
[f
] := -1;
3643 if (weaponOrder
[f
] = WEAPON_KASTET
+666) then
3645 // berserk fist: remove if we don't have a berserk pack
3646 if (R_BERSERK
in FRulez
) then weaponOrder
[f
] := WEAPON_KASTET
else weaponOrder
[f
] := -1;
3654 WEAPON_SHOTGUN1 = 3;
3655 WEAPON_SHOTGUN2 = 4;
3656 WEAPON_CHAINGUN = 5;
3657 WEAPON_ROCKETLAUNCHER = 6;
3660 WEAPON_SUPERPULEMET = 9;
3661 WEAPON_FLAMETHROWER = 10;
3664 // cycling has priority
3665 if (FNextWeap
and $C000) <> 0 then
3667 if (FNextWeap
and $8000) <> 0 then dir
:= 1 else dir
:= -1; // should be reversed if we want "priority-driven cycling"
3668 FNextWeap
:= FNextWeap
or $2000; // we need this
3669 if FNextWeapDelay
> 0 then exit
; // cooldown time
3670 //cwi := real2log(FCurrWeap);
3671 //if (cwi < 0) then cwi := 0;
3673 for i
:= 0 to High(FWeapon
) do
3675 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3676 //rwidx := weaponOrder[cwi];
3677 rwidx
:= cwi
; // sorry
3678 if (rwidx
< 0) then continue
;
3679 if FWeapon
[rwidx
] then
3681 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d (dir=%d; log=%d)', [FCurrWeap, rwidx, dir, cwi]), TMsgType.Warning);
3682 result
:= Byte(rwidx
);
3683 FNextWeapDelay
:= 10;
3692 for i
:= 0 to High(wantThisWeapon
) do wantThisWeapon
[i
] := false;
3695 curlidx
:= -1; // start from a weapon with a highest priority (-1, 'cause loop will immediately increment this index)
3697 for i
:= 0 to High(FWeapon
) do
3699 if (FNextWeap
and (1 shl i
)) <> 0 then
3704 wantThisWeapon
[cwi
] := true;
3706 // if we hit currently selected weapon, start seachring from it, so we'll get "next weaker" weapon
3707 if (i
= FCurrWeap
) then curlidx
:= cwi
; // compare real, start from logical
3712 // slow down alterations a little
3715 // more than one weapon requested, assume "alteration", and check alteration delay
3716 if FNextWeapDelay
> 0 then
3718 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), TMsgType.Warning);
3724 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3725 // but clear all counters if no weapon should be switched
3732 //e_WriteLog(Format('*** wwc=%d; currweap=%d; logweap=%d', [wwc, FCurrWeap, curlidx]), TMsgType.Warning);
3734 // find next weapon to switch onto
3736 for i
:= 0 to High(weaponOrder
) do
3738 cwi
:= (cwi
+length(weaponOrder
)+1) mod length(weaponOrder
);
3739 if (cwi
= curlidx
) then continue
; // skip current weapon
3740 if not wantThisWeapon
[cwi
] then continue
;
3741 rwidx
:= weaponOrder
[cwi
];
3742 if (rwidx
< 0) then continue
;
3743 //e_WriteLog(Format(' trying logical %d (real %d); has=%d, hasammo=%d', [cwi, rwidx, Integer(FWeapon[rwidx]), Integer(hasAmmoForWeapon(rwidx))]), TMsgType.Warning);
3744 if FWeapon
[rwidx
] and ((wwc
= 1) or hasAmmoForWeapon(rwidx
)) then
3746 //e_WriteLog(' I FOUND HER!', TMsgType.Warning);
3748 result
:= Byte(rwidx
);
3750 FNextWeapDelay
:= 10; // anyway, 'cause why not
3755 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3759 procedure TPlayer
.RealizeCurrentWeapon();
3760 function switchAllowed (): Boolean;
3765 if FBFGFireCounter
<> -1 then
3767 if FTime
[T_SWITCH
] > gTime
then
3769 for i
:= WP_FIRST
to WP_LAST
do
3770 if FReloading
[i
] > 0 then
3778 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3779 //FNextWeap := FNextWeap and $1FFF;
3780 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3782 if not switchAllowed
then
3784 //HACK for weapon cycling
3785 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3789 nw
:= getNextWeaponIndex();
3790 if nw
= 255 then exit
; // don't reset anything here
3791 if nw
> High(FWeapon
) then
3793 // don't forget to reset queue here!
3794 //e_WriteLog(Format(' RealizeCurrentWeapon: WUTAFUUUU?! (%d)', [nw]), TMsgType.Warning);
3802 FTime
[T_SWITCH
] := gTime
+156;
3803 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3804 FModel
.SetWeapon(FCurrWeap
);
3805 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3809 procedure TPlayer
.NextWeapon();
3811 if g_Game_IsClient
then Exit
;
3815 procedure TPlayer
.PrevWeapon();
3817 if g_Game_IsClient
then Exit
;
3821 procedure TPlayer
.SetWeapon(W
: Byte);
3823 if FCurrWeap
<> W
then
3824 if W
= WEAPON_SAW
then
3825 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3828 FModel
.SetWeapon(CurrWeap
);
3832 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3834 function allowBerserkSwitching (): Boolean;
3836 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3838 if gBerserkAutoswitch
then exit
;
3839 if not conIsCheatsEnabled
then exit
;
3847 if g_Game_IsClient
then Exit
;
3849 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3850 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3855 if FHealth
< PLAYER_HP_SOFT
then
3857 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3861 if gFlash
= 2 then Inc(FPickup
, 5);
3865 if FHealth
< PLAYER_HP_SOFT
then
3867 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3871 if gFlash
= 2 then Inc(FPickup
, 5);
3875 if FArmor
< PLAYER_AP_SOFT
then
3877 FArmor
:= PLAYER_AP_SOFT
;
3880 if gFlash
= 2 then Inc(FPickup
, 5);
3884 if FArmor
< PLAYER_AP_LIMIT
then
3886 FArmor
:= PLAYER_AP_LIMIT
;
3889 if gFlash
= 2 then Inc(FPickup
, 5);
3893 if FHealth
< PLAYER_HP_LIMIT
then
3895 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3899 if gFlash
= 2 then Inc(FPickup
, 5);
3903 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3905 if FHealth
< PLAYER_HP_LIMIT
then
3906 FHealth
:= PLAYER_HP_LIMIT
;
3907 if FArmor
< PLAYER_AP_LIMIT
then
3908 FArmor
:= PLAYER_AP_LIMIT
;
3912 if gFlash
= 2 then Inc(FPickup
, 5);
3916 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3918 FWeapon
[WEAPON_SAW
] := True;
3920 if gFlash
= 2 then Inc(FPickup
, 5);
3921 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3924 ITEM_WEAPON_SHOTGUN1
:
3925 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3927 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3928 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3930 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3931 FWeapon
[WEAPON_SHOTGUN1
] := 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');
3937 ITEM_WEAPON_SHOTGUN2
:
3938 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3940 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3942 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3943 FWeapon
[WEAPON_SHOTGUN2
] := True;
3945 if gFlash
= 2 then Inc(FPickup
, 5);
3946 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3949 ITEM_WEAPON_CHAINGUN
:
3950 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3952 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3954 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3955 FWeapon
[WEAPON_CHAINGUN
] := True;
3957 if gFlash
= 2 then Inc(FPickup
, 5);
3958 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3961 ITEM_WEAPON_ROCKETLAUNCHER
:
3962 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3964 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3966 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3967 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3969 if gFlash
= 2 then Inc(FPickup
, 5);
3970 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3974 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3976 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3978 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3979 FWeapon
[WEAPON_PLASMA
] := True;
3981 if gFlash
= 2 then Inc(FPickup
, 5);
3982 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3986 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3988 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3990 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3991 FWeapon
[WEAPON_BFG
] := True;
3993 if gFlash
= 2 then Inc(FPickup
, 5);
3994 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3997 ITEM_WEAPON_SUPERPULEMET
:
3998 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
4000 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
4002 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4003 FWeapon
[WEAPON_SUPERPULEMET
] := True;
4005 if gFlash
= 2 then Inc(FPickup
, 5);
4006 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4009 ITEM_WEAPON_FLAMETHROWER
:
4010 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
4012 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
4014 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4015 FWeapon
[WEAPON_FLAMETHROWER
] := True;
4017 if gFlash
= 2 then Inc(FPickup
, 5);
4018 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4022 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4024 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4027 if gFlash
= 2 then Inc(FPickup
, 5);
4030 ITEM_AMMO_BULLETS_BOX
:
4031 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4033 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4036 if gFlash
= 2 then Inc(FPickup
, 5);
4040 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4042 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4045 if gFlash
= 2 then Inc(FPickup
, 5);
4048 ITEM_AMMO_SHELLS_BOX
:
4049 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4051 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
4054 if gFlash
= 2 then Inc(FPickup
, 5);
4058 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4060 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4063 if gFlash
= 2 then Inc(FPickup
, 5);
4066 ITEM_AMMO_ROCKET_BOX
:
4067 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4069 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
4072 if gFlash
= 2 then Inc(FPickup
, 5);
4076 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4078 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4081 if gFlash
= 2 then Inc(FPickup
, 5);
4085 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4087 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4090 if gFlash
= 2 then Inc(FPickup
, 5);
4094 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4096 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4099 if gFlash
= 2 then Inc(FPickup
, 5);
4103 if not(R_ITEM_BACKPACK
in FRulez
) or
4104 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4105 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4106 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4107 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4108 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
4110 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4111 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4112 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4113 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4114 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4116 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4117 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4118 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4119 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4120 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4121 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4122 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4123 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4125 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
4128 if gFlash
= 2 then Inc(FPickup
, 5);
4132 if not(R_KEY_RED
in FRulez
) then
4134 Include(FRulez
, R_KEY_RED
);
4136 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4137 if gFlash
= 2 then Inc(FPickup
, 5);
4138 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4142 if not(R_KEY_GREEN
in FRulez
) then
4144 Include(FRulez
, R_KEY_GREEN
);
4146 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4147 if gFlash
= 2 then Inc(FPickup
, 5);
4148 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4152 if not(R_KEY_BLUE
in FRulez
) then
4154 Include(FRulez
, R_KEY_BLUE
);
4156 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4157 if gFlash
= 2 then Inc(FPickup
, 5);
4158 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4162 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4164 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4168 if gFlash
= 2 then Inc(FPickup
, 5);
4172 if FAir
< AIR_MAX
then
4177 if gFlash
= 2 then Inc(FPickup
, 5);
4182 if not (R_BERSERK
in FRulez
) then
4184 Include(FRulez
, R_BERSERK
);
4185 if allowBerserkSwitching
then
4187 FCurrWeap
:= WEAPON_KASTET
;
4189 FModel
.SetWeapon(WEAPON_KASTET
);
4194 if gFlash
= 2 then Inc(FPickup
, 5);
4196 FBerserk
:= gTime
+30000;
4200 //k8:do we need it? if g_Game_IsNet and g_Game_IsServer then MH_SEND_PlayerStats(FUID);
4202 if FHealth
< PLAYER_HP_SOFT
then
4204 FHealth
:= PLAYER_HP_SOFT
;
4205 FBerserk
:= gTime
+30000;
4213 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4215 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4218 if gFlash
= 2 then Inc(FPickup
, 5);
4222 if FHealth
< PLAYER_HP_LIMIT
then
4224 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4228 if gFlash
= 2 then Inc(FPickup
, 5);
4232 if FArmor
< PLAYER_AP_LIMIT
then
4234 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4237 if gFlash
= 2 then Inc(FPickup
, 5);
4241 if FJetFuel
< JET_MAX
then
4243 FJetFuel
:= JET_MAX
;
4246 if gFlash
= 2 then Inc(FPickup
, 5);
4250 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4252 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4255 if gFlash
= 2 then Inc(FPickup
, 5);
4260 procedure TPlayer
.Touch();
4264 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4267 // Áðîñèòü ôëàã òîâàðèùó:
4268 if gGameSettings
.GameMode
= GM_CTF
then
4273 procedure TPlayer
.Push(vx
, vy
: Integer);
4275 if (not FPhysics
) and FGhost
then
4277 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4278 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4279 if g_Game_IsNet
and g_Game_IsServer
then
4280 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4283 procedure TPlayer
.Reset(Force
: Boolean);
4289 FTime
[T_RESPAWN
] := 0;
4290 FTime
[T_FLAGCAP
] := 0;
4303 FSpectator
:= False;
4306 FSpectatePlayer
:= -1;
4307 FNoRespawn
:= False;
4309 FLives
:= gGameSettings
.MaxLives
;
4314 procedure TPlayer
.SoftReset();
4320 FBFGFireCounter
:= -1;
4328 SetAction(A_STAND
, True);
4331 function TPlayer
.GetRespawnPoint(): Byte;
4336 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4338 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4339 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4341 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4343 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4344 if Self
= gPlayer1
then
4345 c
:= RESPAWNPOINT_PLAYER1
4347 c
:= RESPAWNPOINT_PLAYER2
;
4348 if g_Map_GetPointCount(c
) > 0 then
4354 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4355 if Self
= gPlayer1
then
4356 c
:= RESPAWNPOINT_PLAYER2
4358 c
:= RESPAWNPOINT_PLAYER1
;
4359 if g_Map_GetPointCount(c
) > 0 then
4366 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4367 if Random(2) = 0 then
4368 c
:= RESPAWNPOINT_PLAYER1
4370 c
:= RESPAWNPOINT_PLAYER2
;
4371 if g_Map_GetPointCount(c
) > 0 then
4378 // Òî÷êà ëþáîé èç êîìàíä
4379 if Random(2) = 0 then
4380 c
:= RESPAWNPOINT_RED
4382 c
:= RESPAWNPOINT_BLUE
;
4383 if g_Map_GetPointCount(c
) > 0 then
4390 c
:= RESPAWNPOINT_DM
;
4391 if g_Map_GetPointCount(c
) > 0 then
4399 if gGameSettings
.GameMode
= GM_DM
then
4402 c
:= RESPAWNPOINT_DM
;
4403 if g_Map_GetPointCount(c
) > 0 then
4409 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4410 if Random(2) = 0 then
4411 c
:= RESPAWNPOINT_PLAYER1
4413 c
:= RESPAWNPOINT_PLAYER2
;
4414 if g_Map_GetPointCount(c
) > 0 then
4420 // Òî÷êà ëþáîé èç êîìàíä
4421 if Random(2) = 0 then
4422 c
:= RESPAWNPOINT_RED
4424 c
:= RESPAWNPOINT_BLUE
;
4425 if g_Map_GetPointCount(c
) > 0 then
4433 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4435 // Òî÷êà ñâîåé êîìàíäû
4436 c
:= RESPAWNPOINT_DM
;
4437 if FTeam
= TEAM_RED
then
4438 c
:= RESPAWNPOINT_RED
;
4439 if FTeam
= TEAM_BLUE
then
4440 c
:= RESPAWNPOINT_BLUE
;
4441 if g_Map_GetPointCount(c
) > 0 then
4448 c
:= RESPAWNPOINT_DM
;
4449 if g_Map_GetPointCount(c
) > 0 then
4455 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4456 if Random(2) = 0 then
4457 c
:= RESPAWNPOINT_PLAYER1
4459 c
:= RESPAWNPOINT_PLAYER2
;
4460 if g_Map_GetPointCount(c
) > 0 then
4466 // Òî÷êà äðóãîé êîìàíäû
4467 c
:= RESPAWNPOINT_DM
;
4468 if FTeam
= TEAM_RED
then
4469 c
:= RESPAWNPOINT_BLUE
;
4470 if FTeam
= TEAM_BLUE
then
4471 c
:= RESPAWNPOINT_RED
;
4472 if g_Map_GetPointCount(c
) > 0 then
4480 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4482 RespawnPoint
: TRespawnPoint
;
4488 FBFGFireCounter
:= -1;
4493 if not g_Game_IsServer
then
4497 FWantsInGame
:= True;
4498 FJustTeleported
:= True;
4501 FTime
[T_RESPAWN
] := 0;
4505 // if server changes MaxLives we gotta be ready
4506 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4508 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4509 if FTime
[T_RESPAWN
] > gTime
then
4512 // Ïðîñðàë âñå æèçíè:
4515 if not FSpectator
then Spectate(True);
4516 FWantsInGame
:= True;
4520 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4521 begin // "Ñâîÿ èãðà"
4522 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4523 FRulez
:= FRulez
-[R_BERSERK
];
4525 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4527 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4528 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4531 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4532 c
:= GetRespawnPoint();
4537 // Âîñêðåøåíèå áåç îðóæèÿ:
4540 FHealth
:= PLAYER_HP_SOFT
;
4546 for a
:= WP_FIRST
to WP_LAST
do
4548 FWeapon
[a
] := False;
4552 FWeapon
[WEAPON_PISTOL
] := True;
4553 FWeapon
[WEAPON_KASTET
] := True;
4554 FCurrWeap
:= WEAPON_PISTOL
;
4557 FModel
.SetWeapon(FCurrWeap
);
4559 for b
:= A_BULLETS
to A_HIGH
do
4562 FAmmo
[A_BULLETS
] := 50;
4564 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4565 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4566 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4567 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4568 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4570 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4571 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4576 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4577 if not g_Map_GetPoint(c
, RespawnPoint
) then
4579 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4583 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4584 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4585 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4591 FDirection
:= RespawnPoint
.Direction
;
4592 if FDirection
= TDirection
.D_LEFT
then
4597 SetAction(A_STAND
, True);
4598 FModel
.Direction
:= FDirection
;
4600 for a
:= Low(FTime
) to High(FTime
) do
4603 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4608 FCanJetpack
:= False;
4613 // Àíèìàöèÿ âîçðîæäåíèÿ:
4614 if (not gLoadGameMode
) and (not Silent
) then
4615 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4617 Anim
:= TAnimation
.Create(ID
, False, 3);
4618 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4619 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4623 FSpectator
:= False;
4626 FSpectatePlayer
:= -1;
4629 if (gPlayer1
= nil) and (gLMSPID1
= FUID
) then
4631 if (gPlayer2
= nil) and (gLMSPID2
= FUID
) then
4634 if g_Game_IsNet
then
4636 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4637 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4639 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4640 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4645 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4648 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4649 else if (not NoMove
) then
4651 GameX
:= gMapInfo
.Width
div 2;
4652 GameY
:= gMapInfo
.Height
div 2;
4661 FWantsInGame
:= False;
4666 if Self
= gPlayer1
then
4671 if Self
= gPlayer2
then
4678 if g_Game_IsNet
then
4679 MH_SEND_PlayerStats(FUID
);
4682 procedure TPlayer
.SwitchNoClip
;
4686 FGhost
:= not FGhost
;
4687 FPhysics
:= not FGhost
;
4699 procedure TPlayer
.Run(Direction
: TDirection
);
4703 if MAX_RUNVEL
> 8 then
4707 if Direction
= TDirection
.D_LEFT
then
4709 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4710 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4713 if FObj
.Vel
.X
< MAX_RUNVEL
then
4714 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4716 // Âîçìîæíî, ïèíàåì êóñêè:
4717 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4719 b
:= Abs(FObj
.Vel
.X
);
4720 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4721 for a
:= 0 to High(gGibs
) do
4723 if gGibs
[a
].alive
and
4724 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4725 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4728 if FObj
.Vel
.X
< 0 then
4730 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4734 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4736 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4744 procedure TPlayer
.SeeDown();
4746 SetAction(A_SEEDOWN
);
4748 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4750 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4753 procedure TPlayer
.SeeUp();
4757 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4759 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4762 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4770 A_ATTACK
: Prior
:= 2;
4771 A_SEEUP
: Prior
:= 1;
4772 A_SEEDOWN
: Prior
:= 1;
4773 A_ATTACKUP
: Prior
:= 2;
4774 A_ATTACKDOWN
: Prior
:= 2;
4779 if (Prior
> FActionPrior
) or Force
then
4780 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4782 FActionPrior
:= Prior
;
4783 FActionAnim
:= Action
;
4784 FActionForce
:= Force
;
4785 FActionChanged
:= True;
4788 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4791 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4793 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4794 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4795 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4796 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4799 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4806 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4808 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4809 if g_Game_IsServer
and g_Game_IsNet
then
4810 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4814 FJustTeleported
:= True;
4819 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4821 Anim
:= TAnimation
.Create(ID
, False, 3);
4824 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4825 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4826 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4827 if g_Game_IsServer
and g_Game_IsNet
then
4828 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4829 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4833 FObj
.X
:= X
-PLAYER_RECT
.X
;
4834 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4835 if FAlive
and FGhost
then
4841 if not g_Game_IsNet
then
4845 SetDirection(TDirection
.D_LEFT
);
4851 SetDirection(TDirection
.D_RIGHT
);
4857 if FDirection
= TDirection
.D_RIGHT
then
4859 SetDirection(TDirection
.D_LEFT
);
4864 SetDirection(TDirection
.D_RIGHT
);
4870 if not silent
and (Anim
<> nil) then
4872 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4873 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4876 if g_Game_IsServer
and g_Game_IsNet
then
4877 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4878 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4885 function nonz(a
: Single): Single;
4893 function TPlayer
.followCorpse(): Boolean;
4898 if FAlive
or FSpectator
then
4900 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
4902 for i
:= 0 to High(gCorpses
) do
4903 if gCorpses
[i
] <> nil then
4904 if gCorpses
[i
].FPlayerUID
= FUID
then
4907 FObj
.X
:= gCorpses
[i
].FObj
.X
;
4908 FObj
.Y
:= gCorpses
[i
].FObj
.Y
;
4909 FObj
.Vel
.X
:= gCorpses
[i
].FObj
.Vel
.X
;
4910 FObj
.Vel
.Y
:= gCorpses
[i
].FObj
.Vel
.Y
;
4911 FObj
.Accel
.X
:= gCorpses
[i
].FObj
.Accel
.X
;
4912 FObj
.Accel
.Y
:= gCorpses
[i
].FObj
.Accel
.Y
;
4917 procedure TPlayer
.Update();
4920 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4921 blockmon
, headwater
, dospawn
: Boolean;
4926 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4927 AnyServer
:= g_Game_IsServer
;
4929 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4930 DoLerp(NetInterpLevel
+ 1)
4936 if FClientID
>= 0 then
4938 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4939 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4940 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4949 if FAlive
and (FPunchAnim
<> nil) then
4950 FPunchAnim
.Update();
4952 if FAlive
and (gFly
or FJetpack
) then
4955 if FDirection
= TDirection
.D_LEFT
then
4960 if FAlive
and (not FGhost
) then
4962 if FKeys
[KEY_UP
].Pressed
then
4964 if FKeys
[KEY_DOWN
].Pressed
then
4968 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4971 i
:= g_basic
.Sign(FIncCam
);
4972 FIncCam
:= Abs(FIncCam
);
4973 DecMin(FIncCam
, 5, 0);
4974 FIncCam
:= FIncCam
*i
;
4977 // no need to do that each second frame, weapon queue will take care of it
4978 if FAlive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4979 if FAlive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4981 if gTime
mod (GAME_TICK
*2) <> 0 then
4983 if (FObj
.Vel
.X
= 0) and FAlive
then
4985 if FKeys
[KEY_LEFT
].Pressed
then
4986 Run(TDirection
.D_LEFT
);
4987 if FKeys
[KEY_RIGHT
].Pressed
then
4988 Run(TDirection
.D_RIGHT
);
4993 if not followCorpse() then
4994 g_Obj_Move(@FObj
, True, True, True);
4995 positionChanged(); // this updates spatial accelerators
5001 FActionChanged
:= False;
5005 // Let alive player do some actions
5006 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
5007 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
5008 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
5009 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
5010 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
5011 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
5012 if FKeys
[KEY_JUMP
].Pressed
then Jump()
5015 if AnyServer
and FJetpack
then
5019 if NetServer
then MH_SEND_PlayerStats(FUID
);
5021 FCanJetpack
:= True;
5028 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
5030 if FKeys
[k
].Pressed
then
5038 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5041 if (FTime
[T_RESPAWN
] <= gTime
) and
5042 gGameOn
and (not FAlive
) then
5044 if (g_Player_GetCount() > 1) then
5048 gExit
:= EXIT_RESTART
;
5053 // Dead spectator actions
5056 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
5057 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
5061 if (FSpectatePlayer
>= High(gPlayers
)) then
5062 FSpectatePlayer
:= -1
5066 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
5067 if gPlayers
[I
] <> nil then
5068 if gPlayers
[I
].alive
then
5069 if gPlayers
[I
].UID
<> FUID
then
5071 FSpectatePlayer
:= I
;
5076 if not SetSpect
then FSpectatePlayer
:= -1;
5087 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5089 FYTo
:= FObj
.Y
- 32;
5090 FSpectatePlayer
:= -1;
5092 if FKeys
[KEY_DOWN
].Pressed
then
5094 FYTo
:= FObj
.Y
+ 32;
5095 FSpectatePlayer
:= -1;
5097 if FKeys
[KEY_LEFT
].Pressed
then
5099 FXTo
:= FObj
.X
- 32;
5100 FSpectatePlayer
:= -1;
5102 if FKeys
[KEY_RIGHT
].Pressed
then
5104 FXTo
:= FObj
.X
+ 32;
5105 FSpectatePlayer
:= -1;
5108 if (FXTo
< -64) then
5110 else if (FXTo
> gMapInfo
.Width
+ 32) then
5111 FXTo
:= gMapInfo
.Width
+ 32;
5112 if (FYTo
< -72) then
5114 else if (FYTo
> gMapInfo
.Height
+ 32) then
5115 FYTo
:= gMapInfo
.Height
+ 32;
5120 if not followCorpse() then
5121 g_Obj_Move(@FObj
, True, True, True);
5122 positionChanged(); // this updates spatial accelerators
5129 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5130 if gPlayers
[FSpectatePlayer
] <> nil then
5131 if gPlayers
[FSpectatePlayer
].alive
then
5133 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
5134 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
5138 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5139 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5140 PANEL_BLOCKMON
, True);
5141 headwater
:= HeadInLiquid(0, 0);
5143 // Ñîïðîòèâëåíèå âîçäóõà:
5144 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5145 if FObj
.Vel
.X
<> 0 then
5146 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5148 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5149 DecMin(FPain
, 5, 0);
5150 DecMin(FPickup
, 1, 0);
5152 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5154 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5155 FMegaRulez
[MR_SUIT
] := 0;
5156 FMegaRulez
[MR_INVUL
] := 0;
5157 FMegaRulez
[MR_INVIS
] := 0;
5158 Kill(K_FALLKILL
, 0, HIT_FALL
);
5165 if FCurrWeap
= WEAPON_SAW
then
5166 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5167 FSawSoundSelect
.IsPlaying()) then
5168 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5171 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5172 (not FJetSoundOff
.IsPlaying()) then
5174 FJetSoundFly
.SetPosition(0);
5175 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5178 for b
:= WP_FIRST
to WP_LAST
do
5179 if FReloading
[b
] > 0 then
5185 if FShellTimer
> -1 then
5186 if FShellTimer
= 0 then
5188 if FShellType
= SHELL_SHELL
then
5189 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5190 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5191 else if FShellType
= SHELL_DBLSHELL
then
5193 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5194 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5195 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5196 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5199 end else Dec(FShellTimer
);
5201 if (FBFGFireCounter
> -1) then
5202 if FBFGFireCounter
= 0 then
5206 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5207 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5208 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5209 yd
:= wy
+firediry();
5210 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5211 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5212 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5213 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5214 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5217 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5218 FBFGFireCounter
:= -1;
5221 FBFGFireCounter
:= 0
5223 Dec(FBFGFireCounter
);
5225 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5227 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5229 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5232 if (headwater
or blockmon
) then
5238 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5241 else if (FAir
mod 31 = 0) and not blockmon
then
5243 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5244 if Random(2) = 0 then
5245 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5247 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5249 end else if FAir
< AIR_DEF
then
5252 if FFireTime
> 0 then
5254 if BodyInLiquid(0, 0) then
5259 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5261 if FMegaRulez
[MR_SUIT
] = gTime
then
5268 if FFirePainTime
<= 0 then
5270 if g_Game_IsServer
then
5271 Damage(5, FFireAttacker
, 0, 0, HIT_FLAME
);
5272 FFirePainTime
:= 18;
5274 FFirePainTime
:= FFirePainTime
- 1;
5275 FFireTime
:= FFireTime
- 1;
5276 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5277 MH_SEND_PlayerStats(FUID
);
5281 if FDamageBuffer
> 0 then
5283 if FDamageBuffer
>= 9 then
5287 if FDamageBuffer
< 30 then i
:= 9
5288 else if FDamageBuffer
< 100 then i
:= 18
5292 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5293 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5294 FHealth
:= FHealth
-ii
;
5297 FHealth
:= FHealth
+FArmor
;
5302 if FHealth
<= 0 then
5303 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5304 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5305 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5309 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5310 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5311 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5312 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5319 end; // if FAlive then ...
5321 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5323 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5324 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5325 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5326 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5328 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5329 then SetAction(A_STAND
, True);
5331 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5333 for b
:= Low(FKeys
) to High(FKeys
) do
5334 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5338 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5340 x
:= FObj
.X
+PLAYER_RECT
.X
;
5341 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5342 w
:= PLAYER_RECT
.Width
;
5343 h
:= PLAYER_RECT
.Height
;
5347 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5349 if (dx
<> 0) or (dy
<> 0) then
5358 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5360 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5361 FObj
.Y
+PLAYER_RECT
.Y
,
5368 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5370 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5371 FObj
.Y
+PLAYER_RECT
.Y
,
5375 Panel
.Width
, Panel
.Height
);
5378 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5380 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5381 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5382 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5383 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5386 function g_Player_ValidName(Name
: string): Boolean;
5392 if gPlayers
= nil then Exit
;
5394 for a
:= 0 to High(gPlayers
) do
5395 if gPlayers
[a
] <> nil then
5396 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5403 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5407 d
:= FModel
.Direction
;
5409 FModel
.Direction
:= Direction
;
5410 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5412 FDirection
:= Direction
;
5415 function TPlayer
.GetKeys(): Byte;
5419 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5420 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5421 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5423 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5424 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5427 procedure TPlayer
.Use();
5431 if FTime
[T_USE
] > gTime
then Exit
;
5433 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5434 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5436 for a
:= 0 to High(gPlayers
) do
5437 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5438 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5439 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5440 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5442 gPlayers
[a
].Touch();
5443 if g_Game_IsNet
and g_Game_IsServer
then
5444 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5447 FTime
[T_USE
] := gTime
+120;
5450 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5454 WX
, WY
, XD
, YD
: Integer;
5466 if R_BERSERK
in FRulez
then
5468 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5469 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5470 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5473 locobj
.rect
.Width
:= 39;
5474 locobj
.rect
.Height
:= 52;
5475 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5476 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5477 locobj
.Accel
.X
:= xd
-wx
;
5478 locobj
.Accel
.y
:= yd
-wy
;
5480 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5481 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5483 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5487 FPain
:= min(FPain
+ 25, 50);
5489 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5494 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5495 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5497 FSawSoundSelect
.Stop();
5499 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5501 else if not FSawSoundHit
.IsPlaying() then
5503 FSawSoundSelect
.Stop();
5504 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5511 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5512 FFireAngle
:= FAngle
;
5514 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5515 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5520 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5521 FFireAngle
:= FAngle
;
5524 FShellType
:= SHELL_SHELL
;
5529 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5530 FFireAngle
:= FAngle
;
5533 FShellType
:= SHELL_DBLSHELL
;
5538 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5539 FFireAngle
:= FAngle
;
5541 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5542 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5545 WEAPON_ROCKETLAUNCHER
:
5547 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5548 FFireAngle
:= FAngle
;
5554 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5555 FFireAngle
:= FAngle
;
5561 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5562 FFireAngle
:= FAngle
;
5566 WEAPON_SUPERPULEMET
:
5568 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5569 FFireAngle
:= FAngle
;
5571 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5572 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5575 WEAPON_FLAMETHROWER
:
5577 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5578 FFireAngle
:= FAngle
;
5585 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5586 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5587 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5590 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5592 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5593 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5596 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5600 if NetInterpLevel
< 1 then
5610 AX
:= Abs(FXTo
- FObj
.X
);
5611 AY
:= Abs(FYTo
- FObj
.Y
);
5612 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5614 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5619 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5621 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5622 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5623 PANEL_LIFTUP
, False) then Result
:= -1
5625 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5626 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5627 PANEL_LIFTDOWN
, False) then Result
:= 1
5631 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5638 if Flag
= FLAG_NONE
then
5641 if not g_Game_IsServer
then Exit
;
5643 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5644 if (Flag
= FTeam
) and
5645 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5646 (FFlag
<> FLAG_NONE
) then
5648 if FFlag
= FLAG_RED
then
5649 s
:= _lc
[I_PLAYER_FLAG_RED
]
5651 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5653 evtype
:= FLAG_STATE_SCORED
;
5655 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5656 Insert('.', ts
, Length(ts
) + 1 - 3);
5657 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5659 g_Map_ResetFlag(FFlag
);
5660 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5662 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5665 if g_Game_IsNet
then
5667 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5671 gFlags
[FFlag
].CaptureTime
:= 0;
5676 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5677 if (Flag
= FTeam
) and
5678 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5680 if Flag
= FLAG_RED
then
5681 s
:= _lc
[I_PLAYER_FLAG_RED
]
5683 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5685 evtype
:= FLAG_STATE_RETURNED
;
5686 gFlags
[Flag
].CaptureTime
:= 0;
5688 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5690 g_Map_ResetFlag(Flag
);
5691 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5694 if g_Game_IsNet
then
5696 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5702 // Ïîäîáðàë ÷óæîé ôëàã:
5703 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5707 if Flag
= FLAG_RED
then
5708 s
:= _lc
[I_PLAYER_FLAG_RED
]
5710 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5712 evtype
:= FLAG_STATE_CAPTURED
;
5714 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5716 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5718 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5721 if g_Game_IsNet
then
5723 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5729 procedure TPlayer
.SetFlag(Flag
: Byte);
5732 if FModel
<> nil then
5733 FModel
.SetFlag(FFlag
);
5736 function TPlayer
.DropFlag(): Boolean;
5741 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5743 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5744 with gFlags
[FFlag
] do
5748 Direction
:= FDirection
;
5749 State
:= FLAG_STATE_DROPPED
;
5751 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5752 (FObj
.Vel
.Y
div 2)-2+Random(5));
5753 positionChanged(); // this updates spatial accelerators
5755 if FFlag
= FLAG_RED
then
5756 s
:= _lc
[I_PLAYER_FLAG_RED
]
5758 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5760 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5761 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5763 if g_Game_IsNet
then
5764 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5770 procedure TPlayer
.GetSecret();
5775 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5777 Assert(Key
<= High(FKeys
));
5779 FKeys
[Key
].Pressed
:= True;
5780 FKeys
[Key
].Time
:= Time
;
5783 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5785 Result
:= FKeys
[K
].Pressed
;
5788 procedure TPlayer
.ReleaseKeys();
5792 for a
:= Low(FKeys
) to High(FKeys
) do
5794 FKeys
[a
].Pressed
:= False;
5799 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5803 function TPlayer
.firediry(): Integer;
5805 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5806 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5810 procedure TPlayer
.RememberState();
5814 FSavedState
.Health
:= FHealth
;
5815 FSavedState
.Armor
:= FArmor
;
5816 FSavedState
.Air
:= FAir
;
5817 FSavedState
.JetFuel
:= FJetFuel
;
5818 FSavedState
.CurrWeap
:= FCurrWeap
;
5819 FSavedState
.NextWeap
:= FNextWeap
;
5820 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5823 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5825 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5827 FSavedState
.Rulez
:= FRulez
;
5828 FSavedState
.WaitRecall
:= True;
5831 procedure TPlayer
.RecallState();
5835 if not FSavedState
.WaitRecall
then Exit
;
5837 FHealth
:= FSavedState
.Health
;
5838 FArmor
:= FSavedState
.Armor
;
5839 FAir
:= FSavedState
.Air
;
5840 FJetFuel
:= FSavedState
.JetFuel
;
5841 FCurrWeap
:= FSavedState
.CurrWeap
;
5842 FNextWeap
:= FSavedState
.NextWeap
;
5843 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5846 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5848 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5850 FRulez
:= FSavedState
.Rulez
;
5851 FSavedState
.WaitRecall
:= False;
5853 if gGameSettings
.GameType
= GT_SERVER
then
5854 MH_SEND_PlayerStats(FUID
);
5857 procedure TPlayer
.SaveState (st
: TStream
);
5863 utils
.writeSign(st
, 'PLYR');
5864 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
5866 utils
.writeBool(st
, FIamBot
);
5868 utils
.writeInt(st
, Word(FUID
));
5870 utils
.writeStr(st
, FName
);
5872 utils
.writeInt(st
, Byte(FTeam
));
5874 utils
.writeBool(st
, FAlive
);
5875 // Èçðàñõîäîâàë ëè âñå æèçíè
5876 utils
.writeBool(st
, FNoRespawn
);
5878 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
5879 utils
.writeInt(st
, Byte(b
));
5881 utils
.writeInt(st
, LongInt(FHealth
));
5883 utils
.writeInt(st
, Byte(FLives
));
5885 utils
.writeInt(st
, LongInt(FArmor
));
5887 utils
.writeInt(st
, LongInt(FAir
));
5889 utils
.writeInt(st
, LongInt(FJetFuel
));
5891 utils
.writeInt(st
, LongInt(FPain
));
5893 utils
.writeInt(st
, LongInt(FKills
));
5895 utils
.writeInt(st
, LongInt(FMonsterKills
));
5897 utils
.writeInt(st
, LongInt(FFrags
));
5899 utils
.writeInt(st
, Byte(FFragCombo
));
5900 // Âðåìÿ ïîñëåäíåãî ôðàãà
5901 utils
.writeInt(st
, LongWord(FLastFrag
));
5903 utils
.writeInt(st
, LongInt(FDeath
));
5905 utils
.writeInt(st
, Byte(FFlag
));
5907 utils
.writeInt(st
, LongInt(FSecrets
));
5909 utils
.writeInt(st
, Byte(FCurrWeap
));
5911 utils
.writeInt(st
, Word(FNextWeap
));
5913 utils
.writeInt(st
, Byte(FNextWeapDelay
));
5914 // Âðåìÿ çàðÿäêè BFG
5915 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
5917 utils
.writeInt(st
, LongInt(FDamageBuffer
));
5918 // Ïîñëåäíèé óäàðèâøèé
5919 utils
.writeInt(st
, Word(FLastSpawnerUID
));
5920 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
5921 utils
.writeInt(st
, Byte(FLastHit
));
5923 Obj_SaveState(st
, @FObj
);
5924 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
5925 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
5926 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
5927 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
5929 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
5930 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
5931 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
5933 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
5934 // Íàëè÷èå êðàñíîãî êëþ÷à
5935 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
5936 // Íàëè÷èå çåëåíîãî êëþ÷à
5937 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
5938 // Íàëè÷èå ñèíåãî êëþ÷à
5939 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
5941 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
5942 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
5943 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
5944 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
5945 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
5947 utils
.writeStr(st
, FModel
.Name
);
5949 utils
.writeInt(st
, Byte(FColor
.R
));
5950 utils
.writeInt(st
, Byte(FColor
.G
));
5951 utils
.writeInt(st
, Byte(FColor
.B
));
5955 procedure TPlayer
.LoadState (st
: TStream
);
5964 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
5965 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
5967 FIamBot
:= utils
.readBool(st
);
5969 FUID
:= utils
.readWord(st
);
5971 str
:= utils
.readStr(st
);
5972 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
5974 FTeam
:= utils
.readByte(st
);
5976 FAlive
:= utils
.readBool(st
);
5977 // Èçðàñõîäîâàë ëè âñå æèçíè
5978 FNoRespawn
:= utils
.readBool(st
);
5980 b
:= utils
.readByte(st
);
5981 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
5983 FHealth
:= utils
.readLongInt(st
);
5985 FLives
:= utils
.readByte(st
);
5987 FArmor
:= utils
.readLongInt(st
);
5989 FAir
:= utils
.readLongInt(st
);
5991 FJetFuel
:= utils
.readLongInt(st
);
5993 FPain
:= utils
.readLongInt(st
);
5995 FKills
:= utils
.readLongInt(st
);
5997 FMonsterKills
:= utils
.readLongInt(st
);
5999 FFrags
:= utils
.readLongInt(st
);
6001 FFragCombo
:= utils
.readByte(st
);
6002 // Âðåìÿ ïîñëåäíåãî ôðàãà
6003 FLastFrag
:= utils
.readLongWord(st
);
6005 FDeath
:= utils
.readLongInt(st
);
6007 FFlag
:= utils
.readByte(st
);
6009 FSecrets
:= utils
.readLongInt(st
);
6011 FCurrWeap
:= utils
.readByte(st
);
6013 FNextWeap
:= utils
.readWord(st
);
6015 FNextWeapDelay
:= utils
.readByte(st
);
6016 // Âðåìÿ çàðÿäêè BFG
6017 FBFGFireCounter
:= utils
.readSmallInt(st
);
6019 FDamageBuffer
:= utils
.readLongInt(st
);
6020 // Ïîñëåäíèé óäàðèâøèé
6021 FLastSpawnerUID
:= utils
.readWord(st
);
6022 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6023 FLastHit
:= utils
.readByte(st
);
6025 Obj_LoadState(@FObj
, st
);
6026 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6027 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
6028 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6029 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
6031 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
6032 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6033 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
6035 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
6036 // Íàëè÷èå êðàñíîãî êëþ÷à
6037 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
6038 // Íàëè÷èå çåëåíîãî êëþ÷à
6039 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
6040 // Íàëè÷èå ñèíåãî êëþ÷à
6041 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
6043 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
6044 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6045 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
6046 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6047 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
6049 str
:= utils
.readStr(st
);
6051 FColor
.R
:= utils
.readByte(st
);
6052 FColor
.G
:= utils
.readByte(st
);
6053 FColor
.B
:= utils
.readByte(st
);
6054 if (self
= gPlayer1
) then
6056 str
:= gPlayer1Settings
.Model
;
6057 FColor
:= gPlayer1Settings
.Color
;
6059 else if (self
= gPlayer2
) then
6061 str
:= gPlayer2Settings
.Model
;
6062 FColor
:= gPlayer2Settings
.Color
;
6064 // Îáíîâëÿåì ìîäåëü èãðîêà
6066 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
6067 FModel
.Color
:= TEAMCOLOR
[FTeam
]
6069 FModel
.Color
:= FColor
;
6073 procedure TPlayer
.AllRulez(Health
: Boolean);
6079 FHealth
:= PLAYER_HP_LIMIT
;
6080 FArmor
:= PLAYER_AP_LIMIT
;
6084 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
6085 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
6086 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6089 procedure TPlayer
.RestoreHealthArmor();
6091 FHealth
:= PLAYER_HP_LIMIT
;
6092 FArmor
:= PLAYER_AP_LIMIT
;
6095 procedure TPlayer
.FragCombo();
6099 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6101 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6103 if FFragCombo
< 5 then
6105 Param
:= FUID
or (FFragCombo
shl 16);
6106 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6107 (FComboEvnt
<= High(gDelayedEvents
)) and
6108 gDelayedEvents
[FComboEvnt
].Pending
and
6109 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6110 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6112 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6113 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6116 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6124 procedure TPlayer
.GiveItem(ItemType
: Byte);
6128 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6130 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6134 if FAir
< AIR_MAX
then
6141 if not (R_BERSERK
in FRulez
) then
6143 Include(FRulez
, R_BERSERK
);
6144 if FBFGFireCounter
< 1 then
6146 FCurrWeap
:= WEAPON_KASTET
;
6148 FModel
.SetWeapon(WEAPON_KASTET
);
6152 FBerserk
:= gTime
+30000;
6154 if FHealth
< PLAYER_HP_SOFT
then
6156 FHealth
:= PLAYER_HP_SOFT
;
6157 FBerserk
:= gTime
+30000;
6162 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6164 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6168 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6170 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6174 if FJetFuel
< JET_MAX
then
6176 FJetFuel
:= JET_MAX
;
6179 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6180 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6182 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6183 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6185 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6187 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6189 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6190 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6193 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6194 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6195 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6196 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6197 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6198 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6199 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6200 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6201 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6203 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6204 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6205 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6206 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6207 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6208 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6209 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6210 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6211 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6214 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6215 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6216 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6217 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6218 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6220 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6221 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6222 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6223 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6224 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6226 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6227 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6228 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6229 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6231 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6234 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6235 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6236 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6238 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6239 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6244 if g_Game_IsNet
and g_Game_IsServer
then
6245 MH_SEND_PlayerStats(FUID
);
6248 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6253 if (Random(5) = 1) and (Times
= 1) then
6256 if BodyInLiquid(0, 0) then
6258 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6259 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6260 if Random(2) = 0 then
6261 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6263 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6267 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6269 for i
:= 1 to Times
do
6271 Anim
:= TAnimation
.Create(id
, False, 3);
6273 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6274 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6280 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6285 if (Random(10) = 1) and (Times
= 1) then
6288 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6290 for i
:= 1 to Times
do
6292 Anim
:= TAnimation
.Create(id
, False, 3);
6294 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6295 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6301 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6303 FSawSound
.Pause(Enable
);
6304 FSawSoundIdle
.Pause(Enable
);
6305 FSawSoundHit
.Pause(Enable
);
6306 FSawSoundSelect
.Pause(Enable
);
6311 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6316 FObj
.Rect
:= PLAYER_CORPSERECT
;
6317 FModelName
:= ModelName
;
6322 FState
:= CORPSE_STATE_MESS
;
6323 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6327 FState
:= CORPSE_STATE_NORMAL
;
6328 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6332 destructor TCorpse
.Destroy();
6339 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6341 procedure TCorpse
.positionChanged (); inline; begin end;
6343 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6345 if (dx
<> 0) or (dy
<> 0) then
6354 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6356 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6357 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6358 w
:= PLAYER_CORPSERECT
.Width
;
6359 h
:= PLAYER_CORPSERECT
.Height
;
6363 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6368 if FState
= CORPSE_STATE_REMOVEME
then
6371 FDamage
:= FDamage
+ Value
;
6373 if FDamage
> 150 then
6375 if FAnimation
<> nil then
6380 FState
:= CORPSE_STATE_REMOVEME
;
6382 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6383 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6384 FModelName
, FColor
);
6385 // Çâóê ìÿñà îò òðóïà:
6386 pm
:= g_PlayerModel_Get(FModelName
);
6387 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6391 if (gBodyKillEvent
<> -1)
6392 and gDelayedEvents
[gBodyKillEvent
].Pending
then
6393 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
6394 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, 0);
6399 Blood
:= g_PlayerModel_GetBlood(FModelName
);
6400 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6401 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6402 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6403 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6404 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6405 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
6409 procedure TCorpse
.Draw();
6411 if FState
= CORPSE_STATE_REMOVEME
then
6414 if FAnimation
<> nil then
6415 FAnimation
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6417 if FAnimationMask
<> nil then
6420 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6427 procedure TCorpse
.Update();
6431 if FState
= CORPSE_STATE_REMOVEME
then
6434 if gTime
mod (GAME_TICK
*2) <> 0 then
6436 g_Obj_Move(@FObj
, True, True, True);
6437 positionChanged(); // this updates spatial accelerators
6441 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6442 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6444 st
:= g_Obj_Move(@FObj
, True, True, True);
6445 positionChanged(); // this updates spatial accelerators
6447 if WordBool(st
and MOVE_FALLOUT
) then
6449 FState
:= CORPSE_STATE_REMOVEME
;
6453 if FAnimation
<> nil then
6454 FAnimation
.Update();
6455 if FAnimationMask
<> nil then
6456 FAnimationMask
.Update();
6460 procedure TCorpse
.SaveState (st
: TStream
);
6467 utils
.writeSign(st
, 'CORP');
6468 utils
.writeInt(st
, Byte(0));
6470 utils
.writeInt(st
, Byte(FState
));
6472 utils
.writeInt(st
, Byte(FDamage
));
6474 utils
.writeInt(st
, Byte(FColor
.R
));
6475 utils
.writeInt(st
, Byte(FColor
.G
));
6476 utils
.writeInt(st
, Byte(FColor
.B
));
6478 Obj_SaveState(st
, @FObj
);
6479 utils
.writeInt(st
, Word(FPlayerUID
));
6481 anim
:= (FAnimation
<> nil);
6482 utils
.writeBool(st
, anim
);
6483 // Åñëè åñòü - ñîõðàíÿåì
6484 if anim
then FAnimation
.SaveState(st
);
6485 // Åñòü ëè ìàñêà àíèìàöèè
6486 anim
:= (FAnimationMask
<> nil);
6487 utils
.writeBool(st
, anim
);
6488 // Åñëè åñòü - ñîõðàíÿåì
6489 if anim
then FAnimationMask
.SaveState(st
);
6493 procedure TCorpse
.LoadState (st
: TStream
);
6500 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6501 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6503 FState
:= utils
.readByte(st
);
6505 FDamage
:= utils
.readByte(st
);
6507 FColor
.R
:= utils
.readByte(st
);
6508 FColor
.G
:= utils
.readByte(st
);
6509 FColor
.B
:= utils
.readByte(st
);
6511 Obj_LoadState(@FObj
, st
);
6512 FPlayerUID
:= utils
.readWord(st
);
6514 anim
:= utils
.readBool(st
);
6515 // Åñëè åñòü - çàãðóæàåì
6518 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6519 FAnimation
.LoadState(st
);
6521 // Åñòü ëè ìàñêà àíèìàöèè
6522 anim
:= utils
.readBool(st
);
6523 // Åñëè åñòü - çàãðóæàåì
6526 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6527 FAnimationMask
.LoadState(st
);
6533 constructor TBot
.Create();
6540 FSpectator
:= False;
6547 for a
:= WP_FIRST
to WP_LAST
do
6549 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6550 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6551 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6555 destructor TBot
.Destroy();
6558 inherited Destroy();
6561 procedure TBot
.Draw();
6565 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6566 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6569 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6571 inherited Respawn(Silent
, Force
);
6574 FSelectedWeapon
:= FCurrWeap
;
6579 procedure TBot
.UpdateCombat();
6592 TTargetRecord
= array of TTarget
;
6594 function Compare(a
, b
: TTarget
): Integer;
6596 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6599 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6601 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6602 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6604 if a
.Dist
> b
.Dist
then // B áëèæå
6606 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6609 else // Ñòðàííî -> A
6614 a
, x1
, y1
, x2
, y2
: Integer;
6615 targets
: TTargetRecord
;
6617 Target
, BestTarget
: TTarget
;
6618 firew
, fireh
: Integer;
6622 vsPlayer
, vsMonster
, ok
: Boolean;
6625 function monsUpdate (mon
: TMonster
): Boolean;
6627 result
:= false; // don't stop
6628 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6630 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6632 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6633 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6635 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6636 if g_TraceVector(x1
, y1
, x2
, y2
) then
6638 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6639 SetLength(targets
, Length(targets
)+1);
6640 with targets
[High(targets
)] do
6647 Rect
:= mon
.Obj
.Rect
;
6648 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6649 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6650 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6659 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6660 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6662 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6663 if FCurrWeap
<> FSelectedWeapon
then
6666 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6667 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6669 RemoveAIFlag('NEEDFIRE');
6672 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6673 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6674 else PressKey(KEY_FIRE
);
6678 // Êîîðäèíàòû ñòâîëà:
6679 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6680 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6682 Target
.UID
:= FTargetUID
;
6685 if Target
.UID
<> 0 then
6686 begin // Öåëü åñòü - íàñòðàèâàåì
6687 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6690 tpla
:= g_Player_Get(Target
.UID
);
6694 if (@FObj
) <> nil then
6701 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6702 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6703 Target
.Rect
:= PLAYER_RECT
;
6704 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6705 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6706 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6707 Target
.IsPlayer
:= True;
6711 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6714 mon
:= g_Monsters_ByUID(Target
.UID
);
6717 Target
.X
:= mon
.Obj
.X
;
6718 Target
.Y
:= mon
.Obj
.Y
;
6720 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6721 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6722 Target
.Rect
:= mon
.Obj
.Rect
;
6723 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6724 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6725 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6726 Target
.IsPlayer
:= False;
6733 begin // Öåëè íåò - îáíóëÿåì
6738 Target
.Visible
:= False;
6739 Target
.Line
:= False;
6740 Target
.IsPlayer
:= False;
6745 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6746 if (not Target
.Line
) or (not Target
.Visible
) then
6750 for a
:= 0 to High(gPlayers
) do
6751 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6752 (gPlayers
[a
].FUID
<> FUID
) and
6753 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6754 (not gPlayers
[a
].NoTarget
) and
6755 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6757 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6758 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6761 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6762 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6764 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6765 if g_TraceVector(x1
, y1
, x2
, y2
) then
6767 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6768 SetLength(targets
, Length(targets
)+1);
6769 with targets
[High(targets
)] do
6771 UID
:= gPlayers
[a
].FUID
;
6772 X
:= gPlayers
[a
].FObj
.X
;
6773 Y
:= gPlayers
[a
].FObj
.Y
;
6776 Rect
:= PLAYER_RECT
;
6777 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6778 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6779 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6787 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6790 // Åñëè åñòü âîçìîæíûå öåëè:
6791 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6792 if targets
<> nil then
6794 // Âûáèðàåì íàèëó÷øóþ öåëü:
6795 BestTarget
:= targets
[0];
6796 if Length(targets
) > 1 then
6797 for a
:= 1 to High(targets
) do
6798 if Compare(BestTarget
, targets
[a
]) = 1 then
6799 BestTarget
:= targets
[a
];
6801 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6802 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6803 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6805 Target
:= BestTarget
;
6807 if (Healthy() = 3) or ((Healthy() = 2)) then
6808 begin // Åñëè çäîðîâû - äîãîíÿåì
6809 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6810 SetAIFlag('GORIGHT', '1');
6811 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6812 SetAIFlag('GOLEFT', '1');
6815 begin // Åñëè ïîáèòû - óáåãàåì
6816 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6817 SetAIFlag('GORIGHT', '1');
6818 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6819 SetAIFlag('GOLEFT', '1');
6822 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6823 SelectWeapon(Abs(x1
-Target
.cX
));
6828 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6829 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6830 if Target
.UID
<> 0 then
6832 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6833 Target
.Y
+ Target
.Rect
.Y
) then
6834 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6835 if (Healthy() = 3) or ((Healthy() = 2)) then
6836 begin // Åñëè çäîðîâû - äîãîíÿåì
6837 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6838 SetAIFlag('GORIGHT', '1');
6839 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6840 SetAIFlag('GOLEFT', '1');
6843 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6845 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6846 SetAIFlag('GORIGHT', '1');
6847 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6848 SetAIFlag('GOLEFT', '1');
6852 begin // Öåëü ïîêà íà "ýêðàíå"
6853 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6854 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6855 FLastVisible
:= gTime
;
6856 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6857 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6859 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6860 SetAIFlag('GORIGHT', '1');
6861 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6862 SetAIFlag('GOLEFT', '1');
6866 // Âûáèðàåì óãîë ââåðõ:
6867 if FDirection
= TDirection
.D_LEFT
then
6868 angle
:= ANGLE_LEFTUP
6870 angle
:= ANGLE_RIGHTUP
;
6872 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6873 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6875 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6876 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6877 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6878 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6879 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6880 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6881 begin // òî íóæíî ñòðåëÿòü ââåðõ
6882 SetAIFlag('NEEDFIRE', '1');
6883 SetAIFlag('NEEDSEEUP', '1');
6886 // Âûáèðàåì óãîë âíèç:
6887 if FDirection
= TDirection
.D_LEFT
then
6888 angle
:= ANGLE_LEFTDOWN
6890 angle
:= ANGLE_RIGHTDOWN
;
6892 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6893 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6895 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6896 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6897 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6898 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6899 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6900 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6901 begin // òî íóæíî ñòðåëÿòü âíèç
6902 SetAIFlag('NEEDFIRE', '1');
6903 SetAIFlag('NEEDSEEDOWN', '1');
6906 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6907 if Target
.Visible
and
6908 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6909 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6911 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6912 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
6913 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6914 begin // òî íóæíî ñòðåëÿòü âïåðåä
6915 SetAIFlag('NEEDFIRE', '1');
6916 SetAIFlag('NEEDSEEDOWN', '');
6917 SetAIFlag('NEEDSEEUP', '');
6919 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6920 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6921 if GetRnd(FDifficult
.CloseJump
) then
6922 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6923 if Abs(FObj
.X
-Target
.X
) < 128 then
6927 if Random(a
) = 0 then
6928 SetAIFlag('NEEDJUMP', '1');
6932 // Åñëè öåëü âñå åùå åñòü:
6933 if Target
.UID
<> 0 then
6934 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
6935 Target
.UID
:= 0 // òî çàáûòü öåëü
6936 else // Åñëè âèäåëè íåäàâíî
6937 begin // íî öåëü óáèëè
6938 if Target
.IsPlayer
then
6939 begin // Öåëü - èãðîê
6940 pla
:= g_Player_Get(Target
.UID
);
6941 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
6942 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6943 Target
.UID
:= 0; // òî çàáûòü öåëü
6946 begin // Öåëü - ìîíñòð
6947 mon
:= g_Monsters_ByUID(Target
.UID
);
6948 if (mon
= nil) or (not mon
.alive
) then
6949 Target
.UID
:= 0; // òî çàáûòü öåëü
6952 end; // if Target.UID <> 0
6954 FTargetUID
:= Target
.UID
;
6956 // Åñëè âîçìîæíûõ öåëåé íåò:
6957 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
6958 if targets
= nil then
6959 if GetAIFlag('ATTACKLEFT') <> '' then
6960 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
6961 RemoveAIFlag('ATTACKLEFT');
6963 SetAIFlag('NEEDJUMP', '1');
6965 if RunDirection() = TDirection
.D_RIGHT
then
6966 begin // Èäåì íå â òó ñòîðîíó
6967 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6968 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
6969 SetAIFlag('NEEDFIRE', '1');
6970 SetAIFlag('GOLEFT', '1');
6974 begin // Èäåì â íóæíóþ ñòîðîíó
6975 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6976 SetAIFlag('NEEDFIRE', '1');
6977 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6978 SetAIFlag('GORIGHT', '1');
6982 if GetAIFlag('ATTACKRIGHT') <> '' then
6983 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
6984 RemoveAIFlag('ATTACKRIGHT');
6986 SetAIFlag('NEEDJUMP', '1');
6988 if RunDirection() = TDirection
.D_LEFT
then
6989 begin // Èäåì íå â òó ñòîðîíó
6990 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6991 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
6992 SetAIFlag('NEEDFIRE', '1');
6993 SetAIFlag('GORIGHT', '1');
6998 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6999 SetAIFlag('NEEDFIRE', '1');
7000 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7001 SetAIFlag('GOLEFT', '1');
7005 //HACK! (does it belongs there?)
7006 RealizeCurrentWeapon();
7008 // Åñëè åñòü âîçìîæíûå öåëè:
7009 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7010 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7011 for a
:= 0 to High(targets
) do
7013 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7014 if GetRnd(FDifficult
.DiagFire
) then
7016 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7017 if FDirection
= TDirection
.D_LEFT
then
7018 angle
:= ANGLE_LEFTUP
7020 angle
:= ANGLE_RIGHTUP
;
7022 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7023 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7025 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7026 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7027 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7028 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7029 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7031 SetAIFlag('NEEDFIRE', '1');
7032 SetAIFlag('NEEDSEEUP', '1');
7035 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7036 if FDirection
= TDirection
.D_LEFT
then
7037 angle
:= ANGLE_LEFTDOWN
7039 angle
:= ANGLE_RIGHTDOWN
;
7041 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7042 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7044 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7045 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7046 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7047 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7048 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7050 SetAIFlag('NEEDFIRE', '1');
7051 SetAIFlag('NEEDSEEDOWN', '1');
7055 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7056 if targets
[a
].Line
and targets
[a
].Visible
and
7057 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
7058 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
7060 SetAIFlag('NEEDFIRE', '1');
7065 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7066 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
7067 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
7068 40+GetInterval(FDifficult
.Cover
, 40)) then
7069 SetAIFlag('NEEDJUMP', '1');
7071 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7072 ammo
:= GetAmmoByWeapon(FCurrWeap
);
7073 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
7074 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
7076 SetAIFlag('SELECTWEAPON', '1');
7078 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7079 if GetAIFlag('SELECTWEAPON') = '1' then
7082 RemoveAIFlag('SELECTWEAPON');
7086 procedure TBot
.Update();
7099 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7100 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7102 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7104 if g_debug_BotAIOff
= 3 then
7114 RealizeCurrentWeapon();
7121 procedure TBot
.ReleaseKey(Key
: Byte);
7130 function TBot
.KeyPressed(Key
: Word): Boolean;
7132 Result
:= FKeys
[Key
].Pressed
;
7135 function TBot
.GetAIFlag(aName
: String20
): String20
;
7141 aName
:= LowerCase(aName
);
7143 if FAIFlags
<> nil then
7144 for a
:= 0 to High(FAIFlags
) do
7145 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7147 Result
:= FAIFlags
[a
].Value
;
7152 procedure TBot
.RemoveAIFlag(aName
: String20
);
7156 if FAIFlags
= nil then Exit
;
7158 aName
:= LowerCase(aName
);
7160 for a
:= 0 to High(FAIFlags
) do
7161 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7163 if a
<> High(FAIFlags
) then
7164 for b
:= a
to High(FAIFlags
)-1 do
7165 FAIFlags
[b
] := FAIFlags
[b
+1];
7167 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7172 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7180 aName
:= LowerCase(aName
);
7182 if FAIFlags
<> nil then
7183 for a
:= 0 to High(FAIFlags
) do
7184 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7190 if ok
then FAIFlags
[a
].Value
:= fValue
7193 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7194 with FAIFlags
[High(FAIFlags
)] do
7202 procedure TBot
.UpdateMove
;
7204 procedure GoLeft(Time
: Word = 1);
7206 ReleaseKey(KEY_LEFT
);
7207 ReleaseKey(KEY_RIGHT
);
7208 PressKey(KEY_LEFT
, Time
);
7209 SetDirection(TDirection
.D_LEFT
);
7212 procedure GoRight(Time
: Word = 1);
7214 ReleaseKey(KEY_LEFT
);
7215 ReleaseKey(KEY_RIGHT
);
7216 PressKey(KEY_RIGHT
, Time
);
7217 SetDirection(TDirection
.D_RIGHT
);
7220 function Rnd(a
: Word): Boolean;
7222 Result
:= Random(a
) = 0;
7225 procedure Turn(Time
: Word = 1200);
7227 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7232 ReleaseKey(KEY_LEFT
);
7233 ReleaseKey(KEY_RIGHT
);
7236 function CanRunLeft(): Boolean;
7238 Result
:= not CollideLevel(-1, 0);
7241 function CanRunRight(): Boolean;
7243 Result
:= not CollideLevel(1, 0);
7246 function CanRun(): Boolean;
7248 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7251 procedure Jump(Time
: Word = 30);
7253 PressKey(KEY_JUMP
, Time
);
7256 function NearHole(): Boolean;
7260 { TODO 5 : Ëåñòíèöû }
7261 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7262 for x
:= 1 to PLAYER_RECT
.Width
do
7263 if (not StayOnStep(x
*sx
, 0)) and
7264 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7265 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7274 function BorderHole(): Boolean;
7278 { TODO 5 : Ëåñòíèöû }
7279 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7280 for x
:= 1 to PLAYER_RECT
.Width
do
7281 if (not StayOnStep(x
*sx
, 0)) and
7282 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7283 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7285 for xx
:= x
to x
+32 do
7286 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7296 function NearDeepHole(): Boolean;
7302 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7305 for x
:= 1 to PLAYER_RECT
.Width
do
7306 if (not StayOnStep(x
*sx
, 0)) and
7307 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7308 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7310 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7312 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7317 end else Result
:= False;
7320 function OverDeepHole(): Boolean;
7327 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7329 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7336 function OnGround(): Boolean;
7338 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7341 function OnLadder(): Boolean;
7343 Result
:= FullInStep(0, 0);
7346 function BelowLadder(): Boolean;
7348 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7349 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7350 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7351 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7354 function BelowLiftUp(): Boolean;
7356 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7357 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7358 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7359 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7362 function OnTopLift(): Boolean;
7364 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7367 function CanJumpOver(): Boolean;
7371 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7375 if not CollideLevel(sx
, 0) then Exit
;
7377 for y
:= 1 to BOT_MAXJUMP
do
7378 if CollideLevel(0, -y
) then Exit
else
7379 if not CollideLevel(sx
, -y
) then
7386 function CanJumpUp(Dist
: ShortInt): Boolean;
7393 if CollideLevel(Dist
, 0) then Exit
;
7396 for y
:= 0 to BOT_MAXJUMP
do
7397 if CollideLevel(Dist
, -y
) then
7406 for yy
:= y
+1 to BOT_MAXJUMP
do
7407 if not CollideLevel(Dist
, -yy
) then
7416 for y
:= 0 to BOT_MAXJUMP
do
7417 if CollideLevel(0, -y
) then
7425 if y
< yy
then Exit
;
7430 function IsSafeTrigger(): Boolean;
7435 if gTriggers
= nil then
7437 for a
:= 0 to High(gTriggers
) do
7438 if Collide(gTriggers
[a
].X
,
7441 gTriggers
[a
].Height
) and
7442 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7443 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7444 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7445 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7446 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7451 // Âîçìîæíî, íàæèìàåì êíîïêó:
7452 if Rnd(16) and IsSafeTrigger() then
7455 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7456 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7458 ReleaseKey(KEY_LEFT
);
7459 ReleaseKey(KEY_RIGHT
);
7463 // Èäåì âëåâî, åñëè íàäî áûëî:
7464 if GetAIFlag('GOLEFT') <> '' then
7466 RemoveAIFlag('GOLEFT');
7467 if CanRunLeft() then
7471 // Èäåì âïðàâî, åñëè íàäî áûëî:
7472 if GetAIFlag('GORIGHT') <> '' then
7474 RemoveAIFlag('GORIGHT');
7475 if CanRunRight() then
7479 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7480 if FObj
.X
< -32 then
7483 if FObj
.X
+32 > gMapInfo
.Width
then
7486 // Ïðûãàåì, åñëè íàäî áûëî:
7487 if GetAIFlag('NEEDJUMP') <> '' then
7490 RemoveAIFlag('NEEDJUMP');
7493 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7494 if GetAIFlag('NEEDSEEUP') <> '' then
7497 ReleaseKey(KEY_DOWN
);
7498 PressKey(KEY_UP
, 20);
7499 RemoveAIFlag('NEEDSEEUP');
7502 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7503 if GetAIFlag('NEEDSEEDOWN') <> '' then
7506 ReleaseKey(KEY_DOWN
);
7507 PressKey(KEY_DOWN
, 20);
7508 RemoveAIFlag('NEEDSEEDOWN');
7511 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7512 if GetAIFlag('GOINHOLE') <> '' then
7513 if not OnGround() then
7515 ReleaseKey(KEY_LEFT
);
7516 ReleaseKey(KEY_RIGHT
);
7517 RemoveAIFlag('GOINHOLE');
7518 SetAIFlag('FALLINHOLE', '1');
7521 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7522 if GetAIFlag('FALLINHOLE') <> '' then
7524 RemoveAIFlag('FALLINHOLE');
7526 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7527 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7528 if GetAIFlag('FALLINHOLE') = '' then
7529 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7535 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7537 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7541 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7542 if OnGround() and NearHole() then
7543 if NearDeepHole() then // Åñëè ýòî áåçäíà
7545 0..3: Turn(); // Áåæèì îáðàòíî
7546 4: Jump(); // Ïðûãàåì
7547 5: begin // Ïðûãàåì îáðàòíî
7552 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7553 if GetAIFlag('GOINHOLE') = '' then
7555 0: Turn(); // Íå íóæíî òóäà
7556 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7557 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7558 if BorderHole() then
7559 SetAIFlag('GOINHOLE', '1');
7562 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7563 if (not CanRun()) and OnGround() then
7565 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7566 if CanJumpOver() or OnLadder() then
7568 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7569 if Random(2) = 0 then
7571 if IsSafeTrigger() then
7577 // Îñòàëîñü ìàëî âîçäóõà:
7578 if FAir
< 36 * 2 then
7581 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7582 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7583 if BodyInAcid(0, 0) then
7587 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7589 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7590 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7593 {function TBot.NeedItem(Item: Byte): Byte;
7598 procedure TBot
.SelectWeapon(Dist
: Integer);
7602 function HaveAmmo(weapon
: Byte): Boolean;
7605 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7606 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7607 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7608 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7609 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7610 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7611 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7612 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7613 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7614 else Result
:= True;
7619 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7621 if Dist
> BOT_LONGDIST
then
7622 begin // Äàëüíèé áîé
7624 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7626 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7630 else //if Dist > BOT_UNSAFEDIST then
7631 begin // Áëèæíèé áîé
7633 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7635 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7642 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7644 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7650 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7652 Result
:= inherited PickItem(ItemType
, force
, remove
);
7654 if Result
then SetAIFlag('SELECTWEAPON', '1');
7657 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7659 Result
:= inherited Heal(value
, Soft
);
7662 function TBot
.Healthy(): Byte;
7664 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7665 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7666 else if (FHealth
> 50) then Result
:= 2
7667 else if (FHealth
> 20) then Result
:= 1
7671 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7673 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7674 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7677 procedure TBot
.OnDamage(Angle
: SmallInt);
7685 if (Angle
= 0) or (Angle
= 180) then
7688 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7689 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7691 pla
:= g_Player_Get(FLastSpawnerUID
);
7692 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7693 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7696 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7697 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7699 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7700 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7701 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7706 SetAIFlag('ATTACKLEFT', '1')
7708 SetAIFlag('ATTACKRIGHT', '1');
7712 function TBot
.RunDirection(): TDirection
;
7714 if Abs(Vel
.X
) >= 1 then
7716 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7718 Result
:= FDirection
;
7721 function TBot
.GetRnd(a
: Byte): Boolean;
7723 if a
= 0 then Result
:= False
7724 else if a
= 255 then Result
:= True
7725 else Result
:= Random(256) > 255-a
;
7728 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7730 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7734 procedure TDifficult
.save (st
: TStream
);
7736 utils
.writeInt(st
, Byte(DiagFire
));
7737 utils
.writeInt(st
, Byte(InvisFire
));
7738 utils
.writeInt(st
, Byte(DiagPrecision
));
7739 utils
.writeInt(st
, Byte(FlyPrecision
));
7740 utils
.writeInt(st
, Byte(Cover
));
7741 utils
.writeInt(st
, Byte(CloseJump
));
7742 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7743 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7746 procedure TDifficult
.load (st
: TStream
);
7748 DiagFire
:= utils
.readByte(st
);
7749 InvisFire
:= utils
.readByte(st
);
7750 DiagPrecision
:= utils
.readByte(st
);
7751 FlyPrecision
:= utils
.readByte(st
);
7752 Cover
:= utils
.readByte(st
);
7753 CloseJump
:= utils
.readByte(st
);
7754 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7755 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7759 procedure TBot
.SaveState (st
: TStream
);
7764 inherited SaveState(st
);
7765 utils
.writeSign(st
, 'BOT0');
7767 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7769 utils
.writeInt(st
, Word(FTargetUID
));
7770 // Âðåìÿ ïîòåðè öåëè
7771 utils
.writeInt(st
, LongWord(FLastVisible
));
7772 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7773 dw
:= Length(FAIFlags
);
7774 utils
.writeInt(st
, LongInt(dw
));
7776 for i
:= 0 to dw
-1 do
7778 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7779 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7781 // Íàñòðîéêè ñëîæíîñòè
7782 FDifficult
.save(st
);
7786 procedure TBot
.LoadState (st
: TStream
);
7791 inherited LoadState(st
);
7792 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7794 FSelectedWeapon
:= utils
.readByte(st
);
7796 FTargetUID
:= utils
.readWord(st
);
7797 // Âðåìÿ ïîòåðè öåëè
7798 FLastVisible
:= utils
.readLongWord(st
);
7799 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7800 dw
:= utils
.readLongInt(st
);
7801 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7802 SetLength(FAIFlags
, dw
);
7804 for i
:= 0 to dw
-1 do
7806 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7807 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7809 // Íàñòðîéêè ñëîæíîñòè
7810 FDifficult
.load(st
);
7815 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);