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 SetWeaponHost(W
: Byte);
284 function IsKeyPressed(K
: Byte): Boolean;
285 function GetKeys(): Byte;
286 function PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean; virtual;
287 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
288 function Collide(Panel
: TPanel
): Boolean; overload
;
289 function Collide(X
, Y
: Integer): Boolean; overload
;
290 procedure SetDirection(Direction
: TDirection
);
291 procedure GetSecret();
292 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
294 procedure Push(vx
, vy
: Integer);
295 procedure ChangeModel(ModelName
: String);
296 procedure SwitchTeam
;
297 procedure ChangeTeam(Team
: Byte);
299 function GetFlag(Flag
: Byte): Boolean;
300 procedure SetFlag(Flag
: Byte);
301 function DropFlag(): Boolean;
302 procedure AllRulez(Health
: Boolean);
303 procedure RestoreHealthArmor();
304 procedure FragCombo();
305 procedure GiveItem(ItemType
: Byte);
306 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
307 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
308 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
309 procedure MakeBloodSimple(Count
: Word);
310 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
311 procedure Reset(Force
: Boolean);
312 procedure Spectate(NoMove
: Boolean = False);
313 procedure SwitchNoClip
;
314 procedure SoftReset();
315 procedure Draw(); virtual;
316 procedure DrawPain();
317 procedure DrawPickup();
318 procedure DrawRulez();
320 procedure DrawIndicator();
321 procedure DrawBubble();
323 procedure Update(); virtual;
324 procedure RememberState();
325 procedure RecallState();
326 procedure SaveState (st
: TStream
); virtual;
327 procedure LoadState (st
: TStream
); virtual;
328 procedure PauseSounds(Enable
: Boolean);
329 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
330 procedure DoLerp(Level
: Integer = 2);
331 procedure SetLerp(XTo
, YTo
: Integer);
332 procedure QueueWeaponSwitch(Weapon
: Byte);
333 procedure RealizeCurrentWeapon();
335 procedure JetpackOff
;
336 procedure CatchFire(Attacker
: Word);
338 //WARNING! this does nothing for now, but still call it!
339 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
341 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
342 procedure moveBy (dx
, dy
: Integer); inline;
344 procedure releaseAllWeaponSwitchKeys ();
345 procedure weaponSwitchKeysStateChange (index
: Integer; pressed
: Boolean);
346 function isWeaponSwitchKeyReleased (index
: Integer): Boolean;
347 procedure weaponSwitchKeysShiftNewStates ();
350 property Vel
: TPoint2i read FObj
.Vel
;
351 property Obj
: TObj read FObj
;
353 property Name
: String read FName write FName
;
354 property Model
: TPlayerModel read FModel
;
355 property Health
: Integer read FHealth write FHealth
;
356 property Lives
: Byte read FLives write FLives
;
357 property Armor
: Integer read FArmor write FArmor
;
358 property Air
: Integer read FAir write FAir
;
359 property JetFuel
: Integer read FJetFuel write FJetFuel
;
360 property Frags
: Integer read FFrags write FFrags
;
361 property Death
: Integer read FDeath write FDeath
;
362 property Kills
: Integer read FKills write FKills
;
363 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
364 //property NetForceWeap: Byte read FNetForceWeap write FNetForceWeap;
365 property NetForceWeapFIdx
: LongWord read FNetForceWeapFIdx write FNetForceWeapFIdx
;
366 //property CurrFrameIdx: LongWord read FCurrFrameIdx write FCurrFrameIdx;
367 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
368 property Secrets
: Integer read FSecrets
;
369 property GodMode
: Boolean read FGodMode write FGodMode
;
370 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
371 property NoReload
: Boolean read FNoReload write FNoReload
;
372 property alive
: Boolean read FAlive write FAlive
;
373 property Flag
: Byte read FFlag
;
374 property Team
: Byte read FTeam write FTeam
;
375 property Direction
: TDirection read FDirection
;
376 property GameX
: Integer read FObj
.X write FObj
.X
;
377 property GameY
: Integer read FObj
.Y write FObj
.Y
;
378 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
379 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
380 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
381 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
382 property IncCam
: Integer read FIncCam write FIncCam
;
383 property UID
: Word read FUID write FUID
;
384 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
385 property NetTime
: LongWord read FNetTime write FNetTime
;
388 property eName
: String read FName write FName
;
389 property eHealth
: Integer read FHealth write FHealth
;
390 property eLives
: Byte read FLives write FLives
;
391 property eArmor
: Integer read FArmor write FArmor
;
392 property eAir
: Integer read FAir write FAir
;
393 property eJetFuel
: Integer read FJetFuel write FJetFuel
;
394 property eFrags
: Integer read FFrags write FFrags
;
395 property eDeath
: Integer read FDeath write FDeath
;
396 property eKills
: Integer read FKills write FKills
;
397 property eCurrWeap
: Byte read FCurrWeap write FCurrWeap
;
398 property eMonsterKills
: Integer read FMonsterKills write FMonsterKills
;
399 property eSecrets
: Integer read FSecrets write FSecrets
;
400 property eGodMode
: Boolean read FGodMode write FGodMode
;
401 property eNoTarget
: Boolean read FNoTarget write FNoTarget
;
402 property eNoReload
: Boolean read FNoReload write FNoReload
;
403 property eAlive
: Boolean read FAlive write FAlive
;
404 property eFlag
: Byte read FFlag
;
405 property eTeam
: Byte read FTeam write FTeam
;
406 property eDirection
: TDirection read FDirection
;
407 property eGameX
: Integer read FObj
.X write FObj
.X
;
408 property eGameY
: Integer read FObj
.Y write FObj
.Y
;
409 property eGameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
410 property eGameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
411 property eGameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
412 property eGameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
413 property eIncCam
: Integer read FIncCam write FIncCam
;
414 property eUID
: Word read FUID
;
415 property eJustTeleported
: Boolean read FJustTeleported
;
416 property eNetTime
: LongWord read FNetTime
;
418 // set this before assigning something to `eDamage`
419 property eDamageType
: Integer read mEDamageType write mEDamageType
;
420 property eDamage
: Integer write doDamage
;
431 WeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
432 CloseWeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
433 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
436 procedure save (st
: TStream
);
437 procedure load (st
: TStream
);
445 TBot
= class(TPlayer
)
447 FSelectedWeapon
: Byte;
450 FAIFlags
: Array of TAIFlag
;
451 FDifficult
: TDifficult
;
453 function GetRnd(a
: Byte): Boolean;
454 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
455 function RunDirection(): TDirection
;
456 function FullInStep(XInc
, YInc
: Integer): Boolean;
457 //function NeedItem(Item: Byte): Byte;
458 procedure SelectWeapon(Dist
: Integer);
459 procedure SetAIFlag(aName
, fValue
: String20
);
460 function GetAIFlag(aName
: String20
): String20
;
461 procedure RemoveAIFlag(aName
: String20
);
462 function Healthy(): Byte;
463 procedure UpdateMove();
464 procedure UpdateCombat();
465 function KeyPressed(Key
: Word): Boolean;
466 procedure ReleaseKey(Key
: Byte);
467 function TargetOnScreen(TX
, TY
: Integer): Boolean;
468 procedure OnDamage(Angle
: SmallInt); override;
471 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
472 constructor Create(); override;
473 destructor Destroy(); override;
474 procedure Draw(); override;
475 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
476 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
477 procedure Update(); override;
478 procedure SaveState (st
: TStream
); override;
479 procedure LoadState (st
: TStream
); override;
491 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
492 procedure moveBy (dx
, dy
: Integer); inline;
494 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
508 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
509 procedure moveBy (dx
, dy
: Integer); inline;
511 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
514 TCorpse
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
523 FAnimation
: TAnimation
;
524 FAnimationMask
: TAnimation
;
527 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
528 destructor Destroy(); override;
529 procedure Damage(Value
: Word; vx
, vy
: Integer);
532 procedure SaveState (st
: TStream
);
533 procedure LoadState (st
: TStream
);
535 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
536 procedure moveBy (dx
, dy
: Integer); inline;
538 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
540 function ObjPtr (): PObj
; inline;
542 property Obj
: TObj read FObj
; // copies object
543 property State
: Byte read FState
;
544 property Mess
: Boolean read FMess
;
547 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
553 gPlayers
: Array of TPlayer
;
554 gCorpses
: Array of TCorpse
;
555 gGibs
: Array of TGib
;
556 gShells
: Array of TShell
;
557 gTeamStat
: TTeamStat
;
558 gFly
: Boolean = False;
559 gAimLine
: Boolean = False;
560 gChatBubble
: Byte = 0;
561 gPlayerIndicator
: Boolean = True;
565 MAX_RUNVEL
: Integer = 8;
566 VEL_JUMP
: Integer = 10;
567 SHELL_TIMEOUT
: Cardinal = 60000;
569 function Lerp(X
, Y
, Factor
: Integer): Integer;
571 procedure g_Gibs_SetMax(Count
: Word);
572 function g_Gibs_GetMax(): Word;
573 procedure g_Corpses_SetMax(Count
: Word);
574 function g_Corpses_GetMax(): Word;
575 procedure g_Shells_SetMax(Count
: Word);
576 function g_Shells_GetMax(): Word;
578 procedure g_Player_Init();
579 procedure g_Player_Free();
580 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
581 function g_Player_CreateFromState (st
: TStream
): Word;
582 procedure g_Player_Remove(UID
: Word);
583 procedure g_Player_ResetTeams();
584 procedure g_Player_UpdateAll();
585 procedure g_Player_DrawAll();
586 procedure g_Player_DrawDebug(p
: TPlayer
);
587 procedure g_Player_DrawHealth();
588 procedure g_Player_RememberAll();
589 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
590 function g_Player_Get(UID
: Word): TPlayer
;
591 function g_Player_GetCount(): Byte;
592 function g_Player_GetStats(): TPlayerStatArray
;
593 function g_Player_ValidName(Name
: String): Boolean;
594 procedure g_Player_CreateCorpse(Player
: TPlayer
);
595 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
596 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
597 procedure g_Player_UpdatePhysicalObjects();
598 procedure g_Player_DrawCorpses();
599 procedure g_Player_DrawShells();
600 procedure g_Player_RemoveAllCorpses();
601 procedure g_Player_Corpses_SaveState (st
: TStream
);
602 procedure g_Player_Corpses_LoadState (st
: TStream
);
603 procedure g_Bot_Add(Team
, Difficult
: Byte);
604 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1);
605 procedure g_Bot_MixNames();
606 procedure g_Bot_RemoveAll();
611 {$INCLUDE ../nogl/noGLuses.inc}
612 {$IFDEF ENABLE_HOLMES}
615 e_log
, g_map
, g_items
, g_console
, g_gfx
, Math
,
616 g_options
, g_triggers
, g_menu
, g_game
, g_grid
,
617 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
,
618 g_net
, g_netmsg
, g_window
,
621 const PLR_SAVE_VERSION
= 0;
631 diag_precision
: Byte;
635 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
636 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
637 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
641 TIME_RESPAWN1
= 1500;
642 TIME_RESPAWN2
= 2000;
643 TIME_RESPAWN3
= 3000;
646 JET_MAX
= 540; // ~30 sec
647 PLAYER_SUIT_TIME
= 30000;
648 PLAYER_INVUL_TIME
= 30000;
649 PLAYER_INVIS_TIME
= 35000;
650 FRAG_COMBO_TIME
= 3000;
654 ANGLE_RIGHTDOWN
= -35;
656 ANGLE_LEFTDOWN
= -145;
657 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
658 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
661 BOT_UNSAFEDIST
= 128;
662 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
664 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
665 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
666 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
667 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
668 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
669 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
670 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
671 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
672 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
673 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
674 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
675 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
676 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
677 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
678 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
679 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
680 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
681 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
682 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
683 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
684 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
685 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
686 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
687 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
688 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
689 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
691 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
692 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
694 BOTNAMES_FILENAME
= 'botnames.txt';
695 BOTLIST_FILENAME
= 'botlist.txt';
699 MaxCorpses
: Word = 20;
700 MaxShells
: Word = 300;
701 CurrentGib
: Integer = 0;
702 CurrentShell
: Integer = 0;
703 BotNames
: Array of String;
704 BotList
: Array of TBotProfile
;
707 function Lerp(X
, Y
, Factor
: Integer): Integer;
709 Result
:= X
+ ((Y
- X
) div Factor
);
712 function SameTeam(UID1
, UID2
: Word): Boolean;
716 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
717 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
719 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
721 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
722 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
724 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
727 procedure g_Gibs_SetMax(Count
: Word);
730 SetLength(gGibs
, Count
);
732 if CurrentGib
>= Count
then
736 function g_Gibs_GetMax(): Word;
741 procedure g_Shells_SetMax(Count
: Word);
744 SetLength(gShells
, Count
);
746 if CurrentShell
>= Count
then
750 function g_Shells_GetMax(): Word;
756 procedure g_Corpses_SetMax(Count
: Word);
759 SetLength(gCorpses
, Count
);
762 function g_Corpses_GetMax(): Word;
764 Result
:= MaxCorpses
;
767 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
777 // Åñòü ëè ìåñòî â gPlayers:
778 if gPlayers
<> nil then
779 for a
:= 0 to High(gPlayers
) do
780 if gPlayers
[a
] = nil then
786 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
789 SetLength(gPlayers
, Length(gPlayers
)+1);
793 // Ñîçäàåì îáúåêò èãðîêà:
795 gPlayers
[a
] := TBot
.Create()
797 gPlayers
[a
] := TPlayer
.Create();
800 gPlayers
[a
].FActualModelName
:= ModelName
;
801 gPlayers
[a
].SetModel(ModelName
);
803 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
804 if gPlayers
[a
].FModel
= nil then
808 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
812 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
813 if Random(2) = 0 then
817 gPlayers
[a
].FPreferredTeam
:= Team
;
819 case gGameSettings
.GameMode
of
820 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
822 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
824 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
827 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
828 gPlayers
[a
].FColor
:= Color
;
829 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
830 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
832 gPlayers
[a
].FModel
.Color
:= Color
;
834 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
835 gPlayers
[a
].FAlive
:= False;
837 Result
:= gPlayers
[a
].FUID
;
840 function g_Player_CreateFromState (st
: TStream
): Word;
847 if (st
= nil) then exit
; //???
850 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
851 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
854 Bot
:= utils
.readBool(st
);
859 // Åñòü ëè ìåñòî â gPlayers:
860 for a
:= 0 to High(gPlayers
) do if (gPlayers
[a
] = nil) then begin ok
:= true; break
; end;
862 // Íåò ìåñòà - ðàñøèðÿåì gPlayers
865 SetLength(gPlayers
, Length(gPlayers
)+1);
869 // Ñîçäàåì îáúåêò èãðîêà
871 gPlayers
[a
] := TBot
.Create()
873 gPlayers
[a
] := TPlayer
.Create();
874 gPlayers
[a
].FIamBot
:= Bot
;
875 gPlayers
[a
].FPhysics
:= True;
878 gPlayers
[a
].FUID
:= utils
.readWord(st
);
880 gPlayers
[a
].FName
:= utils
.readStr(st
);
882 gPlayers
[a
].FTeam
:= utils
.readByte(st
);
883 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
885 gPlayers
[a
].FAlive
:= utils
.readBool(st
);
886 // Èçðàñõîäîâàë ëè âñå æèçíè
887 gPlayers
[a
].FNoRespawn
:= utils
.readBool(st
);
889 b
:= utils
.readByte(st
);
890 if b
= 1 then gPlayers
[a
].FDirection
:= TDirection
.D_LEFT
else gPlayers
[a
].FDirection
:= TDirection
.D_RIGHT
; // b = 2
892 gPlayers
[a
].FHealth
:= utils
.readLongInt(st
);
894 gPlayers
[a
].FLives
:= utils
.readByte(st
);
896 gPlayers
[a
].FArmor
:= utils
.readLongInt(st
);
898 gPlayers
[a
].FAir
:= utils
.readLongInt(st
);
900 gPlayers
[a
].FJetFuel
:= utils
.readLongInt(st
);
902 gPlayers
[a
].FPain
:= utils
.readLongInt(st
);
904 gPlayers
[a
].FKills
:= utils
.readLongInt(st
);
906 gPlayers
[a
].FMonsterKills
:= utils
.readLongInt(st
);
908 gPlayers
[a
].FFrags
:= utils
.readLongInt(st
);
910 gPlayers
[a
].FFragCombo
:= utils
.readByte(st
);
911 // Âðåìÿ ïîñëåäíåãî ôðàãà
912 gPlayers
[a
].FLastFrag
:= utils
.readLongWord(st
);
914 gPlayers
[a
].FDeath
:= utils
.readLongInt(st
);
916 gPlayers
[a
].FFlag
:= utils
.readByte(st
);
918 gPlayers
[a
].FSecrets
:= utils
.readLongInt(st
);
920 gPlayers
[a
].FCurrWeap
:= utils
.readByte(st
);
921 //gPlayers[a].FNetForceWeap := gPlayers[a].FCurrWeap;
922 // Ñëåäóþùåå æåëàåìîå îðóæèå
923 gPlayers
[a
].FNextWeap
:= utils
.readWord(st
);
925 gPlayers
[a
].FNextWeapDelay
:= utils
.readByte(st
);
927 gPlayers
[a
].FBFGFireCounter
:= utils
.readSmallInt(st
);
929 gPlayers
[a
].FDamageBuffer
:= utils
.readLongInt(st
);
930 // Ïîñëåäíèé óäàðèâøèé
931 gPlayers
[a
].FLastSpawnerUID
:= utils
.readWord(st
);
932 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
933 gPlayers
[a
].FLastHit
:= utils
.readByte(st
);
935 Obj_LoadState(@gPlayers
[a
].FObj
, st
);
936 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
937 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FAmmo
[i
] := utils
.readWord(st
);
938 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
939 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FMaxAmmo
[i
] := utils
.readWord(st
);
941 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FWeapon
[i
] := utils
.readBool(st
);
942 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
943 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FReloading
[i
] := utils
.readWord(st
);
945 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
946 // Íàëè÷èå êðàñíîãî êëþ÷à
947 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
948 // Íàëè÷èå çåëåíîãî êëþ÷à
949 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
950 // Íàëè÷èå ñèíåãî êëþ÷à
951 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
953 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_BERSERK
);
954 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
955 for i
:= MR_SUIT
to MR_MAX
do gPlayers
[a
].FMegaRulez
[i
] := utils
.readLongWord(st
);
956 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
957 for i
:= T_RESPAWN
to T_FLAGCAP
do gPlayers
[a
].FTime
[i
] := utils
.readLongWord(st
);
960 gPlayers
[a
].FActualModelName
:= utils
.readStr(st
);
962 gPlayers
[a
].FColor
.R
:= utils
.readByte(st
);
963 gPlayers
[a
].FColor
.G
:= utils
.readByte(st
);
964 gPlayers
[a
].FColor
.B
:= utils
.readByte(st
);
965 // Îáíîâëÿåì ìîäåëü èãðîêà
966 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
968 // Íåò ìîäåëè - ñîçäàíèå íåâîçìîæíî
969 if (gPlayers
[a
].FModel
= nil) then
973 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
977 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû
978 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
979 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
981 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
983 result
:= gPlayers
[a
].FUID
;
987 procedure g_Player_ResetTeams();
991 if g_Game_IsClient
then
993 if gPlayers
= nil then
995 for a
:= Low(gPlayers
) to High(gPlayers
) do
996 if gPlayers
[a
] <> nil then
997 case gGameSettings
.GameMode
of
999 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
1001 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
1002 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
1003 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
1006 gPlayers
[a
].ChangeTeam(TEAM_RED
)
1008 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
1011 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
1015 procedure g_Bot_Add(Team
, Difficult
: Byte);
1018 _name
, _model
: String;
1021 if not g_Game_IsServer
then Exit
;
1023 // Ñïèñîê íàçâàíèé ìîäåëåé:
1024 m
:= g_PlayerModel_GetNames();
1029 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1030 Team
:= TEAM_COOP
// COOP
1032 if gGameSettings
.GameMode
= GM_DM
then
1033 Team
:= TEAM_NONE
// DM
1035 if Team
= TEAM_NONE
then // CTF / TDM
1037 // Àâòîáàëàíñ êîìàíä:
1041 for a
:= 0 to High(gPlayers
) do
1042 if gPlayers
[a
] <> nil then
1044 if gPlayers
[a
].Team
= TEAM_RED
then
1047 if gPlayers
[a
].Team
= TEAM_BLUE
then
1057 if Random(2) = 0 then
1063 // Âûáèðàåì áîòó èìÿ:
1065 if BotNames
<> nil then
1066 for a
:= 0 to High(BotNames
) do
1067 if g_Player_ValidName(BotNames
[a
]) then
1069 _name
:= BotNames
[a
];
1073 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
1076 _name
:= Format('DFBOT%.2d', [Random(100)]);
1077 until g_Player_ValidName(_name
);
1079 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1080 _model
:= m
[Random(Length(m
))];
1083 with g_Player_Get(g_Player_Create(_model
,
1084 _RGB(Min(Random(9)*32, 255),
1085 Min(Random(9)*32, 255),
1086 Min(Random(9)*32, 255)),
1087 Team
, True)) as TBot
do
1092 1: FDifficult
:= DIFFICULT_EASY
;
1093 2: FDifficult
:= DIFFICULT_MEDIUM
;
1094 else FDifficult
:= DIFFICULT_HARD
;
1097 for a
:= WP_FIRST
to WP_LAST
do
1099 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1100 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1101 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1104 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1106 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1107 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1112 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1);
1115 _name
, _model
: String;
1118 if not g_Game_IsServer
then Exit
;
1120 // Ñïèñîê íàçâàíèé ìîäåëåé:
1121 m
:= g_PlayerModel_GetNames();
1126 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1127 Team
:= TEAM_COOP
// COOP
1129 if gGameSettings
.GameMode
= GM_DM
then
1130 Team
:= TEAM_NONE
// DM
1132 if Team
= TEAM_NONE
then
1133 Team
:= BotList
[num
].team
; // CTF / TDM
1135 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1136 lName
:= AnsiLowerCase(lName
);
1137 if (num
< 0) or (num
> Length(BotList
)-1) then
1139 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1140 for a
:= 0 to High(BotList
) do
1141 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1150 _name
:= BotList
[num
].name
;
1151 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1152 if not g_Player_ValidName(_name
) then
1154 _name
:= Format('DFBOT%.2d', [Random(100)]);
1155 until g_Player_ValidName(_name
);
1158 _model
:= BotList
[num
].model
;
1159 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1160 if not InSArray(_model
, m
) then
1161 _model
:= m
[Random(Length(m
))];
1164 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1168 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1169 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1170 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1171 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1172 FDifficult
.Cover
:= BotList
[num
].cover
;
1173 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1175 for a
:= WP_FIRST
to WP_LAST
do
1177 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1178 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1179 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1182 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1184 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1188 procedure g_Bot_RemoveAll();
1192 if not g_Game_IsServer
then Exit
;
1193 if gPlayers
= nil then Exit
;
1195 for a
:= 0 to High(gPlayers
) do
1196 if gPlayers
[a
] <> nil then
1197 if gPlayers
[a
] is TBot
then
1199 gPlayers
[a
].Lives
:= 0;
1200 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1201 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1202 g_Player_Remove(gPlayers
[a
].FUID
);
1208 procedure g_Bot_MixNames();
1213 if BotNames
<> nil then
1214 for a
:= 0 to High(BotNames
) do
1216 b
:= Random(Length(BotNames
));
1218 Botnames
[a
] := BotNames
[b
];
1223 procedure g_Player_Remove(UID
: Word);
1227 if gPlayers
= nil then Exit
;
1229 if g_Game_IsServer
and g_Game_IsNet
then
1230 MH_SEND_PlayerDelete(UID
);
1232 for i
:= 0 to High(gPlayers
) do
1233 if gPlayers
[i
] <> nil then
1234 if gPlayers
[i
].FUID
= UID
then
1236 if gPlayers
[i
] is TPlayer
then
1237 TPlayer(gPlayers
[i
]).Free()
1239 TBot(gPlayers
[i
]).Free();
1245 procedure g_Player_Init();
1255 if not FileExists(DataDir
+ BOTNAMES_FILENAME
) then
1258 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1259 AssignFile(F
, DataDir
+ BOTNAMES_FILENAME
);
1270 SetLength(BotNames
, Length(BotNames
)+1);
1271 BotNames
[High(BotNames
)] := s
;
1279 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1280 config
:= TConfig
.CreateFile(DataDir
+ BOTLIST_FILENAME
);
1284 while config
.SectionExists(IntToStr(a
)) do
1286 SetLength(BotList
, Length(BotList
)+1);
1288 with BotList
[High(BotList
)] do
1291 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1293 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1295 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1300 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1301 color
.R
:= StrToIntDef(sa
[0], 0);
1302 color
.G
:= StrToIntDef(sa
[1], 0);
1303 color
.B
:= StrToIntDef(sa
[2], 0);
1304 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1305 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1306 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1307 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1308 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1309 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1310 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1311 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1312 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1313 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1314 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1315 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1316 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1317 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1318 if Length(sa
) = 10 then
1320 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1321 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1322 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1323 if Length(sa
) = 10 then
1325 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1327 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1328 if Length(sa) = 10 then
1330 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1339 procedure g_Player_Free();
1343 if gPlayers
<> nil then
1345 for i
:= 0 to High(gPlayers
) do
1346 if gPlayers
[i
] <> nil then
1348 if gPlayers
[i
] is TPlayer
then
1349 TPlayer(gPlayers
[i
]).Free()
1351 TBot(gPlayers
[i
]).Free();
1362 procedure g_Player_UpdateAll();
1366 if gPlayers
= nil then Exit
;
1368 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1369 for i
:= 0 to High(gPlayers
) do
1371 if gPlayers
[i
] <> nil then
1373 if gPlayers
[i
] is TPlayer
then
1375 //if (gPlayers[i].NetForceWeapFIdx > gTime) then writeln('*** PLAYER #', i, '; gTime=', gTime, '; nfwf=', gPlayers[i].NetForceWeapFIdx);
1376 gPlayers
[i
].Update();
1377 if (not gPlayers
[i
].alive
) or (gPlayers
[i
].NetForceWeapFIdx
>= gTime
+15) then gPlayers
[i
].NetForceWeapFIdx
:= 0; // just in case
1378 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1382 // bot updates weapons in `UpdateCombat()`
1383 TBot(gPlayers
[i
]).Update();
1387 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1390 procedure g_Player_DrawAll();
1394 if gPlayers
= nil then Exit
;
1396 for i
:= 0 to High(gPlayers
) do
1397 if gPlayers
[i
] <> nil then
1398 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1399 else TBot(gPlayers
[i
]).Draw();
1402 procedure g_Player_DrawDebug(p
: TPlayer
);
1406 if p
= nil then Exit
;
1407 if (@p
.FObj
) = nil then Exit
;
1409 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1411 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1412 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1413 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1414 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1415 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1416 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1419 procedure g_Player_DrawHealth();
1424 if gPlayers
= nil then Exit
;
1425 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1427 for i
:= 0 to High(gPlayers
) do
1428 if gPlayers
[i
] <> nil then
1430 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1431 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1432 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1433 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1434 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1435 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1439 function g_Player_Get(UID
: Word): TPlayer
;
1445 if gPlayers
= nil then
1448 for a
:= 0 to High(gPlayers
) do
1449 if gPlayers
[a
] <> nil then
1450 if gPlayers
[a
].FUID
= UID
then
1452 Result
:= gPlayers
[a
];
1457 function g_Player_GetCount(): Byte;
1463 if gPlayers
= nil then
1466 for a
:= 0 to High(gPlayers
) do
1467 if gPlayers
[a
] <> nil then
1468 Result
:= Result
+ 1;
1471 function g_Player_GetStats(): TPlayerStatArray
;
1477 if gPlayers
= nil then Exit
;
1479 for a
:= 0 to High(gPlayers
) do
1480 if gPlayers
[a
] <> nil then
1482 SetLength(Result
, Length(Result
)+1);
1483 with Result
[High(Result
)] do
1485 Ping
:= gPlayers
[a
].FPing
;
1486 Loss
:= gPlayers
[a
].FLoss
;
1487 Name
:= gPlayers
[a
].FName
;
1488 Team
:= gPlayers
[a
].FTeam
;
1489 Frags
:= gPlayers
[a
].FFrags
;
1490 Deaths
:= gPlayers
[a
].FDeath
;
1491 Kills
:= gPlayers
[a
].FKills
;
1492 Color
:= gPlayers
[a
].FModel
.Color
;
1493 Lives
:= gPlayers
[a
].FLives
;
1494 Spectator
:= gPlayers
[a
].FSpectator
;
1499 procedure g_Player_RememberAll
;
1503 for i
:= Low(gPlayers
) to High(gPlayers
) do
1504 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1505 gPlayers
[i
].RememberState
;
1508 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1512 gTeamStat
[TEAM_RED
].Goals
:= 0;
1513 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1515 if gPlayers
<> nil then
1516 for i
:= 0 to High(gPlayers
) do
1517 if gPlayers
[i
] <> nil then
1519 gPlayers
[i
].Reset(Force
);
1521 if gPlayers
[i
] is TPlayer
then
1523 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1524 gPlayers
[i
].Respawn(Silent
)
1526 gPlayers
[i
].Spectate();
1529 TBot(gPlayers
[i
]).Respawn(Silent
);
1533 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1539 if Player
.alive
then
1542 // Ðàçðûâàåì ñâÿçü ñ ïðåæíèì òðóïîì:
1543 if gCorpses
<> nil then
1544 for i
:= 0 to High(gCorpses
) do
1545 if gCorpses
[i
] <> nil then
1546 if gCorpses
[i
].FPlayerUID
= Player
.FUID
then
1547 gCorpses
[i
].FPlayerUID
:= 0;
1549 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1554 if (FHealth
>= -50) or (gGibsCount
= 0) then
1556 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1560 for find_id
:= 0 to High(gCorpses
) do
1561 if gCorpses
[find_id
] = nil then
1568 find_id
:= Random(Length(gCorpses
));
1570 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1571 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1572 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1573 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1574 gCorpses
[find_id
].FPlayerUID
:= FUID
;
1577 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1578 FObj
.Y
+ PLAYER_RECT_CY
,
1579 FModel
.Name
, FModel
.Color
);
1583 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1587 if (gShells
= nil) or (Length(gShells
) = 0) then
1590 with gShells
[CurrentShell
] do
1596 if T
= SHELL_BULLET
then
1598 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1602 Obj
.Rect
.Width
:= 4;
1603 Obj
.Rect
.Height
:= 2;
1607 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1611 Obj
.Rect
.Width
:= 7;
1612 Obj
.Rect
.Height
:= 3;
1618 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1619 positionChanged(); // this updates spatial accelerators
1620 RAngle
:= Random(360);
1621 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1623 if CurrentShell
>= High(gShells
) then
1630 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1633 GibsArray
: TGibsArray
;
1636 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1638 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1640 Blood
:= g_PlayerModel_GetBlood(ModelName
);
1642 for a
:= 0 to High(GibsArray
) do
1643 with gGibs
[CurrentGib
] do
1646 ID
:= GibsArray
[a
].ID
;
1647 MaskID
:= GibsArray
[a
].MaskID
;
1650 Obj
.Rect
:= GibsArray
[a
].Rect
;
1651 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1652 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1653 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1654 positionChanged(); // this updates spatial accelerators
1655 RAngle
:= Random(360);
1657 if gBloodCount
> 0 then
1658 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1659 Random(48), Random(48), Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
1661 if CurrentGib
>= High(gGibs
) then
1668 procedure g_Player_UpdatePhysicalObjects();
1674 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1679 if T
= SHELL_BULLET
then
1680 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1682 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1687 if gGibs
<> nil then
1688 for i
:= 0 to High(gGibs
) do
1689 if gGibs
[i
].alive
then
1693 mr
:= g_Obj_Move(@Obj
, True, False, True);
1694 positionChanged(); // this updates spatial accelerators
1696 if WordBool(mr
and MOVE_FALLOUT
) then
1702 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1703 if WordBool(mr
and MOVE_HITWALL
) then
1704 Obj
.Vel
.X
:= -(vel
.X
div 2);
1705 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1706 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1708 if (Obj
.Vel
.X
>= 0) then
1710 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1711 if RAngle
>= 360 then
1712 RAngle
:= RAngle
mod 360;
1713 end else begin // Counter-clockwise
1714 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1716 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1719 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1720 if gTime
mod (GAME_TICK
*3) = 0 then
1721 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1725 if gCorpses
<> nil then
1726 for i
:= 0 to High(gCorpses
) do
1727 if gCorpses
[i
] <> nil then
1728 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1734 gCorpses
[i
].Update();
1737 if gShells
<> nil then
1738 for i
:= 0 to High(gShells
) do
1739 if gShells
[i
].alive
then
1743 mr
:= g_Obj_Move(@Obj
, True, False, True);
1744 positionChanged(); // this updates spatial accelerators
1746 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1752 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1753 if WordBool(mr
and MOVE_HITWALL
) then
1755 Obj
.Vel
.X
:= -(vel
.X
div 2);
1756 if not WordBool(mr
and MOVE_INWATER
) then
1757 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1759 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1761 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1762 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1763 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1765 if RAngle
mod 90 <> 0 then
1766 RAngle
:= (RAngle
div 90) * 90;
1768 else if not WordBool(mr
and MOVE_INWATER
) then
1769 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1772 if (Obj
.Vel
.X
>= 0) then
1774 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1775 if RAngle
>= 360 then
1776 RAngle
:= RAngle
mod 360;
1777 end else begin // Counter-clockwise
1778 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1780 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1786 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1788 x
:= Obj
.X
+Obj
.Rect
.X
;
1789 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1790 w
:= Obj
.Rect
.Width
;
1791 h
:= Obj
.Rect
.Height
;
1794 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1796 if (dx
<> 0) or (dy
<> 0) then
1805 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1809 w
:= Obj
.Rect
.Width
;
1810 h
:= Obj
.Rect
.Height
;
1813 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1815 if (dx
<> 0) or (dy
<> 0) then
1824 procedure TGib
.positionChanged (); inline; begin end;
1825 procedure TShell
.positionChanged (); inline; begin end;
1828 procedure g_Player_DrawCorpses();
1833 if gGibs
<> nil then
1834 for i
:= 0 to High(gGibs
) do
1835 if gGibs
[i
].alive
then
1838 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1841 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1842 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1844 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1847 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1853 if gCorpses
<> nil then
1854 for i
:= 0 to High(gCorpses
) do
1855 if gCorpses
[i
] <> nil then
1859 procedure g_Player_DrawShells();
1864 if gShells
<> nil then
1865 for i
:= 0 to High(gShells
) do
1866 if gShells
[i
].alive
then
1869 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1875 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1879 procedure g_Player_RemoveAllCorpses();
1885 SetLength(gGibs
, MaxGibs
);
1886 SetLength(gShells
, MaxGibs
);
1890 if gCorpses
<> nil then
1891 for i
:= 0 to High(gCorpses
) do
1895 SetLength(gCorpses
, MaxCorpses
);
1898 procedure g_Player_Corpses_SaveState (st
: TStream
);
1902 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ
1904 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1906 // Êîëè÷åñòâî òðóïîâ
1907 utils
.writeInt(st
, LongInt(count
));
1909 if (count
= 0) then exit
;
1912 for i
:= 0 to High(gCorpses
) do
1914 if gCorpses
[i
] <> nil then
1917 utils
.writeStr(st
, gCorpses
[i
].FModelName
);
1919 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1920 // Ñîõðàíÿåì äàííûå òðóïà:
1921 gCorpses
[i
].SaveState(st
);
1927 procedure g_Player_Corpses_LoadState (st
: TStream
);
1935 g_Player_RemoveAllCorpses();
1937 // Êîëè÷åñòâî òðóïîâ:
1938 count
:= utils
.readLongInt(st
);
1939 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1941 if (count
= 0) then exit
;
1944 for i
:= 0 to count
-1 do
1947 str
:= utils
.readStr(st
);
1949 b
:= utils
.readBool(st
);
1951 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1952 // Çàãðóæàåì äàííûå òðóïà
1953 gCorpses
[i
].LoadState(st
);
1960 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1962 procedure TPlayer
.BFGHit();
1964 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1965 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1966 if g_Game_IsServer
and g_Game_IsNet
then
1967 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1968 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1972 procedure TPlayer
.ChangeModel(ModelName
: string);
1974 locModel
: TPlayerModel
;
1976 locModel
:= g_PlayerModel_Get(ModelName
);
1977 if locModel
= nil then Exit
;
1983 procedure TPlayer
.SetModel(ModelName
: string);
1987 m
:= g_PlayerModel_Get(ModelName
);
1990 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1991 m
:= g_PlayerModel_Get('doomer');
1994 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1999 if FModel
<> nil then
2004 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2005 FModel
.Color
:= FColor
2007 FModel
.Color
:= TEAMCOLOR
[FTeam
];
2008 FModel
.SetWeapon(FCurrWeap
);
2009 FModel
.SetFlag(FFlag
);
2010 SetDirection(FDirection
);
2013 procedure TPlayer
.SetColor(Color
: TRGB
);
2016 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2017 if FModel
<> nil then FModel
.Color
:= Color
;
2020 procedure TPlayer
.SwitchTeam
;
2022 if g_Game_IsClient
then
2024 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
2026 if gGameOn
and FAlive
then
2027 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
2029 if FTeam
= TEAM_RED
then
2031 ChangeTeam(TEAM_BLUE
);
2032 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
2033 if g_Game_IsNet
then
2034 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
2038 ChangeTeam(TEAM_RED
);
2039 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
2040 if g_Game_IsNet
then
2041 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
2043 FPreferredTeam
:= FTeam
;
2046 procedure TPlayer
.ChangeTeam(Team
: Byte);
2053 TEAM_RED
, TEAM_BLUE
:
2054 FModel
.Color
:= TEAMCOLOR
[Team
];
2056 FModel
.Color
:= FColor
;
2058 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2059 MH_SEND_PlayerStats(FUID
);
2063 procedure TPlayer.CollideItem();
2068 if gItems = nil then Exit;
2069 if not FAlive then Exit;
2071 for i := 0 to High(gItems) do
2074 if (ItemType <> ITEM_NONE) and alive then
2075 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2076 PLAYER_RECT.Height, @Obj) then
2078 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2080 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2081 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2082 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2083 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2084 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2086 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2087 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2088 (gGameSettings.GameType = GT_SINGLE) and
2089 (g_Player_GetCount() > 1)) then
2090 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2096 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2098 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2099 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2103 constructor TPlayer
.Create();
2109 mEDamageType
:= HIT_SOME
;
2115 FSawSound
:= TPlayableSound
.Create();
2116 FSawSoundIdle
:= TPlayableSound
.Create();
2117 FSawSoundHit
:= TPlayableSound
.Create();
2118 FSawSoundSelect
:= TPlayableSound
.Create();
2119 FJetSoundFly
:= TPlayableSound
.Create();
2120 FJetSoundOn
:= TPlayableSound
.Create();
2121 FJetSoundOff
:= TPlayableSound
.Create();
2123 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2124 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2125 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2126 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2127 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2128 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2129 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2131 FSpectatePlayer
:= -1;
2135 FSavedState
.WaitRecall
:= False;
2141 FActualModelName
:= 'doomer';
2144 FObj
.Rect
:= PLAYER_RECT
;
2146 FBFGFireCounter
:= -1;
2147 FJustTeleported
:= False;
2150 //FNetForceWeap := FCurrWeap;
2151 FNetForceWeapFIdx
:= 0;
2152 //FCurrFrameIdx := 0;
2155 releaseAllWeaponSwitchKeys();
2159 procedure TPlayer
.releaseAllWeaponSwitchKeys ();
2163 for f
:= 0 to High(weaponSwitchKeyReleased
) do weaponSwitchKeyReleased
[f
] := $03;
2166 procedure TPlayer
.weaponSwitchKeysStateChange (index
: Integer; pressed
: Boolean);
2168 Inc(index
, 2); // -2: prev; -1: next
2169 if (index
< 0) or (index
> High(weaponSwitchKeyReleased
)) then exit
;
2170 weaponSwitchKeyReleased
[index
] := weaponSwitchKeyReleased
[index
] or $02;
2171 if (pressed
) then weaponSwitchKeyReleased
[index
] := weaponSwitchKeyReleased
[index
] xor $02;
2174 function TPlayer
.isWeaponSwitchKeyReleased (index
: Integer): Boolean;
2176 Inc(index
, 2); // -2: prev; -1: next
2177 if (index
< 0) or (index
> High(weaponSwitchKeyReleased
)) then
2183 result
:= (weaponSwitchKeyReleased
[index
] and $01) <> 0;
2187 procedure TPlayer
.weaponSwitchKeysShiftNewStates ();
2191 // copy bit 1 to bit 0
2192 for f
:= 0 to High(weaponSwitchKeyReleased
) do
2194 weaponSwitchKeyReleased
[f
] :=
2195 (weaponSwitchKeyReleased
[f
] and $02) or
2196 ((weaponSwitchKeyReleased
[f
] shr 1) and $01);
2201 procedure TPlayer
.positionChanged (); inline;
2205 procedure TPlayer
.doDamage (v
: Integer);
2207 if (v
<= 0) then exit
;
2208 if (v
> 32767) then v
:= 32767;
2209 Damage(v
, 0, 0, 0, mEDamageType
);
2212 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2216 if (not g_Game_IsClient
) and (not FAlive
) then
2221 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2222 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2224 if not g_Game_IsClient
then
2227 if t
= HIT_TRAP
then
2229 // Ëîâóøêà óáèâàåò ñðàçó:
2231 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2233 if t
= HIT_SELF
then
2237 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2240 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2241 FMegaRulez
[MR_SUIT
] := 0;
2242 FMegaRulez
[MR_INVUL
] := 0;
2243 FMegaRulez
[MR_INVIS
] := 0;
2247 // Íî îò îñòàëüíîãî ñïàñàåò:
2248 if FMegaRulez
[MR_INVUL
] >= gTime
then
2255 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2256 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2257 (SpawnerUID
= FUID
) or
2258 (not SameTeam(FUID
, SpawnerUID
)) then
2260 FLastSpawnerUID
:= SpawnerUID
;
2262 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2263 if gBloodCount
> 0 then
2265 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2266 if value
div 4 <= c
then
2267 c
:= c
- (value
div 4)
2271 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2275 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2276 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2279 if t
= HIT_WATER
then
2280 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2281 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2286 Inc(FDamageBuffer
, value
);
2290 FPain
:= FPain
+ value
;
2293 if g_Game_IsServer
and g_Game_IsNet
then
2295 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2296 MH_SEND_PlayerStats(FUID
);
2297 MH_SEND_PlayerPos(False, FUID
);
2301 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2304 if g_Game_IsClient
then
2309 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2311 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2314 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2316 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2320 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2321 MH_SEND_PlayerStats(FUID
);
2324 destructor TPlayer
.Destroy();
2326 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2328 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2332 FSawSoundIdle
.Free();
2333 FSawSoundHit
.Free();
2334 FJetSoundFly
.Free();
2336 FJetSoundOff
.Free();
2338 if FPunchAnim
<> nil then
2344 procedure TPlayer
.DrawIndicator();
2346 indX
, indY
: Integer;
2352 indX
:= FObj
.X
+FObj
.Rect
.X
;
2353 indY
:= FObj
.Y
- 12;
2354 if g_Texture_Get('TEXTURE_PLAYER_INDICATOR', ID
) then
2356 e_GetTextureSize(ID
, @indW
, @indH
);
2357 e_Draw(ID
, indX
+ indW
div 2, indY
, 0, True, False);
2360 //e_TextureFontPrint(indX, indY, FName, gStdFont); // Shows player name overhead
2363 procedure TPlayer
.DrawBubble();
2365 bubX
, bubY
: Integer;
2368 Rw
, Gw
, Bw
: SmallInt;
2371 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= TDirection
.D_LEFT
, -4, 18);
2372 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2380 1: // simple textual non-bubble
2382 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2383 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2384 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2387 2: // advanced pixel-perfect bubble
2389 if FTeam
= TEAM_RED
then
2392 if FTeam
= TEAM_BLUE
then
2395 3: // colored bubble
2397 Rb
:= FModel
.Color
.R
;
2398 Gb
:= FModel
.Color
.G
;
2399 Bb
:= FModel
.Color
.B
;
2400 Rw
:= Min(Rb
* 2 + 64, 255);
2401 Gw
:= Min(Gb
* 2 + 64, 255);
2402 Bw
:= Min(Bb
* 2 + 64, 255);
2403 if (Abs(Rw
- Rb
) < 32)
2404 or (Abs(Gw
- Gb
) < 32)
2405 or (Abs(Bw
- Bb
) < 32) then
2407 Rb
:= Max(Rw
div 2 - 16, 0);
2408 Gb
:= Max(Gw
div 2 - 16, 0);
2409 Bb
:= Max(Bw
div 2 - 16, 0);
2412 4: // custom textured bubble
2414 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2415 if FDirection
= TDirection
.D_RIGHT
then
2416 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2418 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, TMirrorType
.Horizontal
);
2424 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2425 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2427 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2430 Dot
:= IfThen(FDirection
= TDirection
.D_LEFT
, 14, 5);
2431 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2432 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
);
2433 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
);
2434 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
);
2435 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
);
2439 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2440 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2441 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2444 procedure TPlayer
.Draw();
2449 Mirror
: TMirrorType
;
2453 if Direction
= TDirection
.D_RIGHT
then
2454 Mirror
:= TMirrorType
.None
2456 Mirror
:= TMirrorType
.Horizontal
;
2458 if FPunchAnim
<> nil then
2460 FPunchAnim
.Draw(FObj
.X
+IfThen(Direction
= TDirection
.D_LEFT
, 15-FObj
.Rect
.X
, FObj
.Rect
.X
-15),
2461 FObj
.Y
+FObj
.Rect
.Y
-11, Mirror
);
2462 if FPunchAnim
.played
then
2469 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2470 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2472 e_GetTextureSize(ID
, @w
, @h
);
2473 if FDirection
= TDirection
.D_LEFT
then
2474 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2475 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False)
2477 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2478 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False);
2481 if FMegaRulez
[MR_INVIS
] > gTime
then
2483 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2484 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2486 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2487 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2491 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 200)
2493 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2496 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 254);
2499 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2502 if g_debug_Frames
then
2504 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2506 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2507 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2511 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2513 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2514 if gAimLine
and alive
and
2515 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2520 procedure TPlayer
.DrawAim();
2521 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2526 {$IFDEF ENABLE_HOLMES}
2527 if isValidViewPort
and (self
= gPlayer1
) then
2529 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2533 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2534 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2536 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2540 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2545 wx
, wy
, xx
, yy
: Integer;
2549 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= TDirection
.D_LEFT
, 7, -7);
2550 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2559 1: begin // Chainsaw
2566 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2567 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2568 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2569 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2574 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2575 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2576 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2577 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2579 4: begin // Double Shotgun
2582 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2583 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2584 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2585 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2587 5: begin // Chaingun
2590 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2591 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2592 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2593 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2595 6: begin // Rocket Launcher
2598 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2599 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2600 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2601 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2603 7: begin // Plasmagun
2606 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2607 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2608 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2609 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2614 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2615 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2616 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2617 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2619 9: begin // Super Chaingun
2622 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2623 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2624 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2625 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2628 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2629 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2630 {$IF DEFINED(D2F_DEBUG)}
2631 drawCast(sz
, wx
, wy
, xx
, yy
);
2633 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2637 procedure TPlayer
.DrawGUI();
2640 X
, Y
, SY
, a
, p
, m
: Integer;
2644 stat
: TPlayerStatArray
;
2646 X
:= gPlayerScreenSize
.X
;
2647 SY
:= gPlayerScreenSize
.Y
;
2650 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2652 if gGameSettings
.GameMode
= GM_CTF
then
2656 if gGameSettings
.GameMode
= GM_CTF
then
2658 s
:= 'TEXTURE_PLAYER_REDFLAG';
2659 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2660 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2661 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2662 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2663 if g_Texture_Get(s
, ID
) then
2664 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2667 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2668 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2669 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2671 if gGameSettings
.GameMode
= GM_CTF
then
2673 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2674 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2675 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2676 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2677 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2678 if g_Texture_Get(s
, ID
) then
2679 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2682 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2683 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2684 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2687 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2688 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2691 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2692 e_Draw(ID
, X
+2, Y
, 0, True, False);
2694 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2698 s
:= IntToStr(Frags
);
2699 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2700 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2705 stat
:= g_Player_GetStats();
2710 for a
:= 0 to High(stat
) do
2711 if stat
[a
].Name
<> Name
then
2713 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2714 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2718 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2719 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2720 s
:= s
+IntToStr(Abs(Frags
-m
));
2722 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2723 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2726 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2728 s
:= IntToStr(Lives
);
2729 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2730 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2734 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2735 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2737 if R_BERSERK
in FRulez
then
2738 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2740 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2742 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2743 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2745 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2746 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2747 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2749 s
:= IntToStr(FArmor
);
2750 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2751 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2753 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2759 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2764 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2766 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2767 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2768 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2769 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2770 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2771 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2772 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2773 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2774 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2777 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2778 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2779 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2781 if R_KEY_RED
in FRulez
then
2782 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2784 if R_KEY_GREEN
in FRulez
then
2785 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2787 if R_KEY_BLUE
in FRulez
then
2788 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2790 if FJetFuel
> 0 then
2792 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2793 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2794 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2795 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2796 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2797 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2801 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2802 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2803 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2806 if gShowPing
and g_Game_IsClient
then
2808 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2809 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2815 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2816 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2817 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2820 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2821 s
:= _lc
[I_PLAYER_SPECT4
];
2822 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2823 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2824 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2830 procedure TPlayer
.DrawRulez();
2834 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2835 if FMegaRulez
[MR_INVUL
] >= gTime
then
2837 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2838 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2843 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2844 191, 191, 191, 0, TBlending
.Invert
);
2847 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2848 if FMegaRulez
[MR_SUIT
] >= gTime
then
2850 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2851 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2856 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2857 0, 96, 0, 200, TBlending
.None
);
2860 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2861 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2863 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2864 255, 0, 0, 200, TBlending
.None
);
2868 procedure TPlayer
.DrawPain();
2872 if FPain
= 0 then Exit
;
2876 if a
< 15 then h
:= 0
2877 else if a
< 35 then h
:= 1
2878 else if a
< 55 then h
:= 2
2879 else if a
< 75 then h
:= 3
2880 else if a
< 95 then h
:= 4
2883 //if a > 255 then a := 255;
2885 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2886 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2889 procedure TPlayer
.DrawPickup();
2893 if FPickup
= 0 then Exit
;
2897 if a
< 15 then h
:= 1
2898 else if a
< 35 then h
:= 2
2899 else if a
< 55 then h
:= 3
2900 else if a
< 75 then h
:= 4
2903 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2906 procedure TPlayer
.DoPunch();
2911 if FPunchAnim
<> nil then begin
2916 st
:= 'FRAMES_PUNCH';
2917 if R_BERSERK
in FRulez
then
2918 st
:= st
+ '_BERSERK';
2919 if FKeys
[KEY_UP
].Pressed
then
2921 else if FKeys
[KEY_DOWN
].Pressed
then
2923 g_Frames_Get(id
, st
);
2924 FPunchAnim
:= TAnimation
.Create(id
, False, 1);
2927 procedure TPlayer
.Fire();
2929 f
, DidFire
: Boolean;
2930 wx
, wy
, xd
, yd
: Integer;
2933 if g_Game_IsClient
then Exit
;
2934 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2935 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2943 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2948 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2949 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2950 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
2951 yd
:= wy
+firediry();
2957 if R_BERSERK
in FRulez
then
2959 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2960 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2961 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2964 locobj
.rect
.Width
:= 39;
2965 locobj
.rect
.Height
:= 52;
2966 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2967 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2968 locobj
.Accel
.X
:= xd
-wx
;
2969 locobj
.Accel
.y
:= yd
-wy
;
2971 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2972 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2974 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2976 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
2980 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2984 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2989 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2990 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2992 FSawSoundSelect
.Stop();
2994 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2996 else if not FSawSoundHit
.IsPlaying() then
2998 FSawSoundSelect
.Stop();
2999 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
3002 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3008 if FAmmo
[A_BULLETS
] > 0 then
3010 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
3011 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3012 Dec(FAmmo
[A_BULLETS
]);
3013 FFireAngle
:= FAngle
;
3016 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3017 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3021 if FAmmo
[A_SHELLS
] > 0 then
3023 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3024 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
3025 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3026 Dec(FAmmo
[A_SHELLS
]);
3027 FFireAngle
:= FAngle
;
3031 FShellType
:= SHELL_SHELL
;
3035 if FAmmo
[A_SHELLS
] >= 2 then
3037 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
3038 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3039 Dec(FAmmo
[A_SHELLS
], 2);
3040 FFireAngle
:= FAngle
;
3044 FShellType
:= SHELL_DBLSHELL
;
3048 if FAmmo
[A_BULLETS
] > 0 then
3050 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
3051 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
3052 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3053 Dec(FAmmo
[A_BULLETS
]);
3054 FFireAngle
:= FAngle
;
3057 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3058 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3061 WEAPON_ROCKETLAUNCHER
:
3062 if FAmmo
[A_ROCKETS
] > 0 then
3064 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
3065 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3066 Dec(FAmmo
[A_ROCKETS
]);
3067 FFireAngle
:= FAngle
;
3073 if FAmmo
[A_CELLS
] > 0 then
3075 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
3076 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3077 Dec(FAmmo
[A_CELLS
]);
3078 FFireAngle
:= FAngle
;
3084 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
3086 FBFGFireCounter
:= 17;
3087 if not FNoReload
then
3088 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
3089 Dec(FAmmo
[A_CELLS
], 40);
3093 WEAPON_SUPERPULEMET
:
3094 if FAmmo
[A_SHELLS
] > 0 then
3096 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3097 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
3098 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3099 Dec(FAmmo
[A_SHELLS
]);
3100 FFireAngle
:= FAngle
;
3103 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3104 GameVelX
, GameVelY
-2, SHELL_SHELL
);
3107 WEAPON_FLAMETHROWER
:
3108 if FAmmo
[A_FUEL
] > 0 then
3110 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
3111 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3113 FFireAngle
:= FAngle
;
3119 if g_Game_IsNet
then
3123 if FCurrWeap
<> WEAPON_BFG
then
3124 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
3126 if not FNoReload
then
3127 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
3130 MH_SEND_PlayerStats(FUID
);
3135 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
3136 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
3137 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
3140 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
3143 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
3144 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
3145 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
3146 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
3147 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
3152 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
3154 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
3155 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
3156 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
3159 procedure TPlayer
.JetpackOn
;
3163 FJetSoundOn
.SetPosition(0);
3164 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3168 procedure TPlayer
.JetpackOff
;
3172 FJetSoundOff
.SetPosition(0);
3173 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3176 procedure TPlayer
.CatchFire(Attacker
: Word);
3179 FFireAttacker
:= Attacker
;
3180 if g_Game_IsNet
and g_Game_IsServer
then
3181 MH_SEND_PlayerStats(FUID
);
3184 procedure TPlayer
.Jump();
3186 if gFly
or FJetpack
then
3188 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3189 if FObj
.Vel
.Y
> -VEL_FLY
then
3190 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3193 if FJetFuel
> 0 then
3195 if (FJetFuel
< 1) and g_Game_IsServer
then
3199 if g_Game_IsNet
then
3200 MH_SEND_PlayerStats(FUID
);
3206 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3208 FCanJetpack
:= False;
3210 // Ïðûãàåì èëè âñïëûâàåì:
3211 if (CollideLevel(0, 1) or
3212 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3213 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3214 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3216 FObj
.Vel
.Y
:= -VEL_JUMP
;
3217 FCanJetpack
:= False;
3221 if BodyInLiquid(0, 0) then
3222 FObj
.Vel
.Y
:= -VEL_SW
3223 else if (FJetFuel
> 0) and FCanJetpack
and
3224 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3228 if g_Game_IsNet
then
3229 MH_SEND_PlayerStats(FUID
);
3234 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3236 a
, i
, k
, ab
, ar
: Byte;
3240 srv
, netsrv
: Boolean;
3246 procedure PushItem(t
: Byte);
3250 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3251 it
:= g_Items_ByIdx(id
);
3252 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3254 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3255 (FObj
.Vel
.Y
div 2)-Random(9));
3256 it
.positionChanged(); // this updates spatial accelerators
3260 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3262 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3263 (FObj
.Vel
.Y
div 2)-Random(6));
3265 else // -3..+3; -3..0
3267 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3268 (FObj
.Vel
.Y
div 2)-Random(4));
3270 it
.positionChanged(); // this updates spatial accelerators
3273 if g_Game_IsNet
and g_Game_IsServer
then
3274 MH_SEND_ItemSpawn(True, id
);
3278 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3279 Srv
:= g_Game_IsServer
;
3280 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3281 if Srv
then FDeath
:= FDeath
+ 1;
3286 if not FPhysics
then
3292 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3294 if FLives
> 0 then FLives
:= FLives
- 1;
3295 if FLives
= 0 then FNoRespawn
:= True;
3298 // Íîìåð òèïà ñìåðòè:
3301 K_SIMPLEKILL
: a
:= 1;
3303 K_EXTRAHARDKILL
: a
:= 3;
3308 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3310 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3317 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3319 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3320 K_EXTRAHARDKILL
, K_FALLKILL
:
3321 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3324 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3328 K_HARDKILL
, K_EXTRAHARDKILL
:
3332 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3333 if (KillType
<> K_FALLKILL
) and (Srv
) then
3334 g_Monsters_killedp();
3336 if SpawnerUID
= FUID
then
3338 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3343 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3346 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3347 begin // Óáèò äðóãèì èãðîêîì
3348 KP
:= g_Player_Get(SpawnerUID
);
3349 if (KP
<> nil) and Srv
then
3351 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3352 if SameTeam(FUID
, SpawnerUID
) then
3362 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3363 Inc(gTeamStat
[KP
.Team
].Goals
,
3364 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3366 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3369 plr
:= g_Player_Get(SpawnerUID
);
3377 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3381 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3385 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3390 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3391 begin // Óáèò ìîíñòðîì
3392 mon
:= g_Monsters_ByUID(SpawnerUID
);
3396 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
3400 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3404 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3408 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3413 else // Îñîáûå òèïû ñìåðòè
3416 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3417 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3418 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3419 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3420 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3421 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3427 for a
:= WP_FIRST
to WP_LAST
do
3431 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3432 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3433 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3434 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3435 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3436 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3437 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3438 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3439 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3448 if R_ITEM_BACKPACK
in FRulez
then
3449 PushItem(ITEM_AMMO_BACKPACK
);
3451 // Âûáðîñ ðàêåòíîãî ðàíöà:
3452 if FJetFuel
> 0 then
3453 PushItem(ITEM_JETPACK
);
3456 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3458 if R_KEY_RED
in FRulez
then
3459 PushItem(ITEM_KEY_RED
);
3461 if R_KEY_GREEN
in FRulez
then
3462 PushItem(ITEM_KEY_GREEN
);
3464 if R_KEY_BLUE
in FRulez
then
3465 PushItem(ITEM_KEY_BLUE
);
3472 g_Player_CreateCorpse(Self
);
3474 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3475 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3481 for i
:= Low(gPlayers
) to High(gPlayers
) do
3483 if gPlayers
[i
] = nil then continue
;
3484 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3487 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3488 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3493 OldLR
:= gLMSRespawn
;
3494 if (gGameSettings
.GameMode
= GM_COOP
) then
3498 // everyone is dead, restart the map
3499 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3501 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3502 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3503 gLMSRespawnTime
:= gTime
+ 5000;
3505 else if (a
= 1) then
3507 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3508 if (gPlayers
[k
] = gPlayer1
) or
3509 (gPlayers
[k
] = gPlayer2
) then
3510 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3511 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3512 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3515 else if (gGameSettings
.GameMode
= GM_TDM
) then
3517 if (ab
= 0) and (ar
<> 0) then
3520 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3522 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3523 Inc(gTeamStat
[TEAM_RED
].Goals
);
3524 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3525 gLMSRespawnTime
:= gTime
+ 5000;
3527 else if (ar
= 0) and (ab
<> 0) then
3530 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3532 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3533 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3534 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3535 gLMSRespawnTime
:= gTime
+ 5000;
3537 else if (ar
= 0) and (ab
= 0) then
3540 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3542 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3543 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3544 gLMSRespawnTime
:= gTime
+ 5000;
3547 else if (gGameSettings
.GameMode
= GM_DM
) then
3551 if gPlayers
[k
] <> nil then
3554 // survivor is the winner
3555 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3557 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3560 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3561 gLMSRespawnTime
:= gTime
+ 5000;
3563 else if (a
= 0) then
3565 // everyone is dead, restart the map
3566 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3568 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3569 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3570 gLMSRespawnTime
:= gTime
+ 5000;
3573 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3575 if NetMode
= NET_SERVER
then
3576 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3578 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3584 MH_SEND_PlayerStats(FUID
);
3585 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3586 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3589 if srv
and FNoRespawn
then Spectate(True);
3590 FWantsInGame
:= True;
3593 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3595 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3596 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3599 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3601 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3602 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3605 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3607 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3608 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3609 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3610 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3611 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3612 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3613 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3614 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3617 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3619 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3620 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3621 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3622 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3625 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3627 //if g_Game_IsClient then Exit;
3628 if Weapon
> High(FWeapon
) then Exit
;
3629 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3632 procedure TPlayer
.resetWeaponQueue ();
3635 FNextWeapDelay
:= 0;
3638 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3642 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3643 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
3644 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
3645 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3646 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3647 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3648 else result
:= (weapon
< length(FWeapon
));
3652 // return 255 for "no switch"
3653 function TPlayer
.getNextWeaponIndex (): Byte;
3656 wantThisWeapon
: array[0..64] of Boolean;
3657 weaponOrder
: array[0..16] of Integer; // value: index in `FWeapon`
3659 f
, dir
, cwi
, rwidx
, curlidx
: Integer;
3661 function real2log (ridx
: Integer): Integer;
3667 for f
:= 0 to High(weaponOrder
) do if (weaponOrder
[f
] = ridx
) then begin result
:= f
; exit
; end;
3673 result
:= 255; // default result: "no switch"
3675 // had weapon cycling on previous frame? remove that flag
3676 if (FNextWeap
and $2000) <> 0 then
3678 FNextWeap
:= FNextWeap
and $1FFF;
3679 FNextWeapDelay
:= 0;
3682 for f
:= 0 to High(weaponOrder
) do weaponOrder
[f
] := -1;
3684 // build weapon order (k8: i know, i know, learn how to do constants and such... gtfo, please!)
3685 // two knuckles are for "normal" and "berserk" (see `if` below -- it removes the one that is not needed)
3687 // bfg, launcher, plasma, flamethrower, ssg, minigun, sg, pistol, berserk, chainsaw, fist
3688 weaponOrder
[0] := WEAPON_SUPERPULEMET
;
3689 weaponOrder
[1] := WEAPON_BFG
;
3690 weaponOrder
[2] := WEAPON_ROCKETLAUNCHER
;
3691 weaponOrder
[3] := WEAPON_PLASMA
;
3692 weaponOrder
[4] := WEAPON_FLAMETHROWER
;
3693 weaponOrder
[5] := WEAPON_SHOTGUN2
;
3694 weaponOrder
[6] := WEAPON_CHAINGUN
;
3695 weaponOrder
[7] := WEAPON_SHOTGUN1
;
3696 weaponOrder
[8] := WEAPON_PISTOL
;
3697 weaponOrder
[9] := WEAPON_KASTET
+666; // berserk fist
3698 weaponOrder
[10] := WEAPON_SAW
;
3699 weaponOrder
[11] := WEAPON_KASTET
; // normal fist
3701 for f
:= 0 to High(weaponOrder
) do
3703 if (weaponOrder
[f
] = WEAPON_KASTET
) then
3705 // normal fist: remove if we have a berserk pack
3706 if (R_BERSERK
in FRulez
) then weaponOrder
[f
] := -1;
3709 if (weaponOrder
[f
] = WEAPON_KASTET
+666) then
3711 // berserk fist: remove if we don't have a berserk pack
3712 if (R_BERSERK
in FRulez
) then weaponOrder
[f
] := WEAPON_KASTET
else weaponOrder
[f
] := -1;
3720 WEAPON_SHOTGUN1 = 3;
3721 WEAPON_SHOTGUN2 = 4;
3722 WEAPON_CHAINGUN = 5;
3723 WEAPON_ROCKETLAUNCHER = 6;
3726 WEAPON_SUPERPULEMET = 9;
3727 WEAPON_FLAMETHROWER = 10;
3731 if (FNextWeap <> 0) or (FNextWeapDelay <> 0) then
3733 e_WriteLog(Format('!!! FNextWeap=%04x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), TMsgType.Warning);
3737 // cycling has priority
3738 if (FNextWeap
and $C000) <> 0 then
3740 if (FNextWeap
and $8000) <> 0 then dir
:= 1 else dir
:= -1; // should be reversed if we want "priority-driven cycling"
3741 FNextWeap
:= FNextWeap
or $2000; // we need this
3742 if FNextWeapDelay
> 0 then exit
; // cooldown time
3743 //cwi := real2log(FCurrWeap);
3744 //if (cwi < 0) then cwi := 0;
3746 for i
:= 0 to High(FWeapon
) do
3748 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3749 //rwidx := weaponOrder[cwi];
3750 rwidx
:= cwi
; // sorry
3751 if (rwidx
< 0) then continue
;
3752 if FWeapon
[rwidx
] then
3754 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d (dir=%d; log=%d)', [FCurrWeap, rwidx, dir, cwi]), TMsgType.Warning);
3755 result
:= Byte(rwidx
);
3756 //FNextWeapDelay := 10; //k8: not needed anymore
3765 for i
:= 0 to High(wantThisWeapon
) do wantThisWeapon
[i
] := false;
3768 curlidx
:= -1; // start from a weapon with a highest priority (-1, 'cause loop will immediately increment this index)
3770 for i
:= 0 to High(FWeapon
) do
3772 if (FNextWeap
and (1 shl i
)) <> 0 then
3777 wantThisWeapon
[cwi
] := true;
3779 // if we hit currently selected weapon, start seachring from it, so we'll get "next weaker" weapon
3780 if (i
= FCurrWeap
) then curlidx
:= cwi
; // compare real, start from logical
3785 // slow down alterations a little
3788 // more than one weapon requested, assume "alteration", and check alteration delay
3789 if FNextWeapDelay
> 0 then
3791 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), TMsgType.Warning);
3797 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3798 // but clear all counters if no weapon should be switched
3805 //e_WriteLog(Format('*** wwc=%d; currweap=%d; logweap=%d', [wwc, FCurrWeap, curlidx]), TMsgType.Warning);
3807 // find next weapon to switch onto
3809 for i
:= 0 to High(weaponOrder
) do
3811 cwi
:= (cwi
+length(weaponOrder
)+1) mod length(weaponOrder
);
3812 if (cwi
= curlidx
) then continue
; // skip current weapon
3813 if not wantThisWeapon
[cwi
] then continue
;
3814 rwidx
:= weaponOrder
[cwi
];
3815 if (rwidx
< 0) then continue
;
3816 //e_WriteLog(Format(' trying logical %d (real %d); has=%d, hasammo=%d', [cwi, rwidx, Integer(FWeapon[rwidx]), Integer(hasAmmoForWeapon(rwidx))]), TMsgType.Warning);
3817 if FWeapon
[rwidx
] and ((wwc
= 1) or hasAmmoForWeapon(rwidx
)) then
3819 //e_WriteLog(' I FOUND HER!', TMsgType.Warning);
3821 result
:= Byte(rwidx
);
3823 //FNextWeapDelay := 10; // anyway, 'cause why not; k8: not needed anymore
3828 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3832 procedure TPlayer
.RealizeCurrentWeapon();
3833 function switchAllowed (): Boolean;
3838 if FBFGFireCounter
<> -1 then
3840 if FTime
[T_SWITCH
] > gTime
then
3842 for i
:= WP_FIRST
to WP_LAST
do
3843 if FReloading
[i
] > 0 then
3851 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3852 //FNextWeap := FNextWeap and $1FFF;
3853 //HACK: alteration delay will be reset when player released any weapon switch key
3854 FNextWeapDelay
:= 0; //k8: just in case
3855 //if FNextWeapDelay > 0 then Dec(FNextWeapDelay); // "alteration delay"
3857 if not switchAllowed
then
3859 //writeln('WEAPON SWITCHING IS NOT ALLOWED! FBFGFireCounter=', FBFGFireCounter, '; gTime=', gTime, '; FTime[T_SWITCH]=', FTime[T_SWITCH]);
3860 //HACK for weapon cycling
3861 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3865 if (FNetForceWeapFIdx
>= gTime
+15) then FNetForceWeapFIdx
:= 0;
3867 nw
:= getNextWeaponIndex();
3868 if nw
= 255 then exit
; // don't reset anything here
3869 if nw
> High(FWeapon
) then
3871 // don't forget to reset queue here!
3872 //e_WriteLog(Format(' RealizeCurrentWeapon: WUTAFUUUU?! (%d)', [nw]), TMsgType.Warning);
3879 //k8: emulate this on client immediately, or wait for server confirmation?
3881 if g_Game_IsClient then
3883 FNetForceWeap := nw;
3884 //FNetForceWeapFIdx := FCurrFrameIdx+5; // force for ~5 frames
3885 FNetForceWeapFIdx := gTime+5; // force for ~5 frames
3886 writeln('NETWEAPONSWITCH: fw=', NetForceWeap, '; fwfidx=', NetForceWeapFIdx, '; cfrm=', gTime);
3889 FNetForceWeapFIdx
:= gTime
+5; // force for ~5 frames
3891 if nw
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3892 FModel
.SetWeapon(nw
);
3893 FTime
[T_SWITCH
] := gTime
+156;
3894 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3895 //if g_Game_IsNet and g_Game_IsClient then
3899 procedure TPlayer
.NextWeapon();
3901 //if g_Game_IsClient then Exit;
3905 procedure TPlayer
.PrevWeapon();
3907 //if g_Game_IsClient then Exit;
3911 // used exclusively by network layer
3912 procedure TPlayer
.SetWeaponHost(W
: Byte);
3914 if (W
> High(FWeapon
)) then exit
;
3915 if (not FWeapon
[W
]) then exit
; // server is authority!
3917 if FCurrWeap
<> W
then
3918 if (W
= WEAPON_SAW
) then
3919 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3922 FModel
.SetWeapon(CurrWeap
);
3923 //if g_Game_IsClient then resetWeaponQueue();
3926 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3928 function allowBerserkSwitching (): Boolean;
3930 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3932 if gBerserkAutoswitch
then exit
;
3933 if not conIsCheatsEnabled
then exit
;
3941 if g_Game_IsClient
then Exit
;
3943 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3944 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3949 if FHealth
< PLAYER_HP_SOFT
then
3951 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3955 if gFlash
= 2 then Inc(FPickup
, 5);
3959 if FHealth
< PLAYER_HP_SOFT
then
3961 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3965 if gFlash
= 2 then Inc(FPickup
, 5);
3969 if FArmor
< PLAYER_AP_SOFT
then
3971 FArmor
:= PLAYER_AP_SOFT
;
3974 if gFlash
= 2 then Inc(FPickup
, 5);
3978 if FArmor
< PLAYER_AP_LIMIT
then
3980 FArmor
:= PLAYER_AP_LIMIT
;
3983 if gFlash
= 2 then Inc(FPickup
, 5);
3987 if FHealth
< PLAYER_HP_LIMIT
then
3989 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3993 if gFlash
= 2 then Inc(FPickup
, 5);
3997 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3999 if FHealth
< PLAYER_HP_LIMIT
then
4000 FHealth
:= PLAYER_HP_LIMIT
;
4001 if FArmor
< PLAYER_AP_LIMIT
then
4002 FArmor
:= PLAYER_AP_LIMIT
;
4006 if gFlash
= 2 then Inc(FPickup
, 5);
4010 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
4012 FWeapon
[WEAPON_SAW
] := True;
4014 if gFlash
= 2 then Inc(FPickup
, 5);
4015 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4018 ITEM_WEAPON_SHOTGUN1
:
4019 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
4021 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
4022 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
4024 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4025 FWeapon
[WEAPON_SHOTGUN1
] := 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_SHOTGUN2
:
4032 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
4034 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
4036 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4037 FWeapon
[WEAPON_SHOTGUN2
] := True;
4039 if gFlash
= 2 then Inc(FPickup
, 5);
4040 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4043 ITEM_WEAPON_CHAINGUN
:
4044 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
4046 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
4048 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4049 FWeapon
[WEAPON_CHAINGUN
] := 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');
4055 ITEM_WEAPON_ROCKETLAUNCHER
:
4056 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
4058 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
4060 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
4061 FWeapon
[WEAPON_ROCKETLAUNCHER
] := 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');
4068 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
4070 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
4072 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4073 FWeapon
[WEAPON_PLASMA
] := 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');
4080 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
4082 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
4084 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4085 FWeapon
[WEAPON_BFG
] := 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');
4091 ITEM_WEAPON_SUPERPULEMET
:
4092 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
4094 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
4096 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4097 FWeapon
[WEAPON_SUPERPULEMET
] := True;
4099 if gFlash
= 2 then Inc(FPickup
, 5);
4100 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4103 ITEM_WEAPON_FLAMETHROWER
:
4104 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
4106 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
4108 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4109 FWeapon
[WEAPON_FLAMETHROWER
] := True;
4111 if gFlash
= 2 then Inc(FPickup
, 5);
4112 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4116 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4118 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4121 if gFlash
= 2 then Inc(FPickup
, 5);
4124 ITEM_AMMO_BULLETS_BOX
:
4125 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4127 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4130 if gFlash
= 2 then Inc(FPickup
, 5);
4134 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4136 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4139 if gFlash
= 2 then Inc(FPickup
, 5);
4142 ITEM_AMMO_SHELLS_BOX
:
4143 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4145 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
4148 if gFlash
= 2 then Inc(FPickup
, 5);
4152 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4154 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4157 if gFlash
= 2 then Inc(FPickup
, 5);
4160 ITEM_AMMO_ROCKET_BOX
:
4161 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4163 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
4166 if gFlash
= 2 then Inc(FPickup
, 5);
4170 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4172 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4175 if gFlash
= 2 then Inc(FPickup
, 5);
4179 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4181 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4184 if gFlash
= 2 then Inc(FPickup
, 5);
4188 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4190 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4193 if gFlash
= 2 then Inc(FPickup
, 5);
4197 if not(R_ITEM_BACKPACK
in FRulez
) or
4198 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4199 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4200 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4201 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4202 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
4204 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4205 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4206 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4207 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4208 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4210 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4211 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4212 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4213 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4214 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4215 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4216 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4217 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4219 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
4222 if gFlash
= 2 then Inc(FPickup
, 5);
4226 if not(R_KEY_RED
in FRulez
) then
4228 Include(FRulez
, R_KEY_RED
);
4230 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4231 if gFlash
= 2 then Inc(FPickup
, 5);
4232 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4236 if not(R_KEY_GREEN
in FRulez
) then
4238 Include(FRulez
, R_KEY_GREEN
);
4240 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4241 if gFlash
= 2 then Inc(FPickup
, 5);
4242 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4246 if not(R_KEY_BLUE
in FRulez
) then
4248 Include(FRulez
, R_KEY_BLUE
);
4250 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4251 if gFlash
= 2 then Inc(FPickup
, 5);
4252 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4256 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4258 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4262 if gFlash
= 2 then Inc(FPickup
, 5);
4266 if FAir
< AIR_MAX
then
4271 if gFlash
= 2 then Inc(FPickup
, 5);
4276 if not (R_BERSERK
in FRulez
) then
4278 Include(FRulez
, R_BERSERK
);
4279 if allowBerserkSwitching
then
4281 FCurrWeap
:= WEAPON_KASTET
;
4282 //FNetForceWeap := FCurrWeap;
4284 FModel
.SetWeapon(WEAPON_KASTET
);
4289 if gFlash
= 2 then Inc(FPickup
, 5);
4291 FBerserk
:= gTime
+30000;
4295 //k8:do we need it? if g_Game_IsNet and g_Game_IsServer then MH_SEND_PlayerStats(FUID);
4297 if FHealth
< PLAYER_HP_SOFT
then
4299 FHealth
:= PLAYER_HP_SOFT
;
4300 FBerserk
:= gTime
+30000;
4308 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4310 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4313 if gFlash
= 2 then Inc(FPickup
, 5);
4317 if FHealth
< PLAYER_HP_LIMIT
then
4319 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4323 if gFlash
= 2 then Inc(FPickup
, 5);
4327 if FArmor
< PLAYER_AP_LIMIT
then
4329 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4332 if gFlash
= 2 then Inc(FPickup
, 5);
4336 if FJetFuel
< JET_MAX
then
4338 FJetFuel
:= JET_MAX
;
4341 if gFlash
= 2 then Inc(FPickup
, 5);
4345 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4347 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4350 if gFlash
= 2 then Inc(FPickup
, 5);
4355 procedure TPlayer
.Touch();
4359 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4362 // Áðîñèòü ôëàã òîâàðèùó:
4363 if gGameSettings
.GameMode
= GM_CTF
then
4368 procedure TPlayer
.Push(vx
, vy
: Integer);
4370 if (not FPhysics
) and FGhost
then
4372 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4373 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4374 if g_Game_IsNet
and g_Game_IsServer
then
4375 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4378 procedure TPlayer
.Reset(Force
: Boolean);
4386 FTime
[T_RESPAWN
] := 0;
4387 FTime
[T_FLAGCAP
] := 0;
4398 //FCurrFrameIdx := 0;
4399 //FNetForceWeap := FCurrWeap;
4400 FNetForceWeapFIdx
:= 0;
4404 FSpectator
:= False;
4407 FSpectatePlayer
:= -1;
4408 FNoRespawn
:= False;
4410 FLives
:= gGameSettings
.MaxLives
;
4412 FBFGFireCounter
:= -1;
4413 FTime
[T_SWITCH
] := 0;
4414 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := 0;
4419 procedure TPlayer
.SoftReset();
4427 FBFGFireCounter
:= -1;
4433 FNetForceWeapFIdx
:= 0;
4436 FBFGFireCounter
:= -1;
4437 FTime
[T_SWITCH
] := 0;
4438 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := 0;
4441 SetAction(A_STAND
, True);
4444 function TPlayer
.GetRespawnPoint(): Byte;
4449 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4451 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4452 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4454 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4456 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4457 if Self
= gPlayer1
then
4458 c
:= RESPAWNPOINT_PLAYER1
4460 c
:= RESPAWNPOINT_PLAYER2
;
4461 if g_Map_GetPointCount(c
) > 0 then
4467 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4468 if Self
= gPlayer1
then
4469 c
:= RESPAWNPOINT_PLAYER2
4471 c
:= RESPAWNPOINT_PLAYER1
;
4472 if g_Map_GetPointCount(c
) > 0 then
4479 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4480 if Random(2) = 0 then
4481 c
:= RESPAWNPOINT_PLAYER1
4483 c
:= RESPAWNPOINT_PLAYER2
;
4484 if g_Map_GetPointCount(c
) > 0 then
4491 // Òî÷êà ëþáîé èç êîìàíä
4492 if Random(2) = 0 then
4493 c
:= RESPAWNPOINT_RED
4495 c
:= RESPAWNPOINT_BLUE
;
4496 if g_Map_GetPointCount(c
) > 0 then
4503 c
:= RESPAWNPOINT_DM
;
4504 if g_Map_GetPointCount(c
) > 0 then
4512 if gGameSettings
.GameMode
= GM_DM
then
4515 c
:= RESPAWNPOINT_DM
;
4516 if g_Map_GetPointCount(c
) > 0 then
4522 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4523 if Random(2) = 0 then
4524 c
:= RESPAWNPOINT_PLAYER1
4526 c
:= RESPAWNPOINT_PLAYER2
;
4527 if g_Map_GetPointCount(c
) > 0 then
4533 // Òî÷êà ëþáîé èç êîìàíä
4534 if Random(2) = 0 then
4535 c
:= RESPAWNPOINT_RED
4537 c
:= RESPAWNPOINT_BLUE
;
4538 if g_Map_GetPointCount(c
) > 0 then
4546 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4548 // Òî÷êà ñâîåé êîìàíäû
4549 c
:= RESPAWNPOINT_DM
;
4550 if FTeam
= TEAM_RED
then
4551 c
:= RESPAWNPOINT_RED
;
4552 if FTeam
= TEAM_BLUE
then
4553 c
:= RESPAWNPOINT_BLUE
;
4554 if g_Map_GetPointCount(c
) > 0 then
4561 c
:= RESPAWNPOINT_DM
;
4562 if g_Map_GetPointCount(c
) > 0 then
4568 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4569 if Random(2) = 0 then
4570 c
:= RESPAWNPOINT_PLAYER1
4572 c
:= RESPAWNPOINT_PLAYER2
;
4573 if g_Map_GetPointCount(c
) > 0 then
4579 // Òî÷êà äðóãîé êîìàíäû
4580 c
:= RESPAWNPOINT_DM
;
4581 if FTeam
= TEAM_RED
then
4582 c
:= RESPAWNPOINT_BLUE
;
4583 if FTeam
= TEAM_BLUE
then
4584 c
:= RESPAWNPOINT_RED
;
4585 if g_Map_GetPointCount(c
) > 0 then
4593 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4595 RespawnPoint
: TRespawnPoint
;
4602 FBFGFireCounter
:= -1;
4606 //FNetForceWeap := FCurrWeap;
4607 FNetForceWeapFIdx
:= 0;
4610 FBFGFireCounter
:= -1;
4611 FTime
[T_SWITCH
] := 0;
4612 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := 0;
4614 if not g_Game_IsServer
then
4618 FWantsInGame
:= True;
4619 FJustTeleported
:= True;
4622 FTime
[T_RESPAWN
] := 0;
4626 // if server changes MaxLives we gotta be ready
4627 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4629 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4630 if FTime
[T_RESPAWN
] > gTime
then
4633 // Ïðîñðàë âñå æèçíè:
4636 if not FSpectator
then Spectate(True);
4637 FWantsInGame
:= True;
4641 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4642 begin // "Ñâîÿ èãðà"
4643 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4644 FRulez
:= FRulez
-[R_BERSERK
];
4646 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4648 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4649 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4652 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4653 c
:= GetRespawnPoint();
4658 // Âîñêðåøåíèå áåç îðóæèÿ:
4661 FHealth
:= PLAYER_HP_SOFT
;
4667 for a
:= WP_FIRST
to WP_LAST
do
4669 FWeapon
[a
] := False;
4673 FWeapon
[WEAPON_PISTOL
] := True;
4674 FWeapon
[WEAPON_KASTET
] := True;
4675 FCurrWeap
:= WEAPON_PISTOL
;
4676 //FNetForceWeap := FCurrWeap;
4677 FNetForceWeapFIdx
:= 0;
4680 FModel
.SetWeapon(FCurrWeap
);
4682 for b
:= A_BULLETS
to A_HIGH
do
4685 FAmmo
[A_BULLETS
] := 50;
4687 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4688 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4689 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4690 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4691 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4693 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4694 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4699 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4700 if not g_Map_GetPoint(c
, RespawnPoint
) then
4702 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4706 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4707 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4708 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4714 FDirection
:= RespawnPoint
.Direction
;
4715 if FDirection
= TDirection
.D_LEFT
then
4720 SetAction(A_STAND
, True);
4721 FModel
.Direction
:= FDirection
;
4723 for a
:= Low(FTime
) to High(FTime
) do
4726 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4731 FCanJetpack
:= False;
4736 // Àíèìàöèÿ âîçðîæäåíèÿ:
4737 if (not gLoadGameMode
) and (not Silent
) then
4738 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4740 Anim
:= TAnimation
.Create(ID
, False, 3);
4741 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4742 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4746 FSpectator
:= False;
4749 FSpectatePlayer
:= -1;
4752 if (gPlayer1
= nil) and (gLMSPID1
= FUID
) then
4754 if (gPlayer2
= nil) and (gLMSPID2
= FUID
) then
4757 //FNetForceWeap := FCurrWeap;
4759 if g_Game_IsNet
then
4761 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4762 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4764 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4765 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4770 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4773 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4774 else if (not NoMove
) then
4776 GameX
:= gMapInfo
.Width
div 2;
4777 GameY
:= gMapInfo
.Height
div 2;
4786 FWantsInGame
:= False;
4791 if Self
= gPlayer1
then
4796 if Self
= gPlayer2
then
4803 if g_Game_IsNet
then
4804 MH_SEND_PlayerStats(FUID
);
4807 procedure TPlayer
.SwitchNoClip
;
4811 FGhost
:= not FGhost
;
4812 FPhysics
:= not FGhost
;
4824 procedure TPlayer
.Run(Direction
: TDirection
);
4828 if MAX_RUNVEL
> 8 then
4832 if Direction
= TDirection
.D_LEFT
then
4834 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4835 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4838 if FObj
.Vel
.X
< MAX_RUNVEL
then
4839 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4841 // Âîçìîæíî, ïèíàåì êóñêè:
4842 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4844 b
:= Abs(FObj
.Vel
.X
);
4845 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4846 for a
:= 0 to High(gGibs
) do
4848 if gGibs
[a
].alive
and
4849 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4850 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4853 if FObj
.Vel
.X
< 0 then
4855 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4859 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4861 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4869 procedure TPlayer
.SeeDown();
4871 SetAction(A_SEEDOWN
);
4873 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4875 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4878 procedure TPlayer
.SeeUp();
4882 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4884 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4887 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4895 A_ATTACK
: Prior
:= 2;
4896 A_SEEUP
: Prior
:= 1;
4897 A_SEEDOWN
: Prior
:= 1;
4898 A_ATTACKUP
: Prior
:= 2;
4899 A_ATTACKDOWN
: Prior
:= 2;
4904 if (Prior
> FActionPrior
) or Force
then
4905 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4907 FActionPrior
:= Prior
;
4908 FActionAnim
:= Action
;
4909 FActionForce
:= Force
;
4910 FActionChanged
:= True;
4913 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4916 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4918 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4919 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4920 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4921 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4924 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4931 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4933 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4934 if g_Game_IsServer
and g_Game_IsNet
then
4935 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4939 FJustTeleported
:= True;
4944 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4946 Anim
:= TAnimation
.Create(ID
, False, 3);
4949 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4950 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4951 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4952 if g_Game_IsServer
and g_Game_IsNet
then
4953 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4954 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4958 FObj
.X
:= X
-PLAYER_RECT
.X
;
4959 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4960 if FAlive
and FGhost
then
4966 if not g_Game_IsNet
then
4970 SetDirection(TDirection
.D_LEFT
);
4976 SetDirection(TDirection
.D_RIGHT
);
4982 if FDirection
= TDirection
.D_RIGHT
then
4984 SetDirection(TDirection
.D_LEFT
);
4989 SetDirection(TDirection
.D_RIGHT
);
4995 if not silent
and (Anim
<> nil) then
4997 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4998 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
5001 if g_Game_IsServer
and g_Game_IsNet
then
5002 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
5003 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
5010 function nonz(a
: Single): Single;
5018 function TPlayer
.followCorpse(): Boolean;
5023 if FAlive
or FSpectator
then
5025 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
5027 for i
:= 0 to High(gCorpses
) do
5028 if gCorpses
[i
] <> nil then
5029 if gCorpses
[i
].FPlayerUID
= FUID
then
5032 FObj
.X
:= gCorpses
[i
].FObj
.X
;
5033 FObj
.Y
:= gCorpses
[i
].FObj
.Y
;
5034 FObj
.Vel
.X
:= gCorpses
[i
].FObj
.Vel
.X
;
5035 FObj
.Vel
.Y
:= gCorpses
[i
].FObj
.Vel
.Y
;
5036 FObj
.Accel
.X
:= gCorpses
[i
].FObj
.Accel
.X
;
5037 FObj
.Accel
.Y
:= gCorpses
[i
].FObj
.Accel
.Y
;
5042 procedure TPlayer
.Update();
5045 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
5046 blockmon
, headwater
, dospawn
: Boolean;
5051 //Inc(FCurrFrameIdx);
5053 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
5054 AnyServer
:= g_Game_IsServer
;
5056 if g_Game_IsClient
and (NetInterpLevel
> 0) then
5057 DoLerp(NetInterpLevel
+ 1)
5064 if FClientID
>= 0 then
5066 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
5067 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
5068 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
5078 if FAlive
and (FPunchAnim
<> nil) then
5079 FPunchAnim
.Update();
5081 if FAlive
and (gFly
or FJetpack
) then
5084 if FDirection
= TDirection
.D_LEFT
then
5089 if FAlive
and (not FGhost
) then
5091 if FKeys
[KEY_UP
].Pressed
then
5093 if FKeys
[KEY_DOWN
].Pressed
then
5097 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
5100 i
:= g_basic
.Sign(FIncCam
);
5101 FIncCam
:= Abs(FIncCam
);
5102 DecMin(FIncCam
, 5, 0);
5103 FIncCam
:= FIncCam
*i
;
5106 // no need to do that each second frame, weapon queue will take care of it
5107 if FAlive
and FKeys
[KEY_NEXTWEAPON
].Pressed
{and AnyServer} then NextWeapon();
5108 if FAlive
and FKeys
[KEY_PREVWEAPON
].Pressed
{and AnyServer} then PrevWeapon();
5110 if gTime
mod (GAME_TICK
*2) <> 0 then
5112 if (FObj
.Vel
.X
= 0) and FAlive
then
5114 if FKeys
[KEY_LEFT
].Pressed
then
5115 Run(TDirection
.D_LEFT
);
5116 if FKeys
[KEY_RIGHT
].Pressed
then
5117 Run(TDirection
.D_RIGHT
);
5122 if not followCorpse() then
5123 g_Obj_Move(@FObj
, True, True, True);
5124 positionChanged(); // this updates spatial accelerators
5130 FActionChanged
:= False;
5134 // Let alive player do some actions
5135 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
5136 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
5137 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
5138 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
5139 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
5140 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
5141 if FKeys
[KEY_JUMP
].Pressed
then Jump()
5144 if AnyServer
and FJetpack
then
5148 if NetServer
then MH_SEND_PlayerStats(FUID
);
5150 FCanJetpack
:= True;
5157 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
5159 if FKeys
[k
].Pressed
then
5167 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5170 if (FTime
[T_RESPAWN
] <= gTime
) and
5171 gGameOn
and (not FAlive
) then
5173 if (g_Player_GetCount() > 1) then
5177 gExit
:= EXIT_RESTART
;
5182 // Dead spectator actions
5185 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
5186 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
5190 if (FSpectatePlayer
>= High(gPlayers
)) then
5191 FSpectatePlayer
:= -1
5195 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
5196 if gPlayers
[I
] <> nil then
5197 if gPlayers
[I
].alive
then
5198 if gPlayers
[I
].UID
<> FUID
then
5200 FSpectatePlayer
:= I
;
5205 if not SetSpect
then FSpectatePlayer
:= -1;
5216 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5218 FYTo
:= FObj
.Y
- 32;
5219 FSpectatePlayer
:= -1;
5221 if FKeys
[KEY_DOWN
].Pressed
then
5223 FYTo
:= FObj
.Y
+ 32;
5224 FSpectatePlayer
:= -1;
5226 if FKeys
[KEY_LEFT
].Pressed
then
5228 FXTo
:= FObj
.X
- 32;
5229 FSpectatePlayer
:= -1;
5231 if FKeys
[KEY_RIGHT
].Pressed
then
5233 FXTo
:= FObj
.X
+ 32;
5234 FSpectatePlayer
:= -1;
5237 if (FXTo
< -64) then
5239 else if (FXTo
> gMapInfo
.Width
+ 32) then
5240 FXTo
:= gMapInfo
.Width
+ 32;
5241 if (FYTo
< -72) then
5243 else if (FYTo
> gMapInfo
.Height
+ 32) then
5244 FYTo
:= gMapInfo
.Height
+ 32;
5249 if not followCorpse() then
5250 g_Obj_Move(@FObj
, True, True, True);
5251 positionChanged(); // this updates spatial accelerators
5258 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5259 if gPlayers
[FSpectatePlayer
] <> nil then
5260 if gPlayers
[FSpectatePlayer
].alive
then
5262 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
5263 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
5267 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5268 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5269 PANEL_BLOCKMON
, True);
5270 headwater
:= HeadInLiquid(0, 0);
5272 // Ñîïðîòèâëåíèå âîçäóõà:
5273 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5274 if FObj
.Vel
.X
<> 0 then
5275 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5277 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5278 DecMin(FPain
, 5, 0);
5279 DecMin(FPickup
, 1, 0);
5281 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5283 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5284 FMegaRulez
[MR_SUIT
] := 0;
5285 FMegaRulez
[MR_INVUL
] := 0;
5286 FMegaRulez
[MR_INVIS
] := 0;
5287 Kill(K_FALLKILL
, 0, HIT_FALL
);
5294 if FCurrWeap
= WEAPON_SAW
then
5295 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5296 FSawSoundSelect
.IsPlaying()) then
5297 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5300 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5301 (not FJetSoundOff
.IsPlaying()) then
5303 FJetSoundFly
.SetPosition(0);
5304 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5307 for b
:= WP_FIRST
to WP_LAST
do
5308 if FReloading
[b
] > 0 then
5314 if FShellTimer
> -1 then
5315 if FShellTimer
= 0 then
5317 if FShellType
= SHELL_SHELL
then
5318 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5319 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5320 else if FShellType
= SHELL_DBLSHELL
then
5322 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5323 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5324 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5325 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5328 end else Dec(FShellTimer
);
5330 if (FBFGFireCounter
> -1) then
5331 if FBFGFireCounter
= 0 then
5335 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5336 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5337 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5338 yd
:= wy
+firediry();
5339 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5340 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5341 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5342 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5343 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5346 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5347 FBFGFireCounter
:= -1;
5350 FBFGFireCounter
:= 0
5352 Dec(FBFGFireCounter
);
5354 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5356 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5358 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5361 if (headwater
or blockmon
) then
5367 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5370 else if (FAir
mod 31 = 0) and not blockmon
then
5372 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5373 if Random(2) = 0 then
5374 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5376 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5378 end else if FAir
< AIR_DEF
then
5381 if FFireTime
> 0 then
5383 if BodyInLiquid(0, 0) then
5388 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5390 if FMegaRulez
[MR_SUIT
] = gTime
then
5397 if FFirePainTime
<= 0 then
5399 if g_Game_IsServer
then
5400 Damage(5, FFireAttacker
, 0, 0, HIT_FLAME
);
5401 FFirePainTime
:= 18;
5403 FFirePainTime
:= FFirePainTime
- 1;
5404 FFireTime
:= FFireTime
- 1;
5405 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5406 MH_SEND_PlayerStats(FUID
);
5410 if FDamageBuffer
> 0 then
5412 if FDamageBuffer
>= 9 then
5416 if FDamageBuffer
< 30 then i
:= 9
5417 else if FDamageBuffer
< 100 then i
:= 18
5421 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5422 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5423 FHealth
:= FHealth
-ii
;
5426 FHealth
:= FHealth
+FArmor
;
5431 if FHealth
<= 0 then
5432 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5433 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5434 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5438 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5439 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5440 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5441 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5448 end; // if FAlive then ...
5450 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5452 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5453 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5454 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5455 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5457 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5458 then SetAction(A_STAND
, True);
5460 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5462 for b
:= Low(FKeys
) to High(FKeys
) do
5463 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5467 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5469 x
:= FObj
.X
+PLAYER_RECT
.X
;
5470 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5471 w
:= PLAYER_RECT
.Width
;
5472 h
:= PLAYER_RECT
.Height
;
5476 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5478 if (dx
<> 0) or (dy
<> 0) then
5487 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5489 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5490 FObj
.Y
+PLAYER_RECT
.Y
,
5497 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5499 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5500 FObj
.Y
+PLAYER_RECT
.Y
,
5504 Panel
.Width
, Panel
.Height
);
5507 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5509 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5510 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5511 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5512 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5515 function g_Player_ValidName(Name
: string): Boolean;
5521 if gPlayers
= nil then Exit
;
5523 for a
:= 0 to High(gPlayers
) do
5524 if gPlayers
[a
] <> nil then
5525 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5532 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5536 d
:= FModel
.Direction
;
5538 FModel
.Direction
:= Direction
;
5539 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5541 FDirection
:= Direction
;
5544 function TPlayer
.GetKeys(): Byte;
5548 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5549 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5550 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5552 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5553 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5556 procedure TPlayer
.Use();
5560 if FTime
[T_USE
] > gTime
then Exit
;
5562 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5563 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5565 for a
:= 0 to High(gPlayers
) do
5566 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5567 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5568 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5569 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5571 gPlayers
[a
].Touch();
5572 if g_Game_IsNet
and g_Game_IsServer
then
5573 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5576 FTime
[T_USE
] := gTime
+120;
5579 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5583 WX
, WY
, XD
, YD
: Integer;
5595 if R_BERSERK
in FRulez
then
5597 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5598 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5599 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5602 locobj
.rect
.Width
:= 39;
5603 locobj
.rect
.Height
:= 52;
5604 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5605 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5606 locobj
.Accel
.X
:= xd
-wx
;
5607 locobj
.Accel
.y
:= yd
-wy
;
5609 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5610 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5612 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5616 FPain
:= min(FPain
+ 25, 50);
5618 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5623 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5624 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5626 FSawSoundSelect
.Stop();
5628 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5630 else if not FSawSoundHit
.IsPlaying() then
5632 FSawSoundSelect
.Stop();
5633 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5640 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5641 FFireAngle
:= FAngle
;
5643 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5644 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5649 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5650 FFireAngle
:= FAngle
;
5653 FShellType
:= SHELL_SHELL
;
5658 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5659 FFireAngle
:= FAngle
;
5662 FShellType
:= SHELL_DBLSHELL
;
5667 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5668 FFireAngle
:= FAngle
;
5670 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5671 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5674 WEAPON_ROCKETLAUNCHER
:
5676 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5677 FFireAngle
:= FAngle
;
5683 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5684 FFireAngle
:= FAngle
;
5690 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5691 FFireAngle
:= FAngle
;
5695 WEAPON_SUPERPULEMET
:
5697 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5698 FFireAngle
:= FAngle
;
5700 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5701 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5704 WEAPON_FLAMETHROWER
:
5706 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5707 FFireAngle
:= FAngle
;
5714 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5715 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5716 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5719 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5721 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5722 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5725 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5729 if NetInterpLevel
< 1 then
5739 AX
:= Abs(FXTo
- FObj
.X
);
5740 AY
:= Abs(FYTo
- FObj
.Y
);
5741 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5743 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5748 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5750 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5751 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5752 PANEL_LIFTUP
, False) then Result
:= -1
5754 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5755 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5756 PANEL_LIFTDOWN
, False) then Result
:= 1
5760 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5767 if Flag
= FLAG_NONE
then
5770 if not g_Game_IsServer
then Exit
;
5772 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5773 if (Flag
= FTeam
) and
5774 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5775 (FFlag
<> FLAG_NONE
) then
5777 if FFlag
= FLAG_RED
then
5778 s
:= _lc
[I_PLAYER_FLAG_RED
]
5780 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5782 evtype
:= FLAG_STATE_SCORED
;
5784 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5785 Insert('.', ts
, Length(ts
) + 1 - 3);
5786 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5788 g_Map_ResetFlag(FFlag
);
5789 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5791 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5794 if g_Game_IsNet
then
5796 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5800 gFlags
[FFlag
].CaptureTime
:= 0;
5805 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5806 if (Flag
= FTeam
) and
5807 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5809 if Flag
= FLAG_RED
then
5810 s
:= _lc
[I_PLAYER_FLAG_RED
]
5812 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5814 evtype
:= FLAG_STATE_RETURNED
;
5815 gFlags
[Flag
].CaptureTime
:= 0;
5817 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5819 g_Map_ResetFlag(Flag
);
5820 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5823 if g_Game_IsNet
then
5825 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5831 // Ïîäîáðàë ÷óæîé ôëàã:
5832 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5836 if Flag
= FLAG_RED
then
5837 s
:= _lc
[I_PLAYER_FLAG_RED
]
5839 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5841 evtype
:= FLAG_STATE_CAPTURED
;
5843 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5845 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5847 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5850 if g_Game_IsNet
then
5852 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5858 procedure TPlayer
.SetFlag(Flag
: Byte);
5861 if FModel
<> nil then
5862 FModel
.SetFlag(FFlag
);
5865 function TPlayer
.DropFlag(): Boolean;
5870 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5872 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5873 with gFlags
[FFlag
] do
5877 Direction
:= FDirection
;
5878 State
:= FLAG_STATE_DROPPED
;
5880 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5881 (FObj
.Vel
.Y
div 2)-2+Random(5));
5882 positionChanged(); // this updates spatial accelerators
5884 if FFlag
= FLAG_RED
then
5885 s
:= _lc
[I_PLAYER_FLAG_RED
]
5887 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5889 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5890 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5892 if g_Game_IsNet
then
5893 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5899 procedure TPlayer
.GetSecret();
5904 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5906 Assert(Key
<= High(FKeys
));
5908 FKeys
[Key
].Pressed
:= True;
5909 FKeys
[Key
].Time
:= Time
;
5912 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5914 Result
:= FKeys
[K
].Pressed
;
5917 procedure TPlayer
.ReleaseKeys();
5921 for a
:= Low(FKeys
) to High(FKeys
) do
5923 FKeys
[a
].Pressed
:= False;
5928 procedure TPlayer
.ReleaseKeysNoWeapon();
5932 for a
:= Low(FKeys
) to High(FKeys
) do
5934 if (a
= KEY_PREVWEAPON
) or (a
= KEY_NEXTWEAPON
) then continue
;
5935 FKeys
[a
].Pressed
:= False;
5940 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5944 function TPlayer
.firediry(): Integer;
5946 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5947 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5951 procedure TPlayer
.RememberState();
5955 FSavedState
.Health
:= FHealth
;
5956 FSavedState
.Armor
:= FArmor
;
5957 FSavedState
.Air
:= FAir
;
5958 FSavedState
.JetFuel
:= FJetFuel
;
5959 FSavedState
.CurrWeap
:= FCurrWeap
;
5960 FSavedState
.NextWeap
:= FNextWeap
;
5961 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5964 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5966 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5968 FSavedState
.Rulez
:= FRulez
;
5969 FSavedState
.WaitRecall
:= True;
5972 procedure TPlayer
.RecallState();
5976 if not FSavedState
.WaitRecall
then Exit
;
5978 FHealth
:= FSavedState
.Health
;
5979 FArmor
:= FSavedState
.Armor
;
5980 FAir
:= FSavedState
.Air
;
5981 FJetFuel
:= FSavedState
.JetFuel
;
5982 FCurrWeap
:= FSavedState
.CurrWeap
;
5983 //FNetForceWeap := FCurrWeap;
5984 FNextWeap
:= FSavedState
.NextWeap
;
5985 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5988 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5990 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5992 FRulez
:= FSavedState
.Rulez
;
5993 FSavedState
.WaitRecall
:= False;
5995 if gGameSettings
.GameType
= GT_SERVER
then
5996 MH_SEND_PlayerStats(FUID
);
5999 procedure TPlayer
.SaveState (st
: TStream
);
6005 utils
.writeSign(st
, 'PLYR');
6006 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
6008 utils
.writeBool(st
, FIamBot
);
6010 utils
.writeInt(st
, Word(FUID
));
6012 utils
.writeStr(st
, FName
);
6014 utils
.writeInt(st
, Byte(FTeam
));
6016 utils
.writeBool(st
, FAlive
);
6017 // Èçðàñõîäîâàë ëè âñå æèçíè
6018 utils
.writeBool(st
, FNoRespawn
);
6020 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
6021 utils
.writeInt(st
, Byte(b
));
6023 utils
.writeInt(st
, LongInt(FHealth
));
6025 utils
.writeInt(st
, Byte(FLives
));
6027 utils
.writeInt(st
, LongInt(FArmor
));
6029 utils
.writeInt(st
, LongInt(FAir
));
6031 utils
.writeInt(st
, LongInt(FJetFuel
));
6033 utils
.writeInt(st
, LongInt(FPain
));
6035 utils
.writeInt(st
, LongInt(FKills
));
6037 utils
.writeInt(st
, LongInt(FMonsterKills
));
6039 utils
.writeInt(st
, LongInt(FFrags
));
6041 utils
.writeInt(st
, Byte(FFragCombo
));
6042 // Âðåìÿ ïîñëåäíåãî ôðàãà
6043 utils
.writeInt(st
, LongWord(FLastFrag
));
6045 utils
.writeInt(st
, LongInt(FDeath
));
6047 utils
.writeInt(st
, Byte(FFlag
));
6049 utils
.writeInt(st
, LongInt(FSecrets
));
6051 utils
.writeInt(st
, Byte(FCurrWeap
));
6053 utils
.writeInt(st
, Word(FNextWeap
));
6055 utils
.writeInt(st
, Byte(FNextWeapDelay
));
6056 // Âðåìÿ çàðÿäêè BFG
6057 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
6059 utils
.writeInt(st
, LongInt(FDamageBuffer
));
6060 // Ïîñëåäíèé óäàðèâøèé
6061 utils
.writeInt(st
, Word(FLastSpawnerUID
));
6062 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6063 utils
.writeInt(st
, Byte(FLastHit
));
6065 Obj_SaveState(st
, @FObj
);
6066 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6067 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
6068 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6069 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
6071 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
6072 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6073 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
6075 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
6076 // Íàëè÷èå êðàñíîãî êëþ÷à
6077 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
6078 // Íàëè÷èå çåëåíîãî êëþ÷à
6079 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
6080 // Íàëè÷èå ñèíåãî êëþ÷à
6081 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
6083 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
6084 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6085 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
6086 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6087 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
6089 utils
.writeStr(st
, FModel
.Name
);
6091 utils
.writeInt(st
, Byte(FColor
.R
));
6092 utils
.writeInt(st
, Byte(FColor
.G
));
6093 utils
.writeInt(st
, Byte(FColor
.B
));
6097 procedure TPlayer
.LoadState (st
: TStream
);
6106 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
6107 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
6109 FIamBot
:= utils
.readBool(st
);
6111 FUID
:= utils
.readWord(st
);
6113 str
:= utils
.readStr(st
);
6114 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
6116 FTeam
:= utils
.readByte(st
);
6118 FAlive
:= utils
.readBool(st
);
6119 // Èçðàñõîäîâàë ëè âñå æèçíè
6120 FNoRespawn
:= utils
.readBool(st
);
6122 b
:= utils
.readByte(st
);
6123 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
6125 FHealth
:= utils
.readLongInt(st
);
6127 FLives
:= utils
.readByte(st
);
6129 FArmor
:= utils
.readLongInt(st
);
6131 FAir
:= utils
.readLongInt(st
);
6133 FJetFuel
:= utils
.readLongInt(st
);
6135 FPain
:= utils
.readLongInt(st
);
6137 FKills
:= utils
.readLongInt(st
);
6139 FMonsterKills
:= utils
.readLongInt(st
);
6141 FFrags
:= utils
.readLongInt(st
);
6143 FFragCombo
:= utils
.readByte(st
);
6144 // Âðåìÿ ïîñëåäíåãî ôðàãà
6145 FLastFrag
:= utils
.readLongWord(st
);
6147 FDeath
:= utils
.readLongInt(st
);
6149 FFlag
:= utils
.readByte(st
);
6151 FSecrets
:= utils
.readLongInt(st
);
6153 FCurrWeap
:= utils
.readByte(st
);
6154 //FNetForceWeap := FCurrWeap;
6156 FNextWeap
:= utils
.readWord(st
);
6158 FNextWeapDelay
:= utils
.readByte(st
);
6159 // Âðåìÿ çàðÿäêè BFG
6160 FBFGFireCounter
:= utils
.readSmallInt(st
);
6162 FDamageBuffer
:= utils
.readLongInt(st
);
6163 // Ïîñëåäíèé óäàðèâøèé
6164 FLastSpawnerUID
:= utils
.readWord(st
);
6165 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6166 FLastHit
:= utils
.readByte(st
);
6168 Obj_LoadState(@FObj
, st
);
6169 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6170 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
6171 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6172 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
6174 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
6175 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6176 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
6178 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
6179 // Íàëè÷èå êðàñíîãî êëþ÷à
6180 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
6181 // Íàëè÷èå çåëåíîãî êëþ÷à
6182 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
6183 // Íàëè÷èå ñèíåãî êëþ÷à
6184 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
6186 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
6187 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6188 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
6189 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6190 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
6192 str
:= utils
.readStr(st
);
6194 FColor
.R
:= utils
.readByte(st
);
6195 FColor
.G
:= utils
.readByte(st
);
6196 FColor
.B
:= utils
.readByte(st
);
6197 if (self
= gPlayer1
) then
6199 str
:= gPlayer1Settings
.Model
;
6200 FColor
:= gPlayer1Settings
.Color
;
6202 else if (self
= gPlayer2
) then
6204 str
:= gPlayer2Settings
.Model
;
6205 FColor
:= gPlayer2Settings
.Color
;
6207 // Îáíîâëÿåì ìîäåëü èãðîêà
6209 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
6210 FModel
.Color
:= TEAMCOLOR
[FTeam
]
6212 FModel
.Color
:= FColor
;
6216 procedure TPlayer
.AllRulez(Health
: Boolean);
6222 FHealth
:= PLAYER_HP_LIMIT
;
6223 FArmor
:= PLAYER_AP_LIMIT
;
6227 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
6228 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
6229 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6232 procedure TPlayer
.RestoreHealthArmor();
6234 FHealth
:= PLAYER_HP_LIMIT
;
6235 FArmor
:= PLAYER_AP_LIMIT
;
6238 procedure TPlayer
.FragCombo();
6242 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6244 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6246 if FFragCombo
< 5 then
6248 Param
:= FUID
or (FFragCombo
shl 16);
6249 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6250 (FComboEvnt
<= High(gDelayedEvents
)) and
6251 gDelayedEvents
[FComboEvnt
].Pending
and
6252 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6253 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6255 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6256 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6259 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6267 procedure TPlayer
.GiveItem(ItemType
: Byte);
6271 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6273 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6277 if FAir
< AIR_MAX
then
6284 if not (R_BERSERK
in FRulez
) then
6286 Include(FRulez
, R_BERSERK
);
6287 if FBFGFireCounter
< 1 then
6289 FCurrWeap
:= WEAPON_KASTET
;
6290 //FNetForceWeap := FCurrWeap;
6291 FNetForceWeapFIdx
:= 0;
6293 FModel
.SetWeapon(WEAPON_KASTET
);
6297 FBerserk
:= gTime
+30000;
6299 if FHealth
< PLAYER_HP_SOFT
then
6301 FHealth
:= PLAYER_HP_SOFT
;
6302 FBerserk
:= gTime
+30000;
6307 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6309 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6313 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6315 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6319 if FJetFuel
< JET_MAX
then
6321 FJetFuel
:= JET_MAX
;
6324 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6325 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6327 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6328 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6330 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6332 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6334 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6335 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6338 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6339 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6340 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6341 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6342 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6343 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6344 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6345 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6346 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6348 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6349 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6350 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6351 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6352 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6353 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6354 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6355 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6356 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6359 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6360 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6361 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6362 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6363 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6365 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6366 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6367 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6368 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6369 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6371 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6372 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6373 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6374 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6376 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6379 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6380 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6381 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6383 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6384 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6389 if g_Game_IsNet
and g_Game_IsServer
then
6390 MH_SEND_PlayerStats(FUID
);
6393 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6398 if (Random(5) = 1) and (Times
= 1) then
6401 if BodyInLiquid(0, 0) then
6403 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6404 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6405 if Random(2) = 0 then
6406 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6408 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6412 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6414 for i
:= 1 to Times
do
6416 Anim
:= TAnimation
.Create(id
, False, 3);
6418 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6419 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6425 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6430 if (Random(10) = 1) and (Times
= 1) then
6433 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6435 for i
:= 1 to Times
do
6437 Anim
:= TAnimation
.Create(id
, False, 3);
6439 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6440 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6446 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6448 FSawSound
.Pause(Enable
);
6449 FSawSoundIdle
.Pause(Enable
);
6450 FSawSoundHit
.Pause(Enable
);
6451 FSawSoundSelect
.Pause(Enable
);
6456 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6461 FObj
.Rect
:= PLAYER_CORPSERECT
;
6462 FModelName
:= ModelName
;
6467 FState
:= CORPSE_STATE_MESS
;
6468 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6472 FState
:= CORPSE_STATE_NORMAL
;
6473 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6477 destructor TCorpse
.Destroy();
6484 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6486 procedure TCorpse
.positionChanged (); inline; begin end;
6488 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6490 if (dx
<> 0) or (dy
<> 0) then
6499 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6501 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6502 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6503 w
:= PLAYER_CORPSERECT
.Width
;
6504 h
:= PLAYER_CORPSERECT
.Height
;
6508 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6513 if FState
= CORPSE_STATE_REMOVEME
then
6516 FDamage
:= FDamage
+ Value
;
6518 if FDamage
> 150 then
6520 if FAnimation
<> nil then
6525 FState
:= CORPSE_STATE_REMOVEME
;
6527 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6528 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6529 FModelName
, FColor
);
6530 // Çâóê ìÿñà îò òðóïà:
6531 pm
:= g_PlayerModel_Get(FModelName
);
6532 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6536 if (gBodyKillEvent
<> -1)
6537 and gDelayedEvents
[gBodyKillEvent
].Pending
then
6538 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
6539 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, 0);
6544 Blood
:= g_PlayerModel_GetBlood(FModelName
);
6545 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6546 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6547 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6548 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6549 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6550 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
6554 procedure TCorpse
.Draw();
6556 if FState
= CORPSE_STATE_REMOVEME
then
6559 if FAnimation
<> nil then
6560 FAnimation
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6562 if FAnimationMask
<> nil then
6565 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6572 procedure TCorpse
.Update();
6576 if FState
= CORPSE_STATE_REMOVEME
then
6579 if gTime
mod (GAME_TICK
*2) <> 0 then
6581 g_Obj_Move(@FObj
, True, True, True);
6582 positionChanged(); // this updates spatial accelerators
6586 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6587 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6589 st
:= g_Obj_Move(@FObj
, True, True, True);
6590 positionChanged(); // this updates spatial accelerators
6592 if WordBool(st
and MOVE_FALLOUT
) then
6594 FState
:= CORPSE_STATE_REMOVEME
;
6598 if FAnimation
<> nil then
6599 FAnimation
.Update();
6600 if FAnimationMask
<> nil then
6601 FAnimationMask
.Update();
6605 procedure TCorpse
.SaveState (st
: TStream
);
6612 utils
.writeSign(st
, 'CORP');
6613 utils
.writeInt(st
, Byte(0));
6615 utils
.writeInt(st
, Byte(FState
));
6617 utils
.writeInt(st
, Byte(FDamage
));
6619 utils
.writeInt(st
, Byte(FColor
.R
));
6620 utils
.writeInt(st
, Byte(FColor
.G
));
6621 utils
.writeInt(st
, Byte(FColor
.B
));
6623 Obj_SaveState(st
, @FObj
);
6624 utils
.writeInt(st
, Word(FPlayerUID
));
6626 anim
:= (FAnimation
<> nil);
6627 utils
.writeBool(st
, anim
);
6628 // Åñëè åñòü - ñîõðàíÿåì
6629 if anim
then FAnimation
.SaveState(st
);
6630 // Åñòü ëè ìàñêà àíèìàöèè
6631 anim
:= (FAnimationMask
<> nil);
6632 utils
.writeBool(st
, anim
);
6633 // Åñëè åñòü - ñîõðàíÿåì
6634 if anim
then FAnimationMask
.SaveState(st
);
6638 procedure TCorpse
.LoadState (st
: TStream
);
6645 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6646 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6648 FState
:= utils
.readByte(st
);
6650 FDamage
:= utils
.readByte(st
);
6652 FColor
.R
:= utils
.readByte(st
);
6653 FColor
.G
:= utils
.readByte(st
);
6654 FColor
.B
:= utils
.readByte(st
);
6656 Obj_LoadState(@FObj
, st
);
6657 FPlayerUID
:= utils
.readWord(st
);
6659 anim
:= utils
.readBool(st
);
6660 // Åñëè åñòü - çàãðóæàåì
6663 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6664 FAnimation
.LoadState(st
);
6666 // Åñòü ëè ìàñêà àíèìàöèè
6667 anim
:= utils
.readBool(st
);
6668 // Åñëè åñòü - çàãðóæàåì
6671 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6672 FAnimationMask
.LoadState(st
);
6678 constructor TBot
.Create();
6685 FSpectator
:= False;
6692 for a
:= WP_FIRST
to WP_LAST
do
6694 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6695 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6696 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6700 destructor TBot
.Destroy();
6703 inherited Destroy();
6706 procedure TBot
.Draw();
6710 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6711 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6714 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6716 inherited Respawn(Silent
, Force
);
6719 FSelectedWeapon
:= FCurrWeap
;
6720 FNetForceWeapFIdx
:= 0;
6725 procedure TBot
.UpdateCombat();
6738 TTargetRecord
= array of TTarget
;
6740 function Compare(a
, b
: TTarget
): Integer;
6742 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6745 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6747 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6748 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6750 if a
.Dist
> b
.Dist
then // B áëèæå
6752 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6755 else // Ñòðàííî -> A
6760 a
, x1
, y1
, x2
, y2
: Integer;
6761 targets
: TTargetRecord
;
6763 Target
, BestTarget
: TTarget
;
6764 firew
, fireh
: Integer;
6768 vsPlayer
, vsMonster
, ok
: Boolean;
6771 function monsUpdate (mon
: TMonster
): Boolean;
6773 result
:= false; // don't stop
6774 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6776 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6778 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6779 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6781 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6782 if g_TraceVector(x1
, y1
, x2
, y2
) then
6784 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6785 SetLength(targets
, Length(targets
)+1);
6786 with targets
[High(targets
)] do
6793 Rect
:= mon
.Obj
.Rect
;
6794 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6795 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6796 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6805 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6806 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6808 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6809 if FCurrWeap
<> FSelectedWeapon
then
6812 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6813 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6815 RemoveAIFlag('NEEDFIRE');
6818 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6819 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6820 else PressKey(KEY_FIRE
);
6824 // Êîîðäèíàòû ñòâîëà:
6825 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6826 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6828 Target
.UID
:= FTargetUID
;
6831 if Target
.UID
<> 0 then
6832 begin // Öåëü åñòü - íàñòðàèâàåì
6833 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6836 tpla
:= g_Player_Get(Target
.UID
);
6840 if (@FObj
) <> nil then
6847 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6848 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6849 Target
.Rect
:= PLAYER_RECT
;
6850 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6851 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6852 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6853 Target
.IsPlayer
:= True;
6857 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6860 mon
:= g_Monsters_ByUID(Target
.UID
);
6863 Target
.X
:= mon
.Obj
.X
;
6864 Target
.Y
:= mon
.Obj
.Y
;
6866 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6867 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6868 Target
.Rect
:= mon
.Obj
.Rect
;
6869 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6870 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6871 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6872 Target
.IsPlayer
:= False;
6879 begin // Öåëè íåò - îáíóëÿåì
6884 Target
.Visible
:= False;
6885 Target
.Line
:= False;
6886 Target
.IsPlayer
:= False;
6891 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6892 if (not Target
.Line
) or (not Target
.Visible
) then
6896 for a
:= 0 to High(gPlayers
) do
6897 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6898 (gPlayers
[a
].FUID
<> FUID
) and
6899 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6900 (not gPlayers
[a
].NoTarget
) and
6901 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6903 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6904 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6907 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6908 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6910 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6911 if g_TraceVector(x1
, y1
, x2
, y2
) then
6913 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6914 SetLength(targets
, Length(targets
)+1);
6915 with targets
[High(targets
)] do
6917 UID
:= gPlayers
[a
].FUID
;
6918 X
:= gPlayers
[a
].FObj
.X
;
6919 Y
:= gPlayers
[a
].FObj
.Y
;
6922 Rect
:= PLAYER_RECT
;
6923 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6924 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6925 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6933 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6936 // Åñëè åñòü âîçìîæíûå öåëè:
6937 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6938 if targets
<> nil then
6940 // Âûáèðàåì íàèëó÷øóþ öåëü:
6941 BestTarget
:= targets
[0];
6942 if Length(targets
) > 1 then
6943 for a
:= 1 to High(targets
) do
6944 if Compare(BestTarget
, targets
[a
]) = 1 then
6945 BestTarget
:= targets
[a
];
6947 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6948 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6949 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6951 Target
:= BestTarget
;
6953 if (Healthy() = 3) or ((Healthy() = 2)) then
6954 begin // Åñëè çäîðîâû - äîãîíÿåì
6955 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6956 SetAIFlag('GORIGHT', '1');
6957 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6958 SetAIFlag('GOLEFT', '1');
6961 begin // Åñëè ïîáèòû - óáåãàåì
6962 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6963 SetAIFlag('GORIGHT', '1');
6964 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6965 SetAIFlag('GOLEFT', '1');
6968 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6969 SelectWeapon(Abs(x1
-Target
.cX
));
6974 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6975 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6976 if Target
.UID
<> 0 then
6978 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6979 Target
.Y
+ Target
.Rect
.Y
) then
6980 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6981 if (Healthy() = 3) or ((Healthy() = 2)) then
6982 begin // Åñëè çäîðîâû - äîãîíÿåì
6983 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6984 SetAIFlag('GORIGHT', '1');
6985 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6986 SetAIFlag('GOLEFT', '1');
6989 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6991 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6992 SetAIFlag('GORIGHT', '1');
6993 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6994 SetAIFlag('GOLEFT', '1');
6998 begin // Öåëü ïîêà íà "ýêðàíå"
6999 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
7000 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7001 FLastVisible
:= gTime
;
7002 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
7003 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
7005 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
7006 SetAIFlag('GORIGHT', '1');
7007 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
7008 SetAIFlag('GOLEFT', '1');
7012 // Âûáèðàåì óãîë ââåðõ:
7013 if FDirection
= TDirection
.D_LEFT
then
7014 angle
:= ANGLE_LEFTUP
7016 angle
:= ANGLE_RIGHTUP
;
7018 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7019 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7021 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7022 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7023 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
7024 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7025 Target
.Rect
.Width
, Target
.Rect
.Height
) and
7026 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7027 begin // òî íóæíî ñòðåëÿòü ââåðõ
7028 SetAIFlag('NEEDFIRE', '1');
7029 SetAIFlag('NEEDSEEUP', '1');
7032 // Âûáèðàåì óãîë âíèç:
7033 if FDirection
= TDirection
.D_LEFT
then
7034 angle
:= ANGLE_LEFTDOWN
7036 angle
:= ANGLE_RIGHTDOWN
;
7038 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7039 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7041 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7042 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7043 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7044 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7045 Target
.Rect
.Width
, Target
.Rect
.Height
) and
7046 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7047 begin // òî íóæíî ñòðåëÿòü âíèç
7048 SetAIFlag('NEEDFIRE', '1');
7049 SetAIFlag('NEEDSEEDOWN', '1');
7052 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
7053 if Target
.Visible
and
7054 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
7055 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
7057 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
7058 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
7059 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
7060 begin // òî íóæíî ñòðåëÿòü âïåðåä
7061 SetAIFlag('NEEDFIRE', '1');
7062 SetAIFlag('NEEDSEEDOWN', '');
7063 SetAIFlag('NEEDSEEUP', '');
7065 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
7066 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
7067 if GetRnd(FDifficult
.CloseJump
) then
7068 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
7069 if Abs(FObj
.X
-Target
.X
) < 128 then
7073 if Random(a
) = 0 then
7074 SetAIFlag('NEEDJUMP', '1');
7078 // Åñëè öåëü âñå åùå åñòü:
7079 if Target
.UID
<> 0 then
7080 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
7081 Target
.UID
:= 0 // òî çàáûòü öåëü
7082 else // Åñëè âèäåëè íåäàâíî
7083 begin // íî öåëü óáèëè
7084 if Target
.IsPlayer
then
7085 begin // Öåëü - èãðîê
7086 pla
:= g_Player_Get(Target
.UID
);
7087 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
7088 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
7089 Target
.UID
:= 0; // òî çàáûòü öåëü
7092 begin // Öåëü - ìîíñòð
7093 mon
:= g_Monsters_ByUID(Target
.UID
);
7094 if (mon
= nil) or (not mon
.alive
) then
7095 Target
.UID
:= 0; // òî çàáûòü öåëü
7098 end; // if Target.UID <> 0
7100 FTargetUID
:= Target
.UID
;
7102 // Åñëè âîçìîæíûõ öåëåé íåò:
7103 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
7104 if targets
= nil then
7105 if GetAIFlag('ATTACKLEFT') <> '' then
7106 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
7107 RemoveAIFlag('ATTACKLEFT');
7109 SetAIFlag('NEEDJUMP', '1');
7111 if RunDirection() = TDirection
.D_RIGHT
then
7112 begin // Èäåì íå â òó ñòîðîíó
7113 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7114 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
7115 SetAIFlag('NEEDFIRE', '1');
7116 SetAIFlag('GOLEFT', '1');
7120 begin // Èäåì â íóæíóþ ñòîðîíó
7121 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7122 SetAIFlag('NEEDFIRE', '1');
7123 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7124 SetAIFlag('GORIGHT', '1');
7128 if GetAIFlag('ATTACKRIGHT') <> '' then
7129 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
7130 RemoveAIFlag('ATTACKRIGHT');
7132 SetAIFlag('NEEDJUMP', '1');
7134 if RunDirection() = TDirection
.D_LEFT
then
7135 begin // Èäåì íå â òó ñòîðîíó
7136 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7137 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
7138 SetAIFlag('NEEDFIRE', '1');
7139 SetAIFlag('GORIGHT', '1');
7144 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7145 SetAIFlag('NEEDFIRE', '1');
7146 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7147 SetAIFlag('GOLEFT', '1');
7151 //HACK! (does it belong there?)
7152 RealizeCurrentWeapon();
7154 // Åñëè åñòü âîçìîæíûå öåëè:
7155 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7156 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7157 for a
:= 0 to High(targets
) do
7159 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7160 if GetRnd(FDifficult
.DiagFire
) then
7162 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7163 if FDirection
= TDirection
.D_LEFT
then
7164 angle
:= ANGLE_LEFTUP
7166 angle
:= ANGLE_RIGHTUP
;
7168 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7169 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7171 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7172 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7173 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7174 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7175 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7177 SetAIFlag('NEEDFIRE', '1');
7178 SetAIFlag('NEEDSEEUP', '1');
7181 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7182 if FDirection
= TDirection
.D_LEFT
then
7183 angle
:= ANGLE_LEFTDOWN
7185 angle
:= ANGLE_RIGHTDOWN
;
7187 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7188 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7190 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7191 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7192 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7193 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7194 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7196 SetAIFlag('NEEDFIRE', '1');
7197 SetAIFlag('NEEDSEEDOWN', '1');
7201 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7202 if targets
[a
].Line
and targets
[a
].Visible
and
7203 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
7204 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
7206 SetAIFlag('NEEDFIRE', '1');
7211 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7212 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
7213 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
7214 40+GetInterval(FDifficult
.Cover
, 40)) then
7215 SetAIFlag('NEEDJUMP', '1');
7217 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7218 ammo
:= GetAmmoByWeapon(FCurrWeap
);
7219 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
7220 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
7222 SetAIFlag('SELECTWEAPON', '1');
7224 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7225 if GetAIFlag('SELECTWEAPON') = '1' then
7228 RemoveAIFlag('SELECTWEAPON');
7232 procedure TBot
.Update();
7245 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7246 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7248 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7250 if g_debug_BotAIOff
= 3 then
7260 RealizeCurrentWeapon();
7267 procedure TBot
.ReleaseKey(Key
: Byte);
7276 function TBot
.KeyPressed(Key
: Word): Boolean;
7278 Result
:= FKeys
[Key
].Pressed
;
7281 function TBot
.GetAIFlag(aName
: String20
): String20
;
7287 aName
:= LowerCase(aName
);
7289 if FAIFlags
<> nil then
7290 for a
:= 0 to High(FAIFlags
) do
7291 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7293 Result
:= FAIFlags
[a
].Value
;
7298 procedure TBot
.RemoveAIFlag(aName
: String20
);
7302 if FAIFlags
= nil then Exit
;
7304 aName
:= LowerCase(aName
);
7306 for a
:= 0 to High(FAIFlags
) do
7307 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7309 if a
<> High(FAIFlags
) then
7310 for b
:= a
to High(FAIFlags
)-1 do
7311 FAIFlags
[b
] := FAIFlags
[b
+1];
7313 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7318 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7326 aName
:= LowerCase(aName
);
7328 if FAIFlags
<> nil then
7329 for a
:= 0 to High(FAIFlags
) do
7330 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7336 if ok
then FAIFlags
[a
].Value
:= fValue
7339 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7340 with FAIFlags
[High(FAIFlags
)] do
7348 procedure TBot
.UpdateMove
;
7350 procedure GoLeft(Time
: Word = 1);
7352 ReleaseKey(KEY_LEFT
);
7353 ReleaseKey(KEY_RIGHT
);
7354 PressKey(KEY_LEFT
, Time
);
7355 SetDirection(TDirection
.D_LEFT
);
7358 procedure GoRight(Time
: Word = 1);
7360 ReleaseKey(KEY_LEFT
);
7361 ReleaseKey(KEY_RIGHT
);
7362 PressKey(KEY_RIGHT
, Time
);
7363 SetDirection(TDirection
.D_RIGHT
);
7366 function Rnd(a
: Word): Boolean;
7368 Result
:= Random(a
) = 0;
7371 procedure Turn(Time
: Word = 1200);
7373 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7378 ReleaseKey(KEY_LEFT
);
7379 ReleaseKey(KEY_RIGHT
);
7382 function CanRunLeft(): Boolean;
7384 Result
:= not CollideLevel(-1, 0);
7387 function CanRunRight(): Boolean;
7389 Result
:= not CollideLevel(1, 0);
7392 function CanRun(): Boolean;
7394 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7397 procedure Jump(Time
: Word = 30);
7399 PressKey(KEY_JUMP
, Time
);
7402 function NearHole(): Boolean;
7406 { TODO 5 : Ëåñòíèöû }
7407 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7408 for x
:= 1 to PLAYER_RECT
.Width
do
7409 if (not StayOnStep(x
*sx
, 0)) and
7410 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7411 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7420 function BorderHole(): Boolean;
7424 { TODO 5 : Ëåñòíèöû }
7425 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7426 for x
:= 1 to PLAYER_RECT
.Width
do
7427 if (not StayOnStep(x
*sx
, 0)) and
7428 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7429 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7431 for xx
:= x
to x
+32 do
7432 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7442 function NearDeepHole(): Boolean;
7448 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7451 for x
:= 1 to PLAYER_RECT
.Width
do
7452 if (not StayOnStep(x
*sx
, 0)) and
7453 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7454 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7456 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7458 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7463 end else Result
:= False;
7466 function OverDeepHole(): Boolean;
7473 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7475 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7482 function OnGround(): Boolean;
7484 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7487 function OnLadder(): Boolean;
7489 Result
:= FullInStep(0, 0);
7492 function BelowLadder(): Boolean;
7494 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7495 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7496 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7497 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7500 function BelowLiftUp(): Boolean;
7502 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7503 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7504 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7505 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7508 function OnTopLift(): Boolean;
7510 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7513 function CanJumpOver(): Boolean;
7517 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7521 if not CollideLevel(sx
, 0) then Exit
;
7523 for y
:= 1 to BOT_MAXJUMP
do
7524 if CollideLevel(0, -y
) then Exit
else
7525 if not CollideLevel(sx
, -y
) then
7532 function CanJumpUp(Dist
: ShortInt): Boolean;
7539 if CollideLevel(Dist
, 0) then Exit
;
7542 for y
:= 0 to BOT_MAXJUMP
do
7543 if CollideLevel(Dist
, -y
) then
7552 for yy
:= y
+1 to BOT_MAXJUMP
do
7553 if not CollideLevel(Dist
, -yy
) then
7562 for y
:= 0 to BOT_MAXJUMP
do
7563 if CollideLevel(0, -y
) then
7571 if y
< yy
then Exit
;
7576 function IsSafeTrigger(): Boolean;
7581 if gTriggers
= nil then
7583 for a
:= 0 to High(gTriggers
) do
7584 if Collide(gTriggers
[a
].X
,
7587 gTriggers
[a
].Height
) and
7588 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7589 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7590 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7591 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7592 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7597 // Âîçìîæíî, íàæèìàåì êíîïêó:
7598 if Rnd(16) and IsSafeTrigger() then
7601 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7602 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7604 ReleaseKey(KEY_LEFT
);
7605 ReleaseKey(KEY_RIGHT
);
7609 // Èäåì âëåâî, åñëè íàäî áûëî:
7610 if GetAIFlag('GOLEFT') <> '' then
7612 RemoveAIFlag('GOLEFT');
7613 if CanRunLeft() then
7617 // Èäåì âïðàâî, åñëè íàäî áûëî:
7618 if GetAIFlag('GORIGHT') <> '' then
7620 RemoveAIFlag('GORIGHT');
7621 if CanRunRight() then
7625 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7626 if FObj
.X
< -32 then
7629 if FObj
.X
+32 > gMapInfo
.Width
then
7632 // Ïðûãàåì, åñëè íàäî áûëî:
7633 if GetAIFlag('NEEDJUMP') <> '' then
7636 RemoveAIFlag('NEEDJUMP');
7639 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7640 if GetAIFlag('NEEDSEEUP') <> '' then
7643 ReleaseKey(KEY_DOWN
);
7644 PressKey(KEY_UP
, 20);
7645 RemoveAIFlag('NEEDSEEUP');
7648 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7649 if GetAIFlag('NEEDSEEDOWN') <> '' then
7652 ReleaseKey(KEY_DOWN
);
7653 PressKey(KEY_DOWN
, 20);
7654 RemoveAIFlag('NEEDSEEDOWN');
7657 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7658 if GetAIFlag('GOINHOLE') <> '' then
7659 if not OnGround() then
7661 ReleaseKey(KEY_LEFT
);
7662 ReleaseKey(KEY_RIGHT
);
7663 RemoveAIFlag('GOINHOLE');
7664 SetAIFlag('FALLINHOLE', '1');
7667 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7668 if GetAIFlag('FALLINHOLE') <> '' then
7670 RemoveAIFlag('FALLINHOLE');
7672 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7673 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7674 if GetAIFlag('FALLINHOLE') = '' then
7675 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7681 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7683 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7687 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7688 if OnGround() and NearHole() then
7689 if NearDeepHole() then // Åñëè ýòî áåçäíà
7691 0..3: Turn(); // Áåæèì îáðàòíî
7692 4: Jump(); // Ïðûãàåì
7693 5: begin // Ïðûãàåì îáðàòíî
7698 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7699 if GetAIFlag('GOINHOLE') = '' then
7701 0: Turn(); // Íå íóæíî òóäà
7702 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7703 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7704 if BorderHole() then
7705 SetAIFlag('GOINHOLE', '1');
7708 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7709 if (not CanRun()) and OnGround() then
7711 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7712 if CanJumpOver() or OnLadder() then
7714 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7715 if Random(2) = 0 then
7717 if IsSafeTrigger() then
7723 // Îñòàëîñü ìàëî âîçäóõà:
7724 if FAir
< 36 * 2 then
7727 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7728 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7729 if BodyInAcid(0, 0) then
7733 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7735 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7736 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7739 {function TBot.NeedItem(Item: Byte): Byte;
7744 procedure TBot
.SelectWeapon(Dist
: Integer);
7748 function HaveAmmo(weapon
: Byte): Boolean;
7751 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7752 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7753 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7754 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7755 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7756 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7757 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7758 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7759 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7760 else Result
:= True;
7765 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7767 if Dist
> BOT_LONGDIST
then
7768 begin // Äàëüíèé áîé
7770 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7772 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7776 else //if Dist > BOT_UNSAFEDIST then
7777 begin // Áëèæíèé áîé
7779 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7781 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7788 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7790 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7796 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7798 Result
:= inherited PickItem(ItemType
, force
, remove
);
7800 if Result
then SetAIFlag('SELECTWEAPON', '1');
7803 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7805 Result
:= inherited Heal(value
, Soft
);
7808 function TBot
.Healthy(): Byte;
7810 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7811 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7812 else if (FHealth
> 50) then Result
:= 2
7813 else if (FHealth
> 20) then Result
:= 1
7817 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7819 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7820 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7823 procedure TBot
.OnDamage(Angle
: SmallInt);
7831 if (Angle
= 0) or (Angle
= 180) then
7834 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7835 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7837 pla
:= g_Player_Get(FLastSpawnerUID
);
7838 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7839 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7842 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7843 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7845 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7846 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7847 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7852 SetAIFlag('ATTACKLEFT', '1')
7854 SetAIFlag('ATTACKRIGHT', '1');
7858 function TBot
.RunDirection(): TDirection
;
7860 if Abs(Vel
.X
) >= 1 then
7862 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7864 Result
:= FDirection
;
7867 function TBot
.GetRnd(a
: Byte): Boolean;
7869 if a
= 0 then Result
:= False
7870 else if a
= 255 then Result
:= True
7871 else Result
:= Random(256) > 255-a
;
7874 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7876 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7880 procedure TDifficult
.save (st
: TStream
);
7882 utils
.writeInt(st
, Byte(DiagFire
));
7883 utils
.writeInt(st
, Byte(InvisFire
));
7884 utils
.writeInt(st
, Byte(DiagPrecision
));
7885 utils
.writeInt(st
, Byte(FlyPrecision
));
7886 utils
.writeInt(st
, Byte(Cover
));
7887 utils
.writeInt(st
, Byte(CloseJump
));
7888 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7889 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7892 procedure TDifficult
.load (st
: TStream
);
7894 DiagFire
:= utils
.readByte(st
);
7895 InvisFire
:= utils
.readByte(st
);
7896 DiagPrecision
:= utils
.readByte(st
);
7897 FlyPrecision
:= utils
.readByte(st
);
7898 Cover
:= utils
.readByte(st
);
7899 CloseJump
:= utils
.readByte(st
);
7900 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7901 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7905 procedure TBot
.SaveState (st
: TStream
);
7910 inherited SaveState(st
);
7911 utils
.writeSign(st
, 'BOT0');
7913 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7915 utils
.writeInt(st
, Word(FTargetUID
));
7916 // Âðåìÿ ïîòåðè öåëè
7917 utils
.writeInt(st
, LongWord(FLastVisible
));
7918 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7919 dw
:= Length(FAIFlags
);
7920 utils
.writeInt(st
, LongInt(dw
));
7922 for i
:= 0 to dw
-1 do
7924 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7925 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7927 // Íàñòðîéêè ñëîæíîñòè
7928 FDifficult
.save(st
);
7932 procedure TBot
.LoadState (st
: TStream
);
7937 inherited LoadState(st
);
7938 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7940 FSelectedWeapon
:= utils
.readByte(st
);
7942 FTargetUID
:= utils
.readWord(st
);
7943 // Âðåìÿ ïîòåðè öåëè
7944 FLastVisible
:= utils
.readLongWord(st
);
7945 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7946 dw
:= utils
.readLongInt(st
);
7947 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7948 SetLength(FAIFlags
, dw
);
7950 for i
:= 0 to dw
-1 do
7952 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7953 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7955 // Íàñòðîéêè ñëîæíîñòè
7956 FDifficult
.load(st
);
7961 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);