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);
234 function followCorpse(): Boolean;
237 FDamageBuffer
: Integer;
239 FAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
240 FMaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
241 FWeapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
242 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
244 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
245 FReloading
: Array [WP_FIRST
..WP_LAST
] of Word;
246 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
247 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
249 FPreferredTeam
: Byte;
252 FWantsInGame
: Boolean;
256 FActualModelName
: string;
263 // debug: viewport offset
264 viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer;
266 function isValidViewPort (): Boolean; inline;
268 constructor Create(); virtual;
269 destructor Destroy(); override;
270 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
271 function GetRespawnPoint(): Byte;
272 procedure PressKey(Key
: Byte; Time
: Word = 1);
273 procedure ReleaseKeys();
274 procedure SetModel(ModelName
: String);
275 procedure SetColor(Color
: TRGB
);
276 procedure SetWeapon(W
: Byte);
277 function IsKeyPressed(K
: Byte): Boolean;
278 function GetKeys(): Byte;
279 function PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean; virtual;
280 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
281 function Collide(Panel
: TPanel
): Boolean; overload
;
282 function Collide(X
, Y
: Integer): Boolean; overload
;
283 procedure SetDirection(Direction
: TDirection
);
284 procedure GetSecret();
285 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
287 procedure Push(vx
, vy
: Integer);
288 procedure ChangeModel(ModelName
: String);
289 procedure SwitchTeam
;
290 procedure ChangeTeam(Team
: Byte);
292 function GetFlag(Flag
: Byte): Boolean;
293 procedure SetFlag(Flag
: Byte);
294 function DropFlag(): Boolean;
295 procedure AllRulez(Health
: Boolean);
296 procedure RestoreHealthArmor();
297 procedure FragCombo();
298 procedure GiveItem(ItemType
: Byte);
299 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
300 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
301 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
302 procedure MakeBloodSimple(Count
: Word);
303 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
304 procedure Reset(Force
: Boolean);
305 procedure Spectate(NoMove
: Boolean = False);
306 procedure SwitchNoClip
;
307 procedure SoftReset();
308 procedure Draw(); virtual;
309 procedure DrawPain();
310 procedure DrawPickup();
311 procedure DrawRulez();
313 procedure DrawBubble();
315 procedure Update(); virtual;
316 procedure RememberState();
317 procedure RecallState();
318 procedure SaveState (st
: TStream
); virtual;
319 procedure LoadState (st
: TStream
); virtual;
320 procedure PauseSounds(Enable
: Boolean);
321 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
322 procedure DoLerp(Level
: Integer = 2);
323 procedure SetLerp(XTo
, YTo
: Integer);
324 procedure QueueWeaponSwitch(Weapon
: Byte);
325 procedure RealizeCurrentWeapon();
327 procedure JetpackOff
;
328 procedure CatchFire(Attacker
: Word);
330 //WARNING! this does nothing for now, but still call it!
331 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
333 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
334 procedure moveBy (dx
, dy
: Integer); inline;
337 property Vel
: TPoint2i read FObj
.Vel
;
338 property Obj
: TObj read FObj
;
340 property Name
: String read FName write FName
;
341 property Model
: TPlayerModel read FModel
;
342 property Health
: Integer read FHealth write FHealth
;
343 property Lives
: Byte read FLives write FLives
;
344 property Armor
: Integer read FArmor write FArmor
;
345 property Air
: Integer read FAir write FAir
;
346 property JetFuel
: Integer read FJetFuel write FJetFuel
;
347 property Frags
: Integer read FFrags write FFrags
;
348 property Death
: Integer read FDeath write FDeath
;
349 property Kills
: Integer read FKills write FKills
;
350 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
351 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
352 property Secrets
: Integer read FSecrets
;
353 property GodMode
: Boolean read FGodMode write FGodMode
;
354 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
355 property NoReload
: Boolean read FNoReload write FNoReload
;
356 property alive
: Boolean read FAlive write FAlive
;
357 property Flag
: Byte read FFlag
;
358 property Team
: Byte read FTeam write FTeam
;
359 property Direction
: TDirection read FDirection
;
360 property GameX
: Integer read FObj
.X write FObj
.X
;
361 property GameY
: Integer read FObj
.Y write FObj
.Y
;
362 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
363 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
364 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
365 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
366 property IncCam
: Integer read FIncCam write FIncCam
;
367 property UID
: Word read FUID write FUID
;
368 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
369 property NetTime
: LongWord read FNetTime write FNetTime
;
372 property eName
: String read FName write FName
;
373 property eHealth
: Integer read FHealth write FHealth
;
374 property eLives
: Byte read FLives write FLives
;
375 property eArmor
: Integer read FArmor write FArmor
;
376 property eAir
: Integer read FAir write FAir
;
377 property eJetFuel
: Integer read FJetFuel write FJetFuel
;
378 property eFrags
: Integer read FFrags write FFrags
;
379 property eDeath
: Integer read FDeath write FDeath
;
380 property eKills
: Integer read FKills write FKills
;
381 property eCurrWeap
: Byte read FCurrWeap write FCurrWeap
;
382 property eMonsterKills
: Integer read FMonsterKills write FMonsterKills
;
383 property eSecrets
: Integer read FSecrets write FSecrets
;
384 property eGodMode
: Boolean read FGodMode write FGodMode
;
385 property eNoTarget
: Boolean read FNoTarget write FNoTarget
;
386 property eNoReload
: Boolean read FNoReload write FNoReload
;
387 property eAlive
: Boolean read FAlive write FAlive
;
388 property eFlag
: Byte read FFlag
;
389 property eTeam
: Byte read FTeam write FTeam
;
390 property eDirection
: TDirection read FDirection
;
391 property eGameX
: Integer read FObj
.X write FObj
.X
;
392 property eGameY
: Integer read FObj
.Y write FObj
.Y
;
393 property eGameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
394 property eGameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
395 property eGameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
396 property eGameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
397 property eIncCam
: Integer read FIncCam write FIncCam
;
398 property eUID
: Word read FUID
;
399 property eJustTeleported
: Boolean read FJustTeleported
;
400 property eNetTime
: LongWord read FNetTime
;
402 // set this before assigning something to `eDamage`
403 property eDamageType
: Integer read mEDamageType write mEDamageType
;
404 property eDamage
: Integer write doDamage
;
415 WeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
416 CloseWeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
417 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
420 procedure save (st
: TStream
);
421 procedure load (st
: TStream
);
429 TBot
= class(TPlayer
)
431 FSelectedWeapon
: Byte;
434 FAIFlags
: Array of TAIFlag
;
435 FDifficult
: TDifficult
;
437 function GetRnd(a
: Byte): Boolean;
438 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
439 function RunDirection(): TDirection
;
440 function FullInStep(XInc
, YInc
: Integer): Boolean;
441 //function NeedItem(Item: Byte): Byte;
442 procedure SelectWeapon(Dist
: Integer);
443 procedure SetAIFlag(aName
, fValue
: String20
);
444 function GetAIFlag(aName
: String20
): String20
;
445 procedure RemoveAIFlag(aName
: String20
);
446 function Healthy(): Byte;
447 procedure UpdateMove();
448 procedure UpdateCombat();
449 function KeyPressed(Key
: Word): Boolean;
450 procedure ReleaseKey(Key
: Byte);
451 function TargetOnScreen(TX
, TY
: Integer): Boolean;
452 procedure OnDamage(Angle
: SmallInt); override;
455 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
456 constructor Create(); override;
457 destructor Destroy(); override;
458 procedure Draw(); override;
459 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
460 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
461 procedure Update(); override;
462 procedure SaveState (st
: TStream
); override;
463 procedure LoadState (st
: TStream
); override;
475 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
476 procedure moveBy (dx
, dy
: Integer); inline;
478 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
492 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
493 procedure moveBy (dx
, dy
: Integer); inline;
495 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
498 TCorpse
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
507 FAnimation
: TAnimation
;
508 FAnimationMask
: TAnimation
;
511 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
512 destructor Destroy(); override;
513 procedure Damage(Value
: Word; vx
, vy
: Integer);
516 procedure SaveState (st
: TStream
);
517 procedure LoadState (st
: TStream
);
519 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
520 procedure moveBy (dx
, dy
: Integer); inline;
522 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
524 function ObjPtr (): PObj
; inline;
526 property Obj
: TObj read FObj
; // copies object
527 property State
: Byte read FState
;
528 property Mess
: Boolean read FMess
;
531 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
537 gPlayers
: Array of TPlayer
;
538 gCorpses
: Array of TCorpse
;
539 gGibs
: Array of TGib
;
540 gShells
: Array of TShell
;
541 gTeamStat
: TTeamStat
;
542 gFly
: Boolean = False;
543 gAimLine
: Boolean = False;
544 gChatBubble
: Byte = 0;
548 MAX_RUNVEL
: Integer = 8;
549 VEL_JUMP
: Integer = 10;
550 SHELL_TIMEOUT
: Cardinal = 60000;
552 function Lerp(X
, Y
, Factor
: Integer): Integer;
554 procedure g_Gibs_SetMax(Count
: Word);
555 function g_Gibs_GetMax(): Word;
556 procedure g_Corpses_SetMax(Count
: Word);
557 function g_Corpses_GetMax(): Word;
558 procedure g_Shells_SetMax(Count
: Word);
559 function g_Shells_GetMax(): Word;
561 procedure g_Player_Init();
562 procedure g_Player_Free();
563 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
564 function g_Player_CreateFromState (st
: TStream
): Word;
565 procedure g_Player_Remove(UID
: Word);
566 procedure g_Player_ResetTeams();
567 procedure g_Player_UpdateAll();
568 procedure g_Player_DrawAll();
569 procedure g_Player_DrawDebug(p
: TPlayer
);
570 procedure g_Player_DrawHealth();
571 procedure g_Player_RememberAll();
572 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
573 function g_Player_Get(UID
: Word): TPlayer
;
574 function g_Player_GetCount(): Byte;
575 function g_Player_GetStats(): TPlayerStatArray
;
576 function g_Player_ValidName(Name
: String): Boolean;
577 procedure g_Player_CreateCorpse(Player
: TPlayer
);
578 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
579 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
580 procedure g_Player_UpdatePhysicalObjects();
581 procedure g_Player_DrawCorpses();
582 procedure g_Player_DrawShells();
583 procedure g_Player_RemoveAllCorpses();
584 procedure g_Player_Corpses_SaveState (st
: TStream
);
585 procedure g_Player_Corpses_LoadState (st
: TStream
);
586 procedure g_Bot_Add(Team
, Difficult
: Byte);
587 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1);
588 procedure g_Bot_MixNames();
589 procedure g_Bot_RemoveAll();
594 {$INCLUDE ../nogl/noGLuses.inc}
595 {$IFDEF ENABLE_HOLMES}
598 e_log
, g_map
, g_items
, g_console
, g_gfx
, Math
,
599 g_options
, g_triggers
, g_menu
, g_game
, g_grid
,
600 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
,
601 g_net
, g_netmsg
, g_window
,
604 const PLR_SAVE_VERSION
= 0;
614 diag_precision
: Byte;
618 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
619 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
620 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
624 TIME_RESPAWN1
= 1500;
625 TIME_RESPAWN2
= 2000;
626 TIME_RESPAWN3
= 3000;
629 JET_MAX
= 540; // ~30 sec
630 PLAYER_SUIT_TIME
= 30000;
631 PLAYER_INVUL_TIME
= 30000;
632 PLAYER_INVIS_TIME
= 35000;
633 FRAG_COMBO_TIME
= 3000;
637 ANGLE_RIGHTDOWN
= -35;
639 ANGLE_LEFTDOWN
= -145;
640 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
641 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
644 BOT_UNSAFEDIST
= 128;
645 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
647 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
648 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
649 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
650 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
651 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
652 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
653 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
654 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
655 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
656 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
657 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
658 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
659 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
660 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
661 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
662 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
663 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
664 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
665 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
666 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
667 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
668 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
669 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
670 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
671 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
672 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
674 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
675 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
677 BOTNAMES_FILENAME
= 'botnames.txt';
678 BOTLIST_FILENAME
= 'botlist.txt';
682 MaxCorpses
: Word = 20;
683 MaxShells
: Word = 300;
684 CurrentGib
: Integer = 0;
685 CurrentShell
: Integer = 0;
686 BotNames
: Array of String;
687 BotList
: Array of TBotProfile
;
690 function Lerp(X
, Y
, Factor
: Integer): Integer;
692 Result
:= X
+ ((Y
- X
) div Factor
);
695 function SameTeam(UID1
, UID2
: Word): Boolean;
699 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
700 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
702 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
704 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
705 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
707 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
710 procedure g_Gibs_SetMax(Count
: Word);
713 SetLength(gGibs
, Count
);
715 if CurrentGib
>= Count
then
719 function g_Gibs_GetMax(): Word;
724 procedure g_Shells_SetMax(Count
: Word);
727 SetLength(gShells
, Count
);
729 if CurrentShell
>= Count
then
733 function g_Shells_GetMax(): Word;
739 procedure g_Corpses_SetMax(Count
: Word);
742 SetLength(gCorpses
, Count
);
745 function g_Corpses_GetMax(): Word;
747 Result
:= MaxCorpses
;
750 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
760 // Åñòü ëè ìåñòî â gPlayers:
761 if gPlayers
<> nil then
762 for a
:= 0 to High(gPlayers
) do
763 if gPlayers
[a
] = nil then
769 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
772 SetLength(gPlayers
, Length(gPlayers
)+1);
776 // Ñîçäàåì îáúåêò èãðîêà:
778 gPlayers
[a
] := TBot
.Create()
780 gPlayers
[a
] := TPlayer
.Create();
783 gPlayers
[a
].FActualModelName
:= ModelName
;
784 gPlayers
[a
].SetModel(ModelName
);
786 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
787 if gPlayers
[a
].FModel
= nil then
791 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
795 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
796 if Random(2) = 0 then
800 gPlayers
[a
].FPreferredTeam
:= Team
;
802 case gGameSettings
.GameMode
of
803 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
805 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
807 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
810 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
811 gPlayers
[a
].FColor
:= Color
;
812 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
813 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
815 gPlayers
[a
].FModel
.Color
:= Color
;
817 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
818 gPlayers
[a
].FAlive
:= False;
820 Result
:= gPlayers
[a
].FUID
;
823 function g_Player_CreateFromState (st
: TStream
): Word;
830 if (st
= nil) then exit
; //???
833 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
834 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
837 Bot
:= utils
.readBool(st
);
842 // Åñòü ëè ìåñòî â gPlayers:
843 for a
:= 0 to High(gPlayers
) do if (gPlayers
[a
] = nil) then begin ok
:= true; break
; end;
845 // Íåò ìåñòà - ðàñøèðÿåì gPlayers
848 SetLength(gPlayers
, Length(gPlayers
)+1);
852 // Ñîçäàåì îáúåêò èãðîêà
854 gPlayers
[a
] := TBot
.Create()
856 gPlayers
[a
] := TPlayer
.Create();
857 gPlayers
[a
].FIamBot
:= Bot
;
858 gPlayers
[a
].FPhysics
:= True;
861 gPlayers
[a
].FUID
:= utils
.readWord(st
);
863 gPlayers
[a
].FName
:= utils
.readStr(st
);
865 gPlayers
[a
].FTeam
:= utils
.readByte(st
);
866 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
868 gPlayers
[a
].FAlive
:= utils
.readBool(st
);
869 // Èçðàñõîäîâàë ëè âñå æèçíè
870 gPlayers
[a
].FNoRespawn
:= utils
.readBool(st
);
872 b
:= utils
.readByte(st
);
873 if b
= 1 then gPlayers
[a
].FDirection
:= TDirection
.D_LEFT
else gPlayers
[a
].FDirection
:= TDirection
.D_RIGHT
; // b = 2
875 gPlayers
[a
].FHealth
:= utils
.readLongInt(st
);
877 gPlayers
[a
].FLives
:= utils
.readByte(st
);
879 gPlayers
[a
].FArmor
:= utils
.readLongInt(st
);
881 gPlayers
[a
].FAir
:= utils
.readLongInt(st
);
883 gPlayers
[a
].FJetFuel
:= utils
.readLongInt(st
);
885 gPlayers
[a
].FPain
:= utils
.readLongInt(st
);
887 gPlayers
[a
].FKills
:= utils
.readLongInt(st
);
889 gPlayers
[a
].FMonsterKills
:= utils
.readLongInt(st
);
891 gPlayers
[a
].FFrags
:= utils
.readLongInt(st
);
893 gPlayers
[a
].FFragCombo
:= utils
.readByte(st
);
894 // Âðåìÿ ïîñëåäíåãî ôðàãà
895 gPlayers
[a
].FLastFrag
:= utils
.readLongWord(st
);
897 gPlayers
[a
].FDeath
:= utils
.readLongInt(st
);
899 gPlayers
[a
].FFlag
:= utils
.readByte(st
);
901 gPlayers
[a
].FSecrets
:= utils
.readLongInt(st
);
903 gPlayers
[a
].FCurrWeap
:= utils
.readByte(st
);
904 // Ñëåäóþùåå æåëàåìîå îðóæèå
905 gPlayers
[a
].FNextWeap
:= utils
.readWord(st
);
907 gPlayers
[a
].FNextWeapDelay
:= utils
.readByte(st
);
909 gPlayers
[a
].FBFGFireCounter
:= utils
.readSmallInt(st
);
911 gPlayers
[a
].FDamageBuffer
:= utils
.readLongInt(st
);
912 // Ïîñëåäíèé óäàðèâøèé
913 gPlayers
[a
].FLastSpawnerUID
:= utils
.readWord(st
);
914 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
915 gPlayers
[a
].FLastHit
:= utils
.readByte(st
);
917 Obj_LoadState(@gPlayers
[a
].FObj
, st
);
918 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
919 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FAmmo
[i
] := utils
.readWord(st
);
920 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
921 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FMaxAmmo
[i
] := utils
.readWord(st
);
923 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FWeapon
[i
] := utils
.readBool(st
);
924 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
925 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FReloading
[i
] := utils
.readWord(st
);
927 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
928 // Íàëè÷èå êðàñíîãî êëþ÷à
929 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
930 // Íàëè÷èå çåëåíîãî êëþ÷à
931 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
932 // Íàëè÷èå ñèíåãî êëþ÷à
933 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
935 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_BERSERK
);
936 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
937 for i
:= MR_SUIT
to MR_MAX
do gPlayers
[a
].FMegaRulez
[i
] := utils
.readLongWord(st
);
938 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
939 for i
:= T_RESPAWN
to T_FLAGCAP
do gPlayers
[a
].FTime
[i
] := utils
.readLongWord(st
);
942 gPlayers
[a
].FActualModelName
:= utils
.readStr(st
);
944 gPlayers
[a
].FColor
.R
:= utils
.readByte(st
);
945 gPlayers
[a
].FColor
.G
:= utils
.readByte(st
);
946 gPlayers
[a
].FColor
.B
:= utils
.readByte(st
);
947 // Îáíîâëÿåì ìîäåëü èãðîêà
948 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
950 // Íåò ìîäåëè - ñîçäàíèå íåâîçìîæíî
951 if (gPlayers
[a
].FModel
= nil) then
955 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
959 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû
960 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
961 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
963 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
965 result
:= gPlayers
[a
].FUID
;
969 procedure g_Player_ResetTeams();
973 if g_Game_IsClient
then
975 if gPlayers
= nil then
977 for a
:= Low(gPlayers
) to High(gPlayers
) do
978 if gPlayers
[a
] <> nil then
979 case gGameSettings
.GameMode
of
981 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
983 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
984 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
985 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
988 gPlayers
[a
].ChangeTeam(TEAM_RED
)
990 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
993 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
997 procedure g_Bot_Add(Team
, Difficult
: Byte);
1000 _name
, _model
: String;
1003 if not g_Game_IsServer
then Exit
;
1005 // Ñïèñîê íàçâàíèé ìîäåëåé:
1006 m
:= g_PlayerModel_GetNames();
1011 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1012 Team
:= TEAM_COOP
// COOP
1014 if gGameSettings
.GameMode
= GM_DM
then
1015 Team
:= TEAM_NONE
// DM
1017 if Team
= TEAM_NONE
then // CTF / TDM
1019 // Àâòîáàëàíñ êîìàíä:
1023 for a
:= 0 to High(gPlayers
) do
1024 if gPlayers
[a
] <> nil then
1026 if gPlayers
[a
].Team
= TEAM_RED
then
1029 if gPlayers
[a
].Team
= TEAM_BLUE
then
1039 if Random(2) = 0 then
1045 // Âûáèðàåì áîòó èìÿ:
1047 if BotNames
<> nil then
1048 for a
:= 0 to High(BotNames
) do
1049 if g_Player_ValidName(BotNames
[a
]) then
1051 _name
:= BotNames
[a
];
1055 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
1058 _name
:= Format('DFBOT%.2d', [Random(100)]);
1059 until g_Player_ValidName(_name
);
1061 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1062 _model
:= m
[Random(Length(m
))];
1065 with g_Player_Get(g_Player_Create(_model
,
1066 _RGB(Min(Random(9)*32, 255),
1067 Min(Random(9)*32, 255),
1068 Min(Random(9)*32, 255)),
1069 Team
, True)) as TBot
do
1074 1: FDifficult
:= DIFFICULT_EASY
;
1075 2: FDifficult
:= DIFFICULT_MEDIUM
;
1076 else FDifficult
:= DIFFICULT_HARD
;
1079 for a
:= WP_FIRST
to WP_LAST
do
1081 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1082 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1083 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1086 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1088 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1089 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1094 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1);
1097 _name
, _model
: String;
1100 if not g_Game_IsServer
then Exit
;
1102 // Ñïèñîê íàçâàíèé ìîäåëåé:
1103 m
:= g_PlayerModel_GetNames();
1108 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1109 Team
:= TEAM_COOP
// COOP
1111 if gGameSettings
.GameMode
= GM_DM
then
1112 Team
:= TEAM_NONE
// DM
1114 if Team
= TEAM_NONE
then
1115 Team
:= BotList
[num
].team
; // CTF / TDM
1117 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1118 lName
:= AnsiLowerCase(lName
);
1119 if (num
< 0) or (num
> Length(BotList
)-1) then
1121 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1122 for a
:= 0 to High(BotList
) do
1123 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1132 _name
:= BotList
[num
].name
;
1133 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1134 if not g_Player_ValidName(_name
) then
1136 _name
:= Format('DFBOT%.2d', [Random(100)]);
1137 until g_Player_ValidName(_name
);
1140 _model
:= BotList
[num
].model
;
1141 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1142 if not InSArray(_model
, m
) then
1143 _model
:= m
[Random(Length(m
))];
1146 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1150 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1151 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1152 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1153 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1154 FDifficult
.Cover
:= BotList
[num
].cover
;
1155 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1157 for a
:= WP_FIRST
to WP_LAST
do
1159 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1160 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1161 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1164 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1166 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1170 procedure g_Bot_RemoveAll();
1174 if not g_Game_IsServer
then Exit
;
1175 if gPlayers
= nil then Exit
;
1177 for a
:= 0 to High(gPlayers
) do
1178 if gPlayers
[a
] <> nil then
1179 if gPlayers
[a
] is TBot
then
1181 gPlayers
[a
].Lives
:= 0;
1182 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1183 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1184 g_Player_Remove(gPlayers
[a
].FUID
);
1190 procedure g_Bot_MixNames();
1195 if BotNames
<> nil then
1196 for a
:= 0 to High(BotNames
) do
1198 b
:= Random(Length(BotNames
));
1200 Botnames
[a
] := BotNames
[b
];
1205 procedure g_Player_Remove(UID
: Word);
1209 if gPlayers
= nil then Exit
;
1211 if g_Game_IsServer
and g_Game_IsNet
then
1212 MH_SEND_PlayerDelete(UID
);
1214 for i
:= 0 to High(gPlayers
) do
1215 if gPlayers
[i
] <> nil then
1216 if gPlayers
[i
].FUID
= UID
then
1218 if gPlayers
[i
] is TPlayer
then
1219 TPlayer(gPlayers
[i
]).Free()
1221 TBot(gPlayers
[i
]).Free();
1227 procedure g_Player_Init();
1237 if not FileExists(DataDir
+ BOTNAMES_FILENAME
) then
1240 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1241 AssignFile(F
, DataDir
+ BOTNAMES_FILENAME
);
1252 SetLength(BotNames
, Length(BotNames
)+1);
1253 BotNames
[High(BotNames
)] := s
;
1261 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1262 config
:= TConfig
.CreateFile(DataDir
+ BOTLIST_FILENAME
);
1266 while config
.SectionExists(IntToStr(a
)) do
1268 SetLength(BotList
, Length(BotList
)+1);
1270 with BotList
[High(BotList
)] do
1273 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1275 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1277 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1282 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1283 color
.R
:= StrToIntDef(sa
[0], 0);
1284 color
.G
:= StrToIntDef(sa
[1], 0);
1285 color
.B
:= StrToIntDef(sa
[2], 0);
1286 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1287 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1288 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1289 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1290 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1291 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1292 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1293 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1294 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1295 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1296 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1297 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1298 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1299 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1300 if Length(sa
) = 10 then
1302 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1303 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1304 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1305 if Length(sa
) = 10 then
1307 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1309 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1310 if Length(sa) = 10 then
1312 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1321 procedure g_Player_Free();
1325 if gPlayers
<> nil then
1327 for i
:= 0 to High(gPlayers
) do
1328 if gPlayers
[i
] <> nil then
1330 if gPlayers
[i
] is TPlayer
then
1331 TPlayer(gPlayers
[i
]).Free()
1333 TBot(gPlayers
[i
]).Free();
1344 procedure g_Player_UpdateAll();
1348 if gPlayers
= nil then Exit
;
1350 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1351 for i
:= 0 to High(gPlayers
) do
1353 if gPlayers
[i
] <> nil then
1355 if gPlayers
[i
] is TPlayer
then
1357 gPlayers
[i
].Update();
1358 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1362 // bot updates weapons in `UpdateCombat()`
1363 TBot(gPlayers
[i
]).Update();
1367 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1370 procedure g_Player_DrawAll();
1374 if gPlayers
= nil then Exit
;
1376 for i
:= 0 to High(gPlayers
) do
1377 if gPlayers
[i
] <> nil then
1378 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1379 else TBot(gPlayers
[i
]).Draw();
1382 procedure g_Player_DrawDebug(p
: TPlayer
);
1386 if p
= nil then Exit
;
1387 if (@p
.FObj
) = nil then Exit
;
1389 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1391 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1392 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1393 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1394 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1395 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1396 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1399 procedure g_Player_DrawHealth();
1404 if gPlayers
= nil then Exit
;
1405 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1407 for i
:= 0 to High(gPlayers
) do
1408 if gPlayers
[i
] <> nil then
1410 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1411 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1412 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1413 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1414 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1415 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1419 function g_Player_Get(UID
: Word): TPlayer
;
1425 if gPlayers
= nil then
1428 for a
:= 0 to High(gPlayers
) do
1429 if gPlayers
[a
] <> nil then
1430 if gPlayers
[a
].FUID
= UID
then
1432 Result
:= gPlayers
[a
];
1437 function g_Player_GetCount(): Byte;
1443 if gPlayers
= nil then
1446 for a
:= 0 to High(gPlayers
) do
1447 if gPlayers
[a
] <> nil then
1448 Result
:= Result
+ 1;
1451 function g_Player_GetStats(): TPlayerStatArray
;
1457 if gPlayers
= nil then Exit
;
1459 for a
:= 0 to High(gPlayers
) do
1460 if gPlayers
[a
] <> nil then
1462 SetLength(Result
, Length(Result
)+1);
1463 with Result
[High(Result
)] do
1465 Ping
:= gPlayers
[a
].FPing
;
1466 Loss
:= gPlayers
[a
].FLoss
;
1467 Name
:= gPlayers
[a
].FName
;
1468 Team
:= gPlayers
[a
].FTeam
;
1469 Frags
:= gPlayers
[a
].FFrags
;
1470 Deaths
:= gPlayers
[a
].FDeath
;
1471 Kills
:= gPlayers
[a
].FKills
;
1472 Color
:= gPlayers
[a
].FModel
.Color
;
1473 Lives
:= gPlayers
[a
].FLives
;
1474 Spectator
:= gPlayers
[a
].FSpectator
;
1479 procedure g_Player_RememberAll
;
1483 for i
:= Low(gPlayers
) to High(gPlayers
) do
1484 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1485 gPlayers
[i
].RememberState
;
1488 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1492 gTeamStat
[TEAM_RED
].Goals
:= 0;
1493 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1495 if gPlayers
<> nil then
1496 for i
:= 0 to High(gPlayers
) do
1497 if gPlayers
[i
] <> nil then
1499 gPlayers
[i
].Reset(Force
);
1501 if gPlayers
[i
] is TPlayer
then
1503 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1504 gPlayers
[i
].Respawn(Silent
)
1506 gPlayers
[i
].Spectate();
1509 TBot(gPlayers
[i
]).Respawn(Silent
);
1513 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1518 if Player
.alive
then
1520 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1525 if (FHealth
>= -50) or (gGibsCount
= 0) then
1527 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1531 for find_id
:= 0 to High(gCorpses
) do
1532 if gCorpses
[find_id
] = nil then
1539 find_id
:= Random(Length(gCorpses
));
1541 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1542 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1543 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1544 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1545 gCorpses
[find_id
].FPlayerUID
:= FUID
;
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
2362 FPunchAnim
.Draw(FObj
.X
+IfThen(Direction
= TDirection
.D_LEFT
, 15-FObj
.Rect
.X
, FObj
.Rect
.X
-15),
2363 FObj
.Y
+FObj
.Rect
.Y
-11, Mirror
);
2364 if FPunchAnim
.played
then
2371 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2372 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2374 e_GetTextureSize(ID
, @w
, @h
);
2375 if FDirection
= TDirection
.D_LEFT
then
2376 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2377 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False)
2379 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2380 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False);
2383 if FMegaRulez
[MR_INVIS
] > gTime
then
2385 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2386 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2388 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2389 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2393 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 200)
2395 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2398 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 254);
2401 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2404 if g_debug_Frames
then
2406 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2408 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2409 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2413 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2415 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2416 if gAimLine
and alive
and
2417 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2422 procedure TPlayer
.DrawAim();
2423 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2428 {$IFDEF ENABLE_HOLMES}
2429 if isValidViewPort
and (self
= gPlayer1
) then
2431 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2435 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2436 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2438 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2442 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2447 wx
, wy
, xx
, yy
: Integer;
2451 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= TDirection
.D_LEFT
, 7, -7);
2452 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2461 1: begin // Chainsaw
2468 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2469 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2470 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2471 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2476 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2477 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2478 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2479 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2481 4: begin // Double Shotgun
2484 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2485 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2486 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2487 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2489 5: begin // Chaingun
2492 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2493 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2494 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2495 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2497 6: begin // Rocket Launcher
2500 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2501 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2502 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2503 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2505 7: begin // Plasmagun
2508 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2509 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2510 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2511 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2516 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2517 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2518 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2519 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2521 9: begin // Super Chaingun
2524 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2525 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2526 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2527 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2530 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2531 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2532 {$IF DEFINED(D2F_DEBUG)}
2533 drawCast(sz
, wx
, wy
, xx
, yy
);
2535 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2539 procedure TPlayer
.DrawGUI();
2542 X
, Y
, SY
, a
, p
, m
: Integer;
2546 stat
: TPlayerStatArray
;
2548 X
:= gPlayerScreenSize
.X
;
2549 SY
:= gPlayerScreenSize
.Y
;
2552 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2554 if gGameSettings
.GameMode
= GM_CTF
then
2558 if gGameSettings
.GameMode
= GM_CTF
then
2560 s
:= 'TEXTURE_PLAYER_REDFLAG';
2561 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2562 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2563 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2564 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2565 if g_Texture_Get(s
, ID
) then
2566 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2569 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2570 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2571 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2573 if gGameSettings
.GameMode
= GM_CTF
then
2575 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2576 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2577 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2578 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2579 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2580 if g_Texture_Get(s
, ID
) then
2581 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2584 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2585 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2586 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2589 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2590 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2593 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2594 e_Draw(ID
, X
+2, Y
, 0, True, False);
2596 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2600 s
:= IntToStr(Frags
);
2601 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2602 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2607 stat
:= g_Player_GetStats();
2612 for a
:= 0 to High(stat
) do
2613 if stat
[a
].Name
<> Name
then
2615 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2616 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2620 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2621 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2622 s
:= s
+IntToStr(Abs(Frags
-m
));
2624 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2625 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2628 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2630 s
:= IntToStr(Lives
);
2631 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2632 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2636 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2637 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2639 if R_BERSERK
in FRulez
then
2640 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2642 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2644 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2645 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2647 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2648 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2649 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2651 s
:= IntToStr(FArmor
);
2652 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2653 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2655 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2661 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2666 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2668 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2669 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2670 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2671 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2672 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2673 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2674 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2675 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2676 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2679 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2680 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2681 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2683 if R_KEY_RED
in FRulez
then
2684 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2686 if R_KEY_GREEN
in FRulez
then
2687 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2689 if R_KEY_BLUE
in FRulez
then
2690 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2692 if FJetFuel
> 0 then
2694 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2695 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2696 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2697 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2698 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2699 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2703 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2704 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2705 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2708 if gShowPing
and g_Game_IsClient
then
2710 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2711 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2717 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2718 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2719 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2722 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2723 s
:= _lc
[I_PLAYER_SPECT4
];
2724 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2725 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2726 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2732 procedure TPlayer
.DrawRulez();
2736 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2737 if FMegaRulez
[MR_INVUL
] >= gTime
then
2739 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2740 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2745 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2746 191, 191, 191, 0, TBlending
.Invert
);
2749 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2750 if FMegaRulez
[MR_SUIT
] >= gTime
then
2752 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2753 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2758 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2759 0, 96, 0, 200, TBlending
.None
);
2762 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2763 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2765 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2766 255, 0, 0, 200, TBlending
.None
);
2770 procedure TPlayer
.DrawPain();
2774 if FPain
= 0 then Exit
;
2778 if a
< 15 then h
:= 0
2779 else if a
< 35 then h
:= 1
2780 else if a
< 55 then h
:= 2
2781 else if a
< 75 then h
:= 3
2782 else if a
< 95 then h
:= 4
2785 //if a > 255 then a := 255;
2787 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2788 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2791 procedure TPlayer
.DrawPickup();
2795 if FPickup
= 0 then Exit
;
2799 if a
< 15 then h
:= 1
2800 else if a
< 35 then h
:= 2
2801 else if a
< 55 then h
:= 3
2802 else if a
< 75 then h
:= 4
2805 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2808 procedure TPlayer
.DoPunch();
2813 if FPunchAnim
<> nil then begin
2818 st
:= 'FRAMES_PUNCH';
2819 if R_BERSERK
in FRulez
then
2820 st
:= st
+ '_BERSERK';
2821 if FKeys
[KEY_UP
].Pressed
then
2823 else if FKeys
[KEY_DOWN
].Pressed
then
2825 g_Frames_Get(id
, st
);
2826 FPunchAnim
:= TAnimation
.Create(id
, False, 1);
2829 procedure TPlayer
.Fire();
2831 f
, DidFire
: Boolean;
2832 wx
, wy
, xd
, yd
: Integer;
2835 if g_Game_IsClient
then Exit
;
2836 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2837 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2845 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2850 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2851 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2852 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
2853 yd
:= wy
+firediry();
2859 if R_BERSERK
in FRulez
then
2861 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2862 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2863 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2866 locobj
.rect
.Width
:= 39;
2867 locobj
.rect
.Height
:= 52;
2868 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2869 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2870 locobj
.Accel
.X
:= xd
-wx
;
2871 locobj
.Accel
.y
:= yd
-wy
;
2873 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2874 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2876 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2878 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
2882 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2886 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2891 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2892 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2894 FSawSoundSelect
.Stop();
2896 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2898 else if not FSawSoundHit
.IsPlaying() then
2900 FSawSoundSelect
.Stop();
2901 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2904 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2910 if FAmmo
[A_BULLETS
] > 0 then
2912 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2913 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2914 Dec(FAmmo
[A_BULLETS
]);
2915 FFireAngle
:= FAngle
;
2918 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2919 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2923 if FAmmo
[A_SHELLS
] > 0 then
2925 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2926 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
2927 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2928 Dec(FAmmo
[A_SHELLS
]);
2929 FFireAngle
:= FAngle
;
2933 FShellType
:= SHELL_SHELL
;
2937 if FAmmo
[A_SHELLS
] >= 2 then
2939 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
2940 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2941 Dec(FAmmo
[A_SHELLS
], 2);
2942 FFireAngle
:= FAngle
;
2946 FShellType
:= SHELL_DBLSHELL
;
2950 if FAmmo
[A_BULLETS
] > 0 then
2952 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
2953 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
2954 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2955 Dec(FAmmo
[A_BULLETS
]);
2956 FFireAngle
:= FAngle
;
2959 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2960 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2963 WEAPON_ROCKETLAUNCHER
:
2964 if FAmmo
[A_ROCKETS
] > 0 then
2966 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
2967 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2968 Dec(FAmmo
[A_ROCKETS
]);
2969 FFireAngle
:= FAngle
;
2975 if FAmmo
[A_CELLS
] > 0 then
2977 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
2978 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2979 Dec(FAmmo
[A_CELLS
]);
2980 FFireAngle
:= FAngle
;
2986 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
2988 FBFGFireCounter
:= 17;
2989 if not FNoReload
then
2990 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
2991 Dec(FAmmo
[A_CELLS
], 40);
2995 WEAPON_SUPERPULEMET
:
2996 if FAmmo
[A_SHELLS
] > 0 then
2998 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2999 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
3000 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3001 Dec(FAmmo
[A_SHELLS
]);
3002 FFireAngle
:= FAngle
;
3005 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3006 GameVelX
, GameVelY
-2, SHELL_SHELL
);
3009 WEAPON_FLAMETHROWER
:
3010 if FAmmo
[A_FUEL
] > 0 then
3012 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
3013 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3015 FFireAngle
:= FAngle
;
3021 if g_Game_IsNet
then
3025 if FCurrWeap
<> WEAPON_BFG
then
3026 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
3028 if not FNoReload
then
3029 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
3032 MH_SEND_PlayerStats(FUID
);
3037 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
3038 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
3039 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
3042 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
3045 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
3046 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
3047 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
3048 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
3049 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
3054 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
3056 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
3057 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
3058 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
3061 procedure TPlayer
.JetpackOn
;
3065 FJetSoundOn
.SetPosition(0);
3066 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3070 procedure TPlayer
.JetpackOff
;
3074 FJetSoundOff
.SetPosition(0);
3075 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3078 procedure TPlayer
.CatchFire(Attacker
: Word);
3081 FFireAttacker
:= Attacker
;
3082 if g_Game_IsNet
and g_Game_IsServer
then
3083 MH_SEND_PlayerStats(FUID
);
3086 procedure TPlayer
.Jump();
3088 if gFly
or FJetpack
then
3090 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3091 if FObj
.Vel
.Y
> -VEL_FLY
then
3092 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3095 if FJetFuel
> 0 then
3097 if (FJetFuel
< 1) and g_Game_IsServer
then
3101 if g_Game_IsNet
then
3102 MH_SEND_PlayerStats(FUID
);
3108 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3110 FCanJetpack
:= False;
3112 // Ïðûãàåì èëè âñïëûâàåì:
3113 if (CollideLevel(0, 1) or
3114 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3115 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3116 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3118 FObj
.Vel
.Y
:= -VEL_JUMP
;
3119 FCanJetpack
:= False;
3123 if BodyInLiquid(0, 0) then
3124 FObj
.Vel
.Y
:= -VEL_SW
3125 else if (FJetFuel
> 0) and FCanJetpack
and
3126 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3130 if g_Game_IsNet
then
3131 MH_SEND_PlayerStats(FUID
);
3136 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3138 a
, i
, k
, ab
, ar
: Byte;
3142 srv
, netsrv
: Boolean;
3148 procedure PushItem(t
: Byte);
3152 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3153 it
:= g_Items_ByIdx(id
);
3154 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3156 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3157 (FObj
.Vel
.Y
div 2)-Random(9));
3158 it
.positionChanged(); // this updates spatial accelerators
3162 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3164 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3165 (FObj
.Vel
.Y
div 2)-Random(6));
3167 else // -3..+3; -3..0
3169 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3170 (FObj
.Vel
.Y
div 2)-Random(4));
3172 it
.positionChanged(); // this updates spatial accelerators
3175 if g_Game_IsNet
and g_Game_IsServer
then
3176 MH_SEND_ItemSpawn(True, id
);
3180 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3181 Srv
:= g_Game_IsServer
;
3182 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3183 if Srv
then FDeath
:= FDeath
+ 1;
3188 if not FPhysics
then
3194 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3196 if FLives
> 0 then FLives
:= FLives
- 1;
3197 if FLives
= 0 then FNoRespawn
:= True;
3200 // Íîìåð òèïà ñìåðòè:
3203 K_SIMPLEKILL
: a
:= 1;
3205 K_EXTRAHARDKILL
: a
:= 3;
3210 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3212 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3219 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3221 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3222 K_EXTRAHARDKILL
, K_FALLKILL
:
3223 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3226 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3230 K_HARDKILL
, K_EXTRAHARDKILL
:
3234 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3235 if (KillType
<> K_FALLKILL
) and (Srv
) then
3236 g_Monsters_killedp();
3238 if SpawnerUID
= FUID
then
3240 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3245 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3248 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3249 begin // Óáèò äðóãèì èãðîêîì
3250 KP
:= g_Player_Get(SpawnerUID
);
3251 if (KP
<> nil) and Srv
then
3253 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3254 if SameTeam(FUID
, SpawnerUID
) then
3264 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3265 Inc(gTeamStat
[KP
.Team
].Goals
,
3266 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3268 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3271 plr
:= g_Player_Get(SpawnerUID
);
3279 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3283 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3287 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3292 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3293 begin // Óáèò ìîíñòðîì
3294 mon
:= g_Monsters_ByUID(SpawnerUID
);
3298 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
3302 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3306 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3310 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3315 else // Îñîáûå òèïû ñìåðòè
3318 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3319 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3320 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3321 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3322 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3323 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3329 for a
:= WP_FIRST
to WP_LAST
do
3333 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3334 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3335 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3336 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3337 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3338 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3339 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3340 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3341 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3350 if R_ITEM_BACKPACK
in FRulez
then
3351 PushItem(ITEM_AMMO_BACKPACK
);
3353 // Âûáðîñ ðàêåòíîãî ðàíöà:
3354 if FJetFuel
> 0 then
3355 PushItem(ITEM_JETPACK
);
3358 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3360 if R_KEY_RED
in FRulez
then
3361 PushItem(ITEM_KEY_RED
);
3363 if R_KEY_GREEN
in FRulez
then
3364 PushItem(ITEM_KEY_GREEN
);
3366 if R_KEY_BLUE
in FRulez
then
3367 PushItem(ITEM_KEY_BLUE
);
3374 g_Player_CreateCorpse(Self
);
3376 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3377 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3383 for i
:= Low(gPlayers
) to High(gPlayers
) do
3385 if gPlayers
[i
] = nil then continue
;
3386 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3389 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3390 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3395 OldLR
:= gLMSRespawn
;
3396 if (gGameSettings
.GameMode
= GM_COOP
) then
3400 // everyone is dead, restart the map
3401 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3403 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3404 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3405 gLMSRespawnTime
:= gTime
+ 5000;
3407 else if (a
= 1) then
3409 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3410 if (gPlayers
[k
] = gPlayer1
) or
3411 (gPlayers
[k
] = gPlayer2
) then
3412 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3413 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3414 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3417 else if (gGameSettings
.GameMode
= GM_TDM
) then
3419 if (ab
= 0) and (ar
<> 0) then
3422 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3424 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3425 Inc(gTeamStat
[TEAM_RED
].Goals
);
3426 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3427 gLMSRespawnTime
:= gTime
+ 5000;
3429 else if (ar
= 0) and (ab
<> 0) then
3432 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3434 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3435 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3436 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3437 gLMSRespawnTime
:= gTime
+ 5000;
3439 else if (ar
= 0) and (ab
= 0) then
3442 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3444 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3445 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3446 gLMSRespawnTime
:= gTime
+ 5000;
3449 else if (gGameSettings
.GameMode
= GM_DM
) then
3453 if gPlayers
[k
] <> nil then
3456 // survivor is the winner
3457 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3459 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3462 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3463 gLMSRespawnTime
:= gTime
+ 5000;
3465 else if (a
= 0) then
3467 // everyone is dead, restart the map
3468 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3470 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3471 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3472 gLMSRespawnTime
:= gTime
+ 5000;
3475 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3477 if NetMode
= NET_SERVER
then
3478 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3480 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3486 MH_SEND_PlayerStats(FUID
);
3487 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3488 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3491 if srv
and FNoRespawn
then Spectate(True);
3492 FWantsInGame
:= True;
3495 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3497 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3498 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3501 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3503 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3504 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3507 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3509 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3510 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3511 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3513 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3514 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3515 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3519 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3521 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3522 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3523 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3527 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3529 if g_Game_IsClient
then Exit
;
3530 if Weapon
> High(FWeapon
) then Exit
;
3531 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3534 procedure TPlayer
.resetWeaponQueue ();
3537 FNextWeapDelay
:= 0;
3540 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3544 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3545 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 0);
3546 WEAPON_PISTOL
, WEAPON_CHAINGUN
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_BULLETS
] > 0);
3547 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3548 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3549 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3550 else result
:= (weapon
< length(FWeapon
));
3554 // return 255 for "no switch"
3555 function TPlayer
.getNextWeaponIndex (): Byte;
3558 wantThisWeapon
: array[0..64] of Boolean;
3559 weaponOrder
: array[0..64] of Integer; // value: index in `FWeapon`
3560 wwc
: Integer = 0; //HACK!
3561 dir
, cwi
, rwidx
, curlidx
: Integer;
3563 function real2log (ridx
: Integer): Integer;
3569 for f
:= 0 to 10 do if (weaponOrder
[f
] = ridx
) then begin result
:= f
; exit
; end;
3575 result
:= 255; // default result: "no switch"
3577 // had weapon cycling on previous frame? remove that flag
3578 if (FNextWeap
and $2000) <> 0 then
3580 FNextWeap
:= FNextWeap
and $1FFF;
3581 FNextWeapDelay
:= 0;
3584 // build weapon order (k8: i know, i know, learn how to do constants and such... gtfo, please!)
3586 // bfg, plasma, flamethrower, ssg, minigun, sg, pistol, berserk, chainsaw, fist
3587 weaponOrder
[0] := WEAPON_BFG
;
3588 weaponOrder
[1] := WEAPON_PLASMA
;
3589 weaponOrder
[2] := WEAPON_FLAMETHROWER
;
3590 weaponOrder
[3] := WEAPON_SHOTGUN2
;
3591 weaponOrder
[4] := WEAPON_CHAINGUN
;
3592 weaponOrder
[5] := WEAPON_SHOTGUN1
;
3593 weaponOrder
[6] := WEAPON_PISTOL
;
3594 weaponOrder
[7] := WEAPON_KASTET
;
3595 weaponOrder
[8] := WEAPON_SAW
;
3596 weaponOrder
[9] := WEAPON_KASTET
;
3597 weaponOrder
[10] := WEAPON_SUPERPULEMET
;
3599 if (R_BERSERK
in FRulez
) then weaponOrder
[9] := -1 else weaponOrder
[7] := -1;
3605 WEAPON_SHOTGUN1 = 3;
3606 WEAPON_SHOTGUN2 = 4;
3607 WEAPON_CHAINGUN = 5;
3608 WEAPON_ROCKETLAUNCHER = 6;
3611 WEAPON_SUPERPULEMET = 9;
3612 WEAPON_FLAMETHROWER = 10;
3615 // cycling has priority
3616 if (FNextWeap
and $C000) <> 0 then
3618 if (FNextWeap
and $8000) <> 0 then dir
:= 1 else dir
:= -1; // should be reversed if we want "priority-driven cycling"
3619 FNextWeap
:= FNextWeap
or $2000; // we need this
3620 if FNextWeapDelay
> 0 then exit
; // cooldown time
3621 //cwi := real2log(FCurrWeap);
3622 //if (cwi < 0) then cwi := 0;
3624 for i
:= 0 to High(FWeapon
) do
3626 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3627 //rwidx := weaponOrder[cwi];
3628 rwidx
:= cwi
; // sorry
3629 if (rwidx
< 0) then continue
;
3630 if FWeapon
[rwidx
] then
3632 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d (dir=%d; log=%d)', [FCurrWeap, rwidx, dir, cwi]), TMsgType.Warning);
3633 result
:= Byte(rwidx
);
3634 FNextWeapDelay
:= 10;
3643 for i
:= 0 to High(wantThisWeapon
) do wantThisWeapon
[i
] := false;
3644 for i
:= 0 to High(FWeapon
) do
3646 if (FNextWeap
and (1 shl i
)) <> 0 then
3649 if (cwi
>= 0) then wantThisWeapon
[cwi
] := true;
3654 // slow down alterations a little
3657 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3658 // more than one weapon requested, assume "alteration", and check alteration delay
3659 if FNextWeapDelay
> 0 then
3666 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3667 // but clear all counters if no weapon should be switched
3673 //e_WriteLog(Format('wwc=%d', [wwc]), TMsgType.Warning);
3675 // exclude currently selected weapon from the set
3676 curlidx
:= real2log(FCurrWeap
);
3677 //e_WriteLog(Format('FCurrWeap=%d; curlidx=%d', [FCurrWeap, curlidx]), TMsgType.Warning);
3678 //if (curlidx >= 0) then wantThisWeapon[curlidx] := false;
3679 //if (wwc = 2) then begin Dec(wwc); end; // easy case: switch between two weapons
3681 // find next weapon to switch onto
3683 for i
:= 0 to High(FWeapon
) do
3685 cwi
:= (cwi
+length(FWeapon
)+1) mod length(FWeapon
);
3686 if (cwi
= curlidx
) then continue
; // skip current weapon
3687 if not wantThisWeapon
[cwi
] then continue
;
3688 rwidx
:= weaponOrder
[cwi
];
3689 if (rwidx
< 0) then continue
;
3690 //e_WriteLog(Format(' trying logical %d (real %d)', [cwi, rwidx]), TMsgType.Warning);
3691 if FWeapon
[cwi
] and ((wwc
= 1) or hasAmmoForWeapon(cwi
)) then
3694 result
:= Byte(rwidx
);
3696 FNextWeapDelay
:= 10; // anyway, 'cause why not
3701 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3705 procedure TPlayer
.RealizeCurrentWeapon();
3706 function switchAllowed (): Boolean;
3711 if FBFGFireCounter
<> -1 then
3713 if FTime
[T_SWITCH
] > gTime
then
3715 for i
:= WP_FIRST
to WP_LAST
do
3716 if FReloading
[i
] > 0 then
3724 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3725 //FNextWeap := FNextWeap and $1FFF;
3726 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3728 if not switchAllowed
then
3730 //HACK for weapon cycling
3731 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3735 nw
:= getNextWeaponIndex();
3736 if nw
= 255 then exit
; // don't reset anything here
3737 if nw
> High(FWeapon
) then
3739 // don't forget to reset queue here!
3740 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3748 FTime
[T_SWITCH
] := gTime
+156;
3749 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3750 FModel
.SetWeapon(FCurrWeap
);
3751 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3755 procedure TPlayer
.NextWeapon();
3757 if g_Game_IsClient
then Exit
;
3761 procedure TPlayer
.PrevWeapon();
3763 if g_Game_IsClient
then Exit
;
3767 procedure TPlayer
.SetWeapon(W
: Byte);
3769 if FCurrWeap
<> W
then
3770 if W
= WEAPON_SAW
then
3771 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3774 FModel
.SetWeapon(CurrWeap
);
3778 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3780 function allowBerserkSwitching (): Boolean;
3782 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3784 if gBerserkAutoswitch
then exit
;
3785 if not conIsCheatsEnabled
then exit
;
3793 if g_Game_IsClient
then Exit
;
3795 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3796 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3801 if FHealth
< PLAYER_HP_SOFT
then
3803 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3807 if gFlash
= 2 then Inc(FPickup
, 5);
3811 if FHealth
< PLAYER_HP_SOFT
then
3813 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3817 if gFlash
= 2 then Inc(FPickup
, 5);
3821 if FArmor
< PLAYER_AP_SOFT
then
3823 FArmor
:= PLAYER_AP_SOFT
;
3826 if gFlash
= 2 then Inc(FPickup
, 5);
3830 if FArmor
< PLAYER_AP_LIMIT
then
3832 FArmor
:= PLAYER_AP_LIMIT
;
3835 if gFlash
= 2 then Inc(FPickup
, 5);
3839 if FHealth
< PLAYER_HP_LIMIT
then
3841 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3845 if gFlash
= 2 then Inc(FPickup
, 5);
3849 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3851 if FHealth
< PLAYER_HP_LIMIT
then
3852 FHealth
:= PLAYER_HP_LIMIT
;
3853 if FArmor
< PLAYER_AP_LIMIT
then
3854 FArmor
:= PLAYER_AP_LIMIT
;
3858 if gFlash
= 2 then Inc(FPickup
, 5);
3862 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3864 FWeapon
[WEAPON_SAW
] := True;
3866 if gFlash
= 2 then Inc(FPickup
, 5);
3867 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3870 ITEM_WEAPON_SHOTGUN1
:
3871 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3873 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3874 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3876 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3877 FWeapon
[WEAPON_SHOTGUN1
] := True;
3879 if gFlash
= 2 then Inc(FPickup
, 5);
3880 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3883 ITEM_WEAPON_SHOTGUN2
:
3884 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3886 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3888 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3889 FWeapon
[WEAPON_SHOTGUN2
] := True;
3891 if gFlash
= 2 then Inc(FPickup
, 5);
3892 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3895 ITEM_WEAPON_CHAINGUN
:
3896 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3898 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3900 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3901 FWeapon
[WEAPON_CHAINGUN
] := True;
3903 if gFlash
= 2 then Inc(FPickup
, 5);
3904 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3907 ITEM_WEAPON_ROCKETLAUNCHER
:
3908 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3910 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3912 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3913 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3915 if gFlash
= 2 then Inc(FPickup
, 5);
3916 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3920 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3922 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3924 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3925 FWeapon
[WEAPON_PLASMA
] := True;
3927 if gFlash
= 2 then Inc(FPickup
, 5);
3928 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3932 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3934 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3936 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3937 FWeapon
[WEAPON_BFG
] := True;
3939 if gFlash
= 2 then Inc(FPickup
, 5);
3940 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3943 ITEM_WEAPON_SUPERPULEMET
:
3944 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3946 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3948 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3949 FWeapon
[WEAPON_SUPERPULEMET
] := True;
3951 if gFlash
= 2 then Inc(FPickup
, 5);
3952 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3955 ITEM_WEAPON_FLAMETHROWER
:
3956 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
3958 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
3960 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3961 FWeapon
[WEAPON_FLAMETHROWER
] := True;
3963 if gFlash
= 2 then Inc(FPickup
, 5);
3964 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3968 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3970 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3973 if gFlash
= 2 then Inc(FPickup
, 5);
3976 ITEM_AMMO_BULLETS_BOX
:
3977 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3979 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3982 if gFlash
= 2 then Inc(FPickup
, 5);
3986 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3988 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3991 if gFlash
= 2 then Inc(FPickup
, 5);
3994 ITEM_AMMO_SHELLS_BOX
:
3995 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3997 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
4000 if gFlash
= 2 then Inc(FPickup
, 5);
4004 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4006 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4009 if gFlash
= 2 then Inc(FPickup
, 5);
4012 ITEM_AMMO_ROCKET_BOX
:
4013 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4015 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
4018 if gFlash
= 2 then Inc(FPickup
, 5);
4022 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4024 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4027 if gFlash
= 2 then Inc(FPickup
, 5);
4031 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4033 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4036 if gFlash
= 2 then Inc(FPickup
, 5);
4040 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4042 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4045 if gFlash
= 2 then Inc(FPickup
, 5);
4049 if not(R_ITEM_BACKPACK
in FRulez
) or
4050 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4051 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4052 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4053 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4054 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
4056 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4057 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4058 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4059 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4060 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4062 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4063 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4064 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4065 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4066 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4067 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4068 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4069 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4071 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
4074 if gFlash
= 2 then Inc(FPickup
, 5);
4078 if not(R_KEY_RED
in FRulez
) then
4080 Include(FRulez
, R_KEY_RED
);
4082 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4083 if gFlash
= 2 then Inc(FPickup
, 5);
4084 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4088 if not(R_KEY_GREEN
in FRulez
) then
4090 Include(FRulez
, R_KEY_GREEN
);
4092 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4093 if gFlash
= 2 then Inc(FPickup
, 5);
4094 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4098 if not(R_KEY_BLUE
in FRulez
) then
4100 Include(FRulez
, R_KEY_BLUE
);
4102 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4103 if gFlash
= 2 then Inc(FPickup
, 5);
4104 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4108 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4110 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4114 if gFlash
= 2 then Inc(FPickup
, 5);
4118 if FAir
< AIR_MAX
then
4123 if gFlash
= 2 then Inc(FPickup
, 5);
4128 if not (R_BERSERK
in FRulez
) then
4130 Include(FRulez
, R_BERSERK
);
4131 if allowBerserkSwitching
then
4133 FCurrWeap
:= WEAPON_KASTET
;
4135 FModel
.SetWeapon(WEAPON_KASTET
);
4140 if gFlash
= 2 then Inc(FPickup
, 5);
4142 FBerserk
:= gTime
+30000;
4147 if FHealth
< PLAYER_HP_SOFT
then
4149 FHealth
:= PLAYER_HP_SOFT
;
4150 FBerserk
:= gTime
+30000;
4158 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4160 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4163 if gFlash
= 2 then Inc(FPickup
, 5);
4167 if FHealth
< PLAYER_HP_LIMIT
then
4169 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4173 if gFlash
= 2 then Inc(FPickup
, 5);
4177 if FArmor
< PLAYER_AP_LIMIT
then
4179 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4182 if gFlash
= 2 then Inc(FPickup
, 5);
4186 if FJetFuel
< JET_MAX
then
4188 FJetFuel
:= JET_MAX
;
4191 if gFlash
= 2 then Inc(FPickup
, 5);
4195 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4197 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4200 if gFlash
= 2 then Inc(FPickup
, 5);
4205 procedure TPlayer
.Touch();
4209 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4212 // Áðîñèòü ôëàã òîâàðèùó:
4213 if gGameSettings
.GameMode
= GM_CTF
then
4218 procedure TPlayer
.Push(vx
, vy
: Integer);
4220 if (not FPhysics
) and FGhost
then
4222 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4223 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4224 if g_Game_IsNet
and g_Game_IsServer
then
4225 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4228 procedure TPlayer
.Reset(Force
: Boolean);
4234 FTime
[T_RESPAWN
] := 0;
4235 FTime
[T_FLAGCAP
] := 0;
4248 FSpectator
:= False;
4251 FSpectatePlayer
:= -1;
4252 FNoRespawn
:= False;
4254 FLives
:= gGameSettings
.MaxLives
;
4259 procedure TPlayer
.SoftReset();
4265 FBFGFireCounter
:= -1;
4273 SetAction(A_STAND
, True);
4276 function TPlayer
.GetRespawnPoint(): Byte;
4281 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4283 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4284 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4286 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4288 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4289 if Self
= gPlayer1
then
4290 c
:= RESPAWNPOINT_PLAYER1
4292 c
:= RESPAWNPOINT_PLAYER2
;
4293 if g_Map_GetPointCount(c
) > 0 then
4299 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4300 if Self
= gPlayer1
then
4301 c
:= RESPAWNPOINT_PLAYER2
4303 c
:= RESPAWNPOINT_PLAYER1
;
4304 if g_Map_GetPointCount(c
) > 0 then
4311 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4312 if Random(2) = 0 then
4313 c
:= RESPAWNPOINT_PLAYER1
4315 c
:= RESPAWNPOINT_PLAYER2
;
4316 if g_Map_GetPointCount(c
) > 0 then
4323 // Òî÷êà ëþáîé èç êîìàíä
4324 if Random(2) = 0 then
4325 c
:= RESPAWNPOINT_RED
4327 c
:= RESPAWNPOINT_BLUE
;
4328 if g_Map_GetPointCount(c
) > 0 then
4335 c
:= RESPAWNPOINT_DM
;
4336 if g_Map_GetPointCount(c
) > 0 then
4344 if gGameSettings
.GameMode
= GM_DM
then
4347 c
:= RESPAWNPOINT_DM
;
4348 if g_Map_GetPointCount(c
) > 0 then
4354 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4355 if Random(2) = 0 then
4356 c
:= RESPAWNPOINT_PLAYER1
4358 c
:= RESPAWNPOINT_PLAYER2
;
4359 if g_Map_GetPointCount(c
) > 0 then
4365 // Òî÷êà ëþáîé èç êîìàíä
4366 if Random(2) = 0 then
4367 c
:= RESPAWNPOINT_RED
4369 c
:= RESPAWNPOINT_BLUE
;
4370 if g_Map_GetPointCount(c
) > 0 then
4378 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4380 // Òî÷êà ñâîåé êîìàíäû
4381 c
:= RESPAWNPOINT_DM
;
4382 if FTeam
= TEAM_RED
then
4383 c
:= RESPAWNPOINT_RED
;
4384 if FTeam
= TEAM_BLUE
then
4385 c
:= RESPAWNPOINT_BLUE
;
4386 if g_Map_GetPointCount(c
) > 0 then
4393 c
:= RESPAWNPOINT_DM
;
4394 if g_Map_GetPointCount(c
) > 0 then
4400 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4401 if Random(2) = 0 then
4402 c
:= RESPAWNPOINT_PLAYER1
4404 c
:= RESPAWNPOINT_PLAYER2
;
4405 if g_Map_GetPointCount(c
) > 0 then
4411 // Òî÷êà äðóãîé êîìàíäû
4412 c
:= RESPAWNPOINT_DM
;
4413 if FTeam
= TEAM_RED
then
4414 c
:= RESPAWNPOINT_BLUE
;
4415 if FTeam
= TEAM_BLUE
then
4416 c
:= RESPAWNPOINT_RED
;
4417 if g_Map_GetPointCount(c
) > 0 then
4425 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4427 RespawnPoint
: TRespawnPoint
;
4433 FBFGFireCounter
:= -1;
4438 if not g_Game_IsServer
then
4442 FWantsInGame
:= True;
4443 FJustTeleported
:= True;
4446 FTime
[T_RESPAWN
] := 0;
4450 // if server changes MaxLives we gotta be ready
4451 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4453 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4454 if FTime
[T_RESPAWN
] > gTime
then
4457 // Ïðîñðàë âñå æèçíè:
4460 if not FSpectator
then Spectate(True);
4461 FWantsInGame
:= True;
4465 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4466 begin // "Ñâîÿ èãðà"
4467 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4468 FRulez
:= FRulez
-[R_BERSERK
];
4470 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4472 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4473 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4476 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4477 c
:= GetRespawnPoint();
4482 // Âîñêðåøåíèå áåç îðóæèÿ:
4485 FHealth
:= PLAYER_HP_SOFT
;
4491 for a
:= WP_FIRST
to WP_LAST
do
4493 FWeapon
[a
] := False;
4497 FWeapon
[WEAPON_PISTOL
] := True;
4498 FWeapon
[WEAPON_KASTET
] := True;
4499 FCurrWeap
:= WEAPON_PISTOL
;
4502 FModel
.SetWeapon(FCurrWeap
);
4504 for b
:= A_BULLETS
to A_HIGH
do
4507 FAmmo
[A_BULLETS
] := 50;
4509 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4510 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4511 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4512 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4513 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4515 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4516 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4521 // Ðàçðûâàåì ñâÿçè ñ òðóïàìè:
4522 if gCorpses
<> nil then
4523 for a
:= 0 to High(gCorpses
) do
4524 if gCorpses
[a
] <> nil then
4525 if gCorpses
[a
].FPlayerUID
= FUID
then
4526 gCorpses
[a
].FPlayerUID
:= 0;
4528 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4529 if not g_Map_GetPoint(c
, RespawnPoint
) then
4531 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4535 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4536 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4537 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4543 FDirection
:= RespawnPoint
.Direction
;
4544 if FDirection
= TDirection
.D_LEFT
then
4549 SetAction(A_STAND
, True);
4550 FModel
.Direction
:= FDirection
;
4552 for a
:= Low(FTime
) to High(FTime
) do
4555 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4560 FCanJetpack
:= False;
4565 // Àíèìàöèÿ âîçðîæäåíèÿ:
4566 if (not gLoadGameMode
) and (not Silent
) then
4567 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4569 Anim
:= TAnimation
.Create(ID
, False, 3);
4570 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4571 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4575 FSpectator
:= False;
4578 FSpectatePlayer
:= -1;
4581 if (gPlayer1
= nil) and (gLMSPID1
= FUID
) then
4583 if (gPlayer2
= nil) and (gLMSPID2
= FUID
) then
4586 if g_Game_IsNet
then
4588 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4589 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4591 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4592 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4597 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4600 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4601 else if (not NoMove
) then
4603 GameX
:= gMapInfo
.Width
div 2;
4604 GameY
:= gMapInfo
.Height
div 2;
4613 FWantsInGame
:= False;
4618 if Self
= gPlayer1
then
4623 if Self
= gPlayer2
then
4630 if g_Game_IsNet
then
4631 MH_SEND_PlayerStats(FUID
);
4634 procedure TPlayer
.SwitchNoClip
;
4638 FGhost
:= not FGhost
;
4639 FPhysics
:= not FGhost
;
4651 procedure TPlayer
.Run(Direction
: TDirection
);
4655 if MAX_RUNVEL
> 8 then
4659 if Direction
= TDirection
.D_LEFT
then
4661 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4662 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4665 if FObj
.Vel
.X
< MAX_RUNVEL
then
4666 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4668 // Âîçìîæíî, ïèíàåì êóñêè:
4669 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4671 b
:= Abs(FObj
.Vel
.X
);
4672 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4673 for a
:= 0 to High(gGibs
) do
4675 if gGibs
[a
].alive
and
4676 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4677 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4680 if FObj
.Vel
.X
< 0 then
4682 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4686 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4688 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4696 procedure TPlayer
.SeeDown();
4698 SetAction(A_SEEDOWN
);
4700 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4702 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4705 procedure TPlayer
.SeeUp();
4709 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4711 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4714 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4722 A_ATTACK
: Prior
:= 2;
4723 A_SEEUP
: Prior
:= 1;
4724 A_SEEDOWN
: Prior
:= 1;
4725 A_ATTACKUP
: Prior
:= 2;
4726 A_ATTACKDOWN
: Prior
:= 2;
4731 if (Prior
> FActionPrior
) or Force
then
4732 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4734 FActionPrior
:= Prior
;
4735 FActionAnim
:= Action
;
4736 FActionForce
:= Force
;
4737 FActionChanged
:= True;
4740 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4743 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4745 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4746 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4747 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4748 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4751 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4758 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4760 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4761 if g_Game_IsServer
and g_Game_IsNet
then
4762 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4766 FJustTeleported
:= True;
4771 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4773 Anim
:= TAnimation
.Create(ID
, False, 3);
4776 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4777 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4778 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4779 if g_Game_IsServer
and g_Game_IsNet
then
4780 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4781 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4785 FObj
.X
:= X
-PLAYER_RECT
.X
;
4786 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4787 if FAlive
and FGhost
then
4793 if not g_Game_IsNet
then
4797 SetDirection(TDirection
.D_LEFT
);
4803 SetDirection(TDirection
.D_RIGHT
);
4809 if FDirection
= TDirection
.D_RIGHT
then
4811 SetDirection(TDirection
.D_LEFT
);
4816 SetDirection(TDirection
.D_RIGHT
);
4822 if not silent
and (Anim
<> nil) then
4824 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4825 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4828 if g_Game_IsServer
and g_Game_IsNet
then
4829 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4830 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4837 function nonz(a
: Single): Single;
4845 function TPlayer
.followCorpse(): Boolean;
4850 if FAlive
or FSpectator
then
4852 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
4854 for i
:= 0 to High(gCorpses
) do
4855 if gCorpses
[i
] <> nil then
4856 if gCorpses
[i
].FPlayerUID
= FUID
then
4859 FObj
.X
:= gCorpses
[i
].FObj
.X
;
4860 FObj
.Y
:= gCorpses
[i
].FObj
.Y
;
4861 FObj
.Vel
.X
:= gCorpses
[i
].FObj
.Vel
.X
;
4862 FObj
.Vel
.Y
:= gCorpses
[i
].FObj
.Vel
.Y
;
4863 FObj
.Accel
.X
:= gCorpses
[i
].FObj
.Accel
.X
;
4864 FObj
.Accel
.Y
:= gCorpses
[i
].FObj
.Accel
.Y
;
4869 procedure TPlayer
.Update();
4872 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4873 blockmon
, headwater
, dospawn
: Boolean;
4878 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4879 AnyServer
:= g_Game_IsServer
;
4881 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4882 DoLerp(NetInterpLevel
+ 1)
4888 if FClientID
>= 0 then
4890 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4891 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4892 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4901 if FAlive
and (FPunchAnim
<> nil) then
4902 FPunchAnim
.Update();
4904 if FAlive
and (gFly
or FJetpack
) then
4907 if FDirection
= TDirection
.D_LEFT
then
4912 if FAlive
and (not FGhost
) then
4914 if FKeys
[KEY_UP
].Pressed
then
4916 if FKeys
[KEY_DOWN
].Pressed
then
4920 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4923 i
:= g_basic
.Sign(FIncCam
);
4924 FIncCam
:= Abs(FIncCam
);
4925 DecMin(FIncCam
, 5, 0);
4926 FIncCam
:= FIncCam
*i
;
4929 // no need to do that each second frame, weapon queue will take care of it
4930 if FAlive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4931 if FAlive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4933 if gTime
mod (GAME_TICK
*2) <> 0 then
4935 if (FObj
.Vel
.X
= 0) and FAlive
then
4937 if FKeys
[KEY_LEFT
].Pressed
then
4938 Run(TDirection
.D_LEFT
);
4939 if FKeys
[KEY_RIGHT
].Pressed
then
4940 Run(TDirection
.D_RIGHT
);
4945 if not followCorpse() then
4946 g_Obj_Move(@FObj
, True, True, True);
4947 positionChanged(); // this updates spatial accelerators
4953 FActionChanged
:= False;
4957 // Let alive player do some actions
4958 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
4959 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
4960 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
4961 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
4962 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
4963 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
4964 if FKeys
[KEY_JUMP
].Pressed
then Jump()
4967 if AnyServer
and FJetpack
then
4971 if NetServer
then MH_SEND_PlayerStats(FUID
);
4973 FCanJetpack
:= True;
4980 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
4982 if FKeys
[k
].Pressed
then
4990 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4993 if (FTime
[T_RESPAWN
] <= gTime
) and
4994 gGameOn
and (not FAlive
) then
4996 if (g_Player_GetCount() > 1) then
5000 gExit
:= EXIT_RESTART
;
5005 // Dead spectator actions
5008 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
5009 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
5013 if (FSpectatePlayer
>= High(gPlayers
)) then
5014 FSpectatePlayer
:= -1
5018 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
5019 if gPlayers
[I
] <> nil then
5020 if gPlayers
[I
].alive
then
5021 if gPlayers
[I
].UID
<> FUID
then
5023 FSpectatePlayer
:= I
;
5028 if not SetSpect
then FSpectatePlayer
:= -1;
5039 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5041 FYTo
:= FObj
.Y
- 32;
5042 FSpectatePlayer
:= -1;
5044 if FKeys
[KEY_DOWN
].Pressed
then
5046 FYTo
:= FObj
.Y
+ 32;
5047 FSpectatePlayer
:= -1;
5049 if FKeys
[KEY_LEFT
].Pressed
then
5051 FXTo
:= FObj
.X
- 32;
5052 FSpectatePlayer
:= -1;
5054 if FKeys
[KEY_RIGHT
].Pressed
then
5056 FXTo
:= FObj
.X
+ 32;
5057 FSpectatePlayer
:= -1;
5060 if (FXTo
< -64) then
5062 else if (FXTo
> gMapInfo
.Width
+ 32) then
5063 FXTo
:= gMapInfo
.Width
+ 32;
5064 if (FYTo
< -72) then
5066 else if (FYTo
> gMapInfo
.Height
+ 32) then
5067 FYTo
:= gMapInfo
.Height
+ 32;
5072 if not followCorpse() then
5073 g_Obj_Move(@FObj
, True, True, True);
5074 positionChanged(); // this updates spatial accelerators
5081 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5082 if gPlayers
[FSpectatePlayer
] <> nil then
5083 if gPlayers
[FSpectatePlayer
].alive
then
5085 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
5086 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
5090 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5091 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5092 PANEL_BLOCKMON
, True);
5093 headwater
:= HeadInLiquid(0, 0);
5095 // Ñîïðîòèâëåíèå âîçäóõà:
5096 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5097 if FObj
.Vel
.X
<> 0 then
5098 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5100 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5101 DecMin(FPain
, 5, 0);
5102 DecMin(FPickup
, 1, 0);
5104 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5106 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5107 FMegaRulez
[MR_SUIT
] := 0;
5108 FMegaRulez
[MR_INVUL
] := 0;
5109 FMegaRulez
[MR_INVIS
] := 0;
5110 Kill(K_FALLKILL
, 0, HIT_FALL
);
5117 if FCurrWeap
= WEAPON_SAW
then
5118 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5119 FSawSoundSelect
.IsPlaying()) then
5120 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5123 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5124 (not FJetSoundOff
.IsPlaying()) then
5126 FJetSoundFly
.SetPosition(0);
5127 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5130 for b
:= WP_FIRST
to WP_LAST
do
5131 if FReloading
[b
] > 0 then
5137 if FShellTimer
> -1 then
5138 if FShellTimer
= 0 then
5140 if FShellType
= SHELL_SHELL
then
5141 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5142 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5143 else if FShellType
= SHELL_DBLSHELL
then
5145 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5146 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5147 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5148 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5151 end else Dec(FShellTimer
);
5153 if (FBFGFireCounter
> -1) then
5154 if FBFGFireCounter
= 0 then
5158 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5159 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5160 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5161 yd
:= wy
+firediry();
5162 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5163 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5164 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5165 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5166 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5169 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5170 FBFGFireCounter
:= -1;
5173 FBFGFireCounter
:= 0
5175 Dec(FBFGFireCounter
);
5177 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5179 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5181 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5184 if (headwater
or blockmon
) then
5190 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5193 else if (FAir
mod 31 = 0) and not blockmon
then
5195 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5196 if Random(2) = 0 then
5197 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5199 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5201 end else if FAir
< AIR_DEF
then
5204 if FFireTime
> 0 then
5206 if BodyInLiquid(0, 0) then
5211 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5213 if FMegaRulez
[MR_SUIT
] = gTime
then
5220 if FFirePainTime
<= 0 then
5222 if g_Game_IsServer
then
5223 Damage(5, FFireAttacker
, 0, 0, HIT_FLAME
);
5224 FFirePainTime
:= 18;
5226 FFirePainTime
:= FFirePainTime
- 1;
5227 FFireTime
:= FFireTime
- 1;
5228 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5229 MH_SEND_PlayerStats(FUID
);
5233 if FDamageBuffer
> 0 then
5235 if FDamageBuffer
>= 9 then
5239 if FDamageBuffer
< 30 then i
:= 9
5240 else if FDamageBuffer
< 100 then i
:= 18
5244 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5245 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5246 FHealth
:= FHealth
-ii
;
5249 FHealth
:= FHealth
+FArmor
;
5254 if FHealth
<= 0 then
5255 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5256 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5257 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5261 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5262 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5263 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5264 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5271 end; // if FAlive then ...
5273 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5275 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5276 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5277 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5278 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5280 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5281 then SetAction(A_STAND
, True);
5283 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5285 for b
:= Low(FKeys
) to High(FKeys
) do
5286 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5290 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5292 x
:= FObj
.X
+PLAYER_RECT
.X
;
5293 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5294 w
:= PLAYER_RECT
.Width
;
5295 h
:= PLAYER_RECT
.Height
;
5299 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5301 if (dx
<> 0) or (dy
<> 0) then
5310 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5312 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5313 FObj
.Y
+PLAYER_RECT
.Y
,
5320 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5322 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5323 FObj
.Y
+PLAYER_RECT
.Y
,
5327 Panel
.Width
, Panel
.Height
);
5330 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5332 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5333 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5334 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5335 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5338 function g_Player_ValidName(Name
: string): Boolean;
5344 if gPlayers
= nil then Exit
;
5346 for a
:= 0 to High(gPlayers
) do
5347 if gPlayers
[a
] <> nil then
5348 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5355 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5359 d
:= FModel
.Direction
;
5361 FModel
.Direction
:= Direction
;
5362 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5364 FDirection
:= Direction
;
5367 function TPlayer
.GetKeys(): Byte;
5371 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5372 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5373 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5375 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5376 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5379 procedure TPlayer
.Use();
5383 if FTime
[T_USE
] > gTime
then Exit
;
5385 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5386 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5388 for a
:= 0 to High(gPlayers
) do
5389 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5390 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5391 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5392 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5394 gPlayers
[a
].Touch();
5395 if g_Game_IsNet
and g_Game_IsServer
then
5396 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5399 FTime
[T_USE
] := gTime
+120;
5402 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5406 WX
, WY
, XD
, YD
: Integer;
5418 if R_BERSERK
in FRulez
then
5420 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5421 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5422 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5425 locobj
.rect
.Width
:= 39;
5426 locobj
.rect
.Height
:= 52;
5427 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5428 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5429 locobj
.Accel
.X
:= xd
-wx
;
5430 locobj
.Accel
.y
:= yd
-wy
;
5432 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5433 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5435 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5439 FPain
:= min(FPain
+ 25, 50);
5441 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5446 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5447 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5449 FSawSoundSelect
.Stop();
5451 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5453 else if not FSawSoundHit
.IsPlaying() then
5455 FSawSoundSelect
.Stop();
5456 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5463 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5464 FFireAngle
:= FAngle
;
5466 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5467 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5472 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5473 FFireAngle
:= FAngle
;
5476 FShellType
:= SHELL_SHELL
;
5481 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5482 FFireAngle
:= FAngle
;
5485 FShellType
:= SHELL_DBLSHELL
;
5490 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5491 FFireAngle
:= FAngle
;
5493 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5494 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5497 WEAPON_ROCKETLAUNCHER
:
5499 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5500 FFireAngle
:= FAngle
;
5506 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5507 FFireAngle
:= FAngle
;
5513 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5514 FFireAngle
:= FAngle
;
5518 WEAPON_SUPERPULEMET
:
5520 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5521 FFireAngle
:= FAngle
;
5523 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5524 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5527 WEAPON_FLAMETHROWER
:
5529 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5530 FFireAngle
:= FAngle
;
5537 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5538 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5539 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5542 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5544 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5545 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5548 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5552 if NetInterpLevel
< 1 then
5562 AX
:= Abs(FXTo
- FObj
.X
);
5563 AY
:= Abs(FYTo
- FObj
.Y
);
5564 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5566 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5571 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5573 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5574 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5575 PANEL_LIFTUP
, False) then Result
:= -1
5577 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5578 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5579 PANEL_LIFTDOWN
, False) then Result
:= 1
5583 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5590 if Flag
= FLAG_NONE
then
5593 if not g_Game_IsServer
then Exit
;
5595 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5596 if (Flag
= FTeam
) and
5597 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5598 (FFlag
<> FLAG_NONE
) then
5600 if FFlag
= FLAG_RED
then
5601 s
:= _lc
[I_PLAYER_FLAG_RED
]
5603 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5605 evtype
:= FLAG_STATE_SCORED
;
5607 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5608 Insert('.', ts
, Length(ts
) + 1 - 3);
5609 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5611 g_Map_ResetFlag(FFlag
);
5612 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5614 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5617 if g_Game_IsNet
then
5619 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5623 gFlags
[FFlag
].CaptureTime
:= 0;
5628 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5629 if (Flag
= FTeam
) and
5630 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5632 if Flag
= FLAG_RED
then
5633 s
:= _lc
[I_PLAYER_FLAG_RED
]
5635 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5637 evtype
:= FLAG_STATE_RETURNED
;
5638 gFlags
[Flag
].CaptureTime
:= 0;
5640 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5642 g_Map_ResetFlag(Flag
);
5643 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5646 if g_Game_IsNet
then
5648 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5654 // Ïîäîáðàë ÷óæîé ôëàã:
5655 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5659 if Flag
= FLAG_RED
then
5660 s
:= _lc
[I_PLAYER_FLAG_RED
]
5662 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5664 evtype
:= FLAG_STATE_CAPTURED
;
5666 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5668 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5670 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5673 if g_Game_IsNet
then
5675 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5681 procedure TPlayer
.SetFlag(Flag
: Byte);
5684 if FModel
<> nil then
5685 FModel
.SetFlag(FFlag
);
5688 function TPlayer
.DropFlag(): Boolean;
5693 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5695 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5696 with gFlags
[FFlag
] do
5700 Direction
:= FDirection
;
5701 State
:= FLAG_STATE_DROPPED
;
5703 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5704 (FObj
.Vel
.Y
div 2)-2+Random(5));
5705 positionChanged(); // this updates spatial accelerators
5707 if FFlag
= FLAG_RED
then
5708 s
:= _lc
[I_PLAYER_FLAG_RED
]
5710 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5712 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5713 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5715 if g_Game_IsNet
then
5716 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5722 procedure TPlayer
.GetSecret();
5727 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5729 Assert(Key
<= High(FKeys
));
5731 FKeys
[Key
].Pressed
:= True;
5732 FKeys
[Key
].Time
:= Time
;
5735 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5737 Result
:= FKeys
[K
].Pressed
;
5740 procedure TPlayer
.ReleaseKeys();
5744 for a
:= Low(FKeys
) to High(FKeys
) do
5746 FKeys
[a
].Pressed
:= False;
5751 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5755 function TPlayer
.firediry(): Integer;
5757 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5758 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5762 procedure TPlayer
.RememberState();
5766 FSavedState
.Health
:= FHealth
;
5767 FSavedState
.Armor
:= FArmor
;
5768 FSavedState
.Air
:= FAir
;
5769 FSavedState
.JetFuel
:= FJetFuel
;
5770 FSavedState
.CurrWeap
:= FCurrWeap
;
5771 FSavedState
.NextWeap
:= FNextWeap
;
5772 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5775 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5777 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5779 FSavedState
.Rulez
:= FRulez
;
5780 FSavedState
.WaitRecall
:= True;
5783 procedure TPlayer
.RecallState();
5787 if not FSavedState
.WaitRecall
then Exit
;
5789 FHealth
:= FSavedState
.Health
;
5790 FArmor
:= FSavedState
.Armor
;
5791 FAir
:= FSavedState
.Air
;
5792 FJetFuel
:= FSavedState
.JetFuel
;
5793 FCurrWeap
:= FSavedState
.CurrWeap
;
5794 FNextWeap
:= FSavedState
.NextWeap
;
5795 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5798 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5800 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5802 FRulez
:= FSavedState
.Rulez
;
5803 FSavedState
.WaitRecall
:= False;
5805 if gGameSettings
.GameType
= GT_SERVER
then
5806 MH_SEND_PlayerStats(FUID
);
5809 procedure TPlayer
.SaveState (st
: TStream
);
5815 utils
.writeSign(st
, 'PLYR');
5816 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
5818 utils
.writeBool(st
, FIamBot
);
5820 utils
.writeInt(st
, Word(FUID
));
5822 utils
.writeStr(st
, FName
);
5824 utils
.writeInt(st
, Byte(FTeam
));
5826 utils
.writeBool(st
, FAlive
);
5827 // Èçðàñõîäîâàë ëè âñå æèçíè
5828 utils
.writeBool(st
, FNoRespawn
);
5830 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
5831 utils
.writeInt(st
, Byte(b
));
5833 utils
.writeInt(st
, LongInt(FHealth
));
5835 utils
.writeInt(st
, Byte(FLives
));
5837 utils
.writeInt(st
, LongInt(FArmor
));
5839 utils
.writeInt(st
, LongInt(FAir
));
5841 utils
.writeInt(st
, LongInt(FJetFuel
));
5843 utils
.writeInt(st
, LongInt(FPain
));
5845 utils
.writeInt(st
, LongInt(FKills
));
5847 utils
.writeInt(st
, LongInt(FMonsterKills
));
5849 utils
.writeInt(st
, LongInt(FFrags
));
5851 utils
.writeInt(st
, Byte(FFragCombo
));
5852 // Âðåìÿ ïîñëåäíåãî ôðàãà
5853 utils
.writeInt(st
, LongWord(FLastFrag
));
5855 utils
.writeInt(st
, LongInt(FDeath
));
5857 utils
.writeInt(st
, Byte(FFlag
));
5859 utils
.writeInt(st
, LongInt(FSecrets
));
5861 utils
.writeInt(st
, Byte(FCurrWeap
));
5863 utils
.writeInt(st
, Word(FNextWeap
));
5865 utils
.writeInt(st
, Byte(FNextWeapDelay
));
5866 // Âðåìÿ çàðÿäêè BFG
5867 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
5869 utils
.writeInt(st
, LongInt(FDamageBuffer
));
5870 // Ïîñëåäíèé óäàðèâøèé
5871 utils
.writeInt(st
, Word(FLastSpawnerUID
));
5872 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
5873 utils
.writeInt(st
, Byte(FLastHit
));
5875 Obj_SaveState(st
, @FObj
);
5876 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
5877 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
5878 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
5879 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
5881 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
5882 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
5883 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
5885 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
5886 // Íàëè÷èå êðàñíîãî êëþ÷à
5887 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
5888 // Íàëè÷èå çåëåíîãî êëþ÷à
5889 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
5890 // Íàëè÷èå ñèíåãî êëþ÷à
5891 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
5893 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
5894 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
5895 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
5896 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
5897 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
5899 utils
.writeStr(st
, FModel
.Name
);
5901 utils
.writeInt(st
, Byte(FColor
.R
));
5902 utils
.writeInt(st
, Byte(FColor
.G
));
5903 utils
.writeInt(st
, Byte(FColor
.B
));
5907 procedure TPlayer
.LoadState (st
: TStream
);
5916 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
5917 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
5919 FIamBot
:= utils
.readBool(st
);
5921 FUID
:= utils
.readWord(st
);
5923 str
:= utils
.readStr(st
);
5924 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
5926 FTeam
:= utils
.readByte(st
);
5928 FAlive
:= utils
.readBool(st
);
5929 // Èçðàñõîäîâàë ëè âñå æèçíè
5930 FNoRespawn
:= utils
.readBool(st
);
5932 b
:= utils
.readByte(st
);
5933 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
5935 FHealth
:= utils
.readLongInt(st
);
5937 FLives
:= utils
.readByte(st
);
5939 FArmor
:= utils
.readLongInt(st
);
5941 FAir
:= utils
.readLongInt(st
);
5943 FJetFuel
:= utils
.readLongInt(st
);
5945 FPain
:= utils
.readLongInt(st
);
5947 FKills
:= utils
.readLongInt(st
);
5949 FMonsterKills
:= utils
.readLongInt(st
);
5951 FFrags
:= utils
.readLongInt(st
);
5953 FFragCombo
:= utils
.readByte(st
);
5954 // Âðåìÿ ïîñëåäíåãî ôðàãà
5955 FLastFrag
:= utils
.readLongWord(st
);
5957 FDeath
:= utils
.readLongInt(st
);
5959 FFlag
:= utils
.readByte(st
);
5961 FSecrets
:= utils
.readLongInt(st
);
5963 FCurrWeap
:= utils
.readByte(st
);
5965 FNextWeap
:= utils
.readWord(st
);
5967 FNextWeapDelay
:= utils
.readByte(st
);
5968 // Âðåìÿ çàðÿäêè BFG
5969 FBFGFireCounter
:= utils
.readSmallInt(st
);
5971 FDamageBuffer
:= utils
.readLongInt(st
);
5972 // Ïîñëåäíèé óäàðèâøèé
5973 FLastSpawnerUID
:= utils
.readWord(st
);
5974 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
5975 FLastHit
:= utils
.readByte(st
);
5977 Obj_LoadState(@FObj
, st
);
5978 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
5979 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
5980 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
5981 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
5983 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
5984 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
5985 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
5987 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
5988 // Íàëè÷èå êðàñíîãî êëþ÷à
5989 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
5990 // Íàëè÷èå çåëåíîãî êëþ÷à
5991 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
5992 // Íàëè÷èå ñèíåãî êëþ÷à
5993 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
5995 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
5996 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
5997 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
5998 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
5999 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
6001 str
:= utils
.readStr(st
);
6003 FColor
.R
:= utils
.readByte(st
);
6004 FColor
.G
:= utils
.readByte(st
);
6005 FColor
.B
:= utils
.readByte(st
);
6006 if (self
= gPlayer1
) then
6008 str
:= gPlayer1Settings
.Model
;
6009 FColor
:= gPlayer1Settings
.Color
;
6011 else if (self
= gPlayer2
) then
6013 str
:= gPlayer2Settings
.Model
;
6014 FColor
:= gPlayer2Settings
.Color
;
6016 // Îáíîâëÿåì ìîäåëü èãðîêà
6018 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
6019 FModel
.Color
:= TEAMCOLOR
[FTeam
]
6021 FModel
.Color
:= FColor
;
6025 procedure TPlayer
.AllRulez(Health
: Boolean);
6031 FHealth
:= PLAYER_HP_LIMIT
;
6032 FArmor
:= PLAYER_AP_LIMIT
;
6036 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
6037 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
6038 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6041 procedure TPlayer
.RestoreHealthArmor();
6043 FHealth
:= PLAYER_HP_LIMIT
;
6044 FArmor
:= PLAYER_AP_LIMIT
;
6047 procedure TPlayer
.FragCombo();
6051 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6053 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6055 if FFragCombo
< 5 then
6057 Param
:= FUID
or (FFragCombo
shl 16);
6058 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6059 (FComboEvnt
<= High(gDelayedEvents
)) and
6060 gDelayedEvents
[FComboEvnt
].Pending
and
6061 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6062 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6064 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6065 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6068 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6076 procedure TPlayer
.GiveItem(ItemType
: Byte);
6080 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6082 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6086 if FAir
< AIR_MAX
then
6093 if not (R_BERSERK
in FRulez
) then
6095 Include(FRulez
, R_BERSERK
);
6096 if FBFGFireCounter
< 1 then
6098 FCurrWeap
:= WEAPON_KASTET
;
6100 FModel
.SetWeapon(WEAPON_KASTET
);
6104 FBerserk
:= gTime
+30000;
6106 if FHealth
< PLAYER_HP_SOFT
then
6108 FHealth
:= PLAYER_HP_SOFT
;
6109 FBerserk
:= gTime
+30000;
6114 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6116 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6120 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6122 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6126 if FJetFuel
< JET_MAX
then
6128 FJetFuel
:= JET_MAX
;
6131 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6132 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6134 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6135 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6137 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6139 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6141 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6142 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6145 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6146 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6147 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6148 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6149 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6150 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6151 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6152 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6153 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6155 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6156 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6157 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6158 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6159 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6160 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6161 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6162 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6163 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6166 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6167 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6168 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6169 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6170 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6172 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6173 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6174 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6175 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6176 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6178 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6179 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6180 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6181 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6183 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6186 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6187 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6188 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6190 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6191 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6196 if g_Game_IsNet
and g_Game_IsServer
then
6197 MH_SEND_PlayerStats(FUID
);
6200 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6205 if (Random(5) = 1) and (Times
= 1) then
6208 if BodyInLiquid(0, 0) then
6210 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6211 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6212 if Random(2) = 0 then
6213 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6215 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6219 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6221 for i
:= 1 to Times
do
6223 Anim
:= TAnimation
.Create(id
, False, 3);
6225 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6226 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6232 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6237 if (Random(10) = 1) and (Times
= 1) then
6240 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6242 for i
:= 1 to Times
do
6244 Anim
:= TAnimation
.Create(id
, False, 3);
6246 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6247 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6253 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6255 FSawSound
.Pause(Enable
);
6256 FSawSoundIdle
.Pause(Enable
);
6257 FSawSoundHit
.Pause(Enable
);
6258 FSawSoundSelect
.Pause(Enable
);
6263 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6268 FObj
.Rect
:= PLAYER_CORPSERECT
;
6269 FModelName
:= ModelName
;
6274 FState
:= CORPSE_STATE_MESS
;
6275 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6279 FState
:= CORPSE_STATE_NORMAL
;
6280 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6284 destructor TCorpse
.Destroy();
6291 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6293 procedure TCorpse
.positionChanged (); inline; begin end;
6295 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6297 if (dx
<> 0) or (dy
<> 0) then
6306 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6308 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6309 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6310 w
:= PLAYER_CORPSERECT
.Width
;
6311 h
:= PLAYER_CORPSERECT
.Height
;
6315 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6319 if FState
= CORPSE_STATE_REMOVEME
then
6322 FDamage
:= FDamage
+ Value
;
6324 if FDamage
> 150 then
6326 if FAnimation
<> nil then
6331 FState
:= CORPSE_STATE_REMOVEME
;
6333 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6334 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6335 FModelName
, FColor
);
6336 // Çâóê ìÿñà îò òðóïà:
6337 pm
:= g_PlayerModel_Get(FModelName
);
6338 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6344 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6345 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6346 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6347 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6348 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6353 procedure TCorpse
.Draw();
6355 if FState
= CORPSE_STATE_REMOVEME
then
6358 if FAnimation
<> nil then
6359 FAnimation
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6361 if FAnimationMask
<> nil then
6364 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6371 procedure TCorpse
.Update();
6375 if FState
= CORPSE_STATE_REMOVEME
then
6378 if gTime
mod (GAME_TICK
*2) <> 0 then
6380 g_Obj_Move(@FObj
, True, True, True);
6381 positionChanged(); // this updates spatial accelerators
6385 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6386 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6388 st
:= g_Obj_Move(@FObj
, True, True, True);
6389 positionChanged(); // this updates spatial accelerators
6391 if WordBool(st
and MOVE_FALLOUT
) then
6393 FState
:= CORPSE_STATE_REMOVEME
;
6397 if FAnimation
<> nil then
6398 FAnimation
.Update();
6399 if FAnimationMask
<> nil then
6400 FAnimationMask
.Update();
6404 procedure TCorpse
.SaveState (st
: TStream
);
6411 utils
.writeSign(st
, 'CORP');
6412 utils
.writeInt(st
, Byte(0));
6414 utils
.writeInt(st
, Byte(FState
));
6416 utils
.writeInt(st
, Byte(FDamage
));
6418 utils
.writeInt(st
, Byte(FColor
.R
));
6419 utils
.writeInt(st
, Byte(FColor
.G
));
6420 utils
.writeInt(st
, Byte(FColor
.B
));
6422 Obj_SaveState(st
, @FObj
);
6423 utils
.writeInt(st
, Word(FPlayerUID
));
6425 anim
:= (FAnimation
<> nil);
6426 utils
.writeBool(st
, anim
);
6427 // Åñëè åñòü - ñîõðàíÿåì
6428 if anim
then FAnimation
.SaveState(st
);
6429 // Åñòü ëè ìàñêà àíèìàöèè
6430 anim
:= (FAnimationMask
<> nil);
6431 utils
.writeBool(st
, anim
);
6432 // Åñëè åñòü - ñîõðàíÿåì
6433 if anim
then FAnimationMask
.SaveState(st
);
6437 procedure TCorpse
.LoadState (st
: TStream
);
6444 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6445 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6447 FState
:= utils
.readByte(st
);
6449 FDamage
:= utils
.readByte(st
);
6451 FColor
.R
:= utils
.readByte(st
);
6452 FColor
.G
:= utils
.readByte(st
);
6453 FColor
.B
:= utils
.readByte(st
);
6455 Obj_LoadState(@FObj
, st
);
6456 FPlayerUID
:= utils
.readWord(st
);
6458 anim
:= utils
.readBool(st
);
6459 // Åñëè åñòü - çàãðóæàåì
6462 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6463 FAnimation
.LoadState(st
);
6465 // Åñòü ëè ìàñêà àíèìàöèè
6466 anim
:= utils
.readBool(st
);
6467 // Åñëè åñòü - çàãðóæàåì
6470 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6471 FAnimationMask
.LoadState(st
);
6477 constructor TBot
.Create();
6484 FSpectator
:= False;
6491 for a
:= WP_FIRST
to WP_LAST
do
6493 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6494 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6495 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6499 destructor TBot
.Destroy();
6502 inherited Destroy();
6505 procedure TBot
.Draw();
6509 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6510 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6513 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6515 inherited Respawn(Silent
, Force
);
6518 FSelectedWeapon
:= FCurrWeap
;
6523 procedure TBot
.UpdateCombat();
6536 TTargetRecord
= array of TTarget
;
6538 function Compare(a
, b
: TTarget
): Integer;
6540 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6543 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6545 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6546 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6548 if a
.Dist
> b
.Dist
then // B áëèæå
6550 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6553 else // Ñòðàííî -> A
6558 a
, x1
, y1
, x2
, y2
: Integer;
6559 targets
: TTargetRecord
;
6561 Target
, BestTarget
: TTarget
;
6562 firew
, fireh
: Integer;
6566 vsPlayer
, vsMonster
, ok
: Boolean;
6569 function monsUpdate (mon
: TMonster
): Boolean;
6571 result
:= false; // don't stop
6572 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6574 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6576 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6577 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6579 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6580 if g_TraceVector(x1
, y1
, x2
, y2
) then
6582 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6583 SetLength(targets
, Length(targets
)+1);
6584 with targets
[High(targets
)] do
6591 Rect
:= mon
.Obj
.Rect
;
6592 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6593 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6594 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6603 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6604 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6606 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6607 if FCurrWeap
<> FSelectedWeapon
then
6610 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6611 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6613 RemoveAIFlag('NEEDFIRE');
6616 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6617 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6618 else PressKey(KEY_FIRE
);
6622 // Êîîðäèíàòû ñòâîëà:
6623 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6624 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6626 Target
.UID
:= FTargetUID
;
6629 if Target
.UID
<> 0 then
6630 begin // Öåëü åñòü - íàñòðàèâàåì
6631 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6634 tpla
:= g_Player_Get(Target
.UID
);
6638 if (@FObj
) <> nil then
6645 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6646 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6647 Target
.Rect
:= PLAYER_RECT
;
6648 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6649 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6650 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6651 Target
.IsPlayer
:= True;
6655 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6658 mon
:= g_Monsters_ByUID(Target
.UID
);
6661 Target
.X
:= mon
.Obj
.X
;
6662 Target
.Y
:= mon
.Obj
.Y
;
6664 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6665 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6666 Target
.Rect
:= mon
.Obj
.Rect
;
6667 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6668 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6669 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6670 Target
.IsPlayer
:= False;
6677 begin // Öåëè íåò - îáíóëÿåì
6682 Target
.Visible
:= False;
6683 Target
.Line
:= False;
6684 Target
.IsPlayer
:= False;
6689 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6690 if (not Target
.Line
) or (not Target
.Visible
) then
6694 for a
:= 0 to High(gPlayers
) do
6695 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6696 (gPlayers
[a
].FUID
<> FUID
) and
6697 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6698 (not gPlayers
[a
].NoTarget
) and
6699 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6701 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6702 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6705 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6706 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6708 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6709 if g_TraceVector(x1
, y1
, x2
, y2
) then
6711 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6712 SetLength(targets
, Length(targets
)+1);
6713 with targets
[High(targets
)] do
6715 UID
:= gPlayers
[a
].FUID
;
6716 X
:= gPlayers
[a
].FObj
.X
;
6717 Y
:= gPlayers
[a
].FObj
.Y
;
6720 Rect
:= PLAYER_RECT
;
6721 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6722 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6723 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6731 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6734 // Åñëè åñòü âîçìîæíûå öåëè:
6735 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6736 if targets
<> nil then
6738 // Âûáèðàåì íàèëó÷øóþ öåëü:
6739 BestTarget
:= targets
[0];
6740 if Length(targets
) > 1 then
6741 for a
:= 1 to High(targets
) do
6742 if Compare(BestTarget
, targets
[a
]) = 1 then
6743 BestTarget
:= targets
[a
];
6745 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6746 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6747 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6749 Target
:= BestTarget
;
6751 if (Healthy() = 3) or ((Healthy() = 2)) then
6752 begin // Åñëè çäîðîâû - äîãîíÿåì
6753 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6754 SetAIFlag('GORIGHT', '1');
6755 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6756 SetAIFlag('GOLEFT', '1');
6759 begin // Åñëè ïîáèòû - óáåãàåì
6760 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6761 SetAIFlag('GORIGHT', '1');
6762 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6763 SetAIFlag('GOLEFT', '1');
6766 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6767 SelectWeapon(Abs(x1
-Target
.cX
));
6772 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6773 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6774 if Target
.UID
<> 0 then
6776 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6777 Target
.Y
+ Target
.Rect
.Y
) then
6778 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6779 if (Healthy() = 3) or ((Healthy() = 2)) then
6780 begin // Åñëè çäîðîâû - äîãîíÿåì
6781 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6782 SetAIFlag('GORIGHT', '1');
6783 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6784 SetAIFlag('GOLEFT', '1');
6787 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6789 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6790 SetAIFlag('GORIGHT', '1');
6791 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6792 SetAIFlag('GOLEFT', '1');
6796 begin // Öåëü ïîêà íà "ýêðàíå"
6797 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6798 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6799 FLastVisible
:= gTime
;
6800 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6801 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6803 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6804 SetAIFlag('GORIGHT', '1');
6805 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6806 SetAIFlag('GOLEFT', '1');
6810 // Âûáèðàåì óãîë ââåðõ:
6811 if FDirection
= TDirection
.D_LEFT
then
6812 angle
:= ANGLE_LEFTUP
6814 angle
:= ANGLE_RIGHTUP
;
6816 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6817 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6819 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6820 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6821 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6822 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6823 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6824 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6825 begin // òî íóæíî ñòðåëÿòü ââåðõ
6826 SetAIFlag('NEEDFIRE', '1');
6827 SetAIFlag('NEEDSEEUP', '1');
6830 // Âûáèðàåì óãîë âíèç:
6831 if FDirection
= TDirection
.D_LEFT
then
6832 angle
:= ANGLE_LEFTDOWN
6834 angle
:= ANGLE_RIGHTDOWN
;
6836 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6837 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6839 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6840 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6841 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6842 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6843 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6844 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6845 begin // òî íóæíî ñòðåëÿòü âíèç
6846 SetAIFlag('NEEDFIRE', '1');
6847 SetAIFlag('NEEDSEEDOWN', '1');
6850 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6851 if Target
.Visible
and
6852 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6853 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6855 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6856 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
6857 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6858 begin // òî íóæíî ñòðåëÿòü âïåðåä
6859 SetAIFlag('NEEDFIRE', '1');
6860 SetAIFlag('NEEDSEEDOWN', '');
6861 SetAIFlag('NEEDSEEUP', '');
6863 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6864 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6865 if GetRnd(FDifficult
.CloseJump
) then
6866 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6867 if Abs(FObj
.X
-Target
.X
) < 128 then
6871 if Random(a
) = 0 then
6872 SetAIFlag('NEEDJUMP', '1');
6876 // Åñëè öåëü âñå åùå åñòü:
6877 if Target
.UID
<> 0 then
6878 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
6879 Target
.UID
:= 0 // òî çàáûòü öåëü
6880 else // Åñëè âèäåëè íåäàâíî
6881 begin // íî öåëü óáèëè
6882 if Target
.IsPlayer
then
6883 begin // Öåëü - èãðîê
6884 pla
:= g_Player_Get(Target
.UID
);
6885 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
6886 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6887 Target
.UID
:= 0; // òî çàáûòü öåëü
6890 begin // Öåëü - ìîíñòð
6891 mon
:= g_Monsters_ByUID(Target
.UID
);
6892 if (mon
= nil) or (not mon
.alive
) then
6893 Target
.UID
:= 0; // òî çàáûòü öåëü
6896 end; // if Target.UID <> 0
6898 FTargetUID
:= Target
.UID
;
6900 // Åñëè âîçìîæíûõ öåëåé íåò:
6901 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
6902 if targets
= nil then
6903 if GetAIFlag('ATTACKLEFT') <> '' then
6904 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
6905 RemoveAIFlag('ATTACKLEFT');
6907 SetAIFlag('NEEDJUMP', '1');
6909 if RunDirection() = TDirection
.D_RIGHT
then
6910 begin // Èäåì íå â òó ñòîðîíó
6911 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6912 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
6913 SetAIFlag('NEEDFIRE', '1');
6914 SetAIFlag('GOLEFT', '1');
6918 begin // Èäåì â íóæíóþ ñòîðîíó
6919 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6920 SetAIFlag('NEEDFIRE', '1');
6921 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6922 SetAIFlag('GORIGHT', '1');
6926 if GetAIFlag('ATTACKRIGHT') <> '' then
6927 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
6928 RemoveAIFlag('ATTACKRIGHT');
6930 SetAIFlag('NEEDJUMP', '1');
6932 if RunDirection() = TDirection
.D_LEFT
then
6933 begin // Èäåì íå â òó ñòîðîíó
6934 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6935 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
6936 SetAIFlag('NEEDFIRE', '1');
6937 SetAIFlag('GORIGHT', '1');
6942 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6943 SetAIFlag('NEEDFIRE', '1');
6944 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6945 SetAIFlag('GOLEFT', '1');
6949 //HACK! (does it belongs there?)
6950 RealizeCurrentWeapon();
6952 // Åñëè åñòü âîçìîæíûå öåëè:
6953 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
6954 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6955 for a
:= 0 to High(targets
) do
6957 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
6958 if GetRnd(FDifficult
.DiagFire
) then
6960 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
6961 if FDirection
= TDirection
.D_LEFT
then
6962 angle
:= ANGLE_LEFTUP
6964 angle
:= ANGLE_RIGHTUP
;
6966 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6967 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6969 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6970 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6971 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6972 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6973 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6975 SetAIFlag('NEEDFIRE', '1');
6976 SetAIFlag('NEEDSEEUP', '1');
6979 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
6980 if FDirection
= TDirection
.D_LEFT
then
6981 angle
:= ANGLE_LEFTDOWN
6983 angle
:= ANGLE_RIGHTDOWN
;
6985 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6986 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6988 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6989 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6990 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6991 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6992 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6994 SetAIFlag('NEEDFIRE', '1');
6995 SetAIFlag('NEEDSEEDOWN', '1');
6999 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7000 if targets
[a
].Line
and targets
[a
].Visible
and
7001 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
7002 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
7004 SetAIFlag('NEEDFIRE', '1');
7009 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7010 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
7011 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
7012 40+GetInterval(FDifficult
.Cover
, 40)) then
7013 SetAIFlag('NEEDJUMP', '1');
7015 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7016 ammo
:= GetAmmoByWeapon(FCurrWeap
);
7017 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
7018 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
7020 SetAIFlag('SELECTWEAPON', '1');
7022 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7023 if GetAIFlag('SELECTWEAPON') = '1' then
7026 RemoveAIFlag('SELECTWEAPON');
7030 procedure TBot
.Update();
7043 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7044 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7046 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7048 if g_debug_BotAIOff
= 3 then
7058 RealizeCurrentWeapon();
7065 procedure TBot
.ReleaseKey(Key
: Byte);
7074 function TBot
.KeyPressed(Key
: Word): Boolean;
7076 Result
:= FKeys
[Key
].Pressed
;
7079 function TBot
.GetAIFlag(aName
: String20
): String20
;
7085 aName
:= LowerCase(aName
);
7087 if FAIFlags
<> nil then
7088 for a
:= 0 to High(FAIFlags
) do
7089 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7091 Result
:= FAIFlags
[a
].Value
;
7096 procedure TBot
.RemoveAIFlag(aName
: String20
);
7100 if FAIFlags
= nil then Exit
;
7102 aName
:= LowerCase(aName
);
7104 for a
:= 0 to High(FAIFlags
) do
7105 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7107 if a
<> High(FAIFlags
) then
7108 for b
:= a
to High(FAIFlags
)-1 do
7109 FAIFlags
[b
] := FAIFlags
[b
+1];
7111 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7116 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7124 aName
:= LowerCase(aName
);
7126 if FAIFlags
<> nil then
7127 for a
:= 0 to High(FAIFlags
) do
7128 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7134 if ok
then FAIFlags
[a
].Value
:= fValue
7137 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7138 with FAIFlags
[High(FAIFlags
)] do
7146 procedure TBot
.UpdateMove
;
7148 procedure GoLeft(Time
: Word = 1);
7150 ReleaseKey(KEY_LEFT
);
7151 ReleaseKey(KEY_RIGHT
);
7152 PressKey(KEY_LEFT
, Time
);
7153 SetDirection(TDirection
.D_LEFT
);
7156 procedure GoRight(Time
: Word = 1);
7158 ReleaseKey(KEY_LEFT
);
7159 ReleaseKey(KEY_RIGHT
);
7160 PressKey(KEY_RIGHT
, Time
);
7161 SetDirection(TDirection
.D_RIGHT
);
7164 function Rnd(a
: Word): Boolean;
7166 Result
:= Random(a
) = 0;
7169 procedure Turn(Time
: Word = 1200);
7171 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7176 ReleaseKey(KEY_LEFT
);
7177 ReleaseKey(KEY_RIGHT
);
7180 function CanRunLeft(): Boolean;
7182 Result
:= not CollideLevel(-1, 0);
7185 function CanRunRight(): Boolean;
7187 Result
:= not CollideLevel(1, 0);
7190 function CanRun(): Boolean;
7192 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7195 procedure Jump(Time
: Word = 30);
7197 PressKey(KEY_JUMP
, Time
);
7200 function NearHole(): Boolean;
7204 { TODO 5 : Ëåñòíèöû }
7205 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7206 for x
:= 1 to PLAYER_RECT
.Width
do
7207 if (not StayOnStep(x
*sx
, 0)) and
7208 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7209 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7218 function BorderHole(): Boolean;
7222 { TODO 5 : Ëåñòíèöû }
7223 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7224 for x
:= 1 to PLAYER_RECT
.Width
do
7225 if (not StayOnStep(x
*sx
, 0)) and
7226 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7227 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7229 for xx
:= x
to x
+32 do
7230 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7240 function NearDeepHole(): Boolean;
7246 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7249 for x
:= 1 to PLAYER_RECT
.Width
do
7250 if (not StayOnStep(x
*sx
, 0)) and
7251 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7252 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7254 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7256 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7261 end else Result
:= False;
7264 function OverDeepHole(): Boolean;
7271 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7273 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7280 function OnGround(): Boolean;
7282 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7285 function OnLadder(): Boolean;
7287 Result
:= FullInStep(0, 0);
7290 function BelowLadder(): Boolean;
7292 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7293 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7294 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7295 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7298 function BelowLiftUp(): Boolean;
7300 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7301 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7302 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7303 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7306 function OnTopLift(): Boolean;
7308 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7311 function CanJumpOver(): Boolean;
7315 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7319 if not CollideLevel(sx
, 0) then Exit
;
7321 for y
:= 1 to BOT_MAXJUMP
do
7322 if CollideLevel(0, -y
) then Exit
else
7323 if not CollideLevel(sx
, -y
) then
7330 function CanJumpUp(Dist
: ShortInt): Boolean;
7337 if CollideLevel(Dist
, 0) then Exit
;
7340 for y
:= 0 to BOT_MAXJUMP
do
7341 if CollideLevel(Dist
, -y
) then
7350 for yy
:= y
+1 to BOT_MAXJUMP
do
7351 if not CollideLevel(Dist
, -yy
) then
7360 for y
:= 0 to BOT_MAXJUMP
do
7361 if CollideLevel(0, -y
) then
7369 if y
< yy
then Exit
;
7374 function IsSafeTrigger(): Boolean;
7379 if gTriggers
= nil then
7381 for a
:= 0 to High(gTriggers
) do
7382 if Collide(gTriggers
[a
].X
,
7385 gTriggers
[a
].Height
) and
7386 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7387 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7388 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7389 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7390 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7395 // Âîçìîæíî, íàæèìàåì êíîïêó:
7396 if Rnd(16) and IsSafeTrigger() then
7399 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7400 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7402 ReleaseKey(KEY_LEFT
);
7403 ReleaseKey(KEY_RIGHT
);
7407 // Èäåì âëåâî, åñëè íàäî áûëî:
7408 if GetAIFlag('GOLEFT') <> '' then
7410 RemoveAIFlag('GOLEFT');
7411 if CanRunLeft() then
7415 // Èäåì âïðàâî, åñëè íàäî áûëî:
7416 if GetAIFlag('GORIGHT') <> '' then
7418 RemoveAIFlag('GORIGHT');
7419 if CanRunRight() then
7423 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7424 if FObj
.X
< -32 then
7427 if FObj
.X
+32 > gMapInfo
.Width
then
7430 // Ïðûãàåì, åñëè íàäî áûëî:
7431 if GetAIFlag('NEEDJUMP') <> '' then
7434 RemoveAIFlag('NEEDJUMP');
7437 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7438 if GetAIFlag('NEEDSEEUP') <> '' then
7441 ReleaseKey(KEY_DOWN
);
7442 PressKey(KEY_UP
, 20);
7443 RemoveAIFlag('NEEDSEEUP');
7446 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7447 if GetAIFlag('NEEDSEEDOWN') <> '' then
7450 ReleaseKey(KEY_DOWN
);
7451 PressKey(KEY_DOWN
, 20);
7452 RemoveAIFlag('NEEDSEEDOWN');
7455 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7456 if GetAIFlag('GOINHOLE') <> '' then
7457 if not OnGround() then
7459 ReleaseKey(KEY_LEFT
);
7460 ReleaseKey(KEY_RIGHT
);
7461 RemoveAIFlag('GOINHOLE');
7462 SetAIFlag('FALLINHOLE', '1');
7465 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7466 if GetAIFlag('FALLINHOLE') <> '' then
7468 RemoveAIFlag('FALLINHOLE');
7470 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7471 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7472 if GetAIFlag('FALLINHOLE') = '' then
7473 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7479 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7481 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7485 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7486 if OnGround() and NearHole() then
7487 if NearDeepHole() then // Åñëè ýòî áåçäíà
7489 0..3: Turn(); // Áåæèì îáðàòíî
7490 4: Jump(); // Ïðûãàåì
7491 5: begin // Ïðûãàåì îáðàòíî
7496 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7497 if GetAIFlag('GOINHOLE') = '' then
7499 0: Turn(); // Íå íóæíî òóäà
7500 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7501 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7502 if BorderHole() then
7503 SetAIFlag('GOINHOLE', '1');
7506 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7507 if (not CanRun()) and OnGround() then
7509 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7510 if CanJumpOver() or OnLadder() then
7512 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7513 if Random(2) = 0 then
7515 if IsSafeTrigger() then
7521 // Îñòàëîñü ìàëî âîçäóõà:
7522 if FAir
< 36 * 2 then
7525 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7526 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7527 if BodyInAcid(0, 0) then
7531 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7533 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7534 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7537 {function TBot.NeedItem(Item: Byte): Byte;
7542 procedure TBot
.SelectWeapon(Dist
: Integer);
7546 function HaveAmmo(weapon
: Byte): Boolean;
7549 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7550 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7551 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7552 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7553 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7554 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7555 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7556 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7557 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7558 else Result
:= True;
7563 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7565 if Dist
> BOT_LONGDIST
then
7566 begin // Äàëüíèé áîé
7568 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7570 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7574 else //if Dist > BOT_UNSAFEDIST then
7575 begin // Áëèæíèé áîé
7577 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7579 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7586 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7588 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7594 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7596 Result
:= inherited PickItem(ItemType
, force
, remove
);
7598 if Result
then SetAIFlag('SELECTWEAPON', '1');
7601 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7603 Result
:= inherited Heal(value
, Soft
);
7606 function TBot
.Healthy(): Byte;
7608 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7609 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7610 else if (FHealth
> 50) then Result
:= 2
7611 else if (FHealth
> 20) then Result
:= 1
7615 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7617 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7618 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7621 procedure TBot
.OnDamage(Angle
: SmallInt);
7629 if (Angle
= 0) or (Angle
= 180) then
7632 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7633 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7635 pla
:= g_Player_Get(FLastSpawnerUID
);
7636 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7637 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7640 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7641 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7643 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7644 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7645 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7650 SetAIFlag('ATTACKLEFT', '1')
7652 SetAIFlag('ATTACKRIGHT', '1');
7656 function TBot
.RunDirection(): TDirection
;
7658 if Abs(Vel
.X
) >= 1 then
7660 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7662 Result
:= FDirection
;
7665 function TBot
.GetRnd(a
: Byte): Boolean;
7667 if a
= 0 then Result
:= False
7668 else if a
= 255 then Result
:= True
7669 else Result
:= Random(256) > 255-a
;
7672 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7674 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7678 procedure TDifficult
.save (st
: TStream
);
7680 utils
.writeInt(st
, Byte(DiagFire
));
7681 utils
.writeInt(st
, Byte(InvisFire
));
7682 utils
.writeInt(st
, Byte(DiagPrecision
));
7683 utils
.writeInt(st
, Byte(FlyPrecision
));
7684 utils
.writeInt(st
, Byte(Cover
));
7685 utils
.writeInt(st
, Byte(CloseJump
));
7686 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7687 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7690 procedure TDifficult
.load (st
: TStream
);
7692 DiagFire
:= utils
.readByte(st
);
7693 InvisFire
:= utils
.readByte(st
);
7694 DiagPrecision
:= utils
.readByte(st
);
7695 FlyPrecision
:= utils
.readByte(st
);
7696 Cover
:= utils
.readByte(st
);
7697 CloseJump
:= utils
.readByte(st
);
7698 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7699 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7703 procedure TBot
.SaveState (st
: TStream
);
7708 inherited SaveState(st
);
7709 utils
.writeSign(st
, 'BOT0');
7711 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7713 utils
.writeInt(st
, Word(FTargetUID
));
7714 // Âðåìÿ ïîòåðè öåëè
7715 utils
.writeInt(st
, LongWord(FLastVisible
));
7716 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7717 dw
:= Length(FAIFlags
);
7718 utils
.writeInt(st
, LongInt(dw
));
7720 for i
:= 0 to dw
-1 do
7722 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7723 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7725 // Íàñòðîéêè ñëîæíîñòè
7726 FDifficult
.save(st
);
7730 procedure TBot
.LoadState (st
: TStream
);
7735 inherited LoadState(st
);
7736 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7738 FSelectedWeapon
:= utils
.readByte(st
);
7740 FTargetUID
:= utils
.readWord(st
);
7741 // Âðåìÿ ïîòåðè öåëè
7742 FLastVisible
:= utils
.readLongWord(st
);
7743 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7744 dw
:= utils
.readLongInt(st
);
7745 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7746 SetLength(FAIFlags
, dw
);
7748 for i
:= 0 to dw
-1 do
7750 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7751 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7753 // Íàñòðîéêè ñëîæíîñòè
7754 FDifficult
.load(st
);
7759 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);