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..64] of Integer; // value: index in `FWeapon`
3592 wwc
: Integer = 0; //HACK!
3593 dir
, cwi
, rwidx
, curlidx
: Integer;
3595 function real2log (ridx
: Integer): Integer;
3601 for f
:= 0 to 10 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 // build weapon order (k8: i know, i know, learn how to do constants and such... gtfo, please!)
3618 // bfg, plasma, flamethrower, ssg, minigun, sg, pistol, berserk, chainsaw, fist
3619 weaponOrder
[0] := WEAPON_BFG
;
3620 weaponOrder
[1] := WEAPON_PLASMA
;
3621 weaponOrder
[2] := WEAPON_FLAMETHROWER
;
3622 weaponOrder
[3] := WEAPON_SHOTGUN2
;
3623 weaponOrder
[4] := WEAPON_CHAINGUN
;
3624 weaponOrder
[5] := WEAPON_SHOTGUN1
;
3625 weaponOrder
[6] := WEAPON_PISTOL
;
3626 weaponOrder
[7] := WEAPON_KASTET
;
3627 weaponOrder
[8] := WEAPON_SAW
;
3628 weaponOrder
[9] := WEAPON_KASTET
;
3629 weaponOrder
[10] := WEAPON_SUPERPULEMET
;
3631 if (R_BERSERK
in FRulez
) then weaponOrder
[9] := -1 else weaponOrder
[7] := -1;
3637 WEAPON_SHOTGUN1 = 3;
3638 WEAPON_SHOTGUN2 = 4;
3639 WEAPON_CHAINGUN = 5;
3640 WEAPON_ROCKETLAUNCHER = 6;
3643 WEAPON_SUPERPULEMET = 9;
3644 WEAPON_FLAMETHROWER = 10;
3647 // cycling has priority
3648 if (FNextWeap
and $C000) <> 0 then
3650 if (FNextWeap
and $8000) <> 0 then dir
:= 1 else dir
:= -1; // should be reversed if we want "priority-driven cycling"
3651 FNextWeap
:= FNextWeap
or $2000; // we need this
3652 if FNextWeapDelay
> 0 then exit
; // cooldown time
3653 //cwi := real2log(FCurrWeap);
3654 //if (cwi < 0) then cwi := 0;
3656 for i
:= 0 to High(FWeapon
) do
3658 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3659 //rwidx := weaponOrder[cwi];
3660 rwidx
:= cwi
; // sorry
3661 if (rwidx
< 0) then continue
;
3662 if FWeapon
[rwidx
] then
3664 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d (dir=%d; log=%d)', [FCurrWeap, rwidx, dir, cwi]), TMsgType.Warning);
3665 result
:= Byte(rwidx
);
3666 FNextWeapDelay
:= 10;
3675 for i
:= 0 to High(wantThisWeapon
) do wantThisWeapon
[i
] := false;
3676 for i
:= 0 to High(FWeapon
) do
3678 if (FNextWeap
and (1 shl i
)) <> 0 then
3681 if (cwi
>= 0) then wantThisWeapon
[cwi
] := true;
3686 // slow down alterations a little
3689 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3690 // more than one weapon requested, assume "alteration", and check alteration delay
3691 if FNextWeapDelay
> 0 then
3698 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3699 // but clear all counters if no weapon should be switched
3705 //e_WriteLog(Format('wwc=%d', [wwc]), TMsgType.Warning);
3707 // exclude currently selected weapon from the set
3708 curlidx
:= real2log(FCurrWeap
);
3709 //e_WriteLog(Format('FCurrWeap=%d; curlidx=%d', [FCurrWeap, curlidx]), TMsgType.Warning);
3710 //if (curlidx >= 0) then wantThisWeapon[curlidx] := false;
3711 //if (wwc = 2) then begin Dec(wwc); end; // easy case: switch between two weapons
3713 // find next weapon to switch onto
3715 for i
:= 0 to High(FWeapon
) do
3717 cwi
:= (cwi
+length(FWeapon
)+1) mod length(FWeapon
);
3718 if (cwi
= curlidx
) then continue
; // skip current weapon
3719 if not wantThisWeapon
[cwi
] then continue
;
3720 rwidx
:= weaponOrder
[cwi
];
3721 if (rwidx
< 0) then continue
;
3722 //e_WriteLog(Format(' trying logical %d (real %d)', [cwi, rwidx]), TMsgType.Warning);
3723 if FWeapon
[cwi
] and ((wwc
= 1) or hasAmmoForWeapon(cwi
)) then
3726 result
:= Byte(rwidx
);
3728 FNextWeapDelay
:= 10; // anyway, 'cause why not
3733 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3737 procedure TPlayer
.RealizeCurrentWeapon();
3738 function switchAllowed (): Boolean;
3743 if FBFGFireCounter
<> -1 then
3745 if FTime
[T_SWITCH
] > gTime
then
3747 for i
:= WP_FIRST
to WP_LAST
do
3748 if FReloading
[i
] > 0 then
3756 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3757 //FNextWeap := FNextWeap and $1FFF;
3758 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3760 if not switchAllowed
then
3762 //HACK for weapon cycling
3763 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3767 nw
:= getNextWeaponIndex();
3768 if nw
= 255 then exit
; // don't reset anything here
3769 if nw
> High(FWeapon
) then
3771 // don't forget to reset queue here!
3772 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3780 FTime
[T_SWITCH
] := gTime
+156;
3781 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3782 FModel
.SetWeapon(FCurrWeap
);
3783 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3787 procedure TPlayer
.NextWeapon();
3789 if g_Game_IsClient
then Exit
;
3793 procedure TPlayer
.PrevWeapon();
3795 if g_Game_IsClient
then Exit
;
3799 procedure TPlayer
.SetWeapon(W
: Byte);
3801 if FCurrWeap
<> W
then
3802 if W
= WEAPON_SAW
then
3803 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3806 FModel
.SetWeapon(CurrWeap
);
3810 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3812 function allowBerserkSwitching (): Boolean;
3814 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3816 if gBerserkAutoswitch
then exit
;
3817 if not conIsCheatsEnabled
then exit
;
3825 if g_Game_IsClient
then Exit
;
3827 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3828 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3833 if FHealth
< PLAYER_HP_SOFT
then
3835 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3839 if gFlash
= 2 then Inc(FPickup
, 5);
3843 if FHealth
< PLAYER_HP_SOFT
then
3845 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3849 if gFlash
= 2 then Inc(FPickup
, 5);
3853 if FArmor
< PLAYER_AP_SOFT
then
3855 FArmor
:= PLAYER_AP_SOFT
;
3858 if gFlash
= 2 then Inc(FPickup
, 5);
3862 if FArmor
< PLAYER_AP_LIMIT
then
3864 FArmor
:= PLAYER_AP_LIMIT
;
3867 if gFlash
= 2 then Inc(FPickup
, 5);
3871 if FHealth
< PLAYER_HP_LIMIT
then
3873 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3877 if gFlash
= 2 then Inc(FPickup
, 5);
3881 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3883 if FHealth
< PLAYER_HP_LIMIT
then
3884 FHealth
:= PLAYER_HP_LIMIT
;
3885 if FArmor
< PLAYER_AP_LIMIT
then
3886 FArmor
:= PLAYER_AP_LIMIT
;
3890 if gFlash
= 2 then Inc(FPickup
, 5);
3894 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3896 FWeapon
[WEAPON_SAW
] := True;
3898 if gFlash
= 2 then Inc(FPickup
, 5);
3899 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3902 ITEM_WEAPON_SHOTGUN1
:
3903 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3905 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3906 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3908 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3909 FWeapon
[WEAPON_SHOTGUN1
] := True;
3911 if gFlash
= 2 then Inc(FPickup
, 5);
3912 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3915 ITEM_WEAPON_SHOTGUN2
:
3916 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3918 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3920 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3921 FWeapon
[WEAPON_SHOTGUN2
] := True;
3923 if gFlash
= 2 then Inc(FPickup
, 5);
3924 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3927 ITEM_WEAPON_CHAINGUN
:
3928 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3930 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3932 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3933 FWeapon
[WEAPON_CHAINGUN
] := True;
3935 if gFlash
= 2 then Inc(FPickup
, 5);
3936 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3939 ITEM_WEAPON_ROCKETLAUNCHER
:
3940 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3942 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3944 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3945 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3947 if gFlash
= 2 then Inc(FPickup
, 5);
3948 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3952 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3954 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3956 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3957 FWeapon
[WEAPON_PLASMA
] := True;
3959 if gFlash
= 2 then Inc(FPickup
, 5);
3960 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3964 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3966 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3968 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3969 FWeapon
[WEAPON_BFG
] := True;
3971 if gFlash
= 2 then Inc(FPickup
, 5);
3972 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3975 ITEM_WEAPON_SUPERPULEMET
:
3976 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3978 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3980 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3981 FWeapon
[WEAPON_SUPERPULEMET
] := True;
3983 if gFlash
= 2 then Inc(FPickup
, 5);
3984 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3987 ITEM_WEAPON_FLAMETHROWER
:
3988 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
3990 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
3992 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3993 FWeapon
[WEAPON_FLAMETHROWER
] := True;
3995 if gFlash
= 2 then Inc(FPickup
, 5);
3996 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4000 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4002 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4005 if gFlash
= 2 then Inc(FPickup
, 5);
4008 ITEM_AMMO_BULLETS_BOX
:
4009 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4011 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4014 if gFlash
= 2 then Inc(FPickup
, 5);
4018 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4020 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4023 if gFlash
= 2 then Inc(FPickup
, 5);
4026 ITEM_AMMO_SHELLS_BOX
:
4027 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4029 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
4032 if gFlash
= 2 then Inc(FPickup
, 5);
4036 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4038 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4041 if gFlash
= 2 then Inc(FPickup
, 5);
4044 ITEM_AMMO_ROCKET_BOX
:
4045 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4047 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
4050 if gFlash
= 2 then Inc(FPickup
, 5);
4054 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4056 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4059 if gFlash
= 2 then Inc(FPickup
, 5);
4063 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4065 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4068 if gFlash
= 2 then Inc(FPickup
, 5);
4072 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4074 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4077 if gFlash
= 2 then Inc(FPickup
, 5);
4081 if not(R_ITEM_BACKPACK
in FRulez
) or
4082 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4083 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4084 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4085 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4086 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
4088 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4089 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4090 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4091 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4092 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4094 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4095 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4096 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4097 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4098 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4099 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4100 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4101 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4103 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
4106 if gFlash
= 2 then Inc(FPickup
, 5);
4110 if not(R_KEY_RED
in FRulez
) then
4112 Include(FRulez
, R_KEY_RED
);
4114 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4115 if gFlash
= 2 then Inc(FPickup
, 5);
4116 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4120 if not(R_KEY_GREEN
in FRulez
) then
4122 Include(FRulez
, R_KEY_GREEN
);
4124 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4125 if gFlash
= 2 then Inc(FPickup
, 5);
4126 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4130 if not(R_KEY_BLUE
in FRulez
) then
4132 Include(FRulez
, R_KEY_BLUE
);
4134 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4135 if gFlash
= 2 then Inc(FPickup
, 5);
4136 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4140 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4142 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4146 if gFlash
= 2 then Inc(FPickup
, 5);
4150 if FAir
< AIR_MAX
then
4155 if gFlash
= 2 then Inc(FPickup
, 5);
4160 if not (R_BERSERK
in FRulez
) then
4162 Include(FRulez
, R_BERSERK
);
4163 if allowBerserkSwitching
then
4165 FCurrWeap
:= WEAPON_KASTET
;
4167 FModel
.SetWeapon(WEAPON_KASTET
);
4172 if gFlash
= 2 then Inc(FPickup
, 5);
4174 FBerserk
:= gTime
+30000;
4179 if FHealth
< PLAYER_HP_SOFT
then
4181 FHealth
:= PLAYER_HP_SOFT
;
4182 FBerserk
:= gTime
+30000;
4190 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4192 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4195 if gFlash
= 2 then Inc(FPickup
, 5);
4199 if FHealth
< PLAYER_HP_LIMIT
then
4201 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4205 if gFlash
= 2 then Inc(FPickup
, 5);
4209 if FArmor
< PLAYER_AP_LIMIT
then
4211 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4214 if gFlash
= 2 then Inc(FPickup
, 5);
4218 if FJetFuel
< JET_MAX
then
4220 FJetFuel
:= JET_MAX
;
4223 if gFlash
= 2 then Inc(FPickup
, 5);
4227 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4229 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4232 if gFlash
= 2 then Inc(FPickup
, 5);
4237 procedure TPlayer
.Touch();
4241 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4244 // Áðîñèòü ôëàã òîâàðèùó:
4245 if gGameSettings
.GameMode
= GM_CTF
then
4250 procedure TPlayer
.Push(vx
, vy
: Integer);
4252 if (not FPhysics
) and FGhost
then
4254 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4255 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4256 if g_Game_IsNet
and g_Game_IsServer
then
4257 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4260 procedure TPlayer
.Reset(Force
: Boolean);
4266 FTime
[T_RESPAWN
] := 0;
4267 FTime
[T_FLAGCAP
] := 0;
4280 FSpectator
:= False;
4283 FSpectatePlayer
:= -1;
4284 FNoRespawn
:= False;
4286 FLives
:= gGameSettings
.MaxLives
;
4291 procedure TPlayer
.SoftReset();
4297 FBFGFireCounter
:= -1;
4305 SetAction(A_STAND
, True);
4308 function TPlayer
.GetRespawnPoint(): Byte;
4313 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4315 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4316 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4318 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4320 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4321 if Self
= gPlayer1
then
4322 c
:= RESPAWNPOINT_PLAYER1
4324 c
:= RESPAWNPOINT_PLAYER2
;
4325 if g_Map_GetPointCount(c
) > 0 then
4331 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4332 if Self
= gPlayer1
then
4333 c
:= RESPAWNPOINT_PLAYER2
4335 c
:= RESPAWNPOINT_PLAYER1
;
4336 if g_Map_GetPointCount(c
) > 0 then
4343 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4344 if Random(2) = 0 then
4345 c
:= RESPAWNPOINT_PLAYER1
4347 c
:= RESPAWNPOINT_PLAYER2
;
4348 if g_Map_GetPointCount(c
) > 0 then
4355 // Òî÷êà ëþáîé èç êîìàíä
4356 if Random(2) = 0 then
4357 c
:= RESPAWNPOINT_RED
4359 c
:= RESPAWNPOINT_BLUE
;
4360 if g_Map_GetPointCount(c
) > 0 then
4367 c
:= RESPAWNPOINT_DM
;
4368 if g_Map_GetPointCount(c
) > 0 then
4376 if gGameSettings
.GameMode
= GM_DM
then
4379 c
:= RESPAWNPOINT_DM
;
4380 if g_Map_GetPointCount(c
) > 0 then
4386 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4387 if Random(2) = 0 then
4388 c
:= RESPAWNPOINT_PLAYER1
4390 c
:= RESPAWNPOINT_PLAYER2
;
4391 if g_Map_GetPointCount(c
) > 0 then
4397 // Òî÷êà ëþáîé èç êîìàíä
4398 if Random(2) = 0 then
4399 c
:= RESPAWNPOINT_RED
4401 c
:= RESPAWNPOINT_BLUE
;
4402 if g_Map_GetPointCount(c
) > 0 then
4410 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4412 // Òî÷êà ñâîåé êîìàíäû
4413 c
:= RESPAWNPOINT_DM
;
4414 if FTeam
= TEAM_RED
then
4415 c
:= RESPAWNPOINT_RED
;
4416 if FTeam
= TEAM_BLUE
then
4417 c
:= RESPAWNPOINT_BLUE
;
4418 if g_Map_GetPointCount(c
) > 0 then
4425 c
:= RESPAWNPOINT_DM
;
4426 if g_Map_GetPointCount(c
) > 0 then
4432 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4433 if Random(2) = 0 then
4434 c
:= RESPAWNPOINT_PLAYER1
4436 c
:= RESPAWNPOINT_PLAYER2
;
4437 if g_Map_GetPointCount(c
) > 0 then
4443 // Òî÷êà äðóãîé êîìàíäû
4444 c
:= RESPAWNPOINT_DM
;
4445 if FTeam
= TEAM_RED
then
4446 c
:= RESPAWNPOINT_BLUE
;
4447 if FTeam
= TEAM_BLUE
then
4448 c
:= RESPAWNPOINT_RED
;
4449 if g_Map_GetPointCount(c
) > 0 then
4457 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4459 RespawnPoint
: TRespawnPoint
;
4465 FBFGFireCounter
:= -1;
4470 if not g_Game_IsServer
then
4474 FWantsInGame
:= True;
4475 FJustTeleported
:= True;
4478 FTime
[T_RESPAWN
] := 0;
4482 // if server changes MaxLives we gotta be ready
4483 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4485 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4486 if FTime
[T_RESPAWN
] > gTime
then
4489 // Ïðîñðàë âñå æèçíè:
4492 if not FSpectator
then Spectate(True);
4493 FWantsInGame
:= True;
4497 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4498 begin // "Ñâîÿ èãðà"
4499 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4500 FRulez
:= FRulez
-[R_BERSERK
];
4502 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4504 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4505 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4508 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4509 c
:= GetRespawnPoint();
4514 // Âîñêðåøåíèå áåç îðóæèÿ:
4517 FHealth
:= PLAYER_HP_SOFT
;
4523 for a
:= WP_FIRST
to WP_LAST
do
4525 FWeapon
[a
] := False;
4529 FWeapon
[WEAPON_PISTOL
] := True;
4530 FWeapon
[WEAPON_KASTET
] := True;
4531 FCurrWeap
:= WEAPON_PISTOL
;
4534 FModel
.SetWeapon(FCurrWeap
);
4536 for b
:= A_BULLETS
to A_HIGH
do
4539 FAmmo
[A_BULLETS
] := 50;
4541 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4542 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4543 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4544 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4545 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4547 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4548 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4553 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4554 if not g_Map_GetPoint(c
, RespawnPoint
) then
4556 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4560 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4561 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4562 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4568 FDirection
:= RespawnPoint
.Direction
;
4569 if FDirection
= TDirection
.D_LEFT
then
4574 SetAction(A_STAND
, True);
4575 FModel
.Direction
:= FDirection
;
4577 for a
:= Low(FTime
) to High(FTime
) do
4580 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4585 FCanJetpack
:= False;
4590 // Àíèìàöèÿ âîçðîæäåíèÿ:
4591 if (not gLoadGameMode
) and (not Silent
) then
4592 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4594 Anim
:= TAnimation
.Create(ID
, False, 3);
4595 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4596 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4600 FSpectator
:= False;
4603 FSpectatePlayer
:= -1;
4606 if (gPlayer1
= nil) and (gLMSPID1
= FUID
) then
4608 if (gPlayer2
= nil) and (gLMSPID2
= FUID
) then
4611 if g_Game_IsNet
then
4613 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4614 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4616 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4617 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4622 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4625 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4626 else if (not NoMove
) then
4628 GameX
:= gMapInfo
.Width
div 2;
4629 GameY
:= gMapInfo
.Height
div 2;
4638 FWantsInGame
:= False;
4643 if Self
= gPlayer1
then
4648 if Self
= gPlayer2
then
4655 if g_Game_IsNet
then
4656 MH_SEND_PlayerStats(FUID
);
4659 procedure TPlayer
.SwitchNoClip
;
4663 FGhost
:= not FGhost
;
4664 FPhysics
:= not FGhost
;
4676 procedure TPlayer
.Run(Direction
: TDirection
);
4680 if MAX_RUNVEL
> 8 then
4684 if Direction
= TDirection
.D_LEFT
then
4686 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4687 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4690 if FObj
.Vel
.X
< MAX_RUNVEL
then
4691 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4693 // Âîçìîæíî, ïèíàåì êóñêè:
4694 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4696 b
:= Abs(FObj
.Vel
.X
);
4697 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4698 for a
:= 0 to High(gGibs
) do
4700 if gGibs
[a
].alive
and
4701 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4702 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4705 if FObj
.Vel
.X
< 0 then
4707 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4711 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4713 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4721 procedure TPlayer
.SeeDown();
4723 SetAction(A_SEEDOWN
);
4725 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4727 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4730 procedure TPlayer
.SeeUp();
4734 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4736 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4739 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4747 A_ATTACK
: Prior
:= 2;
4748 A_SEEUP
: Prior
:= 1;
4749 A_SEEDOWN
: Prior
:= 1;
4750 A_ATTACKUP
: Prior
:= 2;
4751 A_ATTACKDOWN
: Prior
:= 2;
4756 if (Prior
> FActionPrior
) or Force
then
4757 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4759 FActionPrior
:= Prior
;
4760 FActionAnim
:= Action
;
4761 FActionForce
:= Force
;
4762 FActionChanged
:= True;
4765 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4768 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4770 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4771 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4772 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4773 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4776 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4783 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4785 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4786 if g_Game_IsServer
and g_Game_IsNet
then
4787 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4791 FJustTeleported
:= True;
4796 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4798 Anim
:= TAnimation
.Create(ID
, False, 3);
4801 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4802 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4803 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4804 if g_Game_IsServer
and g_Game_IsNet
then
4805 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4806 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4810 FObj
.X
:= X
-PLAYER_RECT
.X
;
4811 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4812 if FAlive
and FGhost
then
4818 if not g_Game_IsNet
then
4822 SetDirection(TDirection
.D_LEFT
);
4828 SetDirection(TDirection
.D_RIGHT
);
4834 if FDirection
= TDirection
.D_RIGHT
then
4836 SetDirection(TDirection
.D_LEFT
);
4841 SetDirection(TDirection
.D_RIGHT
);
4847 if not silent
and (Anim
<> nil) then
4849 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4850 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4853 if g_Game_IsServer
and g_Game_IsNet
then
4854 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4855 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4862 function nonz(a
: Single): Single;
4870 function TPlayer
.followCorpse(): Boolean;
4875 if FAlive
or FSpectator
then
4877 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
4879 for i
:= 0 to High(gCorpses
) do
4880 if gCorpses
[i
] <> nil then
4881 if gCorpses
[i
].FPlayerUID
= FUID
then
4884 FObj
.X
:= gCorpses
[i
].FObj
.X
;
4885 FObj
.Y
:= gCorpses
[i
].FObj
.Y
;
4886 FObj
.Vel
.X
:= gCorpses
[i
].FObj
.Vel
.X
;
4887 FObj
.Vel
.Y
:= gCorpses
[i
].FObj
.Vel
.Y
;
4888 FObj
.Accel
.X
:= gCorpses
[i
].FObj
.Accel
.X
;
4889 FObj
.Accel
.Y
:= gCorpses
[i
].FObj
.Accel
.Y
;
4894 procedure TPlayer
.Update();
4897 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4898 blockmon
, headwater
, dospawn
: Boolean;
4903 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4904 AnyServer
:= g_Game_IsServer
;
4906 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4907 DoLerp(NetInterpLevel
+ 1)
4913 if FClientID
>= 0 then
4915 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4916 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4917 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4926 if FAlive
and (FPunchAnim
<> nil) then
4927 FPunchAnim
.Update();
4929 if FAlive
and (gFly
or FJetpack
) then
4932 if FDirection
= TDirection
.D_LEFT
then
4937 if FAlive
and (not FGhost
) then
4939 if FKeys
[KEY_UP
].Pressed
then
4941 if FKeys
[KEY_DOWN
].Pressed
then
4945 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4948 i
:= g_basic
.Sign(FIncCam
);
4949 FIncCam
:= Abs(FIncCam
);
4950 DecMin(FIncCam
, 5, 0);
4951 FIncCam
:= FIncCam
*i
;
4954 // no need to do that each second frame, weapon queue will take care of it
4955 if FAlive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4956 if FAlive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4958 if gTime
mod (GAME_TICK
*2) <> 0 then
4960 if (FObj
.Vel
.X
= 0) and FAlive
then
4962 if FKeys
[KEY_LEFT
].Pressed
then
4963 Run(TDirection
.D_LEFT
);
4964 if FKeys
[KEY_RIGHT
].Pressed
then
4965 Run(TDirection
.D_RIGHT
);
4970 if not followCorpse() then
4971 g_Obj_Move(@FObj
, True, True, True);
4972 positionChanged(); // this updates spatial accelerators
4978 FActionChanged
:= False;
4982 // Let alive player do some actions
4983 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
4984 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
4985 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
4986 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
4987 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
4988 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
4989 if FKeys
[KEY_JUMP
].Pressed
then Jump()
4992 if AnyServer
and FJetpack
then
4996 if NetServer
then MH_SEND_PlayerStats(FUID
);
4998 FCanJetpack
:= True;
5005 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
5007 if FKeys
[k
].Pressed
then
5015 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5018 if (FTime
[T_RESPAWN
] <= gTime
) and
5019 gGameOn
and (not FAlive
) then
5021 if (g_Player_GetCount() > 1) then
5025 gExit
:= EXIT_RESTART
;
5030 // Dead spectator actions
5033 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
5034 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
5038 if (FSpectatePlayer
>= High(gPlayers
)) then
5039 FSpectatePlayer
:= -1
5043 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
5044 if gPlayers
[I
] <> nil then
5045 if gPlayers
[I
].alive
then
5046 if gPlayers
[I
].UID
<> FUID
then
5048 FSpectatePlayer
:= I
;
5053 if not SetSpect
then FSpectatePlayer
:= -1;
5064 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5066 FYTo
:= FObj
.Y
- 32;
5067 FSpectatePlayer
:= -1;
5069 if FKeys
[KEY_DOWN
].Pressed
then
5071 FYTo
:= FObj
.Y
+ 32;
5072 FSpectatePlayer
:= -1;
5074 if FKeys
[KEY_LEFT
].Pressed
then
5076 FXTo
:= FObj
.X
- 32;
5077 FSpectatePlayer
:= -1;
5079 if FKeys
[KEY_RIGHT
].Pressed
then
5081 FXTo
:= FObj
.X
+ 32;
5082 FSpectatePlayer
:= -1;
5085 if (FXTo
< -64) then
5087 else if (FXTo
> gMapInfo
.Width
+ 32) then
5088 FXTo
:= gMapInfo
.Width
+ 32;
5089 if (FYTo
< -72) then
5091 else if (FYTo
> gMapInfo
.Height
+ 32) then
5092 FYTo
:= gMapInfo
.Height
+ 32;
5097 if not followCorpse() then
5098 g_Obj_Move(@FObj
, True, True, True);
5099 positionChanged(); // this updates spatial accelerators
5106 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5107 if gPlayers
[FSpectatePlayer
] <> nil then
5108 if gPlayers
[FSpectatePlayer
].alive
then
5110 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
5111 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
5115 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5116 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5117 PANEL_BLOCKMON
, True);
5118 headwater
:= HeadInLiquid(0, 0);
5120 // Ñîïðîòèâëåíèå âîçäóõà:
5121 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5122 if FObj
.Vel
.X
<> 0 then
5123 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5125 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5126 DecMin(FPain
, 5, 0);
5127 DecMin(FPickup
, 1, 0);
5129 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5131 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5132 FMegaRulez
[MR_SUIT
] := 0;
5133 FMegaRulez
[MR_INVUL
] := 0;
5134 FMegaRulez
[MR_INVIS
] := 0;
5135 Kill(K_FALLKILL
, 0, HIT_FALL
);
5142 if FCurrWeap
= WEAPON_SAW
then
5143 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5144 FSawSoundSelect
.IsPlaying()) then
5145 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5148 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5149 (not FJetSoundOff
.IsPlaying()) then
5151 FJetSoundFly
.SetPosition(0);
5152 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5155 for b
:= WP_FIRST
to WP_LAST
do
5156 if FReloading
[b
] > 0 then
5162 if FShellTimer
> -1 then
5163 if FShellTimer
= 0 then
5165 if FShellType
= SHELL_SHELL
then
5166 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5167 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5168 else if FShellType
= SHELL_DBLSHELL
then
5170 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5171 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5172 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5173 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5176 end else Dec(FShellTimer
);
5178 if (FBFGFireCounter
> -1) then
5179 if FBFGFireCounter
= 0 then
5183 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5184 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5185 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5186 yd
:= wy
+firediry();
5187 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5188 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5189 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5190 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5191 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5194 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5195 FBFGFireCounter
:= -1;
5198 FBFGFireCounter
:= 0
5200 Dec(FBFGFireCounter
);
5202 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5204 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5206 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5209 if (headwater
or blockmon
) then
5215 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5218 else if (FAir
mod 31 = 0) and not blockmon
then
5220 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5221 if Random(2) = 0 then
5222 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5224 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5226 end else if FAir
< AIR_DEF
then
5229 if FFireTime
> 0 then
5231 if BodyInLiquid(0, 0) then
5236 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5238 if FMegaRulez
[MR_SUIT
] = gTime
then
5245 if FFirePainTime
<= 0 then
5247 if g_Game_IsServer
then
5248 Damage(5, FFireAttacker
, 0, 0, HIT_FLAME
);
5249 FFirePainTime
:= 18;
5251 FFirePainTime
:= FFirePainTime
- 1;
5252 FFireTime
:= FFireTime
- 1;
5253 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5254 MH_SEND_PlayerStats(FUID
);
5258 if FDamageBuffer
> 0 then
5260 if FDamageBuffer
>= 9 then
5264 if FDamageBuffer
< 30 then i
:= 9
5265 else if FDamageBuffer
< 100 then i
:= 18
5269 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5270 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5271 FHealth
:= FHealth
-ii
;
5274 FHealth
:= FHealth
+FArmor
;
5279 if FHealth
<= 0 then
5280 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5281 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5282 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5286 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5287 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5288 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5289 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5296 end; // if FAlive then ...
5298 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5300 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5301 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5302 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5303 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5305 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5306 then SetAction(A_STAND
, True);
5308 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5310 for b
:= Low(FKeys
) to High(FKeys
) do
5311 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5315 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5317 x
:= FObj
.X
+PLAYER_RECT
.X
;
5318 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5319 w
:= PLAYER_RECT
.Width
;
5320 h
:= PLAYER_RECT
.Height
;
5324 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5326 if (dx
<> 0) or (dy
<> 0) then
5335 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5337 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5338 FObj
.Y
+PLAYER_RECT
.Y
,
5345 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5347 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5348 FObj
.Y
+PLAYER_RECT
.Y
,
5352 Panel
.Width
, Panel
.Height
);
5355 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5357 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5358 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5359 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5360 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5363 function g_Player_ValidName(Name
: string): Boolean;
5369 if gPlayers
= nil then Exit
;
5371 for a
:= 0 to High(gPlayers
) do
5372 if gPlayers
[a
] <> nil then
5373 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5380 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5384 d
:= FModel
.Direction
;
5386 FModel
.Direction
:= Direction
;
5387 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5389 FDirection
:= Direction
;
5392 function TPlayer
.GetKeys(): Byte;
5396 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5397 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5398 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5400 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5401 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5404 procedure TPlayer
.Use();
5408 if FTime
[T_USE
] > gTime
then Exit
;
5410 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5411 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5413 for a
:= 0 to High(gPlayers
) do
5414 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5415 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5416 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5417 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5419 gPlayers
[a
].Touch();
5420 if g_Game_IsNet
and g_Game_IsServer
then
5421 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5424 FTime
[T_USE
] := gTime
+120;
5427 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5431 WX
, WY
, XD
, YD
: Integer;
5443 if R_BERSERK
in FRulez
then
5445 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5446 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5447 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5450 locobj
.rect
.Width
:= 39;
5451 locobj
.rect
.Height
:= 52;
5452 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5453 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5454 locobj
.Accel
.X
:= xd
-wx
;
5455 locobj
.Accel
.y
:= yd
-wy
;
5457 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5458 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5460 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5464 FPain
:= min(FPain
+ 25, 50);
5466 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5471 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5472 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5474 FSawSoundSelect
.Stop();
5476 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5478 else if not FSawSoundHit
.IsPlaying() then
5480 FSawSoundSelect
.Stop();
5481 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5488 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5489 FFireAngle
:= FAngle
;
5491 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5492 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5497 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5498 FFireAngle
:= FAngle
;
5501 FShellType
:= SHELL_SHELL
;
5506 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5507 FFireAngle
:= FAngle
;
5510 FShellType
:= SHELL_DBLSHELL
;
5515 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5516 FFireAngle
:= FAngle
;
5518 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5519 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5522 WEAPON_ROCKETLAUNCHER
:
5524 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5525 FFireAngle
:= FAngle
;
5531 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5532 FFireAngle
:= FAngle
;
5538 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5539 FFireAngle
:= FAngle
;
5543 WEAPON_SUPERPULEMET
:
5545 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5546 FFireAngle
:= FAngle
;
5548 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5549 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5552 WEAPON_FLAMETHROWER
:
5554 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5555 FFireAngle
:= FAngle
;
5562 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5563 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5564 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5567 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5569 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5570 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5573 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5577 if NetInterpLevel
< 1 then
5587 AX
:= Abs(FXTo
- FObj
.X
);
5588 AY
:= Abs(FYTo
- FObj
.Y
);
5589 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5591 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5596 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5598 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5599 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5600 PANEL_LIFTUP
, False) then Result
:= -1
5602 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5603 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5604 PANEL_LIFTDOWN
, False) then Result
:= 1
5608 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5615 if Flag
= FLAG_NONE
then
5618 if not g_Game_IsServer
then Exit
;
5620 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5621 if (Flag
= FTeam
) and
5622 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5623 (FFlag
<> FLAG_NONE
) then
5625 if FFlag
= FLAG_RED
then
5626 s
:= _lc
[I_PLAYER_FLAG_RED
]
5628 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5630 evtype
:= FLAG_STATE_SCORED
;
5632 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5633 Insert('.', ts
, Length(ts
) + 1 - 3);
5634 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5636 g_Map_ResetFlag(FFlag
);
5637 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5639 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5642 if g_Game_IsNet
then
5644 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5648 gFlags
[FFlag
].CaptureTime
:= 0;
5653 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5654 if (Flag
= FTeam
) and
5655 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5657 if Flag
= FLAG_RED
then
5658 s
:= _lc
[I_PLAYER_FLAG_RED
]
5660 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5662 evtype
:= FLAG_STATE_RETURNED
;
5663 gFlags
[Flag
].CaptureTime
:= 0;
5665 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5667 g_Map_ResetFlag(Flag
);
5668 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5671 if g_Game_IsNet
then
5673 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5679 // Ïîäîáðàë ÷óæîé ôëàã:
5680 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5684 if Flag
= FLAG_RED
then
5685 s
:= _lc
[I_PLAYER_FLAG_RED
]
5687 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5689 evtype
:= FLAG_STATE_CAPTURED
;
5691 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5693 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5695 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5698 if g_Game_IsNet
then
5700 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5706 procedure TPlayer
.SetFlag(Flag
: Byte);
5709 if FModel
<> nil then
5710 FModel
.SetFlag(FFlag
);
5713 function TPlayer
.DropFlag(): Boolean;
5718 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5720 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5721 with gFlags
[FFlag
] do
5725 Direction
:= FDirection
;
5726 State
:= FLAG_STATE_DROPPED
;
5728 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5729 (FObj
.Vel
.Y
div 2)-2+Random(5));
5730 positionChanged(); // this updates spatial accelerators
5732 if FFlag
= FLAG_RED
then
5733 s
:= _lc
[I_PLAYER_FLAG_RED
]
5735 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5737 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5738 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5740 if g_Game_IsNet
then
5741 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5747 procedure TPlayer
.GetSecret();
5752 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5754 Assert(Key
<= High(FKeys
));
5756 FKeys
[Key
].Pressed
:= True;
5757 FKeys
[Key
].Time
:= Time
;
5760 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5762 Result
:= FKeys
[K
].Pressed
;
5765 procedure TPlayer
.ReleaseKeys();
5769 for a
:= Low(FKeys
) to High(FKeys
) do
5771 FKeys
[a
].Pressed
:= False;
5776 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5780 function TPlayer
.firediry(): Integer;
5782 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5783 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5787 procedure TPlayer
.RememberState();
5791 FSavedState
.Health
:= FHealth
;
5792 FSavedState
.Armor
:= FArmor
;
5793 FSavedState
.Air
:= FAir
;
5794 FSavedState
.JetFuel
:= FJetFuel
;
5795 FSavedState
.CurrWeap
:= FCurrWeap
;
5796 FSavedState
.NextWeap
:= FNextWeap
;
5797 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5800 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5802 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5804 FSavedState
.Rulez
:= FRulez
;
5805 FSavedState
.WaitRecall
:= True;
5808 procedure TPlayer
.RecallState();
5812 if not FSavedState
.WaitRecall
then Exit
;
5814 FHealth
:= FSavedState
.Health
;
5815 FArmor
:= FSavedState
.Armor
;
5816 FAir
:= FSavedState
.Air
;
5817 FJetFuel
:= FSavedState
.JetFuel
;
5818 FCurrWeap
:= FSavedState
.CurrWeap
;
5819 FNextWeap
:= FSavedState
.NextWeap
;
5820 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5823 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5825 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5827 FRulez
:= FSavedState
.Rulez
;
5828 FSavedState
.WaitRecall
:= False;
5830 if gGameSettings
.GameType
= GT_SERVER
then
5831 MH_SEND_PlayerStats(FUID
);
5834 procedure TPlayer
.SaveState (st
: TStream
);
5840 utils
.writeSign(st
, 'PLYR');
5841 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
5843 utils
.writeBool(st
, FIamBot
);
5845 utils
.writeInt(st
, Word(FUID
));
5847 utils
.writeStr(st
, FName
);
5849 utils
.writeInt(st
, Byte(FTeam
));
5851 utils
.writeBool(st
, FAlive
);
5852 // Èçðàñõîäîâàë ëè âñå æèçíè
5853 utils
.writeBool(st
, FNoRespawn
);
5855 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
5856 utils
.writeInt(st
, Byte(b
));
5858 utils
.writeInt(st
, LongInt(FHealth
));
5860 utils
.writeInt(st
, Byte(FLives
));
5862 utils
.writeInt(st
, LongInt(FArmor
));
5864 utils
.writeInt(st
, LongInt(FAir
));
5866 utils
.writeInt(st
, LongInt(FJetFuel
));
5868 utils
.writeInt(st
, LongInt(FPain
));
5870 utils
.writeInt(st
, LongInt(FKills
));
5872 utils
.writeInt(st
, LongInt(FMonsterKills
));
5874 utils
.writeInt(st
, LongInt(FFrags
));
5876 utils
.writeInt(st
, Byte(FFragCombo
));
5877 // Âðåìÿ ïîñëåäíåãî ôðàãà
5878 utils
.writeInt(st
, LongWord(FLastFrag
));
5880 utils
.writeInt(st
, LongInt(FDeath
));
5882 utils
.writeInt(st
, Byte(FFlag
));
5884 utils
.writeInt(st
, LongInt(FSecrets
));
5886 utils
.writeInt(st
, Byte(FCurrWeap
));
5888 utils
.writeInt(st
, Word(FNextWeap
));
5890 utils
.writeInt(st
, Byte(FNextWeapDelay
));
5891 // Âðåìÿ çàðÿäêè BFG
5892 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
5894 utils
.writeInt(st
, LongInt(FDamageBuffer
));
5895 // Ïîñëåäíèé óäàðèâøèé
5896 utils
.writeInt(st
, Word(FLastSpawnerUID
));
5897 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
5898 utils
.writeInt(st
, Byte(FLastHit
));
5900 Obj_SaveState(st
, @FObj
);
5901 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
5902 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
5903 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
5904 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
5906 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
5907 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
5908 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
5910 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
5911 // Íàëè÷èå êðàñíîãî êëþ÷à
5912 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
5913 // Íàëè÷èå çåëåíîãî êëþ÷à
5914 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
5915 // Íàëè÷èå ñèíåãî êëþ÷à
5916 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
5918 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
5919 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
5920 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
5921 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
5922 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
5924 utils
.writeStr(st
, FModel
.Name
);
5926 utils
.writeInt(st
, Byte(FColor
.R
));
5927 utils
.writeInt(st
, Byte(FColor
.G
));
5928 utils
.writeInt(st
, Byte(FColor
.B
));
5932 procedure TPlayer
.LoadState (st
: TStream
);
5941 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
5942 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
5944 FIamBot
:= utils
.readBool(st
);
5946 FUID
:= utils
.readWord(st
);
5948 str
:= utils
.readStr(st
);
5949 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
5951 FTeam
:= utils
.readByte(st
);
5953 FAlive
:= utils
.readBool(st
);
5954 // Èçðàñõîäîâàë ëè âñå æèçíè
5955 FNoRespawn
:= utils
.readBool(st
);
5957 b
:= utils
.readByte(st
);
5958 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
5960 FHealth
:= utils
.readLongInt(st
);
5962 FLives
:= utils
.readByte(st
);
5964 FArmor
:= utils
.readLongInt(st
);
5966 FAir
:= utils
.readLongInt(st
);
5968 FJetFuel
:= utils
.readLongInt(st
);
5970 FPain
:= utils
.readLongInt(st
);
5972 FKills
:= utils
.readLongInt(st
);
5974 FMonsterKills
:= utils
.readLongInt(st
);
5976 FFrags
:= utils
.readLongInt(st
);
5978 FFragCombo
:= utils
.readByte(st
);
5979 // Âðåìÿ ïîñëåäíåãî ôðàãà
5980 FLastFrag
:= utils
.readLongWord(st
);
5982 FDeath
:= utils
.readLongInt(st
);
5984 FFlag
:= utils
.readByte(st
);
5986 FSecrets
:= utils
.readLongInt(st
);
5988 FCurrWeap
:= utils
.readByte(st
);
5990 FNextWeap
:= utils
.readWord(st
);
5992 FNextWeapDelay
:= utils
.readByte(st
);
5993 // Âðåìÿ çàðÿäêè BFG
5994 FBFGFireCounter
:= utils
.readSmallInt(st
);
5996 FDamageBuffer
:= utils
.readLongInt(st
);
5997 // Ïîñëåäíèé óäàðèâøèé
5998 FLastSpawnerUID
:= utils
.readWord(st
);
5999 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6000 FLastHit
:= utils
.readByte(st
);
6002 Obj_LoadState(@FObj
, st
);
6003 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6004 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
6005 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6006 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
6008 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
6009 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6010 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
6012 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
6013 // Íàëè÷èå êðàñíîãî êëþ÷à
6014 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
6015 // Íàëè÷èå çåëåíîãî êëþ÷à
6016 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
6017 // Íàëè÷èå ñèíåãî êëþ÷à
6018 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
6020 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
6021 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6022 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
6023 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6024 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
6026 str
:= utils
.readStr(st
);
6028 FColor
.R
:= utils
.readByte(st
);
6029 FColor
.G
:= utils
.readByte(st
);
6030 FColor
.B
:= utils
.readByte(st
);
6031 if (self
= gPlayer1
) then
6033 str
:= gPlayer1Settings
.Model
;
6034 FColor
:= gPlayer1Settings
.Color
;
6036 else if (self
= gPlayer2
) then
6038 str
:= gPlayer2Settings
.Model
;
6039 FColor
:= gPlayer2Settings
.Color
;
6041 // Îáíîâëÿåì ìîäåëü èãðîêà
6043 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
6044 FModel
.Color
:= TEAMCOLOR
[FTeam
]
6046 FModel
.Color
:= FColor
;
6050 procedure TPlayer
.AllRulez(Health
: Boolean);
6056 FHealth
:= PLAYER_HP_LIMIT
;
6057 FArmor
:= PLAYER_AP_LIMIT
;
6061 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
6062 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
6063 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6066 procedure TPlayer
.RestoreHealthArmor();
6068 FHealth
:= PLAYER_HP_LIMIT
;
6069 FArmor
:= PLAYER_AP_LIMIT
;
6072 procedure TPlayer
.FragCombo();
6076 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6078 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6080 if FFragCombo
< 5 then
6082 Param
:= FUID
or (FFragCombo
shl 16);
6083 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6084 (FComboEvnt
<= High(gDelayedEvents
)) and
6085 gDelayedEvents
[FComboEvnt
].Pending
and
6086 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6087 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6089 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6090 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6093 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6101 procedure TPlayer
.GiveItem(ItemType
: Byte);
6105 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6107 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6111 if FAir
< AIR_MAX
then
6118 if not (R_BERSERK
in FRulez
) then
6120 Include(FRulez
, R_BERSERK
);
6121 if FBFGFireCounter
< 1 then
6123 FCurrWeap
:= WEAPON_KASTET
;
6125 FModel
.SetWeapon(WEAPON_KASTET
);
6129 FBerserk
:= gTime
+30000;
6131 if FHealth
< PLAYER_HP_SOFT
then
6133 FHealth
:= PLAYER_HP_SOFT
;
6134 FBerserk
:= gTime
+30000;
6139 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6141 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6145 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6147 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6151 if FJetFuel
< JET_MAX
then
6153 FJetFuel
:= JET_MAX
;
6156 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6157 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6159 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6160 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6162 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6164 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6166 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6167 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6170 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6171 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6172 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6173 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6174 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6175 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6176 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6177 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6178 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6180 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6181 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6182 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6183 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6184 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6185 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6186 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6187 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6188 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6191 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6192 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6193 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6194 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6195 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6197 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6198 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6199 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6200 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6201 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6203 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6204 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6205 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6206 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6208 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6211 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6212 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6213 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6215 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6216 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6221 if g_Game_IsNet
and g_Game_IsServer
then
6222 MH_SEND_PlayerStats(FUID
);
6225 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6230 if (Random(5) = 1) and (Times
= 1) then
6233 if BodyInLiquid(0, 0) then
6235 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6236 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6237 if Random(2) = 0 then
6238 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6240 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6244 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6246 for i
:= 1 to Times
do
6248 Anim
:= TAnimation
.Create(id
, False, 3);
6250 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6251 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6257 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6262 if (Random(10) = 1) and (Times
= 1) then
6265 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6267 for i
:= 1 to Times
do
6269 Anim
:= TAnimation
.Create(id
, False, 3);
6271 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6272 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6278 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6280 FSawSound
.Pause(Enable
);
6281 FSawSoundIdle
.Pause(Enable
);
6282 FSawSoundHit
.Pause(Enable
);
6283 FSawSoundSelect
.Pause(Enable
);
6288 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6293 FObj
.Rect
:= PLAYER_CORPSERECT
;
6294 FModelName
:= ModelName
;
6299 FState
:= CORPSE_STATE_MESS
;
6300 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6304 FState
:= CORPSE_STATE_NORMAL
;
6305 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6309 destructor TCorpse
.Destroy();
6316 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6318 procedure TCorpse
.positionChanged (); inline; begin end;
6320 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6322 if (dx
<> 0) or (dy
<> 0) then
6331 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6333 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6334 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6335 w
:= PLAYER_CORPSERECT
.Width
;
6336 h
:= PLAYER_CORPSERECT
.Height
;
6340 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6345 if FState
= CORPSE_STATE_REMOVEME
then
6348 FDamage
:= FDamage
+ Value
;
6350 if FDamage
> 150 then
6352 if FAnimation
<> nil then
6357 FState
:= CORPSE_STATE_REMOVEME
;
6359 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6360 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6361 FModelName
, FColor
);
6362 // Çâóê ìÿñà îò òðóïà:
6363 pm
:= g_PlayerModel_Get(FModelName
);
6364 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6368 if (gBodyKillEvent
<> -1)
6369 and gDelayedEvents
[gBodyKillEvent
].Pending
then
6370 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
6371 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, 0);
6376 Blood
:= g_PlayerModel_GetBlood(FModelName
);
6377 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6378 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6379 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6380 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6381 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6382 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
6386 procedure TCorpse
.Draw();
6388 if FState
= CORPSE_STATE_REMOVEME
then
6391 if FAnimation
<> nil then
6392 FAnimation
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6394 if FAnimationMask
<> nil then
6397 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6404 procedure TCorpse
.Update();
6408 if FState
= CORPSE_STATE_REMOVEME
then
6411 if gTime
mod (GAME_TICK
*2) <> 0 then
6413 g_Obj_Move(@FObj
, True, True, True);
6414 positionChanged(); // this updates spatial accelerators
6418 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6419 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6421 st
:= g_Obj_Move(@FObj
, True, True, True);
6422 positionChanged(); // this updates spatial accelerators
6424 if WordBool(st
and MOVE_FALLOUT
) then
6426 FState
:= CORPSE_STATE_REMOVEME
;
6430 if FAnimation
<> nil then
6431 FAnimation
.Update();
6432 if FAnimationMask
<> nil then
6433 FAnimationMask
.Update();
6437 procedure TCorpse
.SaveState (st
: TStream
);
6444 utils
.writeSign(st
, 'CORP');
6445 utils
.writeInt(st
, Byte(0));
6447 utils
.writeInt(st
, Byte(FState
));
6449 utils
.writeInt(st
, Byte(FDamage
));
6451 utils
.writeInt(st
, Byte(FColor
.R
));
6452 utils
.writeInt(st
, Byte(FColor
.G
));
6453 utils
.writeInt(st
, Byte(FColor
.B
));
6455 Obj_SaveState(st
, @FObj
);
6456 utils
.writeInt(st
, Word(FPlayerUID
));
6458 anim
:= (FAnimation
<> nil);
6459 utils
.writeBool(st
, anim
);
6460 // Åñëè åñòü - ñîõðàíÿåì
6461 if anim
then FAnimation
.SaveState(st
);
6462 // Åñòü ëè ìàñêà àíèìàöèè
6463 anim
:= (FAnimationMask
<> nil);
6464 utils
.writeBool(st
, anim
);
6465 // Åñëè åñòü - ñîõðàíÿåì
6466 if anim
then FAnimationMask
.SaveState(st
);
6470 procedure TCorpse
.LoadState (st
: TStream
);
6477 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6478 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6480 FState
:= utils
.readByte(st
);
6482 FDamage
:= utils
.readByte(st
);
6484 FColor
.R
:= utils
.readByte(st
);
6485 FColor
.G
:= utils
.readByte(st
);
6486 FColor
.B
:= utils
.readByte(st
);
6488 Obj_LoadState(@FObj
, st
);
6489 FPlayerUID
:= utils
.readWord(st
);
6491 anim
:= utils
.readBool(st
);
6492 // Åñëè åñòü - çàãðóæàåì
6495 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6496 FAnimation
.LoadState(st
);
6498 // Åñòü ëè ìàñêà àíèìàöèè
6499 anim
:= utils
.readBool(st
);
6500 // Åñëè åñòü - çàãðóæàåì
6503 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6504 FAnimationMask
.LoadState(st
);
6510 constructor TBot
.Create();
6517 FSpectator
:= False;
6524 for a
:= WP_FIRST
to WP_LAST
do
6526 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6527 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6528 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6532 destructor TBot
.Destroy();
6535 inherited Destroy();
6538 procedure TBot
.Draw();
6542 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6543 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6546 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6548 inherited Respawn(Silent
, Force
);
6551 FSelectedWeapon
:= FCurrWeap
;
6556 procedure TBot
.UpdateCombat();
6569 TTargetRecord
= array of TTarget
;
6571 function Compare(a
, b
: TTarget
): Integer;
6573 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6576 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6578 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6579 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6581 if a
.Dist
> b
.Dist
then // B áëèæå
6583 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6586 else // Ñòðàííî -> A
6591 a
, x1
, y1
, x2
, y2
: Integer;
6592 targets
: TTargetRecord
;
6594 Target
, BestTarget
: TTarget
;
6595 firew
, fireh
: Integer;
6599 vsPlayer
, vsMonster
, ok
: Boolean;
6602 function monsUpdate (mon
: TMonster
): Boolean;
6604 result
:= false; // don't stop
6605 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6607 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6609 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6610 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6612 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6613 if g_TraceVector(x1
, y1
, x2
, y2
) then
6615 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6616 SetLength(targets
, Length(targets
)+1);
6617 with targets
[High(targets
)] do
6624 Rect
:= mon
.Obj
.Rect
;
6625 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6626 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6627 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6636 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6637 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6639 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6640 if FCurrWeap
<> FSelectedWeapon
then
6643 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6644 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6646 RemoveAIFlag('NEEDFIRE');
6649 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6650 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6651 else PressKey(KEY_FIRE
);
6655 // Êîîðäèíàòû ñòâîëà:
6656 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6657 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6659 Target
.UID
:= FTargetUID
;
6662 if Target
.UID
<> 0 then
6663 begin // Öåëü åñòü - íàñòðàèâàåì
6664 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6667 tpla
:= g_Player_Get(Target
.UID
);
6671 if (@FObj
) <> nil then
6678 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6679 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6680 Target
.Rect
:= PLAYER_RECT
;
6681 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6682 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6683 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6684 Target
.IsPlayer
:= True;
6688 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6691 mon
:= g_Monsters_ByUID(Target
.UID
);
6694 Target
.X
:= mon
.Obj
.X
;
6695 Target
.Y
:= mon
.Obj
.Y
;
6697 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6698 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6699 Target
.Rect
:= mon
.Obj
.Rect
;
6700 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6701 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6702 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6703 Target
.IsPlayer
:= False;
6710 begin // Öåëè íåò - îáíóëÿåì
6715 Target
.Visible
:= False;
6716 Target
.Line
:= False;
6717 Target
.IsPlayer
:= False;
6722 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6723 if (not Target
.Line
) or (not Target
.Visible
) then
6727 for a
:= 0 to High(gPlayers
) do
6728 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6729 (gPlayers
[a
].FUID
<> FUID
) and
6730 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6731 (not gPlayers
[a
].NoTarget
) and
6732 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6734 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6735 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6738 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6739 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6741 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6742 if g_TraceVector(x1
, y1
, x2
, y2
) then
6744 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6745 SetLength(targets
, Length(targets
)+1);
6746 with targets
[High(targets
)] do
6748 UID
:= gPlayers
[a
].FUID
;
6749 X
:= gPlayers
[a
].FObj
.X
;
6750 Y
:= gPlayers
[a
].FObj
.Y
;
6753 Rect
:= PLAYER_RECT
;
6754 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6755 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6756 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6764 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6767 // Åñëè åñòü âîçìîæíûå öåëè:
6768 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6769 if targets
<> nil then
6771 // Âûáèðàåì íàèëó÷øóþ öåëü:
6772 BestTarget
:= targets
[0];
6773 if Length(targets
) > 1 then
6774 for a
:= 1 to High(targets
) do
6775 if Compare(BestTarget
, targets
[a
]) = 1 then
6776 BestTarget
:= targets
[a
];
6778 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6779 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6780 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6782 Target
:= BestTarget
;
6784 if (Healthy() = 3) or ((Healthy() = 2)) then
6785 begin // Åñëè çäîðîâû - äîãîíÿåì
6786 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6787 SetAIFlag('GORIGHT', '1');
6788 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6789 SetAIFlag('GOLEFT', '1');
6792 begin // Åñëè ïîáèòû - óáåãàåì
6793 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6794 SetAIFlag('GORIGHT', '1');
6795 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6796 SetAIFlag('GOLEFT', '1');
6799 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6800 SelectWeapon(Abs(x1
-Target
.cX
));
6805 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6806 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6807 if Target
.UID
<> 0 then
6809 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6810 Target
.Y
+ Target
.Rect
.Y
) then
6811 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6812 if (Healthy() = 3) or ((Healthy() = 2)) then
6813 begin // Åñëè çäîðîâû - äîãîíÿåì
6814 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6815 SetAIFlag('GORIGHT', '1');
6816 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6817 SetAIFlag('GOLEFT', '1');
6820 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6822 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6823 SetAIFlag('GORIGHT', '1');
6824 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6825 SetAIFlag('GOLEFT', '1');
6829 begin // Öåëü ïîêà íà "ýêðàíå"
6830 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6831 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6832 FLastVisible
:= gTime
;
6833 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6834 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6836 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6837 SetAIFlag('GORIGHT', '1');
6838 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6839 SetAIFlag('GOLEFT', '1');
6843 // Âûáèðàåì óãîë ââåðõ:
6844 if FDirection
= TDirection
.D_LEFT
then
6845 angle
:= ANGLE_LEFTUP
6847 angle
:= ANGLE_RIGHTUP
;
6849 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6850 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6852 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6853 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6854 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6855 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6856 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6857 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6858 begin // òî íóæíî ñòðåëÿòü ââåðõ
6859 SetAIFlag('NEEDFIRE', '1');
6860 SetAIFlag('NEEDSEEUP', '1');
6863 // Âûáèðàåì óãîë âíèç:
6864 if FDirection
= TDirection
.D_LEFT
then
6865 angle
:= ANGLE_LEFTDOWN
6867 angle
:= ANGLE_RIGHTDOWN
;
6869 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6870 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6872 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6873 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6874 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6875 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6876 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6877 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6878 begin // òî íóæíî ñòðåëÿòü âíèç
6879 SetAIFlag('NEEDFIRE', '1');
6880 SetAIFlag('NEEDSEEDOWN', '1');
6883 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6884 if Target
.Visible
and
6885 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6886 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6888 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6889 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
6890 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6891 begin // òî íóæíî ñòðåëÿòü âïåðåä
6892 SetAIFlag('NEEDFIRE', '1');
6893 SetAIFlag('NEEDSEEDOWN', '');
6894 SetAIFlag('NEEDSEEUP', '');
6896 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6897 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6898 if GetRnd(FDifficult
.CloseJump
) then
6899 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6900 if Abs(FObj
.X
-Target
.X
) < 128 then
6904 if Random(a
) = 0 then
6905 SetAIFlag('NEEDJUMP', '1');
6909 // Åñëè öåëü âñå åùå åñòü:
6910 if Target
.UID
<> 0 then
6911 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
6912 Target
.UID
:= 0 // òî çàáûòü öåëü
6913 else // Åñëè âèäåëè íåäàâíî
6914 begin // íî öåëü óáèëè
6915 if Target
.IsPlayer
then
6916 begin // Öåëü - èãðîê
6917 pla
:= g_Player_Get(Target
.UID
);
6918 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
6919 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6920 Target
.UID
:= 0; // òî çàáûòü öåëü
6923 begin // Öåëü - ìîíñòð
6924 mon
:= g_Monsters_ByUID(Target
.UID
);
6925 if (mon
= nil) or (not mon
.alive
) then
6926 Target
.UID
:= 0; // òî çàáûòü öåëü
6929 end; // if Target.UID <> 0
6931 FTargetUID
:= Target
.UID
;
6933 // Åñëè âîçìîæíûõ öåëåé íåò:
6934 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
6935 if targets
= nil then
6936 if GetAIFlag('ATTACKLEFT') <> '' then
6937 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
6938 RemoveAIFlag('ATTACKLEFT');
6940 SetAIFlag('NEEDJUMP', '1');
6942 if RunDirection() = TDirection
.D_RIGHT
then
6943 begin // Èäåì íå â òó ñòîðîíó
6944 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6945 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
6946 SetAIFlag('NEEDFIRE', '1');
6947 SetAIFlag('GOLEFT', '1');
6951 begin // Èäåì â íóæíóþ ñòîðîíó
6952 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6953 SetAIFlag('NEEDFIRE', '1');
6954 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6955 SetAIFlag('GORIGHT', '1');
6959 if GetAIFlag('ATTACKRIGHT') <> '' then
6960 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
6961 RemoveAIFlag('ATTACKRIGHT');
6963 SetAIFlag('NEEDJUMP', '1');
6965 if RunDirection() = TDirection
.D_LEFT
then
6966 begin // Èäåì íå â òó ñòîðîíó
6967 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6968 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
6969 SetAIFlag('NEEDFIRE', '1');
6970 SetAIFlag('GORIGHT', '1');
6975 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6976 SetAIFlag('NEEDFIRE', '1');
6977 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6978 SetAIFlag('GOLEFT', '1');
6982 //HACK! (does it belongs there?)
6983 RealizeCurrentWeapon();
6985 // Åñëè åñòü âîçìîæíûå öåëè:
6986 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
6987 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6988 for a
:= 0 to High(targets
) do
6990 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
6991 if GetRnd(FDifficult
.DiagFire
) then
6993 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
6994 if FDirection
= TDirection
.D_LEFT
then
6995 angle
:= ANGLE_LEFTUP
6997 angle
:= ANGLE_RIGHTUP
;
6999 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7000 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7002 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7003 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7004 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7005 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7006 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7008 SetAIFlag('NEEDFIRE', '1');
7009 SetAIFlag('NEEDSEEUP', '1');
7012 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7013 if FDirection
= TDirection
.D_LEFT
then
7014 angle
:= ANGLE_LEFTDOWN
7016 angle
:= ANGLE_RIGHTDOWN
;
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('NEEDSEEDOWN', '1');
7032 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7033 if targets
[a
].Line
and targets
[a
].Visible
and
7034 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
7035 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
7037 SetAIFlag('NEEDFIRE', '1');
7042 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7043 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
7044 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
7045 40+GetInterval(FDifficult
.Cover
, 40)) then
7046 SetAIFlag('NEEDJUMP', '1');
7048 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7049 ammo
:= GetAmmoByWeapon(FCurrWeap
);
7050 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
7051 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
7053 SetAIFlag('SELECTWEAPON', '1');
7055 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7056 if GetAIFlag('SELECTWEAPON') = '1' then
7059 RemoveAIFlag('SELECTWEAPON');
7063 procedure TBot
.Update();
7076 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7077 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7079 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7081 if g_debug_BotAIOff
= 3 then
7091 RealizeCurrentWeapon();
7098 procedure TBot
.ReleaseKey(Key
: Byte);
7107 function TBot
.KeyPressed(Key
: Word): Boolean;
7109 Result
:= FKeys
[Key
].Pressed
;
7112 function TBot
.GetAIFlag(aName
: String20
): String20
;
7118 aName
:= LowerCase(aName
);
7120 if FAIFlags
<> nil then
7121 for a
:= 0 to High(FAIFlags
) do
7122 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7124 Result
:= FAIFlags
[a
].Value
;
7129 procedure TBot
.RemoveAIFlag(aName
: String20
);
7133 if FAIFlags
= nil then Exit
;
7135 aName
:= LowerCase(aName
);
7137 for a
:= 0 to High(FAIFlags
) do
7138 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7140 if a
<> High(FAIFlags
) then
7141 for b
:= a
to High(FAIFlags
)-1 do
7142 FAIFlags
[b
] := FAIFlags
[b
+1];
7144 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7149 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7157 aName
:= LowerCase(aName
);
7159 if FAIFlags
<> nil then
7160 for a
:= 0 to High(FAIFlags
) do
7161 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7167 if ok
then FAIFlags
[a
].Value
:= fValue
7170 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7171 with FAIFlags
[High(FAIFlags
)] do
7179 procedure TBot
.UpdateMove
;
7181 procedure GoLeft(Time
: Word = 1);
7183 ReleaseKey(KEY_LEFT
);
7184 ReleaseKey(KEY_RIGHT
);
7185 PressKey(KEY_LEFT
, Time
);
7186 SetDirection(TDirection
.D_LEFT
);
7189 procedure GoRight(Time
: Word = 1);
7191 ReleaseKey(KEY_LEFT
);
7192 ReleaseKey(KEY_RIGHT
);
7193 PressKey(KEY_RIGHT
, Time
);
7194 SetDirection(TDirection
.D_RIGHT
);
7197 function Rnd(a
: Word): Boolean;
7199 Result
:= Random(a
) = 0;
7202 procedure Turn(Time
: Word = 1200);
7204 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7209 ReleaseKey(KEY_LEFT
);
7210 ReleaseKey(KEY_RIGHT
);
7213 function CanRunLeft(): Boolean;
7215 Result
:= not CollideLevel(-1, 0);
7218 function CanRunRight(): Boolean;
7220 Result
:= not CollideLevel(1, 0);
7223 function CanRun(): Boolean;
7225 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7228 procedure Jump(Time
: Word = 30);
7230 PressKey(KEY_JUMP
, Time
);
7233 function NearHole(): Boolean;
7237 { TODO 5 : Ëåñòíèöû }
7238 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7239 for x
:= 1 to PLAYER_RECT
.Width
do
7240 if (not StayOnStep(x
*sx
, 0)) and
7241 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7242 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7251 function BorderHole(): Boolean;
7255 { TODO 5 : Ëåñòíèöû }
7256 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7257 for x
:= 1 to PLAYER_RECT
.Width
do
7258 if (not StayOnStep(x
*sx
, 0)) and
7259 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7260 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7262 for xx
:= x
to x
+32 do
7263 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7273 function NearDeepHole(): Boolean;
7279 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7282 for x
:= 1 to PLAYER_RECT
.Width
do
7283 if (not StayOnStep(x
*sx
, 0)) and
7284 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7285 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7287 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7289 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7294 end else Result
:= False;
7297 function OverDeepHole(): Boolean;
7304 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7306 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7313 function OnGround(): Boolean;
7315 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7318 function OnLadder(): Boolean;
7320 Result
:= FullInStep(0, 0);
7323 function BelowLadder(): Boolean;
7325 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7326 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7327 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7328 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7331 function BelowLiftUp(): Boolean;
7333 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7334 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7335 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7336 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7339 function OnTopLift(): Boolean;
7341 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7344 function CanJumpOver(): Boolean;
7348 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7352 if not CollideLevel(sx
, 0) then Exit
;
7354 for y
:= 1 to BOT_MAXJUMP
do
7355 if CollideLevel(0, -y
) then Exit
else
7356 if not CollideLevel(sx
, -y
) then
7363 function CanJumpUp(Dist
: ShortInt): Boolean;
7370 if CollideLevel(Dist
, 0) then Exit
;
7373 for y
:= 0 to BOT_MAXJUMP
do
7374 if CollideLevel(Dist
, -y
) then
7383 for yy
:= y
+1 to BOT_MAXJUMP
do
7384 if not CollideLevel(Dist
, -yy
) then
7393 for y
:= 0 to BOT_MAXJUMP
do
7394 if CollideLevel(0, -y
) then
7402 if y
< yy
then Exit
;
7407 function IsSafeTrigger(): Boolean;
7412 if gTriggers
= nil then
7414 for a
:= 0 to High(gTriggers
) do
7415 if Collide(gTriggers
[a
].X
,
7418 gTriggers
[a
].Height
) and
7419 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7420 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7421 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7422 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7423 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7428 // Âîçìîæíî, íàæèìàåì êíîïêó:
7429 if Rnd(16) and IsSafeTrigger() then
7432 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7433 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7435 ReleaseKey(KEY_LEFT
);
7436 ReleaseKey(KEY_RIGHT
);
7440 // Èäåì âëåâî, åñëè íàäî áûëî:
7441 if GetAIFlag('GOLEFT') <> '' then
7443 RemoveAIFlag('GOLEFT');
7444 if CanRunLeft() then
7448 // Èäåì âïðàâî, åñëè íàäî áûëî:
7449 if GetAIFlag('GORIGHT') <> '' then
7451 RemoveAIFlag('GORIGHT');
7452 if CanRunRight() then
7456 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7457 if FObj
.X
< -32 then
7460 if FObj
.X
+32 > gMapInfo
.Width
then
7463 // Ïðûãàåì, åñëè íàäî áûëî:
7464 if GetAIFlag('NEEDJUMP') <> '' then
7467 RemoveAIFlag('NEEDJUMP');
7470 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7471 if GetAIFlag('NEEDSEEUP') <> '' then
7474 ReleaseKey(KEY_DOWN
);
7475 PressKey(KEY_UP
, 20);
7476 RemoveAIFlag('NEEDSEEUP');
7479 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7480 if GetAIFlag('NEEDSEEDOWN') <> '' then
7483 ReleaseKey(KEY_DOWN
);
7484 PressKey(KEY_DOWN
, 20);
7485 RemoveAIFlag('NEEDSEEDOWN');
7488 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7489 if GetAIFlag('GOINHOLE') <> '' then
7490 if not OnGround() then
7492 ReleaseKey(KEY_LEFT
);
7493 ReleaseKey(KEY_RIGHT
);
7494 RemoveAIFlag('GOINHOLE');
7495 SetAIFlag('FALLINHOLE', '1');
7498 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7499 if GetAIFlag('FALLINHOLE') <> '' then
7501 RemoveAIFlag('FALLINHOLE');
7503 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7504 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7505 if GetAIFlag('FALLINHOLE') = '' then
7506 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7512 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7514 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7518 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7519 if OnGround() and NearHole() then
7520 if NearDeepHole() then // Åñëè ýòî áåçäíà
7522 0..3: Turn(); // Áåæèì îáðàòíî
7523 4: Jump(); // Ïðûãàåì
7524 5: begin // Ïðûãàåì îáðàòíî
7529 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7530 if GetAIFlag('GOINHOLE') = '' then
7532 0: Turn(); // Íå íóæíî òóäà
7533 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7534 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7535 if BorderHole() then
7536 SetAIFlag('GOINHOLE', '1');
7539 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7540 if (not CanRun()) and OnGround() then
7542 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7543 if CanJumpOver() or OnLadder() then
7545 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7546 if Random(2) = 0 then
7548 if IsSafeTrigger() then
7554 // Îñòàëîñü ìàëî âîçäóõà:
7555 if FAir
< 36 * 2 then
7558 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7559 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7560 if BodyInAcid(0, 0) then
7564 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7566 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7567 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7570 {function TBot.NeedItem(Item: Byte): Byte;
7575 procedure TBot
.SelectWeapon(Dist
: Integer);
7579 function HaveAmmo(weapon
: Byte): Boolean;
7582 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7583 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7584 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7585 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7586 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7587 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7588 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7589 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7590 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7591 else Result
:= True;
7596 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7598 if Dist
> BOT_LONGDIST
then
7599 begin // Äàëüíèé áîé
7601 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7603 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7607 else //if Dist > BOT_UNSAFEDIST then
7608 begin // Áëèæíèé áîé
7610 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7612 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7619 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7621 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7627 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7629 Result
:= inherited PickItem(ItemType
, force
, remove
);
7631 if Result
then SetAIFlag('SELECTWEAPON', '1');
7634 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7636 Result
:= inherited Heal(value
, Soft
);
7639 function TBot
.Healthy(): Byte;
7641 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7642 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7643 else if (FHealth
> 50) then Result
:= 2
7644 else if (FHealth
> 20) then Result
:= 1
7648 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7650 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7651 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7654 procedure TBot
.OnDamage(Angle
: SmallInt);
7662 if (Angle
= 0) or (Angle
= 180) then
7665 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7666 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7668 pla
:= g_Player_Get(FLastSpawnerUID
);
7669 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7670 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7673 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7674 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7676 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7677 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7678 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7683 SetAIFlag('ATTACKLEFT', '1')
7685 SetAIFlag('ATTACKRIGHT', '1');
7689 function TBot
.RunDirection(): TDirection
;
7691 if Abs(Vel
.X
) >= 1 then
7693 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7695 Result
:= FDirection
;
7698 function TBot
.GetRnd(a
: Byte): Boolean;
7700 if a
= 0 then Result
:= False
7701 else if a
= 255 then Result
:= True
7702 else Result
:= Random(256) > 255-a
;
7705 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7707 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7711 procedure TDifficult
.save (st
: TStream
);
7713 utils
.writeInt(st
, Byte(DiagFire
));
7714 utils
.writeInt(st
, Byte(InvisFire
));
7715 utils
.writeInt(st
, Byte(DiagPrecision
));
7716 utils
.writeInt(st
, Byte(FlyPrecision
));
7717 utils
.writeInt(st
, Byte(Cover
));
7718 utils
.writeInt(st
, Byte(CloseJump
));
7719 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7720 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7723 procedure TDifficult
.load (st
: TStream
);
7725 DiagFire
:= utils
.readByte(st
);
7726 InvisFire
:= utils
.readByte(st
);
7727 DiagPrecision
:= utils
.readByte(st
);
7728 FlyPrecision
:= utils
.readByte(st
);
7729 Cover
:= utils
.readByte(st
);
7730 CloseJump
:= utils
.readByte(st
);
7731 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7732 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7736 procedure TBot
.SaveState (st
: TStream
);
7741 inherited SaveState(st
);
7742 utils
.writeSign(st
, 'BOT0');
7744 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7746 utils
.writeInt(st
, Word(FTargetUID
));
7747 // Âðåìÿ ïîòåðè öåëè
7748 utils
.writeInt(st
, LongWord(FLastVisible
));
7749 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7750 dw
:= Length(FAIFlags
);
7751 utils
.writeInt(st
, LongInt(dw
));
7753 for i
:= 0 to dw
-1 do
7755 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7756 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7758 // Íàñòðîéêè ñëîæíîñòè
7759 FDifficult
.save(st
);
7763 procedure TBot
.LoadState (st
: TStream
);
7768 inherited LoadState(st
);
7769 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7771 FSelectedWeapon
:= utils
.readByte(st
);
7773 FTargetUID
:= utils
.readWord(st
);
7774 // Âðåìÿ ïîòåðè öåëè
7775 FLastVisible
:= utils
.readLongWord(st
);
7776 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7777 dw
:= utils
.readLongInt(st
);
7778 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7779 SetLength(FAIFlags
, dw
);
7781 for i
:= 0 to dw
-1 do
7783 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7784 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7786 // Íàñòðîéêè ñëîæíîñòè
7787 FDifficult
.load(st
);
7792 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);