1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
24 {$IFDEF USE_MEMPOOL}mempool
,{$ENDIF}
25 e_graphics
, g_playermodel
, g_basic
, g_textures
,
26 g_weapons
, g_phys
, g_sound
, g_saveload
, MAPDEF
,
59 AmmoLimits
: Array [0..1] of Array [A_BULLETS
..A_HIGH
] of Word =
60 ((200, 50, 50, 300, 100),
61 (400, 100, 100, 600, 200));
82 ANGLE_NONE
= Low(SmallInt);
84 CORPSE_STATE_REMOVEME
= 0;
85 CORPSE_STATE_NORMAL
= 1;
86 CORPSE_STATE_MESS
= 2;
88 PLAYER_RECT
: TRectWH
= (X
:15; Y
:12; Width
:34; Height
:52);
89 PLAYER_RECT_CX
= 15+(34 div 2);
90 PLAYER_RECT_CY
= 12+(52 div 2);
91 PLAYER_CORPSERECT
: TRectWH
= (X
:15; Y
:48; Width
:34; Height
:16);
94 PLAYER_HP_LIMIT
= 200;
96 PLAYER_AP_LIMIT
= 200;
99 PLAYER1_DEF_COLOR
: TRGB
= (R
:64; G
:175; B
:48);
100 PLAYER2_DEF_COLOR
: TRGB
= (R
:96; G
:96; B
:96);
116 TPlayerStatArray
= Array of TPlayerStat
;
118 TPlayerSavedState
= record
126 Ammo
: Array [A_BULLETS
..A_HIGH
] of Word;
127 MaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
128 Weapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
129 Rulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
138 TPlayer
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
146 FDirection
: TDirection
;
154 FMonsterKills
: Integer;
160 FCanJetpack
: Boolean;
166 FNextWeapDelay
: Byte; // frames
167 FBFGFireCounter
: SmallInt;
168 FLastSpawnerUID
: Word;
172 FSpectatePlayer
: Integer;
173 FFirePainTime
: Integer;
176 FSavedState
: TPlayerSavedState
;
178 FModel
: TPlayerModel
;
179 FPunchAnim
: TAnimation
;
182 FActionForce
: Boolean;
183 FActionChanged
: Boolean;
185 FFireAngle
: SmallInt;
187 FShellTimer
: Integer;
189 FSawSound
: TPlayableSound
;
190 FSawSoundIdle
: TPlayableSound
;
191 FSawSoundHit
: TPlayableSound
;
192 FSawSoundSelect
: TPlayableSound
;
193 FJetSoundOn
: TPlayableSound
;
194 FJetSoundOff
: TPlayableSound
;
195 FJetSoundFly
: TPlayableSound
;
199 FJustTeleported
: Boolean;
201 mEDamageType
: Integer;
204 function CollideLevel(XInc
, YInc
: Integer): Boolean;
205 function StayOnStep(XInc
, YInc
: Integer): Boolean;
206 function HeadInLiquid(XInc
, YInc
: Integer): Boolean;
207 function BodyInLiquid(XInc
, YInc
: Integer): Boolean;
208 function BodyInAcid(XInc
, YInc
: Integer): Boolean;
209 function FullInLift(XInc
, YInc
: Integer): Integer;
210 {procedure CollideItem();}
211 procedure FlySmoke(Times
: DWORD
= 1);
212 procedure OnFireFlame(Times
: DWORD
= 1);
213 function GetAmmoByWeapon(Weapon
: Byte): Word;
214 procedure SetAction(Action
: Byte; Force
: Boolean = False);
215 procedure OnDamage(Angle
: SmallInt); virtual;
216 function firediry(): Integer;
219 procedure Run(Direction
: TDirection
);
220 procedure NextWeapon();
221 procedure PrevWeapon();
228 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
229 procedure resetWeaponQueue ();
230 function hasAmmoForWeapon (weapon
: Byte): Boolean;
232 procedure doDamage (v
: Integer);
234 function followCorpse(): Boolean;
237 FDamageBuffer
: Integer;
239 FAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
240 FMaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
241 FWeapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
242 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
244 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
245 FReloading
: Array [WP_FIRST
..WP_LAST
] of Word;
246 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
247 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
249 FPreferredTeam
: Byte;
252 FWantsInGame
: Boolean;
256 FActualModelName
: string;
263 // debug: viewport offset
264 viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer;
266 function isValidViewPort (): Boolean; inline;
268 constructor Create(); virtual;
269 destructor Destroy(); override;
270 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
271 function GetRespawnPoint(): Byte;
272 procedure PressKey(Key
: Byte; Time
: Word = 1);
273 procedure ReleaseKeys();
274 procedure SetModel(ModelName
: String);
275 procedure SetColor(Color
: TRGB
);
276 procedure SetWeapon(W
: Byte);
277 function IsKeyPressed(K
: Byte): Boolean;
278 function GetKeys(): Byte;
279 function PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean; virtual;
280 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
281 function Collide(Panel
: TPanel
): Boolean; overload
;
282 function Collide(X
, Y
: Integer): Boolean; overload
;
283 procedure SetDirection(Direction
: TDirection
);
284 procedure GetSecret();
285 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
287 procedure Push(vx
, vy
: Integer);
288 procedure ChangeModel(ModelName
: String);
289 procedure SwitchTeam
;
290 procedure ChangeTeam(Team
: Byte);
292 function GetFlag(Flag
: Byte): Boolean;
293 procedure SetFlag(Flag
: Byte);
294 function DropFlag(): Boolean;
295 procedure AllRulez(Health
: Boolean);
296 procedure RestoreHealthArmor();
297 procedure FragCombo();
298 procedure GiveItem(ItemType
: Byte);
299 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
300 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
301 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
302 procedure MakeBloodSimple(Count
: Word);
303 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
304 procedure Reset(Force
: Boolean);
305 procedure Spectate(NoMove
: Boolean = False);
306 procedure SwitchNoClip
;
307 procedure SoftReset();
308 procedure Draw(); virtual;
309 procedure DrawPain();
310 procedure DrawPickup();
311 procedure DrawRulez();
313 procedure DrawIndicator();
314 procedure DrawBubble();
316 procedure Update(); virtual;
317 procedure RememberState();
318 procedure RecallState();
319 procedure SaveState (st
: TStream
); virtual;
320 procedure LoadState (st
: TStream
); virtual;
321 procedure PauseSounds(Enable
: Boolean);
322 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
323 procedure DoLerp(Level
: Integer = 2);
324 procedure SetLerp(XTo
, YTo
: Integer);
325 procedure QueueWeaponSwitch(Weapon
: Byte);
326 procedure RealizeCurrentWeapon();
328 procedure JetpackOff
;
329 procedure CatchFire(Attacker
: Word);
331 //WARNING! this does nothing for now, but still call it!
332 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
334 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
335 procedure moveBy (dx
, dy
: Integer); inline;
338 property Vel
: TPoint2i read FObj
.Vel
;
339 property Obj
: TObj read FObj
;
341 property Name
: String read FName write FName
;
342 property Model
: TPlayerModel read FModel
;
343 property Health
: Integer read FHealth write FHealth
;
344 property Lives
: Byte read FLives write FLives
;
345 property Armor
: Integer read FArmor write FArmor
;
346 property Air
: Integer read FAir write FAir
;
347 property JetFuel
: Integer read FJetFuel write FJetFuel
;
348 property Frags
: Integer read FFrags write FFrags
;
349 property Death
: Integer read FDeath write FDeath
;
350 property Kills
: Integer read FKills write FKills
;
351 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
352 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
353 property Secrets
: Integer read FSecrets
;
354 property GodMode
: Boolean read FGodMode write FGodMode
;
355 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
356 property NoReload
: Boolean read FNoReload write FNoReload
;
357 property alive
: Boolean read FAlive write FAlive
;
358 property Flag
: Byte read FFlag
;
359 property Team
: Byte read FTeam write FTeam
;
360 property Direction
: TDirection read FDirection
;
361 property GameX
: Integer read FObj
.X write FObj
.X
;
362 property GameY
: Integer read FObj
.Y write FObj
.Y
;
363 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
364 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
365 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
366 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
367 property IncCam
: Integer read FIncCam write FIncCam
;
368 property UID
: Word read FUID write FUID
;
369 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
370 property NetTime
: LongWord read FNetTime write FNetTime
;
373 property eName
: String read FName write FName
;
374 property eHealth
: Integer read FHealth write FHealth
;
375 property eLives
: Byte read FLives write FLives
;
376 property eArmor
: Integer read FArmor write FArmor
;
377 property eAir
: Integer read FAir write FAir
;
378 property eJetFuel
: Integer read FJetFuel write FJetFuel
;
379 property eFrags
: Integer read FFrags write FFrags
;
380 property eDeath
: Integer read FDeath write FDeath
;
381 property eKills
: Integer read FKills write FKills
;
382 property eCurrWeap
: Byte read FCurrWeap write FCurrWeap
;
383 property eMonsterKills
: Integer read FMonsterKills write FMonsterKills
;
384 property eSecrets
: Integer read FSecrets write FSecrets
;
385 property eGodMode
: Boolean read FGodMode write FGodMode
;
386 property eNoTarget
: Boolean read FNoTarget write FNoTarget
;
387 property eNoReload
: Boolean read FNoReload write FNoReload
;
388 property eAlive
: Boolean read FAlive write FAlive
;
389 property eFlag
: Byte read FFlag
;
390 property eTeam
: Byte read FTeam write FTeam
;
391 property eDirection
: TDirection read FDirection
;
392 property eGameX
: Integer read FObj
.X write FObj
.X
;
393 property eGameY
: Integer read FObj
.Y write FObj
.Y
;
394 property eGameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
395 property eGameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
396 property eGameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
397 property eGameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
398 property eIncCam
: Integer read FIncCam write FIncCam
;
399 property eUID
: Word read FUID
;
400 property eJustTeleported
: Boolean read FJustTeleported
;
401 property eNetTime
: LongWord read FNetTime
;
403 // set this before assigning something to `eDamage`
404 property eDamageType
: Integer read mEDamageType write mEDamageType
;
405 property eDamage
: Integer write doDamage
;
416 WeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
417 CloseWeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
418 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
421 procedure save (st
: TStream
);
422 procedure load (st
: TStream
);
430 TBot
= class(TPlayer
)
432 FSelectedWeapon
: Byte;
435 FAIFlags
: Array of TAIFlag
;
436 FDifficult
: TDifficult
;
438 function GetRnd(a
: Byte): Boolean;
439 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
440 function RunDirection(): TDirection
;
441 function FullInStep(XInc
, YInc
: Integer): Boolean;
442 //function NeedItem(Item: Byte): Byte;
443 procedure SelectWeapon(Dist
: Integer);
444 procedure SetAIFlag(aName
, fValue
: String20
);
445 function GetAIFlag(aName
: String20
): String20
;
446 procedure RemoveAIFlag(aName
: String20
);
447 function Healthy(): Byte;
448 procedure UpdateMove();
449 procedure UpdateCombat();
450 function KeyPressed(Key
: Word): Boolean;
451 procedure ReleaseKey(Key
: Byte);
452 function TargetOnScreen(TX
, TY
: Integer): Boolean;
453 procedure OnDamage(Angle
: SmallInt); override;
456 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
457 constructor Create(); override;
458 destructor Destroy(); override;
459 procedure Draw(); override;
460 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
461 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
462 procedure Update(); override;
463 procedure SaveState (st
: TStream
); override;
464 procedure LoadState (st
: TStream
); override;
476 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
477 procedure moveBy (dx
, dy
: Integer); inline;
479 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
493 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
494 procedure moveBy (dx
, dy
: Integer); inline;
496 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
499 TCorpse
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
508 FAnimation
: TAnimation
;
509 FAnimationMask
: TAnimation
;
512 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
513 destructor Destroy(); override;
514 procedure Damage(Value
: Word; vx
, vy
: Integer);
517 procedure SaveState (st
: TStream
);
518 procedure LoadState (st
: TStream
);
520 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
521 procedure moveBy (dx
, dy
: Integer); inline;
523 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
525 function ObjPtr (): PObj
; inline;
527 property Obj
: TObj read FObj
; // copies object
528 property State
: Byte read FState
;
529 property Mess
: Boolean read FMess
;
532 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
538 gPlayers
: Array of TPlayer
;
539 gCorpses
: Array of TCorpse
;
540 gGibs
: Array of TGib
;
541 gShells
: Array of TShell
;
542 gTeamStat
: TTeamStat
;
543 gFly
: Boolean = False;
544 gAimLine
: Boolean = False;
545 gChatBubble
: Byte = 0;
546 gPlayerIndicator
: Boolean = True;
550 MAX_RUNVEL
: Integer = 8;
551 VEL_JUMP
: Integer = 10;
552 SHELL_TIMEOUT
: Cardinal = 60000;
554 function Lerp(X
, Y
, Factor
: Integer): Integer;
556 procedure g_Gibs_SetMax(Count
: Word);
557 function g_Gibs_GetMax(): Word;
558 procedure g_Corpses_SetMax(Count
: Word);
559 function g_Corpses_GetMax(): Word;
560 procedure g_Shells_SetMax(Count
: Word);
561 function g_Shells_GetMax(): Word;
563 procedure g_Player_Init();
564 procedure g_Player_Free();
565 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
566 function g_Player_CreateFromState (st
: TStream
): Word;
567 procedure g_Player_Remove(UID
: Word);
568 procedure g_Player_ResetTeams();
569 procedure g_Player_UpdateAll();
570 procedure g_Player_DrawAll();
571 procedure g_Player_DrawDebug(p
: TPlayer
);
572 procedure g_Player_DrawHealth();
573 procedure g_Player_RememberAll();
574 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
575 function g_Player_Get(UID
: Word): TPlayer
;
576 function g_Player_GetCount(): Byte;
577 function g_Player_GetStats(): TPlayerStatArray
;
578 function g_Player_ValidName(Name
: String): Boolean;
579 procedure g_Player_CreateCorpse(Player
: TPlayer
);
580 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
581 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
582 procedure g_Player_UpdatePhysicalObjects();
583 procedure g_Player_DrawCorpses();
584 procedure g_Player_DrawShells();
585 procedure g_Player_RemoveAllCorpses();
586 procedure g_Player_Corpses_SaveState (st
: TStream
);
587 procedure g_Player_Corpses_LoadState (st
: TStream
);
588 procedure g_Bot_Add(Team
, Difficult
: Byte);
589 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1);
590 procedure g_Bot_MixNames();
591 procedure g_Bot_RemoveAll();
596 {$INCLUDE ../nogl/noGLuses.inc}
597 {$IFDEF ENABLE_HOLMES}
600 e_log
, g_map
, g_items
, g_console
, g_gfx
, Math
,
601 g_options
, g_triggers
, g_menu
, g_game
, g_grid
,
602 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
,
603 g_net
, g_netmsg
, g_window
,
606 const PLR_SAVE_VERSION
= 0;
616 diag_precision
: Byte;
620 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
621 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
622 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
626 TIME_RESPAWN1
= 1500;
627 TIME_RESPAWN2
= 2000;
628 TIME_RESPAWN3
= 3000;
631 JET_MAX
= 540; // ~30 sec
632 PLAYER_SUIT_TIME
= 30000;
633 PLAYER_INVUL_TIME
= 30000;
634 PLAYER_INVIS_TIME
= 35000;
635 FRAG_COMBO_TIME
= 3000;
639 ANGLE_RIGHTDOWN
= -35;
641 ANGLE_LEFTDOWN
= -145;
642 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
643 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
646 BOT_UNSAFEDIST
= 128;
647 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
649 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
650 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
651 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
652 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
653 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
654 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
655 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
656 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
657 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
658 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
659 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
660 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
661 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
662 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
663 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
664 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
665 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
666 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
667 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
668 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
669 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
670 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
671 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
672 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
673 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
674 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
676 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
677 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
679 BOTNAMES_FILENAME
= 'botnames.txt';
680 BOTLIST_FILENAME
= 'botlist.txt';
684 MaxCorpses
: Word = 20;
685 MaxShells
: Word = 300;
686 CurrentGib
: Integer = 0;
687 CurrentShell
: Integer = 0;
688 BotNames
: Array of String;
689 BotList
: Array of TBotProfile
;
692 function Lerp(X
, Y
, Factor
: Integer): Integer;
694 Result
:= X
+ ((Y
- X
) div Factor
);
697 function SameTeam(UID1
, UID2
: Word): Boolean;
701 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
702 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
704 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
706 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
707 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
709 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
712 procedure g_Gibs_SetMax(Count
: Word);
715 SetLength(gGibs
, Count
);
717 if CurrentGib
>= Count
then
721 function g_Gibs_GetMax(): Word;
726 procedure g_Shells_SetMax(Count
: Word);
729 SetLength(gShells
, Count
);
731 if CurrentShell
>= Count
then
735 function g_Shells_GetMax(): Word;
741 procedure g_Corpses_SetMax(Count
: Word);
744 SetLength(gCorpses
, Count
);
747 function g_Corpses_GetMax(): Word;
749 Result
:= MaxCorpses
;
752 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
762 // Åñòü ëè ìåñòî â gPlayers:
763 if gPlayers
<> nil then
764 for a
:= 0 to High(gPlayers
) do
765 if gPlayers
[a
] = nil then
771 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
774 SetLength(gPlayers
, Length(gPlayers
)+1);
778 // Ñîçäàåì îáúåêò èãðîêà:
780 gPlayers
[a
] := TBot
.Create()
782 gPlayers
[a
] := TPlayer
.Create();
785 gPlayers
[a
].FActualModelName
:= ModelName
;
786 gPlayers
[a
].SetModel(ModelName
);
788 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
789 if gPlayers
[a
].FModel
= nil then
793 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
797 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
798 if Random(2) = 0 then
802 gPlayers
[a
].FPreferredTeam
:= Team
;
804 case gGameSettings
.GameMode
of
805 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
807 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
809 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
812 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
813 gPlayers
[a
].FColor
:= Color
;
814 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
815 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
817 gPlayers
[a
].FModel
.Color
:= Color
;
819 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
820 gPlayers
[a
].FAlive
:= False;
822 Result
:= gPlayers
[a
].FUID
;
825 function g_Player_CreateFromState (st
: TStream
): Word;
832 if (st
= nil) then exit
; //???
835 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
836 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
839 Bot
:= utils
.readBool(st
);
844 // Åñòü ëè ìåñòî â gPlayers:
845 for a
:= 0 to High(gPlayers
) do if (gPlayers
[a
] = nil) then begin ok
:= true; break
; end;
847 // Íåò ìåñòà - ðàñøèðÿåì gPlayers
850 SetLength(gPlayers
, Length(gPlayers
)+1);
854 // Ñîçäàåì îáúåêò èãðîêà
856 gPlayers
[a
] := TBot
.Create()
858 gPlayers
[a
] := TPlayer
.Create();
859 gPlayers
[a
].FIamBot
:= Bot
;
860 gPlayers
[a
].FPhysics
:= True;
863 gPlayers
[a
].FUID
:= utils
.readWord(st
);
865 gPlayers
[a
].FName
:= utils
.readStr(st
);
867 gPlayers
[a
].FTeam
:= utils
.readByte(st
);
868 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
870 gPlayers
[a
].FAlive
:= utils
.readBool(st
);
871 // Èçðàñõîäîâàë ëè âñå æèçíè
872 gPlayers
[a
].FNoRespawn
:= utils
.readBool(st
);
874 b
:= utils
.readByte(st
);
875 if b
= 1 then gPlayers
[a
].FDirection
:= TDirection
.D_LEFT
else gPlayers
[a
].FDirection
:= TDirection
.D_RIGHT
; // b = 2
877 gPlayers
[a
].FHealth
:= utils
.readLongInt(st
);
879 gPlayers
[a
].FLives
:= utils
.readByte(st
);
881 gPlayers
[a
].FArmor
:= utils
.readLongInt(st
);
883 gPlayers
[a
].FAir
:= utils
.readLongInt(st
);
885 gPlayers
[a
].FJetFuel
:= utils
.readLongInt(st
);
887 gPlayers
[a
].FPain
:= utils
.readLongInt(st
);
889 gPlayers
[a
].FKills
:= utils
.readLongInt(st
);
891 gPlayers
[a
].FMonsterKills
:= utils
.readLongInt(st
);
893 gPlayers
[a
].FFrags
:= utils
.readLongInt(st
);
895 gPlayers
[a
].FFragCombo
:= utils
.readByte(st
);
896 // Âðåìÿ ïîñëåäíåãî ôðàãà
897 gPlayers
[a
].FLastFrag
:= utils
.readLongWord(st
);
899 gPlayers
[a
].FDeath
:= utils
.readLongInt(st
);
901 gPlayers
[a
].FFlag
:= utils
.readByte(st
);
903 gPlayers
[a
].FSecrets
:= utils
.readLongInt(st
);
905 gPlayers
[a
].FCurrWeap
:= utils
.readByte(st
);
906 // Ñëåäóþùåå æåëàåìîå îðóæèå
907 gPlayers
[a
].FNextWeap
:= utils
.readWord(st
);
909 gPlayers
[a
].FNextWeapDelay
:= utils
.readByte(st
);
911 gPlayers
[a
].FBFGFireCounter
:= utils
.readSmallInt(st
);
913 gPlayers
[a
].FDamageBuffer
:= utils
.readLongInt(st
);
914 // Ïîñëåäíèé óäàðèâøèé
915 gPlayers
[a
].FLastSpawnerUID
:= utils
.readWord(st
);
916 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
917 gPlayers
[a
].FLastHit
:= utils
.readByte(st
);
919 Obj_LoadState(@gPlayers
[a
].FObj
, st
);
920 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
921 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FAmmo
[i
] := utils
.readWord(st
);
922 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
923 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FMaxAmmo
[i
] := utils
.readWord(st
);
925 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FWeapon
[i
] := utils
.readBool(st
);
926 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
927 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FReloading
[i
] := utils
.readWord(st
);
929 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
930 // Íàëè÷èå êðàñíîãî êëþ÷à
931 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
932 // Íàëè÷èå çåëåíîãî êëþ÷à
933 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
934 // Íàëè÷èå ñèíåãî êëþ÷à
935 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
937 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_BERSERK
);
938 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
939 for i
:= MR_SUIT
to MR_MAX
do gPlayers
[a
].FMegaRulez
[i
] := utils
.readLongWord(st
);
940 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
941 for i
:= T_RESPAWN
to T_FLAGCAP
do gPlayers
[a
].FTime
[i
] := utils
.readLongWord(st
);
944 gPlayers
[a
].FActualModelName
:= utils
.readStr(st
);
946 gPlayers
[a
].FColor
.R
:= utils
.readByte(st
);
947 gPlayers
[a
].FColor
.G
:= utils
.readByte(st
);
948 gPlayers
[a
].FColor
.B
:= utils
.readByte(st
);
949 // Îáíîâëÿåì ìîäåëü èãðîêà
950 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
952 // Íåò ìîäåëè - ñîçäàíèå íåâîçìîæíî
953 if (gPlayers
[a
].FModel
= nil) then
957 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
961 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû
962 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
963 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
965 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
967 result
:= gPlayers
[a
].FUID
;
971 procedure g_Player_ResetTeams();
975 if g_Game_IsClient
then
977 if gPlayers
= nil then
979 for a
:= Low(gPlayers
) to High(gPlayers
) do
980 if gPlayers
[a
] <> nil then
981 case gGameSettings
.GameMode
of
983 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
985 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
986 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
987 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
990 gPlayers
[a
].ChangeTeam(TEAM_RED
)
992 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
995 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
999 procedure g_Bot_Add(Team
, Difficult
: Byte);
1002 _name
, _model
: String;
1005 if not g_Game_IsServer
then Exit
;
1007 // Ñïèñîê íàçâàíèé ìîäåëåé:
1008 m
:= g_PlayerModel_GetNames();
1013 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1014 Team
:= TEAM_COOP
// COOP
1016 if gGameSettings
.GameMode
= GM_DM
then
1017 Team
:= TEAM_NONE
// DM
1019 if Team
= TEAM_NONE
then // CTF / TDM
1021 // Àâòîáàëàíñ êîìàíä:
1025 for a
:= 0 to High(gPlayers
) do
1026 if gPlayers
[a
] <> nil then
1028 if gPlayers
[a
].Team
= TEAM_RED
then
1031 if gPlayers
[a
].Team
= TEAM_BLUE
then
1041 if Random(2) = 0 then
1047 // Âûáèðàåì áîòó èìÿ:
1049 if BotNames
<> nil then
1050 for a
:= 0 to High(BotNames
) do
1051 if g_Player_ValidName(BotNames
[a
]) then
1053 _name
:= BotNames
[a
];
1057 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
1060 _name
:= Format('DFBOT%.2d', [Random(100)]);
1061 until g_Player_ValidName(_name
);
1063 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1064 _model
:= m
[Random(Length(m
))];
1067 with g_Player_Get(g_Player_Create(_model
,
1068 _RGB(Min(Random(9)*32, 255),
1069 Min(Random(9)*32, 255),
1070 Min(Random(9)*32, 255)),
1071 Team
, True)) as TBot
do
1076 1: FDifficult
:= DIFFICULT_EASY
;
1077 2: FDifficult
:= DIFFICULT_MEDIUM
;
1078 else FDifficult
:= DIFFICULT_HARD
;
1081 for a
:= WP_FIRST
to WP_LAST
do
1083 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1084 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1085 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1088 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1090 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1091 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1096 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1);
1099 _name
, _model
: String;
1102 if not g_Game_IsServer
then Exit
;
1104 // Ñïèñîê íàçâàíèé ìîäåëåé:
1105 m
:= g_PlayerModel_GetNames();
1110 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1111 Team
:= TEAM_COOP
// COOP
1113 if gGameSettings
.GameMode
= GM_DM
then
1114 Team
:= TEAM_NONE
// DM
1116 if Team
= TEAM_NONE
then
1117 Team
:= BotList
[num
].team
; // CTF / TDM
1119 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1120 lName
:= AnsiLowerCase(lName
);
1121 if (num
< 0) or (num
> Length(BotList
)-1) then
1123 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1124 for a
:= 0 to High(BotList
) do
1125 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1134 _name
:= BotList
[num
].name
;
1135 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1136 if not g_Player_ValidName(_name
) then
1138 _name
:= Format('DFBOT%.2d', [Random(100)]);
1139 until g_Player_ValidName(_name
);
1142 _model
:= BotList
[num
].model
;
1143 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1144 if not InSArray(_model
, m
) then
1145 _model
:= m
[Random(Length(m
))];
1148 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1152 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1153 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1154 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1155 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1156 FDifficult
.Cover
:= BotList
[num
].cover
;
1157 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1159 for a
:= WP_FIRST
to WP_LAST
do
1161 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1162 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1163 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1166 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1168 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1172 procedure g_Bot_RemoveAll();
1176 if not g_Game_IsServer
then Exit
;
1177 if gPlayers
= nil then Exit
;
1179 for a
:= 0 to High(gPlayers
) do
1180 if gPlayers
[a
] <> nil then
1181 if gPlayers
[a
] is TBot
then
1183 gPlayers
[a
].Lives
:= 0;
1184 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1185 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1186 g_Player_Remove(gPlayers
[a
].FUID
);
1192 procedure g_Bot_MixNames();
1197 if BotNames
<> nil then
1198 for a
:= 0 to High(BotNames
) do
1200 b
:= Random(Length(BotNames
));
1202 Botnames
[a
] := BotNames
[b
];
1207 procedure g_Player_Remove(UID
: Word);
1211 if gPlayers
= nil then Exit
;
1213 if g_Game_IsServer
and g_Game_IsNet
then
1214 MH_SEND_PlayerDelete(UID
);
1216 for i
:= 0 to High(gPlayers
) do
1217 if gPlayers
[i
] <> nil then
1218 if gPlayers
[i
].FUID
= UID
then
1220 if gPlayers
[i
] is TPlayer
then
1221 TPlayer(gPlayers
[i
]).Free()
1223 TBot(gPlayers
[i
]).Free();
1229 procedure g_Player_Init();
1239 if not FileExists(DataDir
+ BOTNAMES_FILENAME
) then
1242 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1243 AssignFile(F
, DataDir
+ BOTNAMES_FILENAME
);
1254 SetLength(BotNames
, Length(BotNames
)+1);
1255 BotNames
[High(BotNames
)] := s
;
1263 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1264 config
:= TConfig
.CreateFile(DataDir
+ BOTLIST_FILENAME
);
1268 while config
.SectionExists(IntToStr(a
)) do
1270 SetLength(BotList
, Length(BotList
)+1);
1272 with BotList
[High(BotList
)] do
1275 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1277 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1279 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1284 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1285 color
.R
:= StrToIntDef(sa
[0], 0);
1286 color
.G
:= StrToIntDef(sa
[1], 0);
1287 color
.B
:= StrToIntDef(sa
[2], 0);
1288 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1289 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1290 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1291 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1292 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1293 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1294 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1295 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1296 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1297 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1298 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1299 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1300 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1301 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1302 if Length(sa
) = 10 then
1304 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1305 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1306 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1307 if Length(sa
) = 10 then
1309 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1311 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1312 if Length(sa) = 10 then
1314 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1323 procedure g_Player_Free();
1327 if gPlayers
<> nil then
1329 for i
:= 0 to High(gPlayers
) do
1330 if gPlayers
[i
] <> nil then
1332 if gPlayers
[i
] is TPlayer
then
1333 TPlayer(gPlayers
[i
]).Free()
1335 TBot(gPlayers
[i
]).Free();
1346 procedure g_Player_UpdateAll();
1350 if gPlayers
= nil then Exit
;
1352 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1353 for i
:= 0 to High(gPlayers
) do
1355 if gPlayers
[i
] <> nil then
1357 if gPlayers
[i
] is TPlayer
then
1359 gPlayers
[i
].Update();
1360 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1364 // bot updates weapons in `UpdateCombat()`
1365 TBot(gPlayers
[i
]).Update();
1369 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1372 procedure g_Player_DrawAll();
1376 if gPlayers
= nil then Exit
;
1378 for i
:= 0 to High(gPlayers
) do
1379 if gPlayers
[i
] <> nil then
1380 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1381 else TBot(gPlayers
[i
]).Draw();
1384 procedure g_Player_DrawDebug(p
: TPlayer
);
1388 if p
= nil then Exit
;
1389 if (@p
.FObj
) = nil then Exit
;
1391 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1393 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1394 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1395 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1396 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1397 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1398 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1401 procedure g_Player_DrawHealth();
1406 if gPlayers
= nil then Exit
;
1407 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1409 for i
:= 0 to High(gPlayers
) do
1410 if gPlayers
[i
] <> nil then
1412 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1413 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1414 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1415 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1416 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1417 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1421 function g_Player_Get(UID
: Word): TPlayer
;
1427 if gPlayers
= nil then
1430 for a
:= 0 to High(gPlayers
) do
1431 if gPlayers
[a
] <> nil then
1432 if gPlayers
[a
].FUID
= UID
then
1434 Result
:= gPlayers
[a
];
1439 function g_Player_GetCount(): Byte;
1445 if gPlayers
= nil then
1448 for a
:= 0 to High(gPlayers
) do
1449 if gPlayers
[a
] <> nil then
1450 Result
:= Result
+ 1;
1453 function g_Player_GetStats(): TPlayerStatArray
;
1459 if gPlayers
= nil then Exit
;
1461 for a
:= 0 to High(gPlayers
) do
1462 if gPlayers
[a
] <> nil then
1464 SetLength(Result
, Length(Result
)+1);
1465 with Result
[High(Result
)] do
1467 Ping
:= gPlayers
[a
].FPing
;
1468 Loss
:= gPlayers
[a
].FLoss
;
1469 Name
:= gPlayers
[a
].FName
;
1470 Team
:= gPlayers
[a
].FTeam
;
1471 Frags
:= gPlayers
[a
].FFrags
;
1472 Deaths
:= gPlayers
[a
].FDeath
;
1473 Kills
:= gPlayers
[a
].FKills
;
1474 Color
:= gPlayers
[a
].FModel
.Color
;
1475 Lives
:= gPlayers
[a
].FLives
;
1476 Spectator
:= gPlayers
[a
].FSpectator
;
1481 procedure g_Player_RememberAll
;
1485 for i
:= Low(gPlayers
) to High(gPlayers
) do
1486 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1487 gPlayers
[i
].RememberState
;
1490 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1494 gTeamStat
[TEAM_RED
].Goals
:= 0;
1495 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1497 if gPlayers
<> nil then
1498 for i
:= 0 to High(gPlayers
) do
1499 if gPlayers
[i
] <> nil then
1501 gPlayers
[i
].Reset(Force
);
1503 if gPlayers
[i
] is TPlayer
then
1505 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1506 gPlayers
[i
].Respawn(Silent
)
1508 gPlayers
[i
].Spectate();
1511 TBot(gPlayers
[i
]).Respawn(Silent
);
1515 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1521 if Player
.alive
then
1524 // Ðàçðûâàåì ñâÿçü ñ ïðåæíèì òðóïîì:
1525 if gCorpses
<> nil then
1526 for i
:= 0 to High(gCorpses
) do
1527 if gCorpses
[i
] <> nil then
1528 if gCorpses
[i
].FPlayerUID
= Player
.FUID
then
1529 gCorpses
[i
].FPlayerUID
:= 0;
1531 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1536 if (FHealth
>= -50) or (gGibsCount
= 0) then
1538 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1542 for find_id
:= 0 to High(gCorpses
) do
1543 if gCorpses
[find_id
] = nil then
1550 find_id
:= Random(Length(gCorpses
));
1552 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1553 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1554 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1555 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1556 gCorpses
[find_id
].FPlayerUID
:= FUID
;
1559 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1560 FObj
.Y
+ PLAYER_RECT_CY
,
1561 FModel
.Name
, FModel
.Color
);
1565 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1569 if (gShells
= nil) or (Length(gShells
) = 0) then
1572 with gShells
[CurrentShell
] do
1578 if T
= SHELL_BULLET
then
1580 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1584 Obj
.Rect
.Width
:= 4;
1585 Obj
.Rect
.Height
:= 2;
1589 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1593 Obj
.Rect
.Width
:= 7;
1594 Obj
.Rect
.Height
:= 3;
1600 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1601 positionChanged(); // this updates spatial accelerators
1602 RAngle
:= Random(360);
1603 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1605 if CurrentShell
>= High(gShells
) then
1612 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1615 GibsArray
: TGibsArray
;
1618 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1620 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1622 Blood
:= g_PlayerModel_GetBlood(ModelName
);
1624 for a
:= 0 to High(GibsArray
) do
1625 with gGibs
[CurrentGib
] do
1628 ID
:= GibsArray
[a
].ID
;
1629 MaskID
:= GibsArray
[a
].MaskID
;
1632 Obj
.Rect
:= GibsArray
[a
].Rect
;
1633 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1634 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1635 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1636 positionChanged(); // this updates spatial accelerators
1637 RAngle
:= Random(360);
1639 if gBloodCount
> 0 then
1640 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1641 Random(48), Random(48), Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
1643 if CurrentGib
>= High(gGibs
) then
1650 procedure g_Player_UpdatePhysicalObjects();
1656 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1661 if T
= SHELL_BULLET
then
1662 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1664 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1669 if gGibs
<> nil then
1670 for i
:= 0 to High(gGibs
) do
1671 if gGibs
[i
].alive
then
1675 mr
:= g_Obj_Move(@Obj
, True, False, True);
1676 positionChanged(); // this updates spatial accelerators
1678 if WordBool(mr
and MOVE_FALLOUT
) then
1684 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1685 if WordBool(mr
and MOVE_HITWALL
) then
1686 Obj
.Vel
.X
:= -(vel
.X
div 2);
1687 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1688 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1690 if (Obj
.Vel
.X
>= 0) then
1692 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1693 if RAngle
>= 360 then
1694 RAngle
:= RAngle
mod 360;
1695 end else begin // Counter-clockwise
1696 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1698 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1701 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1702 if gTime
mod (GAME_TICK
*3) = 0 then
1703 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1707 if gCorpses
<> nil then
1708 for i
:= 0 to High(gCorpses
) do
1709 if gCorpses
[i
] <> nil then
1710 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1716 gCorpses
[i
].Update();
1719 if gShells
<> nil then
1720 for i
:= 0 to High(gShells
) do
1721 if gShells
[i
].alive
then
1725 mr
:= g_Obj_Move(@Obj
, True, False, True);
1726 positionChanged(); // this updates spatial accelerators
1728 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1734 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1735 if WordBool(mr
and MOVE_HITWALL
) then
1737 Obj
.Vel
.X
:= -(vel
.X
div 2);
1738 if not WordBool(mr
and MOVE_INWATER
) then
1739 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1741 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1743 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1744 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1745 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1747 if RAngle
mod 90 <> 0 then
1748 RAngle
:= (RAngle
div 90) * 90;
1750 else if not WordBool(mr
and MOVE_INWATER
) then
1751 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1754 if (Obj
.Vel
.X
>= 0) then
1756 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1757 if RAngle
>= 360 then
1758 RAngle
:= RAngle
mod 360;
1759 end else begin // Counter-clockwise
1760 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1762 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1768 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1770 x
:= Obj
.X
+Obj
.Rect
.X
;
1771 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1772 w
:= Obj
.Rect
.Width
;
1773 h
:= Obj
.Rect
.Height
;
1776 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1778 if (dx
<> 0) or (dy
<> 0) then
1787 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1791 w
:= Obj
.Rect
.Width
;
1792 h
:= Obj
.Rect
.Height
;
1795 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1797 if (dx
<> 0) or (dy
<> 0) then
1806 procedure TGib
.positionChanged (); inline; begin end;
1807 procedure TShell
.positionChanged (); inline; begin end;
1810 procedure g_Player_DrawCorpses();
1815 if gGibs
<> nil then
1816 for i
:= 0 to High(gGibs
) do
1817 if gGibs
[i
].alive
then
1820 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1823 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1824 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1826 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1829 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1835 if gCorpses
<> nil then
1836 for i
:= 0 to High(gCorpses
) do
1837 if gCorpses
[i
] <> nil then
1841 procedure g_Player_DrawShells();
1846 if gShells
<> nil then
1847 for i
:= 0 to High(gShells
) do
1848 if gShells
[i
].alive
then
1851 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1857 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1861 procedure g_Player_RemoveAllCorpses();
1867 SetLength(gGibs
, MaxGibs
);
1868 SetLength(gShells
, MaxGibs
);
1872 if gCorpses
<> nil then
1873 for i
:= 0 to High(gCorpses
) do
1877 SetLength(gCorpses
, MaxCorpses
);
1880 procedure g_Player_Corpses_SaveState (st
: TStream
);
1884 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ
1886 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1888 // Êîëè÷åñòâî òðóïîâ
1889 utils
.writeInt(st
, LongInt(count
));
1891 if (count
= 0) then exit
;
1894 for i
:= 0 to High(gCorpses
) do
1896 if gCorpses
[i
] <> nil then
1899 utils
.writeStr(st
, gCorpses
[i
].FModelName
);
1901 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1902 // Ñîõðàíÿåì äàííûå òðóïà:
1903 gCorpses
[i
].SaveState(st
);
1909 procedure g_Player_Corpses_LoadState (st
: TStream
);
1917 g_Player_RemoveAllCorpses();
1919 // Êîëè÷åñòâî òðóïîâ:
1920 count
:= utils
.readLongInt(st
);
1921 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1923 if (count
= 0) then exit
;
1926 for i
:= 0 to count
-1 do
1929 str
:= utils
.readStr(st
);
1931 b
:= utils
.readBool(st
);
1933 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1934 // Çàãðóæàåì äàííûå òðóïà
1935 gCorpses
[i
].LoadState(st
);
1942 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1944 procedure TPlayer
.BFGHit();
1946 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1947 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1948 if g_Game_IsServer
and g_Game_IsNet
then
1949 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1950 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1954 procedure TPlayer
.ChangeModel(ModelName
: string);
1956 locModel
: TPlayerModel
;
1958 locModel
:= g_PlayerModel_Get(ModelName
);
1959 if locModel
= nil then Exit
;
1965 procedure TPlayer
.SetModel(ModelName
: string);
1969 m
:= g_PlayerModel_Get(ModelName
);
1972 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1973 m
:= g_PlayerModel_Get('doomer');
1976 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1981 if FModel
<> nil then
1986 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1987 FModel
.Color
:= FColor
1989 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1990 FModel
.SetWeapon(FCurrWeap
);
1991 FModel
.SetFlag(FFlag
);
1992 SetDirection(FDirection
);
1995 procedure TPlayer
.SetColor(Color
: TRGB
);
1998 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1999 if FModel
<> nil then FModel
.Color
:= Color
;
2002 procedure TPlayer
.SwitchTeam
;
2004 if g_Game_IsClient
then
2006 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
2008 if gGameOn
and FAlive
then
2009 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
2011 if FTeam
= TEAM_RED
then
2013 ChangeTeam(TEAM_BLUE
);
2014 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
2015 if g_Game_IsNet
then
2016 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
2020 ChangeTeam(TEAM_RED
);
2021 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
2022 if g_Game_IsNet
then
2023 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
2025 FPreferredTeam
:= FTeam
;
2028 procedure TPlayer
.ChangeTeam(Team
: Byte);
2035 TEAM_RED
, TEAM_BLUE
:
2036 FModel
.Color
:= TEAMCOLOR
[Team
];
2038 FModel
.Color
:= FColor
;
2040 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2041 MH_SEND_PlayerStats(FUID
);
2045 procedure TPlayer.CollideItem();
2050 if gItems = nil then Exit;
2051 if not FAlive then Exit;
2053 for i := 0 to High(gItems) do
2056 if (ItemType <> ITEM_NONE) and alive then
2057 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2058 PLAYER_RECT.Height, @Obj) then
2060 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2062 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2063 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2064 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2065 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2066 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2068 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2069 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2070 (gGameSettings.GameType = GT_SINGLE) and
2071 (g_Player_GetCount() > 1)) then
2072 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2078 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2080 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2081 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2085 constructor TPlayer
.Create();
2091 mEDamageType
:= HIT_SOME
;
2097 FSawSound
:= TPlayableSound
.Create();
2098 FSawSoundIdle
:= TPlayableSound
.Create();
2099 FSawSoundHit
:= TPlayableSound
.Create();
2100 FSawSoundSelect
:= TPlayableSound
.Create();
2101 FJetSoundFly
:= TPlayableSound
.Create();
2102 FJetSoundOn
:= TPlayableSound
.Create();
2103 FJetSoundOff
:= TPlayableSound
.Create();
2105 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2106 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2107 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2108 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2109 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2110 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2111 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2113 FSpectatePlayer
:= -1;
2117 FSavedState
.WaitRecall
:= False;
2123 FActualModelName
:= 'doomer';
2126 FObj
.Rect
:= PLAYER_RECT
;
2128 FBFGFireCounter
:= -1;
2129 FJustTeleported
:= False;
2135 procedure TPlayer
.positionChanged (); inline;
2139 procedure TPlayer
.doDamage (v
: Integer);
2141 if (v
<= 0) then exit
;
2142 if (v
> 32767) then v
:= 32767;
2143 Damage(v
, 0, 0, 0, mEDamageType
);
2146 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2150 if (not g_Game_IsClient
) and (not FAlive
) then
2155 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2156 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2158 if not g_Game_IsClient
then
2161 if t
= HIT_TRAP
then
2163 // Ëîâóøêà óáèâàåò ñðàçó:
2165 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2167 if t
= HIT_SELF
then
2171 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2174 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2175 FMegaRulez
[MR_SUIT
] := 0;
2176 FMegaRulez
[MR_INVUL
] := 0;
2177 FMegaRulez
[MR_INVIS
] := 0;
2181 // Íî îò îñòàëüíîãî ñïàñàåò:
2182 if FMegaRulez
[MR_INVUL
] >= gTime
then
2189 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2190 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2191 (SpawnerUID
= FUID
) or
2192 (not SameTeam(FUID
, SpawnerUID
)) then
2194 FLastSpawnerUID
:= SpawnerUID
;
2196 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2197 if gBloodCount
> 0 then
2199 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2200 if value
div 4 <= c
then
2201 c
:= c
- (value
div 4)
2205 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2209 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2210 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2213 if t
= HIT_WATER
then
2214 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2215 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2220 Inc(FDamageBuffer
, value
);
2224 FPain
:= FPain
+ value
;
2227 if g_Game_IsServer
and g_Game_IsNet
then
2229 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2230 MH_SEND_PlayerStats(FUID
);
2231 MH_SEND_PlayerPos(False, FUID
);
2235 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2238 if g_Game_IsClient
then
2243 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2245 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2248 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2250 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2254 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2255 MH_SEND_PlayerStats(FUID
);
2258 destructor TPlayer
.Destroy();
2260 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2262 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2266 FSawSoundIdle
.Free();
2267 FSawSoundHit
.Free();
2268 FJetSoundFly
.Free();
2270 FJetSoundOff
.Free();
2272 if FPunchAnim
<> nil then
2278 procedure TPlayer
.DrawIndicator();
2280 indX
, indY
: Integer;
2286 indX
:= FObj
.X
+FObj
.Rect
.X
;
2287 indY
:= FObj
.Y
- 12;
2288 if g_Texture_Get('TEXTURE_PLAYER_INDICATOR', ID
) then
2290 e_GetTextureSize(ID
, @indW
, @indH
);
2291 e_Draw(ID
, indX
+ indW
div 2, indY
, 0, True, False);
2294 //e_TextureFontPrint(indX, indY, FName, gStdFont); // Shows player name overhead
2297 procedure TPlayer
.DrawBubble();
2299 bubX
, bubY
: Integer;
2302 Rw
, Gw
, Bw
: SmallInt;
2305 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= TDirection
.D_LEFT
, -4, 18);
2306 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2314 1: // simple textual non-bubble
2316 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2317 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2318 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2321 2: // advanced pixel-perfect bubble
2323 if FTeam
= TEAM_RED
then
2326 if FTeam
= TEAM_BLUE
then
2329 3: // colored bubble
2331 Rb
:= FModel
.Color
.R
;
2332 Gb
:= FModel
.Color
.G
;
2333 Bb
:= FModel
.Color
.B
;
2334 Rw
:= Min(Rb
* 2 + 64, 255);
2335 Gw
:= Min(Gb
* 2 + 64, 255);
2336 Bw
:= Min(Bb
* 2 + 64, 255);
2337 if (Abs(Rw
- Rb
) < 32)
2338 or (Abs(Gw
- Gb
) < 32)
2339 or (Abs(Bw
- Bb
) < 32) then
2341 Rb
:= Max(Rw
div 2 - 16, 0);
2342 Gb
:= Max(Gw
div 2 - 16, 0);
2343 Bb
:= Max(Bw
div 2 - 16, 0);
2346 4: // custom textured bubble
2348 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2349 if FDirection
= TDirection
.D_RIGHT
then
2350 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2352 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, TMirrorType
.Horizontal
);
2358 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2359 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2361 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2364 Dot
:= IfThen(FDirection
= TDirection
.D_LEFT
, 14, 5);
2365 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2366 e_DrawLine(1, bubX
+ IfThen(FDirection
= TDirection
.D_LEFT
, Dot
- 1, Dot
+ 1), bubY
+ 13, bubX
+ IfThen(FDirection
= TDirection
.D_LEFT
, Dot
- 1, Dot
+ 1), bubY
+ 15, Rw
, Gw
, Bw
);
2367 e_DrawLine(1, bubX
+ IfThen(FDirection
= TDirection
.D_LEFT
, Dot
- 2, Dot
+ 2), bubY
+ 13, bubX
+ IfThen(FDirection
= TDirection
.D_LEFT
, Dot
- 2, Dot
+ 2), bubY
+ 14, Rw
, Gw
, Bw
);
2368 e_DrawLine(1, bubX
+ IfThen(FDirection
= TDirection
.D_LEFT
, Dot
- 3, Dot
+ 3), bubY
+ 13, bubX
+ IfThen(FDirection
= TDirection
.D_LEFT
, Dot
- 3, Dot
+ 3), bubY
+ 13, Rw
, Gw
, Bw
);
2369 e_DrawLine(1, bubX
+ IfThen(FDirection
= TDirection
.D_LEFT
, Dot
- 3, Dot
+ 3), bubY
+ 14, bubX
+ IfThen(FDirection
= TDirection
.D_LEFT
, Dot
- 1, Dot
+ 1), bubY
+ 16, Rb
, Gb
, Bb
);
2373 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2374 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2375 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2378 procedure TPlayer
.Draw();
2383 Mirror
: TMirrorType
;
2387 if Direction
= TDirection
.D_RIGHT
then
2388 Mirror
:= TMirrorType
.None
2390 Mirror
:= TMirrorType
.Horizontal
;
2392 if FPunchAnim
<> nil then
2394 FPunchAnim
.Draw(FObj
.X
+IfThen(Direction
= TDirection
.D_LEFT
, 15-FObj
.Rect
.X
, FObj
.Rect
.X
-15),
2395 FObj
.Y
+FObj
.Rect
.Y
-11, Mirror
);
2396 if FPunchAnim
.played
then
2403 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2404 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2406 e_GetTextureSize(ID
, @w
, @h
);
2407 if FDirection
= TDirection
.D_LEFT
then
2408 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2409 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False)
2411 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2412 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False);
2415 if FMegaRulez
[MR_INVIS
] > gTime
then
2417 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2418 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2420 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2421 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2425 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 200)
2427 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2430 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 254);
2433 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2436 if g_debug_Frames
then
2438 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2440 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2441 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2445 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2447 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2448 if gAimLine
and alive
and
2449 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2454 procedure TPlayer
.DrawAim();
2455 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2460 {$IFDEF ENABLE_HOLMES}
2461 if isValidViewPort
and (self
= gPlayer1
) then
2463 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2467 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2468 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2470 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2474 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2479 wx
, wy
, xx
, yy
: Integer;
2483 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= TDirection
.D_LEFT
, 7, -7);
2484 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2493 1: begin // Chainsaw
2500 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2501 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2502 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2503 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2508 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2509 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2510 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2511 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2513 4: begin // Double Shotgun
2516 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2517 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2518 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2519 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2521 5: begin // Chaingun
2524 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2525 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2526 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2527 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2529 6: begin // Rocket Launcher
2532 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2533 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2534 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2535 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2537 7: begin // Plasmagun
2540 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2541 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2542 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2543 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2548 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2549 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2550 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2551 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2553 9: begin // Super Chaingun
2556 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2557 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2558 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2559 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2562 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2563 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2564 {$IF DEFINED(D2F_DEBUG)}
2565 drawCast(sz
, wx
, wy
, xx
, yy
);
2567 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2571 procedure TPlayer
.DrawGUI();
2574 X
, Y
, SY
, a
, p
, m
: Integer;
2578 stat
: TPlayerStatArray
;
2580 X
:= gPlayerScreenSize
.X
;
2581 SY
:= gPlayerScreenSize
.Y
;
2584 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2586 if gGameSettings
.GameMode
= GM_CTF
then
2590 if gGameSettings
.GameMode
= GM_CTF
then
2592 s
:= 'TEXTURE_PLAYER_REDFLAG';
2593 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2594 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2595 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2596 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2597 if g_Texture_Get(s
, ID
) then
2598 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2601 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2602 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2603 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2605 if gGameSettings
.GameMode
= GM_CTF
then
2607 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2608 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2609 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2610 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2611 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2612 if g_Texture_Get(s
, ID
) then
2613 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2616 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2617 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2618 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2621 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2622 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2625 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2626 e_Draw(ID
, X
+2, Y
, 0, True, False);
2628 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2632 s
:= IntToStr(Frags
);
2633 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2634 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2639 stat
:= g_Player_GetStats();
2644 for a
:= 0 to High(stat
) do
2645 if stat
[a
].Name
<> Name
then
2647 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2648 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2652 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2653 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2654 s
:= s
+IntToStr(Abs(Frags
-m
));
2656 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2657 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2660 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2662 s
:= IntToStr(Lives
);
2663 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2664 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2668 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2669 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2671 if R_BERSERK
in FRulez
then
2672 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2674 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2676 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2677 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2679 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2680 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2681 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2683 s
:= IntToStr(FArmor
);
2684 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2685 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2687 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2693 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2698 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2700 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2701 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2702 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2703 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2704 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2705 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2706 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2707 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2708 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2711 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2712 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2713 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2715 if R_KEY_RED
in FRulez
then
2716 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2718 if R_KEY_GREEN
in FRulez
then
2719 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2721 if R_KEY_BLUE
in FRulez
then
2722 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2724 if FJetFuel
> 0 then
2726 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2727 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2728 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2729 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2730 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2731 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2735 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2736 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2737 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2740 if gShowPing
and g_Game_IsClient
then
2742 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2743 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2749 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2750 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2751 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2754 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2755 s
:= _lc
[I_PLAYER_SPECT4
];
2756 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2757 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2758 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2764 procedure TPlayer
.DrawRulez();
2768 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2769 if FMegaRulez
[MR_INVUL
] >= gTime
then
2771 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2772 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2777 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2778 191, 191, 191, 0, TBlending
.Invert
);
2781 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2782 if FMegaRulez
[MR_SUIT
] >= gTime
then
2784 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2785 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2790 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2791 0, 96, 0, 200, TBlending
.None
);
2794 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2795 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2797 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2798 255, 0, 0, 200, TBlending
.None
);
2802 procedure TPlayer
.DrawPain();
2806 if FPain
= 0 then Exit
;
2810 if a
< 15 then h
:= 0
2811 else if a
< 35 then h
:= 1
2812 else if a
< 55 then h
:= 2
2813 else if a
< 75 then h
:= 3
2814 else if a
< 95 then h
:= 4
2817 //if a > 255 then a := 255;
2819 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2820 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2823 procedure TPlayer
.DrawPickup();
2827 if FPickup
= 0 then Exit
;
2831 if a
< 15 then h
:= 1
2832 else if a
< 35 then h
:= 2
2833 else if a
< 55 then h
:= 3
2834 else if a
< 75 then h
:= 4
2837 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2840 procedure TPlayer
.DoPunch();
2845 if FPunchAnim
<> nil then begin
2850 st
:= 'FRAMES_PUNCH';
2851 if R_BERSERK
in FRulez
then
2852 st
:= st
+ '_BERSERK';
2853 if FKeys
[KEY_UP
].Pressed
then
2855 else if FKeys
[KEY_DOWN
].Pressed
then
2857 g_Frames_Get(id
, st
);
2858 FPunchAnim
:= TAnimation
.Create(id
, False, 1);
2861 procedure TPlayer
.Fire();
2863 f
, DidFire
: Boolean;
2864 wx
, wy
, xd
, yd
: Integer;
2867 if g_Game_IsClient
then Exit
;
2868 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2869 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2877 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2882 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2883 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2884 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
2885 yd
:= wy
+firediry();
2891 if R_BERSERK
in FRulez
then
2893 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2894 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2895 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2898 locobj
.rect
.Width
:= 39;
2899 locobj
.rect
.Height
:= 52;
2900 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2901 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2902 locobj
.Accel
.X
:= xd
-wx
;
2903 locobj
.Accel
.y
:= yd
-wy
;
2905 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2906 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2908 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2910 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
2914 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2918 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2923 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2924 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2926 FSawSoundSelect
.Stop();
2928 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2930 else if not FSawSoundHit
.IsPlaying() then
2932 FSawSoundSelect
.Stop();
2933 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2936 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2942 if FAmmo
[A_BULLETS
] > 0 then
2944 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2945 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2946 Dec(FAmmo
[A_BULLETS
]);
2947 FFireAngle
:= FAngle
;
2950 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2951 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2955 if FAmmo
[A_SHELLS
] > 0 then
2957 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2958 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
2959 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2960 Dec(FAmmo
[A_SHELLS
]);
2961 FFireAngle
:= FAngle
;
2965 FShellType
:= SHELL_SHELL
;
2969 if FAmmo
[A_SHELLS
] >= 2 then
2971 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
2972 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2973 Dec(FAmmo
[A_SHELLS
], 2);
2974 FFireAngle
:= FAngle
;
2978 FShellType
:= SHELL_DBLSHELL
;
2982 if FAmmo
[A_BULLETS
] > 0 then
2984 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
2985 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
2986 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2987 Dec(FAmmo
[A_BULLETS
]);
2988 FFireAngle
:= FAngle
;
2991 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2992 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2995 WEAPON_ROCKETLAUNCHER
:
2996 if FAmmo
[A_ROCKETS
] > 0 then
2998 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
2999 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3000 Dec(FAmmo
[A_ROCKETS
]);
3001 FFireAngle
:= FAngle
;
3007 if FAmmo
[A_CELLS
] > 0 then
3009 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
3010 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3011 Dec(FAmmo
[A_CELLS
]);
3012 FFireAngle
:= FAngle
;
3018 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
3020 FBFGFireCounter
:= 17;
3021 if not FNoReload
then
3022 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
3023 Dec(FAmmo
[A_CELLS
], 40);
3027 WEAPON_SUPERPULEMET
:
3028 if FAmmo
[A_SHELLS
] > 0 then
3030 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3031 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
3032 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3033 Dec(FAmmo
[A_SHELLS
]);
3034 FFireAngle
:= FAngle
;
3037 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3038 GameVelX
, GameVelY
-2, SHELL_SHELL
);
3041 WEAPON_FLAMETHROWER
:
3042 if FAmmo
[A_FUEL
] > 0 then
3044 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
3045 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3047 FFireAngle
:= FAngle
;
3053 if g_Game_IsNet
then
3057 if FCurrWeap
<> WEAPON_BFG
then
3058 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
3060 if not FNoReload
then
3061 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
3064 MH_SEND_PlayerStats(FUID
);
3069 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
3070 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
3071 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
3074 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
3077 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
3078 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
3079 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
3080 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
3081 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
3086 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
3088 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
3089 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
3090 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
3093 procedure TPlayer
.JetpackOn
;
3097 FJetSoundOn
.SetPosition(0);
3098 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3102 procedure TPlayer
.JetpackOff
;
3106 FJetSoundOff
.SetPosition(0);
3107 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3110 procedure TPlayer
.CatchFire(Attacker
: Word);
3113 FFireAttacker
:= Attacker
;
3114 if g_Game_IsNet
and g_Game_IsServer
then
3115 MH_SEND_PlayerStats(FUID
);
3118 procedure TPlayer
.Jump();
3120 if gFly
or FJetpack
then
3122 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3123 if FObj
.Vel
.Y
> -VEL_FLY
then
3124 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3127 if FJetFuel
> 0 then
3129 if (FJetFuel
< 1) and g_Game_IsServer
then
3133 if g_Game_IsNet
then
3134 MH_SEND_PlayerStats(FUID
);
3140 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3142 FCanJetpack
:= False;
3144 // Ïðûãàåì èëè âñïëûâàåì:
3145 if (CollideLevel(0, 1) or
3146 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3147 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3148 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3150 FObj
.Vel
.Y
:= -VEL_JUMP
;
3151 FCanJetpack
:= False;
3155 if BodyInLiquid(0, 0) then
3156 FObj
.Vel
.Y
:= -VEL_SW
3157 else if (FJetFuel
> 0) and FCanJetpack
and
3158 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3162 if g_Game_IsNet
then
3163 MH_SEND_PlayerStats(FUID
);
3168 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3170 a
, i
, k
, ab
, ar
: Byte;
3174 srv
, netsrv
: Boolean;
3180 procedure PushItem(t
: Byte);
3184 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3185 it
:= g_Items_ByIdx(id
);
3186 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3188 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3189 (FObj
.Vel
.Y
div 2)-Random(9));
3190 it
.positionChanged(); // this updates spatial accelerators
3194 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3196 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3197 (FObj
.Vel
.Y
div 2)-Random(6));
3199 else // -3..+3; -3..0
3201 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3202 (FObj
.Vel
.Y
div 2)-Random(4));
3204 it
.positionChanged(); // this updates spatial accelerators
3207 if g_Game_IsNet
and g_Game_IsServer
then
3208 MH_SEND_ItemSpawn(True, id
);
3212 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3213 Srv
:= g_Game_IsServer
;
3214 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3215 if Srv
then FDeath
:= FDeath
+ 1;
3220 if not FPhysics
then
3226 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3228 if FLives
> 0 then FLives
:= FLives
- 1;
3229 if FLives
= 0 then FNoRespawn
:= True;
3232 // Íîìåð òèïà ñìåðòè:
3235 K_SIMPLEKILL
: a
:= 1;
3237 K_EXTRAHARDKILL
: a
:= 3;
3242 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3244 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3251 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3253 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3254 K_EXTRAHARDKILL
, K_FALLKILL
:
3255 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3258 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3262 K_HARDKILL
, K_EXTRAHARDKILL
:
3266 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3267 if (KillType
<> K_FALLKILL
) and (Srv
) then
3268 g_Monsters_killedp();
3270 if SpawnerUID
= FUID
then
3272 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3277 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3280 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3281 begin // Óáèò äðóãèì èãðîêîì
3282 KP
:= g_Player_Get(SpawnerUID
);
3283 if (KP
<> nil) and Srv
then
3285 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3286 if SameTeam(FUID
, SpawnerUID
) then
3296 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3297 Inc(gTeamStat
[KP
.Team
].Goals
,
3298 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3300 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3303 plr
:= g_Player_Get(SpawnerUID
);
3311 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3315 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3319 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3324 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3325 begin // Óáèò ìîíñòðîì
3326 mon
:= g_Monsters_ByUID(SpawnerUID
);
3330 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
3334 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3338 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3342 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3347 else // Îñîáûå òèïû ñìåðòè
3350 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3351 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3352 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3353 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3354 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3355 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3361 for a
:= WP_FIRST
to WP_LAST
do
3365 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3366 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3367 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3368 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3369 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3370 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3371 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3372 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3373 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3382 if R_ITEM_BACKPACK
in FRulez
then
3383 PushItem(ITEM_AMMO_BACKPACK
);
3385 // Âûáðîñ ðàêåòíîãî ðàíöà:
3386 if FJetFuel
> 0 then
3387 PushItem(ITEM_JETPACK
);
3390 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3392 if R_KEY_RED
in FRulez
then
3393 PushItem(ITEM_KEY_RED
);
3395 if R_KEY_GREEN
in FRulez
then
3396 PushItem(ITEM_KEY_GREEN
);
3398 if R_KEY_BLUE
in FRulez
then
3399 PushItem(ITEM_KEY_BLUE
);
3406 g_Player_CreateCorpse(Self
);
3408 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3409 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3415 for i
:= Low(gPlayers
) to High(gPlayers
) do
3417 if gPlayers
[i
] = nil then continue
;
3418 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3421 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3422 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3427 OldLR
:= gLMSRespawn
;
3428 if (gGameSettings
.GameMode
= GM_COOP
) then
3432 // everyone is dead, restart the map
3433 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3435 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3436 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3437 gLMSRespawnTime
:= gTime
+ 5000;
3439 else if (a
= 1) then
3441 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3442 if (gPlayers
[k
] = gPlayer1
) or
3443 (gPlayers
[k
] = gPlayer2
) then
3444 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3445 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3446 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3449 else if (gGameSettings
.GameMode
= GM_TDM
) then
3451 if (ab
= 0) and (ar
<> 0) then
3454 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3456 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3457 Inc(gTeamStat
[TEAM_RED
].Goals
);
3458 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3459 gLMSRespawnTime
:= gTime
+ 5000;
3461 else if (ar
= 0) and (ab
<> 0) then
3464 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3466 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3467 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3468 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3469 gLMSRespawnTime
:= gTime
+ 5000;
3471 else if (ar
= 0) and (ab
= 0) then
3474 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3476 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3477 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3478 gLMSRespawnTime
:= gTime
+ 5000;
3481 else if (gGameSettings
.GameMode
= GM_DM
) then
3485 if gPlayers
[k
] <> nil then
3488 // survivor is the winner
3489 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3491 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3494 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3495 gLMSRespawnTime
:= gTime
+ 5000;
3497 else if (a
= 0) then
3499 // everyone is dead, restart the map
3500 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3502 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3503 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3504 gLMSRespawnTime
:= gTime
+ 5000;
3507 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3509 if NetMode
= NET_SERVER
then
3510 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3512 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3518 MH_SEND_PlayerStats(FUID
);
3519 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3520 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3523 if srv
and FNoRespawn
then Spectate(True);
3524 FWantsInGame
:= True;
3527 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3529 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3530 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3533 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3535 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3536 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3539 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3541 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3542 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3543 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3544 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3545 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3546 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3547 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3548 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3551 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3553 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3554 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3555 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3556 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3559 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3561 if g_Game_IsClient
then Exit
;
3562 if Weapon
> High(FWeapon
) then Exit
;
3563 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3566 procedure TPlayer
.resetWeaponQueue ();
3569 FNextWeapDelay
:= 0;
3572 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3576 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3577 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
3578 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
3579 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3580 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3581 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3582 else result
:= (weapon
< length(FWeapon
));
3586 // return 255 for "no switch"
3587 function TPlayer
.getNextWeaponIndex (): Byte;
3590 wantThisWeapon
: array[0..64] of Boolean;
3591 weaponOrder
: array[0..16] of Integer; // value: index in `FWeapon`
3593 f
, dir
, cwi
, rwidx
, curlidx
: Integer;
3595 function real2log (ridx
: Integer): Integer;
3601 for f
:= 0 to High(weaponOrder
) do if (weaponOrder
[f
] = ridx
) then begin result
:= f
; exit
; end;
3607 result
:= 255; // default result: "no switch"
3609 // had weapon cycling on previous frame? remove that flag
3610 if (FNextWeap
and $2000) <> 0 then
3612 FNextWeap
:= FNextWeap
and $1FFF;
3613 FNextWeapDelay
:= 0;
3616 for f
:= 0 to High(weaponOrder
) do weaponOrder
[f
] := -1;
3618 // build weapon order (k8: i know, i know, learn how to do constants and such... gtfo, please!)
3619 // two knuckles are for "normal" and "berserk" (see `if` below -- it removes the one that is not needed)
3621 // bfg, launcher, plasma, flamethrower, ssg, minigun, sg, pistol, berserk, chainsaw, fist
3622 weaponOrder
[0] := WEAPON_SUPERPULEMET
;
3623 weaponOrder
[1] := WEAPON_BFG
;
3624 weaponOrder
[2] := WEAPON_ROCKETLAUNCHER
;
3625 weaponOrder
[3] := WEAPON_PLASMA
;
3626 weaponOrder
[4] := WEAPON_FLAMETHROWER
;
3627 weaponOrder
[5] := WEAPON_SHOTGUN2
;
3628 weaponOrder
[6] := WEAPON_CHAINGUN
;
3629 weaponOrder
[7] := WEAPON_SHOTGUN1
;
3630 weaponOrder
[8] := WEAPON_PISTOL
;
3631 weaponOrder
[9] := WEAPON_KASTET
+666; // berserk fist
3632 weaponOrder
[10] := WEAPON_SAW
;
3633 weaponOrder
[11] := WEAPON_KASTET
; // normal fist
3635 for f
:= 0 to High(weaponOrder
) do
3637 if (weaponOrder
[f
] = WEAPON_KASTET
) then
3639 // normal fist: remove if we have a berserk pack
3640 if (R_BERSERK
in FRulez
) then weaponOrder
[f
] := -1;
3643 if (weaponOrder
[f
] = WEAPON_KASTET
+666) then
3645 // berserk fist: remove if we don't have a berserk pack
3646 if (R_BERSERK
in FRulez
) then weaponOrder
[f
] := WEAPON_KASTET
else weaponOrder
[f
] := -1;
3654 WEAPON_SHOTGUN1 = 3;
3655 WEAPON_SHOTGUN2 = 4;
3656 WEAPON_CHAINGUN = 5;
3657 WEAPON_ROCKETLAUNCHER = 6;
3660 WEAPON_SUPERPULEMET = 9;
3661 WEAPON_FLAMETHROWER = 10;
3664 // cycling has priority
3665 if (FNextWeap
and $C000) <> 0 then
3667 if (FNextWeap
and $8000) <> 0 then dir
:= 1 else dir
:= -1; // should be reversed if we want "priority-driven cycling"
3668 FNextWeap
:= FNextWeap
or $2000; // we need this
3669 if FNextWeapDelay
> 0 then exit
; // cooldown time
3670 //cwi := real2log(FCurrWeap);
3671 //if (cwi < 0) then cwi := 0;
3673 for i
:= 0 to High(FWeapon
) do
3675 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3676 //rwidx := weaponOrder[cwi];
3677 rwidx
:= cwi
; // sorry
3678 if (rwidx
< 0) then continue
;
3679 if FWeapon
[rwidx
] then
3681 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d (dir=%d; log=%d)', [FCurrWeap, rwidx, dir, cwi]), TMsgType.Warning);
3682 result
:= Byte(rwidx
);
3683 FNextWeapDelay
:= 10;
3692 for i
:= 0 to High(wantThisWeapon
) do wantThisWeapon
[i
] := false;
3695 curlidx
:= -1; // start from a weapon with a highest priority (-1, 'cause loop will immediately increment this index)
3697 for i
:= 0 to High(FWeapon
) do
3699 if (FNextWeap
and (1 shl i
)) <> 0 then
3704 wantThisWeapon
[cwi
] := true;
3706 // if we hit currently selected weapon, start seachring from it, so we'll get "next weaker" weapon
3707 if (i
= FCurrWeap
) then curlidx
:= cwi
; // compare real, start from logical
3712 // slow down alterations a little
3715 // more than one weapon requested, assume "alteration", and check alteration delay
3716 if FNextWeapDelay
> 0 then
3718 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), TMsgType.Warning);
3724 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3725 // but clear all counters if no weapon should be switched
3732 //e_WriteLog(Format('*** wwc=%d; currweap=%d; logweap=%d', [wwc, FCurrWeap, curlidx]), TMsgType.Warning);
3734 // find next weapon to switch onto
3736 for i
:= 0 to High(weaponOrder
) do
3738 cwi
:= (cwi
+length(weaponOrder
)+1) mod length(weaponOrder
);
3739 if (cwi
= curlidx
) then continue
; // skip current weapon
3740 if not wantThisWeapon
[cwi
] then continue
;
3741 rwidx
:= weaponOrder
[cwi
];
3742 if (rwidx
< 0) then continue
;
3743 //e_WriteLog(Format(' trying logical %d (real %d); has=%d, hasammo=%d', [cwi, rwidx, Integer(FWeapon[rwidx]), Integer(hasAmmoForWeapon(rwidx))]), TMsgType.Warning);
3744 if FWeapon
[rwidx
] and ((wwc
= 1) or hasAmmoForWeapon(rwidx
)) then
3746 //e_WriteLog(' I FOUND HER!', TMsgType.Warning);
3748 result
:= Byte(rwidx
);
3750 FNextWeapDelay
:= 10; // anyway, 'cause why not
3755 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3759 procedure TPlayer
.RealizeCurrentWeapon();
3760 function switchAllowed (): Boolean;
3765 if FBFGFireCounter
<> -1 then
3767 if FTime
[T_SWITCH
] > gTime
then
3769 for i
:= WP_FIRST
to WP_LAST
do
3770 if FReloading
[i
] > 0 then
3778 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3779 //FNextWeap := FNextWeap and $1FFF;
3780 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3782 if not switchAllowed
then
3784 //HACK for weapon cycling
3785 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3789 nw
:= getNextWeaponIndex();
3790 if nw
= 255 then exit
; // don't reset anything here
3791 if nw
> High(FWeapon
) then
3793 // don't forget to reset queue here!
3794 //e_WriteLog(Format(' RealizeCurrentWeapon: WUTAFUUUU?! (%d)', [nw]), TMsgType.Warning);
3802 FTime
[T_SWITCH
] := gTime
+156;
3803 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3804 FModel
.SetWeapon(FCurrWeap
);
3805 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3809 procedure TPlayer
.NextWeapon();
3811 if g_Game_IsClient
then Exit
;
3815 procedure TPlayer
.PrevWeapon();
3817 if g_Game_IsClient
then Exit
;
3821 procedure TPlayer
.SetWeapon(W
: Byte);
3823 if FCurrWeap
<> W
then
3824 if W
= WEAPON_SAW
then
3825 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3828 FModel
.SetWeapon(CurrWeap
);
3832 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3834 function allowBerserkSwitching (): Boolean;
3836 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3838 if gBerserkAutoswitch
then exit
;
3839 if not conIsCheatsEnabled
then exit
;
3847 if g_Game_IsClient
then Exit
;
3849 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3850 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3855 if FHealth
< PLAYER_HP_SOFT
then
3857 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3861 if gFlash
= 2 then Inc(FPickup
, 5);
3865 if FHealth
< PLAYER_HP_SOFT
then
3867 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3871 if gFlash
= 2 then Inc(FPickup
, 5);
3875 if FArmor
< PLAYER_AP_SOFT
then
3877 FArmor
:= PLAYER_AP_SOFT
;
3880 if gFlash
= 2 then Inc(FPickup
, 5);
3884 if FArmor
< PLAYER_AP_LIMIT
then
3886 FArmor
:= PLAYER_AP_LIMIT
;
3889 if gFlash
= 2 then Inc(FPickup
, 5);
3893 if FHealth
< PLAYER_HP_LIMIT
then
3895 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3899 if gFlash
= 2 then Inc(FPickup
, 5);
3903 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3905 if FHealth
< PLAYER_HP_LIMIT
then
3906 FHealth
:= PLAYER_HP_LIMIT
;
3907 if FArmor
< PLAYER_AP_LIMIT
then
3908 FArmor
:= PLAYER_AP_LIMIT
;
3912 if gFlash
= 2 then Inc(FPickup
, 5);
3916 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3918 FWeapon
[WEAPON_SAW
] := True;
3920 if gFlash
= 2 then Inc(FPickup
, 5);
3921 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3924 ITEM_WEAPON_SHOTGUN1
:
3925 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3927 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3928 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3930 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3931 FWeapon
[WEAPON_SHOTGUN1
] := True;
3933 if gFlash
= 2 then Inc(FPickup
, 5);
3934 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3937 ITEM_WEAPON_SHOTGUN2
:
3938 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3940 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3942 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3943 FWeapon
[WEAPON_SHOTGUN2
] := True;
3945 if gFlash
= 2 then Inc(FPickup
, 5);
3946 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3949 ITEM_WEAPON_CHAINGUN
:
3950 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3952 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3954 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3955 FWeapon
[WEAPON_CHAINGUN
] := True;
3957 if gFlash
= 2 then Inc(FPickup
, 5);
3958 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3961 ITEM_WEAPON_ROCKETLAUNCHER
:
3962 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3964 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3966 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3967 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3969 if gFlash
= 2 then Inc(FPickup
, 5);
3970 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3974 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3976 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3978 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3979 FWeapon
[WEAPON_PLASMA
] := True;
3981 if gFlash
= 2 then Inc(FPickup
, 5);
3982 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3986 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3988 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3990 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3991 FWeapon
[WEAPON_BFG
] := True;
3993 if gFlash
= 2 then Inc(FPickup
, 5);
3994 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3997 ITEM_WEAPON_SUPERPULEMET
:
3998 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
4000 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
4002 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4003 FWeapon
[WEAPON_SUPERPULEMET
] := True;
4005 if gFlash
= 2 then Inc(FPickup
, 5);
4006 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4009 ITEM_WEAPON_FLAMETHROWER
:
4010 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
4012 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
4014 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4015 FWeapon
[WEAPON_FLAMETHROWER
] := True;
4017 if gFlash
= 2 then Inc(FPickup
, 5);
4018 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4022 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4024 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4027 if gFlash
= 2 then Inc(FPickup
, 5);
4030 ITEM_AMMO_BULLETS_BOX
:
4031 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4033 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4036 if gFlash
= 2 then Inc(FPickup
, 5);
4040 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4042 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4045 if gFlash
= 2 then Inc(FPickup
, 5);
4048 ITEM_AMMO_SHELLS_BOX
:
4049 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4051 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
4054 if gFlash
= 2 then Inc(FPickup
, 5);
4058 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4060 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4063 if gFlash
= 2 then Inc(FPickup
, 5);
4066 ITEM_AMMO_ROCKET_BOX
:
4067 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4069 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
4072 if gFlash
= 2 then Inc(FPickup
, 5);
4076 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4078 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4081 if gFlash
= 2 then Inc(FPickup
, 5);
4085 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4087 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4090 if gFlash
= 2 then Inc(FPickup
, 5);
4094 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4096 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4099 if gFlash
= 2 then Inc(FPickup
, 5);
4103 if not(R_ITEM_BACKPACK
in FRulez
) or
4104 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4105 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4106 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4107 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4108 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
4110 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4111 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4112 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4113 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4114 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4116 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4117 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4118 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4119 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4120 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4121 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4122 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4123 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4125 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
4128 if gFlash
= 2 then Inc(FPickup
, 5);
4132 if not(R_KEY_RED
in FRulez
) then
4134 Include(FRulez
, R_KEY_RED
);
4136 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4137 if gFlash
= 2 then Inc(FPickup
, 5);
4138 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4142 if not(R_KEY_GREEN
in FRulez
) then
4144 Include(FRulez
, R_KEY_GREEN
);
4146 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4147 if gFlash
= 2 then Inc(FPickup
, 5);
4148 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4152 if not(R_KEY_BLUE
in FRulez
) then
4154 Include(FRulez
, R_KEY_BLUE
);
4156 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4157 if gFlash
= 2 then Inc(FPickup
, 5);
4158 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4162 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4164 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4168 if gFlash
= 2 then Inc(FPickup
, 5);
4172 if FAir
< AIR_MAX
then
4177 if gFlash
= 2 then Inc(FPickup
, 5);
4182 if not (R_BERSERK
in FRulez
) then
4184 Include(FRulez
, R_BERSERK
);
4185 if allowBerserkSwitching
then
4187 FCurrWeap
:= WEAPON_KASTET
;
4189 FModel
.SetWeapon(WEAPON_KASTET
);
4194 if gFlash
= 2 then Inc(FPickup
, 5);
4196 FBerserk
:= gTime
+30000;
4201 if FHealth
< PLAYER_HP_SOFT
then
4203 FHealth
:= PLAYER_HP_SOFT
;
4204 FBerserk
:= gTime
+30000;
4212 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4214 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4217 if gFlash
= 2 then Inc(FPickup
, 5);
4221 if FHealth
< PLAYER_HP_LIMIT
then
4223 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4227 if gFlash
= 2 then Inc(FPickup
, 5);
4231 if FArmor
< PLAYER_AP_LIMIT
then
4233 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4236 if gFlash
= 2 then Inc(FPickup
, 5);
4240 if FJetFuel
< JET_MAX
then
4242 FJetFuel
:= JET_MAX
;
4245 if gFlash
= 2 then Inc(FPickup
, 5);
4249 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4251 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4254 if gFlash
= 2 then Inc(FPickup
, 5);
4259 procedure TPlayer
.Touch();
4263 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4266 // Áðîñèòü ôëàã òîâàðèùó:
4267 if gGameSettings
.GameMode
= GM_CTF
then
4272 procedure TPlayer
.Push(vx
, vy
: Integer);
4274 if (not FPhysics
) and FGhost
then
4276 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4277 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4278 if g_Game_IsNet
and g_Game_IsServer
then
4279 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4282 procedure TPlayer
.Reset(Force
: Boolean);
4288 FTime
[T_RESPAWN
] := 0;
4289 FTime
[T_FLAGCAP
] := 0;
4302 FSpectator
:= False;
4305 FSpectatePlayer
:= -1;
4306 FNoRespawn
:= False;
4308 FLives
:= gGameSettings
.MaxLives
;
4313 procedure TPlayer
.SoftReset();
4319 FBFGFireCounter
:= -1;
4327 SetAction(A_STAND
, True);
4330 function TPlayer
.GetRespawnPoint(): Byte;
4335 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4337 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4338 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4340 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4342 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4343 if Self
= gPlayer1
then
4344 c
:= RESPAWNPOINT_PLAYER1
4346 c
:= RESPAWNPOINT_PLAYER2
;
4347 if g_Map_GetPointCount(c
) > 0 then
4353 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4354 if Self
= gPlayer1
then
4355 c
:= RESPAWNPOINT_PLAYER2
4357 c
:= RESPAWNPOINT_PLAYER1
;
4358 if g_Map_GetPointCount(c
) > 0 then
4365 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4366 if Random(2) = 0 then
4367 c
:= RESPAWNPOINT_PLAYER1
4369 c
:= RESPAWNPOINT_PLAYER2
;
4370 if g_Map_GetPointCount(c
) > 0 then
4377 // Òî÷êà ëþáîé èç êîìàíä
4378 if Random(2) = 0 then
4379 c
:= RESPAWNPOINT_RED
4381 c
:= RESPAWNPOINT_BLUE
;
4382 if g_Map_GetPointCount(c
) > 0 then
4389 c
:= RESPAWNPOINT_DM
;
4390 if g_Map_GetPointCount(c
) > 0 then
4398 if gGameSettings
.GameMode
= GM_DM
then
4401 c
:= RESPAWNPOINT_DM
;
4402 if g_Map_GetPointCount(c
) > 0 then
4408 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4409 if Random(2) = 0 then
4410 c
:= RESPAWNPOINT_PLAYER1
4412 c
:= RESPAWNPOINT_PLAYER2
;
4413 if g_Map_GetPointCount(c
) > 0 then
4419 // Òî÷êà ëþáîé èç êîìàíä
4420 if Random(2) = 0 then
4421 c
:= RESPAWNPOINT_RED
4423 c
:= RESPAWNPOINT_BLUE
;
4424 if g_Map_GetPointCount(c
) > 0 then
4432 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4434 // Òî÷êà ñâîåé êîìàíäû
4435 c
:= RESPAWNPOINT_DM
;
4436 if FTeam
= TEAM_RED
then
4437 c
:= RESPAWNPOINT_RED
;
4438 if FTeam
= TEAM_BLUE
then
4439 c
:= RESPAWNPOINT_BLUE
;
4440 if g_Map_GetPointCount(c
) > 0 then
4447 c
:= RESPAWNPOINT_DM
;
4448 if g_Map_GetPointCount(c
) > 0 then
4454 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4455 if Random(2) = 0 then
4456 c
:= RESPAWNPOINT_PLAYER1
4458 c
:= RESPAWNPOINT_PLAYER2
;
4459 if g_Map_GetPointCount(c
) > 0 then
4465 // Òî÷êà äðóãîé êîìàíäû
4466 c
:= RESPAWNPOINT_DM
;
4467 if FTeam
= TEAM_RED
then
4468 c
:= RESPAWNPOINT_BLUE
;
4469 if FTeam
= TEAM_BLUE
then
4470 c
:= RESPAWNPOINT_RED
;
4471 if g_Map_GetPointCount(c
) > 0 then
4479 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4481 RespawnPoint
: TRespawnPoint
;
4487 FBFGFireCounter
:= -1;
4492 if not g_Game_IsServer
then
4496 FWantsInGame
:= True;
4497 FJustTeleported
:= True;
4500 FTime
[T_RESPAWN
] := 0;
4504 // if server changes MaxLives we gotta be ready
4505 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4507 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4508 if FTime
[T_RESPAWN
] > gTime
then
4511 // Ïðîñðàë âñå æèçíè:
4514 if not FSpectator
then Spectate(True);
4515 FWantsInGame
:= True;
4519 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4520 begin // "Ñâîÿ èãðà"
4521 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4522 FRulez
:= FRulez
-[R_BERSERK
];
4524 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4526 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4527 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4530 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4531 c
:= GetRespawnPoint();
4536 // Âîñêðåøåíèå áåç îðóæèÿ:
4539 FHealth
:= PLAYER_HP_SOFT
;
4545 for a
:= WP_FIRST
to WP_LAST
do
4547 FWeapon
[a
] := False;
4551 FWeapon
[WEAPON_PISTOL
] := True;
4552 FWeapon
[WEAPON_KASTET
] := True;
4553 FCurrWeap
:= WEAPON_PISTOL
;
4556 FModel
.SetWeapon(FCurrWeap
);
4558 for b
:= A_BULLETS
to A_HIGH
do
4561 FAmmo
[A_BULLETS
] := 50;
4563 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4564 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4565 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4566 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4567 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4569 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4570 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4575 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4576 if not g_Map_GetPoint(c
, RespawnPoint
) then
4578 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4582 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4583 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4584 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4590 FDirection
:= RespawnPoint
.Direction
;
4591 if FDirection
= TDirection
.D_LEFT
then
4596 SetAction(A_STAND
, True);
4597 FModel
.Direction
:= FDirection
;
4599 for a
:= Low(FTime
) to High(FTime
) do
4602 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4607 FCanJetpack
:= False;
4612 // Àíèìàöèÿ âîçðîæäåíèÿ:
4613 if (not gLoadGameMode
) and (not Silent
) then
4614 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4616 Anim
:= TAnimation
.Create(ID
, False, 3);
4617 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4618 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4622 FSpectator
:= False;
4625 FSpectatePlayer
:= -1;
4628 if (gPlayer1
= nil) and (gLMSPID1
= FUID
) then
4630 if (gPlayer2
= nil) and (gLMSPID2
= FUID
) then
4633 if g_Game_IsNet
then
4635 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4636 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4638 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4639 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4644 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4647 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4648 else if (not NoMove
) then
4650 GameX
:= gMapInfo
.Width
div 2;
4651 GameY
:= gMapInfo
.Height
div 2;
4660 FWantsInGame
:= False;
4665 if Self
= gPlayer1
then
4670 if Self
= gPlayer2
then
4677 if g_Game_IsNet
then
4678 MH_SEND_PlayerStats(FUID
);
4681 procedure TPlayer
.SwitchNoClip
;
4685 FGhost
:= not FGhost
;
4686 FPhysics
:= not FGhost
;
4698 procedure TPlayer
.Run(Direction
: TDirection
);
4702 if MAX_RUNVEL
> 8 then
4706 if Direction
= TDirection
.D_LEFT
then
4708 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4709 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4712 if FObj
.Vel
.X
< MAX_RUNVEL
then
4713 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4715 // Âîçìîæíî, ïèíàåì êóñêè:
4716 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4718 b
:= Abs(FObj
.Vel
.X
);
4719 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4720 for a
:= 0 to High(gGibs
) do
4722 if gGibs
[a
].alive
and
4723 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4724 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4727 if FObj
.Vel
.X
< 0 then
4729 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4733 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4735 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4743 procedure TPlayer
.SeeDown();
4745 SetAction(A_SEEDOWN
);
4747 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4749 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4752 procedure TPlayer
.SeeUp();
4756 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4758 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4761 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4769 A_ATTACK
: Prior
:= 2;
4770 A_SEEUP
: Prior
:= 1;
4771 A_SEEDOWN
: Prior
:= 1;
4772 A_ATTACKUP
: Prior
:= 2;
4773 A_ATTACKDOWN
: Prior
:= 2;
4778 if (Prior
> FActionPrior
) or Force
then
4779 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4781 FActionPrior
:= Prior
;
4782 FActionAnim
:= Action
;
4783 FActionForce
:= Force
;
4784 FActionChanged
:= True;
4787 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4790 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4792 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4793 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4794 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4795 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4798 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4805 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4807 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4808 if g_Game_IsServer
and g_Game_IsNet
then
4809 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4813 FJustTeleported
:= True;
4818 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4820 Anim
:= TAnimation
.Create(ID
, False, 3);
4823 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4824 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4825 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4826 if g_Game_IsServer
and g_Game_IsNet
then
4827 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4828 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4832 FObj
.X
:= X
-PLAYER_RECT
.X
;
4833 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4834 if FAlive
and FGhost
then
4840 if not g_Game_IsNet
then
4844 SetDirection(TDirection
.D_LEFT
);
4850 SetDirection(TDirection
.D_RIGHT
);
4856 if FDirection
= TDirection
.D_RIGHT
then
4858 SetDirection(TDirection
.D_LEFT
);
4863 SetDirection(TDirection
.D_RIGHT
);
4869 if not silent
and (Anim
<> nil) then
4871 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4872 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4875 if g_Game_IsServer
and g_Game_IsNet
then
4876 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4877 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4884 function nonz(a
: Single): Single;
4892 function TPlayer
.followCorpse(): Boolean;
4897 if FAlive
or FSpectator
then
4899 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
4901 for i
:= 0 to High(gCorpses
) do
4902 if gCorpses
[i
] <> nil then
4903 if gCorpses
[i
].FPlayerUID
= FUID
then
4906 FObj
.X
:= gCorpses
[i
].FObj
.X
;
4907 FObj
.Y
:= gCorpses
[i
].FObj
.Y
;
4908 FObj
.Vel
.X
:= gCorpses
[i
].FObj
.Vel
.X
;
4909 FObj
.Vel
.Y
:= gCorpses
[i
].FObj
.Vel
.Y
;
4910 FObj
.Accel
.X
:= gCorpses
[i
].FObj
.Accel
.X
;
4911 FObj
.Accel
.Y
:= gCorpses
[i
].FObj
.Accel
.Y
;
4916 procedure TPlayer
.Update();
4919 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4920 blockmon
, headwater
, dospawn
: Boolean;
4925 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4926 AnyServer
:= g_Game_IsServer
;
4928 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4929 DoLerp(NetInterpLevel
+ 1)
4935 if FClientID
>= 0 then
4937 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4938 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4939 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4948 if FAlive
and (FPunchAnim
<> nil) then
4949 FPunchAnim
.Update();
4951 if FAlive
and (gFly
or FJetpack
) then
4954 if FDirection
= TDirection
.D_LEFT
then
4959 if FAlive
and (not FGhost
) then
4961 if FKeys
[KEY_UP
].Pressed
then
4963 if FKeys
[KEY_DOWN
].Pressed
then
4967 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4970 i
:= g_basic
.Sign(FIncCam
);
4971 FIncCam
:= Abs(FIncCam
);
4972 DecMin(FIncCam
, 5, 0);
4973 FIncCam
:= FIncCam
*i
;
4976 // no need to do that each second frame, weapon queue will take care of it
4977 if FAlive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4978 if FAlive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4980 if gTime
mod (GAME_TICK
*2) <> 0 then
4982 if (FObj
.Vel
.X
= 0) and FAlive
then
4984 if FKeys
[KEY_LEFT
].Pressed
then
4985 Run(TDirection
.D_LEFT
);
4986 if FKeys
[KEY_RIGHT
].Pressed
then
4987 Run(TDirection
.D_RIGHT
);
4992 if not followCorpse() then
4993 g_Obj_Move(@FObj
, True, True, True);
4994 positionChanged(); // this updates spatial accelerators
5000 FActionChanged
:= False;
5004 // Let alive player do some actions
5005 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
5006 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
5007 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
5008 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
5009 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
5010 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
5011 if FKeys
[KEY_JUMP
].Pressed
then Jump()
5014 if AnyServer
and FJetpack
then
5018 if NetServer
then MH_SEND_PlayerStats(FUID
);
5020 FCanJetpack
:= True;
5027 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
5029 if FKeys
[k
].Pressed
then
5037 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5040 if (FTime
[T_RESPAWN
] <= gTime
) and
5041 gGameOn
and (not FAlive
) then
5043 if (g_Player_GetCount() > 1) then
5047 gExit
:= EXIT_RESTART
;
5052 // Dead spectator actions
5055 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
5056 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
5060 if (FSpectatePlayer
>= High(gPlayers
)) then
5061 FSpectatePlayer
:= -1
5065 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
5066 if gPlayers
[I
] <> nil then
5067 if gPlayers
[I
].alive
then
5068 if gPlayers
[I
].UID
<> FUID
then
5070 FSpectatePlayer
:= I
;
5075 if not SetSpect
then FSpectatePlayer
:= -1;
5086 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5088 FYTo
:= FObj
.Y
- 32;
5089 FSpectatePlayer
:= -1;
5091 if FKeys
[KEY_DOWN
].Pressed
then
5093 FYTo
:= FObj
.Y
+ 32;
5094 FSpectatePlayer
:= -1;
5096 if FKeys
[KEY_LEFT
].Pressed
then
5098 FXTo
:= FObj
.X
- 32;
5099 FSpectatePlayer
:= -1;
5101 if FKeys
[KEY_RIGHT
].Pressed
then
5103 FXTo
:= FObj
.X
+ 32;
5104 FSpectatePlayer
:= -1;
5107 if (FXTo
< -64) then
5109 else if (FXTo
> gMapInfo
.Width
+ 32) then
5110 FXTo
:= gMapInfo
.Width
+ 32;
5111 if (FYTo
< -72) then
5113 else if (FYTo
> gMapInfo
.Height
+ 32) then
5114 FYTo
:= gMapInfo
.Height
+ 32;
5119 if not followCorpse() then
5120 g_Obj_Move(@FObj
, True, True, True);
5121 positionChanged(); // this updates spatial accelerators
5128 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5129 if gPlayers
[FSpectatePlayer
] <> nil then
5130 if gPlayers
[FSpectatePlayer
].alive
then
5132 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
5133 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
5137 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5138 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5139 PANEL_BLOCKMON
, True);
5140 headwater
:= HeadInLiquid(0, 0);
5142 // Ñîïðîòèâëåíèå âîçäóõà:
5143 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5144 if FObj
.Vel
.X
<> 0 then
5145 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5147 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5148 DecMin(FPain
, 5, 0);
5149 DecMin(FPickup
, 1, 0);
5151 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5153 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5154 FMegaRulez
[MR_SUIT
] := 0;
5155 FMegaRulez
[MR_INVUL
] := 0;
5156 FMegaRulez
[MR_INVIS
] := 0;
5157 Kill(K_FALLKILL
, 0, HIT_FALL
);
5164 if FCurrWeap
= WEAPON_SAW
then
5165 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5166 FSawSoundSelect
.IsPlaying()) then
5167 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5170 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5171 (not FJetSoundOff
.IsPlaying()) then
5173 FJetSoundFly
.SetPosition(0);
5174 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5177 for b
:= WP_FIRST
to WP_LAST
do
5178 if FReloading
[b
] > 0 then
5184 if FShellTimer
> -1 then
5185 if FShellTimer
= 0 then
5187 if FShellType
= SHELL_SHELL
then
5188 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5189 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5190 else if FShellType
= SHELL_DBLSHELL
then
5192 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5193 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5194 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5195 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5198 end else Dec(FShellTimer
);
5200 if (FBFGFireCounter
> -1) then
5201 if FBFGFireCounter
= 0 then
5205 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5206 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5207 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5208 yd
:= wy
+firediry();
5209 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5210 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5211 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5212 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5213 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5216 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5217 FBFGFireCounter
:= -1;
5220 FBFGFireCounter
:= 0
5222 Dec(FBFGFireCounter
);
5224 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5226 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5228 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5231 if (headwater
or blockmon
) then
5237 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5240 else if (FAir
mod 31 = 0) and not blockmon
then
5242 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5243 if Random(2) = 0 then
5244 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5246 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5248 end else if FAir
< AIR_DEF
then
5251 if FFireTime
> 0 then
5253 if BodyInLiquid(0, 0) then
5258 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5260 if FMegaRulez
[MR_SUIT
] = gTime
then
5267 if FFirePainTime
<= 0 then
5269 if g_Game_IsServer
then
5270 Damage(5, FFireAttacker
, 0, 0, HIT_FLAME
);
5271 FFirePainTime
:= 18;
5273 FFirePainTime
:= FFirePainTime
- 1;
5274 FFireTime
:= FFireTime
- 1;
5275 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5276 MH_SEND_PlayerStats(FUID
);
5280 if FDamageBuffer
> 0 then
5282 if FDamageBuffer
>= 9 then
5286 if FDamageBuffer
< 30 then i
:= 9
5287 else if FDamageBuffer
< 100 then i
:= 18
5291 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5292 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5293 FHealth
:= FHealth
-ii
;
5296 FHealth
:= FHealth
+FArmor
;
5301 if FHealth
<= 0 then
5302 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5303 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5304 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5308 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5309 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5310 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5311 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5318 end; // if FAlive then ...
5320 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5322 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5323 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5324 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5325 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5327 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5328 then SetAction(A_STAND
, True);
5330 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5332 for b
:= Low(FKeys
) to High(FKeys
) do
5333 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5337 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5339 x
:= FObj
.X
+PLAYER_RECT
.X
;
5340 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5341 w
:= PLAYER_RECT
.Width
;
5342 h
:= PLAYER_RECT
.Height
;
5346 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5348 if (dx
<> 0) or (dy
<> 0) then
5357 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5359 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5360 FObj
.Y
+PLAYER_RECT
.Y
,
5367 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5369 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5370 FObj
.Y
+PLAYER_RECT
.Y
,
5374 Panel
.Width
, Panel
.Height
);
5377 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5379 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5380 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5381 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5382 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5385 function g_Player_ValidName(Name
: string): Boolean;
5391 if gPlayers
= nil then Exit
;
5393 for a
:= 0 to High(gPlayers
) do
5394 if gPlayers
[a
] <> nil then
5395 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5402 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5406 d
:= FModel
.Direction
;
5408 FModel
.Direction
:= Direction
;
5409 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5411 FDirection
:= Direction
;
5414 function TPlayer
.GetKeys(): Byte;
5418 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5419 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5420 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5422 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5423 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5426 procedure TPlayer
.Use();
5430 if FTime
[T_USE
] > gTime
then Exit
;
5432 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5433 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5435 for a
:= 0 to High(gPlayers
) do
5436 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5437 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5438 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5439 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5441 gPlayers
[a
].Touch();
5442 if g_Game_IsNet
and g_Game_IsServer
then
5443 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5446 FTime
[T_USE
] := gTime
+120;
5449 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5453 WX
, WY
, XD
, YD
: Integer;
5465 if R_BERSERK
in FRulez
then
5467 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5468 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5469 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5472 locobj
.rect
.Width
:= 39;
5473 locobj
.rect
.Height
:= 52;
5474 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5475 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5476 locobj
.Accel
.X
:= xd
-wx
;
5477 locobj
.Accel
.y
:= yd
-wy
;
5479 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5480 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5482 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5486 FPain
:= min(FPain
+ 25, 50);
5488 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5493 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5494 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5496 FSawSoundSelect
.Stop();
5498 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5500 else if not FSawSoundHit
.IsPlaying() then
5502 FSawSoundSelect
.Stop();
5503 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5510 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5511 FFireAngle
:= FAngle
;
5513 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5514 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5519 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5520 FFireAngle
:= FAngle
;
5523 FShellType
:= SHELL_SHELL
;
5528 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5529 FFireAngle
:= FAngle
;
5532 FShellType
:= SHELL_DBLSHELL
;
5537 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5538 FFireAngle
:= FAngle
;
5540 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5541 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5544 WEAPON_ROCKETLAUNCHER
:
5546 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5547 FFireAngle
:= FAngle
;
5553 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5554 FFireAngle
:= FAngle
;
5560 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5561 FFireAngle
:= FAngle
;
5565 WEAPON_SUPERPULEMET
:
5567 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5568 FFireAngle
:= FAngle
;
5570 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5571 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5574 WEAPON_FLAMETHROWER
:
5576 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5577 FFireAngle
:= FAngle
;
5584 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5585 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5586 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5589 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5591 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5592 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5595 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5599 if NetInterpLevel
< 1 then
5609 AX
:= Abs(FXTo
- FObj
.X
);
5610 AY
:= Abs(FYTo
- FObj
.Y
);
5611 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5613 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5618 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5620 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5621 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5622 PANEL_LIFTUP
, False) then Result
:= -1
5624 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5625 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5626 PANEL_LIFTDOWN
, False) then Result
:= 1
5630 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5637 if Flag
= FLAG_NONE
then
5640 if not g_Game_IsServer
then Exit
;
5642 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5643 if (Flag
= FTeam
) and
5644 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5645 (FFlag
<> FLAG_NONE
) then
5647 if FFlag
= FLAG_RED
then
5648 s
:= _lc
[I_PLAYER_FLAG_RED
]
5650 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5652 evtype
:= FLAG_STATE_SCORED
;
5654 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5655 Insert('.', ts
, Length(ts
) + 1 - 3);
5656 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5658 g_Map_ResetFlag(FFlag
);
5659 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5661 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5664 if g_Game_IsNet
then
5666 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5670 gFlags
[FFlag
].CaptureTime
:= 0;
5675 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5676 if (Flag
= FTeam
) and
5677 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5679 if Flag
= FLAG_RED
then
5680 s
:= _lc
[I_PLAYER_FLAG_RED
]
5682 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5684 evtype
:= FLAG_STATE_RETURNED
;
5685 gFlags
[Flag
].CaptureTime
:= 0;
5687 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5689 g_Map_ResetFlag(Flag
);
5690 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5693 if g_Game_IsNet
then
5695 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5701 // Ïîäîáðàë ÷óæîé ôëàã:
5702 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5706 if Flag
= FLAG_RED
then
5707 s
:= _lc
[I_PLAYER_FLAG_RED
]
5709 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5711 evtype
:= FLAG_STATE_CAPTURED
;
5713 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5715 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5717 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5720 if g_Game_IsNet
then
5722 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5728 procedure TPlayer
.SetFlag(Flag
: Byte);
5731 if FModel
<> nil then
5732 FModel
.SetFlag(FFlag
);
5735 function TPlayer
.DropFlag(): Boolean;
5740 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5742 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5743 with gFlags
[FFlag
] do
5747 Direction
:= FDirection
;
5748 State
:= FLAG_STATE_DROPPED
;
5750 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5751 (FObj
.Vel
.Y
div 2)-2+Random(5));
5752 positionChanged(); // this updates spatial accelerators
5754 if FFlag
= FLAG_RED
then
5755 s
:= _lc
[I_PLAYER_FLAG_RED
]
5757 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5759 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5760 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5762 if g_Game_IsNet
then
5763 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5769 procedure TPlayer
.GetSecret();
5774 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5776 Assert(Key
<= High(FKeys
));
5778 FKeys
[Key
].Pressed
:= True;
5779 FKeys
[Key
].Time
:= Time
;
5782 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5784 Result
:= FKeys
[K
].Pressed
;
5787 procedure TPlayer
.ReleaseKeys();
5791 for a
:= Low(FKeys
) to High(FKeys
) do
5793 FKeys
[a
].Pressed
:= False;
5798 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5802 function TPlayer
.firediry(): Integer;
5804 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5805 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5809 procedure TPlayer
.RememberState();
5813 FSavedState
.Health
:= FHealth
;
5814 FSavedState
.Armor
:= FArmor
;
5815 FSavedState
.Air
:= FAir
;
5816 FSavedState
.JetFuel
:= FJetFuel
;
5817 FSavedState
.CurrWeap
:= FCurrWeap
;
5818 FSavedState
.NextWeap
:= FNextWeap
;
5819 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5822 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5824 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5826 FSavedState
.Rulez
:= FRulez
;
5827 FSavedState
.WaitRecall
:= True;
5830 procedure TPlayer
.RecallState();
5834 if not FSavedState
.WaitRecall
then Exit
;
5836 FHealth
:= FSavedState
.Health
;
5837 FArmor
:= FSavedState
.Armor
;
5838 FAir
:= FSavedState
.Air
;
5839 FJetFuel
:= FSavedState
.JetFuel
;
5840 FCurrWeap
:= FSavedState
.CurrWeap
;
5841 FNextWeap
:= FSavedState
.NextWeap
;
5842 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5845 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5847 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5849 FRulez
:= FSavedState
.Rulez
;
5850 FSavedState
.WaitRecall
:= False;
5852 if gGameSettings
.GameType
= GT_SERVER
then
5853 MH_SEND_PlayerStats(FUID
);
5856 procedure TPlayer
.SaveState (st
: TStream
);
5862 utils
.writeSign(st
, 'PLYR');
5863 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
5865 utils
.writeBool(st
, FIamBot
);
5867 utils
.writeInt(st
, Word(FUID
));
5869 utils
.writeStr(st
, FName
);
5871 utils
.writeInt(st
, Byte(FTeam
));
5873 utils
.writeBool(st
, FAlive
);
5874 // Èçðàñõîäîâàë ëè âñå æèçíè
5875 utils
.writeBool(st
, FNoRespawn
);
5877 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
5878 utils
.writeInt(st
, Byte(b
));
5880 utils
.writeInt(st
, LongInt(FHealth
));
5882 utils
.writeInt(st
, Byte(FLives
));
5884 utils
.writeInt(st
, LongInt(FArmor
));
5886 utils
.writeInt(st
, LongInt(FAir
));
5888 utils
.writeInt(st
, LongInt(FJetFuel
));
5890 utils
.writeInt(st
, LongInt(FPain
));
5892 utils
.writeInt(st
, LongInt(FKills
));
5894 utils
.writeInt(st
, LongInt(FMonsterKills
));
5896 utils
.writeInt(st
, LongInt(FFrags
));
5898 utils
.writeInt(st
, Byte(FFragCombo
));
5899 // Âðåìÿ ïîñëåäíåãî ôðàãà
5900 utils
.writeInt(st
, LongWord(FLastFrag
));
5902 utils
.writeInt(st
, LongInt(FDeath
));
5904 utils
.writeInt(st
, Byte(FFlag
));
5906 utils
.writeInt(st
, LongInt(FSecrets
));
5908 utils
.writeInt(st
, Byte(FCurrWeap
));
5910 utils
.writeInt(st
, Word(FNextWeap
));
5912 utils
.writeInt(st
, Byte(FNextWeapDelay
));
5913 // Âðåìÿ çàðÿäêè BFG
5914 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
5916 utils
.writeInt(st
, LongInt(FDamageBuffer
));
5917 // Ïîñëåäíèé óäàðèâøèé
5918 utils
.writeInt(st
, Word(FLastSpawnerUID
));
5919 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
5920 utils
.writeInt(st
, Byte(FLastHit
));
5922 Obj_SaveState(st
, @FObj
);
5923 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
5924 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
5925 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
5926 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
5928 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
5929 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
5930 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
5932 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
5933 // Íàëè÷èå êðàñíîãî êëþ÷à
5934 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
5935 // Íàëè÷èå çåëåíîãî êëþ÷à
5936 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
5937 // Íàëè÷èå ñèíåãî êëþ÷à
5938 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
5940 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
5941 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
5942 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
5943 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
5944 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
5946 utils
.writeStr(st
, FModel
.Name
);
5948 utils
.writeInt(st
, Byte(FColor
.R
));
5949 utils
.writeInt(st
, Byte(FColor
.G
));
5950 utils
.writeInt(st
, Byte(FColor
.B
));
5954 procedure TPlayer
.LoadState (st
: TStream
);
5963 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
5964 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
5966 FIamBot
:= utils
.readBool(st
);
5968 FUID
:= utils
.readWord(st
);
5970 str
:= utils
.readStr(st
);
5971 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
5973 FTeam
:= utils
.readByte(st
);
5975 FAlive
:= utils
.readBool(st
);
5976 // Èçðàñõîäîâàë ëè âñå æèçíè
5977 FNoRespawn
:= utils
.readBool(st
);
5979 b
:= utils
.readByte(st
);
5980 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
5982 FHealth
:= utils
.readLongInt(st
);
5984 FLives
:= utils
.readByte(st
);
5986 FArmor
:= utils
.readLongInt(st
);
5988 FAir
:= utils
.readLongInt(st
);
5990 FJetFuel
:= utils
.readLongInt(st
);
5992 FPain
:= utils
.readLongInt(st
);
5994 FKills
:= utils
.readLongInt(st
);
5996 FMonsterKills
:= utils
.readLongInt(st
);
5998 FFrags
:= utils
.readLongInt(st
);
6000 FFragCombo
:= utils
.readByte(st
);
6001 // Âðåìÿ ïîñëåäíåãî ôðàãà
6002 FLastFrag
:= utils
.readLongWord(st
);
6004 FDeath
:= utils
.readLongInt(st
);
6006 FFlag
:= utils
.readByte(st
);
6008 FSecrets
:= utils
.readLongInt(st
);
6010 FCurrWeap
:= utils
.readByte(st
);
6012 FNextWeap
:= utils
.readWord(st
);
6014 FNextWeapDelay
:= utils
.readByte(st
);
6015 // Âðåìÿ çàðÿäêè BFG
6016 FBFGFireCounter
:= utils
.readSmallInt(st
);
6018 FDamageBuffer
:= utils
.readLongInt(st
);
6019 // Ïîñëåäíèé óäàðèâøèé
6020 FLastSpawnerUID
:= utils
.readWord(st
);
6021 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6022 FLastHit
:= utils
.readByte(st
);
6024 Obj_LoadState(@FObj
, st
);
6025 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6026 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
6027 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6028 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
6030 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
6031 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6032 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
6034 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
6035 // Íàëè÷èå êðàñíîãî êëþ÷à
6036 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
6037 // Íàëè÷èå çåëåíîãî êëþ÷à
6038 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
6039 // Íàëè÷èå ñèíåãî êëþ÷à
6040 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
6042 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
6043 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6044 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
6045 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6046 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
6048 str
:= utils
.readStr(st
);
6050 FColor
.R
:= utils
.readByte(st
);
6051 FColor
.G
:= utils
.readByte(st
);
6052 FColor
.B
:= utils
.readByte(st
);
6053 if (self
= gPlayer1
) then
6055 str
:= gPlayer1Settings
.Model
;
6056 FColor
:= gPlayer1Settings
.Color
;
6058 else if (self
= gPlayer2
) then
6060 str
:= gPlayer2Settings
.Model
;
6061 FColor
:= gPlayer2Settings
.Color
;
6063 // Îáíîâëÿåì ìîäåëü èãðîêà
6065 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
6066 FModel
.Color
:= TEAMCOLOR
[FTeam
]
6068 FModel
.Color
:= FColor
;
6072 procedure TPlayer
.AllRulez(Health
: Boolean);
6078 FHealth
:= PLAYER_HP_LIMIT
;
6079 FArmor
:= PLAYER_AP_LIMIT
;
6083 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
6084 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
6085 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6088 procedure TPlayer
.RestoreHealthArmor();
6090 FHealth
:= PLAYER_HP_LIMIT
;
6091 FArmor
:= PLAYER_AP_LIMIT
;
6094 procedure TPlayer
.FragCombo();
6098 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6100 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6102 if FFragCombo
< 5 then
6104 Param
:= FUID
or (FFragCombo
shl 16);
6105 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6106 (FComboEvnt
<= High(gDelayedEvents
)) and
6107 gDelayedEvents
[FComboEvnt
].Pending
and
6108 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6109 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6111 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6112 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6115 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6123 procedure TPlayer
.GiveItem(ItemType
: Byte);
6127 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6129 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6133 if FAir
< AIR_MAX
then
6140 if not (R_BERSERK
in FRulez
) then
6142 Include(FRulez
, R_BERSERK
);
6143 if FBFGFireCounter
< 1 then
6145 FCurrWeap
:= WEAPON_KASTET
;
6147 FModel
.SetWeapon(WEAPON_KASTET
);
6151 FBerserk
:= gTime
+30000;
6153 if FHealth
< PLAYER_HP_SOFT
then
6155 FHealth
:= PLAYER_HP_SOFT
;
6156 FBerserk
:= gTime
+30000;
6161 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6163 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6167 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6169 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6173 if FJetFuel
< JET_MAX
then
6175 FJetFuel
:= JET_MAX
;
6178 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6179 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6181 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6182 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6184 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6186 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6188 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6189 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6192 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6193 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6194 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6195 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6196 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6197 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6198 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6199 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6200 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6202 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6203 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6204 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6205 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6206 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6207 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6208 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6209 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6210 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6213 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6214 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6215 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6216 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6217 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6219 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6220 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6221 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6222 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6223 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6225 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6226 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6227 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6228 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6230 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6233 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6234 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6235 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6237 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6238 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6243 if g_Game_IsNet
and g_Game_IsServer
then
6244 MH_SEND_PlayerStats(FUID
);
6247 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6252 if (Random(5) = 1) and (Times
= 1) then
6255 if BodyInLiquid(0, 0) then
6257 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6258 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6259 if Random(2) = 0 then
6260 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6262 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6266 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6268 for i
:= 1 to Times
do
6270 Anim
:= TAnimation
.Create(id
, False, 3);
6272 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6273 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6279 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6284 if (Random(10) = 1) and (Times
= 1) then
6287 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6289 for i
:= 1 to Times
do
6291 Anim
:= TAnimation
.Create(id
, False, 3);
6293 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6294 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6300 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6302 FSawSound
.Pause(Enable
);
6303 FSawSoundIdle
.Pause(Enable
);
6304 FSawSoundHit
.Pause(Enable
);
6305 FSawSoundSelect
.Pause(Enable
);
6310 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6315 FObj
.Rect
:= PLAYER_CORPSERECT
;
6316 FModelName
:= ModelName
;
6321 FState
:= CORPSE_STATE_MESS
;
6322 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6326 FState
:= CORPSE_STATE_NORMAL
;
6327 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6331 destructor TCorpse
.Destroy();
6338 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6340 procedure TCorpse
.positionChanged (); inline; begin end;
6342 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6344 if (dx
<> 0) or (dy
<> 0) then
6353 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6355 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6356 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6357 w
:= PLAYER_CORPSERECT
.Width
;
6358 h
:= PLAYER_CORPSERECT
.Height
;
6362 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6367 if FState
= CORPSE_STATE_REMOVEME
then
6370 FDamage
:= FDamage
+ Value
;
6372 if FDamage
> 150 then
6374 if FAnimation
<> nil then
6379 FState
:= CORPSE_STATE_REMOVEME
;
6381 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6382 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6383 FModelName
, FColor
);
6384 // Çâóê ìÿñà îò òðóïà:
6385 pm
:= g_PlayerModel_Get(FModelName
);
6386 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6390 if (gBodyKillEvent
<> -1)
6391 and gDelayedEvents
[gBodyKillEvent
].Pending
then
6392 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
6393 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, 0);
6398 Blood
:= g_PlayerModel_GetBlood(FModelName
);
6399 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6400 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6401 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6402 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6403 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6404 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
6408 procedure TCorpse
.Draw();
6410 if FState
= CORPSE_STATE_REMOVEME
then
6413 if FAnimation
<> nil then
6414 FAnimation
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6416 if FAnimationMask
<> nil then
6419 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6426 procedure TCorpse
.Update();
6430 if FState
= CORPSE_STATE_REMOVEME
then
6433 if gTime
mod (GAME_TICK
*2) <> 0 then
6435 g_Obj_Move(@FObj
, True, True, True);
6436 positionChanged(); // this updates spatial accelerators
6440 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6441 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6443 st
:= g_Obj_Move(@FObj
, True, True, True);
6444 positionChanged(); // this updates spatial accelerators
6446 if WordBool(st
and MOVE_FALLOUT
) then
6448 FState
:= CORPSE_STATE_REMOVEME
;
6452 if FAnimation
<> nil then
6453 FAnimation
.Update();
6454 if FAnimationMask
<> nil then
6455 FAnimationMask
.Update();
6459 procedure TCorpse
.SaveState (st
: TStream
);
6466 utils
.writeSign(st
, 'CORP');
6467 utils
.writeInt(st
, Byte(0));
6469 utils
.writeInt(st
, Byte(FState
));
6471 utils
.writeInt(st
, Byte(FDamage
));
6473 utils
.writeInt(st
, Byte(FColor
.R
));
6474 utils
.writeInt(st
, Byte(FColor
.G
));
6475 utils
.writeInt(st
, Byte(FColor
.B
));
6477 Obj_SaveState(st
, @FObj
);
6478 utils
.writeInt(st
, Word(FPlayerUID
));
6480 anim
:= (FAnimation
<> nil);
6481 utils
.writeBool(st
, anim
);
6482 // Åñëè åñòü - ñîõðàíÿåì
6483 if anim
then FAnimation
.SaveState(st
);
6484 // Åñòü ëè ìàñêà àíèìàöèè
6485 anim
:= (FAnimationMask
<> nil);
6486 utils
.writeBool(st
, anim
);
6487 // Åñëè åñòü - ñîõðàíÿåì
6488 if anim
then FAnimationMask
.SaveState(st
);
6492 procedure TCorpse
.LoadState (st
: TStream
);
6499 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6500 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6502 FState
:= utils
.readByte(st
);
6504 FDamage
:= utils
.readByte(st
);
6506 FColor
.R
:= utils
.readByte(st
);
6507 FColor
.G
:= utils
.readByte(st
);
6508 FColor
.B
:= utils
.readByte(st
);
6510 Obj_LoadState(@FObj
, st
);
6511 FPlayerUID
:= utils
.readWord(st
);
6513 anim
:= utils
.readBool(st
);
6514 // Åñëè åñòü - çàãðóæàåì
6517 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6518 FAnimation
.LoadState(st
);
6520 // Åñòü ëè ìàñêà àíèìàöèè
6521 anim
:= utils
.readBool(st
);
6522 // Åñëè åñòü - çàãðóæàåì
6525 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6526 FAnimationMask
.LoadState(st
);
6532 constructor TBot
.Create();
6539 FSpectator
:= False;
6546 for a
:= WP_FIRST
to WP_LAST
do
6548 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6549 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6550 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6554 destructor TBot
.Destroy();
6557 inherited Destroy();
6560 procedure TBot
.Draw();
6564 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6565 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6568 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6570 inherited Respawn(Silent
, Force
);
6573 FSelectedWeapon
:= FCurrWeap
;
6578 procedure TBot
.UpdateCombat();
6591 TTargetRecord
= array of TTarget
;
6593 function Compare(a
, b
: TTarget
): Integer;
6595 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6598 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6600 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6601 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6603 if a
.Dist
> b
.Dist
then // B áëèæå
6605 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6608 else // Ñòðàííî -> A
6613 a
, x1
, y1
, x2
, y2
: Integer;
6614 targets
: TTargetRecord
;
6616 Target
, BestTarget
: TTarget
;
6617 firew
, fireh
: Integer;
6621 vsPlayer
, vsMonster
, ok
: Boolean;
6624 function monsUpdate (mon
: TMonster
): Boolean;
6626 result
:= false; // don't stop
6627 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6629 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6631 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6632 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6634 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6635 if g_TraceVector(x1
, y1
, x2
, y2
) then
6637 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6638 SetLength(targets
, Length(targets
)+1);
6639 with targets
[High(targets
)] do
6646 Rect
:= mon
.Obj
.Rect
;
6647 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6648 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6649 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6658 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6659 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6661 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6662 if FCurrWeap
<> FSelectedWeapon
then
6665 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6666 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6668 RemoveAIFlag('NEEDFIRE');
6671 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6672 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6673 else PressKey(KEY_FIRE
);
6677 // Êîîðäèíàòû ñòâîëà:
6678 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6679 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6681 Target
.UID
:= FTargetUID
;
6684 if Target
.UID
<> 0 then
6685 begin // Öåëü åñòü - íàñòðàèâàåì
6686 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6689 tpla
:= g_Player_Get(Target
.UID
);
6693 if (@FObj
) <> nil then
6700 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6701 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6702 Target
.Rect
:= PLAYER_RECT
;
6703 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6704 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6705 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6706 Target
.IsPlayer
:= True;
6710 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6713 mon
:= g_Monsters_ByUID(Target
.UID
);
6716 Target
.X
:= mon
.Obj
.X
;
6717 Target
.Y
:= mon
.Obj
.Y
;
6719 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6720 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6721 Target
.Rect
:= mon
.Obj
.Rect
;
6722 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6723 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6724 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6725 Target
.IsPlayer
:= False;
6732 begin // Öåëè íåò - îáíóëÿåì
6737 Target
.Visible
:= False;
6738 Target
.Line
:= False;
6739 Target
.IsPlayer
:= False;
6744 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6745 if (not Target
.Line
) or (not Target
.Visible
) then
6749 for a
:= 0 to High(gPlayers
) do
6750 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6751 (gPlayers
[a
].FUID
<> FUID
) and
6752 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6753 (not gPlayers
[a
].NoTarget
) and
6754 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6756 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6757 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6760 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6761 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6763 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6764 if g_TraceVector(x1
, y1
, x2
, y2
) then
6766 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6767 SetLength(targets
, Length(targets
)+1);
6768 with targets
[High(targets
)] do
6770 UID
:= gPlayers
[a
].FUID
;
6771 X
:= gPlayers
[a
].FObj
.X
;
6772 Y
:= gPlayers
[a
].FObj
.Y
;
6775 Rect
:= PLAYER_RECT
;
6776 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6777 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6778 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6786 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6789 // Åñëè åñòü âîçìîæíûå öåëè:
6790 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6791 if targets
<> nil then
6793 // Âûáèðàåì íàèëó÷øóþ öåëü:
6794 BestTarget
:= targets
[0];
6795 if Length(targets
) > 1 then
6796 for a
:= 1 to High(targets
) do
6797 if Compare(BestTarget
, targets
[a
]) = 1 then
6798 BestTarget
:= targets
[a
];
6800 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6801 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6802 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6804 Target
:= BestTarget
;
6806 if (Healthy() = 3) or ((Healthy() = 2)) then
6807 begin // Åñëè çäîðîâû - äîãîíÿåì
6808 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6809 SetAIFlag('GORIGHT', '1');
6810 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6811 SetAIFlag('GOLEFT', '1');
6814 begin // Åñëè ïîáèòû - óáåãàåì
6815 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6816 SetAIFlag('GORIGHT', '1');
6817 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6818 SetAIFlag('GOLEFT', '1');
6821 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6822 SelectWeapon(Abs(x1
-Target
.cX
));
6827 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6828 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6829 if Target
.UID
<> 0 then
6831 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6832 Target
.Y
+ Target
.Rect
.Y
) then
6833 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6834 if (Healthy() = 3) or ((Healthy() = 2)) then
6835 begin // Åñëè çäîðîâû - äîãîíÿåì
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');
6842 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6844 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6845 SetAIFlag('GORIGHT', '1');
6846 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6847 SetAIFlag('GOLEFT', '1');
6851 begin // Öåëü ïîêà íà "ýêðàíå"
6852 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6853 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6854 FLastVisible
:= gTime
;
6855 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6856 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6858 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6859 SetAIFlag('GORIGHT', '1');
6860 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6861 SetAIFlag('GOLEFT', '1');
6865 // Âûáèðàåì óãîë ââåðõ:
6866 if FDirection
= TDirection
.D_LEFT
then
6867 angle
:= ANGLE_LEFTUP
6869 angle
:= ANGLE_RIGHTUP
;
6871 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6872 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6874 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6875 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6876 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6877 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6878 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6879 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6880 begin // òî íóæíî ñòðåëÿòü ââåðõ
6881 SetAIFlag('NEEDFIRE', '1');
6882 SetAIFlag('NEEDSEEUP', '1');
6885 // Âûáèðàåì óãîë âíèç:
6886 if FDirection
= TDirection
.D_LEFT
then
6887 angle
:= ANGLE_LEFTDOWN
6889 angle
:= ANGLE_RIGHTDOWN
;
6891 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6892 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6894 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6895 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6896 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6897 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6898 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6899 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6900 begin // òî íóæíî ñòðåëÿòü âíèç
6901 SetAIFlag('NEEDFIRE', '1');
6902 SetAIFlag('NEEDSEEDOWN', '1');
6905 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6906 if Target
.Visible
and
6907 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6908 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6910 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6911 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
6912 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6913 begin // òî íóæíî ñòðåëÿòü âïåðåä
6914 SetAIFlag('NEEDFIRE', '1');
6915 SetAIFlag('NEEDSEEDOWN', '');
6916 SetAIFlag('NEEDSEEUP', '');
6918 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6919 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6920 if GetRnd(FDifficult
.CloseJump
) then
6921 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6922 if Abs(FObj
.X
-Target
.X
) < 128 then
6926 if Random(a
) = 0 then
6927 SetAIFlag('NEEDJUMP', '1');
6931 // Åñëè öåëü âñå åùå åñòü:
6932 if Target
.UID
<> 0 then
6933 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
6934 Target
.UID
:= 0 // òî çàáûòü öåëü
6935 else // Åñëè âèäåëè íåäàâíî
6936 begin // íî öåëü óáèëè
6937 if Target
.IsPlayer
then
6938 begin // Öåëü - èãðîê
6939 pla
:= g_Player_Get(Target
.UID
);
6940 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
6941 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6942 Target
.UID
:= 0; // òî çàáûòü öåëü
6945 begin // Öåëü - ìîíñòð
6946 mon
:= g_Monsters_ByUID(Target
.UID
);
6947 if (mon
= nil) or (not mon
.alive
) then
6948 Target
.UID
:= 0; // òî çàáûòü öåëü
6951 end; // if Target.UID <> 0
6953 FTargetUID
:= Target
.UID
;
6955 // Åñëè âîçìîæíûõ öåëåé íåò:
6956 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
6957 if targets
= nil then
6958 if GetAIFlag('ATTACKLEFT') <> '' then
6959 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
6960 RemoveAIFlag('ATTACKLEFT');
6962 SetAIFlag('NEEDJUMP', '1');
6964 if RunDirection() = TDirection
.D_RIGHT
then
6965 begin // Èäåì íå â òó ñòîðîíó
6966 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6967 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
6968 SetAIFlag('NEEDFIRE', '1');
6969 SetAIFlag('GOLEFT', '1');
6973 begin // Èäåì â íóæíóþ ñòîðîíó
6974 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6975 SetAIFlag('NEEDFIRE', '1');
6976 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6977 SetAIFlag('GORIGHT', '1');
6981 if GetAIFlag('ATTACKRIGHT') <> '' then
6982 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
6983 RemoveAIFlag('ATTACKRIGHT');
6985 SetAIFlag('NEEDJUMP', '1');
6987 if RunDirection() = TDirection
.D_LEFT
then
6988 begin // Èäåì íå â òó ñòîðîíó
6989 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6990 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
6991 SetAIFlag('NEEDFIRE', '1');
6992 SetAIFlag('GORIGHT', '1');
6997 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6998 SetAIFlag('NEEDFIRE', '1');
6999 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7000 SetAIFlag('GOLEFT', '1');
7004 //HACK! (does it belongs there?)
7005 RealizeCurrentWeapon();
7007 // Åñëè åñòü âîçìîæíûå öåëè:
7008 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7009 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7010 for a
:= 0 to High(targets
) do
7012 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7013 if GetRnd(FDifficult
.DiagFire
) then
7015 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7016 if FDirection
= TDirection
.D_LEFT
then
7017 angle
:= ANGLE_LEFTUP
7019 angle
:= ANGLE_RIGHTUP
;
7021 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7022 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7024 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7025 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7026 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7027 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7028 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7030 SetAIFlag('NEEDFIRE', '1');
7031 SetAIFlag('NEEDSEEUP', '1');
7034 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7035 if FDirection
= TDirection
.D_LEFT
then
7036 angle
:= ANGLE_LEFTDOWN
7038 angle
:= ANGLE_RIGHTDOWN
;
7040 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7041 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7043 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7044 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7045 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7046 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7047 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7049 SetAIFlag('NEEDFIRE', '1');
7050 SetAIFlag('NEEDSEEDOWN', '1');
7054 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7055 if targets
[a
].Line
and targets
[a
].Visible
and
7056 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
7057 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
7059 SetAIFlag('NEEDFIRE', '1');
7064 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7065 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
7066 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
7067 40+GetInterval(FDifficult
.Cover
, 40)) then
7068 SetAIFlag('NEEDJUMP', '1');
7070 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7071 ammo
:= GetAmmoByWeapon(FCurrWeap
);
7072 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
7073 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
7075 SetAIFlag('SELECTWEAPON', '1');
7077 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7078 if GetAIFlag('SELECTWEAPON') = '1' then
7081 RemoveAIFlag('SELECTWEAPON');
7085 procedure TBot
.Update();
7098 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7099 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7101 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7103 if g_debug_BotAIOff
= 3 then
7113 RealizeCurrentWeapon();
7120 procedure TBot
.ReleaseKey(Key
: Byte);
7129 function TBot
.KeyPressed(Key
: Word): Boolean;
7131 Result
:= FKeys
[Key
].Pressed
;
7134 function TBot
.GetAIFlag(aName
: String20
): String20
;
7140 aName
:= LowerCase(aName
);
7142 if FAIFlags
<> nil then
7143 for a
:= 0 to High(FAIFlags
) do
7144 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7146 Result
:= FAIFlags
[a
].Value
;
7151 procedure TBot
.RemoveAIFlag(aName
: String20
);
7155 if FAIFlags
= nil then Exit
;
7157 aName
:= LowerCase(aName
);
7159 for a
:= 0 to High(FAIFlags
) do
7160 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7162 if a
<> High(FAIFlags
) then
7163 for b
:= a
to High(FAIFlags
)-1 do
7164 FAIFlags
[b
] := FAIFlags
[b
+1];
7166 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7171 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7179 aName
:= LowerCase(aName
);
7181 if FAIFlags
<> nil then
7182 for a
:= 0 to High(FAIFlags
) do
7183 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7189 if ok
then FAIFlags
[a
].Value
:= fValue
7192 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7193 with FAIFlags
[High(FAIFlags
)] do
7201 procedure TBot
.UpdateMove
;
7203 procedure GoLeft(Time
: Word = 1);
7205 ReleaseKey(KEY_LEFT
);
7206 ReleaseKey(KEY_RIGHT
);
7207 PressKey(KEY_LEFT
, Time
);
7208 SetDirection(TDirection
.D_LEFT
);
7211 procedure GoRight(Time
: Word = 1);
7213 ReleaseKey(KEY_LEFT
);
7214 ReleaseKey(KEY_RIGHT
);
7215 PressKey(KEY_RIGHT
, Time
);
7216 SetDirection(TDirection
.D_RIGHT
);
7219 function Rnd(a
: Word): Boolean;
7221 Result
:= Random(a
) = 0;
7224 procedure Turn(Time
: Word = 1200);
7226 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7231 ReleaseKey(KEY_LEFT
);
7232 ReleaseKey(KEY_RIGHT
);
7235 function CanRunLeft(): Boolean;
7237 Result
:= not CollideLevel(-1, 0);
7240 function CanRunRight(): Boolean;
7242 Result
:= not CollideLevel(1, 0);
7245 function CanRun(): Boolean;
7247 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7250 procedure Jump(Time
: Word = 30);
7252 PressKey(KEY_JUMP
, Time
);
7255 function NearHole(): Boolean;
7259 { TODO 5 : Ëåñòíèöû }
7260 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7261 for x
:= 1 to PLAYER_RECT
.Width
do
7262 if (not StayOnStep(x
*sx
, 0)) and
7263 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7264 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7273 function BorderHole(): Boolean;
7277 { TODO 5 : Ëåñòíèöû }
7278 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7279 for x
:= 1 to PLAYER_RECT
.Width
do
7280 if (not StayOnStep(x
*sx
, 0)) and
7281 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7282 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7284 for xx
:= x
to x
+32 do
7285 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7295 function NearDeepHole(): Boolean;
7301 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7304 for x
:= 1 to PLAYER_RECT
.Width
do
7305 if (not StayOnStep(x
*sx
, 0)) and
7306 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7307 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7309 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7311 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7316 end else Result
:= False;
7319 function OverDeepHole(): Boolean;
7326 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7328 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7335 function OnGround(): Boolean;
7337 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7340 function OnLadder(): Boolean;
7342 Result
:= FullInStep(0, 0);
7345 function BelowLadder(): Boolean;
7347 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7348 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7349 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7350 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7353 function BelowLiftUp(): Boolean;
7355 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7356 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7357 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7358 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7361 function OnTopLift(): Boolean;
7363 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7366 function CanJumpOver(): Boolean;
7370 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7374 if not CollideLevel(sx
, 0) then Exit
;
7376 for y
:= 1 to BOT_MAXJUMP
do
7377 if CollideLevel(0, -y
) then Exit
else
7378 if not CollideLevel(sx
, -y
) then
7385 function CanJumpUp(Dist
: ShortInt): Boolean;
7392 if CollideLevel(Dist
, 0) then Exit
;
7395 for y
:= 0 to BOT_MAXJUMP
do
7396 if CollideLevel(Dist
, -y
) then
7405 for yy
:= y
+1 to BOT_MAXJUMP
do
7406 if not CollideLevel(Dist
, -yy
) then
7415 for y
:= 0 to BOT_MAXJUMP
do
7416 if CollideLevel(0, -y
) then
7424 if y
< yy
then Exit
;
7429 function IsSafeTrigger(): Boolean;
7434 if gTriggers
= nil then
7436 for a
:= 0 to High(gTriggers
) do
7437 if Collide(gTriggers
[a
].X
,
7440 gTriggers
[a
].Height
) and
7441 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7442 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7443 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7444 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7445 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7450 // Âîçìîæíî, íàæèìàåì êíîïêó:
7451 if Rnd(16) and IsSafeTrigger() then
7454 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7455 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7457 ReleaseKey(KEY_LEFT
);
7458 ReleaseKey(KEY_RIGHT
);
7462 // Èäåì âëåâî, åñëè íàäî áûëî:
7463 if GetAIFlag('GOLEFT') <> '' then
7465 RemoveAIFlag('GOLEFT');
7466 if CanRunLeft() then
7470 // Èäåì âïðàâî, åñëè íàäî áûëî:
7471 if GetAIFlag('GORIGHT') <> '' then
7473 RemoveAIFlag('GORIGHT');
7474 if CanRunRight() then
7478 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7479 if FObj
.X
< -32 then
7482 if FObj
.X
+32 > gMapInfo
.Width
then
7485 // Ïðûãàåì, åñëè íàäî áûëî:
7486 if GetAIFlag('NEEDJUMP') <> '' then
7489 RemoveAIFlag('NEEDJUMP');
7492 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7493 if GetAIFlag('NEEDSEEUP') <> '' then
7496 ReleaseKey(KEY_DOWN
);
7497 PressKey(KEY_UP
, 20);
7498 RemoveAIFlag('NEEDSEEUP');
7501 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7502 if GetAIFlag('NEEDSEEDOWN') <> '' then
7505 ReleaseKey(KEY_DOWN
);
7506 PressKey(KEY_DOWN
, 20);
7507 RemoveAIFlag('NEEDSEEDOWN');
7510 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7511 if GetAIFlag('GOINHOLE') <> '' then
7512 if not OnGround() then
7514 ReleaseKey(KEY_LEFT
);
7515 ReleaseKey(KEY_RIGHT
);
7516 RemoveAIFlag('GOINHOLE');
7517 SetAIFlag('FALLINHOLE', '1');
7520 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7521 if GetAIFlag('FALLINHOLE') <> '' then
7523 RemoveAIFlag('FALLINHOLE');
7525 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7526 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7527 if GetAIFlag('FALLINHOLE') = '' then
7528 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7534 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7536 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7540 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7541 if OnGround() and NearHole() then
7542 if NearDeepHole() then // Åñëè ýòî áåçäíà
7544 0..3: Turn(); // Áåæèì îáðàòíî
7545 4: Jump(); // Ïðûãàåì
7546 5: begin // Ïðûãàåì îáðàòíî
7551 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7552 if GetAIFlag('GOINHOLE') = '' then
7554 0: Turn(); // Íå íóæíî òóäà
7555 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7556 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7557 if BorderHole() then
7558 SetAIFlag('GOINHOLE', '1');
7561 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7562 if (not CanRun()) and OnGround() then
7564 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7565 if CanJumpOver() or OnLadder() then
7567 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7568 if Random(2) = 0 then
7570 if IsSafeTrigger() then
7576 // Îñòàëîñü ìàëî âîçäóõà:
7577 if FAir
< 36 * 2 then
7580 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7581 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7582 if BodyInAcid(0, 0) then
7586 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7588 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7589 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7592 {function TBot.NeedItem(Item: Byte): Byte;
7597 procedure TBot
.SelectWeapon(Dist
: Integer);
7601 function HaveAmmo(weapon
: Byte): Boolean;
7604 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7605 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7606 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7607 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7608 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7609 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7610 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7611 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7612 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7613 else Result
:= True;
7618 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7620 if Dist
> BOT_LONGDIST
then
7621 begin // Äàëüíèé áîé
7623 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7625 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7629 else //if Dist > BOT_UNSAFEDIST then
7630 begin // Áëèæíèé áîé
7632 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7634 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7641 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7643 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7649 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7651 Result
:= inherited PickItem(ItemType
, force
, remove
);
7653 if Result
then SetAIFlag('SELECTWEAPON', '1');
7656 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7658 Result
:= inherited Heal(value
, Soft
);
7661 function TBot
.Healthy(): Byte;
7663 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7664 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7665 else if (FHealth
> 50) then Result
:= 2
7666 else if (FHealth
> 20) then Result
:= 1
7670 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7672 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7673 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7676 procedure TBot
.OnDamage(Angle
: SmallInt);
7684 if (Angle
= 0) or (Angle
= 180) then
7687 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7688 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7690 pla
:= g_Player_Get(FLastSpawnerUID
);
7691 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7692 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7695 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7696 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7698 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7699 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7700 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7705 SetAIFlag('ATTACKLEFT', '1')
7707 SetAIFlag('ATTACKRIGHT', '1');
7711 function TBot
.RunDirection(): TDirection
;
7713 if Abs(Vel
.X
) >= 1 then
7715 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7717 Result
:= FDirection
;
7720 function TBot
.GetRnd(a
: Byte): Boolean;
7722 if a
= 0 then Result
:= False
7723 else if a
= 255 then Result
:= True
7724 else Result
:= Random(256) > 255-a
;
7727 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7729 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7733 procedure TDifficult
.save (st
: TStream
);
7735 utils
.writeInt(st
, Byte(DiagFire
));
7736 utils
.writeInt(st
, Byte(InvisFire
));
7737 utils
.writeInt(st
, Byte(DiagPrecision
));
7738 utils
.writeInt(st
, Byte(FlyPrecision
));
7739 utils
.writeInt(st
, Byte(Cover
));
7740 utils
.writeInt(st
, Byte(CloseJump
));
7741 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7742 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7745 procedure TDifficult
.load (st
: TStream
);
7747 DiagFire
:= utils
.readByte(st
);
7748 InvisFire
:= utils
.readByte(st
);
7749 DiagPrecision
:= utils
.readByte(st
);
7750 FlyPrecision
:= utils
.readByte(st
);
7751 Cover
:= utils
.readByte(st
);
7752 CloseJump
:= utils
.readByte(st
);
7753 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7754 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7758 procedure TBot
.SaveState (st
: TStream
);
7763 inherited SaveState(st
);
7764 utils
.writeSign(st
, 'BOT0');
7766 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7768 utils
.writeInt(st
, Word(FTargetUID
));
7769 // Âðåìÿ ïîòåðè öåëè
7770 utils
.writeInt(st
, LongWord(FLastVisible
));
7771 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7772 dw
:= Length(FAIFlags
);
7773 utils
.writeInt(st
, LongInt(dw
));
7775 for i
:= 0 to dw
-1 do
7777 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7778 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7780 // Íàñòðîéêè ñëîæíîñòè
7781 FDifficult
.save(st
);
7785 procedure TBot
.LoadState (st
: TStream
);
7790 inherited LoadState(st
);
7791 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7793 FSelectedWeapon
:= utils
.readByte(st
);
7795 FTargetUID
:= utils
.readWord(st
);
7796 // Âðåìÿ ïîòåðè öåëè
7797 FLastVisible
:= utils
.readLongWord(st
);
7798 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7799 dw
:= utils
.readLongInt(st
);
7800 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7801 SetLength(FAIFlags
, dw
);
7803 for i
:= 0 to dw
-1 do
7805 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7806 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7808 // Íàñòðîéêè ñëîæíîñòè
7809 FDifficult
.load(st
);
7814 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);