1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
24 {$IFDEF USE_MEMPOOL}mempool
,{$ENDIF}
25 e_graphics
, g_playermodel
, g_basic
, g_textures
,
26 g_weapons
, g_phys
, g_sound
, g_saveload
, MAPDEF
,
59 AmmoLimits
: Array [0..1] of Array [A_BULLETS
..A_HIGH
] of Word =
60 ((200, 50, 50, 300, 100),
61 (400, 100, 100, 600, 200));
82 ANGLE_NONE
= Low(SmallInt);
84 CORPSE_STATE_REMOVEME
= 0;
85 CORPSE_STATE_NORMAL
= 1;
86 CORPSE_STATE_MESS
= 2;
88 PLAYER_RECT
: TRectWH
= (X
:15; Y
:12; Width
:34; Height
:52);
89 PLAYER_RECT_CX
= 15+(34 div 2);
90 PLAYER_RECT_CY
= 12+(52 div 2);
91 PLAYER_CORPSERECT
: TRectWH
= (X
:15; Y
:48; Width
:34; Height
:16);
94 PLAYER_HP_LIMIT
= 200;
96 PLAYER_AP_LIMIT
= 200;
99 PLAYER1_DEF_COLOR
: TRGB
= (R
:64; G
:175; B
:48);
100 PLAYER2_DEF_COLOR
: TRGB
= (R
:96; G
:96; B
:96);
116 TPlayerStatArray
= Array of TPlayerStat
;
118 TPlayerSavedState
= record
126 Ammo
: Array [A_BULLETS
..A_HIGH
] of Word;
127 MaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
128 Weapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
129 Rulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
138 TPlayer
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
146 FDirection
: TDirection
;
154 FMonsterKills
: Integer;
160 FCanJetpack
: Boolean;
166 FNextWeapDelay
: Byte; // frames
167 FBFGFireCounter
: SmallInt;
168 FLastSpawnerUID
: Word;
172 FSpectatePlayer
: Integer;
173 FFirePainTime
: Integer;
176 FSavedState
: TPlayerSavedState
;
178 FModel
: TPlayerModel
;
179 FPunchAnim
: TAnimation
;
182 FActionForce
: Boolean;
183 FActionChanged
: Boolean;
185 FFireAngle
: SmallInt;
187 FShellTimer
: Integer;
189 FSawSound
: TPlayableSound
;
190 FSawSoundIdle
: TPlayableSound
;
191 FSawSoundHit
: TPlayableSound
;
192 FSawSoundSelect
: TPlayableSound
;
193 FJetSoundOn
: TPlayableSound
;
194 FJetSoundOff
: TPlayableSound
;
195 FJetSoundFly
: TPlayableSound
;
199 FJustTeleported
: Boolean;
201 mEDamageType
: Integer;
204 function CollideLevel(XInc
, YInc
: Integer): Boolean;
205 function StayOnStep(XInc
, YInc
: Integer): Boolean;
206 function HeadInLiquid(XInc
, YInc
: Integer): Boolean;
207 function BodyInLiquid(XInc
, YInc
: Integer): Boolean;
208 function BodyInAcid(XInc
, YInc
: Integer): Boolean;
209 function FullInLift(XInc
, YInc
: Integer): Integer;
210 {procedure CollideItem();}
211 procedure FlySmoke(Times
: DWORD
= 1);
212 procedure OnFireFlame(Times
: DWORD
= 1);
213 function GetAmmoByWeapon(Weapon
: Byte): Word;
214 procedure SetAction(Action
: Byte; Force
: Boolean = False);
215 procedure OnDamage(Angle
: SmallInt); virtual;
216 function firediry(): Integer;
219 procedure Run(Direction
: TDirection
);
220 procedure NextWeapon();
221 procedure PrevWeapon();
228 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
229 procedure resetWeaponQueue ();
230 function hasAmmoForWeapon (weapon
: Byte): Boolean;
232 procedure doDamage (v
: Integer);
235 FDamageBuffer
: Integer;
237 FAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
238 FMaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
239 FWeapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
240 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
242 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
243 FReloading
: Array [WP_FIRST
..WP_LAST
] of Word;
244 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
245 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
247 FPreferredTeam
: Byte;
250 FWantsInGame
: Boolean;
254 FActualModelName
: string;
261 // debug: viewport offset
262 viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer;
264 function isValidViewPort (): Boolean; inline;
266 constructor Create(); virtual;
267 destructor Destroy(); override;
268 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
269 function GetRespawnPoint(): Byte;
270 procedure PressKey(Key
: Byte; Time
: Word = 1);
271 procedure ReleaseKeys();
272 procedure SetModel(ModelName
: String);
273 procedure SetColor(Color
: TRGB
);
274 procedure SetWeapon(W
: Byte);
275 function IsKeyPressed(K
: Byte): Boolean;
276 function GetKeys(): Byte;
277 function PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean; virtual;
278 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
279 function Collide(Panel
: TPanel
): Boolean; overload
;
280 function Collide(X
, Y
: Integer): Boolean; overload
;
281 procedure SetDirection(Direction
: TDirection
);
282 procedure GetSecret();
283 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
285 procedure Push(vx
, vy
: Integer);
286 procedure ChangeModel(ModelName
: String);
287 procedure SwitchTeam
;
288 procedure ChangeTeam(Team
: Byte);
290 function GetFlag(Flag
: Byte): Boolean;
291 procedure SetFlag(Flag
: Byte);
292 function DropFlag(): Boolean;
293 procedure AllRulez(Health
: Boolean);
294 procedure RestoreHealthArmor();
295 procedure FragCombo();
296 procedure GiveItem(ItemType
: Byte);
297 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
298 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
299 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
300 procedure MakeBloodSimple(Count
: Word);
301 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
302 procedure Reset(Force
: Boolean);
303 procedure Spectate(NoMove
: Boolean = False);
304 procedure SwitchNoClip
;
305 procedure SoftReset();
306 procedure Draw(); virtual;
307 procedure DrawPain();
308 procedure DrawPickup();
309 procedure DrawRulez();
311 procedure DrawBubble();
313 procedure Update(); virtual;
314 procedure RememberState();
315 procedure RecallState();
316 procedure SaveState (st
: TStream
); virtual;
317 procedure LoadState (st
: TStream
); virtual;
318 procedure PauseSounds(Enable
: Boolean);
319 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
320 procedure DoLerp(Level
: Integer = 2);
321 procedure SetLerp(XTo
, YTo
: Integer);
322 procedure QueueWeaponSwitch(Weapon
: Byte);
323 procedure RealizeCurrentWeapon();
325 procedure JetpackOff
;
326 procedure CatchFire(Attacker
: Word);
328 //WARNING! this does nothing for now, but still call it!
329 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
331 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
332 procedure moveBy (dx
, dy
: Integer); inline;
335 property Vel
: TPoint2i read FObj
.Vel
;
336 property Obj
: TObj read FObj
;
338 property Name
: String read FName write FName
;
339 property Model
: TPlayerModel read FModel
;
340 property Health
: Integer read FHealth write FHealth
;
341 property Lives
: Byte read FLives write FLives
;
342 property Armor
: Integer read FArmor write FArmor
;
343 property Air
: Integer read FAir write FAir
;
344 property JetFuel
: Integer read FJetFuel write FJetFuel
;
345 property Frags
: Integer read FFrags write FFrags
;
346 property Death
: Integer read FDeath write FDeath
;
347 property Kills
: Integer read FKills write FKills
;
348 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
349 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
350 property Secrets
: Integer read FSecrets
;
351 property GodMode
: Boolean read FGodMode write FGodMode
;
352 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
353 property NoReload
: Boolean read FNoReload write FNoReload
;
354 property alive
: Boolean read FAlive write FAlive
;
355 property Flag
: Byte read FFlag
;
356 property Team
: Byte read FTeam write FTeam
;
357 property Direction
: TDirection read FDirection
;
358 property GameX
: Integer read FObj
.X write FObj
.X
;
359 property GameY
: Integer read FObj
.Y write FObj
.Y
;
360 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
361 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
362 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
363 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
364 property IncCam
: Integer read FIncCam write FIncCam
;
365 property UID
: Word read FUID write FUID
;
366 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
367 property NetTime
: LongWord read FNetTime write FNetTime
;
370 property eName
: String read FName write FName
;
371 property eHealth
: Integer read FHealth write FHealth
;
372 property eLives
: Byte read FLives write FLives
;
373 property eArmor
: Integer read FArmor write FArmor
;
374 property eAir
: Integer read FAir write FAir
;
375 property eJetFuel
: Integer read FJetFuel write FJetFuel
;
376 property eFrags
: Integer read FFrags write FFrags
;
377 property eDeath
: Integer read FDeath write FDeath
;
378 property eKills
: Integer read FKills write FKills
;
379 property eCurrWeap
: Byte read FCurrWeap write FCurrWeap
;
380 property eMonsterKills
: Integer read FMonsterKills write FMonsterKills
;
381 property eSecrets
: Integer read FSecrets write FSecrets
;
382 property eGodMode
: Boolean read FGodMode write FGodMode
;
383 property eNoTarget
: Boolean read FNoTarget write FNoTarget
;
384 property eNoReload
: Boolean read FNoReload write FNoReload
;
385 property eAlive
: Boolean read FAlive write FAlive
;
386 property eFlag
: Byte read FFlag
;
387 property eTeam
: Byte read FTeam write FTeam
;
388 property eDirection
: TDirection read FDirection
;
389 property eGameX
: Integer read FObj
.X write FObj
.X
;
390 property eGameY
: Integer read FObj
.Y write FObj
.Y
;
391 property eGameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
392 property eGameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
393 property eGameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
394 property eGameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
395 property eIncCam
: Integer read FIncCam write FIncCam
;
396 property eUID
: Word read FUID
;
397 property eJustTeleported
: Boolean read FJustTeleported
;
398 property eNetTime
: LongWord read FNetTime
;
400 // set this before assigning something to `eDamage`
401 property eDamageType
: Integer read mEDamageType write mEDamageType
;
402 property eDamage
: Integer write doDamage
;
413 WeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
414 CloseWeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
415 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
418 procedure save (st
: TStream
);
419 procedure load (st
: TStream
);
427 TBot
= class(TPlayer
)
429 FSelectedWeapon
: Byte;
432 FAIFlags
: Array of TAIFlag
;
433 FDifficult
: TDifficult
;
435 function GetRnd(a
: Byte): Boolean;
436 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
437 function RunDirection(): TDirection
;
438 function FullInStep(XInc
, YInc
: Integer): Boolean;
439 //function NeedItem(Item: Byte): Byte;
440 procedure SelectWeapon(Dist
: Integer);
441 procedure SetAIFlag(aName
, fValue
: String20
);
442 function GetAIFlag(aName
: String20
): String20
;
443 procedure RemoveAIFlag(aName
: String20
);
444 function Healthy(): Byte;
445 procedure UpdateMove();
446 procedure UpdateCombat();
447 function KeyPressed(Key
: Word): Boolean;
448 procedure ReleaseKey(Key
: Byte);
449 function TargetOnScreen(TX
, TY
: Integer): Boolean;
450 procedure OnDamage(Angle
: SmallInt); override;
453 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
454 constructor Create(); override;
455 destructor Destroy(); override;
456 procedure Draw(); override;
457 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
458 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
459 procedure Update(); override;
460 procedure SaveState (st
: TStream
); override;
461 procedure LoadState (st
: TStream
); override;
473 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
474 procedure moveBy (dx
, dy
: Integer); inline;
476 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
490 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
491 procedure moveBy (dx
, dy
: Integer); inline;
493 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
496 TCorpse
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
504 FAnimation
: TAnimation
;
505 FAnimationMask
: TAnimation
;
508 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
509 destructor Destroy(); override;
510 procedure Damage(Value
: Word; vx
, vy
: Integer);
513 procedure SaveState (st
: TStream
);
514 procedure LoadState (st
: TStream
);
516 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
517 procedure moveBy (dx
, dy
: Integer); inline;
519 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
521 function ObjPtr (): PObj
; inline;
523 property Obj
: TObj read FObj
; // copies object
524 property State
: Byte read FState
;
525 property Mess
: Boolean read FMess
;
528 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
534 gPlayers
: Array of TPlayer
;
535 gCorpses
: Array of TCorpse
;
536 gGibs
: Array of TGib
;
537 gShells
: Array of TShell
;
538 gTeamStat
: TTeamStat
;
539 gFly
: Boolean = False;
540 gAimLine
: Boolean = False;
541 gChatBubble
: Byte = 0;
545 MAX_RUNVEL
: Integer = 8;
546 VEL_JUMP
: Integer = 10;
547 SHELL_TIMEOUT
: Cardinal = 60000;
549 function Lerp(X
, Y
, Factor
: Integer): Integer;
551 procedure g_Gibs_SetMax(Count
: Word);
552 function g_Gibs_GetMax(): Word;
553 procedure g_Corpses_SetMax(Count
: Word);
554 function g_Corpses_GetMax(): Word;
555 procedure g_Shells_SetMax(Count
: Word);
556 function g_Shells_GetMax(): Word;
558 procedure g_Player_Init();
559 procedure g_Player_Free();
560 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
561 function g_Player_CreateFromState (st
: TStream
): Word;
562 procedure g_Player_Remove(UID
: Word);
563 procedure g_Player_ResetTeams();
564 procedure g_Player_UpdateAll();
565 procedure g_Player_DrawAll();
566 procedure g_Player_DrawDebug(p
: TPlayer
);
567 procedure g_Player_DrawHealth();
568 procedure g_Player_RememberAll();
569 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
570 function g_Player_Get(UID
: Word): TPlayer
;
571 function g_Player_GetCount(): Byte;
572 function g_Player_GetStats(): TPlayerStatArray
;
573 function g_Player_ValidName(Name
: String): Boolean;
574 procedure g_Player_CreateCorpse(Player
: TPlayer
);
575 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
576 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
577 procedure g_Player_UpdatePhysicalObjects();
578 procedure g_Player_DrawCorpses();
579 procedure g_Player_DrawShells();
580 procedure g_Player_RemoveAllCorpses();
581 procedure g_Player_Corpses_SaveState (st
: TStream
);
582 procedure g_Player_Corpses_LoadState (st
: TStream
);
583 procedure g_Bot_Add(Team
, Difficult
: Byte);
584 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1);
585 procedure g_Bot_MixNames();
586 procedure g_Bot_RemoveAll();
591 {$INCLUDE ../nogl/noGLuses.inc}
592 {$IFDEF ENABLE_HOLMES}
595 e_log
, g_map
, g_items
, g_console
, g_gfx
, Math
,
596 g_options
, g_triggers
, g_menu
, g_game
, g_grid
,
597 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
,
598 g_net
, g_netmsg
, g_window
,
601 const PLR_SAVE_VERSION
= 0;
611 diag_precision
: Byte;
615 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
616 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
617 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
621 TIME_RESPAWN1
= 1500;
622 TIME_RESPAWN2
= 2000;
623 TIME_RESPAWN3
= 3000;
626 JET_MAX
= 540; // ~30 sec
627 PLAYER_SUIT_TIME
= 30000;
628 PLAYER_INVUL_TIME
= 30000;
629 PLAYER_INVIS_TIME
= 35000;
630 FRAG_COMBO_TIME
= 3000;
634 ANGLE_RIGHTDOWN
= -35;
636 ANGLE_LEFTDOWN
= -145;
637 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
638 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
641 BOT_UNSAFEDIST
= 128;
642 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
644 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
645 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
646 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
647 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
648 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
649 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
650 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
651 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
652 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
653 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
654 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
655 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
656 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
657 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
658 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
659 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
660 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
661 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
662 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
663 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
664 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
665 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
666 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
667 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
668 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
669 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
671 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
672 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
674 BOTNAMES_FILENAME
= 'botnames.txt';
675 BOTLIST_FILENAME
= 'botlist.txt';
679 MaxCorpses
: Word = 20;
680 MaxShells
: Word = 300;
681 CurrentGib
: Integer = 0;
682 CurrentShell
: Integer = 0;
683 BotNames
: Array of String;
684 BotList
: Array of TBotProfile
;
687 function Lerp(X
, Y
, Factor
: Integer): Integer;
689 Result
:= X
+ ((Y
- X
) div Factor
);
692 function SameTeam(UID1
, UID2
: Word): Boolean;
696 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
697 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
699 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
701 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
702 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
704 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
707 procedure g_Gibs_SetMax(Count
: Word);
710 SetLength(gGibs
, Count
);
712 if CurrentGib
>= Count
then
716 function g_Gibs_GetMax(): Word;
721 procedure g_Shells_SetMax(Count
: Word);
724 SetLength(gShells
, Count
);
726 if CurrentShell
>= Count
then
730 function g_Shells_GetMax(): Word;
736 procedure g_Corpses_SetMax(Count
: Word);
739 SetLength(gCorpses
, Count
);
742 function g_Corpses_GetMax(): Word;
744 Result
:= MaxCorpses
;
747 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
757 // Åñòü ëè ìåñòî â gPlayers:
758 if gPlayers
<> nil then
759 for a
:= 0 to High(gPlayers
) do
760 if gPlayers
[a
] = nil then
766 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
769 SetLength(gPlayers
, Length(gPlayers
)+1);
773 // Ñîçäàåì îáúåêò èãðîêà:
775 gPlayers
[a
] := TBot
.Create()
777 gPlayers
[a
] := TPlayer
.Create();
780 gPlayers
[a
].FActualModelName
:= ModelName
;
781 gPlayers
[a
].SetModel(ModelName
);
783 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
784 if gPlayers
[a
].FModel
= nil then
788 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
792 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
793 if Random(2) = 0 then
797 gPlayers
[a
].FPreferredTeam
:= Team
;
799 case gGameSettings
.GameMode
of
800 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
802 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
804 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
807 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
808 gPlayers
[a
].FColor
:= Color
;
809 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
810 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
812 gPlayers
[a
].FModel
.Color
:= Color
;
814 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
815 gPlayers
[a
].FAlive
:= False;
817 Result
:= gPlayers
[a
].FUID
;
820 function g_Player_CreateFromState (st
: TStream
): Word;
827 if (st
= nil) then exit
; //???
830 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
831 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
834 Bot
:= utils
.readBool(st
);
839 // Åñòü ëè ìåñòî â gPlayers:
840 for a
:= 0 to High(gPlayers
) do if (gPlayers
[a
] = nil) then begin ok
:= true; break
; end;
842 // Íåò ìåñòà - ðàñøèðÿåì gPlayers
845 SetLength(gPlayers
, Length(gPlayers
)+1);
849 // Ñîçäàåì îáúåêò èãðîêà
851 gPlayers
[a
] := TBot
.Create()
853 gPlayers
[a
] := TPlayer
.Create();
854 gPlayers
[a
].FIamBot
:= Bot
;
855 gPlayers
[a
].FPhysics
:= True;
858 gPlayers
[a
].FUID
:= utils
.readWord(st
);
860 gPlayers
[a
].FName
:= utils
.readStr(st
);
862 gPlayers
[a
].FTeam
:= utils
.readByte(st
);
863 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
865 gPlayers
[a
].FAlive
:= utils
.readBool(st
);
866 // Èçðàñõîäîâàë ëè âñå æèçíè
867 gPlayers
[a
].FNoRespawn
:= utils
.readBool(st
);
869 b
:= utils
.readByte(st
);
870 if b
= 1 then gPlayers
[a
].FDirection
:= TDirection
.D_LEFT
else gPlayers
[a
].FDirection
:= TDirection
.D_RIGHT
; // b = 2
872 gPlayers
[a
].FHealth
:= utils
.readLongInt(st
);
874 gPlayers
[a
].FLives
:= utils
.readByte(st
);
876 gPlayers
[a
].FArmor
:= utils
.readLongInt(st
);
878 gPlayers
[a
].FAir
:= utils
.readLongInt(st
);
880 gPlayers
[a
].FJetFuel
:= utils
.readLongInt(st
);
882 gPlayers
[a
].FPain
:= utils
.readLongInt(st
);
884 gPlayers
[a
].FKills
:= utils
.readLongInt(st
);
886 gPlayers
[a
].FMonsterKills
:= utils
.readLongInt(st
);
888 gPlayers
[a
].FFrags
:= utils
.readLongInt(st
);
890 gPlayers
[a
].FFragCombo
:= utils
.readByte(st
);
891 // Âðåìÿ ïîñëåäíåãî ôðàãà
892 gPlayers
[a
].FLastFrag
:= utils
.readLongWord(st
);
894 gPlayers
[a
].FDeath
:= utils
.readLongInt(st
);
896 gPlayers
[a
].FFlag
:= utils
.readByte(st
);
898 gPlayers
[a
].FSecrets
:= utils
.readLongInt(st
);
900 gPlayers
[a
].FCurrWeap
:= utils
.readByte(st
);
901 // Ñëåäóþùåå æåëàåìîå îðóæèå
902 gPlayers
[a
].FNextWeap
:= utils
.readWord(st
);
904 gPlayers
[a
].FNextWeapDelay
:= utils
.readByte(st
);
906 gPlayers
[a
].FBFGFireCounter
:= utils
.readSmallInt(st
);
908 gPlayers
[a
].FDamageBuffer
:= utils
.readLongInt(st
);
909 // Ïîñëåäíèé óäàðèâøèé
910 gPlayers
[a
].FLastSpawnerUID
:= utils
.readWord(st
);
911 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
912 gPlayers
[a
].FLastHit
:= utils
.readByte(st
);
914 Obj_LoadState(@gPlayers
[a
].FObj
, st
);
915 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
916 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FAmmo
[i
] := utils
.readWord(st
);
917 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
918 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FMaxAmmo
[i
] := utils
.readWord(st
);
920 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FWeapon
[i
] := utils
.readBool(st
);
921 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
922 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FReloading
[i
] := utils
.readWord(st
);
924 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
925 // Íàëè÷èå êðàñíîãî êëþ÷à
926 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
927 // Íàëè÷èå çåëåíîãî êëþ÷à
928 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
929 // Íàëè÷èå ñèíåãî êëþ÷à
930 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
932 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_BERSERK
);
933 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
934 for i
:= MR_SUIT
to MR_MAX
do gPlayers
[a
].FMegaRulez
[i
] := utils
.readLongWord(st
);
935 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
936 for i
:= T_RESPAWN
to T_FLAGCAP
do gPlayers
[a
].FTime
[i
] := utils
.readLongWord(st
);
939 gPlayers
[a
].FActualModelName
:= utils
.readStr(st
);
941 gPlayers
[a
].FColor
.R
:= utils
.readByte(st
);
942 gPlayers
[a
].FColor
.G
:= utils
.readByte(st
);
943 gPlayers
[a
].FColor
.B
:= utils
.readByte(st
);
944 // Îáíîâëÿåì ìîäåëü èãðîêà
945 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
947 // Íåò ìîäåëè - ñîçäàíèå íåâîçìîæíî
948 if (gPlayers
[a
].FModel
= nil) then
952 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
956 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû
957 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
958 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
960 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
962 result
:= gPlayers
[a
].FUID
;
966 procedure g_Player_ResetTeams();
970 if g_Game_IsClient
then
972 if gPlayers
= nil then
974 for a
:= Low(gPlayers
) to High(gPlayers
) do
975 if gPlayers
[a
] <> nil then
976 case gGameSettings
.GameMode
of
978 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
980 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
981 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
982 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
985 gPlayers
[a
].ChangeTeam(TEAM_RED
)
987 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
990 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
994 procedure g_Bot_Add(Team
, Difficult
: Byte);
997 _name
, _model
: String;
1000 if not g_Game_IsServer
then Exit
;
1002 // Ñïèñîê íàçâàíèé ìîäåëåé:
1003 m
:= g_PlayerModel_GetNames();
1008 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1009 Team
:= TEAM_COOP
// COOP
1011 if gGameSettings
.GameMode
= GM_DM
then
1012 Team
:= TEAM_NONE
// DM
1014 if Team
= TEAM_NONE
then // CTF / TDM
1016 // Àâòîáàëàíñ êîìàíä:
1020 for a
:= 0 to High(gPlayers
) do
1021 if gPlayers
[a
] <> nil then
1023 if gPlayers
[a
].Team
= TEAM_RED
then
1026 if gPlayers
[a
].Team
= TEAM_BLUE
then
1036 if Random(2) = 0 then
1042 // Âûáèðàåì áîòó èìÿ:
1044 if BotNames
<> nil then
1045 for a
:= 0 to High(BotNames
) do
1046 if g_Player_ValidName(BotNames
[a
]) then
1048 _name
:= BotNames
[a
];
1052 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
1055 _name
:= Format('DFBOT%.2d', [Random(100)]);
1056 until g_Player_ValidName(_name
);
1058 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1059 _model
:= m
[Random(Length(m
))];
1062 with g_Player_Get(g_Player_Create(_model
,
1063 _RGB(Min(Random(9)*32, 255),
1064 Min(Random(9)*32, 255),
1065 Min(Random(9)*32, 255)),
1066 Team
, True)) as TBot
do
1071 1: FDifficult
:= DIFFICULT_EASY
;
1072 2: FDifficult
:= DIFFICULT_MEDIUM
;
1073 else FDifficult
:= DIFFICULT_HARD
;
1076 for a
:= WP_FIRST
to WP_LAST
do
1078 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1079 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1080 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1083 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1085 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1086 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1091 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1);
1094 _name
, _model
: String;
1097 if not g_Game_IsServer
then Exit
;
1099 // Ñïèñîê íàçâàíèé ìîäåëåé:
1100 m
:= g_PlayerModel_GetNames();
1105 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1106 Team
:= TEAM_COOP
// COOP
1108 if gGameSettings
.GameMode
= GM_DM
then
1109 Team
:= TEAM_NONE
// DM
1111 if Team
= TEAM_NONE
then
1112 Team
:= BotList
[num
].team
; // CTF / TDM
1114 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1115 lName
:= AnsiLowerCase(lName
);
1116 if (num
< 0) or (num
> Length(BotList
)-1) then
1118 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1119 for a
:= 0 to High(BotList
) do
1120 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1129 _name
:= BotList
[num
].name
;
1130 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1131 if not g_Player_ValidName(_name
) then
1133 _name
:= Format('DFBOT%.2d', [Random(100)]);
1134 until g_Player_ValidName(_name
);
1137 _model
:= BotList
[num
].model
;
1138 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1139 if not InSArray(_model
, m
) then
1140 _model
:= m
[Random(Length(m
))];
1143 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1147 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1148 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1149 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1150 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1151 FDifficult
.Cover
:= BotList
[num
].cover
;
1152 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1154 for a
:= WP_FIRST
to WP_LAST
do
1156 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1157 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1158 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1161 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1163 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1167 procedure g_Bot_RemoveAll();
1171 if not g_Game_IsServer
then Exit
;
1172 if gPlayers
= nil then Exit
;
1174 for a
:= 0 to High(gPlayers
) do
1175 if gPlayers
[a
] <> nil then
1176 if gPlayers
[a
] is TBot
then
1178 gPlayers
[a
].Lives
:= 0;
1179 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1180 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1181 g_Player_Remove(gPlayers
[a
].FUID
);
1187 procedure g_Bot_MixNames();
1192 if BotNames
<> nil then
1193 for a
:= 0 to High(BotNames
) do
1195 b
:= Random(Length(BotNames
));
1197 Botnames
[a
] := BotNames
[b
];
1202 procedure g_Player_Remove(UID
: Word);
1206 if gPlayers
= nil then Exit
;
1208 if g_Game_IsServer
and g_Game_IsNet
then
1209 MH_SEND_PlayerDelete(UID
);
1211 for i
:= 0 to High(gPlayers
) do
1212 if gPlayers
[i
] <> nil then
1213 if gPlayers
[i
].FUID
= UID
then
1215 if gPlayers
[i
] is TPlayer
then
1216 TPlayer(gPlayers
[i
]).Free()
1218 TBot(gPlayers
[i
]).Free();
1224 procedure g_Player_Init();
1234 if not FileExists(DataDir
+ BOTNAMES_FILENAME
) then
1237 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1238 AssignFile(F
, DataDir
+ BOTNAMES_FILENAME
);
1249 SetLength(BotNames
, Length(BotNames
)+1);
1250 BotNames
[High(BotNames
)] := s
;
1258 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1259 config
:= TConfig
.CreateFile(DataDir
+ BOTLIST_FILENAME
);
1263 while config
.SectionExists(IntToStr(a
)) do
1265 SetLength(BotList
, Length(BotList
)+1);
1267 with BotList
[High(BotList
)] do
1270 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1272 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1274 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1279 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1280 color
.R
:= StrToIntDef(sa
[0], 0);
1281 color
.G
:= StrToIntDef(sa
[1], 0);
1282 color
.B
:= StrToIntDef(sa
[2], 0);
1283 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1284 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1285 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1286 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1287 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1288 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1289 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1290 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1291 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1292 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1293 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1294 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1295 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1296 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1297 if Length(sa
) = 10 then
1299 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1300 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1301 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1302 if Length(sa
) = 10 then
1304 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1306 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1307 if Length(sa) = 10 then
1309 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1318 procedure g_Player_Free();
1322 if gPlayers
<> nil then
1324 for i
:= 0 to High(gPlayers
) do
1325 if gPlayers
[i
] <> nil then
1327 if gPlayers
[i
] is TPlayer
then
1328 TPlayer(gPlayers
[i
]).Free()
1330 TBot(gPlayers
[i
]).Free();
1341 procedure g_Player_UpdateAll();
1345 if gPlayers
= nil then Exit
;
1347 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1348 for i
:= 0 to High(gPlayers
) do
1350 if gPlayers
[i
] <> nil then
1352 if gPlayers
[i
] is TPlayer
then
1354 gPlayers
[i
].Update();
1355 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1359 // bot updates weapons in `UpdateCombat()`
1360 TBot(gPlayers
[i
]).Update();
1364 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1367 procedure g_Player_DrawAll();
1371 if gPlayers
= nil then Exit
;
1373 for i
:= 0 to High(gPlayers
) do
1374 if gPlayers
[i
] <> nil then
1375 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1376 else TBot(gPlayers
[i
]).Draw();
1379 procedure g_Player_DrawDebug(p
: TPlayer
);
1383 if p
= nil then Exit
;
1384 if (@p
.FObj
) = nil then Exit
;
1386 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1388 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1389 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1390 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1391 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1392 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1393 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1396 procedure g_Player_DrawHealth();
1401 if gPlayers
= nil then Exit
;
1402 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1404 for i
:= 0 to High(gPlayers
) do
1405 if gPlayers
[i
] <> nil then
1407 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1408 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1409 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1410 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1411 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1412 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1416 function g_Player_Get(UID
: Word): TPlayer
;
1422 if gPlayers
= nil then
1425 for a
:= 0 to High(gPlayers
) do
1426 if gPlayers
[a
] <> nil then
1427 if gPlayers
[a
].FUID
= UID
then
1429 Result
:= gPlayers
[a
];
1434 function g_Player_GetCount(): Byte;
1440 if gPlayers
= nil then
1443 for a
:= 0 to High(gPlayers
) do
1444 if gPlayers
[a
] <> nil then
1445 Result
:= Result
+ 1;
1448 function g_Player_GetStats(): TPlayerStatArray
;
1454 if gPlayers
= nil then Exit
;
1456 for a
:= 0 to High(gPlayers
) do
1457 if gPlayers
[a
] <> nil then
1459 SetLength(Result
, Length(Result
)+1);
1460 with Result
[High(Result
)] do
1462 Ping
:= gPlayers
[a
].FPing
;
1463 Loss
:= gPlayers
[a
].FLoss
;
1464 Name
:= gPlayers
[a
].FName
;
1465 Team
:= gPlayers
[a
].FTeam
;
1466 Frags
:= gPlayers
[a
].FFrags
;
1467 Deaths
:= gPlayers
[a
].FDeath
;
1468 Kills
:= gPlayers
[a
].FKills
;
1469 Color
:= gPlayers
[a
].FModel
.Color
;
1470 Lives
:= gPlayers
[a
].FLives
;
1471 Spectator
:= gPlayers
[a
].FSpectator
;
1476 procedure g_Player_RememberAll
;
1480 for i
:= Low(gPlayers
) to High(gPlayers
) do
1481 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1482 gPlayers
[i
].RememberState
;
1485 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1489 gTeamStat
[TEAM_RED
].Goals
:= 0;
1490 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1492 if gPlayers
<> nil then
1493 for i
:= 0 to High(gPlayers
) do
1494 if gPlayers
[i
] <> nil then
1496 gPlayers
[i
].Reset(Force
);
1498 if gPlayers
[i
] is TPlayer
then
1500 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1501 gPlayers
[i
].Respawn(Silent
)
1503 gPlayers
[i
].Spectate();
1506 TBot(gPlayers
[i
]).Respawn(Silent
);
1510 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1515 if Player
.alive
then
1517 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1522 if (FHealth
>= -50) or (gGibsCount
= 0) then
1524 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1528 for find_id
:= 0 to High(gCorpses
) do
1529 if gCorpses
[find_id
] = nil then
1536 find_id
:= Random(Length(gCorpses
));
1538 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1539 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1540 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1541 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1544 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1545 FObj
.Y
+ PLAYER_RECT_CY
,
1546 FModel
.Name
, FModel
.Color
);
1550 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1554 if (gShells
= nil) or (Length(gShells
) = 0) then
1557 with gShells
[CurrentShell
] do
1563 if T
= SHELL_BULLET
then
1565 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1569 Obj
.Rect
.Width
:= 4;
1570 Obj
.Rect
.Height
:= 2;
1574 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1578 Obj
.Rect
.Width
:= 7;
1579 Obj
.Rect
.Height
:= 3;
1585 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1586 positionChanged(); // this updates spatial accelerators
1587 RAngle
:= Random(360);
1588 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1590 if CurrentShell
>= High(gShells
) then
1597 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1600 GibsArray
: TGibsArray
;
1602 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1604 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1607 for a
:= 0 to High(GibsArray
) do
1608 with gGibs
[CurrentGib
] do
1611 ID
:= GibsArray
[a
].ID
;
1612 MaskID
:= GibsArray
[a
].MaskID
;
1615 Obj
.Rect
:= GibsArray
[a
].Rect
;
1616 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1617 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1618 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1619 positionChanged(); // this updates spatial accelerators
1620 RAngle
:= Random(360);
1622 if gBloodCount
> 0 then
1623 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1624 Random(48), Random(48), 150, 0, 0);
1626 if CurrentGib
>= High(gGibs
) then
1633 procedure g_Player_UpdatePhysicalObjects();
1639 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1644 if T
= SHELL_BULLET
then
1645 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1647 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1652 if gGibs
<> nil then
1653 for i
:= 0 to High(gGibs
) do
1654 if gGibs
[i
].alive
then
1658 mr
:= g_Obj_Move(@Obj
, True, False, True);
1659 positionChanged(); // this updates spatial accelerators
1661 if WordBool(mr
and MOVE_FALLOUT
) then
1667 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1668 if WordBool(mr
and MOVE_HITWALL
) then
1669 Obj
.Vel
.X
:= -(vel
.X
div 2);
1670 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1671 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1673 if (Obj
.Vel
.X
>= 0) then
1675 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1676 if RAngle
>= 360 then
1677 RAngle
:= RAngle
mod 360;
1678 end else begin // Counter-clockwise
1679 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1681 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1684 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1685 if gTime
mod (GAME_TICK
*3) = 0 then
1686 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1690 if gCorpses
<> nil then
1691 for i
:= 0 to High(gCorpses
) do
1692 if gCorpses
[i
] <> nil then
1693 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1699 gCorpses
[i
].Update();
1702 if gShells
<> nil then
1703 for i
:= 0 to High(gShells
) do
1704 if gShells
[i
].alive
then
1708 mr
:= g_Obj_Move(@Obj
, True, False, True);
1709 positionChanged(); // this updates spatial accelerators
1711 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1717 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1718 if WordBool(mr
and MOVE_HITWALL
) then
1720 Obj
.Vel
.X
:= -(vel
.X
div 2);
1721 if not WordBool(mr
and MOVE_INWATER
) then
1722 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1724 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1726 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1727 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1728 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1730 if RAngle
mod 90 <> 0 then
1731 RAngle
:= (RAngle
div 90) * 90;
1733 else if not WordBool(mr
and MOVE_INWATER
) then
1734 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1737 if (Obj
.Vel
.X
>= 0) then
1739 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1740 if RAngle
>= 360 then
1741 RAngle
:= RAngle
mod 360;
1742 end else begin // Counter-clockwise
1743 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1745 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1751 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1753 x
:= Obj
.X
+Obj
.Rect
.X
;
1754 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1755 w
:= Obj
.Rect
.Width
;
1756 h
:= Obj
.Rect
.Height
;
1759 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1761 if (dx
<> 0) or (dy
<> 0) then
1770 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1774 w
:= Obj
.Rect
.Width
;
1775 h
:= Obj
.Rect
.Height
;
1778 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1780 if (dx
<> 0) or (dy
<> 0) then
1789 procedure TGib
.positionChanged (); inline; begin end;
1790 procedure TShell
.positionChanged (); inline; begin end;
1793 procedure g_Player_DrawCorpses();
1798 if gGibs
<> nil then
1799 for i
:= 0 to High(gGibs
) do
1800 if gGibs
[i
].alive
then
1803 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1806 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1807 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1809 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1812 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1818 if gCorpses
<> nil then
1819 for i
:= 0 to High(gCorpses
) do
1820 if gCorpses
[i
] <> nil then
1824 procedure g_Player_DrawShells();
1829 if gShells
<> nil then
1830 for i
:= 0 to High(gShells
) do
1831 if gShells
[i
].alive
then
1834 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1840 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1844 procedure g_Player_RemoveAllCorpses();
1850 SetLength(gGibs
, MaxGibs
);
1851 SetLength(gShells
, MaxGibs
);
1855 if gCorpses
<> nil then
1856 for i
:= 0 to High(gCorpses
) do
1860 SetLength(gCorpses
, MaxCorpses
);
1863 procedure g_Player_Corpses_SaveState (st
: TStream
);
1867 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ
1869 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1871 // Êîëè÷åñòâî òðóïîâ
1872 utils
.writeInt(st
, LongInt(count
));
1874 if (count
= 0) then exit
;
1877 for i
:= 0 to High(gCorpses
) do
1879 if gCorpses
[i
] <> nil then
1882 utils
.writeStr(st
, gCorpses
[i
].FModelName
);
1884 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1885 // Ñîõðàíÿåì äàííûå òðóïà:
1886 gCorpses
[i
].SaveState(st
);
1892 procedure g_Player_Corpses_LoadState (st
: TStream
);
1900 g_Player_RemoveAllCorpses();
1902 // Êîëè÷åñòâî òðóïîâ:
1903 count
:= utils
.readLongInt(st
);
1904 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1906 if (count
= 0) then exit
;
1909 for i
:= 0 to count
-1 do
1912 str
:= utils
.readStr(st
);
1914 b
:= utils
.readBool(st
);
1916 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1917 // Çàãðóæàåì äàííûå òðóïà
1918 gCorpses
[i
].LoadState(st
);
1925 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1927 procedure TPlayer
.BFGHit();
1929 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1930 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1931 if g_Game_IsServer
and g_Game_IsNet
then
1932 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1933 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1937 procedure TPlayer
.ChangeModel(ModelName
: string);
1939 locModel
: TPlayerModel
;
1941 locModel
:= g_PlayerModel_Get(ModelName
);
1942 if locModel
= nil then Exit
;
1948 procedure TPlayer
.SetModel(ModelName
: string);
1952 m
:= g_PlayerModel_Get(ModelName
);
1955 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1956 m
:= g_PlayerModel_Get('doomer');
1959 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1964 if FModel
<> nil then
1969 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1970 FModel
.Color
:= FColor
1972 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1973 FModel
.SetWeapon(FCurrWeap
);
1974 FModel
.SetFlag(FFlag
);
1975 SetDirection(FDirection
);
1978 procedure TPlayer
.SetColor(Color
: TRGB
);
1981 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1982 if FModel
<> nil then FModel
.Color
:= Color
;
1985 procedure TPlayer
.SwitchTeam
;
1987 if g_Game_IsClient
then
1989 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
1991 if gGameOn
and FAlive
then
1992 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
1994 if FTeam
= TEAM_RED
then
1996 ChangeTeam(TEAM_BLUE
);
1997 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
1998 if g_Game_IsNet
then
1999 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
2003 ChangeTeam(TEAM_RED
);
2004 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
2005 if g_Game_IsNet
then
2006 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
2008 FPreferredTeam
:= FTeam
;
2011 procedure TPlayer
.ChangeTeam(Team
: Byte);
2018 TEAM_RED
, TEAM_BLUE
:
2019 FModel
.Color
:= TEAMCOLOR
[Team
];
2021 FModel
.Color
:= FColor
;
2023 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2024 MH_SEND_PlayerStats(FUID
);
2028 procedure TPlayer.CollideItem();
2033 if gItems = nil then Exit;
2034 if not FAlive then Exit;
2036 for i := 0 to High(gItems) do
2039 if (ItemType <> ITEM_NONE) and alive then
2040 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2041 PLAYER_RECT.Height, @Obj) then
2043 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2045 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2046 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2047 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2048 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2049 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2051 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2052 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2053 (gGameSettings.GameType = GT_SINGLE) and
2054 (g_Player_GetCount() > 1)) then
2055 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2061 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2063 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2064 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2068 constructor TPlayer
.Create();
2074 mEDamageType
:= HIT_SOME
;
2080 FSawSound
:= TPlayableSound
.Create();
2081 FSawSoundIdle
:= TPlayableSound
.Create();
2082 FSawSoundHit
:= TPlayableSound
.Create();
2083 FSawSoundSelect
:= TPlayableSound
.Create();
2084 FJetSoundFly
:= TPlayableSound
.Create();
2085 FJetSoundOn
:= TPlayableSound
.Create();
2086 FJetSoundOff
:= TPlayableSound
.Create();
2088 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2089 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2090 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2091 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2092 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2093 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2094 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2096 FSpectatePlayer
:= -1;
2100 FSavedState
.WaitRecall
:= False;
2106 FActualModelName
:= 'doomer';
2109 FObj
.Rect
:= PLAYER_RECT
;
2111 FBFGFireCounter
:= -1;
2112 FJustTeleported
:= False;
2118 procedure TPlayer
.positionChanged (); inline;
2122 procedure TPlayer
.doDamage (v
: Integer);
2124 if (v
<= 0) then exit
;
2125 if (v
> 32767) then v
:= 32767;
2126 Damage(v
, 0, 0, 0, mEDamageType
);
2129 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2133 if (not g_Game_IsClient
) and (not FAlive
) then
2138 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2139 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2141 if not g_Game_IsClient
then
2144 if t
= HIT_TRAP
then
2146 // Ëîâóøêà óáèâàåò ñðàçó:
2148 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2150 if t
= HIT_SELF
then
2154 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2157 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2158 FMegaRulez
[MR_SUIT
] := 0;
2159 FMegaRulez
[MR_INVUL
] := 0;
2160 FMegaRulez
[MR_INVIS
] := 0;
2164 // Íî îò îñòàëüíîãî ñïàñàåò:
2165 if FMegaRulez
[MR_INVUL
] >= gTime
then
2172 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2173 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2174 (SpawnerUID
= FUID
) or
2175 (not SameTeam(FUID
, SpawnerUID
)) then
2177 FLastSpawnerUID
:= SpawnerUID
;
2179 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2180 if gBloodCount
> 0 then
2182 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2183 if value
div 4 <= c
then
2184 c
:= c
- (value
div 4)
2188 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2192 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2193 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2196 if t
= HIT_WATER
then
2197 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2198 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2203 Inc(FDamageBuffer
, value
);
2207 FPain
:= FPain
+ value
;
2210 if g_Game_IsServer
and g_Game_IsNet
then
2212 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2213 MH_SEND_PlayerStats(FUID
);
2214 MH_SEND_PlayerPos(False, FUID
);
2218 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2221 if g_Game_IsClient
then
2226 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2228 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2231 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2233 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2237 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2238 MH_SEND_PlayerStats(FUID
);
2241 destructor TPlayer
.Destroy();
2243 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2245 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2249 FSawSoundIdle
.Free();
2250 FSawSoundHit
.Free();
2251 FJetSoundFly
.Free();
2253 FJetSoundOff
.Free();
2255 if FPunchAnim
<> nil then
2261 procedure TPlayer
.DrawBubble();
2263 bubX
, bubY
: Integer;
2266 Rw
, Gw
, Bw
: SmallInt;
2269 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= TDirection
.D_LEFT
, -4, 18);
2270 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2278 1: // simple textual non-bubble
2280 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2281 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2282 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2285 2: // advanced pixel-perfect bubble
2287 if FTeam
= TEAM_RED
then
2290 if FTeam
= TEAM_BLUE
then
2293 3: // colored bubble
2295 Rb
:= FModel
.Color
.R
;
2296 Gb
:= FModel
.Color
.G
;
2297 Bb
:= FModel
.Color
.B
;
2298 Rw
:= Min(Rb
* 2 + 64, 255);
2299 Gw
:= Min(Gb
* 2 + 64, 255);
2300 Bw
:= Min(Bb
* 2 + 64, 255);
2301 if (Abs(Rw
- Rb
) < 32)
2302 or (Abs(Gw
- Gb
) < 32)
2303 or (Abs(Bw
- Bb
) < 32) then
2305 Rb
:= Max(Rw
div 2 - 16, 0);
2306 Gb
:= Max(Gw
div 2 - 16, 0);
2307 Bb
:= Max(Bw
div 2 - 16, 0);
2310 4: // custom textured bubble
2312 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2313 if FDirection
= TDirection
.D_RIGHT
then
2314 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2316 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, TMirrorType
.Horizontal
);
2322 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2323 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2325 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2328 Dot
:= IfThen(FDirection
= TDirection
.D_LEFT
, 14, 5);
2329 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2330 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
);
2331 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
);
2332 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
);
2333 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
);
2337 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2338 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2339 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2342 procedure TPlayer
.Draw();
2347 Mirror
: TMirrorType
;
2351 if Direction
= TDirection
.D_RIGHT
then
2352 Mirror
:= TMirrorType
.None
2354 Mirror
:= TMirrorType
.Horizontal
;
2356 if FPunchAnim
<> nil then
2358 FPunchAnim
.Draw(FObj
.X
+IfThen(Direction
= TDirection
.D_LEFT
, 15-FObj
.Rect
.X
, FObj
.Rect
.X
-15),
2359 FObj
.Y
+FObj
.Rect
.Y
-11, Mirror
);
2360 if FPunchAnim
.played
then
2367 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2368 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2370 e_GetTextureSize(ID
, @w
, @h
);
2371 if FDirection
= TDirection
.D_LEFT
then
2372 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2373 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False)
2375 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2376 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False);
2379 if FMegaRulez
[MR_INVIS
] > gTime
then
2381 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2382 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2384 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2385 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2389 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 200)
2391 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2394 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 254);
2397 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2400 if g_debug_Frames
then
2402 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2404 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2405 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2409 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2411 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2412 if gAimLine
and alive
and
2413 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2418 procedure TPlayer
.DrawAim();
2419 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2424 {$IFDEF ENABLE_HOLMES}
2425 if isValidViewPort
and (self
= gPlayer1
) then
2427 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2431 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2432 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2434 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2438 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2443 wx
, wy
, xx
, yy
: Integer;
2447 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= TDirection
.D_LEFT
, 7, -7);
2448 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2457 1: begin // Chainsaw
2464 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2465 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2466 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2467 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2472 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2473 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2474 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2475 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2477 4: begin // Double Shotgun
2480 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2481 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2482 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2483 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2485 5: begin // Chaingun
2488 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2489 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2490 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2491 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2493 6: begin // Rocket Launcher
2496 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2497 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2498 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2499 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2501 7: begin // Plasmagun
2504 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2505 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2506 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2507 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2512 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2513 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2514 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2515 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2517 9: begin // Super Chaingun
2520 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2521 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2522 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2523 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2526 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2527 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2528 {$IF DEFINED(D2F_DEBUG)}
2529 drawCast(sz
, wx
, wy
, xx
, yy
);
2531 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2535 procedure TPlayer
.DrawGUI();
2538 X
, Y
, SY
, a
, p
, m
: Integer;
2542 stat
: TPlayerStatArray
;
2544 X
:= gPlayerScreenSize
.X
;
2545 SY
:= gPlayerScreenSize
.Y
;
2548 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2550 if gGameSettings
.GameMode
= GM_CTF
then
2554 if gGameSettings
.GameMode
= GM_CTF
then
2556 s
:= 'TEXTURE_PLAYER_REDFLAG';
2557 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2558 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2559 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2560 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2561 if g_Texture_Get(s
, ID
) then
2562 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2565 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2566 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2567 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2569 if gGameSettings
.GameMode
= GM_CTF
then
2571 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2572 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2573 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2574 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2575 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2576 if g_Texture_Get(s
, ID
) then
2577 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2580 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2581 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2582 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2585 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2586 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2589 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2590 e_Draw(ID
, X
+2, Y
, 0, True, False);
2592 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2596 s
:= IntToStr(Frags
);
2597 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2598 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2603 stat
:= g_Player_GetStats();
2608 for a
:= 0 to High(stat
) do
2609 if stat
[a
].Name
<> Name
then
2611 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2612 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2616 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2617 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2618 s
:= s
+IntToStr(Abs(Frags
-m
));
2620 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2621 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2624 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2626 s
:= IntToStr(Lives
);
2627 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2628 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2632 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2633 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2635 if R_BERSERK
in FRulez
then
2636 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2638 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2640 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2641 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2643 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2644 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2645 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2647 s
:= IntToStr(FArmor
);
2648 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2649 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2651 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2657 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2662 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2664 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2665 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2666 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2667 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2668 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2669 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2670 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2671 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2672 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2675 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2676 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2677 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2679 if R_KEY_RED
in FRulez
then
2680 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2682 if R_KEY_GREEN
in FRulez
then
2683 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2685 if R_KEY_BLUE
in FRulez
then
2686 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2688 if FJetFuel
> 0 then
2690 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2691 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2692 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2693 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2694 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2695 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2699 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2700 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2701 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2704 if gShowPing
and g_Game_IsClient
then
2706 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2707 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2713 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2714 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2715 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2718 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2719 s
:= _lc
[I_PLAYER_SPECT4
];
2720 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2721 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2722 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2728 procedure TPlayer
.DrawRulez();
2732 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2733 if FMegaRulez
[MR_INVUL
] >= gTime
then
2735 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2736 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2741 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2742 191, 191, 191, 0, TBlending
.Invert
);
2745 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2746 if FMegaRulez
[MR_SUIT
] >= gTime
then
2748 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2749 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2754 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2755 0, 96, 0, 200, TBlending
.None
);
2758 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2759 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2761 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2762 255, 0, 0, 200, TBlending
.None
);
2766 procedure TPlayer
.DrawPain();
2770 if FPain
= 0 then Exit
;
2774 if a
< 15 then h
:= 0
2775 else if a
< 35 then h
:= 1
2776 else if a
< 55 then h
:= 2
2777 else if a
< 75 then h
:= 3
2778 else if a
< 95 then h
:= 4
2781 //if a > 255 then a := 255;
2783 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2784 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2787 procedure TPlayer
.DrawPickup();
2791 if FPickup
= 0 then Exit
;
2795 if a
< 15 then h
:= 1
2796 else if a
< 35 then h
:= 2
2797 else if a
< 55 then h
:= 3
2798 else if a
< 75 then h
:= 4
2801 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2804 procedure TPlayer
.DoPunch();
2809 if FPunchAnim
<> nil then begin
2814 st
:= 'FRAMES_PUNCH';
2815 if R_BERSERK
in FRulez
then
2816 st
:= st
+ '_BERSERK';
2817 if FKeys
[KEY_UP
].Pressed
then
2819 else if FKeys
[KEY_DOWN
].Pressed
then
2821 g_Frames_Get(id
, st
);
2822 FPunchAnim
:= TAnimation
.Create(id
, False, 1);
2825 procedure TPlayer
.Fire();
2827 f
, DidFire
: Boolean;
2828 wx
, wy
, xd
, yd
: Integer;
2831 if g_Game_IsClient
then Exit
;
2832 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2833 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2841 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2846 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2847 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2848 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
2849 yd
:= wy
+firediry();
2855 if R_BERSERK
in FRulez
then
2857 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2858 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2859 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2862 locobj
.rect
.Width
:= 39;
2863 locobj
.rect
.Height
:= 52;
2864 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2865 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2866 locobj
.Accel
.X
:= xd
-wx
;
2867 locobj
.Accel
.y
:= yd
-wy
;
2869 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2870 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2872 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2874 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
2878 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2882 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2887 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2888 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2890 FSawSoundSelect
.Stop();
2892 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2894 else if not FSawSoundHit
.IsPlaying() then
2896 FSawSoundSelect
.Stop();
2897 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2900 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2906 if FAmmo
[A_BULLETS
] > 0 then
2908 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2909 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2910 Dec(FAmmo
[A_BULLETS
]);
2911 FFireAngle
:= FAngle
;
2914 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2915 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2919 if FAmmo
[A_SHELLS
] > 0 then
2921 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2922 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
2923 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2924 Dec(FAmmo
[A_SHELLS
]);
2925 FFireAngle
:= FAngle
;
2929 FShellType
:= SHELL_SHELL
;
2933 if FAmmo
[A_SHELLS
] >= 2 then
2935 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
2936 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2937 Dec(FAmmo
[A_SHELLS
], 2);
2938 FFireAngle
:= FAngle
;
2942 FShellType
:= SHELL_DBLSHELL
;
2946 if FAmmo
[A_BULLETS
] > 0 then
2948 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
2949 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
2950 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2951 Dec(FAmmo
[A_BULLETS
]);
2952 FFireAngle
:= FAngle
;
2955 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2956 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2959 WEAPON_ROCKETLAUNCHER
:
2960 if FAmmo
[A_ROCKETS
] > 0 then
2962 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
2963 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2964 Dec(FAmmo
[A_ROCKETS
]);
2965 FFireAngle
:= FAngle
;
2971 if FAmmo
[A_CELLS
] > 0 then
2973 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
2974 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2975 Dec(FAmmo
[A_CELLS
]);
2976 FFireAngle
:= FAngle
;
2982 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
2984 FBFGFireCounter
:= 17;
2985 if not FNoReload
then
2986 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
2987 Dec(FAmmo
[A_CELLS
], 40);
2991 WEAPON_SUPERPULEMET
:
2992 if FAmmo
[A_SHELLS
] > 0 then
2994 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2995 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
2996 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2997 Dec(FAmmo
[A_SHELLS
]);
2998 FFireAngle
:= FAngle
;
3001 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3002 GameVelX
, GameVelY
-2, SHELL_SHELL
);
3005 WEAPON_FLAMETHROWER
:
3006 if FAmmo
[A_FUEL
] > 0 then
3008 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
3009 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3011 FFireAngle
:= FAngle
;
3017 if g_Game_IsNet
then
3021 if FCurrWeap
<> WEAPON_BFG
then
3022 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
3024 if not FNoReload
then
3025 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
3028 MH_SEND_PlayerStats(FUID
);
3033 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
3034 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
3035 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
3038 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
3041 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
3042 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
3043 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
3044 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
3045 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
3050 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
3052 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
3053 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
3054 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
3057 procedure TPlayer
.JetpackOn
;
3061 FJetSoundOn
.SetPosition(0);
3062 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3066 procedure TPlayer
.JetpackOff
;
3070 FJetSoundOff
.SetPosition(0);
3071 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3074 procedure TPlayer
.CatchFire(Attacker
: Word);
3077 FFireAttacker
:= Attacker
;
3078 if g_Game_IsNet
and g_Game_IsServer
then
3079 MH_SEND_PlayerStats(FUID
);
3082 procedure TPlayer
.Jump();
3084 if gFly
or FJetpack
then
3086 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3087 if FObj
.Vel
.Y
> -VEL_FLY
then
3088 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3091 if FJetFuel
> 0 then
3093 if (FJetFuel
< 1) and g_Game_IsServer
then
3097 if g_Game_IsNet
then
3098 MH_SEND_PlayerStats(FUID
);
3104 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3106 FCanJetpack
:= False;
3108 // Ïðûãàåì èëè âñïëûâàåì:
3109 if (CollideLevel(0, 1) or
3110 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3111 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3112 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3114 FObj
.Vel
.Y
:= -VEL_JUMP
;
3115 FCanJetpack
:= False;
3119 if BodyInLiquid(0, 0) then
3120 FObj
.Vel
.Y
:= -VEL_SW
3121 else if (FJetFuel
> 0) and FCanJetpack
and
3122 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3126 if g_Game_IsNet
then
3127 MH_SEND_PlayerStats(FUID
);
3132 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3134 a
, i
, k
, ab
, ar
: Byte;
3138 srv
, netsrv
: Boolean;
3144 procedure PushItem(t
: Byte);
3148 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3149 it
:= g_Items_ByIdx(id
);
3150 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3152 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3153 (FObj
.Vel
.Y
div 2)-Random(9));
3154 it
.positionChanged(); // this updates spatial accelerators
3158 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3160 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3161 (FObj
.Vel
.Y
div 2)-Random(6));
3163 else // -3..+3; -3..0
3165 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3166 (FObj
.Vel
.Y
div 2)-Random(4));
3168 it
.positionChanged(); // this updates spatial accelerators
3171 if g_Game_IsNet
and g_Game_IsServer
then
3172 MH_SEND_ItemSpawn(True, id
);
3176 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3177 Srv
:= g_Game_IsServer
;
3178 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3179 if Srv
then FDeath
:= FDeath
+ 1;
3184 if not FPhysics
then
3190 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3192 if FLives
> 0 then FLives
:= FLives
- 1;
3193 if FLives
= 0 then FNoRespawn
:= True;
3196 // Íîìåð òèïà ñìåðòè:
3199 K_SIMPLEKILL
: a
:= 1;
3201 K_EXTRAHARDKILL
: a
:= 3;
3206 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3208 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3215 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3217 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3218 K_EXTRAHARDKILL
, K_FALLKILL
:
3219 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3222 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3226 K_HARDKILL
, K_EXTRAHARDKILL
:
3230 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3231 if (KillType
<> K_FALLKILL
) and (Srv
) then
3232 g_Monsters_killedp();
3234 if SpawnerUID
= FUID
then
3236 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3241 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3244 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3245 begin // Óáèò äðóãèì èãðîêîì
3246 KP
:= g_Player_Get(SpawnerUID
);
3247 if (KP
<> nil) and Srv
then
3249 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3250 if SameTeam(FUID
, SpawnerUID
) then
3260 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3261 Inc(gTeamStat
[KP
.Team
].Goals
,
3262 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3264 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3267 plr
:= g_Player_Get(SpawnerUID
);
3275 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3279 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3283 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3288 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3289 begin // Óáèò ìîíñòðîì
3290 mon
:= g_Monsters_ByUID(SpawnerUID
);
3294 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
3298 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3302 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3306 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3311 else // Îñîáûå òèïû ñìåðòè
3314 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3315 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3316 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3317 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3318 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3319 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3325 for a
:= WP_FIRST
to WP_LAST
do
3329 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3330 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3331 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3332 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3333 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3334 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3335 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3336 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3337 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3346 if R_ITEM_BACKPACK
in FRulez
then
3347 PushItem(ITEM_AMMO_BACKPACK
);
3349 // Âûáðîñ ðàêåòíîãî ðàíöà:
3350 if FJetFuel
> 0 then
3351 PushItem(ITEM_JETPACK
);
3354 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3356 if R_KEY_RED
in FRulez
then
3357 PushItem(ITEM_KEY_RED
);
3359 if R_KEY_GREEN
in FRulez
then
3360 PushItem(ITEM_KEY_GREEN
);
3362 if R_KEY_BLUE
in FRulez
then
3363 PushItem(ITEM_KEY_BLUE
);
3370 g_Player_CreateCorpse(Self
);
3372 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3373 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3379 for i
:= Low(gPlayers
) to High(gPlayers
) do
3381 if gPlayers
[i
] = nil then continue
;
3382 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3385 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3386 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3391 OldLR
:= gLMSRespawn
;
3392 if (gGameSettings
.GameMode
= GM_COOP
) then
3396 // everyone is dead, restart the map
3397 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3399 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3400 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3401 gLMSRespawnTime
:= gTime
+ 5000;
3403 else if (a
= 1) then
3405 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3406 if (gPlayers
[k
] = gPlayer1
) or
3407 (gPlayers
[k
] = gPlayer2
) then
3408 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3409 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3410 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3413 else if (gGameSettings
.GameMode
= GM_TDM
) then
3415 if (ab
= 0) and (ar
<> 0) then
3418 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3420 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3421 Inc(gTeamStat
[TEAM_RED
].Goals
);
3422 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3423 gLMSRespawnTime
:= gTime
+ 5000;
3425 else if (ar
= 0) and (ab
<> 0) then
3428 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3430 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3431 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3432 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3433 gLMSRespawnTime
:= gTime
+ 5000;
3435 else if (ar
= 0) and (ab
= 0) then
3438 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3440 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3441 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3442 gLMSRespawnTime
:= gTime
+ 5000;
3445 else if (gGameSettings
.GameMode
= GM_DM
) then
3449 if gPlayers
[k
] <> nil then
3452 // survivor is the winner
3453 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3455 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3458 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3459 gLMSRespawnTime
:= gTime
+ 5000;
3461 else if (a
= 0) then
3463 // everyone is dead, restart the map
3464 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3466 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3467 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3468 gLMSRespawnTime
:= gTime
+ 5000;
3471 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3473 if NetMode
= NET_SERVER
then
3474 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3476 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3482 MH_SEND_PlayerStats(FUID
);
3483 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3484 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3487 if srv
and FNoRespawn
then Spectate(True);
3488 FWantsInGame
:= True;
3491 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3493 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3494 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3497 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3499 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3500 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3503 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3505 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3506 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3507 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3509 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3510 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3511 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3515 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3517 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3518 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3519 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3523 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3525 if g_Game_IsClient
then Exit
;
3526 if Weapon
> High(FWeapon
) then Exit
;
3527 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3530 procedure TPlayer
.resetWeaponQueue ();
3533 FNextWeapDelay
:= 0;
3536 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3540 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3541 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 0);
3542 WEAPON_PISTOL
, WEAPON_CHAINGUN
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_BULLETS
] > 0);
3543 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3544 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3545 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3546 else result
:= (weapon
< length(FWeapon
));
3550 // return 255 for "no switch"
3551 function TPlayer
.getNextWeaponIndex (): Byte;
3554 wantThisWeapon
: array[0..64] of Boolean;
3555 weaponOrder
: array[0..64] of Integer; // value: index in `FWeapon`
3556 wwc
: Integer = 0; //HACK!
3557 dir
, cwi
, rwidx
, curlidx
: Integer;
3559 function real2log (ridx
: Integer): Integer;
3565 for f
:= 0 to 10 do if (weaponOrder
[f
] = ridx
) then begin result
:= f
; exit
; end;
3571 result
:= 255; // default result: "no switch"
3573 // had weapon cycling on previous frame? remove that flag
3574 if (FNextWeap
and $2000) <> 0 then
3576 FNextWeap
:= FNextWeap
and $1FFF;
3577 FNextWeapDelay
:= 0;
3580 // build weapon order (k8: i know, i know, learn how to do constants and such... gtfo, please!)
3582 // bfg, plasma, flamethrower, ssg, minigun, sg, pistol, berserk, chainsaw, fist
3583 weaponOrder
[0] := WEAPON_BFG
;
3584 weaponOrder
[1] := WEAPON_PLASMA
;
3585 weaponOrder
[2] := WEAPON_FLAMETHROWER
;
3586 weaponOrder
[3] := WEAPON_SHOTGUN2
;
3587 weaponOrder
[4] := WEAPON_CHAINGUN
;
3588 weaponOrder
[5] := WEAPON_SHOTGUN1
;
3589 weaponOrder
[6] := WEAPON_PISTOL
;
3590 weaponOrder
[7] := WEAPON_KASTET
;
3591 weaponOrder
[8] := WEAPON_SAW
;
3592 weaponOrder
[9] := WEAPON_KASTET
;
3593 weaponOrder
[10] := WEAPON_SUPERPULEMET
;
3595 if (R_BERSERK
in FRulez
) then weaponOrder
[9] := -1 else weaponOrder
[7] := -1;
3601 WEAPON_SHOTGUN1 = 3;
3602 WEAPON_SHOTGUN2 = 4;
3603 WEAPON_CHAINGUN = 5;
3604 WEAPON_ROCKETLAUNCHER = 6;
3607 WEAPON_SUPERPULEMET = 9;
3608 WEAPON_FLAMETHROWER = 10;
3611 // cycling has priority
3612 if (FNextWeap
and $C000) <> 0 then
3614 if (FNextWeap
and $8000) <> 0 then dir
:= 1 else dir
:= -1; // should be reversed if we want "priority-driven cycling"
3615 FNextWeap
:= FNextWeap
or $2000; // we need this
3616 if FNextWeapDelay
> 0 then exit
; // cooldown time
3617 //cwi := real2log(FCurrWeap);
3618 //if (cwi < 0) then cwi := 0;
3620 for i
:= 0 to High(FWeapon
) do
3622 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3623 //rwidx := weaponOrder[cwi];
3624 rwidx
:= cwi
; // sorry
3625 if (rwidx
< 0) then continue
;
3626 if FWeapon
[rwidx
] then
3628 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d (dir=%d; log=%d)', [FCurrWeap, rwidx, dir, cwi]), TMsgType.Warning);
3629 result
:= Byte(rwidx
);
3630 FNextWeapDelay
:= 10;
3639 for i
:= 0 to High(wantThisWeapon
) do wantThisWeapon
[i
] := false;
3640 for i
:= 0 to High(FWeapon
) do
3642 if (FNextWeap
and (1 shl i
)) <> 0 then
3645 if (cwi
>= 0) then wantThisWeapon
[cwi
] := true;
3650 // slow down alterations a little
3653 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3654 // more than one weapon requested, assume "alteration", and check alteration delay
3655 if FNextWeapDelay
> 0 then
3662 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3663 // but clear all counters if no weapon should be switched
3669 //e_WriteLog(Format('wwc=%d', [wwc]), TMsgType.Warning);
3671 // exclude currently selected weapon from the set
3672 curlidx
:= real2log(FCurrWeap
);
3673 //e_WriteLog(Format('FCurrWeap=%d; curlidx=%d', [FCurrWeap, curlidx]), TMsgType.Warning);
3674 //if (curlidx >= 0) then wantThisWeapon[curlidx] := false;
3675 //if (wwc = 2) then begin Dec(wwc); end; // easy case: switch between two weapons
3677 // find next weapon to switch onto
3679 for i
:= 0 to High(FWeapon
) do
3681 cwi
:= (cwi
+length(FWeapon
)+1) mod length(FWeapon
);
3682 if (cwi
= curlidx
) then continue
; // skip current weapon
3683 if not wantThisWeapon
[cwi
] then continue
;
3684 rwidx
:= weaponOrder
[cwi
];
3685 if (rwidx
< 0) then continue
;
3686 //e_WriteLog(Format(' trying logical %d (real %d)', [cwi, rwidx]), TMsgType.Warning);
3687 if FWeapon
[cwi
] and ((wwc
= 1) or hasAmmoForWeapon(cwi
)) then
3690 result
:= Byte(rwidx
);
3692 FNextWeapDelay
:= 10; // anyway, 'cause why not
3697 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3701 procedure TPlayer
.RealizeCurrentWeapon();
3702 function switchAllowed (): Boolean;
3707 if FBFGFireCounter
<> -1 then
3709 if FTime
[T_SWITCH
] > gTime
then
3711 for i
:= WP_FIRST
to WP_LAST
do
3712 if FReloading
[i
] > 0 then
3720 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3721 //FNextWeap := FNextWeap and $1FFF;
3722 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3724 if not switchAllowed
then
3726 //HACK for weapon cycling
3727 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3731 nw
:= getNextWeaponIndex();
3732 if nw
= 255 then exit
; // don't reset anything here
3733 if nw
> High(FWeapon
) then
3735 // don't forget to reset queue here!
3736 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3744 FTime
[T_SWITCH
] := gTime
+156;
3745 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3746 FModel
.SetWeapon(FCurrWeap
);
3747 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3751 procedure TPlayer
.NextWeapon();
3753 if g_Game_IsClient
then Exit
;
3757 procedure TPlayer
.PrevWeapon();
3759 if g_Game_IsClient
then Exit
;
3763 procedure TPlayer
.SetWeapon(W
: Byte);
3765 if FCurrWeap
<> W
then
3766 if W
= WEAPON_SAW
then
3767 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3770 FModel
.SetWeapon(CurrWeap
);
3774 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3776 function allowBerserkSwitching (): Boolean;
3778 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3780 if gBerserkAutoswitch
then exit
;
3781 if not conIsCheatsEnabled
then exit
;
3789 if g_Game_IsClient
then Exit
;
3791 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3792 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3797 if FHealth
< PLAYER_HP_SOFT
then
3799 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3803 if gFlash
= 2 then Inc(FPickup
, 5);
3807 if FHealth
< PLAYER_HP_SOFT
then
3809 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3813 if gFlash
= 2 then Inc(FPickup
, 5);
3817 if FArmor
< PLAYER_AP_SOFT
then
3819 FArmor
:= PLAYER_AP_SOFT
;
3822 if gFlash
= 2 then Inc(FPickup
, 5);
3826 if FArmor
< PLAYER_AP_LIMIT
then
3828 FArmor
:= PLAYER_AP_LIMIT
;
3831 if gFlash
= 2 then Inc(FPickup
, 5);
3835 if FHealth
< PLAYER_HP_LIMIT
then
3837 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3841 if gFlash
= 2 then Inc(FPickup
, 5);
3845 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3847 if FHealth
< PLAYER_HP_LIMIT
then
3848 FHealth
:= PLAYER_HP_LIMIT
;
3849 if FArmor
< PLAYER_AP_LIMIT
then
3850 FArmor
:= PLAYER_AP_LIMIT
;
3854 if gFlash
= 2 then Inc(FPickup
, 5);
3858 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3860 FWeapon
[WEAPON_SAW
] := True;
3862 if gFlash
= 2 then Inc(FPickup
, 5);
3863 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3866 ITEM_WEAPON_SHOTGUN1
:
3867 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3869 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3870 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3872 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3873 FWeapon
[WEAPON_SHOTGUN1
] := True;
3875 if gFlash
= 2 then Inc(FPickup
, 5);
3876 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3879 ITEM_WEAPON_SHOTGUN2
:
3880 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3882 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3884 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3885 FWeapon
[WEAPON_SHOTGUN2
] := True;
3887 if gFlash
= 2 then Inc(FPickup
, 5);
3888 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3891 ITEM_WEAPON_CHAINGUN
:
3892 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3894 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3896 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3897 FWeapon
[WEAPON_CHAINGUN
] := True;
3899 if gFlash
= 2 then Inc(FPickup
, 5);
3900 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3903 ITEM_WEAPON_ROCKETLAUNCHER
:
3904 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3906 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3908 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3909 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3911 if gFlash
= 2 then Inc(FPickup
, 5);
3912 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3916 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3918 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3920 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3921 FWeapon
[WEAPON_PLASMA
] := True;
3923 if gFlash
= 2 then Inc(FPickup
, 5);
3924 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3928 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3930 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3932 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3933 FWeapon
[WEAPON_BFG
] := True;
3935 if gFlash
= 2 then Inc(FPickup
, 5);
3936 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3939 ITEM_WEAPON_SUPERPULEMET
:
3940 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3942 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3944 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3945 FWeapon
[WEAPON_SUPERPULEMET
] := True;
3947 if gFlash
= 2 then Inc(FPickup
, 5);
3948 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3951 ITEM_WEAPON_FLAMETHROWER
:
3952 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
3954 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
3956 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3957 FWeapon
[WEAPON_FLAMETHROWER
] := True;
3959 if gFlash
= 2 then Inc(FPickup
, 5);
3960 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3964 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3966 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3969 if gFlash
= 2 then Inc(FPickup
, 5);
3972 ITEM_AMMO_BULLETS_BOX
:
3973 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3975 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3978 if gFlash
= 2 then Inc(FPickup
, 5);
3982 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3984 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3987 if gFlash
= 2 then Inc(FPickup
, 5);
3990 ITEM_AMMO_SHELLS_BOX
:
3991 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3993 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
3996 if gFlash
= 2 then Inc(FPickup
, 5);
4000 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4002 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4005 if gFlash
= 2 then Inc(FPickup
, 5);
4008 ITEM_AMMO_ROCKET_BOX
:
4009 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4011 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
4014 if gFlash
= 2 then Inc(FPickup
, 5);
4018 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4020 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4023 if gFlash
= 2 then Inc(FPickup
, 5);
4027 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4029 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4032 if gFlash
= 2 then Inc(FPickup
, 5);
4036 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4038 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4041 if gFlash
= 2 then Inc(FPickup
, 5);
4045 if not(R_ITEM_BACKPACK
in FRulez
) or
4046 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4047 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4048 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4049 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4050 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
4052 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4053 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4054 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4055 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4056 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4058 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4059 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4060 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4061 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4062 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4063 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4064 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4065 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4067 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
4070 if gFlash
= 2 then Inc(FPickup
, 5);
4074 if not(R_KEY_RED
in FRulez
) then
4076 Include(FRulez
, R_KEY_RED
);
4078 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4079 if gFlash
= 2 then Inc(FPickup
, 5);
4080 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4084 if not(R_KEY_GREEN
in FRulez
) then
4086 Include(FRulez
, R_KEY_GREEN
);
4088 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4089 if gFlash
= 2 then Inc(FPickup
, 5);
4090 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4094 if not(R_KEY_BLUE
in FRulez
) then
4096 Include(FRulez
, R_KEY_BLUE
);
4098 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4099 if gFlash
= 2 then Inc(FPickup
, 5);
4100 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4104 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4106 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4110 if gFlash
= 2 then Inc(FPickup
, 5);
4114 if FAir
< AIR_MAX
then
4119 if gFlash
= 2 then Inc(FPickup
, 5);
4124 if not (R_BERSERK
in FRulez
) then
4126 Include(FRulez
, R_BERSERK
);
4127 if allowBerserkSwitching
then
4129 FCurrWeap
:= WEAPON_KASTET
;
4131 FModel
.SetWeapon(WEAPON_KASTET
);
4136 if gFlash
= 2 then Inc(FPickup
, 5);
4138 FBerserk
:= gTime
+30000;
4143 if FHealth
< PLAYER_HP_SOFT
then
4145 FHealth
:= PLAYER_HP_SOFT
;
4146 FBerserk
:= gTime
+30000;
4154 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4156 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4159 if gFlash
= 2 then Inc(FPickup
, 5);
4163 if FHealth
< PLAYER_HP_LIMIT
then
4165 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4169 if gFlash
= 2 then Inc(FPickup
, 5);
4173 if FArmor
< PLAYER_AP_LIMIT
then
4175 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4178 if gFlash
= 2 then Inc(FPickup
, 5);
4182 if FJetFuel
< JET_MAX
then
4184 FJetFuel
:= JET_MAX
;
4187 if gFlash
= 2 then Inc(FPickup
, 5);
4191 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4193 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4196 if gFlash
= 2 then Inc(FPickup
, 5);
4201 procedure TPlayer
.Touch();
4205 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4208 // Áðîñèòü ôëàã òîâàðèùó:
4209 if gGameSettings
.GameMode
= GM_CTF
then
4214 procedure TPlayer
.Push(vx
, vy
: Integer);
4216 if (not FPhysics
) and FGhost
then
4218 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4219 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4220 if g_Game_IsNet
and g_Game_IsServer
then
4221 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4224 procedure TPlayer
.Reset(Force
: Boolean);
4230 FTime
[T_RESPAWN
] := 0;
4231 FTime
[T_FLAGCAP
] := 0;
4244 FSpectator
:= False;
4247 FSpectatePlayer
:= -1;
4248 FNoRespawn
:= False;
4250 FLives
:= gGameSettings
.MaxLives
;
4255 procedure TPlayer
.SoftReset();
4261 FBFGFireCounter
:= -1;
4269 SetAction(A_STAND
, True);
4272 function TPlayer
.GetRespawnPoint(): Byte;
4277 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4279 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4280 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4282 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4284 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4285 if Self
= gPlayer1
then
4286 c
:= RESPAWNPOINT_PLAYER1
4288 c
:= RESPAWNPOINT_PLAYER2
;
4289 if g_Map_GetPointCount(c
) > 0 then
4295 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4296 if Self
= gPlayer1
then
4297 c
:= RESPAWNPOINT_PLAYER2
4299 c
:= RESPAWNPOINT_PLAYER1
;
4300 if g_Map_GetPointCount(c
) > 0 then
4307 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4308 if Random(2) = 0 then
4309 c
:= RESPAWNPOINT_PLAYER1
4311 c
:= RESPAWNPOINT_PLAYER2
;
4312 if g_Map_GetPointCount(c
) > 0 then
4319 // Òî÷êà ëþáîé èç êîìàíä
4320 if Random(2) = 0 then
4321 c
:= RESPAWNPOINT_RED
4323 c
:= RESPAWNPOINT_BLUE
;
4324 if g_Map_GetPointCount(c
) > 0 then
4331 c
:= RESPAWNPOINT_DM
;
4332 if g_Map_GetPointCount(c
) > 0 then
4340 if gGameSettings
.GameMode
= GM_DM
then
4343 c
:= RESPAWNPOINT_DM
;
4344 if g_Map_GetPointCount(c
) > 0 then
4350 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4351 if Random(2) = 0 then
4352 c
:= RESPAWNPOINT_PLAYER1
4354 c
:= RESPAWNPOINT_PLAYER2
;
4355 if g_Map_GetPointCount(c
) > 0 then
4361 // Òî÷êà ëþáîé èç êîìàíä
4362 if Random(2) = 0 then
4363 c
:= RESPAWNPOINT_RED
4365 c
:= RESPAWNPOINT_BLUE
;
4366 if g_Map_GetPointCount(c
) > 0 then
4374 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4376 // Òî÷êà ñâîåé êîìàíäû
4377 c
:= RESPAWNPOINT_DM
;
4378 if FTeam
= TEAM_RED
then
4379 c
:= RESPAWNPOINT_RED
;
4380 if FTeam
= TEAM_BLUE
then
4381 c
:= RESPAWNPOINT_BLUE
;
4382 if g_Map_GetPointCount(c
) > 0 then
4389 c
:= RESPAWNPOINT_DM
;
4390 if g_Map_GetPointCount(c
) > 0 then
4396 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4397 if Random(2) = 0 then
4398 c
:= RESPAWNPOINT_PLAYER1
4400 c
:= RESPAWNPOINT_PLAYER2
;
4401 if g_Map_GetPointCount(c
) > 0 then
4407 // Òî÷êà äðóãîé êîìàíäû
4408 c
:= RESPAWNPOINT_DM
;
4409 if FTeam
= TEAM_RED
then
4410 c
:= RESPAWNPOINT_BLUE
;
4411 if FTeam
= TEAM_BLUE
then
4412 c
:= RESPAWNPOINT_RED
;
4413 if g_Map_GetPointCount(c
) > 0 then
4421 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4423 RespawnPoint
: TRespawnPoint
;
4429 FBFGFireCounter
:= -1;
4434 if not g_Game_IsServer
then
4438 FWantsInGame
:= True;
4439 FJustTeleported
:= True;
4442 FTime
[T_RESPAWN
] := 0;
4446 // if server changes MaxLives we gotta be ready
4447 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4449 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4450 if FTime
[T_RESPAWN
] > gTime
then
4453 // Ïðîñðàë âñå æèçíè:
4456 if not FSpectator
then Spectate(True);
4457 FWantsInGame
:= True;
4461 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4462 begin // "Ñâîÿ èãðà"
4463 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4464 FRulez
:= FRulez
-[R_BERSERK
];
4466 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4468 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4469 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4472 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4473 c
:= GetRespawnPoint();
4478 // Âîñêðåøåíèå áåç îðóæèÿ:
4481 FHealth
:= PLAYER_HP_SOFT
;
4487 for a
:= WP_FIRST
to WP_LAST
do
4489 FWeapon
[a
] := False;
4493 FWeapon
[WEAPON_PISTOL
] := True;
4494 FWeapon
[WEAPON_KASTET
] := True;
4495 FCurrWeap
:= WEAPON_PISTOL
;
4498 FModel
.SetWeapon(FCurrWeap
);
4500 for b
:= A_BULLETS
to A_HIGH
do
4503 FAmmo
[A_BULLETS
] := 50;
4505 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4506 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4507 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4508 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4509 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4511 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4512 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4517 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4518 if not g_Map_GetPoint(c
, RespawnPoint
) then
4520 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4524 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4525 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4526 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4532 FDirection
:= RespawnPoint
.Direction
;
4533 if FDirection
= TDirection
.D_LEFT
then
4538 SetAction(A_STAND
, True);
4539 FModel
.Direction
:= FDirection
;
4541 for a
:= Low(FTime
) to High(FTime
) do
4544 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4549 FCanJetpack
:= False;
4554 // Àíèìàöèÿ âîçðîæäåíèÿ:
4555 if (not gLoadGameMode
) and (not Silent
) then
4556 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4558 Anim
:= TAnimation
.Create(ID
, False, 3);
4559 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4560 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4564 FSpectator
:= False;
4567 FSpectatePlayer
:= -1;
4570 if (gPlayer1
= nil) and (gLMSPID1
= FUID
) then
4572 if (gPlayer2
= nil) and (gLMSPID2
= FUID
) then
4575 if g_Game_IsNet
then
4577 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4578 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4580 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4581 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4586 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4589 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4590 else if (not NoMove
) then
4592 GameX
:= gMapInfo
.Width
div 2;
4593 GameY
:= gMapInfo
.Height
div 2;
4602 FWantsInGame
:= False;
4607 if Self
= gPlayer1
then
4612 if Self
= gPlayer2
then
4619 if g_Game_IsNet
then
4620 MH_SEND_PlayerStats(FUID
);
4623 procedure TPlayer
.SwitchNoClip
;
4627 FGhost
:= not FGhost
;
4628 FPhysics
:= not FGhost
;
4640 procedure TPlayer
.Run(Direction
: TDirection
);
4644 if MAX_RUNVEL
> 8 then
4648 if Direction
= TDirection
.D_LEFT
then
4650 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4651 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4654 if FObj
.Vel
.X
< MAX_RUNVEL
then
4655 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4657 // Âîçìîæíî, ïèíàåì êóñêè:
4658 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4660 b
:= Abs(FObj
.Vel
.X
);
4661 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4662 for a
:= 0 to High(gGibs
) do
4664 if gGibs
[a
].alive
and
4665 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4666 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4669 if FObj
.Vel
.X
< 0 then
4671 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4675 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4677 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4685 procedure TPlayer
.SeeDown();
4687 SetAction(A_SEEDOWN
);
4689 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4691 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4694 procedure TPlayer
.SeeUp();
4698 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4700 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4703 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4711 A_ATTACK
: Prior
:= 2;
4712 A_SEEUP
: Prior
:= 1;
4713 A_SEEDOWN
: Prior
:= 1;
4714 A_ATTACKUP
: Prior
:= 2;
4715 A_ATTACKDOWN
: Prior
:= 2;
4720 if (Prior
> FActionPrior
) or Force
then
4721 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4723 FActionPrior
:= Prior
;
4724 FActionAnim
:= Action
;
4725 FActionForce
:= Force
;
4726 FActionChanged
:= True;
4729 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4732 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4734 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4735 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4736 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4737 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4740 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4747 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4749 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4750 if g_Game_IsServer
and g_Game_IsNet
then
4751 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4755 FJustTeleported
:= True;
4760 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4762 Anim
:= TAnimation
.Create(ID
, False, 3);
4765 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4766 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4767 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4768 if g_Game_IsServer
and g_Game_IsNet
then
4769 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4770 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4774 FObj
.X
:= X
-PLAYER_RECT
.X
;
4775 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4776 if FAlive
and FGhost
then
4782 if not g_Game_IsNet
then
4786 SetDirection(TDirection
.D_LEFT
);
4792 SetDirection(TDirection
.D_RIGHT
);
4798 if FDirection
= TDirection
.D_RIGHT
then
4800 SetDirection(TDirection
.D_LEFT
);
4805 SetDirection(TDirection
.D_RIGHT
);
4811 if not silent
and (Anim
<> nil) then
4813 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4814 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4817 if g_Game_IsServer
and g_Game_IsNet
then
4818 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4819 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4826 function nonz(a
: Single): Single;
4834 procedure TPlayer
.Update();
4837 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4838 blockmon
, headwater
, dospawn
: Boolean;
4843 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4844 AnyServer
:= g_Game_IsServer
;
4846 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4847 DoLerp(NetInterpLevel
+ 1)
4853 if FClientID
>= 0 then
4855 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4856 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4857 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4866 if FAlive
and (FPunchAnim
<> nil) then
4867 FPunchAnim
.Update();
4869 if FAlive
and (gFly
or FJetpack
) then
4872 if FDirection
= TDirection
.D_LEFT
then
4877 if FAlive
and (not FGhost
) then
4879 if FKeys
[KEY_UP
].Pressed
then
4881 if FKeys
[KEY_DOWN
].Pressed
then
4885 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4888 i
:= g_basic
.Sign(FIncCam
);
4889 FIncCam
:= Abs(FIncCam
);
4890 DecMin(FIncCam
, 5, 0);
4891 FIncCam
:= FIncCam
*i
;
4894 // no need to do that each second frame, weapon queue will take care of it
4895 if FAlive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4896 if FAlive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4898 if gTime
mod (GAME_TICK
*2) <> 0 then
4900 if (FObj
.Vel
.X
= 0) and FAlive
then
4902 if FKeys
[KEY_LEFT
].Pressed
then
4903 Run(TDirection
.D_LEFT
);
4904 if FKeys
[KEY_RIGHT
].Pressed
then
4905 Run(TDirection
.D_RIGHT
);
4910 g_Obj_Move(@FObj
, True, True, True);
4911 positionChanged(); // this updates spatial accelerators
4917 FActionChanged
:= False;
4921 // Let alive player do some actions
4922 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
4923 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
4924 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
4925 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
4926 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
4927 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
4928 if FKeys
[KEY_JUMP
].Pressed
then Jump()
4931 if AnyServer
and FJetpack
then
4935 if NetServer
then MH_SEND_PlayerStats(FUID
);
4937 FCanJetpack
:= True;
4944 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
4946 if FKeys
[k
].Pressed
then
4954 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4957 if (FTime
[T_RESPAWN
] <= gTime
) and
4958 gGameOn
and (not FAlive
) then
4960 if (g_Player_GetCount() > 1) then
4964 gExit
:= EXIT_RESTART
;
4969 // Dead spectator actions
4972 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
4973 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
4977 if (FSpectatePlayer
>= High(gPlayers
)) then
4978 FSpectatePlayer
:= -1
4982 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
4983 if gPlayers
[I
] <> nil then
4984 if gPlayers
[I
].alive
then
4985 if gPlayers
[I
].UID
<> FUID
then
4987 FSpectatePlayer
:= I
;
4992 if not SetSpect
then FSpectatePlayer
:= -1;
5003 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5005 FYTo
:= FObj
.Y
- 32;
5006 FSpectatePlayer
:= -1;
5008 if FKeys
[KEY_DOWN
].Pressed
then
5010 FYTo
:= FObj
.Y
+ 32;
5011 FSpectatePlayer
:= -1;
5013 if FKeys
[KEY_LEFT
].Pressed
then
5015 FXTo
:= FObj
.X
- 32;
5016 FSpectatePlayer
:= -1;
5018 if FKeys
[KEY_RIGHT
].Pressed
then
5020 FXTo
:= FObj
.X
+ 32;
5021 FSpectatePlayer
:= -1;
5024 if (FXTo
< -64) then
5026 else if (FXTo
> gMapInfo
.Width
+ 32) then
5027 FXTo
:= gMapInfo
.Width
+ 32;
5028 if (FYTo
< -72) then
5030 else if (FYTo
> gMapInfo
.Height
+ 32) then
5031 FYTo
:= gMapInfo
.Height
+ 32;
5036 g_Obj_Move(@FObj
, True, True, True);
5037 positionChanged(); // this updates spatial accelerators
5044 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5045 if gPlayers
[FSpectatePlayer
] <> nil then
5046 if gPlayers
[FSpectatePlayer
].alive
then
5048 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
5049 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
5053 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5054 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5055 PANEL_BLOCKMON
, True);
5056 headwater
:= HeadInLiquid(0, 0);
5058 // Ñîïðîòèâëåíèå âîçäóõà:
5059 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5060 if FObj
.Vel
.X
<> 0 then
5061 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5063 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5064 DecMin(FPain
, 5, 0);
5065 DecMin(FPickup
, 1, 0);
5067 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5069 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5070 FMegaRulez
[MR_SUIT
] := 0;
5071 FMegaRulez
[MR_INVUL
] := 0;
5072 FMegaRulez
[MR_INVIS
] := 0;
5073 Kill(K_FALLKILL
, 0, HIT_FALL
);
5080 if FCurrWeap
= WEAPON_SAW
then
5081 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5082 FSawSoundSelect
.IsPlaying()) then
5083 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5086 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5087 (not FJetSoundOff
.IsPlaying()) then
5089 FJetSoundFly
.SetPosition(0);
5090 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5093 for b
:= WP_FIRST
to WP_LAST
do
5094 if FReloading
[b
] > 0 then
5100 if FShellTimer
> -1 then
5101 if FShellTimer
= 0 then
5103 if FShellType
= SHELL_SHELL
then
5104 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5105 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5106 else if FShellType
= SHELL_DBLSHELL
then
5108 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5109 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5110 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5111 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5114 end else Dec(FShellTimer
);
5116 if (FBFGFireCounter
> -1) then
5117 if FBFGFireCounter
= 0 then
5121 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5122 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5123 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5124 yd
:= wy
+firediry();
5125 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5126 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5127 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5128 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5129 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5132 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5133 FBFGFireCounter
:= -1;
5136 FBFGFireCounter
:= 0
5138 Dec(FBFGFireCounter
);
5140 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5142 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5144 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5147 if (headwater
or blockmon
) then
5153 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5156 else if (FAir
mod 31 = 0) and not blockmon
then
5158 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5159 if Random(2) = 0 then
5160 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5162 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5164 end else if FAir
< AIR_DEF
then
5167 if FFireTime
> 0 then
5169 if BodyInLiquid(0, 0) then
5174 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5176 if FMegaRulez
[MR_SUIT
] = gTime
then
5183 if FFirePainTime
<= 0 then
5185 if g_Game_IsServer
then
5186 Damage(5, FFireAttacker
, 0, 0, HIT_FLAME
);
5187 FFirePainTime
:= 18;
5189 FFirePainTime
:= FFirePainTime
- 1;
5190 FFireTime
:= FFireTime
- 1;
5191 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5192 MH_SEND_PlayerStats(FUID
);
5196 if FDamageBuffer
> 0 then
5198 if FDamageBuffer
>= 9 then
5202 if FDamageBuffer
< 30 then i
:= 9
5203 else if FDamageBuffer
< 100 then i
:= 18
5207 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5208 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5209 FHealth
:= FHealth
-ii
;
5212 FHealth
:= FHealth
+FArmor
;
5217 if FHealth
<= 0 then
5218 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5219 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5220 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5224 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5225 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5226 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5227 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5234 end; // if FAlive then ...
5236 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5238 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5239 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5240 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5241 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5243 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5244 then SetAction(A_STAND
, True);
5246 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5248 for b
:= Low(FKeys
) to High(FKeys
) do
5249 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5253 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5255 x
:= FObj
.X
+PLAYER_RECT
.X
;
5256 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5257 w
:= PLAYER_RECT
.Width
;
5258 h
:= PLAYER_RECT
.Height
;
5262 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5264 if (dx
<> 0) or (dy
<> 0) then
5273 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5275 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5276 FObj
.Y
+PLAYER_RECT
.Y
,
5283 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5285 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5286 FObj
.Y
+PLAYER_RECT
.Y
,
5290 Panel
.Width
, Panel
.Height
);
5293 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5295 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5296 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5297 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5298 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5301 function g_Player_ValidName(Name
: string): Boolean;
5307 if gPlayers
= nil then Exit
;
5309 for a
:= 0 to High(gPlayers
) do
5310 if gPlayers
[a
] <> nil then
5311 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5318 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5322 d
:= FModel
.Direction
;
5324 FModel
.Direction
:= Direction
;
5325 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5327 FDirection
:= Direction
;
5330 function TPlayer
.GetKeys(): Byte;
5334 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5335 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5336 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5338 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5339 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5342 procedure TPlayer
.Use();
5346 if FTime
[T_USE
] > gTime
then Exit
;
5348 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5349 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5351 for a
:= 0 to High(gPlayers
) do
5352 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5353 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5354 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5355 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5357 gPlayers
[a
].Touch();
5358 if g_Game_IsNet
and g_Game_IsServer
then
5359 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5362 FTime
[T_USE
] := gTime
+120;
5365 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5369 WX
, WY
, XD
, YD
: Integer;
5381 if R_BERSERK
in FRulez
then
5383 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5384 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5385 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5388 locobj
.rect
.Width
:= 39;
5389 locobj
.rect
.Height
:= 52;
5390 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5391 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5392 locobj
.Accel
.X
:= xd
-wx
;
5393 locobj
.Accel
.y
:= yd
-wy
;
5395 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5396 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5398 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5402 FPain
:= min(FPain
+ 25, 50);
5404 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5409 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5410 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5412 FSawSoundSelect
.Stop();
5414 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5416 else if not FSawSoundHit
.IsPlaying() then
5418 FSawSoundSelect
.Stop();
5419 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5426 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5427 FFireAngle
:= FAngle
;
5429 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5430 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5435 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5436 FFireAngle
:= FAngle
;
5439 FShellType
:= SHELL_SHELL
;
5444 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5445 FFireAngle
:= FAngle
;
5448 FShellType
:= SHELL_DBLSHELL
;
5453 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5454 FFireAngle
:= FAngle
;
5456 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5457 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5460 WEAPON_ROCKETLAUNCHER
:
5462 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5463 FFireAngle
:= FAngle
;
5469 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5470 FFireAngle
:= FAngle
;
5476 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5477 FFireAngle
:= FAngle
;
5481 WEAPON_SUPERPULEMET
:
5483 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5484 FFireAngle
:= FAngle
;
5486 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5487 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5490 WEAPON_FLAMETHROWER
:
5492 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5493 FFireAngle
:= FAngle
;
5500 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5501 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5502 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5505 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5507 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5508 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5511 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5515 if NetInterpLevel
< 1 then
5525 AX
:= Abs(FXTo
- FObj
.X
);
5526 AY
:= Abs(FYTo
- FObj
.Y
);
5527 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5529 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5534 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5536 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5537 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5538 PANEL_LIFTUP
, False) then Result
:= -1
5540 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5541 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5542 PANEL_LIFTDOWN
, False) then Result
:= 1
5546 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5553 if Flag
= FLAG_NONE
then
5556 if not g_Game_IsServer
then Exit
;
5558 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5559 if (Flag
= FTeam
) and
5560 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5561 (FFlag
<> FLAG_NONE
) then
5563 if FFlag
= FLAG_RED
then
5564 s
:= _lc
[I_PLAYER_FLAG_RED
]
5566 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5568 evtype
:= FLAG_STATE_SCORED
;
5570 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5571 Insert('.', ts
, Length(ts
) + 1 - 3);
5572 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5574 g_Map_ResetFlag(FFlag
);
5575 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5577 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5580 if g_Game_IsNet
then
5582 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5586 gFlags
[FFlag
].CaptureTime
:= 0;
5591 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5592 if (Flag
= FTeam
) and
5593 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5595 if Flag
= FLAG_RED
then
5596 s
:= _lc
[I_PLAYER_FLAG_RED
]
5598 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5600 evtype
:= FLAG_STATE_RETURNED
;
5601 gFlags
[Flag
].CaptureTime
:= 0;
5603 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5605 g_Map_ResetFlag(Flag
);
5606 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5609 if g_Game_IsNet
then
5611 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5617 // Ïîäîáðàë ÷óæîé ôëàã:
5618 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5622 if Flag
= FLAG_RED
then
5623 s
:= _lc
[I_PLAYER_FLAG_RED
]
5625 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5627 evtype
:= FLAG_STATE_CAPTURED
;
5629 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5631 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5633 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5636 if g_Game_IsNet
then
5638 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5644 procedure TPlayer
.SetFlag(Flag
: Byte);
5647 if FModel
<> nil then
5648 FModel
.SetFlag(FFlag
);
5651 function TPlayer
.DropFlag(): Boolean;
5656 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5658 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5659 with gFlags
[FFlag
] do
5663 Direction
:= FDirection
;
5664 State
:= FLAG_STATE_DROPPED
;
5666 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5667 (FObj
.Vel
.Y
div 2)-2+Random(5));
5668 positionChanged(); // this updates spatial accelerators
5670 if FFlag
= FLAG_RED
then
5671 s
:= _lc
[I_PLAYER_FLAG_RED
]
5673 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5675 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5676 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5678 if g_Game_IsNet
then
5679 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5685 procedure TPlayer
.GetSecret();
5690 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5692 Assert(Key
<= High(FKeys
));
5694 FKeys
[Key
].Pressed
:= True;
5695 FKeys
[Key
].Time
:= Time
;
5698 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5700 Result
:= FKeys
[K
].Pressed
;
5703 procedure TPlayer
.ReleaseKeys();
5707 for a
:= Low(FKeys
) to High(FKeys
) do
5709 FKeys
[a
].Pressed
:= False;
5714 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5718 function TPlayer
.firediry(): Integer;
5720 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5721 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5725 procedure TPlayer
.RememberState();
5729 FSavedState
.Health
:= FHealth
;
5730 FSavedState
.Armor
:= FArmor
;
5731 FSavedState
.Air
:= FAir
;
5732 FSavedState
.JetFuel
:= FJetFuel
;
5733 FSavedState
.CurrWeap
:= FCurrWeap
;
5734 FSavedState
.NextWeap
:= FNextWeap
;
5735 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5738 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5740 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5742 FSavedState
.Rulez
:= FRulez
;
5743 FSavedState
.WaitRecall
:= True;
5746 procedure TPlayer
.RecallState();
5750 if not FSavedState
.WaitRecall
then Exit
;
5752 FHealth
:= FSavedState
.Health
;
5753 FArmor
:= FSavedState
.Armor
;
5754 FAir
:= FSavedState
.Air
;
5755 FJetFuel
:= FSavedState
.JetFuel
;
5756 FCurrWeap
:= FSavedState
.CurrWeap
;
5757 FNextWeap
:= FSavedState
.NextWeap
;
5758 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5761 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5763 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5765 FRulez
:= FSavedState
.Rulez
;
5766 FSavedState
.WaitRecall
:= False;
5768 if gGameSettings
.GameType
= GT_SERVER
then
5769 MH_SEND_PlayerStats(FUID
);
5772 procedure TPlayer
.SaveState (st
: TStream
);
5778 utils
.writeSign(st
, 'PLYR');
5779 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
5781 utils
.writeBool(st
, FIamBot
);
5783 utils
.writeInt(st
, Word(FUID
));
5785 utils
.writeStr(st
, FName
);
5787 utils
.writeInt(st
, Byte(FTeam
));
5789 utils
.writeBool(st
, FAlive
);
5790 // Èçðàñõîäîâàë ëè âñå æèçíè
5791 utils
.writeBool(st
, FNoRespawn
);
5793 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
5794 utils
.writeInt(st
, Byte(b
));
5796 utils
.writeInt(st
, LongInt(FHealth
));
5798 utils
.writeInt(st
, Byte(FLives
));
5800 utils
.writeInt(st
, LongInt(FArmor
));
5802 utils
.writeInt(st
, LongInt(FAir
));
5804 utils
.writeInt(st
, LongInt(FJetFuel
));
5806 utils
.writeInt(st
, LongInt(FPain
));
5808 utils
.writeInt(st
, LongInt(FKills
));
5810 utils
.writeInt(st
, LongInt(FMonsterKills
));
5812 utils
.writeInt(st
, LongInt(FFrags
));
5814 utils
.writeInt(st
, Byte(FFragCombo
));
5815 // Âðåìÿ ïîñëåäíåãî ôðàãà
5816 utils
.writeInt(st
, LongWord(FLastFrag
));
5818 utils
.writeInt(st
, LongInt(FDeath
));
5820 utils
.writeInt(st
, Byte(FFlag
));
5822 utils
.writeInt(st
, LongInt(FSecrets
));
5824 utils
.writeInt(st
, Byte(FCurrWeap
));
5826 utils
.writeInt(st
, Word(FNextWeap
));
5828 utils
.writeInt(st
, Byte(FNextWeapDelay
));
5829 // Âðåìÿ çàðÿäêè BFG
5830 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
5832 utils
.writeInt(st
, LongInt(FDamageBuffer
));
5833 // Ïîñëåäíèé óäàðèâøèé
5834 utils
.writeInt(st
, Word(FLastSpawnerUID
));
5835 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
5836 utils
.writeInt(st
, Byte(FLastHit
));
5838 Obj_SaveState(st
, @FObj
);
5839 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
5840 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
5841 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
5842 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
5844 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
5845 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
5846 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
5848 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
5849 // Íàëè÷èå êðàñíîãî êëþ÷à
5850 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
5851 // Íàëè÷èå çåëåíîãî êëþ÷à
5852 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
5853 // Íàëè÷èå ñèíåãî êëþ÷à
5854 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
5856 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
5857 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
5858 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
5859 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
5860 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
5862 utils
.writeStr(st
, FModel
.Name
);
5864 utils
.writeInt(st
, Byte(FColor
.R
));
5865 utils
.writeInt(st
, Byte(FColor
.G
));
5866 utils
.writeInt(st
, Byte(FColor
.B
));
5870 procedure TPlayer
.LoadState (st
: TStream
);
5879 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
5880 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
5882 FIamBot
:= utils
.readBool(st
);
5884 FUID
:= utils
.readWord(st
);
5886 str
:= utils
.readStr(st
);
5887 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
5889 FTeam
:= utils
.readByte(st
);
5891 FAlive
:= utils
.readBool(st
);
5892 // Èçðàñõîäîâàë ëè âñå æèçíè
5893 FNoRespawn
:= utils
.readBool(st
);
5895 b
:= utils
.readByte(st
);
5896 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
5898 FHealth
:= utils
.readLongInt(st
);
5900 FLives
:= utils
.readByte(st
);
5902 FArmor
:= utils
.readLongInt(st
);
5904 FAir
:= utils
.readLongInt(st
);
5906 FJetFuel
:= utils
.readLongInt(st
);
5908 FPain
:= utils
.readLongInt(st
);
5910 FKills
:= utils
.readLongInt(st
);
5912 FMonsterKills
:= utils
.readLongInt(st
);
5914 FFrags
:= utils
.readLongInt(st
);
5916 FFragCombo
:= utils
.readByte(st
);
5917 // Âðåìÿ ïîñëåäíåãî ôðàãà
5918 FLastFrag
:= utils
.readLongWord(st
);
5920 FDeath
:= utils
.readLongInt(st
);
5922 FFlag
:= utils
.readByte(st
);
5924 FSecrets
:= utils
.readLongInt(st
);
5926 FCurrWeap
:= utils
.readByte(st
);
5928 FNextWeap
:= utils
.readWord(st
);
5930 FNextWeapDelay
:= utils
.readByte(st
);
5931 // Âðåìÿ çàðÿäêè BFG
5932 FBFGFireCounter
:= utils
.readSmallInt(st
);
5934 FDamageBuffer
:= utils
.readLongInt(st
);
5935 // Ïîñëåäíèé óäàðèâøèé
5936 FLastSpawnerUID
:= utils
.readWord(st
);
5937 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
5938 FLastHit
:= utils
.readByte(st
);
5940 Obj_LoadState(@FObj
, st
);
5941 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
5942 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
5943 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
5944 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
5946 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
5947 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
5948 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
5950 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
5951 // Íàëè÷èå êðàñíîãî êëþ÷à
5952 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
5953 // Íàëè÷èå çåëåíîãî êëþ÷à
5954 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
5955 // Íàëè÷èå ñèíåãî êëþ÷à
5956 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
5958 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
5959 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
5960 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
5961 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
5962 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
5964 str
:= utils
.readStr(st
);
5966 FColor
.R
:= utils
.readByte(st
);
5967 FColor
.G
:= utils
.readByte(st
);
5968 FColor
.B
:= utils
.readByte(st
);
5969 if (self
= gPlayer1
) then
5971 str
:= gPlayer1Settings
.Model
;
5972 FColor
:= gPlayer1Settings
.Color
;
5974 else if (self
= gPlayer2
) then
5976 str
:= gPlayer2Settings
.Model
;
5977 FColor
:= gPlayer2Settings
.Color
;
5979 // Îáíîâëÿåì ìîäåëü èãðîêà
5981 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
5982 FModel
.Color
:= TEAMCOLOR
[FTeam
]
5984 FModel
.Color
:= FColor
;
5988 procedure TPlayer
.AllRulez(Health
: Boolean);
5994 FHealth
:= PLAYER_HP_LIMIT
;
5995 FArmor
:= PLAYER_AP_LIMIT
;
5999 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
6000 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
6001 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6004 procedure TPlayer
.RestoreHealthArmor();
6006 FHealth
:= PLAYER_HP_LIMIT
;
6007 FArmor
:= PLAYER_AP_LIMIT
;
6010 procedure TPlayer
.FragCombo();
6014 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6016 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6018 if FFragCombo
< 5 then
6020 Param
:= FUID
or (FFragCombo
shl 16);
6021 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6022 (FComboEvnt
<= High(gDelayedEvents
)) and
6023 gDelayedEvents
[FComboEvnt
].Pending
and
6024 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6025 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6027 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6028 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6031 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6039 procedure TPlayer
.GiveItem(ItemType
: Byte);
6043 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6045 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6049 if FAir
< AIR_MAX
then
6056 if not (R_BERSERK
in FRulez
) then
6058 Include(FRulez
, R_BERSERK
);
6059 if FBFGFireCounter
< 1 then
6061 FCurrWeap
:= WEAPON_KASTET
;
6063 FModel
.SetWeapon(WEAPON_KASTET
);
6067 FBerserk
:= gTime
+30000;
6069 if FHealth
< PLAYER_HP_SOFT
then
6071 FHealth
:= PLAYER_HP_SOFT
;
6072 FBerserk
:= gTime
+30000;
6077 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6079 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6083 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6085 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6089 if FJetFuel
< JET_MAX
then
6091 FJetFuel
:= JET_MAX
;
6094 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6095 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6097 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6098 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6100 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6102 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6104 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6105 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6108 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6109 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6110 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6111 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6112 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6113 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6114 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6115 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6116 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6118 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6119 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6120 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6121 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6122 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6123 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6124 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6125 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6126 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6129 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6130 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6131 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6132 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6133 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6135 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6136 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6137 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6138 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6139 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6141 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6142 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6143 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6144 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6146 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6149 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6150 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6151 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6153 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6154 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6159 if g_Game_IsNet
and g_Game_IsServer
then
6160 MH_SEND_PlayerStats(FUID
);
6163 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6168 if (Random(5) = 1) and (Times
= 1) then
6171 if BodyInLiquid(0, 0) then
6173 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6174 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6175 if Random(2) = 0 then
6176 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6178 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6182 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6184 for i
:= 1 to Times
do
6186 Anim
:= TAnimation
.Create(id
, False, 3);
6188 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6189 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6195 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6200 if (Random(10) = 1) and (Times
= 1) then
6203 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6205 for i
:= 1 to Times
do
6207 Anim
:= TAnimation
.Create(id
, False, 3);
6209 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6210 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6216 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6218 FSawSound
.Pause(Enable
);
6219 FSawSoundIdle
.Pause(Enable
);
6220 FSawSoundHit
.Pause(Enable
);
6221 FSawSoundSelect
.Pause(Enable
);
6226 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6231 FObj
.Rect
:= PLAYER_CORPSERECT
;
6232 FModelName
:= ModelName
;
6237 FState
:= CORPSE_STATE_MESS
;
6238 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6242 FState
:= CORPSE_STATE_NORMAL
;
6243 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6247 destructor TCorpse
.Destroy();
6254 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6256 procedure TCorpse
.positionChanged (); inline; begin end;
6258 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6260 if (dx
<> 0) or (dy
<> 0) then
6269 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6271 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6272 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6273 w
:= PLAYER_CORPSERECT
.Width
;
6274 h
:= PLAYER_CORPSERECT
.Height
;
6278 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6282 if FState
= CORPSE_STATE_REMOVEME
then
6285 FDamage
:= FDamage
+ Value
;
6287 if FDamage
> 150 then
6289 if FAnimation
<> nil then
6294 FState
:= CORPSE_STATE_REMOVEME
;
6296 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6297 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6298 FModelName
, FColor
);
6299 // Çâóê ìÿñà îò òðóïà:
6300 pm
:= g_PlayerModel_Get(FModelName
);
6301 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6307 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6308 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6309 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6310 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6311 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6316 procedure TCorpse
.Draw();
6318 if FState
= CORPSE_STATE_REMOVEME
then
6321 if FAnimation
<> nil then
6322 FAnimation
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6324 if FAnimationMask
<> nil then
6327 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6334 procedure TCorpse
.Update();
6338 if FState
= CORPSE_STATE_REMOVEME
then
6341 if gTime
mod (GAME_TICK
*2) <> 0 then
6343 g_Obj_Move(@FObj
, True, True, True);
6344 positionChanged(); // this updates spatial accelerators
6348 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6349 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6351 st
:= g_Obj_Move(@FObj
, True, True, True);
6352 positionChanged(); // this updates spatial accelerators
6354 if WordBool(st
and MOVE_FALLOUT
) then
6356 FState
:= CORPSE_STATE_REMOVEME
;
6360 if FAnimation
<> nil then
6361 FAnimation
.Update();
6362 if FAnimationMask
<> nil then
6363 FAnimationMask
.Update();
6367 procedure TCorpse
.SaveState (st
: TStream
);
6374 utils
.writeSign(st
, 'CORP');
6375 utils
.writeInt(st
, Byte(0));
6377 utils
.writeInt(st
, Byte(FState
));
6379 utils
.writeInt(st
, Byte(FDamage
));
6381 utils
.writeInt(st
, Byte(FColor
.R
));
6382 utils
.writeInt(st
, Byte(FColor
.G
));
6383 utils
.writeInt(st
, Byte(FColor
.B
));
6385 Obj_SaveState(st
, @FObj
);
6387 anim
:= (FAnimation
<> nil);
6388 utils
.writeBool(st
, anim
);
6389 // Åñëè åñòü - ñîõðàíÿåì
6390 if anim
then FAnimation
.SaveState(st
);
6391 // Åñòü ëè ìàñêà àíèìàöèè
6392 anim
:= (FAnimationMask
<> nil);
6393 utils
.writeBool(st
, anim
);
6394 // Åñëè åñòü - ñîõðàíÿåì
6395 if anim
then FAnimationMask
.SaveState(st
);
6399 procedure TCorpse
.LoadState (st
: TStream
);
6406 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6407 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6409 FState
:= utils
.readByte(st
);
6411 FDamage
:= utils
.readByte(st
);
6413 FColor
.R
:= utils
.readByte(st
);
6414 FColor
.G
:= utils
.readByte(st
);
6415 FColor
.B
:= utils
.readByte(st
);
6417 Obj_LoadState(@FObj
, st
);
6419 anim
:= utils
.readBool(st
);
6420 // Åñëè åñòü - çàãðóæàåì
6423 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6424 FAnimation
.LoadState(st
);
6426 // Åñòü ëè ìàñêà àíèìàöèè
6427 anim
:= utils
.readBool(st
);
6428 // Åñëè åñòü - çàãðóæàåì
6431 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6432 FAnimationMask
.LoadState(st
);
6438 constructor TBot
.Create();
6445 FSpectator
:= False;
6452 for a
:= WP_FIRST
to WP_LAST
do
6454 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6455 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6456 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6460 destructor TBot
.Destroy();
6463 inherited Destroy();
6466 procedure TBot
.Draw();
6470 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6471 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6474 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6476 inherited Respawn(Silent
, Force
);
6479 FSelectedWeapon
:= FCurrWeap
;
6484 procedure TBot
.UpdateCombat();
6497 TTargetRecord
= array of TTarget
;
6499 function Compare(a
, b
: TTarget
): Integer;
6501 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6504 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6506 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6507 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6509 if a
.Dist
> b
.Dist
then // B áëèæå
6511 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6514 else // Ñòðàííî -> A
6519 a
, x1
, y1
, x2
, y2
: Integer;
6520 targets
: TTargetRecord
;
6522 Target
, BestTarget
: TTarget
;
6523 firew
, fireh
: Integer;
6527 vsPlayer
, vsMonster
, ok
: Boolean;
6530 function monsUpdate (mon
: TMonster
): Boolean;
6532 result
:= false; // don't stop
6533 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6535 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6537 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6538 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6540 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6541 if g_TraceVector(x1
, y1
, x2
, y2
) then
6543 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6544 SetLength(targets
, Length(targets
)+1);
6545 with targets
[High(targets
)] do
6552 Rect
:= mon
.Obj
.Rect
;
6553 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6554 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6555 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6564 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6565 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6567 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6568 if FCurrWeap
<> FSelectedWeapon
then
6571 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6572 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6574 RemoveAIFlag('NEEDFIRE');
6577 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6578 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6579 else PressKey(KEY_FIRE
);
6583 // Êîîðäèíàòû ñòâîëà:
6584 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6585 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6587 Target
.UID
:= FTargetUID
;
6590 if Target
.UID
<> 0 then
6591 begin // Öåëü åñòü - íàñòðàèâàåì
6592 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6595 tpla
:= g_Player_Get(Target
.UID
);
6599 if (@FObj
) <> nil then
6606 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6607 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6608 Target
.Rect
:= PLAYER_RECT
;
6609 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6610 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6611 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6612 Target
.IsPlayer
:= True;
6616 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6619 mon
:= g_Monsters_ByUID(Target
.UID
);
6622 Target
.X
:= mon
.Obj
.X
;
6623 Target
.Y
:= mon
.Obj
.Y
;
6625 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6626 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6627 Target
.Rect
:= mon
.Obj
.Rect
;
6628 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6629 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6630 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6631 Target
.IsPlayer
:= False;
6638 begin // Öåëè íåò - îáíóëÿåì
6643 Target
.Visible
:= False;
6644 Target
.Line
:= False;
6645 Target
.IsPlayer
:= False;
6650 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6651 if (not Target
.Line
) or (not Target
.Visible
) then
6655 for a
:= 0 to High(gPlayers
) do
6656 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6657 (gPlayers
[a
].FUID
<> FUID
) and
6658 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6659 (not gPlayers
[a
].NoTarget
) and
6660 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6662 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6663 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6666 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6667 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6669 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6670 if g_TraceVector(x1
, y1
, x2
, y2
) then
6672 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6673 SetLength(targets
, Length(targets
)+1);
6674 with targets
[High(targets
)] do
6676 UID
:= gPlayers
[a
].FUID
;
6677 X
:= gPlayers
[a
].FObj
.X
;
6678 Y
:= gPlayers
[a
].FObj
.Y
;
6681 Rect
:= PLAYER_RECT
;
6682 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6683 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6684 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6692 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6695 // Åñëè åñòü âîçìîæíûå öåëè:
6696 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6697 if targets
<> nil then
6699 // Âûáèðàåì íàèëó÷øóþ öåëü:
6700 BestTarget
:= targets
[0];
6701 if Length(targets
) > 1 then
6702 for a
:= 1 to High(targets
) do
6703 if Compare(BestTarget
, targets
[a
]) = 1 then
6704 BestTarget
:= targets
[a
];
6706 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6707 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6708 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6710 Target
:= BestTarget
;
6712 if (Healthy() = 3) or ((Healthy() = 2)) then
6713 begin // Åñëè çäîðîâû - äîãîíÿåì
6714 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6715 SetAIFlag('GORIGHT', '1');
6716 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6717 SetAIFlag('GOLEFT', '1');
6720 begin // Åñëè ïîáèòû - óáåãàåì
6721 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6722 SetAIFlag('GORIGHT', '1');
6723 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6724 SetAIFlag('GOLEFT', '1');
6727 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6728 SelectWeapon(Abs(x1
-Target
.cX
));
6733 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6734 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6735 if Target
.UID
<> 0 then
6737 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6738 Target
.Y
+ Target
.Rect
.Y
) then
6739 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6740 if (Healthy() = 3) or ((Healthy() = 2)) then
6741 begin // Åñëè çäîðîâû - äîãîíÿåì
6742 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6743 SetAIFlag('GORIGHT', '1');
6744 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6745 SetAIFlag('GOLEFT', '1');
6748 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6750 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6751 SetAIFlag('GORIGHT', '1');
6752 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6753 SetAIFlag('GOLEFT', '1');
6757 begin // Öåëü ïîêà íà "ýêðàíå"
6758 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6759 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6760 FLastVisible
:= gTime
;
6761 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6762 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6764 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6765 SetAIFlag('GORIGHT', '1');
6766 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6767 SetAIFlag('GOLEFT', '1');
6771 // Âûáèðàåì óãîë ââåðõ:
6772 if FDirection
= TDirection
.D_LEFT
then
6773 angle
:= ANGLE_LEFTUP
6775 angle
:= ANGLE_RIGHTUP
;
6777 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6778 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6780 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6781 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6782 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6783 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6784 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6785 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6786 begin // òî íóæíî ñòðåëÿòü ââåðõ
6787 SetAIFlag('NEEDFIRE', '1');
6788 SetAIFlag('NEEDSEEUP', '1');
6791 // Âûáèðàåì óãîë âíèç:
6792 if FDirection
= TDirection
.D_LEFT
then
6793 angle
:= ANGLE_LEFTDOWN
6795 angle
:= ANGLE_RIGHTDOWN
;
6797 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6798 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6800 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6801 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6802 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6803 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6804 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6805 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6806 begin // òî íóæíî ñòðåëÿòü âíèç
6807 SetAIFlag('NEEDFIRE', '1');
6808 SetAIFlag('NEEDSEEDOWN', '1');
6811 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6812 if Target
.Visible
and
6813 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6814 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6816 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6817 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
6818 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6819 begin // òî íóæíî ñòðåëÿòü âïåðåä
6820 SetAIFlag('NEEDFIRE', '1');
6821 SetAIFlag('NEEDSEEDOWN', '');
6822 SetAIFlag('NEEDSEEUP', '');
6824 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6825 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6826 if GetRnd(FDifficult
.CloseJump
) then
6827 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6828 if Abs(FObj
.X
-Target
.X
) < 128 then
6832 if Random(a
) = 0 then
6833 SetAIFlag('NEEDJUMP', '1');
6837 // Åñëè öåëü âñå åùå åñòü:
6838 if Target
.UID
<> 0 then
6839 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
6840 Target
.UID
:= 0 // òî çàáûòü öåëü
6841 else // Åñëè âèäåëè íåäàâíî
6842 begin // íî öåëü óáèëè
6843 if Target
.IsPlayer
then
6844 begin // Öåëü - èãðîê
6845 pla
:= g_Player_Get(Target
.UID
);
6846 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
6847 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6848 Target
.UID
:= 0; // òî çàáûòü öåëü
6851 begin // Öåëü - ìîíñòð
6852 mon
:= g_Monsters_ByUID(Target
.UID
);
6853 if (mon
= nil) or (not mon
.alive
) then
6854 Target
.UID
:= 0; // òî çàáûòü öåëü
6857 end; // if Target.UID <> 0
6859 FTargetUID
:= Target
.UID
;
6861 // Åñëè âîçìîæíûõ öåëåé íåò:
6862 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
6863 if targets
= nil then
6864 if GetAIFlag('ATTACKLEFT') <> '' then
6865 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
6866 RemoveAIFlag('ATTACKLEFT');
6868 SetAIFlag('NEEDJUMP', '1');
6870 if RunDirection() = TDirection
.D_RIGHT
then
6871 begin // Èäåì íå â òó ñòîðîíó
6872 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6873 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
6874 SetAIFlag('NEEDFIRE', '1');
6875 SetAIFlag('GOLEFT', '1');
6879 begin // Èäåì â íóæíóþ ñòîðîíó
6880 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6881 SetAIFlag('NEEDFIRE', '1');
6882 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6883 SetAIFlag('GORIGHT', '1');
6887 if GetAIFlag('ATTACKRIGHT') <> '' then
6888 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
6889 RemoveAIFlag('ATTACKRIGHT');
6891 SetAIFlag('NEEDJUMP', '1');
6893 if RunDirection() = TDirection
.D_LEFT
then
6894 begin // Èäåì íå â òó ñòîðîíó
6895 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6896 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
6897 SetAIFlag('NEEDFIRE', '1');
6898 SetAIFlag('GORIGHT', '1');
6903 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6904 SetAIFlag('NEEDFIRE', '1');
6905 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6906 SetAIFlag('GOLEFT', '1');
6910 //HACK! (does it belongs there?)
6911 RealizeCurrentWeapon();
6913 // Åñëè åñòü âîçìîæíûå öåëè:
6914 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
6915 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6916 for a
:= 0 to High(targets
) do
6918 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
6919 if GetRnd(FDifficult
.DiagFire
) then
6921 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
6922 if FDirection
= TDirection
.D_LEFT
then
6923 angle
:= ANGLE_LEFTUP
6925 angle
:= ANGLE_RIGHTUP
;
6927 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6928 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6930 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6931 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6932 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6933 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6934 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6936 SetAIFlag('NEEDFIRE', '1');
6937 SetAIFlag('NEEDSEEUP', '1');
6940 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
6941 if FDirection
= TDirection
.D_LEFT
then
6942 angle
:= ANGLE_LEFTDOWN
6944 angle
:= ANGLE_RIGHTDOWN
;
6946 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6947 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6949 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6950 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6951 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6952 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6953 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6955 SetAIFlag('NEEDFIRE', '1');
6956 SetAIFlag('NEEDSEEDOWN', '1');
6960 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
6961 if targets
[a
].Line
and targets
[a
].Visible
and
6962 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
6963 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
6965 SetAIFlag('NEEDFIRE', '1');
6970 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
6971 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
6972 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
6973 40+GetInterval(FDifficult
.Cover
, 40)) then
6974 SetAIFlag('NEEDJUMP', '1');
6976 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
6977 ammo
:= GetAmmoByWeapon(FCurrWeap
);
6978 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
6979 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
6981 SetAIFlag('SELECTWEAPON', '1');
6983 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
6984 if GetAIFlag('SELECTWEAPON') = '1' then
6987 RemoveAIFlag('SELECTWEAPON');
6991 procedure TBot
.Update();
7004 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7005 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7007 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7009 if g_debug_BotAIOff
= 3 then
7019 RealizeCurrentWeapon();
7026 procedure TBot
.ReleaseKey(Key
: Byte);
7035 function TBot
.KeyPressed(Key
: Word): Boolean;
7037 Result
:= FKeys
[Key
].Pressed
;
7040 function TBot
.GetAIFlag(aName
: String20
): String20
;
7046 aName
:= LowerCase(aName
);
7048 if FAIFlags
<> nil then
7049 for a
:= 0 to High(FAIFlags
) do
7050 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7052 Result
:= FAIFlags
[a
].Value
;
7057 procedure TBot
.RemoveAIFlag(aName
: String20
);
7061 if FAIFlags
= nil then Exit
;
7063 aName
:= LowerCase(aName
);
7065 for a
:= 0 to High(FAIFlags
) do
7066 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7068 if a
<> High(FAIFlags
) then
7069 for b
:= a
to High(FAIFlags
)-1 do
7070 FAIFlags
[b
] := FAIFlags
[b
+1];
7072 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7077 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7085 aName
:= LowerCase(aName
);
7087 if FAIFlags
<> nil then
7088 for a
:= 0 to High(FAIFlags
) do
7089 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7095 if ok
then FAIFlags
[a
].Value
:= fValue
7098 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7099 with FAIFlags
[High(FAIFlags
)] do
7107 procedure TBot
.UpdateMove
;
7109 procedure GoLeft(Time
: Word = 1);
7111 ReleaseKey(KEY_LEFT
);
7112 ReleaseKey(KEY_RIGHT
);
7113 PressKey(KEY_LEFT
, Time
);
7114 SetDirection(TDirection
.D_LEFT
);
7117 procedure GoRight(Time
: Word = 1);
7119 ReleaseKey(KEY_LEFT
);
7120 ReleaseKey(KEY_RIGHT
);
7121 PressKey(KEY_RIGHT
, Time
);
7122 SetDirection(TDirection
.D_RIGHT
);
7125 function Rnd(a
: Word): Boolean;
7127 Result
:= Random(a
) = 0;
7130 procedure Turn(Time
: Word = 1200);
7132 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7137 ReleaseKey(KEY_LEFT
);
7138 ReleaseKey(KEY_RIGHT
);
7141 function CanRunLeft(): Boolean;
7143 Result
:= not CollideLevel(-1, 0);
7146 function CanRunRight(): Boolean;
7148 Result
:= not CollideLevel(1, 0);
7151 function CanRun(): Boolean;
7153 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7156 procedure Jump(Time
: Word = 30);
7158 PressKey(KEY_JUMP
, Time
);
7161 function NearHole(): Boolean;
7165 { TODO 5 : Ëåñòíèöû }
7166 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7167 for x
:= 1 to PLAYER_RECT
.Width
do
7168 if (not StayOnStep(x
*sx
, 0)) and
7169 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7170 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7179 function BorderHole(): Boolean;
7183 { TODO 5 : Ëåñòíèöû }
7184 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7185 for x
:= 1 to PLAYER_RECT
.Width
do
7186 if (not StayOnStep(x
*sx
, 0)) and
7187 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7188 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7190 for xx
:= x
to x
+32 do
7191 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7201 function NearDeepHole(): Boolean;
7207 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7210 for x
:= 1 to PLAYER_RECT
.Width
do
7211 if (not StayOnStep(x
*sx
, 0)) and
7212 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7213 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7215 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7217 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7222 end else Result
:= False;
7225 function OverDeepHole(): Boolean;
7232 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7234 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7241 function OnGround(): Boolean;
7243 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7246 function OnLadder(): Boolean;
7248 Result
:= FullInStep(0, 0);
7251 function BelowLadder(): Boolean;
7253 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7254 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7255 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7256 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7259 function BelowLiftUp(): Boolean;
7261 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7262 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7263 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7264 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7267 function OnTopLift(): Boolean;
7269 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7272 function CanJumpOver(): Boolean;
7276 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7280 if not CollideLevel(sx
, 0) then Exit
;
7282 for y
:= 1 to BOT_MAXJUMP
do
7283 if CollideLevel(0, -y
) then Exit
else
7284 if not CollideLevel(sx
, -y
) then
7291 function CanJumpUp(Dist
: ShortInt): Boolean;
7298 if CollideLevel(Dist
, 0) then Exit
;
7301 for y
:= 0 to BOT_MAXJUMP
do
7302 if CollideLevel(Dist
, -y
) then
7311 for yy
:= y
+1 to BOT_MAXJUMP
do
7312 if not CollideLevel(Dist
, -yy
) then
7321 for y
:= 0 to BOT_MAXJUMP
do
7322 if CollideLevel(0, -y
) then
7330 if y
< yy
then Exit
;
7335 function IsSafeTrigger(): Boolean;
7340 if gTriggers
= nil then
7342 for a
:= 0 to High(gTriggers
) do
7343 if Collide(gTriggers
[a
].X
,
7346 gTriggers
[a
].Height
) and
7347 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7348 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7349 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7350 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7351 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7356 // Âîçìîæíî, íàæèìàåì êíîïêó:
7357 if Rnd(16) and IsSafeTrigger() then
7360 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7361 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7363 ReleaseKey(KEY_LEFT
);
7364 ReleaseKey(KEY_RIGHT
);
7368 // Èäåì âëåâî, åñëè íàäî áûëî:
7369 if GetAIFlag('GOLEFT') <> '' then
7371 RemoveAIFlag('GOLEFT');
7372 if CanRunLeft() then
7376 // Èäåì âïðàâî, åñëè íàäî áûëî:
7377 if GetAIFlag('GORIGHT') <> '' then
7379 RemoveAIFlag('GORIGHT');
7380 if CanRunRight() then
7384 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7385 if FObj
.X
< -32 then
7388 if FObj
.X
+32 > gMapInfo
.Width
then
7391 // Ïðûãàåì, åñëè íàäî áûëî:
7392 if GetAIFlag('NEEDJUMP') <> '' then
7395 RemoveAIFlag('NEEDJUMP');
7398 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7399 if GetAIFlag('NEEDSEEUP') <> '' then
7402 ReleaseKey(KEY_DOWN
);
7403 PressKey(KEY_UP
, 20);
7404 RemoveAIFlag('NEEDSEEUP');
7407 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7408 if GetAIFlag('NEEDSEEDOWN') <> '' then
7411 ReleaseKey(KEY_DOWN
);
7412 PressKey(KEY_DOWN
, 20);
7413 RemoveAIFlag('NEEDSEEDOWN');
7416 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7417 if GetAIFlag('GOINHOLE') <> '' then
7418 if not OnGround() then
7420 ReleaseKey(KEY_LEFT
);
7421 ReleaseKey(KEY_RIGHT
);
7422 RemoveAIFlag('GOINHOLE');
7423 SetAIFlag('FALLINHOLE', '1');
7426 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7427 if GetAIFlag('FALLINHOLE') <> '' then
7429 RemoveAIFlag('FALLINHOLE');
7431 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7432 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7433 if GetAIFlag('FALLINHOLE') = '' then
7434 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7440 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7442 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7446 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7447 if OnGround() and NearHole() then
7448 if NearDeepHole() then // Åñëè ýòî áåçäíà
7450 0..3: Turn(); // Áåæèì îáðàòíî
7451 4: Jump(); // Ïðûãàåì
7452 5: begin // Ïðûãàåì îáðàòíî
7457 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7458 if GetAIFlag('GOINHOLE') = '' then
7460 0: Turn(); // Íå íóæíî òóäà
7461 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7462 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7463 if BorderHole() then
7464 SetAIFlag('GOINHOLE', '1');
7467 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7468 if (not CanRun()) and OnGround() then
7470 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7471 if CanJumpOver() or OnLadder() then
7473 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7474 if Random(2) = 0 then
7476 if IsSafeTrigger() then
7482 // Îñòàëîñü ìàëî âîçäóõà:
7483 if FAir
< 36 * 2 then
7486 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7487 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7488 if BodyInAcid(0, 0) then
7492 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7494 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7495 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7498 {function TBot.NeedItem(Item: Byte): Byte;
7503 procedure TBot
.SelectWeapon(Dist
: Integer);
7507 function HaveAmmo(weapon
: Byte): Boolean;
7510 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7511 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7512 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7513 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7514 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7515 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7516 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7517 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7518 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7519 else Result
:= True;
7524 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7526 if Dist
> BOT_LONGDIST
then
7527 begin // Äàëüíèé áîé
7529 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7531 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7535 else //if Dist > BOT_UNSAFEDIST then
7536 begin // Áëèæíèé áîé
7538 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7540 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7547 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7549 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7555 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7557 Result
:= inherited PickItem(ItemType
, force
, remove
);
7559 if Result
then SetAIFlag('SELECTWEAPON', '1');
7562 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7564 Result
:= inherited Heal(value
, Soft
);
7567 function TBot
.Healthy(): Byte;
7569 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7570 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7571 else if (FHealth
> 50) then Result
:= 2
7572 else if (FHealth
> 20) then Result
:= 1
7576 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7578 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7579 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7582 procedure TBot
.OnDamage(Angle
: SmallInt);
7590 if (Angle
= 0) or (Angle
= 180) then
7593 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7594 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7596 pla
:= g_Player_Get(FLastSpawnerUID
);
7597 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7598 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7601 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7602 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7604 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7605 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7606 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7611 SetAIFlag('ATTACKLEFT', '1')
7613 SetAIFlag('ATTACKRIGHT', '1');
7617 function TBot
.RunDirection(): TDirection
;
7619 if Abs(Vel
.X
) >= 1 then
7621 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7623 Result
:= FDirection
;
7626 function TBot
.GetRnd(a
: Byte): Boolean;
7628 if a
= 0 then Result
:= False
7629 else if a
= 255 then Result
:= True
7630 else Result
:= Random(256) > 255-a
;
7633 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7635 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7639 procedure TDifficult
.save (st
: TStream
);
7641 utils
.writeInt(st
, Byte(DiagFire
));
7642 utils
.writeInt(st
, Byte(InvisFire
));
7643 utils
.writeInt(st
, Byte(DiagPrecision
));
7644 utils
.writeInt(st
, Byte(FlyPrecision
));
7645 utils
.writeInt(st
, Byte(Cover
));
7646 utils
.writeInt(st
, Byte(CloseJump
));
7647 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7648 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7651 procedure TDifficult
.load (st
: TStream
);
7653 DiagFire
:= utils
.readByte(st
);
7654 InvisFire
:= utils
.readByte(st
);
7655 DiagPrecision
:= utils
.readByte(st
);
7656 FlyPrecision
:= utils
.readByte(st
);
7657 Cover
:= utils
.readByte(st
);
7658 CloseJump
:= utils
.readByte(st
);
7659 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7660 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7664 procedure TBot
.SaveState (st
: TStream
);
7669 inherited SaveState(st
);
7670 utils
.writeSign(st
, 'BOT0');
7672 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7674 utils
.writeInt(st
, Word(FTargetUID
));
7675 // Âðåìÿ ïîòåðè öåëè
7676 utils
.writeInt(st
, LongWord(FLastVisible
));
7677 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7678 dw
:= Length(FAIFlags
);
7679 utils
.writeInt(st
, LongInt(dw
));
7681 for i
:= 0 to dw
-1 do
7683 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7684 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7686 // Íàñòðîéêè ñëîæíîñòè
7687 FDifficult
.save(st
);
7691 procedure TBot
.LoadState (st
: TStream
);
7696 inherited LoadState(st
);
7697 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7699 FSelectedWeapon
:= utils
.readByte(st
);
7701 FTargetUID
:= utils
.readWord(st
);
7702 // Âðåìÿ ïîòåðè öåëè
7703 FLastVisible
:= utils
.readLongWord(st
);
7704 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7705 dw
:= utils
.readLongInt(st
);
7706 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7707 SetLength(FAIFlags
, dw
);
7709 for i
:= 0 to dw
-1 do
7711 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7712 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7714 // Íàñòðîéêè ñëîæíîñòè
7715 FDifficult
.load(st
);
7720 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);