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 (unused)
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 weaponSwitchKeyReleased
: array[0..16] of Byte; // bit 0: was released on prev frame; bit 1: new status
207 function CollideLevel(XInc
, YInc
: Integer): Boolean;
208 function StayOnStep(XInc
, YInc
: Integer): Boolean;
209 function HeadInLiquid(XInc
, YInc
: Integer): Boolean;
210 function BodyInLiquid(XInc
, YInc
: Integer): Boolean;
211 function BodyInAcid(XInc
, YInc
: Integer): Boolean;
212 function FullInLift(XInc
, YInc
: Integer): Integer;
213 {procedure CollideItem();}
214 procedure FlySmoke(Times
: DWORD
= 1);
215 procedure OnFireFlame(Times
: DWORD
= 1);
216 function GetAmmoByWeapon(Weapon
: Byte): Word;
217 procedure SetAction(Action
: Byte; Force
: Boolean = False);
218 procedure OnDamage(Angle
: SmallInt); virtual;
219 function firediry(): Integer;
222 procedure Run(Direction
: TDirection
);
223 procedure NextWeapon();
224 procedure PrevWeapon();
231 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
232 procedure resetWeaponQueue ();
233 function hasAmmoForWeapon (weapon
: Byte): Boolean;
235 procedure doDamage (v
: Integer);
237 function followCorpse(): Boolean;
240 FDamageBuffer
: Integer;
242 FAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
243 FMaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
244 FWeapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
245 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
247 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
248 FReloading
: Array [WP_FIRST
..WP_LAST
] of Word;
249 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
250 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
252 FPreferredTeam
: Byte;
255 FWantsInGame
: Boolean;
259 FActualModelName
: string;
266 // debug: viewport offset
267 viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer;
269 function isValidViewPort (): Boolean; inline;
271 constructor Create(); virtual;
272 destructor Destroy(); override;
273 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
274 function GetRespawnPoint(): Byte;
275 procedure PressKey(Key
: Byte; Time
: Word = 1);
276 procedure ReleaseKeys();
277 procedure ReleaseKeysNoWeapon();
278 procedure SetModel(ModelName
: String);
279 procedure SetColor(Color
: TRGB
);
280 procedure SetWeapon(W
: Byte);
281 function IsKeyPressed(K
: Byte): Boolean;
282 function GetKeys(): Byte;
283 function PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean; virtual;
284 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
285 function Collide(Panel
: TPanel
): Boolean; overload
;
286 function Collide(X
, Y
: Integer): Boolean; overload
;
287 procedure SetDirection(Direction
: TDirection
);
288 procedure GetSecret();
289 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
291 procedure Push(vx
, vy
: Integer);
292 procedure ChangeModel(ModelName
: String);
293 procedure SwitchTeam
;
294 procedure ChangeTeam(Team
: Byte);
296 function GetFlag(Flag
: Byte): Boolean;
297 procedure SetFlag(Flag
: Byte);
298 function DropFlag(): Boolean;
299 procedure AllRulez(Health
: Boolean);
300 procedure RestoreHealthArmor();
301 procedure FragCombo();
302 procedure GiveItem(ItemType
: Byte);
303 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
304 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
305 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
306 procedure MakeBloodSimple(Count
: Word);
307 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
308 procedure Reset(Force
: Boolean);
309 procedure Spectate(NoMove
: Boolean = False);
310 procedure SwitchNoClip
;
311 procedure SoftReset();
312 procedure Draw(); virtual;
313 procedure DrawPain();
314 procedure DrawPickup();
315 procedure DrawRulez();
317 procedure DrawBubble();
319 procedure Update(); virtual;
320 procedure RememberState();
321 procedure RecallState();
322 procedure SaveState (st
: TStream
); virtual;
323 procedure LoadState (st
: TStream
); virtual;
324 procedure PauseSounds(Enable
: Boolean);
325 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
326 procedure DoLerp(Level
: Integer = 2);
327 procedure SetLerp(XTo
, YTo
: Integer);
328 procedure QueueWeaponSwitch(Weapon
: Byte);
329 procedure RealizeCurrentWeapon();
331 procedure JetpackOff
;
332 procedure CatchFire(Attacker
: Word);
334 //WARNING! this does nothing for now, but still call it!
335 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
337 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
338 procedure moveBy (dx
, dy
: Integer); inline;
340 procedure releaseAllWeaponSwitchKeys ();
341 procedure weaponSwitchKeysStateChange (index
: Integer; pressed
: Boolean);
342 function isWeaponSwitchKeyReleased (index
: Integer): Boolean;
343 procedure weaponSwitchKeysShiftNewStates ();
346 property Vel
: TPoint2i read FObj
.Vel
;
347 property Obj
: TObj read FObj
;
349 property Name
: String read FName write FName
;
350 property Model
: TPlayerModel read FModel
;
351 property Health
: Integer read FHealth write FHealth
;
352 property Lives
: Byte read FLives write FLives
;
353 property Armor
: Integer read FArmor write FArmor
;
354 property Air
: Integer read FAir write FAir
;
355 property JetFuel
: Integer read FJetFuel write FJetFuel
;
356 property Frags
: Integer read FFrags write FFrags
;
357 property Death
: Integer read FDeath write FDeath
;
358 property Kills
: Integer read FKills write FKills
;
359 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
360 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
361 property Secrets
: Integer read FSecrets
;
362 property GodMode
: Boolean read FGodMode write FGodMode
;
363 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
364 property NoReload
: Boolean read FNoReload write FNoReload
;
365 property alive
: Boolean read FAlive write FAlive
;
366 property Flag
: Byte read FFlag
;
367 property Team
: Byte read FTeam write FTeam
;
368 property Direction
: TDirection read FDirection
;
369 property GameX
: Integer read FObj
.X write FObj
.X
;
370 property GameY
: Integer read FObj
.Y write FObj
.Y
;
371 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
372 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
373 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
374 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
375 property IncCam
: Integer read FIncCam write FIncCam
;
376 property UID
: Word read FUID write FUID
;
377 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
378 property NetTime
: LongWord read FNetTime write FNetTime
;
381 property eName
: String read FName write FName
;
382 property eHealth
: Integer read FHealth write FHealth
;
383 property eLives
: Byte read FLives write FLives
;
384 property eArmor
: Integer read FArmor write FArmor
;
385 property eAir
: Integer read FAir write FAir
;
386 property eJetFuel
: Integer read FJetFuel write FJetFuel
;
387 property eFrags
: Integer read FFrags write FFrags
;
388 property eDeath
: Integer read FDeath write FDeath
;
389 property eKills
: Integer read FKills write FKills
;
390 property eCurrWeap
: Byte read FCurrWeap write FCurrWeap
;
391 property eMonsterKills
: Integer read FMonsterKills write FMonsterKills
;
392 property eSecrets
: Integer read FSecrets write FSecrets
;
393 property eGodMode
: Boolean read FGodMode write FGodMode
;
394 property eNoTarget
: Boolean read FNoTarget write FNoTarget
;
395 property eNoReload
: Boolean read FNoReload write FNoReload
;
396 property eAlive
: Boolean read FAlive write FAlive
;
397 property eFlag
: Byte read FFlag
;
398 property eTeam
: Byte read FTeam write FTeam
;
399 property eDirection
: TDirection read FDirection
;
400 property eGameX
: Integer read FObj
.X write FObj
.X
;
401 property eGameY
: Integer read FObj
.Y write FObj
.Y
;
402 property eGameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
403 property eGameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
404 property eGameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
405 property eGameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
406 property eIncCam
: Integer read FIncCam write FIncCam
;
407 property eUID
: Word read FUID
;
408 property eJustTeleported
: Boolean read FJustTeleported
;
409 property eNetTime
: LongWord read FNetTime
;
411 // set this before assigning something to `eDamage`
412 property eDamageType
: Integer read mEDamageType write mEDamageType
;
413 property eDamage
: Integer write doDamage
;
424 WeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
425 CloseWeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
426 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
429 procedure save (st
: TStream
);
430 procedure load (st
: TStream
);
438 TBot
= class(TPlayer
)
440 FSelectedWeapon
: Byte;
443 FAIFlags
: Array of TAIFlag
;
444 FDifficult
: TDifficult
;
446 function GetRnd(a
: Byte): Boolean;
447 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
448 function RunDirection(): TDirection
;
449 function FullInStep(XInc
, YInc
: Integer): Boolean;
450 //function NeedItem(Item: Byte): Byte;
451 procedure SelectWeapon(Dist
: Integer);
452 procedure SetAIFlag(aName
, fValue
: String20
);
453 function GetAIFlag(aName
: String20
): String20
;
454 procedure RemoveAIFlag(aName
: String20
);
455 function Healthy(): Byte;
456 procedure UpdateMove();
457 procedure UpdateCombat();
458 function KeyPressed(Key
: Word): Boolean;
459 procedure ReleaseKey(Key
: Byte);
460 function TargetOnScreen(TX
, TY
: Integer): Boolean;
461 procedure OnDamage(Angle
: SmallInt); override;
464 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
465 constructor Create(); override;
466 destructor Destroy(); override;
467 procedure Draw(); override;
468 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
469 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
470 procedure Update(); override;
471 procedure SaveState (st
: TStream
); override;
472 procedure LoadState (st
: TStream
); override;
484 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
485 procedure moveBy (dx
, dy
: Integer); inline;
487 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
501 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
502 procedure moveBy (dx
, dy
: Integer); inline;
504 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
507 TCorpse
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
516 FAnimation
: TAnimation
;
517 FAnimationMask
: TAnimation
;
520 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
521 destructor Destroy(); override;
522 procedure Damage(Value
: Word; vx
, vy
: Integer);
525 procedure SaveState (st
: TStream
);
526 procedure LoadState (st
: TStream
);
528 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
529 procedure moveBy (dx
, dy
: Integer); inline;
531 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
533 function ObjPtr (): PObj
; inline;
535 property Obj
: TObj read FObj
; // copies object
536 property State
: Byte read FState
;
537 property Mess
: Boolean read FMess
;
540 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
546 gPlayers
: Array of TPlayer
;
547 gCorpses
: Array of TCorpse
;
548 gGibs
: Array of TGib
;
549 gShells
: Array of TShell
;
550 gTeamStat
: TTeamStat
;
551 gFly
: Boolean = False;
552 gAimLine
: Boolean = False;
553 gChatBubble
: Byte = 0;
557 MAX_RUNVEL
: Integer = 8;
558 VEL_JUMP
: Integer = 10;
559 SHELL_TIMEOUT
: Cardinal = 60000;
561 function Lerp(X
, Y
, Factor
: Integer): Integer;
563 procedure g_Gibs_SetMax(Count
: Word);
564 function g_Gibs_GetMax(): Word;
565 procedure g_Corpses_SetMax(Count
: Word);
566 function g_Corpses_GetMax(): Word;
567 procedure g_Shells_SetMax(Count
: Word);
568 function g_Shells_GetMax(): Word;
570 procedure g_Player_Init();
571 procedure g_Player_Free();
572 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
573 function g_Player_CreateFromState (st
: TStream
): Word;
574 procedure g_Player_Remove(UID
: Word);
575 procedure g_Player_ResetTeams();
576 procedure g_Player_UpdateAll();
577 procedure g_Player_DrawAll();
578 procedure g_Player_DrawDebug(p
: TPlayer
);
579 procedure g_Player_DrawHealth();
580 procedure g_Player_RememberAll();
581 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
582 function g_Player_Get(UID
: Word): TPlayer
;
583 function g_Player_GetCount(): Byte;
584 function g_Player_GetStats(): TPlayerStatArray
;
585 function g_Player_ValidName(Name
: String): Boolean;
586 procedure g_Player_CreateCorpse(Player
: TPlayer
);
587 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
588 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
589 procedure g_Player_UpdatePhysicalObjects();
590 procedure g_Player_DrawCorpses();
591 procedure g_Player_DrawShells();
592 procedure g_Player_RemoveAllCorpses();
593 procedure g_Player_Corpses_SaveState (st
: TStream
);
594 procedure g_Player_Corpses_LoadState (st
: TStream
);
595 procedure g_Bot_Add(Team
, Difficult
: Byte);
596 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1);
597 procedure g_Bot_MixNames();
598 procedure g_Bot_RemoveAll();
603 {$INCLUDE ../nogl/noGLuses.inc}
604 {$IFDEF ENABLE_HOLMES}
607 e_log
, g_map
, g_items
, g_console
, g_gfx
, Math
,
608 g_options
, g_triggers
, g_menu
, g_game
, g_grid
,
609 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
,
610 g_net
, g_netmsg
, g_window
,
613 const PLR_SAVE_VERSION
= 0;
623 diag_precision
: Byte;
627 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
628 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
629 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
633 TIME_RESPAWN1
= 1500;
634 TIME_RESPAWN2
= 2000;
635 TIME_RESPAWN3
= 3000;
638 JET_MAX
= 540; // ~30 sec
639 PLAYER_SUIT_TIME
= 30000;
640 PLAYER_INVUL_TIME
= 30000;
641 PLAYER_INVIS_TIME
= 35000;
642 FRAG_COMBO_TIME
= 3000;
646 ANGLE_RIGHTDOWN
= -35;
648 ANGLE_LEFTDOWN
= -145;
649 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
650 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
653 BOT_UNSAFEDIST
= 128;
654 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
656 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
657 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
658 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
659 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
660 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
661 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
662 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
663 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
664 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
665 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
666 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
667 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
668 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
669 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
670 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
671 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
672 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
673 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
674 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
675 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
676 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
677 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
678 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
679 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
680 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
681 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
683 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
684 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
686 BOTNAMES_FILENAME
= 'botnames.txt';
687 BOTLIST_FILENAME
= 'botlist.txt';
691 MaxCorpses
: Word = 20;
692 MaxShells
: Word = 300;
693 CurrentGib
: Integer = 0;
694 CurrentShell
: Integer = 0;
695 BotNames
: Array of String;
696 BotList
: Array of TBotProfile
;
699 function Lerp(X
, Y
, Factor
: Integer): Integer;
701 Result
:= X
+ ((Y
- X
) div Factor
);
704 function SameTeam(UID1
, UID2
: Word): Boolean;
708 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
709 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
711 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
713 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
714 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
716 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
719 procedure g_Gibs_SetMax(Count
: Word);
722 SetLength(gGibs
, Count
);
724 if CurrentGib
>= Count
then
728 function g_Gibs_GetMax(): Word;
733 procedure g_Shells_SetMax(Count
: Word);
736 SetLength(gShells
, Count
);
738 if CurrentShell
>= Count
then
742 function g_Shells_GetMax(): Word;
748 procedure g_Corpses_SetMax(Count
: Word);
751 SetLength(gCorpses
, Count
);
754 function g_Corpses_GetMax(): Word;
756 Result
:= MaxCorpses
;
759 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
769 // Åñòü ëè ìåñòî â gPlayers:
770 if gPlayers
<> nil then
771 for a
:= 0 to High(gPlayers
) do
772 if gPlayers
[a
] = nil then
778 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
781 SetLength(gPlayers
, Length(gPlayers
)+1);
785 // Ñîçäàåì îáúåêò èãðîêà:
787 gPlayers
[a
] := TBot
.Create()
789 gPlayers
[a
] := TPlayer
.Create();
792 gPlayers
[a
].FActualModelName
:= ModelName
;
793 gPlayers
[a
].SetModel(ModelName
);
795 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
796 if gPlayers
[a
].FModel
= nil then
800 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
804 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
805 if Random(2) = 0 then
809 gPlayers
[a
].FPreferredTeam
:= Team
;
811 case gGameSettings
.GameMode
of
812 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
814 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
816 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
819 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
820 gPlayers
[a
].FColor
:= Color
;
821 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
822 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
824 gPlayers
[a
].FModel
.Color
:= Color
;
826 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
827 gPlayers
[a
].FAlive
:= False;
829 Result
:= gPlayers
[a
].FUID
;
832 function g_Player_CreateFromState (st
: TStream
): Word;
839 if (st
= nil) then exit
; //???
842 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
843 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
846 Bot
:= utils
.readBool(st
);
851 // Åñòü ëè ìåñòî â gPlayers:
852 for a
:= 0 to High(gPlayers
) do if (gPlayers
[a
] = nil) then begin ok
:= true; break
; end;
854 // Íåò ìåñòà - ðàñøèðÿåì gPlayers
857 SetLength(gPlayers
, Length(gPlayers
)+1);
861 // Ñîçäàåì îáúåêò èãðîêà
863 gPlayers
[a
] := TBot
.Create()
865 gPlayers
[a
] := TPlayer
.Create();
866 gPlayers
[a
].FIamBot
:= Bot
;
867 gPlayers
[a
].FPhysics
:= True;
870 gPlayers
[a
].FUID
:= utils
.readWord(st
);
872 gPlayers
[a
].FName
:= utils
.readStr(st
);
874 gPlayers
[a
].FTeam
:= utils
.readByte(st
);
875 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
877 gPlayers
[a
].FAlive
:= utils
.readBool(st
);
878 // Èçðàñõîäîâàë ëè âñå æèçíè
879 gPlayers
[a
].FNoRespawn
:= utils
.readBool(st
);
881 b
:= utils
.readByte(st
);
882 if b
= 1 then gPlayers
[a
].FDirection
:= TDirection
.D_LEFT
else gPlayers
[a
].FDirection
:= TDirection
.D_RIGHT
; // b = 2
884 gPlayers
[a
].FHealth
:= utils
.readLongInt(st
);
886 gPlayers
[a
].FLives
:= utils
.readByte(st
);
888 gPlayers
[a
].FArmor
:= utils
.readLongInt(st
);
890 gPlayers
[a
].FAir
:= utils
.readLongInt(st
);
892 gPlayers
[a
].FJetFuel
:= utils
.readLongInt(st
);
894 gPlayers
[a
].FPain
:= utils
.readLongInt(st
);
896 gPlayers
[a
].FKills
:= utils
.readLongInt(st
);
898 gPlayers
[a
].FMonsterKills
:= utils
.readLongInt(st
);
900 gPlayers
[a
].FFrags
:= utils
.readLongInt(st
);
902 gPlayers
[a
].FFragCombo
:= utils
.readByte(st
);
903 // Âðåìÿ ïîñëåäíåãî ôðàãà
904 gPlayers
[a
].FLastFrag
:= utils
.readLongWord(st
);
906 gPlayers
[a
].FDeath
:= utils
.readLongInt(st
);
908 gPlayers
[a
].FFlag
:= utils
.readByte(st
);
910 gPlayers
[a
].FSecrets
:= utils
.readLongInt(st
);
912 gPlayers
[a
].FCurrWeap
:= utils
.readByte(st
);
913 // Ñëåäóþùåå æåëàåìîå îðóæèå
914 gPlayers
[a
].FNextWeap
:= utils
.readWord(st
);
916 gPlayers
[a
].FNextWeapDelay
:= utils
.readByte(st
);
918 gPlayers
[a
].FBFGFireCounter
:= utils
.readSmallInt(st
);
920 gPlayers
[a
].FDamageBuffer
:= utils
.readLongInt(st
);
921 // Ïîñëåäíèé óäàðèâøèé
922 gPlayers
[a
].FLastSpawnerUID
:= utils
.readWord(st
);
923 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
924 gPlayers
[a
].FLastHit
:= utils
.readByte(st
);
926 Obj_LoadState(@gPlayers
[a
].FObj
, st
);
927 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
928 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FAmmo
[i
] := utils
.readWord(st
);
929 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
930 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FMaxAmmo
[i
] := utils
.readWord(st
);
932 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FWeapon
[i
] := utils
.readBool(st
);
933 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
934 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FReloading
[i
] := utils
.readWord(st
);
936 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
937 // Íàëè÷èå êðàñíîãî êëþ÷à
938 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
939 // Íàëè÷èå çåëåíîãî êëþ÷à
940 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
941 // Íàëè÷èå ñèíåãî êëþ÷à
942 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
944 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_BERSERK
);
945 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
946 for i
:= MR_SUIT
to MR_MAX
do gPlayers
[a
].FMegaRulez
[i
] := utils
.readLongWord(st
);
947 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
948 for i
:= T_RESPAWN
to T_FLAGCAP
do gPlayers
[a
].FTime
[i
] := utils
.readLongWord(st
);
951 gPlayers
[a
].FActualModelName
:= utils
.readStr(st
);
953 gPlayers
[a
].FColor
.R
:= utils
.readByte(st
);
954 gPlayers
[a
].FColor
.G
:= utils
.readByte(st
);
955 gPlayers
[a
].FColor
.B
:= utils
.readByte(st
);
956 // Îáíîâëÿåì ìîäåëü èãðîêà
957 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
959 // Íåò ìîäåëè - ñîçäàíèå íåâîçìîæíî
960 if (gPlayers
[a
].FModel
= nil) then
964 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
968 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû
969 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
970 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
972 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
974 result
:= gPlayers
[a
].FUID
;
978 procedure g_Player_ResetTeams();
982 if g_Game_IsClient
then
984 if gPlayers
= nil then
986 for a
:= Low(gPlayers
) to High(gPlayers
) do
987 if gPlayers
[a
] <> nil then
988 case gGameSettings
.GameMode
of
990 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
992 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
993 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
994 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
997 gPlayers
[a
].ChangeTeam(TEAM_RED
)
999 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
1002 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
1006 procedure g_Bot_Add(Team
, Difficult
: Byte);
1009 _name
, _model
: String;
1012 if not g_Game_IsServer
then Exit
;
1014 // Ñïèñîê íàçâàíèé ìîäåëåé:
1015 m
:= g_PlayerModel_GetNames();
1020 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1021 Team
:= TEAM_COOP
// COOP
1023 if gGameSettings
.GameMode
= GM_DM
then
1024 Team
:= TEAM_NONE
// DM
1026 if Team
= TEAM_NONE
then // CTF / TDM
1028 // Àâòîáàëàíñ êîìàíä:
1032 for a
:= 0 to High(gPlayers
) do
1033 if gPlayers
[a
] <> nil then
1035 if gPlayers
[a
].Team
= TEAM_RED
then
1038 if gPlayers
[a
].Team
= TEAM_BLUE
then
1048 if Random(2) = 0 then
1054 // Âûáèðàåì áîòó èìÿ:
1056 if BotNames
<> nil then
1057 for a
:= 0 to High(BotNames
) do
1058 if g_Player_ValidName(BotNames
[a
]) then
1060 _name
:= BotNames
[a
];
1064 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
1067 _name
:= Format('DFBOT%.2d', [Random(100)]);
1068 until g_Player_ValidName(_name
);
1070 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1071 _model
:= m
[Random(Length(m
))];
1074 with g_Player_Get(g_Player_Create(_model
,
1075 _RGB(Min(Random(9)*32, 255),
1076 Min(Random(9)*32, 255),
1077 Min(Random(9)*32, 255)),
1078 Team
, True)) as TBot
do
1083 1: FDifficult
:= DIFFICULT_EASY
;
1084 2: FDifficult
:= DIFFICULT_MEDIUM
;
1085 else FDifficult
:= DIFFICULT_HARD
;
1088 for a
:= WP_FIRST
to WP_LAST
do
1090 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1091 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1092 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1095 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1097 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1098 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1103 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1);
1106 _name
, _model
: String;
1109 if not g_Game_IsServer
then Exit
;
1111 // Ñïèñîê íàçâàíèé ìîäåëåé:
1112 m
:= g_PlayerModel_GetNames();
1117 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1118 Team
:= TEAM_COOP
// COOP
1120 if gGameSettings
.GameMode
= GM_DM
then
1121 Team
:= TEAM_NONE
// DM
1123 if Team
= TEAM_NONE
then
1124 Team
:= BotList
[num
].team
; // CTF / TDM
1126 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1127 lName
:= AnsiLowerCase(lName
);
1128 if (num
< 0) or (num
> Length(BotList
)-1) then
1130 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1131 for a
:= 0 to High(BotList
) do
1132 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1141 _name
:= BotList
[num
].name
;
1142 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1143 if not g_Player_ValidName(_name
) then
1145 _name
:= Format('DFBOT%.2d', [Random(100)]);
1146 until g_Player_ValidName(_name
);
1149 _model
:= BotList
[num
].model
;
1150 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1151 if not InSArray(_model
, m
) then
1152 _model
:= m
[Random(Length(m
))];
1155 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1159 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1160 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1161 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1162 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1163 FDifficult
.Cover
:= BotList
[num
].cover
;
1164 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1166 for a
:= WP_FIRST
to WP_LAST
do
1168 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1169 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1170 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1173 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1175 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1179 procedure g_Bot_RemoveAll();
1183 if not g_Game_IsServer
then Exit
;
1184 if gPlayers
= nil then Exit
;
1186 for a
:= 0 to High(gPlayers
) do
1187 if gPlayers
[a
] <> nil then
1188 if gPlayers
[a
] is TBot
then
1190 gPlayers
[a
].Lives
:= 0;
1191 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1192 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1193 g_Player_Remove(gPlayers
[a
].FUID
);
1199 procedure g_Bot_MixNames();
1204 if BotNames
<> nil then
1205 for a
:= 0 to High(BotNames
) do
1207 b
:= Random(Length(BotNames
));
1209 Botnames
[a
] := BotNames
[b
];
1214 procedure g_Player_Remove(UID
: Word);
1218 if gPlayers
= nil then Exit
;
1220 if g_Game_IsServer
and g_Game_IsNet
then
1221 MH_SEND_PlayerDelete(UID
);
1223 for i
:= 0 to High(gPlayers
) do
1224 if gPlayers
[i
] <> nil then
1225 if gPlayers
[i
].FUID
= UID
then
1227 if gPlayers
[i
] is TPlayer
then
1228 TPlayer(gPlayers
[i
]).Free()
1230 TBot(gPlayers
[i
]).Free();
1236 procedure g_Player_Init();
1246 if not FileExists(DataDir
+ BOTNAMES_FILENAME
) then
1249 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1250 AssignFile(F
, DataDir
+ BOTNAMES_FILENAME
);
1261 SetLength(BotNames
, Length(BotNames
)+1);
1262 BotNames
[High(BotNames
)] := s
;
1270 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1271 config
:= TConfig
.CreateFile(DataDir
+ BOTLIST_FILENAME
);
1275 while config
.SectionExists(IntToStr(a
)) do
1277 SetLength(BotList
, Length(BotList
)+1);
1279 with BotList
[High(BotList
)] do
1282 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1284 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1286 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1291 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1292 color
.R
:= StrToIntDef(sa
[0], 0);
1293 color
.G
:= StrToIntDef(sa
[1], 0);
1294 color
.B
:= StrToIntDef(sa
[2], 0);
1295 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1296 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1297 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1298 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1299 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1300 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1301 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1302 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1303 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1304 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1305 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1306 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1307 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1308 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1309 if Length(sa
) = 10 then
1311 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1312 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1313 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1314 if Length(sa
) = 10 then
1316 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1318 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1319 if Length(sa) = 10 then
1321 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1330 procedure g_Player_Free();
1334 if gPlayers
<> nil then
1336 for i
:= 0 to High(gPlayers
) do
1337 if gPlayers
[i
] <> nil then
1339 if gPlayers
[i
] is TPlayer
then
1340 TPlayer(gPlayers
[i
]).Free()
1342 TBot(gPlayers
[i
]).Free();
1353 procedure g_Player_UpdateAll();
1357 if gPlayers
= nil then Exit
;
1359 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1360 for i
:= 0 to High(gPlayers
) do
1362 if gPlayers
[i
] <> nil then
1364 if gPlayers
[i
] is TPlayer
then
1366 gPlayers
[i
].Update();
1367 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1371 // bot updates weapons in `UpdateCombat()`
1372 TBot(gPlayers
[i
]).Update();
1376 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1379 procedure g_Player_DrawAll();
1383 if gPlayers
= nil then Exit
;
1385 for i
:= 0 to High(gPlayers
) do
1386 if gPlayers
[i
] <> nil then
1387 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1388 else TBot(gPlayers
[i
]).Draw();
1391 procedure g_Player_DrawDebug(p
: TPlayer
);
1395 if p
= nil then Exit
;
1396 if (@p
.FObj
) = nil then Exit
;
1398 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1400 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1401 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1402 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1403 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1404 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1405 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1408 procedure g_Player_DrawHealth();
1413 if gPlayers
= nil then Exit
;
1414 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1416 for i
:= 0 to High(gPlayers
) do
1417 if gPlayers
[i
] <> nil then
1419 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1420 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1421 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1422 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1423 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1424 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1428 function g_Player_Get(UID
: Word): TPlayer
;
1434 if gPlayers
= nil then
1437 for a
:= 0 to High(gPlayers
) do
1438 if gPlayers
[a
] <> nil then
1439 if gPlayers
[a
].FUID
= UID
then
1441 Result
:= gPlayers
[a
];
1446 function g_Player_GetCount(): Byte;
1452 if gPlayers
= nil then
1455 for a
:= 0 to High(gPlayers
) do
1456 if gPlayers
[a
] <> nil then
1457 Result
:= Result
+ 1;
1460 function g_Player_GetStats(): TPlayerStatArray
;
1466 if gPlayers
= nil then Exit
;
1468 for a
:= 0 to High(gPlayers
) do
1469 if gPlayers
[a
] <> nil then
1471 SetLength(Result
, Length(Result
)+1);
1472 with Result
[High(Result
)] do
1474 Ping
:= gPlayers
[a
].FPing
;
1475 Loss
:= gPlayers
[a
].FLoss
;
1476 Name
:= gPlayers
[a
].FName
;
1477 Team
:= gPlayers
[a
].FTeam
;
1478 Frags
:= gPlayers
[a
].FFrags
;
1479 Deaths
:= gPlayers
[a
].FDeath
;
1480 Kills
:= gPlayers
[a
].FKills
;
1481 Color
:= gPlayers
[a
].FModel
.Color
;
1482 Lives
:= gPlayers
[a
].FLives
;
1483 Spectator
:= gPlayers
[a
].FSpectator
;
1488 procedure g_Player_RememberAll
;
1492 for i
:= Low(gPlayers
) to High(gPlayers
) do
1493 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1494 gPlayers
[i
].RememberState
;
1497 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1501 gTeamStat
[TEAM_RED
].Goals
:= 0;
1502 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1504 if gPlayers
<> nil then
1505 for i
:= 0 to High(gPlayers
) do
1506 if gPlayers
[i
] <> nil then
1508 gPlayers
[i
].Reset(Force
);
1510 if gPlayers
[i
] is TPlayer
then
1512 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1513 gPlayers
[i
].Respawn(Silent
)
1515 gPlayers
[i
].Spectate();
1518 TBot(gPlayers
[i
]).Respawn(Silent
);
1522 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1528 if Player
.alive
then
1531 // Ðàçðûâàåì ñâÿçü ñ ïðåæíèì òðóïîì:
1532 if gCorpses
<> nil then
1533 for i
:= 0 to High(gCorpses
) do
1534 if gCorpses
[i
] <> nil then
1535 if gCorpses
[i
].FPlayerUID
= Player
.FUID
then
1536 gCorpses
[i
].FPlayerUID
:= 0;
1538 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1543 if (FHealth
>= -50) or (gGibsCount
= 0) then
1545 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1549 for find_id
:= 0 to High(gCorpses
) do
1550 if gCorpses
[find_id
] = nil then
1557 find_id
:= Random(Length(gCorpses
));
1559 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1560 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1561 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1562 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1563 gCorpses
[find_id
].FPlayerUID
:= FUID
;
1566 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1567 FObj
.Y
+ PLAYER_RECT_CY
,
1568 FModel
.Name
, FModel
.Color
);
1572 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1576 if (gShells
= nil) or (Length(gShells
) = 0) then
1579 with gShells
[CurrentShell
] do
1585 if T
= SHELL_BULLET
then
1587 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1591 Obj
.Rect
.Width
:= 4;
1592 Obj
.Rect
.Height
:= 2;
1596 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1600 Obj
.Rect
.Width
:= 7;
1601 Obj
.Rect
.Height
:= 3;
1607 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1608 positionChanged(); // this updates spatial accelerators
1609 RAngle
:= Random(360);
1610 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1612 if CurrentShell
>= High(gShells
) then
1619 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1622 GibsArray
: TGibsArray
;
1625 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1627 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1629 Blood
:= g_PlayerModel_GetBlood(ModelName
);
1631 for a
:= 0 to High(GibsArray
) do
1632 with gGibs
[CurrentGib
] do
1635 ID
:= GibsArray
[a
].ID
;
1636 MaskID
:= GibsArray
[a
].MaskID
;
1639 Obj
.Rect
:= GibsArray
[a
].Rect
;
1640 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1641 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1642 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1643 positionChanged(); // this updates spatial accelerators
1644 RAngle
:= Random(360);
1646 if gBloodCount
> 0 then
1647 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1648 Random(48), Random(48), Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
1650 if CurrentGib
>= High(gGibs
) then
1657 procedure g_Player_UpdatePhysicalObjects();
1663 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1668 if T
= SHELL_BULLET
then
1669 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1671 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1676 if gGibs
<> nil then
1677 for i
:= 0 to High(gGibs
) do
1678 if gGibs
[i
].alive
then
1682 mr
:= g_Obj_Move(@Obj
, True, False, True);
1683 positionChanged(); // this updates spatial accelerators
1685 if WordBool(mr
and MOVE_FALLOUT
) then
1691 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1692 if WordBool(mr
and MOVE_HITWALL
) then
1693 Obj
.Vel
.X
:= -(vel
.X
div 2);
1694 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1695 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1697 if (Obj
.Vel
.X
>= 0) then
1699 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1700 if RAngle
>= 360 then
1701 RAngle
:= RAngle
mod 360;
1702 end else begin // Counter-clockwise
1703 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1705 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1708 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1709 if gTime
mod (GAME_TICK
*3) = 0 then
1710 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1714 if gCorpses
<> nil then
1715 for i
:= 0 to High(gCorpses
) do
1716 if gCorpses
[i
] <> nil then
1717 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1723 gCorpses
[i
].Update();
1726 if gShells
<> nil then
1727 for i
:= 0 to High(gShells
) do
1728 if gShells
[i
].alive
then
1732 mr
:= g_Obj_Move(@Obj
, True, False, True);
1733 positionChanged(); // this updates spatial accelerators
1735 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1741 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1742 if WordBool(mr
and MOVE_HITWALL
) then
1744 Obj
.Vel
.X
:= -(vel
.X
div 2);
1745 if not WordBool(mr
and MOVE_INWATER
) then
1746 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1748 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1750 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1751 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1752 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1754 if RAngle
mod 90 <> 0 then
1755 RAngle
:= (RAngle
div 90) * 90;
1757 else if not WordBool(mr
and MOVE_INWATER
) then
1758 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1761 if (Obj
.Vel
.X
>= 0) then
1763 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1764 if RAngle
>= 360 then
1765 RAngle
:= RAngle
mod 360;
1766 end else begin // Counter-clockwise
1767 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1769 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1775 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1777 x
:= Obj
.X
+Obj
.Rect
.X
;
1778 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1779 w
:= Obj
.Rect
.Width
;
1780 h
:= Obj
.Rect
.Height
;
1783 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1785 if (dx
<> 0) or (dy
<> 0) then
1794 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1798 w
:= Obj
.Rect
.Width
;
1799 h
:= Obj
.Rect
.Height
;
1802 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1804 if (dx
<> 0) or (dy
<> 0) then
1813 procedure TGib
.positionChanged (); inline; begin end;
1814 procedure TShell
.positionChanged (); inline; begin end;
1817 procedure g_Player_DrawCorpses();
1822 if gGibs
<> nil then
1823 for i
:= 0 to High(gGibs
) do
1824 if gGibs
[i
].alive
then
1827 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1830 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1831 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1833 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1836 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1842 if gCorpses
<> nil then
1843 for i
:= 0 to High(gCorpses
) do
1844 if gCorpses
[i
] <> nil then
1848 procedure g_Player_DrawShells();
1853 if gShells
<> nil then
1854 for i
:= 0 to High(gShells
) do
1855 if gShells
[i
].alive
then
1858 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1864 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1868 procedure g_Player_RemoveAllCorpses();
1874 SetLength(gGibs
, MaxGibs
);
1875 SetLength(gShells
, MaxGibs
);
1879 if gCorpses
<> nil then
1880 for i
:= 0 to High(gCorpses
) do
1884 SetLength(gCorpses
, MaxCorpses
);
1887 procedure g_Player_Corpses_SaveState (st
: TStream
);
1891 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ
1893 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1895 // Êîëè÷åñòâî òðóïîâ
1896 utils
.writeInt(st
, LongInt(count
));
1898 if (count
= 0) then exit
;
1901 for i
:= 0 to High(gCorpses
) do
1903 if gCorpses
[i
] <> nil then
1906 utils
.writeStr(st
, gCorpses
[i
].FModelName
);
1908 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1909 // Ñîõðàíÿåì äàííûå òðóïà:
1910 gCorpses
[i
].SaveState(st
);
1916 procedure g_Player_Corpses_LoadState (st
: TStream
);
1924 g_Player_RemoveAllCorpses();
1926 // Êîëè÷åñòâî òðóïîâ:
1927 count
:= utils
.readLongInt(st
);
1928 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1930 if (count
= 0) then exit
;
1933 for i
:= 0 to count
-1 do
1936 str
:= utils
.readStr(st
);
1938 b
:= utils
.readBool(st
);
1940 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1941 // Çàãðóæàåì äàííûå òðóïà
1942 gCorpses
[i
].LoadState(st
);
1949 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1951 procedure TPlayer
.BFGHit();
1953 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1954 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1955 if g_Game_IsServer
and g_Game_IsNet
then
1956 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1957 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1961 procedure TPlayer
.ChangeModel(ModelName
: string);
1963 locModel
: TPlayerModel
;
1965 locModel
:= g_PlayerModel_Get(ModelName
);
1966 if locModel
= nil then Exit
;
1972 procedure TPlayer
.SetModel(ModelName
: string);
1976 m
:= g_PlayerModel_Get(ModelName
);
1979 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1980 m
:= g_PlayerModel_Get('doomer');
1983 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1988 if FModel
<> nil then
1993 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1994 FModel
.Color
:= FColor
1996 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1997 FModel
.SetWeapon(FCurrWeap
);
1998 FModel
.SetFlag(FFlag
);
1999 SetDirection(FDirection
);
2002 procedure TPlayer
.SetColor(Color
: TRGB
);
2005 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2006 if FModel
<> nil then FModel
.Color
:= Color
;
2009 procedure TPlayer
.SwitchTeam
;
2011 if g_Game_IsClient
then
2013 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
2015 if gGameOn
and FAlive
then
2016 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
2018 if FTeam
= TEAM_RED
then
2020 ChangeTeam(TEAM_BLUE
);
2021 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
2022 if g_Game_IsNet
then
2023 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
2027 ChangeTeam(TEAM_RED
);
2028 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
2029 if g_Game_IsNet
then
2030 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
2032 FPreferredTeam
:= FTeam
;
2035 procedure TPlayer
.ChangeTeam(Team
: Byte);
2042 TEAM_RED
, TEAM_BLUE
:
2043 FModel
.Color
:= TEAMCOLOR
[Team
];
2045 FModel
.Color
:= FColor
;
2047 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2048 MH_SEND_PlayerStats(FUID
);
2052 procedure TPlayer.CollideItem();
2057 if gItems = nil then Exit;
2058 if not FAlive then Exit;
2060 for i := 0 to High(gItems) do
2063 if (ItemType <> ITEM_NONE) and alive then
2064 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2065 PLAYER_RECT.Height, @Obj) then
2067 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2069 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2070 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2071 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2072 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2073 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2075 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2076 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2077 (gGameSettings.GameType = GT_SINGLE) and
2078 (g_Player_GetCount() > 1)) then
2079 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2085 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2087 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2088 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2092 constructor TPlayer
.Create();
2098 mEDamageType
:= HIT_SOME
;
2104 FSawSound
:= TPlayableSound
.Create();
2105 FSawSoundIdle
:= TPlayableSound
.Create();
2106 FSawSoundHit
:= TPlayableSound
.Create();
2107 FSawSoundSelect
:= TPlayableSound
.Create();
2108 FJetSoundFly
:= TPlayableSound
.Create();
2109 FJetSoundOn
:= TPlayableSound
.Create();
2110 FJetSoundOff
:= TPlayableSound
.Create();
2112 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2113 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2114 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2115 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2116 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2117 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2118 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2120 FSpectatePlayer
:= -1;
2124 FSavedState
.WaitRecall
:= False;
2130 FActualModelName
:= 'doomer';
2133 FObj
.Rect
:= PLAYER_RECT
;
2135 FBFGFireCounter
:= -1;
2136 FJustTeleported
:= False;
2140 releaseAllWeaponSwitchKeys();
2144 procedure TPlayer
.releaseAllWeaponSwitchKeys ();
2148 for f
:= 0 to High(weaponSwitchKeyReleased
) do weaponSwitchKeyReleased
[f
] := $03;
2151 procedure TPlayer
.weaponSwitchKeysStateChange (index
: Integer; pressed
: Boolean);
2153 Inc(index
, 2); // -2: prev; -1: next
2154 if (index
< 0) or (index
> High(weaponSwitchKeyReleased
)) then exit
;
2155 weaponSwitchKeyReleased
[index
] := weaponSwitchKeyReleased
[index
] or $02;
2156 if (pressed
) then weaponSwitchKeyReleased
[index
] := weaponSwitchKeyReleased
[index
] xor $02;
2159 function TPlayer
.isWeaponSwitchKeyReleased (index
: Integer): Boolean;
2161 Inc(index
, 2); // -2: prev; -1: next
2162 if (index
< 0) or (index
> High(weaponSwitchKeyReleased
)) then
2168 result
:= (weaponSwitchKeyReleased
[index
] and $01) <> 0;
2172 procedure TPlayer
.weaponSwitchKeysShiftNewStates ();
2176 // copy bit 1 to bit 0
2177 for f
:= 0 to High(weaponSwitchKeyReleased
) do
2179 weaponSwitchKeyReleased
[f
] :=
2180 (weaponSwitchKeyReleased
[f
] and $02) or
2181 ((weaponSwitchKeyReleased
[f
] shr 1) and $01);
2186 procedure TPlayer
.positionChanged (); inline;
2190 procedure TPlayer
.doDamage (v
: Integer);
2192 if (v
<= 0) then exit
;
2193 if (v
> 32767) then v
:= 32767;
2194 Damage(v
, 0, 0, 0, mEDamageType
);
2197 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2201 if (not g_Game_IsClient
) and (not FAlive
) then
2206 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2207 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2209 if not g_Game_IsClient
then
2212 if t
= HIT_TRAP
then
2214 // Ëîâóøêà óáèâàåò ñðàçó:
2216 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2218 if t
= HIT_SELF
then
2222 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2225 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2226 FMegaRulez
[MR_SUIT
] := 0;
2227 FMegaRulez
[MR_INVUL
] := 0;
2228 FMegaRulez
[MR_INVIS
] := 0;
2232 // Íî îò îñòàëüíîãî ñïàñàåò:
2233 if FMegaRulez
[MR_INVUL
] >= gTime
then
2240 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2241 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2242 (SpawnerUID
= FUID
) or
2243 (not SameTeam(FUID
, SpawnerUID
)) then
2245 FLastSpawnerUID
:= SpawnerUID
;
2247 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2248 if gBloodCount
> 0 then
2250 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2251 if value
div 4 <= c
then
2252 c
:= c
- (value
div 4)
2256 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2260 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2261 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2264 if t
= HIT_WATER
then
2265 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2266 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2271 Inc(FDamageBuffer
, value
);
2275 FPain
:= FPain
+ value
;
2278 if g_Game_IsServer
and g_Game_IsNet
then
2280 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2281 MH_SEND_PlayerStats(FUID
);
2282 MH_SEND_PlayerPos(False, FUID
);
2286 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2289 if g_Game_IsClient
then
2294 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2296 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2299 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2301 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2305 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2306 MH_SEND_PlayerStats(FUID
);
2309 destructor TPlayer
.Destroy();
2311 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2313 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2317 FSawSoundIdle
.Free();
2318 FSawSoundHit
.Free();
2319 FJetSoundFly
.Free();
2321 FJetSoundOff
.Free();
2323 if FPunchAnim
<> nil then
2329 procedure TPlayer
.DrawBubble();
2331 bubX
, bubY
: Integer;
2334 Rw
, Gw
, Bw
: SmallInt;
2337 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= TDirection
.D_LEFT
, -4, 18);
2338 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2346 1: // simple textual non-bubble
2348 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2349 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2350 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2353 2: // advanced pixel-perfect bubble
2355 if FTeam
= TEAM_RED
then
2358 if FTeam
= TEAM_BLUE
then
2361 3: // colored bubble
2363 Rb
:= FModel
.Color
.R
;
2364 Gb
:= FModel
.Color
.G
;
2365 Bb
:= FModel
.Color
.B
;
2366 Rw
:= Min(Rb
* 2 + 64, 255);
2367 Gw
:= Min(Gb
* 2 + 64, 255);
2368 Bw
:= Min(Bb
* 2 + 64, 255);
2369 if (Abs(Rw
- Rb
) < 32)
2370 or (Abs(Gw
- Gb
) < 32)
2371 or (Abs(Bw
- Bb
) < 32) then
2373 Rb
:= Max(Rw
div 2 - 16, 0);
2374 Gb
:= Max(Gw
div 2 - 16, 0);
2375 Bb
:= Max(Bw
div 2 - 16, 0);
2378 4: // custom textured bubble
2380 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2381 if FDirection
= TDirection
.D_RIGHT
then
2382 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2384 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, TMirrorType
.Horizontal
);
2390 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2391 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2393 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2396 Dot
:= IfThen(FDirection
= TDirection
.D_LEFT
, 14, 5);
2397 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2398 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
);
2399 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
);
2400 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
);
2401 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
);
2405 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2406 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2407 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2410 procedure TPlayer
.Draw();
2415 Mirror
: TMirrorType
;
2419 if Direction
= TDirection
.D_RIGHT
then
2420 Mirror
:= TMirrorType
.None
2422 Mirror
:= TMirrorType
.Horizontal
;
2424 if FPunchAnim
<> nil then
2426 FPunchAnim
.Draw(FObj
.X
+IfThen(Direction
= TDirection
.D_LEFT
, 15-FObj
.Rect
.X
, FObj
.Rect
.X
-15),
2427 FObj
.Y
+FObj
.Rect
.Y
-11, Mirror
);
2428 if FPunchAnim
.played
then
2435 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2436 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2438 e_GetTextureSize(ID
, @w
, @h
);
2439 if FDirection
= TDirection
.D_LEFT
then
2440 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2441 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False)
2443 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2444 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False);
2447 if FMegaRulez
[MR_INVIS
] > gTime
then
2449 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2450 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2452 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2453 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2457 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 200)
2459 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2462 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 254);
2465 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2468 if g_debug_Frames
then
2470 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2472 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2473 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2477 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2479 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2480 if gAimLine
and alive
and
2481 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2486 procedure TPlayer
.DrawAim();
2487 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2492 {$IFDEF ENABLE_HOLMES}
2493 if isValidViewPort
and (self
= gPlayer1
) then
2495 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2499 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2500 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2502 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2506 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2511 wx
, wy
, xx
, yy
: Integer;
2515 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= TDirection
.D_LEFT
, 7, -7);
2516 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2525 1: begin // Chainsaw
2532 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2533 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2534 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2535 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2540 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2541 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2542 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2543 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2545 4: begin // Double Shotgun
2548 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2549 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2550 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2551 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2553 5: begin // 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);
2561 6: begin // Rocket Launcher
2564 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2565 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2566 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2567 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2569 7: begin // Plasmagun
2572 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2573 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2574 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2575 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2580 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2581 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2582 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2583 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2585 9: begin // Super Chaingun
2588 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2589 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2590 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2591 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2594 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2595 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2596 {$IF DEFINED(D2F_DEBUG)}
2597 drawCast(sz
, wx
, wy
, xx
, yy
);
2599 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2603 procedure TPlayer
.DrawGUI();
2606 X
, Y
, SY
, a
, p
, m
: Integer;
2610 stat
: TPlayerStatArray
;
2612 X
:= gPlayerScreenSize
.X
;
2613 SY
:= gPlayerScreenSize
.Y
;
2616 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2618 if gGameSettings
.GameMode
= GM_CTF
then
2622 if gGameSettings
.GameMode
= GM_CTF
then
2624 s
:= 'TEXTURE_PLAYER_REDFLAG';
2625 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2626 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2627 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2628 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2629 if g_Texture_Get(s
, ID
) then
2630 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2633 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2634 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2635 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2637 if gGameSettings
.GameMode
= GM_CTF
then
2639 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2640 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2641 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2642 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2643 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2644 if g_Texture_Get(s
, ID
) then
2645 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2648 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2649 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2650 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2653 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2654 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2657 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2658 e_Draw(ID
, X
+2, Y
, 0, True, False);
2660 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2664 s
:= IntToStr(Frags
);
2665 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2666 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2671 stat
:= g_Player_GetStats();
2676 for a
:= 0 to High(stat
) do
2677 if stat
[a
].Name
<> Name
then
2679 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2680 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2684 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2685 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2686 s
:= s
+IntToStr(Abs(Frags
-m
));
2688 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2689 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2692 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2694 s
:= IntToStr(Lives
);
2695 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2696 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2700 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2701 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2703 if R_BERSERK
in FRulez
then
2704 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2706 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2708 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2709 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2711 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2712 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2713 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2715 s
:= IntToStr(FArmor
);
2716 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2717 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2719 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2725 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2730 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2732 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2733 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2734 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2735 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2736 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2737 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2738 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2739 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2740 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2743 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2744 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2745 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2747 if R_KEY_RED
in FRulez
then
2748 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2750 if R_KEY_GREEN
in FRulez
then
2751 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2753 if R_KEY_BLUE
in FRulez
then
2754 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2756 if FJetFuel
> 0 then
2758 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2759 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2760 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2761 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2762 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2763 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2767 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2768 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2769 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2772 if gShowPing
and g_Game_IsClient
then
2774 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2775 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2781 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2782 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2783 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2786 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2787 s
:= _lc
[I_PLAYER_SPECT4
];
2788 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2789 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2790 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2796 procedure TPlayer
.DrawRulez();
2800 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2801 if FMegaRulez
[MR_INVUL
] >= gTime
then
2803 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2804 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2809 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2810 191, 191, 191, 0, TBlending
.Invert
);
2813 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2814 if FMegaRulez
[MR_SUIT
] >= gTime
then
2816 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2817 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2822 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2823 0, 96, 0, 200, TBlending
.None
);
2826 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2827 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2829 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2830 255, 0, 0, 200, TBlending
.None
);
2834 procedure TPlayer
.DrawPain();
2838 if FPain
= 0 then Exit
;
2842 if a
< 15 then h
:= 0
2843 else if a
< 35 then h
:= 1
2844 else if a
< 55 then h
:= 2
2845 else if a
< 75 then h
:= 3
2846 else if a
< 95 then h
:= 4
2849 //if a > 255 then a := 255;
2851 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2852 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2855 procedure TPlayer
.DrawPickup();
2859 if FPickup
= 0 then Exit
;
2863 if a
< 15 then h
:= 1
2864 else if a
< 35 then h
:= 2
2865 else if a
< 55 then h
:= 3
2866 else if a
< 75 then h
:= 4
2869 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2872 procedure TPlayer
.DoPunch();
2877 if FPunchAnim
<> nil then begin
2882 st
:= 'FRAMES_PUNCH';
2883 if R_BERSERK
in FRulez
then
2884 st
:= st
+ '_BERSERK';
2885 if FKeys
[KEY_UP
].Pressed
then
2887 else if FKeys
[KEY_DOWN
].Pressed
then
2889 g_Frames_Get(id
, st
);
2890 FPunchAnim
:= TAnimation
.Create(id
, False, 1);
2893 procedure TPlayer
.Fire();
2895 f
, DidFire
: Boolean;
2896 wx
, wy
, xd
, yd
: Integer;
2899 if g_Game_IsClient
then Exit
;
2900 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2901 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2909 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2914 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2915 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2916 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
2917 yd
:= wy
+firediry();
2923 if R_BERSERK
in FRulez
then
2925 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2926 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2927 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2930 locobj
.rect
.Width
:= 39;
2931 locobj
.rect
.Height
:= 52;
2932 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2933 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2934 locobj
.Accel
.X
:= xd
-wx
;
2935 locobj
.Accel
.y
:= yd
-wy
;
2937 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2938 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2940 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2942 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
2946 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2950 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2955 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2956 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2958 FSawSoundSelect
.Stop();
2960 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2962 else if not FSawSoundHit
.IsPlaying() then
2964 FSawSoundSelect
.Stop();
2965 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2968 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2974 if FAmmo
[A_BULLETS
] > 0 then
2976 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2977 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2978 Dec(FAmmo
[A_BULLETS
]);
2979 FFireAngle
:= FAngle
;
2982 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2983 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2987 if FAmmo
[A_SHELLS
] > 0 then
2989 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2990 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
2991 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2992 Dec(FAmmo
[A_SHELLS
]);
2993 FFireAngle
:= FAngle
;
2997 FShellType
:= SHELL_SHELL
;
3001 if FAmmo
[A_SHELLS
] >= 2 then
3003 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
3004 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3005 Dec(FAmmo
[A_SHELLS
], 2);
3006 FFireAngle
:= FAngle
;
3010 FShellType
:= SHELL_DBLSHELL
;
3014 if FAmmo
[A_BULLETS
] > 0 then
3016 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
3017 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
3018 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3019 Dec(FAmmo
[A_BULLETS
]);
3020 FFireAngle
:= FAngle
;
3023 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3024 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3027 WEAPON_ROCKETLAUNCHER
:
3028 if FAmmo
[A_ROCKETS
] > 0 then
3030 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
3031 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3032 Dec(FAmmo
[A_ROCKETS
]);
3033 FFireAngle
:= FAngle
;
3039 if FAmmo
[A_CELLS
] > 0 then
3041 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
3042 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3043 Dec(FAmmo
[A_CELLS
]);
3044 FFireAngle
:= FAngle
;
3050 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
3052 FBFGFireCounter
:= 17;
3053 if not FNoReload
then
3054 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
3055 Dec(FAmmo
[A_CELLS
], 40);
3059 WEAPON_SUPERPULEMET
:
3060 if FAmmo
[A_SHELLS
] > 0 then
3062 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3063 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
3064 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3065 Dec(FAmmo
[A_SHELLS
]);
3066 FFireAngle
:= FAngle
;
3069 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3070 GameVelX
, GameVelY
-2, SHELL_SHELL
);
3073 WEAPON_FLAMETHROWER
:
3074 if FAmmo
[A_FUEL
] > 0 then
3076 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
3077 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3079 FFireAngle
:= FAngle
;
3085 if g_Game_IsNet
then
3089 if FCurrWeap
<> WEAPON_BFG
then
3090 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
3092 if not FNoReload
then
3093 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
3096 MH_SEND_PlayerStats(FUID
);
3101 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
3102 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
3103 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
3106 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
3109 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
3110 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
3111 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
3112 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
3113 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
3118 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
3120 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
3121 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
3122 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
3125 procedure TPlayer
.JetpackOn
;
3129 FJetSoundOn
.SetPosition(0);
3130 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3134 procedure TPlayer
.JetpackOff
;
3138 FJetSoundOff
.SetPosition(0);
3139 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3142 procedure TPlayer
.CatchFire(Attacker
: Word);
3145 FFireAttacker
:= Attacker
;
3146 if g_Game_IsNet
and g_Game_IsServer
then
3147 MH_SEND_PlayerStats(FUID
);
3150 procedure TPlayer
.Jump();
3152 if gFly
or FJetpack
then
3154 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3155 if FObj
.Vel
.Y
> -VEL_FLY
then
3156 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3159 if FJetFuel
> 0 then
3161 if (FJetFuel
< 1) and g_Game_IsServer
then
3165 if g_Game_IsNet
then
3166 MH_SEND_PlayerStats(FUID
);
3172 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3174 FCanJetpack
:= False;
3176 // Ïðûãàåì èëè âñïëûâàåì:
3177 if (CollideLevel(0, 1) or
3178 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3179 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3180 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3182 FObj
.Vel
.Y
:= -VEL_JUMP
;
3183 FCanJetpack
:= False;
3187 if BodyInLiquid(0, 0) then
3188 FObj
.Vel
.Y
:= -VEL_SW
3189 else if (FJetFuel
> 0) and FCanJetpack
and
3190 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3194 if g_Game_IsNet
then
3195 MH_SEND_PlayerStats(FUID
);
3200 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3202 a
, i
, k
, ab
, ar
: Byte;
3206 srv
, netsrv
: Boolean;
3212 procedure PushItem(t
: Byte);
3216 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3217 it
:= g_Items_ByIdx(id
);
3218 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3220 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3221 (FObj
.Vel
.Y
div 2)-Random(9));
3222 it
.positionChanged(); // this updates spatial accelerators
3226 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3228 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3229 (FObj
.Vel
.Y
div 2)-Random(6));
3231 else // -3..+3; -3..0
3233 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3234 (FObj
.Vel
.Y
div 2)-Random(4));
3236 it
.positionChanged(); // this updates spatial accelerators
3239 if g_Game_IsNet
and g_Game_IsServer
then
3240 MH_SEND_ItemSpawn(True, id
);
3244 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3245 Srv
:= g_Game_IsServer
;
3246 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3247 if Srv
then FDeath
:= FDeath
+ 1;
3252 if not FPhysics
then
3258 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3260 if FLives
> 0 then FLives
:= FLives
- 1;
3261 if FLives
= 0 then FNoRespawn
:= True;
3264 // Íîìåð òèïà ñìåðòè:
3267 K_SIMPLEKILL
: a
:= 1;
3269 K_EXTRAHARDKILL
: a
:= 3;
3274 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3276 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3283 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3285 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3286 K_EXTRAHARDKILL
, K_FALLKILL
:
3287 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3290 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3294 K_HARDKILL
, K_EXTRAHARDKILL
:
3298 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3299 if (KillType
<> K_FALLKILL
) and (Srv
) then
3300 g_Monsters_killedp();
3302 if SpawnerUID
= FUID
then
3304 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3309 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3312 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3313 begin // Óáèò äðóãèì èãðîêîì
3314 KP
:= g_Player_Get(SpawnerUID
);
3315 if (KP
<> nil) and Srv
then
3317 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3318 if SameTeam(FUID
, SpawnerUID
) then
3328 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3329 Inc(gTeamStat
[KP
.Team
].Goals
,
3330 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3332 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3335 plr
:= g_Player_Get(SpawnerUID
);
3343 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3347 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3351 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3356 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3357 begin // Óáèò ìîíñòðîì
3358 mon
:= g_Monsters_ByUID(SpawnerUID
);
3362 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
3366 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3370 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3374 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3379 else // Îñîáûå òèïû ñìåðòè
3382 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3383 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3384 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3385 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3386 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3387 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3393 for a
:= WP_FIRST
to WP_LAST
do
3397 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3398 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3399 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3400 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3401 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3402 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3403 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3404 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3405 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3414 if R_ITEM_BACKPACK
in FRulez
then
3415 PushItem(ITEM_AMMO_BACKPACK
);
3417 // Âûáðîñ ðàêåòíîãî ðàíöà:
3418 if FJetFuel
> 0 then
3419 PushItem(ITEM_JETPACK
);
3422 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3424 if R_KEY_RED
in FRulez
then
3425 PushItem(ITEM_KEY_RED
);
3427 if R_KEY_GREEN
in FRulez
then
3428 PushItem(ITEM_KEY_GREEN
);
3430 if R_KEY_BLUE
in FRulez
then
3431 PushItem(ITEM_KEY_BLUE
);
3438 g_Player_CreateCorpse(Self
);
3440 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3441 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3447 for i
:= Low(gPlayers
) to High(gPlayers
) do
3449 if gPlayers
[i
] = nil then continue
;
3450 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3453 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3454 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3459 OldLR
:= gLMSRespawn
;
3460 if (gGameSettings
.GameMode
= GM_COOP
) then
3464 // everyone is dead, restart the map
3465 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3467 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3468 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3469 gLMSRespawnTime
:= gTime
+ 5000;
3471 else if (a
= 1) then
3473 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3474 if (gPlayers
[k
] = gPlayer1
) or
3475 (gPlayers
[k
] = gPlayer2
) then
3476 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3477 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3478 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3481 else if (gGameSettings
.GameMode
= GM_TDM
) then
3483 if (ab
= 0) and (ar
<> 0) then
3486 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3488 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3489 Inc(gTeamStat
[TEAM_RED
].Goals
);
3490 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3491 gLMSRespawnTime
:= gTime
+ 5000;
3493 else if (ar
= 0) and (ab
<> 0) then
3496 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3498 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3499 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3500 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3501 gLMSRespawnTime
:= gTime
+ 5000;
3503 else if (ar
= 0) and (ab
= 0) then
3506 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3508 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3509 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3510 gLMSRespawnTime
:= gTime
+ 5000;
3513 else if (gGameSettings
.GameMode
= GM_DM
) then
3517 if gPlayers
[k
] <> nil then
3520 // survivor is the winner
3521 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3523 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3526 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3527 gLMSRespawnTime
:= gTime
+ 5000;
3529 else if (a
= 0) then
3531 // everyone is dead, restart the map
3532 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3534 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3535 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3536 gLMSRespawnTime
:= gTime
+ 5000;
3539 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3541 if NetMode
= NET_SERVER
then
3542 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3544 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3550 MH_SEND_PlayerStats(FUID
);
3551 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3552 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3555 if srv
and FNoRespawn
then Spectate(True);
3556 FWantsInGame
:= True;
3559 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3561 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3562 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3565 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3567 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3568 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3571 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3573 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3574 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3575 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3576 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3577 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3578 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3579 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3580 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3583 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3585 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3586 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3587 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3588 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3591 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3593 //if g_Game_IsClient then Exit;
3594 if Weapon
> High(FWeapon
) then Exit
;
3595 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3598 procedure TPlayer
.resetWeaponQueue ();
3601 FNextWeapDelay
:= 0;
3604 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3608 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3609 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
3610 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
3611 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3612 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3613 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3614 else result
:= (weapon
< length(FWeapon
));
3618 // return 255 for "no switch"
3619 function TPlayer
.getNextWeaponIndex (): Byte;
3622 wantThisWeapon
: array[0..64] of Boolean;
3623 weaponOrder
: array[0..16] of Integer; // value: index in `FWeapon`
3625 f
, dir
, cwi
, rwidx
, curlidx
: Integer;
3627 function real2log (ridx
: Integer): Integer;
3633 for f
:= 0 to High(weaponOrder
) do if (weaponOrder
[f
] = ridx
) then begin result
:= f
; exit
; end;
3639 result
:= 255; // default result: "no switch"
3641 // had weapon cycling on previous frame? remove that flag
3642 if (FNextWeap
and $2000) <> 0 then
3644 FNextWeap
:= FNextWeap
and $1FFF;
3645 FNextWeapDelay
:= 0;
3648 for f
:= 0 to High(weaponOrder
) do weaponOrder
[f
] := -1;
3650 // build weapon order (k8: i know, i know, learn how to do constants and such... gtfo, please!)
3651 // two knuckles are for "normal" and "berserk" (see `if` below -- it removes the one that is not needed)
3653 // bfg, launcher, plasma, flamethrower, ssg, minigun, sg, pistol, berserk, chainsaw, fist
3654 weaponOrder
[0] := WEAPON_SUPERPULEMET
;
3655 weaponOrder
[1] := WEAPON_BFG
;
3656 weaponOrder
[2] := WEAPON_ROCKETLAUNCHER
;
3657 weaponOrder
[3] := WEAPON_PLASMA
;
3658 weaponOrder
[4] := WEAPON_FLAMETHROWER
;
3659 weaponOrder
[5] := WEAPON_SHOTGUN2
;
3660 weaponOrder
[6] := WEAPON_CHAINGUN
;
3661 weaponOrder
[7] := WEAPON_SHOTGUN1
;
3662 weaponOrder
[8] := WEAPON_PISTOL
;
3663 weaponOrder
[9] := WEAPON_KASTET
+666; // berserk fist
3664 weaponOrder
[10] := WEAPON_SAW
;
3665 weaponOrder
[11] := WEAPON_KASTET
; // normal fist
3667 for f
:= 0 to High(weaponOrder
) do
3669 if (weaponOrder
[f
] = WEAPON_KASTET
) then
3671 // normal fist: remove if we have a berserk pack
3672 if (R_BERSERK
in FRulez
) then weaponOrder
[f
] := -1;
3675 if (weaponOrder
[f
] = WEAPON_KASTET
+666) then
3677 // berserk fist: remove if we don't have a berserk pack
3678 if (R_BERSERK
in FRulez
) then weaponOrder
[f
] := WEAPON_KASTET
else weaponOrder
[f
] := -1;
3686 WEAPON_SHOTGUN1 = 3;
3687 WEAPON_SHOTGUN2 = 4;
3688 WEAPON_CHAINGUN = 5;
3689 WEAPON_ROCKETLAUNCHER = 6;
3692 WEAPON_SUPERPULEMET = 9;
3693 WEAPON_FLAMETHROWER = 10;
3696 // cycling has priority
3697 if (FNextWeap
and $C000) <> 0 then
3699 if (FNextWeap
and $8000) <> 0 then dir
:= 1 else dir
:= -1; // should be reversed if we want "priority-driven cycling"
3700 FNextWeap
:= FNextWeap
or $2000; // we need this
3701 if FNextWeapDelay
> 0 then exit
; // cooldown time
3702 //cwi := real2log(FCurrWeap);
3703 //if (cwi < 0) then cwi := 0;
3705 for i
:= 0 to High(FWeapon
) do
3707 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3708 //rwidx := weaponOrder[cwi];
3709 rwidx
:= cwi
; // sorry
3710 if (rwidx
< 0) then continue
;
3711 if FWeapon
[rwidx
] then
3713 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d (dir=%d; log=%d)', [FCurrWeap, rwidx, dir, cwi]), TMsgType.Warning);
3714 result
:= Byte(rwidx
);
3715 //FNextWeapDelay := 10; //k8: not needed anymore
3724 for i
:= 0 to High(wantThisWeapon
) do wantThisWeapon
[i
] := false;
3727 curlidx
:= -1; // start from a weapon with a highest priority (-1, 'cause loop will immediately increment this index)
3729 for i
:= 0 to High(FWeapon
) do
3731 if (FNextWeap
and (1 shl i
)) <> 0 then
3736 wantThisWeapon
[cwi
] := true;
3738 // if we hit currently selected weapon, start seachring from it, so we'll get "next weaker" weapon
3739 if (i
= FCurrWeap
) then curlidx
:= cwi
; // compare real, start from logical
3744 // slow down alterations a little
3747 // more than one weapon requested, assume "alteration", and check alteration delay
3748 if FNextWeapDelay
> 0 then
3750 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), TMsgType.Warning);
3756 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3757 // but clear all counters if no weapon should be switched
3764 //e_WriteLog(Format('*** wwc=%d; currweap=%d; logweap=%d', [wwc, FCurrWeap, curlidx]), TMsgType.Warning);
3766 // find next weapon to switch onto
3768 for i
:= 0 to High(weaponOrder
) do
3770 cwi
:= (cwi
+length(weaponOrder
)+1) mod length(weaponOrder
);
3771 if (cwi
= curlidx
) then continue
; // skip current weapon
3772 if not wantThisWeapon
[cwi
] then continue
;
3773 rwidx
:= weaponOrder
[cwi
];
3774 if (rwidx
< 0) then continue
;
3775 //e_WriteLog(Format(' trying logical %d (real %d); has=%d, hasammo=%d', [cwi, rwidx, Integer(FWeapon[rwidx]), Integer(hasAmmoForWeapon(rwidx))]), TMsgType.Warning);
3776 if FWeapon
[rwidx
] and ((wwc
= 1) or hasAmmoForWeapon(rwidx
)) then
3778 //e_WriteLog(' I FOUND HER!', TMsgType.Warning);
3780 result
:= Byte(rwidx
);
3782 //FNextWeapDelay := 10; // anyway, 'cause why not; k8: not needed anymore
3787 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3791 procedure TPlayer
.RealizeCurrentWeapon();
3792 function switchAllowed (): Boolean;
3797 if FBFGFireCounter
<> -1 then
3799 if FTime
[T_SWITCH
] > gTime
then
3801 for i
:= WP_FIRST
to WP_LAST
do
3802 if FReloading
[i
] > 0 then
3810 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3811 //FNextWeap := FNextWeap and $1FFF;
3812 //HACK: alteration delay will be reset when player released any weapon switch key
3813 FNextWeapDelay
:= 0; //k8: just in case
3814 //if FNextWeapDelay > 0 then Dec(FNextWeapDelay); // "alteration delay"
3816 if not switchAllowed
then
3818 //HACK for weapon cycling
3819 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3823 nw
:= getNextWeaponIndex();
3824 if nw
= 255 then exit
; // don't reset anything here
3825 if nw
> High(FWeapon
) then
3827 // don't forget to reset queue here!
3828 //e_WriteLog(Format(' RealizeCurrentWeapon: WUTAFUUUU?! (%d)', [nw]), TMsgType.Warning);
3836 FTime
[T_SWITCH
] := gTime
+156;
3837 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3838 FModel
.SetWeapon(FCurrWeap
);
3839 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3843 procedure TPlayer
.NextWeapon();
3845 //if g_Game_IsClient then Exit;
3849 procedure TPlayer
.PrevWeapon();
3851 //if g_Game_IsClient then Exit;
3855 procedure TPlayer
.SetWeapon(W
: Byte);
3857 if FCurrWeap
<> W
then
3858 if W
= WEAPON_SAW
then
3859 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3862 FModel
.SetWeapon(CurrWeap
);
3866 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3868 function allowBerserkSwitching (): Boolean;
3870 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3872 if gBerserkAutoswitch
then exit
;
3873 if not conIsCheatsEnabled
then exit
;
3881 if g_Game_IsClient
then Exit
;
3883 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3884 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3889 if FHealth
< PLAYER_HP_SOFT
then
3891 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3895 if gFlash
= 2 then Inc(FPickup
, 5);
3899 if FHealth
< PLAYER_HP_SOFT
then
3901 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3905 if gFlash
= 2 then Inc(FPickup
, 5);
3909 if FArmor
< PLAYER_AP_SOFT
then
3911 FArmor
:= PLAYER_AP_SOFT
;
3914 if gFlash
= 2 then Inc(FPickup
, 5);
3918 if FArmor
< PLAYER_AP_LIMIT
then
3920 FArmor
:= PLAYER_AP_LIMIT
;
3923 if gFlash
= 2 then Inc(FPickup
, 5);
3927 if FHealth
< PLAYER_HP_LIMIT
then
3929 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3933 if gFlash
= 2 then Inc(FPickup
, 5);
3937 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3939 if FHealth
< PLAYER_HP_LIMIT
then
3940 FHealth
:= PLAYER_HP_LIMIT
;
3941 if FArmor
< PLAYER_AP_LIMIT
then
3942 FArmor
:= PLAYER_AP_LIMIT
;
3946 if gFlash
= 2 then Inc(FPickup
, 5);
3950 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3952 FWeapon
[WEAPON_SAW
] := True;
3954 if gFlash
= 2 then Inc(FPickup
, 5);
3955 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3958 ITEM_WEAPON_SHOTGUN1
:
3959 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3961 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3962 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3964 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3965 FWeapon
[WEAPON_SHOTGUN1
] := True;
3967 if gFlash
= 2 then Inc(FPickup
, 5);
3968 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3971 ITEM_WEAPON_SHOTGUN2
:
3972 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3974 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3976 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3977 FWeapon
[WEAPON_SHOTGUN2
] := True;
3979 if gFlash
= 2 then Inc(FPickup
, 5);
3980 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3983 ITEM_WEAPON_CHAINGUN
:
3984 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3986 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3988 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3989 FWeapon
[WEAPON_CHAINGUN
] := True;
3991 if gFlash
= 2 then Inc(FPickup
, 5);
3992 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3995 ITEM_WEAPON_ROCKETLAUNCHER
:
3996 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3998 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
4000 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
4001 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
4003 if gFlash
= 2 then Inc(FPickup
, 5);
4004 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4008 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
4010 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
4012 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4013 FWeapon
[WEAPON_PLASMA
] := True;
4015 if gFlash
= 2 then Inc(FPickup
, 5);
4016 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4020 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
4022 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
4024 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4025 FWeapon
[WEAPON_BFG
] := True;
4027 if gFlash
= 2 then Inc(FPickup
, 5);
4028 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4031 ITEM_WEAPON_SUPERPULEMET
:
4032 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
4034 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
4036 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4037 FWeapon
[WEAPON_SUPERPULEMET
] := True;
4039 if gFlash
= 2 then Inc(FPickup
, 5);
4040 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4043 ITEM_WEAPON_FLAMETHROWER
:
4044 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
4046 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
4048 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4049 FWeapon
[WEAPON_FLAMETHROWER
] := True;
4051 if gFlash
= 2 then Inc(FPickup
, 5);
4052 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4056 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4058 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4061 if gFlash
= 2 then Inc(FPickup
, 5);
4064 ITEM_AMMO_BULLETS_BOX
:
4065 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4067 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4070 if gFlash
= 2 then Inc(FPickup
, 5);
4074 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4076 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4079 if gFlash
= 2 then Inc(FPickup
, 5);
4082 ITEM_AMMO_SHELLS_BOX
:
4083 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4085 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
4088 if gFlash
= 2 then Inc(FPickup
, 5);
4092 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4094 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4097 if gFlash
= 2 then Inc(FPickup
, 5);
4100 ITEM_AMMO_ROCKET_BOX
:
4101 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4103 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
4106 if gFlash
= 2 then Inc(FPickup
, 5);
4110 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4112 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4115 if gFlash
= 2 then Inc(FPickup
, 5);
4119 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4121 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4124 if gFlash
= 2 then Inc(FPickup
, 5);
4128 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4130 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4133 if gFlash
= 2 then Inc(FPickup
, 5);
4137 if not(R_ITEM_BACKPACK
in FRulez
) or
4138 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4139 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4140 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4141 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4142 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
4144 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4145 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4146 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4147 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4148 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4150 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4151 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4152 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4153 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4154 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4155 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4156 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4157 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4159 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
4162 if gFlash
= 2 then Inc(FPickup
, 5);
4166 if not(R_KEY_RED
in FRulez
) then
4168 Include(FRulez
, R_KEY_RED
);
4170 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4171 if gFlash
= 2 then Inc(FPickup
, 5);
4172 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4176 if not(R_KEY_GREEN
in FRulez
) then
4178 Include(FRulez
, R_KEY_GREEN
);
4180 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4181 if gFlash
= 2 then Inc(FPickup
, 5);
4182 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4186 if not(R_KEY_BLUE
in FRulez
) then
4188 Include(FRulez
, R_KEY_BLUE
);
4190 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4191 if gFlash
= 2 then Inc(FPickup
, 5);
4192 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4196 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4198 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4202 if gFlash
= 2 then Inc(FPickup
, 5);
4206 if FAir
< AIR_MAX
then
4211 if gFlash
= 2 then Inc(FPickup
, 5);
4216 if not (R_BERSERK
in FRulez
) then
4218 Include(FRulez
, R_BERSERK
);
4219 if allowBerserkSwitching
then
4221 FCurrWeap
:= WEAPON_KASTET
;
4223 FModel
.SetWeapon(WEAPON_KASTET
);
4228 if gFlash
= 2 then Inc(FPickup
, 5);
4230 FBerserk
:= gTime
+30000;
4234 //k8:do we need it? if g_Game_IsNet and g_Game_IsServer then MH_SEND_PlayerStats(FUID);
4236 if FHealth
< PLAYER_HP_SOFT
then
4238 FHealth
:= PLAYER_HP_SOFT
;
4239 FBerserk
:= gTime
+30000;
4247 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4249 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4252 if gFlash
= 2 then Inc(FPickup
, 5);
4256 if FHealth
< PLAYER_HP_LIMIT
then
4258 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4262 if gFlash
= 2 then Inc(FPickup
, 5);
4266 if FArmor
< PLAYER_AP_LIMIT
then
4268 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4271 if gFlash
= 2 then Inc(FPickup
, 5);
4275 if FJetFuel
< JET_MAX
then
4277 FJetFuel
:= JET_MAX
;
4280 if gFlash
= 2 then Inc(FPickup
, 5);
4284 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4286 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4289 if gFlash
= 2 then Inc(FPickup
, 5);
4294 procedure TPlayer
.Touch();
4298 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4301 // Áðîñèòü ôëàã òîâàðèùó:
4302 if gGameSettings
.GameMode
= GM_CTF
then
4307 procedure TPlayer
.Push(vx
, vy
: Integer);
4309 if (not FPhysics
) and FGhost
then
4311 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4312 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4313 if g_Game_IsNet
and g_Game_IsServer
then
4314 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4317 procedure TPlayer
.Reset(Force
: Boolean);
4323 FTime
[T_RESPAWN
] := 0;
4324 FTime
[T_FLAGCAP
] := 0;
4337 FSpectator
:= False;
4340 FSpectatePlayer
:= -1;
4341 FNoRespawn
:= False;
4343 FLives
:= gGameSettings
.MaxLives
;
4348 procedure TPlayer
.SoftReset();
4354 FBFGFireCounter
:= -1;
4362 SetAction(A_STAND
, True);
4365 function TPlayer
.GetRespawnPoint(): Byte;
4370 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4372 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4373 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4375 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4377 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4378 if Self
= gPlayer1
then
4379 c
:= RESPAWNPOINT_PLAYER1
4381 c
:= RESPAWNPOINT_PLAYER2
;
4382 if g_Map_GetPointCount(c
) > 0 then
4388 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4389 if Self
= gPlayer1
then
4390 c
:= RESPAWNPOINT_PLAYER2
4392 c
:= RESPAWNPOINT_PLAYER1
;
4393 if g_Map_GetPointCount(c
) > 0 then
4400 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4401 if Random(2) = 0 then
4402 c
:= RESPAWNPOINT_PLAYER1
4404 c
:= RESPAWNPOINT_PLAYER2
;
4405 if g_Map_GetPointCount(c
) > 0 then
4412 // Òî÷êà ëþáîé èç êîìàíä
4413 if Random(2) = 0 then
4414 c
:= RESPAWNPOINT_RED
4416 c
:= RESPAWNPOINT_BLUE
;
4417 if g_Map_GetPointCount(c
) > 0 then
4424 c
:= RESPAWNPOINT_DM
;
4425 if g_Map_GetPointCount(c
) > 0 then
4433 if gGameSettings
.GameMode
= GM_DM
then
4436 c
:= RESPAWNPOINT_DM
;
4437 if g_Map_GetPointCount(c
) > 0 then
4443 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4444 if Random(2) = 0 then
4445 c
:= RESPAWNPOINT_PLAYER1
4447 c
:= RESPAWNPOINT_PLAYER2
;
4448 if g_Map_GetPointCount(c
) > 0 then
4454 // Òî÷êà ëþáîé èç êîìàíä
4455 if Random(2) = 0 then
4456 c
:= RESPAWNPOINT_RED
4458 c
:= RESPAWNPOINT_BLUE
;
4459 if g_Map_GetPointCount(c
) > 0 then
4467 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4469 // Òî÷êà ñâîåé êîìàíäû
4470 c
:= RESPAWNPOINT_DM
;
4471 if FTeam
= TEAM_RED
then
4472 c
:= RESPAWNPOINT_RED
;
4473 if FTeam
= TEAM_BLUE
then
4474 c
:= RESPAWNPOINT_BLUE
;
4475 if g_Map_GetPointCount(c
) > 0 then
4482 c
:= RESPAWNPOINT_DM
;
4483 if g_Map_GetPointCount(c
) > 0 then
4489 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4490 if Random(2) = 0 then
4491 c
:= RESPAWNPOINT_PLAYER1
4493 c
:= RESPAWNPOINT_PLAYER2
;
4494 if g_Map_GetPointCount(c
) > 0 then
4500 // Òî÷êà äðóãîé êîìàíäû
4501 c
:= RESPAWNPOINT_DM
;
4502 if FTeam
= TEAM_RED
then
4503 c
:= RESPAWNPOINT_BLUE
;
4504 if FTeam
= TEAM_BLUE
then
4505 c
:= RESPAWNPOINT_RED
;
4506 if g_Map_GetPointCount(c
) > 0 then
4514 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4516 RespawnPoint
: TRespawnPoint
;
4522 FBFGFireCounter
:= -1;
4527 if not g_Game_IsServer
then
4531 FWantsInGame
:= True;
4532 FJustTeleported
:= True;
4535 FTime
[T_RESPAWN
] := 0;
4539 // if server changes MaxLives we gotta be ready
4540 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4542 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4543 if FTime
[T_RESPAWN
] > gTime
then
4546 // Ïðîñðàë âñå æèçíè:
4549 if not FSpectator
then Spectate(True);
4550 FWantsInGame
:= True;
4554 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4555 begin // "Ñâîÿ èãðà"
4556 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4557 FRulez
:= FRulez
-[R_BERSERK
];
4559 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4561 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4562 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4565 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4566 c
:= GetRespawnPoint();
4571 // Âîñêðåøåíèå áåç îðóæèÿ:
4574 FHealth
:= PLAYER_HP_SOFT
;
4580 for a
:= WP_FIRST
to WP_LAST
do
4582 FWeapon
[a
] := False;
4586 FWeapon
[WEAPON_PISTOL
] := True;
4587 FWeapon
[WEAPON_KASTET
] := True;
4588 FCurrWeap
:= WEAPON_PISTOL
;
4591 FModel
.SetWeapon(FCurrWeap
);
4593 for b
:= A_BULLETS
to A_HIGH
do
4596 FAmmo
[A_BULLETS
] := 50;
4598 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4599 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4600 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4601 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4602 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4604 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4605 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4610 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4611 if not g_Map_GetPoint(c
, RespawnPoint
) then
4613 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4617 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4618 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4619 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4625 FDirection
:= RespawnPoint
.Direction
;
4626 if FDirection
= TDirection
.D_LEFT
then
4631 SetAction(A_STAND
, True);
4632 FModel
.Direction
:= FDirection
;
4634 for a
:= Low(FTime
) to High(FTime
) do
4637 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4642 FCanJetpack
:= False;
4647 // Àíèìàöèÿ âîçðîæäåíèÿ:
4648 if (not gLoadGameMode
) and (not Silent
) then
4649 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4651 Anim
:= TAnimation
.Create(ID
, False, 3);
4652 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4653 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4657 FSpectator
:= False;
4660 FSpectatePlayer
:= -1;
4663 if (gPlayer1
= nil) and (gLMSPID1
= FUID
) then
4665 if (gPlayer2
= nil) and (gLMSPID2
= FUID
) then
4668 if g_Game_IsNet
then
4670 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4671 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4673 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4674 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4679 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4682 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4683 else if (not NoMove
) then
4685 GameX
:= gMapInfo
.Width
div 2;
4686 GameY
:= gMapInfo
.Height
div 2;
4695 FWantsInGame
:= False;
4700 if Self
= gPlayer1
then
4705 if Self
= gPlayer2
then
4712 if g_Game_IsNet
then
4713 MH_SEND_PlayerStats(FUID
);
4716 procedure TPlayer
.SwitchNoClip
;
4720 FGhost
:= not FGhost
;
4721 FPhysics
:= not FGhost
;
4733 procedure TPlayer
.Run(Direction
: TDirection
);
4737 if MAX_RUNVEL
> 8 then
4741 if Direction
= TDirection
.D_LEFT
then
4743 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4744 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4747 if FObj
.Vel
.X
< MAX_RUNVEL
then
4748 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4750 // Âîçìîæíî, ïèíàåì êóñêè:
4751 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4753 b
:= Abs(FObj
.Vel
.X
);
4754 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4755 for a
:= 0 to High(gGibs
) do
4757 if gGibs
[a
].alive
and
4758 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4759 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4762 if FObj
.Vel
.X
< 0 then
4764 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4768 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4770 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4778 procedure TPlayer
.SeeDown();
4780 SetAction(A_SEEDOWN
);
4782 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4784 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4787 procedure TPlayer
.SeeUp();
4791 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4793 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4796 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4804 A_ATTACK
: Prior
:= 2;
4805 A_SEEUP
: Prior
:= 1;
4806 A_SEEDOWN
: Prior
:= 1;
4807 A_ATTACKUP
: Prior
:= 2;
4808 A_ATTACKDOWN
: Prior
:= 2;
4813 if (Prior
> FActionPrior
) or Force
then
4814 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4816 FActionPrior
:= Prior
;
4817 FActionAnim
:= Action
;
4818 FActionForce
:= Force
;
4819 FActionChanged
:= True;
4822 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4825 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4827 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4828 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4829 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4830 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4833 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4840 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4842 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4843 if g_Game_IsServer
and g_Game_IsNet
then
4844 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4848 FJustTeleported
:= True;
4853 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4855 Anim
:= TAnimation
.Create(ID
, False, 3);
4858 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4859 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4860 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4861 if g_Game_IsServer
and g_Game_IsNet
then
4862 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4863 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4867 FObj
.X
:= X
-PLAYER_RECT
.X
;
4868 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4869 if FAlive
and FGhost
then
4875 if not g_Game_IsNet
then
4879 SetDirection(TDirection
.D_LEFT
);
4885 SetDirection(TDirection
.D_RIGHT
);
4891 if FDirection
= TDirection
.D_RIGHT
then
4893 SetDirection(TDirection
.D_LEFT
);
4898 SetDirection(TDirection
.D_RIGHT
);
4904 if not silent
and (Anim
<> nil) then
4906 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4907 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4910 if g_Game_IsServer
and g_Game_IsNet
then
4911 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4912 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4919 function nonz(a
: Single): Single;
4927 function TPlayer
.followCorpse(): Boolean;
4932 if FAlive
or FSpectator
then
4934 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
4936 for i
:= 0 to High(gCorpses
) do
4937 if gCorpses
[i
] <> nil then
4938 if gCorpses
[i
].FPlayerUID
= FUID
then
4941 FObj
.X
:= gCorpses
[i
].FObj
.X
;
4942 FObj
.Y
:= gCorpses
[i
].FObj
.Y
;
4943 FObj
.Vel
.X
:= gCorpses
[i
].FObj
.Vel
.X
;
4944 FObj
.Vel
.Y
:= gCorpses
[i
].FObj
.Vel
.Y
;
4945 FObj
.Accel
.X
:= gCorpses
[i
].FObj
.Accel
.X
;
4946 FObj
.Accel
.Y
:= gCorpses
[i
].FObj
.Accel
.Y
;
4951 procedure TPlayer
.Update();
4954 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4955 blockmon
, headwater
, dospawn
: Boolean;
4960 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4961 AnyServer
:= g_Game_IsServer
;
4963 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4964 DoLerp(NetInterpLevel
+ 1)
4971 if FClientID
>= 0 then
4973 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4974 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4975 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4985 if FAlive
and (FPunchAnim
<> nil) then
4986 FPunchAnim
.Update();
4988 if FAlive
and (gFly
or FJetpack
) then
4991 if FDirection
= TDirection
.D_LEFT
then
4996 if FAlive
and (not FGhost
) then
4998 if FKeys
[KEY_UP
].Pressed
then
5000 if FKeys
[KEY_DOWN
].Pressed
then
5004 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
5007 i
:= g_basic
.Sign(FIncCam
);
5008 FIncCam
:= Abs(FIncCam
);
5009 DecMin(FIncCam
, 5, 0);
5010 FIncCam
:= FIncCam
*i
;
5013 // no need to do that each second frame, weapon queue will take care of it
5014 if FAlive
and FKeys
[KEY_NEXTWEAPON
].Pressed
{and AnyServer} then NextWeapon();
5015 if FAlive
and FKeys
[KEY_PREVWEAPON
].Pressed
{and AnyServer} then PrevWeapon();
5017 if gTime
mod (GAME_TICK
*2) <> 0 then
5019 if (FObj
.Vel
.X
= 0) and FAlive
then
5021 if FKeys
[KEY_LEFT
].Pressed
then
5022 Run(TDirection
.D_LEFT
);
5023 if FKeys
[KEY_RIGHT
].Pressed
then
5024 Run(TDirection
.D_RIGHT
);
5029 if not followCorpse() then
5030 g_Obj_Move(@FObj
, True, True, True);
5031 positionChanged(); // this updates spatial accelerators
5037 FActionChanged
:= False;
5041 // Let alive player do some actions
5042 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
5043 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
5044 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
5045 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
5046 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
5047 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
5048 if FKeys
[KEY_JUMP
].Pressed
then Jump()
5051 if AnyServer
and FJetpack
then
5055 if NetServer
then MH_SEND_PlayerStats(FUID
);
5057 FCanJetpack
:= True;
5064 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
5066 if FKeys
[k
].Pressed
then
5074 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5077 if (FTime
[T_RESPAWN
] <= gTime
) and
5078 gGameOn
and (not FAlive
) then
5080 if (g_Player_GetCount() > 1) then
5084 gExit
:= EXIT_RESTART
;
5089 // Dead spectator actions
5092 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
5093 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
5097 if (FSpectatePlayer
>= High(gPlayers
)) then
5098 FSpectatePlayer
:= -1
5102 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
5103 if gPlayers
[I
] <> nil then
5104 if gPlayers
[I
].alive
then
5105 if gPlayers
[I
].UID
<> FUID
then
5107 FSpectatePlayer
:= I
;
5112 if not SetSpect
then FSpectatePlayer
:= -1;
5123 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5125 FYTo
:= FObj
.Y
- 32;
5126 FSpectatePlayer
:= -1;
5128 if FKeys
[KEY_DOWN
].Pressed
then
5130 FYTo
:= FObj
.Y
+ 32;
5131 FSpectatePlayer
:= -1;
5133 if FKeys
[KEY_LEFT
].Pressed
then
5135 FXTo
:= FObj
.X
- 32;
5136 FSpectatePlayer
:= -1;
5138 if FKeys
[KEY_RIGHT
].Pressed
then
5140 FXTo
:= FObj
.X
+ 32;
5141 FSpectatePlayer
:= -1;
5144 if (FXTo
< -64) then
5146 else if (FXTo
> gMapInfo
.Width
+ 32) then
5147 FXTo
:= gMapInfo
.Width
+ 32;
5148 if (FYTo
< -72) then
5150 else if (FYTo
> gMapInfo
.Height
+ 32) then
5151 FYTo
:= gMapInfo
.Height
+ 32;
5156 if not followCorpse() then
5157 g_Obj_Move(@FObj
, True, True, True);
5158 positionChanged(); // this updates spatial accelerators
5165 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5166 if gPlayers
[FSpectatePlayer
] <> nil then
5167 if gPlayers
[FSpectatePlayer
].alive
then
5169 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
5170 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
5174 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5175 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5176 PANEL_BLOCKMON
, True);
5177 headwater
:= HeadInLiquid(0, 0);
5179 // Ñîïðîòèâëåíèå âîçäóõà:
5180 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5181 if FObj
.Vel
.X
<> 0 then
5182 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5184 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5185 DecMin(FPain
, 5, 0);
5186 DecMin(FPickup
, 1, 0);
5188 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5190 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5191 FMegaRulez
[MR_SUIT
] := 0;
5192 FMegaRulez
[MR_INVUL
] := 0;
5193 FMegaRulez
[MR_INVIS
] := 0;
5194 Kill(K_FALLKILL
, 0, HIT_FALL
);
5201 if FCurrWeap
= WEAPON_SAW
then
5202 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5203 FSawSoundSelect
.IsPlaying()) then
5204 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5207 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5208 (not FJetSoundOff
.IsPlaying()) then
5210 FJetSoundFly
.SetPosition(0);
5211 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5214 for b
:= WP_FIRST
to WP_LAST
do
5215 if FReloading
[b
] > 0 then
5221 if FShellTimer
> -1 then
5222 if FShellTimer
= 0 then
5224 if FShellType
= SHELL_SHELL
then
5225 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5226 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5227 else if FShellType
= SHELL_DBLSHELL
then
5229 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5230 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5231 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5232 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5235 end else Dec(FShellTimer
);
5237 if (FBFGFireCounter
> -1) then
5238 if FBFGFireCounter
= 0 then
5242 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5243 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5244 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5245 yd
:= wy
+firediry();
5246 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5247 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5248 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5249 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5250 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5253 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5254 FBFGFireCounter
:= -1;
5257 FBFGFireCounter
:= 0
5259 Dec(FBFGFireCounter
);
5261 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5263 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5265 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5268 if (headwater
or blockmon
) then
5274 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5277 else if (FAir
mod 31 = 0) and not blockmon
then
5279 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5280 if Random(2) = 0 then
5281 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5283 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5285 end else if FAir
< AIR_DEF
then
5288 if FFireTime
> 0 then
5290 if BodyInLiquid(0, 0) then
5295 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5297 if FMegaRulez
[MR_SUIT
] = gTime
then
5304 if FFirePainTime
<= 0 then
5306 if g_Game_IsServer
then
5307 Damage(5, FFireAttacker
, 0, 0, HIT_FLAME
);
5308 FFirePainTime
:= 18;
5310 FFirePainTime
:= FFirePainTime
- 1;
5311 FFireTime
:= FFireTime
- 1;
5312 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5313 MH_SEND_PlayerStats(FUID
);
5317 if FDamageBuffer
> 0 then
5319 if FDamageBuffer
>= 9 then
5323 if FDamageBuffer
< 30 then i
:= 9
5324 else if FDamageBuffer
< 100 then i
:= 18
5328 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5329 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5330 FHealth
:= FHealth
-ii
;
5333 FHealth
:= FHealth
+FArmor
;
5338 if FHealth
<= 0 then
5339 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5340 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5341 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5345 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5346 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5347 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5348 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5355 end; // if FAlive then ...
5357 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5359 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5360 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5361 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5362 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5364 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5365 then SetAction(A_STAND
, True);
5367 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5369 for b
:= Low(FKeys
) to High(FKeys
) do
5370 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5374 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5376 x
:= FObj
.X
+PLAYER_RECT
.X
;
5377 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5378 w
:= PLAYER_RECT
.Width
;
5379 h
:= PLAYER_RECT
.Height
;
5383 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5385 if (dx
<> 0) or (dy
<> 0) then
5394 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5396 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5397 FObj
.Y
+PLAYER_RECT
.Y
,
5404 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5406 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5407 FObj
.Y
+PLAYER_RECT
.Y
,
5411 Panel
.Width
, Panel
.Height
);
5414 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5416 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5417 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5418 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5419 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5422 function g_Player_ValidName(Name
: string): Boolean;
5428 if gPlayers
= nil then Exit
;
5430 for a
:= 0 to High(gPlayers
) do
5431 if gPlayers
[a
] <> nil then
5432 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5439 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5443 d
:= FModel
.Direction
;
5445 FModel
.Direction
:= Direction
;
5446 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5448 FDirection
:= Direction
;
5451 function TPlayer
.GetKeys(): Byte;
5455 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5456 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5457 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5459 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5460 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5463 procedure TPlayer
.Use();
5467 if FTime
[T_USE
] > gTime
then Exit
;
5469 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5470 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5472 for a
:= 0 to High(gPlayers
) do
5473 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5474 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5475 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5476 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5478 gPlayers
[a
].Touch();
5479 if g_Game_IsNet
and g_Game_IsServer
then
5480 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5483 FTime
[T_USE
] := gTime
+120;
5486 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5490 WX
, WY
, XD
, YD
: Integer;
5502 if R_BERSERK
in FRulez
then
5504 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5505 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5506 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5509 locobj
.rect
.Width
:= 39;
5510 locobj
.rect
.Height
:= 52;
5511 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5512 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5513 locobj
.Accel
.X
:= xd
-wx
;
5514 locobj
.Accel
.y
:= yd
-wy
;
5516 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5517 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5519 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5523 FPain
:= min(FPain
+ 25, 50);
5525 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5530 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5531 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5533 FSawSoundSelect
.Stop();
5535 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5537 else if not FSawSoundHit
.IsPlaying() then
5539 FSawSoundSelect
.Stop();
5540 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5547 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5548 FFireAngle
:= FAngle
;
5550 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5551 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5556 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5557 FFireAngle
:= FAngle
;
5560 FShellType
:= SHELL_SHELL
;
5565 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5566 FFireAngle
:= FAngle
;
5569 FShellType
:= SHELL_DBLSHELL
;
5574 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5575 FFireAngle
:= FAngle
;
5577 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5578 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5581 WEAPON_ROCKETLAUNCHER
:
5583 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5584 FFireAngle
:= FAngle
;
5590 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5591 FFireAngle
:= FAngle
;
5597 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5598 FFireAngle
:= FAngle
;
5602 WEAPON_SUPERPULEMET
:
5604 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5605 FFireAngle
:= FAngle
;
5607 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5608 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5611 WEAPON_FLAMETHROWER
:
5613 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5614 FFireAngle
:= FAngle
;
5621 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5622 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5623 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5626 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5628 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5629 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5632 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5636 if NetInterpLevel
< 1 then
5646 AX
:= Abs(FXTo
- FObj
.X
);
5647 AY
:= Abs(FYTo
- FObj
.Y
);
5648 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5650 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5655 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5657 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5658 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5659 PANEL_LIFTUP
, False) then Result
:= -1
5661 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5662 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5663 PANEL_LIFTDOWN
, False) then Result
:= 1
5667 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5674 if Flag
= FLAG_NONE
then
5677 if not g_Game_IsServer
then Exit
;
5679 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5680 if (Flag
= FTeam
) and
5681 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5682 (FFlag
<> FLAG_NONE
) then
5684 if FFlag
= FLAG_RED
then
5685 s
:= _lc
[I_PLAYER_FLAG_RED
]
5687 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5689 evtype
:= FLAG_STATE_SCORED
;
5691 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5692 Insert('.', ts
, Length(ts
) + 1 - 3);
5693 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5695 g_Map_ResetFlag(FFlag
);
5696 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5698 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5701 if g_Game_IsNet
then
5703 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5707 gFlags
[FFlag
].CaptureTime
:= 0;
5712 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5713 if (Flag
= FTeam
) and
5714 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5716 if Flag
= FLAG_RED
then
5717 s
:= _lc
[I_PLAYER_FLAG_RED
]
5719 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5721 evtype
:= FLAG_STATE_RETURNED
;
5722 gFlags
[Flag
].CaptureTime
:= 0;
5724 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5726 g_Map_ResetFlag(Flag
);
5727 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5730 if g_Game_IsNet
then
5732 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5738 // Ïîäîáðàë ÷óæîé ôëàã:
5739 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5743 if Flag
= FLAG_RED
then
5744 s
:= _lc
[I_PLAYER_FLAG_RED
]
5746 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5748 evtype
:= FLAG_STATE_CAPTURED
;
5750 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5752 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5754 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5757 if g_Game_IsNet
then
5759 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5765 procedure TPlayer
.SetFlag(Flag
: Byte);
5768 if FModel
<> nil then
5769 FModel
.SetFlag(FFlag
);
5772 function TPlayer
.DropFlag(): Boolean;
5777 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5779 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5780 with gFlags
[FFlag
] do
5784 Direction
:= FDirection
;
5785 State
:= FLAG_STATE_DROPPED
;
5787 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5788 (FObj
.Vel
.Y
div 2)-2+Random(5));
5789 positionChanged(); // this updates spatial accelerators
5791 if FFlag
= FLAG_RED
then
5792 s
:= _lc
[I_PLAYER_FLAG_RED
]
5794 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5796 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5797 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5799 if g_Game_IsNet
then
5800 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5806 procedure TPlayer
.GetSecret();
5811 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5813 Assert(Key
<= High(FKeys
));
5815 FKeys
[Key
].Pressed
:= True;
5816 FKeys
[Key
].Time
:= Time
;
5819 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5821 Result
:= FKeys
[K
].Pressed
;
5824 procedure TPlayer
.ReleaseKeys();
5828 for a
:= Low(FKeys
) to High(FKeys
) do
5830 FKeys
[a
].Pressed
:= False;
5835 procedure TPlayer
.ReleaseKeysNoWeapon();
5839 for a
:= Low(FKeys
) to High(FKeys
) do
5841 if (a
= KEY_PREVWEAPON
) or (a
= KEY_NEXTWEAPON
) then continue
;
5842 FKeys
[a
].Pressed
:= False;
5847 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5851 function TPlayer
.firediry(): Integer;
5853 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5854 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5858 procedure TPlayer
.RememberState();
5862 FSavedState
.Health
:= FHealth
;
5863 FSavedState
.Armor
:= FArmor
;
5864 FSavedState
.Air
:= FAir
;
5865 FSavedState
.JetFuel
:= FJetFuel
;
5866 FSavedState
.CurrWeap
:= FCurrWeap
;
5867 FSavedState
.NextWeap
:= FNextWeap
;
5868 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5871 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5873 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5875 FSavedState
.Rulez
:= FRulez
;
5876 FSavedState
.WaitRecall
:= True;
5879 procedure TPlayer
.RecallState();
5883 if not FSavedState
.WaitRecall
then Exit
;
5885 FHealth
:= FSavedState
.Health
;
5886 FArmor
:= FSavedState
.Armor
;
5887 FAir
:= FSavedState
.Air
;
5888 FJetFuel
:= FSavedState
.JetFuel
;
5889 FCurrWeap
:= FSavedState
.CurrWeap
;
5890 FNextWeap
:= FSavedState
.NextWeap
;
5891 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5894 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5896 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5898 FRulez
:= FSavedState
.Rulez
;
5899 FSavedState
.WaitRecall
:= False;
5901 if gGameSettings
.GameType
= GT_SERVER
then
5902 MH_SEND_PlayerStats(FUID
);
5905 procedure TPlayer
.SaveState (st
: TStream
);
5911 utils
.writeSign(st
, 'PLYR');
5912 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
5914 utils
.writeBool(st
, FIamBot
);
5916 utils
.writeInt(st
, Word(FUID
));
5918 utils
.writeStr(st
, FName
);
5920 utils
.writeInt(st
, Byte(FTeam
));
5922 utils
.writeBool(st
, FAlive
);
5923 // Èçðàñõîäîâàë ëè âñå æèçíè
5924 utils
.writeBool(st
, FNoRespawn
);
5926 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
5927 utils
.writeInt(st
, Byte(b
));
5929 utils
.writeInt(st
, LongInt(FHealth
));
5931 utils
.writeInt(st
, Byte(FLives
));
5933 utils
.writeInt(st
, LongInt(FArmor
));
5935 utils
.writeInt(st
, LongInt(FAir
));
5937 utils
.writeInt(st
, LongInt(FJetFuel
));
5939 utils
.writeInt(st
, LongInt(FPain
));
5941 utils
.writeInt(st
, LongInt(FKills
));
5943 utils
.writeInt(st
, LongInt(FMonsterKills
));
5945 utils
.writeInt(st
, LongInt(FFrags
));
5947 utils
.writeInt(st
, Byte(FFragCombo
));
5948 // Âðåìÿ ïîñëåäíåãî ôðàãà
5949 utils
.writeInt(st
, LongWord(FLastFrag
));
5951 utils
.writeInt(st
, LongInt(FDeath
));
5953 utils
.writeInt(st
, Byte(FFlag
));
5955 utils
.writeInt(st
, LongInt(FSecrets
));
5957 utils
.writeInt(st
, Byte(FCurrWeap
));
5959 utils
.writeInt(st
, Word(FNextWeap
));
5961 utils
.writeInt(st
, Byte(FNextWeapDelay
));
5962 // Âðåìÿ çàðÿäêè BFG
5963 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
5965 utils
.writeInt(st
, LongInt(FDamageBuffer
));
5966 // Ïîñëåäíèé óäàðèâøèé
5967 utils
.writeInt(st
, Word(FLastSpawnerUID
));
5968 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
5969 utils
.writeInt(st
, Byte(FLastHit
));
5971 Obj_SaveState(st
, @FObj
);
5972 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
5973 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
5974 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
5975 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
5977 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
5978 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
5979 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
5981 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
5982 // Íàëè÷èå êðàñíîãî êëþ÷à
5983 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
5984 // Íàëè÷èå çåëåíîãî êëþ÷à
5985 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
5986 // Íàëè÷èå ñèíåãî êëþ÷à
5987 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
5989 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
5990 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
5991 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
5992 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
5993 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
5995 utils
.writeStr(st
, FModel
.Name
);
5997 utils
.writeInt(st
, Byte(FColor
.R
));
5998 utils
.writeInt(st
, Byte(FColor
.G
));
5999 utils
.writeInt(st
, Byte(FColor
.B
));
6003 procedure TPlayer
.LoadState (st
: TStream
);
6012 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
6013 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
6015 FIamBot
:= utils
.readBool(st
);
6017 FUID
:= utils
.readWord(st
);
6019 str
:= utils
.readStr(st
);
6020 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
6022 FTeam
:= utils
.readByte(st
);
6024 FAlive
:= utils
.readBool(st
);
6025 // Èçðàñõîäîâàë ëè âñå æèçíè
6026 FNoRespawn
:= utils
.readBool(st
);
6028 b
:= utils
.readByte(st
);
6029 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
6031 FHealth
:= utils
.readLongInt(st
);
6033 FLives
:= utils
.readByte(st
);
6035 FArmor
:= utils
.readLongInt(st
);
6037 FAir
:= utils
.readLongInt(st
);
6039 FJetFuel
:= utils
.readLongInt(st
);
6041 FPain
:= utils
.readLongInt(st
);
6043 FKills
:= utils
.readLongInt(st
);
6045 FMonsterKills
:= utils
.readLongInt(st
);
6047 FFrags
:= utils
.readLongInt(st
);
6049 FFragCombo
:= utils
.readByte(st
);
6050 // Âðåìÿ ïîñëåäíåãî ôðàãà
6051 FLastFrag
:= utils
.readLongWord(st
);
6053 FDeath
:= utils
.readLongInt(st
);
6055 FFlag
:= utils
.readByte(st
);
6057 FSecrets
:= utils
.readLongInt(st
);
6059 FCurrWeap
:= utils
.readByte(st
);
6061 FNextWeap
:= utils
.readWord(st
);
6063 FNextWeapDelay
:= utils
.readByte(st
);
6064 // Âðåìÿ çàðÿäêè BFG
6065 FBFGFireCounter
:= utils
.readSmallInt(st
);
6067 FDamageBuffer
:= utils
.readLongInt(st
);
6068 // Ïîñëåäíèé óäàðèâøèé
6069 FLastSpawnerUID
:= utils
.readWord(st
);
6070 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6071 FLastHit
:= utils
.readByte(st
);
6073 Obj_LoadState(@FObj
, st
);
6074 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6075 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
6076 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6077 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
6079 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
6080 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6081 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
6083 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
6084 // Íàëè÷èå êðàñíîãî êëþ÷à
6085 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
6086 // Íàëè÷èå çåëåíîãî êëþ÷à
6087 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
6088 // Íàëè÷èå ñèíåãî êëþ÷à
6089 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
6091 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
6092 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6093 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
6094 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6095 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
6097 str
:= utils
.readStr(st
);
6099 FColor
.R
:= utils
.readByte(st
);
6100 FColor
.G
:= utils
.readByte(st
);
6101 FColor
.B
:= utils
.readByte(st
);
6102 if (self
= gPlayer1
) then
6104 str
:= gPlayer1Settings
.Model
;
6105 FColor
:= gPlayer1Settings
.Color
;
6107 else if (self
= gPlayer2
) then
6109 str
:= gPlayer2Settings
.Model
;
6110 FColor
:= gPlayer2Settings
.Color
;
6112 // Îáíîâëÿåì ìîäåëü èãðîêà
6114 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
6115 FModel
.Color
:= TEAMCOLOR
[FTeam
]
6117 FModel
.Color
:= FColor
;
6121 procedure TPlayer
.AllRulez(Health
: Boolean);
6127 FHealth
:= PLAYER_HP_LIMIT
;
6128 FArmor
:= PLAYER_AP_LIMIT
;
6132 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
6133 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
6134 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6137 procedure TPlayer
.RestoreHealthArmor();
6139 FHealth
:= PLAYER_HP_LIMIT
;
6140 FArmor
:= PLAYER_AP_LIMIT
;
6143 procedure TPlayer
.FragCombo();
6147 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6149 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6151 if FFragCombo
< 5 then
6153 Param
:= FUID
or (FFragCombo
shl 16);
6154 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6155 (FComboEvnt
<= High(gDelayedEvents
)) and
6156 gDelayedEvents
[FComboEvnt
].Pending
and
6157 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6158 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6160 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6161 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6164 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6172 procedure TPlayer
.GiveItem(ItemType
: Byte);
6176 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6178 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6182 if FAir
< AIR_MAX
then
6189 if not (R_BERSERK
in FRulez
) then
6191 Include(FRulez
, R_BERSERK
);
6192 if FBFGFireCounter
< 1 then
6194 FCurrWeap
:= WEAPON_KASTET
;
6196 FModel
.SetWeapon(WEAPON_KASTET
);
6200 FBerserk
:= gTime
+30000;
6202 if FHealth
< PLAYER_HP_SOFT
then
6204 FHealth
:= PLAYER_HP_SOFT
;
6205 FBerserk
:= gTime
+30000;
6210 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6212 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6216 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6218 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6222 if FJetFuel
< JET_MAX
then
6224 FJetFuel
:= JET_MAX
;
6227 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6228 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6230 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6231 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6233 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6235 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6237 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6238 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6241 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6242 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6243 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6244 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6245 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6246 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6247 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6248 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6249 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6251 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6252 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6253 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6254 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6255 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6256 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6257 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6258 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6259 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6262 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6263 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6264 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6265 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6266 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6268 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6269 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6270 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6271 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6272 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6274 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6275 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6276 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6277 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6279 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6282 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6283 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6284 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6286 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6287 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6292 if g_Game_IsNet
and g_Game_IsServer
then
6293 MH_SEND_PlayerStats(FUID
);
6296 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6301 if (Random(5) = 1) and (Times
= 1) then
6304 if BodyInLiquid(0, 0) then
6306 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6307 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6308 if Random(2) = 0 then
6309 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6311 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6315 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6317 for i
:= 1 to Times
do
6319 Anim
:= TAnimation
.Create(id
, False, 3);
6321 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6322 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6328 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6333 if (Random(10) = 1) and (Times
= 1) then
6336 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6338 for i
:= 1 to Times
do
6340 Anim
:= TAnimation
.Create(id
, False, 3);
6342 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6343 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6349 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6351 FSawSound
.Pause(Enable
);
6352 FSawSoundIdle
.Pause(Enable
);
6353 FSawSoundHit
.Pause(Enable
);
6354 FSawSoundSelect
.Pause(Enable
);
6359 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6364 FObj
.Rect
:= PLAYER_CORPSERECT
;
6365 FModelName
:= ModelName
;
6370 FState
:= CORPSE_STATE_MESS
;
6371 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6375 FState
:= CORPSE_STATE_NORMAL
;
6376 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6380 destructor TCorpse
.Destroy();
6387 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6389 procedure TCorpse
.positionChanged (); inline; begin end;
6391 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6393 if (dx
<> 0) or (dy
<> 0) then
6402 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6404 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6405 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6406 w
:= PLAYER_CORPSERECT
.Width
;
6407 h
:= PLAYER_CORPSERECT
.Height
;
6411 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6416 if FState
= CORPSE_STATE_REMOVEME
then
6419 FDamage
:= FDamage
+ Value
;
6421 if FDamage
> 150 then
6423 if FAnimation
<> nil then
6428 FState
:= CORPSE_STATE_REMOVEME
;
6430 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6431 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6432 FModelName
, FColor
);
6433 // Çâóê ìÿñà îò òðóïà:
6434 pm
:= g_PlayerModel_Get(FModelName
);
6435 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6439 if (gBodyKillEvent
<> -1)
6440 and gDelayedEvents
[gBodyKillEvent
].Pending
then
6441 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
6442 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, 0);
6447 Blood
:= g_PlayerModel_GetBlood(FModelName
);
6448 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6449 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6450 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6451 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6452 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6453 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
6457 procedure TCorpse
.Draw();
6459 if FState
= CORPSE_STATE_REMOVEME
then
6462 if FAnimation
<> nil then
6463 FAnimation
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6465 if FAnimationMask
<> nil then
6468 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6475 procedure TCorpse
.Update();
6479 if FState
= CORPSE_STATE_REMOVEME
then
6482 if gTime
mod (GAME_TICK
*2) <> 0 then
6484 g_Obj_Move(@FObj
, True, True, True);
6485 positionChanged(); // this updates spatial accelerators
6489 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6490 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6492 st
:= g_Obj_Move(@FObj
, True, True, True);
6493 positionChanged(); // this updates spatial accelerators
6495 if WordBool(st
and MOVE_FALLOUT
) then
6497 FState
:= CORPSE_STATE_REMOVEME
;
6501 if FAnimation
<> nil then
6502 FAnimation
.Update();
6503 if FAnimationMask
<> nil then
6504 FAnimationMask
.Update();
6508 procedure TCorpse
.SaveState (st
: TStream
);
6515 utils
.writeSign(st
, 'CORP');
6516 utils
.writeInt(st
, Byte(0));
6518 utils
.writeInt(st
, Byte(FState
));
6520 utils
.writeInt(st
, Byte(FDamage
));
6522 utils
.writeInt(st
, Byte(FColor
.R
));
6523 utils
.writeInt(st
, Byte(FColor
.G
));
6524 utils
.writeInt(st
, Byte(FColor
.B
));
6526 Obj_SaveState(st
, @FObj
);
6527 utils
.writeInt(st
, Word(FPlayerUID
));
6529 anim
:= (FAnimation
<> nil);
6530 utils
.writeBool(st
, anim
);
6531 // Åñëè åñòü - ñîõðàíÿåì
6532 if anim
then FAnimation
.SaveState(st
);
6533 // Åñòü ëè ìàñêà àíèìàöèè
6534 anim
:= (FAnimationMask
<> nil);
6535 utils
.writeBool(st
, anim
);
6536 // Åñëè åñòü - ñîõðàíÿåì
6537 if anim
then FAnimationMask
.SaveState(st
);
6541 procedure TCorpse
.LoadState (st
: TStream
);
6548 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6549 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6551 FState
:= utils
.readByte(st
);
6553 FDamage
:= utils
.readByte(st
);
6555 FColor
.R
:= utils
.readByte(st
);
6556 FColor
.G
:= utils
.readByte(st
);
6557 FColor
.B
:= utils
.readByte(st
);
6559 Obj_LoadState(@FObj
, st
);
6560 FPlayerUID
:= utils
.readWord(st
);
6562 anim
:= utils
.readBool(st
);
6563 // Åñëè åñòü - çàãðóæàåì
6566 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6567 FAnimation
.LoadState(st
);
6569 // Åñòü ëè ìàñêà àíèìàöèè
6570 anim
:= utils
.readBool(st
);
6571 // Åñëè åñòü - çàãðóæàåì
6574 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6575 FAnimationMask
.LoadState(st
);
6581 constructor TBot
.Create();
6588 FSpectator
:= False;
6595 for a
:= WP_FIRST
to WP_LAST
do
6597 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6598 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6599 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6603 destructor TBot
.Destroy();
6606 inherited Destroy();
6609 procedure TBot
.Draw();
6613 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6614 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6617 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6619 inherited Respawn(Silent
, Force
);
6622 FSelectedWeapon
:= FCurrWeap
;
6627 procedure TBot
.UpdateCombat();
6640 TTargetRecord
= array of TTarget
;
6642 function Compare(a
, b
: TTarget
): Integer;
6644 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6647 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6649 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6650 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6652 if a
.Dist
> b
.Dist
then // B áëèæå
6654 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6657 else // Ñòðàííî -> A
6662 a
, x1
, y1
, x2
, y2
: Integer;
6663 targets
: TTargetRecord
;
6665 Target
, BestTarget
: TTarget
;
6666 firew
, fireh
: Integer;
6670 vsPlayer
, vsMonster
, ok
: Boolean;
6673 function monsUpdate (mon
: TMonster
): Boolean;
6675 result
:= false; // don't stop
6676 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6678 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6680 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6681 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6683 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6684 if g_TraceVector(x1
, y1
, x2
, y2
) then
6686 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6687 SetLength(targets
, Length(targets
)+1);
6688 with targets
[High(targets
)] do
6695 Rect
:= mon
.Obj
.Rect
;
6696 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6697 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6698 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6707 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6708 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6710 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6711 if FCurrWeap
<> FSelectedWeapon
then
6714 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6715 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6717 RemoveAIFlag('NEEDFIRE');
6720 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6721 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6722 else PressKey(KEY_FIRE
);
6726 // Êîîðäèíàòû ñòâîëà:
6727 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6728 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6730 Target
.UID
:= FTargetUID
;
6733 if Target
.UID
<> 0 then
6734 begin // Öåëü åñòü - íàñòðàèâàåì
6735 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6738 tpla
:= g_Player_Get(Target
.UID
);
6742 if (@FObj
) <> nil then
6749 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6750 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6751 Target
.Rect
:= PLAYER_RECT
;
6752 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6753 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6754 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6755 Target
.IsPlayer
:= True;
6759 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6762 mon
:= g_Monsters_ByUID(Target
.UID
);
6765 Target
.X
:= mon
.Obj
.X
;
6766 Target
.Y
:= mon
.Obj
.Y
;
6768 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6769 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6770 Target
.Rect
:= mon
.Obj
.Rect
;
6771 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6772 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6773 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6774 Target
.IsPlayer
:= False;
6781 begin // Öåëè íåò - îáíóëÿåì
6786 Target
.Visible
:= False;
6787 Target
.Line
:= False;
6788 Target
.IsPlayer
:= False;
6793 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6794 if (not Target
.Line
) or (not Target
.Visible
) then
6798 for a
:= 0 to High(gPlayers
) do
6799 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6800 (gPlayers
[a
].FUID
<> FUID
) and
6801 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6802 (not gPlayers
[a
].NoTarget
) and
6803 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6805 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6806 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6809 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6810 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6812 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6813 if g_TraceVector(x1
, y1
, x2
, y2
) then
6815 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6816 SetLength(targets
, Length(targets
)+1);
6817 with targets
[High(targets
)] do
6819 UID
:= gPlayers
[a
].FUID
;
6820 X
:= gPlayers
[a
].FObj
.X
;
6821 Y
:= gPlayers
[a
].FObj
.Y
;
6824 Rect
:= PLAYER_RECT
;
6825 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6826 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6827 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6835 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6838 // Åñëè åñòü âîçìîæíûå öåëè:
6839 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6840 if targets
<> nil then
6842 // Âûáèðàåì íàèëó÷øóþ öåëü:
6843 BestTarget
:= targets
[0];
6844 if Length(targets
) > 1 then
6845 for a
:= 1 to High(targets
) do
6846 if Compare(BestTarget
, targets
[a
]) = 1 then
6847 BestTarget
:= targets
[a
];
6849 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6850 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6851 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6853 Target
:= BestTarget
;
6855 if (Healthy() = 3) or ((Healthy() = 2)) then
6856 begin // Åñëè çäîðîâû - äîãîíÿåì
6857 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6858 SetAIFlag('GORIGHT', '1');
6859 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6860 SetAIFlag('GOLEFT', '1');
6863 begin // Åñëè ïîáèòû - óáåãàåì
6864 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6865 SetAIFlag('GORIGHT', '1');
6866 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6867 SetAIFlag('GOLEFT', '1');
6870 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6871 SelectWeapon(Abs(x1
-Target
.cX
));
6876 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6877 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6878 if Target
.UID
<> 0 then
6880 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6881 Target
.Y
+ Target
.Rect
.Y
) then
6882 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6883 if (Healthy() = 3) or ((Healthy() = 2)) then
6884 begin // Åñëè çäîðîâû - äîãîíÿåì
6885 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6886 SetAIFlag('GORIGHT', '1');
6887 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6888 SetAIFlag('GOLEFT', '1');
6891 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6893 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6894 SetAIFlag('GORIGHT', '1');
6895 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6896 SetAIFlag('GOLEFT', '1');
6900 begin // Öåëü ïîêà íà "ýêðàíå"
6901 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6902 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6903 FLastVisible
:= gTime
;
6904 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6905 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6907 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6908 SetAIFlag('GORIGHT', '1');
6909 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6910 SetAIFlag('GOLEFT', '1');
6914 // Âûáèðàåì óãîë ââåðõ:
6915 if FDirection
= TDirection
.D_LEFT
then
6916 angle
:= ANGLE_LEFTUP
6918 angle
:= ANGLE_RIGHTUP
;
6920 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6921 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6923 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6924 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6925 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6926 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6927 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6928 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6929 begin // òî íóæíî ñòðåëÿòü ââåðõ
6930 SetAIFlag('NEEDFIRE', '1');
6931 SetAIFlag('NEEDSEEUP', '1');
6934 // Âûáèðàåì óãîë âíèç:
6935 if FDirection
= TDirection
.D_LEFT
then
6936 angle
:= ANGLE_LEFTDOWN
6938 angle
:= ANGLE_RIGHTDOWN
;
6940 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6941 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6943 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6944 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6945 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6946 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6947 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6948 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6949 begin // òî íóæíî ñòðåëÿòü âíèç
6950 SetAIFlag('NEEDFIRE', '1');
6951 SetAIFlag('NEEDSEEDOWN', '1');
6954 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6955 if Target
.Visible
and
6956 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6957 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6959 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6960 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
6961 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6962 begin // òî íóæíî ñòðåëÿòü âïåðåä
6963 SetAIFlag('NEEDFIRE', '1');
6964 SetAIFlag('NEEDSEEDOWN', '');
6965 SetAIFlag('NEEDSEEUP', '');
6967 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6968 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6969 if GetRnd(FDifficult
.CloseJump
) then
6970 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6971 if Abs(FObj
.X
-Target
.X
) < 128 then
6975 if Random(a
) = 0 then
6976 SetAIFlag('NEEDJUMP', '1');
6980 // Åñëè öåëü âñå åùå åñòü:
6981 if Target
.UID
<> 0 then
6982 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
6983 Target
.UID
:= 0 // òî çàáûòü öåëü
6984 else // Åñëè âèäåëè íåäàâíî
6985 begin // íî öåëü óáèëè
6986 if Target
.IsPlayer
then
6987 begin // Öåëü - èãðîê
6988 pla
:= g_Player_Get(Target
.UID
);
6989 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
6990 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6991 Target
.UID
:= 0; // òî çàáûòü öåëü
6994 begin // Öåëü - ìîíñòð
6995 mon
:= g_Monsters_ByUID(Target
.UID
);
6996 if (mon
= nil) or (not mon
.alive
) then
6997 Target
.UID
:= 0; // òî çàáûòü öåëü
7000 end; // if Target.UID <> 0
7002 FTargetUID
:= Target
.UID
;
7004 // Åñëè âîçìîæíûõ öåëåé íåò:
7005 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
7006 if targets
= nil then
7007 if GetAIFlag('ATTACKLEFT') <> '' then
7008 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
7009 RemoveAIFlag('ATTACKLEFT');
7011 SetAIFlag('NEEDJUMP', '1');
7013 if RunDirection() = TDirection
.D_RIGHT
then
7014 begin // Èäåì íå â òó ñòîðîíó
7015 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7016 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
7017 SetAIFlag('NEEDFIRE', '1');
7018 SetAIFlag('GOLEFT', '1');
7022 begin // Èäåì â íóæíóþ ñòîðîíó
7023 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7024 SetAIFlag('NEEDFIRE', '1');
7025 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7026 SetAIFlag('GORIGHT', '1');
7030 if GetAIFlag('ATTACKRIGHT') <> '' then
7031 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
7032 RemoveAIFlag('ATTACKRIGHT');
7034 SetAIFlag('NEEDJUMP', '1');
7036 if RunDirection() = TDirection
.D_LEFT
then
7037 begin // Èäåì íå â òó ñòîðîíó
7038 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7039 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
7040 SetAIFlag('NEEDFIRE', '1');
7041 SetAIFlag('GORIGHT', '1');
7046 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7047 SetAIFlag('NEEDFIRE', '1');
7048 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7049 SetAIFlag('GOLEFT', '1');
7053 //HACK! (does it belong there?)
7054 RealizeCurrentWeapon();
7056 // Åñëè åñòü âîçìîæíûå öåëè:
7057 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7058 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7059 for a
:= 0 to High(targets
) do
7061 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7062 if GetRnd(FDifficult
.DiagFire
) then
7064 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7065 if FDirection
= TDirection
.D_LEFT
then
7066 angle
:= ANGLE_LEFTUP
7068 angle
:= ANGLE_RIGHTUP
;
7070 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7071 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7073 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7074 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7075 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7076 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7077 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7079 SetAIFlag('NEEDFIRE', '1');
7080 SetAIFlag('NEEDSEEUP', '1');
7083 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7084 if FDirection
= TDirection
.D_LEFT
then
7085 angle
:= ANGLE_LEFTDOWN
7087 angle
:= ANGLE_RIGHTDOWN
;
7089 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7090 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7092 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7093 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7094 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7095 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7096 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7098 SetAIFlag('NEEDFIRE', '1');
7099 SetAIFlag('NEEDSEEDOWN', '1');
7103 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7104 if targets
[a
].Line
and targets
[a
].Visible
and
7105 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
7106 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
7108 SetAIFlag('NEEDFIRE', '1');
7113 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7114 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
7115 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
7116 40+GetInterval(FDifficult
.Cover
, 40)) then
7117 SetAIFlag('NEEDJUMP', '1');
7119 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7120 ammo
:= GetAmmoByWeapon(FCurrWeap
);
7121 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
7122 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
7124 SetAIFlag('SELECTWEAPON', '1');
7126 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7127 if GetAIFlag('SELECTWEAPON') = '1' then
7130 RemoveAIFlag('SELECTWEAPON');
7134 procedure TBot
.Update();
7147 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7148 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7150 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7152 if g_debug_BotAIOff
= 3 then
7162 RealizeCurrentWeapon();
7169 procedure TBot
.ReleaseKey(Key
: Byte);
7178 function TBot
.KeyPressed(Key
: Word): Boolean;
7180 Result
:= FKeys
[Key
].Pressed
;
7183 function TBot
.GetAIFlag(aName
: String20
): String20
;
7189 aName
:= LowerCase(aName
);
7191 if FAIFlags
<> nil then
7192 for a
:= 0 to High(FAIFlags
) do
7193 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7195 Result
:= FAIFlags
[a
].Value
;
7200 procedure TBot
.RemoveAIFlag(aName
: String20
);
7204 if FAIFlags
= nil then Exit
;
7206 aName
:= LowerCase(aName
);
7208 for a
:= 0 to High(FAIFlags
) do
7209 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7211 if a
<> High(FAIFlags
) then
7212 for b
:= a
to High(FAIFlags
)-1 do
7213 FAIFlags
[b
] := FAIFlags
[b
+1];
7215 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7220 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7228 aName
:= LowerCase(aName
);
7230 if FAIFlags
<> nil then
7231 for a
:= 0 to High(FAIFlags
) do
7232 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7238 if ok
then FAIFlags
[a
].Value
:= fValue
7241 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7242 with FAIFlags
[High(FAIFlags
)] do
7250 procedure TBot
.UpdateMove
;
7252 procedure GoLeft(Time
: Word = 1);
7254 ReleaseKey(KEY_LEFT
);
7255 ReleaseKey(KEY_RIGHT
);
7256 PressKey(KEY_LEFT
, Time
);
7257 SetDirection(TDirection
.D_LEFT
);
7260 procedure GoRight(Time
: Word = 1);
7262 ReleaseKey(KEY_LEFT
);
7263 ReleaseKey(KEY_RIGHT
);
7264 PressKey(KEY_RIGHT
, Time
);
7265 SetDirection(TDirection
.D_RIGHT
);
7268 function Rnd(a
: Word): Boolean;
7270 Result
:= Random(a
) = 0;
7273 procedure Turn(Time
: Word = 1200);
7275 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7280 ReleaseKey(KEY_LEFT
);
7281 ReleaseKey(KEY_RIGHT
);
7284 function CanRunLeft(): Boolean;
7286 Result
:= not CollideLevel(-1, 0);
7289 function CanRunRight(): Boolean;
7291 Result
:= not CollideLevel(1, 0);
7294 function CanRun(): Boolean;
7296 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7299 procedure Jump(Time
: Word = 30);
7301 PressKey(KEY_JUMP
, Time
);
7304 function NearHole(): Boolean;
7308 { TODO 5 : Ëåñòíèöû }
7309 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7310 for x
:= 1 to PLAYER_RECT
.Width
do
7311 if (not StayOnStep(x
*sx
, 0)) and
7312 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7313 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7322 function BorderHole(): Boolean;
7326 { TODO 5 : Ëåñòíèöû }
7327 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7328 for x
:= 1 to PLAYER_RECT
.Width
do
7329 if (not StayOnStep(x
*sx
, 0)) and
7330 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7331 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7333 for xx
:= x
to x
+32 do
7334 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7344 function NearDeepHole(): Boolean;
7350 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7353 for x
:= 1 to PLAYER_RECT
.Width
do
7354 if (not StayOnStep(x
*sx
, 0)) and
7355 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7356 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7358 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7360 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7365 end else Result
:= False;
7368 function OverDeepHole(): Boolean;
7375 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7377 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7384 function OnGround(): Boolean;
7386 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7389 function OnLadder(): Boolean;
7391 Result
:= FullInStep(0, 0);
7394 function BelowLadder(): Boolean;
7396 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7397 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7398 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7399 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7402 function BelowLiftUp(): Boolean;
7404 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7405 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7406 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7407 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7410 function OnTopLift(): Boolean;
7412 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7415 function CanJumpOver(): Boolean;
7419 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7423 if not CollideLevel(sx
, 0) then Exit
;
7425 for y
:= 1 to BOT_MAXJUMP
do
7426 if CollideLevel(0, -y
) then Exit
else
7427 if not CollideLevel(sx
, -y
) then
7434 function CanJumpUp(Dist
: ShortInt): Boolean;
7441 if CollideLevel(Dist
, 0) then Exit
;
7444 for y
:= 0 to BOT_MAXJUMP
do
7445 if CollideLevel(Dist
, -y
) then
7454 for yy
:= y
+1 to BOT_MAXJUMP
do
7455 if not CollideLevel(Dist
, -yy
) then
7464 for y
:= 0 to BOT_MAXJUMP
do
7465 if CollideLevel(0, -y
) then
7473 if y
< yy
then Exit
;
7478 function IsSafeTrigger(): Boolean;
7483 if gTriggers
= nil then
7485 for a
:= 0 to High(gTriggers
) do
7486 if Collide(gTriggers
[a
].X
,
7489 gTriggers
[a
].Height
) and
7490 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7491 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7492 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7493 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7494 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7499 // Âîçìîæíî, íàæèìàåì êíîïêó:
7500 if Rnd(16) and IsSafeTrigger() then
7503 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7504 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7506 ReleaseKey(KEY_LEFT
);
7507 ReleaseKey(KEY_RIGHT
);
7511 // Èäåì âëåâî, åñëè íàäî áûëî:
7512 if GetAIFlag('GOLEFT') <> '' then
7514 RemoveAIFlag('GOLEFT');
7515 if CanRunLeft() then
7519 // Èäåì âïðàâî, åñëè íàäî áûëî:
7520 if GetAIFlag('GORIGHT') <> '' then
7522 RemoveAIFlag('GORIGHT');
7523 if CanRunRight() then
7527 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7528 if FObj
.X
< -32 then
7531 if FObj
.X
+32 > gMapInfo
.Width
then
7534 // Ïðûãàåì, åñëè íàäî áûëî:
7535 if GetAIFlag('NEEDJUMP') <> '' then
7538 RemoveAIFlag('NEEDJUMP');
7541 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7542 if GetAIFlag('NEEDSEEUP') <> '' then
7545 ReleaseKey(KEY_DOWN
);
7546 PressKey(KEY_UP
, 20);
7547 RemoveAIFlag('NEEDSEEUP');
7550 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7551 if GetAIFlag('NEEDSEEDOWN') <> '' then
7554 ReleaseKey(KEY_DOWN
);
7555 PressKey(KEY_DOWN
, 20);
7556 RemoveAIFlag('NEEDSEEDOWN');
7559 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7560 if GetAIFlag('GOINHOLE') <> '' then
7561 if not OnGround() then
7563 ReleaseKey(KEY_LEFT
);
7564 ReleaseKey(KEY_RIGHT
);
7565 RemoveAIFlag('GOINHOLE');
7566 SetAIFlag('FALLINHOLE', '1');
7569 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7570 if GetAIFlag('FALLINHOLE') <> '' then
7572 RemoveAIFlag('FALLINHOLE');
7574 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7575 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7576 if GetAIFlag('FALLINHOLE') = '' then
7577 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7583 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7585 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7589 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7590 if OnGround() and NearHole() then
7591 if NearDeepHole() then // Åñëè ýòî áåçäíà
7593 0..3: Turn(); // Áåæèì îáðàòíî
7594 4: Jump(); // Ïðûãàåì
7595 5: begin // Ïðûãàåì îáðàòíî
7600 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7601 if GetAIFlag('GOINHOLE') = '' then
7603 0: Turn(); // Íå íóæíî òóäà
7604 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7605 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7606 if BorderHole() then
7607 SetAIFlag('GOINHOLE', '1');
7610 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7611 if (not CanRun()) and OnGround() then
7613 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7614 if CanJumpOver() or OnLadder() then
7616 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7617 if Random(2) = 0 then
7619 if IsSafeTrigger() then
7625 // Îñòàëîñü ìàëî âîçäóõà:
7626 if FAir
< 36 * 2 then
7629 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7630 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7631 if BodyInAcid(0, 0) then
7635 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7637 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7638 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7641 {function TBot.NeedItem(Item: Byte): Byte;
7646 procedure TBot
.SelectWeapon(Dist
: Integer);
7650 function HaveAmmo(weapon
: Byte): Boolean;
7653 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7654 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7655 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7656 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7657 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7658 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7659 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7660 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7661 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7662 else Result
:= True;
7667 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7669 if Dist
> BOT_LONGDIST
then
7670 begin // Äàëüíèé áîé
7672 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7674 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7678 else //if Dist > BOT_UNSAFEDIST then
7679 begin // Áëèæíèé áîé
7681 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7683 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7690 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7692 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7698 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7700 Result
:= inherited PickItem(ItemType
, force
, remove
);
7702 if Result
then SetAIFlag('SELECTWEAPON', '1');
7705 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7707 Result
:= inherited Heal(value
, Soft
);
7710 function TBot
.Healthy(): Byte;
7712 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7713 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7714 else if (FHealth
> 50) then Result
:= 2
7715 else if (FHealth
> 20) then Result
:= 1
7719 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7721 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7722 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7725 procedure TBot
.OnDamage(Angle
: SmallInt);
7733 if (Angle
= 0) or (Angle
= 180) then
7736 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7737 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7739 pla
:= g_Player_Get(FLastSpawnerUID
);
7740 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7741 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7744 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7745 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7747 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7748 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7749 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7754 SetAIFlag('ATTACKLEFT', '1')
7756 SetAIFlag('ATTACKRIGHT', '1');
7760 function TBot
.RunDirection(): TDirection
;
7762 if Abs(Vel
.X
) >= 1 then
7764 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7766 Result
:= FDirection
;
7769 function TBot
.GetRnd(a
: Byte): Boolean;
7771 if a
= 0 then Result
:= False
7772 else if a
= 255 then Result
:= True
7773 else Result
:= Random(256) > 255-a
;
7776 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7778 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7782 procedure TDifficult
.save (st
: TStream
);
7784 utils
.writeInt(st
, Byte(DiagFire
));
7785 utils
.writeInt(st
, Byte(InvisFire
));
7786 utils
.writeInt(st
, Byte(DiagPrecision
));
7787 utils
.writeInt(st
, Byte(FlyPrecision
));
7788 utils
.writeInt(st
, Byte(Cover
));
7789 utils
.writeInt(st
, Byte(CloseJump
));
7790 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7791 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7794 procedure TDifficult
.load (st
: TStream
);
7796 DiagFire
:= utils
.readByte(st
);
7797 InvisFire
:= utils
.readByte(st
);
7798 DiagPrecision
:= utils
.readByte(st
);
7799 FlyPrecision
:= utils
.readByte(st
);
7800 Cover
:= utils
.readByte(st
);
7801 CloseJump
:= utils
.readByte(st
);
7802 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7803 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7807 procedure TBot
.SaveState (st
: TStream
);
7812 inherited SaveState(st
);
7813 utils
.writeSign(st
, 'BOT0');
7815 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7817 utils
.writeInt(st
, Word(FTargetUID
));
7818 // Âðåìÿ ïîòåðè öåëè
7819 utils
.writeInt(st
, LongWord(FLastVisible
));
7820 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7821 dw
:= Length(FAIFlags
);
7822 utils
.writeInt(st
, LongInt(dw
));
7824 for i
:= 0 to dw
-1 do
7826 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7827 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7829 // Íàñòðîéêè ñëîæíîñòè
7830 FDifficult
.save(st
);
7834 procedure TBot
.LoadState (st
: TStream
);
7839 inherited LoadState(st
);
7840 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7842 FSelectedWeapon
:= utils
.readByte(st
);
7844 FTargetUID
:= utils
.readWord(st
);
7845 // Âðåìÿ ïîòåðè öåëè
7846 FLastVisible
:= utils
.readLongWord(st
);
7847 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7848 dw
:= utils
.readLongInt(st
);
7849 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7850 SetLength(FAIFlags
, dw
);
7852 for i
:= 0 to dw
-1 do
7854 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7855 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7857 // Íàñòðîéêè ñëîæíîñòè
7858 FDifficult
.load(st
);
7863 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);