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, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
23 {$IFDEF USE_MEMPOOL}mempool
,{$ENDIF}
24 e_graphics
, g_playermodel
, g_basic
, g_textures
,
25 g_weapons
, g_phys
, g_sound
, g_saveload
, MAPDEF
,
58 AmmoLimits
: Array [0..1] of Array [A_BULLETS
..A_HIGH
] of Word =
59 ((200, 50, 50, 300, 100),
60 (400, 100, 100, 600, 200));
81 ANGLE_NONE
= Low(SmallInt);
83 CORPSE_STATE_REMOVEME
= 0;
84 CORPSE_STATE_NORMAL
= 1;
85 CORPSE_STATE_MESS
= 2;
87 PLAYER_RECT
: TRectWH
= (X
:15; Y
:12; Width
:34; Height
:52);
88 PLAYER_RECT_CX
= 15+(34 div 2);
89 PLAYER_RECT_CY
= 12+(52 div 2);
90 PLAYER_CORPSERECT
: TRectWH
= (X
:15; Y
:48; Width
:34; Height
:16);
93 PLAYER_HP_LIMIT
= 200;
95 PLAYER_AP_LIMIT
= 200;
99 PLAYER_BURN_TIME
= 110;
101 PLAYER1_DEF_COLOR
: TRGB
= (R
:64; G
:175; B
:48);
102 PLAYER2_DEF_COLOR
: TRGB
= (R
:96; G
:96; B
:96);
119 TPlayerStatArray
= Array of TPlayerStat
;
121 TPlayerSavedState
= record
129 Ammo
: Array [A_BULLETS
..A_HIGH
] of Word;
130 MaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
131 Weapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
132 Rulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
141 TPlayer
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
149 FDirection
: TDirection
;
157 FMonsterKills
: Integer;
163 FCanJetpack
: Boolean;
169 FNextWeapDelay
: Byte; // frames
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 FFlameSoundOn
: TPlayableSound
;
197 FFlameSoundOff
: TPlayableSound
;
198 FFlameSoundWork
: TPlayableSound
;
199 FJetSoundOn
: TPlayableSound
;
200 FJetSoundOff
: TPlayableSound
;
201 FJetSoundFly
: TPlayableSound
;
205 FJustTeleported
: Boolean;
207 mEDamageType
: Integer;
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;
263 FActualModelName
: string;
270 FSpawnInvul
: Integer;
272 FWaitForFirstSpawn
: Boolean; // set to `true` in server, used to spawn a player on first full state request
274 // debug: viewport offset
275 viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer;
277 function isValidViewPort (): Boolean; inline;
279 constructor Create(); virtual;
280 destructor Destroy(); override;
281 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
282 function GetRespawnPoint(): Byte;
283 procedure PressKey(Key
: Byte; Time
: Word = 1);
284 procedure ReleaseKeys();
285 procedure SetModel(ModelName
: String);
286 procedure SetColor(Color
: TRGB
);
287 function GetColor(): TRGB
;
288 procedure SetWeapon(W
: Byte);
289 function IsKeyPressed(K
: Byte): Boolean;
290 function GetKeys(): Byte;
291 function PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean; virtual;
292 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
293 function Collide(Panel
: TPanel
): Boolean; overload
;
294 function Collide(X
, Y
: Integer): Boolean; overload
;
295 procedure SetDirection(Direction
: TDirection
);
296 procedure GetSecret();
297 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
299 procedure Push(vx
, vy
: Integer);
300 procedure ChangeModel(ModelName
: String);
301 procedure SwitchTeam
;
302 procedure ChangeTeam(Team
: Byte);
304 function GetFlag(Flag
: Byte): Boolean;
305 procedure SetFlag(Flag
: Byte);
306 function DropFlag(Silent
: Boolean = True): Boolean;
307 procedure AllRulez(Health
: Boolean);
308 procedure RestoreHealthArmor();
309 procedure FragCombo();
310 procedure GiveItem(ItemType
: Byte);
311 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
312 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
313 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
314 procedure MakeBloodSimple(Count
: Word);
315 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
316 procedure Reset(Force
: Boolean);
317 procedure Spectate(NoMove
: Boolean = False);
318 procedure SwitchNoClip
;
319 procedure SoftReset();
320 procedure Draw(); virtual;
321 procedure DrawPain();
322 procedure DrawPickup();
323 procedure DrawRulez();
325 procedure DrawIndicator(Color
: TRGB
);
326 procedure DrawBubble();
328 procedure Update(); virtual;
329 procedure RememberState();
330 procedure RecallState();
331 procedure SaveState (st
: TStream
); virtual;
332 procedure LoadState (st
: TStream
); virtual;
333 procedure PauseSounds(Enable
: Boolean);
334 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
335 procedure DoLerp(Level
: Integer = 2);
336 procedure SetLerp(XTo
, YTo
: Integer);
337 procedure QueueWeaponSwitch(Weapon
: Byte);
338 procedure RealizeCurrentWeapon();
342 procedure JetpackOff
;
343 procedure CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
345 //WARNING! this does nothing for now, but still call it!
346 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
348 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
349 procedure moveBy (dx
, dy
: Integer); inline;
352 property Vel
: TPoint2i read FObj
.Vel
;
353 property Obj
: TObj read FObj
;
355 property Name
: String read FName write FName
;
356 property Model
: TPlayerModel read FModel
;
357 property Health
: Integer read FHealth write FHealth
;
358 property Lives
: Byte read FLives write FLives
;
359 property Armor
: Integer read FArmor write FArmor
;
360 property Air
: Integer read FAir write FAir
;
361 property JetFuel
: Integer read FJetFuel write FJetFuel
;
362 property Frags
: Integer read FFrags write FFrags
;
363 property Death
: Integer read FDeath write FDeath
;
364 property Kills
: Integer read FKills write FKills
;
365 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
366 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
367 property Secrets
: Integer read FSecrets
;
368 property GodMode
: Boolean read FGodMode write FGodMode
;
369 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
370 property NoReload
: Boolean read FNoReload write FNoReload
;
371 property alive
: Boolean read FAlive write FAlive
;
372 property Flag
: Byte read FFlag
;
373 property Team
: Byte read FTeam write FTeam
;
374 property Direction
: TDirection read FDirection
;
375 property GameX
: Integer read FObj
.X write FObj
.X
;
376 property GameY
: Integer read FObj
.Y write FObj
.Y
;
377 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
378 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
379 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
380 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
381 property IncCam
: Integer read FIncCam write FIncCam
;
382 property UID
: Word read FUID write FUID
;
383 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
384 property NetTime
: LongWord read FNetTime write FNetTime
;
387 property eName
: String read FName write FName
;
388 property eHealth
: Integer read FHealth write FHealth
;
389 property eLives
: Byte read FLives write FLives
;
390 property eArmor
: Integer read FArmor write FArmor
;
391 property eAir
: Integer read FAir write FAir
;
392 property eJetFuel
: Integer read FJetFuel write FJetFuel
;
393 property eFrags
: Integer read FFrags write FFrags
;
394 property eDeath
: Integer read FDeath write FDeath
;
395 property eKills
: Integer read FKills write FKills
;
396 property eCurrWeap
: Byte read FCurrWeap write FCurrWeap
;
397 property eMonsterKills
: Integer read FMonsterKills write FMonsterKills
;
398 property eSecrets
: Integer read FSecrets write FSecrets
;
399 property eGodMode
: Boolean read FGodMode write FGodMode
;
400 property eNoTarget
: Boolean read FNoTarget write FNoTarget
;
401 property eNoReload
: Boolean read FNoReload write FNoReload
;
402 property eAlive
: Boolean read FAlive write FAlive
;
403 property eFlag
: Byte read FFlag
;
404 property eTeam
: Byte read FTeam write FTeam
;
405 property eDirection
: TDirection read FDirection
;
406 property eGameX
: Integer read FObj
.X write FObj
.X
;
407 property eGameY
: Integer read FObj
.Y write FObj
.Y
;
408 property eGameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
409 property eGameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
410 property eGameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
411 property eGameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
412 property eIncCam
: Integer read FIncCam write FIncCam
;
413 property eUID
: Word read FUID
;
414 property eJustTeleported
: Boolean read FJustTeleported
;
415 property eNetTime
: LongWord read FNetTime
;
417 // set this before assigning something to `eDamage`
418 property eDamageType
: Integer read mEDamageType write mEDamageType
;
419 property eDamage
: Integer write doDamage
;
430 WeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
431 CloseWeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
432 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
435 procedure save (st
: TStream
);
436 procedure load (st
: TStream
);
444 TBot
= class(TPlayer
)
446 FSelectedWeapon
: Byte;
449 FAIFlags
: Array of TAIFlag
;
450 FDifficult
: TDifficult
;
452 function GetRnd(a
: Byte): Boolean;
453 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
454 function RunDirection(): TDirection
;
455 function FullInStep(XInc
, YInc
: Integer): Boolean;
456 //function NeedItem(Item: Byte): Byte;
457 procedure SelectWeapon(Dist
: Integer);
458 procedure SetAIFlag(aName
, fValue
: String20
);
459 function GetAIFlag(aName
: String20
): String20
;
460 procedure RemoveAIFlag(aName
: String20
);
461 function Healthy(): Byte;
462 procedure UpdateMove();
463 procedure UpdateCombat();
464 function KeyPressed(Key
: Word): Boolean;
465 procedure ReleaseKey(Key
: Byte);
466 function TargetOnScreen(TX
, TY
: Integer): Boolean;
467 procedure OnDamage(Angle
: SmallInt); override;
470 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
471 constructor Create(); override;
472 destructor Destroy(); override;
473 procedure Draw(); override;
474 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
475 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
476 procedure Update(); override;
477 procedure SaveState (st
: TStream
); override;
478 procedure LoadState (st
: TStream
); override;
490 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
491 procedure moveBy (dx
, dy
: Integer); inline;
493 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
507 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
508 procedure moveBy (dx
, dy
: Integer); inline;
510 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
513 TCorpse
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
522 FAnimation
: TAnimation
;
523 FAnimationMask
: TAnimation
;
526 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
527 destructor Destroy(); override;
528 procedure Damage(Value
: Word; vx
, vy
: Integer);
531 procedure SaveState (st
: TStream
);
532 procedure LoadState (st
: TStream
);
534 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
535 procedure moveBy (dx
, dy
: Integer); inline;
537 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
539 function ObjPtr (): PObj
; inline;
541 property Obj
: TObj read FObj
; // copies object
542 property State
: Byte read FState
;
543 property Mess
: Boolean read FMess
;
546 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
552 gPlayers
: Array of TPlayer
;
553 gCorpses
: Array of TCorpse
;
554 gGibs
: Array of TGib
;
555 gShells
: Array of TShell
;
556 gTeamStat
: TTeamStat
;
557 gFly
: Boolean = False;
558 gAimLine
: Boolean = False;
559 gChatBubble
: Integer = 0;
560 gPlayerIndicator
: Integer = 1;
561 gPlayerIndicatorStyle
: Integer = 0;
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_Player_ResetReady();
604 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
605 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
606 procedure g_Bot_MixNames();
607 procedure g_Bot_RemoveAll();
612 {$INCLUDE ../nogl/noGLuses.inc}
613 {$IFDEF ENABLE_HOLMES}
616 e_log
, g_map
, g_items
, g_console
, g_gfx
, Math
,
617 g_options
, g_triggers
, g_menu
, g_game
, g_grid
, e_res
,
618 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
,
619 g_net
, g_netmsg
, g_window
,
622 const PLR_SAVE_VERSION
= 0;
632 diag_precision
: Byte;
636 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
637 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
638 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
642 TIME_RESPAWN1
= 1500;
643 TIME_RESPAWN2
= 2000;
644 TIME_RESPAWN3
= 3000;
647 JET_MAX
= 540; // ~30 sec
648 PLAYER_SUIT_TIME
= 30000;
649 PLAYER_INVUL_TIME
= 30000;
650 PLAYER_INVIS_TIME
= 35000;
651 FRAG_COMBO_TIME
= 3000;
655 ANGLE_RIGHTDOWN
= -35;
657 ANGLE_LEFTDOWN
= -145;
658 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
659 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
662 BOT_UNSAFEDIST
= 128;
663 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
665 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
666 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
667 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
668 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
669 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
670 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
671 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
672 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
673 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
674 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
675 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
676 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
677 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
678 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
679 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
680 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
681 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
682 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
683 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
684 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
685 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
686 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
687 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
688 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
689 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
690 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
692 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
693 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
695 BOTNAMES_FILENAME
= 'botnames.txt';
696 BOTLIST_FILENAME
= 'botlist.txt';
700 MaxCorpses
: Word = 20;
701 MaxShells
: Word = 300;
702 CurrentGib
: Integer = 0;
703 CurrentShell
: Integer = 0;
704 BotNames
: Array of String;
705 BotList
: Array of TBotProfile
;
708 function Lerp(X
, Y
, Factor
: Integer): Integer;
710 Result
:= X
+ ((Y
- X
) div Factor
);
713 function SameTeam(UID1
, UID2
: Word): Boolean;
717 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
718 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
720 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
722 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
723 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
725 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
728 procedure g_Gibs_SetMax(Count
: Word);
731 SetLength(gGibs
, Count
);
733 if CurrentGib
>= Count
then
737 function g_Gibs_GetMax(): Word;
742 procedure g_Shells_SetMax(Count
: Word);
745 SetLength(gShells
, Count
);
747 if CurrentShell
>= Count
then
751 function g_Shells_GetMax(): Word;
757 procedure g_Corpses_SetMax(Count
: Word);
760 SetLength(gCorpses
, Count
);
763 function g_Corpses_GetMax(): Word;
765 Result
:= MaxCorpses
;
768 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
778 // Åñòü ëè ìåñòî â gPlayers:
779 if gPlayers
<> nil then
780 for a
:= 0 to High(gPlayers
) do
781 if gPlayers
[a
] = nil then
787 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
790 SetLength(gPlayers
, Length(gPlayers
)+1);
794 // Ñîçäàåì îáúåêò èãðîêà:
796 gPlayers
[a
] := TBot
.Create()
798 gPlayers
[a
] := TPlayer
.Create();
801 gPlayers
[a
].FActualModelName
:= ModelName
;
802 gPlayers
[a
].SetModel(ModelName
);
804 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
805 if gPlayers
[a
].FModel
= nil then
809 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
813 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
814 if Random(2) = 0 then
818 gPlayers
[a
].FPreferredTeam
:= Team
;
820 case gGameSettings
.GameMode
of
821 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
823 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
825 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
828 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
829 gPlayers
[a
].FColor
:= Color
;
830 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
831 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
833 gPlayers
[a
].FModel
.Color
:= Color
;
835 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
836 gPlayers
[a
].FAlive
:= False;
838 Result
:= gPlayers
[a
].FUID
;
841 function g_Player_CreateFromState (st
: TStream
): Word;
848 if (st
= nil) then exit
; //???
851 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
852 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
855 Bot
:= utils
.readBool(st
);
860 // Åñòü ëè ìåñòî â gPlayers:
861 for a
:= 0 to High(gPlayers
) do if (gPlayers
[a
] = nil) then begin ok
:= true; break
; end;
863 // Íåò ìåñòà - ðàñøèðÿåì gPlayers
866 SetLength(gPlayers
, Length(gPlayers
)+1);
870 // Ñîçäàåì îáúåêò èãðîêà
872 gPlayers
[a
] := TBot
.Create()
874 gPlayers
[a
] := TPlayer
.Create();
875 gPlayers
[a
].FIamBot
:= Bot
;
876 gPlayers
[a
].FPhysics
:= True;
879 gPlayers
[a
].FUID
:= utils
.readWord(st
);
881 gPlayers
[a
].FName
:= utils
.readStr(st
);
883 gPlayers
[a
].FTeam
:= utils
.readByte(st
);
884 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
886 gPlayers
[a
].FAlive
:= utils
.readBool(st
);
887 // Èçðàñõîäîâàë ëè âñå æèçíè
888 gPlayers
[a
].FNoRespawn
:= utils
.readBool(st
);
890 b
:= utils
.readByte(st
);
891 if b
= 1 then gPlayers
[a
].FDirection
:= TDirection
.D_LEFT
else gPlayers
[a
].FDirection
:= TDirection
.D_RIGHT
; // b = 2
893 gPlayers
[a
].FHealth
:= utils
.readLongInt(st
);
895 gPlayers
[a
].FHandicap
:= utils
.readLongInt(st
);
897 gPlayers
[a
].FLives
:= utils
.readByte(st
);
899 gPlayers
[a
].FArmor
:= utils
.readLongInt(st
);
901 gPlayers
[a
].FAir
:= utils
.readLongInt(st
);
903 gPlayers
[a
].FJetFuel
:= utils
.readLongInt(st
);
905 gPlayers
[a
].FPain
:= utils
.readLongInt(st
);
907 gPlayers
[a
].FKills
:= utils
.readLongInt(st
);
909 gPlayers
[a
].FMonsterKills
:= utils
.readLongInt(st
);
911 gPlayers
[a
].FFrags
:= utils
.readLongInt(st
);
913 gPlayers
[a
].FFragCombo
:= utils
.readByte(st
);
914 // Âðåìÿ ïîñëåäíåãî ôðàãà
915 gPlayers
[a
].FLastFrag
:= utils
.readLongWord(st
);
917 gPlayers
[a
].FDeath
:= utils
.readLongInt(st
);
919 gPlayers
[a
].FFlag
:= utils
.readByte(st
);
921 gPlayers
[a
].FSecrets
:= utils
.readLongInt(st
);
923 gPlayers
[a
].FCurrWeap
:= utils
.readByte(st
);
924 // Ñëåäóþùåå æåëàåìîå îðóæèå
925 gPlayers
[a
].FNextWeap
:= utils
.readWord(st
);
927 gPlayers
[a
].FNextWeapDelay
:= utils
.readByte(st
);
929 gPlayers
[a
].FBFGFireCounter
:= utils
.readSmallInt(st
);
931 gPlayers
[a
].FDamageBuffer
:= utils
.readLongInt(st
);
932 // Ïîñëåäíèé óäàðèâøèé
933 gPlayers
[a
].FLastSpawnerUID
:= utils
.readWord(st
);
934 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
935 gPlayers
[a
].FLastHit
:= utils
.readByte(st
);
937 Obj_LoadState(@gPlayers
[a
].FObj
, st
);
938 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
939 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FAmmo
[i
] := utils
.readWord(st
);
940 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
941 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FMaxAmmo
[i
] := utils
.readWord(st
);
943 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FWeapon
[i
] := utils
.readBool(st
);
944 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
945 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FReloading
[i
] := utils
.readWord(st
);
947 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
948 // Íàëè÷èå êðàñíîãî êëþ÷à
949 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
950 // Íàëè÷èå çåëåíîãî êëþ÷à
951 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
952 // Íàëè÷èå ñèíåãî êëþ÷à
953 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
955 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_BERSERK
);
956 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
957 for i
:= MR_SUIT
to MR_MAX
do gPlayers
[a
].FMegaRulez
[i
] := utils
.readLongWord(st
);
958 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
959 for i
:= T_RESPAWN
to T_FLAGCAP
do gPlayers
[a
].FTime
[i
] := utils
.readLongWord(st
);
962 gPlayers
[a
].FActualModelName
:= utils
.readStr(st
);
964 gPlayers
[a
].FColor
.R
:= utils
.readByte(st
);
965 gPlayers
[a
].FColor
.G
:= utils
.readByte(st
);
966 gPlayers
[a
].FColor
.B
:= utils
.readByte(st
);
967 // Îáíîâëÿåì ìîäåëü èãðîêà
968 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
970 // Íåò ìîäåëè - ñîçäàíèå íåâîçìîæíî
971 if (gPlayers
[a
].FModel
= nil) then
975 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
979 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû
980 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
981 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
983 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
985 result
:= gPlayers
[a
].FUID
;
989 procedure g_Player_ResetTeams();
993 if g_Game_IsClient
then
995 if gPlayers
= nil then
997 for a
:= Low(gPlayers
) to High(gPlayers
) do
998 if gPlayers
[a
] <> nil then
999 case gGameSettings
.GameMode
of
1001 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
1003 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
1004 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
1005 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
1008 gPlayers
[a
].ChangeTeam(TEAM_RED
)
1010 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
1013 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
1017 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
1020 _name
, _model
: String;
1023 if not g_Game_IsServer
then Exit
;
1025 // Ñïèñîê íàçâàíèé ìîäåëåé:
1026 m
:= g_PlayerModel_GetNames();
1031 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1032 Team
:= TEAM_COOP
// COOP
1034 if gGameSettings
.GameMode
= GM_DM
then
1035 Team
:= TEAM_NONE
// DM
1037 if Team
= TEAM_NONE
then // CTF / TDM
1039 // Àâòîáàëàíñ êîìàíä:
1043 for a
:= 0 to High(gPlayers
) do
1044 if gPlayers
[a
] <> nil then
1046 if gPlayers
[a
].Team
= TEAM_RED
then
1049 if gPlayers
[a
].Team
= TEAM_BLUE
then
1059 if Random(2) = 0 then
1065 // Âûáèðàåì áîòó èìÿ:
1067 if BotNames
<> nil then
1068 for a
:= 0 to High(BotNames
) do
1069 if g_Player_ValidName(BotNames
[a
]) then
1071 _name
:= BotNames
[a
];
1075 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
1078 _name
:= Format('DFBOT%.2d', [Random(100)]);
1079 until g_Player_ValidName(_name
);
1081 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1082 _model
:= m
[Random(Length(m
))];
1085 with g_Player_Get(g_Player_Create(_model
,
1086 _RGB(Min(Random(9)*32, 255),
1087 Min(Random(9)*32, 255),
1088 Min(Random(9)*32, 255)),
1089 Team
, True)) as TBot
do
1094 1: FDifficult
:= DIFFICULT_EASY
;
1095 2: FDifficult
:= DIFFICULT_MEDIUM
;
1096 else FDifficult
:= DIFFICULT_HARD
;
1099 for a
:= WP_FIRST
to WP_LAST
do
1101 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1102 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1103 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1106 FHandicap
:= Handicap
;
1108 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1110 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1111 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1116 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
1119 _name
, _model
: String;
1122 if not g_Game_IsServer
then Exit
;
1124 // Ñïèñîê íàçâàíèé ìîäåëåé:
1125 m
:= g_PlayerModel_GetNames();
1130 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1131 Team
:= TEAM_COOP
// COOP
1133 if gGameSettings
.GameMode
= GM_DM
then
1134 Team
:= TEAM_NONE
// DM
1136 if Team
= TEAM_NONE
then
1137 Team
:= BotList
[num
].team
; // CTF / TDM
1139 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1140 lName
:= AnsiLowerCase(lName
);
1141 if (num
< 0) or (num
> Length(BotList
)-1) then
1143 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1144 for a
:= 0 to High(BotList
) do
1145 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1154 _name
:= BotList
[num
].name
;
1155 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1156 if not g_Player_ValidName(_name
) then
1158 _name
:= Format('DFBOT%.2d', [Random(100)]);
1159 until g_Player_ValidName(_name
);
1162 _model
:= BotList
[num
].model
;
1163 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1164 if not InSArray(_model
, m
) then
1165 _model
:= m
[Random(Length(m
))];
1168 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1172 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1173 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1174 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1175 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1176 FDifficult
.Cover
:= BotList
[num
].cover
;
1177 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1179 FHandicap
:= Handicap
;
1181 for a
:= WP_FIRST
to WP_LAST
do
1183 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1184 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1185 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1188 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1190 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1194 procedure g_Bot_RemoveAll();
1198 if not g_Game_IsServer
then Exit
;
1199 if gPlayers
= nil then Exit
;
1201 for a
:= 0 to High(gPlayers
) do
1202 if gPlayers
[a
] <> nil then
1203 if gPlayers
[a
] is TBot
then
1205 gPlayers
[a
].Lives
:= 0;
1206 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1207 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1208 g_Player_Remove(gPlayers
[a
].FUID
);
1214 procedure g_Bot_MixNames();
1219 if BotNames
<> nil then
1220 for a
:= 0 to High(BotNames
) do
1222 b
:= Random(Length(BotNames
));
1224 Botnames
[a
] := BotNames
[b
];
1229 procedure g_Player_Remove(UID
: Word);
1233 if gPlayers
= nil then Exit
;
1235 if g_Game_IsServer
and g_Game_IsNet
then
1236 MH_SEND_PlayerDelete(UID
);
1238 for i
:= 0 to High(gPlayers
) do
1239 if gPlayers
[i
] <> nil then
1240 if gPlayers
[i
].FUID
= UID
then
1242 if gPlayers
[i
] is TPlayer
then
1243 TPlayer(gPlayers
[i
]).Free()
1245 TBot(gPlayers
[i
]).Free();
1251 procedure g_Player_Init();
1262 path
:= BOTNAMES_FILENAME
;
1263 if e_FindResource(DataDirs
, path
) = false then
1266 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1267 AssignFile(F
, path
);
1278 SetLength(BotNames
, Length(BotNames
)+1);
1279 BotNames
[High(BotNames
)] := s
;
1287 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1288 config
:= TConfig
.CreateFile(path
);
1292 while config
.SectionExists(IntToStr(a
)) do
1294 SetLength(BotList
, Length(BotList
)+1);
1296 with BotList
[High(BotList
)] do
1299 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1301 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1303 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1308 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1309 color
.R
:= StrToIntDef(sa
[0], 0);
1310 color
.G
:= StrToIntDef(sa
[1], 0);
1311 color
.B
:= StrToIntDef(sa
[2], 0);
1312 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1313 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1314 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1315 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1316 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1317 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1318 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1319 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1320 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1321 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1322 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1323 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1324 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1325 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1326 if Length(sa
) = 10 then
1328 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1329 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1330 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1331 if Length(sa
) = 10 then
1333 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1335 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1336 if Length(sa) = 10 then
1338 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1347 procedure g_Player_Free();
1351 if gPlayers
<> nil then
1353 for i
:= 0 to High(gPlayers
) do
1354 if gPlayers
[i
] <> nil then
1356 if gPlayers
[i
] is TPlayer
then
1357 TPlayer(gPlayers
[i
]).Free()
1359 TBot(gPlayers
[i
]).Free();
1370 procedure g_Player_UpdateAll();
1374 if gPlayers
= nil then Exit
;
1376 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1377 for i
:= 0 to High(gPlayers
) do
1379 if gPlayers
[i
] <> nil then
1381 if gPlayers
[i
] is TPlayer
then
1383 gPlayers
[i
].Update();
1384 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1388 // bot updates weapons in `UpdateCombat()`
1389 TBot(gPlayers
[i
]).Update();
1393 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1396 procedure g_Player_DrawAll();
1400 if gPlayers
= nil then Exit
;
1402 for i
:= 0 to High(gPlayers
) do
1403 if gPlayers
[i
] <> nil then
1404 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1405 else TBot(gPlayers
[i
]).Draw();
1408 procedure g_Player_DrawDebug(p
: TPlayer
);
1412 if p
= nil then Exit
;
1413 if (@p
.FObj
) = nil then Exit
;
1415 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1417 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1418 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1419 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1420 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1421 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1422 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1425 procedure g_Player_DrawHealth();
1430 if gPlayers
= nil then Exit
;
1431 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1433 for i
:= 0 to High(gPlayers
) do
1434 if gPlayers
[i
] <> nil then
1436 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1437 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1438 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1439 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1440 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1441 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1445 function g_Player_Get(UID
: Word): TPlayer
;
1451 if gPlayers
= nil then
1454 for a
:= 0 to High(gPlayers
) do
1455 if gPlayers
[a
] <> nil then
1456 if gPlayers
[a
].FUID
= UID
then
1458 Result
:= gPlayers
[a
];
1463 function g_Player_GetCount(): Byte;
1469 if gPlayers
= nil then
1472 for a
:= 0 to High(gPlayers
) do
1473 if gPlayers
[a
] <> nil then
1474 Result
:= Result
+ 1;
1477 function g_Player_GetStats(): TPlayerStatArray
;
1483 if gPlayers
= nil then Exit
;
1485 for a
:= 0 to High(gPlayers
) do
1486 if gPlayers
[a
] <> nil then
1488 SetLength(Result
, Length(Result
)+1);
1489 with Result
[High(Result
)] do
1492 Ping
:= gPlayers
[a
].FPing
;
1493 Loss
:= gPlayers
[a
].FLoss
;
1494 Name
:= gPlayers
[a
].FName
;
1495 Team
:= gPlayers
[a
].FTeam
;
1496 Frags
:= gPlayers
[a
].FFrags
;
1497 Deaths
:= gPlayers
[a
].FDeath
;
1498 Kills
:= gPlayers
[a
].FKills
;
1499 Color
:= gPlayers
[a
].FModel
.Color
;
1500 Lives
:= gPlayers
[a
].FLives
;
1501 Spectator
:= gPlayers
[a
].FSpectator
;
1506 procedure g_Player_ResetReady();
1510 if not g_Game_IsServer
then Exit
;
1511 if gPlayers
= nil then Exit
;
1513 for a
:= 0 to High(gPlayers
) do
1514 if gPlayers
[a
] <> nil then
1516 gPlayers
[a
].FReady
:= False;
1517 if g_Game_IsNet
then
1518 MH_SEND_GameEvent(NET_EV_INTER_READY
, gPlayers
[a
].UID
, 'N');
1522 procedure g_Player_RememberAll
;
1526 for i
:= Low(gPlayers
) to High(gPlayers
) do
1527 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1528 gPlayers
[i
].RememberState
;
1531 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1535 gTeamStat
[TEAM_RED
].Goals
:= 0;
1536 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1538 if gPlayers
<> nil then
1539 for i
:= 0 to High(gPlayers
) do
1540 if gPlayers
[i
] <> nil then
1542 gPlayers
[i
].Reset(Force
);
1544 if gPlayers
[i
] is TPlayer
then
1546 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1547 gPlayers
[i
].Respawn(Silent
)
1549 gPlayers
[i
].Spectate();
1552 TBot(gPlayers
[i
]).Respawn(Silent
);
1556 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1562 if Player
.alive
then
1565 // Ðàçðûâàåì ñâÿçü ñ ïðåæíèì òðóïîì:
1566 if gCorpses
<> nil then
1567 for i
:= 0 to High(gCorpses
) do
1568 if gCorpses
[i
] <> nil then
1569 if gCorpses
[i
].FPlayerUID
= Player
.FUID
then
1570 gCorpses
[i
].FPlayerUID
:= 0;
1572 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1577 if (FHealth
>= -50) or (gGibsCount
= 0) then
1579 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1583 for find_id
:= 0 to High(gCorpses
) do
1584 if gCorpses
[find_id
] = nil then
1591 find_id
:= Random(Length(gCorpses
));
1593 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1594 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1595 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1596 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1597 gCorpses
[find_id
].FPlayerUID
:= FUID
;
1600 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1601 FObj
.Y
+ PLAYER_RECT_CY
,
1602 FModel
.Name
, FModel
.Color
);
1606 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1610 if (gShells
= nil) or (Length(gShells
) = 0) then
1613 with gShells
[CurrentShell
] do
1619 if T
= SHELL_BULLET
then
1621 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1625 Obj
.Rect
.Width
:= 4;
1626 Obj
.Rect
.Height
:= 2;
1630 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1634 Obj
.Rect
.Width
:= 7;
1635 Obj
.Rect
.Height
:= 3;
1641 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1642 positionChanged(); // this updates spatial accelerators
1643 RAngle
:= Random(360);
1644 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1646 if CurrentShell
>= High(gShells
) then
1653 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1656 GibsArray
: TGibsArray
;
1659 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1661 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1663 Blood
:= g_PlayerModel_GetBlood(ModelName
);
1665 for a
:= 0 to High(GibsArray
) do
1666 with gGibs
[CurrentGib
] do
1669 ID
:= GibsArray
[a
].ID
;
1670 MaskID
:= GibsArray
[a
].MaskID
;
1673 Obj
.Rect
:= GibsArray
[a
].Rect
;
1674 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1675 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1676 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1677 positionChanged(); // this updates spatial accelerators
1678 RAngle
:= Random(360);
1680 if gBloodCount
> 0 then
1681 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1682 Random(48), Random(48), Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
1684 if CurrentGib
>= High(gGibs
) then
1691 procedure g_Player_UpdatePhysicalObjects();
1697 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1702 if T
= SHELL_BULLET
then
1703 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1705 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1710 if gGibs
<> nil then
1711 for i
:= 0 to High(gGibs
) do
1712 if gGibs
[i
].alive
then
1716 mr
:= g_Obj_Move(@Obj
, True, False, True);
1717 positionChanged(); // this updates spatial accelerators
1719 if WordBool(mr
and MOVE_FALLOUT
) then
1725 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1726 if WordBool(mr
and MOVE_HITWALL
) then
1727 Obj
.Vel
.X
:= -(vel
.X
div 2);
1728 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1729 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1731 if (Obj
.Vel
.X
>= 0) then
1733 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1734 if RAngle
>= 360 then
1735 RAngle
:= RAngle
mod 360;
1736 end else begin // Counter-clockwise
1737 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1739 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1742 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1743 if gTime
mod (GAME_TICK
*3) = 0 then
1744 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1748 if gCorpses
<> nil then
1749 for i
:= 0 to High(gCorpses
) do
1750 if gCorpses
[i
] <> nil then
1751 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1757 gCorpses
[i
].Update();
1760 if gShells
<> nil then
1761 for i
:= 0 to High(gShells
) do
1762 if gShells
[i
].alive
then
1766 mr
:= g_Obj_Move(@Obj
, True, False, True);
1767 positionChanged(); // this updates spatial accelerators
1769 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1775 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1776 if WordBool(mr
and MOVE_HITWALL
) then
1778 Obj
.Vel
.X
:= -(vel
.X
div 2);
1779 if not WordBool(mr
and MOVE_INWATER
) then
1780 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1782 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1784 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1785 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1786 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1788 if RAngle
mod 90 <> 0 then
1789 RAngle
:= (RAngle
div 90) * 90;
1791 else if not WordBool(mr
and MOVE_INWATER
) then
1792 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1795 if (Obj
.Vel
.X
>= 0) then
1797 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1798 if RAngle
>= 360 then
1799 RAngle
:= RAngle
mod 360;
1800 end else begin // Counter-clockwise
1801 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1803 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1809 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1811 x
:= Obj
.X
+Obj
.Rect
.X
;
1812 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1813 w
:= Obj
.Rect
.Width
;
1814 h
:= Obj
.Rect
.Height
;
1817 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1819 if (dx
<> 0) or (dy
<> 0) then
1828 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1832 w
:= Obj
.Rect
.Width
;
1833 h
:= Obj
.Rect
.Height
;
1836 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1838 if (dx
<> 0) or (dy
<> 0) then
1847 procedure TGib
.positionChanged (); inline; begin end;
1848 procedure TShell
.positionChanged (); inline; begin end;
1851 procedure g_Player_DrawCorpses();
1856 if gGibs
<> nil then
1857 for i
:= 0 to High(gGibs
) do
1858 if gGibs
[i
].alive
then
1861 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1864 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1865 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1867 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1870 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1876 if gCorpses
<> nil then
1877 for i
:= 0 to High(gCorpses
) do
1878 if gCorpses
[i
] <> nil then
1882 procedure g_Player_DrawShells();
1887 if gShells
<> nil then
1888 for i
:= 0 to High(gShells
) do
1889 if gShells
[i
].alive
then
1892 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1898 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1902 procedure g_Player_RemoveAllCorpses();
1908 SetLength(gGibs
, MaxGibs
);
1909 SetLength(gShells
, MaxGibs
);
1913 if gCorpses
<> nil then
1914 for i
:= 0 to High(gCorpses
) do
1918 SetLength(gCorpses
, MaxCorpses
);
1921 procedure g_Player_Corpses_SaveState (st
: TStream
);
1925 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ
1927 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1929 // Êîëè÷åñòâî òðóïîâ
1930 utils
.writeInt(st
, LongInt(count
));
1932 if (count
= 0) then exit
;
1935 for i
:= 0 to High(gCorpses
) do
1937 if gCorpses
[i
] <> nil then
1940 utils
.writeStr(st
, gCorpses
[i
].FModelName
);
1942 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1943 // Ñîõðàíÿåì äàííûå òðóïà:
1944 gCorpses
[i
].SaveState(st
);
1950 procedure g_Player_Corpses_LoadState (st
: TStream
);
1958 g_Player_RemoveAllCorpses();
1960 // Êîëè÷åñòâî òðóïîâ:
1961 count
:= utils
.readLongInt(st
);
1962 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1964 if (count
= 0) then exit
;
1967 for i
:= 0 to count
-1 do
1970 str
:= utils
.readStr(st
);
1972 b
:= utils
.readBool(st
);
1974 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1975 // Çàãðóæàåì äàííûå òðóïà
1976 gCorpses
[i
].LoadState(st
);
1983 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1985 procedure TPlayer
.BFGHit();
1987 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1988 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1989 if g_Game_IsServer
and g_Game_IsNet
then
1990 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1991 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1995 procedure TPlayer
.ChangeModel(ModelName
: string);
1997 locModel
: TPlayerModel
;
1999 locModel
:= g_PlayerModel_Get(ModelName
);
2000 if locModel
= nil then Exit
;
2006 procedure TPlayer
.SetModel(ModelName
: string);
2010 m
:= g_PlayerModel_Get(ModelName
);
2013 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
2014 m
:= g_PlayerModel_Get('doomer');
2017 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
2022 if FModel
<> nil then
2027 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2028 FModel
.Color
:= FColor
2030 FModel
.Color
:= TEAMCOLOR
[FTeam
];
2031 FModel
.SetWeapon(FCurrWeap
);
2032 FModel
.SetFlag(FFlag
);
2033 SetDirection(FDirection
);
2036 procedure TPlayer
.SetColor(Color
: TRGB
);
2039 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2040 if FModel
<> nil then FModel
.Color
:= Color
;
2043 function TPlayer
.GetColor(): TRGB
;
2045 result
:= FModel
.Color
;
2048 procedure TPlayer
.SwitchTeam
;
2050 if g_Game_IsClient
then
2052 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
2054 if gGameOn
and FAlive
then
2055 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
2057 if FTeam
= TEAM_RED
then
2059 ChangeTeam(TEAM_BLUE
);
2060 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
2061 if g_Game_IsNet
then
2062 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
2066 ChangeTeam(TEAM_RED
);
2067 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
2068 if g_Game_IsNet
then
2069 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
2071 FPreferredTeam
:= FTeam
;
2074 procedure TPlayer
.ChangeTeam(Team
: Byte);
2081 TEAM_RED
, TEAM_BLUE
:
2082 FModel
.Color
:= TEAMCOLOR
[Team
];
2084 FModel
.Color
:= FColor
;
2086 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2087 MH_SEND_PlayerStats(FUID
);
2091 procedure TPlayer.CollideItem();
2096 if gItems = nil then Exit;
2097 if not FAlive then Exit;
2099 for i := 0 to High(gItems) do
2102 if (ItemType <> ITEM_NONE) and alive then
2103 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2104 PLAYER_RECT.Height, @Obj) then
2106 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2108 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2109 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2110 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2111 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2112 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2114 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2115 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2116 (gGameSettings.GameType = GT_SINGLE) and
2117 (g_Player_GetCount() > 1)) then
2118 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2124 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2126 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2127 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2131 constructor TPlayer
.Create();
2137 mEDamageType
:= HIT_SOME
;
2143 FSawSound
:= TPlayableSound
.Create();
2144 FSawSoundIdle
:= TPlayableSound
.Create();
2145 FSawSoundHit
:= TPlayableSound
.Create();
2146 FSawSoundSelect
:= TPlayableSound
.Create();
2147 FFlameSoundOn
:= TPlayableSound
.Create();
2148 FFlameSoundOff
:= TPlayableSound
.Create();
2149 FFlameSoundWork
:= TPlayableSound
.Create();
2150 FJetSoundFly
:= TPlayableSound
.Create();
2151 FJetSoundOn
:= TPlayableSound
.Create();
2152 FJetSoundOff
:= TPlayableSound
.Create();
2154 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2155 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2156 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2157 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2158 FFlameSoundOn
.SetByName('SOUND_WEAPON_FLAMEON');
2159 FFlameSoundOff
.SetByName('SOUND_WEAPON_FLAMEOFF');
2160 FFlameSoundWork
.SetByName('SOUND_WEAPON_FLAMEWORK');
2161 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2162 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2163 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2165 FSpectatePlayer
:= -1;
2169 FSavedState
.WaitRecall
:= False;
2176 FActualModelName
:= 'doomer';
2179 FObj
.Rect
:= PLAYER_RECT
;
2181 FBFGFireCounter
:= -1;
2182 FJustTeleported
:= False;
2185 FWaitForFirstSpawn
:= false;
2190 procedure TPlayer
.positionChanged (); inline;
2194 procedure TPlayer
.doDamage (v
: Integer);
2196 if (v
<= 0) then exit
;
2197 if (v
> 32767) then v
:= 32767;
2198 Damage(v
, 0, 0, 0, mEDamageType
);
2201 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2205 if (not g_Game_IsClient
) and (not FAlive
) then
2210 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2211 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2213 if not g_Game_IsClient
then
2216 if t
= HIT_TRAP
then
2218 // Ëîâóøêà óáèâàåò ñðàçó:
2220 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2222 if t
= HIT_SELF
then
2226 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2229 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2230 FMegaRulez
[MR_SUIT
] := 0;
2231 FMegaRulez
[MR_INVUL
] := 0;
2232 FMegaRulez
[MR_INVIS
] := 0;
2237 // Íî îò îñòàëüíîãî ñïàñàåò:
2238 if FMegaRulez
[MR_INVUL
] >= gTime
then
2245 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2246 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2247 (SpawnerUID
= FUID
) or
2248 (not SameTeam(FUID
, SpawnerUID
)) then
2250 FLastSpawnerUID
:= SpawnerUID
;
2252 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2253 if gBloodCount
> 0 then
2255 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2256 if value
div 4 <= c
then
2257 c
:= c
- (value
div 4)
2261 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2265 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2266 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2269 if t
= HIT_WATER
then
2270 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2271 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2276 Inc(FDamageBuffer
, value
);
2280 FPain
:= FPain
+ value
;
2283 if g_Game_IsServer
and g_Game_IsNet
then
2285 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2286 MH_SEND_PlayerStats(FUID
);
2287 MH_SEND_PlayerPos(False, FUID
);
2291 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2294 if g_Game_IsClient
then
2299 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2301 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2304 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2306 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2310 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2311 MH_SEND_PlayerStats(FUID
);
2314 destructor TPlayer
.Destroy();
2316 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2318 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2322 FSawSoundIdle
.Free();
2323 FSawSoundHit
.Free();
2324 FSawSoundSelect
.Free();
2325 FFlameSoundOn
.Free();
2326 FFlameSoundOff
.Free();
2327 FFlameSoundWork
.Free();
2328 FJetSoundFly
.Free();
2330 FJetSoundOff
.Free();
2332 if FPunchAnim
<> nil then
2338 procedure TPlayer
.DrawIndicator(Color
: TRGB
);
2340 indX
, indY
: Integer;
2349 case gPlayerIndicatorStyle
of
2352 if g_Texture_Get('TEXTURE_PLAYER_INDICATOR', ID
) then
2354 e_GetTextureSize(ID
, @indW
, @indH
);
2358 if (FObj
.X
+ FObj
.Rect
.X
) < 0 then
2361 indX
:= FObj
.X
+ FObj
.Rect
.X
+ FObj
.Rect
.Width
;
2362 indY
:= FObj
.Y
+ FObj
.Rect
.Y
+ (FObj
.Rect
.Height
- indW
) div 2;
2365 else if (FObj
.X
+ FObj
.Rect
.X
+ FObj
.Rect
.Width
) > Max(gMapInfo
.Width
, gPlayerScreenSize
.X
) then
2368 indX
:= FObj
.X
+ FObj
.Rect
.X
- indH
;
2369 indY
:= FObj
.Y
+ FObj
.Rect
.Y
+ (FObj
.Rect
.Height
- indW
) div 2;
2372 else if (fObj
.Y
- indH
) < 0 then
2375 indX
:= FObj
.X
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
- indW
) div 2;
2376 indY
:= FObj
.Y
+ FObj
.Rect
.Y
+ FObj
.Rect
.Height
;
2382 indX
:= FObj
.X
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
- indW
) div 2;
2383 indY
:= FObj
.Y
- indH
;
2386 indX
:= EnsureRange(indX
, 0, Max(gMapInfo
.Width
, gPlayerScreenSize
.X
) - indW
);
2387 indY
:= EnsureRange(indY
, 0, Max(gMapInfo
.Height
, gPlayerScreenSize
.Y
) - indH
);
2391 e_DrawAdv(ID
, indX
, indY
, 0, True, False, indA
, @a
);
2398 e_TextureFontGetSize(gStdFont
, nW
, nH
);
2399 indX
:= FObj
.X
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
- Length(FName
) * nW
) div 2;
2400 indY
:= FObj
.Y
- nH
;
2401 e_TextureFontPrintEx(indX
, indY
, FName
, gStdFont
, Color
.R
, Color
.G
, Color
.B
, 1.0, True);
2406 procedure TPlayer
.DrawBubble();
2408 bubX
, bubY
: Integer;
2411 Rw
, Gw
, Bw
: SmallInt;
2414 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= TDirection
.D_LEFT
, -4, 18);
2415 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2423 1: // simple textual non-bubble
2425 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2426 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2427 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2430 2: // advanced pixel-perfect bubble
2432 if FTeam
= TEAM_RED
then
2435 if FTeam
= TEAM_BLUE
then
2438 3: // colored bubble
2440 Rb
:= FModel
.Color
.R
;
2441 Gb
:= FModel
.Color
.G
;
2442 Bb
:= FModel
.Color
.B
;
2443 Rw
:= Min(Rb
* 2 + 64, 255);
2444 Gw
:= Min(Gb
* 2 + 64, 255);
2445 Bw
:= Min(Bb
* 2 + 64, 255);
2446 if (Abs(Rw
- Rb
) < 32)
2447 or (Abs(Gw
- Gb
) < 32)
2448 or (Abs(Bw
- Bb
) < 32) then
2450 Rb
:= Max(Rw
div 2 - 16, 0);
2451 Gb
:= Max(Gw
div 2 - 16, 0);
2452 Bb
:= Max(Bw
div 2 - 16, 0);
2455 4: // custom textured bubble
2457 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2458 if FDirection
= TDirection
.D_RIGHT
then
2459 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2461 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, TMirrorType
.Horizontal
);
2467 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2468 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2470 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2473 Dot
:= IfThen(FDirection
= TDirection
.D_LEFT
, 14, 5);
2474 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2475 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
);
2476 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
);
2477 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
);
2478 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
);
2482 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2483 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2484 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2487 procedure TPlayer
.Draw();
2492 Mirror
: TMirrorType
;
2496 if Direction
= TDirection
.D_RIGHT
then
2497 Mirror
:= TMirrorType
.None
2499 Mirror
:= TMirrorType
.Horizontal
;
2501 if FPunchAnim
<> nil then
2503 FPunchAnim
.Draw(FObj
.X
+IfThen(Direction
= TDirection
.D_LEFT
, 15-FObj
.Rect
.X
, FObj
.Rect
.X
-15),
2504 FObj
.Y
+FObj
.Rect
.Y
-11, Mirror
);
2505 if FPunchAnim
.played
then
2512 if (FMegaRulez
[MR_INVUL
] > gTime
) and ((gPlayerDrawn
<> Self
) or (FSpawnInvul
>= gTime
)) then
2513 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2515 e_GetTextureSize(ID
, @w
, @h
);
2516 if FDirection
= TDirection
.D_LEFT
then
2517 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2518 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False)
2520 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2521 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False);
2524 if FMegaRulez
[MR_INVIS
] > gTime
then
2526 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2527 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2529 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2530 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2534 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 200)
2536 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2539 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 254);
2542 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2545 if g_debug_Frames
then
2547 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2549 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2550 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2554 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2555 if (FMegaRulez
[MR_INVIS
] <= gTime
) or ((gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2556 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
)))) then
2558 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2559 if gAimLine
and alive
and
2560 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2565 procedure TPlayer
.DrawAim();
2566 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2571 {$IFDEF ENABLE_HOLMES}
2572 if isValidViewPort
and (self
= gPlayer1
) then
2574 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2578 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2579 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2581 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2585 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2590 wx
, wy
, xx
, yy
: Integer;
2594 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= TDirection
.D_LEFT
, 7, -7);
2595 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2604 1: begin // Chainsaw
2611 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2612 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2613 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2614 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2619 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2620 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2621 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2622 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2624 4: begin // Double Shotgun
2627 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2628 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2629 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2630 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2632 5: begin // Chaingun
2635 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2636 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2637 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2638 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2640 6: begin // Rocket Launcher
2643 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2644 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2645 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2646 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2648 7: begin // Plasmagun
2651 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2652 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2653 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2654 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2659 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2660 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2661 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2662 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2664 9: begin // Super Chaingun
2667 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2668 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2669 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2670 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2673 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2674 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2675 {$IF DEFINED(D2F_DEBUG)}
2676 drawCast(sz
, wx
, wy
, xx
, yy
);
2678 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2682 procedure TPlayer
.DrawGUI();
2685 X
, Y
, SY
, a
, p
, m
: Integer;
2689 stat
: TPlayerStatArray
;
2691 X
:= gPlayerScreenSize
.X
;
2692 SY
:= gPlayerScreenSize
.Y
;
2695 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2697 if gGameSettings
.GameMode
= GM_CTF
then
2701 if gGameSettings
.GameMode
= GM_CTF
then
2703 s
:= 'TEXTURE_PLAYER_REDFLAG';
2704 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2705 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2706 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2707 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2708 if g_Texture_Get(s
, ID
) then
2709 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2712 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2713 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2714 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2716 if gGameSettings
.GameMode
= GM_CTF
then
2718 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2719 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2720 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2721 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2722 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2723 if g_Texture_Get(s
, ID
) then
2724 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2727 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2728 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2729 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2732 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2733 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2736 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2737 e_Draw(ID
, X
+2, Y
, 0, True, False);
2739 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2743 s
:= IntToStr(Frags
);
2744 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2745 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2750 stat
:= g_Player_GetStats();
2755 for a
:= 0 to High(stat
) do
2756 if stat
[a
].Name
<> Name
then
2758 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2759 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2763 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2764 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2765 s
:= s
+IntToStr(Abs(Frags
-m
));
2767 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2768 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2771 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2773 s
:= IntToStr(Lives
);
2774 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2775 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2779 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2780 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2782 if R_BERSERK
in FRulez
then
2783 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2785 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2787 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2788 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2790 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2791 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2792 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2794 s
:= IntToStr(FArmor
);
2795 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2796 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2798 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2804 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2809 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2811 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2812 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2813 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2814 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2815 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2816 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2817 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2818 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2819 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2822 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2823 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2824 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2826 if R_KEY_RED
in FRulez
then
2827 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2829 if R_KEY_GREEN
in FRulez
then
2830 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2832 if R_KEY_BLUE
in FRulez
then
2833 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2835 if FJetFuel
> 0 then
2837 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2838 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2839 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2840 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2841 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2842 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2846 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2847 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2848 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2851 if gShowPing
and g_Game_IsClient
then
2853 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2854 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2860 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2861 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2862 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2865 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2866 s
:= _lc
[I_PLAYER_SPECT4
];
2867 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2868 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2869 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2875 procedure TPlayer
.DrawRulez();
2879 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2880 if (FMegaRulez
[MR_INVUL
] >= gTime
) and (FSpawnInvul
< gTime
) then
2882 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2883 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2888 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2889 191, 191, 191, 0, TBlending
.Invert
);
2892 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2893 if FMegaRulez
[MR_SUIT
] >= gTime
then
2895 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2896 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2901 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2902 0, 96, 0, 200, TBlending
.None
);
2905 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2906 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2908 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2909 255, 0, 0, 200, TBlending
.None
);
2913 procedure TPlayer
.DrawPain();
2917 if FPain
= 0 then Exit
;
2921 if a
< 15 then h
:= 0
2922 else if a
< 35 then h
:= 1
2923 else if a
< 55 then h
:= 2
2924 else if a
< 75 then h
:= 3
2925 else if a
< 95 then h
:= 4
2928 //if a > 255 then a := 255;
2930 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2931 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2934 procedure TPlayer
.DrawPickup();
2938 if FPickup
= 0 then Exit
;
2942 if a
< 15 then h
:= 1
2943 else if a
< 35 then h
:= 2
2944 else if a
< 55 then h
:= 3
2945 else if a
< 75 then h
:= 4
2948 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2951 procedure TPlayer
.DoPunch();
2956 if FPunchAnim
<> nil then begin
2961 st
:= 'FRAMES_PUNCH';
2962 if R_BERSERK
in FRulez
then
2963 st
:= st
+ '_BERSERK';
2964 if FKeys
[KEY_UP
].Pressed
then
2966 else if FKeys
[KEY_DOWN
].Pressed
then
2968 g_Frames_Get(id
, st
);
2969 FPunchAnim
:= TAnimation
.Create(id
, False, 1);
2972 procedure TPlayer
.Fire();
2974 f
, DidFire
: Boolean;
2975 wx
, wy
, xd
, yd
: Integer;
2978 if g_Game_IsClient
then Exit
;
2979 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2980 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2988 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2993 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2994 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2995 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
2996 yd
:= wy
+firediry();
3002 if R_BERSERK
in FRulez
then
3004 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
3005 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
3006 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
3009 locobj
.rect
.Width
:= 39;
3010 locobj
.rect
.Height
:= 52;
3011 locobj
.Vel
.X
:= (xd
-wx
) div 2;
3012 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
3013 locobj
.Accel
.X
:= xd
-wx
;
3014 locobj
.Accel
.y
:= yd
-wy
;
3016 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
3017 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
3019 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
3021 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
3025 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
3029 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3034 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
3035 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
3037 FSawSoundSelect
.Stop();
3039 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
3041 else if not FSawSoundHit
.IsPlaying() then
3043 FSawSoundSelect
.Stop();
3044 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
3047 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3053 if FAmmo
[A_BULLETS
] > 0 then
3055 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
3056 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3057 Dec(FAmmo
[A_BULLETS
]);
3058 FFireAngle
:= FAngle
;
3061 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3062 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3066 if FAmmo
[A_SHELLS
] > 0 then
3068 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3069 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
3070 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3071 Dec(FAmmo
[A_SHELLS
]);
3072 FFireAngle
:= FAngle
;
3076 FShellType
:= SHELL_SHELL
;
3080 if FAmmo
[A_SHELLS
] >= 2 then
3082 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
3083 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3084 Dec(FAmmo
[A_SHELLS
], 2);
3085 FFireAngle
:= FAngle
;
3089 FShellType
:= SHELL_DBLSHELL
;
3093 if FAmmo
[A_BULLETS
] > 0 then
3095 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
3096 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
3097 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3098 Dec(FAmmo
[A_BULLETS
]);
3099 FFireAngle
:= FAngle
;
3102 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3103 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3106 WEAPON_ROCKETLAUNCHER
:
3107 if FAmmo
[A_ROCKETS
] > 0 then
3109 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
3110 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3111 Dec(FAmmo
[A_ROCKETS
]);
3112 FFireAngle
:= FAngle
;
3118 if FAmmo
[A_CELLS
] > 0 then
3120 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
3121 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3122 Dec(FAmmo
[A_CELLS
]);
3123 FFireAngle
:= FAngle
;
3129 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
3131 FBFGFireCounter
:= 17;
3132 if not FNoReload
then
3133 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
3134 Dec(FAmmo
[A_CELLS
], 40);
3138 WEAPON_SUPERPULEMET
:
3139 if FAmmo
[A_SHELLS
] > 0 then
3141 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3142 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
3143 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3144 Dec(FAmmo
[A_SHELLS
]);
3145 FFireAngle
:= FAngle
;
3148 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3149 GameVelX
, GameVelY
-2, SHELL_SHELL
);
3152 WEAPON_FLAMETHROWER
:
3153 if FAmmo
[A_FUEL
] > 0 then
3155 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
3157 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3159 FFireAngle
:= FAngle
;
3166 if g_Game_IsNet
and g_Game_IsServer
then MH_SEND_PlayerStats(FUID
);
3170 if g_Game_IsNet
then
3174 if FCurrWeap
<> WEAPON_BFG
then
3175 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
3177 if not FNoReload
then
3178 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
3181 MH_SEND_PlayerStats(FUID
);
3186 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
3187 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
3188 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
3191 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
3194 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
3195 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
3196 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
3197 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
3198 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
3203 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
3205 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
3206 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
3207 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
3210 procedure TPlayer
.FlamerOn
;
3212 FFlameSoundOff
.Stop();
3213 FFlameSoundOff
.SetPosition(0);
3216 if (not FFlameSoundOn
.IsPlaying()) and (not FFlameSoundWork
.IsPlaying()) then
3217 FFlameSoundWork
.PlayAt(FObj
.X
, FObj
.Y
);
3221 FFlameSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3226 procedure TPlayer
.FlamerOff
;
3230 FFlameSoundOn
.Stop();
3231 FFlameSoundOn
.SetPosition(0);
3232 FFlameSoundWork
.Stop();
3233 FFlameSoundWork
.SetPosition(0);
3234 FFlameSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3239 procedure TPlayer
.JetpackOn
;
3243 FJetSoundOn
.SetPosition(0);
3244 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3248 procedure TPlayer
.JetpackOff
;
3252 FJetSoundOff
.SetPosition(0);
3253 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3256 procedure TPlayer
.CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
3258 if Timeout
<= 0 then
3260 if (FMegaRulez
[MR_SUIT
] > gTime
) or (FMegaRulez
[MR_INVUL
] > gTime
) then
3261 exit
; // Íå çàãîðàåìñÿ êîãäà åñòü çàùèòà
3262 if g_Obj_CollidePanel(@FObj
, 0, 0, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
) then
3263 exit
; // Íå ïîäãîðàåì â âîäå íà âñÿêèé ñëó÷àé
3264 if FFireTime
<= 0 then
3265 g_Sound_PlayExAt('SOUND_IGNITE', FObj
.X
, FObj
.Y
);
3266 FFireTime
:= Timeout
;
3267 FFireAttacker
:= Attacker
;
3268 if g_Game_IsNet
and g_Game_IsServer
then
3269 MH_SEND_PlayerStats(FUID
);
3272 procedure TPlayer
.Jump();
3274 if gFly
or FJetpack
then
3276 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3277 if FObj
.Vel
.Y
> -VEL_FLY
then
3278 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3281 if FJetFuel
> 0 then
3283 if (FJetFuel
< 1) and g_Game_IsServer
then
3287 if g_Game_IsNet
then
3288 MH_SEND_PlayerStats(FUID
);
3294 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3296 FCanJetpack
:= False;
3298 // Ïðûãàåì èëè âñïëûâàåì:
3299 if (CollideLevel(0, 1) or
3300 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3301 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3302 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3304 FObj
.Vel
.Y
:= -VEL_JUMP
;
3305 FCanJetpack
:= False;
3309 if BodyInLiquid(0, 0) then
3310 FObj
.Vel
.Y
:= -VEL_SW
3311 else if (FJetFuel
> 0) and FCanJetpack
and
3312 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3316 if g_Game_IsNet
then
3317 MH_SEND_PlayerStats(FUID
);
3322 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3324 a
, i
, k
, ab
, ar
: Byte;
3328 srv
, netsrv
: Boolean;
3334 procedure PushItem(t
: Byte);
3338 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3339 it
:= g_Items_ByIdx(id
);
3340 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3342 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3343 (FObj
.Vel
.Y
div 2)-Random(9));
3344 it
.positionChanged(); // this updates spatial accelerators
3348 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3350 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3351 (FObj
.Vel
.Y
div 2)-Random(6));
3353 else // -3..+3; -3..0
3355 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3356 (FObj
.Vel
.Y
div 2)-Random(4));
3358 it
.positionChanged(); // this updates spatial accelerators
3361 if g_Game_IsNet
and g_Game_IsServer
then
3362 MH_SEND_ItemSpawn(True, id
);
3366 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3367 Srv
:= g_Game_IsServer
;
3368 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3369 if Srv
then FDeath
:= FDeath
+ 1;
3374 if not FPhysics
then
3380 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3382 if FLives
> 0 then FLives
:= FLives
- 1;
3383 if FLives
= 0 then FNoRespawn
:= True;
3386 // Íîìåð òèïà ñìåðòè:
3389 K_SIMPLEKILL
: a
:= 1;
3391 K_EXTRAHARDKILL
: a
:= 3;
3396 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3398 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3405 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3407 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3408 K_EXTRAHARDKILL
, K_FALLKILL
:
3409 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3412 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3416 K_HARDKILL
, K_EXTRAHARDKILL
:
3420 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3421 if (KillType
<> K_FALLKILL
) and (Srv
) then
3422 g_Monsters_killedp();
3424 if SpawnerUID
= FUID
then
3426 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3431 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3434 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3435 begin // Óáèò äðóãèì èãðîêîì
3436 KP
:= g_Player_Get(SpawnerUID
);
3437 if (KP
<> nil) and Srv
then
3439 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3440 if SameTeam(FUID
, SpawnerUID
) then
3450 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3451 Inc(gTeamStat
[KP
.Team
].Goals
,
3452 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3454 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3457 plr
:= g_Player_Get(SpawnerUID
);
3465 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3469 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3473 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3478 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3479 begin // Óáèò ìîíñòðîì
3480 mon
:= g_Monsters_ByUID(SpawnerUID
);
3484 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
3488 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3492 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3496 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3501 else // Îñîáûå òèïû ñìåðòè
3504 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3505 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3506 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3507 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3508 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3509 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3515 for a
:= WP_FIRST
to WP_LAST
do
3519 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3520 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3521 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3522 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3523 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3524 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3525 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3526 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3527 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3536 if R_ITEM_BACKPACK
in FRulez
then
3537 PushItem(ITEM_AMMO_BACKPACK
);
3539 // Âûáðîñ ðàêåòíîãî ðàíöà:
3540 if FJetFuel
> 0 then
3541 PushItem(ITEM_JETPACK
);
3544 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) or
3545 (not LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
)) then
3547 if R_KEY_RED
in FRulez
then
3548 PushItem(ITEM_KEY_RED
);
3550 if R_KEY_GREEN
in FRulez
then
3551 PushItem(ITEM_KEY_GREEN
);
3553 if R_KEY_BLUE
in FRulez
then
3554 PushItem(ITEM_KEY_BLUE
);
3558 DropFlag(KillType
= K_FALLKILL
);
3561 g_Player_CreateCorpse(Self
);
3563 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3564 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3570 for i
:= Low(gPlayers
) to High(gPlayers
) do
3572 if gPlayers
[i
] = nil then continue
;
3573 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3576 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3577 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3582 OldLR
:= gLMSRespawn
;
3583 if (gGameSettings
.GameMode
= GM_COOP
) then
3587 // everyone is dead, restart the map
3588 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3590 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3591 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3592 gLMSRespawnTime
:= gTime
+ 5000;
3594 else if (a
= 1) then
3596 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3597 if (gPlayers
[k
] = gPlayer1
) or
3598 (gPlayers
[k
] = gPlayer2
) then
3599 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3600 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3601 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3604 else if (gGameSettings
.GameMode
= GM_TDM
) then
3606 if (ab
= 0) and (ar
<> 0) then
3609 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3611 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3612 Inc(gTeamStat
[TEAM_RED
].Goals
);
3613 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3614 gLMSRespawnTime
:= gTime
+ 5000;
3616 else if (ar
= 0) and (ab
<> 0) then
3619 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3621 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3622 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3623 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3624 gLMSRespawnTime
:= gTime
+ 5000;
3626 else if (ar
= 0) and (ab
= 0) then
3629 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3631 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3632 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3633 gLMSRespawnTime
:= gTime
+ 5000;
3636 else if (gGameSettings
.GameMode
= GM_DM
) then
3640 if gPlayers
[k
] <> nil then
3643 // survivor is the winner
3644 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3646 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3649 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3650 gLMSRespawnTime
:= gTime
+ 5000;
3652 else if (a
= 0) then
3654 // everyone is dead, restart the map
3655 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3657 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3658 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3659 gLMSRespawnTime
:= gTime
+ 5000;
3662 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3664 if NetMode
= NET_SERVER
then
3665 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3667 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3673 MH_SEND_PlayerStats(FUID
);
3674 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3675 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3678 if srv
and FNoRespawn
then Spectate(True);
3679 FWantsInGame
:= True;
3682 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3684 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3685 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3688 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3690 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3691 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3694 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3696 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3697 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3698 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3699 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3700 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3701 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3702 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3703 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3706 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3708 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3709 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3710 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3711 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3714 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3716 if g_Game_IsClient
then Exit
;
3717 if Weapon
> High(FWeapon
) then Exit
;
3718 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3721 procedure TPlayer
.resetWeaponQueue ();
3724 FNextWeapDelay
:= 0;
3727 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3731 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3732 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
3733 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
3734 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3735 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3736 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3737 else result
:= (weapon
< length(FWeapon
));
3741 // return 255 for "no switch"
3742 function TPlayer
.getNextWeaponIndex (): Byte;
3745 wantThisWeapon
: array[0..64] of Boolean;
3746 wwc
: Integer = 0; //HACK!
3749 result
:= 255; // default result: "no switch"
3750 // had weapon cycling on previous frame? remove that flag
3751 if (FNextWeap
and $2000) <> 0 then
3753 FNextWeap
:= FNextWeap
and $1FFF;
3754 FNextWeapDelay
:= 0;
3756 // cycling has priority
3757 if (FNextWeap
and $C000) <> 0 then
3759 if (FNextWeap
and $8000) <> 0 then
3763 FNextWeap
:= FNextWeap
or $2000; // we need this
3764 if FNextWeapDelay
> 0 then
3765 exit
; // cooldown time
3767 for i
:= 0 to High(FWeapon
) do
3769 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3770 if FWeapon
[cwi
] then
3772 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d', [FCurrWeap, cwi]), MSG_WARNING);
3773 result
:= Byte(cwi
);
3774 FNextWeapDelay
:= WEAPON_DELAY
;
3782 for i
:= 0 to High(wantThisWeapon
) do
3783 wantThisWeapon
[i
] := false;
3784 for i
:= 0 to High(FWeapon
) do
3785 if (FNextWeap
and (1 shl i
)) <> 0 then
3787 wantThisWeapon
[i
] := true;
3790 // exclude currently selected weapon from the set
3791 wantThisWeapon
[FCurrWeap
] := false;
3792 // slow down alterations a little
3795 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3796 // more than one weapon requested, assume "alteration" and check alteration delay
3797 if FNextWeapDelay
> 0 then
3803 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3804 // but clear all counters if no weapon should be switched
3810 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3811 // try weapons in descending order
3812 for i
:= High(FWeapon
) downto 0 do
3814 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3819 FNextWeapDelay
:= WEAPON_DELAY
* 2; // anyway, 'cause why not
3823 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3827 procedure TPlayer
.RealizeCurrentWeapon();
3828 function switchAllowed (): Boolean;
3833 if FBFGFireCounter
<> -1 then
3835 if FTime
[T_SWITCH
] > gTime
then
3837 for i
:= WP_FIRST
to WP_LAST
do
3838 if FReloading
[i
] > 0 then
3846 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3847 //FNextWeap := FNextWeap and $1FFF;
3848 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3850 if not switchAllowed
then
3852 //HACK for weapon cycling
3853 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3857 nw
:= getNextWeaponIndex();
3858 if nw
= 255 then exit
; // don't reset anything here
3859 if nw
> High(FWeapon
) then
3861 // don't forget to reset queue here!
3862 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3870 FTime
[T_SWITCH
] := gTime
+156;
3871 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3872 FModel
.SetWeapon(FCurrWeap
);
3873 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3877 procedure TPlayer
.NextWeapon();
3879 if g_Game_IsClient
then Exit
;
3883 procedure TPlayer
.PrevWeapon();
3885 if g_Game_IsClient
then Exit
;
3889 procedure TPlayer
.SetWeapon(W
: Byte);
3891 if FCurrWeap
<> W
then
3892 if W
= WEAPON_SAW
then
3893 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3896 FModel
.SetWeapon(CurrWeap
);
3900 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3902 function allowBerserkSwitching (): Boolean;
3904 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3906 if gBerserkAutoswitch
then exit
;
3907 if not conIsCheatsEnabled
then exit
;
3915 if g_Game_IsClient
then Exit
;
3917 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3918 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3923 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3925 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3929 if gFlash
= 2 then Inc(FPickup
, 5);
3933 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3935 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3939 if gFlash
= 2 then Inc(FPickup
, 5);
3943 if FArmor
< PLAYER_AP_SOFT
then
3945 FArmor
:= PLAYER_AP_SOFT
;
3948 if gFlash
= 2 then Inc(FPickup
, 5);
3952 if FArmor
< PLAYER_AP_LIMIT
then
3954 FArmor
:= PLAYER_AP_LIMIT
;
3957 if gFlash
= 2 then Inc(FPickup
, 5);
3961 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
3963 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3967 if gFlash
= 2 then Inc(FPickup
, 5);
3971 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) or (FFireTime
> 0) then
3973 if FHealth
< PLAYER_HP_LIMIT
then
3974 FHealth
:= PLAYER_HP_LIMIT
;
3975 if FArmor
< PLAYER_AP_LIMIT
then
3976 FArmor
:= PLAYER_AP_LIMIT
;
3980 if gFlash
= 2 then Inc(FPickup
, 5);
3984 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3986 FWeapon
[WEAPON_SAW
] := True;
3988 if gFlash
= 2 then Inc(FPickup
, 5);
3989 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3992 ITEM_WEAPON_SHOTGUN1
:
3993 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3995 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3996 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3998 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3999 FWeapon
[WEAPON_SHOTGUN1
] := True;
4001 if gFlash
= 2 then Inc(FPickup
, 5);
4002 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4005 ITEM_WEAPON_SHOTGUN2
:
4006 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
4008 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
4010 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4011 FWeapon
[WEAPON_SHOTGUN2
] := True;
4013 if gFlash
= 2 then Inc(FPickup
, 5);
4014 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4017 ITEM_WEAPON_CHAINGUN
:
4018 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
4020 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
4022 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4023 FWeapon
[WEAPON_CHAINGUN
] := True;
4025 if gFlash
= 2 then Inc(FPickup
, 5);
4026 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4029 ITEM_WEAPON_ROCKETLAUNCHER
:
4030 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
4032 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
4034 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
4035 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
4037 if gFlash
= 2 then Inc(FPickup
, 5);
4038 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4042 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
4044 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
4046 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4047 FWeapon
[WEAPON_PLASMA
] := True;
4049 if gFlash
= 2 then Inc(FPickup
, 5);
4050 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4054 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
4056 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
4058 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4059 FWeapon
[WEAPON_BFG
] := True;
4061 if gFlash
= 2 then Inc(FPickup
, 5);
4062 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4065 ITEM_WEAPON_SUPERPULEMET
:
4066 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
4068 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
4070 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4071 FWeapon
[WEAPON_SUPERPULEMET
] := True;
4073 if gFlash
= 2 then Inc(FPickup
, 5);
4074 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4077 ITEM_WEAPON_FLAMETHROWER
:
4078 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
4080 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
4082 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4083 FWeapon
[WEAPON_FLAMETHROWER
] := True;
4085 if gFlash
= 2 then Inc(FPickup
, 5);
4086 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4090 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4092 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4095 if gFlash
= 2 then Inc(FPickup
, 5);
4098 ITEM_AMMO_BULLETS_BOX
:
4099 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4101 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4104 if gFlash
= 2 then Inc(FPickup
, 5);
4108 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4110 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4113 if gFlash
= 2 then Inc(FPickup
, 5);
4116 ITEM_AMMO_SHELLS_BOX
:
4117 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4119 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
4122 if gFlash
= 2 then Inc(FPickup
, 5);
4126 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4128 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4131 if gFlash
= 2 then Inc(FPickup
, 5);
4134 ITEM_AMMO_ROCKET_BOX
:
4135 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4137 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
4140 if gFlash
= 2 then Inc(FPickup
, 5);
4144 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4146 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4149 if gFlash
= 2 then Inc(FPickup
, 5);
4153 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4155 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4158 if gFlash
= 2 then Inc(FPickup
, 5);
4162 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4164 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4167 if gFlash
= 2 then Inc(FPickup
, 5);
4171 if not(R_ITEM_BACKPACK
in FRulez
) or
4172 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4173 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4174 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4175 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4176 (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) then
4178 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4179 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4180 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4181 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4182 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4184 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4185 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4186 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4187 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4188 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4189 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4190 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4191 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4192 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4193 IncMax(FAmmo
[A_FUEL
], 50, FMaxAmmo
[A_FUEL
]);
4195 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
4198 if gFlash
= 2 then Inc(FPickup
, 5);
4202 if not(R_KEY_RED
in FRulez
) then
4204 Include(FRulez
, R_KEY_RED
);
4206 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4207 if gFlash
= 2 then Inc(FPickup
, 5);
4208 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4212 if not(R_KEY_GREEN
in FRulez
) then
4214 Include(FRulez
, R_KEY_GREEN
);
4216 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4217 if gFlash
= 2 then Inc(FPickup
, 5);
4218 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4222 if not(R_KEY_BLUE
in FRulez
) then
4224 Include(FRulez
, R_KEY_BLUE
);
4226 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4227 if gFlash
= 2 then Inc(FPickup
, 5);
4228 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4232 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4234 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4238 if gFlash
= 2 then Inc(FPickup
, 5);
4242 if FAir
< AIR_MAX
then
4247 if gFlash
= 2 then Inc(FPickup
, 5);
4252 if not (R_BERSERK
in FRulez
) then
4254 Include(FRulez
, R_BERSERK
);
4255 if allowBerserkSwitching
then
4257 FCurrWeap
:= WEAPON_KASTET
;
4259 FModel
.SetWeapon(WEAPON_KASTET
);
4264 if gFlash
= 2 then Inc(FPickup
, 5);
4266 FBerserk
:= gTime
+30000;
4271 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
4273 if FHealth
< PLAYER_HP_SOFT
then FHealth
:= PLAYER_HP_SOFT
;
4274 FBerserk
:= gTime
+30000;
4282 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4284 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4288 if gFlash
= 2 then Inc(FPickup
, 5);
4292 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
4294 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4298 if gFlash
= 2 then Inc(FPickup
, 5);
4302 if FArmor
< PLAYER_AP_LIMIT
then
4304 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4307 if gFlash
= 2 then Inc(FPickup
, 5);
4311 if FJetFuel
< JET_MAX
then
4313 FJetFuel
:= JET_MAX
;
4316 if gFlash
= 2 then Inc(FPickup
, 5);
4320 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4322 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4325 if gFlash
= 2 then Inc(FPickup
, 5);
4330 procedure TPlayer
.Touch();
4334 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4337 // Áðîñèòü ôëàã òîâàðèùó:
4338 if gGameSettings
.GameMode
= GM_CTF
then
4343 procedure TPlayer
.Push(vx
, vy
: Integer);
4345 if (not FPhysics
) and FGhost
then
4347 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4348 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4349 if g_Game_IsNet
and g_Game_IsServer
then
4350 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4353 procedure TPlayer
.Reset(Force
: Boolean);
4359 FTime
[T_RESPAWN
] := 0;
4360 FTime
[T_FLAGCAP
] := 0;
4374 FSpectator
:= False;
4377 FSpectatePlayer
:= -1;
4378 FNoRespawn
:= False;
4380 FLives
:= gGameSettings
.MaxLives
;
4385 procedure TPlayer
.SoftReset();
4391 FBFGFireCounter
:= -1;
4399 SetAction(A_STAND
, True);
4402 function TPlayer
.GetRespawnPoint(): Byte;
4407 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4409 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4410 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4412 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4414 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4415 if Self
= gPlayer1
then
4416 c
:= RESPAWNPOINT_PLAYER1
4418 c
:= RESPAWNPOINT_PLAYER2
;
4419 if g_Map_GetPointCount(c
) > 0 then
4425 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4426 if Self
= gPlayer1
then
4427 c
:= RESPAWNPOINT_PLAYER2
4429 c
:= RESPAWNPOINT_PLAYER1
;
4430 if g_Map_GetPointCount(c
) > 0 then
4437 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4438 if Random(2) = 0 then
4439 c
:= RESPAWNPOINT_PLAYER1
4441 c
:= RESPAWNPOINT_PLAYER2
;
4442 if g_Map_GetPointCount(c
) > 0 then
4449 // Òî÷êà ëþáîé èç êîìàíä
4450 if Random(2) = 0 then
4451 c
:= RESPAWNPOINT_RED
4453 c
:= RESPAWNPOINT_BLUE
;
4454 if g_Map_GetPointCount(c
) > 0 then
4461 c
:= RESPAWNPOINT_DM
;
4462 if g_Map_GetPointCount(c
) > 0 then
4470 if gGameSettings
.GameMode
= GM_DM
then
4473 c
:= RESPAWNPOINT_DM
;
4474 if g_Map_GetPointCount(c
) > 0 then
4480 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4481 if Random(2) = 0 then
4482 c
:= RESPAWNPOINT_PLAYER1
4484 c
:= RESPAWNPOINT_PLAYER2
;
4485 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
4504 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4506 // Òî÷êà ñâîåé êîìàíäû
4507 c
:= RESPAWNPOINT_DM
;
4508 if FTeam
= TEAM_RED
then
4509 c
:= RESPAWNPOINT_RED
;
4510 if FTeam
= TEAM_BLUE
then
4511 c
:= RESPAWNPOINT_BLUE
;
4512 if g_Map_GetPointCount(c
) > 0 then
4519 c
:= RESPAWNPOINT_DM
;
4520 if g_Map_GetPointCount(c
) > 0 then
4526 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4527 if Random(2) = 0 then
4528 c
:= RESPAWNPOINT_PLAYER1
4530 c
:= RESPAWNPOINT_PLAYER2
;
4531 if g_Map_GetPointCount(c
) > 0 then
4537 // Òî÷êà äðóãîé êîìàíäû
4538 c
:= RESPAWNPOINT_DM
;
4539 if FTeam
= TEAM_RED
then
4540 c
:= RESPAWNPOINT_BLUE
;
4541 if FTeam
= TEAM_BLUE
then
4542 c
:= RESPAWNPOINT_RED
;
4543 if g_Map_GetPointCount(c
) > 0 then
4551 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4553 RespawnPoint
: TRespawnPoint
;
4559 FBFGFireCounter
:= -1;
4564 if not g_Game_IsServer
then
4568 FWantsInGame
:= True;
4569 FJustTeleported
:= True;
4572 FTime
[T_RESPAWN
] := 0;
4576 // if server changes MaxLives we gotta be ready
4577 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4579 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4580 if FTime
[T_RESPAWN
] > gTime
then
4583 // Ïðîñðàë âñå æèçíè:
4586 if not FSpectator
then Spectate(True);
4587 FWantsInGame
:= True;
4591 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4592 begin // "Ñâîÿ èãðà"
4593 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4594 FRulez
:= FRulez
-[R_BERSERK
];
4596 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4598 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4599 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4602 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4603 c
:= GetRespawnPoint();
4608 // Âîñêðåøåíèå áåç îðóæèÿ:
4611 FHealth
:= Round(PLAYER_HP_SOFT
* (FHandicap
/ 100));
4617 for a
:= WP_FIRST
to WP_LAST
do
4619 FWeapon
[a
] := False;
4623 FWeapon
[WEAPON_PISTOL
] := True;
4624 FWeapon
[WEAPON_KASTET
] := True;
4625 FCurrWeap
:= WEAPON_PISTOL
;
4628 FModel
.SetWeapon(FCurrWeap
);
4630 for b
:= A_BULLETS
to A_HIGH
do
4633 FAmmo
[A_BULLETS
] := 50;
4635 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4636 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4637 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4638 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4639 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4641 if (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) and
4642 LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
) then
4643 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4648 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4649 if not g_Map_GetPoint(c
, RespawnPoint
) then
4651 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4655 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4656 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4657 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4663 FDirection
:= RespawnPoint
.Direction
;
4664 if FDirection
= TDirection
.D_LEFT
then
4669 SetAction(A_STAND
, True);
4670 FModel
.Direction
:= FDirection
;
4672 for a
:= Low(FTime
) to High(FTime
) do
4675 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4678 // Respawn invulnerability
4679 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.SpawnInvul
> 0) then
4681 FMegaRulez
[MR_INVUL
] := gTime
+ gGameSettings
.SpawnInvul
* 1000;
4682 FSpawnInvul
:= FMegaRulez
[MR_INVUL
];
4687 FCanJetpack
:= False;
4693 // Àíèìàöèÿ âîçðîæäåíèÿ:
4694 if (not gLoadGameMode
) and (not Silent
) then
4695 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4697 Anim
:= TAnimation
.Create(ID
, False, 3);
4698 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4699 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4703 FSpectator
:= False;
4706 FSpectatePlayer
:= -1;
4709 if (gPlayer1
= nil) and (gLMSPID1
= FUID
) then
4711 if (gPlayer2
= nil) and (gLMSPID2
= FUID
) then
4714 if g_Game_IsNet
then
4716 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4717 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4719 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4720 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4725 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4728 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4729 else if (not NoMove
) then
4731 GameX
:= gMapInfo
.Width
div 2;
4732 GameY
:= gMapInfo
.Height
div 2;
4741 FWantsInGame
:= False;
4746 if Self
= gPlayer1
then
4751 if Self
= gPlayer2
then
4758 if g_Game_IsNet
then
4759 MH_SEND_PlayerStats(FUID
);
4762 procedure TPlayer
.SwitchNoClip
;
4766 FGhost
:= not FGhost
;
4767 FPhysics
:= not FGhost
;
4779 procedure TPlayer
.Run(Direction
: TDirection
);
4783 if MAX_RUNVEL
> 8 then
4787 if Direction
= TDirection
.D_LEFT
then
4789 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4790 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4793 if FObj
.Vel
.X
< MAX_RUNVEL
then
4794 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4796 // Âîçìîæíî, ïèíàåì êóñêè:
4797 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4799 b
:= Abs(FObj
.Vel
.X
);
4800 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4801 for a
:= 0 to High(gGibs
) do
4803 if gGibs
[a
].alive
and
4804 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4805 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4808 if FObj
.Vel
.X
< 0 then
4810 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4814 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4816 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4824 procedure TPlayer
.SeeDown();
4826 SetAction(A_SEEDOWN
);
4828 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4830 if FIncCam
> -120.0 * g_dbg_scale
then DecMin(FIncCam
, 5, Integer(-120.0 * g_dbg_scale
));
4833 procedure TPlayer
.SeeUp();
4837 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4839 if FIncCam
< 120.0 * g_dbg_scale
then IncMax(FIncCam
, 5, Integer(120.0 * g_dbg_scale
));
4842 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4850 A_ATTACK
: Prior
:= 2;
4851 A_SEEUP
: Prior
:= 1;
4852 A_SEEDOWN
: Prior
:= 1;
4853 A_ATTACKUP
: Prior
:= 2;
4854 A_ATTACKDOWN
: Prior
:= 2;
4859 if (Prior
> FActionPrior
) or Force
then
4860 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4862 FActionPrior
:= Prior
;
4863 FActionAnim
:= Action
;
4864 FActionForce
:= Force
;
4865 FActionChanged
:= True;
4868 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4871 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4873 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4874 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4875 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4876 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4879 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4886 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4888 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4889 if g_Game_IsServer
and g_Game_IsNet
then
4890 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4894 FJustTeleported
:= True;
4899 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4901 Anim
:= TAnimation
.Create(ID
, False, 3);
4904 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4905 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4906 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4907 if g_Game_IsServer
and g_Game_IsNet
then
4908 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4909 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4913 FObj
.X
:= X
-PLAYER_RECT
.X
;
4914 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4915 if FAlive
and FGhost
then
4921 if not g_Game_IsNet
then
4925 SetDirection(TDirection
.D_LEFT
);
4931 SetDirection(TDirection
.D_RIGHT
);
4937 if FDirection
= TDirection
.D_RIGHT
then
4939 SetDirection(TDirection
.D_LEFT
);
4944 SetDirection(TDirection
.D_RIGHT
);
4950 if not silent
and (Anim
<> nil) then
4952 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4953 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4956 if g_Game_IsServer
and g_Game_IsNet
then
4957 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4958 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4965 function nonz(a
: Single): Single;
4973 function TPlayer
.followCorpse(): Boolean;
4978 if FAlive
or FSpectator
then
4980 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
4982 for i
:= 0 to High(gCorpses
) do
4983 if gCorpses
[i
] <> nil then
4984 if gCorpses
[i
].FPlayerUID
= FUID
then
4987 FObj
.X
:= gCorpses
[i
].FObj
.X
;
4988 FObj
.Y
:= gCorpses
[i
].FObj
.Y
;
4989 FObj
.Vel
.X
:= gCorpses
[i
].FObj
.Vel
.X
;
4990 FObj
.Vel
.Y
:= gCorpses
[i
].FObj
.Vel
.Y
;
4991 FObj
.Accel
.X
:= gCorpses
[i
].FObj
.Accel
.X
;
4992 FObj
.Accel
.Y
:= gCorpses
[i
].FObj
.Accel
.Y
;
4997 procedure TPlayer
.Update();
5000 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
5001 blockmon
, headwater
, dospawn
: Boolean;
5006 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
5007 AnyServer
:= g_Game_IsServer
;
5009 if g_Game_IsClient
and (NetInterpLevel
> 0) then
5010 DoLerp(NetInterpLevel
+ 1)
5016 if FClientID
>= 0 then
5018 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
5019 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
5020 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
5029 if FAlive
and (FPunchAnim
<> nil) then
5030 FPunchAnim
.Update();
5032 if FAlive
and (gFly
or FJetpack
) then
5035 if FDirection
= TDirection
.D_LEFT
then
5040 if FAlive
and (not FGhost
) then
5042 if FKeys
[KEY_UP
].Pressed
then
5044 if FKeys
[KEY_DOWN
].Pressed
then
5048 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
5051 i
:= g_basic
.Sign(FIncCam
);
5052 FIncCam
:= Abs(FIncCam
);
5053 DecMin(FIncCam
, 5, 0);
5054 FIncCam
:= FIncCam
*i
;
5057 // no need to do that each second frame, weapon queue will take care of it
5058 if FAlive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
5059 if FAlive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
5061 if gTime
mod (GAME_TICK
*2) <> 0 then
5063 if (FObj
.Vel
.X
= 0) and FAlive
then
5065 if FKeys
[KEY_LEFT
].Pressed
then
5066 Run(TDirection
.D_LEFT
);
5067 if FKeys
[KEY_RIGHT
].Pressed
then
5068 Run(TDirection
.D_RIGHT
);
5073 if not followCorpse() then
5074 g_Obj_Move(@FObj
, True, True, True);
5075 positionChanged(); // this updates spatial accelerators
5081 FActionChanged
:= False;
5085 // Let alive player do some actions
5086 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
5087 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
5088 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
5089 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
5090 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire()
5096 if NetServer
then MH_SEND_PlayerStats(FUID
);
5099 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
5100 if FKeys
[KEY_JUMP
].Pressed
then Jump()
5103 if AnyServer
and FJetpack
then
5107 if NetServer
then MH_SEND_PlayerStats(FUID
);
5109 FCanJetpack
:= True;
5116 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
5118 if FKeys
[k
].Pressed
then
5126 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5129 if (FTime
[T_RESPAWN
] <= gTime
) and
5130 gGameOn
and (not FAlive
) then
5132 if (g_Player_GetCount() > 1) then
5136 gExit
:= EXIT_RESTART
;
5141 // Dead spectator actions
5144 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
5145 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
5149 if (FSpectatePlayer
>= High(gPlayers
)) then
5150 FSpectatePlayer
:= -1
5154 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
5155 if gPlayers
[I
] <> nil then
5156 if gPlayers
[I
].alive
then
5157 if gPlayers
[I
].UID
<> FUID
then
5159 FSpectatePlayer
:= I
;
5164 if not SetSpect
then FSpectatePlayer
:= -1;
5175 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5177 FYTo
:= FObj
.Y
- 32;
5178 FSpectatePlayer
:= -1;
5180 if FKeys
[KEY_DOWN
].Pressed
then
5182 FYTo
:= FObj
.Y
+ 32;
5183 FSpectatePlayer
:= -1;
5185 if FKeys
[KEY_LEFT
].Pressed
then
5187 FXTo
:= FObj
.X
- 32;
5188 FSpectatePlayer
:= -1;
5190 if FKeys
[KEY_RIGHT
].Pressed
then
5192 FXTo
:= FObj
.X
+ 32;
5193 FSpectatePlayer
:= -1;
5196 if (FXTo
< -64) then
5198 else if (FXTo
> gMapInfo
.Width
+ 32) then
5199 FXTo
:= gMapInfo
.Width
+ 32;
5200 if (FYTo
< -72) then
5202 else if (FYTo
> gMapInfo
.Height
+ 32) then
5203 FYTo
:= gMapInfo
.Height
+ 32;
5208 if not followCorpse() then
5209 g_Obj_Move(@FObj
, True, True, True);
5210 positionChanged(); // this updates spatial accelerators
5217 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5218 if gPlayers
[FSpectatePlayer
] <> nil then
5219 if gPlayers
[FSpectatePlayer
].alive
then
5221 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
5222 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
5226 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5227 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5228 PANEL_BLOCKMON
, True);
5229 headwater
:= HeadInLiquid(0, 0);
5231 // Ñîïðîòèâëåíèå âîçäóõà:
5232 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5233 if FObj
.Vel
.X
<> 0 then
5234 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5236 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5237 DecMin(FPain
, 5, 0);
5238 DecMin(FPickup
, 1, 0);
5240 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5242 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5243 FMegaRulez
[MR_SUIT
] := 0;
5244 FMegaRulez
[MR_INVUL
] := 0;
5245 FMegaRulez
[MR_INVIS
] := 0;
5246 Kill(K_FALLKILL
, 0, HIT_FALL
);
5253 if FCurrWeap
= WEAPON_SAW
then
5254 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5255 FSawSoundSelect
.IsPlaying()) then
5256 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5259 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5260 (not FJetSoundOff
.IsPlaying()) then
5262 FJetSoundFly
.SetPosition(0);
5263 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5266 for b
:= WP_FIRST
to WP_LAST
do
5267 if FReloading
[b
] > 0 then
5273 if FShellTimer
> -1 then
5274 if FShellTimer
= 0 then
5276 if FShellType
= SHELL_SHELL
then
5277 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5278 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5279 else if FShellType
= SHELL_DBLSHELL
then
5281 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5282 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5283 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5284 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5287 end else Dec(FShellTimer
);
5289 if (FBFGFireCounter
> -1) then
5290 if FBFGFireCounter
= 0 then
5294 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5295 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5296 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5297 yd
:= wy
+firediry();
5298 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5299 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5300 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5301 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5302 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5305 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5306 FBFGFireCounter
:= -1;
5309 FBFGFireCounter
:= 0
5311 Dec(FBFGFireCounter
);
5313 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5315 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5317 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5320 if (headwater
or blockmon
) then
5326 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5329 else if (FAir
mod 31 = 0) and not blockmon
then
5331 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5332 if Random(2) = 0 then
5333 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5335 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5337 end else if FAir
< AIR_DEF
then
5340 if FFireTime
> 0 then
5342 if BodyInLiquid(0, 0) then
5347 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5349 if FMegaRulez
[MR_SUIT
] = gTime
then
5356 if FFirePainTime
<= 0 then
5358 if g_Game_IsServer
then
5359 Damage(2, FFireAttacker
, 0, 0, HIT_FLAME
);
5360 FFirePainTime
:= 12 - FFireTime
div 12;
5362 FFirePainTime
:= FFirePainTime
- 1;
5363 FFireTime
:= FFireTime
- 1;
5364 if ((FFireTime
mod 33) = 0) and (FMegaRulez
[MR_INVUL
] < gTime
) then
5365 FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
);
5366 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5367 MH_SEND_PlayerStats(FUID
);
5371 if FDamageBuffer
> 0 then
5373 if FDamageBuffer
>= 9 then
5377 if FDamageBuffer
< 30 then i
:= 9
5378 else if FDamageBuffer
< 100 then i
:= 18
5382 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5383 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5384 FHealth
:= FHealth
-ii
;
5387 FHealth
:= FHealth
+FArmor
;
5392 if FHealth
<= 0 then
5393 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5394 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5395 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5397 if FAlive
and ((FLastHit
<> HIT_FLAME
) or (FFireTime
<= 0)) then
5399 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5400 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5401 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5402 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5409 end; // if FAlive then ...
5411 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5413 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5414 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5415 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5416 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5418 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5419 then SetAction(A_STAND
, True);
5421 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5423 for b
:= Low(FKeys
) to High(FKeys
) do
5424 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5428 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5430 x
:= FObj
.X
+PLAYER_RECT
.X
;
5431 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5432 w
:= PLAYER_RECT
.Width
;
5433 h
:= PLAYER_RECT
.Height
;
5437 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5439 if (dx
<> 0) or (dy
<> 0) then
5448 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5450 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5451 FObj
.Y
+PLAYER_RECT
.Y
,
5458 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5460 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5461 FObj
.Y
+PLAYER_RECT
.Y
,
5465 Panel
.Width
, Panel
.Height
);
5468 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5470 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5471 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5472 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5473 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5476 function g_Player_ValidName(Name
: string): Boolean;
5482 if gPlayers
= nil then Exit
;
5484 for a
:= 0 to High(gPlayers
) do
5485 if gPlayers
[a
] <> nil then
5486 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5493 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5497 d
:= FModel
.Direction
;
5499 FModel
.Direction
:= Direction
;
5500 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5502 FDirection
:= Direction
;
5505 function TPlayer
.GetKeys(): Byte;
5509 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5510 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5511 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5513 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5514 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5517 procedure TPlayer
.Use();
5521 if FTime
[T_USE
] > gTime
then Exit
;
5523 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5524 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5526 for a
:= 0 to High(gPlayers
) do
5527 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5528 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5529 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5530 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5532 gPlayers
[a
].Touch();
5533 if g_Game_IsNet
and g_Game_IsServer
then
5534 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5537 FTime
[T_USE
] := gTime
+120;
5540 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5544 WX
, WY
, XD
, YD
: Integer;
5556 if R_BERSERK
in FRulez
then
5558 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5559 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5560 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5563 locobj
.rect
.Width
:= 39;
5564 locobj
.rect
.Height
:= 52;
5565 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5566 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5567 locobj
.Accel
.X
:= xd
-wx
;
5568 locobj
.Accel
.y
:= yd
-wy
;
5570 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5571 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5573 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5577 FPain
:= min(FPain
+ 25, 50);
5579 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5584 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5585 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5587 FSawSoundSelect
.Stop();
5589 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5591 else if not FSawSoundHit
.IsPlaying() then
5593 FSawSoundSelect
.Stop();
5594 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5601 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5602 FFireAngle
:= FAngle
;
5604 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5605 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5610 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5611 FFireAngle
:= FAngle
;
5614 FShellType
:= SHELL_SHELL
;
5619 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5620 FFireAngle
:= FAngle
;
5623 FShellType
:= SHELL_DBLSHELL
;
5628 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5629 FFireAngle
:= FAngle
;
5631 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5632 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5635 WEAPON_ROCKETLAUNCHER
:
5637 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5638 FFireAngle
:= FAngle
;
5644 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5645 FFireAngle
:= FAngle
;
5651 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5652 FFireAngle
:= FAngle
;
5656 WEAPON_SUPERPULEMET
:
5658 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5659 FFireAngle
:= FAngle
;
5661 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5662 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5665 WEAPON_FLAMETHROWER
:
5667 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5669 FFireAngle
:= FAngle
;
5676 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5677 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5678 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5681 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5683 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5684 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5687 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5691 if NetInterpLevel
< 1 then
5701 AX
:= Abs(FXTo
- FObj
.X
);
5702 AY
:= Abs(FYTo
- FObj
.Y
);
5703 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5705 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5710 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5712 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5713 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5714 PANEL_LIFTUP
, False) then Result
:= -1
5716 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5717 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5718 PANEL_LIFTDOWN
, False) then Result
:= 1
5722 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5729 if Flag
= FLAG_NONE
then
5732 if not g_Game_IsServer
then Exit
;
5734 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5735 if (Flag
= FTeam
) and
5736 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5737 (FFlag
<> FLAG_NONE
) then
5739 if FFlag
= FLAG_RED
then
5740 s
:= _lc
[I_PLAYER_FLAG_RED
]
5742 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5744 evtype
:= FLAG_STATE_SCORED
;
5746 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5747 Insert('.', ts
, Length(ts
) + 1 - 3);
5748 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5750 g_Map_ResetFlag(FFlag
);
5751 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5753 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5754 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5755 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5760 if not sound_cap_flag
[a
].IsPlaying() then
5761 sound_cap_flag
[a
].Play();
5763 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5766 if g_Game_IsNet
then
5768 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5772 gFlags
[FFlag
].CaptureTime
:= 0;
5777 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5778 if (Flag
= FTeam
) and
5779 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5781 if Flag
= FLAG_RED
then
5782 s
:= _lc
[I_PLAYER_FLAG_RED
]
5784 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5786 evtype
:= FLAG_STATE_RETURNED
;
5787 gFlags
[Flag
].CaptureTime
:= 0;
5789 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5791 g_Map_ResetFlag(Flag
);
5792 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5794 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5795 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5796 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5801 if not sound_ret_flag
[a
].IsPlaying() then
5802 sound_ret_flag
[a
].Play();
5805 if g_Game_IsNet
then
5807 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5813 // Ïîäîáðàë ÷óæîé ôëàã:
5814 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5818 if Flag
= FLAG_RED
then
5819 s
:= _lc
[I_PLAYER_FLAG_RED
]
5821 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5823 evtype
:= FLAG_STATE_CAPTURED
;
5825 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5827 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5829 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5831 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5832 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5833 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5838 if not sound_get_flag
[a
].IsPlaying() then
5839 sound_get_flag
[a
].Play();
5842 if g_Game_IsNet
then
5844 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5850 procedure TPlayer
.SetFlag(Flag
: Byte);
5853 if FModel
<> nil then
5854 FModel
.SetFlag(FFlag
);
5857 function TPlayer
.DropFlag(Silent
: Boolean = True): Boolean;
5863 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5865 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5866 with gFlags
[FFlag
] do
5870 Direction
:= FDirection
;
5871 State
:= FLAG_STATE_DROPPED
;
5873 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5874 (FObj
.Vel
.Y
div 2)-2+Random(5));
5875 positionChanged(); // this updates spatial accelerators
5877 if FFlag
= FLAG_RED
then
5878 s
:= _lc
[I_PLAYER_FLAG_RED
]
5880 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5882 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5883 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5885 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5886 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5887 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5892 if (not Silent
) and (not sound_lost_flag
[a
].IsPlaying()) then
5893 sound_lost_flag
[a
].Play();
5895 if g_Game_IsNet
then
5896 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5902 procedure TPlayer
.GetSecret();
5904 if (self
= gPlayer1
) or (self
= gPlayer2
) then
5906 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [FName
]), True);
5907 g_Sound_PlayEx('SOUND_GAME_SECRET');
5912 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5914 Assert(Key
<= High(FKeys
));
5916 FKeys
[Key
].Pressed
:= True;
5917 FKeys
[Key
].Time
:= Time
;
5920 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5922 Result
:= FKeys
[K
].Pressed
;
5925 procedure TPlayer
.ReleaseKeys();
5929 for a
:= Low(FKeys
) to High(FKeys
) do
5931 FKeys
[a
].Pressed
:= False;
5936 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5940 function TPlayer
.firediry(): Integer;
5942 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5943 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5947 procedure TPlayer
.RememberState();
5951 FSavedState
.Health
:= FHealth
;
5952 FSavedState
.Armor
:= FArmor
;
5953 FSavedState
.Air
:= FAir
;
5954 FSavedState
.JetFuel
:= FJetFuel
;
5955 FSavedState
.CurrWeap
:= FCurrWeap
;
5956 FSavedState
.NextWeap
:= FNextWeap
;
5957 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5960 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5962 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5964 FSavedState
.Rulez
:= FRulez
;
5965 FSavedState
.WaitRecall
:= True;
5968 procedure TPlayer
.RecallState();
5972 if not FSavedState
.WaitRecall
then Exit
;
5974 FHealth
:= FSavedState
.Health
;
5975 FArmor
:= FSavedState
.Armor
;
5976 FAir
:= FSavedState
.Air
;
5977 FJetFuel
:= FSavedState
.JetFuel
;
5978 FCurrWeap
:= FSavedState
.CurrWeap
;
5979 FNextWeap
:= FSavedState
.NextWeap
;
5980 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5983 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5985 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5987 FRulez
:= FSavedState
.Rulez
;
5988 FSavedState
.WaitRecall
:= False;
5990 if gGameSettings
.GameType
= GT_SERVER
then
5991 MH_SEND_PlayerStats(FUID
);
5994 procedure TPlayer
.SaveState (st
: TStream
);
6000 utils
.writeSign(st
, 'PLYR');
6001 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
6003 utils
.writeBool(st
, FIamBot
);
6005 utils
.writeInt(st
, Word(FUID
));
6007 utils
.writeStr(st
, FName
);
6009 utils
.writeInt(st
, Byte(FTeam
));
6011 utils
.writeBool(st
, FAlive
);
6012 // Èçðàñõîäîâàë ëè âñå æèçíè
6013 utils
.writeBool(st
, FNoRespawn
);
6015 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
6016 utils
.writeInt(st
, Byte(b
));
6018 utils
.writeInt(st
, LongInt(FHealth
));
6019 // Êîýôôèöèåíò èíâàëèäíîñòè
6020 utils
.writeInt(st
, LongInt(FHandicap
));
6022 utils
.writeInt(st
, Byte(FLives
));
6024 utils
.writeInt(st
, LongInt(FArmor
));
6026 utils
.writeInt(st
, LongInt(FAir
));
6028 utils
.writeInt(st
, LongInt(FJetFuel
));
6030 utils
.writeInt(st
, LongInt(FPain
));
6032 utils
.writeInt(st
, LongInt(FKills
));
6034 utils
.writeInt(st
, LongInt(FMonsterKills
));
6036 utils
.writeInt(st
, LongInt(FFrags
));
6038 utils
.writeInt(st
, Byte(FFragCombo
));
6039 // Âðåìÿ ïîñëåäíåãî ôðàãà
6040 utils
.writeInt(st
, LongWord(FLastFrag
));
6042 utils
.writeInt(st
, LongInt(FDeath
));
6044 utils
.writeInt(st
, Byte(FFlag
));
6046 utils
.writeInt(st
, LongInt(FSecrets
));
6048 utils
.writeInt(st
, Byte(FCurrWeap
));
6050 utils
.writeInt(st
, Word(FNextWeap
));
6052 utils
.writeInt(st
, Byte(FNextWeapDelay
));
6053 // Âðåìÿ çàðÿäêè BFG
6054 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
6056 utils
.writeInt(st
, LongInt(FDamageBuffer
));
6057 // Ïîñëåäíèé óäàðèâøèé
6058 utils
.writeInt(st
, Word(FLastSpawnerUID
));
6059 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6060 utils
.writeInt(st
, Byte(FLastHit
));
6062 Obj_SaveState(st
, @FObj
);
6063 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6064 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
6065 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6066 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
6068 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
6069 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6070 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
6072 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
6073 // Íàëè÷èå êðàñíîãî êëþ÷à
6074 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
6075 // Íàëè÷èå çåëåíîãî êëþ÷à
6076 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
6077 // Íàëè÷èå ñèíåãî êëþ÷à
6078 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
6080 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
6081 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6082 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
6083 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6084 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
6086 utils
.writeStr(st
, FModel
.Name
);
6088 utils
.writeInt(st
, Byte(FColor
.R
));
6089 utils
.writeInt(st
, Byte(FColor
.G
));
6090 utils
.writeInt(st
, Byte(FColor
.B
));
6094 procedure TPlayer
.LoadState (st
: TStream
);
6103 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
6104 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
6106 FIamBot
:= utils
.readBool(st
);
6108 FUID
:= utils
.readWord(st
);
6110 str
:= utils
.readStr(st
);
6111 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
6113 FTeam
:= utils
.readByte(st
);
6115 FAlive
:= utils
.readBool(st
);
6116 // Èçðàñõîäîâàë ëè âñå æèçíè
6117 FNoRespawn
:= utils
.readBool(st
);
6119 b
:= utils
.readByte(st
);
6120 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
6122 FHealth
:= utils
.readLongInt(st
);
6123 // Êîýôôèöèåíò èíâàëèäíîñòè
6124 FHandicap
:= utils
.readLongInt(st
);
6126 FLives
:= utils
.readByte(st
);
6128 FArmor
:= utils
.readLongInt(st
);
6130 FAir
:= utils
.readLongInt(st
);
6132 FJetFuel
:= utils
.readLongInt(st
);
6134 FPain
:= utils
.readLongInt(st
);
6136 FKills
:= utils
.readLongInt(st
);
6138 FMonsterKills
:= utils
.readLongInt(st
);
6140 FFrags
:= utils
.readLongInt(st
);
6142 FFragCombo
:= utils
.readByte(st
);
6143 // Âðåìÿ ïîñëåäíåãî ôðàãà
6144 FLastFrag
:= utils
.readLongWord(st
);
6146 FDeath
:= utils
.readLongInt(st
);
6148 FFlag
:= utils
.readByte(st
);
6150 FSecrets
:= utils
.readLongInt(st
);
6152 FCurrWeap
:= utils
.readByte(st
);
6154 FNextWeap
:= utils
.readWord(st
);
6156 FNextWeapDelay
:= utils
.readByte(st
);
6157 // Âðåìÿ çàðÿäêè BFG
6158 FBFGFireCounter
:= utils
.readSmallInt(st
);
6160 FDamageBuffer
:= utils
.readLongInt(st
);
6161 // Ïîñëåäíèé óäàðèâøèé
6162 FLastSpawnerUID
:= utils
.readWord(st
);
6163 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6164 FLastHit
:= utils
.readByte(st
);
6166 Obj_LoadState(@FObj
, st
);
6167 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6168 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
6169 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6170 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
6172 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
6173 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6174 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
6176 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
6177 // Íàëè÷èå êðàñíîãî êëþ÷à
6178 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
6179 // Íàëè÷èå çåëåíîãî êëþ÷à
6180 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
6181 // Íàëè÷èå ñèíåãî êëþ÷à
6182 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
6184 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
6185 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6186 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
6187 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6188 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
6190 str
:= utils
.readStr(st
);
6192 FColor
.R
:= utils
.readByte(st
);
6193 FColor
.G
:= utils
.readByte(st
);
6194 FColor
.B
:= utils
.readByte(st
);
6195 if (self
= gPlayer1
) then
6197 str
:= gPlayer1Settings
.Model
;
6198 FColor
:= gPlayer1Settings
.Color
;
6200 else if (self
= gPlayer2
) then
6202 str
:= gPlayer2Settings
.Model
;
6203 FColor
:= gPlayer2Settings
.Color
;
6205 // Îáíîâëÿåì ìîäåëü èãðîêà
6207 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
6208 FModel
.Color
:= TEAMCOLOR
[FTeam
]
6210 FModel
.Color
:= FColor
;
6214 procedure TPlayer
.AllRulez(Health
: Boolean);
6220 FHealth
:= PLAYER_HP_LIMIT
;
6221 FArmor
:= PLAYER_AP_LIMIT
;
6225 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
6226 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
6227 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6230 procedure TPlayer
.RestoreHealthArmor();
6232 FHealth
:= PLAYER_HP_LIMIT
;
6233 FArmor
:= PLAYER_AP_LIMIT
;
6236 procedure TPlayer
.FragCombo();
6240 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6242 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6244 if FFragCombo
< 5 then
6246 Param
:= FUID
or (FFragCombo
shl 16);
6247 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6248 (FComboEvnt
<= High(gDelayedEvents
)) and
6249 gDelayedEvents
[FComboEvnt
].Pending
and
6250 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6251 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6253 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6254 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6257 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6265 procedure TPlayer
.GiveItem(ItemType
: Byte);
6269 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6271 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6275 if FAir
< AIR_MAX
then
6282 if not (R_BERSERK
in FRulez
) then
6284 Include(FRulez
, R_BERSERK
);
6285 if FBFGFireCounter
< 1 then
6287 FCurrWeap
:= WEAPON_KASTET
;
6289 FModel
.SetWeapon(WEAPON_KASTET
);
6293 FBerserk
:= gTime
+30000;
6295 if FHealth
< PLAYER_HP_SOFT
then
6297 FHealth
:= PLAYER_HP_SOFT
;
6298 FBerserk
:= gTime
+30000;
6303 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6305 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6309 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6311 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6315 if FJetFuel
< JET_MAX
then
6317 FJetFuel
:= JET_MAX
;
6320 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6321 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6323 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6324 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6326 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6328 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6330 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6331 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6334 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6335 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6336 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6337 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6338 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6339 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6340 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6341 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6342 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6344 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6345 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6346 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6347 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6348 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6349 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6350 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6351 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6352 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6355 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6356 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6357 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6358 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6359 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6361 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6362 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6363 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6364 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6365 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6367 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6368 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6369 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6370 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6372 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6375 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6376 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6377 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6379 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6380 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6385 if g_Game_IsNet
and g_Game_IsServer
then
6386 MH_SEND_PlayerStats(FUID
);
6389 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6394 if (Random(5) = 1) and (Times
= 1) then
6397 if BodyInLiquid(0, 0) then
6399 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6400 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6401 if Random(2) = 0 then
6402 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6404 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6408 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6410 for i
:= 1 to Times
do
6412 Anim
:= TAnimation
.Create(id
, False, 3);
6414 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6415 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6421 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6426 if (Random(10) = 1) and (Times
= 1) then
6429 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6431 for i
:= 1 to Times
do
6433 Anim
:= TAnimation
.Create(id
, False, 3);
6435 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6436 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6442 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6444 FSawSound
.Pause(Enable
);
6445 FSawSoundIdle
.Pause(Enable
);
6446 FSawSoundHit
.Pause(Enable
);
6447 FSawSoundSelect
.Pause(Enable
);
6448 FFlameSoundOn
.Pause(Enable
);
6449 FFlameSoundOff
.Pause(Enable
);
6450 FFlameSoundWork
.Pause(Enable
);
6451 FJetSoundFly
.Pause(Enable
);
6452 FJetSoundOn
.Pause(Enable
);
6453 FJetSoundOff
.Pause(Enable
);
6458 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6463 FObj
.Rect
:= PLAYER_CORPSERECT
;
6464 FModelName
:= ModelName
;
6469 FState
:= CORPSE_STATE_MESS
;
6470 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6474 FState
:= CORPSE_STATE_NORMAL
;
6475 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6479 destructor TCorpse
.Destroy();
6486 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6488 procedure TCorpse
.positionChanged (); inline; begin end;
6490 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6492 if (dx
<> 0) or (dy
<> 0) then
6501 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6503 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6504 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6505 w
:= PLAYER_CORPSERECT
.Width
;
6506 h
:= PLAYER_CORPSERECT
.Height
;
6510 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6515 if FState
= CORPSE_STATE_REMOVEME
then
6518 FDamage
:= FDamage
+ Value
;
6520 if FDamage
> 150 then
6522 if FAnimation
<> nil then
6527 FState
:= CORPSE_STATE_REMOVEME
;
6529 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6530 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6531 FModelName
, FColor
);
6532 // Çâóê ìÿñà îò òðóïà:
6533 pm
:= g_PlayerModel_Get(FModelName
);
6534 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6538 if (gBodyKillEvent
<> -1)
6539 and gDelayedEvents
[gBodyKillEvent
].Pending
then
6540 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
6541 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, 0);
6546 Blood
:= g_PlayerModel_GetBlood(FModelName
);
6547 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6548 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6549 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6550 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6551 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6552 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
6556 procedure TCorpse
.Draw();
6558 if FState
= CORPSE_STATE_REMOVEME
then
6561 if FAnimation
<> nil then
6562 FAnimation
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6564 if FAnimationMask
<> nil then
6567 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6574 procedure TCorpse
.Update();
6578 if FState
= CORPSE_STATE_REMOVEME
then
6581 if gTime
mod (GAME_TICK
*2) <> 0 then
6583 g_Obj_Move(@FObj
, True, True, True);
6584 positionChanged(); // this updates spatial accelerators
6588 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6589 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6591 st
:= g_Obj_Move(@FObj
, True, True, True);
6592 positionChanged(); // this updates spatial accelerators
6594 if WordBool(st
and MOVE_FALLOUT
) then
6596 FState
:= CORPSE_STATE_REMOVEME
;
6600 if FAnimation
<> nil then
6601 FAnimation
.Update();
6602 if FAnimationMask
<> nil then
6603 FAnimationMask
.Update();
6607 procedure TCorpse
.SaveState (st
: TStream
);
6614 utils
.writeSign(st
, 'CORP');
6615 utils
.writeInt(st
, Byte(0));
6617 utils
.writeInt(st
, Byte(FState
));
6619 utils
.writeInt(st
, Byte(FDamage
));
6621 utils
.writeInt(st
, Byte(FColor
.R
));
6622 utils
.writeInt(st
, Byte(FColor
.G
));
6623 utils
.writeInt(st
, Byte(FColor
.B
));
6625 Obj_SaveState(st
, @FObj
);
6626 utils
.writeInt(st
, Word(FPlayerUID
));
6628 anim
:= (FAnimation
<> nil);
6629 utils
.writeBool(st
, anim
);
6630 // Åñëè åñòü - ñîõðàíÿåì
6631 if anim
then FAnimation
.SaveState(st
);
6632 // Åñòü ëè ìàñêà àíèìàöèè
6633 anim
:= (FAnimationMask
<> nil);
6634 utils
.writeBool(st
, anim
);
6635 // Åñëè åñòü - ñîõðàíÿåì
6636 if anim
then FAnimationMask
.SaveState(st
);
6640 procedure TCorpse
.LoadState (st
: TStream
);
6647 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6648 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6650 FState
:= utils
.readByte(st
);
6652 FDamage
:= utils
.readByte(st
);
6654 FColor
.R
:= utils
.readByte(st
);
6655 FColor
.G
:= utils
.readByte(st
);
6656 FColor
.B
:= utils
.readByte(st
);
6658 Obj_LoadState(@FObj
, st
);
6659 FPlayerUID
:= utils
.readWord(st
);
6661 anim
:= utils
.readBool(st
);
6662 // Åñëè åñòü - çàãðóæàåì
6665 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6666 FAnimation
.LoadState(st
);
6668 // Åñòü ëè ìàñêà àíèìàöèè
6669 anim
:= utils
.readBool(st
);
6670 // Åñëè åñòü - çàãðóæàåì
6673 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6674 FAnimationMask
.LoadState(st
);
6680 constructor TBot
.Create();
6687 FSpectator
:= False;
6694 for a
:= WP_FIRST
to WP_LAST
do
6696 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6697 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6698 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6702 destructor TBot
.Destroy();
6705 inherited Destroy();
6708 procedure TBot
.Draw();
6712 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6713 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6716 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6718 inherited Respawn(Silent
, Force
);
6721 FSelectedWeapon
:= FCurrWeap
;
6726 procedure TBot
.UpdateCombat();
6739 TTargetRecord
= array of TTarget
;
6741 function Compare(a
, b
: TTarget
): Integer;
6743 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6746 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6748 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6749 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6751 if a
.Dist
> b
.Dist
then // B áëèæå
6753 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6756 else // Ñòðàííî -> A
6761 a
, x1
, y1
, x2
, y2
: Integer;
6762 targets
: TTargetRecord
;
6764 Target
, BestTarget
: TTarget
;
6765 firew
, fireh
: Integer;
6769 vsPlayer
, vsMonster
, ok
: Boolean;
6772 function monsUpdate (mon
: TMonster
): Boolean;
6774 result
:= false; // don't stop
6775 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6777 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6779 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6780 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6782 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6783 if g_TraceVector(x1
, y1
, x2
, y2
) then
6785 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6786 SetLength(targets
, Length(targets
)+1);
6787 with targets
[High(targets
)] do
6794 Rect
:= mon
.Obj
.Rect
;
6795 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6796 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6797 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6806 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6807 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6809 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6810 if FCurrWeap
<> FSelectedWeapon
then
6813 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6814 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6816 RemoveAIFlag('NEEDFIRE');
6819 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6820 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6821 else PressKey(KEY_FIRE
);
6825 // Êîîðäèíàòû ñòâîëà:
6826 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6827 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6829 Target
.UID
:= FTargetUID
;
6832 if Target
.UID
<> 0 then
6833 begin // Öåëü åñòü - íàñòðàèâàåì
6834 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6837 tpla
:= g_Player_Get(Target
.UID
);
6841 if (@FObj
) <> nil then
6848 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6849 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6850 Target
.Rect
:= PLAYER_RECT
;
6851 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6852 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6853 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6854 Target
.IsPlayer
:= True;
6858 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6861 mon
:= g_Monsters_ByUID(Target
.UID
);
6864 Target
.X
:= mon
.Obj
.X
;
6865 Target
.Y
:= mon
.Obj
.Y
;
6867 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6868 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6869 Target
.Rect
:= mon
.Obj
.Rect
;
6870 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6871 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6872 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6873 Target
.IsPlayer
:= False;
6880 begin // Öåëè íåò - îáíóëÿåì
6885 Target
.Visible
:= False;
6886 Target
.Line
:= False;
6887 Target
.IsPlayer
:= False;
6892 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6893 if (not Target
.Line
) or (not Target
.Visible
) then
6897 for a
:= 0 to High(gPlayers
) do
6898 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6899 (gPlayers
[a
].FUID
<> FUID
) and
6900 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6901 (not gPlayers
[a
].NoTarget
) and
6902 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6904 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6905 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6908 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6909 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6911 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6912 if g_TraceVector(x1
, y1
, x2
, y2
) then
6914 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6915 SetLength(targets
, Length(targets
)+1);
6916 with targets
[High(targets
)] do
6918 UID
:= gPlayers
[a
].FUID
;
6919 X
:= gPlayers
[a
].FObj
.X
;
6920 Y
:= gPlayers
[a
].FObj
.Y
;
6923 Rect
:= PLAYER_RECT
;
6924 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6925 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6926 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6934 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6937 // Åñëè åñòü âîçìîæíûå öåëè:
6938 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6939 if targets
<> nil then
6941 // Âûáèðàåì íàèëó÷øóþ öåëü:
6942 BestTarget
:= targets
[0];
6943 if Length(targets
) > 1 then
6944 for a
:= 1 to High(targets
) do
6945 if Compare(BestTarget
, targets
[a
]) = 1 then
6946 BestTarget
:= targets
[a
];
6948 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6949 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6950 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6952 Target
:= BestTarget
;
6954 if (Healthy() = 3) or ((Healthy() = 2)) then
6955 begin // Åñëè çäîðîâû - äîãîíÿåì
6956 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6957 SetAIFlag('GORIGHT', '1');
6958 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6959 SetAIFlag('GOLEFT', '1');
6962 begin // Åñëè ïîáèòû - óáåãàåì
6963 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6964 SetAIFlag('GORIGHT', '1');
6965 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6966 SetAIFlag('GOLEFT', '1');
6969 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6970 SelectWeapon(Abs(x1
-Target
.cX
));
6975 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6976 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6977 if Target
.UID
<> 0 then
6979 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6980 Target
.Y
+ Target
.Rect
.Y
) then
6981 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6982 if (Healthy() = 3) or ((Healthy() = 2)) then
6983 begin // Åñëè çäîðîâû - äîãîíÿåì
6984 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6985 SetAIFlag('GORIGHT', '1');
6986 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6987 SetAIFlag('GOLEFT', '1');
6990 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6992 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6993 SetAIFlag('GORIGHT', '1');
6994 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6995 SetAIFlag('GOLEFT', '1');
6999 begin // Öåëü ïîêà íà "ýêðàíå"
7000 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
7001 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7002 FLastVisible
:= gTime
;
7003 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
7004 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
7006 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
7007 SetAIFlag('GORIGHT', '1');
7008 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
7009 SetAIFlag('GOLEFT', '1');
7013 // Âûáèðàåì óãîë ââåðõ:
7014 if FDirection
= TDirection
.D_LEFT
then
7015 angle
:= ANGLE_LEFTUP
7017 angle
:= ANGLE_RIGHTUP
;
7019 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7020 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7022 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7023 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7024 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
7025 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7026 Target
.Rect
.Width
, Target
.Rect
.Height
) and
7027 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7028 begin // òî íóæíî ñòðåëÿòü ââåðõ
7029 SetAIFlag('NEEDFIRE', '1');
7030 SetAIFlag('NEEDSEEUP', '1');
7033 // Âûáèðàåì óãîë âíèç:
7034 if FDirection
= TDirection
.D_LEFT
then
7035 angle
:= ANGLE_LEFTDOWN
7037 angle
:= ANGLE_RIGHTDOWN
;
7039 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7040 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7042 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7043 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7044 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7045 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7046 Target
.Rect
.Width
, Target
.Rect
.Height
) and
7047 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7048 begin // òî íóæíî ñòðåëÿòü âíèç
7049 SetAIFlag('NEEDFIRE', '1');
7050 SetAIFlag('NEEDSEEDOWN', '1');
7053 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
7054 if Target
.Visible
and
7055 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
7056 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
7058 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
7059 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
7060 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
7061 begin // òî íóæíî ñòðåëÿòü âïåðåä
7062 SetAIFlag('NEEDFIRE', '1');
7063 SetAIFlag('NEEDSEEDOWN', '');
7064 SetAIFlag('NEEDSEEUP', '');
7066 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
7067 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
7068 if GetRnd(FDifficult
.CloseJump
) then
7069 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
7070 if Abs(FObj
.X
-Target
.X
) < 128 then
7074 if Random(a
) = 0 then
7075 SetAIFlag('NEEDJUMP', '1');
7079 // Åñëè öåëü âñå åùå åñòü:
7080 if Target
.UID
<> 0 then
7081 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
7082 Target
.UID
:= 0 // òî çàáûòü öåëü
7083 else // Åñëè âèäåëè íåäàâíî
7084 begin // íî öåëü óáèëè
7085 if Target
.IsPlayer
then
7086 begin // Öåëü - èãðîê
7087 pla
:= g_Player_Get(Target
.UID
);
7088 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
7089 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
7090 Target
.UID
:= 0; // òî çàáûòü öåëü
7093 begin // Öåëü - ìîíñòð
7094 mon
:= g_Monsters_ByUID(Target
.UID
);
7095 if (mon
= nil) or (not mon
.alive
) then
7096 Target
.UID
:= 0; // òî çàáûòü öåëü
7099 end; // if Target.UID <> 0
7101 FTargetUID
:= Target
.UID
;
7103 // Åñëè âîçìîæíûõ öåëåé íåò:
7104 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
7105 if targets
= nil then
7106 if GetAIFlag('ATTACKLEFT') <> '' then
7107 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
7108 RemoveAIFlag('ATTACKLEFT');
7110 SetAIFlag('NEEDJUMP', '1');
7112 if RunDirection() = TDirection
.D_RIGHT
then
7113 begin // Èäåì íå â òó ñòîðîíó
7114 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7115 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
7116 SetAIFlag('NEEDFIRE', '1');
7117 SetAIFlag('GOLEFT', '1');
7121 begin // Èäåì â íóæíóþ ñòîðîíó
7122 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7123 SetAIFlag('NEEDFIRE', '1');
7124 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7125 SetAIFlag('GORIGHT', '1');
7129 if GetAIFlag('ATTACKRIGHT') <> '' then
7130 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
7131 RemoveAIFlag('ATTACKRIGHT');
7133 SetAIFlag('NEEDJUMP', '1');
7135 if RunDirection() = TDirection
.D_LEFT
then
7136 begin // Èäåì íå â òó ñòîðîíó
7137 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7138 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
7139 SetAIFlag('NEEDFIRE', '1');
7140 SetAIFlag('GORIGHT', '1');
7145 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7146 SetAIFlag('NEEDFIRE', '1');
7147 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7148 SetAIFlag('GOLEFT', '1');
7152 //HACK! (does it belongs there?)
7153 RealizeCurrentWeapon();
7155 // Åñëè åñòü âîçìîæíûå öåëè:
7156 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7157 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7158 for a
:= 0 to High(targets
) do
7160 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7161 if GetRnd(FDifficult
.DiagFire
) then
7163 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7164 if FDirection
= TDirection
.D_LEFT
then
7165 angle
:= ANGLE_LEFTUP
7167 angle
:= ANGLE_RIGHTUP
;
7169 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7170 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7172 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7173 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7174 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7175 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7176 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7178 SetAIFlag('NEEDFIRE', '1');
7179 SetAIFlag('NEEDSEEUP', '1');
7182 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7183 if FDirection
= TDirection
.D_LEFT
then
7184 angle
:= ANGLE_LEFTDOWN
7186 angle
:= ANGLE_RIGHTDOWN
;
7188 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7189 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7191 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7192 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7193 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7194 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7195 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7197 SetAIFlag('NEEDFIRE', '1');
7198 SetAIFlag('NEEDSEEDOWN', '1');
7202 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7203 if targets
[a
].Line
and targets
[a
].Visible
and
7204 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
7205 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
7207 SetAIFlag('NEEDFIRE', '1');
7212 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7213 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
7214 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
7215 40+GetInterval(FDifficult
.Cover
, 40)) then
7216 SetAIFlag('NEEDJUMP', '1');
7218 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7219 ammo
:= GetAmmoByWeapon(FCurrWeap
);
7220 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
7221 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
7223 SetAIFlag('SELECTWEAPON', '1');
7225 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7226 if GetAIFlag('SELECTWEAPON') = '1' then
7229 RemoveAIFlag('SELECTWEAPON');
7233 procedure TBot
.Update();
7246 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7247 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7249 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7251 if g_debug_BotAIOff
= 3 then
7261 RealizeCurrentWeapon();
7268 procedure TBot
.ReleaseKey(Key
: Byte);
7277 function TBot
.KeyPressed(Key
: Word): Boolean;
7279 Result
:= FKeys
[Key
].Pressed
;
7282 function TBot
.GetAIFlag(aName
: String20
): String20
;
7288 aName
:= LowerCase(aName
);
7290 if FAIFlags
<> nil then
7291 for a
:= 0 to High(FAIFlags
) do
7292 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7294 Result
:= FAIFlags
[a
].Value
;
7299 procedure TBot
.RemoveAIFlag(aName
: String20
);
7303 if FAIFlags
= nil then Exit
;
7305 aName
:= LowerCase(aName
);
7307 for a
:= 0 to High(FAIFlags
) do
7308 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7310 if a
<> High(FAIFlags
) then
7311 for b
:= a
to High(FAIFlags
)-1 do
7312 FAIFlags
[b
] := FAIFlags
[b
+1];
7314 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7319 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7327 aName
:= LowerCase(aName
);
7329 if FAIFlags
<> nil then
7330 for a
:= 0 to High(FAIFlags
) do
7331 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7337 if ok
then FAIFlags
[a
].Value
:= fValue
7340 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7341 with FAIFlags
[High(FAIFlags
)] do
7349 procedure TBot
.UpdateMove
;
7351 procedure GoLeft(Time
: Word = 1);
7353 ReleaseKey(KEY_LEFT
);
7354 ReleaseKey(KEY_RIGHT
);
7355 PressKey(KEY_LEFT
, Time
);
7356 SetDirection(TDirection
.D_LEFT
);
7359 procedure GoRight(Time
: Word = 1);
7361 ReleaseKey(KEY_LEFT
);
7362 ReleaseKey(KEY_RIGHT
);
7363 PressKey(KEY_RIGHT
, Time
);
7364 SetDirection(TDirection
.D_RIGHT
);
7367 function Rnd(a
: Word): Boolean;
7369 Result
:= Random(a
) = 0;
7372 procedure Turn(Time
: Word = 1200);
7374 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7379 ReleaseKey(KEY_LEFT
);
7380 ReleaseKey(KEY_RIGHT
);
7383 function CanRunLeft(): Boolean;
7385 Result
:= not CollideLevel(-1, 0);
7388 function CanRunRight(): Boolean;
7390 Result
:= not CollideLevel(1, 0);
7393 function CanRun(): Boolean;
7395 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7398 procedure Jump(Time
: Word = 30);
7400 PressKey(KEY_JUMP
, Time
);
7403 function NearHole(): Boolean;
7407 { TODO 5 : Ëåñòíèöû }
7408 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7409 for x
:= 1 to PLAYER_RECT
.Width
do
7410 if (not StayOnStep(x
*sx
, 0)) and
7411 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7412 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7421 function BorderHole(): Boolean;
7425 { TODO 5 : Ëåñòíèöû }
7426 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7427 for x
:= 1 to PLAYER_RECT
.Width
do
7428 if (not StayOnStep(x
*sx
, 0)) and
7429 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7430 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7432 for xx
:= x
to x
+32 do
7433 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7443 function NearDeepHole(): Boolean;
7449 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7452 for x
:= 1 to PLAYER_RECT
.Width
do
7453 if (not StayOnStep(x
*sx
, 0)) and
7454 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7455 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7457 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7459 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7464 end else Result
:= False;
7467 function OverDeepHole(): Boolean;
7474 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7476 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7483 function OnGround(): Boolean;
7485 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7488 function OnLadder(): Boolean;
7490 Result
:= FullInStep(0, 0);
7493 function BelowLadder(): Boolean;
7495 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7496 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7497 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7498 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7501 function BelowLiftUp(): Boolean;
7503 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7504 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7505 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7506 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7509 function OnTopLift(): Boolean;
7511 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7514 function CanJumpOver(): Boolean;
7518 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7522 if not CollideLevel(sx
, 0) then Exit
;
7524 for y
:= 1 to BOT_MAXJUMP
do
7525 if CollideLevel(0, -y
) then Exit
else
7526 if not CollideLevel(sx
, -y
) then
7533 function CanJumpUp(Dist
: ShortInt): Boolean;
7540 if CollideLevel(Dist
, 0) then Exit
;
7543 for y
:= 0 to BOT_MAXJUMP
do
7544 if CollideLevel(Dist
, -y
) then
7553 for yy
:= y
+1 to BOT_MAXJUMP
do
7554 if not CollideLevel(Dist
, -yy
) then
7563 for y
:= 0 to BOT_MAXJUMP
do
7564 if CollideLevel(0, -y
) then
7572 if y
< yy
then Exit
;
7577 function IsSafeTrigger(): Boolean;
7582 if gTriggers
= nil then
7584 for a
:= 0 to High(gTriggers
) do
7585 if Collide(gTriggers
[a
].X
,
7588 gTriggers
[a
].Height
) and
7589 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7590 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7591 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7592 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7593 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7598 // Âîçìîæíî, íàæèìàåì êíîïêó:
7599 if Rnd(16) and IsSafeTrigger() then
7602 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7603 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7605 ReleaseKey(KEY_LEFT
);
7606 ReleaseKey(KEY_RIGHT
);
7610 // Èäåì âëåâî, åñëè íàäî áûëî:
7611 if GetAIFlag('GOLEFT') <> '' then
7613 RemoveAIFlag('GOLEFT');
7614 if CanRunLeft() then
7618 // Èäåì âïðàâî, åñëè íàäî áûëî:
7619 if GetAIFlag('GORIGHT') <> '' then
7621 RemoveAIFlag('GORIGHT');
7622 if CanRunRight() then
7626 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7627 if FObj
.X
< -32 then
7630 if FObj
.X
+32 > gMapInfo
.Width
then
7633 // Ïðûãàåì, åñëè íàäî áûëî:
7634 if GetAIFlag('NEEDJUMP') <> '' then
7637 RemoveAIFlag('NEEDJUMP');
7640 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7641 if GetAIFlag('NEEDSEEUP') <> '' then
7644 ReleaseKey(KEY_DOWN
);
7645 PressKey(KEY_UP
, 20);
7646 RemoveAIFlag('NEEDSEEUP');
7649 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7650 if GetAIFlag('NEEDSEEDOWN') <> '' then
7653 ReleaseKey(KEY_DOWN
);
7654 PressKey(KEY_DOWN
, 20);
7655 RemoveAIFlag('NEEDSEEDOWN');
7658 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7659 if GetAIFlag('GOINHOLE') <> '' then
7660 if not OnGround() then
7662 ReleaseKey(KEY_LEFT
);
7663 ReleaseKey(KEY_RIGHT
);
7664 RemoveAIFlag('GOINHOLE');
7665 SetAIFlag('FALLINHOLE', '1');
7668 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7669 if GetAIFlag('FALLINHOLE') <> '' then
7671 RemoveAIFlag('FALLINHOLE');
7673 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7674 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7675 if GetAIFlag('FALLINHOLE') = '' then
7676 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7682 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7684 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7688 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7689 if OnGround() and NearHole() then
7690 if NearDeepHole() then // Åñëè ýòî áåçäíà
7692 0..3: Turn(); // Áåæèì îáðàòíî
7693 4: Jump(); // Ïðûãàåì
7694 5: begin // Ïðûãàåì îáðàòíî
7699 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7700 if GetAIFlag('GOINHOLE') = '' then
7702 0: Turn(); // Íå íóæíî òóäà
7703 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7704 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7705 if BorderHole() then
7706 SetAIFlag('GOINHOLE', '1');
7709 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7710 if (not CanRun()) and OnGround() then
7712 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7713 if CanJumpOver() or OnLadder() then
7715 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7716 if Random(2) = 0 then
7718 if IsSafeTrigger() then
7724 // Îñòàëîñü ìàëî âîçäóõà:
7725 if FAir
< 36 * 2 then
7728 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7729 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7730 if BodyInAcid(0, 0) then
7734 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7736 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7737 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7740 {function TBot.NeedItem(Item: Byte): Byte;
7745 procedure TBot
.SelectWeapon(Dist
: Integer);
7749 function HaveAmmo(weapon
: Byte): Boolean;
7752 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7753 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7754 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7755 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7756 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7757 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7758 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7759 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7760 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7761 else Result
:= True;
7766 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7768 if Dist
> BOT_LONGDIST
then
7769 begin // Äàëüíèé áîé
7771 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7773 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7777 else //if Dist > BOT_UNSAFEDIST then
7778 begin // Áëèæíèé áîé
7780 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7782 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7789 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7791 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7797 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7799 Result
:= inherited PickItem(ItemType
, force
, remove
);
7801 if Result
then SetAIFlag('SELECTWEAPON', '1');
7804 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7806 Result
:= inherited Heal(value
, Soft
);
7809 function TBot
.Healthy(): Byte;
7811 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7812 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7813 else if (FHealth
> 50) then Result
:= 2
7814 else if (FHealth
> 20) then Result
:= 1
7818 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7820 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7821 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7824 procedure TBot
.OnDamage(Angle
: SmallInt);
7832 if (Angle
= 0) or (Angle
= 180) then
7835 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7836 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7838 pla
:= g_Player_Get(FLastSpawnerUID
);
7839 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7840 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7843 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7844 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7846 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7847 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7848 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7853 SetAIFlag('ATTACKLEFT', '1')
7855 SetAIFlag('ATTACKRIGHT', '1');
7859 function TBot
.RunDirection(): TDirection
;
7861 if Abs(Vel
.X
) >= 1 then
7863 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7865 Result
:= FDirection
;
7868 function TBot
.GetRnd(a
: Byte): Boolean;
7870 if a
= 0 then Result
:= False
7871 else if a
= 255 then Result
:= True
7872 else Result
:= Random(256) > 255-a
;
7875 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7877 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7881 procedure TDifficult
.save (st
: TStream
);
7883 utils
.writeInt(st
, Byte(DiagFire
));
7884 utils
.writeInt(st
, Byte(InvisFire
));
7885 utils
.writeInt(st
, Byte(DiagPrecision
));
7886 utils
.writeInt(st
, Byte(FlyPrecision
));
7887 utils
.writeInt(st
, Byte(Cover
));
7888 utils
.writeInt(st
, Byte(CloseJump
));
7889 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7890 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7893 procedure TDifficult
.load (st
: TStream
);
7895 DiagFire
:= utils
.readByte(st
);
7896 InvisFire
:= utils
.readByte(st
);
7897 DiagPrecision
:= utils
.readByte(st
);
7898 FlyPrecision
:= utils
.readByte(st
);
7899 Cover
:= utils
.readByte(st
);
7900 CloseJump
:= utils
.readByte(st
);
7901 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7902 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7906 procedure TBot
.SaveState (st
: TStream
);
7911 inherited SaveState(st
);
7912 utils
.writeSign(st
, 'BOT0');
7914 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7916 utils
.writeInt(st
, Word(FTargetUID
));
7917 // Âðåìÿ ïîòåðè öåëè
7918 utils
.writeInt(st
, LongWord(FLastVisible
));
7919 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7920 dw
:= Length(FAIFlags
);
7921 utils
.writeInt(st
, LongInt(dw
));
7923 for i
:= 0 to dw
-1 do
7925 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7926 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7928 // Íàñòðîéêè ñëîæíîñòè
7929 FDifficult
.save(st
);
7933 procedure TBot
.LoadState (st
: TStream
);
7938 inherited LoadState(st
);
7939 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7941 FSelectedWeapon
:= utils
.readByte(st
);
7943 FTargetUID
:= utils
.readWord(st
);
7944 // Âðåìÿ ïîòåðè öåëè
7945 FLastVisible
:= utils
.readLongWord(st
);
7946 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7947 dw
:= utils
.readLongInt(st
);
7948 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7949 SetLength(FAIFlags
, dw
);
7951 for i
:= 0 to dw
-1 do
7953 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7954 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7956 // Íàñòðîéêè ñëîæíîñòè
7957 FDifficult
.load(st
);
7962 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);
7963 conRegVar('player_indicator', @gPlayerIndicator
, 'Draw indicator only for current player, also for teammates, or not at all', 'Draw indicator only for current player, also for teammates, or not at all');
7964 conRegVar('player_indicator_style', @gPlayerIndicatorStyle
, 'Visual appearance of indicator', 'Visual appearance of indicator');