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 (unused)
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 weaponSwitchKeyReleased
: array[0..16] of Byte; // bit 0: was released on prev frame; bit 1: new status
207 function CollideLevel(XInc
, YInc
: Integer): Boolean;
208 function StayOnStep(XInc
, YInc
: Integer): Boolean;
209 function HeadInLiquid(XInc
, YInc
: Integer): Boolean;
210 function BodyInLiquid(XInc
, YInc
: Integer): Boolean;
211 function BodyInAcid(XInc
, YInc
: Integer): Boolean;
212 function FullInLift(XInc
, YInc
: Integer): Integer;
213 {procedure CollideItem();}
214 procedure FlySmoke(Times
: DWORD
= 1);
215 procedure OnFireFlame(Times
: DWORD
= 1);
216 function GetAmmoByWeapon(Weapon
: Byte): Word;
217 procedure SetAction(Action
: Byte; Force
: Boolean = False);
218 procedure OnDamage(Angle
: SmallInt); virtual;
219 function firediry(): Integer;
222 procedure Run(Direction
: TDirection
);
223 procedure NextWeapon();
224 procedure PrevWeapon();
231 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
232 procedure resetWeaponQueue ();
233 function hasAmmoForWeapon (weapon
: Byte): Boolean;
235 procedure doDamage (v
: Integer);
237 function followCorpse(): Boolean;
240 FDamageBuffer
: Integer;
242 FAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
243 FMaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
244 FWeapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
245 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
247 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
248 FReloading
: Array [WP_FIRST
..WP_LAST
] of Word;
249 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
250 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
252 FPreferredTeam
: Byte;
255 FWantsInGame
: Boolean;
259 FActualModelName
: string;
266 // debug: viewport offset
267 viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer;
269 function isValidViewPort (): Boolean; inline;
271 constructor Create(); virtual;
272 destructor Destroy(); override;
273 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
274 function GetRespawnPoint(): Byte;
275 procedure PressKey(Key
: Byte; Time
: Word = 1);
276 procedure ReleaseKeys();
277 procedure SetModel(ModelName
: String);
278 procedure SetColor(Color
: TRGB
);
279 procedure SetWeapon(W
: Byte);
280 function IsKeyPressed(K
: Byte): Boolean;
281 function GetKeys(): Byte;
282 function PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean; virtual;
283 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
284 function Collide(Panel
: TPanel
): Boolean; overload
;
285 function Collide(X
, Y
: Integer): Boolean; overload
;
286 procedure SetDirection(Direction
: TDirection
);
287 procedure GetSecret();
288 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
290 procedure Push(vx
, vy
: Integer);
291 procedure ChangeModel(ModelName
: String);
292 procedure SwitchTeam
;
293 procedure ChangeTeam(Team
: Byte);
295 function GetFlag(Flag
: Byte): Boolean;
296 procedure SetFlag(Flag
: Byte);
297 function DropFlag(): Boolean;
298 procedure AllRulez(Health
: Boolean);
299 procedure RestoreHealthArmor();
300 procedure FragCombo();
301 procedure GiveItem(ItemType
: Byte);
302 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
303 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
304 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
305 procedure MakeBloodSimple(Count
: Word);
306 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
307 procedure Reset(Force
: Boolean);
308 procedure Spectate(NoMove
: Boolean = False);
309 procedure SwitchNoClip
;
310 procedure SoftReset();
311 procedure Draw(); virtual;
312 procedure DrawPain();
313 procedure DrawPickup();
314 procedure DrawRulez();
316 procedure DrawIndicator();
317 procedure DrawBubble();
319 procedure Update(); virtual;
320 procedure RememberState();
321 procedure RecallState();
322 procedure SaveState (st
: TStream
); virtual;
323 procedure LoadState (st
: TStream
); virtual;
324 procedure PauseSounds(Enable
: Boolean);
325 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
326 procedure DoLerp(Level
: Integer = 2);
327 procedure SetLerp(XTo
, YTo
: Integer);
328 procedure QueueWeaponSwitch(Weapon
: Byte);
329 procedure RealizeCurrentWeapon();
331 procedure JetpackOff
;
332 procedure CatchFire(Attacker
: Word);
334 //WARNING! this does nothing for now, but still call it!
335 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
337 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
338 procedure moveBy (dx
, dy
: Integer); inline;
340 procedure releaseAllWeaponSwitchKeys ();
341 procedure weaponSwitchKeysStateChange (index
: Integer; pressed
: Boolean);
342 function isWeaponSwitchKeyReleased (index
: Integer): Boolean;
343 procedure weaponSwitchKeysShiftNewStates ();
346 property Vel
: TPoint2i read FObj
.Vel
;
347 property Obj
: TObj read FObj
;
349 property Name
: String read FName write FName
;
350 property Model
: TPlayerModel read FModel
;
351 property Health
: Integer read FHealth write FHealth
;
352 property Lives
: Byte read FLives write FLives
;
353 property Armor
: Integer read FArmor write FArmor
;
354 property Air
: Integer read FAir write FAir
;
355 property JetFuel
: Integer read FJetFuel write FJetFuel
;
356 property Frags
: Integer read FFrags write FFrags
;
357 property Death
: Integer read FDeath write FDeath
;
358 property Kills
: Integer read FKills write FKills
;
359 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
360 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
361 property Secrets
: Integer read FSecrets
;
362 property GodMode
: Boolean read FGodMode write FGodMode
;
363 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
364 property NoReload
: Boolean read FNoReload write FNoReload
;
365 property alive
: Boolean read FAlive write FAlive
;
366 property Flag
: Byte read FFlag
;
367 property Team
: Byte read FTeam write FTeam
;
368 property Direction
: TDirection read FDirection
;
369 property GameX
: Integer read FObj
.X write FObj
.X
;
370 property GameY
: Integer read FObj
.Y write FObj
.Y
;
371 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
372 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
373 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
374 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
375 property IncCam
: Integer read FIncCam write FIncCam
;
376 property UID
: Word read FUID write FUID
;
377 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
378 property NetTime
: LongWord read FNetTime write FNetTime
;
381 property eName
: String read FName write FName
;
382 property eHealth
: Integer read FHealth write FHealth
;
383 property eLives
: Byte read FLives write FLives
;
384 property eArmor
: Integer read FArmor write FArmor
;
385 property eAir
: Integer read FAir write FAir
;
386 property eJetFuel
: Integer read FJetFuel write FJetFuel
;
387 property eFrags
: Integer read FFrags write FFrags
;
388 property eDeath
: Integer read FDeath write FDeath
;
389 property eKills
: Integer read FKills write FKills
;
390 property eCurrWeap
: Byte read FCurrWeap write FCurrWeap
;
391 property eMonsterKills
: Integer read FMonsterKills write FMonsterKills
;
392 property eSecrets
: Integer read FSecrets write FSecrets
;
393 property eGodMode
: Boolean read FGodMode write FGodMode
;
394 property eNoTarget
: Boolean read FNoTarget write FNoTarget
;
395 property eNoReload
: Boolean read FNoReload write FNoReload
;
396 property eAlive
: Boolean read FAlive write FAlive
;
397 property eFlag
: Byte read FFlag
;
398 property eTeam
: Byte read FTeam write FTeam
;
399 property eDirection
: TDirection read FDirection
;
400 property eGameX
: Integer read FObj
.X write FObj
.X
;
401 property eGameY
: Integer read FObj
.Y write FObj
.Y
;
402 property eGameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
403 property eGameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
404 property eGameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
405 property eGameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
406 property eIncCam
: Integer read FIncCam write FIncCam
;
407 property eUID
: Word read FUID
;
408 property eJustTeleported
: Boolean read FJustTeleported
;
409 property eNetTime
: LongWord read FNetTime
;
411 // set this before assigning something to `eDamage`
412 property eDamageType
: Integer read mEDamageType write mEDamageType
;
413 property eDamage
: Integer write doDamage
;
424 WeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
425 CloseWeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
426 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
429 procedure save (st
: TStream
);
430 procedure load (st
: TStream
);
438 TBot
= class(TPlayer
)
440 FSelectedWeapon
: Byte;
443 FAIFlags
: Array of TAIFlag
;
444 FDifficult
: TDifficult
;
446 function GetRnd(a
: Byte): Boolean;
447 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
448 function RunDirection(): TDirection
;
449 function FullInStep(XInc
, YInc
: Integer): Boolean;
450 //function NeedItem(Item: Byte): Byte;
451 procedure SelectWeapon(Dist
: Integer);
452 procedure SetAIFlag(aName
, fValue
: String20
);
453 function GetAIFlag(aName
: String20
): String20
;
454 procedure RemoveAIFlag(aName
: String20
);
455 function Healthy(): Byte;
456 procedure UpdateMove();
457 procedure UpdateCombat();
458 function KeyPressed(Key
: Word): Boolean;
459 procedure ReleaseKey(Key
: Byte);
460 function TargetOnScreen(TX
, TY
: Integer): Boolean;
461 procedure OnDamage(Angle
: SmallInt); override;
464 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
465 constructor Create(); override;
466 destructor Destroy(); override;
467 procedure Draw(); override;
468 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
469 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
470 procedure Update(); override;
471 procedure SaveState (st
: TStream
); override;
472 procedure LoadState (st
: TStream
); override;
484 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
485 procedure moveBy (dx
, dy
: Integer); inline;
487 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
501 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
502 procedure moveBy (dx
, dy
: Integer); inline;
504 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
507 TCorpse
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
516 FAnimation
: TAnimation
;
517 FAnimationMask
: TAnimation
;
520 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
521 destructor Destroy(); override;
522 procedure Damage(Value
: Word; vx
, vy
: Integer);
525 procedure SaveState (st
: TStream
);
526 procedure LoadState (st
: TStream
);
528 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
529 procedure moveBy (dx
, dy
: Integer); inline;
531 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
533 function ObjPtr (): PObj
; inline;
535 property Obj
: TObj read FObj
; // copies object
536 property State
: Byte read FState
;
537 property Mess
: Boolean read FMess
;
540 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
546 gPlayers
: Array of TPlayer
;
547 gCorpses
: Array of TCorpse
;
548 gGibs
: Array of TGib
;
549 gShells
: Array of TShell
;
550 gTeamStat
: TTeamStat
;
551 gFly
: Boolean = False;
552 gAimLine
: Boolean = False;
553 gChatBubble
: Byte = 0;
554 gPlayerIndicator
: Boolean = True;
558 MAX_RUNVEL
: Integer = 8;
559 VEL_JUMP
: Integer = 10;
560 SHELL_TIMEOUT
: Cardinal = 60000;
562 function Lerp(X
, Y
, Factor
: Integer): Integer;
564 procedure g_Gibs_SetMax(Count
: Word);
565 function g_Gibs_GetMax(): Word;
566 procedure g_Corpses_SetMax(Count
: Word);
567 function g_Corpses_GetMax(): Word;
568 procedure g_Shells_SetMax(Count
: Word);
569 function g_Shells_GetMax(): Word;
571 procedure g_Player_Init();
572 procedure g_Player_Free();
573 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
574 function g_Player_CreateFromState (st
: TStream
): Word;
575 procedure g_Player_Remove(UID
: Word);
576 procedure g_Player_ResetTeams();
577 procedure g_Player_UpdateAll();
578 procedure g_Player_DrawAll();
579 procedure g_Player_DrawDebug(p
: TPlayer
);
580 procedure g_Player_DrawHealth();
581 procedure g_Player_RememberAll();
582 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
583 function g_Player_Get(UID
: Word): TPlayer
;
584 function g_Player_GetCount(): Byte;
585 function g_Player_GetStats(): TPlayerStatArray
;
586 function g_Player_ValidName(Name
: String): Boolean;
587 procedure g_Player_CreateCorpse(Player
: TPlayer
);
588 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
589 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
590 procedure g_Player_UpdatePhysicalObjects();
591 procedure g_Player_DrawCorpses();
592 procedure g_Player_DrawShells();
593 procedure g_Player_RemoveAllCorpses();
594 procedure g_Player_Corpses_SaveState (st
: TStream
);
595 procedure g_Player_Corpses_LoadState (st
: TStream
);
596 procedure g_Bot_Add(Team
, Difficult
: Byte);
597 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1);
598 procedure g_Bot_MixNames();
599 procedure g_Bot_RemoveAll();
604 {$INCLUDE ../nogl/noGLuses.inc}
605 {$IFDEF ENABLE_HOLMES}
608 e_log
, g_map
, g_items
, g_console
, g_gfx
, Math
,
609 g_options
, g_triggers
, g_menu
, g_game
, g_grid
,
610 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
,
611 g_net
, g_netmsg
, g_window
,
614 const PLR_SAVE_VERSION
= 0;
624 diag_precision
: Byte;
628 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
629 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
630 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
634 TIME_RESPAWN1
= 1500;
635 TIME_RESPAWN2
= 2000;
636 TIME_RESPAWN3
= 3000;
639 JET_MAX
= 540; // ~30 sec
640 PLAYER_SUIT_TIME
= 30000;
641 PLAYER_INVUL_TIME
= 30000;
642 PLAYER_INVIS_TIME
= 35000;
643 FRAG_COMBO_TIME
= 3000;
647 ANGLE_RIGHTDOWN
= -35;
649 ANGLE_LEFTDOWN
= -145;
650 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
651 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
654 BOT_UNSAFEDIST
= 128;
655 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
657 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
658 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
659 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
660 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
661 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
662 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
663 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
664 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
665 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
666 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
667 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
668 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
669 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
670 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
671 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
672 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
673 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
674 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
675 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
676 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
677 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
678 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
679 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
680 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
681 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
682 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
684 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
685 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
687 BOTNAMES_FILENAME
= 'botnames.txt';
688 BOTLIST_FILENAME
= 'botlist.txt';
692 MaxCorpses
: Word = 20;
693 MaxShells
: Word = 300;
694 CurrentGib
: Integer = 0;
695 CurrentShell
: Integer = 0;
696 BotNames
: Array of String;
697 BotList
: Array of TBotProfile
;
700 function Lerp(X
, Y
, Factor
: Integer): Integer;
702 Result
:= X
+ ((Y
- X
) div Factor
);
705 function SameTeam(UID1
, UID2
: Word): Boolean;
709 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
710 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
712 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
714 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
715 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
717 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
720 procedure g_Gibs_SetMax(Count
: Word);
723 SetLength(gGibs
, Count
);
725 if CurrentGib
>= Count
then
729 function g_Gibs_GetMax(): Word;
734 procedure g_Shells_SetMax(Count
: Word);
737 SetLength(gShells
, Count
);
739 if CurrentShell
>= Count
then
743 function g_Shells_GetMax(): Word;
749 procedure g_Corpses_SetMax(Count
: Word);
752 SetLength(gCorpses
, Count
);
755 function g_Corpses_GetMax(): Word;
757 Result
:= MaxCorpses
;
760 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
770 // Åñòü ëè ìåñòî â gPlayers:
771 if gPlayers
<> nil then
772 for a
:= 0 to High(gPlayers
) do
773 if gPlayers
[a
] = nil then
779 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
782 SetLength(gPlayers
, Length(gPlayers
)+1);
786 // Ñîçäàåì îáúåêò èãðîêà:
788 gPlayers
[a
] := TBot
.Create()
790 gPlayers
[a
] := TPlayer
.Create();
793 gPlayers
[a
].FActualModelName
:= ModelName
;
794 gPlayers
[a
].SetModel(ModelName
);
796 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
797 if gPlayers
[a
].FModel
= nil then
801 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
805 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
806 if Random(2) = 0 then
810 gPlayers
[a
].FPreferredTeam
:= Team
;
812 case gGameSettings
.GameMode
of
813 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
815 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
817 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
820 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
821 gPlayers
[a
].FColor
:= Color
;
822 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
823 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
825 gPlayers
[a
].FModel
.Color
:= Color
;
827 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
828 gPlayers
[a
].FAlive
:= False;
830 Result
:= gPlayers
[a
].FUID
;
833 function g_Player_CreateFromState (st
: TStream
): Word;
840 if (st
= nil) then exit
; //???
843 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
844 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
847 Bot
:= utils
.readBool(st
);
852 // Åñòü ëè ìåñòî â gPlayers:
853 for a
:= 0 to High(gPlayers
) do if (gPlayers
[a
] = nil) then begin ok
:= true; break
; end;
855 // Íåò ìåñòà - ðàñøèðÿåì gPlayers
858 SetLength(gPlayers
, Length(gPlayers
)+1);
862 // Ñîçäàåì îáúåêò èãðîêà
864 gPlayers
[a
] := TBot
.Create()
866 gPlayers
[a
] := TPlayer
.Create();
867 gPlayers
[a
].FIamBot
:= Bot
;
868 gPlayers
[a
].FPhysics
:= True;
871 gPlayers
[a
].FUID
:= utils
.readWord(st
);
873 gPlayers
[a
].FName
:= utils
.readStr(st
);
875 gPlayers
[a
].FTeam
:= utils
.readByte(st
);
876 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
878 gPlayers
[a
].FAlive
:= utils
.readBool(st
);
879 // Èçðàñõîäîâàë ëè âñå æèçíè
880 gPlayers
[a
].FNoRespawn
:= utils
.readBool(st
);
882 b
:= utils
.readByte(st
);
883 if b
= 1 then gPlayers
[a
].FDirection
:= TDirection
.D_LEFT
else gPlayers
[a
].FDirection
:= TDirection
.D_RIGHT
; // b = 2
885 gPlayers
[a
].FHealth
:= utils
.readLongInt(st
);
887 gPlayers
[a
].FLives
:= utils
.readByte(st
);
889 gPlayers
[a
].FArmor
:= utils
.readLongInt(st
);
891 gPlayers
[a
].FAir
:= utils
.readLongInt(st
);
893 gPlayers
[a
].FJetFuel
:= utils
.readLongInt(st
);
895 gPlayers
[a
].FPain
:= utils
.readLongInt(st
);
897 gPlayers
[a
].FKills
:= utils
.readLongInt(st
);
899 gPlayers
[a
].FMonsterKills
:= utils
.readLongInt(st
);
901 gPlayers
[a
].FFrags
:= utils
.readLongInt(st
);
903 gPlayers
[a
].FFragCombo
:= utils
.readByte(st
);
904 // Âðåìÿ ïîñëåäíåãî ôðàãà
905 gPlayers
[a
].FLastFrag
:= utils
.readLongWord(st
);
907 gPlayers
[a
].FDeath
:= utils
.readLongInt(st
);
909 gPlayers
[a
].FFlag
:= utils
.readByte(st
);
911 gPlayers
[a
].FSecrets
:= utils
.readLongInt(st
);
913 gPlayers
[a
].FCurrWeap
:= utils
.readByte(st
);
914 // Ñëåäóþùåå æåëàåìîå îðóæèå
915 gPlayers
[a
].FNextWeap
:= utils
.readWord(st
);
917 gPlayers
[a
].FNextWeapDelay
:= utils
.readByte(st
);
919 gPlayers
[a
].FBFGFireCounter
:= utils
.readSmallInt(st
);
921 gPlayers
[a
].FDamageBuffer
:= utils
.readLongInt(st
);
922 // Ïîñëåäíèé óäàðèâøèé
923 gPlayers
[a
].FLastSpawnerUID
:= utils
.readWord(st
);
924 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
925 gPlayers
[a
].FLastHit
:= utils
.readByte(st
);
927 Obj_LoadState(@gPlayers
[a
].FObj
, st
);
928 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
929 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FAmmo
[i
] := utils
.readWord(st
);
930 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
931 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FMaxAmmo
[i
] := utils
.readWord(st
);
933 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FWeapon
[i
] := utils
.readBool(st
);
934 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
935 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FReloading
[i
] := utils
.readWord(st
);
937 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
938 // Íàëè÷èå êðàñíîãî êëþ÷à
939 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
940 // Íàëè÷èå çåëåíîãî êëþ÷à
941 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
942 // Íàëè÷èå ñèíåãî êëþ÷à
943 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
945 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_BERSERK
);
946 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
947 for i
:= MR_SUIT
to MR_MAX
do gPlayers
[a
].FMegaRulez
[i
] := utils
.readLongWord(st
);
948 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
949 for i
:= T_RESPAWN
to T_FLAGCAP
do gPlayers
[a
].FTime
[i
] := utils
.readLongWord(st
);
952 gPlayers
[a
].FActualModelName
:= utils
.readStr(st
);
954 gPlayers
[a
].FColor
.R
:= utils
.readByte(st
);
955 gPlayers
[a
].FColor
.G
:= utils
.readByte(st
);
956 gPlayers
[a
].FColor
.B
:= utils
.readByte(st
);
957 // Îáíîâëÿåì ìîäåëü èãðîêà
958 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
960 // Íåò ìîäåëè - ñîçäàíèå íåâîçìîæíî
961 if (gPlayers
[a
].FModel
= nil) then
965 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
969 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû
970 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
971 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
973 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
975 result
:= gPlayers
[a
].FUID
;
979 procedure g_Player_ResetTeams();
983 if g_Game_IsClient
then
985 if gPlayers
= nil then
987 for a
:= Low(gPlayers
) to High(gPlayers
) do
988 if gPlayers
[a
] <> nil then
989 case gGameSettings
.GameMode
of
991 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
993 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
994 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
995 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
998 gPlayers
[a
].ChangeTeam(TEAM_RED
)
1000 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
1003 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
1007 procedure g_Bot_Add(Team
, Difficult
: Byte);
1010 _name
, _model
: String;
1013 if not g_Game_IsServer
then Exit
;
1015 // Ñïèñîê íàçâàíèé ìîäåëåé:
1016 m
:= g_PlayerModel_GetNames();
1021 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1022 Team
:= TEAM_COOP
// COOP
1024 if gGameSettings
.GameMode
= GM_DM
then
1025 Team
:= TEAM_NONE
// DM
1027 if Team
= TEAM_NONE
then // CTF / TDM
1029 // Àâòîáàëàíñ êîìàíä:
1033 for a
:= 0 to High(gPlayers
) do
1034 if gPlayers
[a
] <> nil then
1036 if gPlayers
[a
].Team
= TEAM_RED
then
1039 if gPlayers
[a
].Team
= TEAM_BLUE
then
1049 if Random(2) = 0 then
1055 // Âûáèðàåì áîòó èìÿ:
1057 if BotNames
<> nil then
1058 for a
:= 0 to High(BotNames
) do
1059 if g_Player_ValidName(BotNames
[a
]) then
1061 _name
:= BotNames
[a
];
1065 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
1068 _name
:= Format('DFBOT%.2d', [Random(100)]);
1069 until g_Player_ValidName(_name
);
1071 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1072 _model
:= m
[Random(Length(m
))];
1075 with g_Player_Get(g_Player_Create(_model
,
1076 _RGB(Min(Random(9)*32, 255),
1077 Min(Random(9)*32, 255),
1078 Min(Random(9)*32, 255)),
1079 Team
, True)) as TBot
do
1084 1: FDifficult
:= DIFFICULT_EASY
;
1085 2: FDifficult
:= DIFFICULT_MEDIUM
;
1086 else FDifficult
:= DIFFICULT_HARD
;
1089 for a
:= WP_FIRST
to WP_LAST
do
1091 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1092 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1093 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1096 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1098 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1099 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1104 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1);
1107 _name
, _model
: String;
1110 if not g_Game_IsServer
then Exit
;
1112 // Ñïèñîê íàçâàíèé ìîäåëåé:
1113 m
:= g_PlayerModel_GetNames();
1118 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1119 Team
:= TEAM_COOP
// COOP
1121 if gGameSettings
.GameMode
= GM_DM
then
1122 Team
:= TEAM_NONE
// DM
1124 if Team
= TEAM_NONE
then
1125 Team
:= BotList
[num
].team
; // CTF / TDM
1127 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1128 lName
:= AnsiLowerCase(lName
);
1129 if (num
< 0) or (num
> Length(BotList
)-1) then
1131 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1132 for a
:= 0 to High(BotList
) do
1133 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1142 _name
:= BotList
[num
].name
;
1143 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1144 if not g_Player_ValidName(_name
) then
1146 _name
:= Format('DFBOT%.2d', [Random(100)]);
1147 until g_Player_ValidName(_name
);
1150 _model
:= BotList
[num
].model
;
1151 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1152 if not InSArray(_model
, m
) then
1153 _model
:= m
[Random(Length(m
))];
1156 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1160 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1161 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1162 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1163 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1164 FDifficult
.Cover
:= BotList
[num
].cover
;
1165 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1167 for a
:= WP_FIRST
to WP_LAST
do
1169 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1170 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1171 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1174 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1176 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1180 procedure g_Bot_RemoveAll();
1184 if not g_Game_IsServer
then Exit
;
1185 if gPlayers
= nil then Exit
;
1187 for a
:= 0 to High(gPlayers
) do
1188 if gPlayers
[a
] <> nil then
1189 if gPlayers
[a
] is TBot
then
1191 gPlayers
[a
].Lives
:= 0;
1192 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1193 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1194 g_Player_Remove(gPlayers
[a
].FUID
);
1200 procedure g_Bot_MixNames();
1205 if BotNames
<> nil then
1206 for a
:= 0 to High(BotNames
) do
1208 b
:= Random(Length(BotNames
));
1210 Botnames
[a
] := BotNames
[b
];
1215 procedure g_Player_Remove(UID
: Word);
1219 if gPlayers
= nil then Exit
;
1221 if g_Game_IsServer
and g_Game_IsNet
then
1222 MH_SEND_PlayerDelete(UID
);
1224 for i
:= 0 to High(gPlayers
) do
1225 if gPlayers
[i
] <> nil then
1226 if gPlayers
[i
].FUID
= UID
then
1228 if gPlayers
[i
] is TPlayer
then
1229 TPlayer(gPlayers
[i
]).Free()
1231 TBot(gPlayers
[i
]).Free();
1237 procedure g_Player_Init();
1247 if not FileExists(DataDir
+ BOTNAMES_FILENAME
) then
1250 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1251 AssignFile(F
, DataDir
+ BOTNAMES_FILENAME
);
1262 SetLength(BotNames
, Length(BotNames
)+1);
1263 BotNames
[High(BotNames
)] := s
;
1271 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1272 config
:= TConfig
.CreateFile(DataDir
+ BOTLIST_FILENAME
);
1276 while config
.SectionExists(IntToStr(a
)) do
1278 SetLength(BotList
, Length(BotList
)+1);
1280 with BotList
[High(BotList
)] do
1283 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1285 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1287 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1292 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1293 color
.R
:= StrToIntDef(sa
[0], 0);
1294 color
.G
:= StrToIntDef(sa
[1], 0);
1295 color
.B
:= StrToIntDef(sa
[2], 0);
1296 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1297 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1298 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1299 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1300 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1301 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1302 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1303 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1304 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1305 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1306 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1307 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1308 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1309 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1310 if Length(sa
) = 10 then
1312 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1313 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1314 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1315 if Length(sa
) = 10 then
1317 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1319 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1320 if Length(sa) = 10 then
1322 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1331 procedure g_Player_Free();
1335 if gPlayers
<> nil then
1337 for i
:= 0 to High(gPlayers
) do
1338 if gPlayers
[i
] <> nil then
1340 if gPlayers
[i
] is TPlayer
then
1341 TPlayer(gPlayers
[i
]).Free()
1343 TBot(gPlayers
[i
]).Free();
1354 procedure g_Player_UpdateAll();
1358 if gPlayers
= nil then Exit
;
1360 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1361 for i
:= 0 to High(gPlayers
) do
1363 if gPlayers
[i
] <> nil then
1365 if gPlayers
[i
] is TPlayer
then
1367 gPlayers
[i
].Update();
1368 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1372 // bot updates weapons in `UpdateCombat()`
1373 TBot(gPlayers
[i
]).Update();
1377 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1380 procedure g_Player_DrawAll();
1384 if gPlayers
= nil then Exit
;
1386 for i
:= 0 to High(gPlayers
) do
1387 if gPlayers
[i
] <> nil then
1388 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1389 else TBot(gPlayers
[i
]).Draw();
1392 procedure g_Player_DrawDebug(p
: TPlayer
);
1396 if p
= nil then Exit
;
1397 if (@p
.FObj
) = nil then Exit
;
1399 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1401 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1402 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1403 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1404 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1405 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1406 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1409 procedure g_Player_DrawHealth();
1414 if gPlayers
= nil then Exit
;
1415 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1417 for i
:= 0 to High(gPlayers
) do
1418 if gPlayers
[i
] <> nil then
1420 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1421 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1422 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1423 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1424 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1425 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1429 function g_Player_Get(UID
: Word): TPlayer
;
1435 if gPlayers
= nil then
1438 for a
:= 0 to High(gPlayers
) do
1439 if gPlayers
[a
] <> nil then
1440 if gPlayers
[a
].FUID
= UID
then
1442 Result
:= gPlayers
[a
];
1447 function g_Player_GetCount(): Byte;
1453 if gPlayers
= nil then
1456 for a
:= 0 to High(gPlayers
) do
1457 if gPlayers
[a
] <> nil then
1458 Result
:= Result
+ 1;
1461 function g_Player_GetStats(): TPlayerStatArray
;
1467 if gPlayers
= nil then Exit
;
1469 for a
:= 0 to High(gPlayers
) do
1470 if gPlayers
[a
] <> nil then
1472 SetLength(Result
, Length(Result
)+1);
1473 with Result
[High(Result
)] do
1475 Ping
:= gPlayers
[a
].FPing
;
1476 Loss
:= gPlayers
[a
].FLoss
;
1477 Name
:= gPlayers
[a
].FName
;
1478 Team
:= gPlayers
[a
].FTeam
;
1479 Frags
:= gPlayers
[a
].FFrags
;
1480 Deaths
:= gPlayers
[a
].FDeath
;
1481 Kills
:= gPlayers
[a
].FKills
;
1482 Color
:= gPlayers
[a
].FModel
.Color
;
1483 Lives
:= gPlayers
[a
].FLives
;
1484 Spectator
:= gPlayers
[a
].FSpectator
;
1489 procedure g_Player_RememberAll
;
1493 for i
:= Low(gPlayers
) to High(gPlayers
) do
1494 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1495 gPlayers
[i
].RememberState
;
1498 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1502 gTeamStat
[TEAM_RED
].Goals
:= 0;
1503 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1505 if gPlayers
<> nil then
1506 for i
:= 0 to High(gPlayers
) do
1507 if gPlayers
[i
] <> nil then
1509 gPlayers
[i
].Reset(Force
);
1511 if gPlayers
[i
] is TPlayer
then
1513 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1514 gPlayers
[i
].Respawn(Silent
)
1516 gPlayers
[i
].Spectate();
1519 TBot(gPlayers
[i
]).Respawn(Silent
);
1523 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1529 if Player
.alive
then
1532 // Ðàçðûâàåì ñâÿçü ñ ïðåæíèì òðóïîì:
1533 if gCorpses
<> nil then
1534 for i
:= 0 to High(gCorpses
) do
1535 if gCorpses
[i
] <> nil then
1536 if gCorpses
[i
].FPlayerUID
= Player
.FUID
then
1537 gCorpses
[i
].FPlayerUID
:= 0;
1539 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1544 if (FHealth
>= -50) or (gGibsCount
= 0) then
1546 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1550 for find_id
:= 0 to High(gCorpses
) do
1551 if gCorpses
[find_id
] = nil then
1558 find_id
:= Random(Length(gCorpses
));
1560 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1561 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1562 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1563 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1564 gCorpses
[find_id
].FPlayerUID
:= FUID
;
1567 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1568 FObj
.Y
+ PLAYER_RECT_CY
,
1569 FModel
.Name
, FModel
.Color
);
1573 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1577 if (gShells
= nil) or (Length(gShells
) = 0) then
1580 with gShells
[CurrentShell
] do
1586 if T
= SHELL_BULLET
then
1588 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1592 Obj
.Rect
.Width
:= 4;
1593 Obj
.Rect
.Height
:= 2;
1597 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1601 Obj
.Rect
.Width
:= 7;
1602 Obj
.Rect
.Height
:= 3;
1608 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1609 positionChanged(); // this updates spatial accelerators
1610 RAngle
:= Random(360);
1611 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1613 if CurrentShell
>= High(gShells
) then
1620 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1623 GibsArray
: TGibsArray
;
1626 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1628 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1630 Blood
:= g_PlayerModel_GetBlood(ModelName
);
1632 for a
:= 0 to High(GibsArray
) do
1633 with gGibs
[CurrentGib
] do
1636 ID
:= GibsArray
[a
].ID
;
1637 MaskID
:= GibsArray
[a
].MaskID
;
1640 Obj
.Rect
:= GibsArray
[a
].Rect
;
1641 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1642 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1643 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1644 positionChanged(); // this updates spatial accelerators
1645 RAngle
:= Random(360);
1647 if gBloodCount
> 0 then
1648 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1649 Random(48), Random(48), Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
1651 if CurrentGib
>= High(gGibs
) then
1658 procedure g_Player_UpdatePhysicalObjects();
1664 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1669 if T
= SHELL_BULLET
then
1670 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1672 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1677 if gGibs
<> nil then
1678 for i
:= 0 to High(gGibs
) do
1679 if gGibs
[i
].alive
then
1683 mr
:= g_Obj_Move(@Obj
, True, False, True);
1684 positionChanged(); // this updates spatial accelerators
1686 if WordBool(mr
and MOVE_FALLOUT
) then
1692 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1693 if WordBool(mr
and MOVE_HITWALL
) then
1694 Obj
.Vel
.X
:= -(vel
.X
div 2);
1695 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1696 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1698 if (Obj
.Vel
.X
>= 0) then
1700 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1701 if RAngle
>= 360 then
1702 RAngle
:= RAngle
mod 360;
1703 end else begin // Counter-clockwise
1704 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1706 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1709 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1710 if gTime
mod (GAME_TICK
*3) = 0 then
1711 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1715 if gCorpses
<> nil then
1716 for i
:= 0 to High(gCorpses
) do
1717 if gCorpses
[i
] <> nil then
1718 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1724 gCorpses
[i
].Update();
1727 if gShells
<> nil then
1728 for i
:= 0 to High(gShells
) do
1729 if gShells
[i
].alive
then
1733 mr
:= g_Obj_Move(@Obj
, True, False, True);
1734 positionChanged(); // this updates spatial accelerators
1736 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1742 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1743 if WordBool(mr
and MOVE_HITWALL
) then
1745 Obj
.Vel
.X
:= -(vel
.X
div 2);
1746 if not WordBool(mr
and MOVE_INWATER
) then
1747 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1749 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1751 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1752 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1753 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1755 if RAngle
mod 90 <> 0 then
1756 RAngle
:= (RAngle
div 90) * 90;
1758 else if not WordBool(mr
and MOVE_INWATER
) then
1759 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1762 if (Obj
.Vel
.X
>= 0) then
1764 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1765 if RAngle
>= 360 then
1766 RAngle
:= RAngle
mod 360;
1767 end else begin // Counter-clockwise
1768 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1770 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1776 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1778 x
:= Obj
.X
+Obj
.Rect
.X
;
1779 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1780 w
:= Obj
.Rect
.Width
;
1781 h
:= Obj
.Rect
.Height
;
1784 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1786 if (dx
<> 0) or (dy
<> 0) then
1795 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1799 w
:= Obj
.Rect
.Width
;
1800 h
:= Obj
.Rect
.Height
;
1803 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1805 if (dx
<> 0) or (dy
<> 0) then
1814 procedure TGib
.positionChanged (); inline; begin end;
1815 procedure TShell
.positionChanged (); inline; begin end;
1818 procedure g_Player_DrawCorpses();
1823 if gGibs
<> nil then
1824 for i
:= 0 to High(gGibs
) do
1825 if gGibs
[i
].alive
then
1828 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1831 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1832 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1834 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1837 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1843 if gCorpses
<> nil then
1844 for i
:= 0 to High(gCorpses
) do
1845 if gCorpses
[i
] <> nil then
1849 procedure g_Player_DrawShells();
1854 if gShells
<> nil then
1855 for i
:= 0 to High(gShells
) do
1856 if gShells
[i
].alive
then
1859 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1865 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1869 procedure g_Player_RemoveAllCorpses();
1875 SetLength(gGibs
, MaxGibs
);
1876 SetLength(gShells
, MaxGibs
);
1880 if gCorpses
<> nil then
1881 for i
:= 0 to High(gCorpses
) do
1885 SetLength(gCorpses
, MaxCorpses
);
1888 procedure g_Player_Corpses_SaveState (st
: TStream
);
1892 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ
1894 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1896 // Êîëè÷åñòâî òðóïîâ
1897 utils
.writeInt(st
, LongInt(count
));
1899 if (count
= 0) then exit
;
1902 for i
:= 0 to High(gCorpses
) do
1904 if gCorpses
[i
] <> nil then
1907 utils
.writeStr(st
, gCorpses
[i
].FModelName
);
1909 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1910 // Ñîõðàíÿåì äàííûå òðóïà:
1911 gCorpses
[i
].SaveState(st
);
1917 procedure g_Player_Corpses_LoadState (st
: TStream
);
1925 g_Player_RemoveAllCorpses();
1927 // Êîëè÷åñòâî òðóïîâ:
1928 count
:= utils
.readLongInt(st
);
1929 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1931 if (count
= 0) then exit
;
1934 for i
:= 0 to count
-1 do
1937 str
:= utils
.readStr(st
);
1939 b
:= utils
.readBool(st
);
1941 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1942 // Çàãðóæàåì äàííûå òðóïà
1943 gCorpses
[i
].LoadState(st
);
1950 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1952 procedure TPlayer
.BFGHit();
1954 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1955 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1956 if g_Game_IsServer
and g_Game_IsNet
then
1957 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1958 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1962 procedure TPlayer
.ChangeModel(ModelName
: string);
1964 locModel
: TPlayerModel
;
1966 locModel
:= g_PlayerModel_Get(ModelName
);
1967 if locModel
= nil then Exit
;
1973 procedure TPlayer
.SetModel(ModelName
: string);
1977 m
:= g_PlayerModel_Get(ModelName
);
1980 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1981 m
:= g_PlayerModel_Get('doomer');
1984 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1989 if FModel
<> nil then
1994 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1995 FModel
.Color
:= FColor
1997 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1998 FModel
.SetWeapon(FCurrWeap
);
1999 FModel
.SetFlag(FFlag
);
2000 SetDirection(FDirection
);
2003 procedure TPlayer
.SetColor(Color
: TRGB
);
2006 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2007 if FModel
<> nil then FModel
.Color
:= Color
;
2010 procedure TPlayer
.SwitchTeam
;
2012 if g_Game_IsClient
then
2014 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
2016 if gGameOn
and FAlive
then
2017 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
2019 if FTeam
= TEAM_RED
then
2021 ChangeTeam(TEAM_BLUE
);
2022 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
2023 if g_Game_IsNet
then
2024 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
2028 ChangeTeam(TEAM_RED
);
2029 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
2030 if g_Game_IsNet
then
2031 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
2033 FPreferredTeam
:= FTeam
;
2036 procedure TPlayer
.ChangeTeam(Team
: Byte);
2043 TEAM_RED
, TEAM_BLUE
:
2044 FModel
.Color
:= TEAMCOLOR
[Team
];
2046 FModel
.Color
:= FColor
;
2048 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2049 MH_SEND_PlayerStats(FUID
);
2053 procedure TPlayer.CollideItem();
2058 if gItems = nil then Exit;
2059 if not FAlive then Exit;
2061 for i := 0 to High(gItems) do
2064 if (ItemType <> ITEM_NONE) and alive then
2065 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2066 PLAYER_RECT.Height, @Obj) then
2068 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2070 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2071 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2072 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2073 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2074 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2076 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2077 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2078 (gGameSettings.GameType = GT_SINGLE) and
2079 (g_Player_GetCount() > 1)) then
2080 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2086 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2088 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2089 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2093 constructor TPlayer
.Create();
2099 mEDamageType
:= HIT_SOME
;
2105 FSawSound
:= TPlayableSound
.Create();
2106 FSawSoundIdle
:= TPlayableSound
.Create();
2107 FSawSoundHit
:= TPlayableSound
.Create();
2108 FSawSoundSelect
:= TPlayableSound
.Create();
2109 FJetSoundFly
:= TPlayableSound
.Create();
2110 FJetSoundOn
:= TPlayableSound
.Create();
2111 FJetSoundOff
:= TPlayableSound
.Create();
2113 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2114 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2115 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2116 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2117 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2118 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2119 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2121 FSpectatePlayer
:= -1;
2125 FSavedState
.WaitRecall
:= False;
2131 FActualModelName
:= 'doomer';
2134 FObj
.Rect
:= PLAYER_RECT
;
2136 FBFGFireCounter
:= -1;
2137 FJustTeleported
:= False;
2141 releaseAllWeaponSwitchKeys();
2145 procedure TPlayer
.releaseAllWeaponSwitchKeys ();
2149 for f
:= 0 to High(weaponSwitchKeyReleased
) do weaponSwitchKeyReleased
[f
] := $03;
2152 procedure TPlayer
.weaponSwitchKeysStateChange (index
: Integer; pressed
: Boolean);
2154 Inc(index
, 2); // -2: prev; -1: next
2155 if (index
< 0) or (index
> High(weaponSwitchKeyReleased
)) then exit
;
2156 weaponSwitchKeyReleased
[index
] := weaponSwitchKeyReleased
[index
] or $02;
2157 if (pressed
) then weaponSwitchKeyReleased
[index
] := weaponSwitchKeyReleased
[index
] xor $02;
2160 function TPlayer
.isWeaponSwitchKeyReleased (index
: Integer): Boolean;
2162 Inc(index
, 2); // -2: prev; -1: next
2163 if (index
< 0) or (index
> High(weaponSwitchKeyReleased
)) then
2169 result
:= (weaponSwitchKeyReleased
[index
] and $01) <> 0;
2173 procedure TPlayer
.weaponSwitchKeysShiftNewStates ();
2177 // copy bit 1 to bit 0
2178 for f
:= 0 to High(weaponSwitchKeyReleased
) do
2180 weaponSwitchKeyReleased
[f
] :=
2181 (weaponSwitchKeyReleased
[f
] and $02) or
2182 ((weaponSwitchKeyReleased
[f
] shr 1) and $01);
2187 procedure TPlayer
.positionChanged (); inline;
2191 procedure TPlayer
.doDamage (v
: Integer);
2193 if (v
<= 0) then exit
;
2194 if (v
> 32767) then v
:= 32767;
2195 Damage(v
, 0, 0, 0, mEDamageType
);
2198 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2202 if (not g_Game_IsClient
) and (not FAlive
) then
2207 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2208 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2210 if not g_Game_IsClient
then
2213 if t
= HIT_TRAP
then
2215 // Ëîâóøêà óáèâàåò ñðàçó:
2217 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2219 if t
= HIT_SELF
then
2223 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2226 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2227 FMegaRulez
[MR_SUIT
] := 0;
2228 FMegaRulez
[MR_INVUL
] := 0;
2229 FMegaRulez
[MR_INVIS
] := 0;
2233 // Íî îò îñòàëüíîãî ñïàñàåò:
2234 if FMegaRulez
[MR_INVUL
] >= gTime
then
2241 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2242 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2243 (SpawnerUID
= FUID
) or
2244 (not SameTeam(FUID
, SpawnerUID
)) then
2246 FLastSpawnerUID
:= SpawnerUID
;
2248 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2249 if gBloodCount
> 0 then
2251 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2252 if value
div 4 <= c
then
2253 c
:= c
- (value
div 4)
2257 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2261 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2262 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2265 if t
= HIT_WATER
then
2266 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2267 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2272 Inc(FDamageBuffer
, value
);
2276 FPain
:= FPain
+ value
;
2279 if g_Game_IsServer
and g_Game_IsNet
then
2281 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2282 MH_SEND_PlayerStats(FUID
);
2283 MH_SEND_PlayerPos(False, FUID
);
2287 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2290 if g_Game_IsClient
then
2295 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2297 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2300 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2302 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2306 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2307 MH_SEND_PlayerStats(FUID
);
2310 destructor TPlayer
.Destroy();
2312 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2314 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2318 FSawSoundIdle
.Free();
2319 FSawSoundHit
.Free();
2320 FJetSoundFly
.Free();
2322 FJetSoundOff
.Free();
2324 if FPunchAnim
<> nil then
2330 procedure TPlayer
.DrawIndicator();
2332 indX
, indY
: Integer;
2338 indX
:= FObj
.X
+FObj
.Rect
.X
;
2339 indY
:= FObj
.Y
- 12;
2340 if g_Texture_Get('TEXTURE_PLAYER_INDICATOR', ID
) then
2342 e_GetTextureSize(ID
, @indW
, @indH
);
2343 e_Draw(ID
, indX
+ indW
div 2, indY
, 0, True, False);
2346 //e_TextureFontPrint(indX, indY, FName, gStdFont); // Shows player name overhead
2349 procedure TPlayer
.DrawBubble();
2351 bubX
, bubY
: Integer;
2354 Rw
, Gw
, Bw
: SmallInt;
2357 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= TDirection
.D_LEFT
, -4, 18);
2358 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2366 1: // simple textual non-bubble
2368 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2369 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2370 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2373 2: // advanced pixel-perfect bubble
2375 if FTeam
= TEAM_RED
then
2378 if FTeam
= TEAM_BLUE
then
2381 3: // colored bubble
2383 Rb
:= FModel
.Color
.R
;
2384 Gb
:= FModel
.Color
.G
;
2385 Bb
:= FModel
.Color
.B
;
2386 Rw
:= Min(Rb
* 2 + 64, 255);
2387 Gw
:= Min(Gb
* 2 + 64, 255);
2388 Bw
:= Min(Bb
* 2 + 64, 255);
2389 if (Abs(Rw
- Rb
) < 32)
2390 or (Abs(Gw
- Gb
) < 32)
2391 or (Abs(Bw
- Bb
) < 32) then
2393 Rb
:= Max(Rw
div 2 - 16, 0);
2394 Gb
:= Max(Gw
div 2 - 16, 0);
2395 Bb
:= Max(Bw
div 2 - 16, 0);
2398 4: // custom textured bubble
2400 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2401 if FDirection
= TDirection
.D_RIGHT
then
2402 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2404 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, TMirrorType
.Horizontal
);
2410 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2411 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2413 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2416 Dot
:= IfThen(FDirection
= TDirection
.D_LEFT
, 14, 5);
2417 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2418 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
);
2419 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
);
2420 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
);
2421 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
);
2425 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2426 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2427 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2430 procedure TPlayer
.Draw();
2435 Mirror
: TMirrorType
;
2439 if Direction
= TDirection
.D_RIGHT
then
2440 Mirror
:= TMirrorType
.None
2442 Mirror
:= TMirrorType
.Horizontal
;
2444 if FPunchAnim
<> nil then
2446 FPunchAnim
.Draw(FObj
.X
+IfThen(Direction
= TDirection
.D_LEFT
, 15-FObj
.Rect
.X
, FObj
.Rect
.X
-15),
2447 FObj
.Y
+FObj
.Rect
.Y
-11, Mirror
);
2448 if FPunchAnim
.played
then
2455 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2456 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2458 e_GetTextureSize(ID
, @w
, @h
);
2459 if FDirection
= TDirection
.D_LEFT
then
2460 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2461 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False)
2463 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2464 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False);
2467 if FMegaRulez
[MR_INVIS
] > gTime
then
2469 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2470 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2472 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2473 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2477 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 200)
2479 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2482 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 254);
2485 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2488 if g_debug_Frames
then
2490 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2492 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2493 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2497 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2499 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2500 if gAimLine
and alive
and
2501 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2506 procedure TPlayer
.DrawAim();
2507 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2512 {$IFDEF ENABLE_HOLMES}
2513 if isValidViewPort
and (self
= gPlayer1
) then
2515 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2519 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2520 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2522 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2526 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2531 wx
, wy
, xx
, yy
: Integer;
2535 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= TDirection
.D_LEFT
, 7, -7);
2536 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2545 1: begin // Chainsaw
2552 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2553 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2554 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2555 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2560 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2561 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2562 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2563 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2565 4: begin // Double Shotgun
2568 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2569 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2570 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2571 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2573 5: begin // Chaingun
2576 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2577 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2578 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2579 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2581 6: begin // Rocket Launcher
2584 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2585 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2586 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2587 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2589 7: begin // Plasmagun
2592 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2593 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2594 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2595 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2600 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2601 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2602 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2603 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2605 9: begin // Super Chaingun
2608 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2609 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2610 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2611 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2614 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2615 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2616 {$IF DEFINED(D2F_DEBUG)}
2617 drawCast(sz
, wx
, wy
, xx
, yy
);
2619 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2623 procedure TPlayer
.DrawGUI();
2626 X
, Y
, SY
, a
, p
, m
: Integer;
2630 stat
: TPlayerStatArray
;
2632 X
:= gPlayerScreenSize
.X
;
2633 SY
:= gPlayerScreenSize
.Y
;
2636 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2638 if gGameSettings
.GameMode
= GM_CTF
then
2642 if gGameSettings
.GameMode
= GM_CTF
then
2644 s
:= 'TEXTURE_PLAYER_REDFLAG';
2645 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2646 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2647 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2648 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2649 if g_Texture_Get(s
, ID
) then
2650 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2653 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2654 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2655 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2657 if gGameSettings
.GameMode
= GM_CTF
then
2659 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2660 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2661 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2662 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2663 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2664 if g_Texture_Get(s
, ID
) then
2665 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2668 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2669 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2670 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2673 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2674 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2677 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2678 e_Draw(ID
, X
+2, Y
, 0, True, False);
2680 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2684 s
:= IntToStr(Frags
);
2685 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2686 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2691 stat
:= g_Player_GetStats();
2696 for a
:= 0 to High(stat
) do
2697 if stat
[a
].Name
<> Name
then
2699 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2700 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2704 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2705 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2706 s
:= s
+IntToStr(Abs(Frags
-m
));
2708 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2709 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2712 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2714 s
:= IntToStr(Lives
);
2715 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2716 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2720 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2721 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2723 if R_BERSERK
in FRulez
then
2724 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2726 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2728 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2729 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2731 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2732 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2733 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2735 s
:= IntToStr(FArmor
);
2736 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2737 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2739 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2745 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2750 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2752 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2753 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2754 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2755 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2756 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2757 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2758 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2759 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2760 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2763 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2764 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2765 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2767 if R_KEY_RED
in FRulez
then
2768 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2770 if R_KEY_GREEN
in FRulez
then
2771 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2773 if R_KEY_BLUE
in FRulez
then
2774 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2776 if FJetFuel
> 0 then
2778 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2779 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2780 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2781 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2782 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2783 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2787 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2788 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2789 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2792 if gShowPing
and g_Game_IsClient
then
2794 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2795 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2801 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2802 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2803 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2806 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2807 s
:= _lc
[I_PLAYER_SPECT4
];
2808 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2809 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2810 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2816 procedure TPlayer
.DrawRulez();
2820 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2821 if FMegaRulez
[MR_INVUL
] >= gTime
then
2823 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2824 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2829 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2830 191, 191, 191, 0, TBlending
.Invert
);
2833 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2834 if FMegaRulez
[MR_SUIT
] >= gTime
then
2836 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2837 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2842 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2843 0, 96, 0, 200, TBlending
.None
);
2846 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2847 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2849 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2850 255, 0, 0, 200, TBlending
.None
);
2854 procedure TPlayer
.DrawPain();
2858 if FPain
= 0 then Exit
;
2862 if a
< 15 then h
:= 0
2863 else if a
< 35 then h
:= 1
2864 else if a
< 55 then h
:= 2
2865 else if a
< 75 then h
:= 3
2866 else if a
< 95 then h
:= 4
2869 //if a > 255 then a := 255;
2871 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2872 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2875 procedure TPlayer
.DrawPickup();
2879 if FPickup
= 0 then Exit
;
2883 if a
< 15 then h
:= 1
2884 else if a
< 35 then h
:= 2
2885 else if a
< 55 then h
:= 3
2886 else if a
< 75 then h
:= 4
2889 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2892 procedure TPlayer
.DoPunch();
2897 if FPunchAnim
<> nil then begin
2902 st
:= 'FRAMES_PUNCH';
2903 if R_BERSERK
in FRulez
then
2904 st
:= st
+ '_BERSERK';
2905 if FKeys
[KEY_UP
].Pressed
then
2907 else if FKeys
[KEY_DOWN
].Pressed
then
2909 g_Frames_Get(id
, st
);
2910 FPunchAnim
:= TAnimation
.Create(id
, False, 1);
2913 procedure TPlayer
.Fire();
2915 f
, DidFire
: Boolean;
2916 wx
, wy
, xd
, yd
: Integer;
2919 if g_Game_IsClient
then Exit
;
2920 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2921 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2929 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2934 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2935 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2936 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
2937 yd
:= wy
+firediry();
2943 if R_BERSERK
in FRulez
then
2945 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2946 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2947 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2950 locobj
.rect
.Width
:= 39;
2951 locobj
.rect
.Height
:= 52;
2952 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2953 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2954 locobj
.Accel
.X
:= xd
-wx
;
2955 locobj
.Accel
.y
:= yd
-wy
;
2957 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2958 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2960 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2962 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
2966 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2970 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2975 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2976 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2978 FSawSoundSelect
.Stop();
2980 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2982 else if not FSawSoundHit
.IsPlaying() then
2984 FSawSoundSelect
.Stop();
2985 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2988 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2994 if FAmmo
[A_BULLETS
] > 0 then
2996 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2997 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2998 Dec(FAmmo
[A_BULLETS
]);
2999 FFireAngle
:= FAngle
;
3002 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3003 GameVelX
, GameVelY
-2, SHELL_BULLET
);
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_FIRESHOTGUN', wx
, wy
);
3011 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3012 Dec(FAmmo
[A_SHELLS
]);
3013 FFireAngle
:= FAngle
;
3017 FShellType
:= SHELL_SHELL
;
3021 if FAmmo
[A_SHELLS
] >= 2 then
3023 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
3024 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3025 Dec(FAmmo
[A_SHELLS
], 2);
3026 FFireAngle
:= FAngle
;
3030 FShellType
:= SHELL_DBLSHELL
;
3034 if FAmmo
[A_BULLETS
] > 0 then
3036 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
3037 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
3038 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3039 Dec(FAmmo
[A_BULLETS
]);
3040 FFireAngle
:= FAngle
;
3043 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3044 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3047 WEAPON_ROCKETLAUNCHER
:
3048 if FAmmo
[A_ROCKETS
] > 0 then
3050 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
3051 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3052 Dec(FAmmo
[A_ROCKETS
]);
3053 FFireAngle
:= FAngle
;
3059 if FAmmo
[A_CELLS
] > 0 then
3061 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
3062 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3063 Dec(FAmmo
[A_CELLS
]);
3064 FFireAngle
:= FAngle
;
3070 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
3072 FBFGFireCounter
:= 17;
3073 if not FNoReload
then
3074 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
3075 Dec(FAmmo
[A_CELLS
], 40);
3079 WEAPON_SUPERPULEMET
:
3080 if FAmmo
[A_SHELLS
] > 0 then
3082 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3083 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
3084 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3085 Dec(FAmmo
[A_SHELLS
]);
3086 FFireAngle
:= FAngle
;
3089 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3090 GameVelX
, GameVelY
-2, SHELL_SHELL
);
3093 WEAPON_FLAMETHROWER
:
3094 if FAmmo
[A_FUEL
] > 0 then
3096 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
3097 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3099 FFireAngle
:= FAngle
;
3105 if g_Game_IsNet
then
3109 if FCurrWeap
<> WEAPON_BFG
then
3110 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
3112 if not FNoReload
then
3113 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
3116 MH_SEND_PlayerStats(FUID
);
3121 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
3122 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
3123 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
3126 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
3129 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
3130 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
3131 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
3132 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
3133 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
3138 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
3140 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
3141 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
3142 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
3145 procedure TPlayer
.JetpackOn
;
3149 FJetSoundOn
.SetPosition(0);
3150 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3154 procedure TPlayer
.JetpackOff
;
3158 FJetSoundOff
.SetPosition(0);
3159 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3162 procedure TPlayer
.CatchFire(Attacker
: Word);
3165 FFireAttacker
:= Attacker
;
3166 if g_Game_IsNet
and g_Game_IsServer
then
3167 MH_SEND_PlayerStats(FUID
);
3170 procedure TPlayer
.Jump();
3172 if gFly
or FJetpack
then
3174 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3175 if FObj
.Vel
.Y
> -VEL_FLY
then
3176 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3179 if FJetFuel
> 0 then
3181 if (FJetFuel
< 1) and g_Game_IsServer
then
3185 if g_Game_IsNet
then
3186 MH_SEND_PlayerStats(FUID
);
3192 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3194 FCanJetpack
:= False;
3196 // Ïðûãàåì èëè âñïëûâàåì:
3197 if (CollideLevel(0, 1) or
3198 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3199 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3200 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3202 FObj
.Vel
.Y
:= -VEL_JUMP
;
3203 FCanJetpack
:= False;
3207 if BodyInLiquid(0, 0) then
3208 FObj
.Vel
.Y
:= -VEL_SW
3209 else if (FJetFuel
> 0) and FCanJetpack
and
3210 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3214 if g_Game_IsNet
then
3215 MH_SEND_PlayerStats(FUID
);
3220 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3222 a
, i
, k
, ab
, ar
: Byte;
3226 srv
, netsrv
: Boolean;
3232 procedure PushItem(t
: Byte);
3236 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3237 it
:= g_Items_ByIdx(id
);
3238 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3240 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3241 (FObj
.Vel
.Y
div 2)-Random(9));
3242 it
.positionChanged(); // this updates spatial accelerators
3246 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3248 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3249 (FObj
.Vel
.Y
div 2)-Random(6));
3251 else // -3..+3; -3..0
3253 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3254 (FObj
.Vel
.Y
div 2)-Random(4));
3256 it
.positionChanged(); // this updates spatial accelerators
3259 if g_Game_IsNet
and g_Game_IsServer
then
3260 MH_SEND_ItemSpawn(True, id
);
3264 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3265 Srv
:= g_Game_IsServer
;
3266 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3267 if Srv
then FDeath
:= FDeath
+ 1;
3272 if not FPhysics
then
3278 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3280 if FLives
> 0 then FLives
:= FLives
- 1;
3281 if FLives
= 0 then FNoRespawn
:= True;
3284 // Íîìåð òèïà ñìåðòè:
3287 K_SIMPLEKILL
: a
:= 1;
3289 K_EXTRAHARDKILL
: a
:= 3;
3294 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3296 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3303 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3305 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3306 K_EXTRAHARDKILL
, K_FALLKILL
:
3307 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3310 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3314 K_HARDKILL
, K_EXTRAHARDKILL
:
3318 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3319 if (KillType
<> K_FALLKILL
) and (Srv
) then
3320 g_Monsters_killedp();
3322 if SpawnerUID
= FUID
then
3324 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3329 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3332 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3333 begin // Óáèò äðóãèì èãðîêîì
3334 KP
:= g_Player_Get(SpawnerUID
);
3335 if (KP
<> nil) and Srv
then
3337 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3338 if SameTeam(FUID
, SpawnerUID
) then
3348 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3349 Inc(gTeamStat
[KP
.Team
].Goals
,
3350 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3352 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3355 plr
:= g_Player_Get(SpawnerUID
);
3363 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3367 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3371 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3376 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3377 begin // Óáèò ìîíñòðîì
3378 mon
:= g_Monsters_ByUID(SpawnerUID
);
3382 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
3386 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3390 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3394 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3399 else // Îñîáûå òèïû ñìåðòè
3402 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3403 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3404 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3405 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3406 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3407 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3413 for a
:= WP_FIRST
to WP_LAST
do
3417 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3418 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3419 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3420 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3421 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3422 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3423 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3424 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3425 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3434 if R_ITEM_BACKPACK
in FRulez
then
3435 PushItem(ITEM_AMMO_BACKPACK
);
3437 // Âûáðîñ ðàêåòíîãî ðàíöà:
3438 if FJetFuel
> 0 then
3439 PushItem(ITEM_JETPACK
);
3442 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3444 if R_KEY_RED
in FRulez
then
3445 PushItem(ITEM_KEY_RED
);
3447 if R_KEY_GREEN
in FRulez
then
3448 PushItem(ITEM_KEY_GREEN
);
3450 if R_KEY_BLUE
in FRulez
then
3451 PushItem(ITEM_KEY_BLUE
);
3458 g_Player_CreateCorpse(Self
);
3460 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3461 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3467 for i
:= Low(gPlayers
) to High(gPlayers
) do
3469 if gPlayers
[i
] = nil then continue
;
3470 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3473 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3474 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3479 OldLR
:= gLMSRespawn
;
3480 if (gGameSettings
.GameMode
= GM_COOP
) then
3484 // everyone is dead, restart the map
3485 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3487 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3488 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3489 gLMSRespawnTime
:= gTime
+ 5000;
3491 else if (a
= 1) then
3493 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3494 if (gPlayers
[k
] = gPlayer1
) or
3495 (gPlayers
[k
] = gPlayer2
) then
3496 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3497 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3498 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3501 else if (gGameSettings
.GameMode
= GM_TDM
) then
3503 if (ab
= 0) and (ar
<> 0) then
3506 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3508 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3509 Inc(gTeamStat
[TEAM_RED
].Goals
);
3510 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3511 gLMSRespawnTime
:= gTime
+ 5000;
3513 else if (ar
= 0) and (ab
<> 0) then
3516 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3518 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3519 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3520 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3521 gLMSRespawnTime
:= gTime
+ 5000;
3523 else if (ar
= 0) and (ab
= 0) then
3526 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3528 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3529 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3530 gLMSRespawnTime
:= gTime
+ 5000;
3533 else if (gGameSettings
.GameMode
= GM_DM
) then
3537 if gPlayers
[k
] <> nil then
3540 // survivor is the winner
3541 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3543 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3546 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3547 gLMSRespawnTime
:= gTime
+ 5000;
3549 else if (a
= 0) then
3551 // everyone is dead, restart the map
3552 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3554 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3555 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3556 gLMSRespawnTime
:= gTime
+ 5000;
3559 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3561 if NetMode
= NET_SERVER
then
3562 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3564 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3570 MH_SEND_PlayerStats(FUID
);
3571 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3572 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3575 if srv
and FNoRespawn
then Spectate(True);
3576 FWantsInGame
:= True;
3579 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3581 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3582 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3585 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3587 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3588 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3591 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3593 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3594 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3595 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3596 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3597 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3598 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3599 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3600 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3603 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3605 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3606 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3607 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3608 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3611 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3613 if g_Game_IsClient
then Exit
;
3614 if Weapon
> High(FWeapon
) then Exit
;
3615 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3618 procedure TPlayer
.resetWeaponQueue ();
3621 FNextWeapDelay
:= 0;
3624 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3628 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3629 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
3630 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
3631 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3632 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3633 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3634 else result
:= (weapon
< length(FWeapon
));
3638 // return 255 for "no switch"
3639 function TPlayer
.getNextWeaponIndex (): Byte;
3642 wantThisWeapon
: array[0..64] of Boolean;
3643 weaponOrder
: array[0..16] of Integer; // value: index in `FWeapon`
3645 f
, dir
, cwi
, rwidx
, curlidx
: Integer;
3647 function real2log (ridx
: Integer): Integer;
3653 for f
:= 0 to High(weaponOrder
) do if (weaponOrder
[f
] = ridx
) then begin result
:= f
; exit
; end;
3659 result
:= 255; // default result: "no switch"
3661 // had weapon cycling on previous frame? remove that flag
3662 if (FNextWeap
and $2000) <> 0 then
3664 FNextWeap
:= FNextWeap
and $1FFF;
3665 FNextWeapDelay
:= 0;
3668 for f
:= 0 to High(weaponOrder
) do weaponOrder
[f
] := -1;
3670 // build weapon order (k8: i know, i know, learn how to do constants and such... gtfo, please!)
3671 // two knuckles are for "normal" and "berserk" (see `if` below -- it removes the one that is not needed)
3673 // bfg, launcher, plasma, flamethrower, ssg, minigun, sg, pistol, berserk, chainsaw, fist
3674 weaponOrder
[0] := WEAPON_SUPERPULEMET
;
3675 weaponOrder
[1] := WEAPON_BFG
;
3676 weaponOrder
[2] := WEAPON_ROCKETLAUNCHER
;
3677 weaponOrder
[3] := WEAPON_PLASMA
;
3678 weaponOrder
[4] := WEAPON_FLAMETHROWER
;
3679 weaponOrder
[5] := WEAPON_SHOTGUN2
;
3680 weaponOrder
[6] := WEAPON_CHAINGUN
;
3681 weaponOrder
[7] := WEAPON_SHOTGUN1
;
3682 weaponOrder
[8] := WEAPON_PISTOL
;
3683 weaponOrder
[9] := WEAPON_KASTET
+666; // berserk fist
3684 weaponOrder
[10] := WEAPON_SAW
;
3685 weaponOrder
[11] := WEAPON_KASTET
; // normal fist
3687 for f
:= 0 to High(weaponOrder
) do
3689 if (weaponOrder
[f
] = WEAPON_KASTET
) then
3691 // normal fist: remove if we have a berserk pack
3692 if (R_BERSERK
in FRulez
) then weaponOrder
[f
] := -1;
3695 if (weaponOrder
[f
] = WEAPON_KASTET
+666) then
3697 // berserk fist: remove if we don't have a berserk pack
3698 if (R_BERSERK
in FRulez
) then weaponOrder
[f
] := WEAPON_KASTET
else weaponOrder
[f
] := -1;
3706 WEAPON_SHOTGUN1 = 3;
3707 WEAPON_SHOTGUN2 = 4;
3708 WEAPON_CHAINGUN = 5;
3709 WEAPON_ROCKETLAUNCHER = 6;
3712 WEAPON_SUPERPULEMET = 9;
3713 WEAPON_FLAMETHROWER = 10;
3716 // cycling has priority
3717 if (FNextWeap
and $C000) <> 0 then
3719 if (FNextWeap
and $8000) <> 0 then dir
:= 1 else dir
:= -1; // should be reversed if we want "priority-driven cycling"
3720 FNextWeap
:= FNextWeap
or $2000; // we need this
3721 if FNextWeapDelay
> 0 then exit
; // cooldown time
3722 //cwi := real2log(FCurrWeap);
3723 //if (cwi < 0) then cwi := 0;
3725 for i
:= 0 to High(FWeapon
) do
3727 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3728 //rwidx := weaponOrder[cwi];
3729 rwidx
:= cwi
; // sorry
3730 if (rwidx
< 0) then continue
;
3731 if FWeapon
[rwidx
] then
3733 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d (dir=%d; log=%d)', [FCurrWeap, rwidx, dir, cwi]), TMsgType.Warning);
3734 result
:= Byte(rwidx
);
3735 //FNextWeapDelay := 10; //k8: not needed anymore
3744 for i
:= 0 to High(wantThisWeapon
) do wantThisWeapon
[i
] := false;
3747 curlidx
:= -1; // start from a weapon with a highest priority (-1, 'cause loop will immediately increment this index)
3749 for i
:= 0 to High(FWeapon
) do
3751 if (FNextWeap
and (1 shl i
)) <> 0 then
3756 wantThisWeapon
[cwi
] := true;
3758 // if we hit currently selected weapon, start seachring from it, so we'll get "next weaker" weapon
3759 if (i
= FCurrWeap
) then curlidx
:= cwi
; // compare real, start from logical
3764 // slow down alterations a little
3767 // more than one weapon requested, assume "alteration", and check alteration delay
3768 if FNextWeapDelay
> 0 then
3770 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), TMsgType.Warning);
3776 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3777 // but clear all counters if no weapon should be switched
3784 //e_WriteLog(Format('*** wwc=%d; currweap=%d; logweap=%d', [wwc, FCurrWeap, curlidx]), TMsgType.Warning);
3786 // find next weapon to switch onto
3788 for i
:= 0 to High(weaponOrder
) do
3790 cwi
:= (cwi
+length(weaponOrder
)+1) mod length(weaponOrder
);
3791 if (cwi
= curlidx
) then continue
; // skip current weapon
3792 if not wantThisWeapon
[cwi
] then continue
;
3793 rwidx
:= weaponOrder
[cwi
];
3794 if (rwidx
< 0) then continue
;
3795 //e_WriteLog(Format(' trying logical %d (real %d); has=%d, hasammo=%d', [cwi, rwidx, Integer(FWeapon[rwidx]), Integer(hasAmmoForWeapon(rwidx))]), TMsgType.Warning);
3796 if FWeapon
[rwidx
] and ((wwc
= 1) or hasAmmoForWeapon(rwidx
)) then
3798 //e_WriteLog(' I FOUND HER!', TMsgType.Warning);
3800 result
:= Byte(rwidx
);
3802 //FNextWeapDelay := 10; // anyway, 'cause why not; k8: not needed anymore
3807 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3811 procedure TPlayer
.RealizeCurrentWeapon();
3812 function switchAllowed (): Boolean;
3817 if FBFGFireCounter
<> -1 then
3819 if FTime
[T_SWITCH
] > gTime
then
3821 for i
:= WP_FIRST
to WP_LAST
do
3822 if FReloading
[i
] > 0 then
3830 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3831 //FNextWeap := FNextWeap and $1FFF;
3832 //HACK: alteration delay will be reset when player released any weapon switch key
3833 FNextWeapDelay
:= 0; //k8: just in case
3834 //if FNextWeapDelay > 0 then Dec(FNextWeapDelay); // "alteration delay"
3836 if not switchAllowed
then
3838 //HACK for weapon cycling
3839 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3843 nw
:= getNextWeaponIndex();
3844 if nw
= 255 then exit
; // don't reset anything here
3845 if nw
> High(FWeapon
) then
3847 // don't forget to reset queue here!
3848 //e_WriteLog(Format(' RealizeCurrentWeapon: WUTAFUUUU?! (%d)', [nw]), TMsgType.Warning);
3856 FTime
[T_SWITCH
] := gTime
+156;
3857 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3858 FModel
.SetWeapon(FCurrWeap
);
3859 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3863 procedure TPlayer
.NextWeapon();
3865 if g_Game_IsClient
then Exit
;
3869 procedure TPlayer
.PrevWeapon();
3871 if g_Game_IsClient
then Exit
;
3875 procedure TPlayer
.SetWeapon(W
: Byte);
3877 if FCurrWeap
<> W
then
3878 if W
= WEAPON_SAW
then
3879 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3882 FModel
.SetWeapon(CurrWeap
);
3886 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3888 function allowBerserkSwitching (): Boolean;
3890 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3892 if gBerserkAutoswitch
then exit
;
3893 if not conIsCheatsEnabled
then exit
;
3901 if g_Game_IsClient
then Exit
;
3903 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3904 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3909 if FHealth
< PLAYER_HP_SOFT
then
3911 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3915 if gFlash
= 2 then Inc(FPickup
, 5);
3919 if FHealth
< PLAYER_HP_SOFT
then
3921 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3925 if gFlash
= 2 then Inc(FPickup
, 5);
3929 if FArmor
< PLAYER_AP_SOFT
then
3931 FArmor
:= PLAYER_AP_SOFT
;
3934 if gFlash
= 2 then Inc(FPickup
, 5);
3938 if FArmor
< PLAYER_AP_LIMIT
then
3940 FArmor
:= PLAYER_AP_LIMIT
;
3943 if gFlash
= 2 then Inc(FPickup
, 5);
3947 if FHealth
< PLAYER_HP_LIMIT
then
3949 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3953 if gFlash
= 2 then Inc(FPickup
, 5);
3957 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3959 if FHealth
< PLAYER_HP_LIMIT
then
3960 FHealth
:= PLAYER_HP_LIMIT
;
3961 if FArmor
< PLAYER_AP_LIMIT
then
3962 FArmor
:= PLAYER_AP_LIMIT
;
3966 if gFlash
= 2 then Inc(FPickup
, 5);
3970 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3972 FWeapon
[WEAPON_SAW
] := True;
3974 if gFlash
= 2 then Inc(FPickup
, 5);
3975 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3978 ITEM_WEAPON_SHOTGUN1
:
3979 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3981 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3982 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3984 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3985 FWeapon
[WEAPON_SHOTGUN1
] := True;
3987 if gFlash
= 2 then Inc(FPickup
, 5);
3988 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3991 ITEM_WEAPON_SHOTGUN2
:
3992 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3994 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3996 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3997 FWeapon
[WEAPON_SHOTGUN2
] := True;
3999 if gFlash
= 2 then Inc(FPickup
, 5);
4000 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4003 ITEM_WEAPON_CHAINGUN
:
4004 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
4006 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
4008 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4009 FWeapon
[WEAPON_CHAINGUN
] := True;
4011 if gFlash
= 2 then Inc(FPickup
, 5);
4012 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4015 ITEM_WEAPON_ROCKETLAUNCHER
:
4016 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
4018 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
4020 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
4021 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
4023 if gFlash
= 2 then Inc(FPickup
, 5);
4024 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4028 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
4030 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
4032 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4033 FWeapon
[WEAPON_PLASMA
] := True;
4035 if gFlash
= 2 then Inc(FPickup
, 5);
4036 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4040 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
4042 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
4044 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4045 FWeapon
[WEAPON_BFG
] := True;
4047 if gFlash
= 2 then Inc(FPickup
, 5);
4048 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4051 ITEM_WEAPON_SUPERPULEMET
:
4052 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
4054 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
4056 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4057 FWeapon
[WEAPON_SUPERPULEMET
] := True;
4059 if gFlash
= 2 then Inc(FPickup
, 5);
4060 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4063 ITEM_WEAPON_FLAMETHROWER
:
4064 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
4066 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
4068 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4069 FWeapon
[WEAPON_FLAMETHROWER
] := True;
4071 if gFlash
= 2 then Inc(FPickup
, 5);
4072 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4076 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4078 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4081 if gFlash
= 2 then Inc(FPickup
, 5);
4084 ITEM_AMMO_BULLETS_BOX
:
4085 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4087 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4090 if gFlash
= 2 then Inc(FPickup
, 5);
4094 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4096 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4099 if gFlash
= 2 then Inc(FPickup
, 5);
4102 ITEM_AMMO_SHELLS_BOX
:
4103 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4105 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
4108 if gFlash
= 2 then Inc(FPickup
, 5);
4112 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4114 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4117 if gFlash
= 2 then Inc(FPickup
, 5);
4120 ITEM_AMMO_ROCKET_BOX
:
4121 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4123 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
4126 if gFlash
= 2 then Inc(FPickup
, 5);
4130 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4132 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4135 if gFlash
= 2 then Inc(FPickup
, 5);
4139 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4141 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4144 if gFlash
= 2 then Inc(FPickup
, 5);
4148 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4150 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4153 if gFlash
= 2 then Inc(FPickup
, 5);
4157 if not(R_ITEM_BACKPACK
in FRulez
) or
4158 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4159 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4160 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4161 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4162 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
4164 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4165 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4166 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4167 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4168 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4170 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4171 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4172 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4173 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4174 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4175 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4176 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4177 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4179 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
4182 if gFlash
= 2 then Inc(FPickup
, 5);
4186 if not(R_KEY_RED
in FRulez
) then
4188 Include(FRulez
, R_KEY_RED
);
4190 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4191 if gFlash
= 2 then Inc(FPickup
, 5);
4192 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4196 if not(R_KEY_GREEN
in FRulez
) then
4198 Include(FRulez
, R_KEY_GREEN
);
4200 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4201 if gFlash
= 2 then Inc(FPickup
, 5);
4202 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4206 if not(R_KEY_BLUE
in FRulez
) then
4208 Include(FRulez
, R_KEY_BLUE
);
4210 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4211 if gFlash
= 2 then Inc(FPickup
, 5);
4212 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4216 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4218 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4222 if gFlash
= 2 then Inc(FPickup
, 5);
4226 if FAir
< AIR_MAX
then
4231 if gFlash
= 2 then Inc(FPickup
, 5);
4236 if not (R_BERSERK
in FRulez
) then
4238 Include(FRulez
, R_BERSERK
);
4239 if allowBerserkSwitching
then
4241 FCurrWeap
:= WEAPON_KASTET
;
4243 FModel
.SetWeapon(WEAPON_KASTET
);
4248 if gFlash
= 2 then Inc(FPickup
, 5);
4250 FBerserk
:= gTime
+30000;
4255 if FHealth
< PLAYER_HP_SOFT
then
4257 FHealth
:= PLAYER_HP_SOFT
;
4258 FBerserk
:= gTime
+30000;
4266 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4268 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4271 if gFlash
= 2 then Inc(FPickup
, 5);
4275 if FHealth
< PLAYER_HP_LIMIT
then
4277 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4281 if gFlash
= 2 then Inc(FPickup
, 5);
4285 if FArmor
< PLAYER_AP_LIMIT
then
4287 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4290 if gFlash
= 2 then Inc(FPickup
, 5);
4294 if FJetFuel
< JET_MAX
then
4296 FJetFuel
:= JET_MAX
;
4299 if gFlash
= 2 then Inc(FPickup
, 5);
4303 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4305 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4308 if gFlash
= 2 then Inc(FPickup
, 5);
4313 procedure TPlayer
.Touch();
4317 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4320 // Áðîñèòü ôëàã òîâàðèùó:
4321 if gGameSettings
.GameMode
= GM_CTF
then
4326 procedure TPlayer
.Push(vx
, vy
: Integer);
4328 if (not FPhysics
) and FGhost
then
4330 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4331 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4332 if g_Game_IsNet
and g_Game_IsServer
then
4333 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4336 procedure TPlayer
.Reset(Force
: Boolean);
4342 FTime
[T_RESPAWN
] := 0;
4343 FTime
[T_FLAGCAP
] := 0;
4356 FSpectator
:= False;
4359 FSpectatePlayer
:= -1;
4360 FNoRespawn
:= False;
4362 FLives
:= gGameSettings
.MaxLives
;
4367 procedure TPlayer
.SoftReset();
4373 FBFGFireCounter
:= -1;
4381 SetAction(A_STAND
, True);
4384 function TPlayer
.GetRespawnPoint(): Byte;
4389 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4391 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4392 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4394 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4396 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4397 if Self
= gPlayer1
then
4398 c
:= RESPAWNPOINT_PLAYER1
4400 c
:= RESPAWNPOINT_PLAYER2
;
4401 if g_Map_GetPointCount(c
) > 0 then
4407 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4408 if Self
= gPlayer1
then
4409 c
:= RESPAWNPOINT_PLAYER2
4411 c
:= RESPAWNPOINT_PLAYER1
;
4412 if g_Map_GetPointCount(c
) > 0 then
4419 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4420 if Random(2) = 0 then
4421 c
:= RESPAWNPOINT_PLAYER1
4423 c
:= RESPAWNPOINT_PLAYER2
;
4424 if g_Map_GetPointCount(c
) > 0 then
4431 // Òî÷êà ëþáîé èç êîìàíä
4432 if Random(2) = 0 then
4433 c
:= RESPAWNPOINT_RED
4435 c
:= RESPAWNPOINT_BLUE
;
4436 if g_Map_GetPointCount(c
) > 0 then
4443 c
:= RESPAWNPOINT_DM
;
4444 if g_Map_GetPointCount(c
) > 0 then
4452 if gGameSettings
.GameMode
= GM_DM
then
4455 c
:= RESPAWNPOINT_DM
;
4456 if g_Map_GetPointCount(c
) > 0 then
4462 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4463 if Random(2) = 0 then
4464 c
:= RESPAWNPOINT_PLAYER1
4466 c
:= RESPAWNPOINT_PLAYER2
;
4467 if g_Map_GetPointCount(c
) > 0 then
4473 // Òî÷êà ëþáîé èç êîìàíä
4474 if Random(2) = 0 then
4475 c
:= RESPAWNPOINT_RED
4477 c
:= RESPAWNPOINT_BLUE
;
4478 if g_Map_GetPointCount(c
) > 0 then
4486 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4488 // Òî÷êà ñâîåé êîìàíäû
4489 c
:= RESPAWNPOINT_DM
;
4490 if FTeam
= TEAM_RED
then
4491 c
:= RESPAWNPOINT_RED
;
4492 if FTeam
= TEAM_BLUE
then
4493 c
:= RESPAWNPOINT_BLUE
;
4494 if g_Map_GetPointCount(c
) > 0 then
4501 c
:= RESPAWNPOINT_DM
;
4502 if g_Map_GetPointCount(c
) > 0 then
4508 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4509 if Random(2) = 0 then
4510 c
:= RESPAWNPOINT_PLAYER1
4512 c
:= RESPAWNPOINT_PLAYER2
;
4513 if g_Map_GetPointCount(c
) > 0 then
4519 // Òî÷êà äðóãîé êîìàíäû
4520 c
:= RESPAWNPOINT_DM
;
4521 if FTeam
= TEAM_RED
then
4522 c
:= RESPAWNPOINT_BLUE
;
4523 if FTeam
= TEAM_BLUE
then
4524 c
:= RESPAWNPOINT_RED
;
4525 if g_Map_GetPointCount(c
) > 0 then
4533 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4535 RespawnPoint
: TRespawnPoint
;
4541 FBFGFireCounter
:= -1;
4546 if not g_Game_IsServer
then
4550 FWantsInGame
:= True;
4551 FJustTeleported
:= True;
4554 FTime
[T_RESPAWN
] := 0;
4558 // if server changes MaxLives we gotta be ready
4559 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4561 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4562 if FTime
[T_RESPAWN
] > gTime
then
4565 // Ïðîñðàë âñå æèçíè:
4568 if not FSpectator
then Spectate(True);
4569 FWantsInGame
:= True;
4573 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4574 begin // "Ñâîÿ èãðà"
4575 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4576 FRulez
:= FRulez
-[R_BERSERK
];
4578 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4580 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4581 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4584 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4585 c
:= GetRespawnPoint();
4590 // Âîñêðåøåíèå áåç îðóæèÿ:
4593 FHealth
:= PLAYER_HP_SOFT
;
4599 for a
:= WP_FIRST
to WP_LAST
do
4601 FWeapon
[a
] := False;
4605 FWeapon
[WEAPON_PISTOL
] := True;
4606 FWeapon
[WEAPON_KASTET
] := True;
4607 FCurrWeap
:= WEAPON_PISTOL
;
4610 FModel
.SetWeapon(FCurrWeap
);
4612 for b
:= A_BULLETS
to A_HIGH
do
4615 FAmmo
[A_BULLETS
] := 50;
4617 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4618 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4619 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4620 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4621 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4623 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4624 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4629 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4630 if not g_Map_GetPoint(c
, RespawnPoint
) then
4632 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4636 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4637 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4638 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4644 FDirection
:= RespawnPoint
.Direction
;
4645 if FDirection
= TDirection
.D_LEFT
then
4650 SetAction(A_STAND
, True);
4651 FModel
.Direction
:= FDirection
;
4653 for a
:= Low(FTime
) to High(FTime
) do
4656 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4661 FCanJetpack
:= False;
4666 // Àíèìàöèÿ âîçðîæäåíèÿ:
4667 if (not gLoadGameMode
) and (not Silent
) then
4668 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4670 Anim
:= TAnimation
.Create(ID
, False, 3);
4671 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4672 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4676 FSpectator
:= False;
4679 FSpectatePlayer
:= -1;
4682 if (gPlayer1
= nil) and (gLMSPID1
= FUID
) then
4684 if (gPlayer2
= nil) and (gLMSPID2
= FUID
) then
4687 if g_Game_IsNet
then
4689 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4690 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4692 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4693 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4698 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4701 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4702 else if (not NoMove
) then
4704 GameX
:= gMapInfo
.Width
div 2;
4705 GameY
:= gMapInfo
.Height
div 2;
4714 FWantsInGame
:= False;
4719 if Self
= gPlayer1
then
4724 if Self
= gPlayer2
then
4731 if g_Game_IsNet
then
4732 MH_SEND_PlayerStats(FUID
);
4735 procedure TPlayer
.SwitchNoClip
;
4739 FGhost
:= not FGhost
;
4740 FPhysics
:= not FGhost
;
4752 procedure TPlayer
.Run(Direction
: TDirection
);
4756 if MAX_RUNVEL
> 8 then
4760 if Direction
= TDirection
.D_LEFT
then
4762 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4763 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4766 if FObj
.Vel
.X
< MAX_RUNVEL
then
4767 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4769 // Âîçìîæíî, ïèíàåì êóñêè:
4770 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4772 b
:= Abs(FObj
.Vel
.X
);
4773 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4774 for a
:= 0 to High(gGibs
) do
4776 if gGibs
[a
].alive
and
4777 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4778 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4781 if FObj
.Vel
.X
< 0 then
4783 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4787 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4789 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4797 procedure TPlayer
.SeeDown();
4799 SetAction(A_SEEDOWN
);
4801 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4803 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4806 procedure TPlayer
.SeeUp();
4810 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4812 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4815 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4823 A_ATTACK
: Prior
:= 2;
4824 A_SEEUP
: Prior
:= 1;
4825 A_SEEDOWN
: Prior
:= 1;
4826 A_ATTACKUP
: Prior
:= 2;
4827 A_ATTACKDOWN
: Prior
:= 2;
4832 if (Prior
> FActionPrior
) or Force
then
4833 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4835 FActionPrior
:= Prior
;
4836 FActionAnim
:= Action
;
4837 FActionForce
:= Force
;
4838 FActionChanged
:= True;
4841 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4844 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4846 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4847 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4848 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4849 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4852 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4859 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4861 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4862 if g_Game_IsServer
and g_Game_IsNet
then
4863 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4867 FJustTeleported
:= True;
4872 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4874 Anim
:= TAnimation
.Create(ID
, False, 3);
4877 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4878 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4879 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4880 if g_Game_IsServer
and g_Game_IsNet
then
4881 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4882 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4886 FObj
.X
:= X
-PLAYER_RECT
.X
;
4887 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4888 if FAlive
and FGhost
then
4894 if not g_Game_IsNet
then
4898 SetDirection(TDirection
.D_LEFT
);
4904 SetDirection(TDirection
.D_RIGHT
);
4910 if FDirection
= TDirection
.D_RIGHT
then
4912 SetDirection(TDirection
.D_LEFT
);
4917 SetDirection(TDirection
.D_RIGHT
);
4923 if not silent
and (Anim
<> nil) then
4925 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4926 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4929 if g_Game_IsServer
and g_Game_IsNet
then
4930 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4931 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4938 function nonz(a
: Single): Single;
4946 function TPlayer
.followCorpse(): Boolean;
4951 if FAlive
or FSpectator
then
4953 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
4955 for i
:= 0 to High(gCorpses
) do
4956 if gCorpses
[i
] <> nil then
4957 if gCorpses
[i
].FPlayerUID
= FUID
then
4960 FObj
.X
:= gCorpses
[i
].FObj
.X
;
4961 FObj
.Y
:= gCorpses
[i
].FObj
.Y
;
4962 FObj
.Vel
.X
:= gCorpses
[i
].FObj
.Vel
.X
;
4963 FObj
.Vel
.Y
:= gCorpses
[i
].FObj
.Vel
.Y
;
4964 FObj
.Accel
.X
:= gCorpses
[i
].FObj
.Accel
.X
;
4965 FObj
.Accel
.Y
:= gCorpses
[i
].FObj
.Accel
.Y
;
4970 procedure TPlayer
.Update();
4973 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4974 blockmon
, headwater
, dospawn
: Boolean;
4979 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4980 AnyServer
:= g_Game_IsServer
;
4982 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4983 DoLerp(NetInterpLevel
+ 1)
4989 if FClientID
>= 0 then
4991 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4992 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4993 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
5002 if FAlive
and (FPunchAnim
<> nil) then
5003 FPunchAnim
.Update();
5005 if FAlive
and (gFly
or FJetpack
) then
5008 if FDirection
= TDirection
.D_LEFT
then
5013 if FAlive
and (not FGhost
) then
5015 if FKeys
[KEY_UP
].Pressed
then
5017 if FKeys
[KEY_DOWN
].Pressed
then
5021 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
5024 i
:= g_basic
.Sign(FIncCam
);
5025 FIncCam
:= Abs(FIncCam
);
5026 DecMin(FIncCam
, 5, 0);
5027 FIncCam
:= FIncCam
*i
;
5030 // no need to do that each second frame, weapon queue will take care of it
5031 if FAlive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
5032 if FAlive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
5034 if gTime
mod (GAME_TICK
*2) <> 0 then
5036 if (FObj
.Vel
.X
= 0) and FAlive
then
5038 if FKeys
[KEY_LEFT
].Pressed
then
5039 Run(TDirection
.D_LEFT
);
5040 if FKeys
[KEY_RIGHT
].Pressed
then
5041 Run(TDirection
.D_RIGHT
);
5046 if not followCorpse() then
5047 g_Obj_Move(@FObj
, True, True, True);
5048 positionChanged(); // this updates spatial accelerators
5054 FActionChanged
:= False;
5058 // Let alive player do some actions
5059 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
5060 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
5061 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
5062 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
5063 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
5064 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
5065 if FKeys
[KEY_JUMP
].Pressed
then Jump()
5068 if AnyServer
and FJetpack
then
5072 if NetServer
then MH_SEND_PlayerStats(FUID
);
5074 FCanJetpack
:= True;
5081 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
5083 if FKeys
[k
].Pressed
then
5091 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5094 if (FTime
[T_RESPAWN
] <= gTime
) and
5095 gGameOn
and (not FAlive
) then
5097 if (g_Player_GetCount() > 1) then
5101 gExit
:= EXIT_RESTART
;
5106 // Dead spectator actions
5109 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
5110 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
5114 if (FSpectatePlayer
>= High(gPlayers
)) then
5115 FSpectatePlayer
:= -1
5119 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
5120 if gPlayers
[I
] <> nil then
5121 if gPlayers
[I
].alive
then
5122 if gPlayers
[I
].UID
<> FUID
then
5124 FSpectatePlayer
:= I
;
5129 if not SetSpect
then FSpectatePlayer
:= -1;
5140 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5142 FYTo
:= FObj
.Y
- 32;
5143 FSpectatePlayer
:= -1;
5145 if FKeys
[KEY_DOWN
].Pressed
then
5147 FYTo
:= FObj
.Y
+ 32;
5148 FSpectatePlayer
:= -1;
5150 if FKeys
[KEY_LEFT
].Pressed
then
5152 FXTo
:= FObj
.X
- 32;
5153 FSpectatePlayer
:= -1;
5155 if FKeys
[KEY_RIGHT
].Pressed
then
5157 FXTo
:= FObj
.X
+ 32;
5158 FSpectatePlayer
:= -1;
5161 if (FXTo
< -64) then
5163 else if (FXTo
> gMapInfo
.Width
+ 32) then
5164 FXTo
:= gMapInfo
.Width
+ 32;
5165 if (FYTo
< -72) then
5167 else if (FYTo
> gMapInfo
.Height
+ 32) then
5168 FYTo
:= gMapInfo
.Height
+ 32;
5173 if not followCorpse() then
5174 g_Obj_Move(@FObj
, True, True, True);
5175 positionChanged(); // this updates spatial accelerators
5182 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5183 if gPlayers
[FSpectatePlayer
] <> nil then
5184 if gPlayers
[FSpectatePlayer
].alive
then
5186 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
5187 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
5191 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5192 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5193 PANEL_BLOCKMON
, True);
5194 headwater
:= HeadInLiquid(0, 0);
5196 // Ñîïðîòèâëåíèå âîçäóõà:
5197 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5198 if FObj
.Vel
.X
<> 0 then
5199 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5201 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5202 DecMin(FPain
, 5, 0);
5203 DecMin(FPickup
, 1, 0);
5205 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5207 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5208 FMegaRulez
[MR_SUIT
] := 0;
5209 FMegaRulez
[MR_INVUL
] := 0;
5210 FMegaRulez
[MR_INVIS
] := 0;
5211 Kill(K_FALLKILL
, 0, HIT_FALL
);
5218 if FCurrWeap
= WEAPON_SAW
then
5219 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5220 FSawSoundSelect
.IsPlaying()) then
5221 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5224 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5225 (not FJetSoundOff
.IsPlaying()) then
5227 FJetSoundFly
.SetPosition(0);
5228 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5231 for b
:= WP_FIRST
to WP_LAST
do
5232 if FReloading
[b
] > 0 then
5238 if FShellTimer
> -1 then
5239 if FShellTimer
= 0 then
5241 if FShellType
= SHELL_SHELL
then
5242 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5243 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5244 else if FShellType
= SHELL_DBLSHELL
then
5246 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5247 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5248 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5249 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5252 end else Dec(FShellTimer
);
5254 if (FBFGFireCounter
> -1) then
5255 if FBFGFireCounter
= 0 then
5259 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5260 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5261 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5262 yd
:= wy
+firediry();
5263 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5264 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5265 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5266 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5267 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5270 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5271 FBFGFireCounter
:= -1;
5274 FBFGFireCounter
:= 0
5276 Dec(FBFGFireCounter
);
5278 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5280 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5282 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5285 if (headwater
or blockmon
) then
5291 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5294 else if (FAir
mod 31 = 0) and not blockmon
then
5296 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5297 if Random(2) = 0 then
5298 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5300 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5302 end else if FAir
< AIR_DEF
then
5305 if FFireTime
> 0 then
5307 if BodyInLiquid(0, 0) then
5312 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5314 if FMegaRulez
[MR_SUIT
] = gTime
then
5321 if FFirePainTime
<= 0 then
5323 if g_Game_IsServer
then
5324 Damage(5, FFireAttacker
, 0, 0, HIT_FLAME
);
5325 FFirePainTime
:= 18;
5327 FFirePainTime
:= FFirePainTime
- 1;
5328 FFireTime
:= FFireTime
- 1;
5329 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5330 MH_SEND_PlayerStats(FUID
);
5334 if FDamageBuffer
> 0 then
5336 if FDamageBuffer
>= 9 then
5340 if FDamageBuffer
< 30 then i
:= 9
5341 else if FDamageBuffer
< 100 then i
:= 18
5345 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5346 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5347 FHealth
:= FHealth
-ii
;
5350 FHealth
:= FHealth
+FArmor
;
5355 if FHealth
<= 0 then
5356 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5357 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5358 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5362 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5363 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5364 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5365 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5372 end; // if FAlive then ...
5374 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5376 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5377 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5378 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5379 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5381 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5382 then SetAction(A_STAND
, True);
5384 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5386 for b
:= Low(FKeys
) to High(FKeys
) do
5387 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5391 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5393 x
:= FObj
.X
+PLAYER_RECT
.X
;
5394 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5395 w
:= PLAYER_RECT
.Width
;
5396 h
:= PLAYER_RECT
.Height
;
5400 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5402 if (dx
<> 0) or (dy
<> 0) then
5411 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5413 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5414 FObj
.Y
+PLAYER_RECT
.Y
,
5421 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5423 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5424 FObj
.Y
+PLAYER_RECT
.Y
,
5428 Panel
.Width
, Panel
.Height
);
5431 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5433 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5434 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5435 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5436 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5439 function g_Player_ValidName(Name
: string): Boolean;
5445 if gPlayers
= nil then Exit
;
5447 for a
:= 0 to High(gPlayers
) do
5448 if gPlayers
[a
] <> nil then
5449 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5456 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5460 d
:= FModel
.Direction
;
5462 FModel
.Direction
:= Direction
;
5463 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5465 FDirection
:= Direction
;
5468 function TPlayer
.GetKeys(): Byte;
5472 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5473 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5474 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5476 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5477 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5480 procedure TPlayer
.Use();
5484 if FTime
[T_USE
] > gTime
then Exit
;
5486 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5487 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5489 for a
:= 0 to High(gPlayers
) do
5490 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5491 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5492 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5493 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5495 gPlayers
[a
].Touch();
5496 if g_Game_IsNet
and g_Game_IsServer
then
5497 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5500 FTime
[T_USE
] := gTime
+120;
5503 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5507 WX
, WY
, XD
, YD
: Integer;
5519 if R_BERSERK
in FRulez
then
5521 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5522 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5523 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5526 locobj
.rect
.Width
:= 39;
5527 locobj
.rect
.Height
:= 52;
5528 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5529 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5530 locobj
.Accel
.X
:= xd
-wx
;
5531 locobj
.Accel
.y
:= yd
-wy
;
5533 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5534 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5536 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5540 FPain
:= min(FPain
+ 25, 50);
5542 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5547 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5548 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5550 FSawSoundSelect
.Stop();
5552 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5554 else if not FSawSoundHit
.IsPlaying() then
5556 FSawSoundSelect
.Stop();
5557 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5564 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5565 FFireAngle
:= FAngle
;
5567 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5568 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5573 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5574 FFireAngle
:= FAngle
;
5577 FShellType
:= SHELL_SHELL
;
5582 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5583 FFireAngle
:= FAngle
;
5586 FShellType
:= SHELL_DBLSHELL
;
5591 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5592 FFireAngle
:= FAngle
;
5594 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5595 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5598 WEAPON_ROCKETLAUNCHER
:
5600 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5601 FFireAngle
:= FAngle
;
5607 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5608 FFireAngle
:= FAngle
;
5614 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5615 FFireAngle
:= FAngle
;
5619 WEAPON_SUPERPULEMET
:
5621 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5622 FFireAngle
:= FAngle
;
5624 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5625 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5628 WEAPON_FLAMETHROWER
:
5630 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5631 FFireAngle
:= FAngle
;
5638 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5639 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5640 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5643 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5645 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5646 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5649 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5653 if NetInterpLevel
< 1 then
5663 AX
:= Abs(FXTo
- FObj
.X
);
5664 AY
:= Abs(FYTo
- FObj
.Y
);
5665 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5667 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5672 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5674 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5675 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5676 PANEL_LIFTUP
, False) then Result
:= -1
5678 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5679 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5680 PANEL_LIFTDOWN
, False) then Result
:= 1
5684 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5691 if Flag
= FLAG_NONE
then
5694 if not g_Game_IsServer
then Exit
;
5696 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5697 if (Flag
= FTeam
) and
5698 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5699 (FFlag
<> FLAG_NONE
) then
5701 if FFlag
= FLAG_RED
then
5702 s
:= _lc
[I_PLAYER_FLAG_RED
]
5704 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5706 evtype
:= FLAG_STATE_SCORED
;
5708 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5709 Insert('.', ts
, Length(ts
) + 1 - 3);
5710 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5712 g_Map_ResetFlag(FFlag
);
5713 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5715 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5718 if g_Game_IsNet
then
5720 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5724 gFlags
[FFlag
].CaptureTime
:= 0;
5729 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5730 if (Flag
= FTeam
) and
5731 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5733 if Flag
= FLAG_RED
then
5734 s
:= _lc
[I_PLAYER_FLAG_RED
]
5736 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5738 evtype
:= FLAG_STATE_RETURNED
;
5739 gFlags
[Flag
].CaptureTime
:= 0;
5741 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5743 g_Map_ResetFlag(Flag
);
5744 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5747 if g_Game_IsNet
then
5749 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5755 // Ïîäîáðàë ÷óæîé ôëàã:
5756 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5760 if Flag
= FLAG_RED
then
5761 s
:= _lc
[I_PLAYER_FLAG_RED
]
5763 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5765 evtype
:= FLAG_STATE_CAPTURED
;
5767 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5769 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5771 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5774 if g_Game_IsNet
then
5776 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5782 procedure TPlayer
.SetFlag(Flag
: Byte);
5785 if FModel
<> nil then
5786 FModel
.SetFlag(FFlag
);
5789 function TPlayer
.DropFlag(): Boolean;
5794 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5796 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5797 with gFlags
[FFlag
] do
5801 Direction
:= FDirection
;
5802 State
:= FLAG_STATE_DROPPED
;
5804 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5805 (FObj
.Vel
.Y
div 2)-2+Random(5));
5806 positionChanged(); // this updates spatial accelerators
5808 if FFlag
= FLAG_RED
then
5809 s
:= _lc
[I_PLAYER_FLAG_RED
]
5811 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5813 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5814 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5816 if g_Game_IsNet
then
5817 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5823 procedure TPlayer
.GetSecret();
5828 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5830 Assert(Key
<= High(FKeys
));
5832 FKeys
[Key
].Pressed
:= True;
5833 FKeys
[Key
].Time
:= Time
;
5836 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5838 Result
:= FKeys
[K
].Pressed
;
5841 procedure TPlayer
.ReleaseKeys();
5845 for a
:= Low(FKeys
) to High(FKeys
) do
5847 FKeys
[a
].Pressed
:= False;
5852 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5856 function TPlayer
.firediry(): Integer;
5858 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5859 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5863 procedure TPlayer
.RememberState();
5867 FSavedState
.Health
:= FHealth
;
5868 FSavedState
.Armor
:= FArmor
;
5869 FSavedState
.Air
:= FAir
;
5870 FSavedState
.JetFuel
:= FJetFuel
;
5871 FSavedState
.CurrWeap
:= FCurrWeap
;
5872 FSavedState
.NextWeap
:= FNextWeap
;
5873 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5876 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5878 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5880 FSavedState
.Rulez
:= FRulez
;
5881 FSavedState
.WaitRecall
:= True;
5884 procedure TPlayer
.RecallState();
5888 if not FSavedState
.WaitRecall
then Exit
;
5890 FHealth
:= FSavedState
.Health
;
5891 FArmor
:= FSavedState
.Armor
;
5892 FAir
:= FSavedState
.Air
;
5893 FJetFuel
:= FSavedState
.JetFuel
;
5894 FCurrWeap
:= FSavedState
.CurrWeap
;
5895 FNextWeap
:= FSavedState
.NextWeap
;
5896 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5899 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5901 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5903 FRulez
:= FSavedState
.Rulez
;
5904 FSavedState
.WaitRecall
:= False;
5906 if gGameSettings
.GameType
= GT_SERVER
then
5907 MH_SEND_PlayerStats(FUID
);
5910 procedure TPlayer
.SaveState (st
: TStream
);
5916 utils
.writeSign(st
, 'PLYR');
5917 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
5919 utils
.writeBool(st
, FIamBot
);
5921 utils
.writeInt(st
, Word(FUID
));
5923 utils
.writeStr(st
, FName
);
5925 utils
.writeInt(st
, Byte(FTeam
));
5927 utils
.writeBool(st
, FAlive
);
5928 // Èçðàñõîäîâàë ëè âñå æèçíè
5929 utils
.writeBool(st
, FNoRespawn
);
5931 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
5932 utils
.writeInt(st
, Byte(b
));
5934 utils
.writeInt(st
, LongInt(FHealth
));
5936 utils
.writeInt(st
, Byte(FLives
));
5938 utils
.writeInt(st
, LongInt(FArmor
));
5940 utils
.writeInt(st
, LongInt(FAir
));
5942 utils
.writeInt(st
, LongInt(FJetFuel
));
5944 utils
.writeInt(st
, LongInt(FPain
));
5946 utils
.writeInt(st
, LongInt(FKills
));
5948 utils
.writeInt(st
, LongInt(FMonsterKills
));
5950 utils
.writeInt(st
, LongInt(FFrags
));
5952 utils
.writeInt(st
, Byte(FFragCombo
));
5953 // Âðåìÿ ïîñëåäíåãî ôðàãà
5954 utils
.writeInt(st
, LongWord(FLastFrag
));
5956 utils
.writeInt(st
, LongInt(FDeath
));
5958 utils
.writeInt(st
, Byte(FFlag
));
5960 utils
.writeInt(st
, LongInt(FSecrets
));
5962 utils
.writeInt(st
, Byte(FCurrWeap
));
5964 utils
.writeInt(st
, Word(FNextWeap
));
5966 utils
.writeInt(st
, Byte(FNextWeapDelay
));
5967 // Âðåìÿ çàðÿäêè BFG
5968 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
5970 utils
.writeInt(st
, LongInt(FDamageBuffer
));
5971 // Ïîñëåäíèé óäàðèâøèé
5972 utils
.writeInt(st
, Word(FLastSpawnerUID
));
5973 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
5974 utils
.writeInt(st
, Byte(FLastHit
));
5976 Obj_SaveState(st
, @FObj
);
5977 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
5978 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
5979 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
5980 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
5982 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
5983 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
5984 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
5986 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
5987 // Íàëè÷èå êðàñíîãî êëþ÷à
5988 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
5989 // Íàëè÷èå çåëåíîãî êëþ÷à
5990 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
5991 // Íàëè÷èå ñèíåãî êëþ÷à
5992 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
5994 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
5995 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
5996 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
5997 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
5998 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
6000 utils
.writeStr(st
, FModel
.Name
);
6002 utils
.writeInt(st
, Byte(FColor
.R
));
6003 utils
.writeInt(st
, Byte(FColor
.G
));
6004 utils
.writeInt(st
, Byte(FColor
.B
));
6008 procedure TPlayer
.LoadState (st
: TStream
);
6017 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
6018 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
6020 FIamBot
:= utils
.readBool(st
);
6022 FUID
:= utils
.readWord(st
);
6024 str
:= utils
.readStr(st
);
6025 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
6027 FTeam
:= utils
.readByte(st
);
6029 FAlive
:= utils
.readBool(st
);
6030 // Èçðàñõîäîâàë ëè âñå æèçíè
6031 FNoRespawn
:= utils
.readBool(st
);
6033 b
:= utils
.readByte(st
);
6034 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
6036 FHealth
:= utils
.readLongInt(st
);
6038 FLives
:= utils
.readByte(st
);
6040 FArmor
:= utils
.readLongInt(st
);
6042 FAir
:= utils
.readLongInt(st
);
6044 FJetFuel
:= utils
.readLongInt(st
);
6046 FPain
:= utils
.readLongInt(st
);
6048 FKills
:= utils
.readLongInt(st
);
6050 FMonsterKills
:= utils
.readLongInt(st
);
6052 FFrags
:= utils
.readLongInt(st
);
6054 FFragCombo
:= utils
.readByte(st
);
6055 // Âðåìÿ ïîñëåäíåãî ôðàãà
6056 FLastFrag
:= utils
.readLongWord(st
);
6058 FDeath
:= utils
.readLongInt(st
);
6060 FFlag
:= utils
.readByte(st
);
6062 FSecrets
:= utils
.readLongInt(st
);
6064 FCurrWeap
:= utils
.readByte(st
);
6066 FNextWeap
:= utils
.readWord(st
);
6068 FNextWeapDelay
:= utils
.readByte(st
);
6069 // Âðåìÿ çàðÿäêè BFG
6070 FBFGFireCounter
:= utils
.readSmallInt(st
);
6072 FDamageBuffer
:= utils
.readLongInt(st
);
6073 // Ïîñëåäíèé óäàðèâøèé
6074 FLastSpawnerUID
:= utils
.readWord(st
);
6075 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6076 FLastHit
:= utils
.readByte(st
);
6078 Obj_LoadState(@FObj
, st
);
6079 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6080 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
6081 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6082 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
6084 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
6085 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6086 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
6088 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
6089 // Íàëè÷èå êðàñíîãî êëþ÷à
6090 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
6091 // Íàëè÷èå çåëåíîãî êëþ÷à
6092 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
6093 // Íàëè÷èå ñèíåãî êëþ÷à
6094 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
6096 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
6097 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6098 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
6099 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6100 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
6102 str
:= utils
.readStr(st
);
6104 FColor
.R
:= utils
.readByte(st
);
6105 FColor
.G
:= utils
.readByte(st
);
6106 FColor
.B
:= utils
.readByte(st
);
6107 if (self
= gPlayer1
) then
6109 str
:= gPlayer1Settings
.Model
;
6110 FColor
:= gPlayer1Settings
.Color
;
6112 else if (self
= gPlayer2
) then
6114 str
:= gPlayer2Settings
.Model
;
6115 FColor
:= gPlayer2Settings
.Color
;
6117 // Îáíîâëÿåì ìîäåëü èãðîêà
6119 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
6120 FModel
.Color
:= TEAMCOLOR
[FTeam
]
6122 FModel
.Color
:= FColor
;
6126 procedure TPlayer
.AllRulez(Health
: Boolean);
6132 FHealth
:= PLAYER_HP_LIMIT
;
6133 FArmor
:= PLAYER_AP_LIMIT
;
6137 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
6138 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
6139 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6142 procedure TPlayer
.RestoreHealthArmor();
6144 FHealth
:= PLAYER_HP_LIMIT
;
6145 FArmor
:= PLAYER_AP_LIMIT
;
6148 procedure TPlayer
.FragCombo();
6152 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6154 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6156 if FFragCombo
< 5 then
6158 Param
:= FUID
or (FFragCombo
shl 16);
6159 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6160 (FComboEvnt
<= High(gDelayedEvents
)) and
6161 gDelayedEvents
[FComboEvnt
].Pending
and
6162 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6163 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6165 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6166 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6169 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6177 procedure TPlayer
.GiveItem(ItemType
: Byte);
6181 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6183 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6187 if FAir
< AIR_MAX
then
6194 if not (R_BERSERK
in FRulez
) then
6196 Include(FRulez
, R_BERSERK
);
6197 if FBFGFireCounter
< 1 then
6199 FCurrWeap
:= WEAPON_KASTET
;
6201 FModel
.SetWeapon(WEAPON_KASTET
);
6205 FBerserk
:= gTime
+30000;
6207 if FHealth
< PLAYER_HP_SOFT
then
6209 FHealth
:= PLAYER_HP_SOFT
;
6210 FBerserk
:= gTime
+30000;
6215 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6217 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6221 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6223 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6227 if FJetFuel
< JET_MAX
then
6229 FJetFuel
:= JET_MAX
;
6232 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6233 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6235 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6236 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6238 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6240 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6242 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6243 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6246 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6247 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6248 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6249 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6250 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6251 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6252 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6253 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6254 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6256 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6257 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6258 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6259 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6260 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6261 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6262 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6263 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6264 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6267 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6268 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6269 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6270 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6271 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6273 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6274 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6275 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6276 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6277 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6279 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6280 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6281 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6282 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6284 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6287 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6288 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6289 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6291 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6292 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6297 if g_Game_IsNet
and g_Game_IsServer
then
6298 MH_SEND_PlayerStats(FUID
);
6301 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6306 if (Random(5) = 1) and (Times
= 1) then
6309 if BodyInLiquid(0, 0) then
6311 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6312 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6313 if Random(2) = 0 then
6314 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6316 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6320 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6322 for i
:= 1 to Times
do
6324 Anim
:= TAnimation
.Create(id
, False, 3);
6326 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6327 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6333 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6338 if (Random(10) = 1) and (Times
= 1) then
6341 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6343 for i
:= 1 to Times
do
6345 Anim
:= TAnimation
.Create(id
, False, 3);
6347 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6348 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6354 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6356 FSawSound
.Pause(Enable
);
6357 FSawSoundIdle
.Pause(Enable
);
6358 FSawSoundHit
.Pause(Enable
);
6359 FSawSoundSelect
.Pause(Enable
);
6364 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6369 FObj
.Rect
:= PLAYER_CORPSERECT
;
6370 FModelName
:= ModelName
;
6375 FState
:= CORPSE_STATE_MESS
;
6376 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6380 FState
:= CORPSE_STATE_NORMAL
;
6381 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6385 destructor TCorpse
.Destroy();
6392 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6394 procedure TCorpse
.positionChanged (); inline; begin end;
6396 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6398 if (dx
<> 0) or (dy
<> 0) then
6407 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6409 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6410 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6411 w
:= PLAYER_CORPSERECT
.Width
;
6412 h
:= PLAYER_CORPSERECT
.Height
;
6416 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6421 if FState
= CORPSE_STATE_REMOVEME
then
6424 FDamage
:= FDamage
+ Value
;
6426 if FDamage
> 150 then
6428 if FAnimation
<> nil then
6433 FState
:= CORPSE_STATE_REMOVEME
;
6435 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6436 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6437 FModelName
, FColor
);
6438 // Çâóê ìÿñà îò òðóïà:
6439 pm
:= g_PlayerModel_Get(FModelName
);
6440 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6444 if (gBodyKillEvent
<> -1)
6445 and gDelayedEvents
[gBodyKillEvent
].Pending
then
6446 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
6447 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, 0);
6452 Blood
:= g_PlayerModel_GetBlood(FModelName
);
6453 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6454 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6455 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6456 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6457 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6458 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
6462 procedure TCorpse
.Draw();
6464 if FState
= CORPSE_STATE_REMOVEME
then
6467 if FAnimation
<> nil then
6468 FAnimation
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6470 if FAnimationMask
<> nil then
6473 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6480 procedure TCorpse
.Update();
6484 if FState
= CORPSE_STATE_REMOVEME
then
6487 if gTime
mod (GAME_TICK
*2) <> 0 then
6489 g_Obj_Move(@FObj
, True, True, True);
6490 positionChanged(); // this updates spatial accelerators
6494 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6495 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6497 st
:= g_Obj_Move(@FObj
, True, True, True);
6498 positionChanged(); // this updates spatial accelerators
6500 if WordBool(st
and MOVE_FALLOUT
) then
6502 FState
:= CORPSE_STATE_REMOVEME
;
6506 if FAnimation
<> nil then
6507 FAnimation
.Update();
6508 if FAnimationMask
<> nil then
6509 FAnimationMask
.Update();
6513 procedure TCorpse
.SaveState (st
: TStream
);
6520 utils
.writeSign(st
, 'CORP');
6521 utils
.writeInt(st
, Byte(0));
6523 utils
.writeInt(st
, Byte(FState
));
6525 utils
.writeInt(st
, Byte(FDamage
));
6527 utils
.writeInt(st
, Byte(FColor
.R
));
6528 utils
.writeInt(st
, Byte(FColor
.G
));
6529 utils
.writeInt(st
, Byte(FColor
.B
));
6531 Obj_SaveState(st
, @FObj
);
6532 utils
.writeInt(st
, Word(FPlayerUID
));
6534 anim
:= (FAnimation
<> nil);
6535 utils
.writeBool(st
, anim
);
6536 // Åñëè åñòü - ñîõðàíÿåì
6537 if anim
then FAnimation
.SaveState(st
);
6538 // Åñòü ëè ìàñêà àíèìàöèè
6539 anim
:= (FAnimationMask
<> nil);
6540 utils
.writeBool(st
, anim
);
6541 // Åñëè åñòü - ñîõðàíÿåì
6542 if anim
then FAnimationMask
.SaveState(st
);
6546 procedure TCorpse
.LoadState (st
: TStream
);
6553 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6554 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6556 FState
:= utils
.readByte(st
);
6558 FDamage
:= utils
.readByte(st
);
6560 FColor
.R
:= utils
.readByte(st
);
6561 FColor
.G
:= utils
.readByte(st
);
6562 FColor
.B
:= utils
.readByte(st
);
6564 Obj_LoadState(@FObj
, st
);
6565 FPlayerUID
:= utils
.readWord(st
);
6567 anim
:= utils
.readBool(st
);
6568 // Åñëè åñòü - çàãðóæàåì
6571 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6572 FAnimation
.LoadState(st
);
6574 // Åñòü ëè ìàñêà àíèìàöèè
6575 anim
:= utils
.readBool(st
);
6576 // Åñëè åñòü - çàãðóæàåì
6579 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6580 FAnimationMask
.LoadState(st
);
6586 constructor TBot
.Create();
6593 FSpectator
:= False;
6600 for a
:= WP_FIRST
to WP_LAST
do
6602 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6603 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6604 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6608 destructor TBot
.Destroy();
6611 inherited Destroy();
6614 procedure TBot
.Draw();
6618 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6619 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6622 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6624 inherited Respawn(Silent
, Force
);
6627 FSelectedWeapon
:= FCurrWeap
;
6632 procedure TBot
.UpdateCombat();
6645 TTargetRecord
= array of TTarget
;
6647 function Compare(a
, b
: TTarget
): Integer;
6649 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6652 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6654 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6655 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6657 if a
.Dist
> b
.Dist
then // B áëèæå
6659 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6662 else // Ñòðàííî -> A
6667 a
, x1
, y1
, x2
, y2
: Integer;
6668 targets
: TTargetRecord
;
6670 Target
, BestTarget
: TTarget
;
6671 firew
, fireh
: Integer;
6675 vsPlayer
, vsMonster
, ok
: Boolean;
6678 function monsUpdate (mon
: TMonster
): Boolean;
6680 result
:= false; // don't stop
6681 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6683 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6685 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6686 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6688 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6689 if g_TraceVector(x1
, y1
, x2
, y2
) then
6691 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6692 SetLength(targets
, Length(targets
)+1);
6693 with targets
[High(targets
)] do
6700 Rect
:= mon
.Obj
.Rect
;
6701 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6702 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6703 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6712 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6713 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6715 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6716 if FCurrWeap
<> FSelectedWeapon
then
6719 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6720 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6722 RemoveAIFlag('NEEDFIRE');
6725 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6726 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6727 else PressKey(KEY_FIRE
);
6731 // Êîîðäèíàòû ñòâîëà:
6732 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6733 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6735 Target
.UID
:= FTargetUID
;
6738 if Target
.UID
<> 0 then
6739 begin // Öåëü åñòü - íàñòðàèâàåì
6740 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6743 tpla
:= g_Player_Get(Target
.UID
);
6747 if (@FObj
) <> nil then
6754 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6755 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6756 Target
.Rect
:= PLAYER_RECT
;
6757 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6758 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6759 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6760 Target
.IsPlayer
:= True;
6764 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6767 mon
:= g_Monsters_ByUID(Target
.UID
);
6770 Target
.X
:= mon
.Obj
.X
;
6771 Target
.Y
:= mon
.Obj
.Y
;
6773 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6774 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6775 Target
.Rect
:= mon
.Obj
.Rect
;
6776 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6777 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6778 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6779 Target
.IsPlayer
:= False;
6786 begin // Öåëè íåò - îáíóëÿåì
6791 Target
.Visible
:= False;
6792 Target
.Line
:= False;
6793 Target
.IsPlayer
:= False;
6798 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6799 if (not Target
.Line
) or (not Target
.Visible
) then
6803 for a
:= 0 to High(gPlayers
) do
6804 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6805 (gPlayers
[a
].FUID
<> FUID
) and
6806 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6807 (not gPlayers
[a
].NoTarget
) and
6808 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6810 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6811 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6814 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6815 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6817 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6818 if g_TraceVector(x1
, y1
, x2
, y2
) then
6820 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6821 SetLength(targets
, Length(targets
)+1);
6822 with targets
[High(targets
)] do
6824 UID
:= gPlayers
[a
].FUID
;
6825 X
:= gPlayers
[a
].FObj
.X
;
6826 Y
:= gPlayers
[a
].FObj
.Y
;
6829 Rect
:= PLAYER_RECT
;
6830 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6831 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6832 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6840 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6843 // Åñëè åñòü âîçìîæíûå öåëè:
6844 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6845 if targets
<> nil then
6847 // Âûáèðàåì íàèëó÷øóþ öåëü:
6848 BestTarget
:= targets
[0];
6849 if Length(targets
) > 1 then
6850 for a
:= 1 to High(targets
) do
6851 if Compare(BestTarget
, targets
[a
]) = 1 then
6852 BestTarget
:= targets
[a
];
6854 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6855 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6856 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6858 Target
:= BestTarget
;
6860 if (Healthy() = 3) or ((Healthy() = 2)) then
6861 begin // Åñëè çäîðîâû - äîãîíÿåì
6862 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6863 SetAIFlag('GORIGHT', '1');
6864 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6865 SetAIFlag('GOLEFT', '1');
6868 begin // Åñëè ïîáèòû - óáåãàåì
6869 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6870 SetAIFlag('GORIGHT', '1');
6871 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6872 SetAIFlag('GOLEFT', '1');
6875 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6876 SelectWeapon(Abs(x1
-Target
.cX
));
6881 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6882 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6883 if Target
.UID
<> 0 then
6885 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6886 Target
.Y
+ Target
.Rect
.Y
) then
6887 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6888 if (Healthy() = 3) or ((Healthy() = 2)) then
6889 begin // Åñëè çäîðîâû - äîãîíÿåì
6890 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6891 SetAIFlag('GORIGHT', '1');
6892 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6893 SetAIFlag('GOLEFT', '1');
6896 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6898 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6899 SetAIFlag('GORIGHT', '1');
6900 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6901 SetAIFlag('GOLEFT', '1');
6905 begin // Öåëü ïîêà íà "ýêðàíå"
6906 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6907 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6908 FLastVisible
:= gTime
;
6909 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6910 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6912 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6913 SetAIFlag('GORIGHT', '1');
6914 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6915 SetAIFlag('GOLEFT', '1');
6919 // Âûáèðàåì óãîë ââåðõ:
6920 if FDirection
= TDirection
.D_LEFT
then
6921 angle
:= ANGLE_LEFTUP
6923 angle
:= ANGLE_RIGHTUP
;
6925 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6926 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6928 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6929 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6930 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6931 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6932 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6933 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6934 begin // òî íóæíî ñòðåëÿòü ââåðõ
6935 SetAIFlag('NEEDFIRE', '1');
6936 SetAIFlag('NEEDSEEUP', '1');
6939 // Âûáèðàåì óãîë âíèç:
6940 if FDirection
= TDirection
.D_LEFT
then
6941 angle
:= ANGLE_LEFTDOWN
6943 angle
:= ANGLE_RIGHTDOWN
;
6945 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6946 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6948 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6949 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6950 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6951 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6952 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6953 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6954 begin // òî íóæíî ñòðåëÿòü âíèç
6955 SetAIFlag('NEEDFIRE', '1');
6956 SetAIFlag('NEEDSEEDOWN', '1');
6959 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6960 if Target
.Visible
and
6961 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6962 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6964 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6965 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
6966 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6967 begin // òî íóæíî ñòðåëÿòü âïåðåä
6968 SetAIFlag('NEEDFIRE', '1');
6969 SetAIFlag('NEEDSEEDOWN', '');
6970 SetAIFlag('NEEDSEEUP', '');
6972 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6973 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6974 if GetRnd(FDifficult
.CloseJump
) then
6975 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6976 if Abs(FObj
.X
-Target
.X
) < 128 then
6980 if Random(a
) = 0 then
6981 SetAIFlag('NEEDJUMP', '1');
6985 // Åñëè öåëü âñå åùå åñòü:
6986 if Target
.UID
<> 0 then
6987 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
6988 Target
.UID
:= 0 // òî çàáûòü öåëü
6989 else // Åñëè âèäåëè íåäàâíî
6990 begin // íî öåëü óáèëè
6991 if Target
.IsPlayer
then
6992 begin // Öåëü - èãðîê
6993 pla
:= g_Player_Get(Target
.UID
);
6994 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
6995 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6996 Target
.UID
:= 0; // òî çàáûòü öåëü
6999 begin // Öåëü - ìîíñòð
7000 mon
:= g_Monsters_ByUID(Target
.UID
);
7001 if (mon
= nil) or (not mon
.alive
) then
7002 Target
.UID
:= 0; // òî çàáûòü öåëü
7005 end; // if Target.UID <> 0
7007 FTargetUID
:= Target
.UID
;
7009 // Åñëè âîçìîæíûõ öåëåé íåò:
7010 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
7011 if targets
= nil then
7012 if GetAIFlag('ATTACKLEFT') <> '' then
7013 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
7014 RemoveAIFlag('ATTACKLEFT');
7016 SetAIFlag('NEEDJUMP', '1');
7018 if RunDirection() = TDirection
.D_RIGHT
then
7019 begin // Èäåì íå â òó ñòîðîíó
7020 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7021 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
7022 SetAIFlag('NEEDFIRE', '1');
7023 SetAIFlag('GOLEFT', '1');
7027 begin // Èäåì â íóæíóþ ñòîðîíó
7028 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7029 SetAIFlag('NEEDFIRE', '1');
7030 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7031 SetAIFlag('GORIGHT', '1');
7035 if GetAIFlag('ATTACKRIGHT') <> '' then
7036 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
7037 RemoveAIFlag('ATTACKRIGHT');
7039 SetAIFlag('NEEDJUMP', '1');
7041 if RunDirection() = TDirection
.D_LEFT
then
7042 begin // Èäåì íå â òó ñòîðîíó
7043 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7044 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
7045 SetAIFlag('NEEDFIRE', '1');
7046 SetAIFlag('GORIGHT', '1');
7051 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7052 SetAIFlag('NEEDFIRE', '1');
7053 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7054 SetAIFlag('GOLEFT', '1');
7058 //HACK! (does it belongs there?)
7059 RealizeCurrentWeapon();
7061 // Åñëè åñòü âîçìîæíûå öåëè:
7062 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7063 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7064 for a
:= 0 to High(targets
) do
7066 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7067 if GetRnd(FDifficult
.DiagFire
) then
7069 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7070 if FDirection
= TDirection
.D_LEFT
then
7071 angle
:= ANGLE_LEFTUP
7073 angle
:= ANGLE_RIGHTUP
;
7075 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7076 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7078 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7079 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7080 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7081 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7082 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7084 SetAIFlag('NEEDFIRE', '1');
7085 SetAIFlag('NEEDSEEUP', '1');
7088 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7089 if FDirection
= TDirection
.D_LEFT
then
7090 angle
:= ANGLE_LEFTDOWN
7092 angle
:= ANGLE_RIGHTDOWN
;
7094 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7095 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7097 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7098 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7099 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7100 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7101 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7103 SetAIFlag('NEEDFIRE', '1');
7104 SetAIFlag('NEEDSEEDOWN', '1');
7108 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7109 if targets
[a
].Line
and targets
[a
].Visible
and
7110 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
7111 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
7113 SetAIFlag('NEEDFIRE', '1');
7118 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7119 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
7120 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
7121 40+GetInterval(FDifficult
.Cover
, 40)) then
7122 SetAIFlag('NEEDJUMP', '1');
7124 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7125 ammo
:= GetAmmoByWeapon(FCurrWeap
);
7126 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
7127 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
7129 SetAIFlag('SELECTWEAPON', '1');
7131 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7132 if GetAIFlag('SELECTWEAPON') = '1' then
7135 RemoveAIFlag('SELECTWEAPON');
7139 procedure TBot
.Update();
7152 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7153 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7155 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7157 if g_debug_BotAIOff
= 3 then
7167 RealizeCurrentWeapon();
7174 procedure TBot
.ReleaseKey(Key
: Byte);
7183 function TBot
.KeyPressed(Key
: Word): Boolean;
7185 Result
:= FKeys
[Key
].Pressed
;
7188 function TBot
.GetAIFlag(aName
: String20
): String20
;
7194 aName
:= LowerCase(aName
);
7196 if FAIFlags
<> nil then
7197 for a
:= 0 to High(FAIFlags
) do
7198 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7200 Result
:= FAIFlags
[a
].Value
;
7205 procedure TBot
.RemoveAIFlag(aName
: String20
);
7209 if FAIFlags
= nil then Exit
;
7211 aName
:= LowerCase(aName
);
7213 for a
:= 0 to High(FAIFlags
) do
7214 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7216 if a
<> High(FAIFlags
) then
7217 for b
:= a
to High(FAIFlags
)-1 do
7218 FAIFlags
[b
] := FAIFlags
[b
+1];
7220 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7225 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7233 aName
:= LowerCase(aName
);
7235 if FAIFlags
<> nil then
7236 for a
:= 0 to High(FAIFlags
) do
7237 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7243 if ok
then FAIFlags
[a
].Value
:= fValue
7246 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7247 with FAIFlags
[High(FAIFlags
)] do
7255 procedure TBot
.UpdateMove
;
7257 procedure GoLeft(Time
: Word = 1);
7259 ReleaseKey(KEY_LEFT
);
7260 ReleaseKey(KEY_RIGHT
);
7261 PressKey(KEY_LEFT
, Time
);
7262 SetDirection(TDirection
.D_LEFT
);
7265 procedure GoRight(Time
: Word = 1);
7267 ReleaseKey(KEY_LEFT
);
7268 ReleaseKey(KEY_RIGHT
);
7269 PressKey(KEY_RIGHT
, Time
);
7270 SetDirection(TDirection
.D_RIGHT
);
7273 function Rnd(a
: Word): Boolean;
7275 Result
:= Random(a
) = 0;
7278 procedure Turn(Time
: Word = 1200);
7280 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7285 ReleaseKey(KEY_LEFT
);
7286 ReleaseKey(KEY_RIGHT
);
7289 function CanRunLeft(): Boolean;
7291 Result
:= not CollideLevel(-1, 0);
7294 function CanRunRight(): Boolean;
7296 Result
:= not CollideLevel(1, 0);
7299 function CanRun(): Boolean;
7301 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7304 procedure Jump(Time
: Word = 30);
7306 PressKey(KEY_JUMP
, Time
);
7309 function NearHole(): Boolean;
7313 { TODO 5 : Ëåñòíèöû }
7314 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7315 for x
:= 1 to PLAYER_RECT
.Width
do
7316 if (not StayOnStep(x
*sx
, 0)) and
7317 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7318 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7327 function BorderHole(): Boolean;
7331 { TODO 5 : Ëåñòíèöû }
7332 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7333 for x
:= 1 to PLAYER_RECT
.Width
do
7334 if (not StayOnStep(x
*sx
, 0)) and
7335 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7336 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7338 for xx
:= x
to x
+32 do
7339 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7349 function NearDeepHole(): Boolean;
7355 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7358 for x
:= 1 to PLAYER_RECT
.Width
do
7359 if (not StayOnStep(x
*sx
, 0)) and
7360 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7361 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7363 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7365 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7370 end else Result
:= False;
7373 function OverDeepHole(): Boolean;
7380 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7382 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7389 function OnGround(): Boolean;
7391 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7394 function OnLadder(): Boolean;
7396 Result
:= FullInStep(0, 0);
7399 function BelowLadder(): Boolean;
7401 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7402 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7403 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7404 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7407 function BelowLiftUp(): Boolean;
7409 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7410 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7411 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7412 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7415 function OnTopLift(): Boolean;
7417 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7420 function CanJumpOver(): Boolean;
7424 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7428 if not CollideLevel(sx
, 0) then Exit
;
7430 for y
:= 1 to BOT_MAXJUMP
do
7431 if CollideLevel(0, -y
) then Exit
else
7432 if not CollideLevel(sx
, -y
) then
7439 function CanJumpUp(Dist
: ShortInt): Boolean;
7446 if CollideLevel(Dist
, 0) then Exit
;
7449 for y
:= 0 to BOT_MAXJUMP
do
7450 if CollideLevel(Dist
, -y
) then
7459 for yy
:= y
+1 to BOT_MAXJUMP
do
7460 if not CollideLevel(Dist
, -yy
) then
7469 for y
:= 0 to BOT_MAXJUMP
do
7470 if CollideLevel(0, -y
) then
7478 if y
< yy
then Exit
;
7483 function IsSafeTrigger(): Boolean;
7488 if gTriggers
= nil then
7490 for a
:= 0 to High(gTriggers
) do
7491 if Collide(gTriggers
[a
].X
,
7494 gTriggers
[a
].Height
) and
7495 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7496 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7497 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7498 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7499 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7504 // Âîçìîæíî, íàæèìàåì êíîïêó:
7505 if Rnd(16) and IsSafeTrigger() then
7508 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7509 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7511 ReleaseKey(KEY_LEFT
);
7512 ReleaseKey(KEY_RIGHT
);
7516 // Èäåì âëåâî, åñëè íàäî áûëî:
7517 if GetAIFlag('GOLEFT') <> '' then
7519 RemoveAIFlag('GOLEFT');
7520 if CanRunLeft() then
7524 // Èäåì âïðàâî, åñëè íàäî áûëî:
7525 if GetAIFlag('GORIGHT') <> '' then
7527 RemoveAIFlag('GORIGHT');
7528 if CanRunRight() then
7532 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7533 if FObj
.X
< -32 then
7536 if FObj
.X
+32 > gMapInfo
.Width
then
7539 // Ïðûãàåì, åñëè íàäî áûëî:
7540 if GetAIFlag('NEEDJUMP') <> '' then
7543 RemoveAIFlag('NEEDJUMP');
7546 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7547 if GetAIFlag('NEEDSEEUP') <> '' then
7550 ReleaseKey(KEY_DOWN
);
7551 PressKey(KEY_UP
, 20);
7552 RemoveAIFlag('NEEDSEEUP');
7555 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7556 if GetAIFlag('NEEDSEEDOWN') <> '' then
7559 ReleaseKey(KEY_DOWN
);
7560 PressKey(KEY_DOWN
, 20);
7561 RemoveAIFlag('NEEDSEEDOWN');
7564 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7565 if GetAIFlag('GOINHOLE') <> '' then
7566 if not OnGround() then
7568 ReleaseKey(KEY_LEFT
);
7569 ReleaseKey(KEY_RIGHT
);
7570 RemoveAIFlag('GOINHOLE');
7571 SetAIFlag('FALLINHOLE', '1');
7574 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7575 if GetAIFlag('FALLINHOLE') <> '' then
7577 RemoveAIFlag('FALLINHOLE');
7579 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7580 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7581 if GetAIFlag('FALLINHOLE') = '' then
7582 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7588 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7590 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7594 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7595 if OnGround() and NearHole() then
7596 if NearDeepHole() then // Åñëè ýòî áåçäíà
7598 0..3: Turn(); // Áåæèì îáðàòíî
7599 4: Jump(); // Ïðûãàåì
7600 5: begin // Ïðûãàåì îáðàòíî
7605 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7606 if GetAIFlag('GOINHOLE') = '' then
7608 0: Turn(); // Íå íóæíî òóäà
7609 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7610 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7611 if BorderHole() then
7612 SetAIFlag('GOINHOLE', '1');
7615 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7616 if (not CanRun()) and OnGround() then
7618 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7619 if CanJumpOver() or OnLadder() then
7621 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7622 if Random(2) = 0 then
7624 if IsSafeTrigger() then
7630 // Îñòàëîñü ìàëî âîçäóõà:
7631 if FAir
< 36 * 2 then
7634 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7635 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7636 if BodyInAcid(0, 0) then
7640 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7642 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7643 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7646 {function TBot.NeedItem(Item: Byte): Byte;
7651 procedure TBot
.SelectWeapon(Dist
: Integer);
7655 function HaveAmmo(weapon
: Byte): Boolean;
7658 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7659 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7660 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7661 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7662 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7663 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7664 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7665 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7666 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7667 else Result
:= True;
7672 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7674 if Dist
> BOT_LONGDIST
then
7675 begin // Äàëüíèé áîé
7677 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7679 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7683 else //if Dist > BOT_UNSAFEDIST then
7684 begin // Áëèæíèé áîé
7686 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7688 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7695 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7697 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7703 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7705 Result
:= inherited PickItem(ItemType
, force
, remove
);
7707 if Result
then SetAIFlag('SELECTWEAPON', '1');
7710 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7712 Result
:= inherited Heal(value
, Soft
);
7715 function TBot
.Healthy(): Byte;
7717 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7718 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7719 else if (FHealth
> 50) then Result
:= 2
7720 else if (FHealth
> 20) then Result
:= 1
7724 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7726 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7727 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7730 procedure TBot
.OnDamage(Angle
: SmallInt);
7738 if (Angle
= 0) or (Angle
= 180) then
7741 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7742 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7744 pla
:= g_Player_Get(FLastSpawnerUID
);
7745 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7746 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7749 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7750 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7752 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7753 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7754 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7759 SetAIFlag('ATTACKLEFT', '1')
7761 SetAIFlag('ATTACKRIGHT', '1');
7765 function TBot
.RunDirection(): TDirection
;
7767 if Abs(Vel
.X
) >= 1 then
7769 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7771 Result
:= FDirection
;
7774 function TBot
.GetRnd(a
: Byte): Boolean;
7776 if a
= 0 then Result
:= False
7777 else if a
= 255 then Result
:= True
7778 else Result
:= Random(256) > 255-a
;
7781 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7783 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7787 procedure TDifficult
.save (st
: TStream
);
7789 utils
.writeInt(st
, Byte(DiagFire
));
7790 utils
.writeInt(st
, Byte(InvisFire
));
7791 utils
.writeInt(st
, Byte(DiagPrecision
));
7792 utils
.writeInt(st
, Byte(FlyPrecision
));
7793 utils
.writeInt(st
, Byte(Cover
));
7794 utils
.writeInt(st
, Byte(CloseJump
));
7795 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7796 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7799 procedure TDifficult
.load (st
: TStream
);
7801 DiagFire
:= utils
.readByte(st
);
7802 InvisFire
:= utils
.readByte(st
);
7803 DiagPrecision
:= utils
.readByte(st
);
7804 FlyPrecision
:= utils
.readByte(st
);
7805 Cover
:= utils
.readByte(st
);
7806 CloseJump
:= utils
.readByte(st
);
7807 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7808 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7812 procedure TBot
.SaveState (st
: TStream
);
7817 inherited SaveState(st
);
7818 utils
.writeSign(st
, 'BOT0');
7820 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7822 utils
.writeInt(st
, Word(FTargetUID
));
7823 // Âðåìÿ ïîòåðè öåëè
7824 utils
.writeInt(st
, LongWord(FLastVisible
));
7825 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7826 dw
:= Length(FAIFlags
);
7827 utils
.writeInt(st
, LongInt(dw
));
7829 for i
:= 0 to dw
-1 do
7831 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7832 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7834 // Íàñòðîéêè ñëîæíîñòè
7835 FDifficult
.save(st
);
7839 procedure TBot
.LoadState (st
: TStream
);
7844 inherited LoadState(st
);
7845 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7847 FSelectedWeapon
:= utils
.readByte(st
);
7849 FTargetUID
:= utils
.readWord(st
);
7850 // Âðåìÿ ïîòåðè öåëè
7851 FLastVisible
:= utils
.readLongWord(st
);
7852 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7853 dw
:= utils
.readLongInt(st
);
7854 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7855 SetLength(FAIFlags
, dw
);
7857 for i
:= 0 to dw
-1 do
7859 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7860 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7862 // Íàñòðîéêè ñëîæíîñòè
7863 FDifficult
.load(st
);
7868 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);