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
: result
:= (FAmmo
[A_SHELLS
] > 0);
3578 WEAPON_PISTOL
, WEAPON_CHAINGUN
, WEAPON_SUPERPULEMET
: 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_BFG
;
3623 weaponOrder
[1] := WEAPON_ROCKETLAUNCHER
;
3624 weaponOrder
[2] := WEAPON_PLASMA
;
3625 weaponOrder
[3] := WEAPON_FLAMETHROWER
;
3626 weaponOrder
[4] := WEAPON_SHOTGUN2
;
3627 weaponOrder
[5] := WEAPON_CHAINGUN
;
3628 weaponOrder
[6] := WEAPON_SHOTGUN1
;
3629 weaponOrder
[7] := WEAPON_PISTOL
;
3630 weaponOrder
[8] := WEAPON_KASTET
+666; // berserk fist
3631 weaponOrder
[9] := WEAPON_SAW
;
3632 weaponOrder
[10] := WEAPON_KASTET
; // normal fist
3633 weaponOrder
[11] := WEAPON_SUPERPULEMET
;
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;
3694 for i
:= 0 to High(FWeapon
) do
3696 if (FNextWeap
and (1 shl i
)) <> 0 then
3699 if (cwi
>= 0) then wantThisWeapon
[cwi
] := true;
3704 // slow down alterations a little
3707 // more than one weapon requested, assume "alteration", and check alteration delay
3708 if FNextWeapDelay
> 0 then
3710 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), TMsgType.Warning);
3716 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3717 // but clear all counters if no weapon should be switched
3724 // exclude currently selected weapon from the set
3725 curlidx
:= real2log(FCurrWeap
);
3726 //e_WriteLog(Format('*** wwc=%d; currweap=%d; logweap=%d', [wwc, FCurrWeap, curlidx]), TMsgType.Warning);
3727 //e_WriteLog(Format('FCurrWeap=%d; curlidx=%d', [FCurrWeap, curlidx]), TMsgType.Warning);
3728 //if (curlidx >= 0) then wantThisWeapon[curlidx] := false;
3729 //if (wwc = 2) then begin Dec(wwc); end; // easy case: switch between two weapons
3731 // find next weapon to switch onto
3733 for i
:= 0 to High(FWeapon
) do
3735 cwi
:= (cwi
+length(FWeapon
)+1) mod length(FWeapon
);
3736 if (cwi
= curlidx
) then continue
; // skip current weapon
3737 if not wantThisWeapon
[cwi
] then continue
;
3738 rwidx
:= weaponOrder
[cwi
];
3739 if (rwidx
< 0) then continue
;
3740 //e_WriteLog(Format(' trying logical %d (real %d)', [cwi, rwidx]), TMsgType.Warning);
3741 if FWeapon
[rwidx
] and ((wwc
= 1) or hasAmmoForWeapon(rwidx
)) then
3743 //e_WriteLog(' I FOUND HER!', TMsgType.Warning);
3745 result
:= Byte(rwidx
);
3747 FNextWeapDelay
:= 10; // anyway, 'cause why not
3752 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3756 procedure TPlayer
.RealizeCurrentWeapon();
3757 function switchAllowed (): Boolean;
3762 if FBFGFireCounter
<> -1 then
3764 if FTime
[T_SWITCH
] > gTime
then
3766 for i
:= WP_FIRST
to WP_LAST
do
3767 if FReloading
[i
] > 0 then
3775 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3776 //FNextWeap := FNextWeap and $1FFF;
3777 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3779 if not switchAllowed
then
3781 //HACK for weapon cycling
3782 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3786 nw
:= getNextWeaponIndex();
3787 if nw
= 255 then exit
; // don't reset anything here
3788 if nw
> High(FWeapon
) then
3790 // don't forget to reset queue here!
3791 //e_WriteLog(Format(' RealizeCurrentWeapon: WUTAFUUUU?! (%d)', [nw]), TMsgType.Warning);
3799 FTime
[T_SWITCH
] := gTime
+156;
3800 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3801 FModel
.SetWeapon(FCurrWeap
);
3802 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3806 procedure TPlayer
.NextWeapon();
3808 if g_Game_IsClient
then Exit
;
3812 procedure TPlayer
.PrevWeapon();
3814 if g_Game_IsClient
then Exit
;
3818 procedure TPlayer
.SetWeapon(W
: Byte);
3820 if FCurrWeap
<> W
then
3821 if W
= WEAPON_SAW
then
3822 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3825 FModel
.SetWeapon(CurrWeap
);
3829 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3831 function allowBerserkSwitching (): Boolean;
3833 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3835 if gBerserkAutoswitch
then exit
;
3836 if not conIsCheatsEnabled
then exit
;
3844 if g_Game_IsClient
then Exit
;
3846 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3847 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3852 if FHealth
< PLAYER_HP_SOFT
then
3854 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3858 if gFlash
= 2 then Inc(FPickup
, 5);
3862 if FHealth
< PLAYER_HP_SOFT
then
3864 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3868 if gFlash
= 2 then Inc(FPickup
, 5);
3872 if FArmor
< PLAYER_AP_SOFT
then
3874 FArmor
:= PLAYER_AP_SOFT
;
3877 if gFlash
= 2 then Inc(FPickup
, 5);
3881 if FArmor
< PLAYER_AP_LIMIT
then
3883 FArmor
:= PLAYER_AP_LIMIT
;
3886 if gFlash
= 2 then Inc(FPickup
, 5);
3890 if FHealth
< PLAYER_HP_LIMIT
then
3892 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3896 if gFlash
= 2 then Inc(FPickup
, 5);
3900 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3902 if FHealth
< PLAYER_HP_LIMIT
then
3903 FHealth
:= PLAYER_HP_LIMIT
;
3904 if FArmor
< PLAYER_AP_LIMIT
then
3905 FArmor
:= PLAYER_AP_LIMIT
;
3909 if gFlash
= 2 then Inc(FPickup
, 5);
3913 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3915 FWeapon
[WEAPON_SAW
] := True;
3917 if gFlash
= 2 then Inc(FPickup
, 5);
3918 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3921 ITEM_WEAPON_SHOTGUN1
:
3922 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3924 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3925 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3927 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3928 FWeapon
[WEAPON_SHOTGUN1
] := True;
3930 if gFlash
= 2 then Inc(FPickup
, 5);
3931 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3934 ITEM_WEAPON_SHOTGUN2
:
3935 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3937 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3939 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3940 FWeapon
[WEAPON_SHOTGUN2
] := True;
3942 if gFlash
= 2 then Inc(FPickup
, 5);
3943 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3946 ITEM_WEAPON_CHAINGUN
:
3947 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3949 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3951 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3952 FWeapon
[WEAPON_CHAINGUN
] := True;
3954 if gFlash
= 2 then Inc(FPickup
, 5);
3955 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3958 ITEM_WEAPON_ROCKETLAUNCHER
:
3959 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3961 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3963 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3964 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3966 if gFlash
= 2 then Inc(FPickup
, 5);
3967 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3971 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3973 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3975 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3976 FWeapon
[WEAPON_PLASMA
] := True;
3978 if gFlash
= 2 then Inc(FPickup
, 5);
3979 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3983 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3985 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3987 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3988 FWeapon
[WEAPON_BFG
] := True;
3990 if gFlash
= 2 then Inc(FPickup
, 5);
3991 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3994 ITEM_WEAPON_SUPERPULEMET
:
3995 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3997 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3999 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4000 FWeapon
[WEAPON_SUPERPULEMET
] := True;
4002 if gFlash
= 2 then Inc(FPickup
, 5);
4003 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4006 ITEM_WEAPON_FLAMETHROWER
:
4007 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
4009 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
4011 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4012 FWeapon
[WEAPON_FLAMETHROWER
] := True;
4014 if gFlash
= 2 then Inc(FPickup
, 5);
4015 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4019 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4021 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4024 if gFlash
= 2 then Inc(FPickup
, 5);
4027 ITEM_AMMO_BULLETS_BOX
:
4028 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4030 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4033 if gFlash
= 2 then Inc(FPickup
, 5);
4037 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4039 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4042 if gFlash
= 2 then Inc(FPickup
, 5);
4045 ITEM_AMMO_SHELLS_BOX
:
4046 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4048 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
4051 if gFlash
= 2 then Inc(FPickup
, 5);
4055 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4057 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4060 if gFlash
= 2 then Inc(FPickup
, 5);
4063 ITEM_AMMO_ROCKET_BOX
:
4064 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4066 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
4069 if gFlash
= 2 then Inc(FPickup
, 5);
4073 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4075 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4078 if gFlash
= 2 then Inc(FPickup
, 5);
4082 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4084 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4087 if gFlash
= 2 then Inc(FPickup
, 5);
4091 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4093 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4096 if gFlash
= 2 then Inc(FPickup
, 5);
4100 if not(R_ITEM_BACKPACK
in FRulez
) or
4101 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4102 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4103 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4104 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4105 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
4107 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4108 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4109 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4110 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4111 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4113 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4114 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4115 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4116 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4117 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4118 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4119 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4120 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4122 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
4125 if gFlash
= 2 then Inc(FPickup
, 5);
4129 if not(R_KEY_RED
in FRulez
) then
4131 Include(FRulez
, R_KEY_RED
);
4133 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4134 if gFlash
= 2 then Inc(FPickup
, 5);
4135 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4139 if not(R_KEY_GREEN
in FRulez
) then
4141 Include(FRulez
, R_KEY_GREEN
);
4143 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4144 if gFlash
= 2 then Inc(FPickup
, 5);
4145 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4149 if not(R_KEY_BLUE
in FRulez
) then
4151 Include(FRulez
, R_KEY_BLUE
);
4153 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4154 if gFlash
= 2 then Inc(FPickup
, 5);
4155 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4159 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4161 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4165 if gFlash
= 2 then Inc(FPickup
, 5);
4169 if FAir
< AIR_MAX
then
4174 if gFlash
= 2 then Inc(FPickup
, 5);
4179 if not (R_BERSERK
in FRulez
) then
4181 Include(FRulez
, R_BERSERK
);
4182 if allowBerserkSwitching
then
4184 FCurrWeap
:= WEAPON_KASTET
;
4186 FModel
.SetWeapon(WEAPON_KASTET
);
4191 if gFlash
= 2 then Inc(FPickup
, 5);
4193 FBerserk
:= gTime
+30000;
4198 if FHealth
< PLAYER_HP_SOFT
then
4200 FHealth
:= PLAYER_HP_SOFT
;
4201 FBerserk
:= gTime
+30000;
4209 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4211 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4214 if gFlash
= 2 then Inc(FPickup
, 5);
4218 if FHealth
< PLAYER_HP_LIMIT
then
4220 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4224 if gFlash
= 2 then Inc(FPickup
, 5);
4228 if FArmor
< PLAYER_AP_LIMIT
then
4230 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4233 if gFlash
= 2 then Inc(FPickup
, 5);
4237 if FJetFuel
< JET_MAX
then
4239 FJetFuel
:= JET_MAX
;
4242 if gFlash
= 2 then Inc(FPickup
, 5);
4246 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4248 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4251 if gFlash
= 2 then Inc(FPickup
, 5);
4256 procedure TPlayer
.Touch();
4260 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4263 // Áðîñèòü ôëàã òîâàðèùó:
4264 if gGameSettings
.GameMode
= GM_CTF
then
4269 procedure TPlayer
.Push(vx
, vy
: Integer);
4271 if (not FPhysics
) and FGhost
then
4273 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4274 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4275 if g_Game_IsNet
and g_Game_IsServer
then
4276 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4279 procedure TPlayer
.Reset(Force
: Boolean);
4285 FTime
[T_RESPAWN
] := 0;
4286 FTime
[T_FLAGCAP
] := 0;
4299 FSpectator
:= False;
4302 FSpectatePlayer
:= -1;
4303 FNoRespawn
:= False;
4305 FLives
:= gGameSettings
.MaxLives
;
4310 procedure TPlayer
.SoftReset();
4316 FBFGFireCounter
:= -1;
4324 SetAction(A_STAND
, True);
4327 function TPlayer
.GetRespawnPoint(): Byte;
4332 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4334 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4335 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4337 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4339 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4340 if Self
= gPlayer1
then
4341 c
:= RESPAWNPOINT_PLAYER1
4343 c
:= RESPAWNPOINT_PLAYER2
;
4344 if g_Map_GetPointCount(c
) > 0 then
4350 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4351 if Self
= gPlayer1
then
4352 c
:= RESPAWNPOINT_PLAYER2
4354 c
:= RESPAWNPOINT_PLAYER1
;
4355 if g_Map_GetPointCount(c
) > 0 then
4362 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4363 if Random(2) = 0 then
4364 c
:= RESPAWNPOINT_PLAYER1
4366 c
:= RESPAWNPOINT_PLAYER2
;
4367 if g_Map_GetPointCount(c
) > 0 then
4374 // Òî÷êà ëþáîé èç êîìàíä
4375 if Random(2) = 0 then
4376 c
:= RESPAWNPOINT_RED
4378 c
:= RESPAWNPOINT_BLUE
;
4379 if g_Map_GetPointCount(c
) > 0 then
4386 c
:= RESPAWNPOINT_DM
;
4387 if g_Map_GetPointCount(c
) > 0 then
4395 if gGameSettings
.GameMode
= GM_DM
then
4398 c
:= RESPAWNPOINT_DM
;
4399 if g_Map_GetPointCount(c
) > 0 then
4405 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4406 if Random(2) = 0 then
4407 c
:= RESPAWNPOINT_PLAYER1
4409 c
:= RESPAWNPOINT_PLAYER2
;
4410 if g_Map_GetPointCount(c
) > 0 then
4416 // Òî÷êà ëþáîé èç êîìàíä
4417 if Random(2) = 0 then
4418 c
:= RESPAWNPOINT_RED
4420 c
:= RESPAWNPOINT_BLUE
;
4421 if g_Map_GetPointCount(c
) > 0 then
4429 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4431 // Òî÷êà ñâîåé êîìàíäû
4432 c
:= RESPAWNPOINT_DM
;
4433 if FTeam
= TEAM_RED
then
4434 c
:= RESPAWNPOINT_RED
;
4435 if FTeam
= TEAM_BLUE
then
4436 c
:= RESPAWNPOINT_BLUE
;
4437 if g_Map_GetPointCount(c
) > 0 then
4444 c
:= RESPAWNPOINT_DM
;
4445 if g_Map_GetPointCount(c
) > 0 then
4451 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4452 if Random(2) = 0 then
4453 c
:= RESPAWNPOINT_PLAYER1
4455 c
:= RESPAWNPOINT_PLAYER2
;
4456 if g_Map_GetPointCount(c
) > 0 then
4462 // Òî÷êà äðóãîé êîìàíäû
4463 c
:= RESPAWNPOINT_DM
;
4464 if FTeam
= TEAM_RED
then
4465 c
:= RESPAWNPOINT_BLUE
;
4466 if FTeam
= TEAM_BLUE
then
4467 c
:= RESPAWNPOINT_RED
;
4468 if g_Map_GetPointCount(c
) > 0 then
4476 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4478 RespawnPoint
: TRespawnPoint
;
4484 FBFGFireCounter
:= -1;
4489 if not g_Game_IsServer
then
4493 FWantsInGame
:= True;
4494 FJustTeleported
:= True;
4497 FTime
[T_RESPAWN
] := 0;
4501 // if server changes MaxLives we gotta be ready
4502 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4504 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4505 if FTime
[T_RESPAWN
] > gTime
then
4508 // Ïðîñðàë âñå æèçíè:
4511 if not FSpectator
then Spectate(True);
4512 FWantsInGame
:= True;
4516 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4517 begin // "Ñâîÿ èãðà"
4518 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4519 FRulez
:= FRulez
-[R_BERSERK
];
4521 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4523 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4524 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4527 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4528 c
:= GetRespawnPoint();
4533 // Âîñêðåøåíèå áåç îðóæèÿ:
4536 FHealth
:= PLAYER_HP_SOFT
;
4542 for a
:= WP_FIRST
to WP_LAST
do
4544 FWeapon
[a
] := False;
4548 FWeapon
[WEAPON_PISTOL
] := True;
4549 FWeapon
[WEAPON_KASTET
] := True;
4550 FCurrWeap
:= WEAPON_PISTOL
;
4553 FModel
.SetWeapon(FCurrWeap
);
4555 for b
:= A_BULLETS
to A_HIGH
do
4558 FAmmo
[A_BULLETS
] := 50;
4560 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4561 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4562 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4563 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4564 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4566 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4567 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4572 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4573 if not g_Map_GetPoint(c
, RespawnPoint
) then
4575 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4579 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4580 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4581 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4587 FDirection
:= RespawnPoint
.Direction
;
4588 if FDirection
= TDirection
.D_LEFT
then
4593 SetAction(A_STAND
, True);
4594 FModel
.Direction
:= FDirection
;
4596 for a
:= Low(FTime
) to High(FTime
) do
4599 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4604 FCanJetpack
:= False;
4609 // Àíèìàöèÿ âîçðîæäåíèÿ:
4610 if (not gLoadGameMode
) and (not Silent
) then
4611 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4613 Anim
:= TAnimation
.Create(ID
, False, 3);
4614 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4615 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4619 FSpectator
:= False;
4622 FSpectatePlayer
:= -1;
4625 if (gPlayer1
= nil) and (gLMSPID1
= FUID
) then
4627 if (gPlayer2
= nil) and (gLMSPID2
= FUID
) then
4630 if g_Game_IsNet
then
4632 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4633 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4635 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4636 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4641 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4644 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4645 else if (not NoMove
) then
4647 GameX
:= gMapInfo
.Width
div 2;
4648 GameY
:= gMapInfo
.Height
div 2;
4657 FWantsInGame
:= False;
4662 if Self
= gPlayer1
then
4667 if Self
= gPlayer2
then
4674 if g_Game_IsNet
then
4675 MH_SEND_PlayerStats(FUID
);
4678 procedure TPlayer
.SwitchNoClip
;
4682 FGhost
:= not FGhost
;
4683 FPhysics
:= not FGhost
;
4695 procedure TPlayer
.Run(Direction
: TDirection
);
4699 if MAX_RUNVEL
> 8 then
4703 if Direction
= TDirection
.D_LEFT
then
4705 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4706 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4709 if FObj
.Vel
.X
< MAX_RUNVEL
then
4710 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4712 // Âîçìîæíî, ïèíàåì êóñêè:
4713 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4715 b
:= Abs(FObj
.Vel
.X
);
4716 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4717 for a
:= 0 to High(gGibs
) do
4719 if gGibs
[a
].alive
and
4720 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4721 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4724 if FObj
.Vel
.X
< 0 then
4726 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4730 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4732 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4740 procedure TPlayer
.SeeDown();
4742 SetAction(A_SEEDOWN
);
4744 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4746 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4749 procedure TPlayer
.SeeUp();
4753 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4755 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4758 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4766 A_ATTACK
: Prior
:= 2;
4767 A_SEEUP
: Prior
:= 1;
4768 A_SEEDOWN
: Prior
:= 1;
4769 A_ATTACKUP
: Prior
:= 2;
4770 A_ATTACKDOWN
: Prior
:= 2;
4775 if (Prior
> FActionPrior
) or Force
then
4776 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4778 FActionPrior
:= Prior
;
4779 FActionAnim
:= Action
;
4780 FActionForce
:= Force
;
4781 FActionChanged
:= True;
4784 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4787 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4789 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4790 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4791 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4792 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4795 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4802 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4804 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4805 if g_Game_IsServer
and g_Game_IsNet
then
4806 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4810 FJustTeleported
:= True;
4815 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4817 Anim
:= TAnimation
.Create(ID
, False, 3);
4820 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4821 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4822 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4823 if g_Game_IsServer
and g_Game_IsNet
then
4824 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4825 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4829 FObj
.X
:= X
-PLAYER_RECT
.X
;
4830 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4831 if FAlive
and FGhost
then
4837 if not g_Game_IsNet
then
4841 SetDirection(TDirection
.D_LEFT
);
4847 SetDirection(TDirection
.D_RIGHT
);
4853 if FDirection
= TDirection
.D_RIGHT
then
4855 SetDirection(TDirection
.D_LEFT
);
4860 SetDirection(TDirection
.D_RIGHT
);
4866 if not silent
and (Anim
<> nil) then
4868 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4869 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4872 if g_Game_IsServer
and g_Game_IsNet
then
4873 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4874 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4881 function nonz(a
: Single): Single;
4889 function TPlayer
.followCorpse(): Boolean;
4894 if FAlive
or FSpectator
then
4896 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
4898 for i
:= 0 to High(gCorpses
) do
4899 if gCorpses
[i
] <> nil then
4900 if gCorpses
[i
].FPlayerUID
= FUID
then
4903 FObj
.X
:= gCorpses
[i
].FObj
.X
;
4904 FObj
.Y
:= gCorpses
[i
].FObj
.Y
;
4905 FObj
.Vel
.X
:= gCorpses
[i
].FObj
.Vel
.X
;
4906 FObj
.Vel
.Y
:= gCorpses
[i
].FObj
.Vel
.Y
;
4907 FObj
.Accel
.X
:= gCorpses
[i
].FObj
.Accel
.X
;
4908 FObj
.Accel
.Y
:= gCorpses
[i
].FObj
.Accel
.Y
;
4913 procedure TPlayer
.Update();
4916 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4917 blockmon
, headwater
, dospawn
: Boolean;
4922 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4923 AnyServer
:= g_Game_IsServer
;
4925 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4926 DoLerp(NetInterpLevel
+ 1)
4932 if FClientID
>= 0 then
4934 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4935 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4936 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4945 if FAlive
and (FPunchAnim
<> nil) then
4946 FPunchAnim
.Update();
4948 if FAlive
and (gFly
or FJetpack
) then
4951 if FDirection
= TDirection
.D_LEFT
then
4956 if FAlive
and (not FGhost
) then
4958 if FKeys
[KEY_UP
].Pressed
then
4960 if FKeys
[KEY_DOWN
].Pressed
then
4964 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4967 i
:= g_basic
.Sign(FIncCam
);
4968 FIncCam
:= Abs(FIncCam
);
4969 DecMin(FIncCam
, 5, 0);
4970 FIncCam
:= FIncCam
*i
;
4973 // no need to do that each second frame, weapon queue will take care of it
4974 if FAlive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4975 if FAlive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4977 if gTime
mod (GAME_TICK
*2) <> 0 then
4979 if (FObj
.Vel
.X
= 0) and FAlive
then
4981 if FKeys
[KEY_LEFT
].Pressed
then
4982 Run(TDirection
.D_LEFT
);
4983 if FKeys
[KEY_RIGHT
].Pressed
then
4984 Run(TDirection
.D_RIGHT
);
4989 if not followCorpse() then
4990 g_Obj_Move(@FObj
, True, True, True);
4991 positionChanged(); // this updates spatial accelerators
4997 FActionChanged
:= False;
5001 // Let alive player do some actions
5002 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
5003 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
5004 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
5005 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
5006 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
5007 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
5008 if FKeys
[KEY_JUMP
].Pressed
then Jump()
5011 if AnyServer
and FJetpack
then
5015 if NetServer
then MH_SEND_PlayerStats(FUID
);
5017 FCanJetpack
:= True;
5024 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
5026 if FKeys
[k
].Pressed
then
5034 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5037 if (FTime
[T_RESPAWN
] <= gTime
) and
5038 gGameOn
and (not FAlive
) then
5040 if (g_Player_GetCount() > 1) then
5044 gExit
:= EXIT_RESTART
;
5049 // Dead spectator actions
5052 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
5053 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
5057 if (FSpectatePlayer
>= High(gPlayers
)) then
5058 FSpectatePlayer
:= -1
5062 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
5063 if gPlayers
[I
] <> nil then
5064 if gPlayers
[I
].alive
then
5065 if gPlayers
[I
].UID
<> FUID
then
5067 FSpectatePlayer
:= I
;
5072 if not SetSpect
then FSpectatePlayer
:= -1;
5083 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5085 FYTo
:= FObj
.Y
- 32;
5086 FSpectatePlayer
:= -1;
5088 if FKeys
[KEY_DOWN
].Pressed
then
5090 FYTo
:= FObj
.Y
+ 32;
5091 FSpectatePlayer
:= -1;
5093 if FKeys
[KEY_LEFT
].Pressed
then
5095 FXTo
:= FObj
.X
- 32;
5096 FSpectatePlayer
:= -1;
5098 if FKeys
[KEY_RIGHT
].Pressed
then
5100 FXTo
:= FObj
.X
+ 32;
5101 FSpectatePlayer
:= -1;
5104 if (FXTo
< -64) then
5106 else if (FXTo
> gMapInfo
.Width
+ 32) then
5107 FXTo
:= gMapInfo
.Width
+ 32;
5108 if (FYTo
< -72) then
5110 else if (FYTo
> gMapInfo
.Height
+ 32) then
5111 FYTo
:= gMapInfo
.Height
+ 32;
5116 if not followCorpse() then
5117 g_Obj_Move(@FObj
, True, True, True);
5118 positionChanged(); // this updates spatial accelerators
5125 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5126 if gPlayers
[FSpectatePlayer
] <> nil then
5127 if gPlayers
[FSpectatePlayer
].alive
then
5129 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
5130 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
5134 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5135 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5136 PANEL_BLOCKMON
, True);
5137 headwater
:= HeadInLiquid(0, 0);
5139 // Ñîïðîòèâëåíèå âîçäóõà:
5140 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5141 if FObj
.Vel
.X
<> 0 then
5142 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5144 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5145 DecMin(FPain
, 5, 0);
5146 DecMin(FPickup
, 1, 0);
5148 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5150 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5151 FMegaRulez
[MR_SUIT
] := 0;
5152 FMegaRulez
[MR_INVUL
] := 0;
5153 FMegaRulez
[MR_INVIS
] := 0;
5154 Kill(K_FALLKILL
, 0, HIT_FALL
);
5161 if FCurrWeap
= WEAPON_SAW
then
5162 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5163 FSawSoundSelect
.IsPlaying()) then
5164 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5167 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5168 (not FJetSoundOff
.IsPlaying()) then
5170 FJetSoundFly
.SetPosition(0);
5171 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5174 for b
:= WP_FIRST
to WP_LAST
do
5175 if FReloading
[b
] > 0 then
5181 if FShellTimer
> -1 then
5182 if FShellTimer
= 0 then
5184 if FShellType
= SHELL_SHELL
then
5185 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5186 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5187 else if FShellType
= SHELL_DBLSHELL
then
5189 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5190 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5191 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5192 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5195 end else Dec(FShellTimer
);
5197 if (FBFGFireCounter
> -1) then
5198 if FBFGFireCounter
= 0 then
5202 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5203 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5204 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5205 yd
:= wy
+firediry();
5206 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5207 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5208 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5209 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5210 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5213 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5214 FBFGFireCounter
:= -1;
5217 FBFGFireCounter
:= 0
5219 Dec(FBFGFireCounter
);
5221 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5223 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5225 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5228 if (headwater
or blockmon
) then
5234 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5237 else if (FAir
mod 31 = 0) and not blockmon
then
5239 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5240 if Random(2) = 0 then
5241 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5243 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5245 end else if FAir
< AIR_DEF
then
5248 if FFireTime
> 0 then
5250 if BodyInLiquid(0, 0) then
5255 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5257 if FMegaRulez
[MR_SUIT
] = gTime
then
5264 if FFirePainTime
<= 0 then
5266 if g_Game_IsServer
then
5267 Damage(5, FFireAttacker
, 0, 0, HIT_FLAME
);
5268 FFirePainTime
:= 18;
5270 FFirePainTime
:= FFirePainTime
- 1;
5271 FFireTime
:= FFireTime
- 1;
5272 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5273 MH_SEND_PlayerStats(FUID
);
5277 if FDamageBuffer
> 0 then
5279 if FDamageBuffer
>= 9 then
5283 if FDamageBuffer
< 30 then i
:= 9
5284 else if FDamageBuffer
< 100 then i
:= 18
5288 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5289 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5290 FHealth
:= FHealth
-ii
;
5293 FHealth
:= FHealth
+FArmor
;
5298 if FHealth
<= 0 then
5299 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5300 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5301 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5305 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5306 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5307 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5308 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5315 end; // if FAlive then ...
5317 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5319 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5320 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5321 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5322 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5324 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5325 then SetAction(A_STAND
, True);
5327 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5329 for b
:= Low(FKeys
) to High(FKeys
) do
5330 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5334 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5336 x
:= FObj
.X
+PLAYER_RECT
.X
;
5337 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5338 w
:= PLAYER_RECT
.Width
;
5339 h
:= PLAYER_RECT
.Height
;
5343 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5345 if (dx
<> 0) or (dy
<> 0) then
5354 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5356 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5357 FObj
.Y
+PLAYER_RECT
.Y
,
5364 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5366 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5367 FObj
.Y
+PLAYER_RECT
.Y
,
5371 Panel
.Width
, Panel
.Height
);
5374 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5376 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5377 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5378 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5379 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5382 function g_Player_ValidName(Name
: string): Boolean;
5388 if gPlayers
= nil then Exit
;
5390 for a
:= 0 to High(gPlayers
) do
5391 if gPlayers
[a
] <> nil then
5392 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5399 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5403 d
:= FModel
.Direction
;
5405 FModel
.Direction
:= Direction
;
5406 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5408 FDirection
:= Direction
;
5411 function TPlayer
.GetKeys(): Byte;
5415 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5416 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5417 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5419 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5420 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5423 procedure TPlayer
.Use();
5427 if FTime
[T_USE
] > gTime
then Exit
;
5429 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5430 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5432 for a
:= 0 to High(gPlayers
) do
5433 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5434 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5435 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5436 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5438 gPlayers
[a
].Touch();
5439 if g_Game_IsNet
and g_Game_IsServer
then
5440 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5443 FTime
[T_USE
] := gTime
+120;
5446 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5450 WX
, WY
, XD
, YD
: Integer;
5462 if R_BERSERK
in FRulez
then
5464 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5465 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5466 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5469 locobj
.rect
.Width
:= 39;
5470 locobj
.rect
.Height
:= 52;
5471 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5472 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5473 locobj
.Accel
.X
:= xd
-wx
;
5474 locobj
.Accel
.y
:= yd
-wy
;
5476 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5477 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5479 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5483 FPain
:= min(FPain
+ 25, 50);
5485 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5490 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5491 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5493 FSawSoundSelect
.Stop();
5495 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5497 else if not FSawSoundHit
.IsPlaying() then
5499 FSawSoundSelect
.Stop();
5500 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5507 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5508 FFireAngle
:= FAngle
;
5510 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5511 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5516 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5517 FFireAngle
:= FAngle
;
5520 FShellType
:= SHELL_SHELL
;
5525 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5526 FFireAngle
:= FAngle
;
5529 FShellType
:= SHELL_DBLSHELL
;
5534 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5535 FFireAngle
:= FAngle
;
5537 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5538 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5541 WEAPON_ROCKETLAUNCHER
:
5543 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5544 FFireAngle
:= FAngle
;
5550 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5551 FFireAngle
:= FAngle
;
5557 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5558 FFireAngle
:= FAngle
;
5562 WEAPON_SUPERPULEMET
:
5564 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5565 FFireAngle
:= FAngle
;
5567 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5568 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5571 WEAPON_FLAMETHROWER
:
5573 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5574 FFireAngle
:= FAngle
;
5581 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5582 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5583 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5586 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5588 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5589 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5592 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5596 if NetInterpLevel
< 1 then
5606 AX
:= Abs(FXTo
- FObj
.X
);
5607 AY
:= Abs(FYTo
- FObj
.Y
);
5608 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5610 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5615 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5617 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5618 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5619 PANEL_LIFTUP
, False) then Result
:= -1
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_LIFTDOWN
, False) then Result
:= 1
5627 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5634 if Flag
= FLAG_NONE
then
5637 if not g_Game_IsServer
then Exit
;
5639 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5640 if (Flag
= FTeam
) and
5641 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5642 (FFlag
<> FLAG_NONE
) then
5644 if FFlag
= FLAG_RED
then
5645 s
:= _lc
[I_PLAYER_FLAG_RED
]
5647 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5649 evtype
:= FLAG_STATE_SCORED
;
5651 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5652 Insert('.', ts
, Length(ts
) + 1 - 3);
5653 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5655 g_Map_ResetFlag(FFlag
);
5656 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5658 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5661 if g_Game_IsNet
then
5663 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5667 gFlags
[FFlag
].CaptureTime
:= 0;
5672 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5673 if (Flag
= FTeam
) and
5674 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5676 if Flag
= FLAG_RED
then
5677 s
:= _lc
[I_PLAYER_FLAG_RED
]
5679 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5681 evtype
:= FLAG_STATE_RETURNED
;
5682 gFlags
[Flag
].CaptureTime
:= 0;
5684 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5686 g_Map_ResetFlag(Flag
);
5687 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5690 if g_Game_IsNet
then
5692 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5698 // Ïîäîáðàë ÷óæîé ôëàã:
5699 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5703 if Flag
= FLAG_RED
then
5704 s
:= _lc
[I_PLAYER_FLAG_RED
]
5706 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5708 evtype
:= FLAG_STATE_CAPTURED
;
5710 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5712 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5714 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5717 if g_Game_IsNet
then
5719 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5725 procedure TPlayer
.SetFlag(Flag
: Byte);
5728 if FModel
<> nil then
5729 FModel
.SetFlag(FFlag
);
5732 function TPlayer
.DropFlag(): Boolean;
5737 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5739 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5740 with gFlags
[FFlag
] do
5744 Direction
:= FDirection
;
5745 State
:= FLAG_STATE_DROPPED
;
5747 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5748 (FObj
.Vel
.Y
div 2)-2+Random(5));
5749 positionChanged(); // this updates spatial accelerators
5751 if FFlag
= FLAG_RED
then
5752 s
:= _lc
[I_PLAYER_FLAG_RED
]
5754 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5756 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5757 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5759 if g_Game_IsNet
then
5760 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5766 procedure TPlayer
.GetSecret();
5771 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5773 Assert(Key
<= High(FKeys
));
5775 FKeys
[Key
].Pressed
:= True;
5776 FKeys
[Key
].Time
:= Time
;
5779 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5781 Result
:= FKeys
[K
].Pressed
;
5784 procedure TPlayer
.ReleaseKeys();
5788 for a
:= Low(FKeys
) to High(FKeys
) do
5790 FKeys
[a
].Pressed
:= False;
5795 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5799 function TPlayer
.firediry(): Integer;
5801 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5802 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5806 procedure TPlayer
.RememberState();
5810 FSavedState
.Health
:= FHealth
;
5811 FSavedState
.Armor
:= FArmor
;
5812 FSavedState
.Air
:= FAir
;
5813 FSavedState
.JetFuel
:= FJetFuel
;
5814 FSavedState
.CurrWeap
:= FCurrWeap
;
5815 FSavedState
.NextWeap
:= FNextWeap
;
5816 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5819 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5821 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5823 FSavedState
.Rulez
:= FRulez
;
5824 FSavedState
.WaitRecall
:= True;
5827 procedure TPlayer
.RecallState();
5831 if not FSavedState
.WaitRecall
then Exit
;
5833 FHealth
:= FSavedState
.Health
;
5834 FArmor
:= FSavedState
.Armor
;
5835 FAir
:= FSavedState
.Air
;
5836 FJetFuel
:= FSavedState
.JetFuel
;
5837 FCurrWeap
:= FSavedState
.CurrWeap
;
5838 FNextWeap
:= FSavedState
.NextWeap
;
5839 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5842 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5844 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5846 FRulez
:= FSavedState
.Rulez
;
5847 FSavedState
.WaitRecall
:= False;
5849 if gGameSettings
.GameType
= GT_SERVER
then
5850 MH_SEND_PlayerStats(FUID
);
5853 procedure TPlayer
.SaveState (st
: TStream
);
5859 utils
.writeSign(st
, 'PLYR');
5860 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
5862 utils
.writeBool(st
, FIamBot
);
5864 utils
.writeInt(st
, Word(FUID
));
5866 utils
.writeStr(st
, FName
);
5868 utils
.writeInt(st
, Byte(FTeam
));
5870 utils
.writeBool(st
, FAlive
);
5871 // Èçðàñõîäîâàë ëè âñå æèçíè
5872 utils
.writeBool(st
, FNoRespawn
);
5874 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
5875 utils
.writeInt(st
, Byte(b
));
5877 utils
.writeInt(st
, LongInt(FHealth
));
5879 utils
.writeInt(st
, Byte(FLives
));
5881 utils
.writeInt(st
, LongInt(FArmor
));
5883 utils
.writeInt(st
, LongInt(FAir
));
5885 utils
.writeInt(st
, LongInt(FJetFuel
));
5887 utils
.writeInt(st
, LongInt(FPain
));
5889 utils
.writeInt(st
, LongInt(FKills
));
5891 utils
.writeInt(st
, LongInt(FMonsterKills
));
5893 utils
.writeInt(st
, LongInt(FFrags
));
5895 utils
.writeInt(st
, Byte(FFragCombo
));
5896 // Âðåìÿ ïîñëåäíåãî ôðàãà
5897 utils
.writeInt(st
, LongWord(FLastFrag
));
5899 utils
.writeInt(st
, LongInt(FDeath
));
5901 utils
.writeInt(st
, Byte(FFlag
));
5903 utils
.writeInt(st
, LongInt(FSecrets
));
5905 utils
.writeInt(st
, Byte(FCurrWeap
));
5907 utils
.writeInt(st
, Word(FNextWeap
));
5909 utils
.writeInt(st
, Byte(FNextWeapDelay
));
5910 // Âðåìÿ çàðÿäêè BFG
5911 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
5913 utils
.writeInt(st
, LongInt(FDamageBuffer
));
5914 // Ïîñëåäíèé óäàðèâøèé
5915 utils
.writeInt(st
, Word(FLastSpawnerUID
));
5916 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
5917 utils
.writeInt(st
, Byte(FLastHit
));
5919 Obj_SaveState(st
, @FObj
);
5920 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
5921 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
5922 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
5923 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
5925 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
5926 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
5927 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
5929 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
5930 // Íàëè÷èå êðàñíîãî êëþ÷à
5931 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
5932 // Íàëè÷èå çåëåíîãî êëþ÷à
5933 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
5934 // Íàëè÷èå ñèíåãî êëþ÷à
5935 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
5937 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
5938 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
5939 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
5940 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
5941 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
5943 utils
.writeStr(st
, FModel
.Name
);
5945 utils
.writeInt(st
, Byte(FColor
.R
));
5946 utils
.writeInt(st
, Byte(FColor
.G
));
5947 utils
.writeInt(st
, Byte(FColor
.B
));
5951 procedure TPlayer
.LoadState (st
: TStream
);
5960 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
5961 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
5963 FIamBot
:= utils
.readBool(st
);
5965 FUID
:= utils
.readWord(st
);
5967 str
:= utils
.readStr(st
);
5968 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
5970 FTeam
:= utils
.readByte(st
);
5972 FAlive
:= utils
.readBool(st
);
5973 // Èçðàñõîäîâàë ëè âñå æèçíè
5974 FNoRespawn
:= utils
.readBool(st
);
5976 b
:= utils
.readByte(st
);
5977 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
5979 FHealth
:= utils
.readLongInt(st
);
5981 FLives
:= utils
.readByte(st
);
5983 FArmor
:= utils
.readLongInt(st
);
5985 FAir
:= utils
.readLongInt(st
);
5987 FJetFuel
:= utils
.readLongInt(st
);
5989 FPain
:= utils
.readLongInt(st
);
5991 FKills
:= utils
.readLongInt(st
);
5993 FMonsterKills
:= utils
.readLongInt(st
);
5995 FFrags
:= utils
.readLongInt(st
);
5997 FFragCombo
:= utils
.readByte(st
);
5998 // Âðåìÿ ïîñëåäíåãî ôðàãà
5999 FLastFrag
:= utils
.readLongWord(st
);
6001 FDeath
:= utils
.readLongInt(st
);
6003 FFlag
:= utils
.readByte(st
);
6005 FSecrets
:= utils
.readLongInt(st
);
6007 FCurrWeap
:= utils
.readByte(st
);
6009 FNextWeap
:= utils
.readWord(st
);
6011 FNextWeapDelay
:= utils
.readByte(st
);
6012 // Âðåìÿ çàðÿäêè BFG
6013 FBFGFireCounter
:= utils
.readSmallInt(st
);
6015 FDamageBuffer
:= utils
.readLongInt(st
);
6016 // Ïîñëåäíèé óäàðèâøèé
6017 FLastSpawnerUID
:= utils
.readWord(st
);
6018 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6019 FLastHit
:= utils
.readByte(st
);
6021 Obj_LoadState(@FObj
, st
);
6022 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6023 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
6024 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6025 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
6027 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
6028 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6029 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
6031 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
6032 // Íàëè÷èå êðàñíîãî êëþ÷à
6033 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
6034 // Íàëè÷èå çåëåíîãî êëþ÷à
6035 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
6036 // Íàëè÷èå ñèíåãî êëþ÷à
6037 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
6039 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
6040 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6041 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
6042 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6043 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
6045 str
:= utils
.readStr(st
);
6047 FColor
.R
:= utils
.readByte(st
);
6048 FColor
.G
:= utils
.readByte(st
);
6049 FColor
.B
:= utils
.readByte(st
);
6050 if (self
= gPlayer1
) then
6052 str
:= gPlayer1Settings
.Model
;
6053 FColor
:= gPlayer1Settings
.Color
;
6055 else if (self
= gPlayer2
) then
6057 str
:= gPlayer2Settings
.Model
;
6058 FColor
:= gPlayer2Settings
.Color
;
6060 // Îáíîâëÿåì ìîäåëü èãðîêà
6062 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
6063 FModel
.Color
:= TEAMCOLOR
[FTeam
]
6065 FModel
.Color
:= FColor
;
6069 procedure TPlayer
.AllRulez(Health
: Boolean);
6075 FHealth
:= PLAYER_HP_LIMIT
;
6076 FArmor
:= PLAYER_AP_LIMIT
;
6080 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
6081 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
6082 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6085 procedure TPlayer
.RestoreHealthArmor();
6087 FHealth
:= PLAYER_HP_LIMIT
;
6088 FArmor
:= PLAYER_AP_LIMIT
;
6091 procedure TPlayer
.FragCombo();
6095 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6097 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6099 if FFragCombo
< 5 then
6101 Param
:= FUID
or (FFragCombo
shl 16);
6102 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6103 (FComboEvnt
<= High(gDelayedEvents
)) and
6104 gDelayedEvents
[FComboEvnt
].Pending
and
6105 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6106 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6108 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6109 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6112 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6120 procedure TPlayer
.GiveItem(ItemType
: Byte);
6124 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6126 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6130 if FAir
< AIR_MAX
then
6137 if not (R_BERSERK
in FRulez
) then
6139 Include(FRulez
, R_BERSERK
);
6140 if FBFGFireCounter
< 1 then
6142 FCurrWeap
:= WEAPON_KASTET
;
6144 FModel
.SetWeapon(WEAPON_KASTET
);
6148 FBerserk
:= gTime
+30000;
6150 if FHealth
< PLAYER_HP_SOFT
then
6152 FHealth
:= PLAYER_HP_SOFT
;
6153 FBerserk
:= gTime
+30000;
6158 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6160 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6164 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6166 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6170 if FJetFuel
< JET_MAX
then
6172 FJetFuel
:= JET_MAX
;
6175 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6176 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6178 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6179 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6181 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6183 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6185 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6186 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6189 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6190 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6191 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6192 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6193 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6194 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6195 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6196 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6197 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6199 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6200 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6201 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6202 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6203 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6204 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6205 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6206 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6207 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6210 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6211 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6212 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6213 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6214 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6216 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6217 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6218 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6219 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6220 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6222 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6223 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6224 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6225 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6227 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6230 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6231 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6232 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6234 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6235 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6240 if g_Game_IsNet
and g_Game_IsServer
then
6241 MH_SEND_PlayerStats(FUID
);
6244 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6249 if (Random(5) = 1) and (Times
= 1) then
6252 if BodyInLiquid(0, 0) then
6254 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6255 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6256 if Random(2) = 0 then
6257 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6259 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6263 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6265 for i
:= 1 to Times
do
6267 Anim
:= TAnimation
.Create(id
, False, 3);
6269 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6270 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6276 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6281 if (Random(10) = 1) and (Times
= 1) then
6284 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6286 for i
:= 1 to Times
do
6288 Anim
:= TAnimation
.Create(id
, False, 3);
6290 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6291 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6297 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6299 FSawSound
.Pause(Enable
);
6300 FSawSoundIdle
.Pause(Enable
);
6301 FSawSoundHit
.Pause(Enable
);
6302 FSawSoundSelect
.Pause(Enable
);
6307 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6312 FObj
.Rect
:= PLAYER_CORPSERECT
;
6313 FModelName
:= ModelName
;
6318 FState
:= CORPSE_STATE_MESS
;
6319 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6323 FState
:= CORPSE_STATE_NORMAL
;
6324 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6328 destructor TCorpse
.Destroy();
6335 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6337 procedure TCorpse
.positionChanged (); inline; begin end;
6339 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6341 if (dx
<> 0) or (dy
<> 0) then
6350 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6352 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6353 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6354 w
:= PLAYER_CORPSERECT
.Width
;
6355 h
:= PLAYER_CORPSERECT
.Height
;
6359 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6364 if FState
= CORPSE_STATE_REMOVEME
then
6367 FDamage
:= FDamage
+ Value
;
6369 if FDamage
> 150 then
6371 if FAnimation
<> nil then
6376 FState
:= CORPSE_STATE_REMOVEME
;
6378 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6379 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6380 FModelName
, FColor
);
6381 // Çâóê ìÿñà îò òðóïà:
6382 pm
:= g_PlayerModel_Get(FModelName
);
6383 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6387 if (gBodyKillEvent
<> -1)
6388 and gDelayedEvents
[gBodyKillEvent
].Pending
then
6389 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
6390 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, 0);
6395 Blood
:= g_PlayerModel_GetBlood(FModelName
);
6396 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6397 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6398 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6399 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6400 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6401 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
6405 procedure TCorpse
.Draw();
6407 if FState
= CORPSE_STATE_REMOVEME
then
6410 if FAnimation
<> nil then
6411 FAnimation
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6413 if FAnimationMask
<> nil then
6416 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6423 procedure TCorpse
.Update();
6427 if FState
= CORPSE_STATE_REMOVEME
then
6430 if gTime
mod (GAME_TICK
*2) <> 0 then
6432 g_Obj_Move(@FObj
, True, True, True);
6433 positionChanged(); // this updates spatial accelerators
6437 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6438 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6440 st
:= g_Obj_Move(@FObj
, True, True, True);
6441 positionChanged(); // this updates spatial accelerators
6443 if WordBool(st
and MOVE_FALLOUT
) then
6445 FState
:= CORPSE_STATE_REMOVEME
;
6449 if FAnimation
<> nil then
6450 FAnimation
.Update();
6451 if FAnimationMask
<> nil then
6452 FAnimationMask
.Update();
6456 procedure TCorpse
.SaveState (st
: TStream
);
6463 utils
.writeSign(st
, 'CORP');
6464 utils
.writeInt(st
, Byte(0));
6466 utils
.writeInt(st
, Byte(FState
));
6468 utils
.writeInt(st
, Byte(FDamage
));
6470 utils
.writeInt(st
, Byte(FColor
.R
));
6471 utils
.writeInt(st
, Byte(FColor
.G
));
6472 utils
.writeInt(st
, Byte(FColor
.B
));
6474 Obj_SaveState(st
, @FObj
);
6475 utils
.writeInt(st
, Word(FPlayerUID
));
6477 anim
:= (FAnimation
<> nil);
6478 utils
.writeBool(st
, anim
);
6479 // Åñëè åñòü - ñîõðàíÿåì
6480 if anim
then FAnimation
.SaveState(st
);
6481 // Åñòü ëè ìàñêà àíèìàöèè
6482 anim
:= (FAnimationMask
<> nil);
6483 utils
.writeBool(st
, anim
);
6484 // Åñëè åñòü - ñîõðàíÿåì
6485 if anim
then FAnimationMask
.SaveState(st
);
6489 procedure TCorpse
.LoadState (st
: TStream
);
6496 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6497 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6499 FState
:= utils
.readByte(st
);
6501 FDamage
:= utils
.readByte(st
);
6503 FColor
.R
:= utils
.readByte(st
);
6504 FColor
.G
:= utils
.readByte(st
);
6505 FColor
.B
:= utils
.readByte(st
);
6507 Obj_LoadState(@FObj
, st
);
6508 FPlayerUID
:= utils
.readWord(st
);
6510 anim
:= utils
.readBool(st
);
6511 // Åñëè åñòü - çàãðóæàåì
6514 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6515 FAnimation
.LoadState(st
);
6517 // Åñòü ëè ìàñêà àíèìàöèè
6518 anim
:= utils
.readBool(st
);
6519 // Åñëè åñòü - çàãðóæàåì
6522 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6523 FAnimationMask
.LoadState(st
);
6529 constructor TBot
.Create();
6536 FSpectator
:= False;
6543 for a
:= WP_FIRST
to WP_LAST
do
6545 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6546 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6547 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6551 destructor TBot
.Destroy();
6554 inherited Destroy();
6557 procedure TBot
.Draw();
6561 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6562 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6565 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6567 inherited Respawn(Silent
, Force
);
6570 FSelectedWeapon
:= FCurrWeap
;
6575 procedure TBot
.UpdateCombat();
6588 TTargetRecord
= array of TTarget
;
6590 function Compare(a
, b
: TTarget
): Integer;
6592 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6595 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6597 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6598 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6600 if a
.Dist
> b
.Dist
then // B áëèæå
6602 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6605 else // Ñòðàííî -> A
6610 a
, x1
, y1
, x2
, y2
: Integer;
6611 targets
: TTargetRecord
;
6613 Target
, BestTarget
: TTarget
;
6614 firew
, fireh
: Integer;
6618 vsPlayer
, vsMonster
, ok
: Boolean;
6621 function monsUpdate (mon
: TMonster
): Boolean;
6623 result
:= false; // don't stop
6624 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6626 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6628 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6629 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6631 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6632 if g_TraceVector(x1
, y1
, x2
, y2
) then
6634 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6635 SetLength(targets
, Length(targets
)+1);
6636 with targets
[High(targets
)] do
6643 Rect
:= mon
.Obj
.Rect
;
6644 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6645 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6646 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6655 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6656 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6658 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6659 if FCurrWeap
<> FSelectedWeapon
then
6662 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6663 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6665 RemoveAIFlag('NEEDFIRE');
6668 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6669 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6670 else PressKey(KEY_FIRE
);
6674 // Êîîðäèíàòû ñòâîëà:
6675 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6676 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6678 Target
.UID
:= FTargetUID
;
6681 if Target
.UID
<> 0 then
6682 begin // Öåëü åñòü - íàñòðàèâàåì
6683 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6686 tpla
:= g_Player_Get(Target
.UID
);
6690 if (@FObj
) <> nil then
6697 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6698 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6699 Target
.Rect
:= PLAYER_RECT
;
6700 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6701 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6702 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6703 Target
.IsPlayer
:= True;
6707 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6710 mon
:= g_Monsters_ByUID(Target
.UID
);
6713 Target
.X
:= mon
.Obj
.X
;
6714 Target
.Y
:= mon
.Obj
.Y
;
6716 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6717 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6718 Target
.Rect
:= mon
.Obj
.Rect
;
6719 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6720 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6721 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6722 Target
.IsPlayer
:= False;
6729 begin // Öåëè íåò - îáíóëÿåì
6734 Target
.Visible
:= False;
6735 Target
.Line
:= False;
6736 Target
.IsPlayer
:= False;
6741 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6742 if (not Target
.Line
) or (not Target
.Visible
) then
6746 for a
:= 0 to High(gPlayers
) do
6747 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6748 (gPlayers
[a
].FUID
<> FUID
) and
6749 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6750 (not gPlayers
[a
].NoTarget
) and
6751 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6753 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6754 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6757 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6758 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6760 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6761 if g_TraceVector(x1
, y1
, x2
, y2
) then
6763 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6764 SetLength(targets
, Length(targets
)+1);
6765 with targets
[High(targets
)] do
6767 UID
:= gPlayers
[a
].FUID
;
6768 X
:= gPlayers
[a
].FObj
.X
;
6769 Y
:= gPlayers
[a
].FObj
.Y
;
6772 Rect
:= PLAYER_RECT
;
6773 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6774 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6775 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6783 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6786 // Åñëè åñòü âîçìîæíûå öåëè:
6787 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6788 if targets
<> nil then
6790 // Âûáèðàåì íàèëó÷øóþ öåëü:
6791 BestTarget
:= targets
[0];
6792 if Length(targets
) > 1 then
6793 for a
:= 1 to High(targets
) do
6794 if Compare(BestTarget
, targets
[a
]) = 1 then
6795 BestTarget
:= targets
[a
];
6797 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6798 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6799 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6801 Target
:= BestTarget
;
6803 if (Healthy() = 3) or ((Healthy() = 2)) then
6804 begin // Åñëè çäîðîâû - äîãîíÿåì
6805 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6806 SetAIFlag('GORIGHT', '1');
6807 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6808 SetAIFlag('GOLEFT', '1');
6811 begin // Åñëè ïîáèòû - óáåãàåì
6812 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6813 SetAIFlag('GORIGHT', '1');
6814 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6815 SetAIFlag('GOLEFT', '1');
6818 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6819 SelectWeapon(Abs(x1
-Target
.cX
));
6824 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6825 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6826 if Target
.UID
<> 0 then
6828 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6829 Target
.Y
+ Target
.Rect
.Y
) then
6830 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6831 if (Healthy() = 3) or ((Healthy() = 2)) then
6832 begin // Åñëè çäîðîâû - äîãîíÿåì
6833 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6834 SetAIFlag('GORIGHT', '1');
6835 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6836 SetAIFlag('GOLEFT', '1');
6839 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6841 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6842 SetAIFlag('GORIGHT', '1');
6843 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6844 SetAIFlag('GOLEFT', '1');
6848 begin // Öåëü ïîêà íà "ýêðàíå"
6849 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6850 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6851 FLastVisible
:= gTime
;
6852 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6853 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6855 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6856 SetAIFlag('GORIGHT', '1');
6857 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6858 SetAIFlag('GOLEFT', '1');
6862 // Âûáèðàåì óãîë ââåðõ:
6863 if FDirection
= TDirection
.D_LEFT
then
6864 angle
:= ANGLE_LEFTUP
6866 angle
:= ANGLE_RIGHTUP
;
6868 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6869 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6871 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6872 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6873 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6874 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6875 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6876 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6877 begin // òî íóæíî ñòðåëÿòü ââåðõ
6878 SetAIFlag('NEEDFIRE', '1');
6879 SetAIFlag('NEEDSEEUP', '1');
6882 // Âûáèðàåì óãîë âíèç:
6883 if FDirection
= TDirection
.D_LEFT
then
6884 angle
:= ANGLE_LEFTDOWN
6886 angle
:= ANGLE_RIGHTDOWN
;
6888 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6889 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6891 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6892 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6893 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6894 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6895 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6896 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6897 begin // òî íóæíî ñòðåëÿòü âíèç
6898 SetAIFlag('NEEDFIRE', '1');
6899 SetAIFlag('NEEDSEEDOWN', '1');
6902 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6903 if Target
.Visible
and
6904 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6905 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6907 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6908 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
6909 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6910 begin // òî íóæíî ñòðåëÿòü âïåðåä
6911 SetAIFlag('NEEDFIRE', '1');
6912 SetAIFlag('NEEDSEEDOWN', '');
6913 SetAIFlag('NEEDSEEUP', '');
6915 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6916 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6917 if GetRnd(FDifficult
.CloseJump
) then
6918 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6919 if Abs(FObj
.X
-Target
.X
) < 128 then
6923 if Random(a
) = 0 then
6924 SetAIFlag('NEEDJUMP', '1');
6928 // Åñëè öåëü âñå åùå åñòü:
6929 if Target
.UID
<> 0 then
6930 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
6931 Target
.UID
:= 0 // òî çàáûòü öåëü
6932 else // Åñëè âèäåëè íåäàâíî
6933 begin // íî öåëü óáèëè
6934 if Target
.IsPlayer
then
6935 begin // Öåëü - èãðîê
6936 pla
:= g_Player_Get(Target
.UID
);
6937 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
6938 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6939 Target
.UID
:= 0; // òî çàáûòü öåëü
6942 begin // Öåëü - ìîíñòð
6943 mon
:= g_Monsters_ByUID(Target
.UID
);
6944 if (mon
= nil) or (not mon
.alive
) then
6945 Target
.UID
:= 0; // òî çàáûòü öåëü
6948 end; // if Target.UID <> 0
6950 FTargetUID
:= Target
.UID
;
6952 // Åñëè âîçìîæíûõ öåëåé íåò:
6953 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
6954 if targets
= nil then
6955 if GetAIFlag('ATTACKLEFT') <> '' then
6956 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
6957 RemoveAIFlag('ATTACKLEFT');
6959 SetAIFlag('NEEDJUMP', '1');
6961 if RunDirection() = TDirection
.D_RIGHT
then
6962 begin // Èäåì íå â òó ñòîðîíó
6963 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6964 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
6965 SetAIFlag('NEEDFIRE', '1');
6966 SetAIFlag('GOLEFT', '1');
6970 begin // Èäåì â íóæíóþ ñòîðîíó
6971 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6972 SetAIFlag('NEEDFIRE', '1');
6973 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6974 SetAIFlag('GORIGHT', '1');
6978 if GetAIFlag('ATTACKRIGHT') <> '' then
6979 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
6980 RemoveAIFlag('ATTACKRIGHT');
6982 SetAIFlag('NEEDJUMP', '1');
6984 if RunDirection() = TDirection
.D_LEFT
then
6985 begin // Èäåì íå â òó ñòîðîíó
6986 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6987 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
6988 SetAIFlag('NEEDFIRE', '1');
6989 SetAIFlag('GORIGHT', '1');
6994 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6995 SetAIFlag('NEEDFIRE', '1');
6996 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6997 SetAIFlag('GOLEFT', '1');
7001 //HACK! (does it belongs there?)
7002 RealizeCurrentWeapon();
7004 // Åñëè åñòü âîçìîæíûå öåëè:
7005 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7006 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7007 for a
:= 0 to High(targets
) do
7009 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7010 if GetRnd(FDifficult
.DiagFire
) then
7012 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7013 if FDirection
= TDirection
.D_LEFT
then
7014 angle
:= ANGLE_LEFTUP
7016 angle
:= ANGLE_RIGHTUP
;
7018 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7019 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7021 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7022 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7023 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7024 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7025 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7027 SetAIFlag('NEEDFIRE', '1');
7028 SetAIFlag('NEEDSEEUP', '1');
7031 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7032 if FDirection
= TDirection
.D_LEFT
then
7033 angle
:= ANGLE_LEFTDOWN
7035 angle
:= ANGLE_RIGHTDOWN
;
7037 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7038 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7040 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7041 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7042 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7043 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7044 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7046 SetAIFlag('NEEDFIRE', '1');
7047 SetAIFlag('NEEDSEEDOWN', '1');
7051 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7052 if targets
[a
].Line
and targets
[a
].Visible
and
7053 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
7054 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
7056 SetAIFlag('NEEDFIRE', '1');
7061 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7062 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
7063 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
7064 40+GetInterval(FDifficult
.Cover
, 40)) then
7065 SetAIFlag('NEEDJUMP', '1');
7067 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7068 ammo
:= GetAmmoByWeapon(FCurrWeap
);
7069 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
7070 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
7072 SetAIFlag('SELECTWEAPON', '1');
7074 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7075 if GetAIFlag('SELECTWEAPON') = '1' then
7078 RemoveAIFlag('SELECTWEAPON');
7082 procedure TBot
.Update();
7095 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7096 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7098 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7100 if g_debug_BotAIOff
= 3 then
7110 RealizeCurrentWeapon();
7117 procedure TBot
.ReleaseKey(Key
: Byte);
7126 function TBot
.KeyPressed(Key
: Word): Boolean;
7128 Result
:= FKeys
[Key
].Pressed
;
7131 function TBot
.GetAIFlag(aName
: String20
): String20
;
7137 aName
:= LowerCase(aName
);
7139 if FAIFlags
<> nil then
7140 for a
:= 0 to High(FAIFlags
) do
7141 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7143 Result
:= FAIFlags
[a
].Value
;
7148 procedure TBot
.RemoveAIFlag(aName
: String20
);
7152 if FAIFlags
= nil then Exit
;
7154 aName
:= LowerCase(aName
);
7156 for a
:= 0 to High(FAIFlags
) do
7157 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7159 if a
<> High(FAIFlags
) then
7160 for b
:= a
to High(FAIFlags
)-1 do
7161 FAIFlags
[b
] := FAIFlags
[b
+1];
7163 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7168 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7176 aName
:= LowerCase(aName
);
7178 if FAIFlags
<> nil then
7179 for a
:= 0 to High(FAIFlags
) do
7180 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7186 if ok
then FAIFlags
[a
].Value
:= fValue
7189 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7190 with FAIFlags
[High(FAIFlags
)] do
7198 procedure TBot
.UpdateMove
;
7200 procedure GoLeft(Time
: Word = 1);
7202 ReleaseKey(KEY_LEFT
);
7203 ReleaseKey(KEY_RIGHT
);
7204 PressKey(KEY_LEFT
, Time
);
7205 SetDirection(TDirection
.D_LEFT
);
7208 procedure GoRight(Time
: Word = 1);
7210 ReleaseKey(KEY_LEFT
);
7211 ReleaseKey(KEY_RIGHT
);
7212 PressKey(KEY_RIGHT
, Time
);
7213 SetDirection(TDirection
.D_RIGHT
);
7216 function Rnd(a
: Word): Boolean;
7218 Result
:= Random(a
) = 0;
7221 procedure Turn(Time
: Word = 1200);
7223 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7228 ReleaseKey(KEY_LEFT
);
7229 ReleaseKey(KEY_RIGHT
);
7232 function CanRunLeft(): Boolean;
7234 Result
:= not CollideLevel(-1, 0);
7237 function CanRunRight(): Boolean;
7239 Result
:= not CollideLevel(1, 0);
7242 function CanRun(): Boolean;
7244 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7247 procedure Jump(Time
: Word = 30);
7249 PressKey(KEY_JUMP
, Time
);
7252 function NearHole(): Boolean;
7256 { TODO 5 : Ëåñòíèöû }
7257 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7258 for x
:= 1 to PLAYER_RECT
.Width
do
7259 if (not StayOnStep(x
*sx
, 0)) and
7260 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7261 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7270 function BorderHole(): Boolean;
7274 { TODO 5 : Ëåñòíèöû }
7275 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7276 for x
:= 1 to PLAYER_RECT
.Width
do
7277 if (not StayOnStep(x
*sx
, 0)) and
7278 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7279 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7281 for xx
:= x
to x
+32 do
7282 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7292 function NearDeepHole(): Boolean;
7298 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7301 for x
:= 1 to PLAYER_RECT
.Width
do
7302 if (not StayOnStep(x
*sx
, 0)) and
7303 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7304 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7306 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7308 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7313 end else Result
:= False;
7316 function OverDeepHole(): Boolean;
7323 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7325 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7332 function OnGround(): Boolean;
7334 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7337 function OnLadder(): Boolean;
7339 Result
:= FullInStep(0, 0);
7342 function BelowLadder(): Boolean;
7344 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7345 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7346 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7347 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7350 function BelowLiftUp(): Boolean;
7352 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7353 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7354 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7355 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7358 function OnTopLift(): Boolean;
7360 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7363 function CanJumpOver(): Boolean;
7367 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7371 if not CollideLevel(sx
, 0) then Exit
;
7373 for y
:= 1 to BOT_MAXJUMP
do
7374 if CollideLevel(0, -y
) then Exit
else
7375 if not CollideLevel(sx
, -y
) then
7382 function CanJumpUp(Dist
: ShortInt): Boolean;
7389 if CollideLevel(Dist
, 0) then Exit
;
7392 for y
:= 0 to BOT_MAXJUMP
do
7393 if CollideLevel(Dist
, -y
) then
7402 for yy
:= y
+1 to BOT_MAXJUMP
do
7403 if not CollideLevel(Dist
, -yy
) then
7412 for y
:= 0 to BOT_MAXJUMP
do
7413 if CollideLevel(0, -y
) then
7421 if y
< yy
then Exit
;
7426 function IsSafeTrigger(): Boolean;
7431 if gTriggers
= nil then
7433 for a
:= 0 to High(gTriggers
) do
7434 if Collide(gTriggers
[a
].X
,
7437 gTriggers
[a
].Height
) and
7438 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7439 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7440 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7441 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7442 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7447 // Âîçìîæíî, íàæèìàåì êíîïêó:
7448 if Rnd(16) and IsSafeTrigger() then
7451 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7452 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7454 ReleaseKey(KEY_LEFT
);
7455 ReleaseKey(KEY_RIGHT
);
7459 // Èäåì âëåâî, åñëè íàäî áûëî:
7460 if GetAIFlag('GOLEFT') <> '' then
7462 RemoveAIFlag('GOLEFT');
7463 if CanRunLeft() then
7467 // Èäåì âïðàâî, åñëè íàäî áûëî:
7468 if GetAIFlag('GORIGHT') <> '' then
7470 RemoveAIFlag('GORIGHT');
7471 if CanRunRight() then
7475 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7476 if FObj
.X
< -32 then
7479 if FObj
.X
+32 > gMapInfo
.Width
then
7482 // Ïðûãàåì, åñëè íàäî áûëî:
7483 if GetAIFlag('NEEDJUMP') <> '' then
7486 RemoveAIFlag('NEEDJUMP');
7489 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7490 if GetAIFlag('NEEDSEEUP') <> '' then
7493 ReleaseKey(KEY_DOWN
);
7494 PressKey(KEY_UP
, 20);
7495 RemoveAIFlag('NEEDSEEUP');
7498 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7499 if GetAIFlag('NEEDSEEDOWN') <> '' then
7502 ReleaseKey(KEY_DOWN
);
7503 PressKey(KEY_DOWN
, 20);
7504 RemoveAIFlag('NEEDSEEDOWN');
7507 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7508 if GetAIFlag('GOINHOLE') <> '' then
7509 if not OnGround() then
7511 ReleaseKey(KEY_LEFT
);
7512 ReleaseKey(KEY_RIGHT
);
7513 RemoveAIFlag('GOINHOLE');
7514 SetAIFlag('FALLINHOLE', '1');
7517 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7518 if GetAIFlag('FALLINHOLE') <> '' then
7520 RemoveAIFlag('FALLINHOLE');
7522 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7523 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7524 if GetAIFlag('FALLINHOLE') = '' then
7525 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7531 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7533 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7537 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7538 if OnGround() and NearHole() then
7539 if NearDeepHole() then // Åñëè ýòî áåçäíà
7541 0..3: Turn(); // Áåæèì îáðàòíî
7542 4: Jump(); // Ïðûãàåì
7543 5: begin // Ïðûãàåì îáðàòíî
7548 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7549 if GetAIFlag('GOINHOLE') = '' then
7551 0: Turn(); // Íå íóæíî òóäà
7552 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7553 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7554 if BorderHole() then
7555 SetAIFlag('GOINHOLE', '1');
7558 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7559 if (not CanRun()) and OnGround() then
7561 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7562 if CanJumpOver() or OnLadder() then
7564 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7565 if Random(2) = 0 then
7567 if IsSafeTrigger() then
7573 // Îñòàëîñü ìàëî âîçäóõà:
7574 if FAir
< 36 * 2 then
7577 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7578 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7579 if BodyInAcid(0, 0) then
7583 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7585 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7586 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7589 {function TBot.NeedItem(Item: Byte): Byte;
7594 procedure TBot
.SelectWeapon(Dist
: Integer);
7598 function HaveAmmo(weapon
: Byte): Boolean;
7601 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7602 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7603 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7604 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7605 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7606 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7607 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7608 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7609 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7610 else Result
:= True;
7615 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7617 if Dist
> BOT_LONGDIST
then
7618 begin // Äàëüíèé áîé
7620 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7622 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7626 else //if Dist > BOT_UNSAFEDIST then
7627 begin // Áëèæíèé áîé
7629 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7631 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7638 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7640 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7646 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7648 Result
:= inherited PickItem(ItemType
, force
, remove
);
7650 if Result
then SetAIFlag('SELECTWEAPON', '1');
7653 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7655 Result
:= inherited Heal(value
, Soft
);
7658 function TBot
.Healthy(): Byte;
7660 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7661 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7662 else if (FHealth
> 50) then Result
:= 2
7663 else if (FHealth
> 20) then Result
:= 1
7667 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7669 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7670 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7673 procedure TBot
.OnDamage(Angle
: SmallInt);
7681 if (Angle
= 0) or (Angle
= 180) then
7684 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7685 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7687 pla
:= g_Player_Get(FLastSpawnerUID
);
7688 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7689 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7692 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7693 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7695 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7696 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7697 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7702 SetAIFlag('ATTACKLEFT', '1')
7704 SetAIFlag('ATTACKRIGHT', '1');
7708 function TBot
.RunDirection(): TDirection
;
7710 if Abs(Vel
.X
) >= 1 then
7712 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7714 Result
:= FDirection
;
7717 function TBot
.GetRnd(a
: Byte): Boolean;
7719 if a
= 0 then Result
:= False
7720 else if a
= 255 then Result
:= True
7721 else Result
:= Random(256) > 255-a
;
7724 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7726 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7730 procedure TDifficult
.save (st
: TStream
);
7732 utils
.writeInt(st
, Byte(DiagFire
));
7733 utils
.writeInt(st
, Byte(InvisFire
));
7734 utils
.writeInt(st
, Byte(DiagPrecision
));
7735 utils
.writeInt(st
, Byte(FlyPrecision
));
7736 utils
.writeInt(st
, Byte(Cover
));
7737 utils
.writeInt(st
, Byte(CloseJump
));
7738 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7739 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7742 procedure TDifficult
.load (st
: TStream
);
7744 DiagFire
:= utils
.readByte(st
);
7745 InvisFire
:= utils
.readByte(st
);
7746 DiagPrecision
:= utils
.readByte(st
);
7747 FlyPrecision
:= utils
.readByte(st
);
7748 Cover
:= utils
.readByte(st
);
7749 CloseJump
:= utils
.readByte(st
);
7750 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7751 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7755 procedure TBot
.SaveState (st
: TStream
);
7760 inherited SaveState(st
);
7761 utils
.writeSign(st
, 'BOT0');
7763 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7765 utils
.writeInt(st
, Word(FTargetUID
));
7766 // Âðåìÿ ïîòåðè öåëè
7767 utils
.writeInt(st
, LongWord(FLastVisible
));
7768 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7769 dw
:= Length(FAIFlags
);
7770 utils
.writeInt(st
, LongInt(dw
));
7772 for i
:= 0 to dw
-1 do
7774 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7775 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7777 // Íàñòðîéêè ñëîæíîñòè
7778 FDifficult
.save(st
);
7782 procedure TBot
.LoadState (st
: TStream
);
7787 inherited LoadState(st
);
7788 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7790 FSelectedWeapon
:= utils
.readByte(st
);
7792 FTargetUID
:= utils
.readWord(st
);
7793 // Âðåìÿ ïîòåðè öåëè
7794 FLastVisible
:= utils
.readLongWord(st
);
7795 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7796 dw
:= utils
.readLongInt(st
);
7797 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7798 SetLength(FAIFlags
, dw
);
7800 for i
:= 0 to dw
-1 do
7802 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7803 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7805 // Íàñòðîéêè ñëîæíîñòè
7806 FDifficult
.load(st
);
7811 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);