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 DrawBubble();
322 procedure Update(); virtual;
323 procedure RememberState();
324 procedure RecallState();
325 procedure SaveState (st
: TStream
); virtual;
326 procedure LoadState (st
: TStream
); virtual;
327 procedure PauseSounds(Enable
: Boolean);
328 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
329 procedure DoLerp(Level
: Integer = 2);
330 procedure SetLerp(XTo
, YTo
: Integer);
331 procedure QueueWeaponSwitch(Weapon
: Byte);
332 procedure RealizeCurrentWeapon();
334 procedure JetpackOff
;
335 procedure CatchFire(Attacker
: Word);
337 //WARNING! this does nothing for now, but still call it!
338 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
340 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
341 procedure moveBy (dx
, dy
: Integer); inline;
343 procedure releaseAllWeaponSwitchKeys ();
344 procedure weaponSwitchKeysStateChange (index
: Integer; pressed
: Boolean);
345 function isWeaponSwitchKeyReleased (index
: Integer): Boolean;
346 procedure weaponSwitchKeysShiftNewStates ();
349 property Vel
: TPoint2i read FObj
.Vel
;
350 property Obj
: TObj read FObj
;
352 property Name
: String read FName write FName
;
353 property Model
: TPlayerModel read FModel
;
354 property Health
: Integer read FHealth write FHealth
;
355 property Lives
: Byte read FLives write FLives
;
356 property Armor
: Integer read FArmor write FArmor
;
357 property Air
: Integer read FAir write FAir
;
358 property JetFuel
: Integer read FJetFuel write FJetFuel
;
359 property Frags
: Integer read FFrags write FFrags
;
360 property Death
: Integer read FDeath write FDeath
;
361 property Kills
: Integer read FKills write FKills
;
362 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
363 //property NetForceWeap: Byte read FNetForceWeap write FNetForceWeap;
364 property NetForceWeapFIdx
: LongWord read FNetForceWeapFIdx write FNetForceWeapFIdx
;
365 //property CurrFrameIdx: LongWord read FCurrFrameIdx write FCurrFrameIdx;
366 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
367 property Secrets
: Integer read FSecrets
;
368 property GodMode
: Boolean read FGodMode write FGodMode
;
369 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
370 property NoReload
: Boolean read FNoReload write FNoReload
;
371 property alive
: Boolean read FAlive write FAlive
;
372 property Flag
: Byte read FFlag
;
373 property Team
: Byte read FTeam write FTeam
;
374 property Direction
: TDirection read FDirection
;
375 property GameX
: Integer read FObj
.X write FObj
.X
;
376 property GameY
: Integer read FObj
.Y write FObj
.Y
;
377 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
378 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
379 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
380 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
381 property IncCam
: Integer read FIncCam write FIncCam
;
382 property UID
: Word read FUID write FUID
;
383 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
384 property NetTime
: LongWord read FNetTime write FNetTime
;
387 property eName
: String read FName write FName
;
388 property eHealth
: Integer read FHealth write FHealth
;
389 property eLives
: Byte read FLives write FLives
;
390 property eArmor
: Integer read FArmor write FArmor
;
391 property eAir
: Integer read FAir write FAir
;
392 property eJetFuel
: Integer read FJetFuel write FJetFuel
;
393 property eFrags
: Integer read FFrags write FFrags
;
394 property eDeath
: Integer read FDeath write FDeath
;
395 property eKills
: Integer read FKills write FKills
;
396 property eCurrWeap
: Byte read FCurrWeap write FCurrWeap
;
397 property eMonsterKills
: Integer read FMonsterKills write FMonsterKills
;
398 property eSecrets
: Integer read FSecrets write FSecrets
;
399 property eGodMode
: Boolean read FGodMode write FGodMode
;
400 property eNoTarget
: Boolean read FNoTarget write FNoTarget
;
401 property eNoReload
: Boolean read FNoReload write FNoReload
;
402 property eAlive
: Boolean read FAlive write FAlive
;
403 property eFlag
: Byte read FFlag
;
404 property eTeam
: Byte read FTeam write FTeam
;
405 property eDirection
: TDirection read FDirection
;
406 property eGameX
: Integer read FObj
.X write FObj
.X
;
407 property eGameY
: Integer read FObj
.Y write FObj
.Y
;
408 property eGameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
409 property eGameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
410 property eGameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
411 property eGameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
412 property eIncCam
: Integer read FIncCam write FIncCam
;
413 property eUID
: Word read FUID
;
414 property eJustTeleported
: Boolean read FJustTeleported
;
415 property eNetTime
: LongWord read FNetTime
;
417 // set this before assigning something to `eDamage`
418 property eDamageType
: Integer read mEDamageType write mEDamageType
;
419 property eDamage
: Integer write doDamage
;
430 WeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
431 CloseWeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
432 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
435 procedure save (st
: TStream
);
436 procedure load (st
: TStream
);
444 TBot
= class(TPlayer
)
446 FSelectedWeapon
: Byte;
449 FAIFlags
: Array of TAIFlag
;
450 FDifficult
: TDifficult
;
452 function GetRnd(a
: Byte): Boolean;
453 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
454 function RunDirection(): TDirection
;
455 function FullInStep(XInc
, YInc
: Integer): Boolean;
456 //function NeedItem(Item: Byte): Byte;
457 procedure SelectWeapon(Dist
: Integer);
458 procedure SetAIFlag(aName
, fValue
: String20
);
459 function GetAIFlag(aName
: String20
): String20
;
460 procedure RemoveAIFlag(aName
: String20
);
461 function Healthy(): Byte;
462 procedure UpdateMove();
463 procedure UpdateCombat();
464 function KeyPressed(Key
: Word): Boolean;
465 procedure ReleaseKey(Key
: Byte);
466 function TargetOnScreen(TX
, TY
: Integer): Boolean;
467 procedure OnDamage(Angle
: SmallInt); override;
470 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
471 constructor Create(); override;
472 destructor Destroy(); override;
473 procedure Draw(); override;
474 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
475 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
476 procedure Update(); override;
477 procedure SaveState (st
: TStream
); override;
478 procedure LoadState (st
: TStream
); override;
490 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
491 procedure moveBy (dx
, dy
: Integer); inline;
493 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
507 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
508 procedure moveBy (dx
, dy
: Integer); inline;
510 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
513 TCorpse
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
522 FAnimation
: TAnimation
;
523 FAnimationMask
: TAnimation
;
526 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
527 destructor Destroy(); override;
528 procedure Damage(Value
: Word; vx
, vy
: Integer);
531 procedure SaveState (st
: TStream
);
532 procedure LoadState (st
: TStream
);
534 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
535 procedure moveBy (dx
, dy
: Integer); inline;
537 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
539 function ObjPtr (): PObj
; inline;
541 property Obj
: TObj read FObj
; // copies object
542 property State
: Byte read FState
;
543 property Mess
: Boolean read FMess
;
546 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
552 gPlayers
: Array of TPlayer
;
553 gCorpses
: Array of TCorpse
;
554 gGibs
: Array of TGib
;
555 gShells
: Array of TShell
;
556 gTeamStat
: TTeamStat
;
557 gFly
: Boolean = False;
558 gAimLine
: Boolean = False;
559 gChatBubble
: Byte = 0;
563 MAX_RUNVEL
: Integer = 8;
564 VEL_JUMP
: Integer = 10;
565 SHELL_TIMEOUT
: Cardinal = 60000;
567 function Lerp(X
, Y
, Factor
: Integer): Integer;
569 procedure g_Gibs_SetMax(Count
: Word);
570 function g_Gibs_GetMax(): Word;
571 procedure g_Corpses_SetMax(Count
: Word);
572 function g_Corpses_GetMax(): Word;
573 procedure g_Shells_SetMax(Count
: Word);
574 function g_Shells_GetMax(): Word;
576 procedure g_Player_Init();
577 procedure g_Player_Free();
578 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
579 function g_Player_CreateFromState (st
: TStream
): Word;
580 procedure g_Player_Remove(UID
: Word);
581 procedure g_Player_ResetTeams();
582 procedure g_Player_UpdateAll();
583 procedure g_Player_DrawAll();
584 procedure g_Player_DrawDebug(p
: TPlayer
);
585 procedure g_Player_DrawHealth();
586 procedure g_Player_RememberAll();
587 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
588 function g_Player_Get(UID
: Word): TPlayer
;
589 function g_Player_GetCount(): Byte;
590 function g_Player_GetStats(): TPlayerStatArray
;
591 function g_Player_ValidName(Name
: String): Boolean;
592 procedure g_Player_CreateCorpse(Player
: TPlayer
);
593 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
594 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
595 procedure g_Player_UpdatePhysicalObjects();
596 procedure g_Player_DrawCorpses();
597 procedure g_Player_DrawShells();
598 procedure g_Player_RemoveAllCorpses();
599 procedure g_Player_Corpses_SaveState (st
: TStream
);
600 procedure g_Player_Corpses_LoadState (st
: TStream
);
601 procedure g_Bot_Add(Team
, Difficult
: Byte);
602 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1);
603 procedure g_Bot_MixNames();
604 procedure g_Bot_RemoveAll();
609 {$INCLUDE ../nogl/noGLuses.inc}
610 {$IFDEF ENABLE_HOLMES}
613 e_log
, g_map
, g_items
, g_console
, g_gfx
, Math
,
614 g_options
, g_triggers
, g_menu
, g_game
, g_grid
,
615 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
,
616 g_net
, g_netmsg
, g_window
,
619 const PLR_SAVE_VERSION
= 0;
629 diag_precision
: Byte;
633 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
634 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
635 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
639 TIME_RESPAWN1
= 1500;
640 TIME_RESPAWN2
= 2000;
641 TIME_RESPAWN3
= 3000;
644 JET_MAX
= 540; // ~30 sec
645 PLAYER_SUIT_TIME
= 30000;
646 PLAYER_INVUL_TIME
= 30000;
647 PLAYER_INVIS_TIME
= 35000;
648 FRAG_COMBO_TIME
= 3000;
652 ANGLE_RIGHTDOWN
= -35;
654 ANGLE_LEFTDOWN
= -145;
655 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
656 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
659 BOT_UNSAFEDIST
= 128;
660 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
662 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
663 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
664 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
665 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
666 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
667 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
668 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
669 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
670 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
671 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
672 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
673 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
674 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
675 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
676 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
677 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
678 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
679 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
680 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
681 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
682 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
683 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
684 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
685 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
686 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
687 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
689 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
690 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
692 BOTNAMES_FILENAME
= 'botnames.txt';
693 BOTLIST_FILENAME
= 'botlist.txt';
697 MaxCorpses
: Word = 20;
698 MaxShells
: Word = 300;
699 CurrentGib
: Integer = 0;
700 CurrentShell
: Integer = 0;
701 BotNames
: Array of String;
702 BotList
: Array of TBotProfile
;
705 function Lerp(X
, Y
, Factor
: Integer): Integer;
707 Result
:= X
+ ((Y
- X
) div Factor
);
710 function SameTeam(UID1
, UID2
: Word): Boolean;
714 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
715 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
717 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
719 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
720 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
722 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
725 procedure g_Gibs_SetMax(Count
: Word);
728 SetLength(gGibs
, Count
);
730 if CurrentGib
>= Count
then
734 function g_Gibs_GetMax(): Word;
739 procedure g_Shells_SetMax(Count
: Word);
742 SetLength(gShells
, Count
);
744 if CurrentShell
>= Count
then
748 function g_Shells_GetMax(): Word;
754 procedure g_Corpses_SetMax(Count
: Word);
757 SetLength(gCorpses
, Count
);
760 function g_Corpses_GetMax(): Word;
762 Result
:= MaxCorpses
;
765 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
775 // Åñòü ëè ìåñòî â gPlayers:
776 if gPlayers
<> nil then
777 for a
:= 0 to High(gPlayers
) do
778 if gPlayers
[a
] = nil then
784 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
787 SetLength(gPlayers
, Length(gPlayers
)+1);
791 // Ñîçäàåì îáúåêò èãðîêà:
793 gPlayers
[a
] := TBot
.Create()
795 gPlayers
[a
] := TPlayer
.Create();
798 gPlayers
[a
].FActualModelName
:= ModelName
;
799 gPlayers
[a
].SetModel(ModelName
);
801 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
802 if gPlayers
[a
].FModel
= nil then
806 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
810 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
811 if Random(2) = 0 then
815 gPlayers
[a
].FPreferredTeam
:= Team
;
817 case gGameSettings
.GameMode
of
818 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
820 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
822 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
825 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
826 gPlayers
[a
].FColor
:= Color
;
827 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
828 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
830 gPlayers
[a
].FModel
.Color
:= Color
;
832 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
833 gPlayers
[a
].FAlive
:= False;
835 Result
:= gPlayers
[a
].FUID
;
838 function g_Player_CreateFromState (st
: TStream
): Word;
845 if (st
= nil) then exit
; //???
848 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
849 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
852 Bot
:= utils
.readBool(st
);
857 // Åñòü ëè ìåñòî â gPlayers:
858 for a
:= 0 to High(gPlayers
) do if (gPlayers
[a
] = nil) then begin ok
:= true; break
; end;
860 // Íåò ìåñòà - ðàñøèðÿåì gPlayers
863 SetLength(gPlayers
, Length(gPlayers
)+1);
867 // Ñîçäàåì îáúåêò èãðîêà
869 gPlayers
[a
] := TBot
.Create()
871 gPlayers
[a
] := TPlayer
.Create();
872 gPlayers
[a
].FIamBot
:= Bot
;
873 gPlayers
[a
].FPhysics
:= True;
876 gPlayers
[a
].FUID
:= utils
.readWord(st
);
878 gPlayers
[a
].FName
:= utils
.readStr(st
);
880 gPlayers
[a
].FTeam
:= utils
.readByte(st
);
881 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
883 gPlayers
[a
].FAlive
:= utils
.readBool(st
);
884 // Èçðàñõîäîâàë ëè âñå æèçíè
885 gPlayers
[a
].FNoRespawn
:= utils
.readBool(st
);
887 b
:= utils
.readByte(st
);
888 if b
= 1 then gPlayers
[a
].FDirection
:= TDirection
.D_LEFT
else gPlayers
[a
].FDirection
:= TDirection
.D_RIGHT
; // b = 2
890 gPlayers
[a
].FHealth
:= utils
.readLongInt(st
);
892 gPlayers
[a
].FLives
:= utils
.readByte(st
);
894 gPlayers
[a
].FArmor
:= utils
.readLongInt(st
);
896 gPlayers
[a
].FAir
:= utils
.readLongInt(st
);
898 gPlayers
[a
].FJetFuel
:= utils
.readLongInt(st
);
900 gPlayers
[a
].FPain
:= utils
.readLongInt(st
);
902 gPlayers
[a
].FKills
:= utils
.readLongInt(st
);
904 gPlayers
[a
].FMonsterKills
:= utils
.readLongInt(st
);
906 gPlayers
[a
].FFrags
:= utils
.readLongInt(st
);
908 gPlayers
[a
].FFragCombo
:= utils
.readByte(st
);
909 // Âðåìÿ ïîñëåäíåãî ôðàãà
910 gPlayers
[a
].FLastFrag
:= utils
.readLongWord(st
);
912 gPlayers
[a
].FDeath
:= utils
.readLongInt(st
);
914 gPlayers
[a
].FFlag
:= utils
.readByte(st
);
916 gPlayers
[a
].FSecrets
:= utils
.readLongInt(st
);
918 gPlayers
[a
].FCurrWeap
:= utils
.readByte(st
);
919 //gPlayers[a].FNetForceWeap := gPlayers[a].FCurrWeap;
920 // Ñëåäóþùåå æåëàåìîå îðóæèå
921 gPlayers
[a
].FNextWeap
:= utils
.readWord(st
);
923 gPlayers
[a
].FNextWeapDelay
:= utils
.readByte(st
);
925 gPlayers
[a
].FBFGFireCounter
:= utils
.readSmallInt(st
);
927 gPlayers
[a
].FDamageBuffer
:= utils
.readLongInt(st
);
928 // Ïîñëåäíèé óäàðèâøèé
929 gPlayers
[a
].FLastSpawnerUID
:= utils
.readWord(st
);
930 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
931 gPlayers
[a
].FLastHit
:= utils
.readByte(st
);
933 Obj_LoadState(@gPlayers
[a
].FObj
, st
);
934 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
935 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FAmmo
[i
] := utils
.readWord(st
);
936 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
937 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FMaxAmmo
[i
] := utils
.readWord(st
);
939 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FWeapon
[i
] := utils
.readBool(st
);
940 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
941 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FReloading
[i
] := utils
.readWord(st
);
943 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
944 // Íàëè÷èå êðàñíîãî êëþ÷à
945 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
946 // Íàëè÷èå çåëåíîãî êëþ÷à
947 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
948 // Íàëè÷èå ñèíåãî êëþ÷à
949 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
951 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_BERSERK
);
952 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
953 for i
:= MR_SUIT
to MR_MAX
do gPlayers
[a
].FMegaRulez
[i
] := utils
.readLongWord(st
);
954 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
955 for i
:= T_RESPAWN
to T_FLAGCAP
do gPlayers
[a
].FTime
[i
] := utils
.readLongWord(st
);
958 gPlayers
[a
].FActualModelName
:= utils
.readStr(st
);
960 gPlayers
[a
].FColor
.R
:= utils
.readByte(st
);
961 gPlayers
[a
].FColor
.G
:= utils
.readByte(st
);
962 gPlayers
[a
].FColor
.B
:= utils
.readByte(st
);
963 // Îáíîâëÿåì ìîäåëü èãðîêà
964 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
966 // Íåò ìîäåëè - ñîçäàíèå íåâîçìîæíî
967 if (gPlayers
[a
].FModel
= nil) then
971 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
975 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû
976 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
977 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
979 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
981 result
:= gPlayers
[a
].FUID
;
985 procedure g_Player_ResetTeams();
989 if g_Game_IsClient
then
991 if gPlayers
= nil then
993 for a
:= Low(gPlayers
) to High(gPlayers
) do
994 if gPlayers
[a
] <> nil then
995 case gGameSettings
.GameMode
of
997 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
999 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
1000 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
1001 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
1004 gPlayers
[a
].ChangeTeam(TEAM_RED
)
1006 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
1009 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
1013 procedure g_Bot_Add(Team
, Difficult
: Byte);
1016 _name
, _model
: String;
1019 if not g_Game_IsServer
then Exit
;
1021 // Ñïèñîê íàçâàíèé ìîäåëåé:
1022 m
:= g_PlayerModel_GetNames();
1027 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1028 Team
:= TEAM_COOP
// COOP
1030 if gGameSettings
.GameMode
= GM_DM
then
1031 Team
:= TEAM_NONE
// DM
1033 if Team
= TEAM_NONE
then // CTF / TDM
1035 // Àâòîáàëàíñ êîìàíä:
1039 for a
:= 0 to High(gPlayers
) do
1040 if gPlayers
[a
] <> nil then
1042 if gPlayers
[a
].Team
= TEAM_RED
then
1045 if gPlayers
[a
].Team
= TEAM_BLUE
then
1055 if Random(2) = 0 then
1061 // Âûáèðàåì áîòó èìÿ:
1063 if BotNames
<> nil then
1064 for a
:= 0 to High(BotNames
) do
1065 if g_Player_ValidName(BotNames
[a
]) then
1067 _name
:= BotNames
[a
];
1071 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
1074 _name
:= Format('DFBOT%.2d', [Random(100)]);
1075 until g_Player_ValidName(_name
);
1077 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1078 _model
:= m
[Random(Length(m
))];
1081 with g_Player_Get(g_Player_Create(_model
,
1082 _RGB(Min(Random(9)*32, 255),
1083 Min(Random(9)*32, 255),
1084 Min(Random(9)*32, 255)),
1085 Team
, True)) as TBot
do
1090 1: FDifficult
:= DIFFICULT_EASY
;
1091 2: FDifficult
:= DIFFICULT_MEDIUM
;
1092 else FDifficult
:= DIFFICULT_HARD
;
1095 for a
:= WP_FIRST
to WP_LAST
do
1097 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1098 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1099 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1102 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1104 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1105 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1110 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1);
1113 _name
, _model
: String;
1116 if not g_Game_IsServer
then Exit
;
1118 // Ñïèñîê íàçâàíèé ìîäåëåé:
1119 m
:= g_PlayerModel_GetNames();
1124 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1125 Team
:= TEAM_COOP
// COOP
1127 if gGameSettings
.GameMode
= GM_DM
then
1128 Team
:= TEAM_NONE
// DM
1130 if Team
= TEAM_NONE
then
1131 Team
:= BotList
[num
].team
; // CTF / TDM
1133 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1134 lName
:= AnsiLowerCase(lName
);
1135 if (num
< 0) or (num
> Length(BotList
)-1) then
1137 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1138 for a
:= 0 to High(BotList
) do
1139 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1148 _name
:= BotList
[num
].name
;
1149 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1150 if not g_Player_ValidName(_name
) then
1152 _name
:= Format('DFBOT%.2d', [Random(100)]);
1153 until g_Player_ValidName(_name
);
1156 _model
:= BotList
[num
].model
;
1157 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1158 if not InSArray(_model
, m
) then
1159 _model
:= m
[Random(Length(m
))];
1162 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1166 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1167 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1168 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1169 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1170 FDifficult
.Cover
:= BotList
[num
].cover
;
1171 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1173 for a
:= WP_FIRST
to WP_LAST
do
1175 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1176 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1177 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1180 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1182 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1186 procedure g_Bot_RemoveAll();
1190 if not g_Game_IsServer
then Exit
;
1191 if gPlayers
= nil then Exit
;
1193 for a
:= 0 to High(gPlayers
) do
1194 if gPlayers
[a
] <> nil then
1195 if gPlayers
[a
] is TBot
then
1197 gPlayers
[a
].Lives
:= 0;
1198 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1199 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1200 g_Player_Remove(gPlayers
[a
].FUID
);
1206 procedure g_Bot_MixNames();
1211 if BotNames
<> nil then
1212 for a
:= 0 to High(BotNames
) do
1214 b
:= Random(Length(BotNames
));
1216 Botnames
[a
] := BotNames
[b
];
1221 procedure g_Player_Remove(UID
: Word);
1225 if gPlayers
= nil then Exit
;
1227 if g_Game_IsServer
and g_Game_IsNet
then
1228 MH_SEND_PlayerDelete(UID
);
1230 for i
:= 0 to High(gPlayers
) do
1231 if gPlayers
[i
] <> nil then
1232 if gPlayers
[i
].FUID
= UID
then
1234 if gPlayers
[i
] is TPlayer
then
1235 TPlayer(gPlayers
[i
]).Free()
1237 TBot(gPlayers
[i
]).Free();
1243 procedure g_Player_Init();
1253 if not FileExists(DataDir
+ BOTNAMES_FILENAME
) then
1256 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1257 AssignFile(F
, DataDir
+ BOTNAMES_FILENAME
);
1268 SetLength(BotNames
, Length(BotNames
)+1);
1269 BotNames
[High(BotNames
)] := s
;
1277 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1278 config
:= TConfig
.CreateFile(DataDir
+ BOTLIST_FILENAME
);
1282 while config
.SectionExists(IntToStr(a
)) do
1284 SetLength(BotList
, Length(BotList
)+1);
1286 with BotList
[High(BotList
)] do
1289 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1291 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1293 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1298 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1299 color
.R
:= StrToIntDef(sa
[0], 0);
1300 color
.G
:= StrToIntDef(sa
[1], 0);
1301 color
.B
:= StrToIntDef(sa
[2], 0);
1302 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1303 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1304 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1305 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1306 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1307 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1308 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1309 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1310 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1311 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1312 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1313 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1314 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1315 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1316 if Length(sa
) = 10 then
1318 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1319 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1320 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1321 if Length(sa
) = 10 then
1323 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1325 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1326 if Length(sa) = 10 then
1328 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1337 procedure g_Player_Free();
1341 if gPlayers
<> nil then
1343 for i
:= 0 to High(gPlayers
) do
1344 if gPlayers
[i
] <> nil then
1346 if gPlayers
[i
] is TPlayer
then
1347 TPlayer(gPlayers
[i
]).Free()
1349 TBot(gPlayers
[i
]).Free();
1360 procedure g_Player_UpdateAll();
1364 if gPlayers
= nil then Exit
;
1366 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1367 for i
:= 0 to High(gPlayers
) do
1369 if gPlayers
[i
] <> nil then
1371 if gPlayers
[i
] is TPlayer
then
1373 //if (gPlayers[i].NetForceWeapFIdx > gTime) then writeln('*** PLAYER #', i, '; gTime=', gTime, '; nfwf=', gPlayers[i].NetForceWeapFIdx);
1374 gPlayers
[i
].Update();
1375 if (not gPlayers
[i
].alive
) or (gPlayers
[i
].NetForceWeapFIdx
>= gTime
+15) then gPlayers
[i
].NetForceWeapFIdx
:= 0; // just in case
1376 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1380 // bot updates weapons in `UpdateCombat()`
1381 TBot(gPlayers
[i
]).Update();
1385 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1388 procedure g_Player_DrawAll();
1392 if gPlayers
= nil then Exit
;
1394 for i
:= 0 to High(gPlayers
) do
1395 if gPlayers
[i
] <> nil then
1396 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1397 else TBot(gPlayers
[i
]).Draw();
1400 procedure g_Player_DrawDebug(p
: TPlayer
);
1404 if p
= nil then Exit
;
1405 if (@p
.FObj
) = nil then Exit
;
1407 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1409 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1410 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1411 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1412 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1413 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1414 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1417 procedure g_Player_DrawHealth();
1422 if gPlayers
= nil then Exit
;
1423 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1425 for i
:= 0 to High(gPlayers
) do
1426 if gPlayers
[i
] <> nil then
1428 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1429 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1430 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1431 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1432 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1433 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1437 function g_Player_Get(UID
: Word): TPlayer
;
1443 if gPlayers
= nil then
1446 for a
:= 0 to High(gPlayers
) do
1447 if gPlayers
[a
] <> nil then
1448 if gPlayers
[a
].FUID
= UID
then
1450 Result
:= gPlayers
[a
];
1455 function g_Player_GetCount(): Byte;
1461 if gPlayers
= nil then
1464 for a
:= 0 to High(gPlayers
) do
1465 if gPlayers
[a
] <> nil then
1466 Result
:= Result
+ 1;
1469 function g_Player_GetStats(): TPlayerStatArray
;
1475 if gPlayers
= nil then Exit
;
1477 for a
:= 0 to High(gPlayers
) do
1478 if gPlayers
[a
] <> nil then
1480 SetLength(Result
, Length(Result
)+1);
1481 with Result
[High(Result
)] do
1483 Ping
:= gPlayers
[a
].FPing
;
1484 Loss
:= gPlayers
[a
].FLoss
;
1485 Name
:= gPlayers
[a
].FName
;
1486 Team
:= gPlayers
[a
].FTeam
;
1487 Frags
:= gPlayers
[a
].FFrags
;
1488 Deaths
:= gPlayers
[a
].FDeath
;
1489 Kills
:= gPlayers
[a
].FKills
;
1490 Color
:= gPlayers
[a
].FModel
.Color
;
1491 Lives
:= gPlayers
[a
].FLives
;
1492 Spectator
:= gPlayers
[a
].FSpectator
;
1497 procedure g_Player_RememberAll
;
1501 for i
:= Low(gPlayers
) to High(gPlayers
) do
1502 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1503 gPlayers
[i
].RememberState
;
1506 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1510 gTeamStat
[TEAM_RED
].Goals
:= 0;
1511 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1513 if gPlayers
<> nil then
1514 for i
:= 0 to High(gPlayers
) do
1515 if gPlayers
[i
] <> nil then
1517 gPlayers
[i
].Reset(Force
);
1519 if gPlayers
[i
] is TPlayer
then
1521 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1522 gPlayers
[i
].Respawn(Silent
)
1524 gPlayers
[i
].Spectate();
1527 TBot(gPlayers
[i
]).Respawn(Silent
);
1531 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1537 if Player
.alive
then
1540 // Ðàçðûâàåì ñâÿçü ñ ïðåæíèì òðóïîì:
1541 if gCorpses
<> nil then
1542 for i
:= 0 to High(gCorpses
) do
1543 if gCorpses
[i
] <> nil then
1544 if gCorpses
[i
].FPlayerUID
= Player
.FUID
then
1545 gCorpses
[i
].FPlayerUID
:= 0;
1547 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1552 if (FHealth
>= -50) or (gGibsCount
= 0) then
1554 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1558 for find_id
:= 0 to High(gCorpses
) do
1559 if gCorpses
[find_id
] = nil then
1566 find_id
:= Random(Length(gCorpses
));
1568 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1569 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1570 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1571 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1572 gCorpses
[find_id
].FPlayerUID
:= FUID
;
1575 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1576 FObj
.Y
+ PLAYER_RECT_CY
,
1577 FModel
.Name
, FModel
.Color
);
1581 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1585 if (gShells
= nil) or (Length(gShells
) = 0) then
1588 with gShells
[CurrentShell
] do
1594 if T
= SHELL_BULLET
then
1596 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1600 Obj
.Rect
.Width
:= 4;
1601 Obj
.Rect
.Height
:= 2;
1605 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1609 Obj
.Rect
.Width
:= 7;
1610 Obj
.Rect
.Height
:= 3;
1616 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1617 positionChanged(); // this updates spatial accelerators
1618 RAngle
:= Random(360);
1619 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1621 if CurrentShell
>= High(gShells
) then
1628 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1631 GibsArray
: TGibsArray
;
1634 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1636 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1638 Blood
:= g_PlayerModel_GetBlood(ModelName
);
1640 for a
:= 0 to High(GibsArray
) do
1641 with gGibs
[CurrentGib
] do
1644 ID
:= GibsArray
[a
].ID
;
1645 MaskID
:= GibsArray
[a
].MaskID
;
1648 Obj
.Rect
:= GibsArray
[a
].Rect
;
1649 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1650 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1651 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1652 positionChanged(); // this updates spatial accelerators
1653 RAngle
:= Random(360);
1655 if gBloodCount
> 0 then
1656 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1657 Random(48), Random(48), Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
1659 if CurrentGib
>= High(gGibs
) then
1666 procedure g_Player_UpdatePhysicalObjects();
1672 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1677 if T
= SHELL_BULLET
then
1678 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1680 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1685 if gGibs
<> nil then
1686 for i
:= 0 to High(gGibs
) do
1687 if gGibs
[i
].alive
then
1691 mr
:= g_Obj_Move(@Obj
, True, False, True);
1692 positionChanged(); // this updates spatial accelerators
1694 if WordBool(mr
and MOVE_FALLOUT
) then
1700 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1701 if WordBool(mr
and MOVE_HITWALL
) then
1702 Obj
.Vel
.X
:= -(vel
.X
div 2);
1703 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1704 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1706 if (Obj
.Vel
.X
>= 0) then
1708 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1709 if RAngle
>= 360 then
1710 RAngle
:= RAngle
mod 360;
1711 end else begin // Counter-clockwise
1712 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1714 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1717 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1718 if gTime
mod (GAME_TICK
*3) = 0 then
1719 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1723 if gCorpses
<> nil then
1724 for i
:= 0 to High(gCorpses
) do
1725 if gCorpses
[i
] <> nil then
1726 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1732 gCorpses
[i
].Update();
1735 if gShells
<> nil then
1736 for i
:= 0 to High(gShells
) do
1737 if gShells
[i
].alive
then
1741 mr
:= g_Obj_Move(@Obj
, True, False, True);
1742 positionChanged(); // this updates spatial accelerators
1744 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1750 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1751 if WordBool(mr
and MOVE_HITWALL
) then
1753 Obj
.Vel
.X
:= -(vel
.X
div 2);
1754 if not WordBool(mr
and MOVE_INWATER
) then
1755 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1757 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1759 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1760 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1761 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1763 if RAngle
mod 90 <> 0 then
1764 RAngle
:= (RAngle
div 90) * 90;
1766 else if not WordBool(mr
and MOVE_INWATER
) then
1767 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1770 if (Obj
.Vel
.X
>= 0) then
1772 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1773 if RAngle
>= 360 then
1774 RAngle
:= RAngle
mod 360;
1775 end else begin // Counter-clockwise
1776 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1778 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1784 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1786 x
:= Obj
.X
+Obj
.Rect
.X
;
1787 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1788 w
:= Obj
.Rect
.Width
;
1789 h
:= Obj
.Rect
.Height
;
1792 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1794 if (dx
<> 0) or (dy
<> 0) then
1803 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1807 w
:= Obj
.Rect
.Width
;
1808 h
:= Obj
.Rect
.Height
;
1811 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1813 if (dx
<> 0) or (dy
<> 0) then
1822 procedure TGib
.positionChanged (); inline; begin end;
1823 procedure TShell
.positionChanged (); inline; begin end;
1826 procedure g_Player_DrawCorpses();
1831 if gGibs
<> nil then
1832 for i
:= 0 to High(gGibs
) do
1833 if gGibs
[i
].alive
then
1836 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1839 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1840 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1842 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1845 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1851 if gCorpses
<> nil then
1852 for i
:= 0 to High(gCorpses
) do
1853 if gCorpses
[i
] <> nil then
1857 procedure g_Player_DrawShells();
1862 if gShells
<> nil then
1863 for i
:= 0 to High(gShells
) do
1864 if gShells
[i
].alive
then
1867 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1873 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1877 procedure g_Player_RemoveAllCorpses();
1883 SetLength(gGibs
, MaxGibs
);
1884 SetLength(gShells
, MaxGibs
);
1888 if gCorpses
<> nil then
1889 for i
:= 0 to High(gCorpses
) do
1893 SetLength(gCorpses
, MaxCorpses
);
1896 procedure g_Player_Corpses_SaveState (st
: TStream
);
1900 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ
1902 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1904 // Êîëè÷åñòâî òðóïîâ
1905 utils
.writeInt(st
, LongInt(count
));
1907 if (count
= 0) then exit
;
1910 for i
:= 0 to High(gCorpses
) do
1912 if gCorpses
[i
] <> nil then
1915 utils
.writeStr(st
, gCorpses
[i
].FModelName
);
1917 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1918 // Ñîõðàíÿåì äàííûå òðóïà:
1919 gCorpses
[i
].SaveState(st
);
1925 procedure g_Player_Corpses_LoadState (st
: TStream
);
1933 g_Player_RemoveAllCorpses();
1935 // Êîëè÷åñòâî òðóïîâ:
1936 count
:= utils
.readLongInt(st
);
1937 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1939 if (count
= 0) then exit
;
1942 for i
:= 0 to count
-1 do
1945 str
:= utils
.readStr(st
);
1947 b
:= utils
.readBool(st
);
1949 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1950 // Çàãðóæàåì äàííûå òðóïà
1951 gCorpses
[i
].LoadState(st
);
1958 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1960 procedure TPlayer
.BFGHit();
1962 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1963 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1964 if g_Game_IsServer
and g_Game_IsNet
then
1965 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1966 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1970 procedure TPlayer
.ChangeModel(ModelName
: string);
1972 locModel
: TPlayerModel
;
1974 locModel
:= g_PlayerModel_Get(ModelName
);
1975 if locModel
= nil then Exit
;
1981 procedure TPlayer
.SetModel(ModelName
: string);
1985 m
:= g_PlayerModel_Get(ModelName
);
1988 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1989 m
:= g_PlayerModel_Get('doomer');
1992 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1997 if FModel
<> nil then
2002 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2003 FModel
.Color
:= FColor
2005 FModel
.Color
:= TEAMCOLOR
[FTeam
];
2006 FModel
.SetWeapon(FCurrWeap
);
2007 FModel
.SetFlag(FFlag
);
2008 SetDirection(FDirection
);
2011 procedure TPlayer
.SetColor(Color
: TRGB
);
2014 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2015 if FModel
<> nil then FModel
.Color
:= Color
;
2018 procedure TPlayer
.SwitchTeam
;
2020 if g_Game_IsClient
then
2022 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
2024 if gGameOn
and FAlive
then
2025 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
2027 if FTeam
= TEAM_RED
then
2029 ChangeTeam(TEAM_BLUE
);
2030 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
2031 if g_Game_IsNet
then
2032 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
2036 ChangeTeam(TEAM_RED
);
2037 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
2038 if g_Game_IsNet
then
2039 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
2041 FPreferredTeam
:= FTeam
;
2044 procedure TPlayer
.ChangeTeam(Team
: Byte);
2051 TEAM_RED
, TEAM_BLUE
:
2052 FModel
.Color
:= TEAMCOLOR
[Team
];
2054 FModel
.Color
:= FColor
;
2056 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2057 MH_SEND_PlayerStats(FUID
);
2061 procedure TPlayer.CollideItem();
2066 if gItems = nil then Exit;
2067 if not FAlive then Exit;
2069 for i := 0 to High(gItems) do
2072 if (ItemType <> ITEM_NONE) and alive then
2073 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2074 PLAYER_RECT.Height, @Obj) then
2076 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2078 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2079 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2080 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2081 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2082 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2084 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2085 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2086 (gGameSettings.GameType = GT_SINGLE) and
2087 (g_Player_GetCount() > 1)) then
2088 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2094 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2096 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2097 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2101 constructor TPlayer
.Create();
2107 mEDamageType
:= HIT_SOME
;
2113 FSawSound
:= TPlayableSound
.Create();
2114 FSawSoundIdle
:= TPlayableSound
.Create();
2115 FSawSoundHit
:= TPlayableSound
.Create();
2116 FSawSoundSelect
:= TPlayableSound
.Create();
2117 FJetSoundFly
:= TPlayableSound
.Create();
2118 FJetSoundOn
:= TPlayableSound
.Create();
2119 FJetSoundOff
:= TPlayableSound
.Create();
2121 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2122 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2123 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2124 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2125 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2126 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2127 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2129 FSpectatePlayer
:= -1;
2133 FSavedState
.WaitRecall
:= False;
2139 FActualModelName
:= 'doomer';
2142 FObj
.Rect
:= PLAYER_RECT
;
2144 FBFGFireCounter
:= -1;
2145 FJustTeleported
:= False;
2148 //FNetForceWeap := FCurrWeap;
2149 FNetForceWeapFIdx
:= 0;
2150 //FCurrFrameIdx := 0;
2153 releaseAllWeaponSwitchKeys();
2157 procedure TPlayer
.releaseAllWeaponSwitchKeys ();
2161 for f
:= 0 to High(weaponSwitchKeyReleased
) do weaponSwitchKeyReleased
[f
] := $03;
2164 procedure TPlayer
.weaponSwitchKeysStateChange (index
: Integer; pressed
: Boolean);
2166 Inc(index
, 2); // -2: prev; -1: next
2167 if (index
< 0) or (index
> High(weaponSwitchKeyReleased
)) then exit
;
2168 weaponSwitchKeyReleased
[index
] := weaponSwitchKeyReleased
[index
] or $02;
2169 if (pressed
) then weaponSwitchKeyReleased
[index
] := weaponSwitchKeyReleased
[index
] xor $02;
2172 function TPlayer
.isWeaponSwitchKeyReleased (index
: Integer): Boolean;
2174 Inc(index
, 2); // -2: prev; -1: next
2175 if (index
< 0) or (index
> High(weaponSwitchKeyReleased
)) then
2181 result
:= (weaponSwitchKeyReleased
[index
] and $01) <> 0;
2185 procedure TPlayer
.weaponSwitchKeysShiftNewStates ();
2189 // copy bit 1 to bit 0
2190 for f
:= 0 to High(weaponSwitchKeyReleased
) do
2192 weaponSwitchKeyReleased
[f
] :=
2193 (weaponSwitchKeyReleased
[f
] and $02) or
2194 ((weaponSwitchKeyReleased
[f
] shr 1) and $01);
2199 procedure TPlayer
.positionChanged (); inline;
2203 procedure TPlayer
.doDamage (v
: Integer);
2205 if (v
<= 0) then exit
;
2206 if (v
> 32767) then v
:= 32767;
2207 Damage(v
, 0, 0, 0, mEDamageType
);
2210 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2214 if (not g_Game_IsClient
) and (not FAlive
) then
2219 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2220 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2222 if not g_Game_IsClient
then
2225 if t
= HIT_TRAP
then
2227 // Ëîâóøêà óáèâàåò ñðàçó:
2229 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2231 if t
= HIT_SELF
then
2235 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2238 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2239 FMegaRulez
[MR_SUIT
] := 0;
2240 FMegaRulez
[MR_INVUL
] := 0;
2241 FMegaRulez
[MR_INVIS
] := 0;
2245 // Íî îò îñòàëüíîãî ñïàñàåò:
2246 if FMegaRulez
[MR_INVUL
] >= gTime
then
2253 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2254 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2255 (SpawnerUID
= FUID
) or
2256 (not SameTeam(FUID
, SpawnerUID
)) then
2258 FLastSpawnerUID
:= SpawnerUID
;
2260 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2261 if gBloodCount
> 0 then
2263 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2264 if value
div 4 <= c
then
2265 c
:= c
- (value
div 4)
2269 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2273 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2274 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2277 if t
= HIT_WATER
then
2278 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2279 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2284 Inc(FDamageBuffer
, value
);
2288 FPain
:= FPain
+ value
;
2291 if g_Game_IsServer
and g_Game_IsNet
then
2293 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2294 MH_SEND_PlayerStats(FUID
);
2295 MH_SEND_PlayerPos(False, FUID
);
2299 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2302 if g_Game_IsClient
then
2307 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2309 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2312 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2314 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2318 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2319 MH_SEND_PlayerStats(FUID
);
2322 destructor TPlayer
.Destroy();
2324 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2326 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2330 FSawSoundIdle
.Free();
2331 FSawSoundHit
.Free();
2332 FJetSoundFly
.Free();
2334 FJetSoundOff
.Free();
2336 if FPunchAnim
<> nil then
2342 procedure TPlayer
.DrawBubble();
2344 bubX
, bubY
: Integer;
2347 Rw
, Gw
, Bw
: SmallInt;
2350 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= TDirection
.D_LEFT
, -4, 18);
2351 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2359 1: // simple textual non-bubble
2361 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2362 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2363 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2366 2: // advanced pixel-perfect bubble
2368 if FTeam
= TEAM_RED
then
2371 if FTeam
= TEAM_BLUE
then
2374 3: // colored bubble
2376 Rb
:= FModel
.Color
.R
;
2377 Gb
:= FModel
.Color
.G
;
2378 Bb
:= FModel
.Color
.B
;
2379 Rw
:= Min(Rb
* 2 + 64, 255);
2380 Gw
:= Min(Gb
* 2 + 64, 255);
2381 Bw
:= Min(Bb
* 2 + 64, 255);
2382 if (Abs(Rw
- Rb
) < 32)
2383 or (Abs(Gw
- Gb
) < 32)
2384 or (Abs(Bw
- Bb
) < 32) then
2386 Rb
:= Max(Rw
div 2 - 16, 0);
2387 Gb
:= Max(Gw
div 2 - 16, 0);
2388 Bb
:= Max(Bw
div 2 - 16, 0);
2391 4: // custom textured bubble
2393 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2394 if FDirection
= TDirection
.D_RIGHT
then
2395 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2397 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, TMirrorType
.Horizontal
);
2403 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2404 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2406 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2409 Dot
:= IfThen(FDirection
= TDirection
.D_LEFT
, 14, 5);
2410 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2411 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
);
2412 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
);
2413 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
);
2414 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
);
2418 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2419 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2420 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2423 procedure TPlayer
.Draw();
2428 Mirror
: TMirrorType
;
2432 if Direction
= TDirection
.D_RIGHT
then
2433 Mirror
:= TMirrorType
.None
2435 Mirror
:= TMirrorType
.Horizontal
;
2437 if FPunchAnim
<> nil then
2439 FPunchAnim
.Draw(FObj
.X
+IfThen(Direction
= TDirection
.D_LEFT
, 15-FObj
.Rect
.X
, FObj
.Rect
.X
-15),
2440 FObj
.Y
+FObj
.Rect
.Y
-11, Mirror
);
2441 if FPunchAnim
.played
then
2448 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2449 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2451 e_GetTextureSize(ID
, @w
, @h
);
2452 if FDirection
= TDirection
.D_LEFT
then
2453 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2454 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False)
2456 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2457 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False);
2460 if FMegaRulez
[MR_INVIS
] > gTime
then
2462 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2463 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2465 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2466 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2470 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 200)
2472 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2475 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 254);
2478 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2481 if g_debug_Frames
then
2483 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2485 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2486 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2490 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2492 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2493 if gAimLine
and alive
and
2494 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2499 procedure TPlayer
.DrawAim();
2500 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2505 {$IFDEF ENABLE_HOLMES}
2506 if isValidViewPort
and (self
= gPlayer1
) then
2508 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2512 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2513 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2515 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2519 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2524 wx
, wy
, xx
, yy
: Integer;
2528 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= TDirection
.D_LEFT
, 7, -7);
2529 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2538 1: begin // Chainsaw
2545 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2546 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2547 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2548 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2553 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2554 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2555 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2556 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2558 4: begin // Double Shotgun
2561 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2562 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2563 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2564 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2566 5: begin // Chaingun
2569 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2570 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2571 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2572 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2574 6: begin // Rocket Launcher
2577 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2578 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2579 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2580 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2582 7: begin // Plasmagun
2585 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2586 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2587 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2588 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2593 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2594 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2595 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2596 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2598 9: begin // Super Chaingun
2601 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2602 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2603 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2604 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2607 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2608 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2609 {$IF DEFINED(D2F_DEBUG)}
2610 drawCast(sz
, wx
, wy
, xx
, yy
);
2612 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2616 procedure TPlayer
.DrawGUI();
2619 X
, Y
, SY
, a
, p
, m
: Integer;
2623 stat
: TPlayerStatArray
;
2625 X
:= gPlayerScreenSize
.X
;
2626 SY
:= gPlayerScreenSize
.Y
;
2629 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2631 if gGameSettings
.GameMode
= GM_CTF
then
2635 if gGameSettings
.GameMode
= GM_CTF
then
2637 s
:= 'TEXTURE_PLAYER_REDFLAG';
2638 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2639 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2640 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2641 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2642 if g_Texture_Get(s
, ID
) then
2643 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2646 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2647 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2648 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2650 if gGameSettings
.GameMode
= GM_CTF
then
2652 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2653 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2654 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2655 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2656 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2657 if g_Texture_Get(s
, ID
) then
2658 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2661 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2662 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2663 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2666 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2667 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2670 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2671 e_Draw(ID
, X
+2, Y
, 0, True, False);
2673 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2677 s
:= IntToStr(Frags
);
2678 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2679 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2684 stat
:= g_Player_GetStats();
2689 for a
:= 0 to High(stat
) do
2690 if stat
[a
].Name
<> Name
then
2692 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2693 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2697 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2698 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2699 s
:= s
+IntToStr(Abs(Frags
-m
));
2701 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2702 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2705 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2707 s
:= IntToStr(Lives
);
2708 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2709 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2713 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2714 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2716 if R_BERSERK
in FRulez
then
2717 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2719 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2721 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2722 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2724 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2725 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2726 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2728 s
:= IntToStr(FArmor
);
2729 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2730 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2732 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2738 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2743 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2745 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2746 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2747 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2748 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2749 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2750 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2751 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2752 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2753 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2756 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2757 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2758 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2760 if R_KEY_RED
in FRulez
then
2761 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2763 if R_KEY_GREEN
in FRulez
then
2764 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2766 if R_KEY_BLUE
in FRulez
then
2767 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2769 if FJetFuel
> 0 then
2771 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2772 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2773 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2774 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2775 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2776 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2780 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2781 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2782 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2785 if gShowPing
and g_Game_IsClient
then
2787 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2788 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2794 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2795 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2796 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2799 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2800 s
:= _lc
[I_PLAYER_SPECT4
];
2801 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2802 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2803 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2809 procedure TPlayer
.DrawRulez();
2813 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2814 if FMegaRulez
[MR_INVUL
] >= gTime
then
2816 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2817 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2822 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2823 191, 191, 191, 0, TBlending
.Invert
);
2826 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2827 if FMegaRulez
[MR_SUIT
] >= gTime
then
2829 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2830 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2835 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2836 0, 96, 0, 200, TBlending
.None
);
2839 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2840 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2842 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2843 255, 0, 0, 200, TBlending
.None
);
2847 procedure TPlayer
.DrawPain();
2851 if FPain
= 0 then Exit
;
2855 if a
< 15 then h
:= 0
2856 else if a
< 35 then h
:= 1
2857 else if a
< 55 then h
:= 2
2858 else if a
< 75 then h
:= 3
2859 else if a
< 95 then h
:= 4
2862 //if a > 255 then a := 255;
2864 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2865 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2868 procedure TPlayer
.DrawPickup();
2872 if FPickup
= 0 then Exit
;
2876 if a
< 15 then h
:= 1
2877 else if a
< 35 then h
:= 2
2878 else if a
< 55 then h
:= 3
2879 else if a
< 75 then h
:= 4
2882 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2885 procedure TPlayer
.DoPunch();
2890 if FPunchAnim
<> nil then begin
2895 st
:= 'FRAMES_PUNCH';
2896 if R_BERSERK
in FRulez
then
2897 st
:= st
+ '_BERSERK';
2898 if FKeys
[KEY_UP
].Pressed
then
2900 else if FKeys
[KEY_DOWN
].Pressed
then
2902 g_Frames_Get(id
, st
);
2903 FPunchAnim
:= TAnimation
.Create(id
, False, 1);
2906 procedure TPlayer
.Fire();
2908 f
, DidFire
: Boolean;
2909 wx
, wy
, xd
, yd
: Integer;
2912 if g_Game_IsClient
then Exit
;
2913 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2914 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2922 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2927 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2928 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2929 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
2930 yd
:= wy
+firediry();
2936 if R_BERSERK
in FRulez
then
2938 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2939 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2940 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2943 locobj
.rect
.Width
:= 39;
2944 locobj
.rect
.Height
:= 52;
2945 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2946 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2947 locobj
.Accel
.X
:= xd
-wx
;
2948 locobj
.Accel
.y
:= yd
-wy
;
2950 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2951 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2953 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2955 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
2959 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2963 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2968 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2969 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2971 FSawSoundSelect
.Stop();
2973 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2975 else if not FSawSoundHit
.IsPlaying() then
2977 FSawSoundSelect
.Stop();
2978 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2981 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2987 if FAmmo
[A_BULLETS
] > 0 then
2989 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2990 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2991 Dec(FAmmo
[A_BULLETS
]);
2992 FFireAngle
:= FAngle
;
2995 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2996 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3000 if FAmmo
[A_SHELLS
] > 0 then
3002 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3003 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
3004 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3005 Dec(FAmmo
[A_SHELLS
]);
3006 FFireAngle
:= FAngle
;
3010 FShellType
:= SHELL_SHELL
;
3014 if FAmmo
[A_SHELLS
] >= 2 then
3016 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
3017 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3018 Dec(FAmmo
[A_SHELLS
], 2);
3019 FFireAngle
:= FAngle
;
3023 FShellType
:= SHELL_DBLSHELL
;
3027 if FAmmo
[A_BULLETS
] > 0 then
3029 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
3030 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
3031 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3032 Dec(FAmmo
[A_BULLETS
]);
3033 FFireAngle
:= FAngle
;
3036 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3037 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3040 WEAPON_ROCKETLAUNCHER
:
3041 if FAmmo
[A_ROCKETS
] > 0 then
3043 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
3044 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3045 Dec(FAmmo
[A_ROCKETS
]);
3046 FFireAngle
:= FAngle
;
3052 if FAmmo
[A_CELLS
] > 0 then
3054 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
3055 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3056 Dec(FAmmo
[A_CELLS
]);
3057 FFireAngle
:= FAngle
;
3063 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
3065 FBFGFireCounter
:= 17;
3066 if not FNoReload
then
3067 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
3068 Dec(FAmmo
[A_CELLS
], 40);
3072 WEAPON_SUPERPULEMET
:
3073 if FAmmo
[A_SHELLS
] > 0 then
3075 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3076 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
3077 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3078 Dec(FAmmo
[A_SHELLS
]);
3079 FFireAngle
:= FAngle
;
3082 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3083 GameVelX
, GameVelY
-2, SHELL_SHELL
);
3086 WEAPON_FLAMETHROWER
:
3087 if FAmmo
[A_FUEL
] > 0 then
3089 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
3090 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3092 FFireAngle
:= FAngle
;
3098 if g_Game_IsNet
then
3102 if FCurrWeap
<> WEAPON_BFG
then
3103 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
3105 if not FNoReload
then
3106 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
3109 MH_SEND_PlayerStats(FUID
);
3114 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
3115 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
3116 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
3119 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
3122 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
3123 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
3124 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
3125 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
3126 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
3131 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
3133 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
3134 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
3135 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
3138 procedure TPlayer
.JetpackOn
;
3142 FJetSoundOn
.SetPosition(0);
3143 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3147 procedure TPlayer
.JetpackOff
;
3151 FJetSoundOff
.SetPosition(0);
3152 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3155 procedure TPlayer
.CatchFire(Attacker
: Word);
3158 FFireAttacker
:= Attacker
;
3159 if g_Game_IsNet
and g_Game_IsServer
then
3160 MH_SEND_PlayerStats(FUID
);
3163 procedure TPlayer
.Jump();
3165 if gFly
or FJetpack
then
3167 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3168 if FObj
.Vel
.Y
> -VEL_FLY
then
3169 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3172 if FJetFuel
> 0 then
3174 if (FJetFuel
< 1) and g_Game_IsServer
then
3178 if g_Game_IsNet
then
3179 MH_SEND_PlayerStats(FUID
);
3185 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3187 FCanJetpack
:= False;
3189 // Ïðûãàåì èëè âñïëûâàåì:
3190 if (CollideLevel(0, 1) or
3191 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3192 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3193 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3195 FObj
.Vel
.Y
:= -VEL_JUMP
;
3196 FCanJetpack
:= False;
3200 if BodyInLiquid(0, 0) then
3201 FObj
.Vel
.Y
:= -VEL_SW
3202 else if (FJetFuel
> 0) and FCanJetpack
and
3203 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3207 if g_Game_IsNet
then
3208 MH_SEND_PlayerStats(FUID
);
3213 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3215 a
, i
, k
, ab
, ar
: Byte;
3219 srv
, netsrv
: Boolean;
3225 procedure PushItem(t
: Byte);
3229 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3230 it
:= g_Items_ByIdx(id
);
3231 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3233 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3234 (FObj
.Vel
.Y
div 2)-Random(9));
3235 it
.positionChanged(); // this updates spatial accelerators
3239 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3241 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3242 (FObj
.Vel
.Y
div 2)-Random(6));
3244 else // -3..+3; -3..0
3246 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3247 (FObj
.Vel
.Y
div 2)-Random(4));
3249 it
.positionChanged(); // this updates spatial accelerators
3252 if g_Game_IsNet
and g_Game_IsServer
then
3253 MH_SEND_ItemSpawn(True, id
);
3257 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3258 Srv
:= g_Game_IsServer
;
3259 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3260 if Srv
then FDeath
:= FDeath
+ 1;
3265 if not FPhysics
then
3271 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3273 if FLives
> 0 then FLives
:= FLives
- 1;
3274 if FLives
= 0 then FNoRespawn
:= True;
3277 // Íîìåð òèïà ñìåðòè:
3280 K_SIMPLEKILL
: a
:= 1;
3282 K_EXTRAHARDKILL
: a
:= 3;
3287 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3289 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3296 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3298 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3299 K_EXTRAHARDKILL
, K_FALLKILL
:
3300 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3303 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3307 K_HARDKILL
, K_EXTRAHARDKILL
:
3311 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3312 if (KillType
<> K_FALLKILL
) and (Srv
) then
3313 g_Monsters_killedp();
3315 if SpawnerUID
= FUID
then
3317 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3322 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3325 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3326 begin // Óáèò äðóãèì èãðîêîì
3327 KP
:= g_Player_Get(SpawnerUID
);
3328 if (KP
<> nil) and Srv
then
3330 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3331 if SameTeam(FUID
, SpawnerUID
) then
3341 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3342 Inc(gTeamStat
[KP
.Team
].Goals
,
3343 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3345 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3348 plr
:= g_Player_Get(SpawnerUID
);
3356 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3360 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3364 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3369 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3370 begin // Óáèò ìîíñòðîì
3371 mon
:= g_Monsters_ByUID(SpawnerUID
);
3375 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
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 // Îñîáûå òèïû ñìåðòè
3395 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3396 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3397 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3398 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3399 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3400 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3406 for a
:= WP_FIRST
to WP_LAST
do
3410 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3411 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3412 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3413 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3414 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3415 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3416 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3417 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3418 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3427 if R_ITEM_BACKPACK
in FRulez
then
3428 PushItem(ITEM_AMMO_BACKPACK
);
3430 // Âûáðîñ ðàêåòíîãî ðàíöà:
3431 if FJetFuel
> 0 then
3432 PushItem(ITEM_JETPACK
);
3435 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3437 if R_KEY_RED
in FRulez
then
3438 PushItem(ITEM_KEY_RED
);
3440 if R_KEY_GREEN
in FRulez
then
3441 PushItem(ITEM_KEY_GREEN
);
3443 if R_KEY_BLUE
in FRulez
then
3444 PushItem(ITEM_KEY_BLUE
);
3451 g_Player_CreateCorpse(Self
);
3453 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3454 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3460 for i
:= Low(gPlayers
) to High(gPlayers
) do
3462 if gPlayers
[i
] = nil then continue
;
3463 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3466 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3467 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3472 OldLR
:= gLMSRespawn
;
3473 if (gGameSettings
.GameMode
= GM_COOP
) then
3477 // everyone is dead, restart the map
3478 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3480 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3481 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3482 gLMSRespawnTime
:= gTime
+ 5000;
3484 else if (a
= 1) then
3486 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3487 if (gPlayers
[k
] = gPlayer1
) or
3488 (gPlayers
[k
] = gPlayer2
) then
3489 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3490 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3491 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3494 else if (gGameSettings
.GameMode
= GM_TDM
) then
3496 if (ab
= 0) and (ar
<> 0) then
3499 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3501 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3502 Inc(gTeamStat
[TEAM_RED
].Goals
);
3503 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3504 gLMSRespawnTime
:= gTime
+ 5000;
3506 else if (ar
= 0) and (ab
<> 0) then
3509 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3511 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3512 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3513 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3514 gLMSRespawnTime
:= gTime
+ 5000;
3516 else if (ar
= 0) and (ab
= 0) then
3519 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3521 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3522 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3523 gLMSRespawnTime
:= gTime
+ 5000;
3526 else if (gGameSettings
.GameMode
= GM_DM
) then
3530 if gPlayers
[k
] <> nil then
3533 // survivor is the winner
3534 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3536 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3539 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3540 gLMSRespawnTime
:= gTime
+ 5000;
3542 else if (a
= 0) then
3544 // everyone is dead, restart the map
3545 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3547 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3548 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3549 gLMSRespawnTime
:= gTime
+ 5000;
3552 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3554 if NetMode
= NET_SERVER
then
3555 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3557 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3563 MH_SEND_PlayerStats(FUID
);
3564 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3565 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3568 if srv
and FNoRespawn
then Spectate(True);
3569 FWantsInGame
:= True;
3572 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3574 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3575 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3578 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3580 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3581 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3584 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3586 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3587 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3588 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3589 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3590 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3591 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3592 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3593 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3596 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3598 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3599 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3600 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3601 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3604 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3606 //if g_Game_IsClient then Exit;
3607 if Weapon
> High(FWeapon
) then Exit
;
3608 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3611 procedure TPlayer
.resetWeaponQueue ();
3614 FNextWeapDelay
:= 0;
3617 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3621 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3622 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
3623 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
3624 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3625 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3626 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3627 else result
:= (weapon
< length(FWeapon
));
3631 // return 255 for "no switch"
3632 function TPlayer
.getNextWeaponIndex (): Byte;
3635 wantThisWeapon
: array[0..64] of Boolean;
3636 weaponOrder
: array[0..16] of Integer; // value: index in `FWeapon`
3638 f
, dir
, cwi
, rwidx
, curlidx
: Integer;
3640 function real2log (ridx
: Integer): Integer;
3646 for f
:= 0 to High(weaponOrder
) do if (weaponOrder
[f
] = ridx
) then begin result
:= f
; exit
; end;
3652 result
:= 255; // default result: "no switch"
3654 // had weapon cycling on previous frame? remove that flag
3655 if (FNextWeap
and $2000) <> 0 then
3657 FNextWeap
:= FNextWeap
and $1FFF;
3658 FNextWeapDelay
:= 0;
3661 for f
:= 0 to High(weaponOrder
) do weaponOrder
[f
] := -1;
3663 // build weapon order (k8: i know, i know, learn how to do constants and such... gtfo, please!)
3664 // two knuckles are for "normal" and "berserk" (see `if` below -- it removes the one that is not needed)
3666 // bfg, launcher, plasma, flamethrower, ssg, minigun, sg, pistol, berserk, chainsaw, fist
3667 weaponOrder
[0] := WEAPON_SUPERPULEMET
;
3668 weaponOrder
[1] := WEAPON_BFG
;
3669 weaponOrder
[2] := WEAPON_ROCKETLAUNCHER
;
3670 weaponOrder
[3] := WEAPON_PLASMA
;
3671 weaponOrder
[4] := WEAPON_FLAMETHROWER
;
3672 weaponOrder
[5] := WEAPON_SHOTGUN2
;
3673 weaponOrder
[6] := WEAPON_CHAINGUN
;
3674 weaponOrder
[7] := WEAPON_SHOTGUN1
;
3675 weaponOrder
[8] := WEAPON_PISTOL
;
3676 weaponOrder
[9] := WEAPON_KASTET
+666; // berserk fist
3677 weaponOrder
[10] := WEAPON_SAW
;
3678 weaponOrder
[11] := WEAPON_KASTET
; // normal fist
3680 for f
:= 0 to High(weaponOrder
) do
3682 if (weaponOrder
[f
] = WEAPON_KASTET
) then
3684 // normal fist: remove if we have a berserk pack
3685 if (R_BERSERK
in FRulez
) then weaponOrder
[f
] := -1;
3688 if (weaponOrder
[f
] = WEAPON_KASTET
+666) then
3690 // berserk fist: remove if we don't have a berserk pack
3691 if (R_BERSERK
in FRulez
) then weaponOrder
[f
] := WEAPON_KASTET
else weaponOrder
[f
] := -1;
3699 WEAPON_SHOTGUN1 = 3;
3700 WEAPON_SHOTGUN2 = 4;
3701 WEAPON_CHAINGUN = 5;
3702 WEAPON_ROCKETLAUNCHER = 6;
3705 WEAPON_SUPERPULEMET = 9;
3706 WEAPON_FLAMETHROWER = 10;
3710 if (FNextWeap <> 0) or (FNextWeapDelay <> 0) then
3712 e_WriteLog(Format('!!! FNextWeap=%04x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), TMsgType.Warning);
3716 // cycling has priority
3717 if (FNextWeap
and $C000) <> 0 then
3719 if (FNextWeap
and $8000) <> 0 then dir
:= 1 else dir
:= -1; // should be reversed if we want "priority-driven cycling"
3720 FNextWeap
:= FNextWeap
or $2000; // we need this
3721 if FNextWeapDelay
> 0 then exit
; // cooldown time
3722 //cwi := real2log(FCurrWeap);
3723 //if (cwi < 0) then cwi := 0;
3725 for i
:= 0 to High(FWeapon
) do
3727 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3728 //rwidx := weaponOrder[cwi];
3729 rwidx
:= cwi
; // sorry
3730 if (rwidx
< 0) then continue
;
3731 if FWeapon
[rwidx
] then
3733 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d (dir=%d; log=%d)', [FCurrWeap, rwidx, dir, cwi]), TMsgType.Warning);
3734 result
:= Byte(rwidx
);
3735 //FNextWeapDelay := 10; //k8: not needed anymore
3744 for i
:= 0 to High(wantThisWeapon
) do wantThisWeapon
[i
] := false;
3747 curlidx
:= -1; // start from a weapon with a highest priority (-1, 'cause loop will immediately increment this index)
3749 for i
:= 0 to High(FWeapon
) do
3751 if (FNextWeap
and (1 shl i
)) <> 0 then
3756 wantThisWeapon
[cwi
] := true;
3758 // if we hit currently selected weapon, start seachring from it, so we'll get "next weaker" weapon
3759 if (i
= FCurrWeap
) then curlidx
:= cwi
; // compare real, start from logical
3764 // slow down alterations a little
3767 // more than one weapon requested, assume "alteration", and check alteration delay
3768 if FNextWeapDelay
> 0 then
3770 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), TMsgType.Warning);
3776 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3777 // but clear all counters if no weapon should be switched
3784 //e_WriteLog(Format('*** wwc=%d; currweap=%d; logweap=%d', [wwc, FCurrWeap, curlidx]), TMsgType.Warning);
3786 // find next weapon to switch onto
3788 for i
:= 0 to High(weaponOrder
) do
3790 cwi
:= (cwi
+length(weaponOrder
)+1) mod length(weaponOrder
);
3791 if (cwi
= curlidx
) then continue
; // skip current weapon
3792 if not wantThisWeapon
[cwi
] then continue
;
3793 rwidx
:= weaponOrder
[cwi
];
3794 if (rwidx
< 0) then continue
;
3795 //e_WriteLog(Format(' trying logical %d (real %d); has=%d, hasammo=%d', [cwi, rwidx, Integer(FWeapon[rwidx]), Integer(hasAmmoForWeapon(rwidx))]), TMsgType.Warning);
3796 if FWeapon
[rwidx
] and ((wwc
= 1) or hasAmmoForWeapon(rwidx
)) then
3798 //e_WriteLog(' I FOUND HER!', TMsgType.Warning);
3800 result
:= Byte(rwidx
);
3802 //FNextWeapDelay := 10; // anyway, 'cause why not; k8: not needed anymore
3807 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3811 procedure TPlayer
.RealizeCurrentWeapon();
3812 function switchAllowed (): Boolean;
3817 if FBFGFireCounter
<> -1 then
3819 if FTime
[T_SWITCH
] > gTime
then
3821 for i
:= WP_FIRST
to WP_LAST
do
3822 if FReloading
[i
] > 0 then
3830 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3831 //FNextWeap := FNextWeap and $1FFF;
3832 //HACK: alteration delay will be reset when player released any weapon switch key
3833 FNextWeapDelay
:= 0; //k8: just in case
3834 //if FNextWeapDelay > 0 then Dec(FNextWeapDelay); // "alteration delay"
3836 if not switchAllowed
then
3838 //writeln('WEAPON SWITCHING IS NOT ALLOWED! FBFGFireCounter=', FBFGFireCounter, '; gTime=', gTime, '; FTime[T_SWITCH]=', FTime[T_SWITCH]);
3839 //HACK for weapon cycling
3840 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3844 if (FNetForceWeapFIdx
>= gTime
+15) then FNetForceWeapFIdx
:= 0;
3846 nw
:= getNextWeaponIndex();
3847 if nw
= 255 then exit
; // don't reset anything here
3848 if nw
> High(FWeapon
) then
3850 // don't forget to reset queue here!
3851 //e_WriteLog(Format(' RealizeCurrentWeapon: WUTAFUUUU?! (%d)', [nw]), TMsgType.Warning);
3858 //k8: emulate this on client immediately, or wait for server confirmation?
3860 if g_Game_IsClient then
3862 FNetForceWeap := nw;
3863 //FNetForceWeapFIdx := FCurrFrameIdx+5; // force for ~5 frames
3864 FNetForceWeapFIdx := gTime+5; // force for ~5 frames
3865 writeln('NETWEAPONSWITCH: fw=', NetForceWeap, '; fwfidx=', NetForceWeapFIdx, '; cfrm=', gTime);
3868 FNetForceWeapFIdx
:= gTime
+5; // force for ~5 frames
3870 if nw
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3871 FModel
.SetWeapon(nw
);
3872 FTime
[T_SWITCH
] := gTime
+156;
3873 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3874 //if g_Game_IsNet and g_Game_IsClient then
3878 procedure TPlayer
.NextWeapon();
3880 //if g_Game_IsClient then Exit;
3884 procedure TPlayer
.PrevWeapon();
3886 //if g_Game_IsClient then Exit;
3890 // used by network layer
3891 procedure TPlayer
.SetWeapon(W
: Byte);
3893 if FCurrWeap
<> W
then
3894 if (W
= WEAPON_SAW
) then
3895 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3898 FModel
.SetWeapon(CurrWeap
);
3899 //if g_Game_IsClient then resetWeaponQueue();
3902 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3904 function allowBerserkSwitching (): Boolean;
3906 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3908 if gBerserkAutoswitch
then exit
;
3909 if not conIsCheatsEnabled
then exit
;
3917 if g_Game_IsClient
then Exit
;
3919 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3920 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3925 if FHealth
< PLAYER_HP_SOFT
then
3927 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3931 if gFlash
= 2 then Inc(FPickup
, 5);
3935 if FHealth
< PLAYER_HP_SOFT
then
3937 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3941 if gFlash
= 2 then Inc(FPickup
, 5);
3945 if FArmor
< PLAYER_AP_SOFT
then
3947 FArmor
:= PLAYER_AP_SOFT
;
3950 if gFlash
= 2 then Inc(FPickup
, 5);
3954 if FArmor
< PLAYER_AP_LIMIT
then
3956 FArmor
:= PLAYER_AP_LIMIT
;
3959 if gFlash
= 2 then Inc(FPickup
, 5);
3963 if FHealth
< PLAYER_HP_LIMIT
then
3965 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3969 if gFlash
= 2 then Inc(FPickup
, 5);
3973 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3975 if FHealth
< PLAYER_HP_LIMIT
then
3976 FHealth
:= PLAYER_HP_LIMIT
;
3977 if FArmor
< PLAYER_AP_LIMIT
then
3978 FArmor
:= PLAYER_AP_LIMIT
;
3982 if gFlash
= 2 then Inc(FPickup
, 5);
3986 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3988 FWeapon
[WEAPON_SAW
] := True;
3990 if gFlash
= 2 then Inc(FPickup
, 5);
3991 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3994 ITEM_WEAPON_SHOTGUN1
:
3995 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3997 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3998 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
4000 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4001 FWeapon
[WEAPON_SHOTGUN1
] := 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_SHOTGUN2
:
4008 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
4010 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
4012 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4013 FWeapon
[WEAPON_SHOTGUN2
] := True;
4015 if gFlash
= 2 then Inc(FPickup
, 5);
4016 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4019 ITEM_WEAPON_CHAINGUN
:
4020 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
4022 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
4024 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4025 FWeapon
[WEAPON_CHAINGUN
] := True;
4027 if gFlash
= 2 then Inc(FPickup
, 5);
4028 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4031 ITEM_WEAPON_ROCKETLAUNCHER
:
4032 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
4034 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
4036 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
4037 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
4039 if gFlash
= 2 then Inc(FPickup
, 5);
4040 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4044 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
4046 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
4048 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4049 FWeapon
[WEAPON_PLASMA
] := True;
4051 if gFlash
= 2 then Inc(FPickup
, 5);
4052 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4056 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
4058 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
4060 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4061 FWeapon
[WEAPON_BFG
] := True;
4063 if gFlash
= 2 then Inc(FPickup
, 5);
4064 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4067 ITEM_WEAPON_SUPERPULEMET
:
4068 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
4070 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
4072 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4073 FWeapon
[WEAPON_SUPERPULEMET
] := True;
4075 if gFlash
= 2 then Inc(FPickup
, 5);
4076 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4079 ITEM_WEAPON_FLAMETHROWER
:
4080 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
4082 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
4084 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4085 FWeapon
[WEAPON_FLAMETHROWER
] := True;
4087 if gFlash
= 2 then Inc(FPickup
, 5);
4088 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4092 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4094 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4097 if gFlash
= 2 then Inc(FPickup
, 5);
4100 ITEM_AMMO_BULLETS_BOX
:
4101 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4103 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4106 if gFlash
= 2 then Inc(FPickup
, 5);
4110 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4112 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4115 if gFlash
= 2 then Inc(FPickup
, 5);
4118 ITEM_AMMO_SHELLS_BOX
:
4119 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4121 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
4124 if gFlash
= 2 then Inc(FPickup
, 5);
4128 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4130 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4133 if gFlash
= 2 then Inc(FPickup
, 5);
4136 ITEM_AMMO_ROCKET_BOX
:
4137 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4139 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
4142 if gFlash
= 2 then Inc(FPickup
, 5);
4146 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4148 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4151 if gFlash
= 2 then Inc(FPickup
, 5);
4155 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4157 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4160 if gFlash
= 2 then Inc(FPickup
, 5);
4164 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4166 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4169 if gFlash
= 2 then Inc(FPickup
, 5);
4173 if not(R_ITEM_BACKPACK
in FRulez
) or
4174 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4175 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4176 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4177 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4178 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
4180 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4181 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4182 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4183 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4184 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4186 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4187 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4188 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4189 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4190 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4191 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4192 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4193 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4195 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
4198 if gFlash
= 2 then Inc(FPickup
, 5);
4202 if not(R_KEY_RED
in FRulez
) then
4204 Include(FRulez
, R_KEY_RED
);
4206 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4207 if gFlash
= 2 then Inc(FPickup
, 5);
4208 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4212 if not(R_KEY_GREEN
in FRulez
) then
4214 Include(FRulez
, R_KEY_GREEN
);
4216 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4217 if gFlash
= 2 then Inc(FPickup
, 5);
4218 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4222 if not(R_KEY_BLUE
in FRulez
) then
4224 Include(FRulez
, R_KEY_BLUE
);
4226 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4227 if gFlash
= 2 then Inc(FPickup
, 5);
4228 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4232 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4234 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4238 if gFlash
= 2 then Inc(FPickup
, 5);
4242 if FAir
< AIR_MAX
then
4247 if gFlash
= 2 then Inc(FPickup
, 5);
4252 if not (R_BERSERK
in FRulez
) then
4254 Include(FRulez
, R_BERSERK
);
4255 if allowBerserkSwitching
then
4257 FCurrWeap
:= WEAPON_KASTET
;
4258 //FNetForceWeap := FCurrWeap;
4260 FModel
.SetWeapon(WEAPON_KASTET
);
4265 if gFlash
= 2 then Inc(FPickup
, 5);
4267 FBerserk
:= gTime
+30000;
4271 //k8:do we need it? if g_Game_IsNet and g_Game_IsServer then MH_SEND_PlayerStats(FUID);
4273 if FHealth
< PLAYER_HP_SOFT
then
4275 FHealth
:= PLAYER_HP_SOFT
;
4276 FBerserk
:= gTime
+30000;
4284 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4286 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4289 if gFlash
= 2 then Inc(FPickup
, 5);
4293 if FHealth
< PLAYER_HP_LIMIT
then
4295 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4299 if gFlash
= 2 then Inc(FPickup
, 5);
4303 if FArmor
< PLAYER_AP_LIMIT
then
4305 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4308 if gFlash
= 2 then Inc(FPickup
, 5);
4312 if FJetFuel
< JET_MAX
then
4314 FJetFuel
:= JET_MAX
;
4317 if gFlash
= 2 then Inc(FPickup
, 5);
4321 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4323 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4326 if gFlash
= 2 then Inc(FPickup
, 5);
4331 procedure TPlayer
.Touch();
4335 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4338 // Áðîñèòü ôëàã òîâàðèùó:
4339 if gGameSettings
.GameMode
= GM_CTF
then
4344 procedure TPlayer
.Push(vx
, vy
: Integer);
4346 if (not FPhysics
) and FGhost
then
4348 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4349 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4350 if g_Game_IsNet
and g_Game_IsServer
then
4351 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4354 procedure TPlayer
.Reset(Force
: Boolean);
4362 FTime
[T_RESPAWN
] := 0;
4363 FTime
[T_FLAGCAP
] := 0;
4374 //FCurrFrameIdx := 0;
4375 //FNetForceWeap := FCurrWeap;
4376 FNetForceWeapFIdx
:= 0;
4380 FSpectator
:= False;
4383 FSpectatePlayer
:= -1;
4384 FNoRespawn
:= False;
4386 FLives
:= gGameSettings
.MaxLives
;
4388 FBFGFireCounter
:= -1;
4389 FTime
[T_SWITCH
] := 0;
4390 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := 0;
4395 procedure TPlayer
.SoftReset();
4403 FBFGFireCounter
:= -1;
4409 FNetForceWeapFIdx
:= 0;
4412 FBFGFireCounter
:= -1;
4413 FTime
[T_SWITCH
] := 0;
4414 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := 0;
4417 SetAction(A_STAND
, True);
4420 function TPlayer
.GetRespawnPoint(): Byte;
4425 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4427 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4428 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4430 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4432 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4433 if Self
= gPlayer1
then
4434 c
:= RESPAWNPOINT_PLAYER1
4436 c
:= RESPAWNPOINT_PLAYER2
;
4437 if g_Map_GetPointCount(c
) > 0 then
4443 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4444 if Self
= gPlayer1
then
4445 c
:= RESPAWNPOINT_PLAYER2
4447 c
:= RESPAWNPOINT_PLAYER1
;
4448 if g_Map_GetPointCount(c
) > 0 then
4455 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4456 if Random(2) = 0 then
4457 c
:= RESPAWNPOINT_PLAYER1
4459 c
:= RESPAWNPOINT_PLAYER2
;
4460 if g_Map_GetPointCount(c
) > 0 then
4467 // Òî÷êà ëþáîé èç êîìàíä
4468 if Random(2) = 0 then
4469 c
:= RESPAWNPOINT_RED
4471 c
:= RESPAWNPOINT_BLUE
;
4472 if g_Map_GetPointCount(c
) > 0 then
4479 c
:= RESPAWNPOINT_DM
;
4480 if g_Map_GetPointCount(c
) > 0 then
4488 if gGameSettings
.GameMode
= GM_DM
then
4491 c
:= RESPAWNPOINT_DM
;
4492 if g_Map_GetPointCount(c
) > 0 then
4498 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4499 if Random(2) = 0 then
4500 c
:= RESPAWNPOINT_PLAYER1
4502 c
:= RESPAWNPOINT_PLAYER2
;
4503 if g_Map_GetPointCount(c
) > 0 then
4509 // Òî÷êà ëþáîé èç êîìàíä
4510 if Random(2) = 0 then
4511 c
:= RESPAWNPOINT_RED
4513 c
:= RESPAWNPOINT_BLUE
;
4514 if g_Map_GetPointCount(c
) > 0 then
4522 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4524 // Òî÷êà ñâîåé êîìàíäû
4525 c
:= RESPAWNPOINT_DM
;
4526 if FTeam
= TEAM_RED
then
4527 c
:= RESPAWNPOINT_RED
;
4528 if FTeam
= TEAM_BLUE
then
4529 c
:= RESPAWNPOINT_BLUE
;
4530 if g_Map_GetPointCount(c
) > 0 then
4537 c
:= RESPAWNPOINT_DM
;
4538 if g_Map_GetPointCount(c
) > 0 then
4544 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4545 if Random(2) = 0 then
4546 c
:= RESPAWNPOINT_PLAYER1
4548 c
:= RESPAWNPOINT_PLAYER2
;
4549 if g_Map_GetPointCount(c
) > 0 then
4555 // Òî÷êà äðóãîé êîìàíäû
4556 c
:= RESPAWNPOINT_DM
;
4557 if FTeam
= TEAM_RED
then
4558 c
:= RESPAWNPOINT_BLUE
;
4559 if FTeam
= TEAM_BLUE
then
4560 c
:= RESPAWNPOINT_RED
;
4561 if g_Map_GetPointCount(c
) > 0 then
4569 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4571 RespawnPoint
: TRespawnPoint
;
4578 FBFGFireCounter
:= -1;
4582 //FNetForceWeap := FCurrWeap;
4583 FNetForceWeapFIdx
:= 0;
4586 FBFGFireCounter
:= -1;
4587 FTime
[T_SWITCH
] := 0;
4588 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := 0;
4590 if not g_Game_IsServer
then
4594 FWantsInGame
:= True;
4595 FJustTeleported
:= True;
4598 FTime
[T_RESPAWN
] := 0;
4602 // if server changes MaxLives we gotta be ready
4603 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4605 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4606 if FTime
[T_RESPAWN
] > gTime
then
4609 // Ïðîñðàë âñå æèçíè:
4612 if not FSpectator
then Spectate(True);
4613 FWantsInGame
:= True;
4617 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4618 begin // "Ñâîÿ èãðà"
4619 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4620 FRulez
:= FRulez
-[R_BERSERK
];
4622 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4624 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4625 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4628 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4629 c
:= GetRespawnPoint();
4634 // Âîñêðåøåíèå áåç îðóæèÿ:
4637 FHealth
:= PLAYER_HP_SOFT
;
4643 for a
:= WP_FIRST
to WP_LAST
do
4645 FWeapon
[a
] := False;
4649 FWeapon
[WEAPON_PISTOL
] := True;
4650 FWeapon
[WEAPON_KASTET
] := True;
4651 FCurrWeap
:= WEAPON_PISTOL
;
4652 //FNetForceWeap := FCurrWeap;
4653 FNetForceWeapFIdx
:= 0;
4656 FModel
.SetWeapon(FCurrWeap
);
4658 for b
:= A_BULLETS
to A_HIGH
do
4661 FAmmo
[A_BULLETS
] := 50;
4663 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4664 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4665 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4666 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4667 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4669 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4670 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4675 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4676 if not g_Map_GetPoint(c
, RespawnPoint
) then
4678 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4682 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4683 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4684 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4690 FDirection
:= RespawnPoint
.Direction
;
4691 if FDirection
= TDirection
.D_LEFT
then
4696 SetAction(A_STAND
, True);
4697 FModel
.Direction
:= FDirection
;
4699 for a
:= Low(FTime
) to High(FTime
) do
4702 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4707 FCanJetpack
:= False;
4712 // Àíèìàöèÿ âîçðîæäåíèÿ:
4713 if (not gLoadGameMode
) and (not Silent
) then
4714 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4716 Anim
:= TAnimation
.Create(ID
, False, 3);
4717 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4718 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4722 FSpectator
:= False;
4725 FSpectatePlayer
:= -1;
4728 if (gPlayer1
= nil) and (gLMSPID1
= FUID
) then
4730 if (gPlayer2
= nil) and (gLMSPID2
= FUID
) then
4733 //FNetForceWeap := FCurrWeap;
4735 if g_Game_IsNet
then
4737 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4738 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4740 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4741 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4746 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4749 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4750 else if (not NoMove
) then
4752 GameX
:= gMapInfo
.Width
div 2;
4753 GameY
:= gMapInfo
.Height
div 2;
4762 FWantsInGame
:= False;
4767 if Self
= gPlayer1
then
4772 if Self
= gPlayer2
then
4779 if g_Game_IsNet
then
4780 MH_SEND_PlayerStats(FUID
);
4783 procedure TPlayer
.SwitchNoClip
;
4787 FGhost
:= not FGhost
;
4788 FPhysics
:= not FGhost
;
4800 procedure TPlayer
.Run(Direction
: TDirection
);
4804 if MAX_RUNVEL
> 8 then
4808 if Direction
= TDirection
.D_LEFT
then
4810 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4811 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4814 if FObj
.Vel
.X
< MAX_RUNVEL
then
4815 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4817 // Âîçìîæíî, ïèíàåì êóñêè:
4818 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4820 b
:= Abs(FObj
.Vel
.X
);
4821 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4822 for a
:= 0 to High(gGibs
) do
4824 if gGibs
[a
].alive
and
4825 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4826 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4829 if FObj
.Vel
.X
< 0 then
4831 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4835 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4837 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4845 procedure TPlayer
.SeeDown();
4847 SetAction(A_SEEDOWN
);
4849 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4851 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4854 procedure TPlayer
.SeeUp();
4858 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4860 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4863 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4871 A_ATTACK
: Prior
:= 2;
4872 A_SEEUP
: Prior
:= 1;
4873 A_SEEDOWN
: Prior
:= 1;
4874 A_ATTACKUP
: Prior
:= 2;
4875 A_ATTACKDOWN
: Prior
:= 2;
4880 if (Prior
> FActionPrior
) or Force
then
4881 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4883 FActionPrior
:= Prior
;
4884 FActionAnim
:= Action
;
4885 FActionForce
:= Force
;
4886 FActionChanged
:= True;
4889 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4892 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4894 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4895 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4896 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4897 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4900 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4907 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4909 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4910 if g_Game_IsServer
and g_Game_IsNet
then
4911 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4915 FJustTeleported
:= True;
4920 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4922 Anim
:= TAnimation
.Create(ID
, False, 3);
4925 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4926 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4927 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4928 if g_Game_IsServer
and g_Game_IsNet
then
4929 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4930 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4934 FObj
.X
:= X
-PLAYER_RECT
.X
;
4935 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4936 if FAlive
and FGhost
then
4942 if not g_Game_IsNet
then
4946 SetDirection(TDirection
.D_LEFT
);
4952 SetDirection(TDirection
.D_RIGHT
);
4958 if FDirection
= TDirection
.D_RIGHT
then
4960 SetDirection(TDirection
.D_LEFT
);
4965 SetDirection(TDirection
.D_RIGHT
);
4971 if not silent
and (Anim
<> nil) then
4973 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4974 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4977 if g_Game_IsServer
and g_Game_IsNet
then
4978 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4979 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4986 function nonz(a
: Single): Single;
4994 function TPlayer
.followCorpse(): Boolean;
4999 if FAlive
or FSpectator
then
5001 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
5003 for i
:= 0 to High(gCorpses
) do
5004 if gCorpses
[i
] <> nil then
5005 if gCorpses
[i
].FPlayerUID
= FUID
then
5008 FObj
.X
:= gCorpses
[i
].FObj
.X
;
5009 FObj
.Y
:= gCorpses
[i
].FObj
.Y
;
5010 FObj
.Vel
.X
:= gCorpses
[i
].FObj
.Vel
.X
;
5011 FObj
.Vel
.Y
:= gCorpses
[i
].FObj
.Vel
.Y
;
5012 FObj
.Accel
.X
:= gCorpses
[i
].FObj
.Accel
.X
;
5013 FObj
.Accel
.Y
:= gCorpses
[i
].FObj
.Accel
.Y
;
5018 procedure TPlayer
.Update();
5021 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
5022 blockmon
, headwater
, dospawn
: Boolean;
5027 //Inc(FCurrFrameIdx);
5029 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
5030 AnyServer
:= g_Game_IsServer
;
5032 if g_Game_IsClient
and (NetInterpLevel
> 0) then
5033 DoLerp(NetInterpLevel
+ 1)
5040 if FClientID
>= 0 then
5042 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
5043 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
5044 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
5054 if FAlive
and (FPunchAnim
<> nil) then
5055 FPunchAnim
.Update();
5057 if FAlive
and (gFly
or FJetpack
) then
5060 if FDirection
= TDirection
.D_LEFT
then
5065 if FAlive
and (not FGhost
) then
5067 if FKeys
[KEY_UP
].Pressed
then
5069 if FKeys
[KEY_DOWN
].Pressed
then
5073 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
5076 i
:= g_basic
.Sign(FIncCam
);
5077 FIncCam
:= Abs(FIncCam
);
5078 DecMin(FIncCam
, 5, 0);
5079 FIncCam
:= FIncCam
*i
;
5082 // no need to do that each second frame, weapon queue will take care of it
5083 if FAlive
and FKeys
[KEY_NEXTWEAPON
].Pressed
{and AnyServer} then NextWeapon();
5084 if FAlive
and FKeys
[KEY_PREVWEAPON
].Pressed
{and AnyServer} then PrevWeapon();
5086 if gTime
mod (GAME_TICK
*2) <> 0 then
5088 if (FObj
.Vel
.X
= 0) and FAlive
then
5090 if FKeys
[KEY_LEFT
].Pressed
then
5091 Run(TDirection
.D_LEFT
);
5092 if FKeys
[KEY_RIGHT
].Pressed
then
5093 Run(TDirection
.D_RIGHT
);
5098 if not followCorpse() then
5099 g_Obj_Move(@FObj
, True, True, True);
5100 positionChanged(); // this updates spatial accelerators
5106 FActionChanged
:= False;
5110 // Let alive player do some actions
5111 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
5112 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
5113 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
5114 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
5115 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
5116 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
5117 if FKeys
[KEY_JUMP
].Pressed
then Jump()
5120 if AnyServer
and FJetpack
then
5124 if NetServer
then MH_SEND_PlayerStats(FUID
);
5126 FCanJetpack
:= True;
5133 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
5135 if FKeys
[k
].Pressed
then
5143 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5146 if (FTime
[T_RESPAWN
] <= gTime
) and
5147 gGameOn
and (not FAlive
) then
5149 if (g_Player_GetCount() > 1) then
5153 gExit
:= EXIT_RESTART
;
5158 // Dead spectator actions
5161 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
5162 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
5166 if (FSpectatePlayer
>= High(gPlayers
)) then
5167 FSpectatePlayer
:= -1
5171 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
5172 if gPlayers
[I
] <> nil then
5173 if gPlayers
[I
].alive
then
5174 if gPlayers
[I
].UID
<> FUID
then
5176 FSpectatePlayer
:= I
;
5181 if not SetSpect
then FSpectatePlayer
:= -1;
5192 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5194 FYTo
:= FObj
.Y
- 32;
5195 FSpectatePlayer
:= -1;
5197 if FKeys
[KEY_DOWN
].Pressed
then
5199 FYTo
:= FObj
.Y
+ 32;
5200 FSpectatePlayer
:= -1;
5202 if FKeys
[KEY_LEFT
].Pressed
then
5204 FXTo
:= FObj
.X
- 32;
5205 FSpectatePlayer
:= -1;
5207 if FKeys
[KEY_RIGHT
].Pressed
then
5209 FXTo
:= FObj
.X
+ 32;
5210 FSpectatePlayer
:= -1;
5213 if (FXTo
< -64) then
5215 else if (FXTo
> gMapInfo
.Width
+ 32) then
5216 FXTo
:= gMapInfo
.Width
+ 32;
5217 if (FYTo
< -72) then
5219 else if (FYTo
> gMapInfo
.Height
+ 32) then
5220 FYTo
:= gMapInfo
.Height
+ 32;
5225 if not followCorpse() then
5226 g_Obj_Move(@FObj
, True, True, True);
5227 positionChanged(); // this updates spatial accelerators
5234 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5235 if gPlayers
[FSpectatePlayer
] <> nil then
5236 if gPlayers
[FSpectatePlayer
].alive
then
5238 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
5239 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
5243 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5244 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5245 PANEL_BLOCKMON
, True);
5246 headwater
:= HeadInLiquid(0, 0);
5248 // Ñîïðîòèâëåíèå âîçäóõà:
5249 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5250 if FObj
.Vel
.X
<> 0 then
5251 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5253 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5254 DecMin(FPain
, 5, 0);
5255 DecMin(FPickup
, 1, 0);
5257 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5259 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5260 FMegaRulez
[MR_SUIT
] := 0;
5261 FMegaRulez
[MR_INVUL
] := 0;
5262 FMegaRulez
[MR_INVIS
] := 0;
5263 Kill(K_FALLKILL
, 0, HIT_FALL
);
5270 if FCurrWeap
= WEAPON_SAW
then
5271 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5272 FSawSoundSelect
.IsPlaying()) then
5273 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5276 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5277 (not FJetSoundOff
.IsPlaying()) then
5279 FJetSoundFly
.SetPosition(0);
5280 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5283 for b
:= WP_FIRST
to WP_LAST
do
5284 if FReloading
[b
] > 0 then
5290 if FShellTimer
> -1 then
5291 if FShellTimer
= 0 then
5293 if FShellType
= SHELL_SHELL
then
5294 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5295 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5296 else if FShellType
= SHELL_DBLSHELL
then
5298 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5299 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5300 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5301 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5304 end else Dec(FShellTimer
);
5306 if (FBFGFireCounter
> -1) then
5307 if FBFGFireCounter
= 0 then
5311 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5312 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5313 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5314 yd
:= wy
+firediry();
5315 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5316 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5317 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5318 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5319 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5322 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5323 FBFGFireCounter
:= -1;
5326 FBFGFireCounter
:= 0
5328 Dec(FBFGFireCounter
);
5330 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5332 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5334 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5337 if (headwater
or blockmon
) then
5343 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5346 else if (FAir
mod 31 = 0) and not blockmon
then
5348 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5349 if Random(2) = 0 then
5350 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5352 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5354 end else if FAir
< AIR_DEF
then
5357 if FFireTime
> 0 then
5359 if BodyInLiquid(0, 0) then
5364 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5366 if FMegaRulez
[MR_SUIT
] = gTime
then
5373 if FFirePainTime
<= 0 then
5375 if g_Game_IsServer
then
5376 Damage(5, FFireAttacker
, 0, 0, HIT_FLAME
);
5377 FFirePainTime
:= 18;
5379 FFirePainTime
:= FFirePainTime
- 1;
5380 FFireTime
:= FFireTime
- 1;
5381 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5382 MH_SEND_PlayerStats(FUID
);
5386 if FDamageBuffer
> 0 then
5388 if FDamageBuffer
>= 9 then
5392 if FDamageBuffer
< 30 then i
:= 9
5393 else if FDamageBuffer
< 100 then i
:= 18
5397 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5398 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5399 FHealth
:= FHealth
-ii
;
5402 FHealth
:= FHealth
+FArmor
;
5407 if FHealth
<= 0 then
5408 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5409 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5410 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5414 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5415 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5416 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5417 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5424 end; // if FAlive then ...
5426 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5428 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5429 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5430 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5431 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5433 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5434 then SetAction(A_STAND
, True);
5436 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5438 for b
:= Low(FKeys
) to High(FKeys
) do
5439 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5443 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5445 x
:= FObj
.X
+PLAYER_RECT
.X
;
5446 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5447 w
:= PLAYER_RECT
.Width
;
5448 h
:= PLAYER_RECT
.Height
;
5452 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5454 if (dx
<> 0) or (dy
<> 0) then
5463 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5465 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5466 FObj
.Y
+PLAYER_RECT
.Y
,
5473 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5475 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5476 FObj
.Y
+PLAYER_RECT
.Y
,
5480 Panel
.Width
, Panel
.Height
);
5483 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5485 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5486 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5487 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5488 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5491 function g_Player_ValidName(Name
: string): Boolean;
5497 if gPlayers
= nil then Exit
;
5499 for a
:= 0 to High(gPlayers
) do
5500 if gPlayers
[a
] <> nil then
5501 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5508 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5512 d
:= FModel
.Direction
;
5514 FModel
.Direction
:= Direction
;
5515 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5517 FDirection
:= Direction
;
5520 function TPlayer
.GetKeys(): Byte;
5524 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5525 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5526 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5528 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5529 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5532 procedure TPlayer
.Use();
5536 if FTime
[T_USE
] > gTime
then Exit
;
5538 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5539 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5541 for a
:= 0 to High(gPlayers
) do
5542 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5543 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5544 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5545 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5547 gPlayers
[a
].Touch();
5548 if g_Game_IsNet
and g_Game_IsServer
then
5549 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5552 FTime
[T_USE
] := gTime
+120;
5555 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5559 WX
, WY
, XD
, YD
: Integer;
5571 if R_BERSERK
in FRulez
then
5573 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5574 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5575 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5578 locobj
.rect
.Width
:= 39;
5579 locobj
.rect
.Height
:= 52;
5580 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5581 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5582 locobj
.Accel
.X
:= xd
-wx
;
5583 locobj
.Accel
.y
:= yd
-wy
;
5585 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5586 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5588 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5592 FPain
:= min(FPain
+ 25, 50);
5594 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5599 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5600 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5602 FSawSoundSelect
.Stop();
5604 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5606 else if not FSawSoundHit
.IsPlaying() then
5608 FSawSoundSelect
.Stop();
5609 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5616 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5617 FFireAngle
:= FAngle
;
5619 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5620 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5625 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5626 FFireAngle
:= FAngle
;
5629 FShellType
:= SHELL_SHELL
;
5634 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5635 FFireAngle
:= FAngle
;
5638 FShellType
:= SHELL_DBLSHELL
;
5643 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5644 FFireAngle
:= FAngle
;
5646 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5647 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5650 WEAPON_ROCKETLAUNCHER
:
5652 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5653 FFireAngle
:= FAngle
;
5659 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5660 FFireAngle
:= FAngle
;
5666 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5667 FFireAngle
:= FAngle
;
5671 WEAPON_SUPERPULEMET
:
5673 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5674 FFireAngle
:= FAngle
;
5676 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5677 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5680 WEAPON_FLAMETHROWER
:
5682 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5683 FFireAngle
:= FAngle
;
5690 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5691 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5692 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5695 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5697 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5698 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5701 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5705 if NetInterpLevel
< 1 then
5715 AX
:= Abs(FXTo
- FObj
.X
);
5716 AY
:= Abs(FYTo
- FObj
.Y
);
5717 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5719 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5724 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5726 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5727 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5728 PANEL_LIFTUP
, False) then Result
:= -1
5730 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5731 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5732 PANEL_LIFTDOWN
, False) then Result
:= 1
5736 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5743 if Flag
= FLAG_NONE
then
5746 if not g_Game_IsServer
then Exit
;
5748 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5749 if (Flag
= FTeam
) and
5750 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5751 (FFlag
<> FLAG_NONE
) then
5753 if FFlag
= FLAG_RED
then
5754 s
:= _lc
[I_PLAYER_FLAG_RED
]
5756 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5758 evtype
:= FLAG_STATE_SCORED
;
5760 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5761 Insert('.', ts
, Length(ts
) + 1 - 3);
5762 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5764 g_Map_ResetFlag(FFlag
);
5765 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5767 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5770 if g_Game_IsNet
then
5772 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5776 gFlags
[FFlag
].CaptureTime
:= 0;
5781 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5782 if (Flag
= FTeam
) and
5783 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5785 if Flag
= FLAG_RED
then
5786 s
:= _lc
[I_PLAYER_FLAG_RED
]
5788 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5790 evtype
:= FLAG_STATE_RETURNED
;
5791 gFlags
[Flag
].CaptureTime
:= 0;
5793 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5795 g_Map_ResetFlag(Flag
);
5796 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5799 if g_Game_IsNet
then
5801 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5807 // Ïîäîáðàë ÷óæîé ôëàã:
5808 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5812 if Flag
= FLAG_RED
then
5813 s
:= _lc
[I_PLAYER_FLAG_RED
]
5815 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5817 evtype
:= FLAG_STATE_CAPTURED
;
5819 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5821 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5823 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5826 if g_Game_IsNet
then
5828 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5834 procedure TPlayer
.SetFlag(Flag
: Byte);
5837 if FModel
<> nil then
5838 FModel
.SetFlag(FFlag
);
5841 function TPlayer
.DropFlag(): Boolean;
5846 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5848 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5849 with gFlags
[FFlag
] do
5853 Direction
:= FDirection
;
5854 State
:= FLAG_STATE_DROPPED
;
5856 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5857 (FObj
.Vel
.Y
div 2)-2+Random(5));
5858 positionChanged(); // this updates spatial accelerators
5860 if FFlag
= FLAG_RED
then
5861 s
:= _lc
[I_PLAYER_FLAG_RED
]
5863 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5865 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5866 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5868 if g_Game_IsNet
then
5869 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5875 procedure TPlayer
.GetSecret();
5880 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5882 Assert(Key
<= High(FKeys
));
5884 FKeys
[Key
].Pressed
:= True;
5885 FKeys
[Key
].Time
:= Time
;
5888 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5890 Result
:= FKeys
[K
].Pressed
;
5893 procedure TPlayer
.ReleaseKeys();
5897 for a
:= Low(FKeys
) to High(FKeys
) do
5899 FKeys
[a
].Pressed
:= False;
5904 procedure TPlayer
.ReleaseKeysNoWeapon();
5908 for a
:= Low(FKeys
) to High(FKeys
) do
5910 if (a
= KEY_PREVWEAPON
) or (a
= KEY_NEXTWEAPON
) then continue
;
5911 FKeys
[a
].Pressed
:= False;
5916 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5920 function TPlayer
.firediry(): Integer;
5922 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5923 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5927 procedure TPlayer
.RememberState();
5931 FSavedState
.Health
:= FHealth
;
5932 FSavedState
.Armor
:= FArmor
;
5933 FSavedState
.Air
:= FAir
;
5934 FSavedState
.JetFuel
:= FJetFuel
;
5935 FSavedState
.CurrWeap
:= FCurrWeap
;
5936 FSavedState
.NextWeap
:= FNextWeap
;
5937 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5940 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5942 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5944 FSavedState
.Rulez
:= FRulez
;
5945 FSavedState
.WaitRecall
:= True;
5948 procedure TPlayer
.RecallState();
5952 if not FSavedState
.WaitRecall
then Exit
;
5954 FHealth
:= FSavedState
.Health
;
5955 FArmor
:= FSavedState
.Armor
;
5956 FAir
:= FSavedState
.Air
;
5957 FJetFuel
:= FSavedState
.JetFuel
;
5958 FCurrWeap
:= FSavedState
.CurrWeap
;
5959 //FNetForceWeap := FCurrWeap;
5960 FNextWeap
:= FSavedState
.NextWeap
;
5961 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5964 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5966 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5968 FRulez
:= FSavedState
.Rulez
;
5969 FSavedState
.WaitRecall
:= False;
5971 if gGameSettings
.GameType
= GT_SERVER
then
5972 MH_SEND_PlayerStats(FUID
);
5975 procedure TPlayer
.SaveState (st
: TStream
);
5981 utils
.writeSign(st
, 'PLYR');
5982 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
5984 utils
.writeBool(st
, FIamBot
);
5986 utils
.writeInt(st
, Word(FUID
));
5988 utils
.writeStr(st
, FName
);
5990 utils
.writeInt(st
, Byte(FTeam
));
5992 utils
.writeBool(st
, FAlive
);
5993 // Èçðàñõîäîâàë ëè âñå æèçíè
5994 utils
.writeBool(st
, FNoRespawn
);
5996 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
5997 utils
.writeInt(st
, Byte(b
));
5999 utils
.writeInt(st
, LongInt(FHealth
));
6001 utils
.writeInt(st
, Byte(FLives
));
6003 utils
.writeInt(st
, LongInt(FArmor
));
6005 utils
.writeInt(st
, LongInt(FAir
));
6007 utils
.writeInt(st
, LongInt(FJetFuel
));
6009 utils
.writeInt(st
, LongInt(FPain
));
6011 utils
.writeInt(st
, LongInt(FKills
));
6013 utils
.writeInt(st
, LongInt(FMonsterKills
));
6015 utils
.writeInt(st
, LongInt(FFrags
));
6017 utils
.writeInt(st
, Byte(FFragCombo
));
6018 // Âðåìÿ ïîñëåäíåãî ôðàãà
6019 utils
.writeInt(st
, LongWord(FLastFrag
));
6021 utils
.writeInt(st
, LongInt(FDeath
));
6023 utils
.writeInt(st
, Byte(FFlag
));
6025 utils
.writeInt(st
, LongInt(FSecrets
));
6027 utils
.writeInt(st
, Byte(FCurrWeap
));
6029 utils
.writeInt(st
, Word(FNextWeap
));
6031 utils
.writeInt(st
, Byte(FNextWeapDelay
));
6032 // Âðåìÿ çàðÿäêè BFG
6033 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
6035 utils
.writeInt(st
, LongInt(FDamageBuffer
));
6036 // Ïîñëåäíèé óäàðèâøèé
6037 utils
.writeInt(st
, Word(FLastSpawnerUID
));
6038 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6039 utils
.writeInt(st
, Byte(FLastHit
));
6041 Obj_SaveState(st
, @FObj
);
6042 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6043 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
6044 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6045 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
6047 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
6048 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6049 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
6051 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
6052 // Íàëè÷èå êðàñíîãî êëþ÷à
6053 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
6054 // Íàëè÷èå çåëåíîãî êëþ÷à
6055 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
6056 // Íàëè÷èå ñèíåãî êëþ÷à
6057 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
6059 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
6060 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6061 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
6062 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6063 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
6065 utils
.writeStr(st
, FModel
.Name
);
6067 utils
.writeInt(st
, Byte(FColor
.R
));
6068 utils
.writeInt(st
, Byte(FColor
.G
));
6069 utils
.writeInt(st
, Byte(FColor
.B
));
6073 procedure TPlayer
.LoadState (st
: TStream
);
6082 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
6083 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
6085 FIamBot
:= utils
.readBool(st
);
6087 FUID
:= utils
.readWord(st
);
6089 str
:= utils
.readStr(st
);
6090 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
6092 FTeam
:= utils
.readByte(st
);
6094 FAlive
:= utils
.readBool(st
);
6095 // Èçðàñõîäîâàë ëè âñå æèçíè
6096 FNoRespawn
:= utils
.readBool(st
);
6098 b
:= utils
.readByte(st
);
6099 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
6101 FHealth
:= utils
.readLongInt(st
);
6103 FLives
:= utils
.readByte(st
);
6105 FArmor
:= utils
.readLongInt(st
);
6107 FAir
:= utils
.readLongInt(st
);
6109 FJetFuel
:= utils
.readLongInt(st
);
6111 FPain
:= utils
.readLongInt(st
);
6113 FKills
:= utils
.readLongInt(st
);
6115 FMonsterKills
:= utils
.readLongInt(st
);
6117 FFrags
:= utils
.readLongInt(st
);
6119 FFragCombo
:= utils
.readByte(st
);
6120 // Âðåìÿ ïîñëåäíåãî ôðàãà
6121 FLastFrag
:= utils
.readLongWord(st
);
6123 FDeath
:= utils
.readLongInt(st
);
6125 FFlag
:= utils
.readByte(st
);
6127 FSecrets
:= utils
.readLongInt(st
);
6129 FCurrWeap
:= utils
.readByte(st
);
6130 //FNetForceWeap := FCurrWeap;
6132 FNextWeap
:= utils
.readWord(st
);
6134 FNextWeapDelay
:= utils
.readByte(st
);
6135 // Âðåìÿ çàðÿäêè BFG
6136 FBFGFireCounter
:= utils
.readSmallInt(st
);
6138 FDamageBuffer
:= utils
.readLongInt(st
);
6139 // Ïîñëåäíèé óäàðèâøèé
6140 FLastSpawnerUID
:= utils
.readWord(st
);
6141 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6142 FLastHit
:= utils
.readByte(st
);
6144 Obj_LoadState(@FObj
, st
);
6145 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6146 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
6147 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6148 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
6150 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
6151 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6152 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
6154 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
6155 // Íàëè÷èå êðàñíîãî êëþ÷à
6156 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
6157 // Íàëè÷èå çåëåíîãî êëþ÷à
6158 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
6159 // Íàëè÷èå ñèíåãî êëþ÷à
6160 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
6162 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
6163 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6164 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
6165 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6166 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
6168 str
:= utils
.readStr(st
);
6170 FColor
.R
:= utils
.readByte(st
);
6171 FColor
.G
:= utils
.readByte(st
);
6172 FColor
.B
:= utils
.readByte(st
);
6173 if (self
= gPlayer1
) then
6175 str
:= gPlayer1Settings
.Model
;
6176 FColor
:= gPlayer1Settings
.Color
;
6178 else if (self
= gPlayer2
) then
6180 str
:= gPlayer2Settings
.Model
;
6181 FColor
:= gPlayer2Settings
.Color
;
6183 // Îáíîâëÿåì ìîäåëü èãðîêà
6185 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
6186 FModel
.Color
:= TEAMCOLOR
[FTeam
]
6188 FModel
.Color
:= FColor
;
6192 procedure TPlayer
.AllRulez(Health
: Boolean);
6198 FHealth
:= PLAYER_HP_LIMIT
;
6199 FArmor
:= PLAYER_AP_LIMIT
;
6203 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
6204 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
6205 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6208 procedure TPlayer
.RestoreHealthArmor();
6210 FHealth
:= PLAYER_HP_LIMIT
;
6211 FArmor
:= PLAYER_AP_LIMIT
;
6214 procedure TPlayer
.FragCombo();
6218 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6220 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6222 if FFragCombo
< 5 then
6224 Param
:= FUID
or (FFragCombo
shl 16);
6225 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6226 (FComboEvnt
<= High(gDelayedEvents
)) and
6227 gDelayedEvents
[FComboEvnt
].Pending
and
6228 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6229 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6231 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6232 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6235 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6243 procedure TPlayer
.GiveItem(ItemType
: Byte);
6247 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6249 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6253 if FAir
< AIR_MAX
then
6260 if not (R_BERSERK
in FRulez
) then
6262 Include(FRulez
, R_BERSERK
);
6263 if FBFGFireCounter
< 1 then
6265 FCurrWeap
:= WEAPON_KASTET
;
6266 //FNetForceWeap := FCurrWeap;
6267 FNetForceWeapFIdx
:= 0;
6269 FModel
.SetWeapon(WEAPON_KASTET
);
6273 FBerserk
:= gTime
+30000;
6275 if FHealth
< PLAYER_HP_SOFT
then
6277 FHealth
:= PLAYER_HP_SOFT
;
6278 FBerserk
:= gTime
+30000;
6283 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6285 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6289 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6291 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6295 if FJetFuel
< JET_MAX
then
6297 FJetFuel
:= JET_MAX
;
6300 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6301 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6303 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6304 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6306 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6308 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6310 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6311 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6314 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6315 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6316 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6317 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6318 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6319 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6320 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6321 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6322 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6324 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6325 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6326 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6327 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6328 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6329 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6330 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6331 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6332 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6335 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6336 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6337 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6338 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6339 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6341 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6342 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6343 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6344 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6345 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6347 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6348 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6349 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6350 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6352 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6355 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6356 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6357 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6359 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6360 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6365 if g_Game_IsNet
and g_Game_IsServer
then
6366 MH_SEND_PlayerStats(FUID
);
6369 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6374 if (Random(5) = 1) and (Times
= 1) then
6377 if BodyInLiquid(0, 0) then
6379 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6380 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6381 if Random(2) = 0 then
6382 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6384 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6388 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6390 for i
:= 1 to Times
do
6392 Anim
:= TAnimation
.Create(id
, False, 3);
6394 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6395 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6401 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6406 if (Random(10) = 1) and (Times
= 1) then
6409 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6411 for i
:= 1 to Times
do
6413 Anim
:= TAnimation
.Create(id
, False, 3);
6415 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6416 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6422 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6424 FSawSound
.Pause(Enable
);
6425 FSawSoundIdle
.Pause(Enable
);
6426 FSawSoundHit
.Pause(Enable
);
6427 FSawSoundSelect
.Pause(Enable
);
6432 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6437 FObj
.Rect
:= PLAYER_CORPSERECT
;
6438 FModelName
:= ModelName
;
6443 FState
:= CORPSE_STATE_MESS
;
6444 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6448 FState
:= CORPSE_STATE_NORMAL
;
6449 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6453 destructor TCorpse
.Destroy();
6460 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6462 procedure TCorpse
.positionChanged (); inline; begin end;
6464 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6466 if (dx
<> 0) or (dy
<> 0) then
6475 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6477 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6478 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6479 w
:= PLAYER_CORPSERECT
.Width
;
6480 h
:= PLAYER_CORPSERECT
.Height
;
6484 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6489 if FState
= CORPSE_STATE_REMOVEME
then
6492 FDamage
:= FDamage
+ Value
;
6494 if FDamage
> 150 then
6496 if FAnimation
<> nil then
6501 FState
:= CORPSE_STATE_REMOVEME
;
6503 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6504 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6505 FModelName
, FColor
);
6506 // Çâóê ìÿñà îò òðóïà:
6507 pm
:= g_PlayerModel_Get(FModelName
);
6508 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6512 if (gBodyKillEvent
<> -1)
6513 and gDelayedEvents
[gBodyKillEvent
].Pending
then
6514 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
6515 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, 0);
6520 Blood
:= g_PlayerModel_GetBlood(FModelName
);
6521 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6522 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6523 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6524 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6525 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6526 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
6530 procedure TCorpse
.Draw();
6532 if FState
= CORPSE_STATE_REMOVEME
then
6535 if FAnimation
<> nil then
6536 FAnimation
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6538 if FAnimationMask
<> nil then
6541 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6548 procedure TCorpse
.Update();
6552 if FState
= CORPSE_STATE_REMOVEME
then
6555 if gTime
mod (GAME_TICK
*2) <> 0 then
6557 g_Obj_Move(@FObj
, True, True, True);
6558 positionChanged(); // this updates spatial accelerators
6562 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6563 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6565 st
:= g_Obj_Move(@FObj
, True, True, True);
6566 positionChanged(); // this updates spatial accelerators
6568 if WordBool(st
and MOVE_FALLOUT
) then
6570 FState
:= CORPSE_STATE_REMOVEME
;
6574 if FAnimation
<> nil then
6575 FAnimation
.Update();
6576 if FAnimationMask
<> nil then
6577 FAnimationMask
.Update();
6581 procedure TCorpse
.SaveState (st
: TStream
);
6588 utils
.writeSign(st
, 'CORP');
6589 utils
.writeInt(st
, Byte(0));
6591 utils
.writeInt(st
, Byte(FState
));
6593 utils
.writeInt(st
, Byte(FDamage
));
6595 utils
.writeInt(st
, Byte(FColor
.R
));
6596 utils
.writeInt(st
, Byte(FColor
.G
));
6597 utils
.writeInt(st
, Byte(FColor
.B
));
6599 Obj_SaveState(st
, @FObj
);
6600 utils
.writeInt(st
, Word(FPlayerUID
));
6602 anim
:= (FAnimation
<> nil);
6603 utils
.writeBool(st
, anim
);
6604 // Åñëè åñòü - ñîõðàíÿåì
6605 if anim
then FAnimation
.SaveState(st
);
6606 // Åñòü ëè ìàñêà àíèìàöèè
6607 anim
:= (FAnimationMask
<> nil);
6608 utils
.writeBool(st
, anim
);
6609 // Åñëè åñòü - ñîõðàíÿåì
6610 if anim
then FAnimationMask
.SaveState(st
);
6614 procedure TCorpse
.LoadState (st
: TStream
);
6621 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6622 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6624 FState
:= utils
.readByte(st
);
6626 FDamage
:= utils
.readByte(st
);
6628 FColor
.R
:= utils
.readByte(st
);
6629 FColor
.G
:= utils
.readByte(st
);
6630 FColor
.B
:= utils
.readByte(st
);
6632 Obj_LoadState(@FObj
, st
);
6633 FPlayerUID
:= utils
.readWord(st
);
6635 anim
:= utils
.readBool(st
);
6636 // Åñëè åñòü - çàãðóæàåì
6639 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6640 FAnimation
.LoadState(st
);
6642 // Åñòü ëè ìàñêà àíèìàöèè
6643 anim
:= utils
.readBool(st
);
6644 // Åñëè åñòü - çàãðóæàåì
6647 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6648 FAnimationMask
.LoadState(st
);
6654 constructor TBot
.Create();
6661 FSpectator
:= False;
6668 for a
:= WP_FIRST
to WP_LAST
do
6670 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6671 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6672 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6676 destructor TBot
.Destroy();
6679 inherited Destroy();
6682 procedure TBot
.Draw();
6686 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6687 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6690 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6692 inherited Respawn(Silent
, Force
);
6695 FSelectedWeapon
:= FCurrWeap
;
6696 FNetForceWeapFIdx
:= 0;
6701 procedure TBot
.UpdateCombat();
6714 TTargetRecord
= array of TTarget
;
6716 function Compare(a
, b
: TTarget
): Integer;
6718 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6721 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6723 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6724 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6726 if a
.Dist
> b
.Dist
then // B áëèæå
6728 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6731 else // Ñòðàííî -> A
6736 a
, x1
, y1
, x2
, y2
: Integer;
6737 targets
: TTargetRecord
;
6739 Target
, BestTarget
: TTarget
;
6740 firew
, fireh
: Integer;
6744 vsPlayer
, vsMonster
, ok
: Boolean;
6747 function monsUpdate (mon
: TMonster
): Boolean;
6749 result
:= false; // don't stop
6750 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6752 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6754 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6755 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6757 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6758 if g_TraceVector(x1
, y1
, x2
, y2
) then
6760 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6761 SetLength(targets
, Length(targets
)+1);
6762 with targets
[High(targets
)] do
6769 Rect
:= mon
.Obj
.Rect
;
6770 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6771 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6772 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6781 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6782 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6784 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6785 if FCurrWeap
<> FSelectedWeapon
then
6788 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6789 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6791 RemoveAIFlag('NEEDFIRE');
6794 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6795 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6796 else PressKey(KEY_FIRE
);
6800 // Êîîðäèíàòû ñòâîëà:
6801 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6802 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6804 Target
.UID
:= FTargetUID
;
6807 if Target
.UID
<> 0 then
6808 begin // Öåëü åñòü - íàñòðàèâàåì
6809 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6812 tpla
:= g_Player_Get(Target
.UID
);
6816 if (@FObj
) <> nil then
6823 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6824 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6825 Target
.Rect
:= PLAYER_RECT
;
6826 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6827 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6828 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6829 Target
.IsPlayer
:= True;
6833 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6836 mon
:= g_Monsters_ByUID(Target
.UID
);
6839 Target
.X
:= mon
.Obj
.X
;
6840 Target
.Y
:= mon
.Obj
.Y
;
6842 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6843 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6844 Target
.Rect
:= mon
.Obj
.Rect
;
6845 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6846 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6847 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6848 Target
.IsPlayer
:= False;
6855 begin // Öåëè íåò - îáíóëÿåì
6860 Target
.Visible
:= False;
6861 Target
.Line
:= False;
6862 Target
.IsPlayer
:= False;
6867 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6868 if (not Target
.Line
) or (not Target
.Visible
) then
6872 for a
:= 0 to High(gPlayers
) do
6873 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6874 (gPlayers
[a
].FUID
<> FUID
) and
6875 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6876 (not gPlayers
[a
].NoTarget
) and
6877 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6879 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6880 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6883 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6884 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6886 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6887 if g_TraceVector(x1
, y1
, x2
, y2
) then
6889 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6890 SetLength(targets
, Length(targets
)+1);
6891 with targets
[High(targets
)] do
6893 UID
:= gPlayers
[a
].FUID
;
6894 X
:= gPlayers
[a
].FObj
.X
;
6895 Y
:= gPlayers
[a
].FObj
.Y
;
6898 Rect
:= PLAYER_RECT
;
6899 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6900 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6901 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6909 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6912 // Åñëè åñòü âîçìîæíûå öåëè:
6913 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6914 if targets
<> nil then
6916 // Âûáèðàåì íàèëó÷øóþ öåëü:
6917 BestTarget
:= targets
[0];
6918 if Length(targets
) > 1 then
6919 for a
:= 1 to High(targets
) do
6920 if Compare(BestTarget
, targets
[a
]) = 1 then
6921 BestTarget
:= targets
[a
];
6923 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6924 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6925 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6927 Target
:= BestTarget
;
6929 if (Healthy() = 3) or ((Healthy() = 2)) then
6930 begin // Åñëè çäîðîâû - äîãîíÿåì
6931 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6932 SetAIFlag('GORIGHT', '1');
6933 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6934 SetAIFlag('GOLEFT', '1');
6937 begin // Åñëè ïîáèòû - óáåãàåì
6938 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6939 SetAIFlag('GORIGHT', '1');
6940 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6941 SetAIFlag('GOLEFT', '1');
6944 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6945 SelectWeapon(Abs(x1
-Target
.cX
));
6950 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6951 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6952 if Target
.UID
<> 0 then
6954 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6955 Target
.Y
+ Target
.Rect
.Y
) then
6956 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6957 if (Healthy() = 3) or ((Healthy() = 2)) then
6958 begin // Åñëè çäîðîâû - äîãîíÿåì
6959 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6960 SetAIFlag('GORIGHT', '1');
6961 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6962 SetAIFlag('GOLEFT', '1');
6965 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6967 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6968 SetAIFlag('GORIGHT', '1');
6969 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6970 SetAIFlag('GOLEFT', '1');
6974 begin // Öåëü ïîêà íà "ýêðàíå"
6975 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6976 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6977 FLastVisible
:= gTime
;
6978 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6979 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6981 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6982 SetAIFlag('GORIGHT', '1');
6983 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6984 SetAIFlag('GOLEFT', '1');
6988 // Âûáèðàåì óãîë ââåðõ:
6989 if FDirection
= TDirection
.D_LEFT
then
6990 angle
:= ANGLE_LEFTUP
6992 angle
:= ANGLE_RIGHTUP
;
6994 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6995 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6997 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6998 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6999 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
7000 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7001 Target
.Rect
.Width
, Target
.Rect
.Height
) and
7002 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7003 begin // òî íóæíî ñòðåëÿòü ââåðõ
7004 SetAIFlag('NEEDFIRE', '1');
7005 SetAIFlag('NEEDSEEUP', '1');
7008 // Âûáèðàåì óãîë âíèç:
7009 if FDirection
= TDirection
.D_LEFT
then
7010 angle
:= ANGLE_LEFTDOWN
7012 angle
:= ANGLE_RIGHTDOWN
;
7014 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7015 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7017 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7018 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7019 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7020 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7021 Target
.Rect
.Width
, Target
.Rect
.Height
) and
7022 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7023 begin // òî íóæíî ñòðåëÿòü âíèç
7024 SetAIFlag('NEEDFIRE', '1');
7025 SetAIFlag('NEEDSEEDOWN', '1');
7028 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
7029 if Target
.Visible
and
7030 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
7031 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
7033 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
7034 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
7035 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
7036 begin // òî íóæíî ñòðåëÿòü âïåðåä
7037 SetAIFlag('NEEDFIRE', '1');
7038 SetAIFlag('NEEDSEEDOWN', '');
7039 SetAIFlag('NEEDSEEUP', '');
7041 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
7042 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
7043 if GetRnd(FDifficult
.CloseJump
) then
7044 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
7045 if Abs(FObj
.X
-Target
.X
) < 128 then
7049 if Random(a
) = 0 then
7050 SetAIFlag('NEEDJUMP', '1');
7054 // Åñëè öåëü âñå åùå åñòü:
7055 if Target
.UID
<> 0 then
7056 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
7057 Target
.UID
:= 0 // òî çàáûòü öåëü
7058 else // Åñëè âèäåëè íåäàâíî
7059 begin // íî öåëü óáèëè
7060 if Target
.IsPlayer
then
7061 begin // Öåëü - èãðîê
7062 pla
:= g_Player_Get(Target
.UID
);
7063 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
7064 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
7065 Target
.UID
:= 0; // òî çàáûòü öåëü
7068 begin // Öåëü - ìîíñòð
7069 mon
:= g_Monsters_ByUID(Target
.UID
);
7070 if (mon
= nil) or (not mon
.alive
) then
7071 Target
.UID
:= 0; // òî çàáûòü öåëü
7074 end; // if Target.UID <> 0
7076 FTargetUID
:= Target
.UID
;
7078 // Åñëè âîçìîæíûõ öåëåé íåò:
7079 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
7080 if targets
= nil then
7081 if GetAIFlag('ATTACKLEFT') <> '' then
7082 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
7083 RemoveAIFlag('ATTACKLEFT');
7085 SetAIFlag('NEEDJUMP', '1');
7087 if RunDirection() = TDirection
.D_RIGHT
then
7088 begin // Èäåì íå â òó ñòîðîíó
7089 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7090 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
7091 SetAIFlag('NEEDFIRE', '1');
7092 SetAIFlag('GOLEFT', '1');
7096 begin // Èäåì â íóæíóþ ñòîðîíó
7097 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7098 SetAIFlag('NEEDFIRE', '1');
7099 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7100 SetAIFlag('GORIGHT', '1');
7104 if GetAIFlag('ATTACKRIGHT') <> '' then
7105 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
7106 RemoveAIFlag('ATTACKRIGHT');
7108 SetAIFlag('NEEDJUMP', '1');
7110 if RunDirection() = TDirection
.D_LEFT
then
7111 begin // Èäåì íå â òó ñòîðîíó
7112 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7113 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
7114 SetAIFlag('NEEDFIRE', '1');
7115 SetAIFlag('GORIGHT', '1');
7120 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7121 SetAIFlag('NEEDFIRE', '1');
7122 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7123 SetAIFlag('GOLEFT', '1');
7127 //HACK! (does it belong there?)
7128 RealizeCurrentWeapon();
7130 // Åñëè åñòü âîçìîæíûå öåëè:
7131 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7132 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7133 for a
:= 0 to High(targets
) do
7135 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7136 if GetRnd(FDifficult
.DiagFire
) then
7138 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7139 if FDirection
= TDirection
.D_LEFT
then
7140 angle
:= ANGLE_LEFTUP
7142 angle
:= ANGLE_RIGHTUP
;
7144 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7145 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7147 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7148 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7149 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7150 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7151 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7153 SetAIFlag('NEEDFIRE', '1');
7154 SetAIFlag('NEEDSEEUP', '1');
7157 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7158 if FDirection
= TDirection
.D_LEFT
then
7159 angle
:= ANGLE_LEFTDOWN
7161 angle
:= ANGLE_RIGHTDOWN
;
7163 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7164 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7166 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7167 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7168 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7169 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7170 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7172 SetAIFlag('NEEDFIRE', '1');
7173 SetAIFlag('NEEDSEEDOWN', '1');
7177 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7178 if targets
[a
].Line
and targets
[a
].Visible
and
7179 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
7180 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
7182 SetAIFlag('NEEDFIRE', '1');
7187 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7188 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
7189 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
7190 40+GetInterval(FDifficult
.Cover
, 40)) then
7191 SetAIFlag('NEEDJUMP', '1');
7193 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7194 ammo
:= GetAmmoByWeapon(FCurrWeap
);
7195 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
7196 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
7198 SetAIFlag('SELECTWEAPON', '1');
7200 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7201 if GetAIFlag('SELECTWEAPON') = '1' then
7204 RemoveAIFlag('SELECTWEAPON');
7208 procedure TBot
.Update();
7221 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7222 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7224 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7226 if g_debug_BotAIOff
= 3 then
7236 RealizeCurrentWeapon();
7243 procedure TBot
.ReleaseKey(Key
: Byte);
7252 function TBot
.KeyPressed(Key
: Word): Boolean;
7254 Result
:= FKeys
[Key
].Pressed
;
7257 function TBot
.GetAIFlag(aName
: String20
): String20
;
7263 aName
:= LowerCase(aName
);
7265 if FAIFlags
<> nil then
7266 for a
:= 0 to High(FAIFlags
) do
7267 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7269 Result
:= FAIFlags
[a
].Value
;
7274 procedure TBot
.RemoveAIFlag(aName
: String20
);
7278 if FAIFlags
= nil then Exit
;
7280 aName
:= LowerCase(aName
);
7282 for a
:= 0 to High(FAIFlags
) do
7283 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7285 if a
<> High(FAIFlags
) then
7286 for b
:= a
to High(FAIFlags
)-1 do
7287 FAIFlags
[b
] := FAIFlags
[b
+1];
7289 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7294 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7302 aName
:= LowerCase(aName
);
7304 if FAIFlags
<> nil then
7305 for a
:= 0 to High(FAIFlags
) do
7306 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7312 if ok
then FAIFlags
[a
].Value
:= fValue
7315 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7316 with FAIFlags
[High(FAIFlags
)] do
7324 procedure TBot
.UpdateMove
;
7326 procedure GoLeft(Time
: Word = 1);
7328 ReleaseKey(KEY_LEFT
);
7329 ReleaseKey(KEY_RIGHT
);
7330 PressKey(KEY_LEFT
, Time
);
7331 SetDirection(TDirection
.D_LEFT
);
7334 procedure GoRight(Time
: Word = 1);
7336 ReleaseKey(KEY_LEFT
);
7337 ReleaseKey(KEY_RIGHT
);
7338 PressKey(KEY_RIGHT
, Time
);
7339 SetDirection(TDirection
.D_RIGHT
);
7342 function Rnd(a
: Word): Boolean;
7344 Result
:= Random(a
) = 0;
7347 procedure Turn(Time
: Word = 1200);
7349 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7354 ReleaseKey(KEY_LEFT
);
7355 ReleaseKey(KEY_RIGHT
);
7358 function CanRunLeft(): Boolean;
7360 Result
:= not CollideLevel(-1, 0);
7363 function CanRunRight(): Boolean;
7365 Result
:= not CollideLevel(1, 0);
7368 function CanRun(): Boolean;
7370 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7373 procedure Jump(Time
: Word = 30);
7375 PressKey(KEY_JUMP
, Time
);
7378 function NearHole(): Boolean;
7382 { TODO 5 : Ëåñòíèöû }
7383 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7384 for x
:= 1 to PLAYER_RECT
.Width
do
7385 if (not StayOnStep(x
*sx
, 0)) and
7386 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7387 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7396 function BorderHole(): Boolean;
7400 { TODO 5 : Ëåñòíèöû }
7401 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7402 for x
:= 1 to PLAYER_RECT
.Width
do
7403 if (not StayOnStep(x
*sx
, 0)) and
7404 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7405 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7407 for xx
:= x
to x
+32 do
7408 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7418 function NearDeepHole(): Boolean;
7424 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7427 for x
:= 1 to PLAYER_RECT
.Width
do
7428 if (not StayOnStep(x
*sx
, 0)) and
7429 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7430 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7432 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7434 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7439 end else Result
:= False;
7442 function OverDeepHole(): Boolean;
7449 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7451 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7458 function OnGround(): Boolean;
7460 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7463 function OnLadder(): Boolean;
7465 Result
:= FullInStep(0, 0);
7468 function BelowLadder(): Boolean;
7470 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7471 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7472 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7473 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7476 function BelowLiftUp(): Boolean;
7478 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7479 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7480 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7481 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7484 function OnTopLift(): Boolean;
7486 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7489 function CanJumpOver(): Boolean;
7493 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7497 if not CollideLevel(sx
, 0) then Exit
;
7499 for y
:= 1 to BOT_MAXJUMP
do
7500 if CollideLevel(0, -y
) then Exit
else
7501 if not CollideLevel(sx
, -y
) then
7508 function CanJumpUp(Dist
: ShortInt): Boolean;
7515 if CollideLevel(Dist
, 0) then Exit
;
7518 for y
:= 0 to BOT_MAXJUMP
do
7519 if CollideLevel(Dist
, -y
) then
7528 for yy
:= y
+1 to BOT_MAXJUMP
do
7529 if not CollideLevel(Dist
, -yy
) then
7538 for y
:= 0 to BOT_MAXJUMP
do
7539 if CollideLevel(0, -y
) then
7547 if y
< yy
then Exit
;
7552 function IsSafeTrigger(): Boolean;
7557 if gTriggers
= nil then
7559 for a
:= 0 to High(gTriggers
) do
7560 if Collide(gTriggers
[a
].X
,
7563 gTriggers
[a
].Height
) and
7564 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7565 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7566 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7567 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7568 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7573 // Âîçìîæíî, íàæèìàåì êíîïêó:
7574 if Rnd(16) and IsSafeTrigger() then
7577 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7578 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7580 ReleaseKey(KEY_LEFT
);
7581 ReleaseKey(KEY_RIGHT
);
7585 // Èäåì âëåâî, åñëè íàäî áûëî:
7586 if GetAIFlag('GOLEFT') <> '' then
7588 RemoveAIFlag('GOLEFT');
7589 if CanRunLeft() then
7593 // Èäåì âïðàâî, åñëè íàäî áûëî:
7594 if GetAIFlag('GORIGHT') <> '' then
7596 RemoveAIFlag('GORIGHT');
7597 if CanRunRight() then
7601 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7602 if FObj
.X
< -32 then
7605 if FObj
.X
+32 > gMapInfo
.Width
then
7608 // Ïðûãàåì, åñëè íàäî áûëî:
7609 if GetAIFlag('NEEDJUMP') <> '' then
7612 RemoveAIFlag('NEEDJUMP');
7615 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7616 if GetAIFlag('NEEDSEEUP') <> '' then
7619 ReleaseKey(KEY_DOWN
);
7620 PressKey(KEY_UP
, 20);
7621 RemoveAIFlag('NEEDSEEUP');
7624 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7625 if GetAIFlag('NEEDSEEDOWN') <> '' then
7628 ReleaseKey(KEY_DOWN
);
7629 PressKey(KEY_DOWN
, 20);
7630 RemoveAIFlag('NEEDSEEDOWN');
7633 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7634 if GetAIFlag('GOINHOLE') <> '' then
7635 if not OnGround() then
7637 ReleaseKey(KEY_LEFT
);
7638 ReleaseKey(KEY_RIGHT
);
7639 RemoveAIFlag('GOINHOLE');
7640 SetAIFlag('FALLINHOLE', '1');
7643 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7644 if GetAIFlag('FALLINHOLE') <> '' then
7646 RemoveAIFlag('FALLINHOLE');
7648 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7649 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7650 if GetAIFlag('FALLINHOLE') = '' then
7651 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7657 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7659 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7663 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7664 if OnGround() and NearHole() then
7665 if NearDeepHole() then // Åñëè ýòî áåçäíà
7667 0..3: Turn(); // Áåæèì îáðàòíî
7668 4: Jump(); // Ïðûãàåì
7669 5: begin // Ïðûãàåì îáðàòíî
7674 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7675 if GetAIFlag('GOINHOLE') = '' then
7677 0: Turn(); // Íå íóæíî òóäà
7678 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7679 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7680 if BorderHole() then
7681 SetAIFlag('GOINHOLE', '1');
7684 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7685 if (not CanRun()) and OnGround() then
7687 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7688 if CanJumpOver() or OnLadder() then
7690 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7691 if Random(2) = 0 then
7693 if IsSafeTrigger() then
7699 // Îñòàëîñü ìàëî âîçäóõà:
7700 if FAir
< 36 * 2 then
7703 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7704 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7705 if BodyInAcid(0, 0) then
7709 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7711 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7712 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7715 {function TBot.NeedItem(Item: Byte): Byte;
7720 procedure TBot
.SelectWeapon(Dist
: Integer);
7724 function HaveAmmo(weapon
: Byte): Boolean;
7727 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7728 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7729 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7730 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7731 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7732 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7733 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7734 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7735 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7736 else Result
:= True;
7741 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7743 if Dist
> BOT_LONGDIST
then
7744 begin // Äàëüíèé áîé
7746 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7748 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7752 else //if Dist > BOT_UNSAFEDIST then
7753 begin // Áëèæíèé áîé
7755 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7757 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7764 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7766 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7772 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7774 Result
:= inherited PickItem(ItemType
, force
, remove
);
7776 if Result
then SetAIFlag('SELECTWEAPON', '1');
7779 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7781 Result
:= inherited Heal(value
, Soft
);
7784 function TBot
.Healthy(): Byte;
7786 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7787 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7788 else if (FHealth
> 50) then Result
:= 2
7789 else if (FHealth
> 20) then Result
:= 1
7793 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7795 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7796 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7799 procedure TBot
.OnDamage(Angle
: SmallInt);
7807 if (Angle
= 0) or (Angle
= 180) then
7810 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7811 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7813 pla
:= g_Player_Get(FLastSpawnerUID
);
7814 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7815 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7818 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7819 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7821 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7822 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7823 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7828 SetAIFlag('ATTACKLEFT', '1')
7830 SetAIFlag('ATTACKRIGHT', '1');
7834 function TBot
.RunDirection(): TDirection
;
7836 if Abs(Vel
.X
) >= 1 then
7838 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7840 Result
:= FDirection
;
7843 function TBot
.GetRnd(a
: Byte): Boolean;
7845 if a
= 0 then Result
:= False
7846 else if a
= 255 then Result
:= True
7847 else Result
:= Random(256) > 255-a
;
7850 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7852 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7856 procedure TDifficult
.save (st
: TStream
);
7858 utils
.writeInt(st
, Byte(DiagFire
));
7859 utils
.writeInt(st
, Byte(InvisFire
));
7860 utils
.writeInt(st
, Byte(DiagPrecision
));
7861 utils
.writeInt(st
, Byte(FlyPrecision
));
7862 utils
.writeInt(st
, Byte(Cover
));
7863 utils
.writeInt(st
, Byte(CloseJump
));
7864 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7865 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7868 procedure TDifficult
.load (st
: TStream
);
7870 DiagFire
:= utils
.readByte(st
);
7871 InvisFire
:= utils
.readByte(st
);
7872 DiagPrecision
:= utils
.readByte(st
);
7873 FlyPrecision
:= utils
.readByte(st
);
7874 Cover
:= utils
.readByte(st
);
7875 CloseJump
:= utils
.readByte(st
);
7876 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7877 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7881 procedure TBot
.SaveState (st
: TStream
);
7886 inherited SaveState(st
);
7887 utils
.writeSign(st
, 'BOT0');
7889 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7891 utils
.writeInt(st
, Word(FTargetUID
));
7892 // Âðåìÿ ïîòåðè öåëè
7893 utils
.writeInt(st
, LongWord(FLastVisible
));
7894 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7895 dw
:= Length(FAIFlags
);
7896 utils
.writeInt(st
, LongInt(dw
));
7898 for i
:= 0 to dw
-1 do
7900 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7901 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7903 // Íàñòðîéêè ñëîæíîñòè
7904 FDifficult
.save(st
);
7908 procedure TBot
.LoadState (st
: TStream
);
7913 inherited LoadState(st
);
7914 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7916 FSelectedWeapon
:= utils
.readByte(st
);
7918 FTargetUID
:= utils
.readWord(st
);
7919 // Âðåìÿ ïîòåðè öåëè
7920 FLastVisible
:= utils
.readLongWord(st
);
7921 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7922 dw
:= utils
.readLongInt(st
);
7923 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7924 SetLength(FAIFlags
, dw
);
7926 for i
:= 0 to dw
-1 do
7928 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7929 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7931 // Íàñòðîéêè ñëîæíîñòè
7932 FDifficult
.load(st
);
7937 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);