1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
24 {$IFDEF USE_MEMPOOL}mempool
,{$ENDIF}
25 e_graphics
, g_playermodel
, g_basic
, g_textures
,
26 g_weapons
, g_phys
, g_sound
, g_saveload
, MAPDEF
,
59 AmmoLimits
: Array [0..1] of Array [A_BULLETS
..A_HIGH
] of Word =
60 ((200, 50, 50, 300, 100),
61 (400, 100, 100, 600, 200));
82 ANGLE_NONE
= Low(SmallInt);
84 CORPSE_STATE_REMOVEME
= 0;
85 CORPSE_STATE_NORMAL
= 1;
86 CORPSE_STATE_MESS
= 2;
88 PLAYER_RECT
: TRectWH
= (X
:15; Y
:12; Width
:34; Height
:52);
89 PLAYER_RECT_CX
= 15+(34 div 2);
90 PLAYER_RECT_CY
= 12+(52 div 2);
91 PLAYER_CORPSERECT
: TRectWH
= (X
:15; Y
:48; Width
:34; Height
:16);
94 PLAYER_HP_LIMIT
= 200;
96 PLAYER_AP_LIMIT
= 200;
99 PLAYER1_DEF_COLOR
: TRGB
= (R
:64; G
:175; B
:48);
100 PLAYER2_DEF_COLOR
: TRGB
= (R
:96; G
:96; B
:96);
116 TPlayerStatArray
= Array of TPlayerStat
;
118 TPlayerSavedState
= record
126 Ammo
: Array [A_BULLETS
..A_HIGH
] of Word;
127 MaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
128 Weapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
129 Rulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
138 TPlayer
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
146 FDirection
: TDirection
;
154 FMonsterKills
: Integer;
160 FCanJetpack
: Boolean;
165 //FNetForceWeap: Byte; // spam server with this -- this is new weapon we want to use
166 FNetForceWeapFIdx
: LongWord; // frame index; ignore weapon change if it is lesser than this
167 //FCurrFrameIdx: LongWord; // increased in each `Update()`
169 FNextWeapDelay
: Byte; // frames (unused)
170 FBFGFireCounter
: SmallInt;
171 FLastSpawnerUID
: Word;
175 FSpectatePlayer
: Integer;
176 FFirePainTime
: Integer;
179 FSavedState
: TPlayerSavedState
;
181 FModel
: TPlayerModel
;
182 FPunchAnim
: TAnimation
;
185 FActionForce
: Boolean;
186 FActionChanged
: Boolean;
188 FFireAngle
: SmallInt;
190 FShellTimer
: Integer;
192 FSawSound
: TPlayableSound
;
193 FSawSoundIdle
: TPlayableSound
;
194 FSawSoundHit
: TPlayableSound
;
195 FSawSoundSelect
: TPlayableSound
;
196 FJetSoundOn
: TPlayableSound
;
197 FJetSoundOff
: TPlayableSound
;
198 FJetSoundFly
: TPlayableSound
;
202 FJustTeleported
: Boolean;
204 mEDamageType
: Integer;
207 weaponSwitchKeyReleased
: array[0..16] of Byte; // bit 0: was released on prev frame; bit 1: new status
210 function CollideLevel(XInc
, YInc
: Integer): Boolean;
211 function StayOnStep(XInc
, YInc
: Integer): Boolean;
212 function HeadInLiquid(XInc
, YInc
: Integer): Boolean;
213 function BodyInLiquid(XInc
, YInc
: Integer): Boolean;
214 function BodyInAcid(XInc
, YInc
: Integer): Boolean;
215 function FullInLift(XInc
, YInc
: Integer): Integer;
216 {procedure CollideItem();}
217 procedure FlySmoke(Times
: DWORD
= 1);
218 procedure OnFireFlame(Times
: DWORD
= 1);
219 function GetAmmoByWeapon(Weapon
: Byte): Word;
220 procedure SetAction(Action
: Byte; Force
: Boolean = False);
221 procedure OnDamage(Angle
: SmallInt); virtual;
222 function firediry(): Integer;
225 procedure Run(Direction
: TDirection
);
226 procedure NextWeapon();
227 procedure PrevWeapon();
234 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
235 procedure resetWeaponQueue ();
236 function hasAmmoForWeapon (weapon
: Byte): Boolean;
238 procedure doDamage (v
: Integer);
240 function followCorpse(): Boolean;
243 FDamageBuffer
: Integer;
245 FAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
246 FMaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
247 FWeapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
248 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
250 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
251 FReloading
: Array [WP_FIRST
..WP_LAST
] of Word;
252 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
253 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
255 FPreferredTeam
: Byte;
258 FWantsInGame
: Boolean;
262 FActualModelName
: string;
269 // debug: viewport offset
270 viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer;
272 function isValidViewPort (): Boolean; inline;
274 constructor Create(); virtual;
275 destructor Destroy(); override;
276 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
277 function GetRespawnPoint(): Byte;
278 procedure PressKey(Key
: Byte; Time
: Word = 1);
279 procedure ReleaseKeys();
280 procedure ReleaseKeysNoWeapon();
281 procedure SetModel(ModelName
: String);
282 procedure SetColor(Color
: TRGB
);
283 procedure SetWeapon(W
: Byte);
284 function IsKeyPressed(K
: Byte): Boolean;
285 function GetKeys(): Byte;
286 function PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean; virtual;
287 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
288 function Collide(Panel
: TPanel
): Boolean; overload
;
289 function Collide(X
, Y
: Integer): Boolean; overload
;
290 procedure SetDirection(Direction
: TDirection
);
291 procedure GetSecret();
292 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
294 procedure Push(vx
, vy
: Integer);
295 procedure ChangeModel(ModelName
: String);
296 procedure SwitchTeam
;
297 procedure ChangeTeam(Team
: Byte);
299 function GetFlag(Flag
: Byte): Boolean;
300 procedure SetFlag(Flag
: Byte);
301 function DropFlag(): Boolean;
302 procedure AllRulez(Health
: Boolean);
303 procedure RestoreHealthArmor();
304 procedure FragCombo();
305 procedure GiveItem(ItemType
: Byte);
306 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
307 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
308 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
309 procedure MakeBloodSimple(Count
: Word);
310 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
311 procedure Reset(Force
: Boolean);
312 procedure Spectate(NoMove
: Boolean = False);
313 procedure SwitchNoClip
;
314 procedure SoftReset();
315 procedure Draw(); virtual;
316 procedure DrawPain();
317 procedure DrawPickup();
318 procedure DrawRulez();
320 procedure DrawIndicator();
321 procedure DrawBubble();
323 procedure Update(); virtual;
324 procedure RememberState();
325 procedure RecallState();
326 procedure SaveState (st
: TStream
); virtual;
327 procedure LoadState (st
: TStream
); virtual;
328 procedure PauseSounds(Enable
: Boolean);
329 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
330 procedure DoLerp(Level
: Integer = 2);
331 procedure SetLerp(XTo
, YTo
: Integer);
332 procedure QueueWeaponSwitch(Weapon
: Byte);
333 procedure RealizeCurrentWeapon();
335 procedure JetpackOff
;
336 procedure CatchFire(Attacker
: Word);
338 //WARNING! this does nothing for now, but still call it!
339 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
341 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
342 procedure moveBy (dx
, dy
: Integer); inline;
344 procedure releaseAllWeaponSwitchKeys ();
345 procedure weaponSwitchKeysStateChange (index
: Integer; pressed
: Boolean);
346 function isWeaponSwitchKeyReleased (index
: Integer): Boolean;
347 procedure weaponSwitchKeysShiftNewStates ();
350 property Vel
: TPoint2i read FObj
.Vel
;
351 property Obj
: TObj read FObj
;
353 property Name
: String read FName write FName
;
354 property Model
: TPlayerModel read FModel
;
355 property Health
: Integer read FHealth write FHealth
;
356 property Lives
: Byte read FLives write FLives
;
357 property Armor
: Integer read FArmor write FArmor
;
358 property Air
: Integer read FAir write FAir
;
359 property JetFuel
: Integer read FJetFuel write FJetFuel
;
360 property Frags
: Integer read FFrags write FFrags
;
361 property Death
: Integer read FDeath write FDeath
;
362 property Kills
: Integer read FKills write FKills
;
363 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
364 //property NetForceWeap: Byte read FNetForceWeap write FNetForceWeap;
365 property NetForceWeapFIdx
: LongWord read FNetForceWeapFIdx write FNetForceWeapFIdx
;
366 //property CurrFrameIdx: LongWord read FCurrFrameIdx write FCurrFrameIdx;
367 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
368 property Secrets
: Integer read FSecrets
;
369 property GodMode
: Boolean read FGodMode write FGodMode
;
370 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
371 property NoReload
: Boolean read FNoReload write FNoReload
;
372 property alive
: Boolean read FAlive write FAlive
;
373 property Flag
: Byte read FFlag
;
374 property Team
: Byte read FTeam write FTeam
;
375 property Direction
: TDirection read FDirection
;
376 property GameX
: Integer read FObj
.X write FObj
.X
;
377 property GameY
: Integer read FObj
.Y write FObj
.Y
;
378 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
379 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
380 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
381 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
382 property IncCam
: Integer read FIncCam write FIncCam
;
383 property UID
: Word read FUID write FUID
;
384 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
385 property NetTime
: LongWord read FNetTime write FNetTime
;
388 property eName
: String read FName write FName
;
389 property eHealth
: Integer read FHealth write FHealth
;
390 property eLives
: Byte read FLives write FLives
;
391 property eArmor
: Integer read FArmor write FArmor
;
392 property eAir
: Integer read FAir write FAir
;
393 property eJetFuel
: Integer read FJetFuel write FJetFuel
;
394 property eFrags
: Integer read FFrags write FFrags
;
395 property eDeath
: Integer read FDeath write FDeath
;
396 property eKills
: Integer read FKills write FKills
;
397 property eCurrWeap
: Byte read FCurrWeap write FCurrWeap
;
398 property eMonsterKills
: Integer read FMonsterKills write FMonsterKills
;
399 property eSecrets
: Integer read FSecrets write FSecrets
;
400 property eGodMode
: Boolean read FGodMode write FGodMode
;
401 property eNoTarget
: Boolean read FNoTarget write FNoTarget
;
402 property eNoReload
: Boolean read FNoReload write FNoReload
;
403 property eAlive
: Boolean read FAlive write FAlive
;
404 property eFlag
: Byte read FFlag
;
405 property eTeam
: Byte read FTeam write FTeam
;
406 property eDirection
: TDirection read FDirection
;
407 property eGameX
: Integer read FObj
.X write FObj
.X
;
408 property eGameY
: Integer read FObj
.Y write FObj
.Y
;
409 property eGameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
410 property eGameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
411 property eGameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
412 property eGameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
413 property eIncCam
: Integer read FIncCam write FIncCam
;
414 property eUID
: Word read FUID
;
415 property eJustTeleported
: Boolean read FJustTeleported
;
416 property eNetTime
: LongWord read FNetTime
;
418 // set this before assigning something to `eDamage`
419 property eDamageType
: Integer read mEDamageType write mEDamageType
;
420 property eDamage
: Integer write doDamage
;
431 WeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
432 CloseWeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
433 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
436 procedure save (st
: TStream
);
437 procedure load (st
: TStream
);
445 TBot
= class(TPlayer
)
447 FSelectedWeapon
: Byte;
450 FAIFlags
: Array of TAIFlag
;
451 FDifficult
: TDifficult
;
453 function GetRnd(a
: Byte): Boolean;
454 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
455 function RunDirection(): TDirection
;
456 function FullInStep(XInc
, YInc
: Integer): Boolean;
457 //function NeedItem(Item: Byte): Byte;
458 procedure SelectWeapon(Dist
: Integer);
459 procedure SetAIFlag(aName
, fValue
: String20
);
460 function GetAIFlag(aName
: String20
): String20
;
461 procedure RemoveAIFlag(aName
: String20
);
462 function Healthy(): Byte;
463 procedure UpdateMove();
464 procedure UpdateCombat();
465 function KeyPressed(Key
: Word): Boolean;
466 procedure ReleaseKey(Key
: Byte);
467 function TargetOnScreen(TX
, TY
: Integer): Boolean;
468 procedure OnDamage(Angle
: SmallInt); override;
471 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
472 constructor Create(); override;
473 destructor Destroy(); override;
474 procedure Draw(); override;
475 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
476 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
477 procedure Update(); override;
478 procedure SaveState (st
: TStream
); override;
479 procedure LoadState (st
: TStream
); override;
491 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
492 procedure moveBy (dx
, dy
: Integer); inline;
494 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
508 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
509 procedure moveBy (dx
, dy
: Integer); inline;
511 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
514 TCorpse
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
523 FAnimation
: TAnimation
;
524 FAnimationMask
: TAnimation
;
527 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
528 destructor Destroy(); override;
529 procedure Damage(Value
: Word; vx
, vy
: Integer);
532 procedure SaveState (st
: TStream
);
533 procedure LoadState (st
: TStream
);
535 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
536 procedure moveBy (dx
, dy
: Integer); inline;
538 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
540 function ObjPtr (): PObj
; inline;
542 property Obj
: TObj read FObj
; // copies object
543 property State
: Byte read FState
;
544 property Mess
: Boolean read FMess
;
547 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
553 gPlayers
: Array of TPlayer
;
554 gCorpses
: Array of TCorpse
;
555 gGibs
: Array of TGib
;
556 gShells
: Array of TShell
;
557 gTeamStat
: TTeamStat
;
558 gFly
: Boolean = False;
559 gAimLine
: Boolean = False;
560 gChatBubble
: Byte = 0;
561 gPlayerIndicator
: Boolean = True;
565 MAX_RUNVEL
: Integer = 8;
566 VEL_JUMP
: Integer = 10;
567 SHELL_TIMEOUT
: Cardinal = 60000;
569 function Lerp(X
, Y
, Factor
: Integer): Integer;
571 procedure g_Gibs_SetMax(Count
: Word);
572 function g_Gibs_GetMax(): Word;
573 procedure g_Corpses_SetMax(Count
: Word);
574 function g_Corpses_GetMax(): Word;
575 procedure g_Shells_SetMax(Count
: Word);
576 function g_Shells_GetMax(): Word;
578 procedure g_Player_Init();
579 procedure g_Player_Free();
580 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
581 function g_Player_CreateFromState (st
: TStream
): Word;
582 procedure g_Player_Remove(UID
: Word);
583 procedure g_Player_ResetTeams();
584 procedure g_Player_UpdateAll();
585 procedure g_Player_DrawAll();
586 procedure g_Player_DrawDebug(p
: TPlayer
);
587 procedure g_Player_DrawHealth();
588 procedure g_Player_RememberAll();
589 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
590 function g_Player_Get(UID
: Word): TPlayer
;
591 function g_Player_GetCount(): Byte;
592 function g_Player_GetStats(): TPlayerStatArray
;
593 function g_Player_ValidName(Name
: String): Boolean;
594 procedure g_Player_CreateCorpse(Player
: TPlayer
);
595 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
596 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
597 procedure g_Player_UpdatePhysicalObjects();
598 procedure g_Player_DrawCorpses();
599 procedure g_Player_DrawShells();
600 procedure g_Player_RemoveAllCorpses();
601 procedure g_Player_Corpses_SaveState (st
: TStream
);
602 procedure g_Player_Corpses_LoadState (st
: TStream
);
603 procedure g_Bot_Add(Team
, Difficult
: Byte);
604 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1);
605 procedure g_Bot_MixNames();
606 procedure g_Bot_RemoveAll();
611 {$INCLUDE ../nogl/noGLuses.inc}
612 {$IFDEF ENABLE_HOLMES}
615 e_log
, g_map
, g_items
, g_console
, g_gfx
, Math
,
616 g_options
, g_triggers
, g_menu
, g_game
, g_grid
,
617 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
,
618 g_net
, g_netmsg
, g_window
,
621 const PLR_SAVE_VERSION
= 0;
631 diag_precision
: Byte;
635 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
636 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
637 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
641 TIME_RESPAWN1
= 1500;
642 TIME_RESPAWN2
= 2000;
643 TIME_RESPAWN3
= 3000;
646 JET_MAX
= 540; // ~30 sec
647 PLAYER_SUIT_TIME
= 30000;
648 PLAYER_INVUL_TIME
= 30000;
649 PLAYER_INVIS_TIME
= 35000;
650 FRAG_COMBO_TIME
= 3000;
654 ANGLE_RIGHTDOWN
= -35;
656 ANGLE_LEFTDOWN
= -145;
657 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
658 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
661 BOT_UNSAFEDIST
= 128;
662 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
664 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
665 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
666 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
667 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
668 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
669 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
670 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
671 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
672 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
673 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
674 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
675 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
676 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
677 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
678 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
679 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
680 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
681 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
682 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
683 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
684 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
685 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
686 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
687 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
688 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
689 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
691 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
692 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
694 BOTNAMES_FILENAME
= 'botnames.txt';
695 BOTLIST_FILENAME
= 'botlist.txt';
699 MaxCorpses
: Word = 20;
700 MaxShells
: Word = 300;
701 CurrentGib
: Integer = 0;
702 CurrentShell
: Integer = 0;
703 BotNames
: Array of String;
704 BotList
: Array of TBotProfile
;
707 function Lerp(X
, Y
, Factor
: Integer): Integer;
709 Result
:= X
+ ((Y
- X
) div Factor
);
712 function SameTeam(UID1
, UID2
: Word): Boolean;
716 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
717 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
719 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
721 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
722 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
724 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
727 procedure g_Gibs_SetMax(Count
: Word);
730 SetLength(gGibs
, Count
);
732 if CurrentGib
>= Count
then
736 function g_Gibs_GetMax(): Word;
741 procedure g_Shells_SetMax(Count
: Word);
744 SetLength(gShells
, Count
);
746 if CurrentShell
>= Count
then
750 function g_Shells_GetMax(): Word;
756 procedure g_Corpses_SetMax(Count
: Word);
759 SetLength(gCorpses
, Count
);
762 function g_Corpses_GetMax(): Word;
764 Result
:= MaxCorpses
;
767 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
777 // Åñòü ëè ìåñòî â gPlayers:
778 if gPlayers
<> nil then
779 for a
:= 0 to High(gPlayers
) do
780 if gPlayers
[a
] = nil then
786 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
789 SetLength(gPlayers
, Length(gPlayers
)+1);
793 // Ñîçäàåì îáúåêò èãðîêà:
795 gPlayers
[a
] := TBot
.Create()
797 gPlayers
[a
] := TPlayer
.Create();
800 gPlayers
[a
].FActualModelName
:= ModelName
;
801 gPlayers
[a
].SetModel(ModelName
);
803 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
804 if gPlayers
[a
].FModel
= nil then
808 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
812 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
813 if Random(2) = 0 then
817 gPlayers
[a
].FPreferredTeam
:= Team
;
819 case gGameSettings
.GameMode
of
820 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
822 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
824 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
827 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
828 gPlayers
[a
].FColor
:= Color
;
829 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
830 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
832 gPlayers
[a
].FModel
.Color
:= Color
;
834 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
835 gPlayers
[a
].FAlive
:= False;
837 Result
:= gPlayers
[a
].FUID
;
840 function g_Player_CreateFromState (st
: TStream
): Word;
847 if (st
= nil) then exit
; //???
850 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
851 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
854 Bot
:= utils
.readBool(st
);
859 // Åñòü ëè ìåñòî â gPlayers:
860 for a
:= 0 to High(gPlayers
) do if (gPlayers
[a
] = nil) then begin ok
:= true; break
; end;
862 // Íåò ìåñòà - ðàñøèðÿåì gPlayers
865 SetLength(gPlayers
, Length(gPlayers
)+1);
869 // Ñîçäàåì îáúåêò èãðîêà
871 gPlayers
[a
] := TBot
.Create()
873 gPlayers
[a
] := TPlayer
.Create();
874 gPlayers
[a
].FIamBot
:= Bot
;
875 gPlayers
[a
].FPhysics
:= True;
878 gPlayers
[a
].FUID
:= utils
.readWord(st
);
880 gPlayers
[a
].FName
:= utils
.readStr(st
);
882 gPlayers
[a
].FTeam
:= utils
.readByte(st
);
883 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
885 gPlayers
[a
].FAlive
:= utils
.readBool(st
);
886 // Èçðàñõîäîâàë ëè âñå æèçíè
887 gPlayers
[a
].FNoRespawn
:= utils
.readBool(st
);
889 b
:= utils
.readByte(st
);
890 if b
= 1 then gPlayers
[a
].FDirection
:= TDirection
.D_LEFT
else gPlayers
[a
].FDirection
:= TDirection
.D_RIGHT
; // b = 2
892 gPlayers
[a
].FHealth
:= utils
.readLongInt(st
);
894 gPlayers
[a
].FLives
:= utils
.readByte(st
);
896 gPlayers
[a
].FArmor
:= utils
.readLongInt(st
);
898 gPlayers
[a
].FAir
:= utils
.readLongInt(st
);
900 gPlayers
[a
].FJetFuel
:= utils
.readLongInt(st
);
902 gPlayers
[a
].FPain
:= utils
.readLongInt(st
);
904 gPlayers
[a
].FKills
:= utils
.readLongInt(st
);
906 gPlayers
[a
].FMonsterKills
:= utils
.readLongInt(st
);
908 gPlayers
[a
].FFrags
:= utils
.readLongInt(st
);
910 gPlayers
[a
].FFragCombo
:= utils
.readByte(st
);
911 // Âðåìÿ ïîñëåäíåãî ôðàãà
912 gPlayers
[a
].FLastFrag
:= utils
.readLongWord(st
);
914 gPlayers
[a
].FDeath
:= utils
.readLongInt(st
);
916 gPlayers
[a
].FFlag
:= utils
.readByte(st
);
918 gPlayers
[a
].FSecrets
:= utils
.readLongInt(st
);
920 gPlayers
[a
].FCurrWeap
:= utils
.readByte(st
);
921 //gPlayers[a].FNetForceWeap := gPlayers[a].FCurrWeap;
922 // Ñëåäóþùåå æåëàåìîå îðóæèå
923 gPlayers
[a
].FNextWeap
:= utils
.readWord(st
);
925 gPlayers
[a
].FNextWeapDelay
:= utils
.readByte(st
);
927 gPlayers
[a
].FBFGFireCounter
:= utils
.readSmallInt(st
);
929 gPlayers
[a
].FDamageBuffer
:= utils
.readLongInt(st
);
930 // Ïîñëåäíèé óäàðèâøèé
931 gPlayers
[a
].FLastSpawnerUID
:= utils
.readWord(st
);
932 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
933 gPlayers
[a
].FLastHit
:= utils
.readByte(st
);
935 Obj_LoadState(@gPlayers
[a
].FObj
, st
);
936 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
937 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FAmmo
[i
] := utils
.readWord(st
);
938 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
939 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FMaxAmmo
[i
] := utils
.readWord(st
);
941 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FWeapon
[i
] := utils
.readBool(st
);
942 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
943 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FReloading
[i
] := utils
.readWord(st
);
945 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
946 // Íàëè÷èå êðàñíîãî êëþ÷à
947 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
948 // Íàëè÷èå çåëåíîãî êëþ÷à
949 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
950 // Íàëè÷èå ñèíåãî êëþ÷à
951 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
953 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_BERSERK
);
954 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
955 for i
:= MR_SUIT
to MR_MAX
do gPlayers
[a
].FMegaRulez
[i
] := utils
.readLongWord(st
);
956 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
957 for i
:= T_RESPAWN
to T_FLAGCAP
do gPlayers
[a
].FTime
[i
] := utils
.readLongWord(st
);
960 gPlayers
[a
].FActualModelName
:= utils
.readStr(st
);
962 gPlayers
[a
].FColor
.R
:= utils
.readByte(st
);
963 gPlayers
[a
].FColor
.G
:= utils
.readByte(st
);
964 gPlayers
[a
].FColor
.B
:= utils
.readByte(st
);
965 // Îáíîâëÿåì ìîäåëü èãðîêà
966 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
968 // Íåò ìîäåëè - ñîçäàíèå íåâîçìîæíî
969 if (gPlayers
[a
].FModel
= nil) then
973 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
977 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû
978 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
979 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
981 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
983 result
:= gPlayers
[a
].FUID
;
987 procedure g_Player_ResetTeams();
991 if g_Game_IsClient
then
993 if gPlayers
= nil then
995 for a
:= Low(gPlayers
) to High(gPlayers
) do
996 if gPlayers
[a
] <> nil then
997 case gGameSettings
.GameMode
of
999 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
1001 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
1002 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
1003 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
1006 gPlayers
[a
].ChangeTeam(TEAM_RED
)
1008 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
1011 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
1015 procedure g_Bot_Add(Team
, Difficult
: Byte);
1018 _name
, _model
: String;
1021 if not g_Game_IsServer
then Exit
;
1023 // Ñïèñîê íàçâàíèé ìîäåëåé:
1024 m
:= g_PlayerModel_GetNames();
1029 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1030 Team
:= TEAM_COOP
// COOP
1032 if gGameSettings
.GameMode
= GM_DM
then
1033 Team
:= TEAM_NONE
// DM
1035 if Team
= TEAM_NONE
then // CTF / TDM
1037 // Àâòîáàëàíñ êîìàíä:
1041 for a
:= 0 to High(gPlayers
) do
1042 if gPlayers
[a
] <> nil then
1044 if gPlayers
[a
].Team
= TEAM_RED
then
1047 if gPlayers
[a
].Team
= TEAM_BLUE
then
1057 if Random(2) = 0 then
1063 // Âûáèðàåì áîòó èìÿ:
1065 if BotNames
<> nil then
1066 for a
:= 0 to High(BotNames
) do
1067 if g_Player_ValidName(BotNames
[a
]) then
1069 _name
:= BotNames
[a
];
1073 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
1076 _name
:= Format('DFBOT%.2d', [Random(100)]);
1077 until g_Player_ValidName(_name
);
1079 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1080 _model
:= m
[Random(Length(m
))];
1083 with g_Player_Get(g_Player_Create(_model
,
1084 _RGB(Min(Random(9)*32, 255),
1085 Min(Random(9)*32, 255),
1086 Min(Random(9)*32, 255)),
1087 Team
, True)) as TBot
do
1092 1: FDifficult
:= DIFFICULT_EASY
;
1093 2: FDifficult
:= DIFFICULT_MEDIUM
;
1094 else FDifficult
:= DIFFICULT_HARD
;
1097 for a
:= WP_FIRST
to WP_LAST
do
1099 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1100 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1101 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1104 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1106 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1107 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1112 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1);
1115 _name
, _model
: String;
1118 if not g_Game_IsServer
then Exit
;
1120 // Ñïèñîê íàçâàíèé ìîäåëåé:
1121 m
:= g_PlayerModel_GetNames();
1126 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1127 Team
:= TEAM_COOP
// COOP
1129 if gGameSettings
.GameMode
= GM_DM
then
1130 Team
:= TEAM_NONE
// DM
1132 if Team
= TEAM_NONE
then
1133 Team
:= BotList
[num
].team
; // CTF / TDM
1135 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1136 lName
:= AnsiLowerCase(lName
);
1137 if (num
< 0) or (num
> Length(BotList
)-1) then
1139 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1140 for a
:= 0 to High(BotList
) do
1141 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1150 _name
:= BotList
[num
].name
;
1151 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1152 if not g_Player_ValidName(_name
) then
1154 _name
:= Format('DFBOT%.2d', [Random(100)]);
1155 until g_Player_ValidName(_name
);
1158 _model
:= BotList
[num
].model
;
1159 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1160 if not InSArray(_model
, m
) then
1161 _model
:= m
[Random(Length(m
))];
1164 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1168 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1169 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1170 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1171 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1172 FDifficult
.Cover
:= BotList
[num
].cover
;
1173 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1175 for a
:= WP_FIRST
to WP_LAST
do
1177 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1178 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1179 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1182 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1184 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1188 procedure g_Bot_RemoveAll();
1192 if not g_Game_IsServer
then Exit
;
1193 if gPlayers
= nil then Exit
;
1195 for a
:= 0 to High(gPlayers
) do
1196 if gPlayers
[a
] <> nil then
1197 if gPlayers
[a
] is TBot
then
1199 gPlayers
[a
].Lives
:= 0;
1200 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1201 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1202 g_Player_Remove(gPlayers
[a
].FUID
);
1208 procedure g_Bot_MixNames();
1213 if BotNames
<> nil then
1214 for a
:= 0 to High(BotNames
) do
1216 b
:= Random(Length(BotNames
));
1218 Botnames
[a
] := BotNames
[b
];
1223 procedure g_Player_Remove(UID
: Word);
1227 if gPlayers
= nil then Exit
;
1229 if g_Game_IsServer
and g_Game_IsNet
then
1230 MH_SEND_PlayerDelete(UID
);
1232 for i
:= 0 to High(gPlayers
) do
1233 if gPlayers
[i
] <> nil then
1234 if gPlayers
[i
].FUID
= UID
then
1236 if gPlayers
[i
] is TPlayer
then
1237 TPlayer(gPlayers
[i
]).Free()
1239 TBot(gPlayers
[i
]).Free();
1245 procedure g_Player_Init();
1255 if not FileExists(DataDir
+ BOTNAMES_FILENAME
) then
1258 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1259 AssignFile(F
, DataDir
+ BOTNAMES_FILENAME
);
1270 SetLength(BotNames
, Length(BotNames
)+1);
1271 BotNames
[High(BotNames
)] := s
;
1279 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1280 config
:= TConfig
.CreateFile(DataDir
+ BOTLIST_FILENAME
);
1284 while config
.SectionExists(IntToStr(a
)) do
1286 SetLength(BotList
, Length(BotList
)+1);
1288 with BotList
[High(BotList
)] do
1291 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1293 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1295 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1300 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1301 color
.R
:= StrToIntDef(sa
[0], 0);
1302 color
.G
:= StrToIntDef(sa
[1], 0);
1303 color
.B
:= StrToIntDef(sa
[2], 0);
1304 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1305 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1306 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1307 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1308 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1309 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1310 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1311 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1312 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1313 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1314 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1315 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1316 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1317 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1318 if Length(sa
) = 10 then
1320 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1321 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1322 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1323 if Length(sa
) = 10 then
1325 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1327 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1328 if Length(sa) = 10 then
1330 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1339 procedure g_Player_Free();
1343 if gPlayers
<> nil then
1345 for i
:= 0 to High(gPlayers
) do
1346 if gPlayers
[i
] <> nil then
1348 if gPlayers
[i
] is TPlayer
then
1349 TPlayer(gPlayers
[i
]).Free()
1351 TBot(gPlayers
[i
]).Free();
1362 procedure g_Player_UpdateAll();
1366 if gPlayers
= nil then Exit
;
1368 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1369 for i
:= 0 to High(gPlayers
) do
1371 if gPlayers
[i
] <> nil then
1373 if gPlayers
[i
] is TPlayer
then
1375 gPlayers
[i
].Update();
1376 if (not gPlayers
[i
].alive
) then gPlayers
[i
].NetForceWeapFIdx
:= 0; // just in case
1377 //if g_Game_IsClient or not g_Game_IsNet then
1379 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1384 // bot updates weapons in `UpdateCombat()`
1385 TBot(gPlayers
[i
]).Update();
1389 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1392 procedure g_Player_DrawAll();
1396 if gPlayers
= nil then Exit
;
1398 for i
:= 0 to High(gPlayers
) do
1399 if gPlayers
[i
] <> nil then
1400 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1401 else TBot(gPlayers
[i
]).Draw();
1404 procedure g_Player_DrawDebug(p
: TPlayer
);
1408 if p
= nil then Exit
;
1409 if (@p
.FObj
) = nil then Exit
;
1411 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1413 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1414 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1415 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1416 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1417 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1418 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1421 procedure g_Player_DrawHealth();
1426 if gPlayers
= nil then Exit
;
1427 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1429 for i
:= 0 to High(gPlayers
) do
1430 if gPlayers
[i
] <> nil then
1432 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1433 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1434 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1435 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1436 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1437 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1441 function g_Player_Get(UID
: Word): TPlayer
;
1447 if gPlayers
= nil then
1450 for a
:= 0 to High(gPlayers
) do
1451 if gPlayers
[a
] <> nil then
1452 if gPlayers
[a
].FUID
= UID
then
1454 Result
:= gPlayers
[a
];
1459 function g_Player_GetCount(): Byte;
1465 if gPlayers
= nil then
1468 for a
:= 0 to High(gPlayers
) do
1469 if gPlayers
[a
] <> nil then
1470 Result
:= Result
+ 1;
1473 function g_Player_GetStats(): TPlayerStatArray
;
1479 if gPlayers
= nil then Exit
;
1481 for a
:= 0 to High(gPlayers
) do
1482 if gPlayers
[a
] <> nil then
1484 SetLength(Result
, Length(Result
)+1);
1485 with Result
[High(Result
)] do
1487 Ping
:= gPlayers
[a
].FPing
;
1488 Loss
:= gPlayers
[a
].FLoss
;
1489 Name
:= gPlayers
[a
].FName
;
1490 Team
:= gPlayers
[a
].FTeam
;
1491 Frags
:= gPlayers
[a
].FFrags
;
1492 Deaths
:= gPlayers
[a
].FDeath
;
1493 Kills
:= gPlayers
[a
].FKills
;
1494 Color
:= gPlayers
[a
].FModel
.Color
;
1495 Lives
:= gPlayers
[a
].FLives
;
1496 Spectator
:= gPlayers
[a
].FSpectator
;
1501 procedure g_Player_RememberAll
;
1505 for i
:= Low(gPlayers
) to High(gPlayers
) do
1506 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1507 gPlayers
[i
].RememberState
;
1510 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1514 gTeamStat
[TEAM_RED
].Goals
:= 0;
1515 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1517 if gPlayers
<> nil then
1518 for i
:= 0 to High(gPlayers
) do
1519 if gPlayers
[i
] <> nil then
1521 gPlayers
[i
].Reset(Force
);
1523 if gPlayers
[i
] is TPlayer
then
1525 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1526 gPlayers
[i
].Respawn(Silent
)
1528 gPlayers
[i
].Spectate();
1531 TBot(gPlayers
[i
]).Respawn(Silent
);
1535 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1541 if Player
.alive
then
1544 // Ðàçðûâàåì ñâÿçü ñ ïðåæíèì òðóïîì:
1545 if gCorpses
<> nil then
1546 for i
:= 0 to High(gCorpses
) do
1547 if gCorpses
[i
] <> nil then
1548 if gCorpses
[i
].FPlayerUID
= Player
.FUID
then
1549 gCorpses
[i
].FPlayerUID
:= 0;
1551 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1556 if (FHealth
>= -50) or (gGibsCount
= 0) then
1558 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1562 for find_id
:= 0 to High(gCorpses
) do
1563 if gCorpses
[find_id
] = nil then
1570 find_id
:= Random(Length(gCorpses
));
1572 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1573 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1574 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1575 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1576 gCorpses
[find_id
].FPlayerUID
:= FUID
;
1579 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1580 FObj
.Y
+ PLAYER_RECT_CY
,
1581 FModel
.Name
, FModel
.Color
);
1585 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1589 if (gShells
= nil) or (Length(gShells
) = 0) then
1592 with gShells
[CurrentShell
] do
1598 if T
= SHELL_BULLET
then
1600 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1604 Obj
.Rect
.Width
:= 4;
1605 Obj
.Rect
.Height
:= 2;
1609 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1613 Obj
.Rect
.Width
:= 7;
1614 Obj
.Rect
.Height
:= 3;
1620 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1621 positionChanged(); // this updates spatial accelerators
1622 RAngle
:= Random(360);
1623 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1625 if CurrentShell
>= High(gShells
) then
1632 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1635 GibsArray
: TGibsArray
;
1638 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1640 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1642 Blood
:= g_PlayerModel_GetBlood(ModelName
);
1644 for a
:= 0 to High(GibsArray
) do
1645 with gGibs
[CurrentGib
] do
1648 ID
:= GibsArray
[a
].ID
;
1649 MaskID
:= GibsArray
[a
].MaskID
;
1652 Obj
.Rect
:= GibsArray
[a
].Rect
;
1653 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1654 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1655 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1656 positionChanged(); // this updates spatial accelerators
1657 RAngle
:= Random(360);
1659 if gBloodCount
> 0 then
1660 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1661 Random(48), Random(48), Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
1663 if CurrentGib
>= High(gGibs
) then
1670 procedure g_Player_UpdatePhysicalObjects();
1676 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1681 if T
= SHELL_BULLET
then
1682 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1684 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1689 if gGibs
<> nil then
1690 for i
:= 0 to High(gGibs
) do
1691 if gGibs
[i
].alive
then
1695 mr
:= g_Obj_Move(@Obj
, True, False, True);
1696 positionChanged(); // this updates spatial accelerators
1698 if WordBool(mr
and MOVE_FALLOUT
) then
1704 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1705 if WordBool(mr
and MOVE_HITWALL
) then
1706 Obj
.Vel
.X
:= -(vel
.X
div 2);
1707 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1708 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1710 if (Obj
.Vel
.X
>= 0) then
1712 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1713 if RAngle
>= 360 then
1714 RAngle
:= RAngle
mod 360;
1715 end else begin // Counter-clockwise
1716 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1718 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1721 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1722 if gTime
mod (GAME_TICK
*3) = 0 then
1723 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1727 if gCorpses
<> nil then
1728 for i
:= 0 to High(gCorpses
) do
1729 if gCorpses
[i
] <> nil then
1730 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1736 gCorpses
[i
].Update();
1739 if gShells
<> nil then
1740 for i
:= 0 to High(gShells
) do
1741 if gShells
[i
].alive
then
1745 mr
:= g_Obj_Move(@Obj
, True, False, True);
1746 positionChanged(); // this updates spatial accelerators
1748 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1754 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1755 if WordBool(mr
and MOVE_HITWALL
) then
1757 Obj
.Vel
.X
:= -(vel
.X
div 2);
1758 if not WordBool(mr
and MOVE_INWATER
) then
1759 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1761 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1763 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1764 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1765 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1767 if RAngle
mod 90 <> 0 then
1768 RAngle
:= (RAngle
div 90) * 90;
1770 else if not WordBool(mr
and MOVE_INWATER
) then
1771 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1774 if (Obj
.Vel
.X
>= 0) then
1776 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1777 if RAngle
>= 360 then
1778 RAngle
:= RAngle
mod 360;
1779 end else begin // Counter-clockwise
1780 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1782 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1788 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1790 x
:= Obj
.X
+Obj
.Rect
.X
;
1791 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1792 w
:= Obj
.Rect
.Width
;
1793 h
:= Obj
.Rect
.Height
;
1796 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1798 if (dx
<> 0) or (dy
<> 0) then
1807 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1811 w
:= Obj
.Rect
.Width
;
1812 h
:= Obj
.Rect
.Height
;
1815 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1817 if (dx
<> 0) or (dy
<> 0) then
1826 procedure TGib
.positionChanged (); inline; begin end;
1827 procedure TShell
.positionChanged (); inline; begin end;
1830 procedure g_Player_DrawCorpses();
1835 if gGibs
<> nil then
1836 for i
:= 0 to High(gGibs
) do
1837 if gGibs
[i
].alive
then
1840 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1843 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1844 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1846 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1849 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1855 if gCorpses
<> nil then
1856 for i
:= 0 to High(gCorpses
) do
1857 if gCorpses
[i
] <> nil then
1861 procedure g_Player_DrawShells();
1866 if gShells
<> nil then
1867 for i
:= 0 to High(gShells
) do
1868 if gShells
[i
].alive
then
1871 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1877 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1881 procedure g_Player_RemoveAllCorpses();
1887 SetLength(gGibs
, MaxGibs
);
1888 SetLength(gShells
, MaxGibs
);
1892 if gCorpses
<> nil then
1893 for i
:= 0 to High(gCorpses
) do
1897 SetLength(gCorpses
, MaxCorpses
);
1900 procedure g_Player_Corpses_SaveState (st
: TStream
);
1904 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ
1906 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1908 // Êîëè÷åñòâî òðóïîâ
1909 utils
.writeInt(st
, LongInt(count
));
1911 if (count
= 0) then exit
;
1914 for i
:= 0 to High(gCorpses
) do
1916 if gCorpses
[i
] <> nil then
1919 utils
.writeStr(st
, gCorpses
[i
].FModelName
);
1921 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1922 // Ñîõðàíÿåì äàííûå òðóïà:
1923 gCorpses
[i
].SaveState(st
);
1929 procedure g_Player_Corpses_LoadState (st
: TStream
);
1937 g_Player_RemoveAllCorpses();
1939 // Êîëè÷åñòâî òðóïîâ:
1940 count
:= utils
.readLongInt(st
);
1941 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1943 if (count
= 0) then exit
;
1946 for i
:= 0 to count
-1 do
1949 str
:= utils
.readStr(st
);
1951 b
:= utils
.readBool(st
);
1953 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1954 // Çàãðóæàåì äàííûå òðóïà
1955 gCorpses
[i
].LoadState(st
);
1962 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1964 procedure TPlayer
.BFGHit();
1966 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1967 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1968 if g_Game_IsServer
and g_Game_IsNet
then
1969 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1970 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1974 procedure TPlayer
.ChangeModel(ModelName
: string);
1976 locModel
: TPlayerModel
;
1978 locModel
:= g_PlayerModel_Get(ModelName
);
1979 if locModel
= nil then Exit
;
1985 procedure TPlayer
.SetModel(ModelName
: string);
1989 m
:= g_PlayerModel_Get(ModelName
);
1992 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1993 m
:= g_PlayerModel_Get('doomer');
1996 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
2001 if FModel
<> nil then
2006 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2007 FModel
.Color
:= FColor
2009 FModel
.Color
:= TEAMCOLOR
[FTeam
];
2010 FModel
.SetWeapon(FCurrWeap
);
2011 FModel
.SetFlag(FFlag
);
2012 SetDirection(FDirection
);
2015 procedure TPlayer
.SetColor(Color
: TRGB
);
2018 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2019 if FModel
<> nil then FModel
.Color
:= Color
;
2022 procedure TPlayer
.SwitchTeam
;
2024 if g_Game_IsClient
then
2026 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
2028 if gGameOn
and FAlive
then
2029 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
2031 if FTeam
= TEAM_RED
then
2033 ChangeTeam(TEAM_BLUE
);
2034 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
2035 if g_Game_IsNet
then
2036 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
2040 ChangeTeam(TEAM_RED
);
2041 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
2042 if g_Game_IsNet
then
2043 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
2045 FPreferredTeam
:= FTeam
;
2048 procedure TPlayer
.ChangeTeam(Team
: Byte);
2055 TEAM_RED
, TEAM_BLUE
:
2056 FModel
.Color
:= TEAMCOLOR
[Team
];
2058 FModel
.Color
:= FColor
;
2060 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2061 MH_SEND_PlayerStats(FUID
);
2065 procedure TPlayer.CollideItem();
2070 if gItems = nil then Exit;
2071 if not FAlive then Exit;
2073 for i := 0 to High(gItems) do
2076 if (ItemType <> ITEM_NONE) and alive then
2077 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2078 PLAYER_RECT.Height, @Obj) then
2080 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2082 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2083 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2084 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2085 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2086 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2088 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2089 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2090 (gGameSettings.GameType = GT_SINGLE) and
2091 (g_Player_GetCount() > 1)) then
2092 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2098 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2100 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2101 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2105 constructor TPlayer
.Create();
2111 mEDamageType
:= HIT_SOME
;
2117 FSawSound
:= TPlayableSound
.Create();
2118 FSawSoundIdle
:= TPlayableSound
.Create();
2119 FSawSoundHit
:= TPlayableSound
.Create();
2120 FSawSoundSelect
:= TPlayableSound
.Create();
2121 FJetSoundFly
:= TPlayableSound
.Create();
2122 FJetSoundOn
:= TPlayableSound
.Create();
2123 FJetSoundOff
:= TPlayableSound
.Create();
2125 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2126 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2127 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2128 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2129 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2130 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2131 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2133 FSpectatePlayer
:= -1;
2137 FSavedState
.WaitRecall
:= False;
2143 FActualModelName
:= 'doomer';
2146 FObj
.Rect
:= PLAYER_RECT
;
2148 FBFGFireCounter
:= -1;
2149 FJustTeleported
:= False;
2152 //FNetForceWeap := FCurrWeap;
2153 FNetForceWeapFIdx
:= 0;
2154 //FCurrFrameIdx := 0;
2157 releaseAllWeaponSwitchKeys();
2161 procedure TPlayer
.releaseAllWeaponSwitchKeys ();
2165 for f
:= 0 to High(weaponSwitchKeyReleased
) do weaponSwitchKeyReleased
[f
] := $03;
2168 procedure TPlayer
.weaponSwitchKeysStateChange (index
: Integer; pressed
: Boolean);
2170 Inc(index
, 2); // -2: prev; -1: next
2171 if (index
< 0) or (index
> High(weaponSwitchKeyReleased
)) then exit
;
2172 weaponSwitchKeyReleased
[index
] := weaponSwitchKeyReleased
[index
] or $02;
2173 if (pressed
) then weaponSwitchKeyReleased
[index
] := weaponSwitchKeyReleased
[index
] xor $02;
2176 function TPlayer
.isWeaponSwitchKeyReleased (index
: Integer): Boolean;
2178 Inc(index
, 2); // -2: prev; -1: next
2179 if (index
< 0) or (index
> High(weaponSwitchKeyReleased
)) then
2185 result
:= (weaponSwitchKeyReleased
[index
] and $01) <> 0;
2189 procedure TPlayer
.weaponSwitchKeysShiftNewStates ();
2193 // copy bit 1 to bit 0
2194 for f
:= 0 to High(weaponSwitchKeyReleased
) do
2196 weaponSwitchKeyReleased
[f
] :=
2197 (weaponSwitchKeyReleased
[f
] and $02) or
2198 ((weaponSwitchKeyReleased
[f
] shr 1) and $01);
2203 procedure TPlayer
.positionChanged (); inline;
2207 procedure TPlayer
.doDamage (v
: Integer);
2209 if (v
<= 0) then exit
;
2210 if (v
> 32767) then v
:= 32767;
2211 Damage(v
, 0, 0, 0, mEDamageType
);
2214 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2218 if (not g_Game_IsClient
) and (not FAlive
) then
2223 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2224 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2226 if not g_Game_IsClient
then
2229 if t
= HIT_TRAP
then
2231 // Ëîâóøêà óáèâàåò ñðàçó:
2233 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2235 if t
= HIT_SELF
then
2239 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2242 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2243 FMegaRulez
[MR_SUIT
] := 0;
2244 FMegaRulez
[MR_INVUL
] := 0;
2245 FMegaRulez
[MR_INVIS
] := 0;
2249 // Íî îò îñòàëüíîãî ñïàñàåò:
2250 if FMegaRulez
[MR_INVUL
] >= gTime
then
2257 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2258 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2259 (SpawnerUID
= FUID
) or
2260 (not SameTeam(FUID
, SpawnerUID
)) then
2262 FLastSpawnerUID
:= SpawnerUID
;
2264 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2265 if gBloodCount
> 0 then
2267 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2268 if value
div 4 <= c
then
2269 c
:= c
- (value
div 4)
2273 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2277 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2278 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2281 if t
= HIT_WATER
then
2282 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2283 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2288 Inc(FDamageBuffer
, value
);
2292 FPain
:= FPain
+ value
;
2295 if g_Game_IsServer
and g_Game_IsNet
then
2297 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2298 MH_SEND_PlayerStats(FUID
);
2299 MH_SEND_PlayerPos(False, FUID
);
2303 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2306 if g_Game_IsClient
then
2311 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2313 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2316 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2318 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2322 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2323 MH_SEND_PlayerStats(FUID
);
2326 destructor TPlayer
.Destroy();
2328 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2330 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2334 FSawSoundIdle
.Free();
2335 FSawSoundHit
.Free();
2336 FJetSoundFly
.Free();
2338 FJetSoundOff
.Free();
2340 if FPunchAnim
<> nil then
2346 procedure TPlayer
.DrawIndicator();
2348 indX
, indY
: Integer;
2354 indX
:= FObj
.X
+FObj
.Rect
.X
;
2355 indY
:= FObj
.Y
- 12;
2356 if g_Texture_Get('TEXTURE_PLAYER_INDICATOR', ID
) then
2358 e_GetTextureSize(ID
, @indW
, @indH
);
2359 e_Draw(ID
, indX
+ indW
div 2, indY
, 0, True, False);
2362 //e_TextureFontPrint(indX, indY, FName, gStdFont); // Shows player name overhead
2365 procedure TPlayer
.DrawBubble();
2367 bubX
, bubY
: Integer;
2370 Rw
, Gw
, Bw
: SmallInt;
2373 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= TDirection
.D_LEFT
, -4, 18);
2374 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2382 1: // simple textual non-bubble
2384 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2385 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2386 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2389 2: // advanced pixel-perfect bubble
2391 if FTeam
= TEAM_RED
then
2394 if FTeam
= TEAM_BLUE
then
2397 3: // colored bubble
2399 Rb
:= FModel
.Color
.R
;
2400 Gb
:= FModel
.Color
.G
;
2401 Bb
:= FModel
.Color
.B
;
2402 Rw
:= Min(Rb
* 2 + 64, 255);
2403 Gw
:= Min(Gb
* 2 + 64, 255);
2404 Bw
:= Min(Bb
* 2 + 64, 255);
2405 if (Abs(Rw
- Rb
) < 32)
2406 or (Abs(Gw
- Gb
) < 32)
2407 or (Abs(Bw
- Bb
) < 32) then
2409 Rb
:= Max(Rw
div 2 - 16, 0);
2410 Gb
:= Max(Gw
div 2 - 16, 0);
2411 Bb
:= Max(Bw
div 2 - 16, 0);
2414 4: // custom textured bubble
2416 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2417 if FDirection
= TDirection
.D_RIGHT
then
2418 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2420 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, TMirrorType
.Horizontal
);
2426 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2427 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2429 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2432 Dot
:= IfThen(FDirection
= TDirection
.D_LEFT
, 14, 5);
2433 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2434 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
);
2435 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
);
2436 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
);
2437 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
);
2441 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2442 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2443 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2446 procedure TPlayer
.Draw();
2451 Mirror
: TMirrorType
;
2455 if Direction
= TDirection
.D_RIGHT
then
2456 Mirror
:= TMirrorType
.None
2458 Mirror
:= TMirrorType
.Horizontal
;
2460 if FPunchAnim
<> nil then
2462 FPunchAnim
.Draw(FObj
.X
+IfThen(Direction
= TDirection
.D_LEFT
, 15-FObj
.Rect
.X
, FObj
.Rect
.X
-15),
2463 FObj
.Y
+FObj
.Rect
.Y
-11, Mirror
);
2464 if FPunchAnim
.played
then
2471 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2472 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2474 e_GetTextureSize(ID
, @w
, @h
);
2475 if FDirection
= TDirection
.D_LEFT
then
2476 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2477 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False)
2479 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2480 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False);
2483 if FMegaRulez
[MR_INVIS
] > gTime
then
2485 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2486 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2488 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2489 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2493 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 200)
2495 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2498 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 254);
2501 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2504 if g_debug_Frames
then
2506 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2508 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2509 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2513 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2515 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2516 if gAimLine
and alive
and
2517 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2522 procedure TPlayer
.DrawAim();
2523 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2528 {$IFDEF ENABLE_HOLMES}
2529 if isValidViewPort
and (self
= gPlayer1
) then
2531 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2535 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2536 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2538 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2542 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2547 wx
, wy
, xx
, yy
: Integer;
2551 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= TDirection
.D_LEFT
, 7, -7);
2552 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2561 1: begin // Chainsaw
2568 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2569 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2570 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2571 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2576 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2577 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2578 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2579 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2581 4: begin // Double Shotgun
2584 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2585 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2586 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2587 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2589 5: begin // Chaingun
2592 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2593 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2594 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2595 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2597 6: begin // Rocket Launcher
2600 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2601 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2602 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2603 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2605 7: begin // Plasmagun
2608 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2609 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2610 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2611 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2616 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2617 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2618 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2619 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2621 9: begin // Super Chaingun
2624 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2625 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2626 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2627 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2630 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2631 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2632 {$IF DEFINED(D2F_DEBUG)}
2633 drawCast(sz
, wx
, wy
, xx
, yy
);
2635 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2639 procedure TPlayer
.DrawGUI();
2642 X
, Y
, SY
, a
, p
, m
: Integer;
2646 stat
: TPlayerStatArray
;
2648 X
:= gPlayerScreenSize
.X
;
2649 SY
:= gPlayerScreenSize
.Y
;
2652 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2654 if gGameSettings
.GameMode
= GM_CTF
then
2658 if gGameSettings
.GameMode
= GM_CTF
then
2660 s
:= 'TEXTURE_PLAYER_REDFLAG';
2661 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2662 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2663 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2664 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2665 if g_Texture_Get(s
, ID
) then
2666 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2669 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2670 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2671 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2673 if gGameSettings
.GameMode
= GM_CTF
then
2675 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2676 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2677 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2678 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2679 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2680 if g_Texture_Get(s
, ID
) then
2681 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2684 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2685 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2686 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2689 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2690 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2693 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2694 e_Draw(ID
, X
+2, Y
, 0, True, False);
2696 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2700 s
:= IntToStr(Frags
);
2701 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2702 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2707 stat
:= g_Player_GetStats();
2712 for a
:= 0 to High(stat
) do
2713 if stat
[a
].Name
<> Name
then
2715 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2716 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2720 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2721 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2722 s
:= s
+IntToStr(Abs(Frags
-m
));
2724 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2725 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2728 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2730 s
:= IntToStr(Lives
);
2731 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2732 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2736 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2737 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2739 if R_BERSERK
in FRulez
then
2740 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2742 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2744 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2745 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2747 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2748 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2749 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2751 s
:= IntToStr(FArmor
);
2752 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2753 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2755 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2761 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2766 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2768 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2769 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2770 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2771 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2772 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2773 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2774 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2775 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2776 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2779 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2780 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2781 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2783 if R_KEY_RED
in FRulez
then
2784 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2786 if R_KEY_GREEN
in FRulez
then
2787 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2789 if R_KEY_BLUE
in FRulez
then
2790 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2792 if FJetFuel
> 0 then
2794 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2795 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2796 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2797 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2798 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2799 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2803 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2804 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2805 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2808 if gShowPing
and g_Game_IsClient
then
2810 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2811 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2817 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2818 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2819 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2822 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2823 s
:= _lc
[I_PLAYER_SPECT4
];
2824 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2825 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2826 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2832 procedure TPlayer
.DrawRulez();
2836 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2837 if FMegaRulez
[MR_INVUL
] >= gTime
then
2839 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2840 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2845 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2846 191, 191, 191, 0, TBlending
.Invert
);
2849 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2850 if FMegaRulez
[MR_SUIT
] >= gTime
then
2852 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2853 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2858 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2859 0, 96, 0, 200, TBlending
.None
);
2862 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2863 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2865 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2866 255, 0, 0, 200, TBlending
.None
);
2870 procedure TPlayer
.DrawPain();
2874 if FPain
= 0 then Exit
;
2878 if a
< 15 then h
:= 0
2879 else if a
< 35 then h
:= 1
2880 else if a
< 55 then h
:= 2
2881 else if a
< 75 then h
:= 3
2882 else if a
< 95 then h
:= 4
2885 //if a > 255 then a := 255;
2887 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2888 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2891 procedure TPlayer
.DrawPickup();
2895 if FPickup
= 0 then Exit
;
2899 if a
< 15 then h
:= 1
2900 else if a
< 35 then h
:= 2
2901 else if a
< 55 then h
:= 3
2902 else if a
< 75 then h
:= 4
2905 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2908 procedure TPlayer
.DoPunch();
2913 if FPunchAnim
<> nil then begin
2918 st
:= 'FRAMES_PUNCH';
2919 if R_BERSERK
in FRulez
then
2920 st
:= st
+ '_BERSERK';
2921 if FKeys
[KEY_UP
].Pressed
then
2923 else if FKeys
[KEY_DOWN
].Pressed
then
2925 g_Frames_Get(id
, st
);
2926 FPunchAnim
:= TAnimation
.Create(id
, False, 1);
2929 procedure TPlayer
.Fire();
2931 f
, DidFire
: Boolean;
2932 wx
, wy
, xd
, yd
: Integer;
2935 if g_Game_IsClient
then Exit
;
2936 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2937 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2945 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2950 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2951 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2952 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
2953 yd
:= wy
+firediry();
2959 if R_BERSERK
in FRulez
then
2961 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2962 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2963 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2966 locobj
.rect
.Width
:= 39;
2967 locobj
.rect
.Height
:= 52;
2968 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2969 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2970 locobj
.Accel
.X
:= xd
-wx
;
2971 locobj
.Accel
.y
:= yd
-wy
;
2973 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2974 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2976 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2978 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
2982 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2986 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2991 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2992 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2994 FSawSoundSelect
.Stop();
2996 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2998 else if not FSawSoundHit
.IsPlaying() then
3000 FSawSoundSelect
.Stop();
3001 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
3004 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3010 if FAmmo
[A_BULLETS
] > 0 then
3012 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
3013 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3014 Dec(FAmmo
[A_BULLETS
]);
3015 FFireAngle
:= FAngle
;
3018 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3019 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3023 if FAmmo
[A_SHELLS
] > 0 then
3025 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3026 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
3027 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3028 Dec(FAmmo
[A_SHELLS
]);
3029 FFireAngle
:= FAngle
;
3033 FShellType
:= SHELL_SHELL
;
3037 if FAmmo
[A_SHELLS
] >= 2 then
3039 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
3040 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3041 Dec(FAmmo
[A_SHELLS
], 2);
3042 FFireAngle
:= FAngle
;
3046 FShellType
:= SHELL_DBLSHELL
;
3050 if FAmmo
[A_BULLETS
] > 0 then
3052 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
3053 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
3054 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3055 Dec(FAmmo
[A_BULLETS
]);
3056 FFireAngle
:= FAngle
;
3059 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3060 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3063 WEAPON_ROCKETLAUNCHER
:
3064 if FAmmo
[A_ROCKETS
] > 0 then
3066 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
3067 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3068 Dec(FAmmo
[A_ROCKETS
]);
3069 FFireAngle
:= FAngle
;
3075 if FAmmo
[A_CELLS
] > 0 then
3077 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
3078 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3079 Dec(FAmmo
[A_CELLS
]);
3080 FFireAngle
:= FAngle
;
3086 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
3088 FBFGFireCounter
:= 17;
3089 if not FNoReload
then
3090 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
3091 Dec(FAmmo
[A_CELLS
], 40);
3095 WEAPON_SUPERPULEMET
:
3096 if FAmmo
[A_SHELLS
] > 0 then
3098 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3099 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
3100 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3101 Dec(FAmmo
[A_SHELLS
]);
3102 FFireAngle
:= FAngle
;
3105 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3106 GameVelX
, GameVelY
-2, SHELL_SHELL
);
3109 WEAPON_FLAMETHROWER
:
3110 if FAmmo
[A_FUEL
] > 0 then
3112 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
3113 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3115 FFireAngle
:= FAngle
;
3121 if g_Game_IsNet
then
3125 if FCurrWeap
<> WEAPON_BFG
then
3126 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
3128 if not FNoReload
then
3129 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
3132 MH_SEND_PlayerStats(FUID
);
3137 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
3138 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
3139 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
3142 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
3145 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
3146 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
3147 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
3148 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
3149 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
3154 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
3156 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
3157 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
3158 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
3161 procedure TPlayer
.JetpackOn
;
3165 FJetSoundOn
.SetPosition(0);
3166 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3170 procedure TPlayer
.JetpackOff
;
3174 FJetSoundOff
.SetPosition(0);
3175 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3178 procedure TPlayer
.CatchFire(Attacker
: Word);
3181 FFireAttacker
:= Attacker
;
3182 if g_Game_IsNet
and g_Game_IsServer
then
3183 MH_SEND_PlayerStats(FUID
);
3186 procedure TPlayer
.Jump();
3188 if gFly
or FJetpack
then
3190 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3191 if FObj
.Vel
.Y
> -VEL_FLY
then
3192 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3195 if FJetFuel
> 0 then
3197 if (FJetFuel
< 1) and g_Game_IsServer
then
3201 if g_Game_IsNet
then
3202 MH_SEND_PlayerStats(FUID
);
3208 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3210 FCanJetpack
:= False;
3212 // Ïðûãàåì èëè âñïëûâàåì:
3213 if (CollideLevel(0, 1) or
3214 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3215 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3216 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3218 FObj
.Vel
.Y
:= -VEL_JUMP
;
3219 FCanJetpack
:= False;
3223 if BodyInLiquid(0, 0) then
3224 FObj
.Vel
.Y
:= -VEL_SW
3225 else if (FJetFuel
> 0) and FCanJetpack
and
3226 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3230 if g_Game_IsNet
then
3231 MH_SEND_PlayerStats(FUID
);
3236 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3238 a
, i
, k
, ab
, ar
: Byte;
3242 srv
, netsrv
: Boolean;
3248 procedure PushItem(t
: Byte);
3252 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3253 it
:= g_Items_ByIdx(id
);
3254 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3256 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3257 (FObj
.Vel
.Y
div 2)-Random(9));
3258 it
.positionChanged(); // this updates spatial accelerators
3262 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3264 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3265 (FObj
.Vel
.Y
div 2)-Random(6));
3267 else // -3..+3; -3..0
3269 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3270 (FObj
.Vel
.Y
div 2)-Random(4));
3272 it
.positionChanged(); // this updates spatial accelerators
3275 if g_Game_IsNet
and g_Game_IsServer
then
3276 MH_SEND_ItemSpawn(True, id
);
3280 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3281 Srv
:= g_Game_IsServer
;
3282 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3283 if Srv
then FDeath
:= FDeath
+ 1;
3288 if not FPhysics
then
3294 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3296 if FLives
> 0 then FLives
:= FLives
- 1;
3297 if FLives
= 0 then FNoRespawn
:= True;
3300 // Íîìåð òèïà ñìåðòè:
3303 K_SIMPLEKILL
: a
:= 1;
3305 K_EXTRAHARDKILL
: a
:= 3;
3310 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3312 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3319 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3321 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3322 K_EXTRAHARDKILL
, K_FALLKILL
:
3323 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3326 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3330 K_HARDKILL
, K_EXTRAHARDKILL
:
3334 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3335 if (KillType
<> K_FALLKILL
) and (Srv
) then
3336 g_Monsters_killedp();
3338 if SpawnerUID
= FUID
then
3340 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3345 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3348 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3349 begin // Óáèò äðóãèì èãðîêîì
3350 KP
:= g_Player_Get(SpawnerUID
);
3351 if (KP
<> nil) and Srv
then
3353 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3354 if SameTeam(FUID
, SpawnerUID
) then
3364 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3365 Inc(gTeamStat
[KP
.Team
].Goals
,
3366 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3368 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3371 plr
:= g_Player_Get(SpawnerUID
);
3379 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3383 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3387 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3392 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3393 begin // Óáèò ìîíñòðîì
3394 mon
:= g_Monsters_ByUID(SpawnerUID
);
3398 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
3402 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3406 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3410 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3415 else // Îñîáûå òèïû ñìåðòè
3418 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3419 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3420 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3421 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3422 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3423 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3429 for a
:= WP_FIRST
to WP_LAST
do
3433 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3434 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3435 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3436 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3437 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3438 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3439 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3440 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3441 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3450 if R_ITEM_BACKPACK
in FRulez
then
3451 PushItem(ITEM_AMMO_BACKPACK
);
3453 // Âûáðîñ ðàêåòíîãî ðàíöà:
3454 if FJetFuel
> 0 then
3455 PushItem(ITEM_JETPACK
);
3458 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3460 if R_KEY_RED
in FRulez
then
3461 PushItem(ITEM_KEY_RED
);
3463 if R_KEY_GREEN
in FRulez
then
3464 PushItem(ITEM_KEY_GREEN
);
3466 if R_KEY_BLUE
in FRulez
then
3467 PushItem(ITEM_KEY_BLUE
);
3474 g_Player_CreateCorpse(Self
);
3476 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3477 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3483 for i
:= Low(gPlayers
) to High(gPlayers
) do
3485 if gPlayers
[i
] = nil then continue
;
3486 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3489 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3490 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3495 OldLR
:= gLMSRespawn
;
3496 if (gGameSettings
.GameMode
= GM_COOP
) then
3500 // everyone is dead, restart the map
3501 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3503 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3504 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3505 gLMSRespawnTime
:= gTime
+ 5000;
3507 else if (a
= 1) then
3509 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3510 if (gPlayers
[k
] = gPlayer1
) or
3511 (gPlayers
[k
] = gPlayer2
) then
3512 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3513 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3514 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3517 else if (gGameSettings
.GameMode
= GM_TDM
) then
3519 if (ab
= 0) and (ar
<> 0) then
3522 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3524 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3525 Inc(gTeamStat
[TEAM_RED
].Goals
);
3526 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3527 gLMSRespawnTime
:= gTime
+ 5000;
3529 else if (ar
= 0) and (ab
<> 0) then
3532 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3534 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3535 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3536 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3537 gLMSRespawnTime
:= gTime
+ 5000;
3539 else if (ar
= 0) and (ab
= 0) then
3542 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3544 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3545 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3546 gLMSRespawnTime
:= gTime
+ 5000;
3549 else if (gGameSettings
.GameMode
= GM_DM
) then
3553 if gPlayers
[k
] <> nil then
3556 // survivor is the winner
3557 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3559 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3562 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3563 gLMSRespawnTime
:= gTime
+ 5000;
3565 else if (a
= 0) then
3567 // everyone is dead, restart the map
3568 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3570 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3571 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3572 gLMSRespawnTime
:= gTime
+ 5000;
3575 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3577 if NetMode
= NET_SERVER
then
3578 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3580 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3586 MH_SEND_PlayerStats(FUID
);
3587 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3588 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3591 if srv
and FNoRespawn
then Spectate(True);
3592 FWantsInGame
:= True;
3595 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3597 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3598 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3601 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3603 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3604 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3607 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3609 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3610 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3611 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3612 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3613 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3614 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3615 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3616 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3619 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3621 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3622 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3623 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3624 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3627 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3629 //if g_Game_IsClient then Exit;
3630 if Weapon
> High(FWeapon
) then Exit
;
3631 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3634 procedure TPlayer
.resetWeaponQueue ();
3637 FNextWeapDelay
:= 0;
3640 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3644 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3645 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
3646 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
3647 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3648 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3649 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3650 else result
:= (weapon
< length(FWeapon
));
3654 // return 255 for "no switch"
3655 function TPlayer
.getNextWeaponIndex (): Byte;
3658 wantThisWeapon
: array[0..64] of Boolean;
3659 weaponOrder
: array[0..16] of Integer; // value: index in `FWeapon`
3661 f
, dir
, cwi
, rwidx
, curlidx
: Integer;
3663 function real2log (ridx
: Integer): Integer;
3669 for f
:= 0 to High(weaponOrder
) do if (weaponOrder
[f
] = ridx
) then begin result
:= f
; exit
; end;
3675 result
:= 255; // default result: "no switch"
3677 // had weapon cycling on previous frame? remove that flag
3678 if (FNextWeap
and $2000) <> 0 then
3680 FNextWeap
:= FNextWeap
and $1FFF;
3681 FNextWeapDelay
:= 0;
3684 for f
:= 0 to High(weaponOrder
) do weaponOrder
[f
] := -1;
3686 // build weapon order (k8: i know, i know, learn how to do constants and such... gtfo, please!)
3687 // two knuckles are for "normal" and "berserk" (see `if` below -- it removes the one that is not needed)
3689 // bfg, launcher, plasma, flamethrower, ssg, minigun, sg, pistol, berserk, chainsaw, fist
3690 weaponOrder
[0] := WEAPON_SUPERPULEMET
;
3691 weaponOrder
[1] := WEAPON_BFG
;
3692 weaponOrder
[2] := WEAPON_ROCKETLAUNCHER
;
3693 weaponOrder
[3] := WEAPON_PLASMA
;
3694 weaponOrder
[4] := WEAPON_FLAMETHROWER
;
3695 weaponOrder
[5] := WEAPON_SHOTGUN2
;
3696 weaponOrder
[6] := WEAPON_CHAINGUN
;
3697 weaponOrder
[7] := WEAPON_SHOTGUN1
;
3698 weaponOrder
[8] := WEAPON_PISTOL
;
3699 weaponOrder
[9] := WEAPON_KASTET
+666; // berserk fist
3700 weaponOrder
[10] := WEAPON_SAW
;
3701 weaponOrder
[11] := WEAPON_KASTET
; // normal fist
3703 for f
:= 0 to High(weaponOrder
) do
3705 if (weaponOrder
[f
] = WEAPON_KASTET
) then
3707 // normal fist: remove if we have a berserk pack
3708 if (R_BERSERK
in FRulez
) then weaponOrder
[f
] := -1;
3711 if (weaponOrder
[f
] = WEAPON_KASTET
+666) then
3713 // berserk fist: remove if we don't have a berserk pack
3714 if (R_BERSERK
in FRulez
) then weaponOrder
[f
] := WEAPON_KASTET
else weaponOrder
[f
] := -1;
3722 WEAPON_SHOTGUN1 = 3;
3723 WEAPON_SHOTGUN2 = 4;
3724 WEAPON_CHAINGUN = 5;
3725 WEAPON_ROCKETLAUNCHER = 6;
3728 WEAPON_SUPERPULEMET = 9;
3729 WEAPON_FLAMETHROWER = 10;
3732 // cycling has priority
3733 if (FNextWeap
and $C000) <> 0 then
3735 if (FNextWeap
and $8000) <> 0 then dir
:= 1 else dir
:= -1; // should be reversed if we want "priority-driven cycling"
3736 FNextWeap
:= FNextWeap
or $2000; // we need this
3737 if FNextWeapDelay
> 0 then exit
; // cooldown time
3738 //cwi := real2log(FCurrWeap);
3739 //if (cwi < 0) then cwi := 0;
3741 for i
:= 0 to High(FWeapon
) do
3743 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3744 //rwidx := weaponOrder[cwi];
3745 rwidx
:= cwi
; // sorry
3746 if (rwidx
< 0) then continue
;
3747 if FWeapon
[rwidx
] then
3749 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d (dir=%d; log=%d)', [FCurrWeap, rwidx, dir, cwi]), TMsgType.Warning);
3750 result
:= Byte(rwidx
);
3751 //FNextWeapDelay := 10; //k8: not needed anymore
3760 for i
:= 0 to High(wantThisWeapon
) do wantThisWeapon
[i
] := false;
3763 curlidx
:= -1; // start from a weapon with a highest priority (-1, 'cause loop will immediately increment this index)
3765 for i
:= 0 to High(FWeapon
) do
3767 if (FNextWeap
and (1 shl i
)) <> 0 then
3772 wantThisWeapon
[cwi
] := true;
3774 // if we hit currently selected weapon, start seachring from it, so we'll get "next weaker" weapon
3775 if (i
= FCurrWeap
) then curlidx
:= cwi
; // compare real, start from logical
3780 // slow down alterations a little
3783 // more than one weapon requested, assume "alteration", and check alteration delay
3784 if FNextWeapDelay
> 0 then
3786 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), TMsgType.Warning);
3792 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3793 // but clear all counters if no weapon should be switched
3800 //e_WriteLog(Format('*** wwc=%d; currweap=%d; logweap=%d', [wwc, FCurrWeap, curlidx]), TMsgType.Warning);
3802 // find next weapon to switch onto
3804 for i
:= 0 to High(weaponOrder
) do
3806 cwi
:= (cwi
+length(weaponOrder
)+1) mod length(weaponOrder
);
3807 if (cwi
= curlidx
) then continue
; // skip current weapon
3808 if not wantThisWeapon
[cwi
] then continue
;
3809 rwidx
:= weaponOrder
[cwi
];
3810 if (rwidx
< 0) then continue
;
3811 //e_WriteLog(Format(' trying logical %d (real %d); has=%d, hasammo=%d', [cwi, rwidx, Integer(FWeapon[rwidx]), Integer(hasAmmoForWeapon(rwidx))]), TMsgType.Warning);
3812 if FWeapon
[rwidx
] and ((wwc
= 1) or hasAmmoForWeapon(rwidx
)) then
3814 //e_WriteLog(' I FOUND HER!', TMsgType.Warning);
3816 result
:= Byte(rwidx
);
3818 //FNextWeapDelay := 10; // anyway, 'cause why not; k8: not needed anymore
3823 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3827 procedure TPlayer
.RealizeCurrentWeapon();
3828 function switchAllowed (): Boolean;
3833 if FBFGFireCounter
<> -1 then
3835 if FTime
[T_SWITCH
] > gTime
then
3837 for i
:= WP_FIRST
to WP_LAST
do
3838 if FReloading
[i
] > 0 then
3846 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3847 //FNextWeap := FNextWeap and $1FFF;
3848 //HACK: alteration delay will be reset when player released any weapon switch key
3849 FNextWeapDelay
:= 0; //k8: just in case
3850 //if FNextWeapDelay > 0 then Dec(FNextWeapDelay); // "alteration delay"
3852 if not switchAllowed
then
3854 //HACK for weapon cycling
3855 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3859 nw
:= getNextWeaponIndex();
3860 if nw
= 255 then exit
; // don't reset anything here
3861 if nw
> High(FWeapon
) then
3863 // don't forget to reset queue here!
3864 //e_WriteLog(Format(' RealizeCurrentWeapon: WUTAFUUUU?! (%d)', [nw]), TMsgType.Warning);
3871 //k8: emulate this on client immediately, or wait for server confirmation?
3873 if g_Game_IsClient then
3875 FNetForceWeap := nw;
3876 //FNetForceWeapFIdx := FCurrFrameIdx+5; // force for ~5 frames
3877 FNetForceWeapFIdx := gTime+5; // force for ~5 frames
3878 writeln('NETWEAPONSWITCH: fw=', NetForceWeap, '; fwfidx=', NetForceWeapFIdx, '; cfrm=', gTime);
3881 FNetForceWeapFIdx
:= gTime
+5; // force for ~5 frames
3883 if nw
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3884 FModel
.SetWeapon(nw
);
3885 FTime
[T_SWITCH
] := gTime
+156;
3886 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3887 //if g_Game_IsNet and g_Game_IsClient then
3891 procedure TPlayer
.NextWeapon();
3893 //if g_Game_IsClient then Exit;
3897 procedure TPlayer
.PrevWeapon();
3899 //if g_Game_IsClient then Exit;
3903 // used by network layer
3904 procedure TPlayer
.SetWeapon(W
: Byte);
3906 if FCurrWeap
<> W
then
3907 if (W
= WEAPON_SAW
) then
3908 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3911 FModel
.SetWeapon(CurrWeap
);
3912 //if g_Game_IsClient then resetWeaponQueue();
3915 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3917 function allowBerserkSwitching (): Boolean;
3919 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3921 if gBerserkAutoswitch
then exit
;
3922 if not conIsCheatsEnabled
then exit
;
3930 if g_Game_IsClient
then Exit
;
3932 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3933 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3938 if FHealth
< PLAYER_HP_SOFT
then
3940 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3944 if gFlash
= 2 then Inc(FPickup
, 5);
3948 if FHealth
< PLAYER_HP_SOFT
then
3950 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3954 if gFlash
= 2 then Inc(FPickup
, 5);
3958 if FArmor
< PLAYER_AP_SOFT
then
3960 FArmor
:= PLAYER_AP_SOFT
;
3963 if gFlash
= 2 then Inc(FPickup
, 5);
3967 if FArmor
< PLAYER_AP_LIMIT
then
3969 FArmor
:= PLAYER_AP_LIMIT
;
3972 if gFlash
= 2 then Inc(FPickup
, 5);
3976 if FHealth
< PLAYER_HP_LIMIT
then
3978 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3982 if gFlash
= 2 then Inc(FPickup
, 5);
3986 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3988 if FHealth
< PLAYER_HP_LIMIT
then
3989 FHealth
:= PLAYER_HP_LIMIT
;
3990 if FArmor
< PLAYER_AP_LIMIT
then
3991 FArmor
:= PLAYER_AP_LIMIT
;
3995 if gFlash
= 2 then Inc(FPickup
, 5);
3999 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
4001 FWeapon
[WEAPON_SAW
] := True;
4003 if gFlash
= 2 then Inc(FPickup
, 5);
4004 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4007 ITEM_WEAPON_SHOTGUN1
:
4008 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
4010 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
4011 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
4013 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4014 FWeapon
[WEAPON_SHOTGUN1
] := True;
4016 if gFlash
= 2 then Inc(FPickup
, 5);
4017 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4020 ITEM_WEAPON_SHOTGUN2
:
4021 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
4023 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
4025 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4026 FWeapon
[WEAPON_SHOTGUN2
] := True;
4028 if gFlash
= 2 then Inc(FPickup
, 5);
4029 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4032 ITEM_WEAPON_CHAINGUN
:
4033 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
4035 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
4037 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4038 FWeapon
[WEAPON_CHAINGUN
] := True;
4040 if gFlash
= 2 then Inc(FPickup
, 5);
4041 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4044 ITEM_WEAPON_ROCKETLAUNCHER
:
4045 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
4047 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
4049 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
4050 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
4052 if gFlash
= 2 then Inc(FPickup
, 5);
4053 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4057 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
4059 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
4061 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4062 FWeapon
[WEAPON_PLASMA
] := True;
4064 if gFlash
= 2 then Inc(FPickup
, 5);
4065 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4069 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
4071 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
4073 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4074 FWeapon
[WEAPON_BFG
] := True;
4076 if gFlash
= 2 then Inc(FPickup
, 5);
4077 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4080 ITEM_WEAPON_SUPERPULEMET
:
4081 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
4083 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
4085 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4086 FWeapon
[WEAPON_SUPERPULEMET
] := True;
4088 if gFlash
= 2 then Inc(FPickup
, 5);
4089 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4092 ITEM_WEAPON_FLAMETHROWER
:
4093 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
4095 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
4097 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4098 FWeapon
[WEAPON_FLAMETHROWER
] := True;
4100 if gFlash
= 2 then Inc(FPickup
, 5);
4101 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4105 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4107 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4110 if gFlash
= 2 then Inc(FPickup
, 5);
4113 ITEM_AMMO_BULLETS_BOX
:
4114 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4116 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4119 if gFlash
= 2 then Inc(FPickup
, 5);
4123 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4125 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4128 if gFlash
= 2 then Inc(FPickup
, 5);
4131 ITEM_AMMO_SHELLS_BOX
:
4132 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4134 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
4137 if gFlash
= 2 then Inc(FPickup
, 5);
4141 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4143 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4146 if gFlash
= 2 then Inc(FPickup
, 5);
4149 ITEM_AMMO_ROCKET_BOX
:
4150 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4152 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
4155 if gFlash
= 2 then Inc(FPickup
, 5);
4159 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4161 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4164 if gFlash
= 2 then Inc(FPickup
, 5);
4168 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4170 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4173 if gFlash
= 2 then Inc(FPickup
, 5);
4177 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4179 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4182 if gFlash
= 2 then Inc(FPickup
, 5);
4186 if not(R_ITEM_BACKPACK
in FRulez
) or
4187 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4188 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4189 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4190 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4191 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
4193 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4194 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4195 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4196 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4197 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4199 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4200 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4201 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4202 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4203 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4204 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4205 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4206 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4208 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
4211 if gFlash
= 2 then Inc(FPickup
, 5);
4215 if not(R_KEY_RED
in FRulez
) then
4217 Include(FRulez
, R_KEY_RED
);
4219 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4220 if gFlash
= 2 then Inc(FPickup
, 5);
4221 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4225 if not(R_KEY_GREEN
in FRulez
) then
4227 Include(FRulez
, R_KEY_GREEN
);
4229 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4230 if gFlash
= 2 then Inc(FPickup
, 5);
4231 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4235 if not(R_KEY_BLUE
in FRulez
) then
4237 Include(FRulez
, R_KEY_BLUE
);
4239 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4240 if gFlash
= 2 then Inc(FPickup
, 5);
4241 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4245 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4247 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4251 if gFlash
= 2 then Inc(FPickup
, 5);
4255 if FAir
< AIR_MAX
then
4260 if gFlash
= 2 then Inc(FPickup
, 5);
4265 if not (R_BERSERK
in FRulez
) then
4267 Include(FRulez
, R_BERSERK
);
4268 if allowBerserkSwitching
then
4270 FCurrWeap
:= WEAPON_KASTET
;
4271 //FNetForceWeap := FCurrWeap;
4273 FModel
.SetWeapon(WEAPON_KASTET
);
4278 if gFlash
= 2 then Inc(FPickup
, 5);
4280 FBerserk
:= gTime
+30000;
4284 //k8:do we need it? if g_Game_IsNet and g_Game_IsServer then MH_SEND_PlayerStats(FUID);
4286 if FHealth
< PLAYER_HP_SOFT
then
4288 FHealth
:= PLAYER_HP_SOFT
;
4289 FBerserk
:= gTime
+30000;
4297 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4299 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4302 if gFlash
= 2 then Inc(FPickup
, 5);
4306 if FHealth
< PLAYER_HP_LIMIT
then
4308 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4312 if gFlash
= 2 then Inc(FPickup
, 5);
4316 if FArmor
< PLAYER_AP_LIMIT
then
4318 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4321 if gFlash
= 2 then Inc(FPickup
, 5);
4325 if FJetFuel
< JET_MAX
then
4327 FJetFuel
:= JET_MAX
;
4330 if gFlash
= 2 then Inc(FPickup
, 5);
4334 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4336 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4339 if gFlash
= 2 then Inc(FPickup
, 5);
4344 procedure TPlayer
.Touch();
4348 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4351 // Áðîñèòü ôëàã òîâàðèùó:
4352 if gGameSettings
.GameMode
= GM_CTF
then
4357 procedure TPlayer
.Push(vx
, vy
: Integer);
4359 if (not FPhysics
) and FGhost
then
4361 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4362 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4363 if g_Game_IsNet
and g_Game_IsServer
then
4364 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4367 procedure TPlayer
.Reset(Force
: Boolean);
4373 FTime
[T_RESPAWN
] := 0;
4374 FTime
[T_FLAGCAP
] := 0;
4385 //FCurrFrameIdx := 0;
4386 //FNetForceWeap := FCurrWeap;
4387 FNetForceWeapFIdx
:= 0;
4390 FSpectator
:= False;
4393 FSpectatePlayer
:= -1;
4394 FNoRespawn
:= False;
4396 FLives
:= gGameSettings
.MaxLives
;
4401 procedure TPlayer
.SoftReset();
4407 FBFGFireCounter
:= -1;
4413 FNetForceWeapFIdx
:= 0;
4416 SetAction(A_STAND
, True);
4419 function TPlayer
.GetRespawnPoint(): Byte;
4424 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4426 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4427 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4429 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4431 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4432 if Self
= gPlayer1
then
4433 c
:= RESPAWNPOINT_PLAYER1
4435 c
:= RESPAWNPOINT_PLAYER2
;
4436 if g_Map_GetPointCount(c
) > 0 then
4442 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4443 if Self
= gPlayer1
then
4444 c
:= RESPAWNPOINT_PLAYER2
4446 c
:= RESPAWNPOINT_PLAYER1
;
4447 if g_Map_GetPointCount(c
) > 0 then
4454 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4455 if Random(2) = 0 then
4456 c
:= RESPAWNPOINT_PLAYER1
4458 c
:= RESPAWNPOINT_PLAYER2
;
4459 if g_Map_GetPointCount(c
) > 0 then
4466 // Òî÷êà ëþáîé èç êîìàíä
4467 if Random(2) = 0 then
4468 c
:= RESPAWNPOINT_RED
4470 c
:= RESPAWNPOINT_BLUE
;
4471 if g_Map_GetPointCount(c
) > 0 then
4478 c
:= RESPAWNPOINT_DM
;
4479 if g_Map_GetPointCount(c
) > 0 then
4487 if gGameSettings
.GameMode
= GM_DM
then
4490 c
:= RESPAWNPOINT_DM
;
4491 if g_Map_GetPointCount(c
) > 0 then
4497 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4498 if Random(2) = 0 then
4499 c
:= RESPAWNPOINT_PLAYER1
4501 c
:= RESPAWNPOINT_PLAYER2
;
4502 if g_Map_GetPointCount(c
) > 0 then
4508 // Òî÷êà ëþáîé èç êîìàíä
4509 if Random(2) = 0 then
4510 c
:= RESPAWNPOINT_RED
4512 c
:= RESPAWNPOINT_BLUE
;
4513 if g_Map_GetPointCount(c
) > 0 then
4521 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4523 // Òî÷êà ñâîåé êîìàíäû
4524 c
:= RESPAWNPOINT_DM
;
4525 if FTeam
= TEAM_RED
then
4526 c
:= RESPAWNPOINT_RED
;
4527 if FTeam
= TEAM_BLUE
then
4528 c
:= RESPAWNPOINT_BLUE
;
4529 if g_Map_GetPointCount(c
) > 0 then
4536 c
:= RESPAWNPOINT_DM
;
4537 if g_Map_GetPointCount(c
) > 0 then
4543 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4544 if Random(2) = 0 then
4545 c
:= RESPAWNPOINT_PLAYER1
4547 c
:= RESPAWNPOINT_PLAYER2
;
4548 if g_Map_GetPointCount(c
) > 0 then
4554 // Òî÷êà äðóãîé êîìàíäû
4555 c
:= RESPAWNPOINT_DM
;
4556 if FTeam
= TEAM_RED
then
4557 c
:= RESPAWNPOINT_BLUE
;
4558 if FTeam
= TEAM_BLUE
then
4559 c
:= RESPAWNPOINT_RED
;
4560 if g_Map_GetPointCount(c
) > 0 then
4568 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4570 RespawnPoint
: TRespawnPoint
;
4576 FBFGFireCounter
:= -1;
4580 //FNetForceWeap := FCurrWeap;
4581 FNetForceWeapFIdx
:= 0;
4583 if not g_Game_IsServer
then
4587 FWantsInGame
:= True;
4588 FJustTeleported
:= True;
4591 FTime
[T_RESPAWN
] := 0;
4595 // if server changes MaxLives we gotta be ready
4596 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4598 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4599 if FTime
[T_RESPAWN
] > gTime
then
4602 // Ïðîñðàë âñå æèçíè:
4605 if not FSpectator
then Spectate(True);
4606 FWantsInGame
:= True;
4610 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4611 begin // "Ñâîÿ èãðà"
4612 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4613 FRulez
:= FRulez
-[R_BERSERK
];
4615 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4617 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4618 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4621 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4622 c
:= GetRespawnPoint();
4627 // Âîñêðåøåíèå áåç îðóæèÿ:
4630 FHealth
:= PLAYER_HP_SOFT
;
4636 for a
:= WP_FIRST
to WP_LAST
do
4638 FWeapon
[a
] := False;
4642 FWeapon
[WEAPON_PISTOL
] := True;
4643 FWeapon
[WEAPON_KASTET
] := True;
4644 FCurrWeap
:= WEAPON_PISTOL
;
4645 //FNetForceWeap := FCurrWeap;
4648 FModel
.SetWeapon(FCurrWeap
);
4650 for b
:= A_BULLETS
to A_HIGH
do
4653 FAmmo
[A_BULLETS
] := 50;
4655 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4656 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4657 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4658 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4659 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4661 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4662 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4667 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4668 if not g_Map_GetPoint(c
, RespawnPoint
) then
4670 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4674 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4675 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4676 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4682 FDirection
:= RespawnPoint
.Direction
;
4683 if FDirection
= TDirection
.D_LEFT
then
4688 SetAction(A_STAND
, True);
4689 FModel
.Direction
:= FDirection
;
4691 for a
:= Low(FTime
) to High(FTime
) do
4694 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4699 FCanJetpack
:= False;
4704 // Àíèìàöèÿ âîçðîæäåíèÿ:
4705 if (not gLoadGameMode
) and (not Silent
) then
4706 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4708 Anim
:= TAnimation
.Create(ID
, False, 3);
4709 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4710 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4714 FSpectator
:= False;
4717 FSpectatePlayer
:= -1;
4720 if (gPlayer1
= nil) and (gLMSPID1
= FUID
) then
4722 if (gPlayer2
= nil) and (gLMSPID2
= FUID
) then
4725 //FNetForceWeap := FCurrWeap;
4727 if g_Game_IsNet
then
4729 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4730 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4732 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4733 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4738 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4741 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4742 else if (not NoMove
) then
4744 GameX
:= gMapInfo
.Width
div 2;
4745 GameY
:= gMapInfo
.Height
div 2;
4754 FWantsInGame
:= False;
4759 if Self
= gPlayer1
then
4764 if Self
= gPlayer2
then
4771 if g_Game_IsNet
then
4772 MH_SEND_PlayerStats(FUID
);
4775 procedure TPlayer
.SwitchNoClip
;
4779 FGhost
:= not FGhost
;
4780 FPhysics
:= not FGhost
;
4792 procedure TPlayer
.Run(Direction
: TDirection
);
4796 if MAX_RUNVEL
> 8 then
4800 if Direction
= TDirection
.D_LEFT
then
4802 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4803 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4806 if FObj
.Vel
.X
< MAX_RUNVEL
then
4807 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4809 // Âîçìîæíî, ïèíàåì êóñêè:
4810 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4812 b
:= Abs(FObj
.Vel
.X
);
4813 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4814 for a
:= 0 to High(gGibs
) do
4816 if gGibs
[a
].alive
and
4817 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4818 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4821 if FObj
.Vel
.X
< 0 then
4823 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4827 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4829 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4837 procedure TPlayer
.SeeDown();
4839 SetAction(A_SEEDOWN
);
4841 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4843 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4846 procedure TPlayer
.SeeUp();
4850 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4852 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4855 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4863 A_ATTACK
: Prior
:= 2;
4864 A_SEEUP
: Prior
:= 1;
4865 A_SEEDOWN
: Prior
:= 1;
4866 A_ATTACKUP
: Prior
:= 2;
4867 A_ATTACKDOWN
: Prior
:= 2;
4872 if (Prior
> FActionPrior
) or Force
then
4873 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4875 FActionPrior
:= Prior
;
4876 FActionAnim
:= Action
;
4877 FActionForce
:= Force
;
4878 FActionChanged
:= True;
4881 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4884 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4886 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4887 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4888 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4889 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4892 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4899 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4901 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4902 if g_Game_IsServer
and g_Game_IsNet
then
4903 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4907 FJustTeleported
:= True;
4912 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4914 Anim
:= TAnimation
.Create(ID
, False, 3);
4917 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4918 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4919 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4920 if g_Game_IsServer
and g_Game_IsNet
then
4921 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4922 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4926 FObj
.X
:= X
-PLAYER_RECT
.X
;
4927 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4928 if FAlive
and FGhost
then
4934 if not g_Game_IsNet
then
4938 SetDirection(TDirection
.D_LEFT
);
4944 SetDirection(TDirection
.D_RIGHT
);
4950 if FDirection
= TDirection
.D_RIGHT
then
4952 SetDirection(TDirection
.D_LEFT
);
4957 SetDirection(TDirection
.D_RIGHT
);
4963 if not silent
and (Anim
<> nil) then
4965 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4966 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4969 if g_Game_IsServer
and g_Game_IsNet
then
4970 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4971 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4978 function nonz(a
: Single): Single;
4986 function TPlayer
.followCorpse(): Boolean;
4991 if FAlive
or FSpectator
then
4993 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
4995 for i
:= 0 to High(gCorpses
) do
4996 if gCorpses
[i
] <> nil then
4997 if gCorpses
[i
].FPlayerUID
= FUID
then
5000 FObj
.X
:= gCorpses
[i
].FObj
.X
;
5001 FObj
.Y
:= gCorpses
[i
].FObj
.Y
;
5002 FObj
.Vel
.X
:= gCorpses
[i
].FObj
.Vel
.X
;
5003 FObj
.Vel
.Y
:= gCorpses
[i
].FObj
.Vel
.Y
;
5004 FObj
.Accel
.X
:= gCorpses
[i
].FObj
.Accel
.X
;
5005 FObj
.Accel
.Y
:= gCorpses
[i
].FObj
.Accel
.Y
;
5010 procedure TPlayer
.Update();
5013 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
5014 blockmon
, headwater
, dospawn
: Boolean;
5019 //Inc(FCurrFrameIdx);
5021 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
5022 AnyServer
:= g_Game_IsServer
;
5024 if g_Game_IsClient
and (NetInterpLevel
> 0) then
5025 DoLerp(NetInterpLevel
+ 1)
5032 if FClientID
>= 0 then
5034 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
5035 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
5036 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
5046 if FAlive
and (FPunchAnim
<> nil) then
5047 FPunchAnim
.Update();
5049 if FAlive
and (gFly
or FJetpack
) then
5052 if FDirection
= TDirection
.D_LEFT
then
5057 if FAlive
and (not FGhost
) then
5059 if FKeys
[KEY_UP
].Pressed
then
5061 if FKeys
[KEY_DOWN
].Pressed
then
5065 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
5068 i
:= g_basic
.Sign(FIncCam
);
5069 FIncCam
:= Abs(FIncCam
);
5070 DecMin(FIncCam
, 5, 0);
5071 FIncCam
:= FIncCam
*i
;
5074 // no need to do that each second frame, weapon queue will take care of it
5075 if FAlive
and FKeys
[KEY_NEXTWEAPON
].Pressed
{and AnyServer} then NextWeapon();
5076 if FAlive
and FKeys
[KEY_PREVWEAPON
].Pressed
{and AnyServer} then PrevWeapon();
5078 if gTime
mod (GAME_TICK
*2) <> 0 then
5080 if (FObj
.Vel
.X
= 0) and FAlive
then
5082 if FKeys
[KEY_LEFT
].Pressed
then
5083 Run(TDirection
.D_LEFT
);
5084 if FKeys
[KEY_RIGHT
].Pressed
then
5085 Run(TDirection
.D_RIGHT
);
5090 if not followCorpse() then
5091 g_Obj_Move(@FObj
, True, True, True);
5092 positionChanged(); // this updates spatial accelerators
5098 FActionChanged
:= False;
5102 // Let alive player do some actions
5103 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
5104 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
5105 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
5106 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
5107 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
5108 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
5109 if FKeys
[KEY_JUMP
].Pressed
then Jump()
5112 if AnyServer
and FJetpack
then
5116 if NetServer
then MH_SEND_PlayerStats(FUID
);
5118 FCanJetpack
:= True;
5125 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
5127 if FKeys
[k
].Pressed
then
5135 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5138 if (FTime
[T_RESPAWN
] <= gTime
) and
5139 gGameOn
and (not FAlive
) then
5141 if (g_Player_GetCount() > 1) then
5145 gExit
:= EXIT_RESTART
;
5150 // Dead spectator actions
5153 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
5154 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
5158 if (FSpectatePlayer
>= High(gPlayers
)) then
5159 FSpectatePlayer
:= -1
5163 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
5164 if gPlayers
[I
] <> nil then
5165 if gPlayers
[I
].alive
then
5166 if gPlayers
[I
].UID
<> FUID
then
5168 FSpectatePlayer
:= I
;
5173 if not SetSpect
then FSpectatePlayer
:= -1;
5184 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5186 FYTo
:= FObj
.Y
- 32;
5187 FSpectatePlayer
:= -1;
5189 if FKeys
[KEY_DOWN
].Pressed
then
5191 FYTo
:= FObj
.Y
+ 32;
5192 FSpectatePlayer
:= -1;
5194 if FKeys
[KEY_LEFT
].Pressed
then
5196 FXTo
:= FObj
.X
- 32;
5197 FSpectatePlayer
:= -1;
5199 if FKeys
[KEY_RIGHT
].Pressed
then
5201 FXTo
:= FObj
.X
+ 32;
5202 FSpectatePlayer
:= -1;
5205 if (FXTo
< -64) then
5207 else if (FXTo
> gMapInfo
.Width
+ 32) then
5208 FXTo
:= gMapInfo
.Width
+ 32;
5209 if (FYTo
< -72) then
5211 else if (FYTo
> gMapInfo
.Height
+ 32) then
5212 FYTo
:= gMapInfo
.Height
+ 32;
5217 if not followCorpse() then
5218 g_Obj_Move(@FObj
, True, True, True);
5219 positionChanged(); // this updates spatial accelerators
5226 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5227 if gPlayers
[FSpectatePlayer
] <> nil then
5228 if gPlayers
[FSpectatePlayer
].alive
then
5230 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
5231 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
5235 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5236 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5237 PANEL_BLOCKMON
, True);
5238 headwater
:= HeadInLiquid(0, 0);
5240 // Ñîïðîòèâëåíèå âîçäóõà:
5241 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5242 if FObj
.Vel
.X
<> 0 then
5243 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5245 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5246 DecMin(FPain
, 5, 0);
5247 DecMin(FPickup
, 1, 0);
5249 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5251 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5252 FMegaRulez
[MR_SUIT
] := 0;
5253 FMegaRulez
[MR_INVUL
] := 0;
5254 FMegaRulez
[MR_INVIS
] := 0;
5255 Kill(K_FALLKILL
, 0, HIT_FALL
);
5262 if FCurrWeap
= WEAPON_SAW
then
5263 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5264 FSawSoundSelect
.IsPlaying()) then
5265 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5268 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5269 (not FJetSoundOff
.IsPlaying()) then
5271 FJetSoundFly
.SetPosition(0);
5272 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5275 for b
:= WP_FIRST
to WP_LAST
do
5276 if FReloading
[b
] > 0 then
5282 if FShellTimer
> -1 then
5283 if FShellTimer
= 0 then
5285 if FShellType
= SHELL_SHELL
then
5286 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5287 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5288 else if FShellType
= SHELL_DBLSHELL
then
5290 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5291 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5292 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5293 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5296 end else Dec(FShellTimer
);
5298 if (FBFGFireCounter
> -1) then
5299 if FBFGFireCounter
= 0 then
5303 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5304 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5305 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5306 yd
:= wy
+firediry();
5307 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5308 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5309 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5310 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5311 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5314 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5315 FBFGFireCounter
:= -1;
5318 FBFGFireCounter
:= 0
5320 Dec(FBFGFireCounter
);
5322 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5324 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5326 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5329 if (headwater
or blockmon
) then
5335 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5338 else if (FAir
mod 31 = 0) and not blockmon
then
5340 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5341 if Random(2) = 0 then
5342 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5344 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5346 end else if FAir
< AIR_DEF
then
5349 if FFireTime
> 0 then
5351 if BodyInLiquid(0, 0) then
5356 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5358 if FMegaRulez
[MR_SUIT
] = gTime
then
5365 if FFirePainTime
<= 0 then
5367 if g_Game_IsServer
then
5368 Damage(5, FFireAttacker
, 0, 0, HIT_FLAME
);
5369 FFirePainTime
:= 18;
5371 FFirePainTime
:= FFirePainTime
- 1;
5372 FFireTime
:= FFireTime
- 1;
5373 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5374 MH_SEND_PlayerStats(FUID
);
5378 if FDamageBuffer
> 0 then
5380 if FDamageBuffer
>= 9 then
5384 if FDamageBuffer
< 30 then i
:= 9
5385 else if FDamageBuffer
< 100 then i
:= 18
5389 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5390 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5391 FHealth
:= FHealth
-ii
;
5394 FHealth
:= FHealth
+FArmor
;
5399 if FHealth
<= 0 then
5400 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5401 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5402 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5406 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5407 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5408 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5409 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5416 end; // if FAlive then ...
5418 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5420 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5421 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5422 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5423 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5425 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5426 then SetAction(A_STAND
, True);
5428 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5430 for b
:= Low(FKeys
) to High(FKeys
) do
5431 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5435 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5437 x
:= FObj
.X
+PLAYER_RECT
.X
;
5438 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5439 w
:= PLAYER_RECT
.Width
;
5440 h
:= PLAYER_RECT
.Height
;
5444 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5446 if (dx
<> 0) or (dy
<> 0) then
5455 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5457 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5458 FObj
.Y
+PLAYER_RECT
.Y
,
5465 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5467 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5468 FObj
.Y
+PLAYER_RECT
.Y
,
5472 Panel
.Width
, Panel
.Height
);
5475 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5477 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5478 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5479 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5480 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5483 function g_Player_ValidName(Name
: string): Boolean;
5489 if gPlayers
= nil then Exit
;
5491 for a
:= 0 to High(gPlayers
) do
5492 if gPlayers
[a
] <> nil then
5493 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5500 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5504 d
:= FModel
.Direction
;
5506 FModel
.Direction
:= Direction
;
5507 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5509 FDirection
:= Direction
;
5512 function TPlayer
.GetKeys(): Byte;
5516 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5517 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5518 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5520 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5521 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5524 procedure TPlayer
.Use();
5528 if FTime
[T_USE
] > gTime
then Exit
;
5530 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5531 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5533 for a
:= 0 to High(gPlayers
) do
5534 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5535 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5536 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5537 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5539 gPlayers
[a
].Touch();
5540 if g_Game_IsNet
and g_Game_IsServer
then
5541 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5544 FTime
[T_USE
] := gTime
+120;
5547 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5551 WX
, WY
, XD
, YD
: Integer;
5563 if R_BERSERK
in FRulez
then
5565 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5566 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5567 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5570 locobj
.rect
.Width
:= 39;
5571 locobj
.rect
.Height
:= 52;
5572 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5573 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5574 locobj
.Accel
.X
:= xd
-wx
;
5575 locobj
.Accel
.y
:= yd
-wy
;
5577 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5578 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5580 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5584 FPain
:= min(FPain
+ 25, 50);
5586 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5591 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5592 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5594 FSawSoundSelect
.Stop();
5596 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5598 else if not FSawSoundHit
.IsPlaying() then
5600 FSawSoundSelect
.Stop();
5601 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5608 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5609 FFireAngle
:= FAngle
;
5611 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5612 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5617 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5618 FFireAngle
:= FAngle
;
5621 FShellType
:= SHELL_SHELL
;
5626 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5627 FFireAngle
:= FAngle
;
5630 FShellType
:= SHELL_DBLSHELL
;
5635 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5636 FFireAngle
:= FAngle
;
5638 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5639 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5642 WEAPON_ROCKETLAUNCHER
:
5644 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5645 FFireAngle
:= FAngle
;
5651 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5652 FFireAngle
:= FAngle
;
5658 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5659 FFireAngle
:= FAngle
;
5663 WEAPON_SUPERPULEMET
:
5665 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5666 FFireAngle
:= FAngle
;
5668 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5669 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5672 WEAPON_FLAMETHROWER
:
5674 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5675 FFireAngle
:= FAngle
;
5682 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5683 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5684 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5687 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5689 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5690 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5693 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5697 if NetInterpLevel
< 1 then
5707 AX
:= Abs(FXTo
- FObj
.X
);
5708 AY
:= Abs(FYTo
- FObj
.Y
);
5709 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5711 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5716 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5718 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5719 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5720 PANEL_LIFTUP
, False) then Result
:= -1
5722 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5723 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5724 PANEL_LIFTDOWN
, False) then Result
:= 1
5728 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5735 if Flag
= FLAG_NONE
then
5738 if not g_Game_IsServer
then Exit
;
5740 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5741 if (Flag
= FTeam
) and
5742 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5743 (FFlag
<> FLAG_NONE
) then
5745 if FFlag
= FLAG_RED
then
5746 s
:= _lc
[I_PLAYER_FLAG_RED
]
5748 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5750 evtype
:= FLAG_STATE_SCORED
;
5752 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5753 Insert('.', ts
, Length(ts
) + 1 - 3);
5754 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5756 g_Map_ResetFlag(FFlag
);
5757 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5759 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5762 if g_Game_IsNet
then
5764 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5768 gFlags
[FFlag
].CaptureTime
:= 0;
5773 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5774 if (Flag
= FTeam
) and
5775 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5777 if Flag
= FLAG_RED
then
5778 s
:= _lc
[I_PLAYER_FLAG_RED
]
5780 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5782 evtype
:= FLAG_STATE_RETURNED
;
5783 gFlags
[Flag
].CaptureTime
:= 0;
5785 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5787 g_Map_ResetFlag(Flag
);
5788 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5791 if g_Game_IsNet
then
5793 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5799 // Ïîäîáðàë ÷óæîé ôëàã:
5800 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5804 if Flag
= FLAG_RED
then
5805 s
:= _lc
[I_PLAYER_FLAG_RED
]
5807 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5809 evtype
:= FLAG_STATE_CAPTURED
;
5811 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5813 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5815 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5818 if g_Game_IsNet
then
5820 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5826 procedure TPlayer
.SetFlag(Flag
: Byte);
5829 if FModel
<> nil then
5830 FModel
.SetFlag(FFlag
);
5833 function TPlayer
.DropFlag(): Boolean;
5838 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5840 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5841 with gFlags
[FFlag
] do
5845 Direction
:= FDirection
;
5846 State
:= FLAG_STATE_DROPPED
;
5848 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5849 (FObj
.Vel
.Y
div 2)-2+Random(5));
5850 positionChanged(); // this updates spatial accelerators
5852 if FFlag
= FLAG_RED
then
5853 s
:= _lc
[I_PLAYER_FLAG_RED
]
5855 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5857 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5858 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5860 if g_Game_IsNet
then
5861 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5867 procedure TPlayer
.GetSecret();
5872 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5874 Assert(Key
<= High(FKeys
));
5876 FKeys
[Key
].Pressed
:= True;
5877 FKeys
[Key
].Time
:= Time
;
5880 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5882 Result
:= FKeys
[K
].Pressed
;
5885 procedure TPlayer
.ReleaseKeys();
5889 for a
:= Low(FKeys
) to High(FKeys
) do
5891 FKeys
[a
].Pressed
:= False;
5896 procedure TPlayer
.ReleaseKeysNoWeapon();
5900 for a
:= Low(FKeys
) to High(FKeys
) do
5902 if (a
= KEY_PREVWEAPON
) or (a
= KEY_NEXTWEAPON
) then continue
;
5903 FKeys
[a
].Pressed
:= False;
5908 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5912 function TPlayer
.firediry(): Integer;
5914 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5915 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5919 procedure TPlayer
.RememberState();
5923 FSavedState
.Health
:= FHealth
;
5924 FSavedState
.Armor
:= FArmor
;
5925 FSavedState
.Air
:= FAir
;
5926 FSavedState
.JetFuel
:= FJetFuel
;
5927 FSavedState
.CurrWeap
:= FCurrWeap
;
5928 FSavedState
.NextWeap
:= FNextWeap
;
5929 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5932 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5934 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5936 FSavedState
.Rulez
:= FRulez
;
5937 FSavedState
.WaitRecall
:= True;
5940 procedure TPlayer
.RecallState();
5944 if not FSavedState
.WaitRecall
then Exit
;
5946 FHealth
:= FSavedState
.Health
;
5947 FArmor
:= FSavedState
.Armor
;
5948 FAir
:= FSavedState
.Air
;
5949 FJetFuel
:= FSavedState
.JetFuel
;
5950 FCurrWeap
:= FSavedState
.CurrWeap
;
5951 //FNetForceWeap := FCurrWeap;
5952 FNextWeap
:= FSavedState
.NextWeap
;
5953 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5956 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5958 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5960 FRulez
:= FSavedState
.Rulez
;
5961 FSavedState
.WaitRecall
:= False;
5963 if gGameSettings
.GameType
= GT_SERVER
then
5964 MH_SEND_PlayerStats(FUID
);
5967 procedure TPlayer
.SaveState (st
: TStream
);
5973 utils
.writeSign(st
, 'PLYR');
5974 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
5976 utils
.writeBool(st
, FIamBot
);
5978 utils
.writeInt(st
, Word(FUID
));
5980 utils
.writeStr(st
, FName
);
5982 utils
.writeInt(st
, Byte(FTeam
));
5984 utils
.writeBool(st
, FAlive
);
5985 // Èçðàñõîäîâàë ëè âñå æèçíè
5986 utils
.writeBool(st
, FNoRespawn
);
5988 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
5989 utils
.writeInt(st
, Byte(b
));
5991 utils
.writeInt(st
, LongInt(FHealth
));
5993 utils
.writeInt(st
, Byte(FLives
));
5995 utils
.writeInt(st
, LongInt(FArmor
));
5997 utils
.writeInt(st
, LongInt(FAir
));
5999 utils
.writeInt(st
, LongInt(FJetFuel
));
6001 utils
.writeInt(st
, LongInt(FPain
));
6003 utils
.writeInt(st
, LongInt(FKills
));
6005 utils
.writeInt(st
, LongInt(FMonsterKills
));
6007 utils
.writeInt(st
, LongInt(FFrags
));
6009 utils
.writeInt(st
, Byte(FFragCombo
));
6010 // Âðåìÿ ïîñëåäíåãî ôðàãà
6011 utils
.writeInt(st
, LongWord(FLastFrag
));
6013 utils
.writeInt(st
, LongInt(FDeath
));
6015 utils
.writeInt(st
, Byte(FFlag
));
6017 utils
.writeInt(st
, LongInt(FSecrets
));
6019 utils
.writeInt(st
, Byte(FCurrWeap
));
6021 utils
.writeInt(st
, Word(FNextWeap
));
6023 utils
.writeInt(st
, Byte(FNextWeapDelay
));
6024 // Âðåìÿ çàðÿäêè BFG
6025 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
6027 utils
.writeInt(st
, LongInt(FDamageBuffer
));
6028 // Ïîñëåäíèé óäàðèâøèé
6029 utils
.writeInt(st
, Word(FLastSpawnerUID
));
6030 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6031 utils
.writeInt(st
, Byte(FLastHit
));
6033 Obj_SaveState(st
, @FObj
);
6034 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6035 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
6036 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6037 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
6039 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
6040 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6041 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
6043 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
6044 // Íàëè÷èå êðàñíîãî êëþ÷à
6045 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
6046 // Íàëè÷èå çåëåíîãî êëþ÷à
6047 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
6048 // Íàëè÷èå ñèíåãî êëþ÷à
6049 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
6051 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
6052 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6053 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
6054 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6055 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
6057 utils
.writeStr(st
, FModel
.Name
);
6059 utils
.writeInt(st
, Byte(FColor
.R
));
6060 utils
.writeInt(st
, Byte(FColor
.G
));
6061 utils
.writeInt(st
, Byte(FColor
.B
));
6065 procedure TPlayer
.LoadState (st
: TStream
);
6074 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
6075 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
6077 FIamBot
:= utils
.readBool(st
);
6079 FUID
:= utils
.readWord(st
);
6081 str
:= utils
.readStr(st
);
6082 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
6084 FTeam
:= utils
.readByte(st
);
6086 FAlive
:= utils
.readBool(st
);
6087 // Èçðàñõîäîâàë ëè âñå æèçíè
6088 FNoRespawn
:= utils
.readBool(st
);
6090 b
:= utils
.readByte(st
);
6091 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
6093 FHealth
:= utils
.readLongInt(st
);
6095 FLives
:= utils
.readByte(st
);
6097 FArmor
:= utils
.readLongInt(st
);
6099 FAir
:= utils
.readLongInt(st
);
6101 FJetFuel
:= utils
.readLongInt(st
);
6103 FPain
:= utils
.readLongInt(st
);
6105 FKills
:= utils
.readLongInt(st
);
6107 FMonsterKills
:= utils
.readLongInt(st
);
6109 FFrags
:= utils
.readLongInt(st
);
6111 FFragCombo
:= utils
.readByte(st
);
6112 // Âðåìÿ ïîñëåäíåãî ôðàãà
6113 FLastFrag
:= utils
.readLongWord(st
);
6115 FDeath
:= utils
.readLongInt(st
);
6117 FFlag
:= utils
.readByte(st
);
6119 FSecrets
:= utils
.readLongInt(st
);
6121 FCurrWeap
:= utils
.readByte(st
);
6122 //FNetForceWeap := FCurrWeap;
6124 FNextWeap
:= utils
.readWord(st
);
6126 FNextWeapDelay
:= utils
.readByte(st
);
6127 // Âðåìÿ çàðÿäêè BFG
6128 FBFGFireCounter
:= utils
.readSmallInt(st
);
6130 FDamageBuffer
:= utils
.readLongInt(st
);
6131 // Ïîñëåäíèé óäàðèâøèé
6132 FLastSpawnerUID
:= utils
.readWord(st
);
6133 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6134 FLastHit
:= utils
.readByte(st
);
6136 Obj_LoadState(@FObj
, st
);
6137 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6138 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
6139 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6140 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
6142 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
6143 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6144 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
6146 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
6147 // Íàëè÷èå êðàñíîãî êëþ÷à
6148 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
6149 // Íàëè÷èå çåëåíîãî êëþ÷à
6150 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
6151 // Íàëè÷èå ñèíåãî êëþ÷à
6152 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
6154 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
6155 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6156 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
6157 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6158 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
6160 str
:= utils
.readStr(st
);
6162 FColor
.R
:= utils
.readByte(st
);
6163 FColor
.G
:= utils
.readByte(st
);
6164 FColor
.B
:= utils
.readByte(st
);
6165 if (self
= gPlayer1
) then
6167 str
:= gPlayer1Settings
.Model
;
6168 FColor
:= gPlayer1Settings
.Color
;
6170 else if (self
= gPlayer2
) then
6172 str
:= gPlayer2Settings
.Model
;
6173 FColor
:= gPlayer2Settings
.Color
;
6175 // Îáíîâëÿåì ìîäåëü èãðîêà
6177 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
6178 FModel
.Color
:= TEAMCOLOR
[FTeam
]
6180 FModel
.Color
:= FColor
;
6184 procedure TPlayer
.AllRulez(Health
: Boolean);
6190 FHealth
:= PLAYER_HP_LIMIT
;
6191 FArmor
:= PLAYER_AP_LIMIT
;
6195 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
6196 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
6197 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6200 procedure TPlayer
.RestoreHealthArmor();
6202 FHealth
:= PLAYER_HP_LIMIT
;
6203 FArmor
:= PLAYER_AP_LIMIT
;
6206 procedure TPlayer
.FragCombo();
6210 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6212 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6214 if FFragCombo
< 5 then
6216 Param
:= FUID
or (FFragCombo
shl 16);
6217 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6218 (FComboEvnt
<= High(gDelayedEvents
)) and
6219 gDelayedEvents
[FComboEvnt
].Pending
and
6220 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6221 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6223 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6224 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6227 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6235 procedure TPlayer
.GiveItem(ItemType
: Byte);
6239 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6241 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6245 if FAir
< AIR_MAX
then
6252 if not (R_BERSERK
in FRulez
) then
6254 Include(FRulez
, R_BERSERK
);
6255 if FBFGFireCounter
< 1 then
6257 FCurrWeap
:= WEAPON_KASTET
;
6258 //FNetForceWeap := FCurrWeap;
6260 FModel
.SetWeapon(WEAPON_KASTET
);
6264 FBerserk
:= gTime
+30000;
6266 if FHealth
< PLAYER_HP_SOFT
then
6268 FHealth
:= PLAYER_HP_SOFT
;
6269 FBerserk
:= gTime
+30000;
6274 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6276 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6280 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6282 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6286 if FJetFuel
< JET_MAX
then
6288 FJetFuel
:= JET_MAX
;
6291 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6292 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6294 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6295 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6297 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6299 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6301 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6302 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6305 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6306 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6307 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6308 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6309 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6310 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6311 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6312 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6313 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6315 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6316 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6317 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6318 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6319 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6320 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6321 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6322 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6323 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6326 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6327 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6328 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6329 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6330 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6332 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6333 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6334 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6335 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6336 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6338 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6339 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6340 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6341 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6343 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6346 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6347 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6348 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6350 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6351 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6356 if g_Game_IsNet
and g_Game_IsServer
then
6357 MH_SEND_PlayerStats(FUID
);
6360 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6365 if (Random(5) = 1) and (Times
= 1) then
6368 if BodyInLiquid(0, 0) then
6370 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6371 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6372 if Random(2) = 0 then
6373 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6375 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6379 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6381 for i
:= 1 to Times
do
6383 Anim
:= TAnimation
.Create(id
, False, 3);
6385 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6386 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6392 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6397 if (Random(10) = 1) and (Times
= 1) then
6400 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6402 for i
:= 1 to Times
do
6404 Anim
:= TAnimation
.Create(id
, False, 3);
6406 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6407 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6413 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6415 FSawSound
.Pause(Enable
);
6416 FSawSoundIdle
.Pause(Enable
);
6417 FSawSoundHit
.Pause(Enable
);
6418 FSawSoundSelect
.Pause(Enable
);
6423 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6428 FObj
.Rect
:= PLAYER_CORPSERECT
;
6429 FModelName
:= ModelName
;
6434 FState
:= CORPSE_STATE_MESS
;
6435 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6439 FState
:= CORPSE_STATE_NORMAL
;
6440 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6444 destructor TCorpse
.Destroy();
6451 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6453 procedure TCorpse
.positionChanged (); inline; begin end;
6455 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6457 if (dx
<> 0) or (dy
<> 0) then
6466 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6468 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6469 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6470 w
:= PLAYER_CORPSERECT
.Width
;
6471 h
:= PLAYER_CORPSERECT
.Height
;
6475 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6480 if FState
= CORPSE_STATE_REMOVEME
then
6483 FDamage
:= FDamage
+ Value
;
6485 if FDamage
> 150 then
6487 if FAnimation
<> nil then
6492 FState
:= CORPSE_STATE_REMOVEME
;
6494 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6495 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6496 FModelName
, FColor
);
6497 // Çâóê ìÿñà îò òðóïà:
6498 pm
:= g_PlayerModel_Get(FModelName
);
6499 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6503 if (gBodyKillEvent
<> -1)
6504 and gDelayedEvents
[gBodyKillEvent
].Pending
then
6505 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
6506 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, 0);
6511 Blood
:= g_PlayerModel_GetBlood(FModelName
);
6512 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6513 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6514 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6515 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6516 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6517 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
6521 procedure TCorpse
.Draw();
6523 if FState
= CORPSE_STATE_REMOVEME
then
6526 if FAnimation
<> nil then
6527 FAnimation
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6529 if FAnimationMask
<> nil then
6532 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6539 procedure TCorpse
.Update();
6543 if FState
= CORPSE_STATE_REMOVEME
then
6546 if gTime
mod (GAME_TICK
*2) <> 0 then
6548 g_Obj_Move(@FObj
, True, True, True);
6549 positionChanged(); // this updates spatial accelerators
6553 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6554 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6556 st
:= g_Obj_Move(@FObj
, True, True, True);
6557 positionChanged(); // this updates spatial accelerators
6559 if WordBool(st
and MOVE_FALLOUT
) then
6561 FState
:= CORPSE_STATE_REMOVEME
;
6565 if FAnimation
<> nil then
6566 FAnimation
.Update();
6567 if FAnimationMask
<> nil then
6568 FAnimationMask
.Update();
6572 procedure TCorpse
.SaveState (st
: TStream
);
6579 utils
.writeSign(st
, 'CORP');
6580 utils
.writeInt(st
, Byte(0));
6582 utils
.writeInt(st
, Byte(FState
));
6584 utils
.writeInt(st
, Byte(FDamage
));
6586 utils
.writeInt(st
, Byte(FColor
.R
));
6587 utils
.writeInt(st
, Byte(FColor
.G
));
6588 utils
.writeInt(st
, Byte(FColor
.B
));
6590 Obj_SaveState(st
, @FObj
);
6591 utils
.writeInt(st
, Word(FPlayerUID
));
6593 anim
:= (FAnimation
<> nil);
6594 utils
.writeBool(st
, anim
);
6595 // Åñëè åñòü - ñîõðàíÿåì
6596 if anim
then FAnimation
.SaveState(st
);
6597 // Åñòü ëè ìàñêà àíèìàöèè
6598 anim
:= (FAnimationMask
<> nil);
6599 utils
.writeBool(st
, anim
);
6600 // Åñëè åñòü - ñîõðàíÿåì
6601 if anim
then FAnimationMask
.SaveState(st
);
6605 procedure TCorpse
.LoadState (st
: TStream
);
6612 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6613 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6615 FState
:= utils
.readByte(st
);
6617 FDamage
:= utils
.readByte(st
);
6619 FColor
.R
:= utils
.readByte(st
);
6620 FColor
.G
:= utils
.readByte(st
);
6621 FColor
.B
:= utils
.readByte(st
);
6623 Obj_LoadState(@FObj
, st
);
6624 FPlayerUID
:= utils
.readWord(st
);
6626 anim
:= utils
.readBool(st
);
6627 // Åñëè åñòü - çàãðóæàåì
6630 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6631 FAnimation
.LoadState(st
);
6633 // Åñòü ëè ìàñêà àíèìàöèè
6634 anim
:= utils
.readBool(st
);
6635 // Åñëè åñòü - çàãðóæàåì
6638 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6639 FAnimationMask
.LoadState(st
);
6645 constructor TBot
.Create();
6652 FSpectator
:= False;
6659 for a
:= WP_FIRST
to WP_LAST
do
6661 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6662 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6663 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6667 destructor TBot
.Destroy();
6670 inherited Destroy();
6673 procedure TBot
.Draw();
6677 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6678 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6681 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6683 inherited Respawn(Silent
, Force
);
6686 FSelectedWeapon
:= FCurrWeap
;
6691 procedure TBot
.UpdateCombat();
6704 TTargetRecord
= array of TTarget
;
6706 function Compare(a
, b
: TTarget
): Integer;
6708 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6711 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6713 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6714 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6716 if a
.Dist
> b
.Dist
then // B áëèæå
6718 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6721 else // Ñòðàííî -> A
6726 a
, x1
, y1
, x2
, y2
: Integer;
6727 targets
: TTargetRecord
;
6729 Target
, BestTarget
: TTarget
;
6730 firew
, fireh
: Integer;
6734 vsPlayer
, vsMonster
, ok
: Boolean;
6737 function monsUpdate (mon
: TMonster
): Boolean;
6739 result
:= false; // don't stop
6740 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6742 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6744 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6745 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6747 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6748 if g_TraceVector(x1
, y1
, x2
, y2
) then
6750 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6751 SetLength(targets
, Length(targets
)+1);
6752 with targets
[High(targets
)] do
6759 Rect
:= mon
.Obj
.Rect
;
6760 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6761 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6762 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6771 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6772 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6774 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6775 if FCurrWeap
<> FSelectedWeapon
then
6778 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6779 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6781 RemoveAIFlag('NEEDFIRE');
6784 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6785 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6786 else PressKey(KEY_FIRE
);
6790 // Êîîðäèíàòû ñòâîëà:
6791 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6792 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6794 Target
.UID
:= FTargetUID
;
6797 if Target
.UID
<> 0 then
6798 begin // Öåëü åñòü - íàñòðàèâàåì
6799 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6802 tpla
:= g_Player_Get(Target
.UID
);
6806 if (@FObj
) <> nil then
6813 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6814 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6815 Target
.Rect
:= PLAYER_RECT
;
6816 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6817 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6818 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6819 Target
.IsPlayer
:= True;
6823 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6826 mon
:= g_Monsters_ByUID(Target
.UID
);
6829 Target
.X
:= mon
.Obj
.X
;
6830 Target
.Y
:= mon
.Obj
.Y
;
6832 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6833 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6834 Target
.Rect
:= mon
.Obj
.Rect
;
6835 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6836 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6837 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6838 Target
.IsPlayer
:= False;
6845 begin // Öåëè íåò - îáíóëÿåì
6850 Target
.Visible
:= False;
6851 Target
.Line
:= False;
6852 Target
.IsPlayer
:= False;
6857 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6858 if (not Target
.Line
) or (not Target
.Visible
) then
6862 for a
:= 0 to High(gPlayers
) do
6863 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6864 (gPlayers
[a
].FUID
<> FUID
) and
6865 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6866 (not gPlayers
[a
].NoTarget
) and
6867 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6869 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6870 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6873 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6874 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6876 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6877 if g_TraceVector(x1
, y1
, x2
, y2
) then
6879 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6880 SetLength(targets
, Length(targets
)+1);
6881 with targets
[High(targets
)] do
6883 UID
:= gPlayers
[a
].FUID
;
6884 X
:= gPlayers
[a
].FObj
.X
;
6885 Y
:= gPlayers
[a
].FObj
.Y
;
6888 Rect
:= PLAYER_RECT
;
6889 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6890 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6891 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6899 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6902 // Åñëè åñòü âîçìîæíûå öåëè:
6903 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6904 if targets
<> nil then
6906 // Âûáèðàåì íàèëó÷øóþ öåëü:
6907 BestTarget
:= targets
[0];
6908 if Length(targets
) > 1 then
6909 for a
:= 1 to High(targets
) do
6910 if Compare(BestTarget
, targets
[a
]) = 1 then
6911 BestTarget
:= targets
[a
];
6913 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6914 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6915 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6917 Target
:= BestTarget
;
6919 if (Healthy() = 3) or ((Healthy() = 2)) then
6920 begin // Åñëè çäîðîâû - äîãîíÿåì
6921 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6922 SetAIFlag('GORIGHT', '1');
6923 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6924 SetAIFlag('GOLEFT', '1');
6927 begin // Åñëè ïîáèòû - óáåãàåì
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');
6934 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6935 SelectWeapon(Abs(x1
-Target
.cX
));
6940 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6941 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6942 if Target
.UID
<> 0 then
6944 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6945 Target
.Y
+ Target
.Rect
.Y
) then
6946 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6947 if (Healthy() = 3) or ((Healthy() = 2)) then
6948 begin // Åñëè çäîðîâû - äîãîíÿåì
6949 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6950 SetAIFlag('GORIGHT', '1');
6951 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6952 SetAIFlag('GOLEFT', '1');
6955 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6957 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6958 SetAIFlag('GORIGHT', '1');
6959 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6960 SetAIFlag('GOLEFT', '1');
6964 begin // Öåëü ïîêà íà "ýêðàíå"
6965 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6966 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6967 FLastVisible
:= gTime
;
6968 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6969 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6971 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6972 SetAIFlag('GORIGHT', '1');
6973 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6974 SetAIFlag('GOLEFT', '1');
6978 // Âûáèðàåì óãîë ââåðõ:
6979 if FDirection
= TDirection
.D_LEFT
then
6980 angle
:= ANGLE_LEFTUP
6982 angle
:= ANGLE_RIGHTUP
;
6984 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6985 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6987 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6988 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6989 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6990 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6991 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6992 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6993 begin // òî íóæíî ñòðåëÿòü ââåðõ
6994 SetAIFlag('NEEDFIRE', '1');
6995 SetAIFlag('NEEDSEEUP', '1');
6998 // Âûáèðàåì óãîë âíèç:
6999 if FDirection
= TDirection
.D_LEFT
then
7000 angle
:= ANGLE_LEFTDOWN
7002 angle
:= ANGLE_RIGHTDOWN
;
7004 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7005 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7007 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7008 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7009 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7010 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7011 Target
.Rect
.Width
, Target
.Rect
.Height
) and
7012 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7013 begin // òî íóæíî ñòðåëÿòü âíèç
7014 SetAIFlag('NEEDFIRE', '1');
7015 SetAIFlag('NEEDSEEDOWN', '1');
7018 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
7019 if Target
.Visible
and
7020 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
7021 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
7023 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
7024 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
7025 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
7026 begin // òî íóæíî ñòðåëÿòü âïåðåä
7027 SetAIFlag('NEEDFIRE', '1');
7028 SetAIFlag('NEEDSEEDOWN', '');
7029 SetAIFlag('NEEDSEEUP', '');
7031 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
7032 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
7033 if GetRnd(FDifficult
.CloseJump
) then
7034 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
7035 if Abs(FObj
.X
-Target
.X
) < 128 then
7039 if Random(a
) = 0 then
7040 SetAIFlag('NEEDJUMP', '1');
7044 // Åñëè öåëü âñå åùå åñòü:
7045 if Target
.UID
<> 0 then
7046 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
7047 Target
.UID
:= 0 // òî çàáûòü öåëü
7048 else // Åñëè âèäåëè íåäàâíî
7049 begin // íî öåëü óáèëè
7050 if Target
.IsPlayer
then
7051 begin // Öåëü - èãðîê
7052 pla
:= g_Player_Get(Target
.UID
);
7053 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
7054 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
7055 Target
.UID
:= 0; // òî çàáûòü öåëü
7058 begin // Öåëü - ìîíñòð
7059 mon
:= g_Monsters_ByUID(Target
.UID
);
7060 if (mon
= nil) or (not mon
.alive
) then
7061 Target
.UID
:= 0; // òî çàáûòü öåëü
7064 end; // if Target.UID <> 0
7066 FTargetUID
:= Target
.UID
;
7068 // Åñëè âîçìîæíûõ öåëåé íåò:
7069 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
7070 if targets
= nil then
7071 if GetAIFlag('ATTACKLEFT') <> '' then
7072 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
7073 RemoveAIFlag('ATTACKLEFT');
7075 SetAIFlag('NEEDJUMP', '1');
7077 if RunDirection() = TDirection
.D_RIGHT
then
7078 begin // Èäåì íå â òó ñòîðîíó
7079 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7080 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
7081 SetAIFlag('NEEDFIRE', '1');
7082 SetAIFlag('GOLEFT', '1');
7086 begin // Èäåì â íóæíóþ ñòîðîíó
7087 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7088 SetAIFlag('NEEDFIRE', '1');
7089 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7090 SetAIFlag('GORIGHT', '1');
7094 if GetAIFlag('ATTACKRIGHT') <> '' then
7095 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
7096 RemoveAIFlag('ATTACKRIGHT');
7098 SetAIFlag('NEEDJUMP', '1');
7100 if RunDirection() = TDirection
.D_LEFT
then
7101 begin // Èäåì íå â òó ñòîðîíó
7102 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7103 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
7104 SetAIFlag('NEEDFIRE', '1');
7105 SetAIFlag('GORIGHT', '1');
7110 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7111 SetAIFlag('NEEDFIRE', '1');
7112 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7113 SetAIFlag('GOLEFT', '1');
7117 //HACK! (does it belong there?)
7118 RealizeCurrentWeapon();
7120 // Åñëè åñòü âîçìîæíûå öåëè:
7121 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7122 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7123 for a
:= 0 to High(targets
) do
7125 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7126 if GetRnd(FDifficult
.DiagFire
) then
7128 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7129 if FDirection
= TDirection
.D_LEFT
then
7130 angle
:= ANGLE_LEFTUP
7132 angle
:= ANGLE_RIGHTUP
;
7134 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7135 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7137 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7138 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7139 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7140 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7141 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7143 SetAIFlag('NEEDFIRE', '1');
7144 SetAIFlag('NEEDSEEUP', '1');
7147 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7148 if FDirection
= TDirection
.D_LEFT
then
7149 angle
:= ANGLE_LEFTDOWN
7151 angle
:= ANGLE_RIGHTDOWN
;
7153 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7154 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7156 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7157 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7158 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7159 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7160 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7162 SetAIFlag('NEEDFIRE', '1');
7163 SetAIFlag('NEEDSEEDOWN', '1');
7167 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7168 if targets
[a
].Line
and targets
[a
].Visible
and
7169 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
7170 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
7172 SetAIFlag('NEEDFIRE', '1');
7177 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7178 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
7179 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
7180 40+GetInterval(FDifficult
.Cover
, 40)) then
7181 SetAIFlag('NEEDJUMP', '1');
7183 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7184 ammo
:= GetAmmoByWeapon(FCurrWeap
);
7185 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
7186 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
7188 SetAIFlag('SELECTWEAPON', '1');
7190 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7191 if GetAIFlag('SELECTWEAPON') = '1' then
7194 RemoveAIFlag('SELECTWEAPON');
7198 procedure TBot
.Update();
7211 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7212 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7214 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7216 if g_debug_BotAIOff
= 3 then
7226 RealizeCurrentWeapon();
7233 procedure TBot
.ReleaseKey(Key
: Byte);
7242 function TBot
.KeyPressed(Key
: Word): Boolean;
7244 Result
:= FKeys
[Key
].Pressed
;
7247 function TBot
.GetAIFlag(aName
: String20
): String20
;
7253 aName
:= LowerCase(aName
);
7255 if FAIFlags
<> nil then
7256 for a
:= 0 to High(FAIFlags
) do
7257 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7259 Result
:= FAIFlags
[a
].Value
;
7264 procedure TBot
.RemoveAIFlag(aName
: String20
);
7268 if FAIFlags
= nil then Exit
;
7270 aName
:= LowerCase(aName
);
7272 for a
:= 0 to High(FAIFlags
) do
7273 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7275 if a
<> High(FAIFlags
) then
7276 for b
:= a
to High(FAIFlags
)-1 do
7277 FAIFlags
[b
] := FAIFlags
[b
+1];
7279 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7284 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7292 aName
:= LowerCase(aName
);
7294 if FAIFlags
<> nil then
7295 for a
:= 0 to High(FAIFlags
) do
7296 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7302 if ok
then FAIFlags
[a
].Value
:= fValue
7305 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7306 with FAIFlags
[High(FAIFlags
)] do
7314 procedure TBot
.UpdateMove
;
7316 procedure GoLeft(Time
: Word = 1);
7318 ReleaseKey(KEY_LEFT
);
7319 ReleaseKey(KEY_RIGHT
);
7320 PressKey(KEY_LEFT
, Time
);
7321 SetDirection(TDirection
.D_LEFT
);
7324 procedure GoRight(Time
: Word = 1);
7326 ReleaseKey(KEY_LEFT
);
7327 ReleaseKey(KEY_RIGHT
);
7328 PressKey(KEY_RIGHT
, Time
);
7329 SetDirection(TDirection
.D_RIGHT
);
7332 function Rnd(a
: Word): Boolean;
7334 Result
:= Random(a
) = 0;
7337 procedure Turn(Time
: Word = 1200);
7339 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7344 ReleaseKey(KEY_LEFT
);
7345 ReleaseKey(KEY_RIGHT
);
7348 function CanRunLeft(): Boolean;
7350 Result
:= not CollideLevel(-1, 0);
7353 function CanRunRight(): Boolean;
7355 Result
:= not CollideLevel(1, 0);
7358 function CanRun(): Boolean;
7360 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7363 procedure Jump(Time
: Word = 30);
7365 PressKey(KEY_JUMP
, Time
);
7368 function NearHole(): Boolean;
7372 { TODO 5 : Ëåñòíèöû }
7373 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
7386 function BorderHole(): Boolean;
7390 { TODO 5 : Ëåñòíèöû }
7391 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7392 for x
:= 1 to PLAYER_RECT
.Width
do
7393 if (not StayOnStep(x
*sx
, 0)) and
7394 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7395 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7397 for xx
:= x
to x
+32 do
7398 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7408 function NearDeepHole(): Boolean;
7414 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7417 for x
:= 1 to PLAYER_RECT
.Width
do
7418 if (not StayOnStep(x
*sx
, 0)) and
7419 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7420 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7422 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7424 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7429 end else Result
:= False;
7432 function OverDeepHole(): Boolean;
7439 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7441 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7448 function OnGround(): Boolean;
7450 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7453 function OnLadder(): Boolean;
7455 Result
:= FullInStep(0, 0);
7458 function BelowLadder(): Boolean;
7460 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7461 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7462 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7463 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7466 function BelowLiftUp(): Boolean;
7468 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7469 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7470 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7471 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7474 function OnTopLift(): Boolean;
7476 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7479 function CanJumpOver(): Boolean;
7483 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7487 if not CollideLevel(sx
, 0) then Exit
;
7489 for y
:= 1 to BOT_MAXJUMP
do
7490 if CollideLevel(0, -y
) then Exit
else
7491 if not CollideLevel(sx
, -y
) then
7498 function CanJumpUp(Dist
: ShortInt): Boolean;
7505 if CollideLevel(Dist
, 0) then Exit
;
7508 for y
:= 0 to BOT_MAXJUMP
do
7509 if CollideLevel(Dist
, -y
) then
7518 for yy
:= y
+1 to BOT_MAXJUMP
do
7519 if not CollideLevel(Dist
, -yy
) then
7528 for y
:= 0 to BOT_MAXJUMP
do
7529 if CollideLevel(0, -y
) then
7537 if y
< yy
then Exit
;
7542 function IsSafeTrigger(): Boolean;
7547 if gTriggers
= nil then
7549 for a
:= 0 to High(gTriggers
) do
7550 if Collide(gTriggers
[a
].X
,
7553 gTriggers
[a
].Height
) and
7554 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7555 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7556 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7557 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7558 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7563 // Âîçìîæíî, íàæèìàåì êíîïêó:
7564 if Rnd(16) and IsSafeTrigger() then
7567 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7568 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7570 ReleaseKey(KEY_LEFT
);
7571 ReleaseKey(KEY_RIGHT
);
7575 // Èäåì âëåâî, åñëè íàäî áûëî:
7576 if GetAIFlag('GOLEFT') <> '' then
7578 RemoveAIFlag('GOLEFT');
7579 if CanRunLeft() then
7583 // Èäåì âïðàâî, åñëè íàäî áûëî:
7584 if GetAIFlag('GORIGHT') <> '' then
7586 RemoveAIFlag('GORIGHT');
7587 if CanRunRight() then
7591 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7592 if FObj
.X
< -32 then
7595 if FObj
.X
+32 > gMapInfo
.Width
then
7598 // Ïðûãàåì, åñëè íàäî áûëî:
7599 if GetAIFlag('NEEDJUMP') <> '' then
7602 RemoveAIFlag('NEEDJUMP');
7605 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7606 if GetAIFlag('NEEDSEEUP') <> '' then
7609 ReleaseKey(KEY_DOWN
);
7610 PressKey(KEY_UP
, 20);
7611 RemoveAIFlag('NEEDSEEUP');
7614 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7615 if GetAIFlag('NEEDSEEDOWN') <> '' then
7618 ReleaseKey(KEY_DOWN
);
7619 PressKey(KEY_DOWN
, 20);
7620 RemoveAIFlag('NEEDSEEDOWN');
7623 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7624 if GetAIFlag('GOINHOLE') <> '' then
7625 if not OnGround() then
7627 ReleaseKey(KEY_LEFT
);
7628 ReleaseKey(KEY_RIGHT
);
7629 RemoveAIFlag('GOINHOLE');
7630 SetAIFlag('FALLINHOLE', '1');
7633 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7634 if GetAIFlag('FALLINHOLE') <> '' then
7636 RemoveAIFlag('FALLINHOLE');
7638 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7639 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7640 if GetAIFlag('FALLINHOLE') = '' then
7641 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7647 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7649 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7653 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7654 if OnGround() and NearHole() then
7655 if NearDeepHole() then // Åñëè ýòî áåçäíà
7657 0..3: Turn(); // Áåæèì îáðàòíî
7658 4: Jump(); // Ïðûãàåì
7659 5: begin // Ïðûãàåì îáðàòíî
7664 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7665 if GetAIFlag('GOINHOLE') = '' then
7667 0: Turn(); // Íå íóæíî òóäà
7668 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7669 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7670 if BorderHole() then
7671 SetAIFlag('GOINHOLE', '1');
7674 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7675 if (not CanRun()) and OnGround() then
7677 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7678 if CanJumpOver() or OnLadder() then
7680 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7681 if Random(2) = 0 then
7683 if IsSafeTrigger() then
7689 // Îñòàëîñü ìàëî âîçäóõà:
7690 if FAir
< 36 * 2 then
7693 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7694 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7695 if BodyInAcid(0, 0) then
7699 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7701 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7702 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7705 {function TBot.NeedItem(Item: Byte): Byte;
7710 procedure TBot
.SelectWeapon(Dist
: Integer);
7714 function HaveAmmo(weapon
: Byte): Boolean;
7717 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7718 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7719 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7720 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7721 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7722 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7723 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7724 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7725 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7726 else Result
:= True;
7731 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7733 if Dist
> BOT_LONGDIST
then
7734 begin // Äàëüíèé áîé
7736 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7738 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7742 else //if Dist > BOT_UNSAFEDIST then
7743 begin // Áëèæíèé áîé
7745 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7747 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7754 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7756 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7762 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7764 Result
:= inherited PickItem(ItemType
, force
, remove
);
7766 if Result
then SetAIFlag('SELECTWEAPON', '1');
7769 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7771 Result
:= inherited Heal(value
, Soft
);
7774 function TBot
.Healthy(): Byte;
7776 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7777 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7778 else if (FHealth
> 50) then Result
:= 2
7779 else if (FHealth
> 20) then Result
:= 1
7783 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7785 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7786 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7789 procedure TBot
.OnDamage(Angle
: SmallInt);
7797 if (Angle
= 0) or (Angle
= 180) then
7800 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7801 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7803 pla
:= g_Player_Get(FLastSpawnerUID
);
7804 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7805 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7808 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7809 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7811 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7812 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7813 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7818 SetAIFlag('ATTACKLEFT', '1')
7820 SetAIFlag('ATTACKRIGHT', '1');
7824 function TBot
.RunDirection(): TDirection
;
7826 if Abs(Vel
.X
) >= 1 then
7828 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7830 Result
:= FDirection
;
7833 function TBot
.GetRnd(a
: Byte): Boolean;
7835 if a
= 0 then Result
:= False
7836 else if a
= 255 then Result
:= True
7837 else Result
:= Random(256) > 255-a
;
7840 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7842 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7846 procedure TDifficult
.save (st
: TStream
);
7848 utils
.writeInt(st
, Byte(DiagFire
));
7849 utils
.writeInt(st
, Byte(InvisFire
));
7850 utils
.writeInt(st
, Byte(DiagPrecision
));
7851 utils
.writeInt(st
, Byte(FlyPrecision
));
7852 utils
.writeInt(st
, Byte(Cover
));
7853 utils
.writeInt(st
, Byte(CloseJump
));
7854 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7855 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7858 procedure TDifficult
.load (st
: TStream
);
7860 DiagFire
:= utils
.readByte(st
);
7861 InvisFire
:= utils
.readByte(st
);
7862 DiagPrecision
:= utils
.readByte(st
);
7863 FlyPrecision
:= utils
.readByte(st
);
7864 Cover
:= utils
.readByte(st
);
7865 CloseJump
:= utils
.readByte(st
);
7866 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7867 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7871 procedure TBot
.SaveState (st
: TStream
);
7876 inherited SaveState(st
);
7877 utils
.writeSign(st
, 'BOT0');
7879 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7881 utils
.writeInt(st
, Word(FTargetUID
));
7882 // Âðåìÿ ïîòåðè öåëè
7883 utils
.writeInt(st
, LongWord(FLastVisible
));
7884 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7885 dw
:= Length(FAIFlags
);
7886 utils
.writeInt(st
, LongInt(dw
));
7888 for i
:= 0 to dw
-1 do
7890 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7891 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7893 // Íàñòðîéêè ñëîæíîñòè
7894 FDifficult
.save(st
);
7898 procedure TBot
.LoadState (st
: TStream
);
7903 inherited LoadState(st
);
7904 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7906 FSelectedWeapon
:= utils
.readByte(st
);
7908 FTargetUID
:= utils
.readWord(st
);
7909 // Âðåìÿ ïîòåðè öåëè
7910 FLastVisible
:= utils
.readLongWord(st
);
7911 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7912 dw
:= utils
.readLongInt(st
);
7913 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7914 SetLength(FAIFlags
, dw
);
7916 for i
:= 0 to dw
-1 do
7918 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7919 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7921 // Íàñòðîéêè ñëîæíîñòè
7922 FDifficult
.load(st
);
7927 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);