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;
272 // debug: viewport offset
273 viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer;
275 function isValidViewPort (): Boolean; inline;
277 constructor Create(); virtual;
278 destructor Destroy(); override;
279 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
280 function GetRespawnPoint(): Byte;
281 procedure PressKey(Key
: Byte; Time
: Word = 1);
282 procedure ReleaseKeys();
283 procedure SetModel(ModelName
: String);
284 procedure SetColor(Color
: TRGB
);
285 procedure SetWeapon(W
: Byte);
286 function IsKeyPressed(K
: Byte): Boolean;
287 function GetKeys(): Byte;
288 function PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean; virtual;
289 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
290 function Collide(Panel
: TPanel
): Boolean; overload
;
291 function Collide(X
, Y
: Integer): Boolean; overload
;
292 procedure SetDirection(Direction
: TDirection
);
293 procedure GetSecret();
294 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
296 procedure Push(vx
, vy
: Integer);
297 procedure ChangeModel(ModelName
: String);
298 procedure SwitchTeam
;
299 procedure ChangeTeam(Team
: Byte);
301 function GetFlag(Flag
: Byte): Boolean;
302 procedure SetFlag(Flag
: Byte);
303 function DropFlag(Silent
: Boolean = True): Boolean;
304 procedure AllRulez(Health
: Boolean);
305 procedure RestoreHealthArmor();
306 procedure FragCombo();
307 procedure GiveItem(ItemType
: Byte);
308 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
309 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
310 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
311 procedure MakeBloodSimple(Count
: Word);
312 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
313 procedure Reset(Force
: Boolean);
314 procedure Spectate(NoMove
: Boolean = False);
315 procedure SwitchNoClip
;
316 procedure SoftReset();
317 procedure Draw(); virtual;
318 procedure DrawPain();
319 procedure DrawPickup();
320 procedure DrawRulez();
322 procedure DrawIndicator();
323 procedure DrawBubble();
325 procedure Update(); virtual;
326 procedure RememberState();
327 procedure RecallState();
328 procedure SaveState (st
: TStream
); virtual;
329 procedure LoadState (st
: TStream
); virtual;
330 procedure PauseSounds(Enable
: Boolean);
331 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
332 procedure DoLerp(Level
: Integer = 2);
333 procedure SetLerp(XTo
, YTo
: Integer);
334 procedure QueueWeaponSwitch(Weapon
: Byte);
335 procedure RealizeCurrentWeapon();
339 procedure JetpackOff
;
340 procedure CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
342 //WARNING! this does nothing for now, but still call it!
343 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
345 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
346 procedure moveBy (dx
, dy
: Integer); inline;
349 property Vel
: TPoint2i read FObj
.Vel
;
350 property Obj
: TObj read FObj
;
352 property Name
: String read FName write FName
;
353 property Model
: TPlayerModel read FModel
;
354 property Health
: Integer read FHealth write FHealth
;
355 property Lives
: Byte read FLives write FLives
;
356 property Armor
: Integer read FArmor write FArmor
;
357 property Air
: Integer read FAir write FAir
;
358 property JetFuel
: Integer read FJetFuel write FJetFuel
;
359 property Frags
: Integer read FFrags write FFrags
;
360 property Death
: Integer read FDeath write FDeath
;
361 property Kills
: Integer read FKills write FKills
;
362 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
363 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
364 property Secrets
: Integer read FSecrets
;
365 property GodMode
: Boolean read FGodMode write FGodMode
;
366 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
367 property NoReload
: Boolean read FNoReload write FNoReload
;
368 property alive
: Boolean read FAlive write FAlive
;
369 property Flag
: Byte read FFlag
;
370 property Team
: Byte read FTeam write FTeam
;
371 property Direction
: TDirection read FDirection
;
372 property GameX
: Integer read FObj
.X write FObj
.X
;
373 property GameY
: Integer read FObj
.Y write FObj
.Y
;
374 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
375 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
376 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
377 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
378 property IncCam
: Integer read FIncCam write FIncCam
;
379 property UID
: Word read FUID write FUID
;
380 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
381 property NetTime
: LongWord read FNetTime write FNetTime
;
384 property eName
: String read FName write FName
;
385 property eHealth
: Integer read FHealth write FHealth
;
386 property eLives
: Byte read FLives write FLives
;
387 property eArmor
: Integer read FArmor write FArmor
;
388 property eAir
: Integer read FAir write FAir
;
389 property eJetFuel
: Integer read FJetFuel write FJetFuel
;
390 property eFrags
: Integer read FFrags write FFrags
;
391 property eDeath
: Integer read FDeath write FDeath
;
392 property eKills
: Integer read FKills write FKills
;
393 property eCurrWeap
: Byte read FCurrWeap write FCurrWeap
;
394 property eMonsterKills
: Integer read FMonsterKills write FMonsterKills
;
395 property eSecrets
: Integer read FSecrets write FSecrets
;
396 property eGodMode
: Boolean read FGodMode write FGodMode
;
397 property eNoTarget
: Boolean read FNoTarget write FNoTarget
;
398 property eNoReload
: Boolean read FNoReload write FNoReload
;
399 property eAlive
: Boolean read FAlive write FAlive
;
400 property eFlag
: Byte read FFlag
;
401 property eTeam
: Byte read FTeam write FTeam
;
402 property eDirection
: TDirection read FDirection
;
403 property eGameX
: Integer read FObj
.X write FObj
.X
;
404 property eGameY
: Integer read FObj
.Y write FObj
.Y
;
405 property eGameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
406 property eGameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
407 property eGameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
408 property eGameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
409 property eIncCam
: Integer read FIncCam write FIncCam
;
410 property eUID
: Word read FUID
;
411 property eJustTeleported
: Boolean read FJustTeleported
;
412 property eNetTime
: LongWord read FNetTime
;
414 // set this before assigning something to `eDamage`
415 property eDamageType
: Integer read mEDamageType write mEDamageType
;
416 property eDamage
: Integer write doDamage
;
427 WeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
428 CloseWeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
429 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
432 procedure save (st
: TStream
);
433 procedure load (st
: TStream
);
441 TBot
= class(TPlayer
)
443 FSelectedWeapon
: Byte;
446 FAIFlags
: Array of TAIFlag
;
447 FDifficult
: TDifficult
;
449 function GetRnd(a
: Byte): Boolean;
450 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
451 function RunDirection(): TDirection
;
452 function FullInStep(XInc
, YInc
: Integer): Boolean;
453 //function NeedItem(Item: Byte): Byte;
454 procedure SelectWeapon(Dist
: Integer);
455 procedure SetAIFlag(aName
, fValue
: String20
);
456 function GetAIFlag(aName
: String20
): String20
;
457 procedure RemoveAIFlag(aName
: String20
);
458 function Healthy(): Byte;
459 procedure UpdateMove();
460 procedure UpdateCombat();
461 function KeyPressed(Key
: Word): Boolean;
462 procedure ReleaseKey(Key
: Byte);
463 function TargetOnScreen(TX
, TY
: Integer): Boolean;
464 procedure OnDamage(Angle
: SmallInt); override;
467 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
468 constructor Create(); override;
469 destructor Destroy(); override;
470 procedure Draw(); override;
471 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
472 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
473 procedure Update(); override;
474 procedure SaveState (st
: TStream
); override;
475 procedure LoadState (st
: TStream
); override;
487 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
488 procedure moveBy (dx
, dy
: Integer); inline;
490 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
504 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
505 procedure moveBy (dx
, dy
: Integer); inline;
507 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
510 TCorpse
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
519 FAnimation
: TAnimation
;
520 FAnimationMask
: TAnimation
;
523 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
524 destructor Destroy(); override;
525 procedure Damage(Value
: Word; vx
, vy
: Integer);
528 procedure SaveState (st
: TStream
);
529 procedure LoadState (st
: TStream
);
531 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
532 procedure moveBy (dx
, dy
: Integer); inline;
534 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
536 function ObjPtr (): PObj
; inline;
538 property Obj
: TObj read FObj
; // copies object
539 property State
: Byte read FState
;
540 property Mess
: Boolean read FMess
;
543 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
549 gPlayers
: Array of TPlayer
;
550 gCorpses
: Array of TCorpse
;
551 gGibs
: Array of TGib
;
552 gShells
: Array of TShell
;
553 gTeamStat
: TTeamStat
;
554 gFly
: Boolean = False;
555 gAimLine
: Boolean = False;
556 gChatBubble
: Byte = 0;
557 gPlayerIndicator
: Boolean = True;
561 MAX_RUNVEL
: Integer = 8;
562 VEL_JUMP
: Integer = 10;
563 SHELL_TIMEOUT
: Cardinal = 60000;
565 function Lerp(X
, Y
, Factor
: Integer): Integer;
567 procedure g_Gibs_SetMax(Count
: Word);
568 function g_Gibs_GetMax(): Word;
569 procedure g_Corpses_SetMax(Count
: Word);
570 function g_Corpses_GetMax(): Word;
571 procedure g_Shells_SetMax(Count
: Word);
572 function g_Shells_GetMax(): Word;
574 procedure g_Player_Init();
575 procedure g_Player_Free();
576 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
577 function g_Player_CreateFromState (st
: TStream
): Word;
578 procedure g_Player_Remove(UID
: Word);
579 procedure g_Player_ResetTeams();
580 procedure g_Player_UpdateAll();
581 procedure g_Player_DrawAll();
582 procedure g_Player_DrawDebug(p
: TPlayer
);
583 procedure g_Player_DrawHealth();
584 procedure g_Player_RememberAll();
585 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
586 function g_Player_Get(UID
: Word): TPlayer
;
587 function g_Player_GetCount(): Byte;
588 function g_Player_GetStats(): TPlayerStatArray
;
589 function g_Player_ValidName(Name
: String): Boolean;
590 procedure g_Player_CreateCorpse(Player
: TPlayer
);
591 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
592 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
593 procedure g_Player_UpdatePhysicalObjects();
594 procedure g_Player_DrawCorpses();
595 procedure g_Player_DrawShells();
596 procedure g_Player_RemoveAllCorpses();
597 procedure g_Player_Corpses_SaveState (st
: TStream
);
598 procedure g_Player_Corpses_LoadState (st
: TStream
);
599 procedure g_Player_ResetReady();
600 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
601 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
602 procedure g_Bot_MixNames();
603 procedure g_Bot_RemoveAll();
608 {$INCLUDE ../nogl/noGLuses.inc}
609 {$IFDEF ENABLE_HOLMES}
612 e_log
, g_map
, g_items
, g_console
, g_gfx
, Math
,
613 g_options
, g_triggers
, g_menu
, g_game
, g_grid
,
614 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
,
615 g_net
, g_netmsg
, g_window
,
618 const PLR_SAVE_VERSION
= 0;
628 diag_precision
: Byte;
632 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
633 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
634 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
638 TIME_RESPAWN1
= 1500;
639 TIME_RESPAWN2
= 2000;
640 TIME_RESPAWN3
= 3000;
643 JET_MAX
= 540; // ~30 sec
644 PLAYER_SUIT_TIME
= 30000;
645 PLAYER_INVUL_TIME
= 30000;
646 PLAYER_INVIS_TIME
= 35000;
647 FRAG_COMBO_TIME
= 3000;
651 ANGLE_RIGHTDOWN
= -35;
653 ANGLE_LEFTDOWN
= -145;
654 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
655 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
658 BOT_UNSAFEDIST
= 128;
659 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
661 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
662 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
663 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
664 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
665 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
666 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
667 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
668 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
669 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
670 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
671 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
672 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
673 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
674 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
675 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
676 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
677 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
678 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
679 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
680 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
681 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
682 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
683 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
684 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
685 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
686 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
688 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
689 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
691 BOTNAMES_FILENAME
= 'botnames.txt';
692 BOTLIST_FILENAME
= 'botlist.txt';
696 MaxCorpses
: Word = 20;
697 MaxShells
: Word = 300;
698 CurrentGib
: Integer = 0;
699 CurrentShell
: Integer = 0;
700 BotNames
: Array of String;
701 BotList
: Array of TBotProfile
;
704 function Lerp(X
, Y
, Factor
: Integer): Integer;
706 Result
:= X
+ ((Y
- X
) div Factor
);
709 function SameTeam(UID1
, UID2
: Word): Boolean;
713 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
714 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
716 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
718 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
719 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
721 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
724 procedure g_Gibs_SetMax(Count
: Word);
727 SetLength(gGibs
, Count
);
729 if CurrentGib
>= Count
then
733 function g_Gibs_GetMax(): Word;
738 procedure g_Shells_SetMax(Count
: Word);
741 SetLength(gShells
, Count
);
743 if CurrentShell
>= Count
then
747 function g_Shells_GetMax(): Word;
753 procedure g_Corpses_SetMax(Count
: Word);
756 SetLength(gCorpses
, Count
);
759 function g_Corpses_GetMax(): Word;
761 Result
:= MaxCorpses
;
764 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
774 // Åñòü ëè ìåñòî â gPlayers:
775 if gPlayers
<> nil then
776 for a
:= 0 to High(gPlayers
) do
777 if gPlayers
[a
] = nil then
783 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
786 SetLength(gPlayers
, Length(gPlayers
)+1);
790 // Ñîçäàåì îáúåêò èãðîêà:
792 gPlayers
[a
] := TBot
.Create()
794 gPlayers
[a
] := TPlayer
.Create();
797 gPlayers
[a
].FActualModelName
:= ModelName
;
798 gPlayers
[a
].SetModel(ModelName
);
800 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
801 if gPlayers
[a
].FModel
= nil then
805 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
809 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
810 if Random(2) = 0 then
814 gPlayers
[a
].FPreferredTeam
:= Team
;
816 case gGameSettings
.GameMode
of
817 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
819 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
821 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
824 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
825 gPlayers
[a
].FColor
:= Color
;
826 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
827 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
829 gPlayers
[a
].FModel
.Color
:= Color
;
831 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
832 gPlayers
[a
].FAlive
:= False;
834 Result
:= gPlayers
[a
].FUID
;
837 function g_Player_CreateFromState (st
: TStream
): Word;
844 if (st
= nil) then exit
; //???
847 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
848 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
851 Bot
:= utils
.readBool(st
);
856 // Åñòü ëè ìåñòî â gPlayers:
857 for a
:= 0 to High(gPlayers
) do if (gPlayers
[a
] = nil) then begin ok
:= true; break
; end;
859 // Íåò ìåñòà - ðàñøèðÿåì gPlayers
862 SetLength(gPlayers
, Length(gPlayers
)+1);
866 // Ñîçäàåì îáúåêò èãðîêà
868 gPlayers
[a
] := TBot
.Create()
870 gPlayers
[a
] := TPlayer
.Create();
871 gPlayers
[a
].FIamBot
:= Bot
;
872 gPlayers
[a
].FPhysics
:= True;
875 gPlayers
[a
].FUID
:= utils
.readWord(st
);
877 gPlayers
[a
].FName
:= utils
.readStr(st
);
879 gPlayers
[a
].FTeam
:= utils
.readByte(st
);
880 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
882 gPlayers
[a
].FAlive
:= utils
.readBool(st
);
883 // Èçðàñõîäîâàë ëè âñå æèçíè
884 gPlayers
[a
].FNoRespawn
:= utils
.readBool(st
);
886 b
:= utils
.readByte(st
);
887 if b
= 1 then gPlayers
[a
].FDirection
:= TDirection
.D_LEFT
else gPlayers
[a
].FDirection
:= TDirection
.D_RIGHT
; // b = 2
889 gPlayers
[a
].FHealth
:= utils
.readLongInt(st
);
891 gPlayers
[a
].FHandicap
:= utils
.readLongInt(st
);
893 gPlayers
[a
].FLives
:= utils
.readByte(st
);
895 gPlayers
[a
].FArmor
:= utils
.readLongInt(st
);
897 gPlayers
[a
].FAir
:= utils
.readLongInt(st
);
899 gPlayers
[a
].FJetFuel
:= utils
.readLongInt(st
);
901 gPlayers
[a
].FPain
:= utils
.readLongInt(st
);
903 gPlayers
[a
].FKills
:= utils
.readLongInt(st
);
905 gPlayers
[a
].FMonsterKills
:= utils
.readLongInt(st
);
907 gPlayers
[a
].FFrags
:= utils
.readLongInt(st
);
909 gPlayers
[a
].FFragCombo
:= utils
.readByte(st
);
910 // Âðåìÿ ïîñëåäíåãî ôðàãà
911 gPlayers
[a
].FLastFrag
:= utils
.readLongWord(st
);
913 gPlayers
[a
].FDeath
:= utils
.readLongInt(st
);
915 gPlayers
[a
].FFlag
:= utils
.readByte(st
);
917 gPlayers
[a
].FSecrets
:= utils
.readLongInt(st
);
919 gPlayers
[a
].FCurrWeap
:= utils
.readByte(st
);
920 // Ñëåäóþùåå æåëàåìîå îðóæèå
921 gPlayers
[a
].FNextWeap
:= utils
.readWord(st
);
923 gPlayers
[a
].FNextWeapDelay
:= utils
.readByte(st
);
925 gPlayers
[a
].FBFGFireCounter
:= utils
.readSmallInt(st
);
927 gPlayers
[a
].FDamageBuffer
:= utils
.readLongInt(st
);
928 // Ïîñëåäíèé óäàðèâøèé
929 gPlayers
[a
].FLastSpawnerUID
:= utils
.readWord(st
);
930 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
931 gPlayers
[a
].FLastHit
:= utils
.readByte(st
);
933 Obj_LoadState(@gPlayers
[a
].FObj
, st
);
934 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
935 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FAmmo
[i
] := utils
.readWord(st
);
936 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
937 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FMaxAmmo
[i
] := utils
.readWord(st
);
939 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FWeapon
[i
] := utils
.readBool(st
);
940 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
941 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FReloading
[i
] := utils
.readWord(st
);
943 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
944 // Íàëè÷èå êðàñíîãî êëþ÷à
945 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
946 // Íàëè÷èå çåëåíîãî êëþ÷à
947 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
948 // Íàëè÷èå ñèíåãî êëþ÷à
949 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
951 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_BERSERK
);
952 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
953 for i
:= MR_SUIT
to MR_MAX
do gPlayers
[a
].FMegaRulez
[i
] := utils
.readLongWord(st
);
954 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
955 for i
:= T_RESPAWN
to T_FLAGCAP
do gPlayers
[a
].FTime
[i
] := utils
.readLongWord(st
);
958 gPlayers
[a
].FActualModelName
:= utils
.readStr(st
);
960 gPlayers
[a
].FColor
.R
:= utils
.readByte(st
);
961 gPlayers
[a
].FColor
.G
:= utils
.readByte(st
);
962 gPlayers
[a
].FColor
.B
:= utils
.readByte(st
);
963 // Îáíîâëÿåì ìîäåëü èãðîêà
964 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
966 // Íåò ìîäåëè - ñîçäàíèå íåâîçìîæíî
967 if (gPlayers
[a
].FModel
= nil) then
971 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
975 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû
976 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
977 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
979 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
981 result
:= gPlayers
[a
].FUID
;
985 procedure g_Player_ResetTeams();
989 if g_Game_IsClient
then
991 if gPlayers
= nil then
993 for a
:= Low(gPlayers
) to High(gPlayers
) do
994 if gPlayers
[a
] <> nil then
995 case gGameSettings
.GameMode
of
997 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
999 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
1000 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
1001 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
1004 gPlayers
[a
].ChangeTeam(TEAM_RED
)
1006 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
1009 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
1013 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
1016 _name
, _model
: String;
1019 if not g_Game_IsServer
then Exit
;
1021 // Ñïèñîê íàçâàíèé ìîäåëåé:
1022 m
:= g_PlayerModel_GetNames();
1027 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1028 Team
:= TEAM_COOP
// COOP
1030 if gGameSettings
.GameMode
= GM_DM
then
1031 Team
:= TEAM_NONE
// DM
1033 if Team
= TEAM_NONE
then // CTF / TDM
1035 // Àâòîáàëàíñ êîìàíä:
1039 for a
:= 0 to High(gPlayers
) do
1040 if gPlayers
[a
] <> nil then
1042 if gPlayers
[a
].Team
= TEAM_RED
then
1045 if gPlayers
[a
].Team
= TEAM_BLUE
then
1055 if Random(2) = 0 then
1061 // Âûáèðàåì áîòó èìÿ:
1063 if BotNames
<> nil then
1064 for a
:= 0 to High(BotNames
) do
1065 if g_Player_ValidName(BotNames
[a
]) then
1067 _name
:= BotNames
[a
];
1071 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
1074 _name
:= Format('DFBOT%.2d', [Random(100)]);
1075 until g_Player_ValidName(_name
);
1077 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1078 _model
:= m
[Random(Length(m
))];
1081 with g_Player_Get(g_Player_Create(_model
,
1082 _RGB(Min(Random(9)*32, 255),
1083 Min(Random(9)*32, 255),
1084 Min(Random(9)*32, 255)),
1085 Team
, True)) as TBot
do
1090 1: FDifficult
:= DIFFICULT_EASY
;
1091 2: FDifficult
:= DIFFICULT_MEDIUM
;
1092 else FDifficult
:= DIFFICULT_HARD
;
1095 for a
:= WP_FIRST
to WP_LAST
do
1097 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1098 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1099 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1102 FHandicap
:= Handicap
;
1104 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1106 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1107 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1112 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
1115 _name
, _model
: String;
1118 if not g_Game_IsServer
then Exit
;
1120 // Ñïèñîê íàçâàíèé ìîäåëåé:
1121 m
:= g_PlayerModel_GetNames();
1126 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1127 Team
:= TEAM_COOP
// COOP
1129 if gGameSettings
.GameMode
= GM_DM
then
1130 Team
:= TEAM_NONE
// DM
1132 if Team
= TEAM_NONE
then
1133 Team
:= BotList
[num
].team
; // CTF / TDM
1135 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1136 lName
:= AnsiLowerCase(lName
);
1137 if (num
< 0) or (num
> Length(BotList
)-1) then
1139 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1140 for a
:= 0 to High(BotList
) do
1141 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1150 _name
:= BotList
[num
].name
;
1151 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1152 if not g_Player_ValidName(_name
) then
1154 _name
:= Format('DFBOT%.2d', [Random(100)]);
1155 until g_Player_ValidName(_name
);
1158 _model
:= BotList
[num
].model
;
1159 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1160 if not InSArray(_model
, m
) then
1161 _model
:= m
[Random(Length(m
))];
1164 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1168 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1169 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1170 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1171 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1172 FDifficult
.Cover
:= BotList
[num
].cover
;
1173 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1175 FHandicap
:= Handicap
;
1177 for a
:= WP_FIRST
to WP_LAST
do
1179 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1180 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1181 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1184 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1186 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1190 procedure g_Bot_RemoveAll();
1194 if not g_Game_IsServer
then Exit
;
1195 if gPlayers
= nil then Exit
;
1197 for a
:= 0 to High(gPlayers
) do
1198 if gPlayers
[a
] <> nil then
1199 if gPlayers
[a
] is TBot
then
1201 gPlayers
[a
].Lives
:= 0;
1202 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1203 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1204 g_Player_Remove(gPlayers
[a
].FUID
);
1210 procedure g_Bot_MixNames();
1215 if BotNames
<> nil then
1216 for a
:= 0 to High(BotNames
) do
1218 b
:= Random(Length(BotNames
));
1220 Botnames
[a
] := BotNames
[b
];
1225 procedure g_Player_Remove(UID
: Word);
1229 if gPlayers
= nil then Exit
;
1231 if g_Game_IsServer
and g_Game_IsNet
then
1232 MH_SEND_PlayerDelete(UID
);
1234 for i
:= 0 to High(gPlayers
) do
1235 if gPlayers
[i
] <> nil then
1236 if gPlayers
[i
].FUID
= UID
then
1238 if gPlayers
[i
] is TPlayer
then
1239 TPlayer(gPlayers
[i
]).Free()
1241 TBot(gPlayers
[i
]).Free();
1247 procedure g_Player_Init();
1257 if not FileExists(DataDir
+ BOTNAMES_FILENAME
) then
1260 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1261 AssignFile(F
, DataDir
+ BOTNAMES_FILENAME
);
1272 SetLength(BotNames
, Length(BotNames
)+1);
1273 BotNames
[High(BotNames
)] := s
;
1281 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1282 config
:= TConfig
.CreateFile(DataDir
+ BOTLIST_FILENAME
);
1286 while config
.SectionExists(IntToStr(a
)) do
1288 SetLength(BotList
, Length(BotList
)+1);
1290 with BotList
[High(BotList
)] do
1293 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1295 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1297 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1302 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1303 color
.R
:= StrToIntDef(sa
[0], 0);
1304 color
.G
:= StrToIntDef(sa
[1], 0);
1305 color
.B
:= StrToIntDef(sa
[2], 0);
1306 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1307 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1308 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1309 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1310 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1311 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1312 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1313 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1314 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1315 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1316 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1317 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1318 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1319 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1320 if Length(sa
) = 10 then
1322 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1323 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1324 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1325 if Length(sa
) = 10 then
1327 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1329 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1330 if Length(sa) = 10 then
1332 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1341 procedure g_Player_Free();
1345 if gPlayers
<> nil then
1347 for i
:= 0 to High(gPlayers
) do
1348 if gPlayers
[i
] <> nil then
1350 if gPlayers
[i
] is TPlayer
then
1351 TPlayer(gPlayers
[i
]).Free()
1353 TBot(gPlayers
[i
]).Free();
1364 procedure g_Player_UpdateAll();
1368 if gPlayers
= nil then Exit
;
1370 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1371 for i
:= 0 to High(gPlayers
) do
1373 if gPlayers
[i
] <> nil then
1375 if gPlayers
[i
] is TPlayer
then
1377 gPlayers
[i
].Update();
1378 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1382 // bot updates weapons in `UpdateCombat()`
1383 TBot(gPlayers
[i
]).Update();
1387 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1390 procedure g_Player_DrawAll();
1394 if gPlayers
= nil then Exit
;
1396 for i
:= 0 to High(gPlayers
) do
1397 if gPlayers
[i
] <> nil then
1398 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1399 else TBot(gPlayers
[i
]).Draw();
1402 procedure g_Player_DrawDebug(p
: TPlayer
);
1406 if p
= nil then Exit
;
1407 if (@p
.FObj
) = nil then Exit
;
1409 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1411 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1412 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1413 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1414 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1415 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1416 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1419 procedure g_Player_DrawHealth();
1424 if gPlayers
= nil then Exit
;
1425 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1427 for i
:= 0 to High(gPlayers
) do
1428 if gPlayers
[i
] <> nil then
1430 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1431 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1432 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1433 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1434 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1435 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1439 function g_Player_Get(UID
: Word): TPlayer
;
1445 if gPlayers
= nil then
1448 for a
:= 0 to High(gPlayers
) do
1449 if gPlayers
[a
] <> nil then
1450 if gPlayers
[a
].FUID
= UID
then
1452 Result
:= gPlayers
[a
];
1457 function g_Player_GetCount(): Byte;
1463 if gPlayers
= nil then
1466 for a
:= 0 to High(gPlayers
) do
1467 if gPlayers
[a
] <> nil then
1468 Result
:= Result
+ 1;
1471 function g_Player_GetStats(): TPlayerStatArray
;
1477 if gPlayers
= nil then Exit
;
1479 for a
:= 0 to High(gPlayers
) do
1480 if gPlayers
[a
] <> nil then
1482 SetLength(Result
, Length(Result
)+1);
1483 with Result
[High(Result
)] do
1486 Ping
:= gPlayers
[a
].FPing
;
1487 Loss
:= gPlayers
[a
].FLoss
;
1488 Name
:= gPlayers
[a
].FName
;
1489 Team
:= gPlayers
[a
].FTeam
;
1490 Frags
:= gPlayers
[a
].FFrags
;
1491 Deaths
:= gPlayers
[a
].FDeath
;
1492 Kills
:= gPlayers
[a
].FKills
;
1493 Color
:= gPlayers
[a
].FModel
.Color
;
1494 Lives
:= gPlayers
[a
].FLives
;
1495 Spectator
:= gPlayers
[a
].FSpectator
;
1500 procedure g_Player_ResetReady();
1504 if not g_Game_IsServer
then Exit
;
1505 if gPlayers
= nil then Exit
;
1507 for a
:= 0 to High(gPlayers
) do
1508 if gPlayers
[a
] <> nil then
1510 gPlayers
[a
].FReady
:= False;
1511 if g_Game_IsNet
then
1512 MH_SEND_GameEvent(NET_EV_INTER_READY
, gPlayers
[a
].UID
, 'N');
1516 procedure g_Player_RememberAll
;
1520 for i
:= Low(gPlayers
) to High(gPlayers
) do
1521 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1522 gPlayers
[i
].RememberState
;
1525 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1529 gTeamStat
[TEAM_RED
].Goals
:= 0;
1530 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1532 if gPlayers
<> nil then
1533 for i
:= 0 to High(gPlayers
) do
1534 if gPlayers
[i
] <> nil then
1536 gPlayers
[i
].Reset(Force
);
1538 if gPlayers
[i
] is TPlayer
then
1540 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1541 gPlayers
[i
].Respawn(Silent
)
1543 gPlayers
[i
].Spectate();
1546 TBot(gPlayers
[i
]).Respawn(Silent
);
1550 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1556 if Player
.alive
then
1559 // Ðàçðûâàåì ñâÿçü ñ ïðåæíèì òðóïîì:
1560 if gCorpses
<> nil then
1561 for i
:= 0 to High(gCorpses
) do
1562 if gCorpses
[i
] <> nil then
1563 if gCorpses
[i
].FPlayerUID
= Player
.FUID
then
1564 gCorpses
[i
].FPlayerUID
:= 0;
1566 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1571 if (FHealth
>= -50) or (gGibsCount
= 0) then
1573 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1577 for find_id
:= 0 to High(gCorpses
) do
1578 if gCorpses
[find_id
] = nil then
1585 find_id
:= Random(Length(gCorpses
));
1587 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1588 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1589 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1590 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1591 gCorpses
[find_id
].FPlayerUID
:= FUID
;
1594 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1595 FObj
.Y
+ PLAYER_RECT_CY
,
1596 FModel
.Name
, FModel
.Color
);
1600 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1604 if (gShells
= nil) or (Length(gShells
) = 0) then
1607 with gShells
[CurrentShell
] do
1613 if T
= SHELL_BULLET
then
1615 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1619 Obj
.Rect
.Width
:= 4;
1620 Obj
.Rect
.Height
:= 2;
1624 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1628 Obj
.Rect
.Width
:= 7;
1629 Obj
.Rect
.Height
:= 3;
1635 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1636 positionChanged(); // this updates spatial accelerators
1637 RAngle
:= Random(360);
1638 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1640 if CurrentShell
>= High(gShells
) then
1647 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1650 GibsArray
: TGibsArray
;
1653 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1655 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1657 Blood
:= g_PlayerModel_GetBlood(ModelName
);
1659 for a
:= 0 to High(GibsArray
) do
1660 with gGibs
[CurrentGib
] do
1663 ID
:= GibsArray
[a
].ID
;
1664 MaskID
:= GibsArray
[a
].MaskID
;
1667 Obj
.Rect
:= GibsArray
[a
].Rect
;
1668 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1669 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1670 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1671 positionChanged(); // this updates spatial accelerators
1672 RAngle
:= Random(360);
1674 if gBloodCount
> 0 then
1675 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1676 Random(48), Random(48), Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
1678 if CurrentGib
>= High(gGibs
) then
1685 procedure g_Player_UpdatePhysicalObjects();
1691 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1696 if T
= SHELL_BULLET
then
1697 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1699 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1704 if gGibs
<> nil then
1705 for i
:= 0 to High(gGibs
) do
1706 if gGibs
[i
].alive
then
1710 mr
:= g_Obj_Move(@Obj
, True, False, True);
1711 positionChanged(); // this updates spatial accelerators
1713 if WordBool(mr
and MOVE_FALLOUT
) then
1719 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1720 if WordBool(mr
and MOVE_HITWALL
) then
1721 Obj
.Vel
.X
:= -(vel
.X
div 2);
1722 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1723 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1725 if (Obj
.Vel
.X
>= 0) then
1727 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1728 if RAngle
>= 360 then
1729 RAngle
:= RAngle
mod 360;
1730 end else begin // Counter-clockwise
1731 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1733 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1736 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1737 if gTime
mod (GAME_TICK
*3) = 0 then
1738 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1742 if gCorpses
<> nil then
1743 for i
:= 0 to High(gCorpses
) do
1744 if gCorpses
[i
] <> nil then
1745 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1751 gCorpses
[i
].Update();
1754 if gShells
<> nil then
1755 for i
:= 0 to High(gShells
) do
1756 if gShells
[i
].alive
then
1760 mr
:= g_Obj_Move(@Obj
, True, False, True);
1761 positionChanged(); // this updates spatial accelerators
1763 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1769 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1770 if WordBool(mr
and MOVE_HITWALL
) then
1772 Obj
.Vel
.X
:= -(vel
.X
div 2);
1773 if not WordBool(mr
and MOVE_INWATER
) then
1774 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1776 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1778 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1779 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1780 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1782 if RAngle
mod 90 <> 0 then
1783 RAngle
:= (RAngle
div 90) * 90;
1785 else if not WordBool(mr
and MOVE_INWATER
) then
1786 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1789 if (Obj
.Vel
.X
>= 0) then
1791 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1792 if RAngle
>= 360 then
1793 RAngle
:= RAngle
mod 360;
1794 end else begin // Counter-clockwise
1795 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1797 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1803 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1805 x
:= Obj
.X
+Obj
.Rect
.X
;
1806 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1807 w
:= Obj
.Rect
.Width
;
1808 h
:= Obj
.Rect
.Height
;
1811 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1813 if (dx
<> 0) or (dy
<> 0) then
1822 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1826 w
:= Obj
.Rect
.Width
;
1827 h
:= Obj
.Rect
.Height
;
1830 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1832 if (dx
<> 0) or (dy
<> 0) then
1841 procedure TGib
.positionChanged (); inline; begin end;
1842 procedure TShell
.positionChanged (); inline; begin end;
1845 procedure g_Player_DrawCorpses();
1850 if gGibs
<> nil then
1851 for i
:= 0 to High(gGibs
) do
1852 if gGibs
[i
].alive
then
1855 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1858 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1859 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1861 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1864 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1870 if gCorpses
<> nil then
1871 for i
:= 0 to High(gCorpses
) do
1872 if gCorpses
[i
] <> nil then
1876 procedure g_Player_DrawShells();
1881 if gShells
<> nil then
1882 for i
:= 0 to High(gShells
) do
1883 if gShells
[i
].alive
then
1886 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1892 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1896 procedure g_Player_RemoveAllCorpses();
1902 SetLength(gGibs
, MaxGibs
);
1903 SetLength(gShells
, MaxGibs
);
1907 if gCorpses
<> nil then
1908 for i
:= 0 to High(gCorpses
) do
1912 SetLength(gCorpses
, MaxCorpses
);
1915 procedure g_Player_Corpses_SaveState (st
: TStream
);
1919 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ
1921 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1923 // Êîëè÷åñòâî òðóïîâ
1924 utils
.writeInt(st
, LongInt(count
));
1926 if (count
= 0) then exit
;
1929 for i
:= 0 to High(gCorpses
) do
1931 if gCorpses
[i
] <> nil then
1934 utils
.writeStr(st
, gCorpses
[i
].FModelName
);
1936 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1937 // Ñîõðàíÿåì äàííûå òðóïà:
1938 gCorpses
[i
].SaveState(st
);
1944 procedure g_Player_Corpses_LoadState (st
: TStream
);
1952 g_Player_RemoveAllCorpses();
1954 // Êîëè÷åñòâî òðóïîâ:
1955 count
:= utils
.readLongInt(st
);
1956 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1958 if (count
= 0) then exit
;
1961 for i
:= 0 to count
-1 do
1964 str
:= utils
.readStr(st
);
1966 b
:= utils
.readBool(st
);
1968 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1969 // Çàãðóæàåì äàííûå òðóïà
1970 gCorpses
[i
].LoadState(st
);
1977 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1979 procedure TPlayer
.BFGHit();
1981 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1982 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1983 if g_Game_IsServer
and g_Game_IsNet
then
1984 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1985 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1989 procedure TPlayer
.ChangeModel(ModelName
: string);
1991 locModel
: TPlayerModel
;
1993 locModel
:= g_PlayerModel_Get(ModelName
);
1994 if locModel
= nil then Exit
;
2000 procedure TPlayer
.SetModel(ModelName
: string);
2004 m
:= g_PlayerModel_Get(ModelName
);
2007 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
2008 m
:= g_PlayerModel_Get('doomer');
2011 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
2016 if FModel
<> nil then
2021 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2022 FModel
.Color
:= FColor
2024 FModel
.Color
:= TEAMCOLOR
[FTeam
];
2025 FModel
.SetWeapon(FCurrWeap
);
2026 FModel
.SetFlag(FFlag
);
2027 SetDirection(FDirection
);
2030 procedure TPlayer
.SetColor(Color
: TRGB
);
2033 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2034 if FModel
<> nil then FModel
.Color
:= Color
;
2037 procedure TPlayer
.SwitchTeam
;
2039 if g_Game_IsClient
then
2041 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
2043 if gGameOn
and FAlive
then
2044 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
2046 if FTeam
= TEAM_RED
then
2048 ChangeTeam(TEAM_BLUE
);
2049 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
2050 if g_Game_IsNet
then
2051 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
2055 ChangeTeam(TEAM_RED
);
2056 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
2057 if g_Game_IsNet
then
2058 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
2060 FPreferredTeam
:= FTeam
;
2063 procedure TPlayer
.ChangeTeam(Team
: Byte);
2070 TEAM_RED
, TEAM_BLUE
:
2071 FModel
.Color
:= TEAMCOLOR
[Team
];
2073 FModel
.Color
:= FColor
;
2075 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2076 MH_SEND_PlayerStats(FUID
);
2080 procedure TPlayer.CollideItem();
2085 if gItems = nil then Exit;
2086 if not FAlive then Exit;
2088 for i := 0 to High(gItems) do
2091 if (ItemType <> ITEM_NONE) and alive then
2092 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2093 PLAYER_RECT.Height, @Obj) then
2095 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2097 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2098 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2099 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2100 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2101 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2103 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2104 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2105 (gGameSettings.GameType = GT_SINGLE) and
2106 (g_Player_GetCount() > 1)) then
2107 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2113 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2115 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2116 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2120 constructor TPlayer
.Create();
2126 mEDamageType
:= HIT_SOME
;
2132 FSawSound
:= TPlayableSound
.Create();
2133 FSawSoundIdle
:= TPlayableSound
.Create();
2134 FSawSoundHit
:= TPlayableSound
.Create();
2135 FSawSoundSelect
:= TPlayableSound
.Create();
2136 FFlameSoundOn
:= TPlayableSound
.Create();
2137 FFlameSoundOff
:= TPlayableSound
.Create();
2138 FFlameSoundWork
:= TPlayableSound
.Create();
2139 FJetSoundFly
:= TPlayableSound
.Create();
2140 FJetSoundOn
:= TPlayableSound
.Create();
2141 FJetSoundOff
:= TPlayableSound
.Create();
2143 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2144 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2145 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2146 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2147 FFlameSoundOn
.SetByName('SOUND_WEAPON_FLAMEON');
2148 FFlameSoundOff
.SetByName('SOUND_WEAPON_FLAMEOFF');
2149 FFlameSoundWork
.SetByName('SOUND_WEAPON_FLAMEWORK');
2150 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2151 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2152 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2154 FSpectatePlayer
:= -1;
2158 FSavedState
.WaitRecall
:= False;
2165 FActualModelName
:= 'doomer';
2168 FObj
.Rect
:= PLAYER_RECT
;
2170 FBFGFireCounter
:= -1;
2171 FJustTeleported
:= False;
2177 procedure TPlayer
.positionChanged (); inline;
2181 procedure TPlayer
.doDamage (v
: Integer);
2183 if (v
<= 0) then exit
;
2184 if (v
> 32767) then v
:= 32767;
2185 Damage(v
, 0, 0, 0, mEDamageType
);
2188 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2192 if (not g_Game_IsClient
) and (not FAlive
) then
2197 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2198 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2200 if not g_Game_IsClient
then
2203 if t
= HIT_TRAP
then
2205 // Ëîâóøêà óáèâàåò ñðàçó:
2207 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2209 if t
= HIT_SELF
then
2213 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2216 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2217 FMegaRulez
[MR_SUIT
] := 0;
2218 FMegaRulez
[MR_INVUL
] := 0;
2219 FMegaRulez
[MR_INVIS
] := 0;
2223 // Íî îò îñòàëüíîãî ñïàñàåò:
2224 if FMegaRulez
[MR_INVUL
] >= gTime
then
2231 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2232 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2233 (SpawnerUID
= FUID
) or
2234 (not SameTeam(FUID
, SpawnerUID
)) then
2236 FLastSpawnerUID
:= SpawnerUID
;
2238 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2239 if gBloodCount
> 0 then
2241 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2242 if value
div 4 <= c
then
2243 c
:= c
- (value
div 4)
2247 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2251 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2252 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2255 if t
= HIT_WATER
then
2256 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2257 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2262 Inc(FDamageBuffer
, value
);
2266 FPain
:= FPain
+ value
;
2269 if g_Game_IsServer
and g_Game_IsNet
then
2271 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2272 MH_SEND_PlayerStats(FUID
);
2273 MH_SEND_PlayerPos(False, FUID
);
2277 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2280 if g_Game_IsClient
then
2285 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2287 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2290 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2292 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2296 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2297 MH_SEND_PlayerStats(FUID
);
2300 destructor TPlayer
.Destroy();
2302 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2304 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2308 FSawSoundIdle
.Free();
2309 FSawSoundHit
.Free();
2310 FSawSoundSelect
.Free();
2311 FFlameSoundOn
.Free();
2312 FFlameSoundOff
.Free();
2313 FFlameSoundWork
.Free();
2314 FJetSoundFly
.Free();
2316 FJetSoundOff
.Free();
2318 if FPunchAnim
<> nil then
2324 procedure TPlayer
.DrawIndicator();
2326 indX
, indY
: Integer;
2332 if g_Texture_Get('TEXTURE_PLAYER_INDICATOR', ID
) then
2334 e_GetTextureSize(ID
, @indW
, @indH
);
2335 indX
:= FObj
.X
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
- indW
) div 2;
2337 e_Draw(ID
, indX
, indY
- indH
, 0, True, False);
2340 //e_TextureFontPrint(indX, indY, FName, gStdFont); // Shows player name overhead
2343 procedure TPlayer
.DrawBubble();
2345 bubX
, bubY
: Integer;
2348 Rw
, Gw
, Bw
: SmallInt;
2351 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= TDirection
.D_LEFT
, -4, 18);
2352 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2360 1: // simple textual non-bubble
2362 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2363 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2364 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2367 2: // advanced pixel-perfect bubble
2369 if FTeam
= TEAM_RED
then
2372 if FTeam
= TEAM_BLUE
then
2375 3: // colored bubble
2377 Rb
:= FModel
.Color
.R
;
2378 Gb
:= FModel
.Color
.G
;
2379 Bb
:= FModel
.Color
.B
;
2380 Rw
:= Min(Rb
* 2 + 64, 255);
2381 Gw
:= Min(Gb
* 2 + 64, 255);
2382 Bw
:= Min(Bb
* 2 + 64, 255);
2383 if (Abs(Rw
- Rb
) < 32)
2384 or (Abs(Gw
- Gb
) < 32)
2385 or (Abs(Bw
- Bb
) < 32) then
2387 Rb
:= Max(Rw
div 2 - 16, 0);
2388 Gb
:= Max(Gw
div 2 - 16, 0);
2389 Bb
:= Max(Bw
div 2 - 16, 0);
2392 4: // custom textured bubble
2394 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2395 if FDirection
= TDirection
.D_RIGHT
then
2396 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2398 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, TMirrorType
.Horizontal
);
2404 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2405 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2407 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2410 Dot
:= IfThen(FDirection
= TDirection
.D_LEFT
, 14, 5);
2411 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2412 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
);
2413 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
);
2414 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
);
2415 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
);
2419 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2420 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2421 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2424 procedure TPlayer
.Draw();
2429 Mirror
: TMirrorType
;
2433 if Direction
= TDirection
.D_RIGHT
then
2434 Mirror
:= TMirrorType
.None
2436 Mirror
:= TMirrorType
.Horizontal
;
2438 if FPunchAnim
<> nil then
2440 FPunchAnim
.Draw(FObj
.X
+IfThen(Direction
= TDirection
.D_LEFT
, 15-FObj
.Rect
.X
, FObj
.Rect
.X
-15),
2441 FObj
.Y
+FObj
.Rect
.Y
-11, Mirror
);
2442 if FPunchAnim
.played
then
2449 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2450 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2452 e_GetTextureSize(ID
, @w
, @h
);
2453 if FDirection
= TDirection
.D_LEFT
then
2454 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2455 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False)
2457 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2458 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False);
2461 if FMegaRulez
[MR_INVIS
] > gTime
then
2463 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2464 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2466 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2467 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2471 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 200)
2473 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2476 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 254);
2479 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2482 if g_debug_Frames
then
2484 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2486 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2487 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2491 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2492 if (FMegaRulez
[MR_INVIS
] <= gTime
) or ((gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2493 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
)))) then
2495 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2496 if gAimLine
and alive
and
2497 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2502 procedure TPlayer
.DrawAim();
2503 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2508 {$IFDEF ENABLE_HOLMES}
2509 if isValidViewPort
and (self
= gPlayer1
) then
2511 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2515 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2516 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2518 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2522 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2527 wx
, wy
, xx
, yy
: Integer;
2531 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= TDirection
.D_LEFT
, 7, -7);
2532 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2541 1: begin // Chainsaw
2548 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2549 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2550 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2551 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2556 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2557 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2558 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2559 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2561 4: begin // Double Shotgun
2564 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2565 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2566 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2567 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2569 5: begin // Chaingun
2572 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2573 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2574 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2575 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2577 6: begin // Rocket Launcher
2580 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2581 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2582 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2583 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2585 7: begin // Plasmagun
2588 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2589 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2590 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2591 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2596 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2597 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2598 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2599 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2601 9: begin // Super Chaingun
2604 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2605 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2606 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2607 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2610 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2611 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2612 {$IF DEFINED(D2F_DEBUG)}
2613 drawCast(sz
, wx
, wy
, xx
, yy
);
2615 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2619 procedure TPlayer
.DrawGUI();
2622 X
, Y
, SY
, a
, p
, m
: Integer;
2626 stat
: TPlayerStatArray
;
2628 X
:= gPlayerScreenSize
.X
;
2629 SY
:= gPlayerScreenSize
.Y
;
2632 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2634 if gGameSettings
.GameMode
= GM_CTF
then
2638 if gGameSettings
.GameMode
= GM_CTF
then
2640 s
:= 'TEXTURE_PLAYER_REDFLAG';
2641 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2642 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2643 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2644 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2645 if g_Texture_Get(s
, ID
) then
2646 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2649 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2650 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2651 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2653 if gGameSettings
.GameMode
= GM_CTF
then
2655 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2656 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2657 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2658 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2659 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2660 if g_Texture_Get(s
, ID
) then
2661 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2664 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2665 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2666 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2669 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2670 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2673 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2674 e_Draw(ID
, X
+2, Y
, 0, True, False);
2676 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2680 s
:= IntToStr(Frags
);
2681 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2682 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2687 stat
:= g_Player_GetStats();
2692 for a
:= 0 to High(stat
) do
2693 if stat
[a
].Name
<> Name
then
2695 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2696 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2700 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2701 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2702 s
:= s
+IntToStr(Abs(Frags
-m
));
2704 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2705 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2708 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2710 s
:= IntToStr(Lives
);
2711 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2712 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2716 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2717 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2719 if R_BERSERK
in FRulez
then
2720 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2722 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2724 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2725 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2727 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2728 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2729 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2731 s
:= IntToStr(FArmor
);
2732 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2733 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2735 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2741 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2746 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2748 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2749 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2750 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2751 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2752 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2753 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2754 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2755 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2756 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2759 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2760 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2761 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2763 if R_KEY_RED
in FRulez
then
2764 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2766 if R_KEY_GREEN
in FRulez
then
2767 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2769 if R_KEY_BLUE
in FRulez
then
2770 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2772 if FJetFuel
> 0 then
2774 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2775 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2776 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2777 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2778 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2779 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2783 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2784 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2785 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2788 if gShowPing
and g_Game_IsClient
then
2790 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2791 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2797 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2798 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2799 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2802 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2803 s
:= _lc
[I_PLAYER_SPECT4
];
2804 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2805 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2806 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2812 procedure TPlayer
.DrawRulez();
2816 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2817 if FMegaRulez
[MR_INVUL
] >= gTime
then
2819 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2820 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2825 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2826 191, 191, 191, 0, TBlending
.Invert
);
2829 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2830 if FMegaRulez
[MR_SUIT
] >= gTime
then
2832 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2833 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2838 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2839 0, 96, 0, 200, TBlending
.None
);
2842 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2843 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2845 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2846 255, 0, 0, 200, TBlending
.None
);
2850 procedure TPlayer
.DrawPain();
2854 if FPain
= 0 then Exit
;
2858 if a
< 15 then h
:= 0
2859 else if a
< 35 then h
:= 1
2860 else if a
< 55 then h
:= 2
2861 else if a
< 75 then h
:= 3
2862 else if a
< 95 then h
:= 4
2865 //if a > 255 then a := 255;
2867 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2868 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2871 procedure TPlayer
.DrawPickup();
2875 if FPickup
= 0 then Exit
;
2879 if a
< 15 then h
:= 1
2880 else if a
< 35 then h
:= 2
2881 else if a
< 55 then h
:= 3
2882 else if a
< 75 then h
:= 4
2885 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2888 procedure TPlayer
.DoPunch();
2893 if FPunchAnim
<> nil then begin
2898 st
:= 'FRAMES_PUNCH';
2899 if R_BERSERK
in FRulez
then
2900 st
:= st
+ '_BERSERK';
2901 if FKeys
[KEY_UP
].Pressed
then
2903 else if FKeys
[KEY_DOWN
].Pressed
then
2905 g_Frames_Get(id
, st
);
2906 FPunchAnim
:= TAnimation
.Create(id
, False, 1);
2909 procedure TPlayer
.Fire();
2911 f
, DidFire
: Boolean;
2912 wx
, wy
, xd
, yd
: Integer;
2915 if g_Game_IsClient
then Exit
;
2916 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2917 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2925 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2930 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2931 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2932 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
2933 yd
:= wy
+firediry();
2939 if R_BERSERK
in FRulez
then
2941 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2942 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2943 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2946 locobj
.rect
.Width
:= 39;
2947 locobj
.rect
.Height
:= 52;
2948 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2949 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2950 locobj
.Accel
.X
:= xd
-wx
;
2951 locobj
.Accel
.y
:= yd
-wy
;
2953 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2954 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2956 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2958 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
2962 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2966 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2971 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2972 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2974 FSawSoundSelect
.Stop();
2976 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2978 else if not FSawSoundHit
.IsPlaying() then
2980 FSawSoundSelect
.Stop();
2981 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2984 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2990 if FAmmo
[A_BULLETS
] > 0 then
2992 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2993 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2994 Dec(FAmmo
[A_BULLETS
]);
2995 FFireAngle
:= FAngle
;
2998 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2999 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3003 if FAmmo
[A_SHELLS
] > 0 then
3005 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3006 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
3007 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3008 Dec(FAmmo
[A_SHELLS
]);
3009 FFireAngle
:= FAngle
;
3013 FShellType
:= SHELL_SHELL
;
3017 if FAmmo
[A_SHELLS
] >= 2 then
3019 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
3020 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3021 Dec(FAmmo
[A_SHELLS
], 2);
3022 FFireAngle
:= FAngle
;
3026 FShellType
:= SHELL_DBLSHELL
;
3030 if FAmmo
[A_BULLETS
] > 0 then
3032 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
3033 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
3034 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3035 Dec(FAmmo
[A_BULLETS
]);
3036 FFireAngle
:= FAngle
;
3039 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3040 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3043 WEAPON_ROCKETLAUNCHER
:
3044 if FAmmo
[A_ROCKETS
] > 0 then
3046 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
3047 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3048 Dec(FAmmo
[A_ROCKETS
]);
3049 FFireAngle
:= FAngle
;
3055 if FAmmo
[A_CELLS
] > 0 then
3057 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
3058 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3059 Dec(FAmmo
[A_CELLS
]);
3060 FFireAngle
:= FAngle
;
3066 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
3068 FBFGFireCounter
:= 17;
3069 if not FNoReload
then
3070 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
3071 Dec(FAmmo
[A_CELLS
], 40);
3075 WEAPON_SUPERPULEMET
:
3076 if FAmmo
[A_SHELLS
] > 0 then
3078 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3079 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
3080 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3081 Dec(FAmmo
[A_SHELLS
]);
3082 FFireAngle
:= FAngle
;
3085 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3086 GameVelX
, GameVelY
-2, SHELL_SHELL
);
3089 WEAPON_FLAMETHROWER
:
3090 if FAmmo
[A_FUEL
] > 0 then
3092 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
3094 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3096 FFireAngle
:= FAngle
;
3103 if g_Game_IsNet
and g_Game_IsServer
then MH_SEND_PlayerStats(FUID
);
3107 if g_Game_IsNet
then
3111 if FCurrWeap
<> WEAPON_BFG
then
3112 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
3114 if not FNoReload
then
3115 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
3118 MH_SEND_PlayerStats(FUID
);
3123 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
3124 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
3125 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
3128 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
3131 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
3132 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
3133 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
3134 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
3135 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
3140 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
3142 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
3143 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
3144 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
3147 procedure TPlayer
.FlamerOn
;
3149 FFlameSoundOff
.Stop();
3150 FFlameSoundOff
.SetPosition(0);
3153 if (not FFlameSoundOn
.IsPlaying()) and (not FFlameSoundWork
.IsPlaying()) then
3154 FFlameSoundWork
.PlayAt(FObj
.X
, FObj
.Y
);
3158 FFlameSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3163 procedure TPlayer
.FlamerOff
;
3167 FFlameSoundOn
.Stop();
3168 FFlameSoundOn
.SetPosition(0);
3169 FFlameSoundWork
.Stop();
3170 FFlameSoundWork
.SetPosition(0);
3171 FFlameSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3176 procedure TPlayer
.JetpackOn
;
3180 FJetSoundOn
.SetPosition(0);
3181 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3185 procedure TPlayer
.JetpackOff
;
3189 FJetSoundOff
.SetPosition(0);
3190 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3193 procedure TPlayer
.CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
3195 if Timeout
<= 0 then
3197 if (FMegaRulez
[MR_SUIT
] > gTime
) or (FMegaRulez
[MR_INVUL
] > gTime
) then
3198 exit
; // Íå çàãîðàåìñÿ êîãäà åñòü çàùèòà
3199 if g_Obj_CollidePanel(@FObj
, 0, 0, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
) then
3200 exit
; // Íå ïîäãîðàåì â âîäå íà âñÿêèé ñëó÷àé
3201 if FFireTime
<= 0 then
3202 g_Sound_PlayExAt('SOUND_IGNITE', FObj
.X
, FObj
.Y
);
3203 FFireTime
:= Timeout
;
3204 FFireAttacker
:= Attacker
;
3205 if g_Game_IsNet
and g_Game_IsServer
then
3206 MH_SEND_PlayerStats(FUID
);
3209 procedure TPlayer
.Jump();
3211 if gFly
or FJetpack
then
3213 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3214 if FObj
.Vel
.Y
> -VEL_FLY
then
3215 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3218 if FJetFuel
> 0 then
3220 if (FJetFuel
< 1) and g_Game_IsServer
then
3224 if g_Game_IsNet
then
3225 MH_SEND_PlayerStats(FUID
);
3231 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3233 FCanJetpack
:= False;
3235 // Ïðûãàåì èëè âñïëûâàåì:
3236 if (CollideLevel(0, 1) or
3237 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3238 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3239 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3241 FObj
.Vel
.Y
:= -VEL_JUMP
;
3242 FCanJetpack
:= False;
3246 if BodyInLiquid(0, 0) then
3247 FObj
.Vel
.Y
:= -VEL_SW
3248 else if (FJetFuel
> 0) and FCanJetpack
and
3249 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3253 if g_Game_IsNet
then
3254 MH_SEND_PlayerStats(FUID
);
3259 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3261 a
, i
, k
, ab
, ar
: Byte;
3265 srv
, netsrv
: Boolean;
3271 procedure PushItem(t
: Byte);
3275 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3276 it
:= g_Items_ByIdx(id
);
3277 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3279 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3280 (FObj
.Vel
.Y
div 2)-Random(9));
3281 it
.positionChanged(); // this updates spatial accelerators
3285 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3287 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3288 (FObj
.Vel
.Y
div 2)-Random(6));
3290 else // -3..+3; -3..0
3292 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3293 (FObj
.Vel
.Y
div 2)-Random(4));
3295 it
.positionChanged(); // this updates spatial accelerators
3298 if g_Game_IsNet
and g_Game_IsServer
then
3299 MH_SEND_ItemSpawn(True, id
);
3303 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3304 Srv
:= g_Game_IsServer
;
3305 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3306 if Srv
then FDeath
:= FDeath
+ 1;
3311 if not FPhysics
then
3317 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3319 if FLives
> 0 then FLives
:= FLives
- 1;
3320 if FLives
= 0 then FNoRespawn
:= True;
3323 // Íîìåð òèïà ñìåðòè:
3326 K_SIMPLEKILL
: a
:= 1;
3328 K_EXTRAHARDKILL
: a
:= 3;
3333 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3335 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3342 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3344 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3345 K_EXTRAHARDKILL
, K_FALLKILL
:
3346 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3349 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3353 K_HARDKILL
, K_EXTRAHARDKILL
:
3357 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3358 if (KillType
<> K_FALLKILL
) and (Srv
) then
3359 g_Monsters_killedp();
3361 if SpawnerUID
= FUID
then
3363 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3368 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3371 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3372 begin // Óáèò äðóãèì èãðîêîì
3373 KP
:= g_Player_Get(SpawnerUID
);
3374 if (KP
<> nil) and Srv
then
3376 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3377 if SameTeam(FUID
, SpawnerUID
) then
3387 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3388 Inc(gTeamStat
[KP
.Team
].Goals
,
3389 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3391 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3394 plr
:= g_Player_Get(SpawnerUID
);
3402 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3406 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3410 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3415 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3416 begin // Óáèò ìîíñòðîì
3417 mon
:= g_Monsters_ByUID(SpawnerUID
);
3421 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
3425 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3429 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3433 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3438 else // Îñîáûå òèïû ñìåðòè
3441 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3442 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3443 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3444 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3445 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3446 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3452 for a
:= WP_FIRST
to WP_LAST
do
3456 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3457 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3458 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3459 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3460 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3461 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3462 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3463 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3464 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3473 if R_ITEM_BACKPACK
in FRulez
then
3474 PushItem(ITEM_AMMO_BACKPACK
);
3476 // Âûáðîñ ðàêåòíîãî ðàíöà:
3477 if FJetFuel
> 0 then
3478 PushItem(ITEM_JETPACK
);
3481 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3483 if R_KEY_RED
in FRulez
then
3484 PushItem(ITEM_KEY_RED
);
3486 if R_KEY_GREEN
in FRulez
then
3487 PushItem(ITEM_KEY_GREEN
);
3489 if R_KEY_BLUE
in FRulez
then
3490 PushItem(ITEM_KEY_BLUE
);
3494 DropFlag(KillType
= K_FALLKILL
);
3497 g_Player_CreateCorpse(Self
);
3499 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3500 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3506 for i
:= Low(gPlayers
) to High(gPlayers
) do
3508 if gPlayers
[i
] = nil then continue
;
3509 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3512 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3513 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3518 OldLR
:= gLMSRespawn
;
3519 if (gGameSettings
.GameMode
= GM_COOP
) then
3523 // everyone is dead, restart the map
3524 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3526 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3527 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3528 gLMSRespawnTime
:= gTime
+ 5000;
3530 else if (a
= 1) then
3532 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3533 if (gPlayers
[k
] = gPlayer1
) or
3534 (gPlayers
[k
] = gPlayer2
) then
3535 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3536 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3537 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3540 else if (gGameSettings
.GameMode
= GM_TDM
) then
3542 if (ab
= 0) and (ar
<> 0) then
3545 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3547 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3548 Inc(gTeamStat
[TEAM_RED
].Goals
);
3549 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3550 gLMSRespawnTime
:= gTime
+ 5000;
3552 else if (ar
= 0) and (ab
<> 0) then
3555 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3557 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3558 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3559 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3560 gLMSRespawnTime
:= gTime
+ 5000;
3562 else if (ar
= 0) and (ab
= 0) then
3565 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3567 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3568 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3569 gLMSRespawnTime
:= gTime
+ 5000;
3572 else if (gGameSettings
.GameMode
= GM_DM
) then
3576 if gPlayers
[k
] <> nil then
3579 // survivor is the winner
3580 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3582 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3585 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3586 gLMSRespawnTime
:= gTime
+ 5000;
3588 else if (a
= 0) then
3590 // everyone is dead, restart the map
3591 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3593 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3594 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3595 gLMSRespawnTime
:= gTime
+ 5000;
3598 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3600 if NetMode
= NET_SERVER
then
3601 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3603 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3609 MH_SEND_PlayerStats(FUID
);
3610 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3611 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3614 if srv
and FNoRespawn
then Spectate(True);
3615 FWantsInGame
:= True;
3618 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3620 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3621 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3624 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3626 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3627 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3630 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3632 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3633 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3634 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3635 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3636 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3637 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3638 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3639 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3642 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3644 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3645 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3646 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3647 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3650 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3652 if g_Game_IsClient
then Exit
;
3653 if Weapon
> High(FWeapon
) then Exit
;
3654 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3657 procedure TPlayer
.resetWeaponQueue ();
3660 FNextWeapDelay
:= 0;
3663 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3667 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3668 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 0);
3669 WEAPON_PISTOL
, WEAPON_CHAINGUN
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_BULLETS
] > 0);
3670 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3671 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3672 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3673 else result
:= (weapon
< length(FWeapon
));
3677 // return 255 for "no switch"
3678 function TPlayer
.getNextWeaponIndex (): Byte;
3681 wantThisWeapon
: array[0..64] of Boolean;
3682 wwc
: Integer = 0; //HACK!
3685 result
:= 255; // default result: "no switch"
3686 // had weapon cycling on previous frame? remove that flag
3687 if (FNextWeap
and $2000) <> 0 then
3689 FNextWeap
:= FNextWeap
and $1FFF;
3690 FNextWeapDelay
:= 0;
3692 // cycling has priority
3693 if (FNextWeap
and $C000) <> 0 then
3695 if (FNextWeap
and $8000) <> 0 then
3699 FNextWeap
:= FNextWeap
or $2000; // we need this
3700 if FNextWeapDelay
> 0 then
3701 exit
; // cooldown time
3703 for i
:= 0 to High(FWeapon
) do
3705 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3706 if FWeapon
[cwi
] then
3708 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d', [FCurrWeap, cwi]), MSG_WARNING);
3709 result
:= Byte(cwi
);
3710 FNextWeapDelay
:= WEAPON_DELAY
;
3718 for i
:= 0 to High(wantThisWeapon
) do
3719 wantThisWeapon
[i
] := false;
3720 for i
:= 0 to High(FWeapon
) do
3721 if (FNextWeap
and (1 shl i
)) <> 0 then
3723 wantThisWeapon
[i
] := true;
3726 // exclude currently selected weapon from the set
3727 wantThisWeapon
[FCurrWeap
] := false;
3728 // slow down alterations a little
3731 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3732 // more than one weapon requested, assume "alteration" and check alteration delay
3733 if FNextWeapDelay
> 0 then
3739 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3740 // but clear all counters if no weapon should be switched
3746 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3747 // try weapons in descending order
3748 for i
:= High(FWeapon
) downto 0 do
3750 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3755 FNextWeapDelay
:= WEAPON_DELAY
* 2; // anyway, 'cause why not
3759 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3763 procedure TPlayer
.RealizeCurrentWeapon();
3764 function switchAllowed (): Boolean;
3769 if FBFGFireCounter
<> -1 then
3771 if FTime
[T_SWITCH
] > gTime
then
3773 for i
:= WP_FIRST
to WP_LAST
do
3774 if FReloading
[i
] > 0 then
3782 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3783 //FNextWeap := FNextWeap and $1FFF;
3784 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3786 if not switchAllowed
then
3788 //HACK for weapon cycling
3789 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3793 nw
:= getNextWeaponIndex();
3794 if nw
= 255 then exit
; // don't reset anything here
3795 if nw
> High(FWeapon
) then
3797 // don't forget to reset queue here!
3798 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3806 FTime
[T_SWITCH
] := gTime
+156;
3807 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3808 FModel
.SetWeapon(FCurrWeap
);
3809 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3813 procedure TPlayer
.NextWeapon();
3815 if g_Game_IsClient
then Exit
;
3819 procedure TPlayer
.PrevWeapon();
3821 if g_Game_IsClient
then Exit
;
3825 procedure TPlayer
.SetWeapon(W
: Byte);
3827 if FCurrWeap
<> W
then
3828 if W
= WEAPON_SAW
then
3829 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3832 FModel
.SetWeapon(CurrWeap
);
3836 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3838 function allowBerserkSwitching (): Boolean;
3840 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3842 if gBerserkAutoswitch
then exit
;
3843 if not conIsCheatsEnabled
then exit
;
3851 if g_Game_IsClient
then Exit
;
3853 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3854 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3859 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3861 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3865 if gFlash
= 2 then Inc(FPickup
, 5);
3869 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3871 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3875 if gFlash
= 2 then Inc(FPickup
, 5);
3879 if FArmor
< PLAYER_AP_SOFT
then
3881 FArmor
:= PLAYER_AP_SOFT
;
3884 if gFlash
= 2 then Inc(FPickup
, 5);
3888 if FArmor
< PLAYER_AP_LIMIT
then
3890 FArmor
:= PLAYER_AP_LIMIT
;
3893 if gFlash
= 2 then Inc(FPickup
, 5);
3897 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
3899 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3903 if gFlash
= 2 then Inc(FPickup
, 5);
3907 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) or (FFireTime
> 0) then
3909 if FHealth
< PLAYER_HP_LIMIT
then
3910 FHealth
:= PLAYER_HP_LIMIT
;
3911 if FArmor
< PLAYER_AP_LIMIT
then
3912 FArmor
:= PLAYER_AP_LIMIT
;
3916 if gFlash
= 2 then Inc(FPickup
, 5);
3920 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3922 FWeapon
[WEAPON_SAW
] := True;
3924 if gFlash
= 2 then Inc(FPickup
, 5);
3925 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3928 ITEM_WEAPON_SHOTGUN1
:
3929 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3931 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3932 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3934 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3935 FWeapon
[WEAPON_SHOTGUN1
] := True;
3937 if gFlash
= 2 then Inc(FPickup
, 5);
3938 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3941 ITEM_WEAPON_SHOTGUN2
:
3942 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3944 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3946 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3947 FWeapon
[WEAPON_SHOTGUN2
] := True;
3949 if gFlash
= 2 then Inc(FPickup
, 5);
3950 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3953 ITEM_WEAPON_CHAINGUN
:
3954 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3956 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3958 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3959 FWeapon
[WEAPON_CHAINGUN
] := True;
3961 if gFlash
= 2 then Inc(FPickup
, 5);
3962 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3965 ITEM_WEAPON_ROCKETLAUNCHER
:
3966 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3968 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3970 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3971 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3973 if gFlash
= 2 then Inc(FPickup
, 5);
3974 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3978 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3980 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3982 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3983 FWeapon
[WEAPON_PLASMA
] := True;
3985 if gFlash
= 2 then Inc(FPickup
, 5);
3986 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3990 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3992 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3994 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3995 FWeapon
[WEAPON_BFG
] := True;
3997 if gFlash
= 2 then Inc(FPickup
, 5);
3998 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4001 ITEM_WEAPON_SUPERPULEMET
:
4002 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
4004 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
4006 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4007 FWeapon
[WEAPON_SUPERPULEMET
] := True;
4009 if gFlash
= 2 then Inc(FPickup
, 5);
4010 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4013 ITEM_WEAPON_FLAMETHROWER
:
4014 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
4016 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
4018 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4019 FWeapon
[WEAPON_FLAMETHROWER
] := True;
4021 if gFlash
= 2 then Inc(FPickup
, 5);
4022 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4026 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4028 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4031 if gFlash
= 2 then Inc(FPickup
, 5);
4034 ITEM_AMMO_BULLETS_BOX
:
4035 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4037 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4040 if gFlash
= 2 then Inc(FPickup
, 5);
4044 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4046 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4049 if gFlash
= 2 then Inc(FPickup
, 5);
4052 ITEM_AMMO_SHELLS_BOX
:
4053 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4055 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
4058 if gFlash
= 2 then Inc(FPickup
, 5);
4062 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4064 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4067 if gFlash
= 2 then Inc(FPickup
, 5);
4070 ITEM_AMMO_ROCKET_BOX
:
4071 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4073 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
4076 if gFlash
= 2 then Inc(FPickup
, 5);
4080 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4082 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4085 if gFlash
= 2 then Inc(FPickup
, 5);
4089 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4091 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4094 if gFlash
= 2 then Inc(FPickup
, 5);
4098 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4100 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4103 if gFlash
= 2 then Inc(FPickup
, 5);
4107 if not(R_ITEM_BACKPACK
in FRulez
) or
4108 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4109 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4110 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4111 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4112 (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) then
4114 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4115 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4116 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4117 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4118 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4120 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4121 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4122 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4123 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4124 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4125 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4126 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4127 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4128 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4129 IncMax(FAmmo
[A_FUEL
], 50, FMaxAmmo
[A_FUEL
]);
4131 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
4134 if gFlash
= 2 then Inc(FPickup
, 5);
4138 if not(R_KEY_RED
in FRulez
) then
4140 Include(FRulez
, R_KEY_RED
);
4142 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4143 if gFlash
= 2 then Inc(FPickup
, 5);
4144 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4148 if not(R_KEY_GREEN
in FRulez
) then
4150 Include(FRulez
, R_KEY_GREEN
);
4152 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4153 if gFlash
= 2 then Inc(FPickup
, 5);
4154 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4158 if not(R_KEY_BLUE
in FRulez
) then
4160 Include(FRulez
, R_KEY_BLUE
);
4162 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4163 if gFlash
= 2 then Inc(FPickup
, 5);
4164 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4168 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4170 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4174 if gFlash
= 2 then Inc(FPickup
, 5);
4178 if FAir
< AIR_MAX
then
4183 if gFlash
= 2 then Inc(FPickup
, 5);
4188 if not (R_BERSERK
in FRulez
) then
4190 Include(FRulez
, R_BERSERK
);
4191 if allowBerserkSwitching
then
4193 FCurrWeap
:= WEAPON_KASTET
;
4195 FModel
.SetWeapon(WEAPON_KASTET
);
4200 if gFlash
= 2 then Inc(FPickup
, 5);
4202 FBerserk
:= gTime
+30000;
4207 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
4209 if FHealth
< PLAYER_HP_SOFT
then FHealth
:= PLAYER_HP_SOFT
;
4210 FBerserk
:= gTime
+30000;
4218 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4220 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4223 if gFlash
= 2 then Inc(FPickup
, 5);
4227 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
4229 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4233 if gFlash
= 2 then Inc(FPickup
, 5);
4237 if FArmor
< PLAYER_AP_LIMIT
then
4239 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4242 if gFlash
= 2 then Inc(FPickup
, 5);
4246 if FJetFuel
< JET_MAX
then
4248 FJetFuel
:= JET_MAX
;
4251 if gFlash
= 2 then Inc(FPickup
, 5);
4255 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4257 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4260 if gFlash
= 2 then Inc(FPickup
, 5);
4265 procedure TPlayer
.Touch();
4269 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4272 // Áðîñèòü ôëàã òîâàðèùó:
4273 if gGameSettings
.GameMode
= GM_CTF
then
4278 procedure TPlayer
.Push(vx
, vy
: Integer);
4280 if (not FPhysics
) and FGhost
then
4282 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4283 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4284 if g_Game_IsNet
and g_Game_IsServer
then
4285 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4288 procedure TPlayer
.Reset(Force
: Boolean);
4294 FTime
[T_RESPAWN
] := 0;
4295 FTime
[T_FLAGCAP
] := 0;
4309 FSpectator
:= False;
4312 FSpectatePlayer
:= -1;
4313 FNoRespawn
:= False;
4315 FLives
:= gGameSettings
.MaxLives
;
4320 procedure TPlayer
.SoftReset();
4326 FBFGFireCounter
:= -1;
4334 SetAction(A_STAND
, True);
4337 function TPlayer
.GetRespawnPoint(): Byte;
4342 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4344 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4345 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4347 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4349 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4350 if Self
= gPlayer1
then
4351 c
:= RESPAWNPOINT_PLAYER1
4353 c
:= RESPAWNPOINT_PLAYER2
;
4354 if g_Map_GetPointCount(c
) > 0 then
4360 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4361 if Self
= gPlayer1
then
4362 c
:= RESPAWNPOINT_PLAYER2
4364 c
:= RESPAWNPOINT_PLAYER1
;
4365 if g_Map_GetPointCount(c
) > 0 then
4372 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4373 if Random(2) = 0 then
4374 c
:= RESPAWNPOINT_PLAYER1
4376 c
:= RESPAWNPOINT_PLAYER2
;
4377 if g_Map_GetPointCount(c
) > 0 then
4384 // Òî÷êà ëþáîé èç êîìàíä
4385 if Random(2) = 0 then
4386 c
:= RESPAWNPOINT_RED
4388 c
:= RESPAWNPOINT_BLUE
;
4389 if g_Map_GetPointCount(c
) > 0 then
4396 c
:= RESPAWNPOINT_DM
;
4397 if g_Map_GetPointCount(c
) > 0 then
4405 if gGameSettings
.GameMode
= GM_DM
then
4408 c
:= RESPAWNPOINT_DM
;
4409 if g_Map_GetPointCount(c
) > 0 then
4415 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4416 if Random(2) = 0 then
4417 c
:= RESPAWNPOINT_PLAYER1
4419 c
:= RESPAWNPOINT_PLAYER2
;
4420 if g_Map_GetPointCount(c
) > 0 then
4426 // Òî÷êà ëþáîé èç êîìàíä
4427 if Random(2) = 0 then
4428 c
:= RESPAWNPOINT_RED
4430 c
:= RESPAWNPOINT_BLUE
;
4431 if g_Map_GetPointCount(c
) > 0 then
4439 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4441 // Òî÷êà ñâîåé êîìàíäû
4442 c
:= RESPAWNPOINT_DM
;
4443 if FTeam
= TEAM_RED
then
4444 c
:= RESPAWNPOINT_RED
;
4445 if FTeam
= TEAM_BLUE
then
4446 c
:= RESPAWNPOINT_BLUE
;
4447 if g_Map_GetPointCount(c
) > 0 then
4454 c
:= RESPAWNPOINT_DM
;
4455 if g_Map_GetPointCount(c
) > 0 then
4461 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4462 if Random(2) = 0 then
4463 c
:= RESPAWNPOINT_PLAYER1
4465 c
:= RESPAWNPOINT_PLAYER2
;
4466 if g_Map_GetPointCount(c
) > 0 then
4472 // Òî÷êà äðóãîé êîìàíäû
4473 c
:= RESPAWNPOINT_DM
;
4474 if FTeam
= TEAM_RED
then
4475 c
:= RESPAWNPOINT_BLUE
;
4476 if FTeam
= TEAM_BLUE
then
4477 c
:= RESPAWNPOINT_RED
;
4478 if g_Map_GetPointCount(c
) > 0 then
4486 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4488 RespawnPoint
: TRespawnPoint
;
4494 FBFGFireCounter
:= -1;
4499 if not g_Game_IsServer
then
4503 FWantsInGame
:= True;
4504 FJustTeleported
:= True;
4507 FTime
[T_RESPAWN
] := 0;
4511 // if server changes MaxLives we gotta be ready
4512 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4514 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4515 if FTime
[T_RESPAWN
] > gTime
then
4518 // Ïðîñðàë âñå æèçíè:
4521 if not FSpectator
then Spectate(True);
4522 FWantsInGame
:= True;
4526 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4527 begin // "Ñâîÿ èãðà"
4528 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4529 FRulez
:= FRulez
-[R_BERSERK
];
4531 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4533 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4534 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4537 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4538 c
:= GetRespawnPoint();
4543 // Âîñêðåøåíèå áåç îðóæèÿ:
4546 FHealth
:= Round(PLAYER_HP_SOFT
* (FHandicap
/ 100));
4552 for a
:= WP_FIRST
to WP_LAST
do
4554 FWeapon
[a
] := False;
4558 FWeapon
[WEAPON_PISTOL
] := True;
4559 FWeapon
[WEAPON_KASTET
] := True;
4560 FCurrWeap
:= WEAPON_PISTOL
;
4563 FModel
.SetWeapon(FCurrWeap
);
4565 for b
:= A_BULLETS
to A_HIGH
do
4568 FAmmo
[A_BULLETS
] := 50;
4570 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4571 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4572 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4573 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4574 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4576 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4577 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4582 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4583 if not g_Map_GetPoint(c
, RespawnPoint
) then
4585 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4589 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4590 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4591 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4597 FDirection
:= RespawnPoint
.Direction
;
4598 if FDirection
= TDirection
.D_LEFT
then
4603 SetAction(A_STAND
, True);
4604 FModel
.Direction
:= FDirection
;
4606 for a
:= Low(FTime
) to High(FTime
) do
4609 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4614 FCanJetpack
:= False;
4620 // Àíèìàöèÿ âîçðîæäåíèÿ:
4621 if (not gLoadGameMode
) and (not Silent
) then
4622 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4624 Anim
:= TAnimation
.Create(ID
, False, 3);
4625 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4626 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4630 FSpectator
:= False;
4633 FSpectatePlayer
:= -1;
4636 if (gPlayer1
= nil) and (gLMSPID1
= FUID
) then
4638 if (gPlayer2
= nil) and (gLMSPID2
= FUID
) then
4641 if g_Game_IsNet
then
4643 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4644 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4646 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4647 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4652 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4655 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4656 else if (not NoMove
) then
4658 GameX
:= gMapInfo
.Width
div 2;
4659 GameY
:= gMapInfo
.Height
div 2;
4668 FWantsInGame
:= False;
4673 if Self
= gPlayer1
then
4678 if Self
= gPlayer2
then
4685 if g_Game_IsNet
then
4686 MH_SEND_PlayerStats(FUID
);
4689 procedure TPlayer
.SwitchNoClip
;
4693 FGhost
:= not FGhost
;
4694 FPhysics
:= not FGhost
;
4706 procedure TPlayer
.Run(Direction
: TDirection
);
4710 if MAX_RUNVEL
> 8 then
4714 if Direction
= TDirection
.D_LEFT
then
4716 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4717 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4720 if FObj
.Vel
.X
< MAX_RUNVEL
then
4721 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4723 // Âîçìîæíî, ïèíàåì êóñêè:
4724 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4726 b
:= Abs(FObj
.Vel
.X
);
4727 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4728 for a
:= 0 to High(gGibs
) do
4730 if gGibs
[a
].alive
and
4731 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4732 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4735 if FObj
.Vel
.X
< 0 then
4737 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4741 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4743 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4751 procedure TPlayer
.SeeDown();
4753 SetAction(A_SEEDOWN
);
4755 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4757 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4760 procedure TPlayer
.SeeUp();
4764 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4766 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4769 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4777 A_ATTACK
: Prior
:= 2;
4778 A_SEEUP
: Prior
:= 1;
4779 A_SEEDOWN
: Prior
:= 1;
4780 A_ATTACKUP
: Prior
:= 2;
4781 A_ATTACKDOWN
: Prior
:= 2;
4786 if (Prior
> FActionPrior
) or Force
then
4787 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4789 FActionPrior
:= Prior
;
4790 FActionAnim
:= Action
;
4791 FActionForce
:= Force
;
4792 FActionChanged
:= True;
4795 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4798 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4800 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4801 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4802 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4803 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4806 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4813 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4815 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4816 if g_Game_IsServer
and g_Game_IsNet
then
4817 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4821 FJustTeleported
:= True;
4826 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4828 Anim
:= TAnimation
.Create(ID
, False, 3);
4831 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4832 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4833 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4834 if g_Game_IsServer
and g_Game_IsNet
then
4835 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4836 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4840 FObj
.X
:= X
-PLAYER_RECT
.X
;
4841 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4842 if FAlive
and FGhost
then
4848 if not g_Game_IsNet
then
4852 SetDirection(TDirection
.D_LEFT
);
4858 SetDirection(TDirection
.D_RIGHT
);
4864 if FDirection
= TDirection
.D_RIGHT
then
4866 SetDirection(TDirection
.D_LEFT
);
4871 SetDirection(TDirection
.D_RIGHT
);
4877 if not silent
and (Anim
<> nil) then
4879 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4880 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4883 if g_Game_IsServer
and g_Game_IsNet
then
4884 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4885 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4892 function nonz(a
: Single): Single;
4900 function TPlayer
.followCorpse(): Boolean;
4905 if FAlive
or FSpectator
then
4907 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
4909 for i
:= 0 to High(gCorpses
) do
4910 if gCorpses
[i
] <> nil then
4911 if gCorpses
[i
].FPlayerUID
= FUID
then
4914 FObj
.X
:= gCorpses
[i
].FObj
.X
;
4915 FObj
.Y
:= gCorpses
[i
].FObj
.Y
;
4916 FObj
.Vel
.X
:= gCorpses
[i
].FObj
.Vel
.X
;
4917 FObj
.Vel
.Y
:= gCorpses
[i
].FObj
.Vel
.Y
;
4918 FObj
.Accel
.X
:= gCorpses
[i
].FObj
.Accel
.X
;
4919 FObj
.Accel
.Y
:= gCorpses
[i
].FObj
.Accel
.Y
;
4924 procedure TPlayer
.Update();
4927 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4928 blockmon
, headwater
, dospawn
: Boolean;
4933 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4934 AnyServer
:= g_Game_IsServer
;
4936 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4937 DoLerp(NetInterpLevel
+ 1)
4943 if FClientID
>= 0 then
4945 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4946 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4947 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4956 if FAlive
and (FPunchAnim
<> nil) then
4957 FPunchAnim
.Update();
4959 if FAlive
and (gFly
or FJetpack
) then
4962 if FDirection
= TDirection
.D_LEFT
then
4967 if FAlive
and (not FGhost
) then
4969 if FKeys
[KEY_UP
].Pressed
then
4971 if FKeys
[KEY_DOWN
].Pressed
then
4975 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4978 i
:= g_basic
.Sign(FIncCam
);
4979 FIncCam
:= Abs(FIncCam
);
4980 DecMin(FIncCam
, 5, 0);
4981 FIncCam
:= FIncCam
*i
;
4984 // no need to do that each second frame, weapon queue will take care of it
4985 if FAlive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4986 if FAlive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4988 if gTime
mod (GAME_TICK
*2) <> 0 then
4990 if (FObj
.Vel
.X
= 0) and FAlive
then
4992 if FKeys
[KEY_LEFT
].Pressed
then
4993 Run(TDirection
.D_LEFT
);
4994 if FKeys
[KEY_RIGHT
].Pressed
then
4995 Run(TDirection
.D_RIGHT
);
5000 if not followCorpse() then
5001 g_Obj_Move(@FObj
, True, True, True);
5002 positionChanged(); // this updates spatial accelerators
5008 FActionChanged
:= False;
5012 // Let alive player do some actions
5013 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
5014 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
5015 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
5016 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
5017 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire()
5023 if NetServer
then MH_SEND_PlayerStats(FUID
);
5026 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
5027 if FKeys
[KEY_JUMP
].Pressed
then Jump()
5030 if AnyServer
and FJetpack
then
5034 if NetServer
then MH_SEND_PlayerStats(FUID
);
5036 FCanJetpack
:= True;
5043 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
5045 if FKeys
[k
].Pressed
then
5053 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5056 if (FTime
[T_RESPAWN
] <= gTime
) and
5057 gGameOn
and (not FAlive
) then
5059 if (g_Player_GetCount() > 1) then
5063 gExit
:= EXIT_RESTART
;
5068 // Dead spectator actions
5071 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
5072 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
5076 if (FSpectatePlayer
>= High(gPlayers
)) then
5077 FSpectatePlayer
:= -1
5081 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
5082 if gPlayers
[I
] <> nil then
5083 if gPlayers
[I
].alive
then
5084 if gPlayers
[I
].UID
<> FUID
then
5086 FSpectatePlayer
:= I
;
5091 if not SetSpect
then FSpectatePlayer
:= -1;
5102 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5104 FYTo
:= FObj
.Y
- 32;
5105 FSpectatePlayer
:= -1;
5107 if FKeys
[KEY_DOWN
].Pressed
then
5109 FYTo
:= FObj
.Y
+ 32;
5110 FSpectatePlayer
:= -1;
5112 if FKeys
[KEY_LEFT
].Pressed
then
5114 FXTo
:= FObj
.X
- 32;
5115 FSpectatePlayer
:= -1;
5117 if FKeys
[KEY_RIGHT
].Pressed
then
5119 FXTo
:= FObj
.X
+ 32;
5120 FSpectatePlayer
:= -1;
5123 if (FXTo
< -64) then
5125 else if (FXTo
> gMapInfo
.Width
+ 32) then
5126 FXTo
:= gMapInfo
.Width
+ 32;
5127 if (FYTo
< -72) then
5129 else if (FYTo
> gMapInfo
.Height
+ 32) then
5130 FYTo
:= gMapInfo
.Height
+ 32;
5135 if not followCorpse() then
5136 g_Obj_Move(@FObj
, True, True, True);
5137 positionChanged(); // this updates spatial accelerators
5144 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5145 if gPlayers
[FSpectatePlayer
] <> nil then
5146 if gPlayers
[FSpectatePlayer
].alive
then
5148 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
5149 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
5153 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5154 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5155 PANEL_BLOCKMON
, True);
5156 headwater
:= HeadInLiquid(0, 0);
5158 // Ñîïðîòèâëåíèå âîçäóõà:
5159 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5160 if FObj
.Vel
.X
<> 0 then
5161 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5163 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5164 DecMin(FPain
, 5, 0);
5165 DecMin(FPickup
, 1, 0);
5167 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5169 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5170 FMegaRulez
[MR_SUIT
] := 0;
5171 FMegaRulez
[MR_INVUL
] := 0;
5172 FMegaRulez
[MR_INVIS
] := 0;
5173 Kill(K_FALLKILL
, 0, HIT_FALL
);
5180 if FCurrWeap
= WEAPON_SAW
then
5181 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5182 FSawSoundSelect
.IsPlaying()) then
5183 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5186 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5187 (not FJetSoundOff
.IsPlaying()) then
5189 FJetSoundFly
.SetPosition(0);
5190 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5193 for b
:= WP_FIRST
to WP_LAST
do
5194 if FReloading
[b
] > 0 then
5200 if FShellTimer
> -1 then
5201 if FShellTimer
= 0 then
5203 if FShellType
= SHELL_SHELL
then
5204 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5205 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5206 else if FShellType
= SHELL_DBLSHELL
then
5208 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5209 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5210 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5211 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5214 end else Dec(FShellTimer
);
5216 if (FBFGFireCounter
> -1) then
5217 if FBFGFireCounter
= 0 then
5221 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5222 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5223 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5224 yd
:= wy
+firediry();
5225 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5226 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5227 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5228 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5229 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5232 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5233 FBFGFireCounter
:= -1;
5236 FBFGFireCounter
:= 0
5238 Dec(FBFGFireCounter
);
5240 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5242 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5244 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5247 if (headwater
or blockmon
) then
5253 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5256 else if (FAir
mod 31 = 0) and not blockmon
then
5258 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5259 if Random(2) = 0 then
5260 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5262 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5264 end else if FAir
< AIR_DEF
then
5267 if FFireTime
> 0 then
5269 if BodyInLiquid(0, 0) then
5274 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5276 if FMegaRulez
[MR_SUIT
] = gTime
then
5283 if FFirePainTime
<= 0 then
5285 if g_Game_IsServer
then
5286 Damage(2, FFireAttacker
, 0, 0, HIT_FLAME
);
5287 FFirePainTime
:= 12 - FFireTime
div 12;
5289 FFirePainTime
:= FFirePainTime
- 1;
5290 FFireTime
:= FFireTime
- 1;
5291 if ((FFireTime
mod 33) = 0) and (FMegaRulez
[MR_INVUL
] < gTime
) then
5292 FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
);
5293 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5294 MH_SEND_PlayerStats(FUID
);
5298 if FDamageBuffer
> 0 then
5300 if FDamageBuffer
>= 9 then
5304 if FDamageBuffer
< 30 then i
:= 9
5305 else if FDamageBuffer
< 100 then i
:= 18
5309 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5310 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5311 FHealth
:= FHealth
-ii
;
5314 FHealth
:= FHealth
+FArmor
;
5319 if FHealth
<= 0 then
5320 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5321 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5322 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5324 if FAlive
and ((FLastHit
<> HIT_FLAME
) or (FFireTime
<= 0)) then
5326 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5327 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5328 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5329 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5336 end; // if FAlive then ...
5338 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5340 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5341 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5342 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5343 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5345 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5346 then SetAction(A_STAND
, True);
5348 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5350 for b
:= Low(FKeys
) to High(FKeys
) do
5351 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5355 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5357 x
:= FObj
.X
+PLAYER_RECT
.X
;
5358 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5359 w
:= PLAYER_RECT
.Width
;
5360 h
:= PLAYER_RECT
.Height
;
5364 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5366 if (dx
<> 0) or (dy
<> 0) then
5375 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5377 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5378 FObj
.Y
+PLAYER_RECT
.Y
,
5385 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5387 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5388 FObj
.Y
+PLAYER_RECT
.Y
,
5392 Panel
.Width
, Panel
.Height
);
5395 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5397 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5398 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5399 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5400 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5403 function g_Player_ValidName(Name
: string): Boolean;
5409 if gPlayers
= nil then Exit
;
5411 for a
:= 0 to High(gPlayers
) do
5412 if gPlayers
[a
] <> nil then
5413 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5420 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5424 d
:= FModel
.Direction
;
5426 FModel
.Direction
:= Direction
;
5427 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5429 FDirection
:= Direction
;
5432 function TPlayer
.GetKeys(): Byte;
5436 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5437 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5438 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5440 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5441 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5444 procedure TPlayer
.Use();
5448 if FTime
[T_USE
] > gTime
then Exit
;
5450 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5451 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5453 for a
:= 0 to High(gPlayers
) do
5454 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5455 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5456 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5457 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5459 gPlayers
[a
].Touch();
5460 if g_Game_IsNet
and g_Game_IsServer
then
5461 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5464 FTime
[T_USE
] := gTime
+120;
5467 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5471 WX
, WY
, XD
, YD
: Integer;
5483 if R_BERSERK
in FRulez
then
5485 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5486 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5487 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5490 locobj
.rect
.Width
:= 39;
5491 locobj
.rect
.Height
:= 52;
5492 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5493 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5494 locobj
.Accel
.X
:= xd
-wx
;
5495 locobj
.Accel
.y
:= yd
-wy
;
5497 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5498 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5500 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5504 FPain
:= min(FPain
+ 25, 50);
5506 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5511 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5512 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5514 FSawSoundSelect
.Stop();
5516 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5518 else if not FSawSoundHit
.IsPlaying() then
5520 FSawSoundSelect
.Stop();
5521 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5528 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5529 FFireAngle
:= FAngle
;
5531 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5532 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5537 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5538 FFireAngle
:= FAngle
;
5541 FShellType
:= SHELL_SHELL
;
5546 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5547 FFireAngle
:= FAngle
;
5550 FShellType
:= SHELL_DBLSHELL
;
5555 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5556 FFireAngle
:= FAngle
;
5558 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5559 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5562 WEAPON_ROCKETLAUNCHER
:
5564 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5565 FFireAngle
:= FAngle
;
5571 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5572 FFireAngle
:= FAngle
;
5578 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5579 FFireAngle
:= FAngle
;
5583 WEAPON_SUPERPULEMET
:
5585 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5586 FFireAngle
:= FAngle
;
5588 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5589 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5592 WEAPON_FLAMETHROWER
:
5594 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5596 FFireAngle
:= FAngle
;
5603 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5604 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5605 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5608 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5610 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5611 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5614 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5618 if NetInterpLevel
< 1 then
5628 AX
:= Abs(FXTo
- FObj
.X
);
5629 AY
:= Abs(FYTo
- FObj
.Y
);
5630 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5632 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5637 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5639 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5640 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5641 PANEL_LIFTUP
, False) then Result
:= -1
5643 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5644 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5645 PANEL_LIFTDOWN
, False) then Result
:= 1
5649 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5656 if Flag
= FLAG_NONE
then
5659 if not g_Game_IsServer
then Exit
;
5661 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5662 if (Flag
= FTeam
) and
5663 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5664 (FFlag
<> FLAG_NONE
) then
5666 if FFlag
= FLAG_RED
then
5667 s
:= _lc
[I_PLAYER_FLAG_RED
]
5669 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5671 evtype
:= FLAG_STATE_SCORED
;
5673 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5674 Insert('.', ts
, Length(ts
) + 1 - 3);
5675 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5677 g_Map_ResetFlag(FFlag
);
5678 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5680 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5681 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5682 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5687 if not sound_cap_flag
[a
].IsPlaying() then
5688 sound_cap_flag
[a
].Play();
5690 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5693 if g_Game_IsNet
then
5695 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5699 gFlags
[FFlag
].CaptureTime
:= 0;
5704 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5705 if (Flag
= FTeam
) and
5706 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5708 if Flag
= FLAG_RED
then
5709 s
:= _lc
[I_PLAYER_FLAG_RED
]
5711 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5713 evtype
:= FLAG_STATE_RETURNED
;
5714 gFlags
[Flag
].CaptureTime
:= 0;
5716 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5718 g_Map_ResetFlag(Flag
);
5719 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5721 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5722 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5723 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5728 if not sound_ret_flag
[a
].IsPlaying() then
5729 sound_ret_flag
[a
].Play();
5732 if g_Game_IsNet
then
5734 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5740 // Ïîäîáðàë ÷óæîé ôëàã:
5741 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5745 if Flag
= FLAG_RED
then
5746 s
:= _lc
[I_PLAYER_FLAG_RED
]
5748 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5750 evtype
:= FLAG_STATE_CAPTURED
;
5752 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5754 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5756 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5758 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5759 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5760 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5765 if not sound_get_flag
[a
].IsPlaying() then
5766 sound_get_flag
[a
].Play();
5769 if g_Game_IsNet
then
5771 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5777 procedure TPlayer
.SetFlag(Flag
: Byte);
5780 if FModel
<> nil then
5781 FModel
.SetFlag(FFlag
);
5784 function TPlayer
.DropFlag(Silent
: Boolean = True): Boolean;
5790 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5792 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5793 with gFlags
[FFlag
] do
5797 Direction
:= FDirection
;
5798 State
:= FLAG_STATE_DROPPED
;
5800 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5801 (FObj
.Vel
.Y
div 2)-2+Random(5));
5802 positionChanged(); // this updates spatial accelerators
5804 if FFlag
= FLAG_RED
then
5805 s
:= _lc
[I_PLAYER_FLAG_RED
]
5807 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5809 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5810 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5812 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5813 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5814 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5819 if (not Silent
) and (not sound_lost_flag
[a
].IsPlaying()) then
5820 sound_lost_flag
[a
].Play();
5822 if g_Game_IsNet
then
5823 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5829 procedure TPlayer
.GetSecret();
5831 if (self
= gPlayer1
) or (self
= gPlayer2
) then
5833 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [FName
]), True);
5834 g_Sound_PlayEx('SOUND_GAME_SECRET');
5839 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5841 Assert(Key
<= High(FKeys
));
5843 FKeys
[Key
].Pressed
:= True;
5844 FKeys
[Key
].Time
:= Time
;
5847 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5849 Result
:= FKeys
[K
].Pressed
;
5852 procedure TPlayer
.ReleaseKeys();
5856 for a
:= Low(FKeys
) to High(FKeys
) do
5858 FKeys
[a
].Pressed
:= False;
5863 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5867 function TPlayer
.firediry(): Integer;
5869 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5870 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5874 procedure TPlayer
.RememberState();
5878 FSavedState
.Health
:= FHealth
;
5879 FSavedState
.Armor
:= FArmor
;
5880 FSavedState
.Air
:= FAir
;
5881 FSavedState
.JetFuel
:= FJetFuel
;
5882 FSavedState
.CurrWeap
:= FCurrWeap
;
5883 FSavedState
.NextWeap
:= FNextWeap
;
5884 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5887 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5889 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5891 FSavedState
.Rulez
:= FRulez
;
5892 FSavedState
.WaitRecall
:= True;
5895 procedure TPlayer
.RecallState();
5899 if not FSavedState
.WaitRecall
then Exit
;
5901 FHealth
:= FSavedState
.Health
;
5902 FArmor
:= FSavedState
.Armor
;
5903 FAir
:= FSavedState
.Air
;
5904 FJetFuel
:= FSavedState
.JetFuel
;
5905 FCurrWeap
:= FSavedState
.CurrWeap
;
5906 FNextWeap
:= FSavedState
.NextWeap
;
5907 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5910 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5912 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5914 FRulez
:= FSavedState
.Rulez
;
5915 FSavedState
.WaitRecall
:= False;
5917 if gGameSettings
.GameType
= GT_SERVER
then
5918 MH_SEND_PlayerStats(FUID
);
5921 procedure TPlayer
.SaveState (st
: TStream
);
5927 utils
.writeSign(st
, 'PLYR');
5928 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
5930 utils
.writeBool(st
, FIamBot
);
5932 utils
.writeInt(st
, Word(FUID
));
5934 utils
.writeStr(st
, FName
);
5936 utils
.writeInt(st
, Byte(FTeam
));
5938 utils
.writeBool(st
, FAlive
);
5939 // Èçðàñõîäîâàë ëè âñå æèçíè
5940 utils
.writeBool(st
, FNoRespawn
);
5942 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
5943 utils
.writeInt(st
, Byte(b
));
5945 utils
.writeInt(st
, LongInt(FHealth
));
5946 // Êîýôôèöèåíò èíâàëèäíîñòè
5947 utils
.writeInt(st
, LongInt(FHandicap
));
5949 utils
.writeInt(st
, Byte(FLives
));
5951 utils
.writeInt(st
, LongInt(FArmor
));
5953 utils
.writeInt(st
, LongInt(FAir
));
5955 utils
.writeInt(st
, LongInt(FJetFuel
));
5957 utils
.writeInt(st
, LongInt(FPain
));
5959 utils
.writeInt(st
, LongInt(FKills
));
5961 utils
.writeInt(st
, LongInt(FMonsterKills
));
5963 utils
.writeInt(st
, LongInt(FFrags
));
5965 utils
.writeInt(st
, Byte(FFragCombo
));
5966 // Âðåìÿ ïîñëåäíåãî ôðàãà
5967 utils
.writeInt(st
, LongWord(FLastFrag
));
5969 utils
.writeInt(st
, LongInt(FDeath
));
5971 utils
.writeInt(st
, Byte(FFlag
));
5973 utils
.writeInt(st
, LongInt(FSecrets
));
5975 utils
.writeInt(st
, Byte(FCurrWeap
));
5977 utils
.writeInt(st
, Word(FNextWeap
));
5979 utils
.writeInt(st
, Byte(FNextWeapDelay
));
5980 // Âðåìÿ çàðÿäêè BFG
5981 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
5983 utils
.writeInt(st
, LongInt(FDamageBuffer
));
5984 // Ïîñëåäíèé óäàðèâøèé
5985 utils
.writeInt(st
, Word(FLastSpawnerUID
));
5986 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
5987 utils
.writeInt(st
, Byte(FLastHit
));
5989 Obj_SaveState(st
, @FObj
);
5990 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
5991 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
5992 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
5993 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
5995 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
5996 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
5997 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
5999 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
6000 // Íàëè÷èå êðàñíîãî êëþ÷à
6001 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
6002 // Íàëè÷èå çåëåíîãî êëþ÷à
6003 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
6004 // Íàëè÷èå ñèíåãî êëþ÷à
6005 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
6007 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
6008 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6009 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
6010 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6011 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
6013 utils
.writeStr(st
, FModel
.Name
);
6015 utils
.writeInt(st
, Byte(FColor
.R
));
6016 utils
.writeInt(st
, Byte(FColor
.G
));
6017 utils
.writeInt(st
, Byte(FColor
.B
));
6021 procedure TPlayer
.LoadState (st
: TStream
);
6030 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
6031 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
6033 FIamBot
:= utils
.readBool(st
);
6035 FUID
:= utils
.readWord(st
);
6037 str
:= utils
.readStr(st
);
6038 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
6040 FTeam
:= utils
.readByte(st
);
6042 FAlive
:= utils
.readBool(st
);
6043 // Èçðàñõîäîâàë ëè âñå æèçíè
6044 FNoRespawn
:= utils
.readBool(st
);
6046 b
:= utils
.readByte(st
);
6047 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
6049 FHealth
:= utils
.readLongInt(st
);
6050 // Êîýôôèöèåíò èíâàëèäíîñòè
6051 FHandicap
:= utils
.readLongInt(st
);
6053 FLives
:= utils
.readByte(st
);
6055 FArmor
:= utils
.readLongInt(st
);
6057 FAir
:= utils
.readLongInt(st
);
6059 FJetFuel
:= utils
.readLongInt(st
);
6061 FPain
:= utils
.readLongInt(st
);
6063 FKills
:= utils
.readLongInt(st
);
6065 FMonsterKills
:= utils
.readLongInt(st
);
6067 FFrags
:= utils
.readLongInt(st
);
6069 FFragCombo
:= utils
.readByte(st
);
6070 // Âðåìÿ ïîñëåäíåãî ôðàãà
6071 FLastFrag
:= utils
.readLongWord(st
);
6073 FDeath
:= utils
.readLongInt(st
);
6075 FFlag
:= utils
.readByte(st
);
6077 FSecrets
:= utils
.readLongInt(st
);
6079 FCurrWeap
:= utils
.readByte(st
);
6081 FNextWeap
:= utils
.readWord(st
);
6083 FNextWeapDelay
:= utils
.readByte(st
);
6084 // Âðåìÿ çàðÿäêè BFG
6085 FBFGFireCounter
:= utils
.readSmallInt(st
);
6087 FDamageBuffer
:= utils
.readLongInt(st
);
6088 // Ïîñëåäíèé óäàðèâøèé
6089 FLastSpawnerUID
:= utils
.readWord(st
);
6090 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6091 FLastHit
:= utils
.readByte(st
);
6093 Obj_LoadState(@FObj
, st
);
6094 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6095 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
6096 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6097 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
6099 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
6100 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6101 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
6103 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
6104 // Íàëè÷èå êðàñíîãî êëþ÷à
6105 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
6106 // Íàëè÷èå çåëåíîãî êëþ÷à
6107 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
6108 // Íàëè÷èå ñèíåãî êëþ÷à
6109 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
6111 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
6112 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6113 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
6114 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6115 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
6117 str
:= utils
.readStr(st
);
6119 FColor
.R
:= utils
.readByte(st
);
6120 FColor
.G
:= utils
.readByte(st
);
6121 FColor
.B
:= utils
.readByte(st
);
6122 if (self
= gPlayer1
) then
6124 str
:= gPlayer1Settings
.Model
;
6125 FColor
:= gPlayer1Settings
.Color
;
6127 else if (self
= gPlayer2
) then
6129 str
:= gPlayer2Settings
.Model
;
6130 FColor
:= gPlayer2Settings
.Color
;
6132 // Îáíîâëÿåì ìîäåëü èãðîêà
6134 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
6135 FModel
.Color
:= TEAMCOLOR
[FTeam
]
6137 FModel
.Color
:= FColor
;
6141 procedure TPlayer
.AllRulez(Health
: Boolean);
6147 FHealth
:= PLAYER_HP_LIMIT
;
6148 FArmor
:= PLAYER_AP_LIMIT
;
6152 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
6153 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
6154 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6157 procedure TPlayer
.RestoreHealthArmor();
6159 FHealth
:= PLAYER_HP_LIMIT
;
6160 FArmor
:= PLAYER_AP_LIMIT
;
6163 procedure TPlayer
.FragCombo();
6167 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6169 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6171 if FFragCombo
< 5 then
6173 Param
:= FUID
or (FFragCombo
shl 16);
6174 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6175 (FComboEvnt
<= High(gDelayedEvents
)) and
6176 gDelayedEvents
[FComboEvnt
].Pending
and
6177 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6178 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6180 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6181 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6184 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6192 procedure TPlayer
.GiveItem(ItemType
: Byte);
6196 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6198 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6202 if FAir
< AIR_MAX
then
6209 if not (R_BERSERK
in FRulez
) then
6211 Include(FRulez
, R_BERSERK
);
6212 if FBFGFireCounter
< 1 then
6214 FCurrWeap
:= WEAPON_KASTET
;
6216 FModel
.SetWeapon(WEAPON_KASTET
);
6220 FBerserk
:= gTime
+30000;
6222 if FHealth
< PLAYER_HP_SOFT
then
6224 FHealth
:= PLAYER_HP_SOFT
;
6225 FBerserk
:= gTime
+30000;
6230 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6232 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6236 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6238 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6242 if FJetFuel
< JET_MAX
then
6244 FJetFuel
:= JET_MAX
;
6247 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6248 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6250 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6251 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6253 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6255 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6257 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6258 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6261 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6262 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6263 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6264 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6265 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6266 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6267 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6268 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6269 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6271 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6272 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6273 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6274 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6275 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6276 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6277 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6278 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6279 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6282 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6283 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6284 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6285 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6286 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6288 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6289 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6290 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6291 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6292 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6294 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6295 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6296 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6297 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6299 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6302 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6303 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6304 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6306 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6307 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6312 if g_Game_IsNet
and g_Game_IsServer
then
6313 MH_SEND_PlayerStats(FUID
);
6316 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6321 if (Random(5) = 1) and (Times
= 1) then
6324 if BodyInLiquid(0, 0) then
6326 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6327 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6328 if Random(2) = 0 then
6329 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6331 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6335 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6337 for i
:= 1 to Times
do
6339 Anim
:= TAnimation
.Create(id
, False, 3);
6341 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6342 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6348 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6353 if (Random(10) = 1) and (Times
= 1) then
6356 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6358 for i
:= 1 to Times
do
6360 Anim
:= TAnimation
.Create(id
, False, 3);
6362 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6363 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6369 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6371 FSawSound
.Pause(Enable
);
6372 FSawSoundIdle
.Pause(Enable
);
6373 FSawSoundHit
.Pause(Enable
);
6374 FSawSoundSelect
.Pause(Enable
);
6375 FFlameSoundOn
.Pause(Enable
);
6376 FFlameSoundOff
.Pause(Enable
);
6377 FFlameSoundWork
.Pause(Enable
);
6378 FJetSoundFly
.Pause(Enable
);
6379 FJetSoundOn
.Pause(Enable
);
6380 FJetSoundOff
.Pause(Enable
);
6385 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6390 FObj
.Rect
:= PLAYER_CORPSERECT
;
6391 FModelName
:= ModelName
;
6396 FState
:= CORPSE_STATE_MESS
;
6397 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6401 FState
:= CORPSE_STATE_NORMAL
;
6402 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6406 destructor TCorpse
.Destroy();
6413 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6415 procedure TCorpse
.positionChanged (); inline; begin end;
6417 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6419 if (dx
<> 0) or (dy
<> 0) then
6428 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6430 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6431 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6432 w
:= PLAYER_CORPSERECT
.Width
;
6433 h
:= PLAYER_CORPSERECT
.Height
;
6437 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6442 if FState
= CORPSE_STATE_REMOVEME
then
6445 FDamage
:= FDamage
+ Value
;
6447 if FDamage
> 150 then
6449 if FAnimation
<> nil then
6454 FState
:= CORPSE_STATE_REMOVEME
;
6456 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6457 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6458 FModelName
, FColor
);
6459 // Çâóê ìÿñà îò òðóïà:
6460 pm
:= g_PlayerModel_Get(FModelName
);
6461 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6465 if (gBodyKillEvent
<> -1)
6466 and gDelayedEvents
[gBodyKillEvent
].Pending
then
6467 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
6468 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, 0);
6473 Blood
:= g_PlayerModel_GetBlood(FModelName
);
6474 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6475 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6476 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6477 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6478 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6479 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
6483 procedure TCorpse
.Draw();
6485 if FState
= CORPSE_STATE_REMOVEME
then
6488 if FAnimation
<> nil then
6489 FAnimation
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6491 if FAnimationMask
<> nil then
6494 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6501 procedure TCorpse
.Update();
6505 if FState
= CORPSE_STATE_REMOVEME
then
6508 if gTime
mod (GAME_TICK
*2) <> 0 then
6510 g_Obj_Move(@FObj
, True, True, True);
6511 positionChanged(); // this updates spatial accelerators
6515 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6516 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6518 st
:= g_Obj_Move(@FObj
, True, True, True);
6519 positionChanged(); // this updates spatial accelerators
6521 if WordBool(st
and MOVE_FALLOUT
) then
6523 FState
:= CORPSE_STATE_REMOVEME
;
6527 if FAnimation
<> nil then
6528 FAnimation
.Update();
6529 if FAnimationMask
<> nil then
6530 FAnimationMask
.Update();
6534 procedure TCorpse
.SaveState (st
: TStream
);
6541 utils
.writeSign(st
, 'CORP');
6542 utils
.writeInt(st
, Byte(0));
6544 utils
.writeInt(st
, Byte(FState
));
6546 utils
.writeInt(st
, Byte(FDamage
));
6548 utils
.writeInt(st
, Byte(FColor
.R
));
6549 utils
.writeInt(st
, Byte(FColor
.G
));
6550 utils
.writeInt(st
, Byte(FColor
.B
));
6552 Obj_SaveState(st
, @FObj
);
6553 utils
.writeInt(st
, Word(FPlayerUID
));
6555 anim
:= (FAnimation
<> nil);
6556 utils
.writeBool(st
, anim
);
6557 // Åñëè åñòü - ñîõðàíÿåì
6558 if anim
then FAnimation
.SaveState(st
);
6559 // Åñòü ëè ìàñêà àíèìàöèè
6560 anim
:= (FAnimationMask
<> nil);
6561 utils
.writeBool(st
, anim
);
6562 // Åñëè åñòü - ñîõðàíÿåì
6563 if anim
then FAnimationMask
.SaveState(st
);
6567 procedure TCorpse
.LoadState (st
: TStream
);
6574 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6575 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6577 FState
:= utils
.readByte(st
);
6579 FDamage
:= utils
.readByte(st
);
6581 FColor
.R
:= utils
.readByte(st
);
6582 FColor
.G
:= utils
.readByte(st
);
6583 FColor
.B
:= utils
.readByte(st
);
6585 Obj_LoadState(@FObj
, st
);
6586 FPlayerUID
:= utils
.readWord(st
);
6588 anim
:= utils
.readBool(st
);
6589 // Åñëè åñòü - çàãðóæàåì
6592 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6593 FAnimation
.LoadState(st
);
6595 // Åñòü ëè ìàñêà àíèìàöèè
6596 anim
:= utils
.readBool(st
);
6597 // Åñëè åñòü - çàãðóæàåì
6600 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6601 FAnimationMask
.LoadState(st
);
6607 constructor TBot
.Create();
6614 FSpectator
:= False;
6621 for a
:= WP_FIRST
to WP_LAST
do
6623 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6624 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6625 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6629 destructor TBot
.Destroy();
6632 inherited Destroy();
6635 procedure TBot
.Draw();
6639 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6640 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6643 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6645 inherited Respawn(Silent
, Force
);
6648 FSelectedWeapon
:= FCurrWeap
;
6653 procedure TBot
.UpdateCombat();
6666 TTargetRecord
= array of TTarget
;
6668 function Compare(a
, b
: TTarget
): Integer;
6670 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6673 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6675 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6676 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6678 if a
.Dist
> b
.Dist
then // B áëèæå
6680 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6683 else // Ñòðàííî -> A
6688 a
, x1
, y1
, x2
, y2
: Integer;
6689 targets
: TTargetRecord
;
6691 Target
, BestTarget
: TTarget
;
6692 firew
, fireh
: Integer;
6696 vsPlayer
, vsMonster
, ok
: Boolean;
6699 function monsUpdate (mon
: TMonster
): Boolean;
6701 result
:= false; // don't stop
6702 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6704 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6706 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6707 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6709 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6710 if g_TraceVector(x1
, y1
, x2
, y2
) then
6712 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6713 SetLength(targets
, Length(targets
)+1);
6714 with targets
[High(targets
)] do
6721 Rect
:= mon
.Obj
.Rect
;
6722 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6723 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6724 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6733 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6734 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6736 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6737 if FCurrWeap
<> FSelectedWeapon
then
6740 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6741 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6743 RemoveAIFlag('NEEDFIRE');
6746 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6747 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6748 else PressKey(KEY_FIRE
);
6752 // Êîîðäèíàòû ñòâîëà:
6753 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6754 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6756 Target
.UID
:= FTargetUID
;
6759 if Target
.UID
<> 0 then
6760 begin // Öåëü åñòü - íàñòðàèâàåì
6761 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6764 tpla
:= g_Player_Get(Target
.UID
);
6768 if (@FObj
) <> nil then
6775 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6776 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6777 Target
.Rect
:= PLAYER_RECT
;
6778 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6779 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6780 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6781 Target
.IsPlayer
:= True;
6785 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6788 mon
:= g_Monsters_ByUID(Target
.UID
);
6791 Target
.X
:= mon
.Obj
.X
;
6792 Target
.Y
:= mon
.Obj
.Y
;
6794 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6795 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6796 Target
.Rect
:= mon
.Obj
.Rect
;
6797 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6798 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6799 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6800 Target
.IsPlayer
:= False;
6807 begin // Öåëè íåò - îáíóëÿåì
6812 Target
.Visible
:= False;
6813 Target
.Line
:= False;
6814 Target
.IsPlayer
:= False;
6819 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6820 if (not Target
.Line
) or (not Target
.Visible
) then
6824 for a
:= 0 to High(gPlayers
) do
6825 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6826 (gPlayers
[a
].FUID
<> FUID
) and
6827 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6828 (not gPlayers
[a
].NoTarget
) and
6829 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6831 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6832 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6835 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6836 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6838 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6839 if g_TraceVector(x1
, y1
, x2
, y2
) then
6841 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6842 SetLength(targets
, Length(targets
)+1);
6843 with targets
[High(targets
)] do
6845 UID
:= gPlayers
[a
].FUID
;
6846 X
:= gPlayers
[a
].FObj
.X
;
6847 Y
:= gPlayers
[a
].FObj
.Y
;
6850 Rect
:= PLAYER_RECT
;
6851 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6852 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6853 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6861 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6864 // Åñëè åñòü âîçìîæíûå öåëè:
6865 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6866 if targets
<> nil then
6868 // Âûáèðàåì íàèëó÷øóþ öåëü:
6869 BestTarget
:= targets
[0];
6870 if Length(targets
) > 1 then
6871 for a
:= 1 to High(targets
) do
6872 if Compare(BestTarget
, targets
[a
]) = 1 then
6873 BestTarget
:= targets
[a
];
6875 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6876 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6877 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6879 Target
:= BestTarget
;
6881 if (Healthy() = 3) or ((Healthy() = 2)) then
6882 begin // Åñëè çäîðîâû - äîãîíÿåì
6883 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6884 SetAIFlag('GORIGHT', '1');
6885 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6886 SetAIFlag('GOLEFT', '1');
6889 begin // Åñëè ïîáèòû - óáåãàåì
6890 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6891 SetAIFlag('GORIGHT', '1');
6892 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6893 SetAIFlag('GOLEFT', '1');
6896 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6897 SelectWeapon(Abs(x1
-Target
.cX
));
6902 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6903 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6904 if Target
.UID
<> 0 then
6906 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6907 Target
.Y
+ Target
.Rect
.Y
) then
6908 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6909 if (Healthy() = 3) or ((Healthy() = 2)) then
6910 begin // Åñëè çäîðîâû - äîãîíÿåì
6911 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6912 SetAIFlag('GORIGHT', '1');
6913 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6914 SetAIFlag('GOLEFT', '1');
6917 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6919 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6920 SetAIFlag('GORIGHT', '1');
6921 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6922 SetAIFlag('GOLEFT', '1');
6926 begin // Öåëü ïîêà íà "ýêðàíå"
6927 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6928 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6929 FLastVisible
:= gTime
;
6930 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6931 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6933 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6934 SetAIFlag('GORIGHT', '1');
6935 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6936 SetAIFlag('GOLEFT', '1');
6940 // Âûáèðàåì óãîë ââåðõ:
6941 if FDirection
= TDirection
.D_LEFT
then
6942 angle
:= ANGLE_LEFTUP
6944 angle
:= ANGLE_RIGHTUP
;
6946 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6947 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6949 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6950 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6951 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6952 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6953 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6954 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6955 begin // òî íóæíî ñòðåëÿòü ââåðõ
6956 SetAIFlag('NEEDFIRE', '1');
6957 SetAIFlag('NEEDSEEUP', '1');
6960 // Âûáèðàåì óãîë âíèç:
6961 if FDirection
= TDirection
.D_LEFT
then
6962 angle
:= ANGLE_LEFTDOWN
6964 angle
:= ANGLE_RIGHTDOWN
;
6966 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6967 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6969 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6970 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6971 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6972 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6973 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6974 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6975 begin // òî íóæíî ñòðåëÿòü âíèç
6976 SetAIFlag('NEEDFIRE', '1');
6977 SetAIFlag('NEEDSEEDOWN', '1');
6980 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6981 if Target
.Visible
and
6982 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6983 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6985 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6986 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
6987 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6988 begin // òî íóæíî ñòðåëÿòü âïåðåä
6989 SetAIFlag('NEEDFIRE', '1');
6990 SetAIFlag('NEEDSEEDOWN', '');
6991 SetAIFlag('NEEDSEEUP', '');
6993 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6994 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6995 if GetRnd(FDifficult
.CloseJump
) then
6996 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6997 if Abs(FObj
.X
-Target
.X
) < 128 then
7001 if Random(a
) = 0 then
7002 SetAIFlag('NEEDJUMP', '1');
7006 // Åñëè öåëü âñå åùå åñòü:
7007 if Target
.UID
<> 0 then
7008 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
7009 Target
.UID
:= 0 // òî çàáûòü öåëü
7010 else // Åñëè âèäåëè íåäàâíî
7011 begin // íî öåëü óáèëè
7012 if Target
.IsPlayer
then
7013 begin // Öåëü - èãðîê
7014 pla
:= g_Player_Get(Target
.UID
);
7015 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
7016 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
7017 Target
.UID
:= 0; // òî çàáûòü öåëü
7020 begin // Öåëü - ìîíñòð
7021 mon
:= g_Monsters_ByUID(Target
.UID
);
7022 if (mon
= nil) or (not mon
.alive
) then
7023 Target
.UID
:= 0; // òî çàáûòü öåëü
7026 end; // if Target.UID <> 0
7028 FTargetUID
:= Target
.UID
;
7030 // Åñëè âîçìîæíûõ öåëåé íåò:
7031 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
7032 if targets
= nil then
7033 if GetAIFlag('ATTACKLEFT') <> '' then
7034 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
7035 RemoveAIFlag('ATTACKLEFT');
7037 SetAIFlag('NEEDJUMP', '1');
7039 if RunDirection() = TDirection
.D_RIGHT
then
7040 begin // Èäåì íå â òó ñòîðîíó
7041 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7042 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
7043 SetAIFlag('NEEDFIRE', '1');
7044 SetAIFlag('GOLEFT', '1');
7048 begin // Èäåì â íóæíóþ ñòîðîíó
7049 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7050 SetAIFlag('NEEDFIRE', '1');
7051 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7052 SetAIFlag('GORIGHT', '1');
7056 if GetAIFlag('ATTACKRIGHT') <> '' then
7057 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
7058 RemoveAIFlag('ATTACKRIGHT');
7060 SetAIFlag('NEEDJUMP', '1');
7062 if RunDirection() = TDirection
.D_LEFT
then
7063 begin // Èäåì íå â òó ñòîðîíó
7064 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7065 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
7066 SetAIFlag('NEEDFIRE', '1');
7067 SetAIFlag('GORIGHT', '1');
7072 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7073 SetAIFlag('NEEDFIRE', '1');
7074 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7075 SetAIFlag('GOLEFT', '1');
7079 //HACK! (does it belongs there?)
7080 RealizeCurrentWeapon();
7082 // Åñëè åñòü âîçìîæíûå öåëè:
7083 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7084 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7085 for a
:= 0 to High(targets
) do
7087 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7088 if GetRnd(FDifficult
.DiagFire
) then
7090 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7091 if FDirection
= TDirection
.D_LEFT
then
7092 angle
:= ANGLE_LEFTUP
7094 angle
:= ANGLE_RIGHTUP
;
7096 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7097 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7099 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7100 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7101 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7102 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7103 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7105 SetAIFlag('NEEDFIRE', '1');
7106 SetAIFlag('NEEDSEEUP', '1');
7109 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7110 if FDirection
= TDirection
.D_LEFT
then
7111 angle
:= ANGLE_LEFTDOWN
7113 angle
:= ANGLE_RIGHTDOWN
;
7115 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7116 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7118 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7119 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7120 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7121 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7122 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7124 SetAIFlag('NEEDFIRE', '1');
7125 SetAIFlag('NEEDSEEDOWN', '1');
7129 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7130 if targets
[a
].Line
and targets
[a
].Visible
and
7131 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
7132 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
7134 SetAIFlag('NEEDFIRE', '1');
7139 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7140 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
7141 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
7142 40+GetInterval(FDifficult
.Cover
, 40)) then
7143 SetAIFlag('NEEDJUMP', '1');
7145 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7146 ammo
:= GetAmmoByWeapon(FCurrWeap
);
7147 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
7148 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
7150 SetAIFlag('SELECTWEAPON', '1');
7152 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7153 if GetAIFlag('SELECTWEAPON') = '1' then
7156 RemoveAIFlag('SELECTWEAPON');
7160 procedure TBot
.Update();
7173 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7174 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7176 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7178 if g_debug_BotAIOff
= 3 then
7188 RealizeCurrentWeapon();
7195 procedure TBot
.ReleaseKey(Key
: Byte);
7204 function TBot
.KeyPressed(Key
: Word): Boolean;
7206 Result
:= FKeys
[Key
].Pressed
;
7209 function TBot
.GetAIFlag(aName
: String20
): String20
;
7215 aName
:= LowerCase(aName
);
7217 if FAIFlags
<> nil then
7218 for a
:= 0 to High(FAIFlags
) do
7219 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7221 Result
:= FAIFlags
[a
].Value
;
7226 procedure TBot
.RemoveAIFlag(aName
: String20
);
7230 if FAIFlags
= nil then Exit
;
7232 aName
:= LowerCase(aName
);
7234 for a
:= 0 to High(FAIFlags
) do
7235 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7237 if a
<> High(FAIFlags
) then
7238 for b
:= a
to High(FAIFlags
)-1 do
7239 FAIFlags
[b
] := FAIFlags
[b
+1];
7241 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7246 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7254 aName
:= LowerCase(aName
);
7256 if FAIFlags
<> nil then
7257 for a
:= 0 to High(FAIFlags
) do
7258 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7264 if ok
then FAIFlags
[a
].Value
:= fValue
7267 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7268 with FAIFlags
[High(FAIFlags
)] do
7276 procedure TBot
.UpdateMove
;
7278 procedure GoLeft(Time
: Word = 1);
7280 ReleaseKey(KEY_LEFT
);
7281 ReleaseKey(KEY_RIGHT
);
7282 PressKey(KEY_LEFT
, Time
);
7283 SetDirection(TDirection
.D_LEFT
);
7286 procedure GoRight(Time
: Word = 1);
7288 ReleaseKey(KEY_LEFT
);
7289 ReleaseKey(KEY_RIGHT
);
7290 PressKey(KEY_RIGHT
, Time
);
7291 SetDirection(TDirection
.D_RIGHT
);
7294 function Rnd(a
: Word): Boolean;
7296 Result
:= Random(a
) = 0;
7299 procedure Turn(Time
: Word = 1200);
7301 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7306 ReleaseKey(KEY_LEFT
);
7307 ReleaseKey(KEY_RIGHT
);
7310 function CanRunLeft(): Boolean;
7312 Result
:= not CollideLevel(-1, 0);
7315 function CanRunRight(): Boolean;
7317 Result
:= not CollideLevel(1, 0);
7320 function CanRun(): Boolean;
7322 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7325 procedure Jump(Time
: Word = 30);
7327 PressKey(KEY_JUMP
, Time
);
7330 function NearHole(): Boolean;
7334 { TODO 5 : Ëåñòíèöû }
7335 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7336 for x
:= 1 to PLAYER_RECT
.Width
do
7337 if (not StayOnStep(x
*sx
, 0)) and
7338 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7339 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7348 function BorderHole(): Boolean;
7352 { TODO 5 : Ëåñòíèöû }
7353 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7354 for x
:= 1 to PLAYER_RECT
.Width
do
7355 if (not StayOnStep(x
*sx
, 0)) and
7356 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7357 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7359 for xx
:= x
to x
+32 do
7360 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7370 function NearDeepHole(): Boolean;
7376 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7379 for x
:= 1 to PLAYER_RECT
.Width
do
7380 if (not StayOnStep(x
*sx
, 0)) and
7381 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7382 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7384 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7386 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7391 end else Result
:= False;
7394 function OverDeepHole(): Boolean;
7401 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7403 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7410 function OnGround(): Boolean;
7412 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7415 function OnLadder(): Boolean;
7417 Result
:= FullInStep(0, 0);
7420 function BelowLadder(): Boolean;
7422 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7423 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7424 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7425 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7428 function BelowLiftUp(): Boolean;
7430 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7431 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7432 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7433 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7436 function OnTopLift(): Boolean;
7438 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7441 function CanJumpOver(): Boolean;
7445 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7449 if not CollideLevel(sx
, 0) then Exit
;
7451 for y
:= 1 to BOT_MAXJUMP
do
7452 if CollideLevel(0, -y
) then Exit
else
7453 if not CollideLevel(sx
, -y
) then
7460 function CanJumpUp(Dist
: ShortInt): Boolean;
7467 if CollideLevel(Dist
, 0) then Exit
;
7470 for y
:= 0 to BOT_MAXJUMP
do
7471 if CollideLevel(Dist
, -y
) then
7480 for yy
:= y
+1 to BOT_MAXJUMP
do
7481 if not CollideLevel(Dist
, -yy
) then
7490 for y
:= 0 to BOT_MAXJUMP
do
7491 if CollideLevel(0, -y
) then
7499 if y
< yy
then Exit
;
7504 function IsSafeTrigger(): Boolean;
7509 if gTriggers
= nil then
7511 for a
:= 0 to High(gTriggers
) do
7512 if Collide(gTriggers
[a
].X
,
7515 gTriggers
[a
].Height
) and
7516 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7517 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7518 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7519 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7520 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7525 // Âîçìîæíî, íàæèìàåì êíîïêó:
7526 if Rnd(16) and IsSafeTrigger() then
7529 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7530 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7532 ReleaseKey(KEY_LEFT
);
7533 ReleaseKey(KEY_RIGHT
);
7537 // Èäåì âëåâî, åñëè íàäî áûëî:
7538 if GetAIFlag('GOLEFT') <> '' then
7540 RemoveAIFlag('GOLEFT');
7541 if CanRunLeft() then
7545 // Èäåì âïðàâî, åñëè íàäî áûëî:
7546 if GetAIFlag('GORIGHT') <> '' then
7548 RemoveAIFlag('GORIGHT');
7549 if CanRunRight() then
7553 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7554 if FObj
.X
< -32 then
7557 if FObj
.X
+32 > gMapInfo
.Width
then
7560 // Ïðûãàåì, åñëè íàäî áûëî:
7561 if GetAIFlag('NEEDJUMP') <> '' then
7564 RemoveAIFlag('NEEDJUMP');
7567 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7568 if GetAIFlag('NEEDSEEUP') <> '' then
7571 ReleaseKey(KEY_DOWN
);
7572 PressKey(KEY_UP
, 20);
7573 RemoveAIFlag('NEEDSEEUP');
7576 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7577 if GetAIFlag('NEEDSEEDOWN') <> '' then
7580 ReleaseKey(KEY_DOWN
);
7581 PressKey(KEY_DOWN
, 20);
7582 RemoveAIFlag('NEEDSEEDOWN');
7585 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7586 if GetAIFlag('GOINHOLE') <> '' then
7587 if not OnGround() then
7589 ReleaseKey(KEY_LEFT
);
7590 ReleaseKey(KEY_RIGHT
);
7591 RemoveAIFlag('GOINHOLE');
7592 SetAIFlag('FALLINHOLE', '1');
7595 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7596 if GetAIFlag('FALLINHOLE') <> '' then
7598 RemoveAIFlag('FALLINHOLE');
7600 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7601 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7602 if GetAIFlag('FALLINHOLE') = '' then
7603 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7609 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7611 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7615 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7616 if OnGround() and NearHole() then
7617 if NearDeepHole() then // Åñëè ýòî áåçäíà
7619 0..3: Turn(); // Áåæèì îáðàòíî
7620 4: Jump(); // Ïðûãàåì
7621 5: begin // Ïðûãàåì îáðàòíî
7626 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7627 if GetAIFlag('GOINHOLE') = '' then
7629 0: Turn(); // Íå íóæíî òóäà
7630 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7631 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7632 if BorderHole() then
7633 SetAIFlag('GOINHOLE', '1');
7636 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7637 if (not CanRun()) and OnGround() then
7639 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7640 if CanJumpOver() or OnLadder() then
7642 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7643 if Random(2) = 0 then
7645 if IsSafeTrigger() then
7651 // Îñòàëîñü ìàëî âîçäóõà:
7652 if FAir
< 36 * 2 then
7655 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7656 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7657 if BodyInAcid(0, 0) then
7661 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7663 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7664 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7667 {function TBot.NeedItem(Item: Byte): Byte;
7672 procedure TBot
.SelectWeapon(Dist
: Integer);
7676 function HaveAmmo(weapon
: Byte): Boolean;
7679 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7680 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7681 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7682 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7683 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7684 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7685 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7686 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7687 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7688 else Result
:= True;
7693 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7695 if Dist
> BOT_LONGDIST
then
7696 begin // Äàëüíèé áîé
7698 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7700 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7704 else //if Dist > BOT_UNSAFEDIST then
7705 begin // Áëèæíèé áîé
7707 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7709 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7716 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7718 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7724 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7726 Result
:= inherited PickItem(ItemType
, force
, remove
);
7728 if Result
then SetAIFlag('SELECTWEAPON', '1');
7731 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7733 Result
:= inherited Heal(value
, Soft
);
7736 function TBot
.Healthy(): Byte;
7738 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7739 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7740 else if (FHealth
> 50) then Result
:= 2
7741 else if (FHealth
> 20) then Result
:= 1
7745 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7747 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7748 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7751 procedure TBot
.OnDamage(Angle
: SmallInt);
7759 if (Angle
= 0) or (Angle
= 180) then
7762 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7763 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7765 pla
:= g_Player_Get(FLastSpawnerUID
);
7766 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7767 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7770 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7771 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7773 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7774 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7775 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7780 SetAIFlag('ATTACKLEFT', '1')
7782 SetAIFlag('ATTACKRIGHT', '1');
7786 function TBot
.RunDirection(): TDirection
;
7788 if Abs(Vel
.X
) >= 1 then
7790 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7792 Result
:= FDirection
;
7795 function TBot
.GetRnd(a
: Byte): Boolean;
7797 if a
= 0 then Result
:= False
7798 else if a
= 255 then Result
:= True
7799 else Result
:= Random(256) > 255-a
;
7802 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7804 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7808 procedure TDifficult
.save (st
: TStream
);
7810 utils
.writeInt(st
, Byte(DiagFire
));
7811 utils
.writeInt(st
, Byte(InvisFire
));
7812 utils
.writeInt(st
, Byte(DiagPrecision
));
7813 utils
.writeInt(st
, Byte(FlyPrecision
));
7814 utils
.writeInt(st
, Byte(Cover
));
7815 utils
.writeInt(st
, Byte(CloseJump
));
7816 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7817 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7820 procedure TDifficult
.load (st
: TStream
);
7822 DiagFire
:= utils
.readByte(st
);
7823 InvisFire
:= utils
.readByte(st
);
7824 DiagPrecision
:= utils
.readByte(st
);
7825 FlyPrecision
:= utils
.readByte(st
);
7826 Cover
:= utils
.readByte(st
);
7827 CloseJump
:= utils
.readByte(st
);
7828 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7829 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7833 procedure TBot
.SaveState (st
: TStream
);
7838 inherited SaveState(st
);
7839 utils
.writeSign(st
, 'BOT0');
7841 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7843 utils
.writeInt(st
, Word(FTargetUID
));
7844 // Âðåìÿ ïîòåðè öåëè
7845 utils
.writeInt(st
, LongWord(FLastVisible
));
7846 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7847 dw
:= Length(FAIFlags
);
7848 utils
.writeInt(st
, LongInt(dw
));
7850 for i
:= 0 to dw
-1 do
7852 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7853 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7855 // Íàñòðîéêè ñëîæíîñòè
7856 FDifficult
.save(st
);
7860 procedure TBot
.LoadState (st
: TStream
);
7865 inherited LoadState(st
);
7866 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7868 FSelectedWeapon
:= utils
.readByte(st
);
7870 FTargetUID
:= utils
.readWord(st
);
7871 // Âðåìÿ ïîòåðè öåëè
7872 FLastVisible
:= utils
.readLongWord(st
);
7873 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7874 dw
:= utils
.readLongInt(st
);
7875 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7876 SetLength(FAIFlags
, dw
);
7878 for i
:= 0 to dw
-1 do
7880 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7881 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7883 // Íàñòðîéêè ñëîæíîñòè
7884 FDifficult
.load(st
);
7889 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);