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;
3746 for i
:= 0 to High(FWeapon
) do
3748 if (FNextWeap
and (1 shl i
)) <> 0 then
3751 if (cwi
>= 0) then wantThisWeapon
[cwi
] := true;
3756 // slow down alterations a little
3759 // more than one weapon requested, assume "alteration", and check alteration delay
3760 if FNextWeapDelay
> 0 then
3762 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), TMsgType.Warning);
3768 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3769 // but clear all counters if no weapon should be switched
3776 // exclude currently selected weapon from the set
3777 curlidx
:= real2log(FCurrWeap
);
3778 //e_WriteLog(Format('*** wwc=%d; currweap=%d; logweap=%d', [wwc, FCurrWeap, curlidx]), TMsgType.Warning);
3779 //e_WriteLog(Format('FCurrWeap=%d; curlidx=%d', [FCurrWeap, curlidx]), TMsgType.Warning);
3780 //if (curlidx >= 0) then wantThisWeapon[curlidx] := false;
3781 //if (wwc = 2) then begin Dec(wwc); end; // easy case: switch between two weapons
3783 // find next weapon to switch onto
3785 for i
:= 0 to High(weaponOrder
) do
3787 cwi
:= (cwi
+length(weaponOrder
)+1) mod length(weaponOrder
);
3788 if (cwi
= curlidx
) then continue
; // skip current weapon
3789 if not wantThisWeapon
[cwi
] then continue
;
3790 rwidx
:= weaponOrder
[cwi
];
3791 if (rwidx
< 0) then continue
;
3792 //e_WriteLog(Format(' trying logical %d (real %d); has=%d, hasammo=%d', [cwi, rwidx, Integer(FWeapon[rwidx]), Integer(hasAmmoForWeapon(rwidx))]), TMsgType.Warning);
3793 if FWeapon
[rwidx
] and ((wwc
= 1) or hasAmmoForWeapon(rwidx
)) then
3795 //e_WriteLog(' I FOUND HER!', TMsgType.Warning);
3797 result
:= Byte(rwidx
);
3799 //FNextWeapDelay := 10; // anyway, 'cause why not; k8: not needed anymore
3804 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3808 procedure TPlayer
.RealizeCurrentWeapon();
3809 function switchAllowed (): Boolean;
3814 if FBFGFireCounter
<> -1 then
3816 if FTime
[T_SWITCH
] > gTime
then
3818 for i
:= WP_FIRST
to WP_LAST
do
3819 if FReloading
[i
] > 0 then
3827 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3828 //FNextWeap := FNextWeap and $1FFF;
3829 //HACK: alteration delay will be reset when player released any weapon switch key
3830 FNextWeapDelay
:= 0; //k8: just in case
3831 //if FNextWeapDelay > 0 then Dec(FNextWeapDelay); // "alteration delay"
3833 if not switchAllowed
then
3835 //HACK for weapon cycling
3836 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3840 nw
:= getNextWeaponIndex();
3841 if nw
= 255 then exit
; // don't reset anything here
3842 if nw
> High(FWeapon
) then
3844 // don't forget to reset queue here!
3845 //e_WriteLog(Format(' RealizeCurrentWeapon: WUTAFUUUU?! (%d)', [nw]), TMsgType.Warning);
3853 FTime
[T_SWITCH
] := gTime
+156;
3854 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3855 FModel
.SetWeapon(FCurrWeap
);
3856 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3860 procedure TPlayer
.NextWeapon();
3862 if g_Game_IsClient
then Exit
;
3866 procedure TPlayer
.PrevWeapon();
3868 if g_Game_IsClient
then Exit
;
3872 procedure TPlayer
.SetWeapon(W
: Byte);
3874 if FCurrWeap
<> W
then
3875 if W
= WEAPON_SAW
then
3876 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3879 FModel
.SetWeapon(CurrWeap
);
3883 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3885 function allowBerserkSwitching (): Boolean;
3887 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3889 if gBerserkAutoswitch
then exit
;
3890 if not conIsCheatsEnabled
then exit
;
3898 if g_Game_IsClient
then Exit
;
3900 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3901 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3906 if FHealth
< PLAYER_HP_SOFT
then
3908 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3912 if gFlash
= 2 then Inc(FPickup
, 5);
3916 if FHealth
< PLAYER_HP_SOFT
then
3918 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3922 if gFlash
= 2 then Inc(FPickup
, 5);
3926 if FArmor
< PLAYER_AP_SOFT
then
3928 FArmor
:= PLAYER_AP_SOFT
;
3931 if gFlash
= 2 then Inc(FPickup
, 5);
3935 if FArmor
< PLAYER_AP_LIMIT
then
3937 FArmor
:= PLAYER_AP_LIMIT
;
3940 if gFlash
= 2 then Inc(FPickup
, 5);
3944 if FHealth
< PLAYER_HP_LIMIT
then
3946 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3950 if gFlash
= 2 then Inc(FPickup
, 5);
3954 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3956 if FHealth
< PLAYER_HP_LIMIT
then
3957 FHealth
:= PLAYER_HP_LIMIT
;
3958 if FArmor
< PLAYER_AP_LIMIT
then
3959 FArmor
:= PLAYER_AP_LIMIT
;
3963 if gFlash
= 2 then Inc(FPickup
, 5);
3967 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3969 FWeapon
[WEAPON_SAW
] := True;
3971 if gFlash
= 2 then Inc(FPickup
, 5);
3972 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3975 ITEM_WEAPON_SHOTGUN1
:
3976 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3978 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3979 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3981 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3982 FWeapon
[WEAPON_SHOTGUN1
] := True;
3984 if gFlash
= 2 then Inc(FPickup
, 5);
3985 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3988 ITEM_WEAPON_SHOTGUN2
:
3989 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3991 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3993 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3994 FWeapon
[WEAPON_SHOTGUN2
] := True;
3996 if gFlash
= 2 then Inc(FPickup
, 5);
3997 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4000 ITEM_WEAPON_CHAINGUN
:
4001 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
4003 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
4005 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4006 FWeapon
[WEAPON_CHAINGUN
] := True;
4008 if gFlash
= 2 then Inc(FPickup
, 5);
4009 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4012 ITEM_WEAPON_ROCKETLAUNCHER
:
4013 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
4015 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
4017 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
4018 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
4020 if gFlash
= 2 then Inc(FPickup
, 5);
4021 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4025 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
4027 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
4029 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4030 FWeapon
[WEAPON_PLASMA
] := True;
4032 if gFlash
= 2 then Inc(FPickup
, 5);
4033 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4037 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
4039 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
4041 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4042 FWeapon
[WEAPON_BFG
] := True;
4044 if gFlash
= 2 then Inc(FPickup
, 5);
4045 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4048 ITEM_WEAPON_SUPERPULEMET
:
4049 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
4051 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
4053 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4054 FWeapon
[WEAPON_SUPERPULEMET
] := True;
4056 if gFlash
= 2 then Inc(FPickup
, 5);
4057 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4060 ITEM_WEAPON_FLAMETHROWER
:
4061 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
4063 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
4065 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4066 FWeapon
[WEAPON_FLAMETHROWER
] := True;
4068 if gFlash
= 2 then Inc(FPickup
, 5);
4069 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4073 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4075 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4078 if gFlash
= 2 then Inc(FPickup
, 5);
4081 ITEM_AMMO_BULLETS_BOX
:
4082 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4084 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4087 if gFlash
= 2 then Inc(FPickup
, 5);
4091 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4093 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4096 if gFlash
= 2 then Inc(FPickup
, 5);
4099 ITEM_AMMO_SHELLS_BOX
:
4100 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4102 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
4105 if gFlash
= 2 then Inc(FPickup
, 5);
4109 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4111 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4114 if gFlash
= 2 then Inc(FPickup
, 5);
4117 ITEM_AMMO_ROCKET_BOX
:
4118 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4120 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
4123 if gFlash
= 2 then Inc(FPickup
, 5);
4127 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4129 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4132 if gFlash
= 2 then Inc(FPickup
, 5);
4136 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4138 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4141 if gFlash
= 2 then Inc(FPickup
, 5);
4145 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4147 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4150 if gFlash
= 2 then Inc(FPickup
, 5);
4154 if not(R_ITEM_BACKPACK
in FRulez
) or
4155 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4156 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4157 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4158 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4159 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
4161 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4162 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4163 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4164 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4165 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4167 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4168 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4169 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4170 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4171 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4172 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4173 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4174 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4176 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
4179 if gFlash
= 2 then Inc(FPickup
, 5);
4183 if not(R_KEY_RED
in FRulez
) then
4185 Include(FRulez
, R_KEY_RED
);
4187 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4188 if gFlash
= 2 then Inc(FPickup
, 5);
4189 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4193 if not(R_KEY_GREEN
in FRulez
) then
4195 Include(FRulez
, R_KEY_GREEN
);
4197 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4198 if gFlash
= 2 then Inc(FPickup
, 5);
4199 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4203 if not(R_KEY_BLUE
in FRulez
) then
4205 Include(FRulez
, R_KEY_BLUE
);
4207 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4208 if gFlash
= 2 then Inc(FPickup
, 5);
4209 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4213 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4215 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4219 if gFlash
= 2 then Inc(FPickup
, 5);
4223 if FAir
< AIR_MAX
then
4228 if gFlash
= 2 then Inc(FPickup
, 5);
4233 if not (R_BERSERK
in FRulez
) then
4235 Include(FRulez
, R_BERSERK
);
4236 if allowBerserkSwitching
then
4238 FCurrWeap
:= WEAPON_KASTET
;
4240 FModel
.SetWeapon(WEAPON_KASTET
);
4245 if gFlash
= 2 then Inc(FPickup
, 5);
4247 FBerserk
:= gTime
+30000;
4252 if FHealth
< PLAYER_HP_SOFT
then
4254 FHealth
:= PLAYER_HP_SOFT
;
4255 FBerserk
:= gTime
+30000;
4263 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4265 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4268 if gFlash
= 2 then Inc(FPickup
, 5);
4272 if FHealth
< PLAYER_HP_LIMIT
then
4274 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4278 if gFlash
= 2 then Inc(FPickup
, 5);
4282 if FArmor
< PLAYER_AP_LIMIT
then
4284 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4287 if gFlash
= 2 then Inc(FPickup
, 5);
4291 if FJetFuel
< JET_MAX
then
4293 FJetFuel
:= JET_MAX
;
4296 if gFlash
= 2 then Inc(FPickup
, 5);
4300 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4302 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4305 if gFlash
= 2 then Inc(FPickup
, 5);
4310 procedure TPlayer
.Touch();
4314 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4317 // Áðîñèòü ôëàã òîâàðèùó:
4318 if gGameSettings
.GameMode
= GM_CTF
then
4323 procedure TPlayer
.Push(vx
, vy
: Integer);
4325 if (not FPhysics
) and FGhost
then
4327 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4328 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4329 if g_Game_IsNet
and g_Game_IsServer
then
4330 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4333 procedure TPlayer
.Reset(Force
: Boolean);
4339 FTime
[T_RESPAWN
] := 0;
4340 FTime
[T_FLAGCAP
] := 0;
4353 FSpectator
:= False;
4356 FSpectatePlayer
:= -1;
4357 FNoRespawn
:= False;
4359 FLives
:= gGameSettings
.MaxLives
;
4364 procedure TPlayer
.SoftReset();
4370 FBFGFireCounter
:= -1;
4378 SetAction(A_STAND
, True);
4381 function TPlayer
.GetRespawnPoint(): Byte;
4386 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4388 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4389 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4391 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4393 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4394 if Self
= gPlayer1
then
4395 c
:= RESPAWNPOINT_PLAYER1
4397 c
:= RESPAWNPOINT_PLAYER2
;
4398 if g_Map_GetPointCount(c
) > 0 then
4404 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4405 if Self
= gPlayer1
then
4406 c
:= RESPAWNPOINT_PLAYER2
4408 c
:= RESPAWNPOINT_PLAYER1
;
4409 if g_Map_GetPointCount(c
) > 0 then
4416 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4417 if Random(2) = 0 then
4418 c
:= RESPAWNPOINT_PLAYER1
4420 c
:= RESPAWNPOINT_PLAYER2
;
4421 if g_Map_GetPointCount(c
) > 0 then
4428 // Òî÷êà ëþáîé èç êîìàíä
4429 if Random(2) = 0 then
4430 c
:= RESPAWNPOINT_RED
4432 c
:= RESPAWNPOINT_BLUE
;
4433 if g_Map_GetPointCount(c
) > 0 then
4440 c
:= RESPAWNPOINT_DM
;
4441 if g_Map_GetPointCount(c
) > 0 then
4449 if gGameSettings
.GameMode
= GM_DM
then
4452 c
:= RESPAWNPOINT_DM
;
4453 if g_Map_GetPointCount(c
) > 0 then
4459 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4460 if Random(2) = 0 then
4461 c
:= RESPAWNPOINT_PLAYER1
4463 c
:= RESPAWNPOINT_PLAYER2
;
4464 if g_Map_GetPointCount(c
) > 0 then
4470 // Òî÷êà ëþáîé èç êîìàíä
4471 if Random(2) = 0 then
4472 c
:= RESPAWNPOINT_RED
4474 c
:= RESPAWNPOINT_BLUE
;
4475 if g_Map_GetPointCount(c
) > 0 then
4483 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4485 // Òî÷êà ñâîåé êîìàíäû
4486 c
:= RESPAWNPOINT_DM
;
4487 if FTeam
= TEAM_RED
then
4488 c
:= RESPAWNPOINT_RED
;
4489 if FTeam
= TEAM_BLUE
then
4490 c
:= RESPAWNPOINT_BLUE
;
4491 if g_Map_GetPointCount(c
) > 0 then
4498 c
:= RESPAWNPOINT_DM
;
4499 if g_Map_GetPointCount(c
) > 0 then
4505 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4506 if Random(2) = 0 then
4507 c
:= RESPAWNPOINT_PLAYER1
4509 c
:= RESPAWNPOINT_PLAYER2
;
4510 if g_Map_GetPointCount(c
) > 0 then
4516 // Òî÷êà äðóãîé êîìàíäû
4517 c
:= RESPAWNPOINT_DM
;
4518 if FTeam
= TEAM_RED
then
4519 c
:= RESPAWNPOINT_BLUE
;
4520 if FTeam
= TEAM_BLUE
then
4521 c
:= RESPAWNPOINT_RED
;
4522 if g_Map_GetPointCount(c
) > 0 then
4530 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4532 RespawnPoint
: TRespawnPoint
;
4538 FBFGFireCounter
:= -1;
4543 if not g_Game_IsServer
then
4547 FWantsInGame
:= True;
4548 FJustTeleported
:= True;
4551 FTime
[T_RESPAWN
] := 0;
4555 // if server changes MaxLives we gotta be ready
4556 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4558 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4559 if FTime
[T_RESPAWN
] > gTime
then
4562 // Ïðîñðàë âñå æèçíè:
4565 if not FSpectator
then Spectate(True);
4566 FWantsInGame
:= True;
4570 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4571 begin // "Ñâîÿ èãðà"
4572 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4573 FRulez
:= FRulez
-[R_BERSERK
];
4575 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4577 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4578 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4581 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4582 c
:= GetRespawnPoint();
4587 // Âîñêðåøåíèå áåç îðóæèÿ:
4590 FHealth
:= PLAYER_HP_SOFT
;
4596 for a
:= WP_FIRST
to WP_LAST
do
4598 FWeapon
[a
] := False;
4602 FWeapon
[WEAPON_PISTOL
] := True;
4603 FWeapon
[WEAPON_KASTET
] := True;
4604 FCurrWeap
:= WEAPON_PISTOL
;
4607 FModel
.SetWeapon(FCurrWeap
);
4609 for b
:= A_BULLETS
to A_HIGH
do
4612 FAmmo
[A_BULLETS
] := 50;
4614 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4615 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4616 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4617 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4618 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4620 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4621 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4626 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4627 if not g_Map_GetPoint(c
, RespawnPoint
) then
4629 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4633 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4634 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4635 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4641 FDirection
:= RespawnPoint
.Direction
;
4642 if FDirection
= TDirection
.D_LEFT
then
4647 SetAction(A_STAND
, True);
4648 FModel
.Direction
:= FDirection
;
4650 for a
:= Low(FTime
) to High(FTime
) do
4653 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4658 FCanJetpack
:= False;
4663 // Àíèìàöèÿ âîçðîæäåíèÿ:
4664 if (not gLoadGameMode
) and (not Silent
) then
4665 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4667 Anim
:= TAnimation
.Create(ID
, False, 3);
4668 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4669 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4673 FSpectator
:= False;
4676 FSpectatePlayer
:= -1;
4679 if (gPlayer1
= nil) and (gLMSPID1
= FUID
) then
4681 if (gPlayer2
= nil) and (gLMSPID2
= FUID
) then
4684 if g_Game_IsNet
then
4686 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4687 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4689 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4690 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4695 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4698 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4699 else if (not NoMove
) then
4701 GameX
:= gMapInfo
.Width
div 2;
4702 GameY
:= gMapInfo
.Height
div 2;
4711 FWantsInGame
:= False;
4716 if Self
= gPlayer1
then
4721 if Self
= gPlayer2
then
4728 if g_Game_IsNet
then
4729 MH_SEND_PlayerStats(FUID
);
4732 procedure TPlayer
.SwitchNoClip
;
4736 FGhost
:= not FGhost
;
4737 FPhysics
:= not FGhost
;
4749 procedure TPlayer
.Run(Direction
: TDirection
);
4753 if MAX_RUNVEL
> 8 then
4757 if Direction
= TDirection
.D_LEFT
then
4759 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4760 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4763 if FObj
.Vel
.X
< MAX_RUNVEL
then
4764 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4766 // Âîçìîæíî, ïèíàåì êóñêè:
4767 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4769 b
:= Abs(FObj
.Vel
.X
);
4770 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4771 for a
:= 0 to High(gGibs
) do
4773 if gGibs
[a
].alive
and
4774 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4775 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4778 if FObj
.Vel
.X
< 0 then
4780 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4784 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4786 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4794 procedure TPlayer
.SeeDown();
4796 SetAction(A_SEEDOWN
);
4798 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4800 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4803 procedure TPlayer
.SeeUp();
4807 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4809 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4812 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4820 A_ATTACK
: Prior
:= 2;
4821 A_SEEUP
: Prior
:= 1;
4822 A_SEEDOWN
: Prior
:= 1;
4823 A_ATTACKUP
: Prior
:= 2;
4824 A_ATTACKDOWN
: Prior
:= 2;
4829 if (Prior
> FActionPrior
) or Force
then
4830 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4832 FActionPrior
:= Prior
;
4833 FActionAnim
:= Action
;
4834 FActionForce
:= Force
;
4835 FActionChanged
:= True;
4838 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4841 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4843 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4844 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4845 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4846 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4849 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4856 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4858 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4859 if g_Game_IsServer
and g_Game_IsNet
then
4860 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4864 FJustTeleported
:= True;
4869 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4871 Anim
:= TAnimation
.Create(ID
, False, 3);
4874 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4875 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4876 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4877 if g_Game_IsServer
and g_Game_IsNet
then
4878 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4879 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4883 FObj
.X
:= X
-PLAYER_RECT
.X
;
4884 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4885 if FAlive
and FGhost
then
4891 if not g_Game_IsNet
then
4895 SetDirection(TDirection
.D_LEFT
);
4901 SetDirection(TDirection
.D_RIGHT
);
4907 if FDirection
= TDirection
.D_RIGHT
then
4909 SetDirection(TDirection
.D_LEFT
);
4914 SetDirection(TDirection
.D_RIGHT
);
4920 if not silent
and (Anim
<> nil) then
4922 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4923 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4926 if g_Game_IsServer
and g_Game_IsNet
then
4927 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4928 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4935 function nonz(a
: Single): Single;
4943 function TPlayer
.followCorpse(): Boolean;
4948 if FAlive
or FSpectator
then
4950 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
4952 for i
:= 0 to High(gCorpses
) do
4953 if gCorpses
[i
] <> nil then
4954 if gCorpses
[i
].FPlayerUID
= FUID
then
4957 FObj
.X
:= gCorpses
[i
].FObj
.X
;
4958 FObj
.Y
:= gCorpses
[i
].FObj
.Y
;
4959 FObj
.Vel
.X
:= gCorpses
[i
].FObj
.Vel
.X
;
4960 FObj
.Vel
.Y
:= gCorpses
[i
].FObj
.Vel
.Y
;
4961 FObj
.Accel
.X
:= gCorpses
[i
].FObj
.Accel
.X
;
4962 FObj
.Accel
.Y
:= gCorpses
[i
].FObj
.Accel
.Y
;
4967 procedure TPlayer
.Update();
4970 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4971 blockmon
, headwater
, dospawn
: Boolean;
4976 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4977 AnyServer
:= g_Game_IsServer
;
4979 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4980 DoLerp(NetInterpLevel
+ 1)
4986 if FClientID
>= 0 then
4988 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4989 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4990 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4999 if FAlive
and (FPunchAnim
<> nil) then
5000 FPunchAnim
.Update();
5002 if FAlive
and (gFly
or FJetpack
) then
5005 if FDirection
= TDirection
.D_LEFT
then
5010 if FAlive
and (not FGhost
) then
5012 if FKeys
[KEY_UP
].Pressed
then
5014 if FKeys
[KEY_DOWN
].Pressed
then
5018 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
5021 i
:= g_basic
.Sign(FIncCam
);
5022 FIncCam
:= Abs(FIncCam
);
5023 DecMin(FIncCam
, 5, 0);
5024 FIncCam
:= FIncCam
*i
;
5027 // no need to do that each second frame, weapon queue will take care of it
5028 if FAlive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
5029 if FAlive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
5031 if gTime
mod (GAME_TICK
*2) <> 0 then
5033 if (FObj
.Vel
.X
= 0) and FAlive
then
5035 if FKeys
[KEY_LEFT
].Pressed
then
5036 Run(TDirection
.D_LEFT
);
5037 if FKeys
[KEY_RIGHT
].Pressed
then
5038 Run(TDirection
.D_RIGHT
);
5043 if not followCorpse() then
5044 g_Obj_Move(@FObj
, True, True, True);
5045 positionChanged(); // this updates spatial accelerators
5051 FActionChanged
:= False;
5055 // Let alive player do some actions
5056 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
5057 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
5058 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
5059 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
5060 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
5061 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
5062 if FKeys
[KEY_JUMP
].Pressed
then Jump()
5065 if AnyServer
and FJetpack
then
5069 if NetServer
then MH_SEND_PlayerStats(FUID
);
5071 FCanJetpack
:= True;
5078 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
5080 if FKeys
[k
].Pressed
then
5088 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5091 if (FTime
[T_RESPAWN
] <= gTime
) and
5092 gGameOn
and (not FAlive
) then
5094 if (g_Player_GetCount() > 1) then
5098 gExit
:= EXIT_RESTART
;
5103 // Dead spectator actions
5106 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
5107 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
5111 if (FSpectatePlayer
>= High(gPlayers
)) then
5112 FSpectatePlayer
:= -1
5116 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
5117 if gPlayers
[I
] <> nil then
5118 if gPlayers
[I
].alive
then
5119 if gPlayers
[I
].UID
<> FUID
then
5121 FSpectatePlayer
:= I
;
5126 if not SetSpect
then FSpectatePlayer
:= -1;
5137 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5139 FYTo
:= FObj
.Y
- 32;
5140 FSpectatePlayer
:= -1;
5142 if FKeys
[KEY_DOWN
].Pressed
then
5144 FYTo
:= FObj
.Y
+ 32;
5145 FSpectatePlayer
:= -1;
5147 if FKeys
[KEY_LEFT
].Pressed
then
5149 FXTo
:= FObj
.X
- 32;
5150 FSpectatePlayer
:= -1;
5152 if FKeys
[KEY_RIGHT
].Pressed
then
5154 FXTo
:= FObj
.X
+ 32;
5155 FSpectatePlayer
:= -1;
5158 if (FXTo
< -64) then
5160 else if (FXTo
> gMapInfo
.Width
+ 32) then
5161 FXTo
:= gMapInfo
.Width
+ 32;
5162 if (FYTo
< -72) then
5164 else if (FYTo
> gMapInfo
.Height
+ 32) then
5165 FYTo
:= gMapInfo
.Height
+ 32;
5170 if not followCorpse() then
5171 g_Obj_Move(@FObj
, True, True, True);
5172 positionChanged(); // this updates spatial accelerators
5179 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5180 if gPlayers
[FSpectatePlayer
] <> nil then
5181 if gPlayers
[FSpectatePlayer
].alive
then
5183 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
5184 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
5188 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5189 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5190 PANEL_BLOCKMON
, True);
5191 headwater
:= HeadInLiquid(0, 0);
5193 // Ñîïðîòèâëåíèå âîçäóõà:
5194 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5195 if FObj
.Vel
.X
<> 0 then
5196 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5198 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5199 DecMin(FPain
, 5, 0);
5200 DecMin(FPickup
, 1, 0);
5202 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5204 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5205 FMegaRulez
[MR_SUIT
] := 0;
5206 FMegaRulez
[MR_INVUL
] := 0;
5207 FMegaRulez
[MR_INVIS
] := 0;
5208 Kill(K_FALLKILL
, 0, HIT_FALL
);
5215 if FCurrWeap
= WEAPON_SAW
then
5216 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5217 FSawSoundSelect
.IsPlaying()) then
5218 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5221 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5222 (not FJetSoundOff
.IsPlaying()) then
5224 FJetSoundFly
.SetPosition(0);
5225 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5228 for b
:= WP_FIRST
to WP_LAST
do
5229 if FReloading
[b
] > 0 then
5235 if FShellTimer
> -1 then
5236 if FShellTimer
= 0 then
5238 if FShellType
= SHELL_SHELL
then
5239 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5240 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5241 else if FShellType
= SHELL_DBLSHELL
then
5243 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5244 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5245 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5246 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5249 end else Dec(FShellTimer
);
5251 if (FBFGFireCounter
> -1) then
5252 if FBFGFireCounter
= 0 then
5256 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5257 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5258 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5259 yd
:= wy
+firediry();
5260 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5261 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5262 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5263 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5264 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5267 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5268 FBFGFireCounter
:= -1;
5271 FBFGFireCounter
:= 0
5273 Dec(FBFGFireCounter
);
5275 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5277 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5279 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5282 if (headwater
or blockmon
) then
5288 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5291 else if (FAir
mod 31 = 0) and not blockmon
then
5293 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5294 if Random(2) = 0 then
5295 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5297 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5299 end else if FAir
< AIR_DEF
then
5302 if FFireTime
> 0 then
5304 if BodyInLiquid(0, 0) then
5309 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5311 if FMegaRulez
[MR_SUIT
] = gTime
then
5318 if FFirePainTime
<= 0 then
5320 if g_Game_IsServer
then
5321 Damage(5, FFireAttacker
, 0, 0, HIT_FLAME
);
5322 FFirePainTime
:= 18;
5324 FFirePainTime
:= FFirePainTime
- 1;
5325 FFireTime
:= FFireTime
- 1;
5326 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5327 MH_SEND_PlayerStats(FUID
);
5331 if FDamageBuffer
> 0 then
5333 if FDamageBuffer
>= 9 then
5337 if FDamageBuffer
< 30 then i
:= 9
5338 else if FDamageBuffer
< 100 then i
:= 18
5342 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5343 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5344 FHealth
:= FHealth
-ii
;
5347 FHealth
:= FHealth
+FArmor
;
5352 if FHealth
<= 0 then
5353 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5354 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5355 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5359 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5360 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5361 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5362 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5369 end; // if FAlive then ...
5371 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5373 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5374 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5375 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5376 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5378 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5379 then SetAction(A_STAND
, True);
5381 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5383 for b
:= Low(FKeys
) to High(FKeys
) do
5384 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5388 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5390 x
:= FObj
.X
+PLAYER_RECT
.X
;
5391 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5392 w
:= PLAYER_RECT
.Width
;
5393 h
:= PLAYER_RECT
.Height
;
5397 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5399 if (dx
<> 0) or (dy
<> 0) then
5408 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5410 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5411 FObj
.Y
+PLAYER_RECT
.Y
,
5418 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5420 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5421 FObj
.Y
+PLAYER_RECT
.Y
,
5425 Panel
.Width
, Panel
.Height
);
5428 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5430 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5431 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5432 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5433 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5436 function g_Player_ValidName(Name
: string): Boolean;
5442 if gPlayers
= nil then Exit
;
5444 for a
:= 0 to High(gPlayers
) do
5445 if gPlayers
[a
] <> nil then
5446 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5453 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5457 d
:= FModel
.Direction
;
5459 FModel
.Direction
:= Direction
;
5460 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5462 FDirection
:= Direction
;
5465 function TPlayer
.GetKeys(): Byte;
5469 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5470 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5471 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5473 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5474 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5477 procedure TPlayer
.Use();
5481 if FTime
[T_USE
] > gTime
then Exit
;
5483 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5484 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5486 for a
:= 0 to High(gPlayers
) do
5487 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5488 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5489 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5490 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5492 gPlayers
[a
].Touch();
5493 if g_Game_IsNet
and g_Game_IsServer
then
5494 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5497 FTime
[T_USE
] := gTime
+120;
5500 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5504 WX
, WY
, XD
, YD
: Integer;
5516 if R_BERSERK
in FRulez
then
5518 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5519 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5520 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5523 locobj
.rect
.Width
:= 39;
5524 locobj
.rect
.Height
:= 52;
5525 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5526 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5527 locobj
.Accel
.X
:= xd
-wx
;
5528 locobj
.Accel
.y
:= yd
-wy
;
5530 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5531 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5533 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5537 FPain
:= min(FPain
+ 25, 50);
5539 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5544 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5545 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5547 FSawSoundSelect
.Stop();
5549 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5551 else if not FSawSoundHit
.IsPlaying() then
5553 FSawSoundSelect
.Stop();
5554 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5561 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5562 FFireAngle
:= FAngle
;
5564 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5565 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5570 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5571 FFireAngle
:= FAngle
;
5574 FShellType
:= SHELL_SHELL
;
5579 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5580 FFireAngle
:= FAngle
;
5583 FShellType
:= SHELL_DBLSHELL
;
5588 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5589 FFireAngle
:= FAngle
;
5591 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5592 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5595 WEAPON_ROCKETLAUNCHER
:
5597 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5598 FFireAngle
:= FAngle
;
5604 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5605 FFireAngle
:= FAngle
;
5611 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5612 FFireAngle
:= FAngle
;
5616 WEAPON_SUPERPULEMET
:
5618 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5619 FFireAngle
:= FAngle
;
5621 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5622 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5625 WEAPON_FLAMETHROWER
:
5627 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5628 FFireAngle
:= FAngle
;
5635 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5636 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5637 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5640 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5642 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5643 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5646 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5650 if NetInterpLevel
< 1 then
5660 AX
:= Abs(FXTo
- FObj
.X
);
5661 AY
:= Abs(FYTo
- FObj
.Y
);
5662 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5664 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5669 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5671 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5672 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5673 PANEL_LIFTUP
, False) then Result
:= -1
5675 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5676 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5677 PANEL_LIFTDOWN
, False) then Result
:= 1
5681 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5688 if Flag
= FLAG_NONE
then
5691 if not g_Game_IsServer
then Exit
;
5693 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5694 if (Flag
= FTeam
) and
5695 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5696 (FFlag
<> FLAG_NONE
) then
5698 if FFlag
= FLAG_RED
then
5699 s
:= _lc
[I_PLAYER_FLAG_RED
]
5701 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5703 evtype
:= FLAG_STATE_SCORED
;
5705 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5706 Insert('.', ts
, Length(ts
) + 1 - 3);
5707 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5709 g_Map_ResetFlag(FFlag
);
5710 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5712 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5715 if g_Game_IsNet
then
5717 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5721 gFlags
[FFlag
].CaptureTime
:= 0;
5726 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5727 if (Flag
= FTeam
) and
5728 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5730 if Flag
= FLAG_RED
then
5731 s
:= _lc
[I_PLAYER_FLAG_RED
]
5733 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5735 evtype
:= FLAG_STATE_RETURNED
;
5736 gFlags
[Flag
].CaptureTime
:= 0;
5738 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5740 g_Map_ResetFlag(Flag
);
5741 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5744 if g_Game_IsNet
then
5746 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5752 // Ïîäîáðàë ÷óæîé ôëàã:
5753 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5757 if Flag
= FLAG_RED
then
5758 s
:= _lc
[I_PLAYER_FLAG_RED
]
5760 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5762 evtype
:= FLAG_STATE_CAPTURED
;
5764 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5766 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5768 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5771 if g_Game_IsNet
then
5773 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5779 procedure TPlayer
.SetFlag(Flag
: Byte);
5782 if FModel
<> nil then
5783 FModel
.SetFlag(FFlag
);
5786 function TPlayer
.DropFlag(): Boolean;
5791 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5793 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5794 with gFlags
[FFlag
] do
5798 Direction
:= FDirection
;
5799 State
:= FLAG_STATE_DROPPED
;
5801 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5802 (FObj
.Vel
.Y
div 2)-2+Random(5));
5803 positionChanged(); // this updates spatial accelerators
5805 if FFlag
= FLAG_RED
then
5806 s
:= _lc
[I_PLAYER_FLAG_RED
]
5808 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5810 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5811 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5813 if g_Game_IsNet
then
5814 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5820 procedure TPlayer
.GetSecret();
5825 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5827 Assert(Key
<= High(FKeys
));
5829 FKeys
[Key
].Pressed
:= True;
5830 FKeys
[Key
].Time
:= Time
;
5833 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5835 Result
:= FKeys
[K
].Pressed
;
5838 procedure TPlayer
.ReleaseKeys();
5842 for a
:= Low(FKeys
) to High(FKeys
) do
5844 FKeys
[a
].Pressed
:= False;
5849 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5853 function TPlayer
.firediry(): Integer;
5855 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5856 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5860 procedure TPlayer
.RememberState();
5864 FSavedState
.Health
:= FHealth
;
5865 FSavedState
.Armor
:= FArmor
;
5866 FSavedState
.Air
:= FAir
;
5867 FSavedState
.JetFuel
:= FJetFuel
;
5868 FSavedState
.CurrWeap
:= FCurrWeap
;
5869 FSavedState
.NextWeap
:= FNextWeap
;
5870 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5873 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5875 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5877 FSavedState
.Rulez
:= FRulez
;
5878 FSavedState
.WaitRecall
:= True;
5881 procedure TPlayer
.RecallState();
5885 if not FSavedState
.WaitRecall
then Exit
;
5887 FHealth
:= FSavedState
.Health
;
5888 FArmor
:= FSavedState
.Armor
;
5889 FAir
:= FSavedState
.Air
;
5890 FJetFuel
:= FSavedState
.JetFuel
;
5891 FCurrWeap
:= FSavedState
.CurrWeap
;
5892 FNextWeap
:= FSavedState
.NextWeap
;
5893 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5896 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5898 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5900 FRulez
:= FSavedState
.Rulez
;
5901 FSavedState
.WaitRecall
:= False;
5903 if gGameSettings
.GameType
= GT_SERVER
then
5904 MH_SEND_PlayerStats(FUID
);
5907 procedure TPlayer
.SaveState (st
: TStream
);
5913 utils
.writeSign(st
, 'PLYR');
5914 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
5916 utils
.writeBool(st
, FIamBot
);
5918 utils
.writeInt(st
, Word(FUID
));
5920 utils
.writeStr(st
, FName
);
5922 utils
.writeInt(st
, Byte(FTeam
));
5924 utils
.writeBool(st
, FAlive
);
5925 // Èçðàñõîäîâàë ëè âñå æèçíè
5926 utils
.writeBool(st
, FNoRespawn
);
5928 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
5929 utils
.writeInt(st
, Byte(b
));
5931 utils
.writeInt(st
, LongInt(FHealth
));
5933 utils
.writeInt(st
, Byte(FLives
));
5935 utils
.writeInt(st
, LongInt(FArmor
));
5937 utils
.writeInt(st
, LongInt(FAir
));
5939 utils
.writeInt(st
, LongInt(FJetFuel
));
5941 utils
.writeInt(st
, LongInt(FPain
));
5943 utils
.writeInt(st
, LongInt(FKills
));
5945 utils
.writeInt(st
, LongInt(FMonsterKills
));
5947 utils
.writeInt(st
, LongInt(FFrags
));
5949 utils
.writeInt(st
, Byte(FFragCombo
));
5950 // Âðåìÿ ïîñëåäíåãî ôðàãà
5951 utils
.writeInt(st
, LongWord(FLastFrag
));
5953 utils
.writeInt(st
, LongInt(FDeath
));
5955 utils
.writeInt(st
, Byte(FFlag
));
5957 utils
.writeInt(st
, LongInt(FSecrets
));
5959 utils
.writeInt(st
, Byte(FCurrWeap
));
5961 utils
.writeInt(st
, Word(FNextWeap
));
5963 utils
.writeInt(st
, Byte(FNextWeapDelay
));
5964 // Âðåìÿ çàðÿäêè BFG
5965 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
5967 utils
.writeInt(st
, LongInt(FDamageBuffer
));
5968 // Ïîñëåäíèé óäàðèâøèé
5969 utils
.writeInt(st
, Word(FLastSpawnerUID
));
5970 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
5971 utils
.writeInt(st
, Byte(FLastHit
));
5973 Obj_SaveState(st
, @FObj
);
5974 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
5975 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
5976 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
5977 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
5979 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
5980 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
5981 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
5983 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
5984 // Íàëè÷èå êðàñíîãî êëþ÷à
5985 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
5986 // Íàëè÷èå çåëåíîãî êëþ÷à
5987 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
5988 // Íàëè÷èå ñèíåãî êëþ÷à
5989 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
5991 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
5992 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
5993 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
5994 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
5995 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
5997 utils
.writeStr(st
, FModel
.Name
);
5999 utils
.writeInt(st
, Byte(FColor
.R
));
6000 utils
.writeInt(st
, Byte(FColor
.G
));
6001 utils
.writeInt(st
, Byte(FColor
.B
));
6005 procedure TPlayer
.LoadState (st
: TStream
);
6014 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
6015 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
6017 FIamBot
:= utils
.readBool(st
);
6019 FUID
:= utils
.readWord(st
);
6021 str
:= utils
.readStr(st
);
6022 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
6024 FTeam
:= utils
.readByte(st
);
6026 FAlive
:= utils
.readBool(st
);
6027 // Èçðàñõîäîâàë ëè âñå æèçíè
6028 FNoRespawn
:= utils
.readBool(st
);
6030 b
:= utils
.readByte(st
);
6031 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
6033 FHealth
:= utils
.readLongInt(st
);
6035 FLives
:= utils
.readByte(st
);
6037 FArmor
:= utils
.readLongInt(st
);
6039 FAir
:= utils
.readLongInt(st
);
6041 FJetFuel
:= utils
.readLongInt(st
);
6043 FPain
:= utils
.readLongInt(st
);
6045 FKills
:= utils
.readLongInt(st
);
6047 FMonsterKills
:= utils
.readLongInt(st
);
6049 FFrags
:= utils
.readLongInt(st
);
6051 FFragCombo
:= utils
.readByte(st
);
6052 // Âðåìÿ ïîñëåäíåãî ôðàãà
6053 FLastFrag
:= utils
.readLongWord(st
);
6055 FDeath
:= utils
.readLongInt(st
);
6057 FFlag
:= utils
.readByte(st
);
6059 FSecrets
:= utils
.readLongInt(st
);
6061 FCurrWeap
:= utils
.readByte(st
);
6063 FNextWeap
:= utils
.readWord(st
);
6065 FNextWeapDelay
:= utils
.readByte(st
);
6066 // Âðåìÿ çàðÿäêè BFG
6067 FBFGFireCounter
:= utils
.readSmallInt(st
);
6069 FDamageBuffer
:= utils
.readLongInt(st
);
6070 // Ïîñëåäíèé óäàðèâøèé
6071 FLastSpawnerUID
:= utils
.readWord(st
);
6072 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6073 FLastHit
:= utils
.readByte(st
);
6075 Obj_LoadState(@FObj
, st
);
6076 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6077 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
6078 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6079 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
6081 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
6082 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6083 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
6085 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
6086 // Íàëè÷èå êðàñíîãî êëþ÷à
6087 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
6088 // Íàëè÷èå çåëåíîãî êëþ÷à
6089 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
6090 // Íàëè÷èå ñèíåãî êëþ÷à
6091 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
6093 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
6094 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6095 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
6096 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6097 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
6099 str
:= utils
.readStr(st
);
6101 FColor
.R
:= utils
.readByte(st
);
6102 FColor
.G
:= utils
.readByte(st
);
6103 FColor
.B
:= utils
.readByte(st
);
6104 if (self
= gPlayer1
) then
6106 str
:= gPlayer1Settings
.Model
;
6107 FColor
:= gPlayer1Settings
.Color
;
6109 else if (self
= gPlayer2
) then
6111 str
:= gPlayer2Settings
.Model
;
6112 FColor
:= gPlayer2Settings
.Color
;
6114 // Îáíîâëÿåì ìîäåëü èãðîêà
6116 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
6117 FModel
.Color
:= TEAMCOLOR
[FTeam
]
6119 FModel
.Color
:= FColor
;
6123 procedure TPlayer
.AllRulez(Health
: Boolean);
6129 FHealth
:= PLAYER_HP_LIMIT
;
6130 FArmor
:= PLAYER_AP_LIMIT
;
6134 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
6135 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
6136 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6139 procedure TPlayer
.RestoreHealthArmor();
6141 FHealth
:= PLAYER_HP_LIMIT
;
6142 FArmor
:= PLAYER_AP_LIMIT
;
6145 procedure TPlayer
.FragCombo();
6149 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6151 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6153 if FFragCombo
< 5 then
6155 Param
:= FUID
or (FFragCombo
shl 16);
6156 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6157 (FComboEvnt
<= High(gDelayedEvents
)) and
6158 gDelayedEvents
[FComboEvnt
].Pending
and
6159 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6160 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6162 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6163 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6166 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6174 procedure TPlayer
.GiveItem(ItemType
: Byte);
6178 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6180 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6184 if FAir
< AIR_MAX
then
6191 if not (R_BERSERK
in FRulez
) then
6193 Include(FRulez
, R_BERSERK
);
6194 if FBFGFireCounter
< 1 then
6196 FCurrWeap
:= WEAPON_KASTET
;
6198 FModel
.SetWeapon(WEAPON_KASTET
);
6202 FBerserk
:= gTime
+30000;
6204 if FHealth
< PLAYER_HP_SOFT
then
6206 FHealth
:= PLAYER_HP_SOFT
;
6207 FBerserk
:= gTime
+30000;
6212 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6214 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6218 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6220 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6224 if FJetFuel
< JET_MAX
then
6226 FJetFuel
:= JET_MAX
;
6229 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6230 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6232 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6233 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6235 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6237 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6239 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6240 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6243 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6244 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6245 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6246 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6247 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6248 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6249 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6250 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6251 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6253 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6254 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6255 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6256 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6257 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6258 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6259 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6260 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6261 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6264 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6265 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6266 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6267 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6268 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6270 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6271 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6272 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6273 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6274 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6276 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6277 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6278 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6279 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6281 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6284 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6285 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6286 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6288 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6289 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6294 if g_Game_IsNet
and g_Game_IsServer
then
6295 MH_SEND_PlayerStats(FUID
);
6298 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6303 if (Random(5) = 1) and (Times
= 1) then
6306 if BodyInLiquid(0, 0) then
6308 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6309 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6310 if Random(2) = 0 then
6311 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6313 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6317 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6319 for i
:= 1 to Times
do
6321 Anim
:= TAnimation
.Create(id
, False, 3);
6323 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6324 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6330 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6335 if (Random(10) = 1) and (Times
= 1) then
6338 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6340 for i
:= 1 to Times
do
6342 Anim
:= TAnimation
.Create(id
, False, 3);
6344 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6345 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6351 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6353 FSawSound
.Pause(Enable
);
6354 FSawSoundIdle
.Pause(Enable
);
6355 FSawSoundHit
.Pause(Enable
);
6356 FSawSoundSelect
.Pause(Enable
);
6361 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6366 FObj
.Rect
:= PLAYER_CORPSERECT
;
6367 FModelName
:= ModelName
;
6372 FState
:= CORPSE_STATE_MESS
;
6373 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6377 FState
:= CORPSE_STATE_NORMAL
;
6378 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6382 destructor TCorpse
.Destroy();
6389 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6391 procedure TCorpse
.positionChanged (); inline; begin end;
6393 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6395 if (dx
<> 0) or (dy
<> 0) then
6404 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6406 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6407 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6408 w
:= PLAYER_CORPSERECT
.Width
;
6409 h
:= PLAYER_CORPSERECT
.Height
;
6413 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6418 if FState
= CORPSE_STATE_REMOVEME
then
6421 FDamage
:= FDamage
+ Value
;
6423 if FDamage
> 150 then
6425 if FAnimation
<> nil then
6430 FState
:= CORPSE_STATE_REMOVEME
;
6432 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6433 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6434 FModelName
, FColor
);
6435 // Çâóê ìÿñà îò òðóïà:
6436 pm
:= g_PlayerModel_Get(FModelName
);
6437 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6441 if (gBodyKillEvent
<> -1)
6442 and gDelayedEvents
[gBodyKillEvent
].Pending
then
6443 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
6444 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, 0);
6449 Blood
:= g_PlayerModel_GetBlood(FModelName
);
6450 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6451 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6452 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6453 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6454 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6455 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
6459 procedure TCorpse
.Draw();
6461 if FState
= CORPSE_STATE_REMOVEME
then
6464 if FAnimation
<> nil then
6465 FAnimation
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6467 if FAnimationMask
<> nil then
6470 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6477 procedure TCorpse
.Update();
6481 if FState
= CORPSE_STATE_REMOVEME
then
6484 if gTime
mod (GAME_TICK
*2) <> 0 then
6486 g_Obj_Move(@FObj
, True, True, True);
6487 positionChanged(); // this updates spatial accelerators
6491 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6492 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6494 st
:= g_Obj_Move(@FObj
, True, True, True);
6495 positionChanged(); // this updates spatial accelerators
6497 if WordBool(st
and MOVE_FALLOUT
) then
6499 FState
:= CORPSE_STATE_REMOVEME
;
6503 if FAnimation
<> nil then
6504 FAnimation
.Update();
6505 if FAnimationMask
<> nil then
6506 FAnimationMask
.Update();
6510 procedure TCorpse
.SaveState (st
: TStream
);
6517 utils
.writeSign(st
, 'CORP');
6518 utils
.writeInt(st
, Byte(0));
6520 utils
.writeInt(st
, Byte(FState
));
6522 utils
.writeInt(st
, Byte(FDamage
));
6524 utils
.writeInt(st
, Byte(FColor
.R
));
6525 utils
.writeInt(st
, Byte(FColor
.G
));
6526 utils
.writeInt(st
, Byte(FColor
.B
));
6528 Obj_SaveState(st
, @FObj
);
6529 utils
.writeInt(st
, Word(FPlayerUID
));
6531 anim
:= (FAnimation
<> nil);
6532 utils
.writeBool(st
, anim
);
6533 // Åñëè åñòü - ñîõðàíÿåì
6534 if anim
then FAnimation
.SaveState(st
);
6535 // Åñòü ëè ìàñêà àíèìàöèè
6536 anim
:= (FAnimationMask
<> nil);
6537 utils
.writeBool(st
, anim
);
6538 // Åñëè åñòü - ñîõðàíÿåì
6539 if anim
then FAnimationMask
.SaveState(st
);
6543 procedure TCorpse
.LoadState (st
: TStream
);
6550 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6551 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6553 FState
:= utils
.readByte(st
);
6555 FDamage
:= utils
.readByte(st
);
6557 FColor
.R
:= utils
.readByte(st
);
6558 FColor
.G
:= utils
.readByte(st
);
6559 FColor
.B
:= utils
.readByte(st
);
6561 Obj_LoadState(@FObj
, st
);
6562 FPlayerUID
:= utils
.readWord(st
);
6564 anim
:= utils
.readBool(st
);
6565 // Åñëè åñòü - çàãðóæàåì
6568 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6569 FAnimation
.LoadState(st
);
6571 // Åñòü ëè ìàñêà àíèìàöèè
6572 anim
:= utils
.readBool(st
);
6573 // Åñëè åñòü - çàãðóæàåì
6576 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6577 FAnimationMask
.LoadState(st
);
6583 constructor TBot
.Create();
6590 FSpectator
:= False;
6597 for a
:= WP_FIRST
to WP_LAST
do
6599 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6600 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6601 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6605 destructor TBot
.Destroy();
6608 inherited Destroy();
6611 procedure TBot
.Draw();
6615 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6616 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6619 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6621 inherited Respawn(Silent
, Force
);
6624 FSelectedWeapon
:= FCurrWeap
;
6629 procedure TBot
.UpdateCombat();
6642 TTargetRecord
= array of TTarget
;
6644 function Compare(a
, b
: TTarget
): Integer;
6646 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6649 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6651 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6652 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6654 if a
.Dist
> b
.Dist
then // B áëèæå
6656 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6659 else // Ñòðàííî -> A
6664 a
, x1
, y1
, x2
, y2
: Integer;
6665 targets
: TTargetRecord
;
6667 Target
, BestTarget
: TTarget
;
6668 firew
, fireh
: Integer;
6672 vsPlayer
, vsMonster
, ok
: Boolean;
6675 function monsUpdate (mon
: TMonster
): Boolean;
6677 result
:= false; // don't stop
6678 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6680 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6682 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6683 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6685 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6686 if g_TraceVector(x1
, y1
, x2
, y2
) then
6688 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6689 SetLength(targets
, Length(targets
)+1);
6690 with targets
[High(targets
)] do
6697 Rect
:= mon
.Obj
.Rect
;
6698 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6699 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6700 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6709 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6710 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6712 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6713 if FCurrWeap
<> FSelectedWeapon
then
6716 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6717 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6719 RemoveAIFlag('NEEDFIRE');
6722 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6723 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6724 else PressKey(KEY_FIRE
);
6728 // Êîîðäèíàòû ñòâîëà:
6729 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6730 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6732 Target
.UID
:= FTargetUID
;
6735 if Target
.UID
<> 0 then
6736 begin // Öåëü åñòü - íàñòðàèâàåì
6737 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6740 tpla
:= g_Player_Get(Target
.UID
);
6744 if (@FObj
) <> nil then
6751 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6752 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6753 Target
.Rect
:= PLAYER_RECT
;
6754 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6755 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6756 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6757 Target
.IsPlayer
:= True;
6761 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6764 mon
:= g_Monsters_ByUID(Target
.UID
);
6767 Target
.X
:= mon
.Obj
.X
;
6768 Target
.Y
:= mon
.Obj
.Y
;
6770 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6771 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6772 Target
.Rect
:= mon
.Obj
.Rect
;
6773 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6774 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6775 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6776 Target
.IsPlayer
:= False;
6783 begin // Öåëè íåò - îáíóëÿåì
6788 Target
.Visible
:= False;
6789 Target
.Line
:= False;
6790 Target
.IsPlayer
:= False;
6795 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6796 if (not Target
.Line
) or (not Target
.Visible
) then
6800 for a
:= 0 to High(gPlayers
) do
6801 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6802 (gPlayers
[a
].FUID
<> FUID
) and
6803 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6804 (not gPlayers
[a
].NoTarget
) and
6805 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6807 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6808 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6811 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6812 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6814 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6815 if g_TraceVector(x1
, y1
, x2
, y2
) then
6817 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6818 SetLength(targets
, Length(targets
)+1);
6819 with targets
[High(targets
)] do
6821 UID
:= gPlayers
[a
].FUID
;
6822 X
:= gPlayers
[a
].FObj
.X
;
6823 Y
:= gPlayers
[a
].FObj
.Y
;
6826 Rect
:= PLAYER_RECT
;
6827 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6828 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6829 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6837 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6840 // Åñëè åñòü âîçìîæíûå öåëè:
6841 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6842 if targets
<> nil then
6844 // Âûáèðàåì íàèëó÷øóþ öåëü:
6845 BestTarget
:= targets
[0];
6846 if Length(targets
) > 1 then
6847 for a
:= 1 to High(targets
) do
6848 if Compare(BestTarget
, targets
[a
]) = 1 then
6849 BestTarget
:= targets
[a
];
6851 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6852 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6853 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6855 Target
:= BestTarget
;
6857 if (Healthy() = 3) or ((Healthy() = 2)) then
6858 begin // Åñëè çäîðîâû - äîãîíÿåì
6859 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6860 SetAIFlag('GORIGHT', '1');
6861 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6862 SetAIFlag('GOLEFT', '1');
6865 begin // Åñëè ïîáèòû - óáåãàåì
6866 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6867 SetAIFlag('GORIGHT', '1');
6868 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6869 SetAIFlag('GOLEFT', '1');
6872 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6873 SelectWeapon(Abs(x1
-Target
.cX
));
6878 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6879 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6880 if Target
.UID
<> 0 then
6882 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6883 Target
.Y
+ Target
.Rect
.Y
) then
6884 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6885 if (Healthy() = 3) or ((Healthy() = 2)) then
6886 begin // Åñëè çäîðîâû - äîãîíÿåì
6887 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6888 SetAIFlag('GORIGHT', '1');
6889 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6890 SetAIFlag('GOLEFT', '1');
6893 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6895 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6896 SetAIFlag('GORIGHT', '1');
6897 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6898 SetAIFlag('GOLEFT', '1');
6902 begin // Öåëü ïîêà íà "ýêðàíå"
6903 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6904 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6905 FLastVisible
:= gTime
;
6906 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6907 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6909 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6910 SetAIFlag('GORIGHT', '1');
6911 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6912 SetAIFlag('GOLEFT', '1');
6916 // Âûáèðàåì óãîë ââåðõ:
6917 if FDirection
= TDirection
.D_LEFT
then
6918 angle
:= ANGLE_LEFTUP
6920 angle
:= ANGLE_RIGHTUP
;
6922 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6923 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6925 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6926 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6927 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6928 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6929 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6930 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6931 begin // òî íóæíî ñòðåëÿòü ââåðõ
6932 SetAIFlag('NEEDFIRE', '1');
6933 SetAIFlag('NEEDSEEUP', '1');
6936 // Âûáèðàåì óãîë âíèç:
6937 if FDirection
= TDirection
.D_LEFT
then
6938 angle
:= ANGLE_LEFTDOWN
6940 angle
:= ANGLE_RIGHTDOWN
;
6942 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6943 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6945 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6946 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6947 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6948 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6949 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6950 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6951 begin // òî íóæíî ñòðåëÿòü âíèç
6952 SetAIFlag('NEEDFIRE', '1');
6953 SetAIFlag('NEEDSEEDOWN', '1');
6956 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6957 if Target
.Visible
and
6958 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6959 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6961 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6962 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
6963 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6964 begin // òî íóæíî ñòðåëÿòü âïåðåä
6965 SetAIFlag('NEEDFIRE', '1');
6966 SetAIFlag('NEEDSEEDOWN', '');
6967 SetAIFlag('NEEDSEEUP', '');
6969 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6970 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6971 if GetRnd(FDifficult
.CloseJump
) then
6972 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6973 if Abs(FObj
.X
-Target
.X
) < 128 then
6977 if Random(a
) = 0 then
6978 SetAIFlag('NEEDJUMP', '1');
6982 // Åñëè öåëü âñå åùå åñòü:
6983 if Target
.UID
<> 0 then
6984 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
6985 Target
.UID
:= 0 // òî çàáûòü öåëü
6986 else // Åñëè âèäåëè íåäàâíî
6987 begin // íî öåëü óáèëè
6988 if Target
.IsPlayer
then
6989 begin // Öåëü - èãðîê
6990 pla
:= g_Player_Get(Target
.UID
);
6991 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
6992 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6993 Target
.UID
:= 0; // òî çàáûòü öåëü
6996 begin // Öåëü - ìîíñòð
6997 mon
:= g_Monsters_ByUID(Target
.UID
);
6998 if (mon
= nil) or (not mon
.alive
) then
6999 Target
.UID
:= 0; // òî çàáûòü öåëü
7002 end; // if Target.UID <> 0
7004 FTargetUID
:= Target
.UID
;
7006 // Åñëè âîçìîæíûõ öåëåé íåò:
7007 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
7008 if targets
= nil then
7009 if GetAIFlag('ATTACKLEFT') <> '' then
7010 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
7011 RemoveAIFlag('ATTACKLEFT');
7013 SetAIFlag('NEEDJUMP', '1');
7015 if RunDirection() = TDirection
.D_RIGHT
then
7016 begin // Èäåì íå â òó ñòîðîíó
7017 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7018 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
7019 SetAIFlag('NEEDFIRE', '1');
7020 SetAIFlag('GOLEFT', '1');
7024 begin // Èäåì â íóæíóþ ñòîðîíó
7025 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7026 SetAIFlag('NEEDFIRE', '1');
7027 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7028 SetAIFlag('GORIGHT', '1');
7032 if GetAIFlag('ATTACKRIGHT') <> '' then
7033 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
7034 RemoveAIFlag('ATTACKRIGHT');
7036 SetAIFlag('NEEDJUMP', '1');
7038 if RunDirection() = TDirection
.D_LEFT
then
7039 begin // Èäåì íå â òó ñòîðîíó
7040 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7041 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
7042 SetAIFlag('NEEDFIRE', '1');
7043 SetAIFlag('GORIGHT', '1');
7048 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7049 SetAIFlag('NEEDFIRE', '1');
7050 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7051 SetAIFlag('GOLEFT', '1');
7055 //HACK! (does it belongs there?)
7056 RealizeCurrentWeapon();
7058 // Åñëè åñòü âîçìîæíûå öåëè:
7059 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7060 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7061 for a
:= 0 to High(targets
) do
7063 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7064 if GetRnd(FDifficult
.DiagFire
) then
7066 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7067 if FDirection
= TDirection
.D_LEFT
then
7068 angle
:= ANGLE_LEFTUP
7070 angle
:= ANGLE_RIGHTUP
;
7072 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7073 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7075 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7076 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7077 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7078 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7079 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7081 SetAIFlag('NEEDFIRE', '1');
7082 SetAIFlag('NEEDSEEUP', '1');
7085 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7086 if FDirection
= TDirection
.D_LEFT
then
7087 angle
:= ANGLE_LEFTDOWN
7089 angle
:= ANGLE_RIGHTDOWN
;
7091 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7092 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7094 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7095 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7096 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7097 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7098 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7100 SetAIFlag('NEEDFIRE', '1');
7101 SetAIFlag('NEEDSEEDOWN', '1');
7105 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7106 if targets
[a
].Line
and targets
[a
].Visible
and
7107 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
7108 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
7110 SetAIFlag('NEEDFIRE', '1');
7115 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7116 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
7117 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
7118 40+GetInterval(FDifficult
.Cover
, 40)) then
7119 SetAIFlag('NEEDJUMP', '1');
7121 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7122 ammo
:= GetAmmoByWeapon(FCurrWeap
);
7123 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
7124 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
7126 SetAIFlag('SELECTWEAPON', '1');
7128 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7129 if GetAIFlag('SELECTWEAPON') = '1' then
7132 RemoveAIFlag('SELECTWEAPON');
7136 procedure TBot
.Update();
7149 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7150 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7152 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7154 if g_debug_BotAIOff
= 3 then
7164 RealizeCurrentWeapon();
7171 procedure TBot
.ReleaseKey(Key
: Byte);
7180 function TBot
.KeyPressed(Key
: Word): Boolean;
7182 Result
:= FKeys
[Key
].Pressed
;
7185 function TBot
.GetAIFlag(aName
: String20
): String20
;
7191 aName
:= LowerCase(aName
);
7193 if FAIFlags
<> nil then
7194 for a
:= 0 to High(FAIFlags
) do
7195 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7197 Result
:= FAIFlags
[a
].Value
;
7202 procedure TBot
.RemoveAIFlag(aName
: String20
);
7206 if FAIFlags
= nil then Exit
;
7208 aName
:= LowerCase(aName
);
7210 for a
:= 0 to High(FAIFlags
) do
7211 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7213 if a
<> High(FAIFlags
) then
7214 for b
:= a
to High(FAIFlags
)-1 do
7215 FAIFlags
[b
] := FAIFlags
[b
+1];
7217 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7222 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7230 aName
:= LowerCase(aName
);
7232 if FAIFlags
<> nil then
7233 for a
:= 0 to High(FAIFlags
) do
7234 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7240 if ok
then FAIFlags
[a
].Value
:= fValue
7243 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7244 with FAIFlags
[High(FAIFlags
)] do
7252 procedure TBot
.UpdateMove
;
7254 procedure GoLeft(Time
: Word = 1);
7256 ReleaseKey(KEY_LEFT
);
7257 ReleaseKey(KEY_RIGHT
);
7258 PressKey(KEY_LEFT
, Time
);
7259 SetDirection(TDirection
.D_LEFT
);
7262 procedure GoRight(Time
: Word = 1);
7264 ReleaseKey(KEY_LEFT
);
7265 ReleaseKey(KEY_RIGHT
);
7266 PressKey(KEY_RIGHT
, Time
);
7267 SetDirection(TDirection
.D_RIGHT
);
7270 function Rnd(a
: Word): Boolean;
7272 Result
:= Random(a
) = 0;
7275 procedure Turn(Time
: Word = 1200);
7277 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7282 ReleaseKey(KEY_LEFT
);
7283 ReleaseKey(KEY_RIGHT
);
7286 function CanRunLeft(): Boolean;
7288 Result
:= not CollideLevel(-1, 0);
7291 function CanRunRight(): Boolean;
7293 Result
:= not CollideLevel(1, 0);
7296 function CanRun(): Boolean;
7298 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7301 procedure Jump(Time
: Word = 30);
7303 PressKey(KEY_JUMP
, Time
);
7306 function NearHole(): Boolean;
7310 { TODO 5 : Ëåñòíèöû }
7311 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7312 for x
:= 1 to PLAYER_RECT
.Width
do
7313 if (not StayOnStep(x
*sx
, 0)) and
7314 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7315 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7324 function BorderHole(): Boolean;
7328 { TODO 5 : Ëåñòíèöû }
7329 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7330 for x
:= 1 to PLAYER_RECT
.Width
do
7331 if (not StayOnStep(x
*sx
, 0)) and
7332 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7333 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7335 for xx
:= x
to x
+32 do
7336 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7346 function NearDeepHole(): Boolean;
7352 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7355 for x
:= 1 to PLAYER_RECT
.Width
do
7356 if (not StayOnStep(x
*sx
, 0)) and
7357 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7358 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7360 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7362 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7367 end else Result
:= False;
7370 function OverDeepHole(): Boolean;
7377 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7379 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7386 function OnGround(): Boolean;
7388 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7391 function OnLadder(): Boolean;
7393 Result
:= FullInStep(0, 0);
7396 function BelowLadder(): Boolean;
7398 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7399 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7400 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7401 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7404 function BelowLiftUp(): Boolean;
7406 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7407 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7408 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7409 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7412 function OnTopLift(): Boolean;
7414 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7417 function CanJumpOver(): Boolean;
7421 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7425 if not CollideLevel(sx
, 0) then Exit
;
7427 for y
:= 1 to BOT_MAXJUMP
do
7428 if CollideLevel(0, -y
) then Exit
else
7429 if not CollideLevel(sx
, -y
) then
7436 function CanJumpUp(Dist
: ShortInt): Boolean;
7443 if CollideLevel(Dist
, 0) then Exit
;
7446 for y
:= 0 to BOT_MAXJUMP
do
7447 if CollideLevel(Dist
, -y
) then
7456 for yy
:= y
+1 to BOT_MAXJUMP
do
7457 if not CollideLevel(Dist
, -yy
) then
7466 for y
:= 0 to BOT_MAXJUMP
do
7467 if CollideLevel(0, -y
) then
7475 if y
< yy
then Exit
;
7480 function IsSafeTrigger(): Boolean;
7485 if gTriggers
= nil then
7487 for a
:= 0 to High(gTriggers
) do
7488 if Collide(gTriggers
[a
].X
,
7491 gTriggers
[a
].Height
) and
7492 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7493 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7494 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7495 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7496 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7501 // Âîçìîæíî, íàæèìàåì êíîïêó:
7502 if Rnd(16) and IsSafeTrigger() then
7505 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7506 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7508 ReleaseKey(KEY_LEFT
);
7509 ReleaseKey(KEY_RIGHT
);
7513 // Èäåì âëåâî, åñëè íàäî áûëî:
7514 if GetAIFlag('GOLEFT') <> '' then
7516 RemoveAIFlag('GOLEFT');
7517 if CanRunLeft() then
7521 // Èäåì âïðàâî, åñëè íàäî áûëî:
7522 if GetAIFlag('GORIGHT') <> '' then
7524 RemoveAIFlag('GORIGHT');
7525 if CanRunRight() then
7529 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7530 if FObj
.X
< -32 then
7533 if FObj
.X
+32 > gMapInfo
.Width
then
7536 // Ïðûãàåì, åñëè íàäî áûëî:
7537 if GetAIFlag('NEEDJUMP') <> '' then
7540 RemoveAIFlag('NEEDJUMP');
7543 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7544 if GetAIFlag('NEEDSEEUP') <> '' then
7547 ReleaseKey(KEY_DOWN
);
7548 PressKey(KEY_UP
, 20);
7549 RemoveAIFlag('NEEDSEEUP');
7552 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7553 if GetAIFlag('NEEDSEEDOWN') <> '' then
7556 ReleaseKey(KEY_DOWN
);
7557 PressKey(KEY_DOWN
, 20);
7558 RemoveAIFlag('NEEDSEEDOWN');
7561 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7562 if GetAIFlag('GOINHOLE') <> '' then
7563 if not OnGround() then
7565 ReleaseKey(KEY_LEFT
);
7566 ReleaseKey(KEY_RIGHT
);
7567 RemoveAIFlag('GOINHOLE');
7568 SetAIFlag('FALLINHOLE', '1');
7571 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7572 if GetAIFlag('FALLINHOLE') <> '' then
7574 RemoveAIFlag('FALLINHOLE');
7576 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7577 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7578 if GetAIFlag('FALLINHOLE') = '' then
7579 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7585 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7587 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7591 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7592 if OnGround() and NearHole() then
7593 if NearDeepHole() then // Åñëè ýòî áåçäíà
7595 0..3: Turn(); // Áåæèì îáðàòíî
7596 4: Jump(); // Ïðûãàåì
7597 5: begin // Ïðûãàåì îáðàòíî
7602 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7603 if GetAIFlag('GOINHOLE') = '' then
7605 0: Turn(); // Íå íóæíî òóäà
7606 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7607 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7608 if BorderHole() then
7609 SetAIFlag('GOINHOLE', '1');
7612 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7613 if (not CanRun()) and OnGround() then
7615 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7616 if CanJumpOver() or OnLadder() then
7618 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7619 if Random(2) = 0 then
7621 if IsSafeTrigger() then
7627 // Îñòàëîñü ìàëî âîçäóõà:
7628 if FAir
< 36 * 2 then
7631 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7632 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7633 if BodyInAcid(0, 0) then
7637 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7639 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7640 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7643 {function TBot.NeedItem(Item: Byte): Byte;
7648 procedure TBot
.SelectWeapon(Dist
: Integer);
7652 function HaveAmmo(weapon
: Byte): Boolean;
7655 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7656 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7657 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7658 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7659 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7660 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7661 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7662 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7663 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7664 else Result
:= True;
7669 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7671 if Dist
> BOT_LONGDIST
then
7672 begin // Äàëüíèé áîé
7674 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7676 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7680 else //if Dist > BOT_UNSAFEDIST then
7681 begin // Áëèæíèé áîé
7683 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7685 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7692 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7694 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7700 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7702 Result
:= inherited PickItem(ItemType
, force
, remove
);
7704 if Result
then SetAIFlag('SELECTWEAPON', '1');
7707 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7709 Result
:= inherited Heal(value
, Soft
);
7712 function TBot
.Healthy(): Byte;
7714 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7715 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7716 else if (FHealth
> 50) then Result
:= 2
7717 else if (FHealth
> 20) then Result
:= 1
7721 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7723 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7724 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7727 procedure TBot
.OnDamage(Angle
: SmallInt);
7735 if (Angle
= 0) or (Angle
= 180) then
7738 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7739 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7741 pla
:= g_Player_Get(FLastSpawnerUID
);
7742 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7743 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7746 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7747 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7749 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7750 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7751 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7756 SetAIFlag('ATTACKLEFT', '1')
7758 SetAIFlag('ATTACKRIGHT', '1');
7762 function TBot
.RunDirection(): TDirection
;
7764 if Abs(Vel
.X
) >= 1 then
7766 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7768 Result
:= FDirection
;
7771 function TBot
.GetRnd(a
: Byte): Boolean;
7773 if a
= 0 then Result
:= False
7774 else if a
= 255 then Result
:= True
7775 else Result
:= Random(256) > 255-a
;
7778 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7780 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7784 procedure TDifficult
.save (st
: TStream
);
7786 utils
.writeInt(st
, Byte(DiagFire
));
7787 utils
.writeInt(st
, Byte(InvisFire
));
7788 utils
.writeInt(st
, Byte(DiagPrecision
));
7789 utils
.writeInt(st
, Byte(FlyPrecision
));
7790 utils
.writeInt(st
, Byte(Cover
));
7791 utils
.writeInt(st
, Byte(CloseJump
));
7792 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7793 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7796 procedure TDifficult
.load (st
: TStream
);
7798 DiagFire
:= utils
.readByte(st
);
7799 InvisFire
:= utils
.readByte(st
);
7800 DiagPrecision
:= utils
.readByte(st
);
7801 FlyPrecision
:= utils
.readByte(st
);
7802 Cover
:= utils
.readByte(st
);
7803 CloseJump
:= utils
.readByte(st
);
7804 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7805 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7809 procedure TBot
.SaveState (st
: TStream
);
7814 inherited SaveState(st
);
7815 utils
.writeSign(st
, 'BOT0');
7817 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7819 utils
.writeInt(st
, Word(FTargetUID
));
7820 // Âðåìÿ ïîòåðè öåëè
7821 utils
.writeInt(st
, LongWord(FLastVisible
));
7822 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7823 dw
:= Length(FAIFlags
);
7824 utils
.writeInt(st
, LongInt(dw
));
7826 for i
:= 0 to dw
-1 do
7828 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7829 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7831 // Íàñòðîéêè ñëîæíîñòè
7832 FDifficult
.save(st
);
7836 procedure TBot
.LoadState (st
: TStream
);
7841 inherited LoadState(st
);
7842 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7844 FSelectedWeapon
:= utils
.readByte(st
);
7846 FTargetUID
:= utils
.readWord(st
);
7847 // Âðåìÿ ïîòåðè öåëè
7848 FLastVisible
:= utils
.readLongWord(st
);
7849 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7850 dw
:= utils
.readLongInt(st
);
7851 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7852 SetLength(FAIFlags
, dw
);
7854 for i
:= 0 to dw
-1 do
7856 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7857 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7859 // Íàñòðîéêè ñëîæíîñòè
7860 FDifficult
.load(st
);
7865 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);