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;
165 FNetWeapCtr
: LongWord; // spam server with our current weapon until we'll receive this in plrpos packet
167 FNextWeapDelay
: Byte; // frames (unused)
168 FBFGFireCounter
: SmallInt;
169 FLastSpawnerUID
: Word;
173 FSpectatePlayer
: Integer;
174 FFirePainTime
: Integer;
177 FSavedState
: TPlayerSavedState
;
179 FModel
: TPlayerModel
;
180 FPunchAnim
: TAnimation
;
183 FActionForce
: Boolean;
184 FActionChanged
: Boolean;
186 FFireAngle
: SmallInt;
188 FShellTimer
: Integer;
190 FSawSound
: TPlayableSound
;
191 FSawSoundIdle
: TPlayableSound
;
192 FSawSoundHit
: TPlayableSound
;
193 FSawSoundSelect
: TPlayableSound
;
194 FJetSoundOn
: TPlayableSound
;
195 FJetSoundOff
: TPlayableSound
;
196 FJetSoundFly
: TPlayableSound
;
200 FJustTeleported
: Boolean;
202 mEDamageType
: Integer;
205 weaponSwitchKeyReleased
: array[0..16] of Byte; // bit 0: was released on prev frame; bit 1: new status
208 function CollideLevel(XInc
, YInc
: Integer): Boolean;
209 function StayOnStep(XInc
, YInc
: Integer): Boolean;
210 function HeadInLiquid(XInc
, YInc
: Integer): Boolean;
211 function BodyInLiquid(XInc
, YInc
: Integer): Boolean;
212 function BodyInAcid(XInc
, YInc
: Integer): Boolean;
213 function FullInLift(XInc
, YInc
: Integer): Integer;
214 {procedure CollideItem();}
215 procedure FlySmoke(Times
: DWORD
= 1);
216 procedure OnFireFlame(Times
: DWORD
= 1);
217 function GetAmmoByWeapon(Weapon
: Byte): Word;
218 procedure SetAction(Action
: Byte; Force
: Boolean = False);
219 procedure OnDamage(Angle
: SmallInt); virtual;
220 function firediry(): Integer;
223 procedure Run(Direction
: TDirection
);
224 procedure NextWeapon();
225 procedure PrevWeapon();
232 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
233 procedure resetWeaponQueue ();
234 function hasAmmoForWeapon (weapon
: Byte): Boolean;
236 procedure doDamage (v
: Integer);
238 function followCorpse(): Boolean;
241 FDamageBuffer
: Integer;
243 FAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
244 FMaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
245 FWeapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
246 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
248 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
249 FReloading
: Array [WP_FIRST
..WP_LAST
] of Word;
250 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
251 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
253 FPreferredTeam
: Byte;
256 FWantsInGame
: Boolean;
260 FActualModelName
: string;
267 // debug: viewport offset
268 viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer;
270 function isValidViewPort (): Boolean; inline;
271 procedure SetCurrWeapProp (newweap
: Byte);
273 constructor Create(); virtual;
274 destructor Destroy(); override;
275 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
276 function GetRespawnPoint(): Byte;
277 procedure PressKey(Key
: Byte; Time
: Word = 1);
278 procedure ReleaseKeys();
279 procedure ReleaseKeysNoWeapon();
280 procedure SetModel(ModelName
: String);
281 procedure SetColor(Color
: TRGB
);
282 procedure SetWeaponHost(W
: Byte);
283 function IsKeyPressed(K
: Byte): Boolean;
284 function GetKeys(): Byte;
285 function PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean; virtual;
286 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
287 function Collide(Panel
: TPanel
): Boolean; overload
;
288 function Collide(X
, Y
: Integer): Boolean; overload
;
289 procedure SetDirection(Direction
: TDirection
);
290 procedure GetSecret();
291 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
293 procedure Push(vx
, vy
: Integer);
294 procedure ChangeModel(ModelName
: String);
295 procedure SwitchTeam
;
296 procedure ChangeTeam(Team
: Byte);
298 function GetFlag(Flag
: Byte): Boolean;
299 procedure SetFlag(Flag
: Byte);
300 function DropFlag(): Boolean;
301 procedure AllRulez(Health
: Boolean);
302 procedure RestoreHealthArmor();
303 procedure FragCombo();
304 procedure GiveItem(ItemType
: Byte);
305 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
306 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
307 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
308 procedure MakeBloodSimple(Count
: Word);
309 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
310 procedure Reset(Force
: Boolean);
311 procedure Spectate(NoMove
: Boolean = False);
312 procedure SwitchNoClip
;
313 procedure SoftReset();
314 procedure Draw(); virtual;
315 procedure DrawPain();
316 procedure DrawPickup();
317 procedure DrawRulez();
319 procedure DrawIndicator();
320 procedure DrawBubble();
322 procedure Update(); virtual;
323 procedure RememberState();
324 procedure RecallState();
325 procedure SaveState (st
: TStream
); virtual;
326 procedure LoadState (st
: TStream
); virtual;
327 procedure PauseSounds(Enable
: Boolean);
328 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
329 procedure DoLerp(Level
: Integer = 2);
330 procedure SetLerp(XTo
, YTo
: Integer);
331 procedure QueueWeaponSwitch(Weapon
: Byte);
332 procedure RealizeCurrentWeapon();
334 procedure JetpackOff
;
335 procedure CatchFire(Attacker
: Word);
337 //WARNING! this does nothing for now, but still call it!
338 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
340 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
341 procedure moveBy (dx
, dy
: Integer); inline;
343 procedure releaseAllWeaponSwitchKeys ();
344 procedure weaponSwitchKeysStateChange (index
: Integer; pressed
: Boolean);
345 function isWeaponSwitchKeyReleased (index
: Integer): Boolean;
346 procedure weaponSwitchKeysShiftNewStates ();
349 property Vel
: TPoint2i read FObj
.Vel
;
350 property Obj
: TObj read FObj
;
352 property Name
: String read FName write FName
;
353 property Model
: TPlayerModel read FModel
;
354 property Health
: Integer read FHealth write FHealth
;
355 property Lives
: Byte read FLives write FLives
;
356 property Armor
: Integer read FArmor write FArmor
;
357 property Air
: Integer read FAir write FAir
;
358 property JetFuel
: Integer read FJetFuel write FJetFuel
;
359 property Frags
: Integer read FFrags write FFrags
;
360 property Death
: Integer read FDeath write FDeath
;
361 property Kills
: Integer read FKills write FKills
;
362 property CurrWeap
: Byte read FCurrWeap write SetCurrWeapProp
;
363 property NetWeapCtr
: LongWord read FNetWeapCtr write FNetWeapCtr
;
364 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
365 property Secrets
: Integer read FSecrets
;
366 property GodMode
: Boolean read FGodMode write FGodMode
;
367 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
368 property NoReload
: Boolean read FNoReload write FNoReload
;
369 property alive
: Boolean read FAlive write FAlive
;
370 property Flag
: Byte read FFlag
;
371 property Team
: Byte read FTeam write FTeam
;
372 property Direction
: TDirection read FDirection
;
373 property GameX
: Integer read FObj
.X write FObj
.X
;
374 property GameY
: Integer read FObj
.Y write FObj
.Y
;
375 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
376 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
377 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
378 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
379 property IncCam
: Integer read FIncCam write FIncCam
;
380 property UID
: Word read FUID write FUID
;
381 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
382 property NetTime
: LongWord read FNetTime write FNetTime
;
385 property eName
: String read FName write FName
;
386 property eHealth
: Integer read FHealth write FHealth
;
387 property eLives
: Byte read FLives write FLives
;
388 property eArmor
: Integer read FArmor write FArmor
;
389 property eAir
: Integer read FAir write FAir
;
390 property eJetFuel
: Integer read FJetFuel write FJetFuel
;
391 property eFrags
: Integer read FFrags write FFrags
;
392 property eDeath
: Integer read FDeath write FDeath
;
393 property eKills
: Integer read FKills write FKills
;
394 property eCurrWeap
: Byte read FCurrWeap write SetCurrWeapProp
;
395 property eMonsterKills
: Integer read FMonsterKills write FMonsterKills
;
396 property eSecrets
: Integer read FSecrets write FSecrets
;
397 property eGodMode
: Boolean read FGodMode write FGodMode
;
398 property eNoTarget
: Boolean read FNoTarget write FNoTarget
;
399 property eNoReload
: Boolean read FNoReload write FNoReload
;
400 property eAlive
: Boolean read FAlive write FAlive
;
401 property eFlag
: Byte read FFlag
;
402 property eTeam
: Byte read FTeam write FTeam
;
403 property eDirection
: TDirection read FDirection
;
404 property eGameX
: Integer read FObj
.X write FObj
.X
;
405 property eGameY
: Integer read FObj
.Y write FObj
.Y
;
406 property eGameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
407 property eGameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
408 property eGameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
409 property eGameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
410 property eIncCam
: Integer read FIncCam write FIncCam
;
411 property eUID
: Word read FUID
;
412 property eJustTeleported
: Boolean read FJustTeleported
;
413 property eNetTime
: LongWord read FNetTime
;
415 // set this before assigning something to `eDamage`
416 property eDamageType
: Integer read mEDamageType write mEDamageType
;
417 property eDamage
: Integer write doDamage
;
428 WeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
429 CloseWeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
430 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
433 procedure save (st
: TStream
);
434 procedure load (st
: TStream
);
442 TBot
= class(TPlayer
)
444 FSelectedWeapon
: Byte;
447 FAIFlags
: Array of TAIFlag
;
448 FDifficult
: TDifficult
;
450 function GetRnd(a
: Byte): Boolean;
451 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
452 function RunDirection(): TDirection
;
453 function FullInStep(XInc
, YInc
: Integer): Boolean;
454 //function NeedItem(Item: Byte): Byte;
455 procedure SelectWeapon(Dist
: Integer);
456 procedure SetAIFlag(aName
, fValue
: String20
);
457 function GetAIFlag(aName
: String20
): String20
;
458 procedure RemoveAIFlag(aName
: String20
);
459 function Healthy(): Byte;
460 procedure UpdateMove();
461 procedure UpdateCombat();
462 function KeyPressed(Key
: Word): Boolean;
463 procedure ReleaseKey(Key
: Byte);
464 function TargetOnScreen(TX
, TY
: Integer): Boolean;
465 procedure OnDamage(Angle
: SmallInt); override;
468 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
469 constructor Create(); override;
470 destructor Destroy(); override;
471 procedure Draw(); override;
472 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
473 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
474 procedure Update(); override;
475 procedure SaveState (st
: TStream
); override;
476 procedure LoadState (st
: TStream
); override;
488 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
489 procedure moveBy (dx
, dy
: Integer); inline;
491 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
505 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
506 procedure moveBy (dx
, dy
: Integer); inline;
508 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
511 TCorpse
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
520 FAnimation
: TAnimation
;
521 FAnimationMask
: TAnimation
;
524 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
525 destructor Destroy(); override;
526 procedure Damage(Value
: Word; vx
, vy
: Integer);
529 procedure SaveState (st
: TStream
);
530 procedure LoadState (st
: TStream
);
532 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
533 procedure moveBy (dx
, dy
: Integer); inline;
535 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
537 function ObjPtr (): PObj
; inline;
539 property Obj
: TObj read FObj
; // copies object
540 property State
: Byte read FState
;
541 property Mess
: Boolean read FMess
;
544 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
550 gPlayers
: Array of TPlayer
;
551 gCorpses
: Array of TCorpse
;
552 gGibs
: Array of TGib
;
553 gShells
: Array of TShell
;
554 gTeamStat
: TTeamStat
;
555 gFly
: Boolean = False;
556 gAimLine
: Boolean = False;
557 gChatBubble
: Byte = 0;
558 gPlayerIndicator
: Boolean = True;
562 MAX_RUNVEL
: Integer = 8;
563 VEL_JUMP
: Integer = 10;
564 SHELL_TIMEOUT
: Cardinal = 60000;
566 function Lerp(X
, Y
, Factor
: Integer): Integer;
568 procedure g_Gibs_SetMax(Count
: Word);
569 function g_Gibs_GetMax(): Word;
570 procedure g_Corpses_SetMax(Count
: Word);
571 function g_Corpses_GetMax(): Word;
572 procedure g_Shells_SetMax(Count
: Word);
573 function g_Shells_GetMax(): Word;
575 procedure g_Player_Init();
576 procedure g_Player_Free();
577 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
578 function g_Player_CreateFromState (st
: TStream
): Word;
579 procedure g_Player_Remove(UID
: Word);
580 procedure g_Player_ResetTeams();
581 procedure g_Player_UpdateAll();
582 procedure g_Player_DrawAll();
583 procedure g_Player_DrawDebug(p
: TPlayer
);
584 procedure g_Player_DrawHealth();
585 procedure g_Player_RememberAll();
586 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
587 function g_Player_Get(UID
: Word): TPlayer
;
588 function g_Player_GetCount(): Byte;
589 function g_Player_GetStats(): TPlayerStatArray
;
590 function g_Player_ValidName(Name
: String): Boolean;
591 procedure g_Player_CreateCorpse(Player
: TPlayer
);
592 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
593 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
594 procedure g_Player_UpdatePhysicalObjects();
595 procedure g_Player_DrawCorpses();
596 procedure g_Player_DrawShells();
597 procedure g_Player_RemoveAllCorpses();
598 procedure g_Player_Corpses_SaveState (st
: TStream
);
599 procedure g_Player_Corpses_LoadState (st
: TStream
);
600 procedure g_Bot_Add(Team
, Difficult
: Byte);
601 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1);
602 procedure g_Bot_MixNames();
603 procedure g_Bot_RemoveAll();
608 {$INCLUDE ../nogl/noGLuses.inc}
609 {$IFDEF ENABLE_HOLMES}
612 e_log
, g_map
, g_items
, g_console
, g_gfx
, Math
,
613 g_options
, g_triggers
, g_menu
, g_game
, g_grid
,
614 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
,
615 g_net
, g_netmsg
, g_window
,
618 const PLR_SAVE_VERSION
= 0;
628 diag_precision
: Byte;
632 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
633 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
634 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
638 TIME_RESPAWN1
= 1500;
639 TIME_RESPAWN2
= 2000;
640 TIME_RESPAWN3
= 3000;
643 JET_MAX
= 540; // ~30 sec
644 PLAYER_SUIT_TIME
= 30000;
645 PLAYER_INVUL_TIME
= 30000;
646 PLAYER_INVIS_TIME
= 35000;
647 FRAG_COMBO_TIME
= 3000;
651 ANGLE_RIGHTDOWN
= -35;
653 ANGLE_LEFTDOWN
= -145;
654 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
655 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
658 BOT_UNSAFEDIST
= 128;
659 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
661 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
662 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
663 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
664 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
665 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
666 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
667 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
668 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
669 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
670 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
671 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
672 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
673 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
674 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
675 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
676 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
677 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
678 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
679 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
680 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
681 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
682 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
683 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
684 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
685 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
686 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
688 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
689 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
691 BOTNAMES_FILENAME
= 'botnames.txt';
692 BOTLIST_FILENAME
= 'botlist.txt';
696 MaxCorpses
: Word = 20;
697 MaxShells
: Word = 300;
698 CurrentGib
: Integer = 0;
699 CurrentShell
: Integer = 0;
700 BotNames
: Array of String;
701 BotList
: Array of TBotProfile
;
704 function Lerp(X
, Y
, Factor
: Integer): Integer;
706 Result
:= X
+ ((Y
- X
) div Factor
);
709 function SameTeam(UID1
, UID2
: Word): Boolean;
713 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
714 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
716 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
718 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
719 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
721 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
724 procedure g_Gibs_SetMax(Count
: Word);
727 SetLength(gGibs
, Count
);
729 if CurrentGib
>= Count
then
733 function g_Gibs_GetMax(): Word;
738 procedure g_Shells_SetMax(Count
: Word);
741 SetLength(gShells
, Count
);
743 if CurrentShell
>= Count
then
747 function g_Shells_GetMax(): Word;
753 procedure g_Corpses_SetMax(Count
: Word);
756 SetLength(gCorpses
, Count
);
759 function g_Corpses_GetMax(): Word;
761 Result
:= MaxCorpses
;
764 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
774 // Åñòü ëè ìåñòî â gPlayers:
775 if gPlayers
<> nil then
776 for a
:= 0 to High(gPlayers
) do
777 if gPlayers
[a
] = nil then
783 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
786 SetLength(gPlayers
, Length(gPlayers
)+1);
790 // Ñîçäàåì îáúåêò èãðîêà:
792 gPlayers
[a
] := TBot
.Create()
794 gPlayers
[a
] := TPlayer
.Create();
797 gPlayers
[a
].FActualModelName
:= ModelName
;
798 gPlayers
[a
].SetModel(ModelName
);
800 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
801 if gPlayers
[a
].FModel
= nil then
805 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
809 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
810 if Random(2) = 0 then
814 gPlayers
[a
].FPreferredTeam
:= Team
;
816 case gGameSettings
.GameMode
of
817 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
819 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
821 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
824 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
825 gPlayers
[a
].FColor
:= Color
;
826 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
827 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
829 gPlayers
[a
].FModel
.Color
:= Color
;
831 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
832 gPlayers
[a
].FAlive
:= False;
834 Result
:= gPlayers
[a
].FUID
;
837 function g_Player_CreateFromState (st
: TStream
): Word;
844 if (st
= nil) then exit
; //???
847 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
848 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
851 Bot
:= utils
.readBool(st
);
856 // Åñòü ëè ìåñòî â gPlayers:
857 for a
:= 0 to High(gPlayers
) do if (gPlayers
[a
] = nil) then begin ok
:= true; break
; end;
859 // Íåò ìåñòà - ðàñøèðÿåì gPlayers
862 SetLength(gPlayers
, Length(gPlayers
)+1);
866 // Ñîçäàåì îáúåêò èãðîêà
868 gPlayers
[a
] := TBot
.Create()
870 gPlayers
[a
] := TPlayer
.Create();
871 gPlayers
[a
].FIamBot
:= Bot
;
872 gPlayers
[a
].FPhysics
:= True;
875 gPlayers
[a
].FUID
:= utils
.readWord(st
);
877 gPlayers
[a
].FName
:= utils
.readStr(st
);
879 gPlayers
[a
].FTeam
:= utils
.readByte(st
);
880 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
882 gPlayers
[a
].FAlive
:= utils
.readBool(st
);
883 // Èçðàñõîäîâàë ëè âñå æèçíè
884 gPlayers
[a
].FNoRespawn
:= utils
.readBool(st
);
886 b
:= utils
.readByte(st
);
887 if b
= 1 then gPlayers
[a
].FDirection
:= TDirection
.D_LEFT
else gPlayers
[a
].FDirection
:= TDirection
.D_RIGHT
; // b = 2
889 gPlayers
[a
].FHealth
:= utils
.readLongInt(st
);
891 gPlayers
[a
].FLives
:= utils
.readByte(st
);
893 gPlayers
[a
].FArmor
:= utils
.readLongInt(st
);
895 gPlayers
[a
].FAir
:= utils
.readLongInt(st
);
897 gPlayers
[a
].FJetFuel
:= utils
.readLongInt(st
);
899 gPlayers
[a
].FPain
:= utils
.readLongInt(st
);
901 gPlayers
[a
].FKills
:= utils
.readLongInt(st
);
903 gPlayers
[a
].FMonsterKills
:= utils
.readLongInt(st
);
905 gPlayers
[a
].FFrags
:= utils
.readLongInt(st
);
907 gPlayers
[a
].FFragCombo
:= utils
.readByte(st
);
908 // Âðåìÿ ïîñëåäíåãî ôðàãà
909 gPlayers
[a
].FLastFrag
:= utils
.readLongWord(st
);
911 gPlayers
[a
].FDeath
:= utils
.readLongInt(st
);
913 gPlayers
[a
].FFlag
:= utils
.readByte(st
);
915 gPlayers
[a
].FSecrets
:= utils
.readLongInt(st
);
917 gPlayers
[a
].FCurrWeap
:= utils
.readByte(st
);
918 gPlayers
[a
].FNetWeapCtr
:= 0;
919 // Ñëåäóþùåå æåëàåìîå îðóæèå
920 gPlayers
[a
].FNextWeap
:= utils
.readWord(st
);
922 gPlayers
[a
].FNextWeapDelay
:= utils
.readByte(st
);
924 gPlayers
[a
].FBFGFireCounter
:= utils
.readSmallInt(st
);
926 gPlayers
[a
].FDamageBuffer
:= utils
.readLongInt(st
);
927 // Ïîñëåäíèé óäàðèâøèé
928 gPlayers
[a
].FLastSpawnerUID
:= utils
.readWord(st
);
929 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
930 gPlayers
[a
].FLastHit
:= utils
.readByte(st
);
932 Obj_LoadState(@gPlayers
[a
].FObj
, st
);
933 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
934 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FAmmo
[i
] := utils
.readWord(st
);
935 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
936 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FMaxAmmo
[i
] := utils
.readWord(st
);
938 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FWeapon
[i
] := utils
.readBool(st
);
939 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
940 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FReloading
[i
] := utils
.readWord(st
);
942 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
943 // Íàëè÷èå êðàñíîãî êëþ÷à
944 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
945 // Íàëè÷èå çåëåíîãî êëþ÷à
946 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
947 // Íàëè÷èå ñèíåãî êëþ÷à
948 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
950 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_BERSERK
);
951 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
952 for i
:= MR_SUIT
to MR_MAX
do gPlayers
[a
].FMegaRulez
[i
] := utils
.readLongWord(st
);
953 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
954 for i
:= T_RESPAWN
to T_FLAGCAP
do gPlayers
[a
].FTime
[i
] := utils
.readLongWord(st
);
957 gPlayers
[a
].FActualModelName
:= utils
.readStr(st
);
959 gPlayers
[a
].FColor
.R
:= utils
.readByte(st
);
960 gPlayers
[a
].FColor
.G
:= utils
.readByte(st
);
961 gPlayers
[a
].FColor
.B
:= utils
.readByte(st
);
962 // Îáíîâëÿåì ìîäåëü èãðîêà
963 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
965 // Íåò ìîäåëè - ñîçäàíèå íåâîçìîæíî
966 if (gPlayers
[a
].FModel
= nil) then
970 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
974 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû
975 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
976 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
978 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
980 result
:= gPlayers
[a
].FUID
;
984 procedure g_Player_ResetTeams();
988 if g_Game_IsClient
then
990 if gPlayers
= nil then
992 for a
:= Low(gPlayers
) to High(gPlayers
) do
993 if gPlayers
[a
] <> nil then
994 case gGameSettings
.GameMode
of
996 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
998 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
999 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
1000 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
1003 gPlayers
[a
].ChangeTeam(TEAM_RED
)
1005 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
1008 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
1012 procedure g_Bot_Add(Team
, Difficult
: Byte);
1015 _name
, _model
: String;
1018 if not g_Game_IsServer
then Exit
;
1020 // Ñïèñîê íàçâàíèé ìîäåëåé:
1021 m
:= g_PlayerModel_GetNames();
1026 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1027 Team
:= TEAM_COOP
// COOP
1029 if gGameSettings
.GameMode
= GM_DM
then
1030 Team
:= TEAM_NONE
// DM
1032 if Team
= TEAM_NONE
then // CTF / TDM
1034 // Àâòîáàëàíñ êîìàíä:
1038 for a
:= 0 to High(gPlayers
) do
1039 if gPlayers
[a
] <> nil then
1041 if gPlayers
[a
].Team
= TEAM_RED
then
1044 if gPlayers
[a
].Team
= TEAM_BLUE
then
1054 if Random(2) = 0 then
1060 // Âûáèðàåì áîòó èìÿ:
1062 if BotNames
<> nil then
1063 for a
:= 0 to High(BotNames
) do
1064 if g_Player_ValidName(BotNames
[a
]) then
1066 _name
:= BotNames
[a
];
1070 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
1073 _name
:= Format('DFBOT%.2d', [Random(100)]);
1074 until g_Player_ValidName(_name
);
1076 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1077 _model
:= m
[Random(Length(m
))];
1080 with g_Player_Get(g_Player_Create(_model
,
1081 _RGB(Min(Random(9)*32, 255),
1082 Min(Random(9)*32, 255),
1083 Min(Random(9)*32, 255)),
1084 Team
, True)) as TBot
do
1089 1: FDifficult
:= DIFFICULT_EASY
;
1090 2: FDifficult
:= DIFFICULT_MEDIUM
;
1091 else FDifficult
:= DIFFICULT_HARD
;
1094 for a
:= WP_FIRST
to WP_LAST
do
1096 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1097 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1098 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1101 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1103 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1104 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1109 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1);
1112 _name
, _model
: String;
1115 if not g_Game_IsServer
then Exit
;
1117 // Ñïèñîê íàçâàíèé ìîäåëåé:
1118 m
:= g_PlayerModel_GetNames();
1123 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1124 Team
:= TEAM_COOP
// COOP
1126 if gGameSettings
.GameMode
= GM_DM
then
1127 Team
:= TEAM_NONE
// DM
1129 if Team
= TEAM_NONE
then
1130 Team
:= BotList
[num
].team
; // CTF / TDM
1132 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1133 lName
:= AnsiLowerCase(lName
);
1134 if (num
< 0) or (num
> Length(BotList
)-1) then
1136 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1137 for a
:= 0 to High(BotList
) do
1138 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1147 _name
:= BotList
[num
].name
;
1148 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1149 if not g_Player_ValidName(_name
) then
1151 _name
:= Format('DFBOT%.2d', [Random(100)]);
1152 until g_Player_ValidName(_name
);
1155 _model
:= BotList
[num
].model
;
1156 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1157 if not InSArray(_model
, m
) then
1158 _model
:= m
[Random(Length(m
))];
1161 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1165 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1166 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1167 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1168 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1169 FDifficult
.Cover
:= BotList
[num
].cover
;
1170 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1172 for a
:= WP_FIRST
to WP_LAST
do
1174 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1175 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1176 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1179 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1181 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1185 procedure g_Bot_RemoveAll();
1189 if not g_Game_IsServer
then Exit
;
1190 if gPlayers
= nil then Exit
;
1192 for a
:= 0 to High(gPlayers
) do
1193 if gPlayers
[a
] <> nil then
1194 if gPlayers
[a
] is TBot
then
1196 gPlayers
[a
].Lives
:= 0;
1197 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1198 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1199 g_Player_Remove(gPlayers
[a
].FUID
);
1205 procedure g_Bot_MixNames();
1210 if BotNames
<> nil then
1211 for a
:= 0 to High(BotNames
) do
1213 b
:= Random(Length(BotNames
));
1215 Botnames
[a
] := BotNames
[b
];
1220 procedure g_Player_Remove(UID
: Word);
1224 if gPlayers
= nil then Exit
;
1226 if g_Game_IsServer
and g_Game_IsNet
then
1227 MH_SEND_PlayerDelete(UID
);
1229 for i
:= 0 to High(gPlayers
) do
1230 if gPlayers
[i
] <> nil then
1231 if gPlayers
[i
].FUID
= UID
then
1233 if gPlayers
[i
] is TPlayer
then
1234 TPlayer(gPlayers
[i
]).Free()
1236 TBot(gPlayers
[i
]).Free();
1242 procedure g_Player_Init();
1252 if not FileExists(DataDir
+ BOTNAMES_FILENAME
) then
1255 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1256 AssignFile(F
, DataDir
+ BOTNAMES_FILENAME
);
1267 SetLength(BotNames
, Length(BotNames
)+1);
1268 BotNames
[High(BotNames
)] := s
;
1276 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1277 config
:= TConfig
.CreateFile(DataDir
+ BOTLIST_FILENAME
);
1281 while config
.SectionExists(IntToStr(a
)) do
1283 SetLength(BotList
, Length(BotList
)+1);
1285 with BotList
[High(BotList
)] do
1288 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1290 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1292 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1297 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1298 color
.R
:= StrToIntDef(sa
[0], 0);
1299 color
.G
:= StrToIntDef(sa
[1], 0);
1300 color
.B
:= StrToIntDef(sa
[2], 0);
1301 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1302 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1303 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1304 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1305 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1306 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1307 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1308 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1309 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1310 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1311 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1312 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1313 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1314 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1315 if Length(sa
) = 10 then
1317 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1318 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1319 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1320 if Length(sa
) = 10 then
1322 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1324 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1325 if Length(sa) = 10 then
1327 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1336 procedure g_Player_Free();
1340 if gPlayers
<> nil then
1342 for i
:= 0 to High(gPlayers
) do
1343 if gPlayers
[i
] <> nil then
1345 if gPlayers
[i
] is TPlayer
then
1346 TPlayer(gPlayers
[i
]).Free()
1348 TBot(gPlayers
[i
]).Free();
1359 procedure g_Player_UpdateAll();
1363 if gPlayers
= nil then Exit
;
1365 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1366 for i
:= 0 to High(gPlayers
) do
1368 if gPlayers
[i
] <> nil then
1370 if gPlayers
[i
] is TPlayer
then
1372 gPlayers
[i
].Update();
1373 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1377 // bot updates weapons in `UpdateCombat()`
1378 TBot(gPlayers
[i
]).Update();
1382 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1385 procedure g_Player_DrawAll();
1389 if gPlayers
= nil then Exit
;
1391 for i
:= 0 to High(gPlayers
) do
1392 if gPlayers
[i
] <> nil then
1393 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1394 else TBot(gPlayers
[i
]).Draw();
1397 procedure g_Player_DrawDebug(p
: TPlayer
);
1401 if p
= nil then Exit
;
1402 if (@p
.FObj
) = nil then Exit
;
1404 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1406 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1407 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1408 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1409 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1410 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1411 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1414 procedure g_Player_DrawHealth();
1419 if gPlayers
= nil then Exit
;
1420 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1422 for i
:= 0 to High(gPlayers
) do
1423 if gPlayers
[i
] <> nil then
1425 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1426 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1427 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1428 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1429 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1430 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1434 function g_Player_Get(UID
: Word): TPlayer
;
1440 if gPlayers
= nil then
1443 for a
:= 0 to High(gPlayers
) do
1444 if gPlayers
[a
] <> nil then
1445 if gPlayers
[a
].FUID
= UID
then
1447 Result
:= gPlayers
[a
];
1452 function g_Player_GetCount(): Byte;
1458 if gPlayers
= nil then
1461 for a
:= 0 to High(gPlayers
) do
1462 if gPlayers
[a
] <> nil then
1463 Result
:= Result
+ 1;
1466 function g_Player_GetStats(): TPlayerStatArray
;
1472 if gPlayers
= nil then Exit
;
1474 for a
:= 0 to High(gPlayers
) do
1475 if gPlayers
[a
] <> nil then
1477 SetLength(Result
, Length(Result
)+1);
1478 with Result
[High(Result
)] do
1480 Ping
:= gPlayers
[a
].FPing
;
1481 Loss
:= gPlayers
[a
].FLoss
;
1482 Name
:= gPlayers
[a
].FName
;
1483 Team
:= gPlayers
[a
].FTeam
;
1484 Frags
:= gPlayers
[a
].FFrags
;
1485 Deaths
:= gPlayers
[a
].FDeath
;
1486 Kills
:= gPlayers
[a
].FKills
;
1487 Color
:= gPlayers
[a
].FModel
.Color
;
1488 Lives
:= gPlayers
[a
].FLives
;
1489 Spectator
:= gPlayers
[a
].FSpectator
;
1494 procedure g_Player_RememberAll
;
1498 for i
:= Low(gPlayers
) to High(gPlayers
) do
1499 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1500 gPlayers
[i
].RememberState
;
1503 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1507 gTeamStat
[TEAM_RED
].Goals
:= 0;
1508 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1510 if gPlayers
<> nil then
1511 for i
:= 0 to High(gPlayers
) do
1512 if gPlayers
[i
] <> nil then
1514 gPlayers
[i
].Reset(Force
);
1516 if gPlayers
[i
] is TPlayer
then
1518 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1519 gPlayers
[i
].Respawn(Silent
)
1521 gPlayers
[i
].Spectate();
1524 TBot(gPlayers
[i
]).Respawn(Silent
);
1528 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1534 if Player
.alive
then
1537 // Ðàçðûâàåì ñâÿçü ñ ïðåæíèì òðóïîì:
1538 if gCorpses
<> nil then
1539 for i
:= 0 to High(gCorpses
) do
1540 if gCorpses
[i
] <> nil then
1541 if gCorpses
[i
].FPlayerUID
= Player
.FUID
then
1542 gCorpses
[i
].FPlayerUID
:= 0;
1544 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1549 if (FHealth
>= -50) or (gGibsCount
= 0) then
1551 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1555 for find_id
:= 0 to High(gCorpses
) do
1556 if gCorpses
[find_id
] = nil then
1563 find_id
:= Random(Length(gCorpses
));
1565 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1566 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1567 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1568 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1569 gCorpses
[find_id
].FPlayerUID
:= FUID
;
1572 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1573 FObj
.Y
+ PLAYER_RECT_CY
,
1574 FModel
.Name
, FModel
.Color
);
1578 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1582 if (gShells
= nil) or (Length(gShells
) = 0) then
1585 with gShells
[CurrentShell
] do
1591 if T
= SHELL_BULLET
then
1593 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1597 Obj
.Rect
.Width
:= 4;
1598 Obj
.Rect
.Height
:= 2;
1602 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1606 Obj
.Rect
.Width
:= 7;
1607 Obj
.Rect
.Height
:= 3;
1613 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1614 positionChanged(); // this updates spatial accelerators
1615 RAngle
:= Random(360);
1616 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1618 if CurrentShell
>= High(gShells
) then
1625 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1628 GibsArray
: TGibsArray
;
1631 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1633 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1635 Blood
:= g_PlayerModel_GetBlood(ModelName
);
1637 for a
:= 0 to High(GibsArray
) do
1638 with gGibs
[CurrentGib
] do
1641 ID
:= GibsArray
[a
].ID
;
1642 MaskID
:= GibsArray
[a
].MaskID
;
1645 Obj
.Rect
:= GibsArray
[a
].Rect
;
1646 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1647 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1648 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1649 positionChanged(); // this updates spatial accelerators
1650 RAngle
:= Random(360);
1652 if gBloodCount
> 0 then
1653 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1654 Random(48), Random(48), Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
1656 if CurrentGib
>= High(gGibs
) then
1663 procedure g_Player_UpdatePhysicalObjects();
1669 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1674 if T
= SHELL_BULLET
then
1675 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1677 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1682 if gGibs
<> nil then
1683 for i
:= 0 to High(gGibs
) do
1684 if gGibs
[i
].alive
then
1688 mr
:= g_Obj_Move(@Obj
, True, False, True);
1689 positionChanged(); // this updates spatial accelerators
1691 if WordBool(mr
and MOVE_FALLOUT
) then
1697 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1698 if WordBool(mr
and MOVE_HITWALL
) then
1699 Obj
.Vel
.X
:= -(vel
.X
div 2);
1700 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1701 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1703 if (Obj
.Vel
.X
>= 0) then
1705 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1706 if RAngle
>= 360 then
1707 RAngle
:= RAngle
mod 360;
1708 end else begin // Counter-clockwise
1709 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1711 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1714 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1715 if gTime
mod (GAME_TICK
*3) = 0 then
1716 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1720 if gCorpses
<> nil then
1721 for i
:= 0 to High(gCorpses
) do
1722 if gCorpses
[i
] <> nil then
1723 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1729 gCorpses
[i
].Update();
1732 if gShells
<> nil then
1733 for i
:= 0 to High(gShells
) do
1734 if gShells
[i
].alive
then
1738 mr
:= g_Obj_Move(@Obj
, True, False, True);
1739 positionChanged(); // this updates spatial accelerators
1741 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1747 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1748 if WordBool(mr
and MOVE_HITWALL
) then
1750 Obj
.Vel
.X
:= -(vel
.X
div 2);
1751 if not WordBool(mr
and MOVE_INWATER
) then
1752 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1754 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1756 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1757 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1758 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1760 if RAngle
mod 90 <> 0 then
1761 RAngle
:= (RAngle
div 90) * 90;
1763 else if not WordBool(mr
and MOVE_INWATER
) then
1764 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1767 if (Obj
.Vel
.X
>= 0) then
1769 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1770 if RAngle
>= 360 then
1771 RAngle
:= RAngle
mod 360;
1772 end else begin // Counter-clockwise
1773 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1775 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1781 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1783 x
:= Obj
.X
+Obj
.Rect
.X
;
1784 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1785 w
:= Obj
.Rect
.Width
;
1786 h
:= Obj
.Rect
.Height
;
1789 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1791 if (dx
<> 0) or (dy
<> 0) then
1800 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1804 w
:= Obj
.Rect
.Width
;
1805 h
:= Obj
.Rect
.Height
;
1808 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1810 if (dx
<> 0) or (dy
<> 0) then
1819 procedure TGib
.positionChanged (); inline; begin end;
1820 procedure TShell
.positionChanged (); inline; begin end;
1823 procedure g_Player_DrawCorpses();
1828 if gGibs
<> nil then
1829 for i
:= 0 to High(gGibs
) do
1830 if gGibs
[i
].alive
then
1833 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1836 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1837 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1839 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1842 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1848 if gCorpses
<> nil then
1849 for i
:= 0 to High(gCorpses
) do
1850 if gCorpses
[i
] <> nil then
1854 procedure g_Player_DrawShells();
1859 if gShells
<> nil then
1860 for i
:= 0 to High(gShells
) do
1861 if gShells
[i
].alive
then
1864 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1870 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1874 procedure g_Player_RemoveAllCorpses();
1880 SetLength(gGibs
, MaxGibs
);
1881 SetLength(gShells
, MaxGibs
);
1885 if gCorpses
<> nil then
1886 for i
:= 0 to High(gCorpses
) do
1890 SetLength(gCorpses
, MaxCorpses
);
1893 procedure g_Player_Corpses_SaveState (st
: TStream
);
1897 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ
1899 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1901 // Êîëè÷åñòâî òðóïîâ
1902 utils
.writeInt(st
, LongInt(count
));
1904 if (count
= 0) then exit
;
1907 for i
:= 0 to High(gCorpses
) do
1909 if gCorpses
[i
] <> nil then
1912 utils
.writeStr(st
, gCorpses
[i
].FModelName
);
1914 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1915 // Ñîõðàíÿåì äàííûå òðóïà:
1916 gCorpses
[i
].SaveState(st
);
1922 procedure g_Player_Corpses_LoadState (st
: TStream
);
1930 g_Player_RemoveAllCorpses();
1932 // Êîëè÷åñòâî òðóïîâ:
1933 count
:= utils
.readLongInt(st
);
1934 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1936 if (count
= 0) then exit
;
1939 for i
:= 0 to count
-1 do
1942 str
:= utils
.readStr(st
);
1944 b
:= utils
.readBool(st
);
1946 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1947 // Çàãðóæàåì äàííûå òðóïà
1948 gCorpses
[i
].LoadState(st
);
1955 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1957 procedure TPlayer
.SetCurrWeapProp (newweap
: Byte);
1959 if (newweap
> High(FWeapon
)) then exit
;
1960 if (not FWeapon
[newweap
]) then exit
;
1961 if not g_Game_IsClient
then Inc(FNetWeapCtr
, 2); // just in case, to really override client's counter
1962 if (FCurrWeap
<> newweap
) then
1964 if (newweap
= WEAPON_SAW
) then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
1966 FCurrWeap
:= newweap
;
1967 FModel
.SetWeapon(newweap
);
1970 procedure TPlayer
.BFGHit();
1972 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1973 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1974 if g_Game_IsServer
and g_Game_IsNet
then
1975 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1976 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1980 procedure TPlayer
.ChangeModel(ModelName
: string);
1982 locModel
: TPlayerModel
;
1984 locModel
:= g_PlayerModel_Get(ModelName
);
1985 if locModel
= nil then Exit
;
1991 procedure TPlayer
.SetModel(ModelName
: string);
1995 m
:= g_PlayerModel_Get(ModelName
);
1998 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1999 m
:= g_PlayerModel_Get('doomer');
2002 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
2007 if FModel
<> nil then
2012 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2013 FModel
.Color
:= FColor
2015 FModel
.Color
:= TEAMCOLOR
[FTeam
];
2016 FModel
.SetWeapon(FCurrWeap
);
2017 FModel
.SetFlag(FFlag
);
2018 SetDirection(FDirection
);
2021 procedure TPlayer
.SetColor(Color
: TRGB
);
2024 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2025 if FModel
<> nil then FModel
.Color
:= Color
;
2028 procedure TPlayer
.SwitchTeam
;
2030 if g_Game_IsClient
then
2032 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
2034 if gGameOn
and FAlive
then
2035 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
2037 if FTeam
= TEAM_RED
then
2039 ChangeTeam(TEAM_BLUE
);
2040 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
2041 if g_Game_IsNet
then
2042 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
2046 ChangeTeam(TEAM_RED
);
2047 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
2048 if g_Game_IsNet
then
2049 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
2051 FPreferredTeam
:= FTeam
;
2054 procedure TPlayer
.ChangeTeam(Team
: Byte);
2061 TEAM_RED
, TEAM_BLUE
:
2062 FModel
.Color
:= TEAMCOLOR
[Team
];
2064 FModel
.Color
:= FColor
;
2066 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2067 MH_SEND_PlayerStats(FUID
);
2071 procedure TPlayer.CollideItem();
2076 if gItems = nil then Exit;
2077 if not FAlive then Exit;
2079 for i := 0 to High(gItems) do
2082 if (ItemType <> ITEM_NONE) and alive then
2083 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2084 PLAYER_RECT.Height, @Obj) then
2086 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2088 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2089 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2090 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2091 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2092 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2094 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2095 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2096 (gGameSettings.GameType = GT_SINGLE) and
2097 (g_Player_GetCount() > 1)) then
2098 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2104 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2106 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2107 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2111 constructor TPlayer
.Create();
2117 mEDamageType
:= HIT_SOME
;
2123 FSawSound
:= TPlayableSound
.Create();
2124 FSawSoundIdle
:= TPlayableSound
.Create();
2125 FSawSoundHit
:= TPlayableSound
.Create();
2126 FSawSoundSelect
:= TPlayableSound
.Create();
2127 FJetSoundFly
:= TPlayableSound
.Create();
2128 FJetSoundOn
:= TPlayableSound
.Create();
2129 FJetSoundOff
:= TPlayableSound
.Create();
2131 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2132 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2133 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2134 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2135 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2136 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2137 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2139 FSpectatePlayer
:= -1;
2143 FSavedState
.WaitRecall
:= False;
2149 FActualModelName
:= 'doomer';
2152 FObj
.Rect
:= PLAYER_RECT
;
2154 FBFGFireCounter
:= -1;
2155 FJustTeleported
:= False;
2161 releaseAllWeaponSwitchKeys();
2165 procedure TPlayer
.releaseAllWeaponSwitchKeys ();
2169 for f
:= 0 to High(weaponSwitchKeyReleased
) do weaponSwitchKeyReleased
[f
] := $03;
2172 procedure TPlayer
.weaponSwitchKeysStateChange (index
: Integer; pressed
: Boolean);
2174 Inc(index
, 2); // -2: prev; -1: next
2175 if (index
< 0) or (index
> High(weaponSwitchKeyReleased
)) then exit
;
2176 weaponSwitchKeyReleased
[index
] := weaponSwitchKeyReleased
[index
] or $02;
2177 if (pressed
) then weaponSwitchKeyReleased
[index
] := weaponSwitchKeyReleased
[index
] xor $02;
2180 function TPlayer
.isWeaponSwitchKeyReleased (index
: Integer): Boolean;
2182 Inc(index
, 2); // -2: prev; -1: next
2183 if (index
< 0) or (index
> High(weaponSwitchKeyReleased
)) then
2189 result
:= (weaponSwitchKeyReleased
[index
] and $01) <> 0;
2193 procedure TPlayer
.weaponSwitchKeysShiftNewStates ();
2197 // copy bit 1 to bit 0
2198 for f
:= 0 to High(weaponSwitchKeyReleased
) do
2200 weaponSwitchKeyReleased
[f
] :=
2201 (weaponSwitchKeyReleased
[f
] and $02) or
2202 ((weaponSwitchKeyReleased
[f
] shr 1) and $01);
2207 procedure TPlayer
.positionChanged (); inline;
2211 procedure TPlayer
.doDamage (v
: Integer);
2213 if (v
<= 0) then exit
;
2214 if (v
> 32767) then v
:= 32767;
2215 Damage(v
, 0, 0, 0, mEDamageType
);
2218 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2222 if (not g_Game_IsClient
) and (not FAlive
) then
2227 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2228 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2230 if not g_Game_IsClient
then
2233 if t
= HIT_TRAP
then
2235 // Ëîâóøêà óáèâàåò ñðàçó:
2237 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2239 if t
= HIT_SELF
then
2243 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2246 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2247 FMegaRulez
[MR_SUIT
] := 0;
2248 FMegaRulez
[MR_INVUL
] := 0;
2249 FMegaRulez
[MR_INVIS
] := 0;
2253 // Íî îò îñòàëüíîãî ñïàñàåò:
2254 if FMegaRulez
[MR_INVUL
] >= gTime
then
2261 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2262 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2263 (SpawnerUID
= FUID
) or
2264 (not SameTeam(FUID
, SpawnerUID
)) then
2266 FLastSpawnerUID
:= SpawnerUID
;
2268 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2269 if gBloodCount
> 0 then
2271 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2272 if value
div 4 <= c
then
2273 c
:= c
- (value
div 4)
2277 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2281 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2282 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2285 if t
= HIT_WATER
then
2286 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2287 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2292 Inc(FDamageBuffer
, value
);
2296 FPain
:= FPain
+ value
;
2299 if g_Game_IsServer
and g_Game_IsNet
then
2301 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2302 MH_SEND_PlayerStats(FUID
);
2303 MH_SEND_PlayerPos(False, FUID
);
2307 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2310 if g_Game_IsClient
then
2315 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2317 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2320 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2322 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2326 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2327 MH_SEND_PlayerStats(FUID
);
2330 destructor TPlayer
.Destroy();
2332 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2334 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2338 FSawSoundIdle
.Free();
2339 FSawSoundHit
.Free();
2340 FJetSoundFly
.Free();
2342 FJetSoundOff
.Free();
2344 if FPunchAnim
<> nil then
2350 procedure TPlayer
.DrawIndicator();
2352 indX
, indY
: Integer;
2358 indX
:= FObj
.X
+FObj
.Rect
.X
;
2359 indY
:= FObj
.Y
- 12;
2360 if g_Texture_Get('TEXTURE_PLAYER_INDICATOR', ID
) then
2362 e_GetTextureSize(ID
, @indW
, @indH
);
2363 e_Draw(ID
, indX
+ indW
div 2, indY
, 0, True, False);
2366 //e_TextureFontPrint(indX, indY, FName, gStdFont); // Shows player name overhead
2369 procedure TPlayer
.DrawBubble();
2371 bubX
, bubY
: Integer;
2374 Rw
, Gw
, Bw
: SmallInt;
2377 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= TDirection
.D_LEFT
, -4, 18);
2378 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2386 1: // simple textual non-bubble
2388 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2389 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2390 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2393 2: // advanced pixel-perfect bubble
2395 if FTeam
= TEAM_RED
then
2398 if FTeam
= TEAM_BLUE
then
2401 3: // colored bubble
2403 Rb
:= FModel
.Color
.R
;
2404 Gb
:= FModel
.Color
.G
;
2405 Bb
:= FModel
.Color
.B
;
2406 Rw
:= Min(Rb
* 2 + 64, 255);
2407 Gw
:= Min(Gb
* 2 + 64, 255);
2408 Bw
:= Min(Bb
* 2 + 64, 255);
2409 if (Abs(Rw
- Rb
) < 32)
2410 or (Abs(Gw
- Gb
) < 32)
2411 or (Abs(Bw
- Bb
) < 32) then
2413 Rb
:= Max(Rw
div 2 - 16, 0);
2414 Gb
:= Max(Gw
div 2 - 16, 0);
2415 Bb
:= Max(Bw
div 2 - 16, 0);
2418 4: // custom textured bubble
2420 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2421 if FDirection
= TDirection
.D_RIGHT
then
2422 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2424 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, TMirrorType
.Horizontal
);
2430 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2431 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2433 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2436 Dot
:= IfThen(FDirection
= TDirection
.D_LEFT
, 14, 5);
2437 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2438 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
);
2439 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
);
2440 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
);
2441 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
);
2445 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2446 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2447 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2450 procedure TPlayer
.Draw();
2455 Mirror
: TMirrorType
;
2459 if Direction
= TDirection
.D_RIGHT
then
2460 Mirror
:= TMirrorType
.None
2462 Mirror
:= TMirrorType
.Horizontal
;
2464 if FPunchAnim
<> nil then
2466 FPunchAnim
.Draw(FObj
.X
+IfThen(Direction
= TDirection
.D_LEFT
, 15-FObj
.Rect
.X
, FObj
.Rect
.X
-15),
2467 FObj
.Y
+FObj
.Rect
.Y
-11, Mirror
);
2468 if FPunchAnim
.played
then
2475 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2476 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2478 e_GetTextureSize(ID
, @w
, @h
);
2479 if FDirection
= TDirection
.D_LEFT
then
2480 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2481 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False)
2483 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2484 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False);
2487 if FMegaRulez
[MR_INVIS
] > gTime
then
2489 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2490 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2492 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2493 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2497 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 200)
2499 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2502 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 254);
2505 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2508 if g_debug_Frames
then
2510 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2512 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2513 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2517 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2519 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2520 if gAimLine
and alive
and
2521 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2526 procedure TPlayer
.DrawAim();
2527 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2532 {$IFDEF ENABLE_HOLMES}
2533 if isValidViewPort
and (self
= gPlayer1
) then
2535 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2539 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2540 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2542 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2546 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2551 wx
, wy
, xx
, yy
: Integer;
2555 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= TDirection
.D_LEFT
, 7, -7);
2556 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2565 1: begin // Chainsaw
2572 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2573 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2574 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2575 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2580 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2581 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2582 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2583 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2585 4: begin // Double Shotgun
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);
2593 5: begin // Chaingun
2596 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2597 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2598 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2599 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2601 6: begin // Rocket Launcher
2604 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2605 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2606 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2607 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2609 7: begin // Plasmagun
2612 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2613 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2614 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2615 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2620 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2621 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2622 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2623 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2625 9: begin // Super Chaingun
2628 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2629 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2630 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2631 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2634 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2635 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2636 {$IF DEFINED(D2F_DEBUG)}
2637 drawCast(sz
, wx
, wy
, xx
, yy
);
2639 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2643 procedure TPlayer
.DrawGUI();
2646 X
, Y
, SY
, a
, p
, m
: Integer;
2650 stat
: TPlayerStatArray
;
2652 X
:= gPlayerScreenSize
.X
;
2653 SY
:= gPlayerScreenSize
.Y
;
2656 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2658 if gGameSettings
.GameMode
= GM_CTF
then
2662 if gGameSettings
.GameMode
= GM_CTF
then
2664 s
:= 'TEXTURE_PLAYER_REDFLAG';
2665 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2666 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2667 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2668 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2669 if g_Texture_Get(s
, ID
) then
2670 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2673 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2674 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2675 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2677 if gGameSettings
.GameMode
= GM_CTF
then
2679 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2680 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2681 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2682 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2683 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2684 if g_Texture_Get(s
, ID
) then
2685 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2688 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2689 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2690 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2693 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2694 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2697 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2698 e_Draw(ID
, X
+2, Y
, 0, True, False);
2700 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2704 s
:= IntToStr(Frags
);
2705 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2706 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2711 stat
:= g_Player_GetStats();
2716 for a
:= 0 to High(stat
) do
2717 if stat
[a
].Name
<> Name
then
2719 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2720 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2724 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2725 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2726 s
:= s
+IntToStr(Abs(Frags
-m
));
2728 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2729 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2732 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2734 s
:= IntToStr(Lives
);
2735 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2736 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2740 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2741 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2743 if R_BERSERK
in FRulez
then
2744 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2746 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2748 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2749 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2751 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2752 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2753 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2755 s
:= IntToStr(FArmor
);
2756 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2757 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2759 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2765 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2770 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2772 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2773 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2774 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2775 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2776 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2777 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2778 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2779 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2780 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2783 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2784 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2785 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2787 if R_KEY_RED
in FRulez
then
2788 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2790 if R_KEY_GREEN
in FRulez
then
2791 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2793 if R_KEY_BLUE
in FRulez
then
2794 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2796 if FJetFuel
> 0 then
2798 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2799 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2800 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2801 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2802 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2803 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2807 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2808 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2809 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2812 if gShowPing
and g_Game_IsClient
then
2814 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2815 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2821 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2822 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2823 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2826 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2827 s
:= _lc
[I_PLAYER_SPECT4
];
2828 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2829 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2830 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2836 procedure TPlayer
.DrawRulez();
2840 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2841 if FMegaRulez
[MR_INVUL
] >= gTime
then
2843 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2844 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2849 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2850 191, 191, 191, 0, TBlending
.Invert
);
2853 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2854 if FMegaRulez
[MR_SUIT
] >= gTime
then
2856 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2857 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2862 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2863 0, 96, 0, 200, TBlending
.None
);
2866 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2867 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2869 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2870 255, 0, 0, 200, TBlending
.None
);
2874 procedure TPlayer
.DrawPain();
2878 if FPain
= 0 then Exit
;
2882 if a
< 15 then h
:= 0
2883 else if a
< 35 then h
:= 1
2884 else if a
< 55 then h
:= 2
2885 else if a
< 75 then h
:= 3
2886 else if a
< 95 then h
:= 4
2889 //if a > 255 then a := 255;
2891 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2892 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2895 procedure TPlayer
.DrawPickup();
2899 if FPickup
= 0 then Exit
;
2903 if a
< 15 then h
:= 1
2904 else if a
< 35 then h
:= 2
2905 else if a
< 55 then h
:= 3
2906 else if a
< 75 then h
:= 4
2909 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2912 procedure TPlayer
.DoPunch();
2917 if FPunchAnim
<> nil then begin
2922 st
:= 'FRAMES_PUNCH';
2923 if R_BERSERK
in FRulez
then
2924 st
:= st
+ '_BERSERK';
2925 if FKeys
[KEY_UP
].Pressed
then
2927 else if FKeys
[KEY_DOWN
].Pressed
then
2929 g_Frames_Get(id
, st
);
2930 FPunchAnim
:= TAnimation
.Create(id
, False, 1);
2933 procedure TPlayer
.Fire();
2935 f
, DidFire
: Boolean;
2936 wx
, wy
, xd
, yd
: Integer;
2939 if g_Game_IsClient
then Exit
;
2940 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2941 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2949 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2954 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2955 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2956 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
2957 yd
:= wy
+firediry();
2963 if R_BERSERK
in FRulez
then
2965 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2966 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2967 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2970 locobj
.rect
.Width
:= 39;
2971 locobj
.rect
.Height
:= 52;
2972 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2973 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2974 locobj
.Accel
.X
:= xd
-wx
;
2975 locobj
.Accel
.y
:= yd
-wy
;
2977 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2978 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2980 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2982 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
2986 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2990 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2995 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2996 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2998 FSawSoundSelect
.Stop();
3000 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
3002 else if not FSawSoundHit
.IsPlaying() then
3004 FSawSoundSelect
.Stop();
3005 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
3008 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3014 if FAmmo
[A_BULLETS
] > 0 then
3016 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
3017 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3018 Dec(FAmmo
[A_BULLETS
]);
3019 FFireAngle
:= FAngle
;
3022 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3023 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3027 if FAmmo
[A_SHELLS
] > 0 then
3029 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3030 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
3031 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3032 Dec(FAmmo
[A_SHELLS
]);
3033 FFireAngle
:= FAngle
;
3037 FShellType
:= SHELL_SHELL
;
3041 if FAmmo
[A_SHELLS
] >= 2 then
3043 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
3044 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3045 Dec(FAmmo
[A_SHELLS
], 2);
3046 FFireAngle
:= FAngle
;
3050 FShellType
:= SHELL_DBLSHELL
;
3054 if FAmmo
[A_BULLETS
] > 0 then
3056 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
3057 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
3058 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3059 Dec(FAmmo
[A_BULLETS
]);
3060 FFireAngle
:= FAngle
;
3063 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3064 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3067 WEAPON_ROCKETLAUNCHER
:
3068 if FAmmo
[A_ROCKETS
] > 0 then
3070 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
3071 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3072 Dec(FAmmo
[A_ROCKETS
]);
3073 FFireAngle
:= FAngle
;
3079 if FAmmo
[A_CELLS
] > 0 then
3081 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
3082 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3083 Dec(FAmmo
[A_CELLS
]);
3084 FFireAngle
:= FAngle
;
3090 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
3092 FBFGFireCounter
:= 17;
3093 if not FNoReload
then
3094 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
3095 Dec(FAmmo
[A_CELLS
], 40);
3099 WEAPON_SUPERPULEMET
:
3100 if FAmmo
[A_SHELLS
] > 0 then
3102 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3103 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
3104 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3105 Dec(FAmmo
[A_SHELLS
]);
3106 FFireAngle
:= FAngle
;
3109 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3110 GameVelX
, GameVelY
-2, SHELL_SHELL
);
3113 WEAPON_FLAMETHROWER
:
3114 if FAmmo
[A_FUEL
] > 0 then
3116 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
3117 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3119 FFireAngle
:= FAngle
;
3125 if g_Game_IsNet
then
3129 if FCurrWeap
<> WEAPON_BFG
then
3130 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
3132 if not FNoReload
then
3133 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
3136 MH_SEND_PlayerStats(FUID
);
3141 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
3142 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
3143 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
3146 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
3149 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
3150 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
3151 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
3152 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
3153 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
3158 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
3160 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
3161 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
3162 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
3165 procedure TPlayer
.JetpackOn
;
3169 FJetSoundOn
.SetPosition(0);
3170 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3174 procedure TPlayer
.JetpackOff
;
3178 FJetSoundOff
.SetPosition(0);
3179 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3182 procedure TPlayer
.CatchFire(Attacker
: Word);
3185 FFireAttacker
:= Attacker
;
3186 if g_Game_IsNet
and g_Game_IsServer
then
3187 MH_SEND_PlayerStats(FUID
);
3190 procedure TPlayer
.Jump();
3192 if gFly
or FJetpack
then
3194 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3195 if FObj
.Vel
.Y
> -VEL_FLY
then
3196 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3199 if FJetFuel
> 0 then
3201 if (FJetFuel
< 1) and g_Game_IsServer
then
3205 if g_Game_IsNet
then
3206 MH_SEND_PlayerStats(FUID
);
3212 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3214 FCanJetpack
:= False;
3216 // Ïðûãàåì èëè âñïëûâàåì:
3217 if (CollideLevel(0, 1) or
3218 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3219 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3220 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3222 FObj
.Vel
.Y
:= -VEL_JUMP
;
3223 FCanJetpack
:= False;
3227 if BodyInLiquid(0, 0) then
3228 FObj
.Vel
.Y
:= -VEL_SW
3229 else if (FJetFuel
> 0) and FCanJetpack
and
3230 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3234 if g_Game_IsNet
then
3235 MH_SEND_PlayerStats(FUID
);
3240 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3242 a
, i
, k
, ab
, ar
: Byte;
3246 srv
, netsrv
: Boolean;
3252 procedure PushItem(t
: Byte);
3256 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3257 it
:= g_Items_ByIdx(id
);
3258 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3260 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3261 (FObj
.Vel
.Y
div 2)-Random(9));
3262 it
.positionChanged(); // this updates spatial accelerators
3266 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3268 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3269 (FObj
.Vel
.Y
div 2)-Random(6));
3271 else // -3..+3; -3..0
3273 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3274 (FObj
.Vel
.Y
div 2)-Random(4));
3276 it
.positionChanged(); // this updates spatial accelerators
3279 if g_Game_IsNet
and g_Game_IsServer
then
3280 MH_SEND_ItemSpawn(True, id
);
3284 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3285 Srv
:= g_Game_IsServer
;
3286 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3287 if Srv
then FDeath
:= FDeath
+ 1;
3292 if not FPhysics
then
3298 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3300 if FLives
> 0 then FLives
:= FLives
- 1;
3301 if FLives
= 0 then FNoRespawn
:= True;
3304 // Íîìåð òèïà ñìåðòè:
3307 K_SIMPLEKILL
: a
:= 1;
3309 K_EXTRAHARDKILL
: a
:= 3;
3314 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3316 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3323 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3325 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3326 K_EXTRAHARDKILL
, K_FALLKILL
:
3327 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3330 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3334 K_HARDKILL
, K_EXTRAHARDKILL
:
3338 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3339 if (KillType
<> K_FALLKILL
) and (Srv
) then
3340 g_Monsters_killedp();
3342 if SpawnerUID
= FUID
then
3344 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3349 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3352 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3353 begin // Óáèò äðóãèì èãðîêîì
3354 KP
:= g_Player_Get(SpawnerUID
);
3355 if (KP
<> nil) and Srv
then
3357 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3358 if SameTeam(FUID
, SpawnerUID
) then
3368 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3369 Inc(gTeamStat
[KP
.Team
].Goals
,
3370 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3372 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3375 plr
:= g_Player_Get(SpawnerUID
);
3383 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3387 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3391 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3396 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3397 begin // Óáèò ìîíñòðîì
3398 mon
:= g_Monsters_ByUID(SpawnerUID
);
3402 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
3406 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3410 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3414 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3419 else // Îñîáûå òèïû ñìåðòè
3422 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3423 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3424 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3425 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3426 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3427 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3433 for a
:= WP_FIRST
to WP_LAST
do
3437 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3438 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3439 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3440 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3441 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3442 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3443 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3444 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3445 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3454 if R_ITEM_BACKPACK
in FRulez
then
3455 PushItem(ITEM_AMMO_BACKPACK
);
3457 // Âûáðîñ ðàêåòíîãî ðàíöà:
3458 if FJetFuel
> 0 then
3459 PushItem(ITEM_JETPACK
);
3462 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3464 if R_KEY_RED
in FRulez
then
3465 PushItem(ITEM_KEY_RED
);
3467 if R_KEY_GREEN
in FRulez
then
3468 PushItem(ITEM_KEY_GREEN
);
3470 if R_KEY_BLUE
in FRulez
then
3471 PushItem(ITEM_KEY_BLUE
);
3478 g_Player_CreateCorpse(Self
);
3480 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3481 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3487 for i
:= Low(gPlayers
) to High(gPlayers
) do
3489 if gPlayers
[i
] = nil then continue
;
3490 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3493 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3494 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3499 OldLR
:= gLMSRespawn
;
3500 if (gGameSettings
.GameMode
= GM_COOP
) then
3504 // everyone is dead, restart the map
3505 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3507 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3508 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3509 gLMSRespawnTime
:= gTime
+ 5000;
3511 else if (a
= 1) then
3513 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3514 if (gPlayers
[k
] = gPlayer1
) or
3515 (gPlayers
[k
] = gPlayer2
) then
3516 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3517 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3518 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3521 else if (gGameSettings
.GameMode
= GM_TDM
) then
3523 if (ab
= 0) and (ar
<> 0) then
3526 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3528 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3529 Inc(gTeamStat
[TEAM_RED
].Goals
);
3530 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3531 gLMSRespawnTime
:= gTime
+ 5000;
3533 else if (ar
= 0) and (ab
<> 0) then
3536 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3538 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3539 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3540 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3541 gLMSRespawnTime
:= gTime
+ 5000;
3543 else if (ar
= 0) and (ab
= 0) then
3546 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3548 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3549 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3550 gLMSRespawnTime
:= gTime
+ 5000;
3553 else if (gGameSettings
.GameMode
= GM_DM
) then
3557 if gPlayers
[k
] <> nil then
3560 // survivor is the winner
3561 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3563 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3566 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3567 gLMSRespawnTime
:= gTime
+ 5000;
3569 else if (a
= 0) then
3571 // everyone is dead, restart the map
3572 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3574 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3575 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3576 gLMSRespawnTime
:= gTime
+ 5000;
3579 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3581 if NetMode
= NET_SERVER
then
3582 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3584 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3590 MH_SEND_PlayerStats(FUID
);
3591 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3592 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3595 if srv
and FNoRespawn
then Spectate(True);
3596 FWantsInGame
:= True;
3599 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3601 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3602 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3605 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3607 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3608 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3611 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3613 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3614 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3615 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3616 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3617 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3618 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3619 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3620 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3623 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3625 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3626 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3627 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3628 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3631 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3633 //if g_Game_IsClient then Exit;
3634 if Weapon
> High(FWeapon
) then Exit
;
3635 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3638 procedure TPlayer
.resetWeaponQueue ();
3641 FNextWeapDelay
:= 0;
3644 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3648 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3649 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
3650 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
3651 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3652 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3653 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3654 else result
:= (weapon
< length(FWeapon
));
3658 // return 255 for "no switch"
3659 function TPlayer
.getNextWeaponIndex (): Byte;
3662 wantThisWeapon
: array[0..64] of Boolean;
3663 weaponOrder
: array[0..16] of Integer; // value: index in `FWeapon`
3665 f
, dir
, cwi
, rwidx
, curlidx
: Integer;
3667 function real2log (ridx
: Integer): Integer;
3673 for f
:= 0 to High(weaponOrder
) do if (weaponOrder
[f
] = ridx
) then begin result
:= f
; exit
; end;
3679 result
:= 255; // default result: "no switch"
3681 // had weapon cycling on previous frame? remove that flag
3682 if (FNextWeap
and $2000) <> 0 then
3684 FNextWeap
:= FNextWeap
and $1FFF;
3685 FNextWeapDelay
:= 0;
3688 for f
:= 0 to High(weaponOrder
) do weaponOrder
[f
] := -1;
3690 // build weapon order (k8: i know, i know, learn how to do constants and such... gtfo, please!)
3691 // two knuckles are for "normal" and "berserk" (see `if` below -- it removes the one that is not needed)
3693 // bfg, launcher, plasma, flamethrower, ssg, minigun, sg, pistol, berserk, chainsaw, fist
3694 weaponOrder
[0] := WEAPON_SUPERPULEMET
;
3695 weaponOrder
[1] := WEAPON_BFG
;
3696 weaponOrder
[2] := WEAPON_ROCKETLAUNCHER
;
3697 weaponOrder
[3] := WEAPON_PLASMA
;
3698 weaponOrder
[4] := WEAPON_FLAMETHROWER
;
3699 weaponOrder
[5] := WEAPON_SHOTGUN2
;
3700 weaponOrder
[6] := WEAPON_CHAINGUN
;
3701 weaponOrder
[7] := WEAPON_SHOTGUN1
;
3702 weaponOrder
[8] := WEAPON_PISTOL
;
3703 weaponOrder
[9] := WEAPON_KASTET
+666; // berserk fist
3704 weaponOrder
[10] := WEAPON_SAW
;
3705 weaponOrder
[11] := WEAPON_KASTET
; // normal fist
3707 for f
:= 0 to High(weaponOrder
) do
3709 if (weaponOrder
[f
] = WEAPON_KASTET
) then
3711 // normal fist: remove if we have a berserk pack
3712 if (R_BERSERK
in FRulez
) then weaponOrder
[f
] := -1;
3715 if (weaponOrder
[f
] = WEAPON_KASTET
+666) then
3717 // berserk fist: remove if we don't have a berserk pack
3718 if (R_BERSERK
in FRulez
) then weaponOrder
[f
] := WEAPON_KASTET
else weaponOrder
[f
] := -1;
3726 WEAPON_SHOTGUN1 = 3;
3727 WEAPON_SHOTGUN2 = 4;
3728 WEAPON_CHAINGUN = 5;
3729 WEAPON_ROCKETLAUNCHER = 6;
3732 WEAPON_SUPERPULEMET = 9;
3733 WEAPON_FLAMETHROWER = 10;
3737 if (FNextWeap <> 0) or (FNextWeapDelay <> 0) then
3739 e_WriteLog(Format('!!! FNextWeap=%04x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), TMsgType.Warning);
3743 // cycling has priority
3744 if (FNextWeap
and $C000) <> 0 then
3746 if (FNextWeap
and $8000) <> 0 then dir
:= 1 else dir
:= -1; // should be reversed if we want "priority-driven cycling"
3747 FNextWeap
:= FNextWeap
or $2000; // we need this
3748 if FNextWeapDelay
> 0 then exit
; // cooldown time
3749 //cwi := real2log(FCurrWeap);
3750 //if (cwi < 0) then cwi := 0;
3752 for i
:= 0 to High(FWeapon
) do
3754 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3755 //rwidx := weaponOrder[cwi];
3756 rwidx
:= cwi
; // sorry
3757 if (rwidx
< 0) then continue
;
3758 if FWeapon
[rwidx
] then
3760 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d (dir=%d; log=%d)', [FCurrWeap, rwidx, dir, cwi]), TMsgType.Warning);
3761 result
:= Byte(rwidx
);
3762 //FNextWeapDelay := 10; //k8: not needed anymore
3771 for i
:= 0 to High(wantThisWeapon
) do wantThisWeapon
[i
] := false;
3774 curlidx
:= -1; // start from a weapon with a highest priority (-1, 'cause loop will immediately increment this index)
3776 for i
:= 0 to High(FWeapon
) do
3778 if (FNextWeap
and (1 shl i
)) <> 0 then
3783 wantThisWeapon
[cwi
] := true;
3785 // if we hit currently selected weapon, start seachring from it, so we'll get "next weaker" weapon
3786 if (i
= FCurrWeap
) then curlidx
:= cwi
; // compare real, start from logical
3791 // slow down alterations a little
3794 // more than one weapon requested, assume "alteration", and check alteration delay
3795 if FNextWeapDelay
> 0 then
3797 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), TMsgType.Warning);
3803 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3804 // but clear all counters if no weapon should be switched
3811 //e_WriteLog(Format('*** wwc=%d; currweap=%d; logweap=%d', [wwc, FCurrWeap, curlidx]), TMsgType.Warning);
3813 // find next weapon to switch onto
3815 for i
:= 0 to High(weaponOrder
) do
3817 cwi
:= (cwi
+length(weaponOrder
)+1) mod length(weaponOrder
);
3818 if (cwi
= curlidx
) then continue
; // skip current weapon
3819 if not wantThisWeapon
[cwi
] then continue
;
3820 rwidx
:= weaponOrder
[cwi
];
3821 if (rwidx
< 0) then continue
;
3822 //e_WriteLog(Format(' trying logical %d (real %d); has=%d, hasammo=%d', [cwi, rwidx, Integer(FWeapon[rwidx]), Integer(hasAmmoForWeapon(rwidx))]), TMsgType.Warning);
3823 if FWeapon
[rwidx
] and ((wwc
= 1) or hasAmmoForWeapon(rwidx
)) then
3825 //e_WriteLog(' I FOUND HER!', TMsgType.Warning);
3827 result
:= Byte(rwidx
);
3829 //FNextWeapDelay := 10; // anyway, 'cause why not; k8: not needed anymore
3834 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3838 procedure TPlayer
.RealizeCurrentWeapon();
3839 function switchAllowed (): Boolean;
3844 if FBFGFireCounter
<> -1 then
3846 if FTime
[T_SWITCH
] > gTime
then
3848 for i
:= WP_FIRST
to WP_LAST
do
3849 if FReloading
[i
] > 0 then
3857 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3858 //FNextWeap := FNextWeap and $1FFF;
3859 //HACK: alteration delay will be reset when player released any weapon switch key
3860 FNextWeapDelay
:= 0; //k8: just in case
3861 //if FNextWeapDelay > 0 then Dec(FNextWeapDelay); // "alteration delay"
3863 if not switchAllowed
then
3865 //writeln('WEAPON SWITCHING IS NOT ALLOWED! FBFGFireCounter=', FBFGFireCounter, '; gTime=', gTime, '; FTime[T_SWITCH]=', FTime[T_SWITCH]);
3866 //HACK for weapon cycling
3867 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3871 nw
:= getNextWeaponIndex();
3872 if nw
= 255 then exit
; // don't reset anything here
3873 if nw
> High(FWeapon
) then
3875 // don't forget to reset queue here!
3876 //e_WriteLog(Format(' RealizeCurrentWeapon: WUTAFUUUU?! (%d)', [nw]), TMsgType.Warning);
3883 //k8: emulate this on client immediately, or wait for server confirmation?
3886 if (nw
= WEAPON_SAW
) then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3887 FModel
.SetWeapon(nw
);
3888 FTime
[T_SWITCH
] := gTime
+156;
3889 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3893 procedure TPlayer
.NextWeapon();
3895 //if g_Game_IsClient then Exit;
3899 procedure TPlayer
.PrevWeapon();
3901 //if g_Game_IsClient then Exit;
3905 // used exclusively by network layer
3906 procedure TPlayer
.SetWeaponHost(W
: Byte);
3908 if (W
> High(FWeapon
)) then exit
;
3909 if (not FWeapon
[W
]) then exit
; // server is authority!
3911 if FCurrWeap
<> W
then
3913 if (W
= WEAPON_SAW
) then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3917 FModel
.SetWeapon(W
);
3918 //if g_Game_IsClient then resetWeaponQueue();
3921 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3923 function allowBerserkSwitching (): Boolean;
3925 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3927 if gBerserkAutoswitch
then exit
;
3928 if not conIsCheatsEnabled
then exit
;
3936 if g_Game_IsClient
then Exit
;
3938 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3939 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3944 if FHealth
< PLAYER_HP_SOFT
then
3946 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3950 if gFlash
= 2 then Inc(FPickup
, 5);
3954 if FHealth
< PLAYER_HP_SOFT
then
3956 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3960 if gFlash
= 2 then Inc(FPickup
, 5);
3964 if FArmor
< PLAYER_AP_SOFT
then
3966 FArmor
:= PLAYER_AP_SOFT
;
3969 if gFlash
= 2 then Inc(FPickup
, 5);
3973 if FArmor
< PLAYER_AP_LIMIT
then
3975 FArmor
:= PLAYER_AP_LIMIT
;
3978 if gFlash
= 2 then Inc(FPickup
, 5);
3982 if FHealth
< PLAYER_HP_LIMIT
then
3984 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3988 if gFlash
= 2 then Inc(FPickup
, 5);
3992 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3994 if FHealth
< PLAYER_HP_LIMIT
then
3995 FHealth
:= PLAYER_HP_LIMIT
;
3996 if FArmor
< PLAYER_AP_LIMIT
then
3997 FArmor
:= PLAYER_AP_LIMIT
;
4001 if gFlash
= 2 then Inc(FPickup
, 5);
4005 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
4007 FWeapon
[WEAPON_SAW
] := True;
4009 if gFlash
= 2 then Inc(FPickup
, 5);
4010 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4013 ITEM_WEAPON_SHOTGUN1
:
4014 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
4016 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
4017 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
4019 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4020 FWeapon
[WEAPON_SHOTGUN1
] := True;
4022 if gFlash
= 2 then Inc(FPickup
, 5);
4023 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4026 ITEM_WEAPON_SHOTGUN2
:
4027 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
4029 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
4031 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4032 FWeapon
[WEAPON_SHOTGUN2
] := True;
4034 if gFlash
= 2 then Inc(FPickup
, 5);
4035 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4038 ITEM_WEAPON_CHAINGUN
:
4039 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
4041 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
4043 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4044 FWeapon
[WEAPON_CHAINGUN
] := True;
4046 if gFlash
= 2 then Inc(FPickup
, 5);
4047 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4050 ITEM_WEAPON_ROCKETLAUNCHER
:
4051 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
4053 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
4055 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
4056 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
4058 if gFlash
= 2 then Inc(FPickup
, 5);
4059 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4063 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
4065 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
4067 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4068 FWeapon
[WEAPON_PLASMA
] := True;
4070 if gFlash
= 2 then Inc(FPickup
, 5);
4071 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4075 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
4077 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
4079 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4080 FWeapon
[WEAPON_BFG
] := True;
4082 if gFlash
= 2 then Inc(FPickup
, 5);
4083 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4086 ITEM_WEAPON_SUPERPULEMET
:
4087 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
4089 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
4091 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4092 FWeapon
[WEAPON_SUPERPULEMET
] := True;
4094 if gFlash
= 2 then Inc(FPickup
, 5);
4095 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4098 ITEM_WEAPON_FLAMETHROWER
:
4099 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
4101 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
4103 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4104 FWeapon
[WEAPON_FLAMETHROWER
] := True;
4106 if gFlash
= 2 then Inc(FPickup
, 5);
4107 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4111 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4113 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4116 if gFlash
= 2 then Inc(FPickup
, 5);
4119 ITEM_AMMO_BULLETS_BOX
:
4120 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4122 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4125 if gFlash
= 2 then Inc(FPickup
, 5);
4129 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4131 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4134 if gFlash
= 2 then Inc(FPickup
, 5);
4137 ITEM_AMMO_SHELLS_BOX
:
4138 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4140 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
4143 if gFlash
= 2 then Inc(FPickup
, 5);
4147 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4149 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4152 if gFlash
= 2 then Inc(FPickup
, 5);
4155 ITEM_AMMO_ROCKET_BOX
:
4156 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4158 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
4161 if gFlash
= 2 then Inc(FPickup
, 5);
4165 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4167 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4170 if gFlash
= 2 then Inc(FPickup
, 5);
4174 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4176 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4179 if gFlash
= 2 then Inc(FPickup
, 5);
4183 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4185 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4188 if gFlash
= 2 then Inc(FPickup
, 5);
4192 if not(R_ITEM_BACKPACK
in FRulez
) or
4193 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4194 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4195 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4196 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4197 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
4199 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4200 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4201 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4202 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4203 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4205 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4206 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4207 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4208 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4209 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4210 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4211 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4212 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4214 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
4217 if gFlash
= 2 then Inc(FPickup
, 5);
4221 if not(R_KEY_RED
in FRulez
) then
4223 Include(FRulez
, R_KEY_RED
);
4225 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4226 if gFlash
= 2 then Inc(FPickup
, 5);
4227 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4231 if not(R_KEY_GREEN
in FRulez
) then
4233 Include(FRulez
, R_KEY_GREEN
);
4235 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4236 if gFlash
= 2 then Inc(FPickup
, 5);
4237 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4241 if not(R_KEY_BLUE
in FRulez
) then
4243 Include(FRulez
, R_KEY_BLUE
);
4245 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4246 if gFlash
= 2 then Inc(FPickup
, 5);
4247 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4251 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4253 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4257 if gFlash
= 2 then Inc(FPickup
, 5);
4261 if FAir
< AIR_MAX
then
4266 if gFlash
= 2 then Inc(FPickup
, 5);
4271 if not (R_BERSERK
in FRulez
) then
4273 Include(FRulez
, R_BERSERK
);
4274 if allowBerserkSwitching
then
4276 CurrWeap
:= WEAPON_KASTET
;
4278 FModel
.SetWeapon(WEAPON_KASTET
);
4283 if gFlash
= 2 then Inc(FPickup
, 5);
4285 FBerserk
:= gTime
+30000;
4289 //k8:do we need it? if g_Game_IsNet and g_Game_IsServer then MH_SEND_PlayerStats(FUID);
4291 if FHealth
< PLAYER_HP_SOFT
then
4293 FHealth
:= PLAYER_HP_SOFT
;
4294 FBerserk
:= gTime
+30000;
4302 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4304 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4307 if gFlash
= 2 then Inc(FPickup
, 5);
4311 if FHealth
< PLAYER_HP_LIMIT
then
4313 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4317 if gFlash
= 2 then Inc(FPickup
, 5);
4321 if FArmor
< PLAYER_AP_LIMIT
then
4323 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4326 if gFlash
= 2 then Inc(FPickup
, 5);
4330 if FJetFuel
< JET_MAX
then
4332 FJetFuel
:= JET_MAX
;
4335 if gFlash
= 2 then Inc(FPickup
, 5);
4339 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4341 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4344 if gFlash
= 2 then Inc(FPickup
, 5);
4349 procedure TPlayer
.Touch();
4353 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4356 // Áðîñèòü ôëàã òîâàðèùó:
4357 if gGameSettings
.GameMode
= GM_CTF
then
4362 procedure TPlayer
.Push(vx
, vy
: Integer);
4364 if (not FPhysics
) and FGhost
then
4366 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4367 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4368 if g_Game_IsNet
and g_Game_IsServer
then
4369 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4372 procedure TPlayer
.Reset(Force
: Boolean);
4380 FTime
[T_RESPAWN
] := 0;
4381 FTime
[T_FLAGCAP
] := 0;
4392 if g_Game_IsClient
then FNetWeapCtr
:= 0 else Inc(FNetWeapCtr
, 2);
4396 FSpectator
:= False;
4399 FSpectatePlayer
:= -1;
4400 FNoRespawn
:= False;
4402 FLives
:= gGameSettings
.MaxLives
;
4404 FBFGFireCounter
:= -1;
4405 FTime
[T_SWITCH
] := 0;
4406 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := 0;
4411 procedure TPlayer
.SoftReset();
4419 FBFGFireCounter
:= -1;
4425 if g_Game_IsClient
then FNetWeapCtr
:= 0 else Inc(FNetWeapCtr
, 2);
4428 FBFGFireCounter
:= -1;
4429 FTime
[T_SWITCH
] := 0;
4430 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := 0;
4433 SetAction(A_STAND
, True);
4436 function TPlayer
.GetRespawnPoint(): Byte;
4441 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4443 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4444 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4446 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4448 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4449 if Self
= gPlayer1
then
4450 c
:= RESPAWNPOINT_PLAYER1
4452 c
:= RESPAWNPOINT_PLAYER2
;
4453 if g_Map_GetPointCount(c
) > 0 then
4459 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4460 if Self
= gPlayer1
then
4461 c
:= RESPAWNPOINT_PLAYER2
4463 c
:= RESPAWNPOINT_PLAYER1
;
4464 if g_Map_GetPointCount(c
) > 0 then
4471 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4472 if Random(2) = 0 then
4473 c
:= RESPAWNPOINT_PLAYER1
4475 c
:= RESPAWNPOINT_PLAYER2
;
4476 if g_Map_GetPointCount(c
) > 0 then
4483 // Òî÷êà ëþáîé èç êîìàíä
4484 if Random(2) = 0 then
4485 c
:= RESPAWNPOINT_RED
4487 c
:= RESPAWNPOINT_BLUE
;
4488 if g_Map_GetPointCount(c
) > 0 then
4495 c
:= RESPAWNPOINT_DM
;
4496 if g_Map_GetPointCount(c
) > 0 then
4504 if gGameSettings
.GameMode
= GM_DM
then
4507 c
:= RESPAWNPOINT_DM
;
4508 if g_Map_GetPointCount(c
) > 0 then
4514 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4515 if Random(2) = 0 then
4516 c
:= RESPAWNPOINT_PLAYER1
4518 c
:= RESPAWNPOINT_PLAYER2
;
4519 if g_Map_GetPointCount(c
) > 0 then
4525 // Òî÷êà ëþáîé èç êîìàíä
4526 if Random(2) = 0 then
4527 c
:= RESPAWNPOINT_RED
4529 c
:= RESPAWNPOINT_BLUE
;
4530 if g_Map_GetPointCount(c
) > 0 then
4538 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4540 // Òî÷êà ñâîåé êîìàíäû
4541 c
:= RESPAWNPOINT_DM
;
4542 if FTeam
= TEAM_RED
then
4543 c
:= RESPAWNPOINT_RED
;
4544 if FTeam
= TEAM_BLUE
then
4545 c
:= RESPAWNPOINT_BLUE
;
4546 if g_Map_GetPointCount(c
) > 0 then
4553 c
:= RESPAWNPOINT_DM
;
4554 if g_Map_GetPointCount(c
) > 0 then
4560 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4561 if Random(2) = 0 then
4562 c
:= RESPAWNPOINT_PLAYER1
4564 c
:= RESPAWNPOINT_PLAYER2
;
4565 if g_Map_GetPointCount(c
) > 0 then
4571 // Òî÷êà äðóãîé êîìàíäû
4572 c
:= RESPAWNPOINT_DM
;
4573 if FTeam
= TEAM_RED
then
4574 c
:= RESPAWNPOINT_BLUE
;
4575 if FTeam
= TEAM_BLUE
then
4576 c
:= RESPAWNPOINT_RED
;
4577 if g_Map_GetPointCount(c
) > 0 then
4585 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4587 RespawnPoint
: TRespawnPoint
;
4594 FBFGFireCounter
:= -1;
4598 if g_Game_IsClient
then FNetWeapCtr
:= 0 else Inc(FNetWeapCtr
, 2);
4601 FBFGFireCounter
:= -1;
4602 FTime
[T_SWITCH
] := 0;
4603 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := 0;
4605 if not g_Game_IsServer
then
4609 FWantsInGame
:= True;
4610 FJustTeleported
:= True;
4613 FTime
[T_RESPAWN
] := 0;
4617 // if server changes MaxLives we gotta be ready
4618 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4620 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4621 if FTime
[T_RESPAWN
] > gTime
then
4624 // Ïðîñðàë âñå æèçíè:
4627 if not FSpectator
then Spectate(True);
4628 FWantsInGame
:= True;
4632 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4633 begin // "Ñâîÿ èãðà"
4634 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4635 FRulez
:= FRulez
-[R_BERSERK
];
4637 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4639 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4640 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4643 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4644 c
:= GetRespawnPoint();
4649 // Âîñêðåøåíèå áåç îðóæèÿ:
4652 FHealth
:= PLAYER_HP_SOFT
;
4658 for a
:= WP_FIRST
to WP_LAST
do
4660 FWeapon
[a
] := False;
4664 FWeapon
[WEAPON_PISTOL
] := True;
4665 FWeapon
[WEAPON_KASTET
] := True;
4666 CurrWeap
:= WEAPON_PISTOL
;
4667 if g_Game_IsClient
then FNetWeapCtr
:= 0 else Inc(FNetWeapCtr
, 2);
4670 for b
:= A_BULLETS
to A_HIGH
do
4673 FAmmo
[A_BULLETS
] := 50;
4675 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4676 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4677 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4678 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4679 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4681 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4682 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4687 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4688 if not g_Map_GetPoint(c
, RespawnPoint
) then
4690 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4694 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4695 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4696 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4702 FDirection
:= RespawnPoint
.Direction
;
4703 if FDirection
= TDirection
.D_LEFT
then
4708 SetAction(A_STAND
, True);
4709 FModel
.Direction
:= FDirection
;
4711 for a
:= Low(FTime
) to High(FTime
) do
4714 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4719 FCanJetpack
:= False;
4724 // Àíèìàöèÿ âîçðîæäåíèÿ:
4725 if (not gLoadGameMode
) and (not Silent
) then
4726 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4728 Anim
:= TAnimation
.Create(ID
, False, 3);
4729 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4730 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4734 FSpectator
:= False;
4737 FSpectatePlayer
:= -1;
4740 if (gPlayer1
= nil) and (gLMSPID1
= FUID
) then
4742 if (gPlayer2
= nil) and (gLMSPID2
= FUID
) then
4745 if g_Game_IsNet
then
4747 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4748 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4750 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4751 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4756 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4759 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4760 else if (not NoMove
) then
4762 GameX
:= gMapInfo
.Width
div 2;
4763 GameY
:= gMapInfo
.Height
div 2;
4772 FWantsInGame
:= False;
4777 if Self
= gPlayer1
then
4782 if Self
= gPlayer2
then
4789 if g_Game_IsNet
then
4790 MH_SEND_PlayerStats(FUID
);
4793 procedure TPlayer
.SwitchNoClip
;
4797 FGhost
:= not FGhost
;
4798 FPhysics
:= not FGhost
;
4810 procedure TPlayer
.Run(Direction
: TDirection
);
4814 if MAX_RUNVEL
> 8 then
4818 if Direction
= TDirection
.D_LEFT
then
4820 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4821 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4824 if FObj
.Vel
.X
< MAX_RUNVEL
then
4825 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4827 // Âîçìîæíî, ïèíàåì êóñêè:
4828 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4830 b
:= Abs(FObj
.Vel
.X
);
4831 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4832 for a
:= 0 to High(gGibs
) do
4834 if gGibs
[a
].alive
and
4835 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4836 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4839 if FObj
.Vel
.X
< 0 then
4841 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4845 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4847 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4855 procedure TPlayer
.SeeDown();
4857 SetAction(A_SEEDOWN
);
4859 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4861 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4864 procedure TPlayer
.SeeUp();
4868 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4870 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4873 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4881 A_ATTACK
: Prior
:= 2;
4882 A_SEEUP
: Prior
:= 1;
4883 A_SEEDOWN
: Prior
:= 1;
4884 A_ATTACKUP
: Prior
:= 2;
4885 A_ATTACKDOWN
: Prior
:= 2;
4890 if (Prior
> FActionPrior
) or Force
then
4891 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4893 FActionPrior
:= Prior
;
4894 FActionAnim
:= Action
;
4895 FActionForce
:= Force
;
4896 FActionChanged
:= True;
4899 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4902 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4904 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4905 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4906 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4907 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4910 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4917 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4919 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4920 if g_Game_IsServer
and g_Game_IsNet
then
4921 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4925 FJustTeleported
:= True;
4930 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4932 Anim
:= TAnimation
.Create(ID
, False, 3);
4935 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4936 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4937 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4938 if g_Game_IsServer
and g_Game_IsNet
then
4939 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4940 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4944 FObj
.X
:= X
-PLAYER_RECT
.X
;
4945 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4946 if FAlive
and FGhost
then
4952 if not g_Game_IsNet
then
4956 SetDirection(TDirection
.D_LEFT
);
4962 SetDirection(TDirection
.D_RIGHT
);
4968 if FDirection
= TDirection
.D_RIGHT
then
4970 SetDirection(TDirection
.D_LEFT
);
4975 SetDirection(TDirection
.D_RIGHT
);
4981 if not silent
and (Anim
<> nil) then
4983 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4984 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4987 if g_Game_IsServer
and g_Game_IsNet
then
4988 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4989 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4996 function nonz(a
: Single): Single;
5004 function TPlayer
.followCorpse(): Boolean;
5009 if FAlive
or FSpectator
then
5011 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
5013 for i
:= 0 to High(gCorpses
) do
5014 if gCorpses
[i
] <> nil then
5015 if gCorpses
[i
].FPlayerUID
= FUID
then
5018 FObj
.X
:= gCorpses
[i
].FObj
.X
;
5019 FObj
.Y
:= gCorpses
[i
].FObj
.Y
;
5020 FObj
.Vel
.X
:= gCorpses
[i
].FObj
.Vel
.X
;
5021 FObj
.Vel
.Y
:= gCorpses
[i
].FObj
.Vel
.Y
;
5022 FObj
.Accel
.X
:= gCorpses
[i
].FObj
.Accel
.X
;
5023 FObj
.Accel
.Y
:= gCorpses
[i
].FObj
.Accel
.Y
;
5028 procedure TPlayer
.Update();
5031 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
5032 blockmon
, headwater
, dospawn
: Boolean;
5037 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
5038 AnyServer
:= g_Game_IsServer
;
5040 if g_Game_IsClient
and (NetInterpLevel
> 0) then
5041 DoLerp(NetInterpLevel
+ 1)
5048 if FClientID
>= 0 then
5050 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
5051 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
5052 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
5062 if FAlive
and (FPunchAnim
<> nil) then
5063 FPunchAnim
.Update();
5065 if FAlive
and (gFly
or FJetpack
) then
5068 if FDirection
= TDirection
.D_LEFT
then
5073 if FAlive
and (not FGhost
) then
5075 if FKeys
[KEY_UP
].Pressed
then
5077 if FKeys
[KEY_DOWN
].Pressed
then
5081 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
5084 i
:= g_basic
.Sign(FIncCam
);
5085 FIncCam
:= Abs(FIncCam
);
5086 DecMin(FIncCam
, 5, 0);
5087 FIncCam
:= FIncCam
*i
;
5090 // no need to do that each second frame, weapon queue will take care of it
5091 if FAlive
and FKeys
[KEY_NEXTWEAPON
].Pressed
{and AnyServer} then NextWeapon();
5092 if FAlive
and FKeys
[KEY_PREVWEAPON
].Pressed
{and AnyServer} then PrevWeapon();
5094 if gTime
mod (GAME_TICK
*2) <> 0 then
5096 if (FObj
.Vel
.X
= 0) and FAlive
then
5098 if FKeys
[KEY_LEFT
].Pressed
then
5099 Run(TDirection
.D_LEFT
);
5100 if FKeys
[KEY_RIGHT
].Pressed
then
5101 Run(TDirection
.D_RIGHT
);
5106 if not followCorpse() then
5107 g_Obj_Move(@FObj
, True, True, True);
5108 positionChanged(); // this updates spatial accelerators
5114 FActionChanged
:= False;
5118 // Let alive player do some actions
5119 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
5120 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
5121 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
5122 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
5123 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
5124 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
5125 if FKeys
[KEY_JUMP
].Pressed
then Jump()
5128 if AnyServer
and FJetpack
then
5132 if NetServer
then MH_SEND_PlayerStats(FUID
);
5134 FCanJetpack
:= True;
5141 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
5143 if FKeys
[k
].Pressed
then
5151 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5154 if (FTime
[T_RESPAWN
] <= gTime
) and
5155 gGameOn
and (not FAlive
) then
5157 if (g_Player_GetCount() > 1) then
5161 gExit
:= EXIT_RESTART
;
5166 // Dead spectator actions
5169 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
5170 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
5174 if (FSpectatePlayer
>= High(gPlayers
)) then
5175 FSpectatePlayer
:= -1
5179 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
5180 if gPlayers
[I
] <> nil then
5181 if gPlayers
[I
].alive
then
5182 if gPlayers
[I
].UID
<> FUID
then
5184 FSpectatePlayer
:= I
;
5189 if not SetSpect
then FSpectatePlayer
:= -1;
5200 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5202 FYTo
:= FObj
.Y
- 32;
5203 FSpectatePlayer
:= -1;
5205 if FKeys
[KEY_DOWN
].Pressed
then
5207 FYTo
:= FObj
.Y
+ 32;
5208 FSpectatePlayer
:= -1;
5210 if FKeys
[KEY_LEFT
].Pressed
then
5212 FXTo
:= FObj
.X
- 32;
5213 FSpectatePlayer
:= -1;
5215 if FKeys
[KEY_RIGHT
].Pressed
then
5217 FXTo
:= FObj
.X
+ 32;
5218 FSpectatePlayer
:= -1;
5221 if (FXTo
< -64) then
5223 else if (FXTo
> gMapInfo
.Width
+ 32) then
5224 FXTo
:= gMapInfo
.Width
+ 32;
5225 if (FYTo
< -72) then
5227 else if (FYTo
> gMapInfo
.Height
+ 32) then
5228 FYTo
:= gMapInfo
.Height
+ 32;
5233 if not followCorpse() then
5234 g_Obj_Move(@FObj
, True, True, True);
5235 positionChanged(); // this updates spatial accelerators
5242 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5243 if gPlayers
[FSpectatePlayer
] <> nil then
5244 if gPlayers
[FSpectatePlayer
].alive
then
5246 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
5247 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
5251 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5252 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5253 PANEL_BLOCKMON
, True);
5254 headwater
:= HeadInLiquid(0, 0);
5256 // Ñîïðîòèâëåíèå âîçäóõà:
5257 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5258 if FObj
.Vel
.X
<> 0 then
5259 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5261 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5262 DecMin(FPain
, 5, 0);
5263 DecMin(FPickup
, 1, 0);
5265 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5267 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5268 FMegaRulez
[MR_SUIT
] := 0;
5269 FMegaRulez
[MR_INVUL
] := 0;
5270 FMegaRulez
[MR_INVIS
] := 0;
5271 Kill(K_FALLKILL
, 0, HIT_FALL
);
5278 if FCurrWeap
= WEAPON_SAW
then
5279 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5280 FSawSoundSelect
.IsPlaying()) then
5281 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5284 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5285 (not FJetSoundOff
.IsPlaying()) then
5287 FJetSoundFly
.SetPosition(0);
5288 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5291 for b
:= WP_FIRST
to WP_LAST
do
5292 if FReloading
[b
] > 0 then
5298 if FShellTimer
> -1 then
5299 if FShellTimer
= 0 then
5301 if FShellType
= SHELL_SHELL
then
5302 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5303 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5304 else if FShellType
= SHELL_DBLSHELL
then
5306 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5307 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5308 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5309 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5312 end else Dec(FShellTimer
);
5314 if (FBFGFireCounter
> -1) then
5315 if FBFGFireCounter
= 0 then
5319 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5320 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5321 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5322 yd
:= wy
+firediry();
5323 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5324 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5325 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5326 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5327 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5330 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5331 FBFGFireCounter
:= -1;
5334 FBFGFireCounter
:= 0
5336 Dec(FBFGFireCounter
);
5338 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5340 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5342 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5345 if (headwater
or blockmon
) then
5351 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5354 else if (FAir
mod 31 = 0) and not blockmon
then
5356 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5357 if Random(2) = 0 then
5358 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5360 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5362 end else if FAir
< AIR_DEF
then
5365 if FFireTime
> 0 then
5367 if BodyInLiquid(0, 0) then
5372 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5374 if FMegaRulez
[MR_SUIT
] = gTime
then
5381 if FFirePainTime
<= 0 then
5383 if g_Game_IsServer
then
5384 Damage(5, FFireAttacker
, 0, 0, HIT_FLAME
);
5385 FFirePainTime
:= 18;
5387 FFirePainTime
:= FFirePainTime
- 1;
5388 FFireTime
:= FFireTime
- 1;
5389 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5390 MH_SEND_PlayerStats(FUID
);
5394 if FDamageBuffer
> 0 then
5396 if FDamageBuffer
>= 9 then
5400 if FDamageBuffer
< 30 then i
:= 9
5401 else if FDamageBuffer
< 100 then i
:= 18
5405 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5406 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5407 FHealth
:= FHealth
-ii
;
5410 FHealth
:= FHealth
+FArmor
;
5415 if FHealth
<= 0 then
5416 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5417 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5418 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5422 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5423 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5424 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5425 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5432 end; // if FAlive then ...
5434 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5436 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5437 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5438 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5439 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5441 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5442 then SetAction(A_STAND
, True);
5444 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5446 for b
:= Low(FKeys
) to High(FKeys
) do
5447 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5451 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5453 x
:= FObj
.X
+PLAYER_RECT
.X
;
5454 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5455 w
:= PLAYER_RECT
.Width
;
5456 h
:= PLAYER_RECT
.Height
;
5460 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5462 if (dx
<> 0) or (dy
<> 0) then
5471 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5473 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5474 FObj
.Y
+PLAYER_RECT
.Y
,
5481 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5483 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5484 FObj
.Y
+PLAYER_RECT
.Y
,
5488 Panel
.Width
, Panel
.Height
);
5491 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5493 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5494 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5495 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5496 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5499 function g_Player_ValidName(Name
: string): Boolean;
5505 if gPlayers
= nil then Exit
;
5507 for a
:= 0 to High(gPlayers
) do
5508 if gPlayers
[a
] <> nil then
5509 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5516 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5520 d
:= FModel
.Direction
;
5522 FModel
.Direction
:= Direction
;
5523 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5525 FDirection
:= Direction
;
5528 function TPlayer
.GetKeys(): Byte;
5532 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5533 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5534 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5536 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5537 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5540 procedure TPlayer
.Use();
5544 if FTime
[T_USE
] > gTime
then Exit
;
5546 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5547 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5549 for a
:= 0 to High(gPlayers
) do
5550 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5551 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5552 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5553 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5555 gPlayers
[a
].Touch();
5556 if g_Game_IsNet
and g_Game_IsServer
then
5557 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5560 FTime
[T_USE
] := gTime
+120;
5563 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5567 WX
, WY
, XD
, YD
: Integer;
5579 if R_BERSERK
in FRulez
then
5581 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5582 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5583 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5586 locobj
.rect
.Width
:= 39;
5587 locobj
.rect
.Height
:= 52;
5588 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5589 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5590 locobj
.Accel
.X
:= xd
-wx
;
5591 locobj
.Accel
.y
:= yd
-wy
;
5593 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5594 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5596 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5600 FPain
:= min(FPain
+ 25, 50);
5602 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5607 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5608 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5610 FSawSoundSelect
.Stop();
5612 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5614 else if not FSawSoundHit
.IsPlaying() then
5616 FSawSoundSelect
.Stop();
5617 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5624 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5625 FFireAngle
:= FAngle
;
5627 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5628 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5633 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5634 FFireAngle
:= FAngle
;
5637 FShellType
:= SHELL_SHELL
;
5642 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5643 FFireAngle
:= FAngle
;
5646 FShellType
:= SHELL_DBLSHELL
;
5651 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5652 FFireAngle
:= FAngle
;
5654 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5655 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5658 WEAPON_ROCKETLAUNCHER
:
5660 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5661 FFireAngle
:= FAngle
;
5667 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5668 FFireAngle
:= FAngle
;
5674 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5675 FFireAngle
:= FAngle
;
5679 WEAPON_SUPERPULEMET
:
5681 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5682 FFireAngle
:= FAngle
;
5684 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5685 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5688 WEAPON_FLAMETHROWER
:
5690 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5691 FFireAngle
:= FAngle
;
5698 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5699 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5700 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5703 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5705 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5706 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5709 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5713 if NetInterpLevel
< 1 then
5723 AX
:= Abs(FXTo
- FObj
.X
);
5724 AY
:= Abs(FYTo
- FObj
.Y
);
5725 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5727 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5732 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5734 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5735 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5736 PANEL_LIFTUP
, False) then Result
:= -1
5738 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5739 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5740 PANEL_LIFTDOWN
, False) then Result
:= 1
5744 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5751 if Flag
= FLAG_NONE
then
5754 if not g_Game_IsServer
then Exit
;
5756 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5757 if (Flag
= FTeam
) and
5758 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5759 (FFlag
<> FLAG_NONE
) then
5761 if FFlag
= FLAG_RED
then
5762 s
:= _lc
[I_PLAYER_FLAG_RED
]
5764 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5766 evtype
:= FLAG_STATE_SCORED
;
5768 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5769 Insert('.', ts
, Length(ts
) + 1 - 3);
5770 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5772 g_Map_ResetFlag(FFlag
);
5773 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5775 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5778 if g_Game_IsNet
then
5780 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5784 gFlags
[FFlag
].CaptureTime
:= 0;
5789 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5790 if (Flag
= FTeam
) and
5791 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5793 if Flag
= FLAG_RED
then
5794 s
:= _lc
[I_PLAYER_FLAG_RED
]
5796 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5798 evtype
:= FLAG_STATE_RETURNED
;
5799 gFlags
[Flag
].CaptureTime
:= 0;
5801 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5803 g_Map_ResetFlag(Flag
);
5804 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5807 if g_Game_IsNet
then
5809 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5815 // Ïîäîáðàë ÷óæîé ôëàã:
5816 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5820 if Flag
= FLAG_RED
then
5821 s
:= _lc
[I_PLAYER_FLAG_RED
]
5823 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5825 evtype
:= FLAG_STATE_CAPTURED
;
5827 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5829 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5831 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5834 if g_Game_IsNet
then
5836 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5842 procedure TPlayer
.SetFlag(Flag
: Byte);
5845 if FModel
<> nil then
5846 FModel
.SetFlag(FFlag
);
5849 function TPlayer
.DropFlag(): Boolean;
5854 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5856 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5857 with gFlags
[FFlag
] do
5861 Direction
:= FDirection
;
5862 State
:= FLAG_STATE_DROPPED
;
5864 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5865 (FObj
.Vel
.Y
div 2)-2+Random(5));
5866 positionChanged(); // this updates spatial accelerators
5868 if FFlag
= FLAG_RED
then
5869 s
:= _lc
[I_PLAYER_FLAG_RED
]
5871 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5873 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5874 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5876 if g_Game_IsNet
then
5877 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5883 procedure TPlayer
.GetSecret();
5888 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5890 Assert(Key
<= High(FKeys
));
5892 FKeys
[Key
].Pressed
:= True;
5893 FKeys
[Key
].Time
:= Time
;
5896 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5898 Result
:= FKeys
[K
].Pressed
;
5901 procedure TPlayer
.ReleaseKeys();
5905 for a
:= Low(FKeys
) to High(FKeys
) do
5907 FKeys
[a
].Pressed
:= False;
5912 procedure TPlayer
.ReleaseKeysNoWeapon();
5916 for a
:= Low(FKeys
) to High(FKeys
) do
5918 if (a
= KEY_PREVWEAPON
) or (a
= KEY_NEXTWEAPON
) then continue
;
5919 FKeys
[a
].Pressed
:= False;
5924 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5928 function TPlayer
.firediry(): Integer;
5930 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5931 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5935 procedure TPlayer
.RememberState();
5939 FSavedState
.Health
:= FHealth
;
5940 FSavedState
.Armor
:= FArmor
;
5941 FSavedState
.Air
:= FAir
;
5942 FSavedState
.JetFuel
:= FJetFuel
;
5943 FSavedState
.CurrWeap
:= FCurrWeap
;
5944 FSavedState
.NextWeap
:= FNextWeap
;
5945 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5948 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5950 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5952 FSavedState
.Rulez
:= FRulez
;
5953 FSavedState
.WaitRecall
:= True;
5956 procedure TPlayer
.RecallState();
5960 if not FSavedState
.WaitRecall
then Exit
;
5962 FHealth
:= FSavedState
.Health
;
5963 FArmor
:= FSavedState
.Armor
;
5964 FAir
:= FSavedState
.Air
;
5965 FJetFuel
:= FSavedState
.JetFuel
;
5966 FCurrWeap
:= FSavedState
.CurrWeap
;
5967 FModel
.SetWeapon(FCurrWeap
);
5968 FNextWeap
:= FSavedState
.NextWeap
;
5969 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5972 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5974 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5976 FRulez
:= FSavedState
.Rulez
;
5977 FSavedState
.WaitRecall
:= False;
5979 if gGameSettings
.GameType
= GT_SERVER
then
5980 MH_SEND_PlayerStats(FUID
);
5983 procedure TPlayer
.SaveState (st
: TStream
);
5989 utils
.writeSign(st
, 'PLYR');
5990 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
5992 utils
.writeBool(st
, FIamBot
);
5994 utils
.writeInt(st
, Word(FUID
));
5996 utils
.writeStr(st
, FName
);
5998 utils
.writeInt(st
, Byte(FTeam
));
6000 utils
.writeBool(st
, FAlive
);
6001 // Èçðàñõîäîâàë ëè âñå æèçíè
6002 utils
.writeBool(st
, FNoRespawn
);
6004 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
6005 utils
.writeInt(st
, Byte(b
));
6007 utils
.writeInt(st
, LongInt(FHealth
));
6009 utils
.writeInt(st
, Byte(FLives
));
6011 utils
.writeInt(st
, LongInt(FArmor
));
6013 utils
.writeInt(st
, LongInt(FAir
));
6015 utils
.writeInt(st
, LongInt(FJetFuel
));
6017 utils
.writeInt(st
, LongInt(FPain
));
6019 utils
.writeInt(st
, LongInt(FKills
));
6021 utils
.writeInt(st
, LongInt(FMonsterKills
));
6023 utils
.writeInt(st
, LongInt(FFrags
));
6025 utils
.writeInt(st
, Byte(FFragCombo
));
6026 // Âðåìÿ ïîñëåäíåãî ôðàãà
6027 utils
.writeInt(st
, LongWord(FLastFrag
));
6029 utils
.writeInt(st
, LongInt(FDeath
));
6031 utils
.writeInt(st
, Byte(FFlag
));
6033 utils
.writeInt(st
, LongInt(FSecrets
));
6035 utils
.writeInt(st
, Byte(FCurrWeap
));
6037 utils
.writeInt(st
, Word(FNextWeap
));
6039 utils
.writeInt(st
, Byte(FNextWeapDelay
));
6040 // Âðåìÿ çàðÿäêè BFG
6041 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
6043 utils
.writeInt(st
, LongInt(FDamageBuffer
));
6044 // Ïîñëåäíèé óäàðèâøèé
6045 utils
.writeInt(st
, Word(FLastSpawnerUID
));
6046 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6047 utils
.writeInt(st
, Byte(FLastHit
));
6049 Obj_SaveState(st
, @FObj
);
6050 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6051 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
6052 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6053 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
6055 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
6056 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6057 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
6059 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
6060 // Íàëè÷èå êðàñíîãî êëþ÷à
6061 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
6062 // Íàëè÷èå çåëåíîãî êëþ÷à
6063 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
6064 // Íàëè÷èå ñèíåãî êëþ÷à
6065 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
6067 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
6068 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6069 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
6070 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6071 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
6073 utils
.writeStr(st
, FModel
.Name
);
6075 utils
.writeInt(st
, Byte(FColor
.R
));
6076 utils
.writeInt(st
, Byte(FColor
.G
));
6077 utils
.writeInt(st
, Byte(FColor
.B
));
6081 procedure TPlayer
.LoadState (st
: TStream
);
6090 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
6091 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
6093 FIamBot
:= utils
.readBool(st
);
6095 FUID
:= utils
.readWord(st
);
6097 str
:= utils
.readStr(st
);
6098 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
6100 FTeam
:= utils
.readByte(st
);
6102 FAlive
:= utils
.readBool(st
);
6103 // Èçðàñõîäîâàë ëè âñå æèçíè
6104 FNoRespawn
:= utils
.readBool(st
);
6106 b
:= utils
.readByte(st
);
6107 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
6109 FHealth
:= utils
.readLongInt(st
);
6111 FLives
:= utils
.readByte(st
);
6113 FArmor
:= utils
.readLongInt(st
);
6115 FAir
:= utils
.readLongInt(st
);
6117 FJetFuel
:= utils
.readLongInt(st
);
6119 FPain
:= utils
.readLongInt(st
);
6121 FKills
:= utils
.readLongInt(st
);
6123 FMonsterKills
:= utils
.readLongInt(st
);
6125 FFrags
:= utils
.readLongInt(st
);
6127 FFragCombo
:= utils
.readByte(st
);
6128 // Âðåìÿ ïîñëåäíåãî ôðàãà
6129 FLastFrag
:= utils
.readLongWord(st
);
6131 FDeath
:= utils
.readLongInt(st
);
6133 FFlag
:= utils
.readByte(st
);
6135 FSecrets
:= utils
.readLongInt(st
);
6137 FCurrWeap
:= utils
.readByte(st
);
6138 if not g_Game_IsClient
then Inc(FNetWeapCtr
, 2);
6140 FNextWeap
:= utils
.readWord(st
);
6142 FNextWeapDelay
:= utils
.readByte(st
);
6143 // Âðåìÿ çàðÿäêè BFG
6144 FBFGFireCounter
:= utils
.readSmallInt(st
);
6146 FDamageBuffer
:= utils
.readLongInt(st
);
6147 // Ïîñëåäíèé óäàðèâøèé
6148 FLastSpawnerUID
:= utils
.readWord(st
);
6149 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6150 FLastHit
:= utils
.readByte(st
);
6152 Obj_LoadState(@FObj
, st
);
6153 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6154 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
6155 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6156 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
6158 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
6159 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6160 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
6162 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
6163 // Íàëè÷èå êðàñíîãî êëþ÷à
6164 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
6165 // Íàëè÷èå çåëåíîãî êëþ÷à
6166 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
6167 // Íàëè÷èå ñèíåãî êëþ÷à
6168 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
6170 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
6171 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6172 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
6173 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6174 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
6176 str
:= utils
.readStr(st
);
6178 FColor
.R
:= utils
.readByte(st
);
6179 FColor
.G
:= utils
.readByte(st
);
6180 FColor
.B
:= utils
.readByte(st
);
6181 if (self
= gPlayer1
) then
6183 str
:= gPlayer1Settings
.Model
;
6184 FColor
:= gPlayer1Settings
.Color
;
6186 else if (self
= gPlayer2
) then
6188 str
:= gPlayer2Settings
.Model
;
6189 FColor
:= gPlayer2Settings
.Color
;
6191 // Îáíîâëÿåì ìîäåëü èãðîêà
6193 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
6194 FModel
.Color
:= TEAMCOLOR
[FTeam
]
6196 FModel
.Color
:= FColor
;
6200 procedure TPlayer
.AllRulez(Health
: Boolean);
6206 FHealth
:= PLAYER_HP_LIMIT
;
6207 FArmor
:= PLAYER_AP_LIMIT
;
6211 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
6212 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
6213 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6216 procedure TPlayer
.RestoreHealthArmor();
6218 FHealth
:= PLAYER_HP_LIMIT
;
6219 FArmor
:= PLAYER_AP_LIMIT
;
6222 procedure TPlayer
.FragCombo();
6226 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6228 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6230 if FFragCombo
< 5 then
6232 Param
:= FUID
or (FFragCombo
shl 16);
6233 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6234 (FComboEvnt
<= High(gDelayedEvents
)) and
6235 gDelayedEvents
[FComboEvnt
].Pending
and
6236 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6237 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6239 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6240 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6243 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6251 procedure TPlayer
.GiveItem(ItemType
: Byte);
6255 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6257 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6261 if FAir
< AIR_MAX
then
6268 if not (R_BERSERK
in FRulez
) then
6270 Include(FRulez
, R_BERSERK
);
6271 if FBFGFireCounter
< 1 then
6273 CurrWeap
:= WEAPON_KASTET
;
6275 FModel
.SetWeapon(WEAPON_KASTET
);
6279 FBerserk
:= gTime
+30000;
6281 if FHealth
< PLAYER_HP_SOFT
then
6283 FHealth
:= PLAYER_HP_SOFT
;
6284 FBerserk
:= gTime
+30000;
6289 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6291 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6295 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6297 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6301 if FJetFuel
< JET_MAX
then
6303 FJetFuel
:= JET_MAX
;
6306 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6307 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6309 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6310 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6312 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6314 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6316 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6317 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6320 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6321 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6322 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6323 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6324 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6325 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6326 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6327 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6328 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6330 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6331 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6332 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6333 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6334 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6335 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6336 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6337 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6338 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6341 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6342 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6343 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6344 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6345 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6347 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6348 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6349 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6350 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6351 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6353 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6354 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6355 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6356 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6358 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6361 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6362 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6363 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6365 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6366 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6371 if g_Game_IsNet
and g_Game_IsServer
then
6372 MH_SEND_PlayerStats(FUID
);
6375 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6380 if (Random(5) = 1) and (Times
= 1) then
6383 if BodyInLiquid(0, 0) then
6385 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6386 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6387 if Random(2) = 0 then
6388 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6390 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6394 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6396 for i
:= 1 to Times
do
6398 Anim
:= TAnimation
.Create(id
, False, 3);
6400 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6401 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6407 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6412 if (Random(10) = 1) and (Times
= 1) then
6415 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6417 for i
:= 1 to Times
do
6419 Anim
:= TAnimation
.Create(id
, False, 3);
6421 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6422 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6428 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6430 FSawSound
.Pause(Enable
);
6431 FSawSoundIdle
.Pause(Enable
);
6432 FSawSoundHit
.Pause(Enable
);
6433 FSawSoundSelect
.Pause(Enable
);
6438 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6443 FObj
.Rect
:= PLAYER_CORPSERECT
;
6444 FModelName
:= ModelName
;
6449 FState
:= CORPSE_STATE_MESS
;
6450 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6454 FState
:= CORPSE_STATE_NORMAL
;
6455 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6459 destructor TCorpse
.Destroy();
6466 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6468 procedure TCorpse
.positionChanged (); inline; begin end;
6470 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6472 if (dx
<> 0) or (dy
<> 0) then
6481 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6483 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6484 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6485 w
:= PLAYER_CORPSERECT
.Width
;
6486 h
:= PLAYER_CORPSERECT
.Height
;
6490 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6495 if FState
= CORPSE_STATE_REMOVEME
then
6498 FDamage
:= FDamage
+ Value
;
6500 if FDamage
> 150 then
6502 if FAnimation
<> nil then
6507 FState
:= CORPSE_STATE_REMOVEME
;
6509 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6510 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6511 FModelName
, FColor
);
6512 // Çâóê ìÿñà îò òðóïà:
6513 pm
:= g_PlayerModel_Get(FModelName
);
6514 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6518 if (gBodyKillEvent
<> -1)
6519 and gDelayedEvents
[gBodyKillEvent
].Pending
then
6520 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
6521 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, 0);
6526 Blood
:= g_PlayerModel_GetBlood(FModelName
);
6527 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6528 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6529 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6530 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6531 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6532 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
6536 procedure TCorpse
.Draw();
6538 if FState
= CORPSE_STATE_REMOVEME
then
6541 if FAnimation
<> nil then
6542 FAnimation
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6544 if FAnimationMask
<> nil then
6547 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6554 procedure TCorpse
.Update();
6558 if FState
= CORPSE_STATE_REMOVEME
then
6561 if gTime
mod (GAME_TICK
*2) <> 0 then
6563 g_Obj_Move(@FObj
, True, True, True);
6564 positionChanged(); // this updates spatial accelerators
6568 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6569 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6571 st
:= g_Obj_Move(@FObj
, True, True, True);
6572 positionChanged(); // this updates spatial accelerators
6574 if WordBool(st
and MOVE_FALLOUT
) then
6576 FState
:= CORPSE_STATE_REMOVEME
;
6580 if FAnimation
<> nil then
6581 FAnimation
.Update();
6582 if FAnimationMask
<> nil then
6583 FAnimationMask
.Update();
6587 procedure TCorpse
.SaveState (st
: TStream
);
6594 utils
.writeSign(st
, 'CORP');
6595 utils
.writeInt(st
, Byte(0));
6597 utils
.writeInt(st
, Byte(FState
));
6599 utils
.writeInt(st
, Byte(FDamage
));
6601 utils
.writeInt(st
, Byte(FColor
.R
));
6602 utils
.writeInt(st
, Byte(FColor
.G
));
6603 utils
.writeInt(st
, Byte(FColor
.B
));
6605 Obj_SaveState(st
, @FObj
);
6606 utils
.writeInt(st
, Word(FPlayerUID
));
6608 anim
:= (FAnimation
<> nil);
6609 utils
.writeBool(st
, anim
);
6610 // Åñëè åñòü - ñîõðàíÿåì
6611 if anim
then FAnimation
.SaveState(st
);
6612 // Åñòü ëè ìàñêà àíèìàöèè
6613 anim
:= (FAnimationMask
<> nil);
6614 utils
.writeBool(st
, anim
);
6615 // Åñëè åñòü - ñîõðàíÿåì
6616 if anim
then FAnimationMask
.SaveState(st
);
6620 procedure TCorpse
.LoadState (st
: TStream
);
6627 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6628 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6630 FState
:= utils
.readByte(st
);
6632 FDamage
:= utils
.readByte(st
);
6634 FColor
.R
:= utils
.readByte(st
);
6635 FColor
.G
:= utils
.readByte(st
);
6636 FColor
.B
:= utils
.readByte(st
);
6638 Obj_LoadState(@FObj
, st
);
6639 FPlayerUID
:= utils
.readWord(st
);
6641 anim
:= utils
.readBool(st
);
6642 // Åñëè åñòü - çàãðóæàåì
6645 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6646 FAnimation
.LoadState(st
);
6648 // Åñòü ëè ìàñêà àíèìàöèè
6649 anim
:= utils
.readBool(st
);
6650 // Åñëè åñòü - çàãðóæàåì
6653 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6654 FAnimationMask
.LoadState(st
);
6660 constructor TBot
.Create();
6667 FSpectator
:= False;
6674 for a
:= WP_FIRST
to WP_LAST
do
6676 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6677 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6678 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6682 destructor TBot
.Destroy();
6685 inherited Destroy();
6688 procedure TBot
.Draw();
6692 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6693 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6696 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6698 inherited Respawn(Silent
, Force
);
6701 FSelectedWeapon
:= FCurrWeap
;
6707 procedure TBot
.UpdateCombat();
6720 TTargetRecord
= array of TTarget
;
6722 function Compare(a
, b
: TTarget
): Integer;
6724 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6727 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6729 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6730 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6732 if a
.Dist
> b
.Dist
then // B áëèæå
6734 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6737 else // Ñòðàííî -> A
6742 a
, x1
, y1
, x2
, y2
: Integer;
6743 targets
: TTargetRecord
;
6745 Target
, BestTarget
: TTarget
;
6746 firew
, fireh
: Integer;
6750 vsPlayer
, vsMonster
, ok
: Boolean;
6753 function monsUpdate (mon
: TMonster
): Boolean;
6755 result
:= false; // don't stop
6756 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6758 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6760 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6761 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6763 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6764 if g_TraceVector(x1
, y1
, x2
, y2
) then
6766 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6767 SetLength(targets
, Length(targets
)+1);
6768 with targets
[High(targets
)] do
6775 Rect
:= mon
.Obj
.Rect
;
6776 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6777 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6778 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6787 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6788 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6790 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6791 if FCurrWeap
<> FSelectedWeapon
then
6794 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6795 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6797 RemoveAIFlag('NEEDFIRE');
6800 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6801 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6802 else PressKey(KEY_FIRE
);
6806 // Êîîðäèíàòû ñòâîëà:
6807 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6808 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6810 Target
.UID
:= FTargetUID
;
6813 if Target
.UID
<> 0 then
6814 begin // Öåëü åñòü - íàñòðàèâàåì
6815 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6818 tpla
:= g_Player_Get(Target
.UID
);
6822 if (@FObj
) <> nil then
6829 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6830 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6831 Target
.Rect
:= PLAYER_RECT
;
6832 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6833 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6834 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6835 Target
.IsPlayer
:= True;
6839 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6842 mon
:= g_Monsters_ByUID(Target
.UID
);
6845 Target
.X
:= mon
.Obj
.X
;
6846 Target
.Y
:= mon
.Obj
.Y
;
6848 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6849 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6850 Target
.Rect
:= mon
.Obj
.Rect
;
6851 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6852 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6853 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6854 Target
.IsPlayer
:= False;
6861 begin // Öåëè íåò - îáíóëÿåì
6866 Target
.Visible
:= False;
6867 Target
.Line
:= False;
6868 Target
.IsPlayer
:= False;
6873 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6874 if (not Target
.Line
) or (not Target
.Visible
) then
6878 for a
:= 0 to High(gPlayers
) do
6879 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6880 (gPlayers
[a
].FUID
<> FUID
) and
6881 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6882 (not gPlayers
[a
].NoTarget
) and
6883 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6885 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6886 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6889 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6890 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6892 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6893 if g_TraceVector(x1
, y1
, x2
, y2
) then
6895 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6896 SetLength(targets
, Length(targets
)+1);
6897 with targets
[High(targets
)] do
6899 UID
:= gPlayers
[a
].FUID
;
6900 X
:= gPlayers
[a
].FObj
.X
;
6901 Y
:= gPlayers
[a
].FObj
.Y
;
6904 Rect
:= PLAYER_RECT
;
6905 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6906 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6907 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6915 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6918 // Åñëè åñòü âîçìîæíûå öåëè:
6919 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6920 if targets
<> nil then
6922 // Âûáèðàåì íàèëó÷øóþ öåëü:
6923 BestTarget
:= targets
[0];
6924 if Length(targets
) > 1 then
6925 for a
:= 1 to High(targets
) do
6926 if Compare(BestTarget
, targets
[a
]) = 1 then
6927 BestTarget
:= targets
[a
];
6929 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6930 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6931 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6933 Target
:= BestTarget
;
6935 if (Healthy() = 3) or ((Healthy() = 2)) then
6936 begin // Åñëè çäîðîâû - äîãîíÿåì
6937 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6938 SetAIFlag('GORIGHT', '1');
6939 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6940 SetAIFlag('GOLEFT', '1');
6943 begin // Åñëè ïîáèòû - óáåãàåì
6944 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6945 SetAIFlag('GORIGHT', '1');
6946 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6947 SetAIFlag('GOLEFT', '1');
6950 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6951 SelectWeapon(Abs(x1
-Target
.cX
));
6956 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6957 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6958 if Target
.UID
<> 0 then
6960 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6961 Target
.Y
+ Target
.Rect
.Y
) then
6962 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6963 if (Healthy() = 3) or ((Healthy() = 2)) then
6964 begin // Åñëè çäîðîâû - äîãîíÿåì
6965 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6966 SetAIFlag('GORIGHT', '1');
6967 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6968 SetAIFlag('GOLEFT', '1');
6971 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6973 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6974 SetAIFlag('GORIGHT', '1');
6975 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6976 SetAIFlag('GOLEFT', '1');
6980 begin // Öåëü ïîêà íà "ýêðàíå"
6981 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6982 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6983 FLastVisible
:= gTime
;
6984 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6985 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6987 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6988 SetAIFlag('GORIGHT', '1');
6989 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6990 SetAIFlag('GOLEFT', '1');
6994 // Âûáèðàåì óãîë ââåðõ:
6995 if FDirection
= TDirection
.D_LEFT
then
6996 angle
:= ANGLE_LEFTUP
6998 angle
:= ANGLE_RIGHTUP
;
7000 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7001 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7003 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7004 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7005 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
7006 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7007 Target
.Rect
.Width
, Target
.Rect
.Height
) and
7008 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7009 begin // òî íóæíî ñòðåëÿòü ââåðõ
7010 SetAIFlag('NEEDFIRE', '1');
7011 SetAIFlag('NEEDSEEUP', '1');
7014 // Âûáèðàåì óãîë âíèç:
7015 if FDirection
= TDirection
.D_LEFT
then
7016 angle
:= ANGLE_LEFTDOWN
7018 angle
:= ANGLE_RIGHTDOWN
;
7020 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7021 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7023 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7024 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7025 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7026 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7027 Target
.Rect
.Width
, Target
.Rect
.Height
) and
7028 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7029 begin // òî íóæíî ñòðåëÿòü âíèç
7030 SetAIFlag('NEEDFIRE', '1');
7031 SetAIFlag('NEEDSEEDOWN', '1');
7034 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
7035 if Target
.Visible
and
7036 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
7037 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
7039 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
7040 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
7041 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
7042 begin // òî íóæíî ñòðåëÿòü âïåðåä
7043 SetAIFlag('NEEDFIRE', '1');
7044 SetAIFlag('NEEDSEEDOWN', '');
7045 SetAIFlag('NEEDSEEUP', '');
7047 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
7048 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
7049 if GetRnd(FDifficult
.CloseJump
) then
7050 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
7051 if Abs(FObj
.X
-Target
.X
) < 128 then
7055 if Random(a
) = 0 then
7056 SetAIFlag('NEEDJUMP', '1');
7060 // Åñëè öåëü âñå åùå åñòü:
7061 if Target
.UID
<> 0 then
7062 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
7063 Target
.UID
:= 0 // òî çàáûòü öåëü
7064 else // Åñëè âèäåëè íåäàâíî
7065 begin // íî öåëü óáèëè
7066 if Target
.IsPlayer
then
7067 begin // Öåëü - èãðîê
7068 pla
:= g_Player_Get(Target
.UID
);
7069 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
7070 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
7071 Target
.UID
:= 0; // òî çàáûòü öåëü
7074 begin // Öåëü - ìîíñòð
7075 mon
:= g_Monsters_ByUID(Target
.UID
);
7076 if (mon
= nil) or (not mon
.alive
) then
7077 Target
.UID
:= 0; // òî çàáûòü öåëü
7080 end; // if Target.UID <> 0
7082 FTargetUID
:= Target
.UID
;
7084 // Åñëè âîçìîæíûõ öåëåé íåò:
7085 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
7086 if targets
= nil then
7087 if GetAIFlag('ATTACKLEFT') <> '' then
7088 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
7089 RemoveAIFlag('ATTACKLEFT');
7091 SetAIFlag('NEEDJUMP', '1');
7093 if RunDirection() = TDirection
.D_RIGHT
then
7094 begin // Èäåì íå â òó ñòîðîíó
7095 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7096 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
7097 SetAIFlag('NEEDFIRE', '1');
7098 SetAIFlag('GOLEFT', '1');
7102 begin // Èäåì â íóæíóþ ñòîðîíó
7103 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7104 SetAIFlag('NEEDFIRE', '1');
7105 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7106 SetAIFlag('GORIGHT', '1');
7110 if GetAIFlag('ATTACKRIGHT') <> '' then
7111 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
7112 RemoveAIFlag('ATTACKRIGHT');
7114 SetAIFlag('NEEDJUMP', '1');
7116 if RunDirection() = TDirection
.D_LEFT
then
7117 begin // Èäåì íå â òó ñòîðîíó
7118 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7119 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
7120 SetAIFlag('NEEDFIRE', '1');
7121 SetAIFlag('GORIGHT', '1');
7126 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7127 SetAIFlag('NEEDFIRE', '1');
7128 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7129 SetAIFlag('GOLEFT', '1');
7133 //HACK! (does it belong there?)
7134 RealizeCurrentWeapon();
7136 // Åñëè åñòü âîçìîæíûå öåëè:
7137 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7138 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7139 for a
:= 0 to High(targets
) do
7141 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7142 if GetRnd(FDifficult
.DiagFire
) then
7144 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7145 if FDirection
= TDirection
.D_LEFT
then
7146 angle
:= ANGLE_LEFTUP
7148 angle
:= ANGLE_RIGHTUP
;
7150 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7151 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7153 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7154 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7155 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7156 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7157 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7159 SetAIFlag('NEEDFIRE', '1');
7160 SetAIFlag('NEEDSEEUP', '1');
7163 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7164 if FDirection
= TDirection
.D_LEFT
then
7165 angle
:= ANGLE_LEFTDOWN
7167 angle
:= ANGLE_RIGHTDOWN
;
7169 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7170 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7172 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7173 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7174 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7175 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7176 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7178 SetAIFlag('NEEDFIRE', '1');
7179 SetAIFlag('NEEDSEEDOWN', '1');
7183 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7184 if targets
[a
].Line
and targets
[a
].Visible
and
7185 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
7186 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
7188 SetAIFlag('NEEDFIRE', '1');
7193 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7194 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
7195 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
7196 40+GetInterval(FDifficult
.Cover
, 40)) then
7197 SetAIFlag('NEEDJUMP', '1');
7199 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7200 ammo
:= GetAmmoByWeapon(FCurrWeap
);
7201 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
7202 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
7204 SetAIFlag('SELECTWEAPON', '1');
7206 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7207 if GetAIFlag('SELECTWEAPON') = '1' then
7210 RemoveAIFlag('SELECTWEAPON');
7214 procedure TBot
.Update();
7227 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7228 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7230 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7232 if g_debug_BotAIOff
= 3 then
7242 RealizeCurrentWeapon();
7249 procedure TBot
.ReleaseKey(Key
: Byte);
7258 function TBot
.KeyPressed(Key
: Word): Boolean;
7260 Result
:= FKeys
[Key
].Pressed
;
7263 function TBot
.GetAIFlag(aName
: String20
): String20
;
7269 aName
:= LowerCase(aName
);
7271 if FAIFlags
<> nil then
7272 for a
:= 0 to High(FAIFlags
) do
7273 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7275 Result
:= FAIFlags
[a
].Value
;
7280 procedure TBot
.RemoveAIFlag(aName
: String20
);
7284 if FAIFlags
= nil then Exit
;
7286 aName
:= LowerCase(aName
);
7288 for a
:= 0 to High(FAIFlags
) do
7289 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7291 if a
<> High(FAIFlags
) then
7292 for b
:= a
to High(FAIFlags
)-1 do
7293 FAIFlags
[b
] := FAIFlags
[b
+1];
7295 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7300 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7308 aName
:= LowerCase(aName
);
7310 if FAIFlags
<> nil then
7311 for a
:= 0 to High(FAIFlags
) do
7312 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7318 if ok
then FAIFlags
[a
].Value
:= fValue
7321 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7322 with FAIFlags
[High(FAIFlags
)] do
7330 procedure TBot
.UpdateMove
;
7332 procedure GoLeft(Time
: Word = 1);
7334 ReleaseKey(KEY_LEFT
);
7335 ReleaseKey(KEY_RIGHT
);
7336 PressKey(KEY_LEFT
, Time
);
7337 SetDirection(TDirection
.D_LEFT
);
7340 procedure GoRight(Time
: Word = 1);
7342 ReleaseKey(KEY_LEFT
);
7343 ReleaseKey(KEY_RIGHT
);
7344 PressKey(KEY_RIGHT
, Time
);
7345 SetDirection(TDirection
.D_RIGHT
);
7348 function Rnd(a
: Word): Boolean;
7350 Result
:= Random(a
) = 0;
7353 procedure Turn(Time
: Word = 1200);
7355 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7360 ReleaseKey(KEY_LEFT
);
7361 ReleaseKey(KEY_RIGHT
);
7364 function CanRunLeft(): Boolean;
7366 Result
:= not CollideLevel(-1, 0);
7369 function CanRunRight(): Boolean;
7371 Result
:= not CollideLevel(1, 0);
7374 function CanRun(): Boolean;
7376 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7379 procedure Jump(Time
: Word = 30);
7381 PressKey(KEY_JUMP
, Time
);
7384 function NearHole(): Boolean;
7388 { TODO 5 : Ëåñòíèöû }
7389 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7390 for x
:= 1 to PLAYER_RECT
.Width
do
7391 if (not StayOnStep(x
*sx
, 0)) and
7392 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7393 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7402 function BorderHole(): Boolean;
7406 { TODO 5 : Ëåñòíèöû }
7407 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7408 for x
:= 1 to PLAYER_RECT
.Width
do
7409 if (not StayOnStep(x
*sx
, 0)) and
7410 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7411 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7413 for xx
:= x
to x
+32 do
7414 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7424 function NearDeepHole(): Boolean;
7430 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7433 for x
:= 1 to PLAYER_RECT
.Width
do
7434 if (not StayOnStep(x
*sx
, 0)) and
7435 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7436 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7438 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7440 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7445 end else Result
:= False;
7448 function OverDeepHole(): Boolean;
7455 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7457 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7464 function OnGround(): Boolean;
7466 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7469 function OnLadder(): Boolean;
7471 Result
:= FullInStep(0, 0);
7474 function BelowLadder(): Boolean;
7476 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7477 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7478 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7479 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7482 function BelowLiftUp(): Boolean;
7484 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7485 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7486 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7487 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7490 function OnTopLift(): Boolean;
7492 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7495 function CanJumpOver(): Boolean;
7499 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7503 if not CollideLevel(sx
, 0) then Exit
;
7505 for y
:= 1 to BOT_MAXJUMP
do
7506 if CollideLevel(0, -y
) then Exit
else
7507 if not CollideLevel(sx
, -y
) then
7514 function CanJumpUp(Dist
: ShortInt): Boolean;
7521 if CollideLevel(Dist
, 0) then Exit
;
7524 for y
:= 0 to BOT_MAXJUMP
do
7525 if CollideLevel(Dist
, -y
) then
7534 for yy
:= y
+1 to BOT_MAXJUMP
do
7535 if not CollideLevel(Dist
, -yy
) then
7544 for y
:= 0 to BOT_MAXJUMP
do
7545 if CollideLevel(0, -y
) then
7553 if y
< yy
then Exit
;
7558 function IsSafeTrigger(): Boolean;
7563 if gTriggers
= nil then
7565 for a
:= 0 to High(gTriggers
) do
7566 if Collide(gTriggers
[a
].X
,
7569 gTriggers
[a
].Height
) and
7570 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7571 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7572 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7573 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7574 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7579 // Âîçìîæíî, íàæèìàåì êíîïêó:
7580 if Rnd(16) and IsSafeTrigger() then
7583 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7584 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7586 ReleaseKey(KEY_LEFT
);
7587 ReleaseKey(KEY_RIGHT
);
7591 // Èäåì âëåâî, åñëè íàäî áûëî:
7592 if GetAIFlag('GOLEFT') <> '' then
7594 RemoveAIFlag('GOLEFT');
7595 if CanRunLeft() then
7599 // Èäåì âïðàâî, åñëè íàäî áûëî:
7600 if GetAIFlag('GORIGHT') <> '' then
7602 RemoveAIFlag('GORIGHT');
7603 if CanRunRight() then
7607 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7608 if FObj
.X
< -32 then
7611 if FObj
.X
+32 > gMapInfo
.Width
then
7614 // Ïðûãàåì, åñëè íàäî áûëî:
7615 if GetAIFlag('NEEDJUMP') <> '' then
7618 RemoveAIFlag('NEEDJUMP');
7621 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7622 if GetAIFlag('NEEDSEEUP') <> '' then
7625 ReleaseKey(KEY_DOWN
);
7626 PressKey(KEY_UP
, 20);
7627 RemoveAIFlag('NEEDSEEUP');
7630 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7631 if GetAIFlag('NEEDSEEDOWN') <> '' then
7634 ReleaseKey(KEY_DOWN
);
7635 PressKey(KEY_DOWN
, 20);
7636 RemoveAIFlag('NEEDSEEDOWN');
7639 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7640 if GetAIFlag('GOINHOLE') <> '' then
7641 if not OnGround() then
7643 ReleaseKey(KEY_LEFT
);
7644 ReleaseKey(KEY_RIGHT
);
7645 RemoveAIFlag('GOINHOLE');
7646 SetAIFlag('FALLINHOLE', '1');
7649 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7650 if GetAIFlag('FALLINHOLE') <> '' then
7652 RemoveAIFlag('FALLINHOLE');
7654 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7655 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7656 if GetAIFlag('FALLINHOLE') = '' then
7657 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7663 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7665 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7669 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7670 if OnGround() and NearHole() then
7671 if NearDeepHole() then // Åñëè ýòî áåçäíà
7673 0..3: Turn(); // Áåæèì îáðàòíî
7674 4: Jump(); // Ïðûãàåì
7675 5: begin // Ïðûãàåì îáðàòíî
7680 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7681 if GetAIFlag('GOINHOLE') = '' then
7683 0: Turn(); // Íå íóæíî òóäà
7684 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7685 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7686 if BorderHole() then
7687 SetAIFlag('GOINHOLE', '1');
7690 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7691 if (not CanRun()) and OnGround() then
7693 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7694 if CanJumpOver() or OnLadder() then
7696 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7697 if Random(2) = 0 then
7699 if IsSafeTrigger() then
7705 // Îñòàëîñü ìàëî âîçäóõà:
7706 if FAir
< 36 * 2 then
7709 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7710 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7711 if BodyInAcid(0, 0) then
7715 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7717 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7718 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7721 {function TBot.NeedItem(Item: Byte): Byte;
7726 procedure TBot
.SelectWeapon(Dist
: Integer);
7730 function HaveAmmo(weapon
: Byte): Boolean;
7733 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7734 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7735 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7736 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7737 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7738 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7739 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7740 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7741 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7742 else Result
:= True;
7747 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7749 if Dist
> BOT_LONGDIST
then
7750 begin // Äàëüíèé áîé
7752 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7754 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7758 else //if Dist > BOT_UNSAFEDIST then
7759 begin // Áëèæíèé áîé
7761 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7763 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7770 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7772 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7778 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7780 Result
:= inherited PickItem(ItemType
, force
, remove
);
7782 if Result
then SetAIFlag('SELECTWEAPON', '1');
7785 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7787 Result
:= inherited Heal(value
, Soft
);
7790 function TBot
.Healthy(): Byte;
7792 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7793 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7794 else if (FHealth
> 50) then Result
:= 2
7795 else if (FHealth
> 20) then Result
:= 1
7799 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7801 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7802 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7805 procedure TBot
.OnDamage(Angle
: SmallInt);
7813 if (Angle
= 0) or (Angle
= 180) then
7816 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7817 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7819 pla
:= g_Player_Get(FLastSpawnerUID
);
7820 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7821 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7824 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7825 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7827 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7828 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7829 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7834 SetAIFlag('ATTACKLEFT', '1')
7836 SetAIFlag('ATTACKRIGHT', '1');
7840 function TBot
.RunDirection(): TDirection
;
7842 if Abs(Vel
.X
) >= 1 then
7844 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7846 Result
:= FDirection
;
7849 function TBot
.GetRnd(a
: Byte): Boolean;
7851 if a
= 0 then Result
:= False
7852 else if a
= 255 then Result
:= True
7853 else Result
:= Random(256) > 255-a
;
7856 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7858 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7862 procedure TDifficult
.save (st
: TStream
);
7864 utils
.writeInt(st
, Byte(DiagFire
));
7865 utils
.writeInt(st
, Byte(InvisFire
));
7866 utils
.writeInt(st
, Byte(DiagPrecision
));
7867 utils
.writeInt(st
, Byte(FlyPrecision
));
7868 utils
.writeInt(st
, Byte(Cover
));
7869 utils
.writeInt(st
, Byte(CloseJump
));
7870 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7871 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7874 procedure TDifficult
.load (st
: TStream
);
7876 DiagFire
:= utils
.readByte(st
);
7877 InvisFire
:= utils
.readByte(st
);
7878 DiagPrecision
:= utils
.readByte(st
);
7879 FlyPrecision
:= utils
.readByte(st
);
7880 Cover
:= utils
.readByte(st
);
7881 CloseJump
:= utils
.readByte(st
);
7882 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7883 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7887 procedure TBot
.SaveState (st
: TStream
);
7892 inherited SaveState(st
);
7893 utils
.writeSign(st
, 'BOT0');
7895 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7897 utils
.writeInt(st
, Word(FTargetUID
));
7898 // Âðåìÿ ïîòåðè öåëè
7899 utils
.writeInt(st
, LongWord(FLastVisible
));
7900 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7901 dw
:= Length(FAIFlags
);
7902 utils
.writeInt(st
, LongInt(dw
));
7904 for i
:= 0 to dw
-1 do
7906 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7907 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7909 // Íàñòðîéêè ñëîæíîñòè
7910 FDifficult
.save(st
);
7914 procedure TBot
.LoadState (st
: TStream
);
7919 inherited LoadState(st
);
7920 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7922 FSelectedWeapon
:= utils
.readByte(st
);
7924 FTargetUID
:= utils
.readWord(st
);
7925 // Âðåìÿ ïîòåðè öåëè
7926 FLastVisible
:= utils
.readLongWord(st
);
7927 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7928 dw
:= utils
.readLongInt(st
);
7929 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7930 SetLength(FAIFlags
, dw
);
7932 for i
:= 0 to dw
-1 do
7934 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7935 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7937 // Íàñòðîéêè ñëîæíîñòè
7938 FDifficult
.load(st
);
7943 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);