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
);
1519 if Player
.alive
then
1522 // Ðàçðûâàåì ñâÿçü ñ ïðåæíèì òðóïîì:
1523 if gCorpses
<> nil then
1524 for i
:= 0 to High(gCorpses
) do
1525 if gCorpses
[i
] <> nil then
1526 if gCorpses
[i
].FPlayerUID
= Player
.FUID
then
1527 gCorpses
[i
].FPlayerUID
:= 0;
1529 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1534 if (FHealth
>= -50) or (gGibsCount
= 0) then
1536 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1540 for find_id
:= 0 to High(gCorpses
) do
1541 if gCorpses
[find_id
] = nil then
1548 find_id
:= Random(Length(gCorpses
));
1550 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1551 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1552 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1553 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1554 gCorpses
[find_id
].FPlayerUID
:= FUID
;
1557 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1558 FObj
.Y
+ PLAYER_RECT_CY
,
1559 FModel
.Name
, FModel
.Color
);
1563 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1567 if (gShells
= nil) or (Length(gShells
) = 0) then
1570 with gShells
[CurrentShell
] do
1576 if T
= SHELL_BULLET
then
1578 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1582 Obj
.Rect
.Width
:= 4;
1583 Obj
.Rect
.Height
:= 2;
1587 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1591 Obj
.Rect
.Width
:= 7;
1592 Obj
.Rect
.Height
:= 3;
1598 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1599 positionChanged(); // this updates spatial accelerators
1600 RAngle
:= Random(360);
1601 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1603 if CurrentShell
>= High(gShells
) then
1610 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1613 GibsArray
: TGibsArray
;
1616 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1618 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1620 Blood
:= g_PlayerModel_GetBlood(ModelName
);
1622 for a
:= 0 to High(GibsArray
) do
1623 with gGibs
[CurrentGib
] do
1626 ID
:= GibsArray
[a
].ID
;
1627 MaskID
:= GibsArray
[a
].MaskID
;
1630 Obj
.Rect
:= GibsArray
[a
].Rect
;
1631 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1632 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1633 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1634 positionChanged(); // this updates spatial accelerators
1635 RAngle
:= Random(360);
1637 if gBloodCount
> 0 then
1638 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1639 Random(48), Random(48), Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
1641 if CurrentGib
>= High(gGibs
) then
1648 procedure g_Player_UpdatePhysicalObjects();
1654 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1659 if T
= SHELL_BULLET
then
1660 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1662 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1667 if gGibs
<> nil then
1668 for i
:= 0 to High(gGibs
) do
1669 if gGibs
[i
].alive
then
1673 mr
:= g_Obj_Move(@Obj
, True, False, True);
1674 positionChanged(); // this updates spatial accelerators
1676 if WordBool(mr
and MOVE_FALLOUT
) then
1682 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1683 if WordBool(mr
and MOVE_HITWALL
) then
1684 Obj
.Vel
.X
:= -(vel
.X
div 2);
1685 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1686 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1688 if (Obj
.Vel
.X
>= 0) then
1690 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1691 if RAngle
>= 360 then
1692 RAngle
:= RAngle
mod 360;
1693 end else begin // Counter-clockwise
1694 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1696 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1699 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1700 if gTime
mod (GAME_TICK
*3) = 0 then
1701 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1705 if gCorpses
<> nil then
1706 for i
:= 0 to High(gCorpses
) do
1707 if gCorpses
[i
] <> nil then
1708 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1714 gCorpses
[i
].Update();
1717 if gShells
<> nil then
1718 for i
:= 0 to High(gShells
) do
1719 if gShells
[i
].alive
then
1723 mr
:= g_Obj_Move(@Obj
, True, False, True);
1724 positionChanged(); // this updates spatial accelerators
1726 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1732 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1733 if WordBool(mr
and MOVE_HITWALL
) then
1735 Obj
.Vel
.X
:= -(vel
.X
div 2);
1736 if not WordBool(mr
and MOVE_INWATER
) then
1737 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1739 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1741 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1742 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1743 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1745 if RAngle
mod 90 <> 0 then
1746 RAngle
:= (RAngle
div 90) * 90;
1748 else if not WordBool(mr
and MOVE_INWATER
) then
1749 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1752 if (Obj
.Vel
.X
>= 0) then
1754 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1755 if RAngle
>= 360 then
1756 RAngle
:= RAngle
mod 360;
1757 end else begin // Counter-clockwise
1758 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1760 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1766 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1768 x
:= Obj
.X
+Obj
.Rect
.X
;
1769 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1770 w
:= Obj
.Rect
.Width
;
1771 h
:= Obj
.Rect
.Height
;
1774 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1776 if (dx
<> 0) or (dy
<> 0) then
1785 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1789 w
:= Obj
.Rect
.Width
;
1790 h
:= Obj
.Rect
.Height
;
1793 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1795 if (dx
<> 0) or (dy
<> 0) then
1804 procedure TGib
.positionChanged (); inline; begin end;
1805 procedure TShell
.positionChanged (); inline; begin end;
1808 procedure g_Player_DrawCorpses();
1813 if gGibs
<> nil then
1814 for i
:= 0 to High(gGibs
) do
1815 if gGibs
[i
].alive
then
1818 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1821 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1822 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1824 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1827 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1833 if gCorpses
<> nil then
1834 for i
:= 0 to High(gCorpses
) do
1835 if gCorpses
[i
] <> nil then
1839 procedure g_Player_DrawShells();
1844 if gShells
<> nil then
1845 for i
:= 0 to High(gShells
) do
1846 if gShells
[i
].alive
then
1849 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1855 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1859 procedure g_Player_RemoveAllCorpses();
1865 SetLength(gGibs
, MaxGibs
);
1866 SetLength(gShells
, MaxGibs
);
1870 if gCorpses
<> nil then
1871 for i
:= 0 to High(gCorpses
) do
1875 SetLength(gCorpses
, MaxCorpses
);
1878 procedure g_Player_Corpses_SaveState (st
: TStream
);
1882 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ
1884 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1886 // Êîëè÷åñòâî òðóïîâ
1887 utils
.writeInt(st
, LongInt(count
));
1889 if (count
= 0) then exit
;
1892 for i
:= 0 to High(gCorpses
) do
1894 if gCorpses
[i
] <> nil then
1897 utils
.writeStr(st
, gCorpses
[i
].FModelName
);
1899 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1900 // Ñîõðàíÿåì äàííûå òðóïà:
1901 gCorpses
[i
].SaveState(st
);
1907 procedure g_Player_Corpses_LoadState (st
: TStream
);
1915 g_Player_RemoveAllCorpses();
1917 // Êîëè÷åñòâî òðóïîâ:
1918 count
:= utils
.readLongInt(st
);
1919 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1921 if (count
= 0) then exit
;
1924 for i
:= 0 to count
-1 do
1927 str
:= utils
.readStr(st
);
1929 b
:= utils
.readBool(st
);
1931 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1932 // Çàãðóæàåì äàííûå òðóïà
1933 gCorpses
[i
].LoadState(st
);
1940 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1942 procedure TPlayer
.BFGHit();
1944 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1945 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1946 if g_Game_IsServer
and g_Game_IsNet
then
1947 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1948 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1952 procedure TPlayer
.ChangeModel(ModelName
: string);
1954 locModel
: TPlayerModel
;
1956 locModel
:= g_PlayerModel_Get(ModelName
);
1957 if locModel
= nil then Exit
;
1963 procedure TPlayer
.SetModel(ModelName
: string);
1967 m
:= g_PlayerModel_Get(ModelName
);
1970 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1971 m
:= g_PlayerModel_Get('doomer');
1974 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1979 if FModel
<> nil then
1984 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1985 FModel
.Color
:= FColor
1987 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1988 FModel
.SetWeapon(FCurrWeap
);
1989 FModel
.SetFlag(FFlag
);
1990 SetDirection(FDirection
);
1993 procedure TPlayer
.SetColor(Color
: TRGB
);
1996 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1997 if FModel
<> nil then FModel
.Color
:= Color
;
2000 procedure TPlayer
.SwitchTeam
;
2002 if g_Game_IsClient
then
2004 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
2006 if gGameOn
and FAlive
then
2007 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
2009 if FTeam
= TEAM_RED
then
2011 ChangeTeam(TEAM_BLUE
);
2012 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
2013 if g_Game_IsNet
then
2014 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
2018 ChangeTeam(TEAM_RED
);
2019 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
2020 if g_Game_IsNet
then
2021 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
2023 FPreferredTeam
:= FTeam
;
2026 procedure TPlayer
.ChangeTeam(Team
: Byte);
2033 TEAM_RED
, TEAM_BLUE
:
2034 FModel
.Color
:= TEAMCOLOR
[Team
];
2036 FModel
.Color
:= FColor
;
2038 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2039 MH_SEND_PlayerStats(FUID
);
2043 procedure TPlayer.CollideItem();
2048 if gItems = nil then Exit;
2049 if not FAlive then Exit;
2051 for i := 0 to High(gItems) do
2054 if (ItemType <> ITEM_NONE) and alive then
2055 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2056 PLAYER_RECT.Height, @Obj) then
2058 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2060 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2061 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2062 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2063 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2064 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2066 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2067 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2068 (gGameSettings.GameType = GT_SINGLE) and
2069 (g_Player_GetCount() > 1)) then
2070 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2076 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2078 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2079 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2083 constructor TPlayer
.Create();
2089 mEDamageType
:= HIT_SOME
;
2095 FSawSound
:= TPlayableSound
.Create();
2096 FSawSoundIdle
:= TPlayableSound
.Create();
2097 FSawSoundHit
:= TPlayableSound
.Create();
2098 FSawSoundSelect
:= TPlayableSound
.Create();
2099 FJetSoundFly
:= TPlayableSound
.Create();
2100 FJetSoundOn
:= TPlayableSound
.Create();
2101 FJetSoundOff
:= TPlayableSound
.Create();
2103 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2104 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2105 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2106 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2107 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2108 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2109 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2111 FSpectatePlayer
:= -1;
2115 FSavedState
.WaitRecall
:= False;
2121 FActualModelName
:= 'doomer';
2124 FObj
.Rect
:= PLAYER_RECT
;
2126 FBFGFireCounter
:= -1;
2127 FJustTeleported
:= False;
2133 procedure TPlayer
.positionChanged (); inline;
2137 procedure TPlayer
.doDamage (v
: Integer);
2139 if (v
<= 0) then exit
;
2140 if (v
> 32767) then v
:= 32767;
2141 Damage(v
, 0, 0, 0, mEDamageType
);
2144 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2148 if (not g_Game_IsClient
) and (not FAlive
) then
2153 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2154 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2156 if not g_Game_IsClient
then
2159 if t
= HIT_TRAP
then
2161 // Ëîâóøêà óáèâàåò ñðàçó:
2163 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2165 if t
= HIT_SELF
then
2169 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2172 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2173 FMegaRulez
[MR_SUIT
] := 0;
2174 FMegaRulez
[MR_INVUL
] := 0;
2175 FMegaRulez
[MR_INVIS
] := 0;
2179 // Íî îò îñòàëüíîãî ñïàñàåò:
2180 if FMegaRulez
[MR_INVUL
] >= gTime
then
2187 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2188 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2189 (SpawnerUID
= FUID
) or
2190 (not SameTeam(FUID
, SpawnerUID
)) then
2192 FLastSpawnerUID
:= SpawnerUID
;
2194 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2195 if gBloodCount
> 0 then
2197 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2198 if value
div 4 <= c
then
2199 c
:= c
- (value
div 4)
2203 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2207 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2208 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2211 if t
= HIT_WATER
then
2212 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2213 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2218 Inc(FDamageBuffer
, value
);
2222 FPain
:= FPain
+ value
;
2225 if g_Game_IsServer
and g_Game_IsNet
then
2227 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2228 MH_SEND_PlayerStats(FUID
);
2229 MH_SEND_PlayerPos(False, FUID
);
2233 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2236 if g_Game_IsClient
then
2241 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2243 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2246 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2248 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2252 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2253 MH_SEND_PlayerStats(FUID
);
2256 destructor TPlayer
.Destroy();
2258 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2260 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2264 FSawSoundIdle
.Free();
2265 FSawSoundHit
.Free();
2266 FJetSoundFly
.Free();
2268 FJetSoundOff
.Free();
2270 if FPunchAnim
<> nil then
2276 procedure TPlayer
.DrawBubble();
2278 bubX
, bubY
: Integer;
2281 Rw
, Gw
, Bw
: SmallInt;
2284 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= TDirection
.D_LEFT
, -4, 18);
2285 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2293 1: // simple textual non-bubble
2295 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2296 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2297 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2300 2: // advanced pixel-perfect bubble
2302 if FTeam
= TEAM_RED
then
2305 if FTeam
= TEAM_BLUE
then
2308 3: // colored bubble
2310 Rb
:= FModel
.Color
.R
;
2311 Gb
:= FModel
.Color
.G
;
2312 Bb
:= FModel
.Color
.B
;
2313 Rw
:= Min(Rb
* 2 + 64, 255);
2314 Gw
:= Min(Gb
* 2 + 64, 255);
2315 Bw
:= Min(Bb
* 2 + 64, 255);
2316 if (Abs(Rw
- Rb
) < 32)
2317 or (Abs(Gw
- Gb
) < 32)
2318 or (Abs(Bw
- Bb
) < 32) then
2320 Rb
:= Max(Rw
div 2 - 16, 0);
2321 Gb
:= Max(Gw
div 2 - 16, 0);
2322 Bb
:= Max(Bw
div 2 - 16, 0);
2325 4: // custom textured bubble
2327 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2328 if FDirection
= TDirection
.D_RIGHT
then
2329 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2331 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, TMirrorType
.Horizontal
);
2337 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2338 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2340 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2343 Dot
:= IfThen(FDirection
= TDirection
.D_LEFT
, 14, 5);
2344 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2345 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
);
2346 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
);
2347 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
);
2348 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
);
2352 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2353 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2354 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2357 procedure TPlayer
.Draw();
2362 Mirror
: TMirrorType
;
2366 if Direction
= TDirection
.D_RIGHT
then
2367 Mirror
:= TMirrorType
.None
2369 Mirror
:= TMirrorType
.Horizontal
;
2371 if FPunchAnim
<> nil then
2373 FPunchAnim
.Draw(FObj
.X
+IfThen(Direction
= TDirection
.D_LEFT
, 15-FObj
.Rect
.X
, FObj
.Rect
.X
-15),
2374 FObj
.Y
+FObj
.Rect
.Y
-11, Mirror
);
2375 if FPunchAnim
.played
then
2382 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2383 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2385 e_GetTextureSize(ID
, @w
, @h
);
2386 if FDirection
= TDirection
.D_LEFT
then
2387 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2388 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False)
2390 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2391 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False);
2394 if FMegaRulez
[MR_INVIS
] > gTime
then
2396 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2397 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2399 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2400 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2404 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 200)
2406 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2409 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 254);
2412 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2415 if g_debug_Frames
then
2417 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2419 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2420 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2424 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2426 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2427 if gAimLine
and alive
and
2428 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2433 procedure TPlayer
.DrawAim();
2434 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2439 {$IFDEF ENABLE_HOLMES}
2440 if isValidViewPort
and (self
= gPlayer1
) then
2442 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2446 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2447 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2449 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2453 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2458 wx
, wy
, xx
, yy
: Integer;
2462 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= TDirection
.D_LEFT
, 7, -7);
2463 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2472 1: begin // Chainsaw
2479 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2480 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2481 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2482 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2487 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2488 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2489 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2490 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2492 4: begin // Double Shotgun
2495 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2496 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2497 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2498 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2500 5: begin // Chaingun
2503 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2504 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2505 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2506 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2508 6: begin // Rocket Launcher
2511 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2512 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2513 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2514 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2516 7: begin // Plasmagun
2519 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2520 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2521 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2522 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2527 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2528 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2529 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2530 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2532 9: begin // Super Chaingun
2535 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2536 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2537 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2538 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2541 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2542 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2543 {$IF DEFINED(D2F_DEBUG)}
2544 drawCast(sz
, wx
, wy
, xx
, yy
);
2546 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2550 procedure TPlayer
.DrawGUI();
2553 X
, Y
, SY
, a
, p
, m
: Integer;
2557 stat
: TPlayerStatArray
;
2559 X
:= gPlayerScreenSize
.X
;
2560 SY
:= gPlayerScreenSize
.Y
;
2563 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2565 if gGameSettings
.GameMode
= GM_CTF
then
2569 if gGameSettings
.GameMode
= GM_CTF
then
2571 s
:= 'TEXTURE_PLAYER_REDFLAG';
2572 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2573 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2574 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2575 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2576 if g_Texture_Get(s
, ID
) then
2577 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2580 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2581 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2582 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2584 if gGameSettings
.GameMode
= GM_CTF
then
2586 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2587 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2588 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2589 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2590 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2591 if g_Texture_Get(s
, ID
) then
2592 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2595 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2596 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2597 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2600 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2601 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2604 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2605 e_Draw(ID
, X
+2, Y
, 0, True, False);
2607 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2611 s
:= IntToStr(Frags
);
2612 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2613 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2618 stat
:= g_Player_GetStats();
2623 for a
:= 0 to High(stat
) do
2624 if stat
[a
].Name
<> Name
then
2626 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2627 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2631 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2632 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2633 s
:= s
+IntToStr(Abs(Frags
-m
));
2635 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2636 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2639 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2641 s
:= IntToStr(Lives
);
2642 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2643 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2647 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2648 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2650 if R_BERSERK
in FRulez
then
2651 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2653 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2655 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2656 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2658 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2659 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2660 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2662 s
:= IntToStr(FArmor
);
2663 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2664 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2666 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2672 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2677 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2679 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2680 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2681 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2682 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2683 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2684 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2685 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2686 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2687 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2690 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2691 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2692 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2694 if R_KEY_RED
in FRulez
then
2695 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2697 if R_KEY_GREEN
in FRulez
then
2698 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2700 if R_KEY_BLUE
in FRulez
then
2701 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2703 if FJetFuel
> 0 then
2705 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2706 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2707 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2708 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2709 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2710 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2714 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2715 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2716 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2719 if gShowPing
and g_Game_IsClient
then
2721 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2722 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2728 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2729 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2730 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2733 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2734 s
:= _lc
[I_PLAYER_SPECT4
];
2735 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2736 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2737 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2743 procedure TPlayer
.DrawRulez();
2747 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2748 if FMegaRulez
[MR_INVUL
] >= gTime
then
2750 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2751 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2756 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2757 191, 191, 191, 0, TBlending
.Invert
);
2760 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2761 if FMegaRulez
[MR_SUIT
] >= gTime
then
2763 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2764 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2769 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2770 0, 96, 0, 200, TBlending
.None
);
2773 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2774 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2776 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2777 255, 0, 0, 200, TBlending
.None
);
2781 procedure TPlayer
.DrawPain();
2785 if FPain
= 0 then Exit
;
2789 if a
< 15 then h
:= 0
2790 else if a
< 35 then h
:= 1
2791 else if a
< 55 then h
:= 2
2792 else if a
< 75 then h
:= 3
2793 else if a
< 95 then h
:= 4
2796 //if a > 255 then a := 255;
2798 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2799 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2802 procedure TPlayer
.DrawPickup();
2806 if FPickup
= 0 then Exit
;
2810 if a
< 15 then h
:= 1
2811 else if a
< 35 then h
:= 2
2812 else if a
< 55 then h
:= 3
2813 else if a
< 75 then h
:= 4
2816 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2819 procedure TPlayer
.DoPunch();
2824 if FPunchAnim
<> nil then begin
2829 st
:= 'FRAMES_PUNCH';
2830 if R_BERSERK
in FRulez
then
2831 st
:= st
+ '_BERSERK';
2832 if FKeys
[KEY_UP
].Pressed
then
2834 else if FKeys
[KEY_DOWN
].Pressed
then
2836 g_Frames_Get(id
, st
);
2837 FPunchAnim
:= TAnimation
.Create(id
, False, 1);
2840 procedure TPlayer
.Fire();
2842 f
, DidFire
: Boolean;
2843 wx
, wy
, xd
, yd
: Integer;
2846 if g_Game_IsClient
then Exit
;
2847 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2848 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2856 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2861 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2862 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2863 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
2864 yd
:= wy
+firediry();
2870 if R_BERSERK
in FRulez
then
2872 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2873 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2874 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2877 locobj
.rect
.Width
:= 39;
2878 locobj
.rect
.Height
:= 52;
2879 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2880 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2881 locobj
.Accel
.X
:= xd
-wx
;
2882 locobj
.Accel
.y
:= yd
-wy
;
2884 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2885 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2887 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2889 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
2893 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2897 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2902 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2903 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2905 FSawSoundSelect
.Stop();
2907 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2909 else if not FSawSoundHit
.IsPlaying() then
2911 FSawSoundSelect
.Stop();
2912 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2915 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2921 if FAmmo
[A_BULLETS
] > 0 then
2923 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2924 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2925 Dec(FAmmo
[A_BULLETS
]);
2926 FFireAngle
:= FAngle
;
2929 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2930 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2934 if FAmmo
[A_SHELLS
] > 0 then
2936 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2937 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
2938 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2939 Dec(FAmmo
[A_SHELLS
]);
2940 FFireAngle
:= FAngle
;
2944 FShellType
:= SHELL_SHELL
;
2948 if FAmmo
[A_SHELLS
] >= 2 then
2950 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
2951 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2952 Dec(FAmmo
[A_SHELLS
], 2);
2953 FFireAngle
:= FAngle
;
2957 FShellType
:= SHELL_DBLSHELL
;
2961 if FAmmo
[A_BULLETS
] > 0 then
2963 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
2964 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
2965 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2966 Dec(FAmmo
[A_BULLETS
]);
2967 FFireAngle
:= FAngle
;
2970 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2971 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2974 WEAPON_ROCKETLAUNCHER
:
2975 if FAmmo
[A_ROCKETS
] > 0 then
2977 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
2978 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2979 Dec(FAmmo
[A_ROCKETS
]);
2980 FFireAngle
:= FAngle
;
2986 if FAmmo
[A_CELLS
] > 0 then
2988 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
2989 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2990 Dec(FAmmo
[A_CELLS
]);
2991 FFireAngle
:= FAngle
;
2997 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
2999 FBFGFireCounter
:= 17;
3000 if not FNoReload
then
3001 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
3002 Dec(FAmmo
[A_CELLS
], 40);
3006 WEAPON_SUPERPULEMET
:
3007 if FAmmo
[A_SHELLS
] > 0 then
3009 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3010 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
3011 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3012 Dec(FAmmo
[A_SHELLS
]);
3013 FFireAngle
:= FAngle
;
3016 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3017 GameVelX
, GameVelY
-2, SHELL_SHELL
);
3020 WEAPON_FLAMETHROWER
:
3021 if FAmmo
[A_FUEL
] > 0 then
3023 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
3024 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3026 FFireAngle
:= FAngle
;
3032 if g_Game_IsNet
then
3036 if FCurrWeap
<> WEAPON_BFG
then
3037 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
3039 if not FNoReload
then
3040 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
3043 MH_SEND_PlayerStats(FUID
);
3048 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
3049 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
3050 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
3053 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
3056 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
3057 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
3058 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
3059 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
3060 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
3065 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
3067 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
3068 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
3069 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
3072 procedure TPlayer
.JetpackOn
;
3076 FJetSoundOn
.SetPosition(0);
3077 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3081 procedure TPlayer
.JetpackOff
;
3085 FJetSoundOff
.SetPosition(0);
3086 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3089 procedure TPlayer
.CatchFire(Attacker
: Word);
3092 FFireAttacker
:= Attacker
;
3093 if g_Game_IsNet
and g_Game_IsServer
then
3094 MH_SEND_PlayerStats(FUID
);
3097 procedure TPlayer
.Jump();
3099 if gFly
or FJetpack
then
3101 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3102 if FObj
.Vel
.Y
> -VEL_FLY
then
3103 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3106 if FJetFuel
> 0 then
3108 if (FJetFuel
< 1) and g_Game_IsServer
then
3112 if g_Game_IsNet
then
3113 MH_SEND_PlayerStats(FUID
);
3119 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3121 FCanJetpack
:= False;
3123 // Ïðûãàåì èëè âñïëûâàåì:
3124 if (CollideLevel(0, 1) or
3125 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3126 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3127 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3129 FObj
.Vel
.Y
:= -VEL_JUMP
;
3130 FCanJetpack
:= False;
3134 if BodyInLiquid(0, 0) then
3135 FObj
.Vel
.Y
:= -VEL_SW
3136 else if (FJetFuel
> 0) and FCanJetpack
and
3137 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3141 if g_Game_IsNet
then
3142 MH_SEND_PlayerStats(FUID
);
3147 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3149 a
, i
, k
, ab
, ar
: Byte;
3153 srv
, netsrv
: Boolean;
3159 procedure PushItem(t
: Byte);
3163 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3164 it
:= g_Items_ByIdx(id
);
3165 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3167 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3168 (FObj
.Vel
.Y
div 2)-Random(9));
3169 it
.positionChanged(); // this updates spatial accelerators
3173 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3175 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3176 (FObj
.Vel
.Y
div 2)-Random(6));
3178 else // -3..+3; -3..0
3180 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3181 (FObj
.Vel
.Y
div 2)-Random(4));
3183 it
.positionChanged(); // this updates spatial accelerators
3186 if g_Game_IsNet
and g_Game_IsServer
then
3187 MH_SEND_ItemSpawn(True, id
);
3191 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3192 Srv
:= g_Game_IsServer
;
3193 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3194 if Srv
then FDeath
:= FDeath
+ 1;
3199 if not FPhysics
then
3205 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3207 if FLives
> 0 then FLives
:= FLives
- 1;
3208 if FLives
= 0 then FNoRespawn
:= True;
3211 // Íîìåð òèïà ñìåðòè:
3214 K_SIMPLEKILL
: a
:= 1;
3216 K_EXTRAHARDKILL
: a
:= 3;
3221 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3223 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3230 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3232 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3233 K_EXTRAHARDKILL
, K_FALLKILL
:
3234 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3237 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3241 K_HARDKILL
, K_EXTRAHARDKILL
:
3245 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3246 if (KillType
<> K_FALLKILL
) and (Srv
) then
3247 g_Monsters_killedp();
3249 if SpawnerUID
= FUID
then
3251 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3256 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3259 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3260 begin // Óáèò äðóãèì èãðîêîì
3261 KP
:= g_Player_Get(SpawnerUID
);
3262 if (KP
<> nil) and Srv
then
3264 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3265 if SameTeam(FUID
, SpawnerUID
) then
3275 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3276 Inc(gTeamStat
[KP
.Team
].Goals
,
3277 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3279 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3282 plr
:= g_Player_Get(SpawnerUID
);
3290 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3294 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3298 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3303 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3304 begin // Óáèò ìîíñòðîì
3305 mon
:= g_Monsters_ByUID(SpawnerUID
);
3309 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
3313 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3317 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3321 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3326 else // Îñîáûå òèïû ñìåðòè
3329 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3330 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3331 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3332 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3333 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3334 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3340 for a
:= WP_FIRST
to WP_LAST
do
3344 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3345 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3346 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3347 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3348 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3349 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3350 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3351 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3352 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3361 if R_ITEM_BACKPACK
in FRulez
then
3362 PushItem(ITEM_AMMO_BACKPACK
);
3364 // Âûáðîñ ðàêåòíîãî ðàíöà:
3365 if FJetFuel
> 0 then
3366 PushItem(ITEM_JETPACK
);
3369 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3371 if R_KEY_RED
in FRulez
then
3372 PushItem(ITEM_KEY_RED
);
3374 if R_KEY_GREEN
in FRulez
then
3375 PushItem(ITEM_KEY_GREEN
);
3377 if R_KEY_BLUE
in FRulez
then
3378 PushItem(ITEM_KEY_BLUE
);
3385 g_Player_CreateCorpse(Self
);
3387 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3388 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3394 for i
:= Low(gPlayers
) to High(gPlayers
) do
3396 if gPlayers
[i
] = nil then continue
;
3397 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3400 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3401 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3406 OldLR
:= gLMSRespawn
;
3407 if (gGameSettings
.GameMode
= GM_COOP
) then
3411 // everyone is dead, restart the map
3412 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3414 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3415 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3416 gLMSRespawnTime
:= gTime
+ 5000;
3418 else if (a
= 1) then
3420 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3421 if (gPlayers
[k
] = gPlayer1
) or
3422 (gPlayers
[k
] = gPlayer2
) then
3423 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3424 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3425 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3428 else if (gGameSettings
.GameMode
= GM_TDM
) then
3430 if (ab
= 0) and (ar
<> 0) then
3433 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3435 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3436 Inc(gTeamStat
[TEAM_RED
].Goals
);
3437 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3438 gLMSRespawnTime
:= gTime
+ 5000;
3440 else if (ar
= 0) and (ab
<> 0) then
3443 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3445 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3446 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3447 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3448 gLMSRespawnTime
:= gTime
+ 5000;
3450 else if (ar
= 0) and (ab
= 0) then
3453 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3455 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3456 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3457 gLMSRespawnTime
:= gTime
+ 5000;
3460 else if (gGameSettings
.GameMode
= GM_DM
) then
3464 if gPlayers
[k
] <> nil then
3467 // survivor is the winner
3468 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3470 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3473 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3474 gLMSRespawnTime
:= gTime
+ 5000;
3476 else if (a
= 0) then
3478 // everyone is dead, restart the map
3479 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3481 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3482 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3483 gLMSRespawnTime
:= gTime
+ 5000;
3486 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3488 if NetMode
= NET_SERVER
then
3489 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3491 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3497 MH_SEND_PlayerStats(FUID
);
3498 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3499 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3502 if srv
and FNoRespawn
then Spectate(True);
3503 FWantsInGame
:= True;
3506 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3508 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3509 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3512 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3514 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3515 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3518 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3520 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3521 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3522 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3523 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3524 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3525 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3526 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3527 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3530 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3532 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3533 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3534 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3535 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3538 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3540 if g_Game_IsClient
then Exit
;
3541 if Weapon
> High(FWeapon
) then Exit
;
3542 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3545 procedure TPlayer
.resetWeaponQueue ();
3548 FNextWeapDelay
:= 0;
3551 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3555 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3556 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
3557 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
3558 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3559 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3560 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3561 else result
:= (weapon
< length(FWeapon
));
3565 // return 255 for "no switch"
3566 function TPlayer
.getNextWeaponIndex (): Byte;
3569 wantThisWeapon
: array[0..64] of Boolean;
3570 weaponOrder
: array[0..16] of Integer; // value: index in `FWeapon`
3572 f
, dir
, cwi
, rwidx
, curlidx
: Integer;
3574 function real2log (ridx
: Integer): Integer;
3580 for f
:= 0 to High(weaponOrder
) do if (weaponOrder
[f
] = ridx
) then begin result
:= f
; exit
; end;
3586 result
:= 255; // default result: "no switch"
3588 // had weapon cycling on previous frame? remove that flag
3589 if (FNextWeap
and $2000) <> 0 then
3591 FNextWeap
:= FNextWeap
and $1FFF;
3592 FNextWeapDelay
:= 0;
3595 for f
:= 0 to High(weaponOrder
) do weaponOrder
[f
] := -1;
3597 // build weapon order (k8: i know, i know, learn how to do constants and such... gtfo, please!)
3598 // two knuckles are for "normal" and "berserk" (see `if` below -- it removes the one that is not needed)
3600 // bfg, launcher, plasma, flamethrower, ssg, minigun, sg, pistol, berserk, chainsaw, fist
3601 weaponOrder
[0] := WEAPON_SUPERPULEMET
;
3602 weaponOrder
[1] := WEAPON_BFG
;
3603 weaponOrder
[2] := WEAPON_ROCKETLAUNCHER
;
3604 weaponOrder
[3] := WEAPON_PLASMA
;
3605 weaponOrder
[4] := WEAPON_FLAMETHROWER
;
3606 weaponOrder
[5] := WEAPON_SHOTGUN2
;
3607 weaponOrder
[6] := WEAPON_CHAINGUN
;
3608 weaponOrder
[7] := WEAPON_SHOTGUN1
;
3609 weaponOrder
[8] := WEAPON_PISTOL
;
3610 weaponOrder
[9] := WEAPON_KASTET
+666; // berserk fist
3611 weaponOrder
[10] := WEAPON_SAW
;
3612 weaponOrder
[11] := WEAPON_KASTET
; // normal fist
3614 for f
:= 0 to High(weaponOrder
) do
3616 if (weaponOrder
[f
] = WEAPON_KASTET
) then
3618 // normal fist: remove if we have a berserk pack
3619 if (R_BERSERK
in FRulez
) then weaponOrder
[f
] := -1;
3622 if (weaponOrder
[f
] = WEAPON_KASTET
+666) then
3624 // berserk fist: remove if we don't have a berserk pack
3625 if (R_BERSERK
in FRulez
) then weaponOrder
[f
] := WEAPON_KASTET
else weaponOrder
[f
] := -1;
3633 WEAPON_SHOTGUN1 = 3;
3634 WEAPON_SHOTGUN2 = 4;
3635 WEAPON_CHAINGUN = 5;
3636 WEAPON_ROCKETLAUNCHER = 6;
3639 WEAPON_SUPERPULEMET = 9;
3640 WEAPON_FLAMETHROWER = 10;
3643 // cycling has priority
3644 if (FNextWeap
and $C000) <> 0 then
3646 if (FNextWeap
and $8000) <> 0 then dir
:= 1 else dir
:= -1; // should be reversed if we want "priority-driven cycling"
3647 FNextWeap
:= FNextWeap
or $2000; // we need this
3648 if FNextWeapDelay
> 0 then exit
; // cooldown time
3649 //cwi := real2log(FCurrWeap);
3650 //if (cwi < 0) then cwi := 0;
3652 for i
:= 0 to High(FWeapon
) do
3654 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3655 //rwidx := weaponOrder[cwi];
3656 rwidx
:= cwi
; // sorry
3657 if (rwidx
< 0) then continue
;
3658 if FWeapon
[rwidx
] then
3660 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d (dir=%d; log=%d)', [FCurrWeap, rwidx, dir, cwi]), TMsgType.Warning);
3661 result
:= Byte(rwidx
);
3662 FNextWeapDelay
:= 10;
3671 for i
:= 0 to High(wantThisWeapon
) do wantThisWeapon
[i
] := false;
3674 curlidx
:= -1; // start from a weapon with a highest priority (-1, 'cause loop will immediately increment this index)
3676 for i
:= 0 to High(FWeapon
) do
3678 if (FNextWeap
and (1 shl i
)) <> 0 then
3683 wantThisWeapon
[cwi
] := true;
3685 // if we hit currently selected weapon, start seachring from it, so we'll get "next weaker" weapon
3686 if (i
= FCurrWeap
) then curlidx
:= cwi
; // compare real, start from logical
3691 // slow down alterations a little
3694 // more than one weapon requested, assume "alteration", and check alteration delay
3695 if FNextWeapDelay
> 0 then
3697 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), TMsgType.Warning);
3703 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3704 // but clear all counters if no weapon should be switched
3711 //e_WriteLog(Format('*** wwc=%d; currweap=%d; logweap=%d', [wwc, FCurrWeap, curlidx]), TMsgType.Warning);
3713 // find next weapon to switch onto
3715 for i
:= 0 to High(weaponOrder
) do
3717 cwi
:= (cwi
+length(weaponOrder
)+1) mod length(weaponOrder
);
3718 if (cwi
= curlidx
) then continue
; // skip current weapon
3719 if not wantThisWeapon
[cwi
] then continue
;
3720 rwidx
:= weaponOrder
[cwi
];
3721 if (rwidx
< 0) then continue
;
3722 //e_WriteLog(Format(' trying logical %d (real %d); has=%d, hasammo=%d', [cwi, rwidx, Integer(FWeapon[rwidx]), Integer(hasAmmoForWeapon(rwidx))]), TMsgType.Warning);
3723 if FWeapon
[rwidx
] and ((wwc
= 1) or hasAmmoForWeapon(rwidx
)) then
3725 //e_WriteLog(' I FOUND HER!', TMsgType.Warning);
3727 result
:= Byte(rwidx
);
3729 FNextWeapDelay
:= 10; // anyway, 'cause why not
3734 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3738 procedure TPlayer
.RealizeCurrentWeapon();
3739 function switchAllowed (): Boolean;
3744 if FBFGFireCounter
<> -1 then
3746 if FTime
[T_SWITCH
] > gTime
then
3748 for i
:= WP_FIRST
to WP_LAST
do
3749 if FReloading
[i
] > 0 then
3757 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3758 //FNextWeap := FNextWeap and $1FFF;
3759 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3761 if not switchAllowed
then
3763 //HACK for weapon cycling
3764 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3768 nw
:= getNextWeaponIndex();
3769 if nw
= 255 then exit
; // don't reset anything here
3770 if nw
> High(FWeapon
) then
3772 // don't forget to reset queue here!
3773 //e_WriteLog(Format(' RealizeCurrentWeapon: WUTAFUUUU?! (%d)', [nw]), TMsgType.Warning);
3781 FTime
[T_SWITCH
] := gTime
+156;
3782 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3783 FModel
.SetWeapon(FCurrWeap
);
3784 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3788 procedure TPlayer
.NextWeapon();
3790 if g_Game_IsClient
then Exit
;
3794 procedure TPlayer
.PrevWeapon();
3796 if g_Game_IsClient
then Exit
;
3800 procedure TPlayer
.SetWeapon(W
: Byte);
3802 if FCurrWeap
<> W
then
3803 if W
= WEAPON_SAW
then
3804 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3807 FModel
.SetWeapon(CurrWeap
);
3811 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3813 function allowBerserkSwitching (): Boolean;
3815 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3817 if gBerserkAutoswitch
then exit
;
3818 if not conIsCheatsEnabled
then exit
;
3826 if g_Game_IsClient
then Exit
;
3828 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3829 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3834 if FHealth
< PLAYER_HP_SOFT
then
3836 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3840 if gFlash
= 2 then Inc(FPickup
, 5);
3844 if FHealth
< PLAYER_HP_SOFT
then
3846 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3850 if gFlash
= 2 then Inc(FPickup
, 5);
3854 if FArmor
< PLAYER_AP_SOFT
then
3856 FArmor
:= PLAYER_AP_SOFT
;
3859 if gFlash
= 2 then Inc(FPickup
, 5);
3863 if FArmor
< PLAYER_AP_LIMIT
then
3865 FArmor
:= PLAYER_AP_LIMIT
;
3868 if gFlash
= 2 then Inc(FPickup
, 5);
3872 if FHealth
< PLAYER_HP_LIMIT
then
3874 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3878 if gFlash
= 2 then Inc(FPickup
, 5);
3882 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3884 if FHealth
< PLAYER_HP_LIMIT
then
3885 FHealth
:= PLAYER_HP_LIMIT
;
3886 if FArmor
< PLAYER_AP_LIMIT
then
3887 FArmor
:= PLAYER_AP_LIMIT
;
3891 if gFlash
= 2 then Inc(FPickup
, 5);
3895 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3897 FWeapon
[WEAPON_SAW
] := True;
3899 if gFlash
= 2 then Inc(FPickup
, 5);
3900 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3903 ITEM_WEAPON_SHOTGUN1
:
3904 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3906 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3907 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3909 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3910 FWeapon
[WEAPON_SHOTGUN1
] := True;
3912 if gFlash
= 2 then Inc(FPickup
, 5);
3913 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3916 ITEM_WEAPON_SHOTGUN2
:
3917 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3919 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3921 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3922 FWeapon
[WEAPON_SHOTGUN2
] := True;
3924 if gFlash
= 2 then Inc(FPickup
, 5);
3925 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3928 ITEM_WEAPON_CHAINGUN
:
3929 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3931 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3933 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3934 FWeapon
[WEAPON_CHAINGUN
] := True;
3936 if gFlash
= 2 then Inc(FPickup
, 5);
3937 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3940 ITEM_WEAPON_ROCKETLAUNCHER
:
3941 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3943 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3945 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3946 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3948 if gFlash
= 2 then Inc(FPickup
, 5);
3949 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3953 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3955 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3957 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3958 FWeapon
[WEAPON_PLASMA
] := True;
3960 if gFlash
= 2 then Inc(FPickup
, 5);
3961 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3965 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3967 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3969 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3970 FWeapon
[WEAPON_BFG
] := True;
3972 if gFlash
= 2 then Inc(FPickup
, 5);
3973 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3976 ITEM_WEAPON_SUPERPULEMET
:
3977 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3979 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3981 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3982 FWeapon
[WEAPON_SUPERPULEMET
] := True;
3984 if gFlash
= 2 then Inc(FPickup
, 5);
3985 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3988 ITEM_WEAPON_FLAMETHROWER
:
3989 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
3991 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
3993 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3994 FWeapon
[WEAPON_FLAMETHROWER
] := True;
3996 if gFlash
= 2 then Inc(FPickup
, 5);
3997 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4001 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4003 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4006 if gFlash
= 2 then Inc(FPickup
, 5);
4009 ITEM_AMMO_BULLETS_BOX
:
4010 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4012 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4015 if gFlash
= 2 then Inc(FPickup
, 5);
4019 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4021 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4024 if gFlash
= 2 then Inc(FPickup
, 5);
4027 ITEM_AMMO_SHELLS_BOX
:
4028 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4030 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
4033 if gFlash
= 2 then Inc(FPickup
, 5);
4037 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4039 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4042 if gFlash
= 2 then Inc(FPickup
, 5);
4045 ITEM_AMMO_ROCKET_BOX
:
4046 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4048 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
4051 if gFlash
= 2 then Inc(FPickup
, 5);
4055 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4057 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4060 if gFlash
= 2 then Inc(FPickup
, 5);
4064 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4066 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4069 if gFlash
= 2 then Inc(FPickup
, 5);
4073 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4075 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4078 if gFlash
= 2 then Inc(FPickup
, 5);
4082 if not(R_ITEM_BACKPACK
in FRulez
) or
4083 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4084 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4085 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4086 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4087 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
4089 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4090 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4091 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4092 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4093 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4095 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4096 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4097 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4098 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4099 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4100 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4101 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4102 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4104 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
4107 if gFlash
= 2 then Inc(FPickup
, 5);
4111 if not(R_KEY_RED
in FRulez
) then
4113 Include(FRulez
, R_KEY_RED
);
4115 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4116 if gFlash
= 2 then Inc(FPickup
, 5);
4117 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4121 if not(R_KEY_GREEN
in FRulez
) then
4123 Include(FRulez
, R_KEY_GREEN
);
4125 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4126 if gFlash
= 2 then Inc(FPickup
, 5);
4127 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4131 if not(R_KEY_BLUE
in FRulez
) then
4133 Include(FRulez
, R_KEY_BLUE
);
4135 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4136 if gFlash
= 2 then Inc(FPickup
, 5);
4137 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4141 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4143 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4147 if gFlash
= 2 then Inc(FPickup
, 5);
4151 if FAir
< AIR_MAX
then
4156 if gFlash
= 2 then Inc(FPickup
, 5);
4161 if not (R_BERSERK
in FRulez
) then
4163 Include(FRulez
, R_BERSERK
);
4164 if allowBerserkSwitching
then
4166 FCurrWeap
:= WEAPON_KASTET
;
4168 FModel
.SetWeapon(WEAPON_KASTET
);
4173 if gFlash
= 2 then Inc(FPickup
, 5);
4175 FBerserk
:= gTime
+30000;
4180 if FHealth
< PLAYER_HP_SOFT
then
4182 FHealth
:= PLAYER_HP_SOFT
;
4183 FBerserk
:= gTime
+30000;
4191 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4193 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4196 if gFlash
= 2 then Inc(FPickup
, 5);
4200 if FHealth
< PLAYER_HP_LIMIT
then
4202 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4206 if gFlash
= 2 then Inc(FPickup
, 5);
4210 if FArmor
< PLAYER_AP_LIMIT
then
4212 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4215 if gFlash
= 2 then Inc(FPickup
, 5);
4219 if FJetFuel
< JET_MAX
then
4221 FJetFuel
:= JET_MAX
;
4224 if gFlash
= 2 then Inc(FPickup
, 5);
4228 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4230 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4233 if gFlash
= 2 then Inc(FPickup
, 5);
4238 procedure TPlayer
.Touch();
4242 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4245 // Áðîñèòü ôëàã òîâàðèùó:
4246 if gGameSettings
.GameMode
= GM_CTF
then
4251 procedure TPlayer
.Push(vx
, vy
: Integer);
4253 if (not FPhysics
) and FGhost
then
4255 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4256 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4257 if g_Game_IsNet
and g_Game_IsServer
then
4258 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4261 procedure TPlayer
.Reset(Force
: Boolean);
4267 FTime
[T_RESPAWN
] := 0;
4268 FTime
[T_FLAGCAP
] := 0;
4281 FSpectator
:= False;
4284 FSpectatePlayer
:= -1;
4285 FNoRespawn
:= False;
4287 FLives
:= gGameSettings
.MaxLives
;
4292 procedure TPlayer
.SoftReset();
4298 FBFGFireCounter
:= -1;
4306 SetAction(A_STAND
, True);
4309 function TPlayer
.GetRespawnPoint(): Byte;
4314 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4316 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4317 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4319 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4321 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4322 if Self
= gPlayer1
then
4323 c
:= RESPAWNPOINT_PLAYER1
4325 c
:= RESPAWNPOINT_PLAYER2
;
4326 if g_Map_GetPointCount(c
) > 0 then
4332 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4333 if Self
= gPlayer1
then
4334 c
:= RESPAWNPOINT_PLAYER2
4336 c
:= RESPAWNPOINT_PLAYER1
;
4337 if g_Map_GetPointCount(c
) > 0 then
4344 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4345 if Random(2) = 0 then
4346 c
:= RESPAWNPOINT_PLAYER1
4348 c
:= RESPAWNPOINT_PLAYER2
;
4349 if g_Map_GetPointCount(c
) > 0 then
4356 // Òî÷êà ëþáîé èç êîìàíä
4357 if Random(2) = 0 then
4358 c
:= RESPAWNPOINT_RED
4360 c
:= RESPAWNPOINT_BLUE
;
4361 if g_Map_GetPointCount(c
) > 0 then
4368 c
:= RESPAWNPOINT_DM
;
4369 if g_Map_GetPointCount(c
) > 0 then
4377 if gGameSettings
.GameMode
= GM_DM
then
4380 c
:= RESPAWNPOINT_DM
;
4381 if g_Map_GetPointCount(c
) > 0 then
4387 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4388 if Random(2) = 0 then
4389 c
:= RESPAWNPOINT_PLAYER1
4391 c
:= RESPAWNPOINT_PLAYER2
;
4392 if g_Map_GetPointCount(c
) > 0 then
4398 // Òî÷êà ëþáîé èç êîìàíä
4399 if Random(2) = 0 then
4400 c
:= RESPAWNPOINT_RED
4402 c
:= RESPAWNPOINT_BLUE
;
4403 if g_Map_GetPointCount(c
) > 0 then
4411 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4413 // Òî÷êà ñâîåé êîìàíäû
4414 c
:= RESPAWNPOINT_DM
;
4415 if FTeam
= TEAM_RED
then
4416 c
:= RESPAWNPOINT_RED
;
4417 if FTeam
= TEAM_BLUE
then
4418 c
:= RESPAWNPOINT_BLUE
;
4419 if g_Map_GetPointCount(c
) > 0 then
4426 c
:= RESPAWNPOINT_DM
;
4427 if g_Map_GetPointCount(c
) > 0 then
4433 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4434 if Random(2) = 0 then
4435 c
:= RESPAWNPOINT_PLAYER1
4437 c
:= RESPAWNPOINT_PLAYER2
;
4438 if g_Map_GetPointCount(c
) > 0 then
4444 // Òî÷êà äðóãîé êîìàíäû
4445 c
:= RESPAWNPOINT_DM
;
4446 if FTeam
= TEAM_RED
then
4447 c
:= RESPAWNPOINT_BLUE
;
4448 if FTeam
= TEAM_BLUE
then
4449 c
:= RESPAWNPOINT_RED
;
4450 if g_Map_GetPointCount(c
) > 0 then
4458 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4460 RespawnPoint
: TRespawnPoint
;
4466 FBFGFireCounter
:= -1;
4471 if not g_Game_IsServer
then
4475 FWantsInGame
:= True;
4476 FJustTeleported
:= True;
4479 FTime
[T_RESPAWN
] := 0;
4483 // if server changes MaxLives we gotta be ready
4484 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4486 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4487 if FTime
[T_RESPAWN
] > gTime
then
4490 // Ïðîñðàë âñå æèçíè:
4493 if not FSpectator
then Spectate(True);
4494 FWantsInGame
:= True;
4498 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4499 begin // "Ñâîÿ èãðà"
4500 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4501 FRulez
:= FRulez
-[R_BERSERK
];
4503 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4505 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4506 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4509 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4510 c
:= GetRespawnPoint();
4515 // Âîñêðåøåíèå áåç îðóæèÿ:
4518 FHealth
:= PLAYER_HP_SOFT
;
4524 for a
:= WP_FIRST
to WP_LAST
do
4526 FWeapon
[a
] := False;
4530 FWeapon
[WEAPON_PISTOL
] := True;
4531 FWeapon
[WEAPON_KASTET
] := True;
4532 FCurrWeap
:= WEAPON_PISTOL
;
4535 FModel
.SetWeapon(FCurrWeap
);
4537 for b
:= A_BULLETS
to A_HIGH
do
4540 FAmmo
[A_BULLETS
] := 50;
4542 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4543 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4544 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4545 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4546 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4548 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4549 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4554 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4555 if not g_Map_GetPoint(c
, RespawnPoint
) then
4557 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4561 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4562 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4563 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4569 FDirection
:= RespawnPoint
.Direction
;
4570 if FDirection
= TDirection
.D_LEFT
then
4575 SetAction(A_STAND
, True);
4576 FModel
.Direction
:= FDirection
;
4578 for a
:= Low(FTime
) to High(FTime
) do
4581 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4586 FCanJetpack
:= False;
4591 // Àíèìàöèÿ âîçðîæäåíèÿ:
4592 if (not gLoadGameMode
) and (not Silent
) then
4593 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4595 Anim
:= TAnimation
.Create(ID
, False, 3);
4596 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4597 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4601 FSpectator
:= False;
4604 FSpectatePlayer
:= -1;
4607 if (gPlayer1
= nil) and (gLMSPID1
= FUID
) then
4609 if (gPlayer2
= nil) and (gLMSPID2
= FUID
) then
4612 if g_Game_IsNet
then
4614 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4615 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4617 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4618 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4623 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4626 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4627 else if (not NoMove
) then
4629 GameX
:= gMapInfo
.Width
div 2;
4630 GameY
:= gMapInfo
.Height
div 2;
4639 FWantsInGame
:= False;
4644 if Self
= gPlayer1
then
4649 if Self
= gPlayer2
then
4656 if g_Game_IsNet
then
4657 MH_SEND_PlayerStats(FUID
);
4660 procedure TPlayer
.SwitchNoClip
;
4664 FGhost
:= not FGhost
;
4665 FPhysics
:= not FGhost
;
4677 procedure TPlayer
.Run(Direction
: TDirection
);
4681 if MAX_RUNVEL
> 8 then
4685 if Direction
= TDirection
.D_LEFT
then
4687 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4688 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4691 if FObj
.Vel
.X
< MAX_RUNVEL
then
4692 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4694 // Âîçìîæíî, ïèíàåì êóñêè:
4695 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4697 b
:= Abs(FObj
.Vel
.X
);
4698 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4699 for a
:= 0 to High(gGibs
) do
4701 if gGibs
[a
].alive
and
4702 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4703 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4706 if FObj
.Vel
.X
< 0 then
4708 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4712 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4714 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4722 procedure TPlayer
.SeeDown();
4724 SetAction(A_SEEDOWN
);
4726 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4728 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4731 procedure TPlayer
.SeeUp();
4735 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4737 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4740 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4748 A_ATTACK
: Prior
:= 2;
4749 A_SEEUP
: Prior
:= 1;
4750 A_SEEDOWN
: Prior
:= 1;
4751 A_ATTACKUP
: Prior
:= 2;
4752 A_ATTACKDOWN
: Prior
:= 2;
4757 if (Prior
> FActionPrior
) or Force
then
4758 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4760 FActionPrior
:= Prior
;
4761 FActionAnim
:= Action
;
4762 FActionForce
:= Force
;
4763 FActionChanged
:= True;
4766 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4769 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4771 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4772 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4773 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4774 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4777 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4784 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4786 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4787 if g_Game_IsServer
and g_Game_IsNet
then
4788 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4792 FJustTeleported
:= True;
4797 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4799 Anim
:= TAnimation
.Create(ID
, False, 3);
4802 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4803 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4804 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4805 if g_Game_IsServer
and g_Game_IsNet
then
4806 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4807 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4811 FObj
.X
:= X
-PLAYER_RECT
.X
;
4812 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4813 if FAlive
and FGhost
then
4819 if not g_Game_IsNet
then
4823 SetDirection(TDirection
.D_LEFT
);
4829 SetDirection(TDirection
.D_RIGHT
);
4835 if FDirection
= TDirection
.D_RIGHT
then
4837 SetDirection(TDirection
.D_LEFT
);
4842 SetDirection(TDirection
.D_RIGHT
);
4848 if not silent
and (Anim
<> nil) then
4850 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4851 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4854 if g_Game_IsServer
and g_Game_IsNet
then
4855 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4856 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4863 function nonz(a
: Single): Single;
4871 function TPlayer
.followCorpse(): Boolean;
4876 if FAlive
or FSpectator
then
4878 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
4880 for i
:= 0 to High(gCorpses
) do
4881 if gCorpses
[i
] <> nil then
4882 if gCorpses
[i
].FPlayerUID
= FUID
then
4885 FObj
.X
:= gCorpses
[i
].FObj
.X
;
4886 FObj
.Y
:= gCorpses
[i
].FObj
.Y
;
4887 FObj
.Vel
.X
:= gCorpses
[i
].FObj
.Vel
.X
;
4888 FObj
.Vel
.Y
:= gCorpses
[i
].FObj
.Vel
.Y
;
4889 FObj
.Accel
.X
:= gCorpses
[i
].FObj
.Accel
.X
;
4890 FObj
.Accel
.Y
:= gCorpses
[i
].FObj
.Accel
.Y
;
4895 procedure TPlayer
.Update();
4898 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4899 blockmon
, headwater
, dospawn
: Boolean;
4904 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4905 AnyServer
:= g_Game_IsServer
;
4907 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4908 DoLerp(NetInterpLevel
+ 1)
4914 if FClientID
>= 0 then
4916 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4917 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4918 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4927 if FAlive
and (FPunchAnim
<> nil) then
4928 FPunchAnim
.Update();
4930 if FAlive
and (gFly
or FJetpack
) then
4933 if FDirection
= TDirection
.D_LEFT
then
4938 if FAlive
and (not FGhost
) then
4940 if FKeys
[KEY_UP
].Pressed
then
4942 if FKeys
[KEY_DOWN
].Pressed
then
4946 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4949 i
:= g_basic
.Sign(FIncCam
);
4950 FIncCam
:= Abs(FIncCam
);
4951 DecMin(FIncCam
, 5, 0);
4952 FIncCam
:= FIncCam
*i
;
4955 // no need to do that each second frame, weapon queue will take care of it
4956 if FAlive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4957 if FAlive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4959 if gTime
mod (GAME_TICK
*2) <> 0 then
4961 if (FObj
.Vel
.X
= 0) and FAlive
then
4963 if FKeys
[KEY_LEFT
].Pressed
then
4964 Run(TDirection
.D_LEFT
);
4965 if FKeys
[KEY_RIGHT
].Pressed
then
4966 Run(TDirection
.D_RIGHT
);
4971 if not followCorpse() then
4972 g_Obj_Move(@FObj
, True, True, True);
4973 positionChanged(); // this updates spatial accelerators
4979 FActionChanged
:= False;
4983 // Let alive player do some actions
4984 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
4985 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
4986 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
4987 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
4988 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
4989 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
4990 if FKeys
[KEY_JUMP
].Pressed
then Jump()
4993 if AnyServer
and FJetpack
then
4997 if NetServer
then MH_SEND_PlayerStats(FUID
);
4999 FCanJetpack
:= True;
5006 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
5008 if FKeys
[k
].Pressed
then
5016 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5019 if (FTime
[T_RESPAWN
] <= gTime
) and
5020 gGameOn
and (not FAlive
) then
5022 if (g_Player_GetCount() > 1) then
5026 gExit
:= EXIT_RESTART
;
5031 // Dead spectator actions
5034 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
5035 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
5039 if (FSpectatePlayer
>= High(gPlayers
)) then
5040 FSpectatePlayer
:= -1
5044 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
5045 if gPlayers
[I
] <> nil then
5046 if gPlayers
[I
].alive
then
5047 if gPlayers
[I
].UID
<> FUID
then
5049 FSpectatePlayer
:= I
;
5054 if not SetSpect
then FSpectatePlayer
:= -1;
5065 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5067 FYTo
:= FObj
.Y
- 32;
5068 FSpectatePlayer
:= -1;
5070 if FKeys
[KEY_DOWN
].Pressed
then
5072 FYTo
:= FObj
.Y
+ 32;
5073 FSpectatePlayer
:= -1;
5075 if FKeys
[KEY_LEFT
].Pressed
then
5077 FXTo
:= FObj
.X
- 32;
5078 FSpectatePlayer
:= -1;
5080 if FKeys
[KEY_RIGHT
].Pressed
then
5082 FXTo
:= FObj
.X
+ 32;
5083 FSpectatePlayer
:= -1;
5086 if (FXTo
< -64) then
5088 else if (FXTo
> gMapInfo
.Width
+ 32) then
5089 FXTo
:= gMapInfo
.Width
+ 32;
5090 if (FYTo
< -72) then
5092 else if (FYTo
> gMapInfo
.Height
+ 32) then
5093 FYTo
:= gMapInfo
.Height
+ 32;
5098 if not followCorpse() then
5099 g_Obj_Move(@FObj
, True, True, True);
5100 positionChanged(); // this updates spatial accelerators
5107 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5108 if gPlayers
[FSpectatePlayer
] <> nil then
5109 if gPlayers
[FSpectatePlayer
].alive
then
5111 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
5112 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
5116 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5117 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5118 PANEL_BLOCKMON
, True);
5119 headwater
:= HeadInLiquid(0, 0);
5121 // Ñîïðîòèâëåíèå âîçäóõà:
5122 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5123 if FObj
.Vel
.X
<> 0 then
5124 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5126 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5127 DecMin(FPain
, 5, 0);
5128 DecMin(FPickup
, 1, 0);
5130 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5132 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5133 FMegaRulez
[MR_SUIT
] := 0;
5134 FMegaRulez
[MR_INVUL
] := 0;
5135 FMegaRulez
[MR_INVIS
] := 0;
5136 Kill(K_FALLKILL
, 0, HIT_FALL
);
5143 if FCurrWeap
= WEAPON_SAW
then
5144 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5145 FSawSoundSelect
.IsPlaying()) then
5146 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5149 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5150 (not FJetSoundOff
.IsPlaying()) then
5152 FJetSoundFly
.SetPosition(0);
5153 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5156 for b
:= WP_FIRST
to WP_LAST
do
5157 if FReloading
[b
] > 0 then
5163 if FShellTimer
> -1 then
5164 if FShellTimer
= 0 then
5166 if FShellType
= SHELL_SHELL
then
5167 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5168 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5169 else if FShellType
= SHELL_DBLSHELL
then
5171 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5172 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5173 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5174 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5177 end else Dec(FShellTimer
);
5179 if (FBFGFireCounter
> -1) then
5180 if FBFGFireCounter
= 0 then
5184 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5185 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5186 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5187 yd
:= wy
+firediry();
5188 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5189 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5190 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5191 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5192 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5195 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5196 FBFGFireCounter
:= -1;
5199 FBFGFireCounter
:= 0
5201 Dec(FBFGFireCounter
);
5203 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5205 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5207 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5210 if (headwater
or blockmon
) then
5216 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5219 else if (FAir
mod 31 = 0) and not blockmon
then
5221 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5222 if Random(2) = 0 then
5223 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5225 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5227 end else if FAir
< AIR_DEF
then
5230 if FFireTime
> 0 then
5232 if BodyInLiquid(0, 0) then
5237 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5239 if FMegaRulez
[MR_SUIT
] = gTime
then
5246 if FFirePainTime
<= 0 then
5248 if g_Game_IsServer
then
5249 Damage(5, FFireAttacker
, 0, 0, HIT_FLAME
);
5250 FFirePainTime
:= 18;
5252 FFirePainTime
:= FFirePainTime
- 1;
5253 FFireTime
:= FFireTime
- 1;
5254 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5255 MH_SEND_PlayerStats(FUID
);
5259 if FDamageBuffer
> 0 then
5261 if FDamageBuffer
>= 9 then
5265 if FDamageBuffer
< 30 then i
:= 9
5266 else if FDamageBuffer
< 100 then i
:= 18
5270 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5271 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5272 FHealth
:= FHealth
-ii
;
5275 FHealth
:= FHealth
+FArmor
;
5280 if FHealth
<= 0 then
5281 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5282 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5283 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5287 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5288 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5289 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5290 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5297 end; // if FAlive then ...
5299 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5301 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5302 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5303 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5304 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5306 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5307 then SetAction(A_STAND
, True);
5309 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5311 for b
:= Low(FKeys
) to High(FKeys
) do
5312 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5316 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5318 x
:= FObj
.X
+PLAYER_RECT
.X
;
5319 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5320 w
:= PLAYER_RECT
.Width
;
5321 h
:= PLAYER_RECT
.Height
;
5325 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5327 if (dx
<> 0) or (dy
<> 0) then
5336 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5338 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5339 FObj
.Y
+PLAYER_RECT
.Y
,
5346 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5348 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5349 FObj
.Y
+PLAYER_RECT
.Y
,
5353 Panel
.Width
, Panel
.Height
);
5356 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5358 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5359 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5360 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5361 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5364 function g_Player_ValidName(Name
: string): Boolean;
5370 if gPlayers
= nil then Exit
;
5372 for a
:= 0 to High(gPlayers
) do
5373 if gPlayers
[a
] <> nil then
5374 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5381 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5385 d
:= FModel
.Direction
;
5387 FModel
.Direction
:= Direction
;
5388 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5390 FDirection
:= Direction
;
5393 function TPlayer
.GetKeys(): Byte;
5397 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5398 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5399 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5401 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5402 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5405 procedure TPlayer
.Use();
5409 if FTime
[T_USE
] > gTime
then Exit
;
5411 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5412 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5414 for a
:= 0 to High(gPlayers
) do
5415 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5416 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5417 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5418 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5420 gPlayers
[a
].Touch();
5421 if g_Game_IsNet
and g_Game_IsServer
then
5422 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5425 FTime
[T_USE
] := gTime
+120;
5428 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5432 WX
, WY
, XD
, YD
: Integer;
5444 if R_BERSERK
in FRulez
then
5446 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5447 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5448 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5451 locobj
.rect
.Width
:= 39;
5452 locobj
.rect
.Height
:= 52;
5453 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5454 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5455 locobj
.Accel
.X
:= xd
-wx
;
5456 locobj
.Accel
.y
:= yd
-wy
;
5458 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5459 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5461 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5465 FPain
:= min(FPain
+ 25, 50);
5467 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5472 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5473 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5475 FSawSoundSelect
.Stop();
5477 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5479 else if not FSawSoundHit
.IsPlaying() then
5481 FSawSoundSelect
.Stop();
5482 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5489 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5490 FFireAngle
:= FAngle
;
5492 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5493 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5498 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5499 FFireAngle
:= FAngle
;
5502 FShellType
:= SHELL_SHELL
;
5507 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5508 FFireAngle
:= FAngle
;
5511 FShellType
:= SHELL_DBLSHELL
;
5516 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5517 FFireAngle
:= FAngle
;
5519 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5520 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5523 WEAPON_ROCKETLAUNCHER
:
5525 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5526 FFireAngle
:= FAngle
;
5532 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5533 FFireAngle
:= FAngle
;
5539 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5540 FFireAngle
:= FAngle
;
5544 WEAPON_SUPERPULEMET
:
5546 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5547 FFireAngle
:= FAngle
;
5549 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5550 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5553 WEAPON_FLAMETHROWER
:
5555 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5556 FFireAngle
:= FAngle
;
5563 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5564 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5565 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5568 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5570 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5571 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5574 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5578 if NetInterpLevel
< 1 then
5588 AX
:= Abs(FXTo
- FObj
.X
);
5589 AY
:= Abs(FYTo
- FObj
.Y
);
5590 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5592 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5597 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5599 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5600 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5601 PANEL_LIFTUP
, False) then Result
:= -1
5603 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5604 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5605 PANEL_LIFTDOWN
, False) then Result
:= 1
5609 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5616 if Flag
= FLAG_NONE
then
5619 if not g_Game_IsServer
then Exit
;
5621 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5622 if (Flag
= FTeam
) and
5623 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5624 (FFlag
<> FLAG_NONE
) then
5626 if FFlag
= FLAG_RED
then
5627 s
:= _lc
[I_PLAYER_FLAG_RED
]
5629 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5631 evtype
:= FLAG_STATE_SCORED
;
5633 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5634 Insert('.', ts
, Length(ts
) + 1 - 3);
5635 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5637 g_Map_ResetFlag(FFlag
);
5638 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5640 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5643 if g_Game_IsNet
then
5645 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5649 gFlags
[FFlag
].CaptureTime
:= 0;
5654 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5655 if (Flag
= FTeam
) and
5656 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5658 if Flag
= FLAG_RED
then
5659 s
:= _lc
[I_PLAYER_FLAG_RED
]
5661 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5663 evtype
:= FLAG_STATE_RETURNED
;
5664 gFlags
[Flag
].CaptureTime
:= 0;
5666 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5668 g_Map_ResetFlag(Flag
);
5669 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5672 if g_Game_IsNet
then
5674 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5680 // Ïîäîáðàë ÷óæîé ôëàã:
5681 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5685 if Flag
= FLAG_RED
then
5686 s
:= _lc
[I_PLAYER_FLAG_RED
]
5688 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5690 evtype
:= FLAG_STATE_CAPTURED
;
5692 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5694 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5696 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5699 if g_Game_IsNet
then
5701 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5707 procedure TPlayer
.SetFlag(Flag
: Byte);
5710 if FModel
<> nil then
5711 FModel
.SetFlag(FFlag
);
5714 function TPlayer
.DropFlag(): Boolean;
5719 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5721 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5722 with gFlags
[FFlag
] do
5726 Direction
:= FDirection
;
5727 State
:= FLAG_STATE_DROPPED
;
5729 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5730 (FObj
.Vel
.Y
div 2)-2+Random(5));
5731 positionChanged(); // this updates spatial accelerators
5733 if FFlag
= FLAG_RED
then
5734 s
:= _lc
[I_PLAYER_FLAG_RED
]
5736 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5738 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5739 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5741 if g_Game_IsNet
then
5742 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5748 procedure TPlayer
.GetSecret();
5753 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5755 Assert(Key
<= High(FKeys
));
5757 FKeys
[Key
].Pressed
:= True;
5758 FKeys
[Key
].Time
:= Time
;
5761 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5763 Result
:= FKeys
[K
].Pressed
;
5766 procedure TPlayer
.ReleaseKeys();
5770 for a
:= Low(FKeys
) to High(FKeys
) do
5772 FKeys
[a
].Pressed
:= False;
5777 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5781 function TPlayer
.firediry(): Integer;
5783 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5784 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5788 procedure TPlayer
.RememberState();
5792 FSavedState
.Health
:= FHealth
;
5793 FSavedState
.Armor
:= FArmor
;
5794 FSavedState
.Air
:= FAir
;
5795 FSavedState
.JetFuel
:= FJetFuel
;
5796 FSavedState
.CurrWeap
:= FCurrWeap
;
5797 FSavedState
.NextWeap
:= FNextWeap
;
5798 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5801 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5803 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5805 FSavedState
.Rulez
:= FRulez
;
5806 FSavedState
.WaitRecall
:= True;
5809 procedure TPlayer
.RecallState();
5813 if not FSavedState
.WaitRecall
then Exit
;
5815 FHealth
:= FSavedState
.Health
;
5816 FArmor
:= FSavedState
.Armor
;
5817 FAir
:= FSavedState
.Air
;
5818 FJetFuel
:= FSavedState
.JetFuel
;
5819 FCurrWeap
:= FSavedState
.CurrWeap
;
5820 FNextWeap
:= FSavedState
.NextWeap
;
5821 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5824 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5826 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5828 FRulez
:= FSavedState
.Rulez
;
5829 FSavedState
.WaitRecall
:= False;
5831 if gGameSettings
.GameType
= GT_SERVER
then
5832 MH_SEND_PlayerStats(FUID
);
5835 procedure TPlayer
.SaveState (st
: TStream
);
5841 utils
.writeSign(st
, 'PLYR');
5842 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
5844 utils
.writeBool(st
, FIamBot
);
5846 utils
.writeInt(st
, Word(FUID
));
5848 utils
.writeStr(st
, FName
);
5850 utils
.writeInt(st
, Byte(FTeam
));
5852 utils
.writeBool(st
, FAlive
);
5853 // Èçðàñõîäîâàë ëè âñå æèçíè
5854 utils
.writeBool(st
, FNoRespawn
);
5856 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
5857 utils
.writeInt(st
, Byte(b
));
5859 utils
.writeInt(st
, LongInt(FHealth
));
5861 utils
.writeInt(st
, Byte(FLives
));
5863 utils
.writeInt(st
, LongInt(FArmor
));
5865 utils
.writeInt(st
, LongInt(FAir
));
5867 utils
.writeInt(st
, LongInt(FJetFuel
));
5869 utils
.writeInt(st
, LongInt(FPain
));
5871 utils
.writeInt(st
, LongInt(FKills
));
5873 utils
.writeInt(st
, LongInt(FMonsterKills
));
5875 utils
.writeInt(st
, LongInt(FFrags
));
5877 utils
.writeInt(st
, Byte(FFragCombo
));
5878 // Âðåìÿ ïîñëåäíåãî ôðàãà
5879 utils
.writeInt(st
, LongWord(FLastFrag
));
5881 utils
.writeInt(st
, LongInt(FDeath
));
5883 utils
.writeInt(st
, Byte(FFlag
));
5885 utils
.writeInt(st
, LongInt(FSecrets
));
5887 utils
.writeInt(st
, Byte(FCurrWeap
));
5889 utils
.writeInt(st
, Word(FNextWeap
));
5891 utils
.writeInt(st
, Byte(FNextWeapDelay
));
5892 // Âðåìÿ çàðÿäêè BFG
5893 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
5895 utils
.writeInt(st
, LongInt(FDamageBuffer
));
5896 // Ïîñëåäíèé óäàðèâøèé
5897 utils
.writeInt(st
, Word(FLastSpawnerUID
));
5898 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
5899 utils
.writeInt(st
, Byte(FLastHit
));
5901 Obj_SaveState(st
, @FObj
);
5902 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
5903 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
5904 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
5905 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
5907 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
5908 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
5909 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
5911 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
5912 // Íàëè÷èå êðàñíîãî êëþ÷à
5913 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
5914 // Íàëè÷èå çåëåíîãî êëþ÷à
5915 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
5916 // Íàëè÷èå ñèíåãî êëþ÷à
5917 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
5919 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
5920 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
5921 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
5922 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
5923 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
5925 utils
.writeStr(st
, FModel
.Name
);
5927 utils
.writeInt(st
, Byte(FColor
.R
));
5928 utils
.writeInt(st
, Byte(FColor
.G
));
5929 utils
.writeInt(st
, Byte(FColor
.B
));
5933 procedure TPlayer
.LoadState (st
: TStream
);
5942 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
5943 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
5945 FIamBot
:= utils
.readBool(st
);
5947 FUID
:= utils
.readWord(st
);
5949 str
:= utils
.readStr(st
);
5950 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
5952 FTeam
:= utils
.readByte(st
);
5954 FAlive
:= utils
.readBool(st
);
5955 // Èçðàñõîäîâàë ëè âñå æèçíè
5956 FNoRespawn
:= utils
.readBool(st
);
5958 b
:= utils
.readByte(st
);
5959 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
5961 FHealth
:= utils
.readLongInt(st
);
5963 FLives
:= utils
.readByte(st
);
5965 FArmor
:= utils
.readLongInt(st
);
5967 FAir
:= utils
.readLongInt(st
);
5969 FJetFuel
:= utils
.readLongInt(st
);
5971 FPain
:= utils
.readLongInt(st
);
5973 FKills
:= utils
.readLongInt(st
);
5975 FMonsterKills
:= utils
.readLongInt(st
);
5977 FFrags
:= utils
.readLongInt(st
);
5979 FFragCombo
:= utils
.readByte(st
);
5980 // Âðåìÿ ïîñëåäíåãî ôðàãà
5981 FLastFrag
:= utils
.readLongWord(st
);
5983 FDeath
:= utils
.readLongInt(st
);
5985 FFlag
:= utils
.readByte(st
);
5987 FSecrets
:= utils
.readLongInt(st
);
5989 FCurrWeap
:= utils
.readByte(st
);
5991 FNextWeap
:= utils
.readWord(st
);
5993 FNextWeapDelay
:= utils
.readByte(st
);
5994 // Âðåìÿ çàðÿäêè BFG
5995 FBFGFireCounter
:= utils
.readSmallInt(st
);
5997 FDamageBuffer
:= utils
.readLongInt(st
);
5998 // Ïîñëåäíèé óäàðèâøèé
5999 FLastSpawnerUID
:= utils
.readWord(st
);
6000 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6001 FLastHit
:= utils
.readByte(st
);
6003 Obj_LoadState(@FObj
, st
);
6004 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6005 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
6006 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6007 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
6009 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
6010 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6011 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
6013 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
6014 // Íàëè÷èå êðàñíîãî êëþ÷à
6015 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
6016 // Íàëè÷èå çåëåíîãî êëþ÷à
6017 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
6018 // Íàëè÷èå ñèíåãî êëþ÷à
6019 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
6021 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
6022 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6023 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
6024 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6025 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
6027 str
:= utils
.readStr(st
);
6029 FColor
.R
:= utils
.readByte(st
);
6030 FColor
.G
:= utils
.readByte(st
);
6031 FColor
.B
:= utils
.readByte(st
);
6032 if (self
= gPlayer1
) then
6034 str
:= gPlayer1Settings
.Model
;
6035 FColor
:= gPlayer1Settings
.Color
;
6037 else if (self
= gPlayer2
) then
6039 str
:= gPlayer2Settings
.Model
;
6040 FColor
:= gPlayer2Settings
.Color
;
6042 // Îáíîâëÿåì ìîäåëü èãðîêà
6044 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
6045 FModel
.Color
:= TEAMCOLOR
[FTeam
]
6047 FModel
.Color
:= FColor
;
6051 procedure TPlayer
.AllRulez(Health
: Boolean);
6057 FHealth
:= PLAYER_HP_LIMIT
;
6058 FArmor
:= PLAYER_AP_LIMIT
;
6062 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
6063 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
6064 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6067 procedure TPlayer
.RestoreHealthArmor();
6069 FHealth
:= PLAYER_HP_LIMIT
;
6070 FArmor
:= PLAYER_AP_LIMIT
;
6073 procedure TPlayer
.FragCombo();
6077 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6079 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6081 if FFragCombo
< 5 then
6083 Param
:= FUID
or (FFragCombo
shl 16);
6084 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6085 (FComboEvnt
<= High(gDelayedEvents
)) and
6086 gDelayedEvents
[FComboEvnt
].Pending
and
6087 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6088 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6090 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6091 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6094 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6102 procedure TPlayer
.GiveItem(ItemType
: Byte);
6106 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6108 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6112 if FAir
< AIR_MAX
then
6119 if not (R_BERSERK
in FRulez
) then
6121 Include(FRulez
, R_BERSERK
);
6122 if FBFGFireCounter
< 1 then
6124 FCurrWeap
:= WEAPON_KASTET
;
6126 FModel
.SetWeapon(WEAPON_KASTET
);
6130 FBerserk
:= gTime
+30000;
6132 if FHealth
< PLAYER_HP_SOFT
then
6134 FHealth
:= PLAYER_HP_SOFT
;
6135 FBerserk
:= gTime
+30000;
6140 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6142 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6146 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6148 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6152 if FJetFuel
< JET_MAX
then
6154 FJetFuel
:= JET_MAX
;
6157 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6158 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6160 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6161 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6163 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6165 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6167 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6168 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6171 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6172 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6173 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6174 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6175 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6176 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6177 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6178 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6179 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6181 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6182 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6183 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6184 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6185 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6186 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6187 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6188 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6189 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6192 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6193 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6194 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6195 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6196 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6198 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6199 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6200 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6201 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6202 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6204 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6205 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6206 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6207 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6209 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6212 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6213 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6214 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6216 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6217 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6222 if g_Game_IsNet
and g_Game_IsServer
then
6223 MH_SEND_PlayerStats(FUID
);
6226 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6231 if (Random(5) = 1) and (Times
= 1) then
6234 if BodyInLiquid(0, 0) then
6236 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6237 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6238 if Random(2) = 0 then
6239 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6241 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6245 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6247 for i
:= 1 to Times
do
6249 Anim
:= TAnimation
.Create(id
, False, 3);
6251 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6252 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6258 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6263 if (Random(10) = 1) and (Times
= 1) then
6266 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6268 for i
:= 1 to Times
do
6270 Anim
:= TAnimation
.Create(id
, False, 3);
6272 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6273 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6279 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6281 FSawSound
.Pause(Enable
);
6282 FSawSoundIdle
.Pause(Enable
);
6283 FSawSoundHit
.Pause(Enable
);
6284 FSawSoundSelect
.Pause(Enable
);
6289 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6294 FObj
.Rect
:= PLAYER_CORPSERECT
;
6295 FModelName
:= ModelName
;
6300 FState
:= CORPSE_STATE_MESS
;
6301 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6305 FState
:= CORPSE_STATE_NORMAL
;
6306 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6310 destructor TCorpse
.Destroy();
6317 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6319 procedure TCorpse
.positionChanged (); inline; begin end;
6321 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6323 if (dx
<> 0) or (dy
<> 0) then
6332 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6334 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6335 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6336 w
:= PLAYER_CORPSERECT
.Width
;
6337 h
:= PLAYER_CORPSERECT
.Height
;
6341 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6346 if FState
= CORPSE_STATE_REMOVEME
then
6349 FDamage
:= FDamage
+ Value
;
6351 if FDamage
> 150 then
6353 if FAnimation
<> nil then
6358 FState
:= CORPSE_STATE_REMOVEME
;
6360 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6361 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6362 FModelName
, FColor
);
6363 // Çâóê ìÿñà îò òðóïà:
6364 pm
:= g_PlayerModel_Get(FModelName
);
6365 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6369 if (gBodyKillEvent
<> -1)
6370 and gDelayedEvents
[gBodyKillEvent
].Pending
then
6371 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
6372 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, 0);
6377 Blood
:= g_PlayerModel_GetBlood(FModelName
);
6378 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6379 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6380 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6381 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6382 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6383 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
6387 procedure TCorpse
.Draw();
6389 if FState
= CORPSE_STATE_REMOVEME
then
6392 if FAnimation
<> nil then
6393 FAnimation
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6395 if FAnimationMask
<> nil then
6398 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6405 procedure TCorpse
.Update();
6409 if FState
= CORPSE_STATE_REMOVEME
then
6412 if gTime
mod (GAME_TICK
*2) <> 0 then
6414 g_Obj_Move(@FObj
, True, True, True);
6415 positionChanged(); // this updates spatial accelerators
6419 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6420 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6422 st
:= g_Obj_Move(@FObj
, True, True, True);
6423 positionChanged(); // this updates spatial accelerators
6425 if WordBool(st
and MOVE_FALLOUT
) then
6427 FState
:= CORPSE_STATE_REMOVEME
;
6431 if FAnimation
<> nil then
6432 FAnimation
.Update();
6433 if FAnimationMask
<> nil then
6434 FAnimationMask
.Update();
6438 procedure TCorpse
.SaveState (st
: TStream
);
6445 utils
.writeSign(st
, 'CORP');
6446 utils
.writeInt(st
, Byte(0));
6448 utils
.writeInt(st
, Byte(FState
));
6450 utils
.writeInt(st
, Byte(FDamage
));
6452 utils
.writeInt(st
, Byte(FColor
.R
));
6453 utils
.writeInt(st
, Byte(FColor
.G
));
6454 utils
.writeInt(st
, Byte(FColor
.B
));
6456 Obj_SaveState(st
, @FObj
);
6457 utils
.writeInt(st
, Word(FPlayerUID
));
6459 anim
:= (FAnimation
<> nil);
6460 utils
.writeBool(st
, anim
);
6461 // Åñëè åñòü - ñîõðàíÿåì
6462 if anim
then FAnimation
.SaveState(st
);
6463 // Åñòü ëè ìàñêà àíèìàöèè
6464 anim
:= (FAnimationMask
<> nil);
6465 utils
.writeBool(st
, anim
);
6466 // Åñëè åñòü - ñîõðàíÿåì
6467 if anim
then FAnimationMask
.SaveState(st
);
6471 procedure TCorpse
.LoadState (st
: TStream
);
6478 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6479 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6481 FState
:= utils
.readByte(st
);
6483 FDamage
:= utils
.readByte(st
);
6485 FColor
.R
:= utils
.readByte(st
);
6486 FColor
.G
:= utils
.readByte(st
);
6487 FColor
.B
:= utils
.readByte(st
);
6489 Obj_LoadState(@FObj
, st
);
6490 FPlayerUID
:= utils
.readWord(st
);
6492 anim
:= utils
.readBool(st
);
6493 // Åñëè åñòü - çàãðóæàåì
6496 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6497 FAnimation
.LoadState(st
);
6499 // Åñòü ëè ìàñêà àíèìàöèè
6500 anim
:= utils
.readBool(st
);
6501 // Åñëè åñòü - çàãðóæàåì
6504 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6505 FAnimationMask
.LoadState(st
);
6511 constructor TBot
.Create();
6518 FSpectator
:= False;
6525 for a
:= WP_FIRST
to WP_LAST
do
6527 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6528 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6529 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6533 destructor TBot
.Destroy();
6536 inherited Destroy();
6539 procedure TBot
.Draw();
6543 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6544 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6547 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6549 inherited Respawn(Silent
, Force
);
6552 FSelectedWeapon
:= FCurrWeap
;
6557 procedure TBot
.UpdateCombat();
6570 TTargetRecord
= array of TTarget
;
6572 function Compare(a
, b
: TTarget
): Integer;
6574 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6577 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6579 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6580 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6582 if a
.Dist
> b
.Dist
then // B áëèæå
6584 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6587 else // Ñòðàííî -> A
6592 a
, x1
, y1
, x2
, y2
: Integer;
6593 targets
: TTargetRecord
;
6595 Target
, BestTarget
: TTarget
;
6596 firew
, fireh
: Integer;
6600 vsPlayer
, vsMonster
, ok
: Boolean;
6603 function monsUpdate (mon
: TMonster
): Boolean;
6605 result
:= false; // don't stop
6606 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6608 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6610 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6611 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6613 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6614 if g_TraceVector(x1
, y1
, x2
, y2
) then
6616 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6617 SetLength(targets
, Length(targets
)+1);
6618 with targets
[High(targets
)] do
6625 Rect
:= mon
.Obj
.Rect
;
6626 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6627 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6628 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6637 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6638 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6640 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6641 if FCurrWeap
<> FSelectedWeapon
then
6644 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6645 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6647 RemoveAIFlag('NEEDFIRE');
6650 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6651 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6652 else PressKey(KEY_FIRE
);
6656 // Êîîðäèíàòû ñòâîëà:
6657 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6658 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6660 Target
.UID
:= FTargetUID
;
6663 if Target
.UID
<> 0 then
6664 begin // Öåëü åñòü - íàñòðàèâàåì
6665 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6668 tpla
:= g_Player_Get(Target
.UID
);
6672 if (@FObj
) <> nil then
6679 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6680 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6681 Target
.Rect
:= PLAYER_RECT
;
6682 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6683 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6684 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6685 Target
.IsPlayer
:= True;
6689 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6692 mon
:= g_Monsters_ByUID(Target
.UID
);
6695 Target
.X
:= mon
.Obj
.X
;
6696 Target
.Y
:= mon
.Obj
.Y
;
6698 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6699 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6700 Target
.Rect
:= mon
.Obj
.Rect
;
6701 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6702 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6703 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6704 Target
.IsPlayer
:= False;
6711 begin // Öåëè íåò - îáíóëÿåì
6716 Target
.Visible
:= False;
6717 Target
.Line
:= False;
6718 Target
.IsPlayer
:= False;
6723 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6724 if (not Target
.Line
) or (not Target
.Visible
) then
6728 for a
:= 0 to High(gPlayers
) do
6729 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6730 (gPlayers
[a
].FUID
<> FUID
) and
6731 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6732 (not gPlayers
[a
].NoTarget
) and
6733 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6735 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6736 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6739 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6740 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6742 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6743 if g_TraceVector(x1
, y1
, x2
, y2
) then
6745 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6746 SetLength(targets
, Length(targets
)+1);
6747 with targets
[High(targets
)] do
6749 UID
:= gPlayers
[a
].FUID
;
6750 X
:= gPlayers
[a
].FObj
.X
;
6751 Y
:= gPlayers
[a
].FObj
.Y
;
6754 Rect
:= PLAYER_RECT
;
6755 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6756 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6757 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6765 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6768 // Åñëè åñòü âîçìîæíûå öåëè:
6769 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6770 if targets
<> nil then
6772 // Âûáèðàåì íàèëó÷øóþ öåëü:
6773 BestTarget
:= targets
[0];
6774 if Length(targets
) > 1 then
6775 for a
:= 1 to High(targets
) do
6776 if Compare(BestTarget
, targets
[a
]) = 1 then
6777 BestTarget
:= targets
[a
];
6779 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6780 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6781 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6783 Target
:= BestTarget
;
6785 if (Healthy() = 3) or ((Healthy() = 2)) then
6786 begin // Åñëè çäîðîâû - äîãîíÿåì
6787 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6788 SetAIFlag('GORIGHT', '1');
6789 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6790 SetAIFlag('GOLEFT', '1');
6793 begin // Åñëè ïîáèòû - óáåãàåì
6794 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6795 SetAIFlag('GORIGHT', '1');
6796 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6797 SetAIFlag('GOLEFT', '1');
6800 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6801 SelectWeapon(Abs(x1
-Target
.cX
));
6806 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6807 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6808 if Target
.UID
<> 0 then
6810 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6811 Target
.Y
+ Target
.Rect
.Y
) then
6812 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6813 if (Healthy() = 3) or ((Healthy() = 2)) then
6814 begin // Åñëè çäîðîâû - äîãîíÿåì
6815 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6816 SetAIFlag('GORIGHT', '1');
6817 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6818 SetAIFlag('GOLEFT', '1');
6821 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6823 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6824 SetAIFlag('GORIGHT', '1');
6825 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6826 SetAIFlag('GOLEFT', '1');
6830 begin // Öåëü ïîêà íà "ýêðàíå"
6831 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6832 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6833 FLastVisible
:= gTime
;
6834 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6835 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6837 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6838 SetAIFlag('GORIGHT', '1');
6839 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6840 SetAIFlag('GOLEFT', '1');
6844 // Âûáèðàåì óãîë ââåðõ:
6845 if FDirection
= TDirection
.D_LEFT
then
6846 angle
:= ANGLE_LEFTUP
6848 angle
:= ANGLE_RIGHTUP
;
6850 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6851 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6853 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6854 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6855 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6856 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6857 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6858 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6859 begin // òî íóæíî ñòðåëÿòü ââåðõ
6860 SetAIFlag('NEEDFIRE', '1');
6861 SetAIFlag('NEEDSEEUP', '1');
6864 // Âûáèðàåì óãîë âíèç:
6865 if FDirection
= TDirection
.D_LEFT
then
6866 angle
:= ANGLE_LEFTDOWN
6868 angle
:= ANGLE_RIGHTDOWN
;
6870 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6871 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6873 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6874 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6875 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6876 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6877 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6878 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6879 begin // òî íóæíî ñòðåëÿòü âíèç
6880 SetAIFlag('NEEDFIRE', '1');
6881 SetAIFlag('NEEDSEEDOWN', '1');
6884 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6885 if Target
.Visible
and
6886 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6887 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6889 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6890 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
6891 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6892 begin // òî íóæíî ñòðåëÿòü âïåðåä
6893 SetAIFlag('NEEDFIRE', '1');
6894 SetAIFlag('NEEDSEEDOWN', '');
6895 SetAIFlag('NEEDSEEUP', '');
6897 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6898 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6899 if GetRnd(FDifficult
.CloseJump
) then
6900 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6901 if Abs(FObj
.X
-Target
.X
) < 128 then
6905 if Random(a
) = 0 then
6906 SetAIFlag('NEEDJUMP', '1');
6910 // Åñëè öåëü âñå åùå åñòü:
6911 if Target
.UID
<> 0 then
6912 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
6913 Target
.UID
:= 0 // òî çàáûòü öåëü
6914 else // Åñëè âèäåëè íåäàâíî
6915 begin // íî öåëü óáèëè
6916 if Target
.IsPlayer
then
6917 begin // Öåëü - èãðîê
6918 pla
:= g_Player_Get(Target
.UID
);
6919 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
6920 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6921 Target
.UID
:= 0; // òî çàáûòü öåëü
6924 begin // Öåëü - ìîíñòð
6925 mon
:= g_Monsters_ByUID(Target
.UID
);
6926 if (mon
= nil) or (not mon
.alive
) then
6927 Target
.UID
:= 0; // òî çàáûòü öåëü
6930 end; // if Target.UID <> 0
6932 FTargetUID
:= Target
.UID
;
6934 // Åñëè âîçìîæíûõ öåëåé íåò:
6935 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
6936 if targets
= nil then
6937 if GetAIFlag('ATTACKLEFT') <> '' then
6938 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
6939 RemoveAIFlag('ATTACKLEFT');
6941 SetAIFlag('NEEDJUMP', '1');
6943 if RunDirection() = TDirection
.D_RIGHT
then
6944 begin // Èäåì íå â òó ñòîðîíó
6945 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6946 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
6947 SetAIFlag('NEEDFIRE', '1');
6948 SetAIFlag('GOLEFT', '1');
6952 begin // Èäåì â íóæíóþ ñòîðîíó
6953 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6954 SetAIFlag('NEEDFIRE', '1');
6955 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6956 SetAIFlag('GORIGHT', '1');
6960 if GetAIFlag('ATTACKRIGHT') <> '' then
6961 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
6962 RemoveAIFlag('ATTACKRIGHT');
6964 SetAIFlag('NEEDJUMP', '1');
6966 if RunDirection() = TDirection
.D_LEFT
then
6967 begin // Èäåì íå â òó ñòîðîíó
6968 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6969 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
6970 SetAIFlag('NEEDFIRE', '1');
6971 SetAIFlag('GORIGHT', '1');
6976 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6977 SetAIFlag('NEEDFIRE', '1');
6978 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6979 SetAIFlag('GOLEFT', '1');
6983 //HACK! (does it belongs there?)
6984 RealizeCurrentWeapon();
6986 // Åñëè åñòü âîçìîæíûå öåëè:
6987 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
6988 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6989 for a
:= 0 to High(targets
) do
6991 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
6992 if GetRnd(FDifficult
.DiagFire
) then
6994 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
6995 if FDirection
= TDirection
.D_LEFT
then
6996 angle
:= ANGLE_LEFTUP
6998 angle
:= ANGLE_RIGHTUP
;
7000 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7001 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7003 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7004 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7005 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7006 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7007 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7009 SetAIFlag('NEEDFIRE', '1');
7010 SetAIFlag('NEEDSEEUP', '1');
7013 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7014 if FDirection
= TDirection
.D_LEFT
then
7015 angle
:= ANGLE_LEFTDOWN
7017 angle
:= ANGLE_RIGHTDOWN
;
7019 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7020 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7022 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7023 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7024 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7025 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7026 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7028 SetAIFlag('NEEDFIRE', '1');
7029 SetAIFlag('NEEDSEEDOWN', '1');
7033 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7034 if targets
[a
].Line
and targets
[a
].Visible
and
7035 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
7036 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
7038 SetAIFlag('NEEDFIRE', '1');
7043 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7044 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
7045 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
7046 40+GetInterval(FDifficult
.Cover
, 40)) then
7047 SetAIFlag('NEEDJUMP', '1');
7049 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7050 ammo
:= GetAmmoByWeapon(FCurrWeap
);
7051 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
7052 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
7054 SetAIFlag('SELECTWEAPON', '1');
7056 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7057 if GetAIFlag('SELECTWEAPON') = '1' then
7060 RemoveAIFlag('SELECTWEAPON');
7064 procedure TBot
.Update();
7077 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7078 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7080 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7082 if g_debug_BotAIOff
= 3 then
7092 RealizeCurrentWeapon();
7099 procedure TBot
.ReleaseKey(Key
: Byte);
7108 function TBot
.KeyPressed(Key
: Word): Boolean;
7110 Result
:= FKeys
[Key
].Pressed
;
7113 function TBot
.GetAIFlag(aName
: String20
): String20
;
7119 aName
:= LowerCase(aName
);
7121 if FAIFlags
<> nil then
7122 for a
:= 0 to High(FAIFlags
) do
7123 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7125 Result
:= FAIFlags
[a
].Value
;
7130 procedure TBot
.RemoveAIFlag(aName
: String20
);
7134 if FAIFlags
= nil then Exit
;
7136 aName
:= LowerCase(aName
);
7138 for a
:= 0 to High(FAIFlags
) do
7139 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7141 if a
<> High(FAIFlags
) then
7142 for b
:= a
to High(FAIFlags
)-1 do
7143 FAIFlags
[b
] := FAIFlags
[b
+1];
7145 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7150 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7158 aName
:= LowerCase(aName
);
7160 if FAIFlags
<> nil then
7161 for a
:= 0 to High(FAIFlags
) do
7162 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7168 if ok
then FAIFlags
[a
].Value
:= fValue
7171 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7172 with FAIFlags
[High(FAIFlags
)] do
7180 procedure TBot
.UpdateMove
;
7182 procedure GoLeft(Time
: Word = 1);
7184 ReleaseKey(KEY_LEFT
);
7185 ReleaseKey(KEY_RIGHT
);
7186 PressKey(KEY_LEFT
, Time
);
7187 SetDirection(TDirection
.D_LEFT
);
7190 procedure GoRight(Time
: Word = 1);
7192 ReleaseKey(KEY_LEFT
);
7193 ReleaseKey(KEY_RIGHT
);
7194 PressKey(KEY_RIGHT
, Time
);
7195 SetDirection(TDirection
.D_RIGHT
);
7198 function Rnd(a
: Word): Boolean;
7200 Result
:= Random(a
) = 0;
7203 procedure Turn(Time
: Word = 1200);
7205 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7210 ReleaseKey(KEY_LEFT
);
7211 ReleaseKey(KEY_RIGHT
);
7214 function CanRunLeft(): Boolean;
7216 Result
:= not CollideLevel(-1, 0);
7219 function CanRunRight(): Boolean;
7221 Result
:= not CollideLevel(1, 0);
7224 function CanRun(): Boolean;
7226 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7229 procedure Jump(Time
: Word = 30);
7231 PressKey(KEY_JUMP
, Time
);
7234 function NearHole(): Boolean;
7238 { TODO 5 : Ëåñòíèöû }
7239 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7240 for x
:= 1 to PLAYER_RECT
.Width
do
7241 if (not StayOnStep(x
*sx
, 0)) and
7242 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7243 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7252 function BorderHole(): Boolean;
7256 { TODO 5 : Ëåñòíèöû }
7257 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7258 for x
:= 1 to PLAYER_RECT
.Width
do
7259 if (not StayOnStep(x
*sx
, 0)) and
7260 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7261 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7263 for xx
:= x
to x
+32 do
7264 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7274 function NearDeepHole(): Boolean;
7280 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7283 for x
:= 1 to PLAYER_RECT
.Width
do
7284 if (not StayOnStep(x
*sx
, 0)) and
7285 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7286 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7288 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7290 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7295 end else Result
:= False;
7298 function OverDeepHole(): Boolean;
7305 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7307 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7314 function OnGround(): Boolean;
7316 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7319 function OnLadder(): Boolean;
7321 Result
:= FullInStep(0, 0);
7324 function BelowLadder(): Boolean;
7326 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7327 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7328 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7329 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7332 function BelowLiftUp(): Boolean;
7334 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7335 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7336 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7337 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7340 function OnTopLift(): Boolean;
7342 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7345 function CanJumpOver(): Boolean;
7349 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7353 if not CollideLevel(sx
, 0) then Exit
;
7355 for y
:= 1 to BOT_MAXJUMP
do
7356 if CollideLevel(0, -y
) then Exit
else
7357 if not CollideLevel(sx
, -y
) then
7364 function CanJumpUp(Dist
: ShortInt): Boolean;
7371 if CollideLevel(Dist
, 0) then Exit
;
7374 for y
:= 0 to BOT_MAXJUMP
do
7375 if CollideLevel(Dist
, -y
) then
7384 for yy
:= y
+1 to BOT_MAXJUMP
do
7385 if not CollideLevel(Dist
, -yy
) then
7394 for y
:= 0 to BOT_MAXJUMP
do
7395 if CollideLevel(0, -y
) then
7403 if y
< yy
then Exit
;
7408 function IsSafeTrigger(): Boolean;
7413 if gTriggers
= nil then
7415 for a
:= 0 to High(gTriggers
) do
7416 if Collide(gTriggers
[a
].X
,
7419 gTriggers
[a
].Height
) and
7420 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7421 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7422 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7423 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7424 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7429 // Âîçìîæíî, íàæèìàåì êíîïêó:
7430 if Rnd(16) and IsSafeTrigger() then
7433 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7434 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7436 ReleaseKey(KEY_LEFT
);
7437 ReleaseKey(KEY_RIGHT
);
7441 // Èäåì âëåâî, åñëè íàäî áûëî:
7442 if GetAIFlag('GOLEFT') <> '' then
7444 RemoveAIFlag('GOLEFT');
7445 if CanRunLeft() then
7449 // Èäåì âïðàâî, åñëè íàäî áûëî:
7450 if GetAIFlag('GORIGHT') <> '' then
7452 RemoveAIFlag('GORIGHT');
7453 if CanRunRight() then
7457 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7458 if FObj
.X
< -32 then
7461 if FObj
.X
+32 > gMapInfo
.Width
then
7464 // Ïðûãàåì, åñëè íàäî áûëî:
7465 if GetAIFlag('NEEDJUMP') <> '' then
7468 RemoveAIFlag('NEEDJUMP');
7471 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7472 if GetAIFlag('NEEDSEEUP') <> '' then
7475 ReleaseKey(KEY_DOWN
);
7476 PressKey(KEY_UP
, 20);
7477 RemoveAIFlag('NEEDSEEUP');
7480 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7481 if GetAIFlag('NEEDSEEDOWN') <> '' then
7484 ReleaseKey(KEY_DOWN
);
7485 PressKey(KEY_DOWN
, 20);
7486 RemoveAIFlag('NEEDSEEDOWN');
7489 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7490 if GetAIFlag('GOINHOLE') <> '' then
7491 if not OnGround() then
7493 ReleaseKey(KEY_LEFT
);
7494 ReleaseKey(KEY_RIGHT
);
7495 RemoveAIFlag('GOINHOLE');
7496 SetAIFlag('FALLINHOLE', '1');
7499 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7500 if GetAIFlag('FALLINHOLE') <> '' then
7502 RemoveAIFlag('FALLINHOLE');
7504 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7505 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7506 if GetAIFlag('FALLINHOLE') = '' then
7507 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7513 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7515 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7519 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7520 if OnGround() and NearHole() then
7521 if NearDeepHole() then // Åñëè ýòî áåçäíà
7523 0..3: Turn(); // Áåæèì îáðàòíî
7524 4: Jump(); // Ïðûãàåì
7525 5: begin // Ïðûãàåì îáðàòíî
7530 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7531 if GetAIFlag('GOINHOLE') = '' then
7533 0: Turn(); // Íå íóæíî òóäà
7534 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7535 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7536 if BorderHole() then
7537 SetAIFlag('GOINHOLE', '1');
7540 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7541 if (not CanRun()) and OnGround() then
7543 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7544 if CanJumpOver() or OnLadder() then
7546 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7547 if Random(2) = 0 then
7549 if IsSafeTrigger() then
7555 // Îñòàëîñü ìàëî âîçäóõà:
7556 if FAir
< 36 * 2 then
7559 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7560 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7561 if BodyInAcid(0, 0) then
7565 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7567 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7568 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7571 {function TBot.NeedItem(Item: Byte): Byte;
7576 procedure TBot
.SelectWeapon(Dist
: Integer);
7580 function HaveAmmo(weapon
: Byte): Boolean;
7583 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7584 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7585 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7586 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7587 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7588 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7589 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7590 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7591 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7592 else Result
:= True;
7597 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7599 if Dist
> BOT_LONGDIST
then
7600 begin // Äàëüíèé áîé
7602 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7604 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7608 else //if Dist > BOT_UNSAFEDIST then
7609 begin // Áëèæíèé áîé
7611 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7613 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7620 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7622 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7628 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7630 Result
:= inherited PickItem(ItemType
, force
, remove
);
7632 if Result
then SetAIFlag('SELECTWEAPON', '1');
7635 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7637 Result
:= inherited Heal(value
, Soft
);
7640 function TBot
.Healthy(): Byte;
7642 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7643 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7644 else if (FHealth
> 50) then Result
:= 2
7645 else if (FHealth
> 20) then Result
:= 1
7649 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7651 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7652 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7655 procedure TBot
.OnDamage(Angle
: SmallInt);
7663 if (Angle
= 0) or (Angle
= 180) then
7666 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7667 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7669 pla
:= g_Player_Get(FLastSpawnerUID
);
7670 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7671 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7674 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7675 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7677 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7678 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7679 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7684 SetAIFlag('ATTACKLEFT', '1')
7686 SetAIFlag('ATTACKRIGHT', '1');
7690 function TBot
.RunDirection(): TDirection
;
7692 if Abs(Vel
.X
) >= 1 then
7694 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7696 Result
:= FDirection
;
7699 function TBot
.GetRnd(a
: Byte): Boolean;
7701 if a
= 0 then Result
:= False
7702 else if a
= 255 then Result
:= True
7703 else Result
:= Random(256) > 255-a
;
7706 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7708 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7712 procedure TDifficult
.save (st
: TStream
);
7714 utils
.writeInt(st
, Byte(DiagFire
));
7715 utils
.writeInt(st
, Byte(InvisFire
));
7716 utils
.writeInt(st
, Byte(DiagPrecision
));
7717 utils
.writeInt(st
, Byte(FlyPrecision
));
7718 utils
.writeInt(st
, Byte(Cover
));
7719 utils
.writeInt(st
, Byte(CloseJump
));
7720 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7721 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7724 procedure TDifficult
.load (st
: TStream
);
7726 DiagFire
:= utils
.readByte(st
);
7727 InvisFire
:= utils
.readByte(st
);
7728 DiagPrecision
:= utils
.readByte(st
);
7729 FlyPrecision
:= utils
.readByte(st
);
7730 Cover
:= utils
.readByte(st
);
7731 CloseJump
:= utils
.readByte(st
);
7732 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7733 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7737 procedure TBot
.SaveState (st
: TStream
);
7742 inherited SaveState(st
);
7743 utils
.writeSign(st
, 'BOT0');
7745 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7747 utils
.writeInt(st
, Word(FTargetUID
));
7748 // Âðåìÿ ïîòåðè öåëè
7749 utils
.writeInt(st
, LongWord(FLastVisible
));
7750 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7751 dw
:= Length(FAIFlags
);
7752 utils
.writeInt(st
, LongInt(dw
));
7754 for i
:= 0 to dw
-1 do
7756 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7757 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7759 // Íàñòðîéêè ñëîæíîñòè
7760 FDifficult
.save(st
);
7764 procedure TBot
.LoadState (st
: TStream
);
7769 inherited LoadState(st
);
7770 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7772 FSelectedWeapon
:= utils
.readByte(st
);
7774 FTargetUID
:= utils
.readWord(st
);
7775 // Âðåìÿ ïîòåðè öåëè
7776 FLastVisible
:= utils
.readLongWord(st
);
7777 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7778 dw
:= utils
.readLongInt(st
);
7779 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7780 SetLength(FAIFlags
, dw
);
7782 for i
:= 0 to dw
-1 do
7784 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7785 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7787 // Íàñòðîéêè ñëîæíîñòè
7788 FDifficult
.load(st
);
7793 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);