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();
596 {$IFDEF ENABLE_HOLMES}
599 e_log
, g_map
, g_items
, g_console
, g_gfx
, Math
,
600 g_options
, g_triggers
, g_menu
, g_game
, g_grid
,
601 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
,
602 g_net
, g_netmsg
, g_window
,
605 const PLR_SAVE_VERSION
= 0;
615 diag_precision
: Byte;
619 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
620 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
621 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
625 TIME_RESPAWN1
= 1500;
626 TIME_RESPAWN2
= 2000;
627 TIME_RESPAWN3
= 3000;
630 JET_MAX
= 540; // ~30 sec
631 PLAYER_SUIT_TIME
= 30000;
632 PLAYER_INVUL_TIME
= 30000;
633 PLAYER_INVIS_TIME
= 35000;
634 FRAG_COMBO_TIME
= 3000;
638 ANGLE_RIGHTDOWN
= -35;
640 ANGLE_LEFTDOWN
= -145;
641 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
642 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
645 BOT_UNSAFEDIST
= 128;
646 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
648 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
649 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
650 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
651 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
652 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
653 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
654 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
655 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
656 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
657 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
658 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
659 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
660 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
661 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
662 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
663 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
664 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
665 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
666 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
667 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
668 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
669 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
670 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
671 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
672 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
673 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
675 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
676 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
678 BOTNAMES_FILENAME
= 'botnames.txt';
679 BOTLIST_FILENAME
= 'botlist.txt';
683 MaxCorpses
: Word = 20;
684 MaxShells
: Word = 300;
685 CurrentGib
: Integer = 0;
686 CurrentShell
: Integer = 0;
687 BotNames
: Array of String;
688 BotList
: Array of TBotProfile
;
691 function Lerp(X
, Y
, Factor
: Integer): Integer;
693 Result
:= X
+ ((Y
- X
) div Factor
);
696 function SameTeam(UID1
, UID2
: Word): Boolean;
700 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
701 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
703 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
705 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
706 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
708 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
711 procedure g_Gibs_SetMax(Count
: Word);
714 SetLength(gGibs
, Count
);
716 if CurrentGib
>= Count
then
720 function g_Gibs_GetMax(): Word;
725 procedure g_Shells_SetMax(Count
: Word);
728 SetLength(gShells
, Count
);
730 if CurrentShell
>= Count
then
734 function g_Shells_GetMax(): Word;
740 procedure g_Corpses_SetMax(Count
: Word);
743 SetLength(gCorpses
, Count
);
746 function g_Corpses_GetMax(): Word;
748 Result
:= MaxCorpses
;
751 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
761 // Åñòü ëè ìåñòî â gPlayers:
762 if gPlayers
<> nil then
763 for a
:= 0 to High(gPlayers
) do
764 if gPlayers
[a
] = nil then
770 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
773 SetLength(gPlayers
, Length(gPlayers
)+1);
777 // Ñîçäàåì îáúåêò èãðîêà:
779 gPlayers
[a
] := TBot
.Create()
781 gPlayers
[a
] := TPlayer
.Create();
784 gPlayers
[a
].FActualModelName
:= ModelName
;
785 gPlayers
[a
].SetModel(ModelName
);
787 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
788 if gPlayers
[a
].FModel
= nil then
792 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
796 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
797 if Random(2) = 0 then
801 gPlayers
[a
].FPreferredTeam
:= Team
;
803 case gGameSettings
.GameMode
of
804 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
806 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
808 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
811 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
812 gPlayers
[a
].FColor
:= Color
;
813 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
814 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
816 gPlayers
[a
].FModel
.Color
:= Color
;
818 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
819 gPlayers
[a
].FAlive
:= False;
821 Result
:= gPlayers
[a
].FUID
;
824 function g_Player_CreateFromState (st
: TStream
): Word;
831 if (st
= nil) then exit
; //???
834 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
835 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
838 Bot
:= utils
.readBool(st
);
843 // Åñòü ëè ìåñòî â gPlayers:
844 for a
:= 0 to High(gPlayers
) do if (gPlayers
[a
] = nil) then begin ok
:= true; break
; end;
846 // Íåò ìåñòà - ðàñøèðÿåì gPlayers
849 SetLength(gPlayers
, Length(gPlayers
)+1);
853 // Ñîçäàåì îáúåêò èãðîêà
855 gPlayers
[a
] := TBot
.Create()
857 gPlayers
[a
] := TPlayer
.Create();
858 gPlayers
[a
].FIamBot
:= Bot
;
859 gPlayers
[a
].FPhysics
:= True;
862 gPlayers
[a
].FUID
:= utils
.readWord(st
);
864 gPlayers
[a
].FName
:= utils
.readStr(st
);
866 gPlayers
[a
].FTeam
:= utils
.readByte(st
);
867 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
869 gPlayers
[a
].FAlive
:= utils
.readBool(st
);
870 // Èçðàñõîäîâàë ëè âñå æèçíè
871 gPlayers
[a
].FNoRespawn
:= utils
.readBool(st
);
873 b
:= utils
.readByte(st
);
874 if b
= 1 then gPlayers
[a
].FDirection
:= TDirection
.D_LEFT
else gPlayers
[a
].FDirection
:= TDirection
.D_RIGHT
; // b = 2
876 gPlayers
[a
].FHealth
:= utils
.readLongInt(st
);
878 gPlayers
[a
].FLives
:= utils
.readByte(st
);
880 gPlayers
[a
].FArmor
:= utils
.readLongInt(st
);
882 gPlayers
[a
].FAir
:= utils
.readLongInt(st
);
884 gPlayers
[a
].FJetFuel
:= utils
.readLongInt(st
);
886 gPlayers
[a
].FPain
:= utils
.readLongInt(st
);
888 gPlayers
[a
].FKills
:= utils
.readLongInt(st
);
890 gPlayers
[a
].FMonsterKills
:= utils
.readLongInt(st
);
892 gPlayers
[a
].FFrags
:= utils
.readLongInt(st
);
894 gPlayers
[a
].FFragCombo
:= utils
.readByte(st
);
895 // Âðåìÿ ïîñëåäíåãî ôðàãà
896 gPlayers
[a
].FLastFrag
:= utils
.readLongWord(st
);
898 gPlayers
[a
].FDeath
:= utils
.readLongInt(st
);
900 gPlayers
[a
].FFlag
:= utils
.readByte(st
);
902 gPlayers
[a
].FSecrets
:= utils
.readLongInt(st
);
904 gPlayers
[a
].FCurrWeap
:= utils
.readByte(st
);
905 // Ñëåäóþùåå æåëàåìîå îðóæèå
906 gPlayers
[a
].FNextWeap
:= utils
.readWord(st
);
908 gPlayers
[a
].FNextWeapDelay
:= utils
.readByte(st
);
910 gPlayers
[a
].FBFGFireCounter
:= utils
.readSmallInt(st
);
912 gPlayers
[a
].FDamageBuffer
:= utils
.readLongInt(st
);
913 // Ïîñëåäíèé óäàðèâøèé
914 gPlayers
[a
].FLastSpawnerUID
:= utils
.readWord(st
);
915 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
916 gPlayers
[a
].FLastHit
:= utils
.readByte(st
);
918 Obj_LoadState(@gPlayers
[a
].FObj
, st
);
919 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
920 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FAmmo
[i
] := utils
.readWord(st
);
921 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
922 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FMaxAmmo
[i
] := utils
.readWord(st
);
924 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FWeapon
[i
] := utils
.readBool(st
);
925 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
926 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FReloading
[i
] := utils
.readWord(st
);
928 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
929 // Íàëè÷èå êðàñíîãî êëþ÷à
930 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
931 // Íàëè÷èå çåëåíîãî êëþ÷à
932 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
933 // Íàëè÷èå ñèíåãî êëþ÷à
934 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
936 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_BERSERK
);
937 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
938 for i
:= MR_SUIT
to MR_MAX
do gPlayers
[a
].FMegaRulez
[i
] := utils
.readLongWord(st
);
939 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
940 for i
:= T_RESPAWN
to T_FLAGCAP
do gPlayers
[a
].FTime
[i
] := utils
.readLongWord(st
);
943 gPlayers
[a
].FActualModelName
:= utils
.readStr(st
);
945 gPlayers
[a
].FColor
.R
:= utils
.readByte(st
);
946 gPlayers
[a
].FColor
.G
:= utils
.readByte(st
);
947 gPlayers
[a
].FColor
.B
:= utils
.readByte(st
);
948 // Îáíîâëÿåì ìîäåëü èãðîêà
949 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
951 // Íåò ìîäåëè - ñîçäàíèå íåâîçìîæíî
952 if (gPlayers
[a
].FModel
= nil) then
956 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
960 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû
961 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
962 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
964 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
966 result
:= gPlayers
[a
].FUID
;
970 procedure g_Player_ResetTeams();
974 if g_Game_IsClient
then
976 if gPlayers
= nil then
978 for a
:= Low(gPlayers
) to High(gPlayers
) do
979 if gPlayers
[a
] <> nil then
980 case gGameSettings
.GameMode
of
982 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
984 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
985 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
986 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
989 gPlayers
[a
].ChangeTeam(TEAM_RED
)
991 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
994 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
998 procedure g_Bot_Add(Team
, Difficult
: Byte);
1001 _name
, _model
: String;
1004 if not g_Game_IsServer
then Exit
;
1006 // Ñïèñîê íàçâàíèé ìîäåëåé:
1007 m
:= g_PlayerModel_GetNames();
1012 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1013 Team
:= TEAM_COOP
// COOP
1015 if gGameSettings
.GameMode
= GM_DM
then
1016 Team
:= TEAM_NONE
// DM
1018 if Team
= TEAM_NONE
then // CTF / TDM
1020 // Àâòîáàëàíñ êîìàíä:
1024 for a
:= 0 to High(gPlayers
) do
1025 if gPlayers
[a
] <> nil then
1027 if gPlayers
[a
].Team
= TEAM_RED
then
1030 if gPlayers
[a
].Team
= TEAM_BLUE
then
1040 if Random(2) = 0 then
1046 // Âûáèðàåì áîòó èìÿ:
1048 if BotNames
<> nil then
1049 for a
:= 0 to High(BotNames
) do
1050 if g_Player_ValidName(BotNames
[a
]) then
1052 _name
:= BotNames
[a
];
1056 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
1059 _name
:= Format('DFBOT%.2d', [Random(100)]);
1060 until g_Player_ValidName(_name
);
1062 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1063 _model
:= m
[Random(Length(m
))];
1066 with g_Player_Get(g_Player_Create(_model
,
1067 _RGB(Min(Random(9)*32, 255),
1068 Min(Random(9)*32, 255),
1069 Min(Random(9)*32, 255)),
1070 Team
, True)) as TBot
do
1075 1: FDifficult
:= DIFFICULT_EASY
;
1076 2: FDifficult
:= DIFFICULT_MEDIUM
;
1077 else FDifficult
:= DIFFICULT_HARD
;
1080 for a
:= WP_FIRST
to WP_LAST
do
1082 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1083 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1084 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1087 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1089 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1090 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1095 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1);
1098 _name
, _model
: String;
1101 if not g_Game_IsServer
then Exit
;
1103 // Ñïèñîê íàçâàíèé ìîäåëåé:
1104 m
:= g_PlayerModel_GetNames();
1109 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1110 Team
:= TEAM_COOP
// COOP
1112 if gGameSettings
.GameMode
= GM_DM
then
1113 Team
:= TEAM_NONE
// DM
1115 if Team
= TEAM_NONE
then
1116 Team
:= BotList
[num
].team
; // CTF / TDM
1118 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1119 lName
:= AnsiLowerCase(lName
);
1120 if (num
< 0) or (num
> Length(BotList
)-1) then
1122 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1123 for a
:= 0 to High(BotList
) do
1124 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1133 _name
:= BotList
[num
].name
;
1134 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1135 if not g_Player_ValidName(_name
) then
1137 _name
:= Format('DFBOT%.2d', [Random(100)]);
1138 until g_Player_ValidName(_name
);
1141 _model
:= BotList
[num
].model
;
1142 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1143 if not InSArray(_model
, m
) then
1144 _model
:= m
[Random(Length(m
))];
1147 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1151 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1152 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1153 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1154 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1155 FDifficult
.Cover
:= BotList
[num
].cover
;
1156 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1158 for a
:= WP_FIRST
to WP_LAST
do
1160 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1161 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1162 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1165 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1167 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1171 procedure g_Bot_RemoveAll();
1175 if not g_Game_IsServer
then Exit
;
1176 if gPlayers
= nil then Exit
;
1178 for a
:= 0 to High(gPlayers
) do
1179 if gPlayers
[a
] <> nil then
1180 if gPlayers
[a
] is TBot
then
1182 gPlayers
[a
].Lives
:= 0;
1183 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1184 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1185 g_Player_Remove(gPlayers
[a
].FUID
);
1191 procedure g_Bot_MixNames();
1196 if BotNames
<> nil then
1197 for a
:= 0 to High(BotNames
) do
1199 b
:= Random(Length(BotNames
));
1201 Botnames
[a
] := BotNames
[b
];
1206 procedure g_Player_Remove(UID
: Word);
1210 if gPlayers
= nil then Exit
;
1212 if g_Game_IsServer
and g_Game_IsNet
then
1213 MH_SEND_PlayerDelete(UID
);
1215 for i
:= 0 to High(gPlayers
) do
1216 if gPlayers
[i
] <> nil then
1217 if gPlayers
[i
].FUID
= UID
then
1219 if gPlayers
[i
] is TPlayer
then
1220 TPlayer(gPlayers
[i
]).Free()
1222 TBot(gPlayers
[i
]).Free();
1228 procedure g_Player_Init();
1238 if not FileExists(DataDir
+ BOTNAMES_FILENAME
) then
1241 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1242 AssignFile(F
, DataDir
+ BOTNAMES_FILENAME
);
1253 SetLength(BotNames
, Length(BotNames
)+1);
1254 BotNames
[High(BotNames
)] := s
;
1262 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1263 config
:= TConfig
.CreateFile(DataDir
+ BOTLIST_FILENAME
);
1267 while config
.SectionExists(IntToStr(a
)) do
1269 SetLength(BotList
, Length(BotList
)+1);
1271 with BotList
[High(BotList
)] do
1274 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1276 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1278 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1283 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1284 color
.R
:= StrToIntDef(sa
[0], 0);
1285 color
.G
:= StrToIntDef(sa
[1], 0);
1286 color
.B
:= StrToIntDef(sa
[2], 0);
1287 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1288 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1289 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1290 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1291 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1292 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1293 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1294 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1295 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1296 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1297 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1298 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1299 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1300 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1301 if Length(sa
) = 10 then
1303 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1304 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1305 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1306 if Length(sa
) = 10 then
1308 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1310 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1311 if Length(sa) = 10 then
1313 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1322 procedure g_Player_Free();
1326 if gPlayers
<> nil then
1328 for i
:= 0 to High(gPlayers
) do
1329 if gPlayers
[i
] <> nil then
1331 if gPlayers
[i
] is TPlayer
then
1332 TPlayer(gPlayers
[i
]).Free()
1334 TBot(gPlayers
[i
]).Free();
1345 procedure g_Player_UpdateAll();
1349 if gPlayers
= nil then Exit
;
1351 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1352 for i
:= 0 to High(gPlayers
) do
1354 if gPlayers
[i
] <> nil then
1356 if gPlayers
[i
] is TPlayer
then
1358 gPlayers
[i
].Update();
1359 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1363 // bot updates weapons in `UpdateCombat()`
1364 TBot(gPlayers
[i
]).Update();
1368 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1371 procedure g_Player_DrawAll();
1375 if gPlayers
= nil then Exit
;
1377 for i
:= 0 to High(gPlayers
) do
1378 if gPlayers
[i
] <> nil then
1379 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1380 else TBot(gPlayers
[i
]).Draw();
1383 procedure g_Player_DrawDebug(p
: TPlayer
);
1387 if p
= nil then Exit
;
1388 if (@p
.FObj
) = nil then Exit
;
1390 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1392 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1393 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1394 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1395 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1396 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1397 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1400 procedure g_Player_DrawHealth();
1405 if gPlayers
= nil then Exit
;
1406 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1408 for i
:= 0 to High(gPlayers
) do
1409 if gPlayers
[i
] <> nil then
1411 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1412 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1413 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1414 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1415 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1416 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1420 function g_Player_Get(UID
: Word): TPlayer
;
1426 if gPlayers
= nil then
1429 for a
:= 0 to High(gPlayers
) do
1430 if gPlayers
[a
] <> nil then
1431 if gPlayers
[a
].FUID
= UID
then
1433 Result
:= gPlayers
[a
];
1438 function g_Player_GetCount(): Byte;
1444 if gPlayers
= nil then
1447 for a
:= 0 to High(gPlayers
) do
1448 if gPlayers
[a
] <> nil then
1449 Result
:= Result
+ 1;
1452 function g_Player_GetStats(): TPlayerStatArray
;
1458 if gPlayers
= nil then Exit
;
1460 for a
:= 0 to High(gPlayers
) do
1461 if gPlayers
[a
] <> nil then
1463 SetLength(Result
, Length(Result
)+1);
1464 with Result
[High(Result
)] do
1466 Ping
:= gPlayers
[a
].FPing
;
1467 Loss
:= gPlayers
[a
].FLoss
;
1468 Name
:= gPlayers
[a
].FName
;
1469 Team
:= gPlayers
[a
].FTeam
;
1470 Frags
:= gPlayers
[a
].FFrags
;
1471 Deaths
:= gPlayers
[a
].FDeath
;
1472 Kills
:= gPlayers
[a
].FKills
;
1473 Color
:= gPlayers
[a
].FModel
.Color
;
1474 Lives
:= gPlayers
[a
].FLives
;
1475 Spectator
:= gPlayers
[a
].FSpectator
;
1480 procedure g_Player_RememberAll
;
1484 for i
:= Low(gPlayers
) to High(gPlayers
) do
1485 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1486 gPlayers
[i
].RememberState
;
1489 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1493 gTeamStat
[TEAM_RED
].Goals
:= 0;
1494 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1496 if gPlayers
<> nil then
1497 for i
:= 0 to High(gPlayers
) do
1498 if gPlayers
[i
] <> nil then
1500 gPlayers
[i
].Reset(Force
);
1502 if gPlayers
[i
] is TPlayer
then
1504 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1505 gPlayers
[i
].Respawn(Silent
)
1507 gPlayers
[i
].Spectate();
1510 TBot(gPlayers
[i
]).Respawn(Silent
);
1514 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1519 if Player
.alive
then
1521 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1526 if (FHealth
>= -50) or (gGibsCount
= 0) then
1528 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1532 for find_id
:= 0 to High(gCorpses
) do
1533 if gCorpses
[find_id
] = nil then
1540 find_id
:= Random(Length(gCorpses
));
1542 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1543 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1544 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1545 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1548 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1549 FObj
.Y
+ PLAYER_RECT_CY
,
1550 FModel
.Name
, FModel
.Color
);
1554 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1558 if (gShells
= nil) or (Length(gShells
) = 0) then
1561 with gShells
[CurrentShell
] do
1567 if T
= SHELL_BULLET
then
1569 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1573 Obj
.Rect
.Width
:= 4;
1574 Obj
.Rect
.Height
:= 2;
1578 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1582 Obj
.Rect
.Width
:= 7;
1583 Obj
.Rect
.Height
:= 3;
1589 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1590 positionChanged(); // this updates spatial accelerators
1591 RAngle
:= Random(360);
1592 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1594 if CurrentShell
>= High(gShells
) then
1601 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1604 GibsArray
: TGibsArray
;
1606 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1608 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1611 for a
:= 0 to High(GibsArray
) do
1612 with gGibs
[CurrentGib
] do
1615 ID
:= GibsArray
[a
].ID
;
1616 MaskID
:= GibsArray
[a
].MaskID
;
1619 Obj
.Rect
:= GibsArray
[a
].Rect
;
1620 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1621 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1622 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1623 positionChanged(); // this updates spatial accelerators
1624 RAngle
:= Random(360);
1626 if gBloodCount
> 0 then
1627 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1628 Random(48), Random(48), 150, 0, 0);
1630 if CurrentGib
>= High(gGibs
) then
1637 procedure g_Player_UpdatePhysicalObjects();
1643 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1648 if T
= SHELL_BULLET
then
1649 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1651 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1656 if gGibs
<> nil then
1657 for i
:= 0 to High(gGibs
) do
1658 if gGibs
[i
].alive
then
1662 mr
:= g_Obj_Move(@Obj
, True, False, True);
1663 positionChanged(); // this updates spatial accelerators
1665 if WordBool(mr
and MOVE_FALLOUT
) then
1671 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1672 if WordBool(mr
and MOVE_HITWALL
) then
1673 Obj
.Vel
.X
:= -(vel
.X
div 2);
1674 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1675 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1677 if (Obj
.Vel
.X
>= 0) then
1679 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1680 if RAngle
>= 360 then
1681 RAngle
:= RAngle
mod 360;
1682 end else begin // Counter-clockwise
1683 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1685 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1688 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1689 if gTime
mod (GAME_TICK
*3) = 0 then
1690 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1694 if gCorpses
<> nil then
1695 for i
:= 0 to High(gCorpses
) do
1696 if gCorpses
[i
] <> nil then
1697 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1703 gCorpses
[i
].Update();
1706 if gShells
<> nil then
1707 for i
:= 0 to High(gShells
) do
1708 if gShells
[i
].alive
then
1712 mr
:= g_Obj_Move(@Obj
, True, False, True);
1713 positionChanged(); // this updates spatial accelerators
1715 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1721 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1722 if WordBool(mr
and MOVE_HITWALL
) then
1724 Obj
.Vel
.X
:= -(vel
.X
div 2);
1725 if not WordBool(mr
and MOVE_INWATER
) then
1726 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1728 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1730 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1731 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1732 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1734 if RAngle
mod 90 <> 0 then
1735 RAngle
:= (RAngle
div 90) * 90;
1737 else if not WordBool(mr
and MOVE_INWATER
) then
1738 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1741 if (Obj
.Vel
.X
>= 0) then
1743 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1744 if RAngle
>= 360 then
1745 RAngle
:= RAngle
mod 360;
1746 end else begin // Counter-clockwise
1747 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1749 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1755 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1757 x
:= Obj
.X
+Obj
.Rect
.X
;
1758 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1759 w
:= Obj
.Rect
.Width
;
1760 h
:= Obj
.Rect
.Height
;
1763 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1765 if (dx
<> 0) or (dy
<> 0) then
1774 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1778 w
:= Obj
.Rect
.Width
;
1779 h
:= Obj
.Rect
.Height
;
1782 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1784 if (dx
<> 0) or (dy
<> 0) then
1793 procedure TGib
.positionChanged (); inline; begin end;
1794 procedure TShell
.positionChanged (); inline; begin end;
1797 procedure g_Player_DrawCorpses();
1802 if gGibs
<> nil then
1803 for i
:= 0 to High(gGibs
) do
1804 if gGibs
[i
].alive
then
1807 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1810 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1811 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1813 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1816 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1822 if gCorpses
<> nil then
1823 for i
:= 0 to High(gCorpses
) do
1824 if gCorpses
[i
] <> nil then
1828 procedure g_Player_DrawShells();
1833 if gShells
<> nil then
1834 for i
:= 0 to High(gShells
) do
1835 if gShells
[i
].alive
then
1838 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1844 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1848 procedure g_Player_RemoveAllCorpses();
1854 SetLength(gGibs
, MaxGibs
);
1855 SetLength(gShells
, MaxGibs
);
1859 if gCorpses
<> nil then
1860 for i
:= 0 to High(gCorpses
) do
1864 SetLength(gCorpses
, MaxCorpses
);
1867 procedure g_Player_Corpses_SaveState (st
: TStream
);
1871 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ
1873 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1875 // Êîëè÷åñòâî òðóïîâ
1876 utils
.writeInt(st
, LongInt(count
));
1878 if (count
= 0) then exit
;
1881 for i
:= 0 to High(gCorpses
) do
1883 if gCorpses
[i
] <> nil then
1886 utils
.writeStr(st
, gCorpses
[i
].FModelName
);
1888 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1889 // Ñîõðàíÿåì äàííûå òðóïà:
1890 gCorpses
[i
].SaveState(st
);
1896 procedure g_Player_Corpses_LoadState (st
: TStream
);
1904 g_Player_RemoveAllCorpses();
1906 // Êîëè÷åñòâî òðóïîâ:
1907 count
:= utils
.readLongInt(st
);
1908 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1910 if (count
= 0) then exit
;
1913 for i
:= 0 to count
-1 do
1916 str
:= utils
.readStr(st
);
1918 b
:= utils
.readBool(st
);
1920 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1921 // Çàãðóæàåì äàííûå òðóïà
1922 gCorpses
[i
].LoadState(st
);
1929 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1931 procedure TPlayer
.BFGHit();
1933 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1934 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1935 if g_Game_IsServer
and g_Game_IsNet
then
1936 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1937 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1941 procedure TPlayer
.ChangeModel(ModelName
: string);
1943 locModel
: TPlayerModel
;
1945 locModel
:= g_PlayerModel_Get(ModelName
);
1946 if locModel
= nil then Exit
;
1952 procedure TPlayer
.SetModel(ModelName
: string);
1956 m
:= g_PlayerModel_Get(ModelName
);
1959 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1960 m
:= g_PlayerModel_Get('doomer');
1963 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1968 if FModel
<> nil then
1973 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1974 FModel
.Color
:= FColor
1976 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1977 FModel
.SetWeapon(FCurrWeap
);
1978 FModel
.SetFlag(FFlag
);
1979 SetDirection(FDirection
);
1982 procedure TPlayer
.SetColor(Color
: TRGB
);
1985 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1986 if FModel
<> nil then FModel
.Color
:= Color
;
1989 procedure TPlayer
.SwitchTeam
;
1991 if g_Game_IsClient
then
1993 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
1995 if gGameOn
and FAlive
then
1996 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
1998 if FTeam
= TEAM_RED
then
2000 ChangeTeam(TEAM_BLUE
);
2001 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
2002 if g_Game_IsNet
then
2003 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
2007 ChangeTeam(TEAM_RED
);
2008 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
2009 if g_Game_IsNet
then
2010 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
2012 FPreferredTeam
:= FTeam
;
2015 procedure TPlayer
.ChangeTeam(Team
: Byte);
2022 TEAM_RED
, TEAM_BLUE
:
2023 FModel
.Color
:= TEAMCOLOR
[Team
];
2025 FModel
.Color
:= FColor
;
2027 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2028 MH_SEND_PlayerStats(FUID
);
2032 procedure TPlayer.CollideItem();
2037 if gItems = nil then Exit;
2038 if not FAlive then Exit;
2040 for i := 0 to High(gItems) do
2043 if (ItemType <> ITEM_NONE) and alive then
2044 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2045 PLAYER_RECT.Height, @Obj) then
2047 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2049 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2050 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2051 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2052 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2053 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2055 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2056 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2057 (gGameSettings.GameType = GT_SINGLE) and
2058 (g_Player_GetCount() > 1)) then
2059 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2065 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2067 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2068 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2072 constructor TPlayer
.Create();
2078 mEDamageType
:= HIT_SOME
;
2084 FSawSound
:= TPlayableSound
.Create();
2085 FSawSoundIdle
:= TPlayableSound
.Create();
2086 FSawSoundHit
:= TPlayableSound
.Create();
2087 FSawSoundSelect
:= TPlayableSound
.Create();
2088 FJetSoundFly
:= TPlayableSound
.Create();
2089 FJetSoundOn
:= TPlayableSound
.Create();
2090 FJetSoundOff
:= TPlayableSound
.Create();
2092 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2093 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2094 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2095 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2096 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2097 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2098 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2100 FSpectatePlayer
:= -1;
2104 FSavedState
.WaitRecall
:= False;
2110 FActualModelName
:= 'doomer';
2113 FObj
.Rect
:= PLAYER_RECT
;
2115 FBFGFireCounter
:= -1;
2116 FJustTeleported
:= False;
2122 procedure TPlayer
.positionChanged (); inline;
2126 procedure TPlayer
.doDamage (v
: Integer);
2128 if (v
<= 0) then exit
;
2129 if (v
> 32767) then v
:= 32767;
2130 Damage(v
, 0, 0, 0, mEDamageType
);
2133 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2137 if (not g_Game_IsClient
) and (not FAlive
) then
2142 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2143 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2145 if not g_Game_IsClient
then
2148 if t
= HIT_TRAP
then
2150 // Ëîâóøêà óáèâàåò ñðàçó:
2152 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2154 if t
= HIT_SELF
then
2158 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2161 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2162 FMegaRulez
[MR_SUIT
] := 0;
2163 FMegaRulez
[MR_INVUL
] := 0;
2164 FMegaRulez
[MR_INVIS
] := 0;
2168 // Íî îò îñòàëüíîãî ñïàñàåò:
2169 if FMegaRulez
[MR_INVUL
] >= gTime
then
2176 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2177 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2178 (SpawnerUID
= FUID
) or
2179 (not SameTeam(FUID
, SpawnerUID
)) then
2181 FLastSpawnerUID
:= SpawnerUID
;
2183 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2184 if gBloodCount
> 0 then
2186 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2187 if value
div 4 <= c
then
2188 c
:= c
- (value
div 4)
2192 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2196 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2197 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2200 if t
= HIT_WATER
then
2201 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2202 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2207 Inc(FDamageBuffer
, value
);
2211 FPain
:= FPain
+ value
;
2214 if g_Game_IsServer
and g_Game_IsNet
then
2216 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2217 MH_SEND_PlayerStats(FUID
);
2218 MH_SEND_PlayerPos(False, FUID
);
2222 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2225 if g_Game_IsClient
then
2230 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2232 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2235 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2237 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2241 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2242 MH_SEND_PlayerStats(FUID
);
2245 destructor TPlayer
.Destroy();
2247 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2249 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2253 FSawSoundIdle
.Free();
2254 FSawSoundHit
.Free();
2255 FJetSoundFly
.Free();
2257 FJetSoundOff
.Free();
2259 if FPunchAnim
<> nil then
2265 procedure TPlayer
.DrawBubble();
2267 bubX
, bubY
: Integer;
2270 Rw
, Gw
, Bw
: SmallInt;
2273 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= TDirection
.D_LEFT
, -4, 18);
2274 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2282 1: // simple textual non-bubble
2284 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2285 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2286 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2289 2: // advanced pixel-perfect bubble
2291 if FTeam
= TEAM_RED
then
2294 if FTeam
= TEAM_BLUE
then
2297 3: // colored bubble
2299 Rb
:= FModel
.Color
.R
;
2300 Gb
:= FModel
.Color
.G
;
2301 Bb
:= FModel
.Color
.B
;
2302 Rw
:= Min(Rb
* 2 + 64, 255);
2303 Gw
:= Min(Gb
* 2 + 64, 255);
2304 Bw
:= Min(Bb
* 2 + 64, 255);
2305 if (Abs(Rw
- Rb
) < 32)
2306 or (Abs(Gw
- Gb
) < 32)
2307 or (Abs(Bw
- Bb
) < 32) then
2309 Rb
:= Max(Rw
div 2 - 16, 0);
2310 Gb
:= Max(Gw
div 2 - 16, 0);
2311 Bb
:= Max(Bw
div 2 - 16, 0);
2314 4: // custom textured bubble
2316 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2317 if FDirection
= TDirection
.D_RIGHT
then
2318 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2320 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, TMirrorType
.Horizontal
);
2326 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2327 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2329 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2332 Dot
:= IfThen(FDirection
= TDirection
.D_LEFT
, 14, 5);
2333 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2334 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
);
2335 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
);
2336 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
);
2337 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
);
2341 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2342 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2343 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2346 procedure TPlayer
.Draw();
2351 Mirror
: TMirrorType
;
2355 if Direction
= TDirection
.D_RIGHT
then
2356 Mirror
:= TMirrorType
.None
2358 Mirror
:= TMirrorType
.Horizontal
;
2360 if FPunchAnim
<> nil then
2361 FPunchAnim
.Draw(FObj
.X
+IfThen(Direction
= TDirection
.D_LEFT
, 15-FObj
.Rect
.X
, FObj
.Rect
.X
-15),
2362 FObj
.Y
+FObj
.Rect
.Y
-11, Mirror
);
2364 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2365 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2367 e_GetTextureSize(ID
, @w
, @h
);
2368 if FDirection
= TDirection
.D_LEFT
then
2369 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2370 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False)
2372 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2373 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False);
2376 if FMegaRulez
[MR_INVIS
] > gTime
then
2378 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2379 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2381 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2382 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2386 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 200)
2388 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2391 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 254);
2394 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2397 if g_debug_Frames
then
2399 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2401 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2402 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2406 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2408 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2409 if gAimLine
and alive
and
2410 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2415 procedure TPlayer
.DrawAim();
2416 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2421 {$IFDEF ENABLE_HOLMES}
2422 if isValidViewPort
and (self
= gPlayer1
) then
2424 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2428 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2429 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2431 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2435 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2440 wx
, wy
, xx
, yy
: Integer;
2444 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= TDirection
.D_LEFT
, 7, -7);
2445 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2454 1: begin // Chainsaw
2461 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2462 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2463 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2464 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2469 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2470 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2471 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2472 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2474 4: begin // Double Shotgun
2477 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2478 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2479 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2480 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2482 5: begin // Chaingun
2485 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2486 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2487 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2488 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2490 6: begin // Rocket Launcher
2493 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2494 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2495 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2496 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2498 7: begin // Plasmagun
2501 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2502 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2503 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2504 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2509 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2510 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2511 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2512 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2514 9: begin // Super Chaingun
2517 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2518 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2519 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2520 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2523 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2524 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2525 {$IF DEFINED(D2F_DEBUG)}
2526 drawCast(sz
, wx
, wy
, xx
, yy
);
2528 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2532 procedure TPlayer
.DrawGUI();
2535 X
, Y
, SY
, a
, p
, m
: Integer;
2539 stat
: TPlayerStatArray
;
2541 X
:= gPlayerScreenSize
.X
;
2542 SY
:= gPlayerScreenSize
.Y
;
2545 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2547 if gGameSettings
.GameMode
= GM_CTF
then
2551 if gGameSettings
.GameMode
= GM_CTF
then
2553 s
:= 'TEXTURE_PLAYER_REDFLAG';
2554 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2555 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2556 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2557 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2558 if g_Texture_Get(s
, ID
) then
2559 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2562 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2563 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2564 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2566 if gGameSettings
.GameMode
= GM_CTF
then
2568 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2569 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2570 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2571 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2572 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2573 if g_Texture_Get(s
, ID
) then
2574 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2577 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2578 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2579 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2582 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2583 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2586 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2587 e_Draw(ID
, X
+2, Y
, 0, True, False);
2589 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2593 s
:= IntToStr(Frags
);
2594 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2595 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2600 stat
:= g_Player_GetStats();
2605 for a
:= 0 to High(stat
) do
2606 if stat
[a
].Name
<> Name
then
2608 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2609 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2613 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2614 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2615 s
:= s
+IntToStr(Abs(Frags
-m
));
2617 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2618 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2621 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2623 s
:= IntToStr(Lives
);
2624 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2625 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2629 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2630 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2632 if R_BERSERK
in FRulez
then
2633 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2635 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2637 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2638 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2640 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2641 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2642 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2644 s
:= IntToStr(FArmor
);
2645 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2646 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2648 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2654 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2659 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2661 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2662 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2663 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2664 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2665 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2666 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2667 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2668 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2669 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2672 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2673 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2674 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2676 if R_KEY_RED
in FRulez
then
2677 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2679 if R_KEY_GREEN
in FRulez
then
2680 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2682 if R_KEY_BLUE
in FRulez
then
2683 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2685 if FJetFuel
> 0 then
2687 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2688 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2689 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2690 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2691 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2692 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2696 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2697 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2698 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2701 if gShowPing
and g_Game_IsClient
then
2703 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2704 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2710 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2711 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2712 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2715 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2716 s
:= _lc
[I_PLAYER_SPECT4
];
2717 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2718 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2719 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2725 procedure TPlayer
.DrawRulez();
2729 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2730 if FMegaRulez
[MR_INVUL
] >= gTime
then
2732 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2733 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2738 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2739 191, 191, 191, 0, TBlending
.Invert
);
2742 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2743 if FMegaRulez
[MR_SUIT
] >= gTime
then
2745 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2746 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2751 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2752 0, 96, 0, 200, TBlending
.None
);
2755 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2756 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2758 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2759 255, 0, 0, 200, TBlending
.None
);
2763 procedure TPlayer
.DrawPain();
2767 if FPain
= 0 then Exit
;
2771 if a
< 15 then h
:= 0
2772 else if a
< 35 then h
:= 1
2773 else if a
< 55 then h
:= 2
2774 else if a
< 75 then h
:= 3
2775 else if a
< 95 then h
:= 4
2778 //if a > 255 then a := 255;
2780 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2781 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2784 procedure TPlayer
.DrawPickup();
2788 if FPickup
= 0 then Exit
;
2792 if a
< 15 then h
:= 1
2793 else if a
< 35 then h
:= 2
2794 else if a
< 55 then h
:= 3
2795 else if a
< 75 then h
:= 4
2798 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2801 procedure TPlayer
.DoPunch();
2805 if FPunchAnim
= nil then begin
2806 g_Frames_Get(id
, 'FRAMES_PUNCH');
2807 FPunchAnim
:= TAnimation
.Create(id
, False, 1);
2812 procedure TPlayer
.Fire();
2814 f
, DidFire
: Boolean;
2815 wx
, wy
, xd
, yd
: Integer;
2818 if g_Game_IsClient
then Exit
;
2819 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2820 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2828 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2833 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2834 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2835 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
2836 yd
:= wy
+firediry();
2841 if R_BERSERK
in FRulez
then
2843 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2844 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2845 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2848 locobj
.rect
.Width
:= 39;
2849 locobj
.rect
.Height
:= 52;
2850 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2851 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2852 locobj
.Accel
.X
:= xd
-wx
;
2853 locobj
.Accel
.y
:= yd
-wy
;
2857 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2858 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2860 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2862 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
2866 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2870 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2875 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2876 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2878 FSawSoundSelect
.Stop();
2880 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2882 else if not FSawSoundHit
.IsPlaying() then
2884 FSawSoundSelect
.Stop();
2885 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2888 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2894 if FAmmo
[A_BULLETS
] > 0 then
2896 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2897 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2898 Dec(FAmmo
[A_BULLETS
]);
2899 FFireAngle
:= FAngle
;
2902 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2903 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2907 if FAmmo
[A_SHELLS
] > 0 then
2909 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2910 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
2911 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2912 Dec(FAmmo
[A_SHELLS
]);
2913 FFireAngle
:= FAngle
;
2917 FShellType
:= SHELL_SHELL
;
2921 if FAmmo
[A_SHELLS
] >= 2 then
2923 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
2924 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2925 Dec(FAmmo
[A_SHELLS
], 2);
2926 FFireAngle
:= FAngle
;
2930 FShellType
:= SHELL_DBLSHELL
;
2934 if FAmmo
[A_BULLETS
] > 0 then
2936 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
2937 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
2938 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2939 Dec(FAmmo
[A_BULLETS
]);
2940 FFireAngle
:= FAngle
;
2943 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2944 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2947 WEAPON_ROCKETLAUNCHER
:
2948 if FAmmo
[A_ROCKETS
] > 0 then
2950 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
2951 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2952 Dec(FAmmo
[A_ROCKETS
]);
2953 FFireAngle
:= FAngle
;
2959 if FAmmo
[A_CELLS
] > 0 then
2961 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
2962 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2963 Dec(FAmmo
[A_CELLS
]);
2964 FFireAngle
:= FAngle
;
2970 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
2972 FBFGFireCounter
:= 17;
2973 if not FNoReload
then
2974 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
2975 Dec(FAmmo
[A_CELLS
], 40);
2979 WEAPON_SUPERPULEMET
:
2980 if FAmmo
[A_SHELLS
] > 0 then
2982 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2983 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
2984 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2985 Dec(FAmmo
[A_SHELLS
]);
2986 FFireAngle
:= FAngle
;
2989 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2990 GameVelX
, GameVelY
-2, SHELL_SHELL
);
2993 WEAPON_FLAMETHROWER
:
2994 if FAmmo
[A_FUEL
] > 0 then
2996 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
2997 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2999 FFireAngle
:= FAngle
;
3005 if g_Game_IsNet
then
3009 if FCurrWeap
<> WEAPON_BFG
then
3010 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
3012 if not FNoReload
then
3013 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
3016 MH_SEND_PlayerStats(FUID
);
3021 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
3022 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
3023 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
3026 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
3029 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
3030 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
3031 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
3032 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
3033 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
3038 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
3040 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
3041 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
3042 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
3045 procedure TPlayer
.JetpackOn
;
3049 FJetSoundOn
.SetPosition(0);
3050 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3054 procedure TPlayer
.JetpackOff
;
3058 FJetSoundOff
.SetPosition(0);
3059 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3062 procedure TPlayer
.CatchFire(Attacker
: Word);
3065 FFireAttacker
:= Attacker
;
3066 if g_Game_IsNet
and g_Game_IsServer
then
3067 MH_SEND_PlayerStats(FUID
);
3070 procedure TPlayer
.Jump();
3072 if gFly
or FJetpack
then
3074 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3075 if FObj
.Vel
.Y
> -VEL_FLY
then
3076 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3079 if FJetFuel
> 0 then
3081 if (FJetFuel
< 1) and g_Game_IsServer
then
3085 if g_Game_IsNet
then
3086 MH_SEND_PlayerStats(FUID
);
3092 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3094 FCanJetpack
:= False;
3096 // Ïðûãàåì èëè âñïëûâàåì:
3097 if (CollideLevel(0, 1) or
3098 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3099 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3100 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3102 FObj
.Vel
.Y
:= -VEL_JUMP
;
3103 FCanJetpack
:= False;
3107 if BodyInLiquid(0, 0) then
3108 FObj
.Vel
.Y
:= -VEL_SW
3109 else if (FJetFuel
> 0) and FCanJetpack
and
3110 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3114 if g_Game_IsNet
then
3115 MH_SEND_PlayerStats(FUID
);
3120 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3122 a
, i
, k
, ab
, ar
: Byte;
3126 srv
, netsrv
: Boolean;
3132 procedure PushItem(t
: Byte);
3136 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3137 it
:= g_Items_ByIdx(id
);
3138 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3140 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3141 (FObj
.Vel
.Y
div 2)-Random(9));
3142 it
.positionChanged(); // this updates spatial accelerators
3146 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3148 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3149 (FObj
.Vel
.Y
div 2)-Random(6));
3151 else // -3..+3; -3..0
3153 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3154 (FObj
.Vel
.Y
div 2)-Random(4));
3156 it
.positionChanged(); // this updates spatial accelerators
3159 if g_Game_IsNet
and g_Game_IsServer
then
3160 MH_SEND_ItemSpawn(True, id
);
3164 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3165 Srv
:= g_Game_IsServer
;
3166 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3167 if Srv
then FDeath
:= FDeath
+ 1;
3172 if not FPhysics
then
3178 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3180 if FLives
> 0 then FLives
:= FLives
- 1;
3181 if FLives
= 0 then FNoRespawn
:= True;
3184 // Íîìåð òèïà ñìåðòè:
3187 K_SIMPLEKILL
: a
:= 1;
3189 K_EXTRAHARDKILL
: a
:= 3;
3194 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3196 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3203 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3205 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3206 K_EXTRAHARDKILL
, K_FALLKILL
:
3207 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3210 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3214 K_HARDKILL
, K_EXTRAHARDKILL
:
3218 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3219 if (KillType
<> K_FALLKILL
) and (Srv
) then
3220 g_Monsters_killedp();
3222 if SpawnerUID
= FUID
then
3224 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3229 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3232 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3233 begin // Óáèò äðóãèì èãðîêîì
3234 KP
:= g_Player_Get(SpawnerUID
);
3235 if (KP
<> nil) and Srv
then
3237 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3238 if SameTeam(FUID
, SpawnerUID
) then
3248 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3249 Inc(gTeamStat
[KP
.Team
].Goals
,
3250 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3252 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3255 plr
:= g_Player_Get(SpawnerUID
);
3263 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3267 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3271 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3276 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3277 begin // Óáèò ìîíñòðîì
3278 mon
:= g_Monsters_ByUID(SpawnerUID
);
3282 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
3286 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3290 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3294 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3299 else // Îñîáûå òèïû ñìåðòè
3302 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3303 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3304 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3305 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3306 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3307 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3313 for a
:= WP_FIRST
to WP_LAST
do
3317 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3318 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3319 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3320 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3321 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3322 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3323 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3324 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3325 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3334 if R_ITEM_BACKPACK
in FRulez
then
3335 PushItem(ITEM_AMMO_BACKPACK
);
3337 // Âûáðîñ ðàêåòíîãî ðàíöà:
3338 if FJetFuel
> 0 then
3339 PushItem(ITEM_JETPACK
);
3342 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3344 if R_KEY_RED
in FRulez
then
3345 PushItem(ITEM_KEY_RED
);
3347 if R_KEY_GREEN
in FRulez
then
3348 PushItem(ITEM_KEY_GREEN
);
3350 if R_KEY_BLUE
in FRulez
then
3351 PushItem(ITEM_KEY_BLUE
);
3358 g_Player_CreateCorpse(Self
);
3360 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3361 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3367 for i
:= Low(gPlayers
) to High(gPlayers
) do
3369 if gPlayers
[i
] = nil then continue
;
3370 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3373 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3374 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3379 OldLR
:= gLMSRespawn
;
3380 if (gGameSettings
.GameMode
= GM_COOP
) then
3384 // everyone is dead, restart the map
3385 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3387 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3388 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3389 gLMSRespawnTime
:= gTime
+ 5000;
3391 else if (a
= 1) then
3393 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3394 if (gPlayers
[k
] = gPlayer1
) or
3395 (gPlayers
[k
] = gPlayer2
) then
3396 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3397 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3398 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3401 else if (gGameSettings
.GameMode
= GM_TDM
) then
3403 if (ab
= 0) and (ar
<> 0) then
3406 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3408 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3409 Inc(gTeamStat
[TEAM_RED
].Goals
);
3410 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3411 gLMSRespawnTime
:= gTime
+ 5000;
3413 else if (ar
= 0) and (ab
<> 0) then
3416 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3418 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3419 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3420 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3421 gLMSRespawnTime
:= gTime
+ 5000;
3423 else if (ar
= 0) and (ab
= 0) then
3426 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3428 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3429 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3430 gLMSRespawnTime
:= gTime
+ 5000;
3433 else if (gGameSettings
.GameMode
= GM_DM
) then
3437 if gPlayers
[k
] <> nil then
3440 // survivor is the winner
3441 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3443 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3446 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3447 gLMSRespawnTime
:= gTime
+ 5000;
3449 else if (a
= 0) then
3451 // everyone is dead, restart the map
3452 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3454 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3455 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3456 gLMSRespawnTime
:= gTime
+ 5000;
3459 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3461 if NetMode
= NET_SERVER
then
3462 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3464 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3470 MH_SEND_PlayerStats(FUID
);
3471 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3472 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3475 if srv
and FNoRespawn
then Spectate(True);
3476 FWantsInGame
:= True;
3479 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3481 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3482 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3485 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3487 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3488 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3491 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3493 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3494 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3495 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3497 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3498 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3499 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3503 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3505 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3506 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3507 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3511 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3513 if g_Game_IsClient
then Exit
;
3514 if Weapon
> High(FWeapon
) then Exit
;
3515 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3518 procedure TPlayer
.resetWeaponQueue ();
3521 FNextWeapDelay
:= 0;
3524 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3528 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3529 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 0);
3530 WEAPON_PISTOL
, WEAPON_CHAINGUN
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_BULLETS
] > 0);
3531 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3532 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3533 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3534 else result
:= (weapon
< length(FWeapon
));
3538 // return 255 for "no switch"
3539 function TPlayer
.getNextWeaponIndex (): Byte;
3542 wantThisWeapon
: array[0..64] of Boolean;
3543 wwc
: Integer = 0; //HACK!
3546 result
:= 255; // default result: "no switch"
3547 // had weapon cycling on previous frame? remove that flag
3548 if (FNextWeap
and $2000) <> 0 then
3550 FNextWeap
:= FNextWeap
and $1FFF;
3551 FNextWeapDelay
:= 0;
3553 // cycling has priority
3554 if (FNextWeap
and $C000) <> 0 then
3556 if (FNextWeap
and $8000) <> 0 then
3560 FNextWeap
:= FNextWeap
or $2000; // we need this
3561 if FNextWeapDelay
> 0 then
3562 exit
; // cooldown time
3564 for i
:= 0 to High(FWeapon
) do
3566 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3567 if FWeapon
[cwi
] then
3569 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d', [FCurrWeap, cwi]), MSG_WARNING);
3570 result
:= Byte(cwi
);
3571 FNextWeapDelay
:= 10;
3579 for i
:= 0 to High(wantThisWeapon
) do
3580 wantThisWeapon
[i
] := false;
3581 for i
:= 0 to High(FWeapon
) do
3582 if (FNextWeap
and (1 shl i
)) <> 0 then
3584 wantThisWeapon
[i
] := true;
3587 // exclude currently selected weapon from the set
3588 wantThisWeapon
[FCurrWeap
] := false;
3589 // slow down alterations a little
3592 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3593 // more than one weapon requested, assume "alteration" and check alteration delay
3594 if FNextWeapDelay
> 0 then
3600 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3601 // but clear all counters if no weapon should be switched
3607 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3608 // try weapons in descending order
3609 for i
:= High(FWeapon
) downto 0 do
3611 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3616 FNextWeapDelay
:= 10; // anyway, 'cause why not
3620 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3624 procedure TPlayer
.RealizeCurrentWeapon();
3625 function switchAllowed (): Boolean;
3630 if FBFGFireCounter
<> -1 then
3632 if FTime
[T_SWITCH
] > gTime
then
3634 for i
:= WP_FIRST
to WP_LAST
do
3635 if FReloading
[i
] > 0 then
3643 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3644 //FNextWeap := FNextWeap and $1FFF;
3645 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3647 if not switchAllowed
then
3649 //HACK for weapon cycling
3650 if (FNextWeap
and $7000) <> 0 then FNextWeap
:= 0;
3654 nw
:= getNextWeaponIndex();
3655 if nw
= 255 then exit
; // don't reset anything here
3656 if nw
> High(FWeapon
) then
3658 // don't forget to reset queue here!
3659 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3667 FTime
[T_SWITCH
] := gTime
+156;
3668 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3669 FModel
.SetWeapon(FCurrWeap
);
3670 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3674 procedure TPlayer
.NextWeapon();
3676 if g_Game_IsClient
then Exit
;
3680 procedure TPlayer
.PrevWeapon();
3682 if g_Game_IsClient
then Exit
;
3686 procedure TPlayer
.SetWeapon(W
: Byte);
3688 if FCurrWeap
<> W
then
3689 if W
= WEAPON_SAW
then
3690 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3693 FModel
.SetWeapon(CurrWeap
);
3697 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3699 function allowBerserkSwitching (): Boolean;
3701 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3703 if gBerserkAutoswitch
then exit
;
3704 if not conIsCheatsEnabled
then exit
;
3712 if g_Game_IsClient
then Exit
;
3714 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3715 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3720 if FHealth
< PLAYER_HP_SOFT
then
3722 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3726 if gFlash
= 2 then Inc(FPickup
, 5);
3730 if FHealth
< PLAYER_HP_SOFT
then
3732 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3736 if gFlash
= 2 then Inc(FPickup
, 5);
3740 if FArmor
< PLAYER_AP_SOFT
then
3742 FArmor
:= PLAYER_AP_SOFT
;
3745 if gFlash
= 2 then Inc(FPickup
, 5);
3749 if FArmor
< PLAYER_AP_LIMIT
then
3751 FArmor
:= PLAYER_AP_LIMIT
;
3754 if gFlash
= 2 then Inc(FPickup
, 5);
3758 if FHealth
< PLAYER_HP_LIMIT
then
3760 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3764 if gFlash
= 2 then Inc(FPickup
, 5);
3768 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3770 if FHealth
< PLAYER_HP_LIMIT
then
3771 FHealth
:= PLAYER_HP_LIMIT
;
3772 if FArmor
< PLAYER_AP_LIMIT
then
3773 FArmor
:= PLAYER_AP_LIMIT
;
3777 if gFlash
= 2 then Inc(FPickup
, 5);
3781 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3783 FWeapon
[WEAPON_SAW
] := True;
3785 if gFlash
= 2 then Inc(FPickup
, 5);
3786 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3789 ITEM_WEAPON_SHOTGUN1
:
3790 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3792 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3793 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3795 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3796 FWeapon
[WEAPON_SHOTGUN1
] := True;
3798 if gFlash
= 2 then Inc(FPickup
, 5);
3799 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3802 ITEM_WEAPON_SHOTGUN2
:
3803 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3805 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3807 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3808 FWeapon
[WEAPON_SHOTGUN2
] := True;
3810 if gFlash
= 2 then Inc(FPickup
, 5);
3811 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3814 ITEM_WEAPON_CHAINGUN
:
3815 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3817 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3819 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3820 FWeapon
[WEAPON_CHAINGUN
] := True;
3822 if gFlash
= 2 then Inc(FPickup
, 5);
3823 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3826 ITEM_WEAPON_ROCKETLAUNCHER
:
3827 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3829 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3831 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3832 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3834 if gFlash
= 2 then Inc(FPickup
, 5);
3835 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3839 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3841 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3843 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3844 FWeapon
[WEAPON_PLASMA
] := True;
3846 if gFlash
= 2 then Inc(FPickup
, 5);
3847 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3851 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3853 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3855 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3856 FWeapon
[WEAPON_BFG
] := True;
3858 if gFlash
= 2 then Inc(FPickup
, 5);
3859 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3862 ITEM_WEAPON_SUPERPULEMET
:
3863 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3865 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3867 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3868 FWeapon
[WEAPON_SUPERPULEMET
] := True;
3870 if gFlash
= 2 then Inc(FPickup
, 5);
3871 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3874 ITEM_WEAPON_FLAMETHROWER
:
3875 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
3877 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
3879 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3880 FWeapon
[WEAPON_FLAMETHROWER
] := True;
3882 if gFlash
= 2 then Inc(FPickup
, 5);
3883 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3887 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3889 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3892 if gFlash
= 2 then Inc(FPickup
, 5);
3895 ITEM_AMMO_BULLETS_BOX
:
3896 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3898 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3901 if gFlash
= 2 then Inc(FPickup
, 5);
3905 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3907 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3910 if gFlash
= 2 then Inc(FPickup
, 5);
3913 ITEM_AMMO_SHELLS_BOX
:
3914 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3916 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
3919 if gFlash
= 2 then Inc(FPickup
, 5);
3923 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3925 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3928 if gFlash
= 2 then Inc(FPickup
, 5);
3931 ITEM_AMMO_ROCKET_BOX
:
3932 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3934 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
3937 if gFlash
= 2 then Inc(FPickup
, 5);
3941 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3943 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3946 if gFlash
= 2 then Inc(FPickup
, 5);
3950 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3952 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
3955 if gFlash
= 2 then Inc(FPickup
, 5);
3959 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
3961 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3964 if gFlash
= 2 then Inc(FPickup
, 5);
3968 if not(R_ITEM_BACKPACK
in FRulez
) or
3969 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
3970 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
3971 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
3972 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
3973 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
3975 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
3976 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
3977 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
3978 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
3979 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
3981 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3982 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3983 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3984 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3985 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3986 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3987 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3988 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3990 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
3993 if gFlash
= 2 then Inc(FPickup
, 5);
3997 if not(R_KEY_RED
in FRulez
) then
3999 Include(FRulez
, R_KEY_RED
);
4001 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4002 if gFlash
= 2 then Inc(FPickup
, 5);
4003 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4007 if not(R_KEY_GREEN
in FRulez
) then
4009 Include(FRulez
, R_KEY_GREEN
);
4011 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4012 if gFlash
= 2 then Inc(FPickup
, 5);
4013 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4017 if not(R_KEY_BLUE
in FRulez
) then
4019 Include(FRulez
, R_KEY_BLUE
);
4021 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4022 if gFlash
= 2 then Inc(FPickup
, 5);
4023 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4027 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4029 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4033 if gFlash
= 2 then Inc(FPickup
, 5);
4037 if FAir
< AIR_MAX
then
4042 if gFlash
= 2 then Inc(FPickup
, 5);
4047 if not (R_BERSERK
in FRulez
) then
4049 Include(FRulez
, R_BERSERK
);
4050 if allowBerserkSwitching
then
4052 FCurrWeap
:= WEAPON_KASTET
;
4054 FModel
.SetWeapon(WEAPON_KASTET
);
4059 if gFlash
= 2 then Inc(FPickup
, 5);
4061 FBerserk
:= gTime
+30000;
4066 if FHealth
< PLAYER_HP_SOFT
then
4068 FHealth
:= PLAYER_HP_SOFT
;
4069 FBerserk
:= gTime
+30000;
4077 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4079 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4082 if gFlash
= 2 then Inc(FPickup
, 5);
4086 if FHealth
< PLAYER_HP_LIMIT
then
4088 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4092 if gFlash
= 2 then Inc(FPickup
, 5);
4096 if FArmor
< PLAYER_AP_LIMIT
then
4098 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4101 if gFlash
= 2 then Inc(FPickup
, 5);
4105 if FJetFuel
< JET_MAX
then
4107 FJetFuel
:= JET_MAX
;
4110 if gFlash
= 2 then Inc(FPickup
, 5);
4114 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4116 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4119 if gFlash
= 2 then Inc(FPickup
, 5);
4124 procedure TPlayer
.Touch();
4128 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4131 // Áðîñèòü ôëàã òîâàðèùó:
4132 if gGameSettings
.GameMode
= GM_CTF
then
4137 procedure TPlayer
.Push(vx
, vy
: Integer);
4139 if (not FPhysics
) and FGhost
then
4141 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4142 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4143 if g_Game_IsNet
and g_Game_IsServer
then
4144 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4147 procedure TPlayer
.Reset(Force
: Boolean);
4153 FTime
[T_RESPAWN
] := 0;
4154 FTime
[T_FLAGCAP
] := 0;
4167 FSpectator
:= False;
4170 FSpectatePlayer
:= -1;
4171 FNoRespawn
:= False;
4173 FLives
:= gGameSettings
.MaxLives
;
4178 procedure TPlayer
.SoftReset();
4184 FBFGFireCounter
:= -1;
4192 SetAction(A_STAND
, True);
4195 function TPlayer
.GetRespawnPoint(): Byte;
4200 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4202 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4203 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4205 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4207 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4208 if Self
= gPlayer1
then
4209 c
:= RESPAWNPOINT_PLAYER1
4211 c
:= RESPAWNPOINT_PLAYER2
;
4212 if g_Map_GetPointCount(c
) > 0 then
4218 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4219 if Self
= gPlayer1
then
4220 c
:= RESPAWNPOINT_PLAYER2
4222 c
:= RESPAWNPOINT_PLAYER1
;
4223 if g_Map_GetPointCount(c
) > 0 then
4230 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4231 if Random(2) = 0 then
4232 c
:= RESPAWNPOINT_PLAYER1
4234 c
:= RESPAWNPOINT_PLAYER2
;
4235 if g_Map_GetPointCount(c
) > 0 then
4242 // Òî÷êà ëþáîé èç êîìàíä
4243 if Random(2) = 0 then
4244 c
:= RESPAWNPOINT_RED
4246 c
:= RESPAWNPOINT_BLUE
;
4247 if g_Map_GetPointCount(c
) > 0 then
4254 c
:= RESPAWNPOINT_DM
;
4255 if g_Map_GetPointCount(c
) > 0 then
4263 if gGameSettings
.GameMode
= GM_DM
then
4266 c
:= RESPAWNPOINT_DM
;
4267 if g_Map_GetPointCount(c
) > 0 then
4273 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4274 if Random(2) = 0 then
4275 c
:= RESPAWNPOINT_PLAYER1
4277 c
:= RESPAWNPOINT_PLAYER2
;
4278 if g_Map_GetPointCount(c
) > 0 then
4284 // Òî÷êà ëþáîé èç êîìàíä
4285 if Random(2) = 0 then
4286 c
:= RESPAWNPOINT_RED
4288 c
:= RESPAWNPOINT_BLUE
;
4289 if g_Map_GetPointCount(c
) > 0 then
4297 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4299 // Òî÷êà ñâîåé êîìàíäû
4300 c
:= RESPAWNPOINT_DM
;
4301 if FTeam
= TEAM_RED
then
4302 c
:= RESPAWNPOINT_RED
;
4303 if FTeam
= TEAM_BLUE
then
4304 c
:= RESPAWNPOINT_BLUE
;
4305 if g_Map_GetPointCount(c
) > 0 then
4312 c
:= RESPAWNPOINT_DM
;
4313 if g_Map_GetPointCount(c
) > 0 then
4319 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4320 if Random(2) = 0 then
4321 c
:= RESPAWNPOINT_PLAYER1
4323 c
:= RESPAWNPOINT_PLAYER2
;
4324 if g_Map_GetPointCount(c
) > 0 then
4330 // Òî÷êà äðóãîé êîìàíäû
4331 c
:= RESPAWNPOINT_DM
;
4332 if FTeam
= TEAM_RED
then
4333 c
:= RESPAWNPOINT_BLUE
;
4334 if FTeam
= TEAM_BLUE
then
4335 c
:= RESPAWNPOINT_RED
;
4336 if g_Map_GetPointCount(c
) > 0 then
4344 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4346 RespawnPoint
: TRespawnPoint
;
4352 FBFGFireCounter
:= -1;
4357 if not g_Game_IsServer
then
4361 FWantsInGame
:= True;
4362 FJustTeleported
:= True;
4365 FTime
[T_RESPAWN
] := 0;
4369 // if server changes MaxLives we gotta be ready
4370 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4372 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4373 if FTime
[T_RESPAWN
] > gTime
then
4376 // Ïðîñðàë âñå æèçíè:
4379 if not FSpectator
then Spectate(True);
4380 FWantsInGame
:= True;
4384 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4385 begin // "Ñâîÿ èãðà"
4386 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4387 FRulez
:= FRulez
-[R_BERSERK
];
4389 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4391 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4392 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4395 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4396 c
:= GetRespawnPoint();
4401 // Âîñêðåøåíèå áåç îðóæèÿ:
4404 FHealth
:= PLAYER_HP_SOFT
;
4410 for a
:= WP_FIRST
to WP_LAST
do
4412 FWeapon
[a
] := False;
4416 FWeapon
[WEAPON_PISTOL
] := True;
4417 FWeapon
[WEAPON_KASTET
] := True;
4418 FCurrWeap
:= WEAPON_PISTOL
;
4421 FModel
.SetWeapon(FCurrWeap
);
4423 for b
:= A_BULLETS
to A_HIGH
do
4426 FAmmo
[A_BULLETS
] := 50;
4428 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4429 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4430 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4431 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4432 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4434 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4435 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4440 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4441 if not g_Map_GetPoint(c
, RespawnPoint
) then
4443 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4447 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4448 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4449 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4455 FDirection
:= RespawnPoint
.Direction
;
4456 if FDirection
= TDirection
.D_LEFT
then
4461 SetAction(A_STAND
, True);
4462 FModel
.Direction
:= FDirection
;
4464 for a
:= Low(FTime
) to High(FTime
) do
4467 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4472 FCanJetpack
:= False;
4477 // Àíèìàöèÿ âîçðîæäåíèÿ:
4478 if (not gLoadGameMode
) and (not Silent
) then
4479 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4481 Anim
:= TAnimation
.Create(ID
, False, 3);
4482 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4483 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4487 FSpectator
:= False;
4490 FSpectatePlayer
:= -1;
4493 if (gPlayer1
= nil) and (gLMSPID1
= FUID
) then
4495 if (gPlayer2
= nil) and (gLMSPID2
= FUID
) then
4498 if g_Game_IsNet
then
4500 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4501 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4503 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4504 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4509 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4512 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4513 else if (not NoMove
) then
4515 GameX
:= gMapInfo
.Width
div 2;
4516 GameY
:= gMapInfo
.Height
div 2;
4525 FWantsInGame
:= False;
4530 if Self
= gPlayer1
then
4535 if Self
= gPlayer2
then
4542 if g_Game_IsNet
then
4543 MH_SEND_PlayerStats(FUID
);
4546 procedure TPlayer
.SwitchNoClip
;
4550 FGhost
:= not FGhost
;
4551 FPhysics
:= not FGhost
;
4563 procedure TPlayer
.Run(Direction
: TDirection
);
4567 if MAX_RUNVEL
> 8 then
4571 if Direction
= TDirection
.D_LEFT
then
4573 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4574 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4577 if FObj
.Vel
.X
< MAX_RUNVEL
then
4578 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4580 // Âîçìîæíî, ïèíàåì êóñêè:
4581 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4583 b
:= Abs(FObj
.Vel
.X
);
4584 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4585 for a
:= 0 to High(gGibs
) do
4587 if gGibs
[a
].alive
and
4588 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4589 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4592 if FObj
.Vel
.X
< 0 then
4594 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4598 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4600 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4608 procedure TPlayer
.SeeDown();
4610 SetAction(A_SEEDOWN
);
4612 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4614 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4617 procedure TPlayer
.SeeUp();
4621 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4623 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4626 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4634 A_ATTACK
: Prior
:= 2;
4635 A_SEEUP
: Prior
:= 1;
4636 A_SEEDOWN
: Prior
:= 1;
4637 A_ATTACKUP
: Prior
:= 2;
4638 A_ATTACKDOWN
: Prior
:= 2;
4643 if (Prior
> FActionPrior
) or Force
then
4644 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4646 FActionPrior
:= Prior
;
4647 FActionAnim
:= Action
;
4648 FActionForce
:= Force
;
4649 FActionChanged
:= True;
4652 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4655 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4657 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4658 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4659 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4660 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4663 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4670 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4672 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4673 if g_Game_IsServer
and g_Game_IsNet
then
4674 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4678 FJustTeleported
:= True;
4683 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4685 Anim
:= TAnimation
.Create(ID
, False, 3);
4688 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4689 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4690 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4691 if g_Game_IsServer
and g_Game_IsNet
then
4692 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4693 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4697 FObj
.X
:= X
-PLAYER_RECT
.X
;
4698 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4699 if FAlive
and FGhost
then
4705 if not g_Game_IsNet
then
4709 SetDirection(TDirection
.D_LEFT
);
4715 SetDirection(TDirection
.D_RIGHT
);
4721 if FDirection
= TDirection
.D_RIGHT
then
4723 SetDirection(TDirection
.D_LEFT
);
4728 SetDirection(TDirection
.D_RIGHT
);
4734 if not silent
and (Anim
<> nil) then
4736 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4737 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4740 if g_Game_IsServer
and g_Game_IsNet
then
4741 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4742 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4749 function nonz(a
: Single): Single;
4757 procedure TPlayer
.Update();
4760 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4761 blockmon
, headwater
, dospawn
: Boolean;
4766 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4767 AnyServer
:= g_Game_IsServer
;
4769 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4770 DoLerp(NetInterpLevel
+ 1)
4776 if FClientID
>= 0 then
4778 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4779 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4780 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4789 if FAlive
and (FPunchAnim
<> nil) then
4790 FPunchAnim
.Update();
4792 if FAlive
and (gFly
or FJetpack
) then
4795 if FDirection
= TDirection
.D_LEFT
then
4800 if FAlive
and (not FGhost
) then
4802 if FKeys
[KEY_UP
].Pressed
then
4804 if FKeys
[KEY_DOWN
].Pressed
then
4808 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4811 i
:= g_basic
.Sign(FIncCam
);
4812 FIncCam
:= Abs(FIncCam
);
4813 DecMin(FIncCam
, 5, 0);
4814 FIncCam
:= FIncCam
*i
;
4817 // no need to do that each second frame, weapon queue will take care of it
4818 if FAlive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4819 if FAlive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4821 if gTime
mod (GAME_TICK
*2) <> 0 then
4823 if (FObj
.Vel
.X
= 0) and FAlive
then
4825 if FKeys
[KEY_LEFT
].Pressed
then
4826 Run(TDirection
.D_LEFT
);
4827 if FKeys
[KEY_RIGHT
].Pressed
then
4828 Run(TDirection
.D_RIGHT
);
4833 g_Obj_Move(@FObj
, True, True, True);
4834 positionChanged(); // this updates spatial accelerators
4840 FActionChanged
:= False;
4844 // Let alive player do some actions
4845 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
4846 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
4847 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
4848 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
4849 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
4850 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
4851 if FKeys
[KEY_JUMP
].Pressed
then Jump()
4854 if AnyServer
and FJetpack
then
4858 if NetServer
then MH_SEND_PlayerStats(FUID
);
4860 FCanJetpack
:= True;
4867 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
4869 if FKeys
[k
].Pressed
then
4877 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4880 if (FTime
[T_RESPAWN
] <= gTime
) and
4881 gGameOn
and (not FAlive
) then
4883 if (g_Player_GetCount() > 1) then
4887 gExit
:= EXIT_RESTART
;
4892 // Dead spectator actions
4895 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
4896 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
4900 if (FSpectatePlayer
>= High(gPlayers
)) then
4901 FSpectatePlayer
:= -1
4905 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
4906 if gPlayers
[I
] <> nil then
4907 if gPlayers
[I
].alive
then
4908 if gPlayers
[I
].UID
<> FUID
then
4910 FSpectatePlayer
:= I
;
4915 if not SetSpect
then FSpectatePlayer
:= -1;
4926 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
4928 FYTo
:= FObj
.Y
- 32;
4929 FSpectatePlayer
:= -1;
4931 if FKeys
[KEY_DOWN
].Pressed
then
4933 FYTo
:= FObj
.Y
+ 32;
4934 FSpectatePlayer
:= -1;
4936 if FKeys
[KEY_LEFT
].Pressed
then
4938 FXTo
:= FObj
.X
- 32;
4939 FSpectatePlayer
:= -1;
4941 if FKeys
[KEY_RIGHT
].Pressed
then
4943 FXTo
:= FObj
.X
+ 32;
4944 FSpectatePlayer
:= -1;
4947 if (FXTo
< -64) then
4949 else if (FXTo
> gMapInfo
.Width
+ 32) then
4950 FXTo
:= gMapInfo
.Width
+ 32;
4951 if (FYTo
< -72) then
4953 else if (FYTo
> gMapInfo
.Height
+ 32) then
4954 FYTo
:= gMapInfo
.Height
+ 32;
4959 g_Obj_Move(@FObj
, True, True, True);
4960 positionChanged(); // this updates spatial accelerators
4967 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
4968 if gPlayers
[FSpectatePlayer
] <> nil then
4969 if gPlayers
[FSpectatePlayer
].alive
then
4971 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
4972 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
4976 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
4977 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
4978 PANEL_BLOCKMON
, True);
4979 headwater
:= HeadInLiquid(0, 0);
4981 // Ñîïðîòèâëåíèå âîçäóõà:
4982 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
4983 if FObj
.Vel
.X
<> 0 then
4984 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
4986 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
4987 DecMin(FPain
, 5, 0);
4988 DecMin(FPickup
, 1, 0);
4990 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
4992 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
4993 FMegaRulez
[MR_SUIT
] := 0;
4994 FMegaRulez
[MR_INVUL
] := 0;
4995 FMegaRulez
[MR_INVIS
] := 0;
4996 Kill(K_FALLKILL
, 0, HIT_FALL
);
5003 if FCurrWeap
= WEAPON_SAW
then
5004 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5005 FSawSoundSelect
.IsPlaying()) then
5006 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5009 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5010 (not FJetSoundOff
.IsPlaying()) then
5012 FJetSoundFly
.SetPosition(0);
5013 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5016 for b
:= WP_FIRST
to WP_LAST
do
5017 if FReloading
[b
] > 0 then
5023 if FShellTimer
> -1 then
5024 if FShellTimer
= 0 then
5026 if FShellType
= SHELL_SHELL
then
5027 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5028 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5029 else if FShellType
= SHELL_DBLSHELL
then
5031 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5032 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5033 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5034 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5037 end else Dec(FShellTimer
);
5039 if (FBFGFireCounter
> -1) then
5040 if FBFGFireCounter
= 0 then
5044 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5045 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5046 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5047 yd
:= wy
+firediry();
5048 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5049 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5050 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5051 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5052 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5055 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5056 FBFGFireCounter
:= -1;
5059 FBFGFireCounter
:= 0
5061 Dec(FBFGFireCounter
);
5063 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5065 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5067 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5070 if (headwater
or blockmon
) then
5076 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5079 else if (FAir
mod 31 = 0) and not blockmon
then
5081 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5082 if Random(2) = 0 then
5083 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5085 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5087 end else if FAir
< AIR_DEF
then
5090 if FFireTime
> 0 then
5092 if BodyInLiquid(0, 0) then
5097 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5099 if FMegaRulez
[MR_SUIT
] = gTime
then
5106 if FFirePainTime
<= 0 then
5108 if g_Game_IsServer
then
5109 Damage(5, FFireAttacker
, 0, 0, HIT_FLAME
);
5110 FFirePainTime
:= 18;
5112 FFirePainTime
:= FFirePainTime
- 1;
5113 FFireTime
:= FFireTime
- 1;
5114 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5115 MH_SEND_PlayerStats(FUID
);
5119 if FDamageBuffer
> 0 then
5121 if FDamageBuffer
>= 9 then
5125 if FDamageBuffer
< 30 then i
:= 9
5126 else if FDamageBuffer
< 100 then i
:= 18
5130 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5131 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5132 FHealth
:= FHealth
-ii
;
5135 FHealth
:= FHealth
+FArmor
;
5140 if FHealth
<= 0 then
5141 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5142 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5143 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5147 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5148 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5149 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5150 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5157 end; // if FAlive then ...
5159 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5161 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5162 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5163 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5164 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5166 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5167 then SetAction(A_STAND
, True);
5169 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5171 for b
:= Low(FKeys
) to High(FKeys
) do
5172 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5176 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5178 x
:= FObj
.X
+PLAYER_RECT
.X
;
5179 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5180 w
:= PLAYER_RECT
.Width
;
5181 h
:= PLAYER_RECT
.Height
;
5185 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5187 if (dx
<> 0) or (dy
<> 0) then
5196 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5198 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5199 FObj
.Y
+PLAYER_RECT
.Y
,
5206 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5208 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5209 FObj
.Y
+PLAYER_RECT
.Y
,
5213 Panel
.Width
, Panel
.Height
);
5216 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5218 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5219 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5220 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5221 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5224 function g_Player_ValidName(Name
: string): Boolean;
5230 if gPlayers
= nil then Exit
;
5232 for a
:= 0 to High(gPlayers
) do
5233 if gPlayers
[a
] <> nil then
5234 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5241 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5245 d
:= FModel
.Direction
;
5247 FModel
.Direction
:= Direction
;
5248 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5250 FDirection
:= Direction
;
5253 function TPlayer
.GetKeys(): Byte;
5257 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5258 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5259 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5261 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5262 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5265 procedure TPlayer
.Use();
5269 if FTime
[T_USE
] > gTime
then Exit
;
5271 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5272 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5274 for a
:= 0 to High(gPlayers
) do
5275 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5276 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5277 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5278 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5280 gPlayers
[a
].Touch();
5281 if g_Game_IsNet
and g_Game_IsServer
then
5282 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5285 FTime
[T_USE
] := gTime
+120;
5288 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5292 WX
, WY
, XD
, YD
: Integer;
5303 if R_BERSERK
in FRulez
then
5305 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5306 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5307 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5310 locobj
.rect
.Width
:= 39;
5311 locobj
.rect
.Height
:= 52;
5312 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5313 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5314 locobj
.Accel
.X
:= xd
-wx
;
5315 locobj
.Accel
.y
:= yd
-wy
;
5319 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5320 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5322 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5326 FPain
:= min(FPain
+ 25, 50);
5328 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5333 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5334 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5336 FSawSoundSelect
.Stop();
5338 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5340 else if not FSawSoundHit
.IsPlaying() then
5342 FSawSoundSelect
.Stop();
5343 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5350 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5351 FFireAngle
:= FAngle
;
5353 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5354 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5359 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5360 FFireAngle
:= FAngle
;
5363 FShellType
:= SHELL_SHELL
;
5368 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5369 FFireAngle
:= FAngle
;
5372 FShellType
:= SHELL_DBLSHELL
;
5377 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5378 FFireAngle
:= FAngle
;
5380 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5381 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5384 WEAPON_ROCKETLAUNCHER
:
5386 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5387 FFireAngle
:= FAngle
;
5393 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5394 FFireAngle
:= FAngle
;
5400 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5401 FFireAngle
:= FAngle
;
5405 WEAPON_SUPERPULEMET
:
5407 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5408 FFireAngle
:= FAngle
;
5410 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5411 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5414 WEAPON_FLAMETHROWER
:
5416 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5417 FFireAngle
:= FAngle
;
5424 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5425 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5426 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5429 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5431 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5432 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5435 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5439 if NetInterpLevel
< 1 then
5449 AX
:= Abs(FXTo
- FObj
.X
);
5450 AY
:= Abs(FYTo
- FObj
.Y
);
5451 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5453 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5458 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5460 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5461 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5462 PANEL_LIFTUP
, False) then Result
:= -1
5464 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5465 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5466 PANEL_LIFTDOWN
, False) then Result
:= 1
5470 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5477 if Flag
= FLAG_NONE
then
5480 if not g_Game_IsServer
then Exit
;
5482 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5483 if (Flag
= FTeam
) and
5484 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5485 (FFlag
<> FLAG_NONE
) then
5487 if FFlag
= FLAG_RED
then
5488 s
:= _lc
[I_PLAYER_FLAG_RED
]
5490 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5492 evtype
:= FLAG_STATE_SCORED
;
5494 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5495 Insert('.', ts
, Length(ts
) + 1 - 3);
5496 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5498 g_Map_ResetFlag(FFlag
);
5499 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5501 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5504 if g_Game_IsNet
then
5506 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5510 gFlags
[FFlag
].CaptureTime
:= 0;
5515 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5516 if (Flag
= FTeam
) and
5517 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5519 if Flag
= FLAG_RED
then
5520 s
:= _lc
[I_PLAYER_FLAG_RED
]
5522 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5524 evtype
:= FLAG_STATE_RETURNED
;
5525 gFlags
[Flag
].CaptureTime
:= 0;
5527 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5529 g_Map_ResetFlag(Flag
);
5530 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5533 if g_Game_IsNet
then
5535 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5541 // Ïîäîáðàë ÷óæîé ôëàã:
5542 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5546 if Flag
= FLAG_RED
then
5547 s
:= _lc
[I_PLAYER_FLAG_RED
]
5549 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5551 evtype
:= FLAG_STATE_CAPTURED
;
5553 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5555 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5557 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5560 if g_Game_IsNet
then
5562 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5568 procedure TPlayer
.SetFlag(Flag
: Byte);
5571 if FModel
<> nil then
5572 FModel
.SetFlag(FFlag
);
5575 function TPlayer
.DropFlag(): Boolean;
5580 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5582 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5583 with gFlags
[FFlag
] do
5587 Direction
:= FDirection
;
5588 State
:= FLAG_STATE_DROPPED
;
5590 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5591 (FObj
.Vel
.Y
div 2)-2+Random(5));
5592 positionChanged(); // this updates spatial accelerators
5594 if FFlag
= FLAG_RED
then
5595 s
:= _lc
[I_PLAYER_FLAG_RED
]
5597 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5599 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5600 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5602 if g_Game_IsNet
then
5603 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5609 procedure TPlayer
.GetSecret();
5614 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5616 Assert(Key
<= High(FKeys
));
5618 FKeys
[Key
].Pressed
:= True;
5619 FKeys
[Key
].Time
:= Time
;
5622 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5624 Result
:= FKeys
[K
].Pressed
;
5627 procedure TPlayer
.ReleaseKeys();
5631 for a
:= Low(FKeys
) to High(FKeys
) do
5633 FKeys
[a
].Pressed
:= False;
5638 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5642 function TPlayer
.firediry(): Integer;
5644 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5645 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5649 procedure TPlayer
.RememberState();
5653 FSavedState
.Health
:= FHealth
;
5654 FSavedState
.Armor
:= FArmor
;
5655 FSavedState
.Air
:= FAir
;
5656 FSavedState
.JetFuel
:= FJetFuel
;
5657 FSavedState
.CurrWeap
:= FCurrWeap
;
5658 FSavedState
.NextWeap
:= FNextWeap
;
5659 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5662 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5664 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5666 FSavedState
.Rulez
:= FRulez
;
5667 FSavedState
.WaitRecall
:= True;
5670 procedure TPlayer
.RecallState();
5674 if not FSavedState
.WaitRecall
then Exit
;
5676 FHealth
:= FSavedState
.Health
;
5677 FArmor
:= FSavedState
.Armor
;
5678 FAir
:= FSavedState
.Air
;
5679 FJetFuel
:= FSavedState
.JetFuel
;
5680 FCurrWeap
:= FSavedState
.CurrWeap
;
5681 FNextWeap
:= FSavedState
.NextWeap
;
5682 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5685 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5687 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5689 FRulez
:= FSavedState
.Rulez
;
5690 FSavedState
.WaitRecall
:= False;
5692 if gGameSettings
.GameType
= GT_SERVER
then
5693 MH_SEND_PlayerStats(FUID
);
5696 procedure TPlayer
.SaveState (st
: TStream
);
5702 utils
.writeSign(st
, 'PLYR');
5703 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
5705 utils
.writeBool(st
, FIamBot
);
5707 utils
.writeInt(st
, Word(FUID
));
5709 utils
.writeStr(st
, FName
);
5711 utils
.writeInt(st
, Byte(FTeam
));
5713 utils
.writeBool(st
, FAlive
);
5714 // Èçðàñõîäîâàë ëè âñå æèçíè
5715 utils
.writeBool(st
, FNoRespawn
);
5717 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
5718 utils
.writeInt(st
, Byte(b
));
5720 utils
.writeInt(st
, LongInt(FHealth
));
5722 utils
.writeInt(st
, Byte(FLives
));
5724 utils
.writeInt(st
, LongInt(FArmor
));
5726 utils
.writeInt(st
, LongInt(FAir
));
5728 utils
.writeInt(st
, LongInt(FJetFuel
));
5730 utils
.writeInt(st
, LongInt(FPain
));
5732 utils
.writeInt(st
, LongInt(FKills
));
5734 utils
.writeInt(st
, LongInt(FMonsterKills
));
5736 utils
.writeInt(st
, LongInt(FFrags
));
5738 utils
.writeInt(st
, Byte(FFragCombo
));
5739 // Âðåìÿ ïîñëåäíåãî ôðàãà
5740 utils
.writeInt(st
, LongWord(FLastFrag
));
5742 utils
.writeInt(st
, LongInt(FDeath
));
5744 utils
.writeInt(st
, Byte(FFlag
));
5746 utils
.writeInt(st
, LongInt(FSecrets
));
5748 utils
.writeInt(st
, Byte(FCurrWeap
));
5750 utils
.writeInt(st
, Word(FNextWeap
));
5752 utils
.writeInt(st
, Byte(FNextWeapDelay
));
5753 // Âðåìÿ çàðÿäêè BFG
5754 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
5756 utils
.writeInt(st
, LongInt(FDamageBuffer
));
5757 // Ïîñëåäíèé óäàðèâøèé
5758 utils
.writeInt(st
, Word(FLastSpawnerUID
));
5759 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
5760 utils
.writeInt(st
, Byte(FLastHit
));
5762 Obj_SaveState(st
, @FObj
);
5763 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
5764 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
5765 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
5766 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
5768 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
5769 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
5770 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
5772 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
5773 // Íàëè÷èå êðàñíîãî êëþ÷à
5774 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
5775 // Íàëè÷èå çåëåíîãî êëþ÷à
5776 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
5777 // Íàëè÷èå ñèíåãî êëþ÷à
5778 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
5780 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
5781 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
5782 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
5783 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
5784 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
5786 utils
.writeStr(st
, FModel
.Name
);
5788 utils
.writeInt(st
, Byte(FColor
.R
));
5789 utils
.writeInt(st
, Byte(FColor
.G
));
5790 utils
.writeInt(st
, Byte(FColor
.B
));
5794 procedure TPlayer
.LoadState (st
: TStream
);
5803 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
5804 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
5806 FIamBot
:= utils
.readBool(st
);
5808 FUID
:= utils
.readWord(st
);
5810 str
:= utils
.readStr(st
);
5811 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
5813 FTeam
:= utils
.readByte(st
);
5815 FAlive
:= utils
.readBool(st
);
5816 // Èçðàñõîäîâàë ëè âñå æèçíè
5817 FNoRespawn
:= utils
.readBool(st
);
5819 b
:= utils
.readByte(st
);
5820 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
5822 FHealth
:= utils
.readLongInt(st
);
5824 FLives
:= utils
.readByte(st
);
5826 FArmor
:= utils
.readLongInt(st
);
5828 FAir
:= utils
.readLongInt(st
);
5830 FJetFuel
:= utils
.readLongInt(st
);
5832 FPain
:= utils
.readLongInt(st
);
5834 FKills
:= utils
.readLongInt(st
);
5836 FMonsterKills
:= utils
.readLongInt(st
);
5838 FFrags
:= utils
.readLongInt(st
);
5840 FFragCombo
:= utils
.readByte(st
);
5841 // Âðåìÿ ïîñëåäíåãî ôðàãà
5842 FLastFrag
:= utils
.readLongWord(st
);
5844 FDeath
:= utils
.readLongInt(st
);
5846 FFlag
:= utils
.readByte(st
);
5848 FSecrets
:= utils
.readLongInt(st
);
5850 FCurrWeap
:= utils
.readByte(st
);
5852 FNextWeap
:= utils
.readWord(st
);
5854 FNextWeapDelay
:= utils
.readByte(st
);
5855 // Âðåìÿ çàðÿäêè BFG
5856 FBFGFireCounter
:= utils
.readSmallInt(st
);
5858 FDamageBuffer
:= utils
.readLongInt(st
);
5859 // Ïîñëåäíèé óäàðèâøèé
5860 FLastSpawnerUID
:= utils
.readWord(st
);
5861 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
5862 FLastHit
:= utils
.readByte(st
);
5864 Obj_LoadState(@FObj
, st
);
5865 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
5866 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
5867 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
5868 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
5870 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
5871 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
5872 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
5874 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
5875 // Íàëè÷èå êðàñíîãî êëþ÷à
5876 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
5877 // Íàëè÷èå çåëåíîãî êëþ÷à
5878 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
5879 // Íàëè÷èå ñèíåãî êëþ÷à
5880 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
5882 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
5883 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
5884 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
5885 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
5886 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
5888 str
:= utils
.readStr(st
);
5890 FColor
.R
:= utils
.readByte(st
);
5891 FColor
.G
:= utils
.readByte(st
);
5892 FColor
.B
:= utils
.readByte(st
);
5893 if (self
= gPlayer1
) then
5895 str
:= gPlayer1Settings
.Model
;
5896 FColor
:= gPlayer1Settings
.Color
;
5898 else if (self
= gPlayer2
) then
5900 str
:= gPlayer2Settings
.Model
;
5901 FColor
:= gPlayer2Settings
.Color
;
5903 // Îáíîâëÿåì ìîäåëü èãðîêà
5905 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
5906 FModel
.Color
:= TEAMCOLOR
[FTeam
]
5908 FModel
.Color
:= FColor
;
5912 procedure TPlayer
.AllRulez(Health
: Boolean);
5918 FHealth
:= PLAYER_HP_LIMIT
;
5919 FArmor
:= PLAYER_AP_LIMIT
;
5923 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
5924 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
5925 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5928 procedure TPlayer
.RestoreHealthArmor();
5930 FHealth
:= PLAYER_HP_LIMIT
;
5931 FArmor
:= PLAYER_AP_LIMIT
;
5934 procedure TPlayer
.FragCombo();
5938 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
5940 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
5942 if FFragCombo
< 5 then
5944 Param
:= FUID
or (FFragCombo
shl 16);
5945 if (FComboEvnt
>= Low(gDelayedEvents
)) and
5946 (FComboEvnt
<= High(gDelayedEvents
)) and
5947 gDelayedEvents
[FComboEvnt
].Pending
and
5948 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
5949 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
5951 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
5952 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
5955 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
5963 procedure TPlayer
.GiveItem(ItemType
: Byte);
5967 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
5969 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
5973 if FAir
< AIR_MAX
then
5980 if not (R_BERSERK
in FRulez
) then
5982 Include(FRulez
, R_BERSERK
);
5983 if FBFGFireCounter
< 1 then
5985 FCurrWeap
:= WEAPON_KASTET
;
5987 FModel
.SetWeapon(WEAPON_KASTET
);
5991 FBerserk
:= gTime
+30000;
5993 if FHealth
< PLAYER_HP_SOFT
then
5995 FHealth
:= PLAYER_HP_SOFT
;
5996 FBerserk
:= gTime
+30000;
6001 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6003 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6007 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6009 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6013 if FJetFuel
< JET_MAX
then
6015 FJetFuel
:= JET_MAX
;
6018 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6019 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6021 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6022 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6024 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6026 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6028 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6029 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6032 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6033 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6034 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6035 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6036 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6037 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6038 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6039 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6040 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6042 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6043 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6044 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6045 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6046 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6047 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6048 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6049 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6050 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6053 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6054 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6055 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6056 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6057 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6059 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6060 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6061 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6062 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6063 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6065 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6066 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6067 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6068 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6070 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6073 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6074 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6075 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6077 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6078 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6083 if g_Game_IsNet
and g_Game_IsServer
then
6084 MH_SEND_PlayerStats(FUID
);
6087 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6092 if (Random(5) = 1) and (Times
= 1) then
6095 if BodyInLiquid(0, 0) then
6097 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6098 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6099 if Random(2) = 0 then
6100 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6102 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6106 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6108 for i
:= 1 to Times
do
6110 Anim
:= TAnimation
.Create(id
, False, 3);
6112 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6113 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6119 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6124 if (Random(10) = 1) and (Times
= 1) then
6127 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6129 for i
:= 1 to Times
do
6131 Anim
:= TAnimation
.Create(id
, False, 3);
6133 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6134 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6140 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6142 FSawSound
.Pause(Enable
);
6143 FSawSoundIdle
.Pause(Enable
);
6144 FSawSoundHit
.Pause(Enable
);
6145 FSawSoundSelect
.Pause(Enable
);
6150 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6155 FObj
.Rect
:= PLAYER_CORPSERECT
;
6156 FModelName
:= ModelName
;
6161 FState
:= CORPSE_STATE_MESS
;
6162 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6166 FState
:= CORPSE_STATE_NORMAL
;
6167 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6171 destructor TCorpse
.Destroy();
6178 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6180 procedure TCorpse
.positionChanged (); inline; begin end;
6182 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6184 if (dx
<> 0) or (dy
<> 0) then
6193 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6195 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6196 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6197 w
:= PLAYER_CORPSERECT
.Width
;
6198 h
:= PLAYER_CORPSERECT
.Height
;
6202 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6206 if FState
= CORPSE_STATE_REMOVEME
then
6209 FDamage
:= FDamage
+ Value
;
6211 if FDamage
> 150 then
6213 if FAnimation
<> nil then
6218 FState
:= CORPSE_STATE_REMOVEME
;
6220 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6221 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6222 FModelName
, FColor
);
6223 // Çâóê ìÿñà îò òðóïà:
6224 pm
:= g_PlayerModel_Get(FModelName
);
6225 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6231 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6232 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6233 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6234 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6235 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6240 procedure TCorpse
.Draw();
6242 if FState
= CORPSE_STATE_REMOVEME
then
6245 if FAnimation
<> nil then
6246 FAnimation
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6248 if FAnimationMask
<> nil then
6251 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6258 procedure TCorpse
.Update();
6262 if FState
= CORPSE_STATE_REMOVEME
then
6265 if gTime
mod (GAME_TICK
*2) <> 0 then
6267 g_Obj_Move(@FObj
, True, True, True);
6268 positionChanged(); // this updates spatial accelerators
6272 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6273 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6275 st
:= g_Obj_Move(@FObj
, True, True, True);
6276 positionChanged(); // this updates spatial accelerators
6278 if WordBool(st
and MOVE_FALLOUT
) then
6280 FState
:= CORPSE_STATE_REMOVEME
;
6284 if FAnimation
<> nil then
6285 FAnimation
.Update();
6286 if FAnimationMask
<> nil then
6287 FAnimationMask
.Update();
6291 procedure TCorpse
.SaveState (st
: TStream
);
6298 utils
.writeSign(st
, 'CORP');
6299 utils
.writeInt(st
, Byte(0));
6301 utils
.writeInt(st
, Byte(FState
));
6303 utils
.writeInt(st
, Byte(FDamage
));
6305 utils
.writeInt(st
, Byte(FColor
.R
));
6306 utils
.writeInt(st
, Byte(FColor
.G
));
6307 utils
.writeInt(st
, Byte(FColor
.B
));
6309 Obj_SaveState(st
, @FObj
);
6311 anim
:= (FAnimation
<> nil);
6312 utils
.writeBool(st
, anim
);
6313 // Åñëè åñòü - ñîõðàíÿåì
6314 if anim
then FAnimation
.SaveState(st
);
6315 // Åñòü ëè ìàñêà àíèìàöèè
6316 anim
:= (FAnimationMask
<> nil);
6317 utils
.writeBool(st
, anim
);
6318 // Åñëè åñòü - ñîõðàíÿåì
6319 if anim
then FAnimationMask
.SaveState(st
);
6323 procedure TCorpse
.LoadState (st
: TStream
);
6330 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6331 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6333 FState
:= utils
.readByte(st
);
6335 FDamage
:= utils
.readByte(st
);
6337 FColor
.R
:= utils
.readByte(st
);
6338 FColor
.G
:= utils
.readByte(st
);
6339 FColor
.B
:= utils
.readByte(st
);
6341 Obj_LoadState(@FObj
, st
);
6343 anim
:= utils
.readBool(st
);
6344 // Åñëè åñòü - çàãðóæàåì
6347 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6348 FAnimation
.LoadState(st
);
6350 // Åñòü ëè ìàñêà àíèìàöèè
6351 anim
:= utils
.readBool(st
);
6352 // Åñëè åñòü - çàãðóæàåì
6355 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6356 FAnimationMask
.LoadState(st
);
6362 constructor TBot
.Create();
6369 FSpectator
:= False;
6376 for a
:= WP_FIRST
to WP_LAST
do
6378 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6379 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6380 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6384 destructor TBot
.Destroy();
6387 inherited Destroy();
6390 procedure TBot
.Draw();
6394 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6395 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6398 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6400 inherited Respawn(Silent
, Force
);
6403 FSelectedWeapon
:= FCurrWeap
;
6408 procedure TBot
.UpdateCombat();
6421 TTargetRecord
= array of TTarget
;
6423 function Compare(a
, b
: TTarget
): Integer;
6425 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6428 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6430 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6431 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6433 if a
.Dist
> b
.Dist
then // B áëèæå
6435 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6438 else // Ñòðàííî -> A
6443 a
, x1
, y1
, x2
, y2
: Integer;
6444 targets
: TTargetRecord
;
6446 Target
, BestTarget
: TTarget
;
6447 firew
, fireh
: Integer;
6451 vsPlayer
, vsMonster
, ok
: Boolean;
6454 function monsUpdate (mon
: TMonster
): Boolean;
6456 result
:= false; // don't stop
6457 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6459 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6461 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6462 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6464 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6465 if g_TraceVector(x1
, y1
, x2
, y2
) then
6467 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6468 SetLength(targets
, Length(targets
)+1);
6469 with targets
[High(targets
)] do
6476 Rect
:= mon
.Obj
.Rect
;
6477 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6478 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6479 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6488 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6489 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6491 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6492 if FCurrWeap
<> FSelectedWeapon
then
6495 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6496 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6498 RemoveAIFlag('NEEDFIRE');
6501 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6502 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6503 else PressKey(KEY_FIRE
);
6507 // Êîîðäèíàòû ñòâîëà:
6508 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6509 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6511 Target
.UID
:= FTargetUID
;
6514 if Target
.UID
<> 0 then
6515 begin // Öåëü åñòü - íàñòðàèâàåì
6516 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6519 tpla
:= g_Player_Get(Target
.UID
);
6523 if (@FObj
) <> nil then
6530 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6531 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6532 Target
.Rect
:= PLAYER_RECT
;
6533 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6534 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6535 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6536 Target
.IsPlayer
:= True;
6540 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6543 mon
:= g_Monsters_ByUID(Target
.UID
);
6546 Target
.X
:= mon
.Obj
.X
;
6547 Target
.Y
:= mon
.Obj
.Y
;
6549 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6550 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6551 Target
.Rect
:= mon
.Obj
.Rect
;
6552 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6553 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6554 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6555 Target
.IsPlayer
:= False;
6562 begin // Öåëè íåò - îáíóëÿåì
6567 Target
.Visible
:= False;
6568 Target
.Line
:= False;
6569 Target
.IsPlayer
:= False;
6574 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6575 if (not Target
.Line
) or (not Target
.Visible
) then
6579 for a
:= 0 to High(gPlayers
) do
6580 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6581 (gPlayers
[a
].FUID
<> FUID
) and
6582 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6583 (not gPlayers
[a
].NoTarget
) and
6584 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6586 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6587 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6590 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6591 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6593 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6594 if g_TraceVector(x1
, y1
, x2
, y2
) then
6596 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6597 SetLength(targets
, Length(targets
)+1);
6598 with targets
[High(targets
)] do
6600 UID
:= gPlayers
[a
].FUID
;
6601 X
:= gPlayers
[a
].FObj
.X
;
6602 Y
:= gPlayers
[a
].FObj
.Y
;
6605 Rect
:= PLAYER_RECT
;
6606 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6607 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6608 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6616 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6619 // Åñëè åñòü âîçìîæíûå öåëè:
6620 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6621 if targets
<> nil then
6623 // Âûáèðàåì íàèëó÷øóþ öåëü:
6624 BestTarget
:= targets
[0];
6625 if Length(targets
) > 1 then
6626 for a
:= 1 to High(targets
) do
6627 if Compare(BestTarget
, targets
[a
]) = 1 then
6628 BestTarget
:= targets
[a
];
6630 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6631 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6632 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6634 Target
:= BestTarget
;
6636 if (Healthy() = 3) or ((Healthy() = 2)) then
6637 begin // Åñëè çäîðîâû - äîãîíÿåì
6638 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6639 SetAIFlag('GORIGHT', '1');
6640 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6641 SetAIFlag('GOLEFT', '1');
6644 begin // Åñëè ïîáèòû - óáåãàåì
6645 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6646 SetAIFlag('GORIGHT', '1');
6647 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6648 SetAIFlag('GOLEFT', '1');
6651 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6652 SelectWeapon(Abs(x1
-Target
.cX
));
6657 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6658 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6659 if Target
.UID
<> 0 then
6661 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6662 Target
.Y
+ Target
.Rect
.Y
) then
6663 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6664 if (Healthy() = 3) or ((Healthy() = 2)) then
6665 begin // Åñëè çäîðîâû - äîãîíÿåì
6666 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6667 SetAIFlag('GORIGHT', '1');
6668 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6669 SetAIFlag('GOLEFT', '1');
6672 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6674 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6675 SetAIFlag('GORIGHT', '1');
6676 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6677 SetAIFlag('GOLEFT', '1');
6681 begin // Öåëü ïîêà íà "ýêðàíå"
6682 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6683 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6684 FLastVisible
:= gTime
;
6685 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6686 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6688 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6689 SetAIFlag('GORIGHT', '1');
6690 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6691 SetAIFlag('GOLEFT', '1');
6695 // Âûáèðàåì óãîë ââåðõ:
6696 if FDirection
= TDirection
.D_LEFT
then
6697 angle
:= ANGLE_LEFTUP
6699 angle
:= ANGLE_RIGHTUP
;
6701 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6702 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6704 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6705 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6706 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6707 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6708 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6709 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6710 begin // òî íóæíî ñòðåëÿòü ââåðõ
6711 SetAIFlag('NEEDFIRE', '1');
6712 SetAIFlag('NEEDSEEUP', '1');
6715 // Âûáèðàåì óãîë âíèç:
6716 if FDirection
= TDirection
.D_LEFT
then
6717 angle
:= ANGLE_LEFTDOWN
6719 angle
:= ANGLE_RIGHTDOWN
;
6721 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6722 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6724 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6725 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6726 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6727 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6728 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6729 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6730 begin // òî íóæíî ñòðåëÿòü âíèç
6731 SetAIFlag('NEEDFIRE', '1');
6732 SetAIFlag('NEEDSEEDOWN', '1');
6735 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6736 if Target
.Visible
and
6737 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6738 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6740 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6741 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
6742 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6743 begin // òî íóæíî ñòðåëÿòü âïåðåä
6744 SetAIFlag('NEEDFIRE', '1');
6745 SetAIFlag('NEEDSEEDOWN', '');
6746 SetAIFlag('NEEDSEEUP', '');
6748 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6749 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6750 if GetRnd(FDifficult
.CloseJump
) then
6751 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6752 if Abs(FObj
.X
-Target
.X
) < 128 then
6756 if Random(a
) = 0 then
6757 SetAIFlag('NEEDJUMP', '1');
6761 // Åñëè öåëü âñå åùå åñòü:
6762 if Target
.UID
<> 0 then
6763 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
6764 Target
.UID
:= 0 // òî çàáûòü öåëü
6765 else // Åñëè âèäåëè íåäàâíî
6766 begin // íî öåëü óáèëè
6767 if Target
.IsPlayer
then
6768 begin // Öåëü - èãðîê
6769 pla
:= g_Player_Get(Target
.UID
);
6770 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
6771 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6772 Target
.UID
:= 0; // òî çàáûòü öåëü
6775 begin // Öåëü - ìîíñòð
6776 mon
:= g_Monsters_ByUID(Target
.UID
);
6777 if (mon
= nil) or (not mon
.alive
) then
6778 Target
.UID
:= 0; // òî çàáûòü öåëü
6781 end; // if Target.UID <> 0
6783 FTargetUID
:= Target
.UID
;
6785 // Åñëè âîçìîæíûõ öåëåé íåò:
6786 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
6787 if targets
= nil then
6788 if GetAIFlag('ATTACKLEFT') <> '' then
6789 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
6790 RemoveAIFlag('ATTACKLEFT');
6792 SetAIFlag('NEEDJUMP', '1');
6794 if RunDirection() = TDirection
.D_RIGHT
then
6795 begin // Èäåì íå â òó ñòîðîíó
6796 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6797 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
6798 SetAIFlag('NEEDFIRE', '1');
6799 SetAIFlag('GOLEFT', '1');
6803 begin // Èäåì â íóæíóþ ñòîðîíó
6804 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6805 SetAIFlag('NEEDFIRE', '1');
6806 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6807 SetAIFlag('GORIGHT', '1');
6811 if GetAIFlag('ATTACKRIGHT') <> '' then
6812 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
6813 RemoveAIFlag('ATTACKRIGHT');
6815 SetAIFlag('NEEDJUMP', '1');
6817 if RunDirection() = TDirection
.D_LEFT
then
6818 begin // Èäåì íå â òó ñòîðîíó
6819 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6820 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
6821 SetAIFlag('NEEDFIRE', '1');
6822 SetAIFlag('GORIGHT', '1');
6827 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6828 SetAIFlag('NEEDFIRE', '1');
6829 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6830 SetAIFlag('GOLEFT', '1');
6834 //HACK! (does it belongs there?)
6835 RealizeCurrentWeapon();
6837 // Åñëè åñòü âîçìîæíûå öåëè:
6838 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
6839 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6840 for a
:= 0 to High(targets
) do
6842 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
6843 if GetRnd(FDifficult
.DiagFire
) then
6845 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
6846 if FDirection
= TDirection
.D_LEFT
then
6847 angle
:= ANGLE_LEFTUP
6849 angle
:= ANGLE_RIGHTUP
;
6851 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6852 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6854 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6855 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6856 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6857 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6858 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6860 SetAIFlag('NEEDFIRE', '1');
6861 SetAIFlag('NEEDSEEUP', '1');
6864 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
6865 if FDirection
= TDirection
.D_LEFT
then
6866 angle
:= ANGLE_LEFTDOWN
6868 angle
:= ANGLE_RIGHTDOWN
;
6870 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6871 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6873 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6874 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6875 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6876 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6877 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6879 SetAIFlag('NEEDFIRE', '1');
6880 SetAIFlag('NEEDSEEDOWN', '1');
6884 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
6885 if targets
[a
].Line
and targets
[a
].Visible
and
6886 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
6887 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
6889 SetAIFlag('NEEDFIRE', '1');
6894 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
6895 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
6896 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
6897 40+GetInterval(FDifficult
.Cover
, 40)) then
6898 SetAIFlag('NEEDJUMP', '1');
6900 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
6901 ammo
:= GetAmmoByWeapon(FCurrWeap
);
6902 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
6903 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
6905 SetAIFlag('SELECTWEAPON', '1');
6907 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
6908 if GetAIFlag('SELECTWEAPON') = '1' then
6911 RemoveAIFlag('SELECTWEAPON');
6915 procedure TBot
.Update();
6928 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
6929 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
6931 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
6933 if g_debug_BotAIOff
= 3 then
6943 RealizeCurrentWeapon();
6950 procedure TBot
.ReleaseKey(Key
: Byte);
6959 function TBot
.KeyPressed(Key
: Word): Boolean;
6961 Result
:= FKeys
[Key
].Pressed
;
6964 function TBot
.GetAIFlag(aName
: String20
): String20
;
6970 aName
:= LowerCase(aName
);
6972 if FAIFlags
<> nil then
6973 for a
:= 0 to High(FAIFlags
) do
6974 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6976 Result
:= FAIFlags
[a
].Value
;
6981 procedure TBot
.RemoveAIFlag(aName
: String20
);
6985 if FAIFlags
= nil then Exit
;
6987 aName
:= LowerCase(aName
);
6989 for a
:= 0 to High(FAIFlags
) do
6990 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6992 if a
<> High(FAIFlags
) then
6993 for b
:= a
to High(FAIFlags
)-1 do
6994 FAIFlags
[b
] := FAIFlags
[b
+1];
6996 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7001 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7009 aName
:= LowerCase(aName
);
7011 if FAIFlags
<> nil then
7012 for a
:= 0 to High(FAIFlags
) do
7013 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7019 if ok
then FAIFlags
[a
].Value
:= fValue
7022 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7023 with FAIFlags
[High(FAIFlags
)] do
7031 procedure TBot
.UpdateMove
;
7033 procedure GoLeft(Time
: Word = 1);
7035 ReleaseKey(KEY_LEFT
);
7036 ReleaseKey(KEY_RIGHT
);
7037 PressKey(KEY_LEFT
, Time
);
7038 SetDirection(TDirection
.D_LEFT
);
7041 procedure GoRight(Time
: Word = 1);
7043 ReleaseKey(KEY_LEFT
);
7044 ReleaseKey(KEY_RIGHT
);
7045 PressKey(KEY_RIGHT
, Time
);
7046 SetDirection(TDirection
.D_RIGHT
);
7049 function Rnd(a
: Word): Boolean;
7051 Result
:= Random(a
) = 0;
7054 procedure Turn(Time
: Word = 1200);
7056 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7061 ReleaseKey(KEY_LEFT
);
7062 ReleaseKey(KEY_RIGHT
);
7065 function CanRunLeft(): Boolean;
7067 Result
:= not CollideLevel(-1, 0);
7070 function CanRunRight(): Boolean;
7072 Result
:= not CollideLevel(1, 0);
7075 function CanRun(): Boolean;
7077 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7080 procedure Jump(Time
: Word = 30);
7082 PressKey(KEY_JUMP
, Time
);
7085 function NearHole(): Boolean;
7089 { TODO 5 : Ëåñòíèöû }
7090 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7091 for x
:= 1 to PLAYER_RECT
.Width
do
7092 if (not StayOnStep(x
*sx
, 0)) and
7093 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7094 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7103 function BorderHole(): Boolean;
7107 { TODO 5 : Ëåñòíèöû }
7108 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7109 for x
:= 1 to PLAYER_RECT
.Width
do
7110 if (not StayOnStep(x
*sx
, 0)) and
7111 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7112 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7114 for xx
:= x
to x
+32 do
7115 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7125 function NearDeepHole(): Boolean;
7131 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7134 for x
:= 1 to PLAYER_RECT
.Width
do
7135 if (not StayOnStep(x
*sx
, 0)) and
7136 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7137 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7139 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7141 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7146 end else Result
:= False;
7149 function OverDeepHole(): Boolean;
7156 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7158 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7165 function OnGround(): Boolean;
7167 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7170 function OnLadder(): Boolean;
7172 Result
:= FullInStep(0, 0);
7175 function BelowLadder(): Boolean;
7177 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7178 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7179 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7180 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7183 function BelowLiftUp(): Boolean;
7185 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7186 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7187 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7188 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7191 function OnTopLift(): Boolean;
7193 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7196 function CanJumpOver(): Boolean;
7200 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7204 if not CollideLevel(sx
, 0) then Exit
;
7206 for y
:= 1 to BOT_MAXJUMP
do
7207 if CollideLevel(0, -y
) then Exit
else
7208 if not CollideLevel(sx
, -y
) then
7215 function CanJumpUp(Dist
: ShortInt): Boolean;
7222 if CollideLevel(Dist
, 0) then Exit
;
7225 for y
:= 0 to BOT_MAXJUMP
do
7226 if CollideLevel(Dist
, -y
) then
7235 for yy
:= y
+1 to BOT_MAXJUMP
do
7236 if not CollideLevel(Dist
, -yy
) then
7245 for y
:= 0 to BOT_MAXJUMP
do
7246 if CollideLevel(0, -y
) then
7254 if y
< yy
then Exit
;
7259 function IsSafeTrigger(): Boolean;
7264 if gTriggers
= nil then
7266 for a
:= 0 to High(gTriggers
) do
7267 if Collide(gTriggers
[a
].X
,
7270 gTriggers
[a
].Height
) and
7271 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7272 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7273 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7274 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7275 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7280 // Âîçìîæíî, íàæèìàåì êíîïêó:
7281 if Rnd(16) and IsSafeTrigger() then
7284 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7285 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7287 ReleaseKey(KEY_LEFT
);
7288 ReleaseKey(KEY_RIGHT
);
7292 // Èäåì âëåâî, åñëè íàäî áûëî:
7293 if GetAIFlag('GOLEFT') <> '' then
7295 RemoveAIFlag('GOLEFT');
7296 if CanRunLeft() then
7300 // Èäåì âïðàâî, åñëè íàäî áûëî:
7301 if GetAIFlag('GORIGHT') <> '' then
7303 RemoveAIFlag('GORIGHT');
7304 if CanRunRight() then
7308 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7309 if FObj
.X
< -32 then
7312 if FObj
.X
+32 > gMapInfo
.Width
then
7315 // Ïðûãàåì, åñëè íàäî áûëî:
7316 if GetAIFlag('NEEDJUMP') <> '' then
7319 RemoveAIFlag('NEEDJUMP');
7322 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7323 if GetAIFlag('NEEDSEEUP') <> '' then
7326 ReleaseKey(KEY_DOWN
);
7327 PressKey(KEY_UP
, 20);
7328 RemoveAIFlag('NEEDSEEUP');
7331 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7332 if GetAIFlag('NEEDSEEDOWN') <> '' then
7335 ReleaseKey(KEY_DOWN
);
7336 PressKey(KEY_DOWN
, 20);
7337 RemoveAIFlag('NEEDSEEDOWN');
7340 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7341 if GetAIFlag('GOINHOLE') <> '' then
7342 if not OnGround() then
7344 ReleaseKey(KEY_LEFT
);
7345 ReleaseKey(KEY_RIGHT
);
7346 RemoveAIFlag('GOINHOLE');
7347 SetAIFlag('FALLINHOLE', '1');
7350 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7351 if GetAIFlag('FALLINHOLE') <> '' then
7353 RemoveAIFlag('FALLINHOLE');
7355 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7356 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7357 if GetAIFlag('FALLINHOLE') = '' then
7358 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7364 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7366 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7370 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7371 if OnGround() and NearHole() then
7372 if NearDeepHole() then // Åñëè ýòî áåçäíà
7374 0..3: Turn(); // Áåæèì îáðàòíî
7375 4: Jump(); // Ïðûãàåì
7376 5: begin // Ïðûãàåì îáðàòíî
7381 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7382 if GetAIFlag('GOINHOLE') = '' then
7384 0: Turn(); // Íå íóæíî òóäà
7385 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7386 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7387 if BorderHole() then
7388 SetAIFlag('GOINHOLE', '1');
7391 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7392 if (not CanRun()) and OnGround() then
7394 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7395 if CanJumpOver() or OnLadder() then
7397 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7398 if Random(2) = 0 then
7400 if IsSafeTrigger() then
7406 // Îñòàëîñü ìàëî âîçäóõà:
7407 if FAir
< 36 * 2 then
7410 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7411 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7412 if BodyInAcid(0, 0) then
7416 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7418 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7419 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7422 {function TBot.NeedItem(Item: Byte): Byte;
7427 procedure TBot
.SelectWeapon(Dist
: Integer);
7431 function HaveAmmo(weapon
: Byte): Boolean;
7434 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7435 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7436 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7437 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7438 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7439 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7440 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7441 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7442 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7443 else Result
:= True;
7448 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7450 if Dist
> BOT_LONGDIST
then
7451 begin // Äàëüíèé áîé
7453 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7455 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7459 else //if Dist > BOT_UNSAFEDIST then
7460 begin // Áëèæíèé áîé
7462 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7464 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7471 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7473 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7479 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7481 Result
:= inherited PickItem(ItemType
, force
, remove
);
7483 if Result
then SetAIFlag('SELECTWEAPON', '1');
7486 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7488 Result
:= inherited Heal(value
, Soft
);
7491 function TBot
.Healthy(): Byte;
7493 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7494 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7495 else if (FHealth
> 50) then Result
:= 2
7496 else if (FHealth
> 20) then Result
:= 1
7500 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7502 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7503 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7506 procedure TBot
.OnDamage(Angle
: SmallInt);
7514 if (Angle
= 0) or (Angle
= 180) then
7517 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7518 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7520 pla
:= g_Player_Get(FLastSpawnerUID
);
7521 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7522 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7525 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7526 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7528 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7529 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7530 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7535 SetAIFlag('ATTACKLEFT', '1')
7537 SetAIFlag('ATTACKRIGHT', '1');
7541 function TBot
.RunDirection(): TDirection
;
7543 if Abs(Vel
.X
) >= 1 then
7545 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7547 Result
:= FDirection
;
7550 function TBot
.GetRnd(a
: Byte): Boolean;
7552 if a
= 0 then Result
:= False
7553 else if a
= 255 then Result
:= True
7554 else Result
:= Random(256) > 255-a
;
7557 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7559 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7563 procedure TDifficult
.save (st
: TStream
);
7565 utils
.writeInt(st
, Byte(DiagFire
));
7566 utils
.writeInt(st
, Byte(InvisFire
));
7567 utils
.writeInt(st
, Byte(DiagPrecision
));
7568 utils
.writeInt(st
, Byte(FlyPrecision
));
7569 utils
.writeInt(st
, Byte(Cover
));
7570 utils
.writeInt(st
, Byte(CloseJump
));
7571 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7572 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7575 procedure TDifficult
.load (st
: TStream
);
7577 DiagFire
:= utils
.readByte(st
);
7578 InvisFire
:= utils
.readByte(st
);
7579 DiagPrecision
:= utils
.readByte(st
);
7580 FlyPrecision
:= utils
.readByte(st
);
7581 Cover
:= utils
.readByte(st
);
7582 CloseJump
:= utils
.readByte(st
);
7583 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7584 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7588 procedure TBot
.SaveState (st
: TStream
);
7593 inherited SaveState(st
);
7594 utils
.writeSign(st
, 'BOT0');
7596 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7598 utils
.writeInt(st
, Word(FTargetUID
));
7599 // Âðåìÿ ïîòåðè öåëè
7600 utils
.writeInt(st
, LongWord(FLastVisible
));
7601 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7602 dw
:= Length(FAIFlags
);
7603 utils
.writeInt(st
, LongInt(dw
));
7605 for i
:= 0 to dw
-1 do
7607 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7608 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7610 // Íàñòðîéêè ñëîæíîñòè
7611 FDifficult
.save(st
);
7615 procedure TBot
.LoadState (st
: TStream
);
7620 inherited LoadState(st
);
7621 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7623 FSelectedWeapon
:= utils
.readByte(st
);
7625 FTargetUID
:= utils
.readWord(st
);
7626 // Âðåìÿ ïîòåðè öåëè
7627 FLastVisible
:= utils
.readLongWord(st
);
7628 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7629 dw
:= utils
.readLongInt(st
);
7630 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7631 SetLength(FAIFlags
, dw
);
7633 for i
:= 0 to dw
-1 do
7635 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7636 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7638 // Íàñòðîéêè ñëîæíîñòè
7639 FDifficult
.load(st
);
7644 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);