1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
24 {$IFDEF USE_MEMPOOL}mempool
,{$ENDIF}
25 e_graphics
, g_playermodel
, g_basic
, g_textures
,
26 g_weapons
, g_phys
, g_sound
, g_saveload
, MAPDEF
,
59 AmmoLimits
: Array [0..1] of Array [A_BULLETS
..A_HIGH
] of Word =
60 ((200, 50, 50, 300, 100),
61 (400, 100, 100, 600, 200));
82 ANGLE_NONE
= Low(SmallInt);
84 CORPSE_STATE_REMOVEME
= 0;
85 CORPSE_STATE_NORMAL
= 1;
86 CORPSE_STATE_MESS
= 2;
88 PLAYER_RECT
: TRectWH
= (X
:15; Y
:12; Width
:34; Height
:52);
89 PLAYER_RECT_CX
= 15+(34 div 2);
90 PLAYER_RECT_CY
= 12+(52 div 2);
91 PLAYER_CORPSERECT
: TRectWH
= (X
:15; Y
:48; Width
:34; Height
:16);
94 PLAYER_HP_LIMIT
= 200;
96 PLAYER_AP_LIMIT
= 200;
99 PLAYER1_DEF_COLOR
: TRGB
= (R
:64; G
:175; B
:48);
100 PLAYER2_DEF_COLOR
: TRGB
= (R
:96; G
:96; B
:96);
116 TPlayerStatArray
= Array of TPlayerStat
;
118 TPlayerSavedState
= record
126 Ammo
: Array [A_BULLETS
..A_HIGH
] of Word;
127 MaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
128 Weapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
129 Rulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
138 TPlayer
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
146 FDirection
: TDirection
;
154 FMonsterKills
: Integer;
160 FCanJetpack
: Boolean;
166 FNextWeapDelay
: Byte; // frames (unused)
167 FBFGFireCounter
: SmallInt;
168 FLastSpawnerUID
: Word;
172 FSpectatePlayer
: Integer;
173 FFirePainTime
: Integer;
176 FSavedState
: TPlayerSavedState
;
178 FModel
: TPlayerModel
;
179 FPunchAnim
: TAnimation
;
182 FActionForce
: Boolean;
183 FActionChanged
: Boolean;
185 FFireAngle
: SmallInt;
187 FShellTimer
: Integer;
189 FSawSound
: TPlayableSound
;
190 FSawSoundIdle
: TPlayableSound
;
191 FSawSoundHit
: TPlayableSound
;
192 FSawSoundSelect
: TPlayableSound
;
193 FJetSoundOn
: TPlayableSound
;
194 FJetSoundOff
: TPlayableSound
;
195 FJetSoundFly
: TPlayableSound
;
199 FJustTeleported
: Boolean;
201 mEDamageType
: Integer;
204 weaponSwitchKeyReleased
: array[0..16] of Byte; // bit 0: was released on prev frame; bit 1: new status
207 function CollideLevel(XInc
, YInc
: Integer): Boolean;
208 function StayOnStep(XInc
, YInc
: Integer): Boolean;
209 function HeadInLiquid(XInc
, YInc
: Integer): Boolean;
210 function BodyInLiquid(XInc
, YInc
: Integer): Boolean;
211 function BodyInAcid(XInc
, YInc
: Integer): Boolean;
212 function FullInLift(XInc
, YInc
: Integer): Integer;
213 {procedure CollideItem();}
214 procedure FlySmoke(Times
: DWORD
= 1);
215 procedure OnFireFlame(Times
: DWORD
= 1);
216 function GetAmmoByWeapon(Weapon
: Byte): Word;
217 procedure SetAction(Action
: Byte; Force
: Boolean = False);
218 procedure OnDamage(Angle
: SmallInt); virtual;
219 function firediry(): Integer;
222 procedure Run(Direction
: TDirection
);
223 procedure NextWeapon();
224 procedure PrevWeapon();
231 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
232 procedure resetWeaponQueue ();
233 function hasAmmoForWeapon (weapon
: Byte): Boolean;
235 procedure doDamage (v
: Integer);
237 function followCorpse(): Boolean;
240 FDamageBuffer
: Integer;
242 FAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
243 FMaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
244 FWeapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
245 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
247 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
248 FReloading
: Array [WP_FIRST
..WP_LAST
] of Word;
249 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
250 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
252 FPreferredTeam
: Byte;
255 FWantsInGame
: Boolean;
259 FActualModelName
: string;
266 // debug: viewport offset
267 viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer;
269 function isValidViewPort (): Boolean; inline;
271 constructor Create(); virtual;
272 destructor Destroy(); override;
273 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
274 function GetRespawnPoint(): Byte;
275 procedure PressKey(Key
: Byte; Time
: Word = 1);
276 procedure ReleaseKeys();
277 procedure ReleaseKeysNoWeapon();
278 procedure SetModel(ModelName
: String);
279 procedure SetColor(Color
: TRGB
);
280 procedure SetWeapon(W
: Byte);
281 function IsKeyPressed(K
: Byte): Boolean;
282 function GetKeys(): Byte;
283 function PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean; virtual;
284 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
285 function Collide(Panel
: TPanel
): Boolean; overload
;
286 function Collide(X
, Y
: Integer): Boolean; overload
;
287 procedure SetDirection(Direction
: TDirection
);
288 procedure GetSecret();
289 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
291 procedure Push(vx
, vy
: Integer);
292 procedure ChangeModel(ModelName
: String);
293 procedure SwitchTeam
;
294 procedure ChangeTeam(Team
: Byte);
296 function GetFlag(Flag
: Byte): Boolean;
297 procedure SetFlag(Flag
: Byte);
298 function DropFlag(): Boolean;
299 procedure AllRulez(Health
: Boolean);
300 procedure RestoreHealthArmor();
301 procedure FragCombo();
302 procedure GiveItem(ItemType
: Byte);
303 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
304 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
305 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
306 procedure MakeBloodSimple(Count
: Word);
307 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
308 procedure Reset(Force
: Boolean);
309 procedure Spectate(NoMove
: Boolean = False);
310 procedure SwitchNoClip
;
311 procedure SoftReset();
312 procedure Draw(); virtual;
313 procedure DrawPain();
314 procedure DrawPickup();
315 procedure DrawRulez();
317 procedure DrawIndicator();
318 procedure DrawBubble();
320 procedure Update(); virtual;
321 procedure RememberState();
322 procedure RecallState();
323 procedure SaveState (st
: TStream
); virtual;
324 procedure LoadState (st
: TStream
); virtual;
325 procedure PauseSounds(Enable
: Boolean);
326 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
327 procedure DoLerp(Level
: Integer = 2);
328 procedure SetLerp(XTo
, YTo
: Integer);
329 procedure QueueWeaponSwitch(Weapon
: Byte);
330 procedure RealizeCurrentWeapon();
332 procedure JetpackOff
;
333 procedure CatchFire(Attacker
: Word);
335 //WARNING! this does nothing for now, but still call it!
336 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
338 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
339 procedure moveBy (dx
, dy
: Integer); inline;
341 procedure releaseAllWeaponSwitchKeys ();
342 procedure weaponSwitchKeysStateChange (index
: Integer; pressed
: Boolean);
343 function isWeaponSwitchKeyReleased (index
: Integer): Boolean;
344 procedure weaponSwitchKeysShiftNewStates ();
347 property Vel
: TPoint2i read FObj
.Vel
;
348 property Obj
: TObj read FObj
;
350 property Name
: String read FName write FName
;
351 property Model
: TPlayerModel read FModel
;
352 property Health
: Integer read FHealth write FHealth
;
353 property Lives
: Byte read FLives write FLives
;
354 property Armor
: Integer read FArmor write FArmor
;
355 property Air
: Integer read FAir write FAir
;
356 property JetFuel
: Integer read FJetFuel write FJetFuel
;
357 property Frags
: Integer read FFrags write FFrags
;
358 property Death
: Integer read FDeath write FDeath
;
359 property Kills
: Integer read FKills write FKills
;
360 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
361 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
362 property Secrets
: Integer read FSecrets
;
363 property GodMode
: Boolean read FGodMode write FGodMode
;
364 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
365 property NoReload
: Boolean read FNoReload write FNoReload
;
366 property alive
: Boolean read FAlive write FAlive
;
367 property Flag
: Byte read FFlag
;
368 property Team
: Byte read FTeam write FTeam
;
369 property Direction
: TDirection read FDirection
;
370 property GameX
: Integer read FObj
.X write FObj
.X
;
371 property GameY
: Integer read FObj
.Y write FObj
.Y
;
372 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
373 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
374 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
375 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
376 property IncCam
: Integer read FIncCam write FIncCam
;
377 property UID
: Word read FUID write FUID
;
378 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
379 property NetTime
: LongWord read FNetTime write FNetTime
;
382 property eName
: String read FName write FName
;
383 property eHealth
: Integer read FHealth write FHealth
;
384 property eLives
: Byte read FLives write FLives
;
385 property eArmor
: Integer read FArmor write FArmor
;
386 property eAir
: Integer read FAir write FAir
;
387 property eJetFuel
: Integer read FJetFuel write FJetFuel
;
388 property eFrags
: Integer read FFrags write FFrags
;
389 property eDeath
: Integer read FDeath write FDeath
;
390 property eKills
: Integer read FKills write FKills
;
391 property eCurrWeap
: Byte read FCurrWeap write FCurrWeap
;
392 property eMonsterKills
: Integer read FMonsterKills write FMonsterKills
;
393 property eSecrets
: Integer read FSecrets write FSecrets
;
394 property eGodMode
: Boolean read FGodMode write FGodMode
;
395 property eNoTarget
: Boolean read FNoTarget write FNoTarget
;
396 property eNoReload
: Boolean read FNoReload write FNoReload
;
397 property eAlive
: Boolean read FAlive write FAlive
;
398 property eFlag
: Byte read FFlag
;
399 property eTeam
: Byte read FTeam write FTeam
;
400 property eDirection
: TDirection read FDirection
;
401 property eGameX
: Integer read FObj
.X write FObj
.X
;
402 property eGameY
: Integer read FObj
.Y write FObj
.Y
;
403 property eGameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
404 property eGameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
405 property eGameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
406 property eGameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
407 property eIncCam
: Integer read FIncCam write FIncCam
;
408 property eUID
: Word read FUID
;
409 property eJustTeleported
: Boolean read FJustTeleported
;
410 property eNetTime
: LongWord read FNetTime
;
412 // set this before assigning something to `eDamage`
413 property eDamageType
: Integer read mEDamageType write mEDamageType
;
414 property eDamage
: Integer write doDamage
;
425 WeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
426 CloseWeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
427 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
430 procedure save (st
: TStream
);
431 procedure load (st
: TStream
);
439 TBot
= class(TPlayer
)
441 FSelectedWeapon
: Byte;
444 FAIFlags
: Array of TAIFlag
;
445 FDifficult
: TDifficult
;
447 function GetRnd(a
: Byte): Boolean;
448 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
449 function RunDirection(): TDirection
;
450 function FullInStep(XInc
, YInc
: Integer): Boolean;
451 //function NeedItem(Item: Byte): Byte;
452 procedure SelectWeapon(Dist
: Integer);
453 procedure SetAIFlag(aName
, fValue
: String20
);
454 function GetAIFlag(aName
: String20
): String20
;
455 procedure RemoveAIFlag(aName
: String20
);
456 function Healthy(): Byte;
457 procedure UpdateMove();
458 procedure UpdateCombat();
459 function KeyPressed(Key
: Word): Boolean;
460 procedure ReleaseKey(Key
: Byte);
461 function TargetOnScreen(TX
, TY
: Integer): Boolean;
462 procedure OnDamage(Angle
: SmallInt); override;
465 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
466 constructor Create(); override;
467 destructor Destroy(); override;
468 procedure Draw(); override;
469 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
470 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
471 procedure Update(); override;
472 procedure SaveState (st
: TStream
); override;
473 procedure LoadState (st
: TStream
); override;
485 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
486 procedure moveBy (dx
, dy
: Integer); inline;
488 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
502 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
503 procedure moveBy (dx
, dy
: Integer); inline;
505 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
508 TCorpse
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
517 FAnimation
: TAnimation
;
518 FAnimationMask
: TAnimation
;
521 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
522 destructor Destroy(); override;
523 procedure Damage(Value
: Word; vx
, vy
: Integer);
526 procedure SaveState (st
: TStream
);
527 procedure LoadState (st
: TStream
);
529 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
530 procedure moveBy (dx
, dy
: Integer); inline;
532 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
534 function ObjPtr (): PObj
; inline;
536 property Obj
: TObj read FObj
; // copies object
537 property State
: Byte read FState
;
538 property Mess
: Boolean read FMess
;
541 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
547 gPlayers
: Array of TPlayer
;
548 gCorpses
: Array of TCorpse
;
549 gGibs
: Array of TGib
;
550 gShells
: Array of TShell
;
551 gTeamStat
: TTeamStat
;
552 gFly
: Boolean = False;
553 gAimLine
: Boolean = False;
554 gChatBubble
: Byte = 0;
555 gPlayerIndicator
: Boolean = True;
559 MAX_RUNVEL
: Integer = 8;
560 VEL_JUMP
: Integer = 10;
561 SHELL_TIMEOUT
: Cardinal = 60000;
563 function Lerp(X
, Y
, Factor
: Integer): Integer;
565 procedure g_Gibs_SetMax(Count
: Word);
566 function g_Gibs_GetMax(): Word;
567 procedure g_Corpses_SetMax(Count
: Word);
568 function g_Corpses_GetMax(): Word;
569 procedure g_Shells_SetMax(Count
: Word);
570 function g_Shells_GetMax(): Word;
572 procedure g_Player_Init();
573 procedure g_Player_Free();
574 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
575 function g_Player_CreateFromState (st
: TStream
): Word;
576 procedure g_Player_Remove(UID
: Word);
577 procedure g_Player_ResetTeams();
578 procedure g_Player_UpdateAll();
579 procedure g_Player_DrawAll();
580 procedure g_Player_DrawDebug(p
: TPlayer
);
581 procedure g_Player_DrawHealth();
582 procedure g_Player_RememberAll();
583 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
584 function g_Player_Get(UID
: Word): TPlayer
;
585 function g_Player_GetCount(): Byte;
586 function g_Player_GetStats(): TPlayerStatArray
;
587 function g_Player_ValidName(Name
: String): Boolean;
588 procedure g_Player_CreateCorpse(Player
: TPlayer
);
589 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
590 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
591 procedure g_Player_UpdatePhysicalObjects();
592 procedure g_Player_DrawCorpses();
593 procedure g_Player_DrawShells();
594 procedure g_Player_RemoveAllCorpses();
595 procedure g_Player_Corpses_SaveState (st
: TStream
);
596 procedure g_Player_Corpses_LoadState (st
: TStream
);
597 procedure g_Bot_Add(Team
, Difficult
: Byte);
598 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1);
599 procedure g_Bot_MixNames();
600 procedure g_Bot_RemoveAll();
605 {$INCLUDE ../nogl/noGLuses.inc}
606 {$IFDEF ENABLE_HOLMES}
609 e_log
, g_map
, g_items
, g_console
, g_gfx
, Math
,
610 g_options
, g_triggers
, g_menu
, g_game
, g_grid
,
611 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
,
612 g_net
, g_netmsg
, g_window
,
615 const PLR_SAVE_VERSION
= 0;
625 diag_precision
: Byte;
629 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
630 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
631 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
635 TIME_RESPAWN1
= 1500;
636 TIME_RESPAWN2
= 2000;
637 TIME_RESPAWN3
= 3000;
640 JET_MAX
= 540; // ~30 sec
641 PLAYER_SUIT_TIME
= 30000;
642 PLAYER_INVUL_TIME
= 30000;
643 PLAYER_INVIS_TIME
= 35000;
644 FRAG_COMBO_TIME
= 3000;
648 ANGLE_RIGHTDOWN
= -35;
650 ANGLE_LEFTDOWN
= -145;
651 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
652 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
655 BOT_UNSAFEDIST
= 128;
656 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
658 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
659 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
660 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
661 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
662 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
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_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
665 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
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 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
668 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
669 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
670 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
671 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
672 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
673 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
674 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
675 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
676 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
677 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
678 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
679 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
680 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
681 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
682 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
683 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
685 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
686 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
688 BOTNAMES_FILENAME
= 'botnames.txt';
689 BOTLIST_FILENAME
= 'botlist.txt';
693 MaxCorpses
: Word = 20;
694 MaxShells
: Word = 300;
695 CurrentGib
: Integer = 0;
696 CurrentShell
: Integer = 0;
697 BotNames
: Array of String;
698 BotList
: Array of TBotProfile
;
701 function Lerp(X
, Y
, Factor
: Integer): Integer;
703 Result
:= X
+ ((Y
- X
) div Factor
);
706 function SameTeam(UID1
, UID2
: Word): Boolean;
710 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
711 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
713 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
715 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
716 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
718 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
721 procedure g_Gibs_SetMax(Count
: Word);
724 SetLength(gGibs
, Count
);
726 if CurrentGib
>= Count
then
730 function g_Gibs_GetMax(): Word;
735 procedure g_Shells_SetMax(Count
: Word);
738 SetLength(gShells
, Count
);
740 if CurrentShell
>= Count
then
744 function g_Shells_GetMax(): Word;
750 procedure g_Corpses_SetMax(Count
: Word);
753 SetLength(gCorpses
, Count
);
756 function g_Corpses_GetMax(): Word;
758 Result
:= MaxCorpses
;
761 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
771 // Åñòü ëè ìåñòî â gPlayers:
772 if gPlayers
<> nil then
773 for a
:= 0 to High(gPlayers
) do
774 if gPlayers
[a
] = nil then
780 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
783 SetLength(gPlayers
, Length(gPlayers
)+1);
787 // Ñîçäàåì îáúåêò èãðîêà:
789 gPlayers
[a
] := TBot
.Create()
791 gPlayers
[a
] := TPlayer
.Create();
794 gPlayers
[a
].FActualModelName
:= ModelName
;
795 gPlayers
[a
].SetModel(ModelName
);
797 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
798 if gPlayers
[a
].FModel
= nil then
802 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
806 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
807 if Random(2) = 0 then
811 gPlayers
[a
].FPreferredTeam
:= Team
;
813 case gGameSettings
.GameMode
of
814 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
816 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
818 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
821 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
822 gPlayers
[a
].FColor
:= Color
;
823 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
824 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
826 gPlayers
[a
].FModel
.Color
:= Color
;
828 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
829 gPlayers
[a
].FAlive
:= False;
831 Result
:= gPlayers
[a
].FUID
;
834 function g_Player_CreateFromState (st
: TStream
): Word;
841 if (st
= nil) then exit
; //???
844 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
845 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
848 Bot
:= utils
.readBool(st
);
853 // Åñòü ëè ìåñòî â gPlayers:
854 for a
:= 0 to High(gPlayers
) do if (gPlayers
[a
] = nil) then begin ok
:= true; break
; end;
856 // Íåò ìåñòà - ðàñøèðÿåì gPlayers
859 SetLength(gPlayers
, Length(gPlayers
)+1);
863 // Ñîçäàåì îáúåêò èãðîêà
865 gPlayers
[a
] := TBot
.Create()
867 gPlayers
[a
] := TPlayer
.Create();
868 gPlayers
[a
].FIamBot
:= Bot
;
869 gPlayers
[a
].FPhysics
:= True;
872 gPlayers
[a
].FUID
:= utils
.readWord(st
);
874 gPlayers
[a
].FName
:= utils
.readStr(st
);
876 gPlayers
[a
].FTeam
:= utils
.readByte(st
);
877 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
879 gPlayers
[a
].FAlive
:= utils
.readBool(st
);
880 // Èçðàñõîäîâàë ëè âñå æèçíè
881 gPlayers
[a
].FNoRespawn
:= utils
.readBool(st
);
883 b
:= utils
.readByte(st
);
884 if b
= 1 then gPlayers
[a
].FDirection
:= TDirection
.D_LEFT
else gPlayers
[a
].FDirection
:= TDirection
.D_RIGHT
; // b = 2
886 gPlayers
[a
].FHealth
:= utils
.readLongInt(st
);
888 gPlayers
[a
].FLives
:= utils
.readByte(st
);
890 gPlayers
[a
].FArmor
:= utils
.readLongInt(st
);
892 gPlayers
[a
].FAir
:= utils
.readLongInt(st
);
894 gPlayers
[a
].FJetFuel
:= utils
.readLongInt(st
);
896 gPlayers
[a
].FPain
:= utils
.readLongInt(st
);
898 gPlayers
[a
].FKills
:= utils
.readLongInt(st
);
900 gPlayers
[a
].FMonsterKills
:= utils
.readLongInt(st
);
902 gPlayers
[a
].FFrags
:= utils
.readLongInt(st
);
904 gPlayers
[a
].FFragCombo
:= utils
.readByte(st
);
905 // Âðåìÿ ïîñëåäíåãî ôðàãà
906 gPlayers
[a
].FLastFrag
:= utils
.readLongWord(st
);
908 gPlayers
[a
].FDeath
:= utils
.readLongInt(st
);
910 gPlayers
[a
].FFlag
:= utils
.readByte(st
);
912 gPlayers
[a
].FSecrets
:= utils
.readLongInt(st
);
914 gPlayers
[a
].FCurrWeap
:= utils
.readByte(st
);
915 // Ñëåäóþùåå æåëàåìîå îðóæèå
916 gPlayers
[a
].FNextWeap
:= utils
.readWord(st
);
918 gPlayers
[a
].FNextWeapDelay
:= utils
.readByte(st
);
920 gPlayers
[a
].FBFGFireCounter
:= utils
.readSmallInt(st
);
922 gPlayers
[a
].FDamageBuffer
:= utils
.readLongInt(st
);
923 // Ïîñëåäíèé óäàðèâøèé
924 gPlayers
[a
].FLastSpawnerUID
:= utils
.readWord(st
);
925 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
926 gPlayers
[a
].FLastHit
:= utils
.readByte(st
);
928 Obj_LoadState(@gPlayers
[a
].FObj
, st
);
929 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
930 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FAmmo
[i
] := utils
.readWord(st
);
931 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
932 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FMaxAmmo
[i
] := utils
.readWord(st
);
934 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FWeapon
[i
] := utils
.readBool(st
);
935 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
936 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FReloading
[i
] := utils
.readWord(st
);
938 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
939 // Íàëè÷èå êðàñíîãî êëþ÷à
940 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
941 // Íàëè÷èå çåëåíîãî êëþ÷à
942 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
943 // Íàëè÷èå ñèíåãî êëþ÷à
944 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
946 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_BERSERK
);
947 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
948 for i
:= MR_SUIT
to MR_MAX
do gPlayers
[a
].FMegaRulez
[i
] := utils
.readLongWord(st
);
949 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
950 for i
:= T_RESPAWN
to T_FLAGCAP
do gPlayers
[a
].FTime
[i
] := utils
.readLongWord(st
);
953 gPlayers
[a
].FActualModelName
:= utils
.readStr(st
);
955 gPlayers
[a
].FColor
.R
:= utils
.readByte(st
);
956 gPlayers
[a
].FColor
.G
:= utils
.readByte(st
);
957 gPlayers
[a
].FColor
.B
:= utils
.readByte(st
);
958 // Îáíîâëÿåì ìîäåëü èãðîêà
959 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
961 // Íåò ìîäåëè - ñîçäàíèå íåâîçìîæíî
962 if (gPlayers
[a
].FModel
= nil) then
966 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
970 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû
971 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
972 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
974 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
976 result
:= gPlayers
[a
].FUID
;
980 procedure g_Player_ResetTeams();
984 if g_Game_IsClient
then
986 if gPlayers
= nil then
988 for a
:= Low(gPlayers
) to High(gPlayers
) do
989 if gPlayers
[a
] <> nil then
990 case gGameSettings
.GameMode
of
992 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
994 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
995 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
996 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
999 gPlayers
[a
].ChangeTeam(TEAM_RED
)
1001 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
1004 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
1008 procedure g_Bot_Add(Team
, Difficult
: Byte);
1011 _name
, _model
: String;
1014 if not g_Game_IsServer
then Exit
;
1016 // Ñïèñîê íàçâàíèé ìîäåëåé:
1017 m
:= g_PlayerModel_GetNames();
1022 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1023 Team
:= TEAM_COOP
// COOP
1025 if gGameSettings
.GameMode
= GM_DM
then
1026 Team
:= TEAM_NONE
// DM
1028 if Team
= TEAM_NONE
then // CTF / TDM
1030 // Àâòîáàëàíñ êîìàíä:
1034 for a
:= 0 to High(gPlayers
) do
1035 if gPlayers
[a
] <> nil then
1037 if gPlayers
[a
].Team
= TEAM_RED
then
1040 if gPlayers
[a
].Team
= TEAM_BLUE
then
1050 if Random(2) = 0 then
1056 // Âûáèðàåì áîòó èìÿ:
1058 if BotNames
<> nil then
1059 for a
:= 0 to High(BotNames
) do
1060 if g_Player_ValidName(BotNames
[a
]) then
1062 _name
:= BotNames
[a
];
1066 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
1069 _name
:= Format('DFBOT%.2d', [Random(100)]);
1070 until g_Player_ValidName(_name
);
1072 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1073 _model
:= m
[Random(Length(m
))];
1076 with g_Player_Get(g_Player_Create(_model
,
1077 _RGB(Min(Random(9)*32, 255),
1078 Min(Random(9)*32, 255),
1079 Min(Random(9)*32, 255)),
1080 Team
, True)) as TBot
do
1085 1: FDifficult
:= DIFFICULT_EASY
;
1086 2: FDifficult
:= DIFFICULT_MEDIUM
;
1087 else FDifficult
:= DIFFICULT_HARD
;
1090 for a
:= WP_FIRST
to WP_LAST
do
1092 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1093 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1094 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1097 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1099 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1100 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1105 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1);
1108 _name
, _model
: String;
1111 if not g_Game_IsServer
then Exit
;
1113 // Ñïèñîê íàçâàíèé ìîäåëåé:
1114 m
:= g_PlayerModel_GetNames();
1119 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1120 Team
:= TEAM_COOP
// COOP
1122 if gGameSettings
.GameMode
= GM_DM
then
1123 Team
:= TEAM_NONE
// DM
1125 if Team
= TEAM_NONE
then
1126 Team
:= BotList
[num
].team
; // CTF / TDM
1128 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1129 lName
:= AnsiLowerCase(lName
);
1130 if (num
< 0) or (num
> Length(BotList
)-1) then
1132 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1133 for a
:= 0 to High(BotList
) do
1134 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1143 _name
:= BotList
[num
].name
;
1144 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1145 if not g_Player_ValidName(_name
) then
1147 _name
:= Format('DFBOT%.2d', [Random(100)]);
1148 until g_Player_ValidName(_name
);
1151 _model
:= BotList
[num
].model
;
1152 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1153 if not InSArray(_model
, m
) then
1154 _model
:= m
[Random(Length(m
))];
1157 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1161 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1162 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1163 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1164 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1165 FDifficult
.Cover
:= BotList
[num
].cover
;
1166 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1168 for a
:= WP_FIRST
to WP_LAST
do
1170 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1171 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1172 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1175 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1177 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1181 procedure g_Bot_RemoveAll();
1185 if not g_Game_IsServer
then Exit
;
1186 if gPlayers
= nil then Exit
;
1188 for a
:= 0 to High(gPlayers
) do
1189 if gPlayers
[a
] <> nil then
1190 if gPlayers
[a
] is TBot
then
1192 gPlayers
[a
].Lives
:= 0;
1193 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1194 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1195 g_Player_Remove(gPlayers
[a
].FUID
);
1201 procedure g_Bot_MixNames();
1206 if BotNames
<> nil then
1207 for a
:= 0 to High(BotNames
) do
1209 b
:= Random(Length(BotNames
));
1211 Botnames
[a
] := BotNames
[b
];
1216 procedure g_Player_Remove(UID
: Word);
1220 if gPlayers
= nil then Exit
;
1222 if g_Game_IsServer
and g_Game_IsNet
then
1223 MH_SEND_PlayerDelete(UID
);
1225 for i
:= 0 to High(gPlayers
) do
1226 if gPlayers
[i
] <> nil then
1227 if gPlayers
[i
].FUID
= UID
then
1229 if gPlayers
[i
] is TPlayer
then
1230 TPlayer(gPlayers
[i
]).Free()
1232 TBot(gPlayers
[i
]).Free();
1238 procedure g_Player_Init();
1248 if not FileExists(DataDir
+ BOTNAMES_FILENAME
) then
1251 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1252 AssignFile(F
, DataDir
+ BOTNAMES_FILENAME
);
1263 SetLength(BotNames
, Length(BotNames
)+1);
1264 BotNames
[High(BotNames
)] := s
;
1272 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1273 config
:= TConfig
.CreateFile(DataDir
+ BOTLIST_FILENAME
);
1277 while config
.SectionExists(IntToStr(a
)) do
1279 SetLength(BotList
, Length(BotList
)+1);
1281 with BotList
[High(BotList
)] do
1284 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1286 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1288 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1293 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1294 color
.R
:= StrToIntDef(sa
[0], 0);
1295 color
.G
:= StrToIntDef(sa
[1], 0);
1296 color
.B
:= StrToIntDef(sa
[2], 0);
1297 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1298 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1299 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1300 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1301 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1302 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1303 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1304 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1305 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1306 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1307 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1308 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1309 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1310 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1311 if Length(sa
) = 10 then
1313 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1314 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1315 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1316 if Length(sa
) = 10 then
1318 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1320 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1321 if Length(sa) = 10 then
1323 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1332 procedure g_Player_Free();
1336 if gPlayers
<> nil then
1338 for i
:= 0 to High(gPlayers
) do
1339 if gPlayers
[i
] <> nil then
1341 if gPlayers
[i
] is TPlayer
then
1342 TPlayer(gPlayers
[i
]).Free()
1344 TBot(gPlayers
[i
]).Free();
1355 procedure g_Player_UpdateAll();
1359 if gPlayers
= nil then Exit
;
1361 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1362 for i
:= 0 to High(gPlayers
) do
1364 if gPlayers
[i
] <> nil then
1366 if gPlayers
[i
] is TPlayer
then
1368 gPlayers
[i
].Update();
1369 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1373 // bot updates weapons in `UpdateCombat()`
1374 TBot(gPlayers
[i
]).Update();
1378 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1381 procedure g_Player_DrawAll();
1385 if gPlayers
= nil then Exit
;
1387 for i
:= 0 to High(gPlayers
) do
1388 if gPlayers
[i
] <> nil then
1389 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1390 else TBot(gPlayers
[i
]).Draw();
1393 procedure g_Player_DrawDebug(p
: TPlayer
);
1397 if p
= nil then Exit
;
1398 if (@p
.FObj
) = nil then Exit
;
1400 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1402 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1403 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1404 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1405 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1406 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1407 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1410 procedure g_Player_DrawHealth();
1415 if gPlayers
= nil then Exit
;
1416 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1418 for i
:= 0 to High(gPlayers
) do
1419 if gPlayers
[i
] <> nil then
1421 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1422 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1423 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1424 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1425 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1426 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1430 function g_Player_Get(UID
: Word): TPlayer
;
1436 if gPlayers
= nil then
1439 for a
:= 0 to High(gPlayers
) do
1440 if gPlayers
[a
] <> nil then
1441 if gPlayers
[a
].FUID
= UID
then
1443 Result
:= gPlayers
[a
];
1448 function g_Player_GetCount(): Byte;
1454 if gPlayers
= nil then
1457 for a
:= 0 to High(gPlayers
) do
1458 if gPlayers
[a
] <> nil then
1459 Result
:= Result
+ 1;
1462 function g_Player_GetStats(): TPlayerStatArray
;
1468 if gPlayers
= nil then Exit
;
1470 for a
:= 0 to High(gPlayers
) do
1471 if gPlayers
[a
] <> nil then
1473 SetLength(Result
, Length(Result
)+1);
1474 with Result
[High(Result
)] do
1476 Ping
:= gPlayers
[a
].FPing
;
1477 Loss
:= gPlayers
[a
].FLoss
;
1478 Name
:= gPlayers
[a
].FName
;
1479 Team
:= gPlayers
[a
].FTeam
;
1480 Frags
:= gPlayers
[a
].FFrags
;
1481 Deaths
:= gPlayers
[a
].FDeath
;
1482 Kills
:= gPlayers
[a
].FKills
;
1483 Color
:= gPlayers
[a
].FModel
.Color
;
1484 Lives
:= gPlayers
[a
].FLives
;
1485 Spectator
:= gPlayers
[a
].FSpectator
;
1490 procedure g_Player_RememberAll
;
1494 for i
:= Low(gPlayers
) to High(gPlayers
) do
1495 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1496 gPlayers
[i
].RememberState
;
1499 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1503 gTeamStat
[TEAM_RED
].Goals
:= 0;
1504 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1506 if gPlayers
<> nil then
1507 for i
:= 0 to High(gPlayers
) do
1508 if gPlayers
[i
] <> nil then
1510 gPlayers
[i
].Reset(Force
);
1512 if gPlayers
[i
] is TPlayer
then
1514 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1515 gPlayers
[i
].Respawn(Silent
)
1517 gPlayers
[i
].Spectate();
1520 TBot(gPlayers
[i
]).Respawn(Silent
);
1524 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1530 if Player
.alive
then
1533 // Ðàçðûâàåì ñâÿçü ñ ïðåæíèì òðóïîì:
1534 if gCorpses
<> nil then
1535 for i
:= 0 to High(gCorpses
) do
1536 if gCorpses
[i
] <> nil then
1537 if gCorpses
[i
].FPlayerUID
= Player
.FUID
then
1538 gCorpses
[i
].FPlayerUID
:= 0;
1540 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1545 if (FHealth
>= -50) or (gGibsCount
= 0) then
1547 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1551 for find_id
:= 0 to High(gCorpses
) do
1552 if gCorpses
[find_id
] = nil then
1559 find_id
:= Random(Length(gCorpses
));
1561 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1562 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1563 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1564 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1565 gCorpses
[find_id
].FPlayerUID
:= FUID
;
1568 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1569 FObj
.Y
+ PLAYER_RECT_CY
,
1570 FModel
.Name
, FModel
.Color
);
1574 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1578 if (gShells
= nil) or (Length(gShells
) = 0) then
1581 with gShells
[CurrentShell
] do
1587 if T
= SHELL_BULLET
then
1589 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1593 Obj
.Rect
.Width
:= 4;
1594 Obj
.Rect
.Height
:= 2;
1598 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1602 Obj
.Rect
.Width
:= 7;
1603 Obj
.Rect
.Height
:= 3;
1609 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1610 positionChanged(); // this updates spatial accelerators
1611 RAngle
:= Random(360);
1612 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1614 if CurrentShell
>= High(gShells
) then
1621 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1624 GibsArray
: TGibsArray
;
1627 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1629 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1631 Blood
:= g_PlayerModel_GetBlood(ModelName
);
1633 for a
:= 0 to High(GibsArray
) do
1634 with gGibs
[CurrentGib
] do
1637 ID
:= GibsArray
[a
].ID
;
1638 MaskID
:= GibsArray
[a
].MaskID
;
1641 Obj
.Rect
:= GibsArray
[a
].Rect
;
1642 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1643 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1644 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1645 positionChanged(); // this updates spatial accelerators
1646 RAngle
:= Random(360);
1648 if gBloodCount
> 0 then
1649 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1650 Random(48), Random(48), Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
1652 if CurrentGib
>= High(gGibs
) then
1659 procedure g_Player_UpdatePhysicalObjects();
1665 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1670 if T
= SHELL_BULLET
then
1671 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1673 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1678 if gGibs
<> nil then
1679 for i
:= 0 to High(gGibs
) do
1680 if gGibs
[i
].alive
then
1684 mr
:= g_Obj_Move(@Obj
, True, False, True);
1685 positionChanged(); // this updates spatial accelerators
1687 if WordBool(mr
and MOVE_FALLOUT
) then
1693 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1694 if WordBool(mr
and MOVE_HITWALL
) then
1695 Obj
.Vel
.X
:= -(vel
.X
div 2);
1696 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1697 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1699 if (Obj
.Vel
.X
>= 0) then
1701 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1702 if RAngle
>= 360 then
1703 RAngle
:= RAngle
mod 360;
1704 end else begin // Counter-clockwise
1705 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1707 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1710 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1711 if gTime
mod (GAME_TICK
*3) = 0 then
1712 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1716 if gCorpses
<> nil then
1717 for i
:= 0 to High(gCorpses
) do
1718 if gCorpses
[i
] <> nil then
1719 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1725 gCorpses
[i
].Update();
1728 if gShells
<> nil then
1729 for i
:= 0 to High(gShells
) do
1730 if gShells
[i
].alive
then
1734 mr
:= g_Obj_Move(@Obj
, True, False, True);
1735 positionChanged(); // this updates spatial accelerators
1737 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1743 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1744 if WordBool(mr
and MOVE_HITWALL
) then
1746 Obj
.Vel
.X
:= -(vel
.X
div 2);
1747 if not WordBool(mr
and MOVE_INWATER
) then
1748 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1750 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1752 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1753 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1754 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1756 if RAngle
mod 90 <> 0 then
1757 RAngle
:= (RAngle
div 90) * 90;
1759 else if not WordBool(mr
and MOVE_INWATER
) then
1760 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1763 if (Obj
.Vel
.X
>= 0) then
1765 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1766 if RAngle
>= 360 then
1767 RAngle
:= RAngle
mod 360;
1768 end else begin // Counter-clockwise
1769 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1771 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1777 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1779 x
:= Obj
.X
+Obj
.Rect
.X
;
1780 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1781 w
:= Obj
.Rect
.Width
;
1782 h
:= Obj
.Rect
.Height
;
1785 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1787 if (dx
<> 0) or (dy
<> 0) then
1796 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1800 w
:= Obj
.Rect
.Width
;
1801 h
:= Obj
.Rect
.Height
;
1804 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1806 if (dx
<> 0) or (dy
<> 0) then
1815 procedure TGib
.positionChanged (); inline; begin end;
1816 procedure TShell
.positionChanged (); inline; begin end;
1819 procedure g_Player_DrawCorpses();
1824 if gGibs
<> nil then
1825 for i
:= 0 to High(gGibs
) do
1826 if gGibs
[i
].alive
then
1829 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1832 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1833 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1835 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1838 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1844 if gCorpses
<> nil then
1845 for i
:= 0 to High(gCorpses
) do
1846 if gCorpses
[i
] <> nil then
1850 procedure g_Player_DrawShells();
1855 if gShells
<> nil then
1856 for i
:= 0 to High(gShells
) do
1857 if gShells
[i
].alive
then
1860 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1866 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1870 procedure g_Player_RemoveAllCorpses();
1876 SetLength(gGibs
, MaxGibs
);
1877 SetLength(gShells
, MaxGibs
);
1881 if gCorpses
<> nil then
1882 for i
:= 0 to High(gCorpses
) do
1886 SetLength(gCorpses
, MaxCorpses
);
1889 procedure g_Player_Corpses_SaveState (st
: TStream
);
1893 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ
1895 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1897 // Êîëè÷åñòâî òðóïîâ
1898 utils
.writeInt(st
, LongInt(count
));
1900 if (count
= 0) then exit
;
1903 for i
:= 0 to High(gCorpses
) do
1905 if gCorpses
[i
] <> nil then
1908 utils
.writeStr(st
, gCorpses
[i
].FModelName
);
1910 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1911 // Ñîõðàíÿåì äàííûå òðóïà:
1912 gCorpses
[i
].SaveState(st
);
1918 procedure g_Player_Corpses_LoadState (st
: TStream
);
1926 g_Player_RemoveAllCorpses();
1928 // Êîëè÷åñòâî òðóïîâ:
1929 count
:= utils
.readLongInt(st
);
1930 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1932 if (count
= 0) then exit
;
1935 for i
:= 0 to count
-1 do
1938 str
:= utils
.readStr(st
);
1940 b
:= utils
.readBool(st
);
1942 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1943 // Çàãðóæàåì äàííûå òðóïà
1944 gCorpses
[i
].LoadState(st
);
1951 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1953 procedure TPlayer
.BFGHit();
1955 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1956 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1957 if g_Game_IsServer
and g_Game_IsNet
then
1958 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1959 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1963 procedure TPlayer
.ChangeModel(ModelName
: string);
1965 locModel
: TPlayerModel
;
1967 locModel
:= g_PlayerModel_Get(ModelName
);
1968 if locModel
= nil then Exit
;
1974 procedure TPlayer
.SetModel(ModelName
: string);
1978 m
:= g_PlayerModel_Get(ModelName
);
1981 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1982 m
:= g_PlayerModel_Get('doomer');
1985 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1990 if FModel
<> nil then
1995 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1996 FModel
.Color
:= FColor
1998 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1999 FModel
.SetWeapon(FCurrWeap
);
2000 FModel
.SetFlag(FFlag
);
2001 SetDirection(FDirection
);
2004 procedure TPlayer
.SetColor(Color
: TRGB
);
2007 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2008 if FModel
<> nil then FModel
.Color
:= Color
;
2011 procedure TPlayer
.SwitchTeam
;
2013 if g_Game_IsClient
then
2015 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
2017 if gGameOn
and FAlive
then
2018 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
2020 if FTeam
= TEAM_RED
then
2022 ChangeTeam(TEAM_BLUE
);
2023 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
2024 if g_Game_IsNet
then
2025 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
2029 ChangeTeam(TEAM_RED
);
2030 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
2031 if g_Game_IsNet
then
2032 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
2034 FPreferredTeam
:= FTeam
;
2037 procedure TPlayer
.ChangeTeam(Team
: Byte);
2044 TEAM_RED
, TEAM_BLUE
:
2045 FModel
.Color
:= TEAMCOLOR
[Team
];
2047 FModel
.Color
:= FColor
;
2049 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2050 MH_SEND_PlayerStats(FUID
);
2054 procedure TPlayer.CollideItem();
2059 if gItems = nil then Exit;
2060 if not FAlive then Exit;
2062 for i := 0 to High(gItems) do
2065 if (ItemType <> ITEM_NONE) and alive then
2066 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2067 PLAYER_RECT.Height, @Obj) then
2069 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2071 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2072 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2073 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2074 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2075 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2077 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2078 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2079 (gGameSettings.GameType = GT_SINGLE) and
2080 (g_Player_GetCount() > 1)) then
2081 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2087 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2089 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2090 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2094 constructor TPlayer
.Create();
2100 mEDamageType
:= HIT_SOME
;
2106 FSawSound
:= TPlayableSound
.Create();
2107 FSawSoundIdle
:= TPlayableSound
.Create();
2108 FSawSoundHit
:= TPlayableSound
.Create();
2109 FSawSoundSelect
:= TPlayableSound
.Create();
2110 FJetSoundFly
:= TPlayableSound
.Create();
2111 FJetSoundOn
:= TPlayableSound
.Create();
2112 FJetSoundOff
:= TPlayableSound
.Create();
2114 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2115 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2116 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2117 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2118 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2119 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2120 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2122 FSpectatePlayer
:= -1;
2126 FSavedState
.WaitRecall
:= False;
2132 FActualModelName
:= 'doomer';
2135 FObj
.Rect
:= PLAYER_RECT
;
2137 FBFGFireCounter
:= -1;
2138 FJustTeleported
:= False;
2142 releaseAllWeaponSwitchKeys();
2146 procedure TPlayer
.releaseAllWeaponSwitchKeys ();
2150 for f
:= 0 to High(weaponSwitchKeyReleased
) do weaponSwitchKeyReleased
[f
] := $03;
2153 procedure TPlayer
.weaponSwitchKeysStateChange (index
: Integer; pressed
: Boolean);
2155 Inc(index
, 2); // -2: prev; -1: next
2156 if (index
< 0) or (index
> High(weaponSwitchKeyReleased
)) then exit
;
2157 weaponSwitchKeyReleased
[index
] := weaponSwitchKeyReleased
[index
] or $02;
2158 if (pressed
) then weaponSwitchKeyReleased
[index
] := weaponSwitchKeyReleased
[index
] xor $02;
2161 function TPlayer
.isWeaponSwitchKeyReleased (index
: Integer): Boolean;
2163 Inc(index
, 2); // -2: prev; -1: next
2164 if (index
< 0) or (index
> High(weaponSwitchKeyReleased
)) then
2170 result
:= (weaponSwitchKeyReleased
[index
] and $01) <> 0;
2174 procedure TPlayer
.weaponSwitchKeysShiftNewStates ();
2178 // copy bit 1 to bit 0
2179 for f
:= 0 to High(weaponSwitchKeyReleased
) do
2181 weaponSwitchKeyReleased
[f
] :=
2182 (weaponSwitchKeyReleased
[f
] and $02) or
2183 ((weaponSwitchKeyReleased
[f
] shr 1) and $01);
2188 procedure TPlayer
.positionChanged (); inline;
2192 procedure TPlayer
.doDamage (v
: Integer);
2194 if (v
<= 0) then exit
;
2195 if (v
> 32767) then v
:= 32767;
2196 Damage(v
, 0, 0, 0, mEDamageType
);
2199 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2203 if (not g_Game_IsClient
) and (not FAlive
) then
2208 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2209 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2211 if not g_Game_IsClient
then
2214 if t
= HIT_TRAP
then
2216 // Ëîâóøêà óáèâàåò ñðàçó:
2218 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2220 if t
= HIT_SELF
then
2224 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2227 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2228 FMegaRulez
[MR_SUIT
] := 0;
2229 FMegaRulez
[MR_INVUL
] := 0;
2230 FMegaRulez
[MR_INVIS
] := 0;
2234 // Íî îò îñòàëüíîãî ñïàñàåò:
2235 if FMegaRulez
[MR_INVUL
] >= gTime
then
2242 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2243 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2244 (SpawnerUID
= FUID
) or
2245 (not SameTeam(FUID
, SpawnerUID
)) then
2247 FLastSpawnerUID
:= SpawnerUID
;
2249 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2250 if gBloodCount
> 0 then
2252 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2253 if value
div 4 <= c
then
2254 c
:= c
- (value
div 4)
2258 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2262 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2263 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2266 if t
= HIT_WATER
then
2267 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2268 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2273 Inc(FDamageBuffer
, value
);
2277 FPain
:= FPain
+ value
;
2280 if g_Game_IsServer
and g_Game_IsNet
then
2282 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2283 MH_SEND_PlayerStats(FUID
);
2284 MH_SEND_PlayerPos(False, FUID
);
2288 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2291 if g_Game_IsClient
then
2296 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2298 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2301 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2303 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2307 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2308 MH_SEND_PlayerStats(FUID
);
2311 destructor TPlayer
.Destroy();
2313 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2315 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2319 FSawSoundIdle
.Free();
2320 FSawSoundHit
.Free();
2321 FJetSoundFly
.Free();
2323 FJetSoundOff
.Free();
2325 if FPunchAnim
<> nil then
2331 procedure TPlayer
.DrawIndicator();
2333 indX
, indY
: Integer;
2339 indX
:= FObj
.X
+FObj
.Rect
.X
;
2340 indY
:= FObj
.Y
- 12;
2341 if g_Texture_Get('TEXTURE_PLAYER_INDICATOR', ID
) then
2343 e_GetTextureSize(ID
, @indW
, @indH
);
2344 e_Draw(ID
, indX
+ indW
div 2, indY
, 0, True, False);
2347 //e_TextureFontPrint(indX, indY, FName, gStdFont); // Shows player name overhead
2350 procedure TPlayer
.DrawBubble();
2352 bubX
, bubY
: Integer;
2355 Rw
, Gw
, Bw
: SmallInt;
2358 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= TDirection
.D_LEFT
, -4, 18);
2359 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2367 1: // simple textual non-bubble
2369 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2370 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2371 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2374 2: // advanced pixel-perfect bubble
2376 if FTeam
= TEAM_RED
then
2379 if FTeam
= TEAM_BLUE
then
2382 3: // colored bubble
2384 Rb
:= FModel
.Color
.R
;
2385 Gb
:= FModel
.Color
.G
;
2386 Bb
:= FModel
.Color
.B
;
2387 Rw
:= Min(Rb
* 2 + 64, 255);
2388 Gw
:= Min(Gb
* 2 + 64, 255);
2389 Bw
:= Min(Bb
* 2 + 64, 255);
2390 if (Abs(Rw
- Rb
) < 32)
2391 or (Abs(Gw
- Gb
) < 32)
2392 or (Abs(Bw
- Bb
) < 32) then
2394 Rb
:= Max(Rw
div 2 - 16, 0);
2395 Gb
:= Max(Gw
div 2 - 16, 0);
2396 Bb
:= Max(Bw
div 2 - 16, 0);
2399 4: // custom textured bubble
2401 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2402 if FDirection
= TDirection
.D_RIGHT
then
2403 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2405 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, TMirrorType
.Horizontal
);
2411 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2412 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2414 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2417 Dot
:= IfThen(FDirection
= TDirection
.D_LEFT
, 14, 5);
2418 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2419 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
);
2420 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
);
2421 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
);
2422 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
);
2426 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2427 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2428 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2431 procedure TPlayer
.Draw();
2436 Mirror
: TMirrorType
;
2440 if Direction
= TDirection
.D_RIGHT
then
2441 Mirror
:= TMirrorType
.None
2443 Mirror
:= TMirrorType
.Horizontal
;
2445 if FPunchAnim
<> nil then
2447 FPunchAnim
.Draw(FObj
.X
+IfThen(Direction
= TDirection
.D_LEFT
, 15-FObj
.Rect
.X
, FObj
.Rect
.X
-15),
2448 FObj
.Y
+FObj
.Rect
.Y
-11, Mirror
);
2449 if FPunchAnim
.played
then
2456 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2457 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2459 e_GetTextureSize(ID
, @w
, @h
);
2460 if FDirection
= TDirection
.D_LEFT
then
2461 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2462 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False)
2464 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2465 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False);
2468 if FMegaRulez
[MR_INVIS
] > gTime
then
2470 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2471 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2473 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2474 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2478 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 200)
2480 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2483 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 254);
2486 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2489 if g_debug_Frames
then
2491 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2493 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2494 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2498 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2500 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2501 if gAimLine
and alive
and
2502 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2507 procedure TPlayer
.DrawAim();
2508 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2513 {$IFDEF ENABLE_HOLMES}
2514 if isValidViewPort
and (self
= gPlayer1
) then
2516 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2520 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2521 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2523 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2527 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2532 wx
, wy
, xx
, yy
: Integer;
2536 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= TDirection
.D_LEFT
, 7, -7);
2537 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2546 1: begin // Chainsaw
2553 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2554 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2555 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2556 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2561 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2562 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2563 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2564 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2566 4: begin // Double Shotgun
2569 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2570 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2571 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2572 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2574 5: begin // Chaingun
2577 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2578 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2579 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2580 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2582 6: begin // Rocket Launcher
2585 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2586 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2587 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2588 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2590 7: begin // Plasmagun
2593 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2594 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2595 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2596 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2601 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2602 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2603 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2604 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2606 9: begin // Super Chaingun
2609 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2610 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2611 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2612 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2615 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2616 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2617 {$IF DEFINED(D2F_DEBUG)}
2618 drawCast(sz
, wx
, wy
, xx
, yy
);
2620 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2624 procedure TPlayer
.DrawGUI();
2627 X
, Y
, SY
, a
, p
, m
: Integer;
2631 stat
: TPlayerStatArray
;
2633 X
:= gPlayerScreenSize
.X
;
2634 SY
:= gPlayerScreenSize
.Y
;
2637 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2639 if gGameSettings
.GameMode
= GM_CTF
then
2643 if gGameSettings
.GameMode
= GM_CTF
then
2645 s
:= 'TEXTURE_PLAYER_REDFLAG';
2646 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2647 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2648 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2649 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2650 if g_Texture_Get(s
, ID
) then
2651 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2654 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2655 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2656 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2658 if gGameSettings
.GameMode
= GM_CTF
then
2660 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2661 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2662 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2663 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2664 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2665 if g_Texture_Get(s
, ID
) then
2666 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2669 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2670 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2671 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2674 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2675 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2678 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2679 e_Draw(ID
, X
+2, Y
, 0, True, False);
2681 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2685 s
:= IntToStr(Frags
);
2686 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2687 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2692 stat
:= g_Player_GetStats();
2697 for a
:= 0 to High(stat
) do
2698 if stat
[a
].Name
<> Name
then
2700 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2701 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2705 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2706 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2707 s
:= s
+IntToStr(Abs(Frags
-m
));
2709 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2710 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2713 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2715 s
:= IntToStr(Lives
);
2716 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2717 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2721 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2722 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2724 if R_BERSERK
in FRulez
then
2725 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2727 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2729 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2730 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2732 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2733 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2734 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2736 s
:= IntToStr(FArmor
);
2737 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2738 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2740 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2746 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2751 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2753 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2754 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2755 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2756 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2757 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2758 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2759 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2760 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2761 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2764 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2765 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2766 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2768 if R_KEY_RED
in FRulez
then
2769 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2771 if R_KEY_GREEN
in FRulez
then
2772 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2774 if R_KEY_BLUE
in FRulez
then
2775 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2777 if FJetFuel
> 0 then
2779 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2780 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2781 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2782 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2783 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2784 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2788 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2789 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2790 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2793 if gShowPing
and g_Game_IsClient
then
2795 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2796 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2802 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2803 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2804 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2807 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2808 s
:= _lc
[I_PLAYER_SPECT4
];
2809 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2810 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2811 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2817 procedure TPlayer
.DrawRulez();
2821 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2822 if FMegaRulez
[MR_INVUL
] >= gTime
then
2824 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2825 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2830 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2831 191, 191, 191, 0, TBlending
.Invert
);
2834 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2835 if FMegaRulez
[MR_SUIT
] >= gTime
then
2837 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2838 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2843 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2844 0, 96, 0, 200, TBlending
.None
);
2847 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2848 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2850 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2851 255, 0, 0, 200, TBlending
.None
);
2855 procedure TPlayer
.DrawPain();
2859 if FPain
= 0 then Exit
;
2863 if a
< 15 then h
:= 0
2864 else if a
< 35 then h
:= 1
2865 else if a
< 55 then h
:= 2
2866 else if a
< 75 then h
:= 3
2867 else if a
< 95 then h
:= 4
2870 //if a > 255 then a := 255;
2872 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2873 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2876 procedure TPlayer
.DrawPickup();
2880 if FPickup
= 0 then Exit
;
2884 if a
< 15 then h
:= 1
2885 else if a
< 35 then h
:= 2
2886 else if a
< 55 then h
:= 3
2887 else if a
< 75 then h
:= 4
2890 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2893 procedure TPlayer
.DoPunch();
2898 if FPunchAnim
<> nil then begin
2903 st
:= 'FRAMES_PUNCH';
2904 if R_BERSERK
in FRulez
then
2905 st
:= st
+ '_BERSERK';
2906 if FKeys
[KEY_UP
].Pressed
then
2908 else if FKeys
[KEY_DOWN
].Pressed
then
2910 g_Frames_Get(id
, st
);
2911 FPunchAnim
:= TAnimation
.Create(id
, False, 1);
2914 procedure TPlayer
.Fire();
2916 f
, DidFire
: Boolean;
2917 wx
, wy
, xd
, yd
: Integer;
2920 if g_Game_IsClient
then Exit
;
2921 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2922 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2930 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2935 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2936 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2937 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
2938 yd
:= wy
+firediry();
2944 if R_BERSERK
in FRulez
then
2946 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2947 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2948 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2951 locobj
.rect
.Width
:= 39;
2952 locobj
.rect
.Height
:= 52;
2953 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2954 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2955 locobj
.Accel
.X
:= xd
-wx
;
2956 locobj
.Accel
.y
:= yd
-wy
;
2958 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2959 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2961 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2963 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
2967 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2971 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2976 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2977 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2979 FSawSoundSelect
.Stop();
2981 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2983 else if not FSawSoundHit
.IsPlaying() then
2985 FSawSoundSelect
.Stop();
2986 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2989 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2995 if FAmmo
[A_BULLETS
] > 0 then
2997 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2998 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2999 Dec(FAmmo
[A_BULLETS
]);
3000 FFireAngle
:= FAngle
;
3003 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3004 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3008 if FAmmo
[A_SHELLS
] > 0 then
3010 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3011 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
3012 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3013 Dec(FAmmo
[A_SHELLS
]);
3014 FFireAngle
:= FAngle
;
3018 FShellType
:= SHELL_SHELL
;
3022 if FAmmo
[A_SHELLS
] >= 2 then
3024 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
3025 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3026 Dec(FAmmo
[A_SHELLS
], 2);
3027 FFireAngle
:= FAngle
;
3031 FShellType
:= SHELL_DBLSHELL
;
3035 if FAmmo
[A_BULLETS
] > 0 then
3037 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
3038 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
3039 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3040 Dec(FAmmo
[A_BULLETS
]);
3041 FFireAngle
:= FAngle
;
3044 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3045 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3048 WEAPON_ROCKETLAUNCHER
:
3049 if FAmmo
[A_ROCKETS
] > 0 then
3051 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
3052 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3053 Dec(FAmmo
[A_ROCKETS
]);
3054 FFireAngle
:= FAngle
;
3060 if FAmmo
[A_CELLS
] > 0 then
3062 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
3063 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3064 Dec(FAmmo
[A_CELLS
]);
3065 FFireAngle
:= FAngle
;
3071 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
3073 FBFGFireCounter
:= 17;
3074 if not FNoReload
then
3075 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
3076 Dec(FAmmo
[A_CELLS
], 40);
3080 WEAPON_SUPERPULEMET
:
3081 if FAmmo
[A_SHELLS
] > 0 then
3083 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3084 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
3085 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3086 Dec(FAmmo
[A_SHELLS
]);
3087 FFireAngle
:= FAngle
;
3090 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3091 GameVelX
, GameVelY
-2, SHELL_SHELL
);
3094 WEAPON_FLAMETHROWER
:
3095 if FAmmo
[A_FUEL
] > 0 then
3097 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
3098 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3100 FFireAngle
:= FAngle
;
3106 if g_Game_IsNet
then
3110 if FCurrWeap
<> WEAPON_BFG
then
3111 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
3113 if not FNoReload
then
3114 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
3117 MH_SEND_PlayerStats(FUID
);
3122 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
3123 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
3124 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
3127 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
3130 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
3131 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
3132 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
3133 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
3134 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
3139 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
3141 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
3142 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
3143 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
3146 procedure TPlayer
.JetpackOn
;
3150 FJetSoundOn
.SetPosition(0);
3151 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3155 procedure TPlayer
.JetpackOff
;
3159 FJetSoundOff
.SetPosition(0);
3160 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3163 procedure TPlayer
.CatchFire(Attacker
: Word);
3166 FFireAttacker
:= Attacker
;
3167 if g_Game_IsNet
and g_Game_IsServer
then
3168 MH_SEND_PlayerStats(FUID
);
3171 procedure TPlayer
.Jump();
3173 if gFly
or FJetpack
then
3175 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3176 if FObj
.Vel
.Y
> -VEL_FLY
then
3177 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3180 if FJetFuel
> 0 then
3182 if (FJetFuel
< 1) and g_Game_IsServer
then
3186 if g_Game_IsNet
then
3187 MH_SEND_PlayerStats(FUID
);
3193 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3195 FCanJetpack
:= False;
3197 // Ïðûãàåì èëè âñïëûâàåì:
3198 if (CollideLevel(0, 1) or
3199 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3200 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3201 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3203 FObj
.Vel
.Y
:= -VEL_JUMP
;
3204 FCanJetpack
:= False;
3208 if BodyInLiquid(0, 0) then
3209 FObj
.Vel
.Y
:= -VEL_SW
3210 else if (FJetFuel
> 0) and FCanJetpack
and
3211 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3215 if g_Game_IsNet
then
3216 MH_SEND_PlayerStats(FUID
);
3221 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3223 a
, i
, k
, ab
, ar
: Byte;
3227 srv
, netsrv
: Boolean;
3233 procedure PushItem(t
: Byte);
3237 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3238 it
:= g_Items_ByIdx(id
);
3239 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3241 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3242 (FObj
.Vel
.Y
div 2)-Random(9));
3243 it
.positionChanged(); // this updates spatial accelerators
3247 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3249 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3250 (FObj
.Vel
.Y
div 2)-Random(6));
3252 else // -3..+3; -3..0
3254 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3255 (FObj
.Vel
.Y
div 2)-Random(4));
3257 it
.positionChanged(); // this updates spatial accelerators
3260 if g_Game_IsNet
and g_Game_IsServer
then
3261 MH_SEND_ItemSpawn(True, id
);
3265 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3266 Srv
:= g_Game_IsServer
;
3267 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3268 if Srv
then FDeath
:= FDeath
+ 1;
3273 if not FPhysics
then
3279 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3281 if FLives
> 0 then FLives
:= FLives
- 1;
3282 if FLives
= 0 then FNoRespawn
:= True;
3285 // Íîìåð òèïà ñìåðòè:
3288 K_SIMPLEKILL
: a
:= 1;
3290 K_EXTRAHARDKILL
: a
:= 3;
3295 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3297 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3304 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3306 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3307 K_EXTRAHARDKILL
, K_FALLKILL
:
3308 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3311 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3315 K_HARDKILL
, K_EXTRAHARDKILL
:
3319 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3320 if (KillType
<> K_FALLKILL
) and (Srv
) then
3321 g_Monsters_killedp();
3323 if SpawnerUID
= FUID
then
3325 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3330 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3333 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3334 begin // Óáèò äðóãèì èãðîêîì
3335 KP
:= g_Player_Get(SpawnerUID
);
3336 if (KP
<> nil) and Srv
then
3338 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3339 if SameTeam(FUID
, SpawnerUID
) then
3349 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3350 Inc(gTeamStat
[KP
.Team
].Goals
,
3351 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3353 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3356 plr
:= g_Player_Get(SpawnerUID
);
3364 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3368 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3372 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3377 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3378 begin // Óáèò ìîíñòðîì
3379 mon
:= g_Monsters_ByUID(SpawnerUID
);
3383 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
3387 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3391 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3395 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3400 else // Îñîáûå òèïû ñìåðòè
3403 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3404 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3405 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3406 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3407 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3408 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3414 for a
:= WP_FIRST
to WP_LAST
do
3418 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3419 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3420 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3421 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3422 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3423 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3424 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3425 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3426 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3435 if R_ITEM_BACKPACK
in FRulez
then
3436 PushItem(ITEM_AMMO_BACKPACK
);
3438 // Âûáðîñ ðàêåòíîãî ðàíöà:
3439 if FJetFuel
> 0 then
3440 PushItem(ITEM_JETPACK
);
3443 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3445 if R_KEY_RED
in FRulez
then
3446 PushItem(ITEM_KEY_RED
);
3448 if R_KEY_GREEN
in FRulez
then
3449 PushItem(ITEM_KEY_GREEN
);
3451 if R_KEY_BLUE
in FRulez
then
3452 PushItem(ITEM_KEY_BLUE
);
3459 g_Player_CreateCorpse(Self
);
3461 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3462 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3468 for i
:= Low(gPlayers
) to High(gPlayers
) do
3470 if gPlayers
[i
] = nil then continue
;
3471 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3474 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3475 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3480 OldLR
:= gLMSRespawn
;
3481 if (gGameSettings
.GameMode
= GM_COOP
) then
3485 // everyone is dead, restart the map
3486 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3488 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3489 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3490 gLMSRespawnTime
:= gTime
+ 5000;
3492 else if (a
= 1) then
3494 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3495 if (gPlayers
[k
] = gPlayer1
) or
3496 (gPlayers
[k
] = gPlayer2
) then
3497 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3498 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3499 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3502 else if (gGameSettings
.GameMode
= GM_TDM
) then
3504 if (ab
= 0) and (ar
<> 0) then
3507 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3509 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3510 Inc(gTeamStat
[TEAM_RED
].Goals
);
3511 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3512 gLMSRespawnTime
:= gTime
+ 5000;
3514 else if (ar
= 0) and (ab
<> 0) then
3517 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3519 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3520 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3521 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3522 gLMSRespawnTime
:= gTime
+ 5000;
3524 else if (ar
= 0) and (ab
= 0) then
3527 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3529 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3530 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3531 gLMSRespawnTime
:= gTime
+ 5000;
3534 else if (gGameSettings
.GameMode
= GM_DM
) then
3538 if gPlayers
[k
] <> nil then
3541 // survivor is the winner
3542 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3544 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3547 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3548 gLMSRespawnTime
:= gTime
+ 5000;
3550 else if (a
= 0) then
3552 // everyone is dead, restart the map
3553 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3555 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3556 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3557 gLMSRespawnTime
:= gTime
+ 5000;
3560 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3562 if NetMode
= NET_SERVER
then
3563 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3565 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3571 MH_SEND_PlayerStats(FUID
);
3572 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3573 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3576 if srv
and FNoRespawn
then Spectate(True);
3577 FWantsInGame
:= True;
3580 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3582 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3583 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3586 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3588 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3589 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3592 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3594 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3595 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3596 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3597 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3598 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3599 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3600 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3601 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3604 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3606 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3607 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3608 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3609 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3612 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3614 //if g_Game_IsClient then Exit;
3615 if Weapon
> High(FWeapon
) then Exit
;
3616 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3619 procedure TPlayer
.resetWeaponQueue ();
3622 FNextWeapDelay
:= 0;
3625 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3629 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3630 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
3631 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
3632 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3633 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3634 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3635 else result
:= (weapon
< length(FWeapon
));
3639 // return 255 for "no switch"
3640 function TPlayer
.getNextWeaponIndex (): Byte;
3643 wantThisWeapon
: array[0..64] of Boolean;
3644 weaponOrder
: array[0..16] of Integer; // value: index in `FWeapon`
3646 f
, dir
, cwi
, rwidx
, curlidx
: Integer;
3648 function real2log (ridx
: Integer): Integer;
3654 for f
:= 0 to High(weaponOrder
) do if (weaponOrder
[f
] = ridx
) then begin result
:= f
; exit
; end;
3660 result
:= 255; // default result: "no switch"
3662 // had weapon cycling on previous frame? remove that flag
3663 if (FNextWeap
and $2000) <> 0 then
3665 FNextWeap
:= FNextWeap
and $1FFF;
3666 FNextWeapDelay
:= 0;
3669 for f
:= 0 to High(weaponOrder
) do weaponOrder
[f
] := -1;
3671 // build weapon order (k8: i know, i know, learn how to do constants and such... gtfo, please!)
3672 // two knuckles are for "normal" and "berserk" (see `if` below -- it removes the one that is not needed)
3674 // bfg, launcher, plasma, flamethrower, ssg, minigun, sg, pistol, berserk, chainsaw, fist
3675 weaponOrder
[0] := WEAPON_SUPERPULEMET
;
3676 weaponOrder
[1] := WEAPON_BFG
;
3677 weaponOrder
[2] := WEAPON_ROCKETLAUNCHER
;
3678 weaponOrder
[3] := WEAPON_PLASMA
;
3679 weaponOrder
[4] := WEAPON_FLAMETHROWER
;
3680 weaponOrder
[5] := WEAPON_SHOTGUN2
;
3681 weaponOrder
[6] := WEAPON_CHAINGUN
;
3682 weaponOrder
[7] := WEAPON_SHOTGUN1
;
3683 weaponOrder
[8] := WEAPON_PISTOL
;
3684 weaponOrder
[9] := WEAPON_KASTET
+666; // berserk fist
3685 weaponOrder
[10] := WEAPON_SAW
;
3686 weaponOrder
[11] := WEAPON_KASTET
; // normal fist
3688 for f
:= 0 to High(weaponOrder
) do
3690 if (weaponOrder
[f
] = WEAPON_KASTET
) then
3692 // normal fist: remove if we have a berserk pack
3693 if (R_BERSERK
in FRulez
) then weaponOrder
[f
] := -1;
3696 if (weaponOrder
[f
] = WEAPON_KASTET
+666) then
3698 // berserk fist: remove if we don't have a berserk pack
3699 if (R_BERSERK
in FRulez
) then weaponOrder
[f
] := WEAPON_KASTET
else weaponOrder
[f
] := -1;
3707 WEAPON_SHOTGUN1 = 3;
3708 WEAPON_SHOTGUN2 = 4;
3709 WEAPON_CHAINGUN = 5;
3710 WEAPON_ROCKETLAUNCHER = 6;
3713 WEAPON_SUPERPULEMET = 9;
3714 WEAPON_FLAMETHROWER = 10;
3717 // cycling has priority
3718 if (FNextWeap
and $C000) <> 0 then
3720 if (FNextWeap
and $8000) <> 0 then dir
:= 1 else dir
:= -1; // should be reversed if we want "priority-driven cycling"
3721 FNextWeap
:= FNextWeap
or $2000; // we need this
3722 if FNextWeapDelay
> 0 then exit
; // cooldown time
3723 //cwi := real2log(FCurrWeap);
3724 //if (cwi < 0) then cwi := 0;
3726 for i
:= 0 to High(FWeapon
) do
3728 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3729 //rwidx := weaponOrder[cwi];
3730 rwidx
:= cwi
; // sorry
3731 if (rwidx
< 0) then continue
;
3732 if FWeapon
[rwidx
] then
3734 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d (dir=%d; log=%d)', [FCurrWeap, rwidx, dir, cwi]), TMsgType.Warning);
3735 result
:= Byte(rwidx
);
3736 //FNextWeapDelay := 10; //k8: not needed anymore
3745 for i
:= 0 to High(wantThisWeapon
) do wantThisWeapon
[i
] := false;
3748 curlidx
:= -1; // start from a weapon with a highest priority (-1, 'cause loop will immediately increment this index)
3750 for i
:= 0 to High(FWeapon
) do
3752 if (FNextWeap
and (1 shl i
)) <> 0 then
3757 wantThisWeapon
[cwi
] := true;
3759 // if we hit currently selected weapon, start seachring from it, so we'll get "next weaker" weapon
3760 if (i
= FCurrWeap
) then curlidx
:= cwi
; // compare real, start from logical
3765 // slow down alterations a little
3768 // more than one weapon requested, assume "alteration", and check alteration delay
3769 if FNextWeapDelay
> 0 then
3771 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), TMsgType.Warning);
3777 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3778 // but clear all counters if no weapon should be switched
3785 //e_WriteLog(Format('*** wwc=%d; currweap=%d; logweap=%d', [wwc, FCurrWeap, curlidx]), TMsgType.Warning);
3787 // find next weapon to switch onto
3789 for i
:= 0 to High(weaponOrder
) do
3791 cwi
:= (cwi
+length(weaponOrder
)+1) mod length(weaponOrder
);
3792 if (cwi
= curlidx
) then continue
; // skip current weapon
3793 if not wantThisWeapon
[cwi
] then continue
;
3794 rwidx
:= weaponOrder
[cwi
];
3795 if (rwidx
< 0) then continue
;
3796 //e_WriteLog(Format(' trying logical %d (real %d); has=%d, hasammo=%d', [cwi, rwidx, Integer(FWeapon[rwidx]), Integer(hasAmmoForWeapon(rwidx))]), TMsgType.Warning);
3797 if FWeapon
[rwidx
] and ((wwc
= 1) or hasAmmoForWeapon(rwidx
)) then
3799 //e_WriteLog(' I FOUND HER!', TMsgType.Warning);
3801 result
:= Byte(rwidx
);
3803 //FNextWeapDelay := 10; // anyway, 'cause why not; k8: not needed anymore
3808 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3812 procedure TPlayer
.RealizeCurrentWeapon();
3813 function switchAllowed (): Boolean;
3818 if FBFGFireCounter
<> -1 then
3820 if FTime
[T_SWITCH
] > gTime
then
3822 for i
:= WP_FIRST
to WP_LAST
do
3823 if FReloading
[i
] > 0 then
3831 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3832 //FNextWeap := FNextWeap and $1FFF;
3833 //HACK: alteration delay will be reset when player released any weapon switch key
3834 FNextWeapDelay
:= 0; //k8: just in case
3835 //if FNextWeapDelay > 0 then Dec(FNextWeapDelay); // "alteration delay"
3837 if not switchAllowed
then
3839 //HACK for weapon cycling
3840 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3844 nw
:= getNextWeaponIndex();
3845 if nw
= 255 then exit
; // don't reset anything here
3846 if nw
> High(FWeapon
) then
3848 // don't forget to reset queue here!
3849 //e_WriteLog(Format(' RealizeCurrentWeapon: WUTAFUUUU?! (%d)', [nw]), TMsgType.Warning);
3857 FTime
[T_SWITCH
] := gTime
+156;
3858 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3859 FModel
.SetWeapon(FCurrWeap
);
3860 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3864 procedure TPlayer
.NextWeapon();
3866 //if g_Game_IsClient then Exit;
3870 procedure TPlayer
.PrevWeapon();
3872 //if g_Game_IsClient then Exit;
3876 procedure TPlayer
.SetWeapon(W
: Byte);
3878 if FCurrWeap
<> W
then
3879 if W
= WEAPON_SAW
then
3880 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3883 FModel
.SetWeapon(CurrWeap
);
3887 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3889 function allowBerserkSwitching (): Boolean;
3891 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3893 if gBerserkAutoswitch
then exit
;
3894 if not conIsCheatsEnabled
then exit
;
3902 if g_Game_IsClient
then Exit
;
3904 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3905 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3910 if FHealth
< PLAYER_HP_SOFT
then
3912 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3916 if gFlash
= 2 then Inc(FPickup
, 5);
3920 if FHealth
< PLAYER_HP_SOFT
then
3922 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3926 if gFlash
= 2 then Inc(FPickup
, 5);
3930 if FArmor
< PLAYER_AP_SOFT
then
3932 FArmor
:= PLAYER_AP_SOFT
;
3935 if gFlash
= 2 then Inc(FPickup
, 5);
3939 if FArmor
< PLAYER_AP_LIMIT
then
3941 FArmor
:= PLAYER_AP_LIMIT
;
3944 if gFlash
= 2 then Inc(FPickup
, 5);
3948 if FHealth
< PLAYER_HP_LIMIT
then
3950 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3954 if gFlash
= 2 then Inc(FPickup
, 5);
3958 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3960 if FHealth
< PLAYER_HP_LIMIT
then
3961 FHealth
:= PLAYER_HP_LIMIT
;
3962 if FArmor
< PLAYER_AP_LIMIT
then
3963 FArmor
:= PLAYER_AP_LIMIT
;
3967 if gFlash
= 2 then Inc(FPickup
, 5);
3971 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3973 FWeapon
[WEAPON_SAW
] := True;
3975 if gFlash
= 2 then Inc(FPickup
, 5);
3976 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3979 ITEM_WEAPON_SHOTGUN1
:
3980 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3982 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3983 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3985 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3986 FWeapon
[WEAPON_SHOTGUN1
] := True;
3988 if gFlash
= 2 then Inc(FPickup
, 5);
3989 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3992 ITEM_WEAPON_SHOTGUN2
:
3993 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3995 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3997 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3998 FWeapon
[WEAPON_SHOTGUN2
] := True;
4000 if gFlash
= 2 then Inc(FPickup
, 5);
4001 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4004 ITEM_WEAPON_CHAINGUN
:
4005 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
4007 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
4009 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4010 FWeapon
[WEAPON_CHAINGUN
] := True;
4012 if gFlash
= 2 then Inc(FPickup
, 5);
4013 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4016 ITEM_WEAPON_ROCKETLAUNCHER
:
4017 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
4019 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
4021 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
4022 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
4024 if gFlash
= 2 then Inc(FPickup
, 5);
4025 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4029 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
4031 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
4033 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4034 FWeapon
[WEAPON_PLASMA
] := True;
4036 if gFlash
= 2 then Inc(FPickup
, 5);
4037 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4041 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
4043 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
4045 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4046 FWeapon
[WEAPON_BFG
] := True;
4048 if gFlash
= 2 then Inc(FPickup
, 5);
4049 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4052 ITEM_WEAPON_SUPERPULEMET
:
4053 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
4055 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
4057 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4058 FWeapon
[WEAPON_SUPERPULEMET
] := True;
4060 if gFlash
= 2 then Inc(FPickup
, 5);
4061 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4064 ITEM_WEAPON_FLAMETHROWER
:
4065 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
4067 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
4069 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4070 FWeapon
[WEAPON_FLAMETHROWER
] := True;
4072 if gFlash
= 2 then Inc(FPickup
, 5);
4073 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4077 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4079 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4082 if gFlash
= 2 then Inc(FPickup
, 5);
4085 ITEM_AMMO_BULLETS_BOX
:
4086 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4088 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4091 if gFlash
= 2 then Inc(FPickup
, 5);
4095 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4097 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4100 if gFlash
= 2 then Inc(FPickup
, 5);
4103 ITEM_AMMO_SHELLS_BOX
:
4104 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4106 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
4109 if gFlash
= 2 then Inc(FPickup
, 5);
4113 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4115 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4118 if gFlash
= 2 then Inc(FPickup
, 5);
4121 ITEM_AMMO_ROCKET_BOX
:
4122 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4124 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
4127 if gFlash
= 2 then Inc(FPickup
, 5);
4131 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4133 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4136 if gFlash
= 2 then Inc(FPickup
, 5);
4140 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4142 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4145 if gFlash
= 2 then Inc(FPickup
, 5);
4149 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4151 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4154 if gFlash
= 2 then Inc(FPickup
, 5);
4158 if not(R_ITEM_BACKPACK
in FRulez
) or
4159 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4160 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4161 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4162 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4163 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
4165 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4166 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4167 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4168 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4169 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4171 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4172 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4173 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4174 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4175 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4176 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4177 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4178 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4180 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
4183 if gFlash
= 2 then Inc(FPickup
, 5);
4187 if not(R_KEY_RED
in FRulez
) then
4189 Include(FRulez
, R_KEY_RED
);
4191 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4192 if gFlash
= 2 then Inc(FPickup
, 5);
4193 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4197 if not(R_KEY_GREEN
in FRulez
) then
4199 Include(FRulez
, R_KEY_GREEN
);
4201 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4202 if gFlash
= 2 then Inc(FPickup
, 5);
4203 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4207 if not(R_KEY_BLUE
in FRulez
) then
4209 Include(FRulez
, R_KEY_BLUE
);
4211 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4212 if gFlash
= 2 then Inc(FPickup
, 5);
4213 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4217 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4219 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4223 if gFlash
= 2 then Inc(FPickup
, 5);
4227 if FAir
< AIR_MAX
then
4232 if gFlash
= 2 then Inc(FPickup
, 5);
4237 if not (R_BERSERK
in FRulez
) then
4239 Include(FRulez
, R_BERSERK
);
4240 if allowBerserkSwitching
then
4242 FCurrWeap
:= WEAPON_KASTET
;
4244 FModel
.SetWeapon(WEAPON_KASTET
);
4249 if gFlash
= 2 then Inc(FPickup
, 5);
4251 FBerserk
:= gTime
+30000;
4255 //k8:do we need it? if g_Game_IsNet and g_Game_IsServer then MH_SEND_PlayerStats(FUID);
4257 if FHealth
< PLAYER_HP_SOFT
then
4259 FHealth
:= PLAYER_HP_SOFT
;
4260 FBerserk
:= gTime
+30000;
4268 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4270 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4273 if gFlash
= 2 then Inc(FPickup
, 5);
4277 if FHealth
< PLAYER_HP_LIMIT
then
4279 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4283 if gFlash
= 2 then Inc(FPickup
, 5);
4287 if FArmor
< PLAYER_AP_LIMIT
then
4289 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4292 if gFlash
= 2 then Inc(FPickup
, 5);
4296 if FJetFuel
< JET_MAX
then
4298 FJetFuel
:= JET_MAX
;
4301 if gFlash
= 2 then Inc(FPickup
, 5);
4305 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4307 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4310 if gFlash
= 2 then Inc(FPickup
, 5);
4315 procedure TPlayer
.Touch();
4319 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4322 // Áðîñèòü ôëàã òîâàðèùó:
4323 if gGameSettings
.GameMode
= GM_CTF
then
4328 procedure TPlayer
.Push(vx
, vy
: Integer);
4330 if (not FPhysics
) and FGhost
then
4332 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4333 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4334 if g_Game_IsNet
and g_Game_IsServer
then
4335 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4338 procedure TPlayer
.Reset(Force
: Boolean);
4344 FTime
[T_RESPAWN
] := 0;
4345 FTime
[T_FLAGCAP
] := 0;
4358 FSpectator
:= False;
4361 FSpectatePlayer
:= -1;
4362 FNoRespawn
:= False;
4364 FLives
:= gGameSettings
.MaxLives
;
4369 procedure TPlayer
.SoftReset();
4375 FBFGFireCounter
:= -1;
4383 SetAction(A_STAND
, True);
4386 function TPlayer
.GetRespawnPoint(): Byte;
4391 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4393 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4394 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4396 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4398 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4399 if Self
= gPlayer1
then
4400 c
:= RESPAWNPOINT_PLAYER1
4402 c
:= RESPAWNPOINT_PLAYER2
;
4403 if g_Map_GetPointCount(c
) > 0 then
4409 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4410 if Self
= gPlayer1
then
4411 c
:= RESPAWNPOINT_PLAYER2
4413 c
:= RESPAWNPOINT_PLAYER1
;
4414 if g_Map_GetPointCount(c
) > 0 then
4421 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4422 if Random(2) = 0 then
4423 c
:= RESPAWNPOINT_PLAYER1
4425 c
:= RESPAWNPOINT_PLAYER2
;
4426 if g_Map_GetPointCount(c
) > 0 then
4433 // Òî÷êà ëþáîé èç êîìàíä
4434 if Random(2) = 0 then
4435 c
:= RESPAWNPOINT_RED
4437 c
:= RESPAWNPOINT_BLUE
;
4438 if g_Map_GetPointCount(c
) > 0 then
4445 c
:= RESPAWNPOINT_DM
;
4446 if g_Map_GetPointCount(c
) > 0 then
4454 if gGameSettings
.GameMode
= GM_DM
then
4457 c
:= RESPAWNPOINT_DM
;
4458 if g_Map_GetPointCount(c
) > 0 then
4464 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4465 if Random(2) = 0 then
4466 c
:= RESPAWNPOINT_PLAYER1
4468 c
:= RESPAWNPOINT_PLAYER2
;
4469 if g_Map_GetPointCount(c
) > 0 then
4475 // Òî÷êà ëþáîé èç êîìàíä
4476 if Random(2) = 0 then
4477 c
:= RESPAWNPOINT_RED
4479 c
:= RESPAWNPOINT_BLUE
;
4480 if g_Map_GetPointCount(c
) > 0 then
4488 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4490 // Òî÷êà ñâîåé êîìàíäû
4491 c
:= RESPAWNPOINT_DM
;
4492 if FTeam
= TEAM_RED
then
4493 c
:= RESPAWNPOINT_RED
;
4494 if FTeam
= TEAM_BLUE
then
4495 c
:= RESPAWNPOINT_BLUE
;
4496 if g_Map_GetPointCount(c
) > 0 then
4503 c
:= RESPAWNPOINT_DM
;
4504 if g_Map_GetPointCount(c
) > 0 then
4510 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4511 if Random(2) = 0 then
4512 c
:= RESPAWNPOINT_PLAYER1
4514 c
:= RESPAWNPOINT_PLAYER2
;
4515 if g_Map_GetPointCount(c
) > 0 then
4521 // Òî÷êà äðóãîé êîìàíäû
4522 c
:= RESPAWNPOINT_DM
;
4523 if FTeam
= TEAM_RED
then
4524 c
:= RESPAWNPOINT_BLUE
;
4525 if FTeam
= TEAM_BLUE
then
4526 c
:= RESPAWNPOINT_RED
;
4527 if g_Map_GetPointCount(c
) > 0 then
4535 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4537 RespawnPoint
: TRespawnPoint
;
4543 FBFGFireCounter
:= -1;
4548 if not g_Game_IsServer
then
4552 FWantsInGame
:= True;
4553 FJustTeleported
:= True;
4556 FTime
[T_RESPAWN
] := 0;
4560 // if server changes MaxLives we gotta be ready
4561 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4563 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4564 if FTime
[T_RESPAWN
] > gTime
then
4567 // Ïðîñðàë âñå æèçíè:
4570 if not FSpectator
then Spectate(True);
4571 FWantsInGame
:= True;
4575 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4576 begin // "Ñâîÿ èãðà"
4577 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4578 FRulez
:= FRulez
-[R_BERSERK
];
4580 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4582 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4583 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4586 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4587 c
:= GetRespawnPoint();
4592 // Âîñêðåøåíèå áåç îðóæèÿ:
4595 FHealth
:= PLAYER_HP_SOFT
;
4601 for a
:= WP_FIRST
to WP_LAST
do
4603 FWeapon
[a
] := False;
4607 FWeapon
[WEAPON_PISTOL
] := True;
4608 FWeapon
[WEAPON_KASTET
] := True;
4609 FCurrWeap
:= WEAPON_PISTOL
;
4612 FModel
.SetWeapon(FCurrWeap
);
4614 for b
:= A_BULLETS
to A_HIGH
do
4617 FAmmo
[A_BULLETS
] := 50;
4619 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4620 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4621 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4622 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4623 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4625 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4626 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4631 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4632 if not g_Map_GetPoint(c
, RespawnPoint
) then
4634 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4638 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4639 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4640 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4646 FDirection
:= RespawnPoint
.Direction
;
4647 if FDirection
= TDirection
.D_LEFT
then
4652 SetAction(A_STAND
, True);
4653 FModel
.Direction
:= FDirection
;
4655 for a
:= Low(FTime
) to High(FTime
) do
4658 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4663 FCanJetpack
:= False;
4668 // Àíèìàöèÿ âîçðîæäåíèÿ:
4669 if (not gLoadGameMode
) and (not Silent
) then
4670 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4672 Anim
:= TAnimation
.Create(ID
, False, 3);
4673 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4674 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4678 FSpectator
:= False;
4681 FSpectatePlayer
:= -1;
4684 if (gPlayer1
= nil) and (gLMSPID1
= FUID
) then
4686 if (gPlayer2
= nil) and (gLMSPID2
= FUID
) then
4689 if g_Game_IsNet
then
4691 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4692 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4694 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4695 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4700 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4703 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4704 else if (not NoMove
) then
4706 GameX
:= gMapInfo
.Width
div 2;
4707 GameY
:= gMapInfo
.Height
div 2;
4716 FWantsInGame
:= False;
4721 if Self
= gPlayer1
then
4726 if Self
= gPlayer2
then
4733 if g_Game_IsNet
then
4734 MH_SEND_PlayerStats(FUID
);
4737 procedure TPlayer
.SwitchNoClip
;
4741 FGhost
:= not FGhost
;
4742 FPhysics
:= not FGhost
;
4754 procedure TPlayer
.Run(Direction
: TDirection
);
4758 if MAX_RUNVEL
> 8 then
4762 if Direction
= TDirection
.D_LEFT
then
4764 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4765 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4768 if FObj
.Vel
.X
< MAX_RUNVEL
then
4769 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4771 // Âîçìîæíî, ïèíàåì êóñêè:
4772 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4774 b
:= Abs(FObj
.Vel
.X
);
4775 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4776 for a
:= 0 to High(gGibs
) do
4778 if gGibs
[a
].alive
and
4779 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4780 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4783 if FObj
.Vel
.X
< 0 then
4785 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4789 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4791 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4799 procedure TPlayer
.SeeDown();
4801 SetAction(A_SEEDOWN
);
4803 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4805 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4808 procedure TPlayer
.SeeUp();
4812 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4814 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4817 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4825 A_ATTACK
: Prior
:= 2;
4826 A_SEEUP
: Prior
:= 1;
4827 A_SEEDOWN
: Prior
:= 1;
4828 A_ATTACKUP
: Prior
:= 2;
4829 A_ATTACKDOWN
: Prior
:= 2;
4834 if (Prior
> FActionPrior
) or Force
then
4835 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4837 FActionPrior
:= Prior
;
4838 FActionAnim
:= Action
;
4839 FActionForce
:= Force
;
4840 FActionChanged
:= True;
4843 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4846 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4848 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4849 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4850 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4851 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4854 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4861 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4863 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4864 if g_Game_IsServer
and g_Game_IsNet
then
4865 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4869 FJustTeleported
:= True;
4874 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4876 Anim
:= TAnimation
.Create(ID
, False, 3);
4879 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4880 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4881 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4882 if g_Game_IsServer
and g_Game_IsNet
then
4883 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4884 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4888 FObj
.X
:= X
-PLAYER_RECT
.X
;
4889 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4890 if FAlive
and FGhost
then
4896 if not g_Game_IsNet
then
4900 SetDirection(TDirection
.D_LEFT
);
4906 SetDirection(TDirection
.D_RIGHT
);
4912 if FDirection
= TDirection
.D_RIGHT
then
4914 SetDirection(TDirection
.D_LEFT
);
4919 SetDirection(TDirection
.D_RIGHT
);
4925 if not silent
and (Anim
<> nil) then
4927 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4928 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4931 if g_Game_IsServer
and g_Game_IsNet
then
4932 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4933 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4940 function nonz(a
: Single): Single;
4948 function TPlayer
.followCorpse(): Boolean;
4953 if FAlive
or FSpectator
then
4955 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
4957 for i
:= 0 to High(gCorpses
) do
4958 if gCorpses
[i
] <> nil then
4959 if gCorpses
[i
].FPlayerUID
= FUID
then
4962 FObj
.X
:= gCorpses
[i
].FObj
.X
;
4963 FObj
.Y
:= gCorpses
[i
].FObj
.Y
;
4964 FObj
.Vel
.X
:= gCorpses
[i
].FObj
.Vel
.X
;
4965 FObj
.Vel
.Y
:= gCorpses
[i
].FObj
.Vel
.Y
;
4966 FObj
.Accel
.X
:= gCorpses
[i
].FObj
.Accel
.X
;
4967 FObj
.Accel
.Y
:= gCorpses
[i
].FObj
.Accel
.Y
;
4972 procedure TPlayer
.Update();
4975 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4976 blockmon
, headwater
, dospawn
: Boolean;
4981 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4982 AnyServer
:= g_Game_IsServer
;
4984 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4985 DoLerp(NetInterpLevel
+ 1)
4992 if FClientID
>= 0 then
4994 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4995 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4996 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
5006 if FAlive
and (FPunchAnim
<> nil) then
5007 FPunchAnim
.Update();
5009 if FAlive
and (gFly
or FJetpack
) then
5012 if FDirection
= TDirection
.D_LEFT
then
5017 if FAlive
and (not FGhost
) then
5019 if FKeys
[KEY_UP
].Pressed
then
5021 if FKeys
[KEY_DOWN
].Pressed
then
5025 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
5028 i
:= g_basic
.Sign(FIncCam
);
5029 FIncCam
:= Abs(FIncCam
);
5030 DecMin(FIncCam
, 5, 0);
5031 FIncCam
:= FIncCam
*i
;
5034 // no need to do that each second frame, weapon queue will take care of it
5035 if FAlive
and FKeys
[KEY_NEXTWEAPON
].Pressed
{and AnyServer} then NextWeapon();
5036 if FAlive
and FKeys
[KEY_PREVWEAPON
].Pressed
{and AnyServer} then PrevWeapon();
5038 if gTime
mod (GAME_TICK
*2) <> 0 then
5040 if (FObj
.Vel
.X
= 0) and FAlive
then
5042 if FKeys
[KEY_LEFT
].Pressed
then
5043 Run(TDirection
.D_LEFT
);
5044 if FKeys
[KEY_RIGHT
].Pressed
then
5045 Run(TDirection
.D_RIGHT
);
5050 if not followCorpse() then
5051 g_Obj_Move(@FObj
, True, True, True);
5052 positionChanged(); // this updates spatial accelerators
5058 FActionChanged
:= False;
5062 // Let alive player do some actions
5063 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
5064 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
5065 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
5066 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
5067 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
5068 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
5069 if FKeys
[KEY_JUMP
].Pressed
then Jump()
5072 if AnyServer
and FJetpack
then
5076 if NetServer
then MH_SEND_PlayerStats(FUID
);
5078 FCanJetpack
:= True;
5085 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
5087 if FKeys
[k
].Pressed
then
5095 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5098 if (FTime
[T_RESPAWN
] <= gTime
) and
5099 gGameOn
and (not FAlive
) then
5101 if (g_Player_GetCount() > 1) then
5105 gExit
:= EXIT_RESTART
;
5110 // Dead spectator actions
5113 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
5114 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
5118 if (FSpectatePlayer
>= High(gPlayers
)) then
5119 FSpectatePlayer
:= -1
5123 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
5124 if gPlayers
[I
] <> nil then
5125 if gPlayers
[I
].alive
then
5126 if gPlayers
[I
].UID
<> FUID
then
5128 FSpectatePlayer
:= I
;
5133 if not SetSpect
then FSpectatePlayer
:= -1;
5144 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5146 FYTo
:= FObj
.Y
- 32;
5147 FSpectatePlayer
:= -1;
5149 if FKeys
[KEY_DOWN
].Pressed
then
5151 FYTo
:= FObj
.Y
+ 32;
5152 FSpectatePlayer
:= -1;
5154 if FKeys
[KEY_LEFT
].Pressed
then
5156 FXTo
:= FObj
.X
- 32;
5157 FSpectatePlayer
:= -1;
5159 if FKeys
[KEY_RIGHT
].Pressed
then
5161 FXTo
:= FObj
.X
+ 32;
5162 FSpectatePlayer
:= -1;
5165 if (FXTo
< -64) then
5167 else if (FXTo
> gMapInfo
.Width
+ 32) then
5168 FXTo
:= gMapInfo
.Width
+ 32;
5169 if (FYTo
< -72) then
5171 else if (FYTo
> gMapInfo
.Height
+ 32) then
5172 FYTo
:= gMapInfo
.Height
+ 32;
5177 if not followCorpse() then
5178 g_Obj_Move(@FObj
, True, True, True);
5179 positionChanged(); // this updates spatial accelerators
5186 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5187 if gPlayers
[FSpectatePlayer
] <> nil then
5188 if gPlayers
[FSpectatePlayer
].alive
then
5190 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
5191 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
5195 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5196 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5197 PANEL_BLOCKMON
, True);
5198 headwater
:= HeadInLiquid(0, 0);
5200 // Ñîïðîòèâëåíèå âîçäóõà:
5201 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5202 if FObj
.Vel
.X
<> 0 then
5203 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5205 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5206 DecMin(FPain
, 5, 0);
5207 DecMin(FPickup
, 1, 0);
5209 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5211 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5212 FMegaRulez
[MR_SUIT
] := 0;
5213 FMegaRulez
[MR_INVUL
] := 0;
5214 FMegaRulez
[MR_INVIS
] := 0;
5215 Kill(K_FALLKILL
, 0, HIT_FALL
);
5222 if FCurrWeap
= WEAPON_SAW
then
5223 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5224 FSawSoundSelect
.IsPlaying()) then
5225 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5228 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5229 (not FJetSoundOff
.IsPlaying()) then
5231 FJetSoundFly
.SetPosition(0);
5232 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5235 for b
:= WP_FIRST
to WP_LAST
do
5236 if FReloading
[b
] > 0 then
5242 if FShellTimer
> -1 then
5243 if FShellTimer
= 0 then
5245 if FShellType
= SHELL_SHELL
then
5246 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5247 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5248 else if FShellType
= SHELL_DBLSHELL
then
5250 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5251 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5252 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5253 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5256 end else Dec(FShellTimer
);
5258 if (FBFGFireCounter
> -1) then
5259 if FBFGFireCounter
= 0 then
5263 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5264 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5265 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5266 yd
:= wy
+firediry();
5267 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5268 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5269 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5270 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5271 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5274 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5275 FBFGFireCounter
:= -1;
5278 FBFGFireCounter
:= 0
5280 Dec(FBFGFireCounter
);
5282 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5284 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5286 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5289 if (headwater
or blockmon
) then
5295 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5298 else if (FAir
mod 31 = 0) and not blockmon
then
5300 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5301 if Random(2) = 0 then
5302 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5304 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5306 end else if FAir
< AIR_DEF
then
5309 if FFireTime
> 0 then
5311 if BodyInLiquid(0, 0) then
5316 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5318 if FMegaRulez
[MR_SUIT
] = gTime
then
5325 if FFirePainTime
<= 0 then
5327 if g_Game_IsServer
then
5328 Damage(5, FFireAttacker
, 0, 0, HIT_FLAME
);
5329 FFirePainTime
:= 18;
5331 FFirePainTime
:= FFirePainTime
- 1;
5332 FFireTime
:= FFireTime
- 1;
5333 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5334 MH_SEND_PlayerStats(FUID
);
5338 if FDamageBuffer
> 0 then
5340 if FDamageBuffer
>= 9 then
5344 if FDamageBuffer
< 30 then i
:= 9
5345 else if FDamageBuffer
< 100 then i
:= 18
5349 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5350 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5351 FHealth
:= FHealth
-ii
;
5354 FHealth
:= FHealth
+FArmor
;
5359 if FHealth
<= 0 then
5360 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5361 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5362 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5366 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5367 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5368 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5369 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5376 end; // if FAlive then ...
5378 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5380 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5381 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5382 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5383 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5385 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5386 then SetAction(A_STAND
, True);
5388 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5390 for b
:= Low(FKeys
) to High(FKeys
) do
5391 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5395 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5397 x
:= FObj
.X
+PLAYER_RECT
.X
;
5398 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5399 w
:= PLAYER_RECT
.Width
;
5400 h
:= PLAYER_RECT
.Height
;
5404 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5406 if (dx
<> 0) or (dy
<> 0) then
5415 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5417 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5418 FObj
.Y
+PLAYER_RECT
.Y
,
5425 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5427 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5428 FObj
.Y
+PLAYER_RECT
.Y
,
5432 Panel
.Width
, Panel
.Height
);
5435 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5437 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5438 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5439 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5440 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5443 function g_Player_ValidName(Name
: string): Boolean;
5449 if gPlayers
= nil then Exit
;
5451 for a
:= 0 to High(gPlayers
) do
5452 if gPlayers
[a
] <> nil then
5453 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5460 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5464 d
:= FModel
.Direction
;
5466 FModel
.Direction
:= Direction
;
5467 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5469 FDirection
:= Direction
;
5472 function TPlayer
.GetKeys(): Byte;
5476 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5477 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5478 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5480 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5481 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5484 procedure TPlayer
.Use();
5488 if FTime
[T_USE
] > gTime
then Exit
;
5490 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5491 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5493 for a
:= 0 to High(gPlayers
) do
5494 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5495 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5496 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5497 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5499 gPlayers
[a
].Touch();
5500 if g_Game_IsNet
and g_Game_IsServer
then
5501 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5504 FTime
[T_USE
] := gTime
+120;
5507 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5511 WX
, WY
, XD
, YD
: Integer;
5523 if R_BERSERK
in FRulez
then
5525 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5526 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5527 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5530 locobj
.rect
.Width
:= 39;
5531 locobj
.rect
.Height
:= 52;
5532 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5533 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5534 locobj
.Accel
.X
:= xd
-wx
;
5535 locobj
.Accel
.y
:= yd
-wy
;
5537 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5538 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5540 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5544 FPain
:= min(FPain
+ 25, 50);
5546 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5551 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5552 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5554 FSawSoundSelect
.Stop();
5556 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5558 else if not FSawSoundHit
.IsPlaying() then
5560 FSawSoundSelect
.Stop();
5561 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5568 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5569 FFireAngle
:= FAngle
;
5571 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5572 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5577 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5578 FFireAngle
:= FAngle
;
5581 FShellType
:= SHELL_SHELL
;
5586 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5587 FFireAngle
:= FAngle
;
5590 FShellType
:= SHELL_DBLSHELL
;
5595 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5596 FFireAngle
:= FAngle
;
5598 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5599 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5602 WEAPON_ROCKETLAUNCHER
:
5604 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5605 FFireAngle
:= FAngle
;
5611 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5612 FFireAngle
:= FAngle
;
5618 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5619 FFireAngle
:= FAngle
;
5623 WEAPON_SUPERPULEMET
:
5625 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5626 FFireAngle
:= FAngle
;
5628 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5629 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5632 WEAPON_FLAMETHROWER
:
5634 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5635 FFireAngle
:= FAngle
;
5642 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5643 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5644 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5647 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5649 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5650 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5653 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5657 if NetInterpLevel
< 1 then
5667 AX
:= Abs(FXTo
- FObj
.X
);
5668 AY
:= Abs(FYTo
- FObj
.Y
);
5669 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5671 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5676 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5678 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5679 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5680 PANEL_LIFTUP
, False) then Result
:= -1
5682 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5683 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5684 PANEL_LIFTDOWN
, False) then Result
:= 1
5688 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5695 if Flag
= FLAG_NONE
then
5698 if not g_Game_IsServer
then Exit
;
5700 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5701 if (Flag
= FTeam
) and
5702 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5703 (FFlag
<> FLAG_NONE
) then
5705 if FFlag
= FLAG_RED
then
5706 s
:= _lc
[I_PLAYER_FLAG_RED
]
5708 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5710 evtype
:= FLAG_STATE_SCORED
;
5712 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5713 Insert('.', ts
, Length(ts
) + 1 - 3);
5714 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5716 g_Map_ResetFlag(FFlag
);
5717 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5719 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5722 if g_Game_IsNet
then
5724 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5728 gFlags
[FFlag
].CaptureTime
:= 0;
5733 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5734 if (Flag
= FTeam
) and
5735 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5737 if Flag
= FLAG_RED
then
5738 s
:= _lc
[I_PLAYER_FLAG_RED
]
5740 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5742 evtype
:= FLAG_STATE_RETURNED
;
5743 gFlags
[Flag
].CaptureTime
:= 0;
5745 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5747 g_Map_ResetFlag(Flag
);
5748 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5751 if g_Game_IsNet
then
5753 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5759 // Ïîäîáðàë ÷óæîé ôëàã:
5760 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5764 if Flag
= FLAG_RED
then
5765 s
:= _lc
[I_PLAYER_FLAG_RED
]
5767 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5769 evtype
:= FLAG_STATE_CAPTURED
;
5771 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5773 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5775 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5778 if g_Game_IsNet
then
5780 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5786 procedure TPlayer
.SetFlag(Flag
: Byte);
5789 if FModel
<> nil then
5790 FModel
.SetFlag(FFlag
);
5793 function TPlayer
.DropFlag(): Boolean;
5798 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5800 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5801 with gFlags
[FFlag
] do
5805 Direction
:= FDirection
;
5806 State
:= FLAG_STATE_DROPPED
;
5808 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5809 (FObj
.Vel
.Y
div 2)-2+Random(5));
5810 positionChanged(); // this updates spatial accelerators
5812 if FFlag
= FLAG_RED
then
5813 s
:= _lc
[I_PLAYER_FLAG_RED
]
5815 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5817 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5818 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5820 if g_Game_IsNet
then
5821 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5827 procedure TPlayer
.GetSecret();
5832 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5834 Assert(Key
<= High(FKeys
));
5836 FKeys
[Key
].Pressed
:= True;
5837 FKeys
[Key
].Time
:= Time
;
5840 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5842 Result
:= FKeys
[K
].Pressed
;
5845 procedure TPlayer
.ReleaseKeys();
5849 for a
:= Low(FKeys
) to High(FKeys
) do
5851 FKeys
[a
].Pressed
:= False;
5856 procedure TPlayer
.ReleaseKeysNoWeapon();
5860 for a
:= Low(FKeys
) to High(FKeys
) do
5862 if (a
= KEY_PREVWEAPON
) or (a
= KEY_NEXTWEAPON
) then continue
;
5863 FKeys
[a
].Pressed
:= False;
5868 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5872 function TPlayer
.firediry(): Integer;
5874 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5875 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5879 procedure TPlayer
.RememberState();
5883 FSavedState
.Health
:= FHealth
;
5884 FSavedState
.Armor
:= FArmor
;
5885 FSavedState
.Air
:= FAir
;
5886 FSavedState
.JetFuel
:= FJetFuel
;
5887 FSavedState
.CurrWeap
:= FCurrWeap
;
5888 FSavedState
.NextWeap
:= FNextWeap
;
5889 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5892 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5894 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5896 FSavedState
.Rulez
:= FRulez
;
5897 FSavedState
.WaitRecall
:= True;
5900 procedure TPlayer
.RecallState();
5904 if not FSavedState
.WaitRecall
then Exit
;
5906 FHealth
:= FSavedState
.Health
;
5907 FArmor
:= FSavedState
.Armor
;
5908 FAir
:= FSavedState
.Air
;
5909 FJetFuel
:= FSavedState
.JetFuel
;
5910 FCurrWeap
:= FSavedState
.CurrWeap
;
5911 FNextWeap
:= FSavedState
.NextWeap
;
5912 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5915 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5917 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5919 FRulez
:= FSavedState
.Rulez
;
5920 FSavedState
.WaitRecall
:= False;
5922 if gGameSettings
.GameType
= GT_SERVER
then
5923 MH_SEND_PlayerStats(FUID
);
5926 procedure TPlayer
.SaveState (st
: TStream
);
5932 utils
.writeSign(st
, 'PLYR');
5933 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
5935 utils
.writeBool(st
, FIamBot
);
5937 utils
.writeInt(st
, Word(FUID
));
5939 utils
.writeStr(st
, FName
);
5941 utils
.writeInt(st
, Byte(FTeam
));
5943 utils
.writeBool(st
, FAlive
);
5944 // Èçðàñõîäîâàë ëè âñå æèçíè
5945 utils
.writeBool(st
, FNoRespawn
);
5947 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
5948 utils
.writeInt(st
, Byte(b
));
5950 utils
.writeInt(st
, LongInt(FHealth
));
5952 utils
.writeInt(st
, Byte(FLives
));
5954 utils
.writeInt(st
, LongInt(FArmor
));
5956 utils
.writeInt(st
, LongInt(FAir
));
5958 utils
.writeInt(st
, LongInt(FJetFuel
));
5960 utils
.writeInt(st
, LongInt(FPain
));
5962 utils
.writeInt(st
, LongInt(FKills
));
5964 utils
.writeInt(st
, LongInt(FMonsterKills
));
5966 utils
.writeInt(st
, LongInt(FFrags
));
5968 utils
.writeInt(st
, Byte(FFragCombo
));
5969 // Âðåìÿ ïîñëåäíåãî ôðàãà
5970 utils
.writeInt(st
, LongWord(FLastFrag
));
5972 utils
.writeInt(st
, LongInt(FDeath
));
5974 utils
.writeInt(st
, Byte(FFlag
));
5976 utils
.writeInt(st
, LongInt(FSecrets
));
5978 utils
.writeInt(st
, Byte(FCurrWeap
));
5980 utils
.writeInt(st
, Word(FNextWeap
));
5982 utils
.writeInt(st
, Byte(FNextWeapDelay
));
5983 // Âðåìÿ çàðÿäêè BFG
5984 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
5986 utils
.writeInt(st
, LongInt(FDamageBuffer
));
5987 // Ïîñëåäíèé óäàðèâøèé
5988 utils
.writeInt(st
, Word(FLastSpawnerUID
));
5989 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
5990 utils
.writeInt(st
, Byte(FLastHit
));
5992 Obj_SaveState(st
, @FObj
);
5993 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
5994 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
5995 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
5996 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
5998 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
5999 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6000 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
6002 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
6003 // Íàëè÷èå êðàñíîãî êëþ÷à
6004 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
6005 // Íàëè÷èå çåëåíîãî êëþ÷à
6006 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
6007 // Íàëè÷èå ñèíåãî êëþ÷à
6008 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
6010 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
6011 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6012 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
6013 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6014 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
6016 utils
.writeStr(st
, FModel
.Name
);
6018 utils
.writeInt(st
, Byte(FColor
.R
));
6019 utils
.writeInt(st
, Byte(FColor
.G
));
6020 utils
.writeInt(st
, Byte(FColor
.B
));
6024 procedure TPlayer
.LoadState (st
: TStream
);
6033 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
6034 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
6036 FIamBot
:= utils
.readBool(st
);
6038 FUID
:= utils
.readWord(st
);
6040 str
:= utils
.readStr(st
);
6041 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
6043 FTeam
:= utils
.readByte(st
);
6045 FAlive
:= utils
.readBool(st
);
6046 // Èçðàñõîäîâàë ëè âñå æèçíè
6047 FNoRespawn
:= utils
.readBool(st
);
6049 b
:= utils
.readByte(st
);
6050 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
6052 FHealth
:= utils
.readLongInt(st
);
6054 FLives
:= utils
.readByte(st
);
6056 FArmor
:= utils
.readLongInt(st
);
6058 FAir
:= utils
.readLongInt(st
);
6060 FJetFuel
:= utils
.readLongInt(st
);
6062 FPain
:= utils
.readLongInt(st
);
6064 FKills
:= utils
.readLongInt(st
);
6066 FMonsterKills
:= utils
.readLongInt(st
);
6068 FFrags
:= utils
.readLongInt(st
);
6070 FFragCombo
:= utils
.readByte(st
);
6071 // Âðåìÿ ïîñëåäíåãî ôðàãà
6072 FLastFrag
:= utils
.readLongWord(st
);
6074 FDeath
:= utils
.readLongInt(st
);
6076 FFlag
:= utils
.readByte(st
);
6078 FSecrets
:= utils
.readLongInt(st
);
6080 FCurrWeap
:= utils
.readByte(st
);
6082 FNextWeap
:= utils
.readWord(st
);
6084 FNextWeapDelay
:= utils
.readByte(st
);
6085 // Âðåìÿ çàðÿäêè BFG
6086 FBFGFireCounter
:= utils
.readSmallInt(st
);
6088 FDamageBuffer
:= utils
.readLongInt(st
);
6089 // Ïîñëåäíèé óäàðèâøèé
6090 FLastSpawnerUID
:= utils
.readWord(st
);
6091 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6092 FLastHit
:= utils
.readByte(st
);
6094 Obj_LoadState(@FObj
, st
);
6095 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6096 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
6097 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6098 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
6100 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
6101 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6102 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
6104 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
6105 // Íàëè÷èå êðàñíîãî êëþ÷à
6106 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
6107 // Íàëè÷èå çåëåíîãî êëþ÷à
6108 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
6109 // Íàëè÷èå ñèíåãî êëþ÷à
6110 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
6112 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
6113 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6114 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
6115 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6116 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
6118 str
:= utils
.readStr(st
);
6120 FColor
.R
:= utils
.readByte(st
);
6121 FColor
.G
:= utils
.readByte(st
);
6122 FColor
.B
:= utils
.readByte(st
);
6123 if (self
= gPlayer1
) then
6125 str
:= gPlayer1Settings
.Model
;
6126 FColor
:= gPlayer1Settings
.Color
;
6128 else if (self
= gPlayer2
) then
6130 str
:= gPlayer2Settings
.Model
;
6131 FColor
:= gPlayer2Settings
.Color
;
6133 // Îáíîâëÿåì ìîäåëü èãðîêà
6135 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
6136 FModel
.Color
:= TEAMCOLOR
[FTeam
]
6138 FModel
.Color
:= FColor
;
6142 procedure TPlayer
.AllRulez(Health
: Boolean);
6148 FHealth
:= PLAYER_HP_LIMIT
;
6149 FArmor
:= PLAYER_AP_LIMIT
;
6153 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
6154 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
6155 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6158 procedure TPlayer
.RestoreHealthArmor();
6160 FHealth
:= PLAYER_HP_LIMIT
;
6161 FArmor
:= PLAYER_AP_LIMIT
;
6164 procedure TPlayer
.FragCombo();
6168 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6170 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6172 if FFragCombo
< 5 then
6174 Param
:= FUID
or (FFragCombo
shl 16);
6175 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6176 (FComboEvnt
<= High(gDelayedEvents
)) and
6177 gDelayedEvents
[FComboEvnt
].Pending
and
6178 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6179 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6181 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6182 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6185 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6193 procedure TPlayer
.GiveItem(ItemType
: Byte);
6197 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6199 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6203 if FAir
< AIR_MAX
then
6210 if not (R_BERSERK
in FRulez
) then
6212 Include(FRulez
, R_BERSERK
);
6213 if FBFGFireCounter
< 1 then
6215 FCurrWeap
:= WEAPON_KASTET
;
6217 FModel
.SetWeapon(WEAPON_KASTET
);
6221 FBerserk
:= gTime
+30000;
6223 if FHealth
< PLAYER_HP_SOFT
then
6225 FHealth
:= PLAYER_HP_SOFT
;
6226 FBerserk
:= gTime
+30000;
6231 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6233 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6237 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6239 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6243 if FJetFuel
< JET_MAX
then
6245 FJetFuel
:= JET_MAX
;
6248 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6249 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6251 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6252 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6254 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6256 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6258 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6259 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6262 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6263 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6264 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6265 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6266 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6267 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6268 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6269 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6270 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6272 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6273 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6274 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6275 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6276 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6277 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6278 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6279 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6280 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6283 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6284 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6285 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6286 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6287 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6289 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6290 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6291 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6292 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6293 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6295 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6296 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6297 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6298 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6300 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6303 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6304 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6305 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6307 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6308 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6313 if g_Game_IsNet
and g_Game_IsServer
then
6314 MH_SEND_PlayerStats(FUID
);
6317 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6322 if (Random(5) = 1) and (Times
= 1) then
6325 if BodyInLiquid(0, 0) then
6327 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6328 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6329 if Random(2) = 0 then
6330 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6332 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6336 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6338 for i
:= 1 to Times
do
6340 Anim
:= TAnimation
.Create(id
, False, 3);
6342 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6343 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6349 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6354 if (Random(10) = 1) and (Times
= 1) then
6357 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6359 for i
:= 1 to Times
do
6361 Anim
:= TAnimation
.Create(id
, False, 3);
6363 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6364 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6370 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6372 FSawSound
.Pause(Enable
);
6373 FSawSoundIdle
.Pause(Enable
);
6374 FSawSoundHit
.Pause(Enable
);
6375 FSawSoundSelect
.Pause(Enable
);
6380 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6385 FObj
.Rect
:= PLAYER_CORPSERECT
;
6386 FModelName
:= ModelName
;
6391 FState
:= CORPSE_STATE_MESS
;
6392 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6396 FState
:= CORPSE_STATE_NORMAL
;
6397 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6401 destructor TCorpse
.Destroy();
6408 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6410 procedure TCorpse
.positionChanged (); inline; begin end;
6412 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6414 if (dx
<> 0) or (dy
<> 0) then
6423 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6425 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6426 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6427 w
:= PLAYER_CORPSERECT
.Width
;
6428 h
:= PLAYER_CORPSERECT
.Height
;
6432 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6437 if FState
= CORPSE_STATE_REMOVEME
then
6440 FDamage
:= FDamage
+ Value
;
6442 if FDamage
> 150 then
6444 if FAnimation
<> nil then
6449 FState
:= CORPSE_STATE_REMOVEME
;
6451 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6452 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6453 FModelName
, FColor
);
6454 // Çâóê ìÿñà îò òðóïà:
6455 pm
:= g_PlayerModel_Get(FModelName
);
6456 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6460 if (gBodyKillEvent
<> -1)
6461 and gDelayedEvents
[gBodyKillEvent
].Pending
then
6462 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
6463 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, 0);
6468 Blood
:= g_PlayerModel_GetBlood(FModelName
);
6469 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6470 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6471 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6472 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6473 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6474 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
6478 procedure TCorpse
.Draw();
6480 if FState
= CORPSE_STATE_REMOVEME
then
6483 if FAnimation
<> nil then
6484 FAnimation
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6486 if FAnimationMask
<> nil then
6489 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6496 procedure TCorpse
.Update();
6500 if FState
= CORPSE_STATE_REMOVEME
then
6503 if gTime
mod (GAME_TICK
*2) <> 0 then
6505 g_Obj_Move(@FObj
, True, True, True);
6506 positionChanged(); // this updates spatial accelerators
6510 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6511 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6513 st
:= g_Obj_Move(@FObj
, True, True, True);
6514 positionChanged(); // this updates spatial accelerators
6516 if WordBool(st
and MOVE_FALLOUT
) then
6518 FState
:= CORPSE_STATE_REMOVEME
;
6522 if FAnimation
<> nil then
6523 FAnimation
.Update();
6524 if FAnimationMask
<> nil then
6525 FAnimationMask
.Update();
6529 procedure TCorpse
.SaveState (st
: TStream
);
6536 utils
.writeSign(st
, 'CORP');
6537 utils
.writeInt(st
, Byte(0));
6539 utils
.writeInt(st
, Byte(FState
));
6541 utils
.writeInt(st
, Byte(FDamage
));
6543 utils
.writeInt(st
, Byte(FColor
.R
));
6544 utils
.writeInt(st
, Byte(FColor
.G
));
6545 utils
.writeInt(st
, Byte(FColor
.B
));
6547 Obj_SaveState(st
, @FObj
);
6548 utils
.writeInt(st
, Word(FPlayerUID
));
6550 anim
:= (FAnimation
<> nil);
6551 utils
.writeBool(st
, anim
);
6552 // Åñëè åñòü - ñîõðàíÿåì
6553 if anim
then FAnimation
.SaveState(st
);
6554 // Åñòü ëè ìàñêà àíèìàöèè
6555 anim
:= (FAnimationMask
<> nil);
6556 utils
.writeBool(st
, anim
);
6557 // Åñëè åñòü - ñîõðàíÿåì
6558 if anim
then FAnimationMask
.SaveState(st
);
6562 procedure TCorpse
.LoadState (st
: TStream
);
6569 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6570 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6572 FState
:= utils
.readByte(st
);
6574 FDamage
:= utils
.readByte(st
);
6576 FColor
.R
:= utils
.readByte(st
);
6577 FColor
.G
:= utils
.readByte(st
);
6578 FColor
.B
:= utils
.readByte(st
);
6580 Obj_LoadState(@FObj
, st
);
6581 FPlayerUID
:= utils
.readWord(st
);
6583 anim
:= utils
.readBool(st
);
6584 // Åñëè åñòü - çàãðóæàåì
6587 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6588 FAnimation
.LoadState(st
);
6590 // Åñòü ëè ìàñêà àíèìàöèè
6591 anim
:= utils
.readBool(st
);
6592 // Åñëè åñòü - çàãðóæàåì
6595 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6596 FAnimationMask
.LoadState(st
);
6602 constructor TBot
.Create();
6609 FSpectator
:= False;
6616 for a
:= WP_FIRST
to WP_LAST
do
6618 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6619 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6620 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6624 destructor TBot
.Destroy();
6627 inherited Destroy();
6630 procedure TBot
.Draw();
6634 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6635 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6638 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6640 inherited Respawn(Silent
, Force
);
6643 FSelectedWeapon
:= FCurrWeap
;
6648 procedure TBot
.UpdateCombat();
6661 TTargetRecord
= array of TTarget
;
6663 function Compare(a
, b
: TTarget
): Integer;
6665 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6668 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6670 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6671 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6673 if a
.Dist
> b
.Dist
then // B áëèæå
6675 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6678 else // Ñòðàííî -> A
6683 a
, x1
, y1
, x2
, y2
: Integer;
6684 targets
: TTargetRecord
;
6686 Target
, BestTarget
: TTarget
;
6687 firew
, fireh
: Integer;
6691 vsPlayer
, vsMonster
, ok
: Boolean;
6694 function monsUpdate (mon
: TMonster
): Boolean;
6696 result
:= false; // don't stop
6697 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6699 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6701 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6702 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6704 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6705 if g_TraceVector(x1
, y1
, x2
, y2
) then
6707 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6708 SetLength(targets
, Length(targets
)+1);
6709 with targets
[High(targets
)] do
6716 Rect
:= mon
.Obj
.Rect
;
6717 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6718 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6719 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6728 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6729 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6731 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6732 if FCurrWeap
<> FSelectedWeapon
then
6735 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6736 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6738 RemoveAIFlag('NEEDFIRE');
6741 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6742 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6743 else PressKey(KEY_FIRE
);
6747 // Êîîðäèíàòû ñòâîëà:
6748 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6749 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6751 Target
.UID
:= FTargetUID
;
6754 if Target
.UID
<> 0 then
6755 begin // Öåëü åñòü - íàñòðàèâàåì
6756 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6759 tpla
:= g_Player_Get(Target
.UID
);
6763 if (@FObj
) <> nil then
6770 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6771 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6772 Target
.Rect
:= PLAYER_RECT
;
6773 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6774 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6775 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6776 Target
.IsPlayer
:= True;
6780 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6783 mon
:= g_Monsters_ByUID(Target
.UID
);
6786 Target
.X
:= mon
.Obj
.X
;
6787 Target
.Y
:= mon
.Obj
.Y
;
6789 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6790 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6791 Target
.Rect
:= mon
.Obj
.Rect
;
6792 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6793 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6794 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6795 Target
.IsPlayer
:= False;
6802 begin // Öåëè íåò - îáíóëÿåì
6807 Target
.Visible
:= False;
6808 Target
.Line
:= False;
6809 Target
.IsPlayer
:= False;
6814 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6815 if (not Target
.Line
) or (not Target
.Visible
) then
6819 for a
:= 0 to High(gPlayers
) do
6820 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6821 (gPlayers
[a
].FUID
<> FUID
) and
6822 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6823 (not gPlayers
[a
].NoTarget
) and
6824 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6826 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6827 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6830 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6831 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6833 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6834 if g_TraceVector(x1
, y1
, x2
, y2
) then
6836 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6837 SetLength(targets
, Length(targets
)+1);
6838 with targets
[High(targets
)] do
6840 UID
:= gPlayers
[a
].FUID
;
6841 X
:= gPlayers
[a
].FObj
.X
;
6842 Y
:= gPlayers
[a
].FObj
.Y
;
6845 Rect
:= PLAYER_RECT
;
6846 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6847 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6848 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6856 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6859 // Åñëè åñòü âîçìîæíûå öåëè:
6860 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6861 if targets
<> nil then
6863 // Âûáèðàåì íàèëó÷øóþ öåëü:
6864 BestTarget
:= targets
[0];
6865 if Length(targets
) > 1 then
6866 for a
:= 1 to High(targets
) do
6867 if Compare(BestTarget
, targets
[a
]) = 1 then
6868 BestTarget
:= targets
[a
];
6870 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6871 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6872 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6874 Target
:= BestTarget
;
6876 if (Healthy() = 3) or ((Healthy() = 2)) then
6877 begin // Åñëè çäîðîâû - äîãîíÿåì
6878 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6879 SetAIFlag('GORIGHT', '1');
6880 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6881 SetAIFlag('GOLEFT', '1');
6884 begin // Åñëè ïîáèòû - óáåãàåì
6885 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6886 SetAIFlag('GORIGHT', '1');
6887 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6888 SetAIFlag('GOLEFT', '1');
6891 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6892 SelectWeapon(Abs(x1
-Target
.cX
));
6897 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6898 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6899 if Target
.UID
<> 0 then
6901 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6902 Target
.Y
+ Target
.Rect
.Y
) then
6903 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6904 if (Healthy() = 3) or ((Healthy() = 2)) then
6905 begin // Åñëè çäîðîâû - äîãîíÿåì
6906 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6907 SetAIFlag('GORIGHT', '1');
6908 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6909 SetAIFlag('GOLEFT', '1');
6912 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6914 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6915 SetAIFlag('GORIGHT', '1');
6916 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6917 SetAIFlag('GOLEFT', '1');
6921 begin // Öåëü ïîêà íà "ýêðàíå"
6922 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6923 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6924 FLastVisible
:= gTime
;
6925 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6926 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6928 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6929 SetAIFlag('GORIGHT', '1');
6930 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6931 SetAIFlag('GOLEFT', '1');
6935 // Âûáèðàåì óãîë ââåðõ:
6936 if FDirection
= TDirection
.D_LEFT
then
6937 angle
:= ANGLE_LEFTUP
6939 angle
:= ANGLE_RIGHTUP
;
6941 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6942 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6944 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6945 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6946 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6947 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6948 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6949 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6950 begin // òî íóæíî ñòðåëÿòü ââåðõ
6951 SetAIFlag('NEEDFIRE', '1');
6952 SetAIFlag('NEEDSEEUP', '1');
6955 // Âûáèðàåì óãîë âíèç:
6956 if FDirection
= TDirection
.D_LEFT
then
6957 angle
:= ANGLE_LEFTDOWN
6959 angle
:= ANGLE_RIGHTDOWN
;
6961 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6962 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6964 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6965 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6966 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6967 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6968 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6969 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6970 begin // òî íóæíî ñòðåëÿòü âíèç
6971 SetAIFlag('NEEDFIRE', '1');
6972 SetAIFlag('NEEDSEEDOWN', '1');
6975 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6976 if Target
.Visible
and
6977 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6978 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6980 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6981 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
6982 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6983 begin // òî íóæíî ñòðåëÿòü âïåðåä
6984 SetAIFlag('NEEDFIRE', '1');
6985 SetAIFlag('NEEDSEEDOWN', '');
6986 SetAIFlag('NEEDSEEUP', '');
6988 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6989 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6990 if GetRnd(FDifficult
.CloseJump
) then
6991 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6992 if Abs(FObj
.X
-Target
.X
) < 128 then
6996 if Random(a
) = 0 then
6997 SetAIFlag('NEEDJUMP', '1');
7001 // Åñëè öåëü âñå åùå åñòü:
7002 if Target
.UID
<> 0 then
7003 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
7004 Target
.UID
:= 0 // òî çàáûòü öåëü
7005 else // Åñëè âèäåëè íåäàâíî
7006 begin // íî öåëü óáèëè
7007 if Target
.IsPlayer
then
7008 begin // Öåëü - èãðîê
7009 pla
:= g_Player_Get(Target
.UID
);
7010 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
7011 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
7012 Target
.UID
:= 0; // òî çàáûòü öåëü
7015 begin // Öåëü - ìîíñòð
7016 mon
:= g_Monsters_ByUID(Target
.UID
);
7017 if (mon
= nil) or (not mon
.alive
) then
7018 Target
.UID
:= 0; // òî çàáûòü öåëü
7021 end; // if Target.UID <> 0
7023 FTargetUID
:= Target
.UID
;
7025 // Åñëè âîçìîæíûõ öåëåé íåò:
7026 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
7027 if targets
= nil then
7028 if GetAIFlag('ATTACKLEFT') <> '' then
7029 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
7030 RemoveAIFlag('ATTACKLEFT');
7032 SetAIFlag('NEEDJUMP', '1');
7034 if RunDirection() = TDirection
.D_RIGHT
then
7035 begin // Èäåì íå â òó ñòîðîíó
7036 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7037 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
7038 SetAIFlag('NEEDFIRE', '1');
7039 SetAIFlag('GOLEFT', '1');
7043 begin // Èäåì â íóæíóþ ñòîðîíó
7044 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7045 SetAIFlag('NEEDFIRE', '1');
7046 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7047 SetAIFlag('GORIGHT', '1');
7051 if GetAIFlag('ATTACKRIGHT') <> '' then
7052 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
7053 RemoveAIFlag('ATTACKRIGHT');
7055 SetAIFlag('NEEDJUMP', '1');
7057 if RunDirection() = TDirection
.D_LEFT
then
7058 begin // Èäåì íå â òó ñòîðîíó
7059 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7060 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
7061 SetAIFlag('NEEDFIRE', '1');
7062 SetAIFlag('GORIGHT', '1');
7067 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7068 SetAIFlag('NEEDFIRE', '1');
7069 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7070 SetAIFlag('GOLEFT', '1');
7074 //HACK! (does it belong there?)
7075 RealizeCurrentWeapon();
7077 // Åñëè åñòü âîçìîæíûå öåëè:
7078 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7079 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7080 for a
:= 0 to High(targets
) do
7082 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7083 if GetRnd(FDifficult
.DiagFire
) then
7085 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7086 if FDirection
= TDirection
.D_LEFT
then
7087 angle
:= ANGLE_LEFTUP
7089 angle
:= ANGLE_RIGHTUP
;
7091 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7092 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7094 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7095 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7096 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7097 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7098 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7100 SetAIFlag('NEEDFIRE', '1');
7101 SetAIFlag('NEEDSEEUP', '1');
7104 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7105 if FDirection
= TDirection
.D_LEFT
then
7106 angle
:= ANGLE_LEFTDOWN
7108 angle
:= ANGLE_RIGHTDOWN
;
7110 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7111 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7113 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7114 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7115 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7116 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7117 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7119 SetAIFlag('NEEDFIRE', '1');
7120 SetAIFlag('NEEDSEEDOWN', '1');
7124 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7125 if targets
[a
].Line
and targets
[a
].Visible
and
7126 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
7127 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
7129 SetAIFlag('NEEDFIRE', '1');
7134 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7135 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
7136 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
7137 40+GetInterval(FDifficult
.Cover
, 40)) then
7138 SetAIFlag('NEEDJUMP', '1');
7140 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7141 ammo
:= GetAmmoByWeapon(FCurrWeap
);
7142 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
7143 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
7145 SetAIFlag('SELECTWEAPON', '1');
7147 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7148 if GetAIFlag('SELECTWEAPON') = '1' then
7151 RemoveAIFlag('SELECTWEAPON');
7155 procedure TBot
.Update();
7168 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7169 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7171 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7173 if g_debug_BotAIOff
= 3 then
7183 RealizeCurrentWeapon();
7190 procedure TBot
.ReleaseKey(Key
: Byte);
7199 function TBot
.KeyPressed(Key
: Word): Boolean;
7201 Result
:= FKeys
[Key
].Pressed
;
7204 function TBot
.GetAIFlag(aName
: String20
): String20
;
7210 aName
:= LowerCase(aName
);
7212 if FAIFlags
<> nil then
7213 for a
:= 0 to High(FAIFlags
) do
7214 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7216 Result
:= FAIFlags
[a
].Value
;
7221 procedure TBot
.RemoveAIFlag(aName
: String20
);
7225 if FAIFlags
= nil then Exit
;
7227 aName
:= LowerCase(aName
);
7229 for a
:= 0 to High(FAIFlags
) do
7230 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7232 if a
<> High(FAIFlags
) then
7233 for b
:= a
to High(FAIFlags
)-1 do
7234 FAIFlags
[b
] := FAIFlags
[b
+1];
7236 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7241 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7249 aName
:= LowerCase(aName
);
7251 if FAIFlags
<> nil then
7252 for a
:= 0 to High(FAIFlags
) do
7253 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7259 if ok
then FAIFlags
[a
].Value
:= fValue
7262 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7263 with FAIFlags
[High(FAIFlags
)] do
7271 procedure TBot
.UpdateMove
;
7273 procedure GoLeft(Time
: Word = 1);
7275 ReleaseKey(KEY_LEFT
);
7276 ReleaseKey(KEY_RIGHT
);
7277 PressKey(KEY_LEFT
, Time
);
7278 SetDirection(TDirection
.D_LEFT
);
7281 procedure GoRight(Time
: Word = 1);
7283 ReleaseKey(KEY_LEFT
);
7284 ReleaseKey(KEY_RIGHT
);
7285 PressKey(KEY_RIGHT
, Time
);
7286 SetDirection(TDirection
.D_RIGHT
);
7289 function Rnd(a
: Word): Boolean;
7291 Result
:= Random(a
) = 0;
7294 procedure Turn(Time
: Word = 1200);
7296 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7301 ReleaseKey(KEY_LEFT
);
7302 ReleaseKey(KEY_RIGHT
);
7305 function CanRunLeft(): Boolean;
7307 Result
:= not CollideLevel(-1, 0);
7310 function CanRunRight(): Boolean;
7312 Result
:= not CollideLevel(1, 0);
7315 function CanRun(): Boolean;
7317 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7320 procedure Jump(Time
: Word = 30);
7322 PressKey(KEY_JUMP
, Time
);
7325 function NearHole(): Boolean;
7329 { TODO 5 : Ëåñòíèöû }
7330 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7331 for x
:= 1 to PLAYER_RECT
.Width
do
7332 if (not StayOnStep(x
*sx
, 0)) and
7333 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7334 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7343 function BorderHole(): Boolean;
7347 { TODO 5 : Ëåñòíèöû }
7348 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7349 for x
:= 1 to PLAYER_RECT
.Width
do
7350 if (not StayOnStep(x
*sx
, 0)) and
7351 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7352 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7354 for xx
:= x
to x
+32 do
7355 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7365 function NearDeepHole(): Boolean;
7371 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7374 for x
:= 1 to PLAYER_RECT
.Width
do
7375 if (not StayOnStep(x
*sx
, 0)) and
7376 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7377 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7379 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7381 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7386 end else Result
:= False;
7389 function OverDeepHole(): Boolean;
7396 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7398 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7405 function OnGround(): Boolean;
7407 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7410 function OnLadder(): Boolean;
7412 Result
:= FullInStep(0, 0);
7415 function BelowLadder(): Boolean;
7417 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7418 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7419 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7420 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7423 function BelowLiftUp(): Boolean;
7425 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7426 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7427 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7428 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7431 function OnTopLift(): Boolean;
7433 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7436 function CanJumpOver(): Boolean;
7440 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7444 if not CollideLevel(sx
, 0) then Exit
;
7446 for y
:= 1 to BOT_MAXJUMP
do
7447 if CollideLevel(0, -y
) then Exit
else
7448 if not CollideLevel(sx
, -y
) then
7455 function CanJumpUp(Dist
: ShortInt): Boolean;
7462 if CollideLevel(Dist
, 0) then Exit
;
7465 for y
:= 0 to BOT_MAXJUMP
do
7466 if CollideLevel(Dist
, -y
) then
7475 for yy
:= y
+1 to BOT_MAXJUMP
do
7476 if not CollideLevel(Dist
, -yy
) then
7485 for y
:= 0 to BOT_MAXJUMP
do
7486 if CollideLevel(0, -y
) then
7494 if y
< yy
then Exit
;
7499 function IsSafeTrigger(): Boolean;
7504 if gTriggers
= nil then
7506 for a
:= 0 to High(gTriggers
) do
7507 if Collide(gTriggers
[a
].X
,
7510 gTriggers
[a
].Height
) and
7511 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7512 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7513 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7514 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7515 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7520 // Âîçìîæíî, íàæèìàåì êíîïêó:
7521 if Rnd(16) and IsSafeTrigger() then
7524 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7525 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7527 ReleaseKey(KEY_LEFT
);
7528 ReleaseKey(KEY_RIGHT
);
7532 // Èäåì âëåâî, åñëè íàäî áûëî:
7533 if GetAIFlag('GOLEFT') <> '' then
7535 RemoveAIFlag('GOLEFT');
7536 if CanRunLeft() then
7540 // Èäåì âïðàâî, åñëè íàäî áûëî:
7541 if GetAIFlag('GORIGHT') <> '' then
7543 RemoveAIFlag('GORIGHT');
7544 if CanRunRight() then
7548 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7549 if FObj
.X
< -32 then
7552 if FObj
.X
+32 > gMapInfo
.Width
then
7555 // Ïðûãàåì, åñëè íàäî áûëî:
7556 if GetAIFlag('NEEDJUMP') <> '' then
7559 RemoveAIFlag('NEEDJUMP');
7562 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7563 if GetAIFlag('NEEDSEEUP') <> '' then
7566 ReleaseKey(KEY_DOWN
);
7567 PressKey(KEY_UP
, 20);
7568 RemoveAIFlag('NEEDSEEUP');
7571 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7572 if GetAIFlag('NEEDSEEDOWN') <> '' then
7575 ReleaseKey(KEY_DOWN
);
7576 PressKey(KEY_DOWN
, 20);
7577 RemoveAIFlag('NEEDSEEDOWN');
7580 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7581 if GetAIFlag('GOINHOLE') <> '' then
7582 if not OnGround() then
7584 ReleaseKey(KEY_LEFT
);
7585 ReleaseKey(KEY_RIGHT
);
7586 RemoveAIFlag('GOINHOLE');
7587 SetAIFlag('FALLINHOLE', '1');
7590 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7591 if GetAIFlag('FALLINHOLE') <> '' then
7593 RemoveAIFlag('FALLINHOLE');
7595 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7596 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7597 if GetAIFlag('FALLINHOLE') = '' then
7598 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7604 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7606 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7610 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7611 if OnGround() and NearHole() then
7612 if NearDeepHole() then // Åñëè ýòî áåçäíà
7614 0..3: Turn(); // Áåæèì îáðàòíî
7615 4: Jump(); // Ïðûãàåì
7616 5: begin // Ïðûãàåì îáðàòíî
7621 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7622 if GetAIFlag('GOINHOLE') = '' then
7624 0: Turn(); // Íå íóæíî òóäà
7625 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7626 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7627 if BorderHole() then
7628 SetAIFlag('GOINHOLE', '1');
7631 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7632 if (not CanRun()) and OnGround() then
7634 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7635 if CanJumpOver() or OnLadder() then
7637 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7638 if Random(2) = 0 then
7640 if IsSafeTrigger() then
7646 // Îñòàëîñü ìàëî âîçäóõà:
7647 if FAir
< 36 * 2 then
7650 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7651 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7652 if BodyInAcid(0, 0) then
7656 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7658 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7659 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7662 {function TBot.NeedItem(Item: Byte): Byte;
7667 procedure TBot
.SelectWeapon(Dist
: Integer);
7671 function HaveAmmo(weapon
: Byte): Boolean;
7674 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7675 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7676 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7677 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7678 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7679 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7680 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7681 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7682 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7683 else Result
:= True;
7688 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7690 if Dist
> BOT_LONGDIST
then
7691 begin // Äàëüíèé áîé
7693 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7695 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7699 else //if Dist > BOT_UNSAFEDIST then
7700 begin // Áëèæíèé áîé
7702 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7704 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7711 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7713 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7719 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7721 Result
:= inherited PickItem(ItemType
, force
, remove
);
7723 if Result
then SetAIFlag('SELECTWEAPON', '1');
7726 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7728 Result
:= inherited Heal(value
, Soft
);
7731 function TBot
.Healthy(): Byte;
7733 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7734 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7735 else if (FHealth
> 50) then Result
:= 2
7736 else if (FHealth
> 20) then Result
:= 1
7740 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7742 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7743 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7746 procedure TBot
.OnDamage(Angle
: SmallInt);
7754 if (Angle
= 0) or (Angle
= 180) then
7757 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7758 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7760 pla
:= g_Player_Get(FLastSpawnerUID
);
7761 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7762 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7765 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7766 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7768 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7769 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7770 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7775 SetAIFlag('ATTACKLEFT', '1')
7777 SetAIFlag('ATTACKRIGHT', '1');
7781 function TBot
.RunDirection(): TDirection
;
7783 if Abs(Vel
.X
) >= 1 then
7785 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7787 Result
:= FDirection
;
7790 function TBot
.GetRnd(a
: Byte): Boolean;
7792 if a
= 0 then Result
:= False
7793 else if a
= 255 then Result
:= True
7794 else Result
:= Random(256) > 255-a
;
7797 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7799 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7803 procedure TDifficult
.save (st
: TStream
);
7805 utils
.writeInt(st
, Byte(DiagFire
));
7806 utils
.writeInt(st
, Byte(InvisFire
));
7807 utils
.writeInt(st
, Byte(DiagPrecision
));
7808 utils
.writeInt(st
, Byte(FlyPrecision
));
7809 utils
.writeInt(st
, Byte(Cover
));
7810 utils
.writeInt(st
, Byte(CloseJump
));
7811 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7812 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7815 procedure TDifficult
.load (st
: TStream
);
7817 DiagFire
:= utils
.readByte(st
);
7818 InvisFire
:= utils
.readByte(st
);
7819 DiagPrecision
:= utils
.readByte(st
);
7820 FlyPrecision
:= utils
.readByte(st
);
7821 Cover
:= utils
.readByte(st
);
7822 CloseJump
:= utils
.readByte(st
);
7823 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7824 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7828 procedure TBot
.SaveState (st
: TStream
);
7833 inherited SaveState(st
);
7834 utils
.writeSign(st
, 'BOT0');
7836 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7838 utils
.writeInt(st
, Word(FTargetUID
));
7839 // Âðåìÿ ïîòåðè öåëè
7840 utils
.writeInt(st
, LongWord(FLastVisible
));
7841 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7842 dw
:= Length(FAIFlags
);
7843 utils
.writeInt(st
, LongInt(dw
));
7845 for i
:= 0 to dw
-1 do
7847 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7848 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7850 // Íàñòðîéêè ñëîæíîñòè
7851 FDifficult
.save(st
);
7855 procedure TBot
.LoadState (st
: TStream
);
7860 inherited LoadState(st
);
7861 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7863 FSelectedWeapon
:= utils
.readByte(st
);
7865 FTargetUID
:= utils
.readWord(st
);
7866 // Âðåìÿ ïîòåðè öåëè
7867 FLastVisible
:= utils
.readLongWord(st
);
7868 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7869 dw
:= utils
.readLongInt(st
);
7870 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7871 SetLength(FAIFlags
, dw
);
7873 for i
:= 0 to dw
-1 do
7875 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7876 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7878 // Íàñòðîéêè ñëîæíîñòè
7879 FDifficult
.load(st
);
7884 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);